Index: trunk/MagicSoft/Mars/datacenter/db/include.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 7546)
+++ trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 7873)
@@ -118,25 +118,4 @@
 }
 
-function PrintLimitsMenu($limits, $rms, $alias)
-{
-    foreach($limits as $key => $element)
-    {
-        printf("<tr><td>%s</td>\n", $alias[$key]);
-        $mean=$key . "Mean";
-        $limitmean=$_GET[$mean];
-        printf("<td><input name=\"%sMean\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitmean);
-        if ($rms[$key]=="yes")
-        {
-            $rms2=$key . "Rms";
-            $limitrms=$_GET[$rms2];
-            printf("<td><input name=\"%sRms\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitrms);
-        }
-        else
-            printf("<td><br></td>\n");
-        printf("</tr>\n");
-    }
-
-}
-
 function PrintPullDown($host, $user, $pw, $db, $table, $name, $index, $descr)
 {
@@ -257,4 +236,17 @@
         printf("\n");
     }
+}
+
+function PrintSubmittedQuery($query0, $html, $db, $old)
+{
+    //diplay query on old websites
+    if (empty($old))
+        printf("<tr class='Block' id='showquery' style='display:none'><td>");
+    else
+        printf("<tr class='Block' id='showquery' style='display:block'><td>");
+    printf("<b>DB:</b> %s <br>", $db);
+    if ($html=="1")
+        printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    printf("</td></tr>");
 }
 
@@ -323,4 +315,31 @@
 
     if ($_GET["fNumStart"]!=0)
+    {
+        $uri = htmlspecialchars($_SERVER["REQUEST_URI"]);
+        $pos = strpos($uri, "fNumStart");
+        $amp3=FALSE;
+        if ($pos!=FALSE)
+        {
+            $amp1 = substr($uri, 0, $pos-1);
+            $amp2 = substr($uri, $pos);
+            $amp3 = strchr($amp2, "&");
+
+            $uri = $amp1;
+        }
+        $pos = $_GET["fNumStart"]-$rows;
+        if ($pos<0)
+            $pos=0;
+        $uri .= "&fNumStart=" . $pos;
+        if ($amp3!=FALSE)
+            $uri .= $amp3;
+
+        $menu .= "<A HREF='" . $uri . "'><<< Prev</A>\n";
+    }
+
+    $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
+    $menu .= $_GET["fNumStart"];
+    $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
+
+    if ($rows==$_GET["fNumResults"])
     {
         $uri = $_SERVER["REQUEST_URI"];
@@ -335,41 +354,14 @@
             $uri = $amp1;
         }
-        $pos = $_GET["fNumStart"]-$rows;
-        if ($pos<0)
-            $pos=0;
-        $uri .= "&fNumStart=" . $pos;
-        if ($amp3!=FALSE)
-            $uri .= $amp3;
-
-        $menu .= "<A HREF='" . $uri . "'><<< Prev</A>\n";
-    }
-
-    $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
-    $menu .= $_GET["fNumStart"];
-    $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
-
-    if ($rows==$_GET["fNumResults"])
-    {
-        $uri = $_SERVER["REQUEST_URI"];
-        $pos = strpos($uri, "fNumStart");
-        $amp3=FALSE;
-        if ($pos!=FALSE)
-        {
-            $amp1 = substr($uri, 0, $pos-1);
-            $amp2 = substr($uri, $pos);
-            $amp3 = strchr($amp2, "&");
-
-            $uri = $amp1;
-        }
         $uri .= "&fNumStart=" . ($_GET["fNumStart"]+$rows);
         if ($amp3!=FALSE)
             $uri .= $amp3;
 
-        $menu .= "<A HREF='" . $uri . "'>Next >>></A>\n";
+        $menu .= "<A HREF='" . htmlspecialchars($uri) . "'>Next >>></A>\n";
     }
     return $menu;
 }
 
-function RemoveSortBy($rows)
+function RemoveSortBy()
 {
     $menu = "";
@@ -399,12 +391,25 @@
 }
 
-function PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET)
+function PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $_GET)
 {
     $col   = FALSE;
     $first = TRUE;
 
+    $sigma = array
+        (
+         5    => "#FF9900",
+         3    => "#FFFF66",
+         2    => "#33CC00",
+         1    => "#006600",
+        );
+    $offlimitcolour="#FF0000";
+
+
+
     $menu = CreateMenu(mysql_num_rows($result0));
 
-    printf("\n<center>\n<p>%s<P>\n", $menu);
+    printf("\n<center>\n");
+    if (empty($_GET["fPrintTable"]))
+        printf("<p>%s<P>\n", $menu);
     printf("<table BORDER=\"0\">\n");
     while ($row0 = mysql_fetch_assoc($result0))
@@ -430,6 +435,6 @@
                         $issort="&nbsp;<IMG SRC='up.gif'>";
                 }
-                printf("  <th>&nbsp;<A HREF='%s&fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
-                       RemoveSortBy($_SERVER["REQUEST_URI"]), $col, $ord, $key, $issort);
+                printf("  <th>&nbsp;<A HREF='%s&amp;fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
+                       htmlspecialchars(RemoveSortBy()), $col, $ord, $key, $issort);
             }
             printf(" </tr>\n\n");
@@ -449,47 +454,70 @@
                 printf("  <td align=\"right\">");
 
-            if (!(empty($limits) && empty($rms)))
+            //determine color of text in cell
+            foreach($limitsmean as $key2 => $element2)
             {
-                foreach($limits as $key2 => $element2)
+                $mean=$key2 . "Mean";
+                $rms2=$key2 . "Rms";
+                if ($key==$alias[$element2] && !empty($_GET[$mean]))
                 {
-                    $mean=$key2 . "Mean";
-                    $rms2=$key2 . "Rms";
-                    if ($key==$alias[$element2] && !empty($_GET[$mean]))
+                    if (!empty($_GET[$rms2]))
                     {
-                        if ($rms[$key2]=="yes")
+                        $colour=$offlimitcolour;
+                        foreach ($sigma as $margin => $newcolour)
                         {
-                            if (!empty($_GET[$rms2]))
-                            {
-                                $min=$_GET[$mean] - $_GET[$rms2];
-                                $max=$_GET[$mean] + $_GET[$rms2];
-                                if ($min < $element && $element < $max)
-                                    printf("<font color='green'>");
-                                else
-                                    printf("<font color='red'>");
-                            }
+                            $min=$_GET[$mean] - ($margin * $_GET[$rms2]);
+                            $max=$_GET[$mean] + ($margin * $_GET[$rms2]);
+                            if ($min < $element && $element < $max)
+                                $colour=$newcolour;
                         }
-                        else
+                        printf("<font color='%s' style='font-weight:bold'>", $colour);
+                    }
+                }
+            }
+
+            foreach($limitsmin as $key2 => $element2)
+            {
+                $limit1=$key2 . "1";
+                $limit2=$key2 . "2";
+                if ($key==$alias[$element2] && !empty($_GET[$limit1]))
+                {
+                    $colour=$offlimitcolour;
+                    if ($_GET[$limit1] <= $element)
+                        $colour=$sigma[1];
+                    else
+                    {
+                        if (!empty($_GET[$limit2]))
                         {
-                            if ($rms[$key2]=="min")
-                            {
-                                if ($_GET[$mean] <= $element)
-                                    printf("<font color='green'>");
-                                else
-                                    printf("<font color='red'>");
-                            }
-
-                            if ($rms[$key2]=="max")
-                            {
-                                if ($_GET[$mean] >= $element)
-                                    printf("<font color='green'>");
-                                else
-                                    printf("<font color='red'>");
-                            }
+                            if ($_GET[$limit2] <= $element)
+                                $colour=$sigma[5];
                         }
                     }
-
+                    printf("<font color='%s' style='font-weight:bold'>", $colour);
+                }
+
+            }
+
+            foreach($limitsmax as $key2 => $element2)
+            {
+                $limit1=$key2 . "1";
+                $limit2=$key2 . "2";
+                if ($key==$alias[$element2] && !empty($_GET[$limit1]))
+                {
+                    $colour=$offlimitcolour;
+                    if ($_GET[$limit1] >= $element)
+                        $colour=$sigma[1];
+                    else
+                    {
+                        if (!empty($_GET[$limit2]))
+                        {
+                            if ($_GET[$limit2] >= $element)
+                                $colour=$sigma[5];
+                        }
+                    }
+                    printf("<font color='%s' style='font-weight:bold'>", $colour);
                 }
             }
 
+            //fill text in cell
             printf("&nbsp;%s&nbsp;</td>\n", str_replace("&ws;", " ", str_replace(" ", "&nbsp;", $element)));
         }
@@ -505,8 +533,10 @@
 
     printf("<P><B>Number of displayed results: %d</B><P><P>\n", mysql_num_rows($result0));
-    printf("%s\n", $menu);
+    if (empty($_GET["fPrintTable"]))
+        printf("%s\n", $menu);
     printf("<P>\n");
     printf("</center>\n");
-    printf("</tr><tr class='Block'><td>\n");
+    printf("</td>\n");
+    printf("</tr>\n");
 }
 
