Index: trunk/ippMonitor/raw/ipp.php
===================================================================
--- trunk/ippMonitor/raw/ipp.php	(revision 19302)
+++ trunk/ippMonitor/raw/ipp.php	(revision 21137)
@@ -23,54 +23,74 @@
 
 function projectform ($ID) {
-    menu ('ipp.menu.dat', 'Select Project', 'ipp.css', $ID['link'], $ID['proj']);
-    if ($_GET['new'] && $_GET['proj']) {
-      echo "<p> Project is now <b>" . $_GET['proj'] . "</b></p>\n";
-    }
-    echo "<p> Please select the project of interest </p>\n";
-    // echo "<form action=\"SelectProject.php\" method=\"POST\">\n";
-    // echo "Project: <input type=\"text\" name=\"proj\"><br>\n";
-    // echo "<input type=\"submit\" name=\"project\">\n";
-
-    $pass = $ID['pass'];
-    // echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
-    // echo "</form>\n";
-
-    $db = dbconnect('ippadmin');
-
-    // make this a DB lookup
-    $sql = "SELECT projname FROM projects";
-
-    $qry = $db->query($sql);
-    if (DB::iserror($db)) {
-      echo "<b>error reading project list</b><br>\n";
-      menu_end();
-    }
+
+  menu ('ipp.menu.dat', 'Select Project', 'ipp.css', $ID['link'], $ID['proj']);
+  if ($_GET['new'] && $_GET['proj']) {
+    echo "<p> Project is now <b>" . $_GET['proj'] . "</b></p>\n";
+  }
+  echo "<p> Please select the project of interest </p>\n";
+  // echo "<form action=\"SelectProject.php\" method=\"POST\">\n";
+  // echo "Project: <input type=\"text\" name=\"proj\"><br>\n";
+  // echo "<input type=\"submit\" name=\"project\">\n";
+
+  $pass = $ID['pass'];
+  // echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
+  // echo "</form>\n";
+
+  $db = dbconnect('ippadmin');
+
+  // make this a DB lookup
+  $sql = "SELECT projname FROM projects";
+
+  $qry = $db->query($sql);
+  if (dberror($db)) {
+    echo "<b>error reading project list</b><br>\n";
+    menu_end();
+  }
   
-    echo "<table class=select>\n";
-    echo "<tr class=select><th class=select> projects </th></tr>\n";
-    while ($qry->fetchInto($row)) {
-      // add a link here to set the database
-      $tmp_proj = $row[0];
-      $tmp_link = "pass=$pass";
-      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 ();
+  echo "<table class=select>\n";
+  echo "<tr class=select><th class=select> projects </th></tr>\n";
+  while ($qry->fetchInto($row)) {
+    // add a link here to set the database
+    $tmp_proj = $row[0];
+    $tmp_link = "pass=$pass";
+    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 dbconnect ($database) {
 
-  require_once('DB.php');
-
   // these are set in 'site.php'
+  global $DBI;
   global $DBHOST;
   global $DBUSER;
   global $DBPASS;
 
+  $success = 0;
+  if ($DBI == "MDB2") {
+    $success = include_once('MDB2.php');
+  }
+  if ($DBI == "DB") {
+    $success = include_once('DB.php');
+  }
+  if ($success != 1) {
+    echo "<b>installation error: php file for $DBI not found.</b><br>\n";
+    echo "<b>please consult the IPP Wiki for install help (get $DBI.php via Pear)</b><br>\n";
+    menu_end();
+    return 0;
+  }
+
   // connect to the database
-  $db = DB::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
-  if (DB::iserror($db)) {
+  if ($DBI == "DB") {
+    $db = DB::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
+  }
+  if ($DBI == "MDB2") {
+    $db = MDB2::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
+  }
+
+  if (dberror($db)) {
     echo "<b>error accessing database</b><br>\n";
     echo "<b>tried mysql://$DBUSER:XXX@$DBHOST/$database</b><br>\n";
@@ -82,4 +102,17 @@
 }
 
+function dberror ($db) {
+  global $DBI;
+
+  if ($DBI == "MDB2") {
+    $dberr = MDB2::isError($db);
+  }
+  if ($DBI == "DB") {
+    $dberr = DB::isError($db);
+  }
+
+  return $dberr;
+}
+
 // there are three pieces of data that are used to define a user:
 // - name (the username: available somewhere: db table?)
@@ -106,5 +139,5 @@
 
   $qry = $db->query($sql);
-  if (DB::iserror($db)) {
+  if (dberror($db)) {
     menu ('ipp.menu.dat', 'Login', 'ipp.css', '', '');
     echo "<b>error reading users table</b><br>\n";
@@ -130,5 +163,5 @@
   $sql = "SELECT username,cookie FROM cookies WHERE username = '$username'";
   $qry = $db->query($sql);
-  if (DB::iserror($db)) {
+  if (dberror($db)) {
     echo "Cookie Failed, please try again<br>\n";
     menu_end();
@@ -142,5 +175,5 @@
     $sql = "INSERT into cookies (username, cookie) values ('$username', '$cookie')";
     $qry = $db->query($sql);
-    if (DB::iserror($db)) {
+    if (dberror($db)) {
       echo "Cookie Failed, please try again<br>\n";
       menu_end();
@@ -214,5 +247,5 @@
   $sql = "SELECT username FROM cookies WHERE cookie = '$pass'";
   $qry = $db->query($sql);
-  if (DB::iserror($db)) {
+  if (dberror($db)) {
     echo "<b>error reading users table</b><br>\n";
     echo "Login Failed, please try again<br>\n";
@@ -276,22 +309,22 @@
     $page = "$root/" . $base;
     if ($page == $thisname) {
-	$style = trim($line[1]);
+      $style = trim($line[1]);
     } else { 
-	$style = trim($line[0]);
+      $style = trim($line[0]);
     }       
 
     switch ($type) { 
-      case 'plain':
-        echo "<tr><td class=\"$style\"> $name </td></tr>\n";  
-        break;
-      case 'picture':
-        echo "<tr><td class=\"$style\"> <img src=\"$name\"> </td></tr>\n";     
-        break;
-      case 'piclink':
-        echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> <img class=\"$style\" src=\"$name\"> </a></td></tr>\n";     
-        break;
-      default:
-        echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> $name </a></td></tr>\n";     
-        break;
+    case 'plain':
+      echo "<tr><td class=\"$style\"> $name </td></tr>\n";  
+      break;
+    case 'picture':
+      echo "<tr><td class=\"$style\"> <img src=\"$name\"> </td></tr>\n";     
+      break;
+    case 'piclink':
+      echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> <img class=\"$style\" src=\"$name\"> </a></td></tr>\n";     
+      break;
+    default:
+      echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> $name </a></td></tr>\n";     
+      break;
     } 
   }
