Friday 22 June 2012

PhP Application Source Code

Program Start

The document type is set to XHTML 1.1. The cascading stylesheet stylea.css controls the elements on the screen, whereas the second stylesheet stylep.css controls printed elements. The include statements add subroutine libraries to the module: all the MySQL functions are in their own file subconfig.php, configuration functions similarly in subconfig.php, often repeated form headings and input prompts are in subdisplay.php, and, finally, the date and time validation routines are in subtimedate.php.
<html >
<head>
 <title>Item Maintenance</title>
 <link type="text/css" rel="stylesheet" href="../stylea.css" />
 <link type="text/css" rel="stylesheet" media="print" href="../stylep.css" />
</head>
<body>
<?php
/* maintitem.php                   */
/* Item Maintenance 
*/
*/
include("../../sub/submysql.php");
include("../../sub/subconfig.php");
include("../../sub/subdisplay.php");
include("../../sub/subtimedate.php");

/* HTML special characters converted before data is displayed        */
/* CRLF in description stored in the database to retain formatting   */

Item Form

The presentation of the item form on the screen is a function which has the form fields as input parameters, with the address or URL of the menu. The list of all the subcategories and and the supplier list are available to the function as global variables defined in the main module. If an item code has been entered on the form, the value of the subcategory and the supplier are saved.
The form is defined using the POST method. The action element tells the web server to return to the same module once a button has been pressed. All the input fields like Item, Subcategory and Description are defined as select fields inside table detail elements. The dropdown list of subcategories and suppliers involves a MySQL command mysqli_fetch_array getting the list from the input array where the list has been prepared at the very beginning of the execution of the module.
The table row containing hidden fields passes the value of the previously stored codes to the next stage in the program loop. The table row starting with the input type submit and value First, defines the buttons using which the user can navigate the item table back and forth and select the type of operation like Add, Delete and Update. The last button Menu is added to the end of the form in a subroutine, stored in the library subdisplay.php.
/ ----------
// item form
function show_item($item, $subcategory, $description, $supplier, $item_index, $menu) {
global $sql_result_subcategories, $sql_result_suppliers;
  if ($item) {
     $sel_subcategory = $subcategory;
     $sel_supplier = $supplier;
   }
?>
   <form method="post" name="maintitem" action="<?php echo $_SERVER['PHP_SELF'];?>">
   <table class="entry">
   <tbody>
     <tr>
       <td><strong>Item</strong></td>  
<?php
     echo "<td><input type=\"text\" size=\"50\" name=\"item\" value=\"$item\" /></td>
     </tr>
     <tr>
       <td><strong>Subcategory</strong></td>
       <td><select name=\"sel_subcategory\"><option value=\"$subcategory\">$subcategory</option>";
     while ($row = mysqli_fetch_array($sql_result_subcategories)) {
         $subcat_opt = $row['subcategory'];
         echo "<option value=\"$subcat_opt\">$subcat_opt</option>";
       }
     echo "</select></td>
     </tr>
     <tr>
       <td><strong>Description</strong></td>
        <td><input type=\"text\" size=\"50\" name=\"description\" value=\"$description\" /></td>
     </tr>
     <tr>
       <td><strong>Supplier</strong></td>

       <td><select name=\"sel_supplier\"><option value=\"$supplier\">$supplier</option>";
     while ($row = mysqli_fetch_array($sql_result_suppliers)) {
         $supplier_opt = $row['supplier'];
         echo "<option value=\"$supplier_opt\">$supplier_opt</option>";
       }
     echo "</select></td>
     </tr>
<tr><td><input type=\"hidden\" name=\"item_code\" value=\"$item\"/></td>
<td><input type=\"hidden\" name=\"item_index\" value=\"$item_index\" /></td></tr>";
?>
    <tr><td></td><td><table><tbody><tr>
<td><input type="submit" value="First" name="first" /></td>
<td><input type="submit" value="Previous" name="previous" /></td>
<td><input type="submit" value="Next" name="next" /></td>
<td><input type="submit" value="Last" name="last" /></td><td>&nbsp;</td>
<td><input type="submit" value="Reset" name="reset" /></td><td>&nbsp;</td><td>&nbsp;</td>
<td><input type="submit" value="Clear" name="clear" /><td><td>&nbsp;</td><td>&nbsp;</td>
<td><input type="submit" value="Add" name="add" /></td>
<td><input type="submit" value="Update" name="update" /></td>
<td><input type="submit" value="List" name="list" />
<td><input type="submit" value="Delete" name="delete" />
</tr></tbody></table></td>
   </tr>
   </tbody>
  </table></form>
<?php
  sub_button($menu, "Menu");
  return;
 }

Item Array and Lookup Tables

The function create_item_list($db_connection) reads all the items and writes them to an array. The inbuilt addslashes function escapes special characters quote, double quote, backslash and the NUL byte with a backslash before the variable is written into the array. The arrays containing the items, the subcategories and the suppliers are global variables.
The error handling routines use functions from subroutine libraries which display standard headings or buttons on the form. The Reset button clears the form and the Menu button returns the control back to the menu. The URL for the menu has been defined in the configuration table, see subconfig.php.
// -----------------
// create item array , list of subcategories and suppliers
function create_item_list($db_connection) {
global $item_array, $sql_result_subcategories, $sql_result_suppliers;

// sql query - list items
 $sql_item_list = "SELECT item, subcategory, description, supplier FROM item ORDER BY item";

// list items
 $sql_item_list_result = sub_query($sql_item_list, $db_connection);

 if (!$sql_item_list_result) {
    sub_company_heading($my_company, $module_name, $application);
    sub_message_error("Unable to access item table");
    sub_button($module, "Reset");
    sub_button($menu, "Menu");
    exit;
  }

// create item array
 $item_index = 0;

// escape single, double quote, backslash
 while ($row = mysqli_fetch_array($sql_item_list_result)) {
      $item_esc = addslashes($row['item']);
      $subcategory_esc = addslashes($row['subcategory']);
      $description_esc = addslashes($row['description']);
      $supplier_esc = addslashes($row['supplier']);
      $item_array[$item_index] = array($item_esc, $subcategory_esc, $description_esc, $supplier_esc);
      $item_index += 1;
   }
 $last_item = $item_index - 1;

// sql query - list of subcategories
 $sql_list_subcategories = "SELECT subcategory, category, description from subcategory ORDER BY category, subcategory";

// execute SQL query
 $sql_result_subcategories = sub_query($sql_list_subcategories, $db_connection);

 if (!$sql_result_subcategories) {
   sub_company_heading($my_company, $module_name, $application);
   sub_message_error("Unable to access subcategory table");
   sub_button($module, "Reset");
   sub_button($menu, "Menu");
   exit;
  }

// sql query - list of suppliers
 $sql_list_suppliers = "SELECT supplier, address, contact, telephone FROM supplier ORDER BY supplier";

// execute SQL query
 $sql_result_suppliers = sub_query($sql_list_suppliers, $db_connection);

 if (!$sql_result_suppliers) {
   sub_company_heading($my_company, $module_name, $application);
   sub_message_error("Unable to access supplier table");
   sub_button($module, "Reset");
   sub_button($menu, "Menu");
   exit;
  }
//  -1 if no items
 return $last_item;
 }

Item Functions

The function no_item_data() displays the item maintenance form with blank fields. It first displays the standard headings and then displays the item form with a blank item, subcategory, description and supplier.
The function get_item_html($item_index) returns the item fields associated using the input parameter as index to the item array. The inbuilt function stripslashes removes the backslashes as escape characters. The inbuilt function htmlspecialchars converts special characters, e.g. &, to their HTML equivalent string, e.g. &amp;.
The function get_item_esc($item_index) returns the item fields as above, but without stripping the backslashes.
// ------------------------------
// display item form with no data
function no_item_data($item_index, $my_company, $module_name, $menu, $application) {
 sub_company_heading($my_company, $module_name, $application);
 show_item("", "", "", "", $item_index, $menu);
 return;
 }

// ---------------------------------------------------
// extract item data from item array and use htmlspecialchars
function get_item_html($item_index) {
global $item_array;

  if (!($item_index < 0)) {
    list($item_esc, $subcategory_esc, $description_esc, $supplier_esc) = $item_array[$item_index];
    $item_html = htmlspecialchars(stripslashes($item_esc), ENT_QUOTES);
    $subcategory_html = htmlspecialchars(stripslashes($subcategory_esc), ENT_QUOTES);
    $description_html = htmlspecialchars(stripslashes($description_esc), ENT_QUOTES);
    $supplier_html = htmlspecialchars(stripslashes($supplier_esc), ENT_QUOTES);
    return array($item_html, $subcategory_html, $description_html, $supplier_html);
   } else {
       return array("", "", "", "");
     }
}

// ---------------------------------------------------
// extract item data from item array, with backslashes
function get_item_esc($item_index) {
global $item_array;
 if (!($item_index < 0)) {
    list($item_esc, $subcategory_esc, $description_esc, $supplier_esc) = $item_array[$item_index];
    return array($item_esc, $subcategory_esc, $description_esc, $supplier_esc);
  } else {
  return array("", "", "", "");
    }       
}

Main Module

The main module starts by setting the variables for the name of the module and the database. It creates a database connection using the subconfig($db) function and returns a list with a few parameters like the name of the company and the application for the forms, the date format, the file name of the menu program. The module then creates an array with the list of items from the item table. The variable $last_item is the index of the last item in the array, or the total number of items.
The module then checks if any buttons had been pressed before the module was launched. The name of the button is assigned as the value of the variable $switch, to be used in the following case statement which directs the module to the right routine for processing.
// ---------------------------------
// main module
// ---------------------------------

 $module_name="Item Maintenance";
 $module="maintitem.php";
 $db = "billing";

// get config variables and create connection
 list($my_company, $date_format, $menu, $database, $date_separator, $db_connection, $application) = sub_config($db);  

 $first_item = 0;
 $last_item = create_item_list($db_connection);

// check if form was submitted and which button was pressed, set switch
 $switch = "first";

 if (isset($_POST['update']))  {
   $switch = "update";
  }
 if (isset($_POST['previous']))  {
   $switch = "previous";
  }
 if (isset($_POST['next']))  {
   $switch = "next";
  }
 if (isset($_POST['first']))  {
   $switch = "first";
  }
 if (isset($_POST['last']))  {
   $switch = "last";
  }
 if (isset($_POST['reset']))  {
   $switch = "reset";
  }
 if (isset($_POST['clear']))  {
   $switch = "clear";
  }
 if (isset($_POST['add']))  {
   $switch = "add";
  }
 if (isset($_POST['list']))  {
   $switch = "list";
  }
 if (isset($_POST['delete']))  {
   $switch = "delete";
  }

First Item

The user has pressed the button First to get to the first item in the item table. If the item table is empty, a blank item form is displayed. Otherwise the details of the first item are retrieved and displayed on the form.
switch($switch) {
//---------------------------------------------------
  case "first":
// start case - first item

  $item_index = $first_item;
  if ($last_item < 0) {
     no_item_data($last_item, $my_company, $module_name, $menu, $application);
     exit;
   }

// get item details from array processed for html
  list($item_html, $subcategory_html, $description_html, $supplier_html) = get_item_html($item_index);

// display form
  sub_company_heading($my_company, $module_name, $application);
  show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
    
  break;
// end case first

Add Item

The user has pressed the Add button. The variables are retrieved from the form and additional leading or trailing spaces are trimmed. Two additional versions of variables are generated by escaping certain characters and converting characters like & to their HTML equivalent strings like &amp;. The program checks the input fields and gives a warning if any of them are blank.
An insert statement is prepared using the version of the input variables where the special characters have been escaped. The item code is then used looked up from the item table and a warning is displayed if the item already exists. The new item is inserted into the item table and a message is displayed at the bottom of the form, if the item was added, or if an error occurred.
The item index '$new_item_index' is set to point past the last item in the item table, to prevent the Previous and Next buttons from working after a new item has been added.
//---------------------------------------------------
 case "add":
// start case - add pressed

// retrieve variables
  $item = trim($_POST['item']);
  $subcategory = trim($_POST['sel_subcategory']); 
  $description = trim($_POST['description']);
  $supplier = trim($_POST['sel_supplier']);
  $item_index = $_POST['item_index'];
 
// escape quotes and slash
  $item_esc = addslashes($item);
  $subcategory_esc = addslashes($subcategory);
  $description_esc = addslashes($description);
  $supplier_esc = addslashes($supplier);
  
// htmlspecialchars because of ampersand (&)
  $item_html = htmlspecialchars($item, ENT_QUOTES);
  $subcategory_html = htmlspecialchars($subcategory, ENT_QUOTES);
  $description_html = htmlspecialchars($description, ENT_QUOTES);
  $supplier_html = htmlspecialchars($supplier, ENT_QUOTES);
 
// validate input
  if ((!$item_esc) or (!$subcategory_esc) or (!$description_esc) or (!$supplier_esc)) {
     sub_company_heading($my_company, $module_name, $application);
     show_item($item_html, $subcategory_html, $description_html, $supplier_html, $last_item + 1, $menu);
     sub_message_warning("At least one field is blank");
     exit;
   }

// sql query - insert
 $sql_insert = "INSERT INTO item (item, subcategory, description, supplier) VALUES ('$item_esc', '$subcategory_esc', '$description_esc', '$supplier_esc')";

// sql query - lookup
 $sql_lookup = "SELECT item, subcategory, description, supplier FROM item WHERE item='$item_esc'";

// lookup and get result
 $sql_result = sub_query($sql_lookup,$db_connection);

 while ($row = mysqli_fetch_array($sql_result)) {
   $item2 =  $row['item'];
   $subcategory2 =  $row['subcategory']; 
   $description2 =  $row['description'];
   $supplier2 =  $row['supplier'];
  
// html
   $item2_html = htmlspecialchars($item2, ENT_QUOTES);
   $subcategory2_html = htmlspecialchars($subcategory2, ENT_QUOTES);
   $description2_html = htmlspecialchars($description2, ENT_QUOTES);
   $supplier2_html = htmlspecialchars($supplier2, ENT_QUOTES);
  }

 if (isset($item2)) {
    sub_company_heading($my_company, $module_name, $application);
    show_item($item2_html, $subcategory2_html, $description2_html, $supplier2_html, $last_item, $menu);
    sub_message_error("Item already exists");
    exit;
  }

 $sql_result = sub_query($sql_insert,$db_connection);

// dummy item_index
 $new_item_index = $last_item + 1;

 if (!$sql_result) {
    sub_company_heading($my_company, $module_name, $application);
    show_item($item_html, $subcategory_html, $description_html, $supplier_html, $new_item_index, $menu);
    sub_message_error("Unable to add item");
  } else {
     sub_company_heading($my_company, $module_name, $application);
     show_item($item_html, $subcategory_html, $description_html, $supplier_html, $new_item_index, $menu);
     sub_message_info("A new item was added");
  }

 break;
// end case add

Update Item

The user has pressed the Update button. The variables are retrieved from the form and additional leading or trailing spaces are trimmed. Two additional versions of variables are generated by escaping certain characters and converting characters like & to their HTML equivalent strings like &amp;. The program checks the input fields and gives a warning if any of them are blank.
An update statement is prepared using the version of the input variables where the special characters have been escaped. The item is then updated in the item table and a message is displayed at the bottom of the form, if the item was updated or if an error occurred.
//---------------------------------------------------
 case "update":
// start case - update item
// item_index from the original item
// item name is the key and cannot be changed

// retrieve variables
  $item = trim($_POST['item']);
  $subcategory = trim($_POST['sel_subcategory']); 
  $description = trim($_POST['description']);
  $supplier = trim($_POST['sel_supplier']);
  $item_index = $_POST['item_index'];
 
// escape quotes and slash
  $item_esc = addslashes($item);
  $subcategory_esc = addslashes($subcategory);
  $description_esc = addslashes($description);
  $supplier_esc = addslashes($supplier);
  
// htmlspecialchars because of ampersand (&)
  $item_html = htmlspecialchars($item, ENT_QUOTES);
  $subcategory_html = htmlspecialchars($subcategory, ENT_QUOTES);
  $description_html = htmlspecialchars($description, ENT_QUOTES);
  $supplier_html = htmlspecialchars($supplier, ENT_QUOTES);
 
// validate input
  if ((!$item_esc) or (!$subcategory_esc) or (!$description_esc) or (!$supplier_esc)) {
     sub_company_heading($my_company, $module_name, $application);
     show_item($item_html, $subcategory_html, $description_html, $supplier_html, $last_item + 1, $menu);
     sub_message_warning("At least one of the fields is blank");
     exit;
   }

// *******************
// validate item index
// *******************
 if (!is_numeric($item_index) or ($item_index > $last_item) or ($item_index < 0)) {
    sub_company_heading($my_company, $module_name, $application);
    show_item($item_html, $subcategory_html, $description_html, $supplier_html, $last_item + 1, $menu);
    sub_message_error("Item does not exist, it cannot be updated");
    exit;
  }

// ***********************
// cannot change item key 
// ***********************
// get item details from array
 list($item2_esc, $subcategory2_esc, $description2_esc, $supplier2_esc) = get_item_esc($item_index);

// compare form to array
 if (!($item_esc == $item2_esc)) {
    sub_company_heading($my_company, $module_name, $application);
    show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
    sub_message_error("Item code was changed, item cannot be updated");
    exit;
  }
 
// sql query - update a row in item table
   $sql_update_item = "UPDATE item SET subcategory='$subcategory_esc', description='$description_esc', supplier='$supplier' WHERE item='$item'";
   
   $sql_update_item_result = sub_query($sql_update_item, $db_connection);

   if (!$sql_update_item_result) {
       sub_company_heading($my_company, $module_name, $application);
       show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
  sub_message_error("Unable to update item");
 exit;
     }

// display form
  sub_company_heading($my_company, $module_name, $application);
  show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu); 
  sub_message_info("Item was updated");

  break;
// end case update

Delete Item

The user has pressed the Delete button. The variables are retrieved from the form and additional leading or trailing spaces are trimmed. Two additional versions of variables are generated by escaping certain characters and converting characters like & to their HTML equivalent strings like &amp;. The program checks the item field and gives a warning if it points to a non-existent item in the item array.
A delete statement is prepared using the version of the item variable where the special characters have been escaped. The item is then deleted from the item table and a message is displayed at the bottom of the form, if the item was deleted or if an error occurred.
//---------------------------------------------------
 case "delete":
// start case delete

// retrieve variables
  $item = trim($_POST['item']);
  $subcategory = trim($_POST['sel_subcategory']); 
  $description = trim($_POST['description']);
  $supplier = trim($_POST['sel_supplier']);
  $item_index = $_POST['item_index'];
 
// escape quotes and slash
  $item_esc = addslashes($item);
  
// htmlspecialchars because of ampersand (&)
  $item_html = htmlspecialchars($item, ENT_QUOTES);
  $subcategory_html = htmlspecialchars($subcategory, ENT_QUOTES);
  $description_html = htmlspecialchars($description, ENT_QUOTES);
  $supplier_html = htmlspecialchars($supplier, ENT_QUOTES); 

// *******************
// validate item index
// *******************
 if (!is_numeric($item_index) or ($item_index > $last_item) or ($item_index $<) {
    sub_company_heading($my_company, $module_name, $application);
    show_item($item_html, $subcategory_html, $description_html, $supplier_html, $last_item + 1, $menu);
    sub_message_error("Item does not exist, it cannot be deleted");
    exit;
  }

// ***********************
// cannot change item key 
// ***********************
// get item details from array
 list($item2_esc, $subcategory2_esc, $description2_esc, $supplier2_esc) = get_item_esc($item_index);

// compare item
 if (!($item_esc == $item2_esc)) {
    sub_company_heading($my_company, $module_name, $application);
    show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
    sub_message_error("Item code was changed, item cannot be deleted");
    exit;
  }

// sql query
 $sql_delete = "DELETE FROM item WHERE item='$item_esc'";

// execute delete query
 $sql_delete_result = sub_query($sql_delete, $db_connection);

 if (!$sql_delete_result) {
    sub_company_heading($my_company, $module_name, $application);
    show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
    sub_message_error("Unable to delete from item table");
    exit;
  } else {
      sub_company_heading($my_company, $module_name, $application);
      show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
      sub_message_info("Item was deleted");
      exit;
  }

 break;
// end case delete

Previous Item

The user has pressed the Previous button. The index pointing to the current item in the item array is retrieved from the form and validated. If the value of the index is outside the array, a blank form is displayed. The index is decremented by one, except when the current item is the first item in the array, in which case the index is changed to point to the last item. The item details are retrieved from the item array and the item form is displayed.
//---------------------------------------------------
  case "previous":
// start case - previous pressed

// retrieve hidden field from form
  $item_index = $_POST['item_index'];
 
  if (!is_numeric($item_index) or ($item_index > $last_item) or ($item_index < 0)) {
     no_item_data($last_item, $my_company, $module_name, $menu, $application);
     exit;
   }

// decrement item pointer, first --> last
  if (($item_index > 0) and ($item_index <= $last_item)) {
     $item_index -= 1; 
    } else {
     $item_index = $last_item;
   }

// get item details from array processed for html
  list($item_html, $subcategory_html, $description_html, $supplier_html) = get_item_html($item_index);

// display form
  sub_company_heading($my_company, $module_name, $application);
  show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);

  break;
// end case previous

Next Item

The user has pressed the Next button. The index pointing to the current item in the item array is retrieved from the form and validated. If the value of the index is outside the array, a blank form is displayed. The index is incremented by one, except when the current item is the last item in the array, in which case the index is changed to point to the first item. The item details are retrieved from the item array and the item form is displayed.
//---------------------------------------------------
  case "next":
// start case - next pressed

// retrieve hidden field from form
  $item_index = $_POST['item_index'];
 
  if (!is_numeric($item_index) or ($item_index > $last_item) or ($item_index < 0)) {
     no_item_data($last_item, $my_company, $module_name, $menu, $application);
     exit;
   }
 
// increment item pointer, last --> first
  if (($item_index >= 0) and ($item_index < $last_item)) {
     $item_index += 1; 
    } else {
     $item_index = 0;
   }

  list($item_html, $subcategory_html, $description_html, $supplier_html) = get_item_html($item_index);

// display the form
  sub_company_heading($my_company, $module_name, $application);
  show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);

  break;
// end case next

Last Item

The user has pressed the Last button. The index pointing to the last item in the item array is validated. If the value of the index is less than zero, meaning that the item array is empty, a blank form is displayed. Otherwise the item details are retrieved from the item array and the item form is displayed.
//---------------------------------------------------
  case "last":
// start case - last pressed

  $item_index = $last_item;

  if ($last_item < 0) {
     no_item_data($last_item, $my_company, $module_name, $menu, $application);
     exit;
   }

  list($item_html, $subcategory_html, $description_html, $supplier_html) = get_item_html($item_index);
 
// display the form
  sub_company_heading($my_company, $module_name, $application);
  show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
 
  break;
// end case last

Reset Item

The user has pressed the Reset button. The index pointing to the current item in the item array is retrieved from the form and validated. If the value of the index is outside the array, a blank form is displayed. The item details are retrieved from the item array and the item form is displayed.
//---------------------------------------------------
  case "reset":
// start case - reset pressed

// retrieve hidden field from form
  $item_index = $_POST['item_index'];
 
  if (!is_numeric($item_index) or ($item_index > $last_item) or ($item_index < 0)) {
     no_item_data($last_item, $my_company, $module_name, $menu, $application);
     exit;
   }
 
  list($item_html, $subcategory_html, $description_html, $supplier_html) = get_item_html($item_index);
 
// display the form
  sub_company_heading($my_company, $module_name, $application);
  show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);
 
  break;
// end case reset

Clear Item

The user has pressed the Clear button. The index pointing to the current item in the item array is retrieved from the form. The item variables are set to blank and the item form is displayed.
//---------------------------------------------------
  case "clear":
// start case - clear pressed

// retrieve hidden field from form
  $item_index = $_POST['item_index'];
 
  $item_html = "";
  $subcategory_html = "";
  $description_html = "";
  $supplier_html = "";

// display the form
  sub_company_heading($my_company, $module_name, $application);
  show_item($item_html, $subcategory_html, $description_html, $supplier_html, $item_index, $menu);

  break;
// end case clear

List Items

The user has pressed the List button. The current date is retrieved for the heading of the listing. The report headings are sent to the HTML page, and each item is retrieved from the item array and listed in a table format on the HTML page.
The default case is included in case the program logic in the case statement does not cover all the values of the switch set in the beginning of the module.
//---------------------------------------------------
 case "list":
// start case - list item table from the item array

 list($timestamp, $today, $local_date) = get_date($date_format, $date_separator);

 $item_index = 0;
 echo "<h1>$my_company</h1><h1>&nbsp;</h1><h1>Inventory Items &nbsp; &nbsp; &nbsp; $local_date</h1><h1>&nbsp;</h1>
   <table><tbody>
   <tr style=\"font-family: helvetica; background-color: #FFEC69; font-weight: bold\">";
 echo "<td>Item</td><td style=\"background-color: #FFFFFF;\">&nbsp;</td><td>Subcategory</td><td>Description</td><td>Supplier</td></tr>"; 
 while (!($item_index > $last_item)) { 
     list($item_html, $subcategory_html, $description_html, $supplier_html) = get_item_html($item_index);
     $item_index += 1;
     echo "<tr><td>$item_html</td><td>&nbsp;</td><td>$subcategory_html</td><td>$description_html</td><td>$supplier_html</td></tr>";
   }
 echo "</tbody></table>"; 
 echo "<p><b>$item_index &nbsp; items</b></p>";
 break;
// end case list

//---------------------------------------------------
 default:
   sub_company_heading($my_company, $module_name, $application);
   sub_message_error("case = default");
 }
?>
</body>
</html>

0 comments:

Post a Comment