<?php


// Title: crud_main.php
// Description: See crud.php. 

// Author: Burton Rosenberg
// Created: 29 May 2007
// Last Update: 30 May

// Copyright (c) 2007 Burton Rosenberg. All rights reserved.


function crud_main($status) {

   global 
$fields ;
   global 
$link ;

   if ( 
$status!="" ) {
      echo 
'<div id="statusbox">'.$status.'</div>' ;
   }
?>

<form action="crud.php" method="POST">

<div class="mybox">
<table id="newrow">
<tr>
<td>
<div class="actions">
<input type="radio" name="activity" value="new" checked="checked">Create
</div>
<tr>
<th>User name
<td><input type="text" name="username" value="">
<tr>
<th>Password
<td><input type="password" name="password" value="">
<tr>
<th>First name
<td><input type="text" name="firstname" value="">
<tr>
<th>Last name
<td><input type="text" name="lastname" value="">
<tr>
<th>Email
<td><input type="text" name="email" value"">
</table>
</div>

<div class="mybox">
<table id="rellist">
<tr><td colspan="3">
<div class="actions" style="margin-bottom: 2px;">
<input type="radio" name="activity" value="edit">Update
</div>
<div class="actions">
<input type="radio" name="activity" value="delete">Delete
</div>
<tr><th style="background: none;">

<?php

     
foreach ( $fields as $f ) {
         echo 
"<th>$f" ;
     }
     
$query 'SELECT * FROM users';
     
$result mysql_query($query) or 
         die(
'Query failed: ' mysql_error());

     while (
$row mysql_fetch_assoc($result)) {
         echo 
'<tr><th><input type="checkbox" name="item[]" value="'
               
$row['id'],'">';
         foreach ( 
$fields as $f ) {
             echo 
"<td>$row[$f]\n" ;
         }
     }

     
mysql_free_result($result);
?>

</table>
</div>


<div class="mybox">
<input type="Submit" value="Submit Action" style="color:red;">
</div>

</form>

<?php
    
return ;
}
?>