<?php 
 if ($thisID) {
  $query="SELECT * FROM $dbconfig[todo_table] WHERE id = '$thisID' AND ($groupquery)";
  $result=dbQuery($query);
  $data=dbResultArray($result,0);
 }

 if ((!$data["groupid"]) && ($thisGroup)) {
  $data["groupid"] = $thisGroup;
 }
?>
<?php if ($action == "New" || $action == "Edit"):?>
<form action=<?php echo $baseurl?>/todo_edit/ method=POST>
<input type=hidden name=data[id] value=<?php echo $data[id]?>>
<input type=hidden name=thisGroup value="<?php echo $thisGroup?>">
<table>

 <tr>
  <td colspan=3 bgcolor=black>
   <table width=100%><tr><td>
   <font face="<?php echo $cellfont?>" color=white size=+2>
   <?php if ($action == "New"):?>
   Add New Item
   <?php else:?>
   Edit Item
   <?php endif;?>
   </font>
   </td><td align=right>
   <font face="<?php echo $cellfont?>" color=white>
   Added by:
   <?php echo twigLink("<font color=white>" . $data[username] . "</font>","compose","form[to]=" . URLEncode("$data[username]@$fromdomain") . "&form[subject]=" . URLEncode("Re: [TODO] $data[item]"))?>
   </font>
   </td></tr></table>
  </td>
 </tr>

 <tr>
  <td colspan=3 bgcolor=#e0e0e0>
   <font face="<?php echo $cellfont?>">
   <b>Item Name</b>:<br>
   <input name=data[item] value="<?php echo massage($data["item"])?>" size=50>
   </font>
  </td>
 </tr>

 <tr>
  <td bgcolor=#e0e0e0>
   <font face="<?php echo $cellfont?>">
   <b>Group</b>:<br>
   <select name=data[groupid]>
   <?php echo groupSelect($PHP_AUTH_USER, $data[groupid])?>
   </select>
   </font>
  </td>
  <td bgcolor=#e0e0e0>
   <font face="<?php echo $cellfont?>">
   <b>Priority</b>:<br>
   <select name=data[priority]>
   <?php
    for ($p=0; $p<=10; $p++) {
     $selected="";
     if ($p == $data["priority"]) { $selected = "selected"; }
     echo "    <option $selected>$p\n";
    }
   ?>
   </select>
   </font>
  </td>
  <td bgcolor=#e0e0e0>
   <font face="<?php echo $cellfont?>">
   <b>Status</b>:<br>
   <select name=data[completed]>
    <?php if ($data[completed]):?>
    <option selected value=1>Completed
    <?php endif;?>
    <option value=0>Not Completed
    <option value=1>Completed
   </select>
   </font>
  </td>
 </tr>

 <tr>
  <td colspan=3 bgcolor=#e0e0e0>
   <font face="<?php echo $cellfont?>">
   <b>Description</b>:<br>
   <textarea name=data[description] rows=5 cols=50 wrap=soft><?php echo massage($data[description])?></textarea>
   </font>
  </td>
 </tr>
</table>

<?php if ($action == "New"):?>
<input type=submit name=action value="Add">
<?php else:?>
<input type=submit name=action value="Update">
<input type=submit name=action value="Delete">
<?php endif;?>

</form>

<?php elseif ($action == "Update"):?>
<?php 
 $data[username]=$PHP_AUTH_USER;
 $upd=MakeUpdateString($data);
 $query="UPDATE $dbconfig[todo_table] SET $upd WHERE id = $data[id] AND ($groupquery)";
 $result=dbQuery($query);
 include("features/todo.feature");
?>
<?php elseif ($action == "Delete"):?>
<?php 
 $query="DELETE FROM $dbconfig[todo_table] WHERE id = $data[id] AND ($groupquery)";
 $result=dbQuery($query);
 include("features/todo.feature");
?>
<?php elseif ($action == "Add"):?>
<?php 
 $data[username]=$PHP_AUTH_USER;
 $ins=MakeInsertString($data);
 $query="INSERT INTO $dbconfig[todo_table] ($ins[fields]) VALUES ($ins[values])";
 $result=dbQuery($query);
 include("features/todo.feature");
?>
<?php endif;?>
