diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -301,6 +301,58 @@ class page /** * \brief + * Perform a redirect. + * + * By consolidating all redirects here, we're hopefully able to do + * it in a somewhat compliant and portablish way ;-). + * + * This function does not return. It calls exit(). + * + * \param $dest + * A URL relative to the slate_permutate root. For example, + * 'input.php' or '44' (for clean urls, for example). + * \param $http_code + * The redirection code to use, if any. For example, this can be + * used to implement ``permanent'' redirects if necessary. + */ + public static function redirect($dest, $http_code = NULL) + { + if ($http_code) + header('HTTP/1.1 ' . $http_code); + + $uri = ''; + + $host = ''; + if (isset($_SERVER['SERVER_NAME'])) + $host = $_SERVER['SERVER_NAME']; + if (isset($_SERvER['HTTP_HOST'])) + $host = $_SERVER['HTTP_HOST']; + + if (strlen($host)) + { + $proto = 'http'; + $port = NULL; + if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) + { + if ($_SERVER['SERVER_PORT'] == 443 || !empty($_SERVER['HTTPS'])) + $proto .= 's'; + if ($_SERVER['SERVER_PORT'] != 433) + $port = $_SERVER['SERVER_PORT']; + } + + $uri = $proto . '://' . $host; + if ($port !== NULL) + $uri .= ':' . $port; + $uri .= dirname($_SERVER['REQUEST_URI']) . '/'; + } + + header('Location: ' . $uri . $dest); + + exit(); + } + + /** + * \brief * Get the current school profile handle. */ public function get_school() diff --git a/process.php b/process.php --- a/process.php +++ b/process.php @@ -84,12 +84,12 @@ if(!$DEBUG) unset($_SESSION['saved'][(int)$_GET['del']]); } - header('Location: input.php'); + page::redirect('input.php'); exit; } elseif (!isset($_POST['postData'])) { - header('Location: input.php'); + page::redirect('input.php'); exit; } else @@ -131,14 +131,8 @@ if(!$DEBUG) $process_php_s = ''; if (!$clean_urls) $process_php_s = 'process.php?s='; - header('Location: ' . $process_php_s . $schedule_id); + page::redirect($process_php_s . $schedule_id); exit; - /* - * writeoutTables() needs to know $schedule_id, so it - * has to be called after we save the schedule. See - * schedule_store_store(). - */ - $allClasses->writeoutTables(); } } else