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($course_name, $letter, $time_start, $time_end, $days, $synonym = NULL, $faculty = NULL, $location = NULL)
  {
    $found = false;
    $counter = 0;
      
    while(!$found && ($counter < $this->nclasses))
      {
	$temp = $this->classStorage[$counter]->getName();
			
	if((strcmp($temp,$course_name)) == 0)
	  {
	    $found = true;
	  } else {
	  $counter++;
	}
      }
		
    if($counter == $this->nclasses)
      {
	echo 'Could not find class: ' . $course_name . "
\n";
      } else {
      $section = $this->classStorage[$counter]->section_get($letter);
      if (!$section)
	{
	  $section = new Section($letter, array(), $synonym, $faculty);
	  $this->classStorage[$counter]->section_add($section);
	}
      $section->meeting_add(new SectionMeeting($days, $time_start, $time_end, $location));
    }
  }
  //--------------------------------------------------
  // 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 --)
				{
				  if ($this->classStorage[$upCounter]->getSection($cs[$upCounter])
				      ->conflictsWith($this->classStorage[$downCounter]->getSection($cs[$downCounter])))
				    {
				      $conflict = TRUE;
				      break;
				    }
				}
			}
	
	// 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
Having problems? Let us know.
Keyboard Shortcut: Left and right arrow keys switch between schedules
'; } if($this->nPermutations > 0) { $table .= "
| ' . ($i + 1) . " | \n" . "Monday | \n" . "Tuesday | \n" . "Wednesday | \n" . "Thursday | \n" . "Friday | \n" . "
| " . $this->prettyTime($time[$r]) . " | \n"; for($dayLoop = 0; $dayLoop < 5; $dayLoop++) { /* Makes sure there is not a class already in progress */ if($rowspan[$lastDay] <= 0) { for($j = 0; $j < $this->nclasses; $j++) { $class = $this->classStorage[$j]; $section_index = $this->storage[$i][$j]; $section = $class->getSection($section_index); /* iterate through all of a class's meeting times */ $meetings = $section->getMeetings(); /* find any meeting which are going on at this time */ $current_meeting = NULL; foreach ($meetings as $meeting) { if ($meeting->getDay($dayLoop) && $meeting->getStartTime() >= $time[$r] && $meeting->getStartTime() < $time[$r+1]) { $current_meeting = $meeting; } } if ($current_meeting) { /* calculate how many rows this section should span */ for ($my_r = $r; $current_meeting->getEndTime() > $time[$my_r]; $my_r ++) ; $rowspan[$dayLoop] = $my_r - $r; $single_multi = 'single'; if ($rowspan[$dayLoop] > 1) $single_multi = 'multi'; $table .= '' . htmlentities($class->getName(), ENT_QUOTES) . '-' . htmlentities($section->getLetter(), ENT_QUOTES) . "\n" . '' . htmlentities($section->getProf(), ENT_QUOTES) . "\n" . '' . htmlentities($current_meeting->getLocation(), ENT_QUOTES) . "\n" . " | \n"; $filled = TRUE; } } } if ($rowspan[$dayLoop] > 0) { $filled = TRUE; $rowspan[$dayLoop] --; } /* If the cell was not filled, fill it with an empty cell. */ if(!$filled) { $table .= "\n"; } $filled = FALSE; } // End of row $table .= " | 
There are no possible schedules. Please try again.
'; } /* edit button */ if ($id = $this->id_get()) echo ''; echo "There were a total of " . $this->possiblePermutations . " possible permutations. Only " . $this->nPermutations . " permutations had no class conflicts.
"; $outputPage->foot(); } //-------------------------------------------------- // 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; } }