Code: Select all
<html>
<head>
<title>SMTNW Maintenance Tracker</title>
</head>
<body>
<?php
$currdate = getdate();
$datestring = date($currdate['year']."-".$currdate['mon']."-".$currdate['mday']);
$qtr_array = array('January','April','July','October');
$username="user";
$password="password";
$database="maintenance";
$frequency="('daily'";
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die("Unable to connect to $database");
if ($currdate['wday'] == 1)
$frequency = $frequency . ",'weekly'";
if ($currdate['mday'] > 29 || $currdate['mday'] < 4){
if (in_array($currdate['month'],$qtr_array)){
$frequency = $frequency . ",'quarterly'";
}
$frequency = $frequency . ",'monthly'";
}
if ($currdate['month'] = "May"){
if ($currdate['mday'] == 5){
$frequency = $frequency . ",'annually'";
}
}
$frequency = $frequency . ")";
$query = "SELECT m.name, i.desc, i.code FROM schedule s, items i, machines m where s.item = i.code and s.machine = m.ser_no and i.freq in $frequency and 0 < (select count(*) from history h where date = '$datestring' and h.machine = m.name and h.code = i.code and h.complete is null)";
$result = mysql_query($query);
$numrows = mysql_numrows($result);
echo "<form action=\"show_schedule.php\" method=\"post\">";
$i = 0;
while ($i < $numrows){
$NAME = mysql_result($result,$i,"NAME");
$DESC = mysql_result($result,$i,"DESC");
$CODE = mysql_result($result,$i,"CODE");
echo "$NAME<br>$DESC<br><input type=\"checkbox\" name=$CODE value=\"Y\">Completed<hr>";
$query = "INSERT INTO history VALUES ('$datestring','$NAME','$CODE')";
mysql_query($query);
$i++;
}
mysql_close();
?>
<input type="Submit" value="Clear checked items">
</form><br>
<a href='index.php'>Home</a>
<?php
$username="user";
$password="password";
$database="maintenance";
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die("Unable to connect to $database");
$query = "SELECT m.name, i.desc, i.code FROM schedule s, items i, machines m where s.item = i.code and s.machine = m.ser_no and i.freq in $frequency and 0 < (select count(*) from history h where date = '$datestring' and h.machine = m.name and h.code = i.code and h.complete is null)";
$result = mysql_query($query);
$numrows = mysql_numrows($result);
$i = 0;
while ($i < $numrows){
$CODE = mysql_result($result,$i,"CODE");
$CHECK = $_POST[$CODE];
$NAME = mysql_result($result,$i,"NAME");
if ($CHECK == "Y"){
$query = "UPDATE history SET complete = 'Y' WHERE date = '$datestring' AND code = '$CODE' AND machine = '$NAME'";
mysql_query($query);
}
$i++;
}
mysql_close();
?>
</body>
</html>