# HG changeset patch # User Nathan Phillip Brink # Date 2011-04-09 11:42:43 # Node ID 85225ae6e519b9b42655f88d1e9f84fb5a6d0d00 # Parent f2de63b6af0b01de0f40dbd10357cb8fba4ddacc Fix up remembering the school of an edited schedule on the input pages. diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -257,6 +257,11 @@ class page foreach ($this->scripts as $i) echo ' ' . $this->headCode["$i"] . "\n"; + $selectschool_query = '&school=' . $this->school['id']; + /* kludge */ + if (!empty($_REQUEST['s'])) + $selectschool_query .= '&s=' . (int)$_REQUEST['s']; + echo ' ' . PHP_EOL . ' '. PHP_EOL . '
'. PHP_EOL . @@ -266,9 +271,9 @@ class page '

'. PHP_EOL . ' '.$this->pagetitle.''. PHP_EOL . ' ' . PHP_EOL - . ' Profile: ' . $this->school['name'] . '' . ($this->school_semester_constant ? '' : ' (change)') . PHP_EOL; + . ' Profile: ' . $this->school['name'] . '' . ($this->school_semester_constant ? '' : ' (change)') . PHP_EOL; if (!empty($this->semester)) - echo ' Semester: ' . $this->semester['name'] . '' . ($this->school_semester_constant ? '' : ' (change)') . PHP_EOL; + echo ' Semester: ' . $this->semester['name'] . '' . ($this->school_semester_constant ? '' : ' (change)') . PHP_EOL; echo ' '. PHP_EOL . '

'. PHP_EOL . '
'. PHP_EOL . diff --git a/inc/class.schedule.php b/inc/class.schedule.php --- a/inc/class.schedule.php +++ b/inc/class.schedule.php @@ -117,7 +117,7 @@ class Schedule $this->parent_id = $parent; if (empty($school)) - $school = school_load_guess(); + $school = school_load_guess(FALSE); $this->school_id = $school['id']; if (empty($semester)) @@ -211,7 +211,7 @@ class Schedule { /* Ensure we have $_SESSION. */ page::session_start(); - $school = school_load_guess(); + $school = school_load_guess(FALSE); } return $school; @@ -822,7 +822,7 @@ class Schedule { /* Ensure we have $_SESSION. */ page::session_start(); - $school = school_load_guess(); + $school = school_load_guess(FALSE); $this->school_id = $school['id']; } if (empty($this->semester)) diff --git a/inc/school.inc b/inc/school.inc --- a/inc/school.inc +++ b/inc/school.inc @@ -227,7 +227,7 @@ function school_list_html($highlight = N $linkto = '?'; elseif (strpos($linkto, '?') === FALSE) $linkto .= '?'; - else + elseif (strpos('?&', strstr($linkto, -1)) !== FALSE) $linkto .= '&'; $linkto .= 'school='; $linkto = htmlentities($linkto); @@ -239,7 +239,7 @@ function school_list_html($highlight = N if ($school_id == $highlight) $class_highlight = ' highlight'; $html .= '
  • ' - . $school_info['name'] . "
  • \n"; + . htmlentities($school_info['name']) . "\n"; } $html .= "\n"; @@ -352,7 +352,7 @@ function school_semesters(array $school) * to the same keys in the arrays returned by school_semesters() or * NULL if no semester can be found. */ -function school_semester_guess(array $school, $update_session = FALSE) +function school_semester_guess(array $school, $update_session = TRUE) { $semesters = school_semesters($school); diff --git a/input.php b/input.php --- a/input.php +++ b/input.php @@ -24,6 +24,14 @@ include_once 'inc' . DIRECTORY_SEPARATOR include_once 'inc' . DIRECTORY_SEPARATOR . 'class.page.php'; require_once('inc' . DIRECTORY_SEPARATOR . 'schedule_store.inc'); +/* + * Help constrol whether or not the school selection dialogue should + * be shown or whether or not $_SESSION['school_chosen'] should be set + * TRUE. These things should generally be false when loading a saved + * schedule. + */ +$creating_new_schedule = TRUE; + $schedule_store = FALSE; $sch = FALSE; $errors_fix = FALSE; @@ -35,8 +43,14 @@ if (isset($_REQUEST['s'])) $schedule_store = schedule_store_init(); $parent_schedule_id = (int)$_REQUEST['s']; $sch = schedule_store_retrieve($schedule_store, $parent_schedule_id); - $inputPage_options += array('school' => $sch->school_get(), - 'semester' => $sch->semester_get()); + if (!empty($sch)) + { + $creating_new_schedule = FALSE; + $inputPage_options += array('school' => $sch->school_get(), + 'semester' => $sch->semester_get()); + } + else + $parent_schedule_id = NULL; } elseif (!empty($_REQUEST['e'])) { @@ -48,6 +62,8 @@ elseif (!empty($_REQUEST['e'])) $errors_fix = TRUE; if (!empty($_POST['postData']['parent_schedule_id'])) $parent_schedule_id = (int)$_POST['postData']['parent_schedule_id']; + + $creating_new_schedule = FALSE; } /* @@ -59,7 +75,7 @@ elseif (!empty($_REQUEST['e'])) $inputPage = page::page_create('Scheduler', $scripts, $inputPage_options); $school = $inputPage->get_school(); -$my_hc = 'var slate_permutate_example_course_id = ' . json_encode(school_example_course_id($inputPage->get_school())) . '; +$my_hc = 'var slate_permutate_example_course_id = ' . json_encode(school_example_course_id($school)) . '; jQuery(document).ready( function() @@ -125,20 +141,22 @@ if ($qtips_always || !isset($_SESSION['s * student before displaying the input form. To do this, we need * another variable in $_SESSION: $_SESSION['school_chosen']. */ -if ($school && (!empty($_REQUEST['school']) || $school['id'] != 'default')) +if (!empty($_REQUEST['school']) && !empty($_SESSION['school']) && !strcmp($_REQUEST['school'], $_SESSION['school'])) $_SESSION['school_chosen'] = TRUE; if (!empty($_REQUEST['selectschool']) - || $school['id'] == 'default' && !isset($_SESSION['school_chosen'])) + || empty($school) || $school['id'] == 'default' && empty($_SESSION['school_chosen'])) { - $next_page = 'input.php'; + $next_page = 'input.php?'; if (isset($_GET['s'])) - $next_page .= '?s=' . (int)$_GET['s']; + $next_page .= 's=' . (int)$_GET['s'] . '&'; + if (isset($_GET['semester'])) + $next_page .= 'semester=' . htmlentities($$_GET['semester']) . '&'; ?>

    School Selection

    Choose the school you attend from the list below. If you cannot find your school, you may proceed using - the generic + the generic settings.

    let us know.

    showSemesters(); + $next_page = 'input.php?'; + if (isset($_GET['s'])) + $next_page .= 's=' . (int)$_GET['s'] . '&'; + if (!empty($_GET['school'])) + $next_page .= 'school=' . $_GET['school'] . '&'; + + $inputPage->showSemesters($next_page); $inputPage->foot(); exit; }