Index: trunk/ippMonitor/raw/ipp.php
===================================================================
--- trunk/ippMonitor/raw/ipp.php	(revision 38262)
+++ trunk/ippMonitor/raw/ipp.php	(revision 39498)
@@ -1,4 +1,5 @@
 <?php
 
+$debug = 0;
 $dTABLE = 80;
 include 'site.php';
@@ -50,5 +51,5 @@
   echo "<table class=select>\n";
   echo "<tr class=select><th class=select> projects </th></tr>\n";
-  while ($qry->fetchInto($row)) {
+  while (dbFetchInto($qry, $row)) {
     // add a link here to set the database
     $tmp_proj = $row[0];
@@ -56,8 +57,25 @@
     echo "<tr class=select><td class=select><a class=\"menutop\" href=\"SelectProject.php?$tmp_link&proj=$tmp_proj&new=1\"> $row[0] </a></td></tr>\n";
     // echo "<tr class=select><td class=select> $row[0] </td></tr>\n";
-  }
+  } 
   echo "</table>\n";
 
   menu_end ();
+}
+
+function dbFetchInto ($qry, &$result) {
+  global $DBI;
+
+  if ($DBI == "MDB2") {
+    $result = $qry->fetchRow();
+    if ($result == NULL) {
+      $success = 0;
+    } else {
+      $success = 1;
+    }
+  }
+  if ($DBI == "DB") {
+    $success = $qry->fetchInto($result);
+  }
+  return $success;
 }
 
@@ -87,18 +105,21 @@
 
   // connect to the database
+  if ($database == $CZARDBNAME) {
+    $dsn = "mysql://$DBUSER:$DBPASS@$CZARDBHOST/$database";
+    $dsnerr = "mysql://$DBUSER:XXX@$CZARDBHOST/$database"; // only used to report the error
+  } else {
+    $dsn = "mysql://$DBUSER:$DBPASS@$DBHOST/$database";
+    $dsnerr = "mysql://$DBUSER:XXX@$DBHOST/$database"; // only used to report the error
+  }
   if ($DBI == "DB") {
-    if ($database == $CZARDBNAME) {
-        $db = DB::connect("mysql://$DBUSER:$DBPASS@$CZARDBHOST/$database");
-    } else {
-        $db = DB::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
-    }
+    $db = DB::connect($dsn);
   }
   if ($DBI == "MDB2") {
-    $db = MDB2::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
+    $db = MDB2::connect($dsn);
   }
 
   if (dberror($db)) {
     echo "<b>error accessing database</b><br>\n";
-    echo "<b>tried mysql://$DBUSER:XXX@$DBHOST/$database</b><br>\n";
+    echo "<b>tried $dsnerr</b><br>\n";
     $result = $db->getMessage();
     echo "$result<br>";
@@ -112,5 +133,5 @@
 
   if ($DBI == "MDB2") {
-    $dberr = MDB2::isError($db);
+    $dberr = PEAR::isError($db);
   }
   if ($DBI == "DB") {
@@ -129,6 +150,6 @@
 function checkLogin () {
 
-  $username = $_POST[username];
-  $password = $_POST[password];
+  $username = $_POST['username'];
+  $password = $_POST['password'];
 
   // if password is not specified, keep username and ask again
@@ -143,6 +164,6 @@
   // get the users from the DB
   $sql = "SELECT username FROM users WHERE username = '$username' AND password = '$password'";
-
   $qry = $db->query($sql);
+
   if (dberror($db)) {
     menu ('ipp.menu.dat', 'Login', 'ipp.css', '', '');
@@ -152,6 +173,6 @@
     menu_end();
   }
-  
-  $success = $qry->fetchInto($row);
+
+  $success = dbFetchInto($qry, $row);
   if (!$success) {  
     menu ('ipp.menu.dat', 'Login', 'ipp.css', '', '');
@@ -174,5 +195,5 @@
   }
 
-  if ($qry->fetchInto($row)) {
+  if (dbFetchInto($qry, $row)) {
     $ID['pass'] = $row[1];
   } else {
@@ -197,6 +218,4 @@
 
 function checkID () {
-
-
   $VERBOSE = 0;
   if ($VERBOSE > 1) {
@@ -205,5 +224,5 @@
 
   // check for valid server method
-  if (($_SERVER[REQUEST_METHOD] != 'POST') && ($_SERVER[REQUEST_METHOD] != 'GET')) {
+  if (($_SERVER['REQUEST_METHOD'] != 'POST') && ($_SERVER['REQUEST_METHOD'] != 'GET')) {
     menu ('ipp.menu.dat', 'Login', 'ipp.css', '', '');
     echo "Invalid Client Request<br>\n";
@@ -213,9 +232,9 @@
 
   // look for pass & proj in appropriate location
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $ID['pass'] = $_GET[pass];
-    $ID['proj'] = $_GET[proj];
-    $ID['menu'] = $_GET[menu];
-    $ID['from'] = $_GET[from];
+  if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
+    $ID['pass'] = array_key_exists('pass', $_GET) ? $_GET['pass'] : "";
+    $ID['proj'] = array_key_exists('proj', $_GET) ? $_GET['proj'] : "";
+    $ID['menu'] = array_key_exists('menu', $_GET) ? $_GET['menu'] : "";
+    $ID['from'] = array_key_exists('from', $_GET) ? $_GET['from'] : "";
 
     if ($VERBOSE) {
@@ -227,9 +246,9 @@
     }
   }
-  if ($_SERVER[REQUEST_METHOD] == 'POST') { 
-    $ID['pass'] = $_POST[pass];
-    $ID['proj'] = $_POST[proj];
-    $ID['menu'] = $_POST[menu];
-    $ID['from'] = $_POST[from];
+  if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
+    $ID['pass'] = array_key_exists('pass', $_POST) ? $_POST['pass'] : "";
+    $ID['proj'] = array_key_exists('proj', $_POST) ? $_POST['proj'] : "";
+    $ID['menu'] = array_key_exists('menu', $_POST) ? $_POST['menu'] : "";
+    $ID['from'] = array_key_exists('from', $_POST) ? $_POST['from'] : "";
 
     if ($VERBOSE) {
@@ -264,5 +283,5 @@
   }
   
-  $success = $qry->fetchInto($row);
+  $success = dbFetchInto($qry,$row);
   if (! $success) {
     menu('ipp.menu.dat', 'Login', 'ipp.css', '', '');
@@ -359,5 +378,5 @@
     }
 	
-    $thisname = $_SERVER[SCRIPT_NAME]; 
+    $thisname = $_SERVER['SCRIPT_NAME']; 
     $page = "$root/" . $base;
     if ($page == $thisname) {
@@ -396,9 +415,5 @@
   $sortKey = "";
   // try sort forward
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $sortVal = $_GET['sort']; 
-  } else {
-    $sortVal = $_POST['sort'];
-  }
+  $sortVal = get_htmlkey_value ('sort');
   if ($sortVal != "") {
     $sortKey = "&sort=" . $sortVal;
@@ -406,9 +421,5 @@
   // try sort reverse
   if ($sortKey == "") {
-    if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-      $sortVal = $_GET['rsort']; 
-    } else {
-      $sortVal = $_POST['rsort'];
-    }
+    $sortVal = get_htmlkey_value ('rsort');
     if ($sortVal != "") {
       $sortKey = "&rsort=" . $sortVal;
@@ -473,8 +484,8 @@
   }
 
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
+  if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
+    $value = array_key_exists($htmlkey, $_GET) ? $_GET[$htmlkey] : ""; 
+  } else {
+    $value = array_key_exists($htmlkey, $_POST) ? $_POST[$htmlkey] : ""; 
   }
   if ($value == "") { return $where; }
@@ -517,18 +528,10 @@
   }
 
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET['sort']; 
-  } else {
-    $value = $_POST['sort'];
-  }
+  $value = get_htmlkey_value ('sort');
   if ($value != "") {
     $where = $where . " ORDER BY $value";
     return $where;
   }
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET['rsort']; 
-  } else {
-    $value = $_POST['rsort'];
-  }
+  $value = get_htmlkey_value ('rsort');
   if ($value != "") {
     $where = $where . " ORDER BY $value DESC";
@@ -538,12 +541,18 @@
 }
 
+function get_htmlkey_value ($htmlkey) {
+  if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
+    $value = array_key_exists($htmlkey, $_GET) ? $_GET[$htmlkey] : ""; 
+  } else {
+    $value = array_key_exists($htmlkey, $_POST) ? $_POST[$htmlkey] : ""; 
+  }
+  return $value;
+}
+
 // if we have a restriction for a string-valued field, supply it to outgoing links
 function button_restrict_string ($key, $line) {
   $htmlkey = preg_replace ('|\.|', '_', $key);
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
+
   # a search restriction may include an SQL wild-card.  we have to mangle these so that the http 
   # does not get converted to a special character
@@ -563,9 +572,5 @@
   $htmlkey = preg_replace ('|\.|', '_', $key);
   $htmlkey = $htmlkey . '_min';
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
   if ($value != "") {
     if ($line) {
@@ -582,9 +587,5 @@
   $htmlkey = preg_replace ('|\.|', '_', $key);
   $htmlkey = $htmlkey . '_max';
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
   if ($value != "") {
     if ($line) {
@@ -600,9 +601,5 @@
 function button_restrict_checkbox ($key, $line) {
   $htmlkey = preg_replace ('|\.|', '_', $key);
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
   if ($value != "") {
     if ($line) {
@@ -618,9 +615,5 @@
 function button_restrict_radio ($key, $line) {
   $htmlkey = preg_replace ('|\.|', '_', $key);
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
   if ($value != "") {
     if ($line) {
@@ -648,12 +641,12 @@
   }
 
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $up   = $_GET['rsort']; 
-    $down = $_GET['sort']; 
-    $from = $_GET['from']; 
-  } else {
-    $up   = $_POST['rsort']; 
-    $down = $_POST['sort']; 
-    $from = $_POST['from']; 
+  if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
+    $up   = array_key_exists('rsort', $_GET) ? $_GET['rsort'] : "";
+    $down = array_key_exists('sort',  $_GET) ? $_GET['sort'] : "";
+    $from = array_key_exists('from',  $_GET) ? $_GET['from'] : "";
+  } else {
+    $up   = array_key_exists('rsort', $_POST) ? $_POST['rsort'] : "";
+    $down = array_key_exists('sort',  $_POST) ? $_POST['sort'] : "";
+    $from = array_key_exists('from',  $_POST) ? $_POST['from'] : "";
   }
 
@@ -695,9 +688,5 @@
     $htmlkey = $htmlkey . "_max";
   }
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
 
   // full table element includes optionally the <= or >= words
@@ -714,10 +703,6 @@
 function write_query_checkbox ($key, $comment) {
   $htmlkey = preg_replace ('|\.|', '_', $key);
-
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
+
   echo "<td> <input type=\"checkbox\" name=\"$htmlkey\"";
   if ($value == "on") { 
@@ -734,9 +719,5 @@
   $htmlvalue = preg_replace ('|\.|', '_', $value);
 
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $value = $_GET[$htmlkey]; 
-  } else {
-    $value = $_POST[$htmlkey];
-  }
+  $value = get_htmlkey_value ($htmlkey);
   if ($htmlvalue == get_value_from_key($htmlkey, TRUE)) {
     $checked = "checked";
@@ -779,12 +760,12 @@
 function insert_image ($rule, $size) {
 
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $basename = $_GET['basename']; 
-    $class_id = $_GET['class']; 
-    $camera   = $_GET['camera']; 
-  } else {
-    $basename = $_POST['basename']; 
-    $class_id = $_POST['class']; 
-    $camera   = $_POST['camera']; 
+  if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
+    $basename = array_key_exists('basename', $_GET) ? $_GET['basename'] : "";
+    $class_id = array_key_exists('class',    $_GET) ? $_GET['class']    : "";
+    $camera   = array_key_exists('camera',   $_GET) ? $_GET['camera']   : "";
+  } else {
+    $basename = array_key_exists('basename', $_POST) ? $_POST['basename'] : "";
+    $class_id = array_key_exists('class',    $_POST) ? $_POST['class']    : "";
+    $camera   = array_key_exists('camera',   $_POST) ? $_POST['camera']   : "";
   }
 
@@ -802,14 +783,14 @@
 function insert_log ($filerule) {
 
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $basename = $_GET['basename']; 
-    $class_id = $_GET['class']; 
-    $camera   = $_GET['camera']; 
-    $state    = $_GET['state']; 
-  } else {
-    $basename = $_POST['basename']; 
-    $class_id = $_POST['class']; 
-    $camera   = $_POST['camera']; 
-    $state    = $_POST['state']; 
+  if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
+    $basename = array_key_exists('basename', $_GET) ? $_GET['basename'] : "";
+    $class_id = array_key_exists('class',    $_GET) ? $_GET['class']    : "";
+    $camera   = array_key_exists('camera',   $_GET) ? $_GET['camera']   : "";
+    $state    = array_key_exists('state',    $_GET) ? $_GET['state']    : "";
+  } else {
+    $basename = array_key_exists('basename', $_POST) ? $_POST['basename'] : "";
+    $class_id = array_key_exists('class',    $_POST) ? $_POST['class']    : "";
+    $camera   = array_key_exists('camera',   $_POST) ? $_POST['camera']   : "";
+    $state    = array_key_exists('state',    $_POST) ? $_POST['state']    : "";
   }
 
@@ -830,5 +811,7 @@
   //It's necessary for staticsky logs and it would require to join tables
   //back to the warpRun table
-  if (! $camera) { $camera = strtoupper($_GET['proj']); }
+  if (! $camera) { 
+    $camera = strtoupper($_GET['proj']); 
+  }
 
   if ($basename && $camera && $filerule) {
@@ -886,9 +869,5 @@
 function insert_backref ($page, $key, $link) {
 
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    $name = $_GET[$key]; 
-  } else {
-    $name = $_POST[$key]; 
-  }
+  $name = get_htmlkey_value ($key);
 
   if ($name) {
@@ -911,9 +890,6 @@
     $htmlkey = $key;
   }
-  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
-    return $_GET[$htmlkey]; 
-  } else {
-    return $_POST[$htmlkey]; 
-  }
+  $value = get_htmlkey_value ($key);
+  return $value;
 }
 
