Forum Moderators: coopster
<?php
// This routine at the top getts the path to the root of your web site on your server and setts it as a variable
$fullpath=realpath(basename(getenv("SCRIPT_NAME")));
$fullpath=str_replace("\\","/",$fullpath);
$localpath=getenv("SCRIPT_NAME");
$rootpath = str_replace($localpath, "", $fullpath);
?>
<!-- This is where you put the content -->
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
// Explode text file and store each row of the file into the array elements
function explodeRows($data) {
$rowsArr = explode("\n", $data);
return $rowsArr;
}
// Explode the columns according to tabs
function explodeTabs($singleLine) {
$tabsArr = explode("\t", $singleLine);
return $tabsArr;
}
// Open the text file and get the content
$filename = $rootpath . "/m/libraryhourstable.txt";
$handle = fopen($filename, 'r');
$data = fread($handle, filesize($filename));
$rowsArr = explodeRows($data);
$today = date("n/j/Y");
// Make array containing today and seven other dates
echo "<div id=today><p class=center><b>Today:</b> " . date("l n/j/Y") . "<br>\n";
for($i=1; $i<=6; $i=$i+1)
{
$days[$i] = date("n/j/Y", strtotime("+$i day"));
//echo $days[$i] . " the days<br />";
}
// Display content which is exploded by regular expression parameters \n and \t
for($i=0;$i<count($rowsArr);$i++) {
$lineDetails = explodeTabs($rowsArr[$i]);
if ($lineDetails[1]==$today && $lineDetails[4]=="Closed") {
$j=0;
echo "\n <span class=redtext><b>" . " " . $lineDetails[4] . "</b></span></p></div>\n<ul id=hourslist>\n";
} elseif ($lineDetails[1]==$today) {
$j=0;
echo "\n<big><b>Hours:" . " " . $lineDetails[4] . " - " . $lineDetails[5] . " </b></big> \n";
if (trim($lineDetails[8])!=="Closed"){
echo "<br /><span class=latehour>Late Room until: " . $lineDetails[8] . "</span>\n";
}
echo "</p>\n<ul id=hourslist>\n";
} elseif (in_array($lineDetails[1], $days) && $lineDetails[4]=="Closed") {
$j=$j+1;
if ( $j&1 ){
$oddoreven="hoursodd";
} else {
$oddoreven="hourseven";
}
echo "<li class=" . $oddoreven . "> <b> <span class=redtext> " . $lineDetails[3] . " : " . " " . $lineDetails[4] . "</span></b></li>\n";
} elseif (in_array($lineDetails[1], $days)) {
$j=$j+1;
if ( $j&1 ){
$oddoreven="hoursodd";
} else {
$oddoreven="hourseven";
}
echo "<li class=" . $oddoreven . "> <b> " . $lineDetails[3] . ": </b>" . $lineDetails[4] . " - " . $lineDetails[5];
if (trim($lineDetails[8])!=="Closed"){
echo "<br /><span class=latehour> Late Room until: " . $lineDetails[8] . "</span>\n";
}
echo "</li>\n";
}
}
echo "</ul>\n ";
?>