2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
15 define('AT_INCLUDE_PATH', 'include/');
16 define('AT_REDIRECT_LOADED', true);
18 $_user_location = 'public'; //like browse, and registration, doesn't need username/passwords to get into
20 require_once(AT_INCLUDE_PATH . 'classes/UrlRewrite/UrlParser.class.php');
21 include_once(AT_INCLUDE_PATH.'config.inc.php');
22 require_once(AT_INCLUDE_PATH.'lib/constants.inc.php');
23 require_once(AT_INCLUDE_PATH.'lib/mysql_connect.inc.php');
24 //require_once(AT_INCLUDE_PATH.'vitals.inc.php');
26 //mimic config variables, vitals.inc.php 135-140
27 /* get config variables. if they're not in the db then it uses the installation default value in constants.inc.php */
28 $sql = "SELECT * FROM ".TABLE_PREFIX."config";
29 $result = mysql_query($sql, $db);
30 while ($row = mysql_fetch_assoc($result)) {
31 $_config[$row['name']] = $row['value'];
35 $pathinfo = getPathInfo();
37 $url_parser = new UrlParser($pathinfo);
38 $path_array = $url_parser->getPathArray();
39 $_pretty_url_course_id = $path_array[0];
40 $obj = $path_array[1];
42 if (!$obj->isEmpty()){
44 * Addresses the issue for relative uri
45 * @refer to constants.inc.php $_rel_link
47 $_rel_url = $obj->redirect();
48 $var_query = $obj->parsePrettyQuery();
49 save2Get($var_query); //remake all the _GET and _REQUEST variables so that the vitals can use it
51 $_user_location = ''; //reset user_location so that the vital file in each page would validate
52 $pretty_current_page = $obj->getPage();
53 //If page not found, forward back to index.php
54 //ignore error, cause it will give a warning: No such file error, and can't send header.
55 if (!@include($pretty_current_page)){
56 header('Location: '.AT_BASE_HREF.'index.php');
59 } elseif ($_pretty_url_course_id==0) {
60 //TODO: $_SESSION[course_id] seems to be resetted to 0, causing vitals.inc.php line 273 to redirect incorrectly.
61 // Need to find out where exactly the course_id is being resetted.
63 // header('location: '.AT_BASE_HREF.'bounce.php?course=0');
65 } elseif ($_pretty_url_course_id != ''){
66 header('location: '.AT_BASE_HREF.'bounce.php?course='.$_pretty_url_course_id);
72 * This function will reconstruct all the $_GET variables.
73 * @param array consist of all the pathinfo variables in querystring format
75 function save2Get($var_query){
76 if (empty($var_query) || !is_array($var_query))
79 //recreate URL querystring so we can use the PHP function - parse_str() later on
80 foreach($var_query as $k=>$v){
81 if ($k=='page_to_load'){
85 //If mod_rewrite is on, the page# will be shown as <page#>.html.
86 //in this case, parse the page number out.
88 if (preg_match('/(.*)\.html$/', $v, $matches)==1){
92 $temp[] = $k . '=' . $v;
94 $var_query = implode(SEP, $temp);
95 parse_str($var_query, $output); //convert querystring to php array
97 //saves it to both GET and REQUEST
98 //TODO: Would overwrite POST value that has the same GET name within REQUEST. Fix this.
99 //Avoid the use of REQUEST in the code.
100 foreach($output as $k=>$v){
108 * @return the path info string
110 function getPathInfo(){
111 //Handles path_info in diff versions of PHP
112 if(isset($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO']!=''){
113 //if both PATH_INFO and ORIG_PATH_INFO are set, then decide which to use by str ops.
114 if (isset($_SERVER['PATH_INFO'])){
115 $pathpos = strpos($_SERVER['ORIG_PATH_INFO'], $_SERVER['SCRIPT_NAME']);
116 $pathlen = strlen($_SERVER['SCRIPT_NAME']);
117 if (substr($_SERVER['ORIG_PATH_INFO'], $pathpos + $pathlen) == $_SERVER['PATH_INFO']){
118 return $_SERVER['PATH_INFO'];
121 return $_SERVER['ORIG_PATH_INFO'];
123 return $_SERVER['PATH_INFO'];