(no commit message)
[atutor.git] / install / include / ustep1.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg, Heidi Hazelton */
6 /* http://atutor.ca                                                                                                             */
7 /*                                                                                                                                              */
8 /* This program is free software. You can redistribute it and/or                */
9 /* modify it under the terms of the GNU General Public License                  */
10 /* as published by the Free Software Foundation.                                                */
11 /************************************************************************/
12 // $Id$
13
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
15 session_unset();        //clear session before using it
16 $_SESSION = array();
17 print_progress($step);
18
19 if (isset($_POST['submit']) && (trim($_POST['old_path']) != '')) {
20         if ((strpos($_POST['old_path'], '/') === false) && is_dir('../../'.$_POST['old_path'])) {
21                 if ( file_exists('../../'.$_POST['old_path'] . '/include/config.inc.php') ) {
22                         
23                         require('../../'.$_POST['old_path'] . '/include/lib/constants.inc.php');
24                         if (!defined('VERSION')) {
25                                 $errors[] = 'Cannot detect version number. Only ATutor versions greater than 1.0 can be upgraded. Upgrade to 1.1 manually then try upgrading to the latest version again.';
26                         } else {
27                                 $progress[] = 'Found ATutor version <kbd><b>'.VERSION . '</b></kbd> in path <kbd><b>'.$_POST['old_path'].'</b></kbd>.';
28                         }
29                         if (!version_compare(VERSION, $new_version, '<')) {
30                                 $errors[] = 'The version upgrading (<kbd><b>'.VERSION.'</b></kbd>) is not older than the new version (<kbd><b>'.$new_version.'</b></kbd>).';
31                         }
32
33                         if (!$errors) {
34                                 $progress[] = 'Will be upgrading from version <kbd><b>'.VERSION.'</b></kbd> to version <kbd><b>'.$new_version.'</b></kbd>.';
35                                 print_feedback($progress);
36
37                                 require('../../'.$_POST['old_path'] . '/include/config.inc.php');
38
39                                 if (is_array($IllegalExtentions)) {
40                                         $IllegalExtentions = implode(',', $IllegalExtentions);
41                                 }
42
43                                 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">';
44                                 echo '<input type="hidden" name="step" value="2" />';
45                                 echo '<input type="hidden" name="old_path" value="'.$_POST['old_path'].'" />';
46
47                                 echo '<input type="hidden" name="db_login" value="'.urlencode(DB_USER).'" />';
48                                 echo '<input type="hidden" name="db_password" value="'.urlencode(DB_PASSWORD).'" />';
49                                 echo '<input type="hidden" name="db_host" value="'.DB_HOST.'" />';
50                                 if (defined('DB_PORT')) {
51                                         echo '<input type="hidden" name="db_port" value="'.DB_PORT.'" />';
52                                 } else {
53                                         echo '<input type="hidden" name="db_port" value="3306" />';
54                                 }
55                                 echo '<input type="hidden" name="db_name" value="'.DB_NAME.'" />';
56
57                                 if (defined('TABLE_PREFIX')) {
58                                         echo '<input type="hidden" name="tb_prefix" value="'.TABLE_PREFIX.'" />';
59                                 } else {
60                                         echo '<input type="hidden" name="tb_prefix" value="" />';
61                                 }
62                                 if (defined('SITE_NAME')) {
63                                         echo '<input type="hidden" name="site_name" value="'.urlencode(SITE_NAME).'" />';
64                                 } else {
65                                         echo '<input type="hidden" name="site_name" value="'.$_defaults['site_name'].'" />';
66                                 }
67                                 if (defined('HEADER_IMAGE')) {
68                                         echo '<input type="hidden" name="header_img" value="'.HEADER_IMAGE.'" />';
69                                 } else {
70                                         echo '<input type="hidden" name="header_img" value="'.$_defaults['header_img'].'" />';
71                                 }
72                                 if (defined('HEADER_LOGO')) {
73                                         echo '<input type="hidden" name="header_logo" value="'.HEADER_LOGO.'" />';
74                                 } else {
75                                         echo '<input type="hidden" name="header_logo" value="'.$_defaults['header_logo'].'" />';
76                                 }
77                                 if (defined('HOME_URL')) {
78                                         echo '<input type="hidden" name="home_url" value="'.HOME_URL.'" />';
79                                 } else {
80                                         echo '<input type="hidden" name="home_url" value="'.$_defaults['home_url'].'" />';
81                                 }
82
83                                 if (defined('MAIL_USE_SMTP')) {
84                                         echo '<input type="hidden" name="smtp" value="'.(MAIL_USE_SMTP ? 'TRUE' : 'FALSE').'" />';
85                                 } else {
86                                         echo '<input type="hidden" name="smtp" value="FALSE" />';
87                                 }
88                                 if (defined('AT_FORCE_GET_FILE')) {
89                                         echo '<input type="hidden" name="get_file" value="'.(AT_FORCE_GET_FILE ? 'TRUE' : 'FALSE').'" />';
90                                 } else {
91                                         echo '<input type="hidden" name="get_file" value="FALSE" />';
92                                 }
93                                 echo '<input type="hidden" name="admin_password" value="'.urlencode(ADMIN_PASSWORD).'" />';
94
95                                 if (defined('ADMIN_USERNAME')) {
96                                         echo '<input type="hidden" name="admin_username" value="'.ADMIN_USERNAME.'" />';
97                                 } else {
98                                         echo '<input type="hidden" name="admin_username" value="'.$_defaults['admin_username'].'" />';
99                                 }
100
101                                 if (defined('ADMIN_EMAIL')) {
102                                         echo '<input type="hidden" name="admin_email" value="'.ADMIN_EMAIL.'" />';
103                                 } else {
104                                         echo '<input type="hidden" name="admin_email" value="'.$_defaults['admin_email'].'" />';
105                                 }
106                                 if (defined('EMAIL')) {
107                                         echo '<input type="hidden" name="contact_email" value="'.EMAIL.'" />';
108                                 } else if (defined('ADMIN_EMAIL')) {
109                                         echo '<input type="hidden" name="contact_email" value="'.ADMIN_EMAIL.'" />';
110                                 } else {
111                                         echo '<input type="hidden" name="contact_email" value="'.$_defaults['admin_email'].'" />';
112                                 }
113                                 if (defined('EMAIL_NOTIFY')) {
114                                         echo '<input type="hidden" name="email_notification" value="'.(EMAIL_NOTIFY ? 'TRUE' : 'FALSE').'" />';
115                                 } else {
116                                         echo '<input type="hidden" name="email_notification" value="'.$_defaults['email_notification'].'" />';
117                                 }
118                                 if (defined('ALLOW_INSTRUCTOR_REQUESTS')) {
119                                         echo '<input type="hidden" name="allow_instructor_requests" value="'.(ALLOW_INSTRUCTOR_REQUESTS ? 'TRUE' : 'FALSE').'" />';
120                                 } else {
121                                         echo '<input type="hidden" name="allow_instructor_requests" value="'.$_defaults['allow_instructor_requests'].'" />';
122                                 }
123
124                                 if (defined('AT_EMAIL_CONFIRMATION')) {
125                                         echo '<input type="hidden" name="email_confirmation" value="'.(AT_EMAIL_CONFIRMATION ? 'TRUE' : 'FALSE').'" />';
126                                 } else {
127                                         echo '<input type="hidden" name="email_confirmation" value="FALSE" />';
128                                 }
129                                 
130                                 if (defined('AT_MASTER_LIST')) {
131                                         echo '<input type="hidden" name="master_list" value="'.(AT_MASTER_LIST ? 'TRUE' : 'FALSE').'" />';
132                                 } else {
133                                         echo '<input type="hidden" name="master_list" value="FALSE" />';
134                                 }
135                                 if (defined('AT_ENABLE_HANDBOOK_NOTES')) {
136                                         echo '<input type="hidden" name="enable_handbook_notes" value="'.(AT_ENABLE_HANDBOOK_NOTES ? 'TRUE' : 'FALSE').'" />';
137                                 } else {
138                                         echo '<input type="hidden" name="enable_handbook_notes" value="FALSE" />';
139                                 }
140                                 if (defined('AUTO_APPROVE_INSTRUCTORS')) {
141                                         echo '<input type="hidden" name="auto_approve" value="'.(AUTO_APPROVE_INSTRUCTORS ? 'TRUE' : 'FALSE').'" />';
142                                 } else {
143                                         echo '<input type="hidden" name="auto_approve" value="'.$_defaults['auto_approve'].'" />';
144                                 }
145
146                                 if (isset($MaxFileSize)) {
147                                         echo '<input type="hidden" name="max_file_size" value="'.$MaxFileSize.'" />';
148                                 } else {
149                                         echo '<input type="hidden" name="max_file_size" value="'.$_defaults['max_file_size'].'" />';
150                                 }
151                                 if (isset($MaxCourseSize)) {
152                                         echo '<input type="hidden" name="max_course_size" value="'.$MaxCourseSize.'" />';
153                                 } else {
154                                         echo '<input type="hidden" name="max_course_size" value="'.$_defaults['max_course_size'].'" />';
155                                 }
156                                 if (isset($MaxCourseFloat)) {
157                                         echo '<input type="hidden" name="max_course_float" value="'.$MaxCourseFloat.'" />';
158                                 } else {
159                                         echo '<input type="hidden" name="max_course_float" value="' . $_defaults['max_course_float'] . '" />';
160                                 }
161                                 
162                                 if (isset($IllegalExtentions)) {
163                                         echo '<input type="hidden" name="ill_ext" value="' . $IllegalExtentions . '" />';
164                                 } else {
165                                         echo '<input type="hidden" name="ill_ext" value="' . $_defaults['ill_ext'] . '" />';
166                                 }
167                                 if (defined('CACHE_DIR')) {
168                                         echo '<input type="hidden" name="cache_dir" value="' . CACHE_DIR . '" />';
169                                 } else {
170                                         echo '<input type="hidden" name="cache_dir" value="' . $_defaults['cache_dir'] . '" />';
171                                 }
172
173                                 if (defined('AT_ENABLE_CATEGORY_THEMES')) {
174                                         echo '<input type="hidden" name="theme_categories" value="' . (AT_ENABLE_CATEGORY_THEMES ? 'TRUE' : 'FALSE') . '" />';
175                                 } else {
176                                         echo '<input type="hidden" name="theme_categories" value="' . $_defaults['theme_categories'] . '" />';
177                                 }
178
179                                 if (defined('AT_COURSE_BACKUPS')) {
180                                         echo '<input type="hidden" name="course_backups" value="' . AT_COURSE_BACKUPS . '" />';
181                                 } else {
182                                         echo '<input type="hidden" name="course_backups" value="' . $_defaults['course_backups'] . '" />';
183                                 }
184
185                                 if (defined('AT_CONTENT_DIR')) {
186                                         echo '<input type="hidden" name="content_dir" value="'.AT_CONTENT_DIR.'" />';
187                                 } else {
188                                         echo '<input type="hidden" name="content_dir" value="'.$_defaults['content_dir'].'" />';
189                                 }
190                                 echo '<input type="hidden" name="new_version" value="'.$new_version.'" />';
191                                 echo '<input type="hidden" name="old_version" value="'.VERSION.'" />';
192                                 echo '<p align="center"><input type="submit" class="button" value=" Next &raquo; " name="submit" /></p></form>';
193                                 return;
194                         }
195                 } else {
196                         $errors[] = 'Directory was found, but the old configuration file cannot be found.';
197                 }
198         } else {
199                 $errors[] = 'Directory does not exist relative to the new installation.';
200         }
201 }
202
203 if (isset($progress)) {
204         print_feedback($progress);
205 }
206
207 if (isset($errors)) {
208         print_errors($errors);
209 }
210
211 ?>
212 <p>Please specify the location of the old ATutor installation.</p>
213
214 <ol>
215         <li>Release Candidate (RC) installations cannot be upgraded.</li>
216         <li>Depending on the size of the existing courses, some steps (particularly 2 and 6) of the upgrade may require considerable time to complete.</li>
217         <li>All installed language packs will be deleted.</li>
218         <li>Some installed themes may not be supported by this version.</li>
219         <li>All extra modules will have to be reinstalled before they can be enabled again.</li>
220 </ol>
221
222 <p>Select the old ATutor installation directory below.</p>
223
224 <?php
225         $dirs = scandir('../../');
226         $path = realpath('../../').'/';
227         $current_dir = basename(realpath(getcwd() .'../../'));
228         foreach ($dirs as $key => $value) {
229                 if ($value == '.' || $value == '..') {
230                         unset($dirs[$key]);
231                 }
232                 if ($current_dir == $value) {
233                         unset($dirs[$key]);
234                         continue;
235                 }
236                 if (!is_dir($path . $value) || !file_exists($path . $value . '/include/config.inc.php')) {
237                         unset($dirs[$key]);
238                 }
239         }
240 ?>
241
242 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
243 <input type="hidden" name="new_version" value="<?php echo $new_version; ?>" />
244 <input type="hidden" name="step" value="1" />
245
246 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
247 <tr>
248         <td class="row1"><div class="required" title="Required Field">*</div><b><label for="dir">Old Directory Name:</label></b><br />
249                 The old directory must be at the same level as the current directory.</td>
250                 <td class="row1" valign="middle">
251                 <?php if ($dirs): ?>
252                         <select name="old_path">
253                                 <?php foreach ($dirs as $dir): ?>
254                                         <option value="<?php echo htmlspecialchars($dir); ?>"><?php echo $dir; ?>/</option>
255                                 <?php endforeach; ?>
256                         </select>
257                 <?php else: ?>
258                         <em>None found.</em>
259                 <?php endif; ?>
260                 </td>
261 </tr>
262 </table>
263
264 <br />
265
266 <?php if ($dirs): ?>
267         <br /><p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p>
268 <?php endif; ?>
269
270 </form>