Files
@ 3ee56e630825
Branch filter:
Location: SlatePermutate/process.php - annotation
3ee56e630825
5.0 KiB
text/x-php
Upon a valid autocompletion, highlight the input box for the automatically created new course for smoother workflow.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | 27edaecc0d90 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 1cb6f6105b45 27edaecc0d90 6b24e9820611 6b24e9820611 30c9462fd881 5d94cc8ac7cd 30c9462fd881 27edaecc0d90 7a6777d84d07 27edaecc0d90 27edaecc0d90 27edaecc0d90 12553a2740cb 12553a2740cb 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 12553a2740cb 12553a2740cb 12553a2740cb 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 58eeb176287a 58eeb176287a 58eeb176287a 58eeb176287a 58eeb176287a 6b24e9820611 6b24e9820611 6b24e9820611 27edaecc0d90 6b24e9820611 27edaecc0d90 6b24e9820611 6b24e9820611 a23c8e3ebe9e a23c8e3ebe9e a23c8e3ebe9e a23c8e3ebe9e a23c8e3ebe9e 6b24e9820611 a23c8e3ebe9e 6b24e9820611 6b24e9820611 6b24e9820611 a23c8e3ebe9e 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 f13987338fbf 864e30313107 58eeb176287a 6b24e9820611 a23c8e3ebe9e a23c8e3ebe9e 864e30313107 a23c8e3ebe9e a23c8e3ebe9e 6b24e9820611 6b24e9820611 a23c8e3ebe9e a23c8e3ebe9e a23c8e3ebe9e a23c8e3ebe9e a23c8e3ebe9e 5cce14d5f1c2 8a7d392478a6 58eeb176287a 8a7d392478a6 cebfe2251d8c cebfe2251d8c cebfe2251d8c cebfe2251d8c cebfe2251d8c cebfe2251d8c cebfe2251d8c 5cce14d5f1c2 5d94cc8ac7cd 5cce14d5f1c2 5cce14d5f1c2 cebfe2251d8c cebfe2251d8c 5cce14d5f1c2 3a5b03ccb906 5cce14d5f1c2 5cce14d5f1c2 8a7d392478a6 8a7d392478a6 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 a23c8e3ebe9e a23c8e3ebe9e a23c8e3ebe9e 864e30313107 a23c8e3ebe9e 6b24e9820611 6b24e9820611 6b24e9820611 6b24e9820611 27edaecc0d90 58eeb176287a 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 27edaecc0d90 | <?php
/*
* Copyright 2010 Nathan Gelderloos, Ethan Zonca, Nathan Phillip Brink
*
* This file is part of SlatePermutate.
*
* SlatePermutate is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SlatePermutate is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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/>.
*/
require_once('inc/schedule_store.inc');
require_once('inc/class.page.php');
include_once 'inc/class.schedule.php';
include_once('inc/class.course.inc');
include_once 'inc/class.section.php';
// Converts a 5-element day array into a string.
// Supports multiple modes, prettiness, and searching for different indicators
function arrayToDays($array, $mode = 'num', $pretty = false, $key = 1) {
$outString = '';
switch($mode)
{
case 'short':
$days = array('Mon','Tue','Wed','Thur','Fri');
break;
case 'long':
$days = array('Monday','Tuesday','Wednesday','Thursday','Friday');
break;
case 'num':
$days = array('1','2','3','4','5');
break;
case 'alpha':
$days = array('m', 't', 'w', 'h', 'f');
break;
default:
$outString = 'Invalid mode passed to arrayToDays()!';
return $outString;
}
if(count($array) > 1){
for($i=0; $i<=4; $i++) {
if(isset($array[$i]) && $array[$i] == $key){
$outString .= $days[$i];
if($pretty)
$outString .= ', ';
}
}
if($pretty){
$outString = substr($outString,0,strlen($outString) - 2); // Remove last comma and space
$outString = substr($outString,0, strrpos( $outString, ' ')) . ' and' . substr($outString, strrpos( $outString, ' '), strlen($outString));
}
}
else {
for($i=0; $i<=4; $i++)
if(isset($array[$i]))
$outString = $days[$i];
}
return $outString;
}
function prettyTime($time){
return substr($time,0,strlen($time)-2) . ":" . substr($time,strlen($time)-2, strlen($time));
}
/*
* The below code relies on sessions being started already.
*/
page::session_start();
$DEBUG = FALSE;
if (isset($_GET['debug']))
$DEBUG = $_GET['debug'];
$schedule_store = schedule_store_init();
if(!$DEBUG)
{
$s = FALSE;
if (isset($_GET['s']))
$s = $_GET['s'];
if($s !== FALSE)
{
$savedSched = schedule_store_retrieve($schedule_store, $s);
if ($savedSched)
$savedSched->writeoutTables();
else
page::show_404('Unable to find a saved schedule with an ID of ' . $s . '.');
}
elseif(isset($_GET['del']))
{
/* Allow the user to delete schedules that he has stored in his session */
if ($_SESSION['saved'][(int)$_GET['del']])
{
/* user owns this schedule ID */
schedule_store_delete($schedule_store, (int)$_GET['del']);
unset($_SESSION['saved'][(int)$_GET['del']]);
}
page::redirect('input.php');
exit;
}
elseif (!isset($_POST['postData']))
{
page::redirect('input.php');
exit;
}
else
{
/*
* we probably have input from the user and should interpret
* 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']);
foreach($_POST['postData'] as $class)
{
/*
* 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->addCourse($class['name']);
foreach($class as $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'], 'alpha'), $section['synonym'], $section['professor'], $section['location'], $section['type']);
}
}
}
$allClasses->findPossibilities();
if (!isset($_SESSION['saved']))
$_SESSION['saved'] = array();
$schedule_id = schedule_store_store($schedule_store, $allClasses);
if ($schedule_id != NULL)
$_SESSION['saved'][$schedule_id] = $allClasses->getName();
$process_php_s = '';
if (!$clean_urls)
$process_php_s = 'process.php?s=';
page::redirect($process_php_s . $schedule_id);
exit;
}
}
else
{
echo '<pre>DEBUG OUTPUT: <br /><br />';
foreach($_POST['postData'] as $class) {
echo 'Class: ' . $class['name'] . '<br />';
foreach($class as $section)
if(is_array($section))
{
echo '---- Section that starts at ' . prettyTime($section['start']) . ' and ends at ' . prettyTime($section['end']) . '. This class meets on ';
echo arrayToDays($section['days'],'long',true) . '.<br />';
}
echo '<br />';
}
echo '</pre>';
}
|