Code Part 2
<?php
if (isset($_POST['submit']))
{
$platform= $_POST['platform']; //defining variable before use
$owner= $_POST['owner']; //defining variable before use
if ($platform=="Android") {
if ($owner=="Mobile Team") {
//prepare 'mtand.txt' file for data
$fh = fopen("mtand.txt","a+") or die("File Close"); }
}
if ($platform=="iOS") {
if ($owner=="Mobile Team") {
//prepare 'mtios.txt' file for data
$fh = fopen("mtios.txt","a+") or die("File Close"); }
}
if ($platform=="MISC") {
if ($owner=="Mobile Team") {
//prepare 'mtmisc.txt' file for data
$fh = fopen("mtmisc.txt","a+") or die("File Close"); }
}
if ($platform=="Android") {
if ($owner=="Biz Dev") {
//prepare 'bdand.txt' file for data
$fh = fopen("bdand.txt","a+") or die("File Close"); }
}
if ($platform=="iOS") {
if ($owner=="Biz Dev") {
//prepare 'bdios.txt' file for data
$fh = fopen("bdios.txt","a+") or die("File Close"); }
}
if ($platform=="MISC") {
if ($owner=="Biz Dev") {
//prepare 'bdmisc.txt' file for data
$fh = fopen("bdmisc.txt","a+") or die("File Close"); }
}
$name= $_POST['name'];
$mdn= $_POST['mdn'];
$carrier= $_POST['carrier'];
$meid= $_POST['meid'];
$version= $_POST['version'];
$date= $_POST['date'];
$notes= $_POST['notes'];
$voice= $_POST['voice'];
/* $platform= $_POST['platform'] */
/* $owner= $_POST['owner'] */
//setup implementation rules for notes
$notes=stripslashes($notes);
//implement validation
if (empty($name)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($mdn)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($carrier)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($meid)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($version)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($date)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
else {
//assemble the data into a line variable
$data= $name . ":" . $mdn . ":" . $carrier . ":" . $meid . ":" . $version . ":" . $date . ":" . $notes . ":" . $voice . ":" . "\r\n";
//Figure out what choice was made so that data can be written to correct text file
if ($platform=="Android") {
if ($owner=="Mobile Team") {
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";
//write the data to the file
fwrite($fh, $data);
$mtandcount = ''; //defining variable before use. Variable is used to count devices
if ($mtandcount == null) { //setting initial value to 0, will increment with every added device
$mtandcount = 0; }
//counter for devices
if ($fh = fopen('mtand.txt', 'r')) {
while (!feof($fh)) {
if (fgets($fh)) {
$mtandcount++;
}
}
}
/* adding a print or echo line here will show that $mtandcount is increasing properly, however, it does not reflect at the top of the script */
}
}
//Figure out what choice was made so that data can be written to correct text file
if ($platform=="iOS") {
if ($owner=="Mobile Team") {
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";
//write the data to the file
fwrite($fh, $data);
}
}
//Figure out what choice was made so that data can be written to correct text file
if ($platform=="MISC") {
if ($owner=="Mobile Team") {
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";
//write the data to the file
fwrite($fh, $data);
}
}
//Figure out what choice was made so that data can be written to correct text file
if ($platform=="Android") {
if ($owner=="Biz Dev") {
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";
//write the data to the file
fwrite($fh, $data);
}
}
//Figure out what choice was made so that data can be written to correct text file
if ($platform=="iOS") {
if ($owner=="Biz Dev") {
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";
//write the data to the file
fwrite($fh, $data);
}
}
//Figure out what choice was made so that data can be written to correct text file
if ($platform=="MISC") {
if ($owner=="Biz Dev") {
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";
//write the data to the file
fwrite($fh, $data);
}
}
//close the file
fclose($fh);
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{
font: 10px Verdana, Arial, Helvetica, sans-serif;
}
</style>
<?php
$output = ''; //defining variable before use. Line 255
if($output!=""){ echo $output; } ?>
<form action = "<? echo $_SERVER['PHP_SELF']?>" method = "post">
<div style="border:2px solid #cccccc;margin:8px;padding:8px;width:600px;">
<table width="80%">
<tr><td><b>Enter Device Name: </b></td><td><input name="name" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter MDN: </b></td><td><input name="mdn" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Carrier: </b></td><td><input name="carrier" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter MEID/IMEI: </b></td><td><input name="meid" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter OS Version: </b></td><td><input name="version" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Received Date: </b></td><td><input name="date" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Notes: </b></td><td><input name="notes" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Is Voice Enabled (Yes/No):</b></td><td>
<select name="voice" style="width:200px;">
<option>Yes</option>
<option>No</option>
</select></td></tr>
<tr><td><b>Select Device Platform (Android/iOS/MISC):</b></td><td>
<select name="platform" style="width:200px;">
<option>Android</option>
<option>iOS</option>
<option>MISC</option>
</select></td></tr>
<tr><td><b>Select Device Owner (Mobile Team/Biz Dev):</b></td><td>
<select name="owner" style="width:200px;">
<option>Mobile Team</option>
<option>Biz Dev</option>
</select></td></tr>
</table>
<input type="submit" name="submit" value="Update" />
</div>
</form>
</tr>
</table>
</ul>
</li>
</ul>
</div>
<?php
if ($mtandcount == null) { //setting initial value to 0, will increment with every added device
$mtandcount = 0; }
$fh = fopen("mtand.txt","a+") or die("File Close");
//counter for devices
if ($fh = fopen('mtand.txt', 'r')) {
while (!feof($fh)) {
if (fgets($fh)) {
}
}
}
print "<font size='6'>DEVICE INVENTORY (Android): MOBILE TEAM ($mtandcount)</font><br>";
//close the file
fclose($fh);
$textfile = 'mtand.txt';
$data = ''; //defining variable before use
$data1 = ''; //defining variable before use
if (file_exists($textfile) && is_readable($textfile))
{
$file = file($textfile);
foreach ($file as $line)
{
//separate each element and store in temp array.
$tmp = explode(":", $line);
//assign each element to array.
$data[] = array('name' => $tmp[0], 'mdn' => $tmp[1], 'carrier' => $tmp[2], 'meid' => $tmp[3], 'version' => $tmp[4], 'date' => $tmp[5], 'notes' => $tmp[6], 'voice' => $tmp[7]);
}
}
echo "<table cellspacing='0' cellpadding='14'>";
if ($data!=""){
echo "<tr><th style='background:#6699FF'>Device Name</th><th style='background:#6699FF'>MDN</th><th style='background:#6699FF'>Carrier</th><th style='background:#6699FF'>MEID/IMEI</th><th style='background:#6699FF'>OS Version</th><th style='background:#6699FF'>Received Date</th><th style='background:#6699FF'>Notes</th><th style='background:#6699FF'>Voice</th></tr>";
foreach ($data as $key => $row)
{
$name[$key]= $row['name'];
$mdn[$key]= $row['mdn'];
$carrier[$key]= $row['carrier'];
$meid[$key]= $row['meid'];
$version[$key]= $row['version'];
$date[$key]= $row['date'];
$notes[$key]= $row['notes'];
$voice[$key]= $row['voice'];
echo "<tr><td>{$name[$key]}</td><td>{$mdn[$key]}</td><td>{$carrier[$key]}</td><td>{$meid[$key]}</td><td>{$version[$key]}</td><td>{$date[$key]}</td><td>{$notes[$key]}</td><td>{$voice[$key]}</td></tr>";
}
}
echo "</table>";
?>
</body>
</html>