IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 18, 2009, 9:12:05 AM (17 years ago)
Author:
eugene
Message:

allow for DB or MDB2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippMonitor/raw/ipp.php

    r19302 r21137  
    2323
    2424function projectform ($ID) {
    25     menu ('ipp.menu.dat', 'Select Project', 'ipp.css', $ID['link'], $ID['proj']);
    26     if ($_GET['new'] && $_GET['proj']) {
    27       echo "<p> Project is now <b>" . $_GET['proj'] . "</b></p>\n";
    28     }
    29     echo "<p> Please select the project of interest </p>\n";
    30     // echo "<form action=\"SelectProject.php\" method=\"POST\">\n";
    31     // echo "Project: <input type=\"text\" name=\"proj\"><br>\n";
    32     // echo "<input type=\"submit\" name=\"project\">\n";
    33 
    34     $pass = $ID['pass'];
    35     // echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
    36     // echo "</form>\n";
    37 
    38     $db = dbconnect('ippadmin');
    39 
    40     // make this a DB lookup
    41     $sql = "SELECT projname FROM projects";
    42 
    43     $qry = $db->query($sql);
    44     if (DB::iserror($db)) {
    45       echo "<b>error reading project list</b><br>\n";
    46       menu_end();
    47     }
     25
     26  menu ('ipp.menu.dat', 'Select Project', 'ipp.css', $ID['link'], $ID['proj']);
     27  if ($_GET['new'] && $_GET['proj']) {
     28    echo "<p> Project is now <b>" . $_GET['proj'] . "</b></p>\n";
     29  }
     30  echo "<p> Please select the project of interest </p>\n";
     31  // echo "<form action=\"SelectProject.php\" method=\"POST\">\n";
     32  // echo "Project: <input type=\"text\" name=\"proj\"><br>\n";
     33  // echo "<input type=\"submit\" name=\"project\">\n";
     34
     35  $pass = $ID['pass'];
     36  // echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
     37  // echo "</form>\n";
     38
     39  $db = dbconnect('ippadmin');
     40
     41  // make this a DB lookup
     42  $sql = "SELECT projname FROM projects";
     43
     44  $qry = $db->query($sql);
     45  if (dberror($db)) {
     46    echo "<b>error reading project list</b><br>\n";
     47    menu_end();
     48  }
    4849 
    49     echo "<table class=select>\n";
    50     echo "<tr class=select><th class=select> projects </th></tr>\n";
    51     while ($qry->fetchInto($row)) {
    52       // add a link here to set the database
    53       $tmp_proj = $row[0];
    54       $tmp_link = "pass=$pass";
    55       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";
    56       // echo "<tr class=select><td class=select> $row[0] </td></tr>\n";
    57     }
    58     echo "</table>\n";
    59 
    60     menu_end ();
     50  echo "<table class=select>\n";
     51  echo "<tr class=select><th class=select> projects </th></tr>\n";
     52  while ($qry->fetchInto($row)) {
     53    // add a link here to set the database
     54    $tmp_proj = $row[0];
     55    $tmp_link = "pass=$pass";
     56    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";
     57    // echo "<tr class=select><td class=select> $row[0] </td></tr>\n";
     58  }
     59  echo "</table>\n";
     60
     61  menu_end ();
    6162}
    6263
    6364function dbconnect ($database) {
    6465
    65   require_once('DB.php');
    66 
    6766  // these are set in 'site.php'
     67  global $DBI;
    6868  global $DBHOST;
    6969  global $DBUSER;
    7070  global $DBPASS;
    7171
     72  $success = 0;
     73  if ($DBI == "MDB2") {
     74    $success = include_once('MDB2.php');
     75  }
     76  if ($DBI == "DB") {
     77    $success = include_once('DB.php');
     78  }
     79  if ($success != 1) {
     80    echo "<b>installation error: php file for $DBI not found.</b><br>\n";
     81    echo "<b>please consult the IPP Wiki for install help (get $DBI.php via Pear)</b><br>\n";
     82    menu_end();
     83    return 0;
     84  }
     85
    7286  // connect to the database
    73   $db = DB::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
    74   if (DB::iserror($db)) {
     87  if ($DBI == "DB") {
     88    $db = DB::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
     89  }
     90  if ($DBI == "MDB2") {
     91    $db = MDB2::connect("mysql://$DBUSER:$DBPASS@$DBHOST/$database");
     92  }
     93
     94  if (dberror($db)) {
    7595    echo "<b>error accessing database</b><br>\n";
    7696    echo "<b>tried mysql://$DBUSER:XXX@$DBHOST/$database</b><br>\n";
     
    82102}
    83103
     104function dberror ($db) {
     105  global $DBI;
     106
     107  if ($DBI == "MDB2") {
     108    $dberr = MDB2::isError($db);
     109  }
     110  if ($DBI == "DB") {
     111    $dberr = DB::isError($db);
     112  }
     113
     114  return $dberr;
     115}
     116
    84117// there are three pieces of data that are used to define a user:
    85118// - name (the username: available somewhere: db table?)
     
    106139
    107140  $qry = $db->query($sql);
    108   if (DB::iserror($db)) {
     141  if (dberror($db)) {
    109142    menu ('ipp.menu.dat', 'Login', 'ipp.css', '', '');
    110143    echo "<b>error reading users table</b><br>\n";
     
    130163  $sql = "SELECT username,cookie FROM cookies WHERE username = '$username'";
    131164  $qry = $db->query($sql);
    132   if (DB::iserror($db)) {
     165  if (dberror($db)) {
    133166    echo "Cookie Failed, please try again<br>\n";
    134167    menu_end();
     
    142175    $sql = "INSERT into cookies (username, cookie) values ('$username', '$cookie')";
    143176    $qry = $db->query($sql);
    144     if (DB::iserror($db)) {
     177    if (dberror($db)) {
    145178      echo "Cookie Failed, please try again<br>\n";
    146179      menu_end();
     
    214247  $sql = "SELECT username FROM cookies WHERE cookie = '$pass'";
    215248  $qry = $db->query($sql);
    216   if (DB::iserror($db)) {
     249  if (dberror($db)) {
    217250    echo "<b>error reading users table</b><br>\n";
    218251    echo "Login Failed, please try again<br>\n";
     
    276309    $page = "$root/" . $base;
    277310    if ($page == $thisname) {
    278         $style = trim($line[1]);
     311      $style = trim($line[1]);
    279312    } else {
    280         $style = trim($line[0]);
     313      $style = trim($line[0]);
    281314    }       
    282315
    283316    switch ($type) {
    284       case 'plain':
    285         echo "<tr><td class=\"$style\"> $name </td></tr>\n"; 
    286         break;
    287       case 'picture':
    288         echo "<tr><td class=\"$style\"> <img src=\"$name\"> </td></tr>\n";     
    289         break;
    290       case 'piclink':
    291         echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> <img class=\"$style\" src=\"$name\"> </a></td></tr>\n";     
    292         break;
    293       default:
    294         echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> $name </a></td></tr>\n";     
    295         break;
     317    case 'plain':
     318      echo "<tr><td class=\"$style\"> $name </td></tr>\n"; 
     319      break;
     320    case 'picture':
     321      echo "<tr><td class=\"$style\"> <img src=\"$name\"> </td></tr>\n";     
     322      break;
     323    case 'piclink':
     324      echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> <img class=\"$style\" src=\"$name\"> </a></td></tr>\n";     
     325      break;
     326    default:
     327      echo "<tr><td class=\"$style\"> <a class=\"$style\" href=\"$link\"> $name </a></td></tr>\n";     
     328      break;
    296329    }
    297330  }
Note: See TracChangeset for help on using the changeset viewer.