Changeset - 85225ae6e519
[Not reviewed]
default
0 4 0
Nathan Brink (binki) - 14 years ago 2011-04-09 11:42:43
ohnobinki@ohnopublishing.net
Fix up remembering the school of an edited schedule on the input pages.
4 files changed with 46 insertions and 17 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
@@ -248,36 +248,41 @@ class page
 
          '    <![endif]-->'. PHP_EOL .
 
          '    <link rel="shortcut icon" href="images/favicon.png" />'. PHP_EOL
 
      . '    <style type="text/css">' . PHP_EOL
 
      . $this->cdata_wrap(school_page_css($this->school))
 
      . '    </style>' . PHP_EOL
 
      . $this->script_wrap(''
 
			   . 'var slate_permutate_school = ' . json_encode($this->school['id']) . ';' . PHP_EOL
 
			   . 'var slate_permutate_semester = ' . json_encode($this->semester['id']) . ';' . PHP_EOL);
 
    // Write out all passed scripts
 
    foreach ($this->scripts as $i)
 
      echo '    ' . $this->headCode["$i"] . "\n";
 

	
 
    $selectschool_query = '&amp;school=' . $this->school['id'];
 
    /* kludge */
 
    if (!empty($_REQUEST['s']))
 
      $selectschool_query .= '&amp;s=' . (int)$_REQUEST['s'];
 

	
 
    echo '  </head>' . PHP_EOL .
 
	 '  <body>'. PHP_EOL .
 
         '    <div id="page">'. PHP_EOL .
 
         '      <div id="header">'. PHP_EOL .
 
	 '        <div id="title">'. PHP_EOL .
 
         '          <h1><a href="index.php"><img src="images/slatepermutate-alpha.png" alt="SlatePermutate" class="noborder" /></a><br /></h1>'. PHP_EOL .
 
         '          <p>'. PHP_EOL .
 
         '            <span id="subtitle">'.$this->pagetitle.'</span>'. PHP_EOL .
 
  	 '            <span id="menu">' . PHP_EOL
 
      . '              Profile: <em>' . $this->school['name'] . '</em>' . ($this->school_semester_constant ? '' : ' <a href="input.php?selectschool=1">(change)</a>') . PHP_EOL;
 
      . '              Profile: <em>' . $this->school['name'] . '</em>' . ($this->school_semester_constant ? '' : ' <a href="input.php?selectschool=1' . $selectschool_query . '">(change)</a>') . PHP_EOL;
 
    if (!empty($this->semester))
 
      echo  '             Semester: <em>' . $this->semester['name'] . '</em>' . ($this->school_semester_constant ? '' : ' <a href="input.php?selectsemester=1">(change)</a>') . PHP_EOL;
 
      echo  '             Semester: <em>' . $this->semester['name'] . '</em>' . ($this->school_semester_constant ? '' : ' <a href="input.php?selectsemester=1' . $selectschool_query . '">(change)</a>') . PHP_EOL;
 
    echo '            </span>'. PHP_EOL .
 
         '          </p>'. PHP_EOL .
 
         '        </div>'. PHP_EOL .
 
	 '      </div>'. PHP_EOL .
 
         '      <div id="content">'. PHP_EOL;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Write out the foot of the page and closing divs
 
   */
 
  public function foot(){
inc/class.schedule.php
Show inline comments
 
@@ -108,25 +108,25 @@ class Schedule
 
   * \param $semester
 
   *   The semester used for this schedule.
 
   */
 
  function __construct($name, $parent = NULL, array $school = NULL, array $semester = NULL)
 
  {
 
    $this->courses = array();
 
    $this->scheduleName = $name;
 
    $this->storage = array();
 
    $this->title = "SlatePermutate - Scheduler";
 
    $this->parent_id = $parent;
 

	
 
    if (empty($school))
 
      $school = school_load_guess();
 
      $school = school_load_guess(FALSE);
 
    $this->school_id = $school['id'];
 

	
 
    if (empty($semester))
 
      {
 
	$semester = school_semester_guess($school);
 
      }
 
    $this->semester = $semester;
 

	
 
    /* mark this as an upgraded Schedule class. See __wakeup() */
 
    $this->nclasses = -1;
 
  }
 

	
 
@@ -202,25 +202,25 @@ class Schedule
 
    $school = NULL;
 

	
 
    if (!empty($this->school_id))
 
      /*
 
       * May return NULL, so we don't just return this value right
 
       * away -- we fall through.
 
       */
 
      $school = school_load($this->school_id);
 
    if (empty($school))
 
      {
 
	/* Ensure we have $_SESSION. */
 
	page::session_start();
 
	$school = school_load_guess();
 
	$school = school_load_guess(FALSE);
 
      }
 

	
 
    return $school;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Get the semester associated with this schedule.
 
   *
 
   * \return
 
   *   The schedule's associated semester.
 
   */
 
@@ -813,25 +813,25 @@ class Schedule
 
      {
 
	$this->courses[] = $classes->to_course();
 
      }
 
    $this->nclasses = -1;
 

	
 
    if (empty($this->parent_id))
 
      $this->parent_id = NULL;
 

	
 
    if (empty($this->school_id))
 
      {
 
	/* 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))
 
      {
 
	if (empty($school))
 
	  {
 
	    /* Ensure we have $_SESSION. */
 
	    page::session_start();
 

	
 
	    $school = school_load($this->school_id);
 
	    $this->semester = school_semester_guess($school);
 
	  }
inc/school.inc
Show inline comments
 
@@ -218,37 +218,37 @@ function school_load_guess($update_sessi
 
function school_list_html($highlight = NULL, $linkto = NULL)
 
{
 
  $cache = _school_cache_load();
 
  if (!$cache || !count($cache['list']))
 
    return NULL;
 
  $school_list = $cache['list'];
 

	
 
  /* form the query string for the links */
 
  if (!$linkto)
 
    $linkto = '?';
 
  elseif (strpos($linkto, '?') === FALSE)
 
    $linkto .= '?';
 
  else
 
  elseif (strpos('?&', strstr($linkto, -1)) !== FALSE)
 
    $linkto .= '&';
 
  $linkto .= 'school=';
 
  $linkto = htmlentities($linkto);
 

	
 
  $html = "<ul>\n";
 
  foreach ($school_list as $school_id => $school_info)
 
    {
 
      $class_highlight = '';
 
      if ($school_id == $highlight)
 
	$class_highlight = ' highlight';
 
      $html .= '<li class="school' . $class_highlight . '"><a href="' . $linkto . $school_id . '">'
 
	. $school_info['name'] . "</a></li>\n";
 
	. htmlentities($school_info['name']) . "</a></li>\n";
 
    }
 
  $html .= "</ul>\n";
 

	
 
  return $html;
 
}
 

	
 
/**
 
 * \brief
 
 *   Get a school-specific information page.
 
 *
 
 * Each school may define a function called
 
 * <school_id>_instructions_html(). This is the wrapper which retrieves a
 
@@ -343,25 +343,25 @@ function school_semesters(array $school)
 
 *   makes the most sense.
 
 *
 
 * \param $school
 
 *   The school for which a semester should be guessed.
 
 * \param $update_session
 
 *   Whether or not $_SESSION should be updatd with the new value. A
 
 *   value of FALSE makes sense for the ajax.php callback script.
 
 * \return
 
 *   An array with the keys 'id', 'name', and 'weight' corresponding
 
 *   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);
 

	
 
  if (!empty($_REQUEST['semester'])
 
      && isset($semesters[$_REQUEST['semester']]))
 
    {
 
      $semester = $semesters[$_REQUEST['semester']];
 
      if ($update_session)
 
	$_SESSION['semester'] = $semester['id'];
 
      return $semester;
 
    }
 

	
input.php
Show inline comments
 
@@ -15,60 +15,76 @@
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with SlatePermutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
include_once 'inc' . DIRECTORY_SEPARATOR . 'class.schedule.php';
 
include_once 'inc' . DIRECTORY_SEPARATOR . 'class.course.inc';
 
include_once 'inc' . DIRECTORY_SEPARATOR . 'class.section.php';
 
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;
 
$inputPage_options = array('school_semester_constant' => FALSE);
 

	
 
$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);
 
    $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']))
 
  {
 
    /*
 
     * 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'];
 

	
 
    $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();
 

	
 
$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()
 
  {
 
    var class_last = 0;
 

	
 
';
 
if ($sch)
 
{
 
  $nclasses = $sch->nclasses_get();
 
  for ($class_key = 0; $class_key < $nclasses; $class_key ++)
 
    {
 
@@ -116,57 +132,65 @@ if ($qtips_always || !isset($_SESSION['s
 
$my_hc .= '  });
 
';
 

	
 
$inputPage->headcode_add('scheduleInput', $inputPage->script_wrap($my_hc), TRUE);
 

	
 
$inputPage->head();
 

	
 
/*
 
 * Force a student to choose a school or declare he's a generic
 
 * 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']) . '&';
 
?>
 
<h2>School Selection</h2>
 
<p>
 
  Choose the school you attend from the list below. <strong>If you cannot
 
  find your school</strong>, you may proceed using
 
  the <a href="<?php echo $next_page . (strpos($next_page, '?') === FALSE ? '?' : '&amp;'); ?>school=default">generic
 
  the <a href="<?php echo htmlentities($next_page); ?>school=default">generic
 
  settings</a>.
 
</p>
 
<?php
 
    $inputPage->showSchools($next_page);
 
    $inputPage->foot();
 
    exit;
 
  }
 

	
 
if (!empty($_REQUEST['selectsemester']))
 
  {
 
?>
 
<h2>Semester Selection</h2>
 
<p>
 
  Choose the semester for which you wish you make a schedule from the
 
  list below. If any semester is missing, please <a
 
  href="feedback.php?feedback=My+school+is+missing+the+&lt;semester+name&gt;+semester.">let us know</a>.
 
</p>
 
<?php
 
  $inputPage->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;
 
  }
 

	
 
$inputPage->showSavedScheds($_SESSION);
 
?>
 

	
 
<?php if (!empty($input_warning_banner)): ?>
 
<div class="warning">
 
  <?php echo $input_warning_banner; ?>
 
</div>
 
<?php endif; ?>
0 comments (0 inline, 0 general)