tagging as ATutor 1.5.4-release
[atutor.git] / install / include / ustep2.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2004 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 ignore_user_abort(true); 
15 @set_time_limit(0); 
16
17 if (!defined('AT_INCLUDE_PATH')) { exit; }
18
19 function update_one_ver($up_file) {
20         global $progress;
21         $update_file = implode('_',$up_file);
22         queryFromFile('db/'.$update_file.'sql');
23         //$progress[] = 'Successful update from version '.$up_file[2].' to '.$up_file[4];
24         return $up_file[4];
25 }
26
27 $_POST['db_login'] = urldecode($_POST['db_login']);
28 $_POST['db_password'] = urldecode($_POST['db_password']);
29
30         unset($errors);
31         //check DB & table connection
32
33         $db = @mysql_connect($_POST['db_host'] . ':' . $_POST['db_port'], $_POST['db_login'], urldecode($_POST['db_password']));
34
35         if (!$db) {
36                 $error_no = mysql_errno();
37                 if ($error_no == 2005) {
38                         $errors[] = 'Unable to connect to database server. Database with hostname '.$_POST['db_host'].' not found.';
39                 } else {
40                         $errors[] = 'Unable to connect to database server. Wrong username/password combination.';
41                 }
42         } else {
43                 if (!mysql_select_db($_POST['db_name'], $db)) {
44                         $errors[] = 'Unable to connect to database <b>'.$_POST['db_name'].'</b>.';
45                 }
46
47                 $sql = "SELECT VERSION() AS version";
48                 $result = mysql_query($sql, $db);
49                 $row = mysql_fetch_assoc($result);
50                 if (version_compare($row['version'], '4.0.2', '>=') === FALSE) {
51                         $errors[] = 'MySQL version '.$row['version'].' was detected. ATutor requires version 4.0.2 or later.';
52                 }
53
54                 if (!$errors) {
55                         $progress[] = 'Connected to database <b>'.$_POST['db_name'].'</b> successfully.';
56                         unset($errors);
57
58                         $sql = "DELETE FROM ".$_POST['tb_prefix']."language_text WHERE `variable`<>'_c_template' AND `variable`<>'_c_msgs'";
59                         @mysql_query($sql, $db);
60
61                         $sql = "DELETE FROM ".$_POST['tb_prefix']."languages WHERE language_code<>'en'";
62                         @mysql_query($sql, $db);
63
64                         //get list of all update scripts minus sql extension
65                         $files = scandir('db'); 
66                         foreach ($files as $file) {
67                                 if(count($file = explode('_',$file))==5) {
68                                         $file[4] = substr($file[4],0,-3);
69                                         $update_files[$file[2]] = $file;
70                                 }
71                         }
72                         
73                         $curr_ver = $_POST['old_version'];
74                         ksort($update_files);
75                         foreach ($update_files as $up_file) {
76                                 if(version_compare($curr_ver, $up_file[4], '<')) {
77                                         update_one_ver($up_file);
78                                 }
79                         }
80                         
81                         /* reset all the accounts to English */
82                         $sql = "UPDATE ".$_POST['tb_prefix']."members SET language='en', creation_date=creation_date, last_login=last_login";
83                         @mysql_query($sql, $db);
84
85                         /* set all the courses to 'en' as primary language if empty. added 1.4.1 */
86                         $sql = "UPDATE ".$_POST['tb_prefix']."courses SET primary_language='en' WHERE primary_language=''";
87                         @mysql_query($sql, $db);
88
89                         queryFromFile('db/atutor_language_text.sql');
90
91                         if (!$errors) {
92                                 print_progress($step);
93
94                                 unset($_POST['submit']);
95                                 store_steps(1);
96                                 print_feedback($progress);
97
98                                 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
99                                 <input type="hidden" name="step" value="3" />
100                                 <input type="hidden" name="upgrade_action" value="true" />';
101                                 print_hidden(3);
102                                 echo '<p align="center"><input type="submit" class="button" value=" Next &raquo; " name="submit" /></p></form>';
103                                 return;
104                         }
105                 }
106         }
107
108         print_progress($step);
109
110         unset($_POST['submit']);
111         if (isset($progress)) {
112                 print_feedback($progress);
113         }
114
115         if (isset($errors)) {
116                 print_errors($errors);
117         }
118
119
120         echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
121         <input type="hidden" name="step" value="2" />';
122         store_steps(1);
123         print_hidden(2);
124         
125         if ($found_lang) {
126 ?>
127 <table width="60%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
128 <tr>
129         <td colspan="2" class="row1"><p><small>All installed language packs and changes made to the default English language will be deleted. You will have to re-install any language packs by downloading the latest versions from ATutor.ca. Some language packs may not currently be available.</small></p></td>
130 </tr>
131 <tr>
132         <td class="row1"><small><b><label for="dir">Continue with the upgrade?</label></b></small></td>
133                 <td class="row1" valign="middle" nowrap="nowrap"><input type="radio" name="override" value="1" id="c2" /><label for="c2">Yes, Continue</label>, <input type="radio" name="override" value="0" id="c1" checked="checked" /><label for="c1">No, Cancel</label></td>
134 </tr>
135 </table><br />
136         <?php
137         }
138
139         echo '<input type="hidden" name="db_login" value="'.urlencode($_POST['db_login']).'" />';
140         echo '<input type="hidden" name="db_password" value="'.urlencode($_POST['db_password']).'" />';
141         echo '<input type="hidden" name="db_host" value="'.$_POST['db_host'].'" />';
142         echo '<input type="hidden" name="db_name" value="'.$_POST['db_name'].'" />';
143         echo '<input type="hidden" name="db_port" value="'.$_POST['db_port'].'" />';
144         echo '<input type="hidden" name="tb_prefix" value="'.$_POST['tb_prefix'].'" />';
145         echo '<input type="hidden" name="old_version" value="'.$_POST['old_version'].'" />';
146         echo '<input type="hidden" name="new_version" value="'.$_POST['new_version'].'" />';
147
148         echo '<p align="center"><input type="submit" class="button" value=" Retry " name="submit" /></p></form>';
149         return;
150 ?>