diff --git a/class.class.php b/class.class.php --- a/class.class.php +++ b/class.class.php @@ -65,4 +65,25 @@ class Classes { return $this->name; } + + /** + * \brief + * Renders this Classes into something suitable for input.php. + */ + function input_form_render($class_key) + { + $n = "\n"; + $out = '' . $n + . ' getName()) . '"/>' . $n + . ' ' . $n + . '
' . $n + . '
' . $n + . "\n"; + + foreach ($this->sections as $key => $section) + $out .= $section->input_form_render($class_key, $key); + + return $out; + } + } diff --git a/class.schedule.php b/class.schedule.php --- a/class.schedule.php +++ b/class.schedule.php @@ -21,15 +21,24 @@ class Schedule private $possiblePermutations; // Integer number of possible permutations private $scheduleName; // String name of schedule private $storage; // Integer array of valid schedules - private $title = "SlatePermutate - Scheduler"; + private $title; + /** + * The input format of the sections. Only used for the UI. Valid + * values are 'numerous' for custom, 'numbered' for numeric, and 'lettered' for + * alphabetical. + */ + public $section_format; - //-------------------------------------------------- - // Creates a schedule with the given name. - //-------------------------------------------------- - function __construct($n) - { - $this->nclasses = 0; - $this->scheduleName = $n; + /** + * \brief + * Create a schedule with the given name. + */ + function __construct($name) + { + $this->nclasses = 0; + $this->scheduleName = $name; + $this->title = "SlatePermutate - Scheduler"; + $this->section_format = 'numerous'; } //-------------------------------------------------- @@ -528,9 +537,42 @@ class Schedule } else { echo '

There are no possible schedules. Please try again.

'; } + + /* edit button */ + if (!isset($savedkey)) + { + if (isset($_REQUEST['savedkey'])) + $savedkey = (int)$_REQUEST['savedkey']; + else + /* + * if this is a new saved schedule, it'll be the + * next item added to $_SESSION['saved'] + */ + $savedkey = max(array_keys($_SESSION['saved'])) + 1; + } + echo '
'; + $outputPage->foot(); } + /** + * \brief + * Render the input table form for editing a saved schedule in input.php. + * + * This function's output must be synchronized with the + * associated javascript in scripts/scheduleInput.js. + */ + function input_form_render() + { + $out = ''; + static $n = "\n"; + + foreach ($this->classStorage as $class_key => $class) + $out .= $class->input_form_render($class_key); + + return $out; + } + //-------------------------------------------------- // Changes the title of the page. //-------------------------------------------------- @@ -552,4 +594,21 @@ class Schedule } } + /** + * \brief + * fetch the number of classes + */ + function nclasses_get() + { + return $this->nclasses; + } + + /* + * \brief + * fetch a specified class by its key + */ + function class_get($class_key) + { + return $this->classStorage[$class_key]; + } } diff --git a/class.section.php b/class.section.php --- a/class.section.php +++ b/class.section.php @@ -146,4 +146,95 @@ function getF() return $this->bdays[4]; } + /** + * \brief + * Create output suitable for editing on input.php. + * + * \see Classes::input_form_render() + * + * \param $class_key + * The same $class_key passed to Classes::input_form_render(). + * \param $section_key + * The index of this section. + * \param $section_format + * The type of input method used for this section. Valid values + * are 'numerous', 'numbered', and 'lettered' + */ + function input_form_render($class_key, $section_key, $section_format = 'numerous') + { + static $n = "\n"; + $out = '' . $n + . ' ' . $n; + switch ($section_format) + { + case 'numerous': + default: + /* see customIds() in scheduleInput.js */ + $out .= ' ' . $n + . ' ' . $n + . " \n"; + break; + } + + $out .= " \n" + . ' \n" + . " \n"; + + /* ugh, code duplication :-( --binki commenting on his own code*/ + $out .= " \n" + . ' \n" + . " \n"; + + foreach ($this->bdays as $day_key => $day_enabled) + { + if ($day_enabled) + $day_enabled = 'checked="checked"'; + else + $day_enabled = ''; + $out .= " \n" + . ' ' . $n + . " \n"; + } + + $out .= "\n"; + + return $out; + } } diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -30,7 +30,8 @@ class page { private $pagetitle = ''; // Title of page private $scripts = array(); // Scripts to include on page - public function __construct($ntitle, $nscripts = array() ){ + public function __construct($ntitle, $nscripts = array(), $immediate = TRUE) + { // Scripts and styles available to include $this->headCode['jQuery'] = ''; $this->headCode['jValidate'] = ''; @@ -41,11 +42,31 @@ class page { $this->pagetitle = $ntitle; $this->scripts = $nscripts; - if($ntitle != "NOHEAD") + if($immediate + && $ntitle != "NOHEAD") $this->head(); + session_start(); } + /** + * \brief + * Adds some headcode to this page. + * + * \param $key + * The key to register this headcode under. + * \param $code + * The actuall code, such as a '; + $inputPage->headcode_add('scheduleInput', $my_hc, TRUE); +} +else + $inputPage->headcode_add('schduleInput', '', TRUE); + +$inputPage->head(); $inputPage->showSavedScheds($_SESSION); - ?>
- - - - - + + + + @@ -38,6 +77,7 @@ include_once 'inc/class.page.php'; + input_form_render(); ?>
- (For example: Fall ) -
+
+ getName()) . '"'; /*"*/ ?> + /> + (For example: Fall ) +
+
Add Class - This row should be just as wide as the one above someday diff --git a/process.php b/process.php --- a/process.php +++ b/process.php @@ -78,12 +78,19 @@ if(!$DEBUG){ foreach(sortInputs($_POST) as $class) { - if(is_array($class)) // Skip the schedule name + /* + * Only add classes if the user added at least one + * section to the class. We know that $class['name'] + * is not a section, so count() needs to be > 1 and + * we need to skip over 'name' in our loop. + */ + if(is_array($class) && count($class) > 1) { $allClasses->addClass($class['name']); foreach($class as $section) - if(is_array($section)) // Skip the section name, which isn't a section + /* Skip the section name, which isn't a section */ + if(is_array($section)) { $allClasses->addSection($class['name'], $section['letter'], $section['start'], $section['end'], arrayToDays($section['days'])); } @@ -95,7 +102,6 @@ if(!$DEBUG){ $_SESSION['saved'] = array(); array_push ( $_SESSION['saved'], serialize($allClasses)); } - } else { diff --git a/schedulecreator.php b/schedulecreator.php --- a/schedulecreator.php +++ b/schedulecreator.php @@ -14,7 +14,7 @@ include_once 'class.section.php'; $allClasses = new Schedule("Fall 2010"); - $allClasses->changeTitle("Demonstration :: SlatePermutate - Scheduler"); + $allClasses->title = "Demonstration :: SlatePermutate - Scheduler"; $allClasses->addClass("CS 104"); $allClasses->addSection("CS 104", "A", 1030, 1120, 24); diff --git a/scripts/scheduleInput.js b/scripts/scheduleInput.js --- a/scripts/scheduleInput.js +++ b/scripts/scheduleInput.js @@ -54,8 +54,8 @@ }); - var classNum = 0; - var sectionsOfClass = new Array(); // holds number of sections for each class + /* classNum is declared in the to enable loading of saved classes */ + /* sectionsOfClass is declared in the to enable loading of saved sections */ function numberedIds(name){ return '\ @@ -72,7 +72,7 @@ '; } function customIds(name){ - return ''; + return ''; } //--------------------------------------------------