Changeset - ba908910fd8f
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 14 years ago 2011-04-09 13:04:17
ohnobinki@ohnopublishing.net
Carry the school and semester used when creating a schedule through to where the schedule is saved and fix the workflows for repairing broken inputs.
3 files changed with 84 insertions and 14 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
@@ -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);
 
  }
 

	
 
  /**
input.php
Show inline comments
 
@@ -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 <?php $semester = $inputPage->semester_get(); echo $semester['name'] ?> Schedule"
 
    title="My <?php echo $semester['name']; ?> Schedule"
 
    name="postData[name]"
 
    <?php
 
      if ($sch)
 
@@ -228,6 +268,8 @@ if (!empty($_REQUEST['selectsemester']))
 
    ?> />
 
  <?php if (!empty($parent_schedule_id)): ?>
 
  <input type="hidden" name="postData[parent_schedule_id]" value="<?php echo htmlentities($parent_schedule_id, ENT_QUOTES); ?>" />
 
  <input type="hidden" name="postData[school]" value="<?php echo htmlentities($school['id']); ?>" />
 
  <input type="hidden" name="postData[semester]" value="<?php echo htmlentities($semester['id']); ?>" />
 
  <?php endif; ?>
 
</p>
 

	
process.php
Show inline comments
 
@@ -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 '        <p>' . PHP_EOL
 
		      . '          You have the following errors in your input:' . PHP_EOL
 
@@ -214,7 +242,7 @@ if(!$DEBUG)
 
		    /* Regurgitate the postData into a <form /> */
 
		    echo '        <form action="input.php" method="post">' . PHP_EOL
 
		      . '          <input name="e" value="1" type="hidden" />' . PHP_EOL;
 
		    array_to_form($_POST['postData'], 'postData', '          ');
 
		    array_to_form($postData, 'postData', '          ');
 
		    echo '          <button type="submit" class="gray">Fix Errors!</button>' . PHP_EOL
 
		      . '        </form>' . PHP_EOL;
 

	
0 comments (0 inline, 0 general)