classStorage = array();
    $this->nclasses = 0;
    $this->scheduleName = $name;
    $this->storage = array();
    $this->title = "SlatePermutate - Scheduler";
    $this->section_format = 'numerous';
  }
  //--------------------------------------------------
  // Mutators and Accessors
  //--------------------------------------------------
  public function getName()
  {
    return $this->scheduleName;
  }    
  //--------------------------------------------------
  // Adds a new class to the schedule.
  //--------------------------------------------------
  function addClass($n)
  {
    $this->classStorage[$this->nclasses] = new Classes($n);
    $this->nclasses++;
  }
  //--------------------------------------------------
  // Adds a section to the desired class.
  //--------------------------------------------------
  function addSection($n, $l, $s, $e, $d)
  {
    $found = false;
    $counter = 0;
      
    while(!$found && ($counter < $this->nclasses))
      {
	$temp = $this->classStorage[$counter]->getName();
			
	if((strcmp($temp,$n)) == 0)
	  {
	    $found = true;
	  } else {
	  $counter++;
	}
      }
		
    if($counter == $this->nclasses)
      {
	echo "Could not find class: " . $n . "
";
      } else {
      $p = "unknown prof";
      $this->classStorage[$counter]->addSection($l, $p, $s, $e, $d);
    }
  }
  //--------------------------------------------------
  // Finds all of the possible permutations and stores
  // the results in the storage array.
  //--------------------------------------------------
	function findPossibilities()
	{
		$this->possiblePermutations = 1;
		/* special case: there is nothing entered into the schedule and thus there is one, NULL permutation */
		if (!$this->nclasses)
		{
			/* have an empty schedule */
			$this->classStorage[0] = array();
			$this->nPermutations = 1;
			return;
		}
		$position = 0;
		$counter = 0;
		for($i = 0; $i < $this->nclasses; $i++)
		{
			$this->possiblePermutations = $this->possiblePermutations * $this->classStorage[$i]->getnsections();
			$cs[$i] = 0;	// Sets the counter array to all zeroes.
		}
        
		// Checks for conflicts in given classes, stores if none found
		do
		{
			$conflict = false;
         
			// Get first class to compare
			for ($upCounter = 0; $upCounter < $this->nclasses && !$conflict; $upCounter ++)
			{
	    
				for ($downCounter = $this->nclasses - 1; $downCounter > $upCounter && !$conflict; $downCounter --)
				{
					$start1 = $this->classStorage[$upCounter]->getSection($cs[$upCounter])->getStartTime();
					$end1 = $this->classStorage[$upCounter]->getSection($cs[$upCounter])->getEndTime();
					$start2 = $this->classStorage[$downCounter]->getSection($cs[$downCounter])->getStartTime();
					$end2 = $this->classStorage[$downCounter]->getSection($cs[$downCounter])->getEndTime();
					
					// If the two times overlap, then check if days overlap.
					if ((($start1 >= $start2) && ($start1 <= $end2)) || (($start2 >= $start1) && ($start2 <= $end1)))
					{
				
					for($day=0; $day<5; $day++)
						{
							if(!$conflict
								&& ($this->classStorage[$upCounter]->getSection($cs[$upCounter])->getDay($day)
								&& $this->classStorage[$downCounter]->getSection($cs[$downCounter])->getDay($day)))
							{
								$conflict = TRUE;
							}
						}
		
				}
			}
		}
            
	// Store to storage if no conflict is found.
	if(!$conflict)
	  {
	    for($i = 0; $i < $this->nclasses; $i++)
	      {
		$this->storage[$this->nPermutations][$i] = $cs[$i];
	      }
	    $this->nPermutations++;
	  }
			
	// Increase the counter by one to get the next combination of class sections.
	$cs[$position] = $cs[$position] + 1;
			
	// Check to make sure the counter is still valid.
	$valid = false;
	while(!$valid)
	  {
	    if($cs[$position] == $this->classStorage[$position]->getnsections())
	      {
		$cs[$position] = 0;
		$position++;
					
		// This is for the very last permutation. Even 
		// though the combination is not actually true
		// the larger while loop will end before any 
		// new combinations are performed.
		if($position == $this->nclasses)
		  {
		    $valid = true;
		  } else {
		  $cs[$position]++;
		}
	      } else {
	      $valid = true;
	      $position = 0;
	    }
	  }
            
	$counter++;
      } while($counter < $this->possiblePermutations);
  }
    
  //--------------------------------------------------
  // Prints out the possible permutations in tables.
  //--------------------------------------------------
  function writeoutTables()
  {
    $table = "";
    $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);
    $footcloser = '';
    if(isset($_REQUEST['print']) && $_REQUEST['print'] != ''){
      $headcode = array('jQuery', 'jQueryUI', 'uiTabsKeyboard', 'outputStyle', 'outputPrintStyle');
    }
    else {
      $headcode = array('outputStyle',  'jQuery', 'jQueryUI', 'uiTabsKeyboard');
    }
    $outputPage = new Page(htmlentities($this->getName()), $headcode);
    if(isset($_REQUEST['print'])){
 
     echo '';
      echo '
Select Schedules to Print :: Return to normal view :: Home
'; echo 'id_get() . '&print=all">Print :: Home
Keyboard Shortcut: Left and right arrow keys switch between schedules
'; } if($this->nPermutations > 0) { $table .= "
| " . ($i+1) . " | \n\t\tMonday | \n\t\tTuesday | \n\t\tWednesday | \n\t\tThursday | \n\t\tFriday | \n\t
| " . $this->prettyTime($time[$r]) . " | "; for($dayLoop = 0; $dayLoop < 5; $dayLoop++) { for($j = 0; $j < $this->nclasses; $j++) { // Makes sure there is not a class already in progress if($this->getClassCont($dayLoop) == -1) { // Checks if the class meets on the given day if(($this->classStorage[$j]->getSection($this->storage[$i][$j])->getDay($dayLoop))) { // Checks if the class meets at the given time if(($this->classStorage[$j]->getSection($this->storage[$i][$j])->getStartTime() >= $time[$r]) && ($this->classStorage[$j]->getSection($this->storage[$i][$j])->getStartTime() < $time[$r+1])) { // Checks if the class continues after the given time if($this->classStorage[$j]->getSection($this->storage[$i][$j])->getEndTime() > $time[$r+1]) { $table .= "\n\t\t" . htmlentities($this->classStorage[$j]->getName()) . " " . htmlentities($this->classStorage[$j]->getSection($this->storage[$i][$j])->getLetter()) . " | "; $this->setClassCont($dayLoop, $j); $filled = true; }else{ $table .= "\n\n\t" . htmlentities($this->classStorage[$j]->getName()) . " " . htmlentities($this->classStorage[$j]->getSection($this->storage[$i][$j])->getLetter()) . " | "; $filled = true; } } } }else{ if($j == $this->getClassCont($dayLoop)) { if($this->classStorage[$j]->getSection($this->storage[$i][$j])->getEndTime() > $time[$r+1]) { $table .= "\n\t\t"; $filled = true; }else{ $table .= "\n\t\t | "; $this->setClassCont($dayLoop, -1); $filled = true; } } } } // If the cell was not filled, fill it with an empty cell. if(!$filled) { $table .= "\n\t\t | "; } $filled = false; } // End of row $table .= "\n\t | 
There are no possible schedules. Please try again.
'; } /* edit button */ echo ''; echo "There were a total of " . $this->possiblePermutations . " possible permutations. Only " . $this->nPermutations . " permutations had no class conflicts.
"; $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. //-------------------------------------------------- function changeTitle($t) { $this->title = $t; } //-------------------------------------------------- // Make the time "pretty." //-------------------------------------------------- function prettyTime($t){ if($t > 1259) { $t = ($t-1200); return substr($t, 0, strlen($t)-2) . ":" . substr($t, strlen($t)-2, strlen($t)) . " PM"; } else { return substr($t, 0, strlen($t)-2) . ":" . substr($t, strlen($t)-2, strlen($t)) . " AM"; } } /** * \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]; } /** * \brief * Set my global ID. * * Only to be called by schedule_store_store(). */ function id_set($id) { $this->id = $id; } /* * \brief * Get my global ID. */ function id_get() { return $this->id; } function getClassCont($day) { return $this->classContinue[$day]; } function setClassCont($day, $i) { $this->classContinue[$day] = $i; } }