<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
  <title>Browse How-To Database</title>
  <LINK REL="stylesheet" HREF="/PHP/style.css">
  <META NAME="author"      CONTENT="Denice Deatrich">
  <META NAME="description" CONTENT="PHP web-based MySQL DB Management">
  <META NAME="keywords"    CONTENT="PHP web MySQL database">
</head>

<body>
  <h1>How-To Database</h1>
<?php
  
function showForm( $arr )
  {
    echo
"
    <table width=300 cols=4>
    <tr>
      <td>Topic:</td>
      <td nowrap>
      <input name=\"topic\" size=30 maxlength=30 value=\"$arr[1]\">
      </td>
      <td>&nbsp;&nbsp;OS:</td>
      <td>
      <select name=\"os\">"
;
      
$osii = array( "unix", "*", "linux", "solaris", "hp-ux",
       
"windows", "WinNT" );
      for(
$i= 0; $i < sizeof($osii); $i++ ) {
        echo
"<option value=\"$osii[$i]\"";
        if(
$osii[$i] == $arr[2] ) {
          echo
" selected>$osii[$i]";
        }
        else {
          echo
">$osii[$i]";
        }
      }
      echo
"</select>
      </td>
    </tr>
    <tr>
      <td>Ver:</td>
      <td>
        <input name=\"ver\" size=10 maxlength=10 value=\"$arr[3]\">
      </td>
      <td>&nbsp;&nbsp;Arch:</td>
      <td>
      <select name=\"arch\">"
;
      
$arches = array( "*", "intel", "sparc", "pa-risc" );
      for(
$i= 0; $i < sizeof($arches); $i++ ) {
        echo
"<option value=\"$arches[$i]\"";
        if(
$arches[$i] == $arr[4] ) {
          echo
" selected>$arches[$i]";
        }
        else {
          echo
">$arches[$i]";
        }
      }
      echo
"</select>
      </td>
    </tr>

    <tr>
      <td>Keywords:</td>
      <td>
      <input name=\"keywords\" size=30 maxlength=30 value=\"$arr[5]\">
      </td>
    </tr>
    </table>\n<BR>"
;
    echo
"Notes:<BR>
    <textarea name=\"notes\" rows=10 cols=80>$arr[6]</textarea>"
;
  }
// end of function showForm()

  
require( "db_connect.php" );
  
checkDBStatus( );
  
$loop = true;
  
$act = "none";
  while( (list(
$key, $val) = each($HTTP_POST_VARS)) && $loop ) {
//echo $key . " => ".  $val . "<BR>";
    
if( ereg("^option\-[0-9]", $key) == true && $val != "none" ) {
      
$act = $val;   // user picked option from popup menu on a row
    
}
    else if(
ereg("^[0-9]+", $key) == true && $act != "none" ) {
      if( (
$link=mysql_pconnect($DB_HOST, $DB_USER, $DB_PW)) ) {
        
$q = "select * from how_to where rowid = " . $key;
        if(
$res=mysql_db_query($DB_NAME, $q, $link) ) {
          if(
$row = mysql_fetch_array($res, MYSQL_NUM) ) {
            if(
$act == "notes" ) {
              echo
"<h2>Browse full record:</h2>";
              echo
"<form action=\"/PHP/db/db_insert.php\" method=\"post\">";
              
showForm( $row );
              echo
"</form>";
            }
            else if(
$act == "modify" ) {
              echo
"<h2>Modify record:</h2>
              <form action=\"/PHP/db/db_modify.php?$key\"
              method=\"post\">"
;
              
showForm( $row );
              echo
"<font color=\"red\">
              <input type=\"submit\" VALUE=\"Apply Modification\"></font>"
;
              echo
"</form>";
            }
            else if(
$act == "delete" ) {
              echo
"<h2>Delete record:</h2>
              <form action=\"/PHP/db/db_delete.php?$key\"
              method=\"post\">"
;
              
showForm( $row );
              echo
"<font color=\"red\">
              <input type=\"submit\" VALUE=\"Delete Entry\"></font>"
;
              echo
"</form>";
            }
          }
          else {
            
printError( "Fetch", $link );
          }
        }
        else {
          
printError( "Query", $link );
        }
      }
      else {
        
printf( "Connect: %s: %s\n<BR>", mysql_errno(), mysql_error() );
      }
    }
    else if(
$key == "insert" ) {
      echo
"<h2>Insert new record:</h2>";
      echo
"<form action=\"/PHP/db/db_insert.php\" method=\"post\">";
      
$arr = array( "", "", "", "*", "", "", "", "" );
      
showForm( $arr );
      echo
"<input type=\"reset\" VALUE=\"Reset Form\">";
      echo
"<font color=\"red\">
      <input type=\"submit\" VALUE=\"Apply Insert\"></font>"
;
      echo
"</form>";
    }
  }
?>
  <hr>
  <div class="footer">
  <address>
    <a href="mailto&#058;Denice&#046;Deatrich&#064;epfl.ch">Denice Deatrich</a>
  </address>
<!-- Created: Sun Jan 16 17:22:34 MET 2000 -->
<!-- hhmts start -->
Last modified: Wed Jun  7 00:08:13 MEST 2000
<!-- hhmts end -->
  </div>
</body>
</html>