diff --git a/inc/class.schedule.php b/inc/class.schedule.php --- a/inc/class.schedule.php +++ b/inc/class.schedule.php @@ -108,15 +108,28 @@ class Schedule $this->courses[] = new Course($n); } - //-------------------------------------------------- - // Adds a section to the desired class. - //-------------------------------------------------- + /** + * \brief + * Adds a section to this semester after finding the class. + * + * \return + * NULL on success, a string on error which is a message for the + * user and a valid XHTML fragment. + */ function addSection($course_name, $letter, $time_start, $time_end, $days, $synonym = NULL, $faculty = NULL, $location = NULL, $type = 'lecture') { if (empty($letter) && (empty($time_start) || !strcmp($time_start, 'none')) && (empty($time_end) || !strcmp($time_end, 'none')) && empty($days) && empty($synonym) && empty($faculty) && empty($location) && (empty($type) || !strcmp($type, 'lecture'))) return; + /* reject invalid times */ + if (!strcmp($time_start, 'none') || !strcmp($time_end, 'none') + || $time_start > $time_end) + { + return 'Invalid time specifications for ' . htmlentities($course_name) . '-' . htmlentities($letter) + . '. Start time: ' . htmlentities($time_start) . '. End time: ' . htmlentities($time_end) . '.'; + } + foreach ($this->courses as $course) if (!strcmp($course_name, $course->getName())) { diff --git a/input.php b/input.php --- a/input.php +++ b/input.php @@ -29,6 +29,7 @@ require_once('inc' . DIRECTORY_SEPARATOR $schedule_store = FALSE; $sch = FALSE; +$fix_errors = FALSE; $school = $inputPage->get_school(); $parent_schedule_id = NULL; @@ -38,6 +39,16 @@ if (isset($_REQUEST['s'])) $parent_schedule_id = (int)$_REQUEST['s']; $sch = schedule_store_retrieve($schedule_store, $parent_schedule_id); } +elseif (!empty($_REQUEST['e'])) + { + /* + * Read an errorful schedule out of $_POST, this $_POST is created + * by process.php when the originally sinful user produces bad + * data. + */ + $errors_fix = TRUE; + $parent_schedule_id = (int)$_POST['postData']['parent_schedule_id']; + } $my_hc = 'var slate_permutate_example_course_id = \'' . str_replace('\'', '\\\'', school_example_course_id($inputPage->get_school())) . '\'; @@ -55,6 +66,29 @@ if ($sch) $my_hc .= input_class_js($sch->class_get($class_key), ' '); } } +elseif ($errors_fix) + { + foreach ($_POST['postData'] as $course) + if (is_array($course)) + { + if (empty($course['name'])) + $my_hc .= ' class_last = add_class();' . PHP_EOL; + else + $my_hc .= ' class_last = add_class_n(\'' . htmlentities($course['name'], ENT_QUOTES) . '\');' . PHP_EOL; + foreach ($course as $section) + if (is_array($section)) + $my_hc .= ' add_section_n(class_last, \'' . htmlentities($section['letter'], ENT_QUOTES) . '\', \'' + . htmlentities($section['synonym'], ENT_QUOTES) . '\', \'' . htmlentities($section['start'], ENT_QUOTES) . '\', \'' + . htmlentities($section['end'], ENT_QUOTES) . '\', ' + . json_encode(array('m' => !empty($section['days'][0]), 't' => !empty($section['days'][1]), 'w' => !empty($section['days'][2]), + 'h' => !empty($section['days'][3]), 'f' => !empty($section['days'][4]), + 's' => !empty($section['days'][5]))) + . ', \'' . htmlentities($section['professor'], ENT_QUOTES) . '\', \'' + . htmlentities($section['location'], ENT_QUOTES) . '\', \'' + . htmlentities($section['type'], ENT_QUOTES) . '\');' . PHP_EOL; + $my_hc .= PHP_EOL; + } + } else { $default_courses = school_default_courses($school); @@ -135,7 +169,20 @@ if (!empty($_REQUEST['selectsemester']))
*/ + echo ' ' . PHP_EOL; + + $error_page->foot(); + exit; + } + $allClasses->findPossibilities(); if (!isset($_SESSION['saved'])) $_SESSION['saved'] = array();