2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
7 /* This program is free software. You can redistribute it and/or */
8 /* modify it under the terms of the GNU General Public License */
9 /* as published by the Free Software Foundation. */
10 /************************************************************************/
13 if (!defined('AT_INCLUDE_PATH')) { exit; }
15 $_POST['db_login'] = urldecode($_POST['db_login']);
16 $_POST['db_password'] = urldecode($_POST['db_password']);
20 if(isset($_POST['submit']) && ($_POST['action'] == 'process')) {
22 $db = @mysql_connect($_POST['step1']['db_host'] . ':' . $_POST['step1']['db_port'], $_POST['step1']['db_login'], urldecode($_POST['step1']['db_password']));
23 @mysql_select_db($_POST['step1']['db_name'], $db);
25 if (version_compare($_POST['step1']['old_version'], '1.5', '<')) {
26 $_POST['admin_username'] = trim($_POST['admin_username']);
27 $_POST['admin_password'] = trim($_POST['admin_password']);
28 $_POST['admin_email'] = trim($_POST['admin_email']);
29 $_POST['site_name'] = trim($_POST['site_name']);
30 $_POST['home_url'] = trim($_POST['home_url']);
32 /* Super Administrator Account checking: */
33 if ($_POST['admin_username'] == ''){
34 $errors[] = 'Administrator username cannot be empty.';
36 /* check for special characters */
37 if (!(preg_match("/^[a-zA-Z0-9_]([a-zA-Z0-9_])*$/i", $_POST['admin_username']))){
38 $errors[] = 'Administrator username is not valid.';
41 if ($_POST['admin_password'] == '') {
42 $errors[] = 'Administrator password cannot be empty.';
44 if ($_POST['admin_email'] == '') {
45 $errors[] = 'Administrator email cannot be empty.';
46 } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['admin_email'])) {
47 $errors[] = 'Administrator email is not valid.';
50 /* System Preferences checking: */
51 if ($_POST['email'] == '') {
52 $errors[] = 'Contact email cannot be empty.';
53 } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['email'])) {
54 $errors[] = 'Contact email is not valid.';
57 if (!isset($errors)) {
58 $sql = "INSERT INTO ".$_POST['step1']['tb_prefix']."admins VALUES ('$_POST[admin_username]', '$_POST[admin_password]', '', '$_POST[admin_email]', 'en', 1, NOW())";
59 $result= mysql_query($sql, $db);
61 unset($_POST['admin_username']);
62 unset($_POST['admin_password']);
63 unset($_POST['admin_email']);
66 if (version_compare($_POST['step1']['old_version'], '1.5.2', '<')) {
67 // update config table
68 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('contact_email', '".urldecode($_POST['step1']['contact_email'])."')";
69 mysql_query($sql, $db);
71 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('email_notification', '".($_POST['step1']['email_notification'] ? 1 : 0)."')";
72 mysql_query($sql, $db);
74 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('allow_instructor_requests', '".($_POST['step1']['allow_instructor_requests'] ? 1 : 0)."')";
75 mysql_query($sql, $db);
77 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('auto_approve_instructors', '".($_POST['step1']['auto_approve'] ? 1 : 0)."')";
78 mysql_query($sql, $db);
80 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('max_file_size', '".(int) $_POST['step1']['max_file_size']."')";
81 mysql_query($sql, $db);
83 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('max_course_size', '".(int) $_POST['step1']['max_course_size']."')";
84 mysql_query($sql, $db);
86 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('max_course_float', '".(int) $_POST['step1']['max_course_float']."')";
87 mysql_query($sql, $db);
89 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('illegal_extentions', '".str_replace(',','|',urldecode($_POST['step1']['ill_ext']))."')";
90 mysql_query($sql, $db);
92 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('site_name', '".urldecode($_POST['step1']['site_name'])."')";
93 mysql_query($sql, $db);
95 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('home_url', '".urldecode($_POST['step1']['home_url'])."')";
96 mysql_query($sql, $db);
98 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('default_language', 'en')";
99 mysql_query($sql, $db);
101 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('cache_dir', '".urldecode($_POST['step1']['cache_dir'])."')";
102 mysql_query($sql, $db);
104 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('enable_category_themes', '".($_POST['step1']['theme_categories'] ? 1 : 0)."')";
105 mysql_query($sql, $db);
107 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('course_backups', '". (int) $_POST['step1']['course_backups']."')";
108 mysql_query($sql, $db);
110 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('email_confirmation', '".($_POST['step1']['email_confirmation'] ? 1 : 0)."')";
111 mysql_query($sql, $db);
113 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('master_list', '".($_POST['step1']['master_list'] ? 1 : 0)."')";
114 mysql_query($sql, $db);
116 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('enable_handbook_notes', '".($_POST['step1']['enable_handbook_notes'] ? 1 : 0)."')";
117 mysql_query($sql, $db);
119 // check for bits 8192 and 4096 and remove them if they're set.
120 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."course_enrollment SET `privileges` = `privileges` - 8192 WHERE `privileges` & 8192";
121 mysql_query($sql, $db);
123 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."course_enrollment SET `privileges` = `privileges` - 4096 WHERE `privileges` & 4096";
124 mysql_query($sql, $db);
127 if (version_compare($_POST['step1']['old_version'], '1.5.3', '<')) {
128 $sql = "DELETE FROM ".$_POST['step1']['tb_prefix']."groups";
129 mysql_query($sql, $db);
131 $sql = "DELETE FROM ".$_POST['step1']['tb_prefix']."groups_members";
132 mysql_query($sql, $db);
134 $sql = "DELETE FROM ".$_POST['step1']['tb_prefix']."tests_groups";
135 mysql_query($sql, $db);
137 if (version_compare($_POST['step1']['old_version'], '1.5.3.3', '<')) {
138 // set display_name_format to "login"
139 $sql = "INSERT INTO ".$_POST['step1']['tb_prefix']."config VALUES ('display_name_format', '0')";
140 mysql_query($sql, $db);
143 if (version_compare($_POST['step1']['old_version'], '1.5.4', '<')) {
144 /* find all the multiple choice multiple answer questions and convert them to
145 * Multiple Answer which is number 7.
147 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."tests_questions SET type=7 WHERE type=1 AND answer_0 + answer_1 + answer_2 + answer_3 + answer_4 + answer_5 + answer_6 + answer_7 + answer_8 + answer_9 > 1";
148 mysql_query($sql, $db);
150 $sql = "SELECT MAX(admin_privilege) AS max FROM ".$_POST['step1']['tb_prefix']."modules";
151 $result = mysql_query($sql, $db);
152 $row = mysql_fetch_assoc($result);
153 $priv = $row['max'] * 2;
155 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."modules SET `admin_privilege`=$priv WHERE `dir_name`='_core/enrolment'";
156 mysql_query($sql, $db);
158 if (version_compare($_POST['step1']['old_version'], '1.5.5', '<')) {
159 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."tests_results SET status=1, date_taken=date_taken, end_time=date_taken";
160 mysql_query($sql, $db);
162 if (version_compare($_POST['step1']['old_version'], '1.6.4', '<')) {
163 /* convert all content nodes to the IMS standard. (adds null nodes for all top pages) */
164 include('ustep_content_conversion.php');
166 // fix all the wrong ordering
167 $sql = "SELECT content_id, content_parent_id, ordering, course_id FROM ".$_POST['step1']['tb_prefix']."content ORDER BY course_id, content_parent_id, ordering";
168 $result = mysql_query($sql, $db);
169 while ($row = mysql_fetch_assoc($result)) {
170 if ($current_course_id != $row['course_id']) {
171 $current_course_id = $row['course_id'];
172 unset($current_parent_id);
175 if ($current_parent_id != $row['content_parent_id']) {
176 $current_parent_id = $row['content_parent_id'];
180 if ($row['ordering'] != $ordering) {
181 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."content SET ordering=$ordering WHERE content_id=$row[content_id]";
182 mysql_query($sql, $db);
190 /* Convert db to a tree */
191 $sql = 'SELECT distinct course_id FROM '.$_POST['step1']['tb_prefix'].'content';
192 $result_course = mysql_query($sql, $db);
193 while ($row_course = mysql_fetch_assoc($result_course)){
195 $sql = 'SELECT * FROM '.$_POST['step1']['tb_prefix'].'content WHERE course_id='.$row_course['course_id'];
196 $result = mysql_query($sql, $db);
197 $content_array = array();
199 while ($row = mysql_fetch_assoc($result)){
200 $content_array[$row['content_parent_id']][$row['ordering']] = $row['content_id'];
203 $tree = buildTree($content_array[0], $content_array);
205 /* Restructure the tree */
206 $tree = rebuild($tree);
209 /* Update the Db based on this new tree */
210 reconstruct($tree, '', 0, $_POST['step1']['tb_prefix']);
214 /* deal with the extra modules: */
215 /* for each module in the modules table check if that module still exists in the mod directory. */
216 /* if that module does not exist then check the old directory and prompt to have it copied */
217 /* or delete it from the modules table. or maybe disable it instead? */
218 if (version_compare($_POST['step1']['old_version'], '1.5.1', '>')) {
219 define('TABLE_PREFIX', $_POST['step1']['tb_prefix']);
220 require(AT_INCLUDE_PATH . '../mods/_core/modules/classes/Module.class.php');
221 $moduleFactory = new ModuleFactory(FALSE);
222 $module_list =& $moduleFactory->getModules(AT_MODULE_STATUS_DISABLED | AT_MODULE_STATUS_ENABLED);
223 $keys = array_keys($module_list);
224 foreach($keys as $dir_name) {
225 $module =& $module_list[$dir_name];
226 $module->setIsMissing($module->isExtra());
230 /* fixed the typo of "fuild" theme that was introduced in 1.6.1 : */
231 if (version_compare($_POST['step1']['new_version'], '1.6.0', '>')) {
232 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."themes
233 SET title='Fluid', dir_name='fluid'
234 WHERE dir_name='fuild'";
235 mysql_query($sql, $db);
237 $sql = 'UPDATE '.$_POST['step1']['tb_prefix'].'config
238 SET value=replace(value, \':"fuild";\', \':"fluid";\')
239 WHERE name=\'pref_defaults\'';
240 mysql_query($sql, $db);
242 $sql = 'UPDATE '.$_POST['step1']['tb_prefix'].'members
243 SET preferences=replace(preferences, \':"fuild";\', \':"fluid";\')';
244 mysql_query($sql, $db);
247 /* Saved the atutor installation path into "config" table after 2.0.2 */
248 if (version_compare($_POST['step1']['new_version'], '2.0.2', '>')) {
249 // Calculate the ATutor installation path and save into database for the usage of
250 // session associated path @ include/vitals.inc.php
251 $sql = "INSERT INTO ".$_POST['step1']['tb_prefix']."config VALUES ('session_path', '".get_atutor_installation_path(AT_UPGRADE_INCLUDE_PATH)."')";
252 mysql_query($sql ,$db);
255 if (!isset($errors)) {
257 unset($_POST['submit']);
265 print_progress($step);
267 if (isset($errors)) {
268 print_errors($errors);
274 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
275 <input type="hidden" name="action" value="process" />
276 <input type="hidden" name="step" value="<?php echo $step; ?>" />
277 <?php print_hidden($step); ?>
279 <?php if (version_compare($_POST['step1']['old_version'], '1.5', '<')): ?>
280 <p>Below are new configuration options that are available for this version.</p>
283 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
285 <th colspan="2">Super Administrator</th>
288 <td class="row1" colspan="2">The Super Administrator account is used for managing ATutor. Since ATutor version 1.5 the Super Administrator can also create additional Administrators each with their own privileges and roles.</td>
291 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="username">Administrator Username:</label></b><br />
292 May contain only letters, numbers, or underscores.</td>
293 <td class="row1"><input type="text" name="admin_username" id="username" maxlength="20" size="20" value="<?php if (!empty($_POST['admin_username'])) { echo $stripslashes(htmlspecialchars($_POST['admin_username'])); } else { echo urldecode($_POST['step1']['admin_username']); } ?>" class="formfield" /></td>
296 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="password">Administrator Password:</label></b></td>
297 <td class="row1"><input type="text" name="admin_password" id="password" maxlength="15" size="15" value="<?php if (!empty($_POST['admin_password'])) { echo $stripslashes(htmlspecialchars($_POST['admin_password'])); } else { echo urldecode($_POST['step1']['admin_password']); } ?>" class="formfield" /></td>
300 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="email">Administrator Email:</label></b></td>
301 <td class="row1"><input type="text" name="admin_email" id="email" size="30" value="<?php if (!empty($_POST['admin_email'])) { echo $stripslashes(htmlspecialchars($_POST['admin_email'])); } else { echo urldecode($_POST['step1']['admin_email']); } ?>" class="formfield" /></td>
307 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
309 <th colspan="2">System Preferences</th>
312 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="cemail">Contact Email:</label></b><br />
313 The email that will be used as the return email when needed and when instructor account requests are made.</td>
314 <td class="row1"><input type="text" name="email" id="cemail" size="30" value="<?php if (!empty($_POST['email'])) { echo $stripslashes(htmlspecialchars($_POST['admin_email'])); } else { echo urldecode($_POST['step1']['admin_email']); } ?>" class="formfield" /></td>
318 <?php if (version_compare($_POST['step1']['old_version'], '1.5.3', '<')): ?>
319 <p>Groups made prior to 1.5.3 are not backwards compatible and will be removed.</p>
321 <p>There are no new configuration options for this version.</p>
326 <div align="center"><input type="submit" class="button" value=" Next »" name="submit" /></div>