= 30) { $myTime+= .5; } //set current class and timeleft to nothing $cClass = ""; $timeLeft = ""; //array of day names $wd = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); //keyed array with keys as day names $week = array("Sunday" => array(), "Monday" => array(),"Tuesday" => array(),"Wednesday" => array(), "Thursday" => array(),"Friday" => array(), "Saturday" => array()); //set min and max hours beyond normal day $minh = 25; $maxh = -1; //read in schedule $rawsched = file('classSched.txt'); //puts class in proper array function insertClass($day,$class,$start,$len) { //declare globals global $theDay, $week, $theHour, $theMin, $myTime, $cClass, $timeLeft; //make lengh into half hours $tmplen = $len * 2; //set style to empty $cb = ""; //find out if i am currently in a class if($day == $theDay && $myTime >= $start && $myTime < ($start+$len)) { //set style $cb = "style=\"background-color: blue; font-weight: bold;\""; //set current class to the class I am in $cClass = "$class"; //find the time left in the class $timeLeft = (($start+$len-$theHour)*60)-$theMin; } //insert class cell into array keyed by the day and indexed //by start time $week["$day"]["$start"] = "$class"; $tmp = .5; //make array null untill end of class while(($len-$tmp) > 0) { $week[$day][strval($start+$tmp)] = null; $tmp+= .5; } } //go through the file line by line foreach($rawsched as $cs) { //remove new lines $cs = rtrim($cs,"\n"); //break up each line by colon delineation $ps = split(':',$cs); //break up start and end hours $shour = split('-',$ps[2]); //find class length $tlen = ($shour[1] - $shour[0]); //find time of earliest class if ($shour[0] < $minh) { $minh = $shour[0]; } //find time of latest class if ($shour[1] > $maxh) { $maxh = $shour[1]; } //loop through days and add classes found to //apropriate day for ($i = 0; $i <= 7; $i++) { $test = strpos($ps[1],"$i"); if ($test === false) {} else { insertClass("{$wd[$i]}", $ps[0], $shour[0], $tlen); } } } ?> \n{$wd[$i]}\n\n"; } echo "\n"; //fine total number of half hours needed $thours = ($maxh - $minh) * 2; //loop through and fill the table for ($i = 0; $i < $thours; $i++) { $time = $minh; //set time to am $st = "am"; //if after or 12 make time pm if ($minh >= 12) { $st = "pm"; } //if afternoon set time to below 12 for 12hr time format in table if ($minh >= 13) { $time-= 12; } //replace .5 with :30 for looks $time = str_replace(".5",":30",$time); //make a row for the current half hour echo "\n"; //make cell for time echo "\n"; //look for a class for ($j = 0; $j <= 6; $j++) { //if a class exists for curent time, echo it if(array_key_exists("$minh",$week["{$wd[$j]}"])) { echo "{$week["{$wd[$j]}"]["$minh"]}\n"; } else { //if cell is current time, make it blue if ($minh == $myTime && strcmp($wd[$j],$theDay) == 0) { echo "\n"; } //echo empty cell else { echo "\n"; } } } //end row echo "\n"; //increment time half hour for next row $minh+= .5; } ?>
Time
$time$st