You'll need the extra functions from include-wxstatus.php to make the do_check() functions work
<?php
// Functions used on this page
function do_check($title, $fileOrAppTime,$maxFileSecs,$type='file') {
if(preg_match('/file/i',$type)) {
$cur_status = do_check_file($fileOrAppTime,$maxFileSecs);
} else {
$cur_status = do_check_applic($fileOrAppTime,$maxFileSecs);
}
list($stat,$age,$data) = explode("\t",$cur_status);
echo " <tr>
<td>$title</td>
<td align=\"center\">$stat</td>
<td align=\"right\">$age</td>
<td align=\"right\">$data</td>
</tr>\n";
}
// check time on a file for last update
function do_check_file($chkfile,$maxFileSecs) {
global $SITE;
$timeFormat = $SITE['timeFormat'];
$now = time();
if (file_exists($chkfile)) {
$age = $now - filemtime($chkfile);
$updateTime = date($timeFormat,filemtime($chkfile));
} else {
$age = 'unknown';
$updateTime = 'file not found';
}
$status = '';
$hms = sec2hms($age);
print "<!-- $chkfile age = $age secs. $hms -->\n";
$age = $hms;
if (file_exists($chkfile) and (filemtime($chkfile) + $maxFileSecs > $now) ) { // stale file
$status = "<span style=\"color: green\"><b>".langtransstr('Current')."</b></span>\t$age\t$updateTime ";
} else {
$status = "<span style=\"color: red\"><b>".langtransstr('NOT Current')."</b></span>\t$age\t > " . sec2hms($maxFileSecs) ."<br/><b>$updateTime</b>";
}
return($status);
}
// check time on an application returned update time
function do_check_applic($applTime,$maxFileSecs) {
global $SITE;
$timeFormat = $SITE['timeFormat'];
$now = time();
$age = $now - $applTime;
$updateTime = date($timeFormat,$applTime);
$status = '';
$hms = sec2hms($age);
print "<!-- age = $age secs. $hms -->\n";
$age=$hms;
if ($applTime + $maxFileSecs > $now ) { // stale file
$status = "<span style=\"color: green\"><b>".langtransstr('Current')."</b></span>\t$age\t$updateTime ";
} else {
$status = "<span style=\"color: red\"><b>".langtransstr('NOT Current')."</b></span>\t$age\t > " . sec2hms($maxFileSecs) . " <br/><b>$updateTime</b>";
}
return($status);
}
//
function sec2hms ($sec, $padHours = false)
{
// holds formatted string
$hms = "";
if (! is_numeric($sec)) { return($sec); }
// there are 3600 seconds in an hour, so if we
// divide total seconds by 3600 and throw away
// the remainder, we've got the number of hours
$hours = intval(intval($sec) / 3600);
// add to $hms, with a leading 0 if asked for
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
: $hours. ':';
// dividing the total seconds by 60 will give us
// the number of minutes, but we're interested in
// minutes past the hour: to get that, we need to
// divide by 60 again and keep the remainder
$minutes = intval(($sec / 60) % 60);
// then add to $hms (with a leading 0 if needed)
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
// seconds are simple - just divide the total
// seconds by 60 and keep the remainder
$seconds = intval($sec % 60);
// add to $hms, again with a leading 0 if needed
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
// done!
return $hms;
}
//=========================================================================
// change the hh:mm AM/PM to h:mmam/pm format
function fixup_time ( $WDtime ) {
global $timeOnlyFormat,$DebugMode;
if ($WDtime == "00:00: AM") { return ''; }
$t = explode(':',$WDtime);
if (preg_match('/p/i',$WDtime)) { $t[0] = $t[0] + 12; }
if ($t[0] > 23) {$t[0] = 12; }
if (preg_match('/^12.*a/i',$WDtime)) { $t[0] = 0; }
$t2 = join(':',$t); // put time back to gether;
$t2 = preg_replace('/[^\d\:]/is','',$t2); // strip out the am/pm if any
return ($t2);
}
//=========================================================================
// adjust date to standard format
//
function fixup_date ($WDdate) {
global $SITE;
$d = explode('/',$WDdate);
if(!isset($d[2])) {$d=explode("-",$WDdate); }
if(!isset($d[2])) {$d=explode(".",$WDdate); }
if ($d[2] > 70 and $d[2] <= 99) {$d[2] += 1900;} // 2 digit dates 70-99 are 1970-1999
if ($d[2] < 99) {$d[2] += 2000; } // 2 digit dates (left) are assumed 20xx dates.
if ($SITE['WDdateMDY']) {
$new = sprintf('%04d-%02d-%02d',$d[2],$d[0],$d[1]); // M/D/YYYY -> YYYY-MM-DD
} else {
$new = sprintf('%04d-%02d-%02d',$d[2],$d[1],$d[0]); // D/M/YYYY -> YYYY-MM-DD
}
return($new);
}
// end of functions
?>