<?php
/* this is a quick-and-dirty schedule drawing script. It is O(classes * days * 
 * hours), but who cares?
 *
 * Copyright (c) 2009, Tom Quetchenbach
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * The name of the author may not be used to endorse or promote products 
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */ 

$step 0.5;
$start_hour 8;
$end_hour 22;
$num_days 5;  /* could expand to 7, if weekend classes existed */

$classes = array(
    
//    number       MTWRF   hours   type     title
    
array('SCI 530',  '10100'1113'class''Env. Sys. data collection/analysis'),
    array(
'ENGR 326''01010'1314'class''Computational Methods for Environmental Engineering III'),
    array(
'ENGR 571''01010'1112'class''Advanced Thermodynamics and Energy Systems'),
    array(
'SCI 530''00001'1113'lab',   'Env. Sys. data collection/analysis'),
    array(
'ENGR 571''00100'1417'lab',   'Advanced Thermodynamics and Energy Systems'),
    array(
'ENGR 326''10000'1417'lab',   'Computational Methods for Environmental Engineering III'),
    array(
'SERC',     '00100'1314'meeting''Schatz Lab staff meeting'),
    array(
'Lighting',     '00001'8.510'meeting''Lighting Lab staff meeting'),
);

$title "Tom Quetchenbach's Schedule for Spring 2010";
$headcontent = <<<EOF

<style type="text/css">
<![CDATA[
table {
    border-collapse: collapse;
}

td, th {
    /* 'ridge' has lower priority than 'solid', but '1px ridge' looks the same 
     * as '1px solid'. */
    border: 1px ridge #cccccc;
    width: 16.6666666%;
    text-align: center;
}

tr.row1{
    background-color: #eeeeee;
}

td.time, th{
    font-weight: bold;
    background-color: #dddddd;
    border-color: #aaaaaa;
}

td.time {
    text-align: right;
}

td.class{
    background-color: #ADD8E6; /*mozilla "lightblue"*/
    border: 1px solid #002B66;
}

td.lab{
    background-color: #ADE6AD;
    border: 1px solid #006600;
}

td.meeting{
    background-color: #ffaaaa;
    border: 1px solid #aa0000;
}

#key th, #key td{
    width:auto;
    font-weight:bold;
}

#key td{
    text-align: left;
}

#key td.key{
    width: 2em;
}

#key{
    margin-bottom: 1em;
}
]]>
</style>
EOF;
include(
'../qtop.php');
?>
<h1>Schedule</h1>
<p>Spring 2010, Updated 1/31/2010.</p>
<p>In most browsers, mouse over the course number for the course title.</p>

<table id="key" border="1">
    <tr>
        <th colspan="2"><strong>Key</strong></th>
    </tr>
    <tr>
        <td class="key class">&nbsp;</td>
        <td>class</td>
    </tr>
    <tr>
        <td class="key lab">&nbsp;</td>
        <td>lab</td>
    </tr>
    <tr>
        <td class="key meeting">&nbsp;</td>
        <td>meeting</td>
    </tr>
</table>

<table><tr><th>&nbsp;</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th></tr>
<?php
/* the end of the latest class encountered so far each day, used to decide 
 * whether a blank cell is needed for that time */

$class_end = array(00000);

/* get time zone offset in seconds. DST, of course, doesn't matter, except that 
 * the DST time change can't be on the chosen day.*/
$tzoffset strtotime('1970-01-01 0:00');

for (
$h $start_hour$a 0$h $end_hour$h += $step$a ^= 1){
    
$time strftime('%l:%M %p'$h 60 60 $tzoffset);

    echo 
"<tr class='row$a'><td class='time'>$time</td>\n";
    for (
$j 0$j $num_days$j++){
        foreach (
$classes as $class){
            if (
$class[1][$j] == '1' && $class[2] == $h){
                
/* a class starts now */
                
$rowspan=($class[3] - $h) / $step;
                
$class_end[$j] = $class[3];
                echo 
"\t<td class='$class[4]' title='$class[5]'";
                if (
$rowspan)
                    echo 
" rowspan='$rowspan'";
                echo 
">$class[0]</td>\n";
                
/* don't handle overlapping classes */
                
break;
            }
        }
        
/* draw a blank if there is no class now */
        
if ($class_end[$j] <= $h)
            echo 
"\t<td>&nbsp;</td>\n";
    }
    echo 
"</tr>\n";
}

?>
</table>

<p>This schedule is generated by a "quick hack" PHP script; you can see the
<a href="schedule.phps">source code here</a>.</p>
<?php include('../qbot.php');?>