Changeset - fe65a57a01fe
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 15 years ago 2011-03-18 19:47:26
ohnobinki@ohnopublishing.net
Store a schedule's parent_id and make awkwardly accessible via a ``Parent'' buttonlink. Fixes bug 91.
3 files changed with 84 insertions and 18 deletions:
0 comments (0 inline, 0 general)
inc/class.schedule.php
Show inline comments
 
@@ -52,6 +52,7 @@ class Schedule
 
  private $possiblePermutations;	// Integer number of possible permutations
 
  private $scheduleName;			// String name of schedule
 
  private $storage;				// Integer array of valid schedules
 
  /* The <title /> of the page used when rendering this schedule */
 
  private $title;
 

	
 
  /**
 
@@ -61,16 +62,31 @@ class Schedule
 
   */
 
  private $id;
 

	
 
  /*
 
   * The identifier of the schedule from which this schedule was
 
   * derived or NULL.
 
   */
 
  private $parent_id;
 

	
 
  /**
 
   * \brief
 
   *   Create a schedule with the given name.
 
   *
 
   * \param $name
 
   *   A string, the friendly name the user gave this schedule.
 
   * \param $parent
 
   *   An integer, the id of the schedule from which this schedule is
 
   *   derived. A schedule is considered to be derived of another of
 
   *   the user created this schedule by clicking ``Edit'' for the
 
   *   previous schedule. Or NULL if this schedule stands on its own.
 
   */
 
  function __construct($name)
 
  function __construct($name, $parent = NULL)
 
  {
 
    $this->courses = array();
 
    $this->scheduleName = $name;
 
    $this->storage = array();
 
    $this->title = "SlatePermutate - Scheduler";
 
    $this->parent_id = $parent;
 

	
 
    /* mark this as an upgraded Schedule class. See __wakeup() */
 
    $this->nclasses = -1;
 
@@ -206,10 +222,16 @@ class Schedule
 
      } while($counter < $this->possiblePermutations);
 
  }
 
    
 
  /**
 
   * \brief
 
   *   Prints out the possible permutations in tables.
 
   *
 
   * \param $schedule_store
 
   *   The schedule_store handle with which this schedule was loaded,
 
   *   used to query the parent schedule.
 
   */
 
  //--------------------------------------------------
 
  // Prints out the possible permutations in tables.
 
  //--------------------------------------------------
 
  function writeoutTables()
 
  function writeoutTables(array $schedule_store = NULL)
 
  {
 
    $filled = false;
 
    $time = array(700,730,800,830,900,930,1000,1030,1100,1130,1200,1230,1300,1330,1400,1430,1500,1530,1600,1630,1700,1730,1800,1830,1900,1930,2000,2030,2100,2130, 2200);
 
@@ -264,7 +286,7 @@ class Schedule
 

	
 
    }
 
    else {
 
      echo '<script type="text/javascript">';
 
      echo '        <script type="text/javascript">';
 
      echo '  jQuery(document).ready( function() {';
 
      echo '    jQuery("#tabs").tabs();';
 
      echo '    jQuery.address.change(function(event){';
 
@@ -284,15 +306,28 @@ class Schedule
 
	        });
 
	        jQuery(\'#cancelItems\').click( function() {
 
		  jQuery(\'#selectItemsInput\').hide();
 
	        });';
 
      echo '  });
 
            </script>';
 
	        });'
 
	. '  });' . PHP_EOL
 
	. '        </script>' . PHP_EOL;
 

	
 
      echo '<div id="sharedialog" title="Share Schedule"><p class="indent"><img class="noborder" src="http://facebook.com/favicon.ico" /> <a target="_blank" href="http://www.facebook.com/sharer.php?u=' . urlencode(htmlentities($outputPage->gen_share_url($this->id_get()))) .'&amp;t=My%20Schedule">Share on Facebook</a></p><p class="indent">You can also share your schedule with the URL below:<br /><em class="centeredtext smallurl">' . htmlentities($outputPage->gen_share_url($this->id_get())) . '</em></p></div>' . "\n";
 
      echo '<p><a href="input.php?s='.$this->id.'" class="button">Edit</a> <span id="printItems"><a href="#" class="button">Print</a></span> <span id="share"><a href="#" class="button">Share</a></span>  <a class="button" href="input.php">Home</a></p>'. "\n";
 
      echo '<p class="centeredtext">Having problems? <a href="feedback.php">Let us know</a>.</p>' . "\n";
 
      echo '<p class="centeredtext graytext"><em>Keyboard Shortcut: Left and right arrow keys switch between schedules</em></p>' . "\n";
 
      echo '        <div id="sharedialog" title="Share Schedule">' . PHP_EOL
 
	. '          <p class="indent"><img class="noborder" src="http://facebook.com/favicon.ico" /> <a target="_blank" href="http://www.facebook.com/sharer.php?u=' . urlencode(htmlentities($outputPage->gen_share_url($this->id_get()))) .'&amp;t=My%20Schedule">Share on Facebook</a></p><p class="indent">You can also share your schedule with the URL below:<br /><em class="centeredtext smallurl">' . htmlentities($outputPage->gen_share_url($this->id_get())) . '</em></p>' . PHP_EOL
 
	. '        </div>' . PHP_EOL
 
	. '        <p>' . PHP_EOL
 
	. '          <a href="input.php?s='.$this->id.'" class="button">Edit</a>' . PHP_EOL
 
	. '          <span id="printItems"><a href="#" class="button">Print</a></span>' . PHP_EOL
 
	. '          <span id="share"><a href="#" class="button">Share</a></span>' . PHP_EOL;
 

	
 

	
 
      if ($schedule_store !== NULL
 
	  && $this->parent_get() !== NULL
 
	  && ($parent_schedule = schedule_store_retrieve($schedule_store, $this->parent_get())) !== NULL)
 
	echo '          <a class="button" href="' . htmlentities($parent_schedule->url()) . '" title="Parent schedule: ' . htmlentities($parent_schedule->getName()) . '">Parent</a>' . PHP_EOL;
 

	
 
      echo '          <a class="button" href="input.php">Home</a>' . PHP_EOL
 
	. '        </p>'. PHP_EOL
 
	. '        <p class="centeredtext">Having problems? <a href="feedback.php">Let us know</a>.</p>' . PHP_EOL
 
	. '        <p class="centeredtext graytext"><em>Keyboard Shortcut: Left and right arrow keys switch between schedules</em></p>' . PHP_EOL;
 
    }		
 

	
 
    echo "\n";
 
@@ -598,6 +633,16 @@ class Schedule
 

	
 
  /**
 
   * \brief
 
   *   Get the ID of the schedule from which this schedule was
 
   *   derived.
 
   */
 
  public function parent_get()
 
  {
 
    return $this->parent_id;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   A magic function which tries to upgrade old serialized sections
 
   *   to the new format.
 
   */
 
@@ -613,5 +658,8 @@ class Schedule
 
	$this->courses[] = $classes->to_course();
 
      }
 
    $this->nclasses = -1;
 

	
 
    if (empty($this->parent_id))
 
      $this->parent_id = NULL;
 
  }
 
}
input.php
Show inline comments
 
@@ -31,11 +31,12 @@ require_once('inc' . DIRECTORY_SEPARATOR
 
$sch = FALSE;
 
$school = $inputPage->get_school();
 

	
 
$parent_schedule_id = NULL;
 
if (isset($_REQUEST['s']))
 
  {
 
    $schedule_store = schedule_store_init();
 
    $schedule_id = (int)$_REQUEST['s'];
 
    $sch = schedule_store_retrieve($schedule_store, $schedule_id);
 
    $parent_schedule_id = (int)$_REQUEST['s'];
 
    $sch = schedule_store_retrieve($schedule_store, $parent_schedule_id);
 
  }
 

	
 
$my_hc = 'var slate_permutate_example_course_id = \'' . str_replace('\'', '\\\'', school_example_course_id($inputPage->get_school())) . '\';
 
@@ -135,7 +136,10 @@ if (!empty($_REQUEST['selectsemester']))
 

	
 
<form method="post" action="process.php" id="scheduleForm">
 
<p class="nospace" style="border-left: 5px solid #999; padding-left: 5px!important; padding-top: 5px!important;"><label>Schedule Name</label><br />
 
  <input id="scheduleName" style="margin-bottom: 1em;" class="defText required" type="text" size="25" title="Spring 2011" name="postData[name]" <?php if ($sch) echo 'value="' . htmlentities($sch->getName(), ENT_QUOTES) . '"'; /*"*/ ?> />
 
  <input id="scheduleName" style="margin-bottom: 1em;" class="defText required" type="text" size="25" title="Spring 2011" name="postData[name]" <?php if ($sch) echo 'value="' . htmlentities($sch->getName(), ENT_QUOTES) . '"'; ?> />
 
  <?php if (!empty($parent_schedule_id)): ?>
 
  <input type="hidden" name="postData[parent_schedule_id]" value="<?php echo htmlentities($parent_schedule_id); ?>" />
 
  <?php endif; ?>
 
</p>
 

	
 
<table id="container">
process.php
Show inline comments
 
@@ -93,7 +93,7 @@ if(!$DEBUG)
 
      {
 
	$savedSched = schedule_store_retrieve($schedule_store, $s);
 
	if ($savedSched)
 
	  $savedSched->writeoutTables();
 
	  $savedSched->writeoutTables($schedule_store);
 
	else
 
	  page::show_404('Unable to find a saved schedule with an ID of ' . $s . '.');
 
      }
 
@@ -122,8 +122,22 @@ if(!$DEBUG)
 
	 * it as a schedule to permutate. Then we should redirect the
 
	 * user to the canonical URL for that schedule.
 
	 */
 
		$allClasses = new Schedule($_POST['postData']['name']);
 
	
 
	$name = '';
 
	if (!empty($_POST['postData']['name']))
 
	  $name = $_POST['postData']['name'];
 

	
 
	$parent_schedule_id = NULL;
 
	if (!empty($_POST['postData']['parent_schedule_id']))
 
	  {
 
	    $parent_schedule_id = (int)$_POST['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);
 

	
 
		foreach($_POST['postData'] as $class)
 
		{
 
		  /*
0 comments (0 inline, 0 general)