2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg, Heidi Hazelton */
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 /************************************************************************/
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 $_POST['db_login'] = urldecode($_POST['db_login']);
17 $_POST['db_password'] = urldecode($_POST['db_password']);
21 if(isset($_POST['submit']) && ($_POST['action'] == 'process')) {
23 $db = @mysql_connect($_POST['step1']['db_host'] . ':' . $_POST['step1']['db_port'], $_POST['step1']['db_login'], urldecode($_POST['step1']['db_password']));
24 @mysql_select_db($_POST['step1']['db_name'], $db);
26 if (version_compare($_POST['step1']['old_version'], '1.5', '<')) {
27 $_POST['admin_username'] = trim($_POST['admin_username']);
28 $_POST['admin_password'] = trim($_POST['admin_password']);
29 $_POST['admin_email'] = trim($_POST['admin_email']);
30 $_POST['site_name'] = trim($_POST['site_name']);
31 $_POST['home_url'] = trim($_POST['home_url']);
33 /* Super Administrator Account checking: */
34 if ($_POST['admin_username'] == ''){
35 $errors[] = 'Administrator username cannot be empty.';
37 /* check for special characters */
38 if (!(preg_match("/^[a-zA-Z0-9_]([a-zA-Z0-9_])*$/i", $_POST['admin_username']))){
39 $errors[] = 'Administrator username is not valid.';
42 if ($_POST['admin_password'] == '') {
43 $errors[] = 'Administrator password cannot be empty.';
45 if ($_POST['admin_email'] == '') {
46 $errors[] = 'Administrator email cannot be empty.';
47 } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['admin_email'])) {
48 $errors[] = 'Administrator email is not valid.';
51 /* System Preferences checking: */
52 if ($_POST['email'] == '') {
53 $errors[] = 'Contact email cannot be empty.';
54 } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['email'])) {
55 $errors[] = 'Contact email is not valid.';
58 if (!isset($errors)) {
59 $sql = "INSERT INTO ".$_POST['step1']['tb_prefix']."admins VALUES ('$_POST[admin_username]', '$_POST[admin_password]', '', '$_POST[admin_email]', 'en', 1, NOW())";
60 $result= mysql_query($sql, $db);
62 unset($_POST['admin_username']);
63 unset($_POST['admin_password']);
64 unset($_POST['admin_email']);
67 if (version_compare($_POST['step1']['old_version'], '1.5.2', '<')) {
68 // update config table
69 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('contact_email', '".urldecode($_POST['step1']['contact_email'])."')";
70 mysql_query($sql, $db);
72 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('email_notification', '".($_POST['step1']['email_notification'] ? 1 : 0)."')";
73 mysql_query($sql, $db);
75 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('allow_instructor_requests', '".($_POST['step1']['allow_instructor_requests'] ? 1 : 0)."')";
76 mysql_query($sql, $db);
78 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('auto_approve_instructors', '".($_POST['step1']['auto_approve'] ? 1 : 0)."')";
79 mysql_query($sql, $db);
81 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('max_file_size', '".(int) $_POST['step1']['max_file_size']."')";
82 mysql_query($sql, $db);
84 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('max_course_size', '".(int) $_POST['step1']['max_course_size']."')";
85 mysql_query($sql, $db);
87 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('max_course_float', '".(int) $_POST['step1']['max_course_float']."')";
88 mysql_query($sql, $db);
90 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('illegal_extentions', '".str_replace(',','|',urldecode($_POST['step1']['ill_ext']))."')";
91 mysql_query($sql, $db);
93 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('site_name', '".urldecode($_POST['step1']['site_name'])."')";
94 mysql_query($sql, $db);
96 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('home_url', '".urldecode($_POST['step1']['home_url'])."')";
97 mysql_query($sql, $db);
99 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('default_language', 'en')";
100 mysql_query($sql, $db);
102 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('cache_dir', '".urldecode($_POST['step1']['cache_dir'])."')";
103 mysql_query($sql, $db);
105 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('enable_category_themes', '".($_POST['step1']['theme_categories'] ? 1 : 0)."')";
106 mysql_query($sql, $db);
108 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('course_backups', '". (int) $_POST['step1']['course_backups']."')";
109 mysql_query($sql, $db);
111 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('email_confirmation', '".($_POST['step1']['email_confirmation'] ? 1 : 0)."')";
112 mysql_query($sql, $db);
114 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('master_list', '".($_POST['step1']['master_list'] ? 1 : 0)."')";
115 mysql_query($sql, $db);
117 $sql = "REPLACE INTO ".$_POST['step1']['tb_prefix']."config VALUES ('enable_handbook_notes', '".($_POST['step1']['enable_handbook_notes'] ? 1 : 0)."')";
118 mysql_query($sql, $db);
120 // check for bits 8192 and 4096 and remove them if they're set.
121 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."course_enrollment SET `privileges` = `privileges` - 8192 WHERE `privileges` & 8192";
122 mysql_query($sql, $db);
124 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."course_enrollment SET `privileges` = `privileges` - 4096 WHERE `privileges` & 4096";
125 mysql_query($sql, $db);
128 if (version_compare($_POST['step1']['old_version'], '1.5.3', '<')) {
129 $sql = "DELETE FROM ".$_POST['step1']['tb_prefix']."groups";
130 mysql_query($sql, $db);
132 $sql = "DELETE FROM ".$_POST['step1']['tb_prefix']."groups_members";
133 mysql_query($sql, $db);
135 $sql = "DELETE FROM ".$_POST['step1']['tb_prefix']."tests_groups";
136 mysql_query($sql, $db);
138 if (version_compare($_POST['step1']['old_version'], '1.5.3.3', '<')) {
139 // set display_name_format to "login"
140 $sql = "INSERT INTO ".$_POST['step1']['tb_prefix']."config VALUES ('display_name_format', '0')";
141 mysql_query($sql, $db);
144 if (version_compare($_POST['step1']['old_version'], '1.5.4', '<')) {
145 /* find all the multiple choice multiple answer questions and convert them to
146 * Multiple Answer which is number 7.
148 $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";
149 mysql_query($sql, $db);
151 $sql = "SELECT MAX(admin_privilege) AS max FROM ".$_POST['step1']['tb_prefix']."modules";
152 $result = mysql_query($sql, $db);
153 $row = mysql_fetch_assoc($result);
154 $priv = $row['max'] * 2;
156 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."modules SET `admin_privilege`=$priv WHERE `dir_name`='_core/enrolment'";
157 mysql_query($sql, $db);
159 if (version_compare($_POST['step1']['old_version'], '1.5.5', '<')) {
160 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."tests_results SET status=1, date_taken=date_taken, end_time=date_taken";
161 mysql_query($sql, $db);
163 if (version_compare($_POST['step1']['old_version'], '1.6.4', '<')) {
164 /* convert all content nodes to the IMS standard. (adds null nodes for all top pages) */
165 include('ustep_content_conversion.php');
167 // fix all the wrong ordering
168 $sql = "SELECT content_id, content_parent_id, ordering, course_id FROM ".$_POST['step1']['tb_prefix']."content ORDER BY course_id, content_parent_id, ordering";
169 $result = mysql_query($sql, $db);
170 while ($row = mysql_fetch_assoc($result)) {
171 if ($current_course_id != $row['course_id']) {
172 $current_course_id = $row['course_id'];
173 unset($current_parent_id);
176 if ($current_parent_id != $row['content_parent_id']) {
177 $current_parent_id = $row['content_parent_id'];
181 if ($row['ordering'] != $ordering) {
182 $sql = "UPDATE ".$_POST['step1']['tb_prefix']."content SET ordering=$ordering WHERE content_id=$row[content_id]";
183 mysql_query($sql, $db);
191 /* Convert db to a tree */
192 $sql = 'SELECT distinct course_id FROM '.$_POST['step1']['tb_prefix'].'content';
193 $result_course = mysql_query($sql, $db);
194 while ($row_course = mysql_fetch_assoc($result_course)){
196 $sql = 'SELECT * FROM '.$_POST['step1']['tb_prefix'].'content WHERE course_id='.$row_course['course_id'];
197 $result = mysql_query($sql, $db);
198 $content_array = array();
200 while ($row = mysql_fetch_assoc($result)){
201 $content_array[$row['content_parent_id']][$row['ordering']] = $row['content_id'];
204 $tree = buildTree($content_array[0], $content_array);
206 /* Restructure the tree */
207 $tree = rebuild($tree);
210 /* Update the Db based on this new tree */
211 reconstruct($tree, '', 0, $_POST['step1']['tb_prefix']);
215 /* deal with the extra modules: */
216 /* for each module in the modules table check if that module still exists in the mod directory. */
217 /* if that module does not exist then check the old directory and prompt to have it copied */
218 /* or delete it from the modules table. or maybe disable it instead? */
219 if (version_compare($_POST['step1']['old_version'], '1.5.1', '>')) {
220 define('TABLE_PREFIX', $_POST['step1']['tb_prefix']);
221 require(AT_INCLUDE_PATH . 'classes/Module/Module.class.php');
222 $moduleFactory = new ModuleFactory(FALSE);
223 $module_list =& $moduleFactory->getModules(AT_MODULE_STATUS_DISABLED | AT_MODULE_STATUS_ENABLED);
224 $keys = array_keys($module_list);
225 foreach($keys as $dir_name) {
226 $module =& $module_list[$dir_name];
227 $module->setIsMissing($module->isExtra());
232 if (!isset($errors)) {
234 unset($_POST['submit']);
242 print_progress($step);
244 if (isset($errors)) {
245 print_errors($errors);
251 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
252 <input type="hidden" name="action" value="process" />
253 <input type="hidden" name="step" value="<?php echo $step; ?>" />
254 <?php print_hidden($step); ?>
256 <?php if (version_compare($_POST['step1']['old_version'], '1.5', '<')): ?>
257 <p>Below are new configuration options that are available for this version.</p>
260 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
262 <th colspan="2">Super Administrator</th>
265 <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>
268 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="username">Administrator Username:</label></b><br />
269 May contain only letters, numbers, or underscores.</td>
270 <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>
273 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="password">Administrator Password:</label></b></td>
274 <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>
277 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="email">Administrator Email:</label></b></td>
278 <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>
284 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
286 <th colspan="2">System Preferences</th>
289 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="cemail">Contact Email:</label></b><br />
290 The email that will be used as the return email when needed and when instructor account requests are made.</td>
291 <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>
295 <?php if (version_compare($_POST['step1']['old_version'], '1.5.3', '<')): ?>
296 <p>Groups made prior to 1.5.3 are not backwards compatible and will be removed.</p>
298 <p>There are no new configuration options for this version.</p>
303 <div align="center"><input type="submit" class="button" value=" Next »" name="submit" /></div>