diff --git a/process.php b/process.php --- a/process.php +++ b/process.php @@ -72,6 +72,29 @@ function prettyTime($time){ return substr($time,0,strlen($time)-2) . ":" . substr($time,strlen($time)-2, strlen($time)); } +/** + * \brief + * Convert a multidimensional array to a set of s. + * + * Currently just echos out the s as they are created. + * + * \param $array + * The array to make into a set of s. + * \param $base + * The string to prefix. Normally the name of the array variable. + * \param $blankness + * A string to insert at the beginning of each line before an for indentation's sake. + */ +function array_to_form($array, $base = '', $blankness = ' ') +{ + foreach ($array as $key => $val) + if (is_array($val)) + array_to_form($val, $base . '[' . $key . ']', $blankness); + else + echo $blankness . '' . PHP_EOL; +} + /* * The below code relies on sessions being started already. */ @@ -138,6 +161,7 @@ if(!$DEBUG) $allClasses = new Schedule($name, $parent_schedule_id); + $errors = array(); foreach($_POST['postData'] as $class) { /* @@ -154,10 +178,47 @@ if(!$DEBUG) /* 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']); + $error_string = $allClasses->addSection($class['name'], $section['letter'], $section['start'], $section['end'], arrayToDays($section['days'], 'alpha'), $section['synonym'], $section['professor'], $section['location'], $section['type']); + if ($error_string !== NULL) + $errors[] = $error_string; } } } + + /* + * Tell the user that his input is erroneous and + * require him to fix it. + */ + if (count($errors)) + { + $error_page = new Page('Process Schedule — Errors'); + + echo '

' . PHP_EOL + . ' You have the following errors in your input:' . PHP_EOL + . '

' . PHP_EOL + . ' ' . PHP_EOL + . '

Solving Errors

' . PHP_EOL + . ' ' . PHP_EOL; + + /* Regurgitate the postData into a
*/ + echo ' ' . PHP_EOL + . ' ' . PHP_EOL; + array_to_form($_POST['postData'], 'postData', ' '); + echo ' ' . PHP_EOL + . '
' . PHP_EOL; + + $error_page->foot(); + exit; + } + $allClasses->findPossibilities(); if (!isset($_SESSION['saved'])) $_SESSION['saved'] = array();