Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dana Turner works for a large exclusive department store. She needs an applicati

ID: 3702579 • Letter: D

Question

Dana Turner works for a large exclusive department store. She needs an application to help her with processing sales of various items in 3 districts. The information is stored in a collection of text files (at least 4 including one from the instructor and 1 file that is empty). Each item's record consists of description, item type (C-clothing, F- Foot wear, B-health/beauty products, J-jewelry), product ID district 1 sales, district 2 sales, and district 3 sales. Each field will be separated by a The user interface (HTML file) will have the user input the following: Name of the input file Product ID Item Type Additional Controls needed (Process and Reset) When the user selects the Process control, the program (PHP file) should open the file and read the contents. (Note:Do not have any empty line in the file especially at the end of the input text file). Display the contents of the file in a table format. Be sure to display the item category entirely i.e input will be C, the display should be Clothing. Next, search for the Product ID entered by the user. If found, display all the information for that item. If not found, display an appropriate message. Finally, list the item description and total sales for all items in the Item Type Category in table format Save the program as departmentStoreApp.html and departmentStoreApp.php

Explanation / Answer

//departmentStoreApp.php

<html>
<body>
     <link rel="stylesheet" type="text/css" href="departmentStoreApp.css"/>
<?php
$stockFile = $_POST['productFile'];
$ID = $_POST['pid'];
$itemType = $_POST['item'];
$stockOpen = fopen("$stockFile","r") or exit("<h1>File is currently unavaible </h1>");
if(feof($stockOpen))
exit("<h1> File is empty </h1>");
else
{
$descArray =array();
$itemArray =array();
$proIDArray= array();
$d1Array = array();
$d2Array = array();
$d3Array = array();
   while(!feof($stockOpen)){
$stockRec = fgets($stockOpen);
list($desc,$item,$proID,$d1,$d2,$d3)= explode("*",$stockRec);
$descArray[]=$desc;
$itemArray[]=$item;
$proIDArray[]= $proID;
$d1Array[]= $d1;
$d2Array[]= $d2;
$d3Array[]= $d3;
//update of stock record
$stockRec = fgets($stockOpen);
}
}
fclose($stockOpen);
function C($type,$Array,$Array2,$Array3,$Array4, $Array5,$Array6){
$i = 0;
   if($type =="c")
   {
      print("<table border="4">");
         print ("clothing");
          for($i= 0; $i < count($Array); $i++){
               print("<tr><td>");
               print($Array[$i]);
               print("</td>");
         if ($Array[$i] == "c"){
               print("<td>");
               print($Array2[$i]);
               print("</td>");
               print("<td>");
               print($Array3[$i]);
               print("</td>");
               print("<td>");
               print($Array4[$i]);
               print("</td>");
               print("<td>");
               print($Array5[$i]);
               print("</td>");
               print("<td>");
               print($Array6[$i]);
               print("</td>");
               print("</tr>");
      $total = $Array4[$i] +$Array5[$i] +$Array6[$i];
print("</table>");
                  }
}print("<div>");
print("Total:" . $total);
print("</div>");
}
else if($type =="f")
   {
      print("<table border="4">");
         print ("footwear");
          foreach($Array as $j ){
              if ($j == "f"){
               print("<tr><td>");
               print($j);
               print("</td>");
               print("<td>");
               print($Array2[$i]);
               print("</td>");
               print("<td>");
               print($Array3[$i]);
               print("</td>");
               print("<td>");
               print($Array4[$i]);
               print("</td>");
               print("<td>");
               print($Array5[$i]);
               print("</td>");
               print("<td>");
               print($Array6[$i]);
               print("</td>");
               print("</tr>");
}$total = $Array4[$i] +$Array5[$i] +$Array6[$i];
$i++;}
print("</table>");
print("Total sales:". $total);
}
else if($type =="h")
   {
      print("<table border="4">");
         print ("Health & Beauty");
          foreach($Array as $j ){
              if ($j == "h"){
               print("<tr><td>");
               print($j);
               print("</td>");
               print("<td>");
               print($Array2[$i]);
               print("</td>");
               print("<td>");
               print($Array3[$i]);
               print("</td>");
               print("<td>");
               print($Array4[$i]);
               print("</td>");
               print("<td>");
               print($Array5[$i]);
               print("</td>");
               print("<td>");
               print($Array6[$i]);
               print("</td>");
               print("</tr>");
$total = $Array4[$i] +$Array5[$i] +$Array6[$i];
}
$i++;}
print("</table>");
print("<div>");
print("Total sales:". $total);
print("</div>");
}
else if($type=="j")
{
         print ("Jewelry");
        print("<table>");
          foreach($Array as $j ){
              if ($j == "j"){
               print("<tr><td>");
               print($j);
               print("</td>");
               print("<td>");
               print($Array2[$i]);
               print("</td>");
               print("<td>");
               print($Array3[$i]);
               print("</td>");
               print("<td>");
               print($Array4[$i]);
               print("</td>");
               print("<td>");
               print($Array5[$i]);
               print("</td>");
               print("<td>");
               print($Array6[$i]);
               print("</td>");
               print("</tr>");
$total = $Array4[$i] +$Array5[$i] +$Array6[$i];
$i++;}
print("</table>");
print("<div>");
print("Total:".$total);
print("</div>");
return $type;
}
function search($key,$IDarray,$Array2){
       print("<table>");
         print ("Product Results ");
          foreach($IDarray as $j){
              if ($key == $j){
               print("<tr><td>");
               print($j);
               print("</td>");
              print("<td>");
               print(each($Array2));
               print("</td>");
            }
               /* print("<td>");
               print($Array3[$i]);
               print("</td>");
               print("<td>");
               print($Array4[$i]);
               print("</td>");
               print("<td>");
               print($Array5[$i]);
               print("</td>");
               print("<td>");
               print($Array6[$i]);
               print("</td>");
               print("</tr>");*/
return $key;}
}}
print("</table>");
}
print("<div>");C($itemType,$itemArray,$descArray,$proIDArray, $d1Array,$d2Array,$d3Array); print("</div>");
print("<div>"); search($ID,$proIDArray,$descArray);print("</div>");?>
</body>
</html>

-------------------------------------------------------------------------------------------------
//departmentStoreApp.html
<html>
<head>
   <title> </title>
   <link rel="stylesheet" type="text/css" href="departmentStoreApp.css"/>
</head>
<body>
<h1> </h1>

<form action="departmentStoreApp.php" method="post">


<fieldset> <select name="productFile">
<option>inStock.txt</option>
<option>inStock2.txt </option>
<option>inStock3.txt </option>
<option>inStock4.txt </option>
</select>

<p><input type="radio" name ="item" value="c"> Clothing
<input type="radio" name ="item" value ="f"> Footwear
<input type="radio" name ="item" value ="h"> Health/Beauty
<input type="radio" name ="item" value ="j"> Jewelry</p>
<p>Product I.D. <input type ="text" size = "20" name ="pid"></p>
</fieldset>

<table>
      <tr>
      <td><input type="submit" value = "submit" Submit" ></td>
      <td><input type="reset" value = "Clear the form" ></td>
      </tr>
</table>
</form>
</body>
</html>
-------------------------------------------------------------------------------------------------
//departmentStoreApp.css
body{
background-color:Blue;
color:White;


}