Location: PHPKode > projects > NOLA > invitemcatupd.php
<? include('includes/main.php'); ?>
<? //invitemcatupd.php
     echo texttitle('Item Category Update');
     if ($id) { // if the user has submitted info
          if ($delete) { //if we should be deleting the entry
               checkpermissions('inv');
               if ($conn->Execute("delete from itemcategory where id=".sqlprep($id)) === false) {
                          echo texterror("Error deleting item category.");
               } else {
                          echo textsuccess("Item category deleted successfully.");
               };
          } elseif ($name) { //if we should update the entry
               checkpermissions('inv');
               if ($seasonbegin1==0) {
                    $seasonname1="all";
                    $seasonbegin1=1;
                    $seasonend1=12;
                    $seasonname2="";
                    $seasonbegin2=0;
                    $seasonend2=0;
                    $seasonname3="";
                    $seasonbegin3=0;
                    $seasonend3=0;
                    $seasonname4="";
                    $seasonbegin4=0;
                    $seasonend4=0;
               };
               if ($conn->Execute("update itemcategory set name=".sqlprep($name).", seasonname1=".sqlprep($seasonname1).", seasonname2=".sqlprep($seasonname2).", seasonname3=".sqlprep($seasonname3).", seasonname4=".sqlprep($seasonname4).", seasonbegin1=".sqlprep($seasonbegin1).", seasonbegin2=".sqlprep($seasonbegin2).", seasonbegin3=".sqlprep($seasonbegin3).", seasonbegin4=".sqlprep($seasonbegin4).", seasonend1=".sqlprep($seasonend1).", seasonend2=".sqlprep($seasonend2).", seasonend3=".sqlprep($seasonend3).", seasonend4=".sqlprep($seasonend4)." where id=".sqlprep($id)) === false) {
                          echo texterror("Error updating item category.");
               } else {
                          echo textsuccess("Item category updated successfully.");
               };
          } else {
          //display more info about the entry that the user can edit
               echo '<form action="invitemcatupd.php" method="post"><table><tr><td>Item Category:</td><td><input type="hidden" name="id" value="'.$id.'">';
               $recordSet = &$conn->Execute('select name,seasonname1,seasonname2,seasonname3,seasonname4,seasonbegin1,seasonbegin2,seasonbegin3,seasonbegin4,seasonend1,seasonend2,seasonend3,seasonend4 from itemcategory where id='.$id);
               if (!$recordSet->EOF) {
                    echo '<input type="text" name="name" size="30" value="'.$recordSet->fields[0].'"'.INC_TEXTBOX.'>';
                    $seasonname1=$recordSet->fields[1];
                    $seasonname2=$recordSet->fields[2];
                    $seasonname3=$recordSet->fields[3];
                    $seasonname4=$recordSet->fields[4];
                    $seasonbegin1=$recordSet->fields[5];
                    $seasonbegin2=$recordSet->fields[6];
                    $seasonbegin3=$recordSet->fields[7];
                    $seasonbegin4=$recordSet->fields[8];
                    $seasonend1=$recordSet->fields[9];
                    $seasonend2=$recordSet->fields[10];
                    $seasonend3=$recordSet->fields[11];
                    $seasonend4=$recordSet->fields[12];

               };
               if (!$seasonbegin1) {
                    $seasonbegin1=1;
                    $seasonend1=12;
               };
               echo '<tr><th>Season Name</th><th>Beginning Month</th><th>Ending Month</th></tr>';
               echo '<tr><td><input type="text" name="seasonname1" maxlength="20" value="'.$seasonname1.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonbegin1" value="'.$seasonbegin1.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonend1" value="'.$seasonend1.'"'.INC_TEXTBOX.'></td></tr>';
               echo '<tr><td><input type="text" name="seasonname2" maxlength="20" value="'.$seasonname2.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonbegin2" value="'.$seasonbegin2.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonend2" value="'.$seasonend2.'"'.INC_TEXTBOX.'></td></tr>';
               echo '<tr><td><input type="text" name="seasonname3" maxlength="20" value="'.$seasonname3.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonbegin3" value="'.$seasonbegin3.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonend3" value="'.$seasonend3.'"'.INC_TEXTBOX.'></td></tr>';
               echo '<tr><td><input type="text" name="seasonname4" maxlength="20" value="'.$seasonname4.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonbegin4" value="'.$seasonbegin4.'"'.INC_TEXTBOX.'></td><td><input type="text" name="seasonend4" value="'.$seasonend4.'"'.INC_TEXTBOX.'></td></tr>';

               echo '</select></td></tr></table><input type="submit" value="Save Changes"></form> <a href="javascript:confirmdelete(\'invitemcatupd.php?delete=1&id='.$id.'\')">Delete this Item Category</a>';
          };
     } else { //display item categories, let the user pick one to edit
          $recordSet = &$conn->Execute('select id,name from itemcategory order by name');
          if (!$recordSet->EOF) {
              echo '<form action="invitemcatupd.php" method="post"><table><tr><td>Item Category:</td><td><select name="id"'.INC_TEXTBOX.'>';
              while (!$recordSet->EOF) {
                 echo '<option value="'.$recordSet->fields[0].'">'.$recordSet->fields[1]."\n";
                 $recordSet->MoveNext();
              };
              echo '</select></td></tr></table><input type="submit" value="Edit"></form>';
          };
          echo '<a href="invitemcatadd.php">Add new Item Category</a>';
     };
?>
<? include('includes/footer.php'); ?>
Return current item: NOLA