2 if (!defined('AT_INCLUDE_PATH')) { exit; }
3 error_reporting(E_ALL ^ E_NOTICE);
6 // set the default timezone to avoid the warning of "cannot rely on system timezone"
7 @date_default_timezone_set(@date_default_timezone_get());
9 /* atutor default configuration options */
10 /* used on: ustep1.php, step3.php, step5.php */
11 $_defaults['admin_username'] = ($_POST['old_path'] ? 'admin' : '');
12 $_defaults['admin_password'] = '';
13 $_defaults['admin_email'] = '';
15 $_defaults['site_name'] = 'Course Server';
16 $_defaults['header_img'] = '';
17 $_defaults['header_logo'] = '';
18 $_defaults['home_url'] = '';
20 $_defaults['email_notification'] = 'TRUE';
21 $_defaults['email_confirmation'] = 'TRUE';
22 $_defaults['allow_instructor_requests'] = 'TRUE';
23 $_defaults['auto_approve_instructors'] = 'FALSE';
25 $_defaults['max_file_size'] = '1048576';
26 $_defaults['max_course_size'] = '10485760';
27 $_defaults['max_course_float'] = '2097152';
28 $_defaults['ill_ext'] = 'exe, asp, php, php3, bat, cgi, pl, com, vbs, reg, pcd, pif, scr, bas, inf, vb, vbe, wsc, wsf, wsh';
29 $_defaults['cache_dir'] = '';
31 $_defaults['theme_categories'] = 'FALSE';
32 $_defaults['content_dir'] = realpath('../').DIRECTORY_SEPARATOR.'content';
34 $_defaults['course_backups'] = 5;
36 require('include/classes/sqlutility.php');
39 function my_add_null_slashes( $string ) {
40 return @mysql_real_escape_string(stripslashes($string));
42 function my_null_slashes($string) {
46 if ( get_magic_quotes_gpc() == 1 ) {
47 $addslashes = 'my_add_null_slashes';
48 $stripslashes = 'stripslashes';
50 $addslashes = 'mysql_real_escape_string';
51 $stripslashes = 'my_null_slashes';
54 function queryFromFile($sql_file_path){
55 global $db, $progress, $errors;
59 if (!file_exists($sql_file_path)) {
63 $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)));
64 SqlUtility::splitSqlFile($pieces, $sql_query);
66 foreach ($pieces as $piece) {
67 $piece = trim($piece);
68 // [0] contains the prefixed query
69 // [4] contains unprefixed table name
72 if ($_POST['tb_prefix'] || ($_POST['tb_prefix'] == '')) {
73 $prefixed_query = SqlUtility::prefixQuery($piece, $_POST['tb_prefix']);
75 $prefixed_query = $piece;
78 if ($prefixed_query != false ) {
79 $table = $_POST['tb_prefix'].$prefixed_query[4];
80 if($prefixed_query[1] == 'CREATE TABLE'){
81 if (mysql_query($prefixed_query[0],$db) !== false) {
82 $progress[] = 'Table <strong>'.$table . '</strong> created successfully.';
84 if (mysql_errno($db) == 1050) {
85 $progress[] = 'Table <strong>'.$table . '</strong> already exists. Skipping.';
87 $errors[] = 'Table <strong>' . $table . '</strong> creation failed.';
91 elseif($prefixed_query[1] == 'INSERT INTO'){
92 mysql_query($prefixed_query[0],$db);
93 }elseif($prefixed_query[1] == 'REPLACE INTO'){
94 mysql_query($prefixed_query[0],$db);
95 }elseif($prefixed_query[1] == 'ALTER TABLE'){
96 if (mysql_query($prefixed_query[0],$db) !== false) {
97 $progress[] = 'Table <strong>'.$table.'</strong> altered successfully.';
99 if (mysql_errno($db) == 1060)
100 $progress[] = 'Table <strong>'.$table . '</strong> fields already exists. Skipping.';
101 elseif (mysql_errno($db) == 1091)
102 $progress[] = 'Table <strong>'.$table . '</strong> fields already dropped. Skipping.';
104 $errors[] = 'Table <strong>'.$table.'</strong> alteration failed.';
107 }elseif($prefixed_query[1] == 'DROP TABLE'){
108 mysql_query($prefixed_query[1] . ' ' .$table,$db);
109 }elseif($prefixed_query[1] == 'UPDATE'){
110 mysql_query($prefixed_query[0],$db);
117 function print_errors( $errors ) {
120 <table border="0" class="errbox" cellpadding="3" cellspacing="2" width="90%" summary="" align="center">
123 <h3 class="err"><img src="images/bad.gif" align="top" alt="" class="img" /> Error</h3>
126 foreach ($errors as $p) {
127 echo '<li>'.$p.'</li>';
137 function print_feedback( $feedback ) {
140 <table border="0" class="fbkbox" cellpadding="3" cellspacing="2" width="90%" summary="" align="center">
142 <td><h3 class="feedback2"><img src="images/feedback.gif" align="top" alt="" class="img" /> Feedback</h3>
145 foreach ($feedback as $p) {
146 echo '<li>'.$p.'</li>';
156 function store_steps($step) {
158 global $stripslashes;
160 foreach($_POST as $key => $value) {
161 if (substr($key, 0, strlen('step')) == 'step') {
163 } else if ($key == 'step') {
165 } else if ($key == 'action') {
167 } else if ($key == 'submit') {
171 $_POST['step'.$step][$key] = urlencode($stripslashes($value));
176 function print_hidden($current_step) {
177 for ($i=1; $i<$current_step; $i++) {
178 if (is_array($_POST['step'.$i])) {
179 foreach($_POST['step'.$i] as $key => $value) {
180 echo '<input type="hidden" name="step'.$i.'['.$key.']" value="'.$value.'" />'."\n";
186 function print_progress($step) {
187 global $install_steps;
189 echo '<div class="install"><h3>Installation Progress</h3><p>';
191 $num_steps = count($install_steps);
192 for ($i=0; $i<$num_steps; $i++) {
194 echo '<strong style="margin-left: 12px; color: #006699;">Step '.$i.': '.$install_steps[$i]['name'].'</strong>';
196 echo '<small style="margin-left: 10px; color: gray;">';
198 echo '<img src="../images/check.gif" height="9" width="9" alt="Step Done!" /> ';
200 echo '<img src="../images/clr.gif" height="9" width="9" alt="" /> ';
202 echo 'Step '.$i.': '.$install_steps[$i]['name'].'</small>';
204 if ($i+1 < $num_steps) {
208 echo '</p></div><br />';
210 echo '<h3>'.$install_steps[$step]['name'].'</h3>';
214 if (version_compare(phpversion(), '5.0') < 0) {
215 function scandir($dirstr) {
217 $fh = opendir($dirstr);
218 while (false !== ($filename = readdir($fh))) {
219 array_push($files, $filename);
227 * Print the HTML of the meta forward codes
229 function print_meta_redirect(){
230 $body = 'ATutor appears to have been installed already. <br/>';
231 $body .= '<a href="../index.php">Click here<a/> to login.';
234 $html .= '<body>'.$body.'</body>'."\n";
235 $html .= "</html>\n";
241 * This function calculate the ATutor installation path
243 * @param include_path: The relative path to install/include
244 * @return string: atutor installation path, for example: /ATutor/
246 function get_atutor_installation_path($include_path) {
247 /* get the base url */
248 if (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on')) {
249 $server_protocol = 'https://';
251 $server_protocol = 'http://';
254 $dir_deep = substr_count($include_path, '..');
255 $url_parts = explode('/', $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
256 $base_href = array_slice($url_parts, 0, count($url_parts) - $dir_deep-2);
257 $base_href = $server_protocol . implode('/', $base_href).'/';
259 $session_path = substr($base_href, strlen($server_protocol . $_SERVER['HTTP_HOST']));
261 return $session_path;
265 * This function is used for printing variables for debugging.
267 * @param mixed $var The variable to output
268 * @param string $title The name of the variable, or some mark-up identifier.
269 * @author Joel Kronenberg
271 function debug($var, $title='') {
272 echo '<pre style="border: 1px black solid; padding: 0px; margin: 10px;" title="debugging box">';
274 echo '<h4>'.$title.'</h4>';
279 $str = ob_get_contents();
282 $str = str_replace('<', '<', $str);
284 $str = str_replace('[', '<span style="color: red; font-weight: bold;">[', $str);
285 $str = str_replace(']', ']</span>', $str);
286 $str = str_replace('=>', '<span style="color: blue; font-weight: bold;">=></span>', $str);
287 $str = str_replace('Array', '<span style="color: purple; font-weight: bold;">Array</span>', $str);