示例#1
0
        }
    }
    echo "</select>";
}
?>
<input type="submit" value="Go!" name="submit">
</form>
Manage selected courses:<br>
<form action="editcourse.php?sem=<?php 
echo $sem;
?>
" method='post'>
<select name="mycourse" id='mycourses'>
<?php 
// print out a select form to show the courses the student already registered in
$mycourses = myCourses($schedule, $sem);
foreach ($mycourses as $key => $value) {
    echo "<option value='{$value}'>{$value}</option>";
}
?>
</select>
<input type="submit" value="Go!" name="submit">
</form>
<form action="timetable.php?sem=<?php 
echo $sem;
?>
" id='purge' method='post'>
<input type="hidden" value="Purge" name="action">
<input type="submit" value="Remove all courses" name="submit">
</form>
<p>Filter Conflicts:
示例#2
0
function displaySchedule($sched, $sem)
{
    // get the chosen courses into a 2D array form
    $data = arraySchedule($sched, $sem);
    // dynamically generate the table in HTML
    $schedule = "<table class='records' border='1' align='center' \n\t\t\t\tcellspacing='0' cellpadding='3'>\n\t\t\t\t<tr><th>Time<th>Mon<th>Tue<th>Wed<th>Thu<th>Fri</tr>";
    // we want to format the table such that one course section taking multiple
    // vertically consecutive cells will be shown as one huge cell spanning
    // multiple rows. E.g. a course going from 6-9 on Monday would mean
    // the cells for Monday 6-9 would be merged into one big cell.
    // this variable is a 2D array. It tracks duplicates in each weekday column
    // of the schedule (our $data array)
    $last = array();
    for ($i = 0; $i < count($data); $i++) {
        list($Time, $Mon, $Tue, $Wed, $Thu, $Fri) = $data[$i];
        // the 0th index of our 2D array is used for the schedule time indicator
        // so we have to start from 1 when assigning keys
        $arr = array(1 => $Mon, $Tue, $Wed, $Thu, $Fri);
        $schedule .= "<tr>";
        // convert the time to 12-hr form, and chop off trailing :00 (seconds)
        if ($check && $i % 2 == 0) {
            $Time = convertTime($Time);
            // Don't want to show x:30 times. Make x:00 times span 2 rows
            $schedule .= "<td rowspan='2'>{$Time}</td>";
        } else {
            if (!$check) {
                $Time = convertTime($Time);
                $schedule .= "<td>{$Time}</td>";
            }
        }
        // this 2D array will track the size of each group of duplicates
        // in each weekday column
        $rowspan = array();
        // initialize the duplicate group sizes to zero
        foreach ($arr as $key => $value) {
            $rowspan[$key] = 0;
        }
        // predefine 6 colours
        $cols = array("F7E967", "A9CF54", "70B7BA", "45D99E", "A062DE", "DB9A37");
        $mycourses = myCourses($sched, $sem);
        if (count($mycourses)) {
            $cols2 = array_slice($cols, 0, count($mycourses));
            $colslist = array_combine($mycourses, $cols2);
        }
        // iterate through the schedule table and hunt for duplicates and adjust
        // rowspan values where necessary
        foreach ($arr as $key => $value) {
            if ($value != "") {
                // use only the 9-char course code, i.e. ABC123H1F as an index
                // for the colour array
                $name = substr($value, 0, CRSCODELEN);
                for ($j = $i; $data[$j][$key] !== $last[$key] && $j < count($data) && $data[$j][$key] == $data[$i][$key]; $j++) {
                    $rowspan[$key]++;
                }
                if ($rowspan[$key] > 0) {
                    $last[$key] = $data[$i][$key];
                    // if there's no conflict, pick one of the 6 colours
                    if (strpos($value, "CONFLICT") === false) {
                        $schedule .= "<td bgcolor={$colslist[$name]} \n\t\t\t\t\t\t\t\t\trowspan='{$rowspan[$key]}'>" . $value . "</td>";
                    } else {
                        // colour the cell red if there's a conflict
                        $schedule .= "<td bgcolor='F1433F' \n\t\t\t\t\t\t\t\t\trowspan='{$rowspan[$key]}'>" . $value . "</td>";
                    }
                }
            } else {
                // if the cell is blank, then it's blank!
                $schedule .= "<td></td>";
            }
        }
        $schedule .= "</tr>";
    }
    $schedule .= "</table>";
    return $schedule;
}