diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -202,7 +202,7 @@ class page */ public static function page_create($title, array $scripts = array(), array $options = array()) { - return new page(htmlentities($title), $scripts, FALSE, $options); + return new page(htmlentities($title, ENT_QUOTES, 'UTF-8'), $scripts, FALSE, $options); } /** diff --git a/input.php b/input.php --- a/input.php +++ b/input.php @@ -43,14 +43,35 @@ if (isset($_REQUEST['s'])) $schedule_store = schedule_store_init(); $parent_schedule_id = (int)$_REQUEST['s']; $sch = schedule_store_retrieve($schedule_store, $parent_schedule_id); + + /* + * Allow a user to change the school and semester of a + * saved_schedule he's trying to revive if he really wants to. + */ + if (!empty($_GET['school'])) + $school = school_load_guess(FALSE); + else + $school = $sch->school_get(); + + if (!empty($_GET['semester'])) + $semester = school_semester_guess(FALSE); + else + $semester = $sch->semester_get(); + if (!empty($sch)) { $creating_new_schedule = FALSE; - $inputPage_options += array('school' => $sch->school_get(), - 'semester' => $sch->semester_get()); + $inputPage_options += array('school' => $school, + 'semester' => $semester); } else $parent_schedule_id = NULL; + + /* + * Code outside of this block should _not_ assume $school and/or + * $semester are defined. But it'd be more expensive to unset() + * them here than to just overwrite them later... + */ } elseif (!empty($_REQUEST['e'])) { @@ -60,8 +81,26 @@ elseif (!empty($_REQUEST['e'])) * data. */ $errors_fix = TRUE; - if (!empty($_POST['postData']['parent_schedule_id'])) - $parent_schedule_id = (int)$_POST['postData']['parent_schedule_id']; + + if (!empty($_POST['postData'])) + $postData = $_POST['postData']; + + if (!empty($postData['parent_schedule_id'])) + $parent_schedule_id = (int)$postData['parent_schedule_id']; + + if (!empty($postData['school'])) + { + $school = school_load($postData['school']); + if (!empty($school)) + $inputPage_options['school'] = $school; + } + + if (!empty($school) && !empty($postData['semester'])) + { + $semesters = school_semesters($school); + if (!empty($semesters[$postData['semester']])) + $inputPage_options['semester'] = $semester; + } $creating_new_schedule = FALSE; } @@ -74,6 +113,7 @@ elseif (!empty($_REQUEST['e'])) $scripts = array('jQuery', 'jQueryUI', 'qTip2', 'schedInput'); $inputPage = page::page_create('Scheduler', $scripts, $inputPage_options); $school = $inputPage->get_school(); +$semester = $inputPage->semester_get(); $my_hc = 'var slate_permutate_example_course_id = ' . json_encode(school_example_course_id($school)) . '; @@ -218,7 +258,7 @@ if (!empty($_REQUEST['selectsemester'])) class="defText required" type="text" size="25" - title="My semester_get(); echo $semester['name'] ?> Schedule" + title="My Schedule" name="postData[name]" /> + +

diff --git a/process.php b/process.php --- a/process.php +++ b/process.php @@ -145,24 +145,51 @@ if(!$DEBUG) * it as a schedule to permutate. Then we should redirect the * user to the canonical URL for that schedule. */ + $page_create_options = array(); + if (!empty($_POST['postData'])) + $postData = $_POST['postData']; + $name = ''; - if (!empty($_POST['postData']['name'])) - $name = $_POST['postData']['name']; + if (!empty($postData['name'])) + $name = $postData['name']; $parent_schedule_id = NULL; - if (!empty($_POST['postData']['parent_schedule_id'])) + if (!empty($postData['parent_schedule_id'])) { - $parent_schedule_id = (int)$_POST['postData']['parent_schedule_id']; + $parent_schedule_id = (int)$postData['parent_schedule_id']; $parent_schedule = schedule_store_retrieve($schedule_store, $parent_schedule_id); /* Detect bad parent_schedule reference. */ if (empty($parent_schedule)) $parent_schedule_id = NULL; } - $allClasses = new Schedule($name, $parent_schedule_id); + $school = NULL; + if (!empty($postData['school'])) + { + /* + * This function returns NULL if it can't find the school_id + * so we're all good -- this is a type of error which is + * better to silently ignore ;-). + */ + $school = school_load($postData['school']); + $page_create_options['school'] = $school; + } + + $semester = NULL; + if (!empty($school) && !empty($postData['semester'])) + { + $semesters = school_semesters($school); + if (!empty($semesters[$postData['semester']])) + { + $semester = $semesters[$postData['semester']]; + $page_create_options['semester'] = $semester; + } + } + + $allClasses = new Schedule($name, $parent_schedule_id, $school, $semester); $errors = array(); - foreach($_POST['postData'] as $course) + foreach($postData as $course) { /* * Only add classes if the user added at least one @@ -194,7 +221,8 @@ if(!$DEBUG) */ if (count($errors)) { - $error_page = new Page('Process Schedule — Errors'); + $error_page = page::page_create('Process Schedule — Errors', array(), $page_create_options); + $error_page->head(); echo '

' . PHP_EOL . ' You have the following errors in your input:' . PHP_EOL @@ -214,7 +242,7 @@ if(!$DEBUG) /* Regurgitate the postData into a

*/ echo ' ' . PHP_EOL . ' ' . PHP_EOL; - array_to_form($_POST['postData'], 'postData', ' '); + array_to_form($postData, 'postData', ' '); echo ' ' . PHP_EOL . '
' . PHP_EOL;