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
 
@@ -199,13 +199,13 @@ class page
 
   *     - 'school_semester_constant': Whether the options to change
 
   *        the current school and semester should be hidden. TRUE by
 
   *        default.
 
   */
 
  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);
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Adds some headcode to this page.
 
   *
input.php
Show inline comments
 
@@ -40,43 +40,83 @@ require_once('inc' . DIRECTORY_SEPARATOR
 
$parent_schedule_id = NULL;
 
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']))
 
  {
 
    /*
 
     * 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;
 
    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;
 
  }
 

	
 
/*
 
 * We cannot initialize the page object nor guess the school before
 
 * figuring loading a saved schedule because we'll default to that
 
 * saved_schedule's school/semester.
 
 */
 
$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)) . ';
 

	
 
jQuery(document).ready(
 
  function()
 
  {
 
@@ -215,22 +255,24 @@ if (!empty($_REQUEST['selectsemester']))
 
<input
 
    id="scheduleName"
 
    style="margin-bottom: 1em;"
 
    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)
 
        echo 'value="' . htmlentities($sch->getName(), ENT_QUOTES) . '"';
 
      elseif ($errors_fix)
 
        echo 'value="' . htmlentities($_POST['postData']['name'], ENT_QUOTES) . '"';
 
    ?> />
 
  <?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>
 

	
 
<table id="container">
 
  <tr>
 
    <td>
process.php
Show inline comments
 
@@ -142,30 +142,57 @@ if(!$DEBUG)
 
      {
 
	/*
 
	 * we probably have input from the user and should interpret
 
	 * 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
 
	     * section to the class. We know that $course['name']
 
	     * is not a section, so count() needs to be > 1 and
 
	     * we need to skip over 'name' in our loop.
 
@@ -191,13 +218,14 @@ if(!$DEBUG)
 
		/*
 
		 * Tell the user that his input is erroneous and
 
		 * require him to fix it.
 
		 */
 
		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
 
		      . '        </p>' . PHP_EOL
 
		      . '        <ul>' . PHP_EOL;
 
		    foreach ($errors as $error)
 
@@ -211,13 +239,13 @@ if(!$DEBUG)
 
		      . '          <li>If you are having trouble resolving these issues, please feel free to <a href="feedback.php">leave us feedback</a>. Be sure to describe your problem with as much detail as possible; otherwise we may only be able to make conjectures about the errors instead of finding and fixing any bugs. Thanks! <em>(To provide us with the most reliable data, save this webpage onto disk and paste the entire (X)HTML source into the feedback form.)</em></li>' . PHP_EOL
 
		      . '        </ul>' . PHP_EOL;
 

	
 
		    /* 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;
 

	
 
		    $error_page->foot();
 
		    exit;
 
		  }
0 comments (0 inline, 0 general)