[mapguide-commits] r6145 - in trunk/MgDev/Web/src/mapadmin: . images

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Sep 22 02:13:22 EDT 2011


Author: liuar
Date: 2011-09-21 23:13:21 -0700 (Wed, 21 Sep 2011)
New Revision: 6145

Modified:
   trunk/MgDev/Web/src/mapadmin/images/warning.png
   trunk/MgDev/Web/src/mapadmin/performanceReport.php
   trunk/MgDev/Web/src/mapadmin/performanceReport_Export.php
   trunk/MgDev/Web/src/mapadmin/performanceReport_GetResult.php
   trunk/MgDev/Web/src/mapadmin/performanceReport_MapViewer.php
   trunk/MgDev/Web/src/mapadmin/resizablepagecomponents.php
   trunk/MgDev/Web/src/mapadmin/serverdatafunctions.php
Log:
On behalf of Ted Yang.
fix the ticket 1768(part II): http://trac.osgeo.org/mapguide/ticket/1768

1. implement the "Recent Settings" functions 
2. use cookie to save the last run settings 
3. display inline alert message when the setting is changed 
4. get the real profiling result use the new profiling API 
5. click the layer table row to display the detailed info 
6. export the performance report use the real data
7. fix some UI defects:
a) pass the session ID to the mapViewer so users don't need to input the username and password
b) user reopen the mapviewer can zoom to the view which last time opened
c) when the mapViewer opened, user press "Enter" should not refresh the whole page
d) the order of the map names should be case insensitive

Modified: trunk/MgDev/Web/src/mapadmin/images/warning.png
===================================================================
(Binary files differ)

Modified: trunk/MgDev/Web/src/mapadmin/performanceReport.php
===================================================================
--- trunk/MgDev/Web/src/mapadmin/performanceReport.php	2011-09-22 01:57:08 UTC (rev 6144)
+++ trunk/MgDev/Web/src/mapadmin/performanceReport.php	2011-09-22 06:13:21 UTC (rev 6145)
@@ -40,7 +40,8 @@
     $mapProfileResult=new MapProfileResult();
     $mapResources;
     $mapResourceShortNames;
-    $displayManager= new DisplayProfileResultManager();
+    $displayManager = new DisplayProfileResultManager();
+    $recentSettings = new RecentSettings();
 
     function GetAllMapResources()
     {
@@ -82,7 +83,9 @@
                 $mapResourceShortNames[$i] = $shortMapName;
             }
 
-            array_multisort($mapResourceShortNames, $mapResources);
+            //Case insensitive sorting
+            $mapResourceShortNames_Lower = array_map("strtolower", $mapResourceShortNames);
+            array_multisort($mapResourceShortNames_Lower, SORT_ASC, SORT_STRING,$mapResources,$mapResourceShortNames);
         }
         catch (Exception $exc)
         {
@@ -91,6 +94,8 @@
     }
 
     GetAllMapResources();
+
+    $recentSettings->GetRecentSettings();    
 }
 catch ( MgException $e )
 {
@@ -248,7 +253,7 @@
 
                 .mapNameStyle
                 {
-                    background: #EEEEEE url('images/mapDefinitionNameInfo.png') no-repeat right;
+                    background: transparent url('images/mapDefinitionNameInfo.png') no-repeat right;
                     padding-right: 20px;
                     cursor:default;
                 }
@@ -301,6 +306,16 @@
                     left: 400px;
                 }
 
+                #ResultNotMatchWrn
+                {
+                    border: 2px solid #CCCCCC;
+                    background: #FFFEBB url('images/warning.png') no-repeat left top;
+                    margin-top: 25px;
+                    padding-left: 30px;
+                    display: none;
+                    width: auto;
+                }
+
             </style>
         
             <script type="text/javascript">
@@ -403,6 +418,8 @@
                     content.style.display = "none";
                 }
 
+                //As soon as the user changed the settings,
+                //an inline alert message is displayed between the Action buttons and the “Results” title
                 function SetResultNotMatchWarningMsg(visible)
                 {
                     var wrnMsg = document.getElementById("ResultNotMatchWrn");
@@ -416,15 +433,89 @@
                     }
                 }
 
+                //Determine whether to show the "settings changed" inline warning message or not
                 function ShowReportWarningMsg()
                 {
-                    var reportTab = document.getElementById("resultsTab");
-                    if(reportTab.style.display=="block")
+                    var scale = document.getElementById("txtScale");
+                    var centerPoint = document.getElementById("txtCenterPoint");
+                    var mapSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
+
+                    var mapIdLastRun = document.getElementById("lastRunMapId");
+                    var centerPointLastRun = document.getElementById("lastRunCenterPoint");
+                    var scaleLastRun = document.getElementById("lastRunScale");
+
+                    var currentMapIdValue = RemoveSpace(mapSelector.value);
+                    var currentCenterPointValue = RemoveSpace(centerPoint.value);
+                    var currentScaleValue = RemoveSpace(scale.value);
+
+                    //if the value of the mapIdLastRun textbox is not empty,
+                    //then the performance report has been ran at least once
+                    if(mapIdLastRun.value != "")
                     {
-                        SetResultNotMatchWarningMsg(true);
+                        //if the map resource ID is not match then show the warning message
+                        if(currentMapIdValue != mapIdLastRun.value)
+                        {
+                            SetResultNotMatchWarningMsg(true);
+                            return;
+                        }
+
+                        //if the center point is not match then show the warning message
+                        if(ValidateCenterPoint(false))
+                        {
+                            var point = currentCenterPointValue.split("*");
+                            var x = point[0];
+                            var y = point[1];
+
+                            currentCenterPointValue = RemoveSpace( FormatCenterPoint(x,y,2) );
+
+                            if(currentCenterPointValue != centerPointLastRun.value)
+                            {
+                                SetResultNotMatchWarningMsg(true);
+                                return;
+                            }
+                        }
+                        else
+                        {
+                            SetResultNotMatchWarningMsg(true);
+                            return;
+                        }
+
+                        //if the scale is not match then show the warning message
+                        if(ValidateScale(false))
+                        {
+                            currentScaleValue = RemoveSpace( FormatNumber(currentScaleValue,2) );
+
+                            if(currentScaleValue != scaleLastRun.value)
+                            {
+                               SetResultNotMatchWarningMsg(true);
+                               return;
+                            }
+                        }
+                        else 
+                        {
+                            SetResultNotMatchWarningMsg(true);
+                            return;
+                        }
+
+                        SetResultNotMatchWarningMsg(false);
                     }
                 }
 
+                function SaveLastRunSettings()
+                {
+                    var scale = document.getElementById("txtScale");
+                    var centerPoint = document.getElementById("txtCenterPoint");
+                    var mapSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
+
+                    var mapIdLastRun = document.getElementById("lastRunMapId");
+                    var centerPointLastRun = document.getElementById("lastRunCenterPoint");
+                    var scaleLastRun = document.getElementById("lastRunScale");
+
+                    mapIdLastRun.value = RemoveSpace(mapSelector.value);
+                    centerPointLastRun.value = RemoveSpace(centerPoint.value);
+                    scaleLastRun.value = RemoveSpace(scale.value);
+                }
+
                 function ExpandResultsTab()
                 {
                     var content = document.getElementById("resultsTab");
@@ -433,31 +524,31 @@
 
                 function MapResoucesNameSelectChange()
                 {
-                    var tipDiv=document.getElementById("mapResourceNameTip");
-                    var mapDefinitonSelector=document.getElementById("mapSelector_DO_NOT_PERSIST");
+                    var tipDiv = document.getElementById("mapResourceNameTip");
+                    var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
 
-                    var settingsBtn=document.getElementById("mapViewerBtn");
-                    var centerPoint=document.getElementById("txtCenterPoint");
-                    var scale=document.getElementById("txtScale");
+                    var settingsBtn = document.getElementById("mapViewerBtn");
+                    var centerPoint = document.getElementById("txtCenterPoint");
+                    var scale = document.getElementById("txtScale");
 
                     //If another map is selected, then the center point and scale should be cleared of values,
                     //that is return to default values “enter center point”  and “enter scale”.
-                    if(centerPoint.value!="Enter center point")
+                    if(centerPoint.value != "Enter center point")
                     {
-                        centerPoint.value="Enter center point";
+                        centerPoint.value = "Enter center point";
                     }
 
-                    if( scale.value!="Enter scale")
+                    if(scale.value != "Enter scale")
                     {
-                        scale.value="Enter scale";
+                        scale.value = "Enter scale";
                     }
 
                     //show the map definition ID by the side of the map selector
                     if(mapDefinitonSelector.selectedIndex >= 0)
                     {
-                        tipDiv.innerHTML=mapDefinitonSelector.options[mapDefinitonSelector.selectedIndex].value;
+                        tipDiv.innerHTML = mapDefinitonSelector.options[mapDefinitonSelector.selectedIndex].value;
                         //clear warning message
-                        var mapSelectorWarnMsg=document.getElementById("selectMapResourceWarningMessage");
+                        var mapSelectorWarnMsg = document.getElementById("selectMapResourceWarningMessage");
                         mapSelectorWarnMsg.innerHTML = "";
 
                         //text input Controls in Step 2 are enabled once a map resource is selected in Step 1.
@@ -465,17 +556,17 @@
                         scale.removeAttribute("disabled");
                         settingsBtn.removeAttribute("disabled");
 
-                        var visible=ValidateScale(false);
+                        var visible = ValidateScale(false);
                         if(visible)
                         {
-                           visible=ValidateCenterPoint(false);
+                           visible = ValidateCenterPoint(false);
                         }
 
                         SetRunButtonState(visible);
                     }
                     else
                     {
-                        tipDiv.innerHTML="";
+                        tipDiv.innerHTML = "";
                         //when user clear the settings, the mapselector is not seleced and the text area is disabled
                         settingsBtn.setAttribute("disabled","disabled");
                         centerPoint.setAttribute("disabled", "disabled");
@@ -484,21 +575,38 @@
                         SetRunButtonState(false);
                     }
 
+                    ShowReportWarningMsg();
+
                     ClearWrnMsg();
-                    ShowReportWarningMsg();
                 }
 
+                function ClearWrnMsg()
+                {
+                    var scale = document.getElementById("txtScale");
+                    scale.className="";
+
+                    var centerPoint = document.getElementById("txtCenterPoint");
+                    centerPoint.className="";
+
+                    var scaleWarnMsg = document.getElementById("scaleWarnMessage");
+                    scaleWarnMsg.innerHTML = "";
+
+                    var centerPointWarnMsg = document.getElementById("centerPointWarnMessage");
+                    centerPointWarnMsg.innerHTML = "";
+                }
+
+                //check the value for the scale is resonable or not
                 function ValidateScale(needFormat)
                 {
-                    var result=false;
+                    var result = false;
                    
                     var scale = document.getElementById("txtScale");
                     var scaleWarnMsg = document.getElementById("scaleWarnMessage");
-                    var scaleValue=RemoveSpace(scale.value);
+                    var scaleValue = RemoveSpace(scale.value);
 
                     if("" == scaleValue)
                     {
-                        result=false;
+                        result = false;
                         scaleWarnMsg.innerHTML = "A map scale was not entered.";
                         scale.className="warnMsgStyle";
                     }
@@ -517,17 +625,18 @@
                         {
                             if(needFormat)
                             {
-                                scale.value=formatNumber(scaleValue,2);
+                                scale.value = FormatNumber(scaleValue,2);
                             }
-                                
 
                             scaleWarnMsg.innerHTML = "";
                             scale.className="";
                         }
                     }
+
                     return result;
                 }
 
+                //check the value for the center point is resonable or not
                 function ValidateCenterPoint(needFormat)
                 {
                     var result = false;
@@ -538,27 +647,27 @@
 
                     if("" == centerPointValue)
                     {
-                        result=false;
+                        result = false;
                         centerPointWarnMsg.innerHTML = "A center point was not entered.";
-                        centerPoint.className="warnMsgStyle";
+                        centerPoint.className = "warnMsgStyle";
                     }
                     else
                     {
                         try
                         {
-                            var point=centerPointValue.split("*");
-                            if(point.length!=2)
+                            var point = centerPointValue.split("*");
+                            if(point.length != 2)
                             {
-                                result=false;
+                                result = false;
                                 centerPointWarnMsg.innerHTML = "Not a valid center point.";
-                                centerPoint.className="warnMsgStyle";
+                                centerPoint.className = "warnMsgStyle";
                             }
                             else
                             {
-                                var x=point[0];
-                                var y=point[1];
+                                var x = point[0];
+                                var y = point[1];
                               
-                                result=!(IsNotFloat(x)||IsNotFloat(y));
+                                result = !(IsNotFloat(x)||IsNotFloat(y));
 
                                 if(!result)
                                 {
@@ -569,19 +678,19 @@
                                 {
                                     if(needFormat)
                                     {
-                                        centerPoint.value=formatCenterPoint(x,y,2);
+                                        centerPoint.value = FormatCenterPoint(x,y,2);
                                     }
                                         
                                     centerPointWarnMsg.innerHTML = "";
-                                    centerPoint.className="";
+                                    centerPoint.className = "";
                                 }
                             }
                         }
                         catch(e)
                         {
-                            result=false;
+                            result = false;
                             centerPointWarnMsg.innerHTML = "Not a valid center point.";
-                            centerPoint.className="warnMsgStyle";
+                            centerPoint.className = "warnMsgStyle";
                         }
                     }
 
@@ -590,14 +699,17 @@
 
                 function ScaleTxtKeyUp()
                 {
-                    var visible=ValidateScale(false);
+                    //when the scale textbox has new input
+                    //get the new value and check if the input is resonable
+                    var visible = ValidateScale(false);
 
+                    //check other settings to see if it is reasonable
                     if(visible)
                     {
                         var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
-                        if(mapDefinitonSelector.selectedIndex>=0)
+                        if(mapDefinitonSelector.selectedIndex >= 0)
                         {
-                            visible=ValidateCenterPoint(false);
+                            visible = ValidateCenterPoint(false);
                         }
                         else
                         {
@@ -606,18 +718,22 @@
                     }
 
                     SetRunButtonState(visible);
+
+                    //show the "settings changed" inline warning message depends on new setting
+                    ShowReportWarningMsg();
                 }
 
                 function CenterPointTxtKeyUp()
                 {
                     var visible=ValidateCenterPoint(false);
 
+                    //check other settings to see if it is reasonable
                     if(visible)
                     {
                         var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
-                        if(mapDefinitonSelector.selectedIndex>=0)
+                        if(mapDefinitonSelector.selectedIndex >= 0)
                         {
-                            visible=ValidateScale(false);
+                            visible = ValidateScale(false);
                         }
                         else
                         {
@@ -626,6 +742,9 @@
                     }
 
                     SetRunButtonState(visible);
+
+                    //show the "settings changed" inline warning message depends on new setting
+                    ShowReportWarningMsg();
                 }
 
                 function ScaleFocus()
@@ -653,9 +772,9 @@
                 {
                     var mapFrame = document.getElementById("mapViewerFrame");
                     var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
-                    if(mapDefinitonSelector.selectedIndex>=0)
+                    if(mapDefinitonSelector.selectedIndex >= 0)
                     {
-                        mapFrame.src="performanceReport_MapViewer.php?mapDefinition="+mapDefinitonSelector.options[mapDefinitonSelector.selectedIndex].value;
+                        mapFrame.src = "performanceReport_MapViewer.php?mapDefinition=" + mapDefinitonSelector.options[mapDefinitonSelector.selectedIndex].value;
                     }
 
                     var bgDiv = document.getElementById("bgDiv");
@@ -667,17 +786,43 @@
                     mapViewerDiv.style.display = "block";
                     SetMapViewerLoaction(mapViewerDiv);
 
+                    //make the textbox focused
+                    var autoFoucsTxt = document.getElementById("mapViewerAutoFocusTxt");
+                    autoFoucsTxt.focus();
+
                     checkMapFrameLoadedInterval = setInterval(CheckMapFrameLoaded, 100);
                 }
 
+                //when the map viewer dialogue is displayed, user press "Enter",
+                //it will cause the page reload, so we add a textbox here,
+                //and make it focus when the map viewer is shown.
+                //add the event handler for the "keyUp", when user press the key "Enter",
+                //make it the same with press button "OK".
+                //Here is an issue, to make the input invisible but can focus,
+                //we set the width and height as 0, and border as none,
+                //it works well in IE9 and firefox, but in chrome and safari,
+                //if the border set as none, this event will not be fired.
+                //TODO:Multiple Browsers:Safari and Chrome not work
+                function MapViewerKeyUp(event)
+                {
+                    if(event.keyCode == 13)
+                    {
+                        if(!IsMapFrameLoaded())
+                            return;
+
+                        MapViewerBtnOKClicked();
+                    }
+                }
+
                 function SetBgDivSize(bgDiv)
                 {
                     bgDiv.style.height = document.body.offsetHeight+"px";
                     bgDiv.style.width = document.body.offsetWidth+"px";
                 }
 
-                var mapViewerWidth=800;
-                var mapViewerHeight=600;
+                //default map viewer width and height
+                var mapViewerWidth = 800;
+                var mapViewerHeight = 600;
                 function SetMapViewerLoaction(mapViewerDiv)
                 {
                     if(document.body.clientHeight > mapViewerHeight)
@@ -699,7 +844,7 @@
                     }
                 }
 
-                window.onresize=WindowResized;
+                window.onresize = WindowResized;
 
                 function WindowResized()
                 {
@@ -757,18 +902,22 @@
                 }
 
                 var messageShorterInterval = null;
+
+                var zoomToViewInterval = null;
                 
                 function CreateButtons()
                 {
-                    var mapViewerFrame=window.frames["mapViewerFrame"];
+                    var mapViewerFrame = window.frames["mapViewerFrame"];
                     
                     var mapFrame = mapViewerFrame.GetMapFrame();
-                    var mapFrameDocument=mapFrame.document;
+                    var mapFrameDocument = mapFrame.document;
 
                     mapFrame.ShowMapMessage("Use the map controls in the toolbar above to specify the center point and scale.", "info");
                     //use setInterval to make sure that the message div has been created.
                     messageShorterInterval = window.setInterval(function(){ makeMessageShorter(mapFrame); }, 100);
 
+                    zoomToViewInterval = window.setInterval(function(){ ZoomToPreviousView(mapFrame); }, 100);
+
                     var mapSpace = mapFrameDocument.getElementById("mapSpace");
                     var buttonPanel = mapFrameDocument.createElement('div');
                     buttonPanel.style.backgroundColor="transparent";
@@ -802,30 +951,31 @@
 
                 function MapViewerBtnOKClicked()
                 {
-                   var mapViewerFrame=window.frames["mapViewerFrame"];
+                   var mapViewerFrame = window.frames["mapViewerFrame"];
                    var mapFrame = mapViewerFrame.GetMapFrame();
                    var center = mapFrame.GetCenter();
                    var scale = mapFrame.GetScale();
 
                    var centerPoint = document.getElementById("txtCenterPoint");
-                   centerPoint.value=center.X+"*"+center.Y;
-                   var centerPointValidate=ValidateCenterPoint(true);
+                   centerPoint.value = center.X + "*" + center.Y;
+                   var centerPointValidate = ValidateCenterPoint(true);
 
                    var scaleInput = document.getElementById("txtScale");
-                   scaleInput.value=scale;
-                   var scaleValidate=ValidateScale(true);
+                   scaleInput.value = scale;
+                   var scaleValidate = ValidateScale(true);
 
-                   var visible=centerPointValidate&&scaleValidate;
+                   var visible = centerPointValidate && scaleValidate;
                    if(visible)
                    {
                        var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
-                       if(mapDefinitonSelector.selectedIndex>=0)
+                       if(mapDefinitonSelector.selectedIndex >= 0)
                        {
-                           visible=true;
+                           visible = true;
+                           SaveCurrentSelect(mapDefinitonSelector.options[mapDefinitonSelector.selectedIndex].value,center,scale);
                        }
                        else
                        {
-                           visible=false;
+                           visible = false;
                        }
                    }
 
@@ -834,6 +984,18 @@
                    CloseMapViewer();
                 }
 
+                function SaveCurrentSelect(mapId,center,scale)
+                {
+                    var mapIdSaved = document.getElementById("mapViewerLastOpenMapId");
+                    mapIdSaved.value = mapId;
+
+                    var centerPointSaved = document.getElementById("mapViewerLastOpenCenterPoint");
+                    centerPointSaved.value = center.X + "*" + center.Y;
+
+                    var scaleSaved = document.getElementById("mapViewerLastOpenScale");
+                    scaleSaved.value = scale;
+                }
+
                 function makeMessageShorter(mapFrame)
                 {
                     if(!mapFrame.mapMessage || !mapFrame.mapMessage.container)
@@ -841,9 +1003,36 @@
                     
                     window.clearInterval(messageShorterInterval);
                     // make it shorter
-                    mapFrame.mapMessage.container.style.padding="1px";
+                    mapFrame.mapMessage.container.style.padding = "1px";
                 }
 
+                function ZoomToPreviousView(mapFrame)
+                {
+                    if(!mapFrame.mapLoading)
+                        return;
+
+                    window.clearInterval(zoomToViewInterval);
+
+                    var mapViewerFrame = window.frames["mapViewerFrame"];
+                    var mapFrame = mapViewerFrame.GetMapFrame();
+
+                    var mapIdSaved = document.getElementById("mapViewerLastOpenMapId");
+                    var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
+                    var selectMapId = mapDefinitonSelector.options[mapDefinitonSelector.selectedIndex].value;
+
+                    if(("" != mapIdSaved.value) && (mapIdSaved.value === selectMapId))
+                    {
+                        var centerPointSaved = document.getElementById("mapViewerLastOpenCenterPoint");
+                        var scaleSaved = document.getElementById("mapViewerLastOpenScale");
+
+                        var point = centerPointSaved.value.split("*");
+                        if(2 == point.length)
+                        {
+                            mapFrame.ZoomToView( parseFloat(point[0]), parseFloat(point[1]), parseFloat(scaleSaved.value), true);
+                        }
+                    }
+                }
+
                 //remove the space at the begin and end of a string
                 function Trim(str)
                 {
@@ -885,7 +1074,7 @@
                     return strWithoutSpace;
                 }
 
-                function formatNumber(s, n)
+                function FormatNumber(s, n)
                 {
                    var n = n > 0 && n <= 20 ? n : 2;
 
@@ -904,9 +1093,9 @@
                    return t.split("").reverse().join("") + "." + r;
                 }
 
-                function formatCenterPoint(x,y,fractionDigits)
+                function FormatCenterPoint(x,y,fractionDigits)
                 {
-                    return parseFloat(x).toExponential(fractionDigits)+"*"+parseFloat(y).toExponential(fractionDigits);
+                     return parseFloat(x).toExponential(fractionDigits) + "*" + parseFloat(y).toExponential(fractionDigits);
                 }
 
                 function IsNotFloat(str)
@@ -1079,10 +1268,10 @@
                 {
                     var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
 
-                    if(mapDefinitonSelector.selectedIndex<0)
+                    if(mapDefinitonSelector.selectedIndex < 0)
                     {
                         var mapResourceWarningMessage = document.getElementById("selectMapResourceWarningMessage");
-                        mapResourceWarningMessage.innerHTML="A map resource was not selected.";
+                        mapResourceWarningMessage.innerHTML = "A map resource was not selected.";
                         return false;
                     }
 
@@ -1092,34 +1281,46 @@
                     if(!ValidateScale(true))
                         return false;
 
+                    //when a new report is run, the inline message disappears
                     SetResultNotMatchWarningMsg(false);
 
                     var loadingImg = document.getElementById("ajax_loading_img");
-                    loadingImg.style.display="inline";
+                    loadingImg.style.display = "inline";
 
                     var btnClear = document.getElementById("btnClearSpan");
-                    btnClear.style.display="none";
+                    btnClear.style.display = "none";
 
                     var runButton = document.getElementById("runBtn");
                     runButton.setAttribute("disabled", "disabled");
 
-                    xmlHttp=GetXmlHttpObject();
-                    if (xmlHttp==null)
+                    xmlHttp = GetXmlHttpObject();
+                    if (xmlHttp == null)
                     {
                        alert ("Browser does not support HTTP Request!");
                        return;
                     }
 
+                    //the profiling map API requires the image width and height
+                    var imageWidth = document.body.clientWidth?document.body.clientWidth:1280;
+                    var imageHeight = document.body.clientHeight?document.body.clientHeight:1024;
+
+                    //get the parameters for map resource ID, center point, scale
                     var scale = document.getElementById("txtScale");
                     var centerPoint = document.getElementById("txtCenterPoint");
                     var mapSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
+
+                    //pass the parameters through the URL query string
                     var url="performanceReport_GetResult.php";
 
-                    url+="?scale="+encodeURIComponent(scale.value);
-                    url+="&centerPoint="+encodeURIComponent(centerPoint.value);
-                    url+="&mapDefinition="+encodeURIComponent(mapSelector.value);
-                    url+="&sid="+Math.random();
-                    xmlHttp.onreadystatechange=StateChanged;
+                    url+= "?scale=" + encodeURIComponent(RemoveSpace(scale.value));
+                    url+= "&centerPoint=" + encodeURIComponent(RemoveSpace(centerPoint.value));
+                    url+= "&mapDefinition=" + encodeURIComponent(mapSelector.value);
+                    url+= "&imageWidth=" + imageWidth;
+                    url+= "&imageHeight=" + imageHeight;
+                    url+= "&sid="+Math.random();
+
+                    //send the ajax request
+                    xmlHttp.onreadystatechange = StateChanged;
                     xmlHttp.open("POST",url,true);
                     xmlHttp.send(null);
                 }
@@ -1129,44 +1330,108 @@
                     if ((4 == xmlHttp.readyState || "complete" == xmlHttp.readyState)&& 200 == xmlHttp.status)
                     {
                         var profileResult = document.getElementById("resultsTab");
-                        profileResult.innerHTML=xmlHttp.responseText;
+                        profileResult.innerHTML = xmlHttp.responseText;
 
                         var btnClear = document.getElementById("btnClearSpan");
-                        btnClear.style.display="inline";
+                        btnClear.style.display = "inline";
 
                         var loadingImg = document.getElementById("ajax_loading_img");
-                        loadingImg.style.display="none";
+                        loadingImg.style.display = "none";
                         
                         CollapseSettingTab();
                         ExpandResultsTab();
                         SetRunButtonState(true);
 
-                        // the js in the ajax returned content will not be executed and recognized,
-                        // so we get the js content and append it to the <head>
-                        if(document.getElementById('layerDetailsJsArray'))
+                        SetLayerJsArray();
+                        SetRecentSettingJsArray();
+
+                        SetRecentSettingsContent();
+
+                        SaveLastRunSettings();
+                    }
+                }
+
+                // the js in the ajax returned content will not be executed and recognized,
+                // so we get the js content and append it to the <head>
+                function SetLayerJsArray()
+                {
+                    var tempLayersJsArray = document.getElementById("layerDetailsJsArray");
+                    if(tempLayersJsArray)
+                    {
+                        //get js content in the hidden span
+                        var innerScript = tempLayersJsArray.innerHTML;
+                        innerScript = innerScript.replace(/\\n/,'');
+
+                        //check to remove the script if it already exists
+                        var insertScript = document.getElementById("layerDetailsJs");
+                        if(insertScript)
                         {
-                            //get js content in the hidden span
-                            var innerScript = document.getElementById('layerDetailsJsArray').innerHTML;
-                            innerScript=innerScript.replace(/\\n/,'');
+                            document.getElementsByTagName("head").item(0).removeChild(insertScript);
+                        }
 
-                            //check to remove the script if it already exists
-                            var insertScript = document.getElementById("layerDetailsJs");
-                            if(insertScript)
-                            {
-                                document.getElementsByTagName("head").item(0).removeChild(insertScript);
-                            }
+                        //every new execute should generate new js array data
+                        insertScript = document.createElement("script");
+                        insertScript.type = "text/javascript";
+                        insertScript.id = "layerDetailsJs";
+                        insertScript.text=innerScript;
 
-                            //every new execute should generate new js array data
-                            insertScript = document.createElement("script");
-                            insertScript.type = "text/javascript";
-                            insertScript.id = "layerDetailsJs";
-                            insertScript.text=innerScript;
+                        document.getElementsByTagName("head").item(0).appendChild(insertScript);
+                        tempLayersJsArray.parentNode.removeChild(tempLayersJsArray);
+                    }
+                }
 
-                            document.getElementsByTagName("head").item(0).appendChild(insertScript);
+                function SetRecentSettingJsArray()
+                {
+                    var tempSettingJsArray = document.getElementById("tempRecentSettingsJsArray");
+
+                    if(tempSettingJsArray)
+                    {
+                        //get js content in the hidden span
+                        var innerScript = tempSettingJsArray.innerHTML;
+                        innerScript = innerScript.replace(/\\n/,'');
+
+                        //check to remove the script if it already exists
+                        var insertScript = document.getElementById("recentSettingsJs");
+                        if(insertScript)
+                        {
+                            document.getElementsByTagName("head").item(0).removeChild(insertScript);
                         }
+
+                        //every new execute should generate new js array data
+                        insertScript = document.createElement("script");
+                        insertScript.type = "text/javascript";
+                        insertScript.id = "recentSettingsJs";
+                        insertScript.text = innerScript;
+
+                        document.getElementsByTagName("head").item(0).appendChild(insertScript);
+
+                        tempSettingJsArray.parentNode.removeChild(tempSettingJsArray);
                     }
                 }
-                
+
+                function SetRecentSettingsContent()
+                {
+                    //remove the layer detail info if it already exist
+                    var tempRecentSettings = document.getElementById("tempRecentSettingDiv");
+                    var settingsTab= document.getElementById("settingsDiv");
+                    var settingsContentDiv = document.getElementById("recentSettingsDiv");
+
+                    if (settingsContentDiv)
+                    {
+                        settingsContentDiv.parentNode.removeChild(settingsContentDiv);
+                    }
+
+                    settingsContentDiv = document.createElement("div");
+                    settingsContentDiv.id = "recentSettingsDiv";
+                    settingsContentDiv.innerHTML = tempRecentSettings.innerHTML;
+
+                    if (tempRecentSettings)
+                    {
+                        tempRecentSettings.parentNode.removeChild(tempRecentSettings);
+                    }
+
+                    settingsTab.appendChild(settingsContentDiv);
+                }
                 //End AJAX part
 
                 function ExportCSV()
@@ -1186,9 +1451,9 @@
                     //Also removes any validation messages that are visible.
                     var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
 
-                    if(mapDefinitonSelector.selectedIndex>=0)
+                    if(mapDefinitonSelector.selectedIndex >= 0)
                     {
-                        mapDefinitonSelector.selectedIndex=-1;
+                        mapDefinitonSelector.selectedIndex = -1;
                         //change the selectedIndex valule by the js will not fire the event "onchange",
                         //so we manually do it.
                         MapResoucesNameSelectChange();
@@ -1203,21 +1468,6 @@
                     SetRunButtonState(false);
                 }
 
-                function ClearWrnMsg()
-                {
-                    var scale = document.getElementById("txtScale");
-                    scale.className="";
-
-                    var centerPoint = document.getElementById("txtCenterPoint");
-                    centerPoint.className="";
-
-                    var scaleWarnMsg = document.getElementById("scaleWarnMessage");
-                    scaleWarnMsg.innerHTML = "";
-
-                    var centerPointWarnMsg = document.getElementById("centerPointWarnMessage");
-                    centerPointWarnMsg.innerHTML = "";
-                }
-
                 function SetRunButtonState(visible)
                 {                 
                     var runButton = document.getElementById("runBtn");
@@ -1397,7 +1647,7 @@
 
                         //get the content need to be sorted into a 2-D array
                         rowArray = [];
-                        //TODO: it has problem under IE9 quirks mode, will fix it in part 3
+                        //TODO:Multiple Browsers:It has problem under IE9 quirks mode, will fix it in part 3
                         colIndex = headerColumn.attributes["columnindex"].value-1;
                         rows = layersTBody.rows;
                         var j = 0;
@@ -1407,7 +1657,7 @@
                         }
 
                         //only the second column needs to be sorted by numeric, others are all by alpha
-                        if(1==colIndex)
+                        if(1 == colIndex)
                         {
                             rowArray.sort(SortLayers.sortByNumeric);
                         }
@@ -1515,6 +1765,109 @@
                     }
                 }
 
+                //recent Settings
+                window.onload = LoadRecentSettings;
+
+                function LoadRecentSettings()
+                {
+                    var tempSettingJs = document.getElementById("recentSettingsJsArray");
+
+                    if(tempSettingJs)
+                    {
+                        //get js content in the hidden span
+                        var innerScript = tempSettingJs.innerHTML;
+                        innerScript = innerScript.replace(/\\n/,'');
+
+                        //check to remove the script if it already exists
+                        var insertScript = document.getElementById("recentSettingsJs");
+                        if(insertScript)
+                        {
+                            document.getElementsByTagName("head").item(0).removeChild(insertScript);
+                        }
+
+                        //every new execute should generate new js array data
+                        insertScript = document.createElement("script");
+                        insertScript.type = "text/javascript";
+                        insertScript.id = "recentSettingsJs";
+                        insertScript.text = innerScript;
+
+                        document.getElementsByTagName("head").item(0).appendChild(insertScript);
+
+                        tempSettingJs.parentNode.removeChild(tempSettingJs);
+                    }
+
+                    SetSettingsWithCookie();
+                }
+
+                function SetSettingsWithCookie()
+                {
+                    var mapIdCookie = document.getElementById("cookieMapId");
+                    var centerPointCookie = document.getElementById("cookieCenterPoint");
+                    var scaleCookie = document.getElementById("cookieScale");
+
+                    if(mapIdCookie)
+                    {
+                        var centerPoint = document.getElementById("txtCenterPoint");
+                        centerPoint.value = centerPointCookie.value;
+
+                        var scaleInput = document.getElementById("txtScale");
+                        scaleInput.value = FormatNumber(scaleCookie.value,2);
+
+                        var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
+                        mapDefinitonSelector.value = Trim(mapIdCookie.value);
+
+                        var tipDiv = document.getElementById("mapResourceNameTip");
+                        tipDiv.innerHTML = mapDefinitonSelector.value;
+
+                        var settingsBtn = document.getElementById("mapViewerBtn");
+                        centerPoint.removeAttribute("disabled");
+                        scaleInput.removeAttribute("disabled");
+                        settingsBtn.removeAttribute("disabled");
+                        SetRunButtonState(true);
+                    }
+                }
+
+                function RecentSettingClicked(settingId)
+                {
+                    var settingsCount = recentSettings.length;
+                    var selectSetting = null;
+
+                    var i = 0;
+                    for(; i < settingsCount; i++)
+                    {
+                        if( Trim(settingId) == Trim(recentSettings[i][0]) )
+                        {
+                            selectSetting = recentSettings[i];
+                            break;
+                        }
+                    }
+
+                    //TODO: Excepions: what if the map is removed
+                    if(null != selectSetting)
+                    {
+                        var centerPoint = document.getElementById("txtCenterPoint");
+                        centerPoint.value = selectSetting[2];
+
+                        var scaleInput = document.getElementById("txtScale");
+                        scaleInput.value = FormatNumber(selectSetting[3],2);
+                        
+                        var mapDefinitonSelector = document.getElementById("mapSelector_DO_NOT_PERSIST");
+                        mapDefinitonSelector.value = Trim(selectSetting[1]);
+
+                        var tipDiv = document.getElementById("mapResourceNameTip");
+                        tipDiv.innerHTML = mapDefinitonSelector.value;
+
+                        var settingsBtn = document.getElementById("mapViewerBtn");
+
+                        centerPoint.removeAttribute("disabled");
+                        scaleInput.removeAttribute("disabled");
+                        settingsBtn.removeAttribute("disabled");
+
+                        SetRunButtonState(true);
+
+                        ShowReportWarningMsg();
+                    }
+                }
             </script>
 
             <div id="settingsTitle">
@@ -1524,12 +1877,23 @@
                          <img src="images/arrow_down.png" alt="down" style="cursor:pointer;"
                               id="settings_CollapseImage_ID" onclick="CollapsibleTabClick('settings_CollapseImage_ID','settingsContent')"/>
                      </td>
-                     <td style=" font-size:18px;  font-weight: bold; text-align: left;"  >
+                     <td style="font-size:18px;  font-weight: bold; text-align: left;"  >
                          <span style="cursor:pointer;" onclick="CollapsibleTabClick('settings_CollapseImage_ID','settingsContent')">Settings</span>
                      </td>
                  </tr>
              </table>
             </div>
+            <?php
+                //get settings in cookie
+                if(isset($_COOKIE['c_mapResourceId'],$_COOKIE['c_centerPoint'],$_COOKIE['c_scale']))
+                {
+                    echo "<span style='display:none;'>";
+                    echo '<input type="hidden" id="cookieMapId" value="'.$_COOKIE['c_mapResourceId'].'"/>';
+                    echo '<input type="hidden" id="cookieCenterPoint" value="'.$_COOKIE['c_centerPoint'].'"/>';
+                    echo '<input type="hidden" id="cookieScale" value="'.$_COOKIE['c_scale'].'"/>';
+                    echo "</span>";
+                }
+            ?>
             <div id="settingsContent">
                 <table style="width:100%;">
                     <tr>
@@ -1574,6 +1938,9 @@
                                                                 </div>
                                                                 <div id="selectMapResourceWarningMessage" style="color:#F03136;">
                                                                 </div>
+                                                                <input type="hidden" id="lastRunMapId" value=""/>
+                                                                <input type="hidden" id="lastRunCenterPoint" value=""/>
+                                                                <input type="hidden" id="lastRunScale" value=""/>
                                                             </td>
                                                         </tr>
                                                     </table>
@@ -1599,8 +1966,9 @@
                                                                             Select a Center Point and Map Scale
                                                                             </span>
                                                                         </td>
-                                                                        <td style=" text-align: right;border-bottom:1px solid #000000;">
+                                                                        <td style=" text-align: right;border-bottom:1px solid #000000; cursor: default;">
                                                                             <img alt="Close" src="images/close.png" onclick="CloseMapViewer();"/>
+                                                                            <input type="text" id="mapViewerAutoFocusTxt" style="width:0px; height:0px; border: none; cursor:default;" onKeyUp="MapViewerKeyUp(event);"/>
                                                                         </td>
                                                                     </tr>
                                                                     <tr>
@@ -1610,8 +1978,14 @@
                                                                             </iframe>
                                                                         </td>
                                                                     </tr>
-                                                                </table> 
+                                                                </table>
                                                             </div>
+                                                            <!--System should load map by the previous center point and scale-->
+                                                            <!--if this map was opened by 'Select Settings' before-->
+                                                            <!--So these inputs are used to save the settings of last open-->
+                                                            <input type="hidden" id="mapViewerLastOpenMapId" value=""/>
+                                                            <input type="hidden" id="mapViewerLastOpenCenterPoint" value=""/>
+                                                            <input type="hidden" id="mapViewerLastOpenScale" value=""/>
                                                         </td>
                                                     </tr>
                                                     <tr>
@@ -1646,8 +2020,8 @@
                                         </td>
                                     </tr>
                                     <tr>
-                                        <td style=" padding-top: 80px;">
-                                            <table>
+                                        <td style="padding-top: 80px;">
+                                            <table style="margin: 0px; padding: 0px;" cellspacing="0" cellpadding="0">
                                                 <tr>
                                                     <td style="padding-right:5px;">
                                                         <input id="runBtn" type="button" value="Run" style="width:80px; font-weight: bold;height: 28px;"
@@ -1670,58 +2044,33 @@
                                     </tr>
                                     <tr>
                                         <td>
-                                            <div id="ResultNotMatchWrn"
-                                                 style="border: 3px solid #CCCCCC;background: #FFFEBB url('images/warning.png') no-repeat left top;padding:0px 0px 10px 20px; margin-top: 10px;display: none;">
+                                            <div id="ResultNotMatchWrn" >
                                                 <span style="font-size:12pt; font-weight: bold;">
                                                     The performance report results no longer match the settings found in Steps 1 and 2.
                                                 </span>
-                                                <br/>
-                                                Return the settings found in Steps 1 and 2 to the previous settings or run a new performance report.
+                                                <p style="padding-left: 3px; margin-bottom: 8px; margin-top: 6px">
+                                                    Return the settings found in Steps 1 and 2 to the previous settings or run a new performance report.
+                                                </p>
                                             </div>
                                         </td>
                                     </tr>
                                 </table>
                             </div>
                         </td>
-                        <td style=" vertical-align: top; width: 30%;">
-                            <h2>Recent Settings</h2>
-                            <table style="padding: 5px;">
-                                <tr>
-                                    <td>
-                                        CEVEK
-                                        <br>
-                                        MAY 12,2012&nbsp;&nbsp;&nbsp;&nbsp;11:35:52
-                                    </td>
-                                </tr>
-                                <tr>
-                                    <td style=" background-color: #EEEEEE;">
-                                        CEVEK
-                                        <br>
-                                        MAY 12,2012&nbsp;&nbsp;&nbsp;&nbsp;11:35:52
-                                    </td>
-                                </tr>
-                                <tr>
-                                    <td>
-                                        CEVEK
-                                        <br>
-                                        MAY 12,2012&nbsp;&nbsp;&nbsp;&nbsp;11:35:52
-                                    </td>
-                                </tr>
-                                <tr>
-                                    <td style=" background-color: #EEEEEE;">
-                                        CEVEK
-                                        <br>
-                                        MAY 12,2012&nbsp;&nbsp;&nbsp;&nbsp;11:35:52
-                                    </td>
-                                </tr>
-                                <tr>
-                                    <td>
-                                        CEVEK
-                                        <br>
-                                        MAY 12,2012&nbsp;&nbsp;&nbsp;&nbsp;11:35:52
-                                    </td>
-                                </tr>
-                            </table>
+                        <td style=" vertical-align: top; width: 30%; padding-left: 15px;">
+                            <span id="recentSettingsJsArray" style="display:none;">
+                                <?php
+                                    $displayManager->OutputSettingsJsArray($recentSettings->recentSettings);
+                                ?>
+                            </span>
+                            <div style="font-size:18px;  font-weight: bold; text-align: left;">Recent Settings</div>
+                            <div style="border: 1px solid #CCCCCC; width: 100%; margin-top: 15px;" id="settingsDiv">
+                                <div id="recentSettingsDiv">
+                                    <?php
+                                        $displayManager->OutputRecentSettings($recentSettings->recentSettings);
+                                    ?>
+                                </div>
+                            </div>
                         </td>
                     </tr>
                 </table>

Modified: trunk/MgDev/Web/src/mapadmin/performanceReport_Export.php
===================================================================
--- trunk/MgDev/Web/src/mapadmin/performanceReport_Export.php	2011-09-22 01:57:08 UTC (rev 6144)
+++ trunk/MgDev/Web/src/mapadmin/performanceReport_Export.php	2011-09-22 06:13:21 UTC (rev 6145)
@@ -12,15 +12,30 @@
     // Define Local values
     $mapProfileResult=new MapProfileResult();
 
+    function ReplaceCSVSpecialChar($value)
+    {
+        $newValue = str_replace("\"", "\"\"", $value);
+        return "\"".$newValue."\"";
+    }
+
     function GetProfilingResults()
     {
-        global $mapProfileResult;
-        $resultSource=new DOMDocument();
-        //As the profiling API is not finished, now we just use a temp xml file to simulate it.
-        //we will change it in part 3.
-        $resultSource->load("profilingmapxml/profileResults.xml");
-        $mapProfileResult->ReadFromXML($resultSource);
-        $mapProfileResult->GetBaseLayerCount();
+        $profilingResultFile = $_SESSION["ProfilingResultFile"];
+
+        if (isset($profilingResultFile))
+        {
+            global $mapProfileResult;
+            $resultSource = new DOMDocument();
+            $resultSource->load($profilingResultFile);
+            $mapProfileResult->ReadFromXML($resultSource);
+            $mapProfileResult->GetBaseLayerCount();
+        }
+        else
+        {
+            //TODO: Excepions: more user friendly hint
+            //should give some warning message about "No profiling result file found, please re-generate it!"
+            throw $e;
+        }
     }
 
     GetProfilingResults();
@@ -31,7 +46,7 @@
     //output the basic information of the map resource
     //get the extent display string
     list($x1, $y1, $x2, $y2) = explode(",", $mapProfileResult->MapProfileData->DataExtents);
-    $extents= '"X1:' . $x1 . '    Y1:' . $y1.'    X2:' . $x2 . '    Y2:' . $y2.'"';
+    $extents= '"MinX:' . $x1 . '    MinY:' . $y1.'    MaxX:' . $x2 . '    MaxY:' . $y2.'"';
 
     //get the scale display string
     $scale= "1:" . number_format($mapProfileResult->MapProfileData->Scale,0,"."," ");
@@ -47,7 +62,7 @@
     echo $mapProfileResult->MapProfileData->ImageFormat,"\n";
     echo '"Center Point",'.$centerPoint.',Layers,';
     echo $mapProfileResult->MapProfileData->LayerCount,"\n";
-    echo '"Coordinate System",'.$mapProfileResult->MapProfileData->CoordinateSystem;
+    echo '"Coordinate System",'.ReplaceCSVSpecialChar($mapProfileResult->MapProfileData->CoordinateSystem);
     echo ',"Render Type",'.$mapProfileResult->MapProfileData->RenderType,"\n";
     echo 'Scale,'.$scale,"\n";
 
@@ -84,10 +99,10 @@
     {
         echo '"'.$layerProfileData->LayerName.'",' ;
         echo '"'.$layerProfileData->TotalRenderTime.' ms",' ;
-        echo '"'.$layerProfileData->FeatureClass .'",';
-        echo '"'.$layerProfileData->CoordinateSystem .'",';
+        echo ReplaceCSVSpecialChar($layerProfileData->FeatureClass) .',';
+        echo ReplaceCSVSpecialChar($layerProfileData->CoordinateSystem) .',';
         echo '"'.$layerProfileData->LayerType.'",' ;
-        echo '"'.$layerProfileData->Filters.'",' ;
+        echo ReplaceCSVSpecialChar($layerProfileData->Filters).',' ;
         echo '"'.$layerProfileData->ScaleRange.'"' ;
         echo "\n";
     }

Modified: trunk/MgDev/Web/src/mapadmin/performanceReport_GetResult.php
===================================================================
--- trunk/MgDev/Web/src/mapadmin/performanceReport_GetResult.php	2011-09-22 01:57:08 UTC (rev 6144)
+++ trunk/MgDev/Web/src/mapadmin/performanceReport_GetResult.php	2011-09-22 06:13:21 UTC (rev 6145)
@@ -15,24 +15,161 @@
     // Define Local values
     $confirmationMsg = "";
     $errorMsg = "";
-    $mapProfileResult=new MapProfileResult();
-    $displayManager= new DisplayProfileResultManager();
+    $mapProfileResult = new MapProfileResult();
+    $displayManager = new DisplayProfileResultManager();
+    $mapResourceId = $_REQUEST["mapDefinition"];
+    $centerPoint = $_REQUEST["centerPoint"];
+    $scale = $_REQUEST["scale"];
+    $clientWidth = $_REQUEST["imageWidth"];
+    $clientHeigth = $_REQUEST["imageHeight"];
 
+    //get the background color of the given map resource id
+    function GetBackGroundColor($resourceID)
+    {
+        $bgc;
+
+        try
+        {
+            //site and userInfo are saved in the session
+            global $userInfo;
+            $mapResourceContent = "";
+
+            //connect to the site and get a resource service instance
+            $siteConn = new MgSiteConnection();
+            $siteConn->Open($userInfo);
+            $resourceService = $siteConn->CreateService(MgServiceType::ResourceService);
+            //get the map resource content from the server
+            $mgResourceID = new MgResourceIdentifier($resourceID);
+            $byteReader = $resourceService->GetResourceContent($mgResourceID);
+
+            //read the content into a string
+            $chunk = "";
+            do
+            {
+                $chunkSize = $byteReader->Read($chunk, 4096);
+                $mapResourceContent = $mapResourceContent . $chunk;
+            } while ($chunkSize != 0);
+
+            //parse the xml data use DOMDocument
+            $resourceContent = new DOMDocument();
+            $resourceContent->loadXML($mapResourceContent);
+
+            //get all the elements with the element name "BackgroundColor"
+            $backgroundColor = $resourceContent->documentElement->getElementsByTagName("BackgroundColor");
+
+            //if there's no "BackgroundColor" node
+            if(0 == $backgroundColor->length)
+            {
+                $bgc = new MgColor(255, 255, 255, 255);
+            }
+            else
+            {
+                //the background color is saved as hex format string
+                $tempBackgroundColor = $backgroundColor->item(0)->nodeValue;
+                $red    = hexdec(substr($tempBackgroundColor, 0,2));
+                $green  = hexdec(substr($tempBackgroundColor, 2,2));
+                $blue   = hexdec(substr($tempBackgroundColor, 4,2));
+                $alpha  = hexdec(substr($tempBackgroundColor, 6,2));
+
+                $bgc = new MgColor($red, $green, $blue, $alpha);
+            }
+        }
+        catch (Exception $exc)
+        {
+            $errorMsg = $exc->getMessage();
+            $bgc = new MgColor(255, 255, 255, 255);
+        }
+
+        return $bgc;
+    }
+
     function GetProfilingResults()
     {
+        //profiling map parameters
+        global $mapResourceId;
         global $mapProfileResult;
-        $resultSource=new DOMDocument();
-        //As the profiling API is not finished, now we just use a temp xml file to simulate it.
-        //we will change it in part 3.
-        $resultSource->load("profilingmapxml/profileResults.xml");
+        global $scale;
+        global $centerPoint;
+        global $clientWidth;
+        global $clientHeigth;
+
+        list($x, $y) = explode("*", $centerPoint);
+        $x = trim($x);
+        $y = trim($y);
+
+        $geometryFactory = new MgGeometryFactory();
+        //[centerPoint]
+        $coordNewCenter = $geometryFactory->CreateCoordinateXY($x,$y);
+
+        //[backgroundColor]
+        $bgc = GetBackGroundColor($mapResourceId);
+
+        //[imageFormat]
+        $imageFormat = "PNG";
+        
+        //userInfo are saved in the session
+        global $userInfo;
+
+        //connect to the site and get a resource service instance
+        //create profiling service too
+        $siteConn = new MgSiteConnection();
+        $siteConn->Open($userInfo);
+
+        $resourceService = $siteConn->CreateService(MgServiceType::ResourceService);
+        $profilingService = $siteConn->CreateService(MgServiceType::ProfilingService);
+
+        //the profiling result is saved as xml file, the file name is unique
+        //the format is like this "YYYYMMDDHHMMSS10"
+        $newXmlFileId = date("YmdHis") . rand(10, 99);
+
+        $resourceID = new MgResourceIdentifier($mapResourceId);
+        // Get a runtime map from a map definition
+        $map = new MgMap();
+        $map->Create($resourceService, $resourceID, $newXmlFileId);
+
+        //get the profiling map result
+        $byteReader = $profilingService->ProfileRenderMap($map, NULL, $coordNewCenter, $scale, $clientWidth, $clientHeigth, $bgc, $imageFormat, false);
+
+        //read the content into a string
+        $profilingResourceContent = "";
+        $chunk = "";
+        do
+        {
+            $chunkSize = $byteReader->Read($chunk, 4096);
+            $profilingResourceContent = $profilingResourceContent . $chunk;
+        } while ($chunkSize != 0);
+
+        //save the file on the server
+        $newXmlFileName = "profilingmapxml/".$newXmlFileId.".xml";
+        $fp = fopen($newXmlFileName, "w");
+        fwrite($fp, $profilingResourceContent);
+        fclose($fp);
+
+        //put the file name in the session
+        $_SESSION["ProfilingResultFile"] = $newXmlFileName;
+
+        //read the result into the DOM
+        $resultSource = new DOMDocument();
+        $resultSource->load($newXmlFileName);
         $mapProfileResult->ReadFromXML($resultSource);
         $mapProfileResult->GetBaseLayerCount();
     }
 
     GetProfilingResults();
 
-    $displayManager->mapProfileResult=$mapProfileResult;
+    $displayManager->mapProfileResult = $mapProfileResult;
 
+    $recentSettings = new RecentSettings();
+
+    $recentSettings->SaveRecentSettings($mapResourceId,$centerPoint,$scale);
+    
+    //set cookie
+    //save the recent setting in the cookie, so next time the user open 
+    //the page will restore the last time setting
+    //it will expire in 1 month
+    setcookie("c_mapResourceId", $mapResourceId, time()+60*60*24*30);
+    setcookie("c_centerPoint", $centerPoint, time()+60*60*24*30);
+    setcookie("c_scale", $scale, time()+60*60*24*30);
 }
 catch ( MgException $e )
 {
@@ -66,9 +203,9 @@
                 <table style="width:100%;" class="mapDefinitionResultTableStyle">
                     <tr>
                         <td style="width:22%; font-weight: bold;">Resource Name:</td>
-                        <td style="width:32%;">
+                        <td style="width:32%; font-weight: bold;">
                             <?php
-                                $displayManager->OutputMapResourceNameWithToolTip($mapProfileResult->MapProfileData->MapResourceId);
+                                $displayManager->OutputMapResourceNameWithToolTip($mapProfileResult->MapProfileData->MapResourceId,false);
                             ?>
                         </td>
                         <td style="width:18%;font-weight: bold;">
@@ -76,10 +213,36 @@
                         </td>
                         <td style="width:27%;">
                             <?php
+                                //Data extents can be displayed in many different ways depending on the coordinate system used.
+                                //Scientific E Notation is used to create a shorter and more managable string length.
+                                function FormatDataExtents($value)
+                                {
+                                    if(strlen($value) > 10)
+                                    {
+                                        //numfmt_create("en", NumberFormatter::SCIENTIFIC, "");
+                                        //$fmt = new NumberFormatter("en", NumberFormatter::SCIENTIFIC, "");
+                                        //$value = $fmt->format($value);
+
+                                        $pos = strpos($value, ".");
+
+                                        if( ( strlen($value) - $pos ) > 7)
+                                        {
+                                           $value = number_format($value,4);
+                                        }
+                                    }
+                                    else
+                                    {
+                                        $value = number_format($value,4);
+                                    }
+
+                                    return $value;
+                                }
+
                                 list($x1, $y1, $x2, $y2) = explode(",", $mapProfileResult->MapProfileData->DataExtents);
-                                echo "X:" . $x1 . "&nbsp;&nbsp;&nbsp;Y:" . $y1;
+
+                                echo "X:" . FormatDataExtents($x1) . "&nbsp;&nbsp;&nbsp;Y:" . FormatDataExtents($y1);
                                 echo "<br/>";
-                                echo "X:" . $x2 . "&nbsp;&nbsp;&nbsp;Y:" . $y2;
+                                echo "X:" . FormatDataExtents($x2) . "&nbsp;&nbsp;&nbsp;Y:" . FormatDataExtents($y2);
                             ?>
                         </td>
                     </tr>
@@ -101,7 +264,7 @@
                         <td style=" font-weight: bold;">Center Point:</td>
                         <td>
                             <?php
-                                list($x, $y) = explode("*", $_REQUEST["centerPoint"]);
+                                list($x, $y) = explode("*", $centerPoint);
                                 $x = trim($x);
                                 $y = trim($y);
                                 echo "X:&nbsp;" . $x;
@@ -119,9 +282,12 @@
                     <tr>
                         <td style=" font-weight: bold;">Coordinate System:</td>
                         <td>
+                            <span style="width:50px; overflow:hidden;">
                             <?php
-                                echo $mapProfileResult->MapProfileData->CoordinateSystem;
+                                //TODO: Waiting:Test on new build
+                                echo substr($mapProfileResult->MapProfileData->CoordinateSystem,0,25);
                             ?>
+                            </span>
                         </td>
                         <td  style=" font-weight: bold;">Renderer Type:</td>
                         <td>
@@ -148,7 +314,7 @@
         <td colspan="2" style="padding-top:20px; padding-left: 15px;">
             <?php
                 echo "<span>";
-                echo "Total Generation Time:&nbsp;" . $mapProfileResult->MapProfileData->TotalMapRenderTime . "&nbsp;ms";
+                echo "Total Generation Time:&nbsp;" . number_format($mapProfileResult->MapProfileData->TotalMapRenderTime,2) . "&nbsp;ms";
                 echo "</span>";
             ?>
         </td>
@@ -161,7 +327,7 @@
                         $displayManager->OutputMapRenderTimeGraph();
                     ?>
                     <tr style="height:35px;">
-                        <td colspan="4" style=" text-align: center;">
+                        <td colspan="5" style=" text-align: center;">
                             <span style="width: 11px; height: 11px; background-color:#E4C7AE; margin-right: 5px;">
                                 &nbsp;&nbsp;&nbsp;&nbsp;</span>
                             <span style=" font-size: small; margin-right: 20px;">Layers</span>
@@ -225,5 +391,15 @@
         </tr>
     </table>
 </div>
+<div id="tempRecentSettingDiv" style="display:none;">
+    <?php
+        $recentSettings->GetRecentSettings();
+        $displayManager->OutputRecentSettings($recentSettings->recentSettings);
+    ?>
+</div>
+<span id="tempRecentSettingsJsArray" style="display:none;">
+    <?php
+        $displayManager->OutputSettingsJsArray($recentSettings->recentSettings);
+    ?>
+</span>
 
-

Modified: trunk/MgDev/Web/src/mapadmin/performanceReport_MapViewer.php
===================================================================
--- trunk/MgDev/Web/src/mapadmin/performanceReport_MapViewer.php	2011-09-22 01:57:08 UTC (rev 6144)
+++ trunk/MgDev/Web/src/mapadmin/performanceReport_MapViewer.php	2011-09-22 06:13:21 UTC (rev 6145)
@@ -36,8 +36,9 @@
     $content_byteReader = $content_byteSource->GetReader();
 
     $resourceSrvc->SetResource($webLayOutId, $content_byteReader, null);
-    
-    $webLayoutUrl="../mapviewerajax/?WEBLAYOUT=".urlencode($webLayoutName)."&LOCALE=en";
 
+    //pass the seesion ID with the url, so when the map viewer is opened, there is no need to re-enter the password
+    $webLayoutUrl="../mapviewerajax/?WEBLAYOUT=".urlencode($webLayoutName)."&LOCALE=en&SESSION=".$site->GetCurrentSession();
+
     header('Location:'. $webLayoutUrl);
 ?>

Modified: trunk/MgDev/Web/src/mapadmin/resizablepagecomponents.php
===================================================================
--- trunk/MgDev/Web/src/mapadmin/resizablepagecomponents.php	2011-09-22 01:57:08 UTC (rev 6144)
+++ trunk/MgDev/Web/src/mapadmin/resizablepagecomponents.php	2011-09-22 06:13:21 UTC (rev 6145)
@@ -2166,16 +2166,19 @@
     {
         public $mapProfileResult;
 
-        public function OutputMapDefinitionData()
-        {
-            //TODO: will be implemented in part 3
-        }
-
         //Output the layer profiling information to the webpage as table rows
-        //TODO: will refine in part 3, when there's no data
         public function OutputLayerDefinitionData()
         {
-            $rowNumber=1;
+            $layerCount = count($this->mapProfileResult->LayerProfileData->LayerProfileDataCollection);
+
+            if(0 == $layerCount)
+            {
+                echo "<tr class='odd'><td colspan='5' style='height:150px;text-align:center; vertical-align:middle;font-size:15px;'>The selected map resource does not contain any layers.</td></tr>","\n";
+                return;
+            }
+
+            $rowNumber = 1;
+            $sumofRenderTime = $this->mapProfileResult->LayerProfileData->GetSumOfLayerRenderTime();
             foreach ($this->mapProfileResult->LayerProfileData->LayerProfileDataCollection as $layerProfileData)
             {
                 //set different colors for alternate rows and when mouse move over the row it will change color
@@ -2191,9 +2194,12 @@
                 //output the layer profiling information by each column,
                 //for the render time column, we set the sort key as the original number, which will be used as client sort
                 echo "<td style='width:15%;'>".$layerProfileData->LayerName."</td>","\n";
-                echo "<td style='width:20%;' sortKey='".$layerProfileData->TotalRenderTime."'>".$layerProfileData->TotalRenderTime."&nbsp;ms (15%)</td>","\n";
+                echo "<td style='width:20%;' sortKey='".number_format($layerProfileData->TotalRenderTime,2)."'>".
+                        number_format($layerProfileData->TotalRenderTime,2)."&nbsp;ms&nbsp;(".
+                        $layerProfileData->GetRenderTimePercentage($sumofRenderTime)."%)&nbsp;</td>","\n";
                 echo "<td style='width:25%;'>".$layerProfileData->FeatureClass."</td>","\n";
-                echo "<td style='width:25%;'>".$layerProfileData->CoordinateSystem."</td>","\n";
+                //TODO: Waiting:Test on new build CoordinateSystem Length
+                echo "<td style='width:25%;'>".substr($layerProfileData->CoordinateSystem,0,25)."</td>","\n";
                 echo "<td style='width:15%;'>".$layerProfileData->LayerType."</td>","\n";
                 echo "</tr>","\n";
 
@@ -2206,11 +2212,11 @@
         public function OutputLayerDetailData()
         {
             //get the layer profiling data from the LayerProfileData
-            $layerDetails=$this->mapProfileResult->LayerProfileData->LayerProfileDataCollection;
-            $layerDetailCount=count($layerDetails);
+            $layerDetails = $this->mapProfileResult->LayerProfileData->LayerProfileDataCollection;
+            $layerDetailCount = count($layerDetails);
 
             //if there's no layer, return
-            if($layerDetailCount<=0)
+            if($layerDetailCount <= 0)
             {
                 return;
             }
@@ -2222,9 +2228,17 @@
             $i=0;
             foreach ($layerDetails as $key => $value)
             {
+                // Order of replacement
+                // Processes \r\n's first so they aren't converted twice.
+                $order = array("\r\n", "\n", "\r");
+
+                $str = trim($value->Filters);
+                $replace = "<br/>";
+                $newFilters = str_replace($order, $replace, $str);
+
                 $script = $script." layerDetailValues[".$i."]=new Array(3); ";
                 $script = $script." layerDetailValues[".$i."][0]='".$value->LayerName."'; ";
-                $script = $script." layerDetailValues[".$i."][1]='".$value->Filters."'; ";
+                $script = $script." layerDetailValues[".$i."][1]='".$newFilters."'; ";
                 $script = $script." layerDetailValues[".$i."][2]='".$value->ScaleRange."'; ";
                
                 $i++;
@@ -2239,22 +2253,22 @@
             echo "<tr style='height: 25px;'>","\n";
             
             echo '<td style="width:'.$this->mapProfileResult->MapProfileData->GetLayerRenderPercent() .'%; background-color: #E4C7AE;font-size:80%;">',"\n";
-            echo $this->mapProfileResult->MapProfileData->TotalLayerRenderTime."&nbsp;ms&nbsp;";
+            echo number_format($this->mapProfileResult->MapProfileData->TotalLayerRenderTime,2)."&nbsp;ms&nbsp;";
             echo "(" . $this->mapProfileResult->MapProfileData->GetLayerRenderPercent() . "%)","\n";
             echo '</td>',"\n";
 
             echo '<td style="width: '.$this->mapProfileResult->MapProfileData->GetLabelRenderPercent().'%; background-color: #AECBE4;font-size:80%;">',"\n";
-            echo $this->mapProfileResult->MapProfileData->TotalLabelRenderTime."&nbsp;ms&nbsp;";
+            echo number_format($this->mapProfileResult->MapProfileData->TotalLabelRenderTime,2)."&nbsp;ms&nbsp;";
             echo "(".$this->mapProfileResult->MapProfileData->GetLabelRenderPercent()."%)","\n";
             echo "</td>","\n";
 
             echo '<td style="width: '.$this->mapProfileResult->MapProfileData->GetWartermarkRenderPercent().'%; background-color: #E79661;font-size:80%;">',"\n";
-            echo $this->mapProfileResult->MapProfileData->TotalWatermarkRenderTime."&nbsp;ms&nbsp;";
+            echo number_format($this->mapProfileResult->MapProfileData->TotalWatermarkRenderTime,2)."&nbsp;ms&nbsp;";
             echo "(".$this->mapProfileResult->MapProfileData->GetWartermarkRenderPercent()."%)","\n";
             echo "</td>","\n";
 
             echo '<td style="width: '.$this->mapProfileResult->MapProfileData->GetImageRenderPercent().'%; background-color: #BE76EE;font-size:80%;">',"\n";
-            echo $this->mapProfileResult->MapProfileData->TotalImageRenderTime."&nbsp;ms&nbsp;";
+            echo number_format($this->mapProfileResult->MapProfileData->TotalImageRenderTime,2)."&nbsp;ms&nbsp;";
             echo "(".$this->mapProfileResult->MapProfileData->GetImageRenderPercent()."%)","\n";
             echo "</td>","\n";
 
@@ -2267,19 +2281,88 @@
             echo "</tr>","\n";
         }
 
-        public function OutputMapResourceNameWithToolTip($mapResourceID)
+        public function OutputMapResourceNameWithToolTip($mapResourceID,$IsSetting)
         {
+            $mapResourceID = trim($mapResourceID);
             $tempMapName = strrchr($mapResourceID, '/');
             $tempMapName = substr($tempMapName, 1, strlen($tempMapName) - 15);
-            $toolTipDivId="toolTip_".$tempMapName;
+
+            $toolTipDivId = "toolTip_".rand()."_".$tempMapName;
+
+            if($IsSetting)
+            {
+                $toolTipDivId = "settings_".$toolTipDivId;
+            }
             
             echo '<span onMouseOver="ShowToopTip(this,\''.$toolTipDivId.'\',event);" onmousemove="ShowToopTip(this,\''.$toolTipDivId.'\',event);" onmouseout="HideToolTop(\''.$toolTipDivId.'\');" class="mapNameStyle">';
-            echo "<b>".$tempMapName."</b></span>";
+            echo $tempMapName."</span>";
 
             echo '<div id="'.$toolTipDivId.'" class="hideTooltip">',"\n";
             echo $mapResourceID;
             echo '</div>',"\n";
         }
+
+        public function OutputSettingsJsArray($recentSettings)
+        {
+            $settingsCount = count($recentSettings);
+
+            //if there's no setting, return
+            if($settingsCount <= 0)
+            {
+                return;
+            }
+
+            // create script string to append to content.
+            $script = "var recentSettings = new Array(".$settingsCount.");";
+
+            $i = 0;
+            foreach ($recentSettings as $setting)
+            {
+                $script = $script." recentSettings[".$i."]=new Array(4); ";
+                $script = $script." recentSettings[".$i."][0]='".$setting->SettingId."'; ";
+                $script = $script." recentSettings[".$i."][1]='".$setting->MapResourceId."'; ";
+                $script = $script." recentSettings[".$i."][2]='".$setting->CenterPoint."'; ";
+                $script = $script." recentSettings[".$i."][3]='".$setting->Scale."'; ";
+                $i++;
+            }
+
+            //output to UI
+            echo $script;
+        }
+
+        public function OutputRecentSettings($recentSettings)
+        {
+            for($i = 0; $i < count($recentSettings) && $i < 10; $i++)
+            {
+                $currentSetting = $recentSettings[$i];
+
+                $dTime = new DateTime(trim($currentSetting->ModifyTime));
+
+                echo '<table style="padding: 0px; width: 100%;" cellspacing="0" cellpadding="0">',"\n";
+                echo "<tr style='cursor:pointer;' onClick='RecentSettingClicked(\"".$currentSetting->SettingId."\");'>","\n";
+                if(0 == $i%2)
+                {
+                    echo "<td>","\n";
+                }
+                else
+                {
+                    echo "<td style=' background-color: #EEEEEE;'>","\n";
+                }
+
+                echo "<table style='padding: 3px; width: 100%;'>","\n";
+                echo "<tr>","\n";
+                echo "<td colspan='2' style='font-weight:bold; padding-bottom: 5px;'>","\n";
+                $this->OutputMapResourceNameWithToolTip($currentSetting->MapResourceId,true);
+                echo "</td></tr><tr>","\n";
+                echo "<td style='width:50%;text-align: left;'>","\n";
+                echo $dTime->format("M d,Y");
+                echo "</td>","\n";
+                echo "<td style='width:50%;text-align: right;'>","\n";
+                echo $dTime->format("H:m:s");
+                echo "</td>","\n";
+                echo "</tr></table></td></tr></table>","\n";
+            }
+        }
     }
     
 ?>

Modified: trunk/MgDev/Web/src/mapadmin/serverdatafunctions.php
===================================================================
--- trunk/MgDev/Web/src/mapadmin/serverdatafunctions.php	2011-09-22 01:57:08 UTC (rev 6144)
+++ trunk/MgDev/Web/src/mapadmin/serverdatafunctions.php	2011-09-22 06:13:21 UTC (rev 6145)
@@ -2292,6 +2292,257 @@
         }
     }
 
+
+    //represent on setting of Performance report
+    class RecentSetting
+    {
+        public $SettingId;
+        public $MapResourceId;
+        public $CreateTime;
+        public $ModifyTime;
+        public $CenterPoint;
+        public $Scale;
+    }
+
+    //A class which contains a list of recentSetting
+    //and some methods to manipulate the recent settings
+    class RecentSettings
+    {
+        public $recentSettings;
+
+        public function GetRecentSettings()
+        {
+            $recentSettingsDoc = new DOMDocument();
+            $recentSettingsFile = "profilingmapxml/RecentSettings.xml";
+
+            if(file_exists($recentSettingsFile))
+            {
+                $recentSettingsDoc->load($recentSettingsFile);
+                $settingList = $recentSettingsDoc->documentElement->getElementsByTagName("Setting");
+
+                //only fetch latest 10 records
+                for($i = 0; $i < $settingList->length && $i < 10; $i++)
+                {
+                    $SettingNode = $settingList->item($i);
+                    $recentSetting = new RecentSetting();
+
+                    foreach ($SettingNode->childNodes as $cNode)
+                    {
+                        if(1 == $cNode->nodeType)
+                        {
+                            switch ($cNode->nodeName)
+                            {
+                                case "mapResourceId":
+                                    $recentSetting->MapResourceId = $cNode->nodeValue;
+                                    break;
+                                case "createTime":
+                                    $recentSetting->CreateTime = $cNode->nodeValue;
+                                    break;
+                                case "modifyTime":
+                                    $recentSetting->ModifyTime = $cNode->nodeValue;
+                                    break;
+                                case "centerPoint":
+                                    $recentSetting->CenterPoint = $cNode->nodeValue;
+                                    break;
+                                case "scale":
+                                    $recentSetting->Scale = $cNode->nodeValue;
+                                    break;
+                                default :break;
+                            }
+                        }
+                    }
+
+                    $recentSetting->SettingId = $SettingNode->getAttribute("ID");
+                    $this->recentSettings[$i] = $recentSetting;
+                }
+            }
+        }
+
+        //when a new setting is run, save the setting to the xml file
+        public function SaveRecentSettings($mapResourceId, $centerPoint, $scale)
+        {
+            $mapResourceId = trim($mapResourceId);
+            $centerPoint = trim($centerPoint);
+            $scale = trim($scale);
+            
+            //required parameters are null or empty then ignore this setting
+            //TODO: Excepions: we can ignore this setting, but we need to send signal not to update the original part
+            if( (!isset($mapResourceId,$centerPoint,$scale)) || ("" == trim($mapResourceId)) || ("" == trim($centerPoint)) || ("" == trim($scale)) )
+            {
+                return;
+            }
+
+            $recentSettingsDoc = new DOMDocument();
+            $recentSettingsFile = "profilingmapxml/RecentSettings.xml";
+            $rootElement;
+            $settingElement;
+
+            //get the root element <RecentSettings>
+            //if the file already exists, get the documentElement
+            //if not exists, create new element and append to the DOMDocument
+            if(file_exists($recentSettingsFile))
+            {
+                $recentSettingsDoc->load($recentSettingsFile);
+                $rootElement = $recentSettingsDoc->documentElement;
+                
+                //search the xml doc to see if the same setting is existed
+                $settingElement = $this->GetExistedSetting($rootElement, $mapResourceId, $centerPoint, $scale);
+                
+                if(!isset ($settingElement))
+                {
+                    //if not existed, create the new one
+                    $settingElement = $this->CreateNewSettting($recentSettingsDoc, $mapResourceId, $centerPoint, $scale);
+                }
+                else
+                {
+                    //if existed, update the modify time
+                    $settingElement->getElementsByTagName("modifyTime")->item(0)->nodeValue = date(DATE_W3C);
+                }
+            }
+            else
+            {
+                $rootElement = $recentSettingsDoc->createElement("RecentSettings");
+                $recentSettingsDoc->appendChild($rootElement);
+                
+                $settingElement = $this->CreateNewSettting($recentSettingsDoc, $mapResourceId, $centerPoint, $scale);
+            }
+
+            //add the setting node at the top
+            if($rootElement->hasChildNodes())
+            {
+                $firstSetting = $rootElement->firstChild;
+               
+                //if the found one is the first one, do noting
+                if($settingElement === $firstSetting)
+                {
+                    ;
+                }
+                else
+                {
+                    $firstSetting->parentNode->insertBefore($settingElement, $firstSetting);
+                }
+            }
+            else
+            {
+                $rootElement->appendChild($settingElement);
+            }
+
+            $recentSettingsDoc = $this->DeleteSettings($recentSettingsDoc);
+            //save the setting to the file
+            $recentSettingsDoc->save($recentSettingsFile);
+        }
+        
+        //find the setting that has already existed in the xml file
+        public function GetExistedSetting($rootElement, $mapResourceId, $centerPoint, $scale)
+        {
+            $foundElement = null;
+            $settingList = $rootElement->getElementsByTagName("Setting");
+            
+            foreach($settingList as $settingNode)
+            {
+                $mapIdValue = trim($settingNode->getElementsByTagName("mapResourceId")->item(0)->nodeValue);
+                $centerPointValue = trim($settingNode->getElementsByTagName("centerPoint")->item(0)->nodeValue);
+                $scaleValue = trim($settingNode->getElementsByTagName("scale")->item(0)->nodeValue);
+
+                if( ($mapResourceId == $mapIdValue) && ($centerPoint == $centerPointValue) && ($scale == $scaleValue) )
+                {
+                    $foundElement = $settingNode;
+                    break;
+                }
+            }
+            
+            return $foundElement;
+        }
+        
+        //create new element for the setting 
+        public function CreateNewSettting($recentSettingsDoc, $mapResourceId, $centerPoint, $scale)
+        {
+            $newSettingElement = $recentSettingsDoc->createElement("Setting");
+            //use settingId to identify the unique setting
+            $settingId = date("YmdHis") . rand(10, 99);
+            $newSettingElement->setAttribute("ID", $settingId);
+
+            $mapResourceIdElement = $recentSettingsDoc->createElement("mapResourceId", $mapResourceId);
+            $newSettingElement->appendChild($mapResourceIdElement);
+
+            $centerPointElement = $recentSettingsDoc->createElement("centerPoint", $centerPoint);
+            $newSettingElement->appendChild($centerPointElement);
+
+            $scaleElement = $recentSettingsDoc->createElement("scale", $scale);
+            $newSettingElement->appendChild($scaleElement);
+
+            $createDate = date(DATE_W3C);
+            $createTimeElement = $recentSettingsDoc->createElement("modifyTime", $createDate);
+            $newSettingElement->appendChild($createTimeElement);
+
+            //when create new setting, the create Time and the modify time is the same
+            $modifyTimeElement = $recentSettingsDoc->createElement("createTime", $createDate);
+            $newSettingElement->appendChild($modifyTimeElement);
+            
+            return $newSettingElement;
+        }
+
+        //To avoid the recent file to be too large, we will remove the old settings 
+        //if the total records exceed 1000
+        public function DeleteSettings($recentSettingsDoc)
+        {
+            $newXMLDoc;
+            $settingElements = $recentSettingsDoc->documentElement->getElementsByTagName("Setting");
+            $settingCount = $settingElements->length;
+            
+            if($settingCount >= 1000)
+            {
+                $newXMLDoc = new DOMDocument();
+                $rootElement1 = $newXMLDoc->createElement("RecentSettings");
+                $newXMLDoc->appendChild($rootElement1);
+                
+                for($i = 0; $i < 10; $i++)
+                {
+                    $tempNode = $this->CopyNode($newXMLDoc,$settingElements->item($i));
+                    $rootElement1->appendChild($tempNode);
+                }
+            }
+            else
+            {
+                $newXMLDoc = $recentSettingsDoc;
+            }
+            
+            return $newXMLDoc;
+        }
+
+        //copy the existed nodes to the new xml document
+        private function CopyNode($doc, $oldNode)
+        {
+            $nd = $doc->createElement("Setting");
+            
+            $settingIdValue = trim( $oldNode->getAttribute("ID") );
+            $mapIdValue = trim( $oldNode->getElementsByTagName("mapResourceId")->item(0)->nodeValue );
+            $centerPointValue = trim( $oldNode->getElementsByTagName("centerPoint")->item(0)->nodeValue );
+            $scaleValue = trim( $oldNode->getElementsByTagName("scale")->item(0)->nodeValue );
+            $createTimeValue = trim( $oldNode->getElementsByTagName("createTime")->item(0)->nodeValue );
+            $modifyTimeValue = trim( $oldNode->getElementsByTagName("modifyTime")->item(0)->nodeValue );
+
+            $nd->setAttribute("ID", $settingIdValue);
+
+            $mapResourceIdElement = $doc->createElement("mapResourceId", $mapIdValue);
+            $nd->appendChild($mapResourceIdElement);
+
+            $centerPointElement = $doc->createElement("centerPoint", $centerPointValue);
+            $nd->appendChild($centerPointElement);
+
+            $scaleElement = $doc->createElement("scale", $scaleValue);
+            $nd->appendChild($scaleElement);
+
+            $createTimeElement = $doc->createElement("modifyTime", $createTimeValue);
+            $nd->appendChild($createTimeElement);
+
+            $modifyTimeElement = $doc->createElement("createTime", $modifyTimeValue);
+            $nd->appendChild($modifyTimeElement);
+            
+            return $nd;
+         }
+    }
+
     class LayerDefinitionProfileData
     {
         public $LayerName;
@@ -2302,11 +2553,39 @@
         public $LayerType;
         public $Filters;
         public $ScaleRange;
+
+        public function GetRenderTimePercentage($sumofRenderTime)
+        {
+            $percentage = 0.0;
+
+            if($sumofRenderTime > 0.0)
+            {
+                $percentage = $this->TotalRenderTime/$sumofRenderTime;
+            }
+
+            return number_format($percentage*100,1);
+        }
     }
 
     class LayerDefinitionProfileResults
     {
+        // an array of LayerDefinitionProfileData,
+        // which consist the profiling map layers info
         public $LayerProfileDataCollection;
+
+        //get the sum of each layer render time
+        //note that this sum can be different with the $TotalLayerRenderTime
+        public function GetSumOfLayerRenderTime()
+        {
+            $sum = 0.0;
+
+            foreach ($this->LayerProfileDataCollection as $layerProfileData)
+            {
+                $sum = $sum + $layerProfileData->TotalRenderTime;
+            }
+
+            return $sum;
+        }
     }
 
     class MapDefinitionProfileData
@@ -2374,8 +2653,16 @@
         public function ReadFromXML($resultSource)
         {
             $this->MapProfileData = new MapDefinitionProfileData();
-            $mapResultList = $resultSource->documentElement->getElementsByTagName("ProfileRenderMap");
+            $mapResultList = $resultSource->documentElement->getElementsByTagName("ProfileRenderMapResult");
             $profileRenderMap = $mapResultList->item(0);
+
+            //if the map has no watermark, then the returned results will not contain the node ProfileRenderWatermarksResult
+            $watermarkNodeList = $profileRenderMap->getElementsByTagName("ProfileRenderWatermarksResult");
+            if(0 == $watermarkNodeList->length)
+            {
+                $this->MapProfileData->TotalWatermarkRenderTime = 0.00;
+            }
+
             if ($profileRenderMap->hasChildNodes()) 
             {
                 foreach ($profileRenderMap->childNodes as $node)
@@ -2390,8 +2677,13 @@
                             case "CoordinateSystem":
                                 $this->MapProfileData->CoordinateSystem = $node->nodeValue;
                                 break;
-                            case "Extent":
-                                $this->MapProfileData->DataExtents = $node->nodeValue;
+                            case "Extents":
+                                $minX = $node->getElementsByTagName("MinX")->item(0)->nodeValue;
+                                $maxX = $node->getElementsByTagName("MaxX")->item(0)->nodeValue;
+                                $minY = $node->getElementsByTagName("MinY")->item(0)->nodeValue;
+                                $maxY = $node->getElementsByTagName("MaxY")->item(0)->nodeValue;
+
+                                $this->MapProfileData->DataExtents = $minX.",".$minY.",".$maxX.",".$maxY;
                                 break;
                             case "LayerCount":
                                 $this->MapProfileData->LayerCount = $node->nodeValue;
@@ -2411,7 +2703,7 @@
                             case "CreateImageTime":
                                 $this->MapProfileData->TotalImageRenderTime = $node->nodeValue;
                                 break;
-                            case "ProfileRenderLabels":
+                            case "ProfileRenderLabelsResult":
                                 foreach ($node->childNodes as $labelNode)
                                 {
                                     if ($labelNode->nodeType == 1 && $labelNode->nodeName == "RenderTime")
@@ -2420,7 +2712,7 @@
                                     }
                                 }
                                 break;
-                            case "ProfileRenderLayers":
+                            case "ProfileRenderLayersResult":
                                 foreach ($node->childNodes as $layerNode)
                                 {
                                     if (1 == $layerNode->nodeType && "RenderTime" == $layerNode->nodeName)
@@ -2430,7 +2722,7 @@
                                 }
                                 $this->ParseLayerResult($node);
                                 break;
-                            case "ProfileRenderWatermarks":
+                            case "ProfileRenderWatermarksResult":
                                 foreach ($node->childNodes as $watermarkNode)
                                 {
                                     if (1 == $watermarkNode->nodeType && "RenderTime" == $watermarkNode->nodeName)
@@ -2448,11 +2740,11 @@
 
         private function ParseLayerResult($LayerNodeList)
         {
-            $this->LayerProfileData=new LayerDefinitionProfileResults();
-            $this->LayerProfileData->LayerProfileDataCollection=array();
+            $this->LayerProfileData = new LayerDefinitionProfileResults();
+            $this->LayerProfileData->LayerProfileDataCollection = array();
 
             foreach ($LayerNodeList->childNodes as $layerNode) {
-                if (1 == $layerNode->nodeType && "ProfileRenderLayer" == $layerNode->nodeName) {
+                if (1 == $layerNode->nodeType && "ProfileRenderLayerResult" == $layerNode->nodeName) {
 
                     $tempLayerProfileData = new LayerDefinitionProfileData();
 
@@ -2478,7 +2770,9 @@
                                     $tempLayerProfileData->TotalRenderTime = $node->nodeValue;
                                     break;
                                 case "ScaleRange":
-                                    $tempLayerProfileData->ScaleRange= $node->nodeValue;
+                                    $minScale = $node->getElementsByTagName("MinScale")->item(0)->nodeValue;
+                                    $maxScale = $node->getElementsByTagName("MaxScale")->item(0)->nodeValue;
+                                    $tempLayerProfileData->ScaleRange= $minScale." - ".$maxScale;
                                     break;
                                 case "Filter":
                                     $tempLayerProfileData->Filters= $node->nodeValue;
@@ -2487,16 +2781,11 @@
                             }
                         }
                     }
-                    $this->LayerProfileData->LayerProfileDataCollection[$tempLayerProfileData->LayerName]=$tempLayerProfileData;
+                    $this->LayerProfileData->LayerProfileDataCollection[$tempLayerProfileData->LayerName] = $tempLayerProfileData;
                 }
             }
         }
 
-        public function SaveAsCSV()
-        {
-            //TODO: will be implemented in part3
-        }
-
         //Get the base map layer count of the specified map resource
         //The base map layer count is not provided by the profiling report
         //but we need it on UI



More information about the mapguide-commits mailing list