f85ae122a7d25d3290433bf7edf748d14e7fc0b4
[acontent.git] / docs / install / include / ustep2.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
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
13 ignore_user_abort(true); 
14 @set_time_limit(0); 
15
16 if (!defined('TR_INCLUDE_PATH')) { exit; }
17
18 function update_one_ver($up_file) {
19         global $progress;
20         $update_file = implode('_',$up_file);
21         queryFromFile('db/'.$update_file.'sql');
22         //$progress[] = 'Successful update from version '.$up_file[2].' to '.$up_file[4];
23         return $up_file[4];
24 }
25
26 $_POST['db_login'] = urldecode($_POST['db_login']);
27 $_POST['db_password'] = urldecode($_POST['db_password']);
28
29         unset($errors);
30
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. AContent 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                         //Save all the course primary language into session variables iff it has not been set. 
59 //                      if (!isset($_SESSION['course_info'])){
60 //                              $sql = "SELECT a.course_id, a.title, l.language_code, l.char_set FROM ".$_POST['tb_prefix']."courses a left join ".$_POST['tb_prefix']."languages l ON l.language_code = a.primary_language";
61 //                              $result = mysql_query($sql, $db);
62 //                              while ($row = mysql_fetch_assoc($result)){
63 //                                      $_SESSION['course_info'][$row['course_id']] = array('char_set'=>$row['char_set'], 'language_code'=>$row['language_code']);
64 //                              }
65 //                      }
66
67                         $sql = "DELETE FROM ".$_POST['tb_prefix']."languages WHERE language_code<>'en'";
68                         @mysql_query($sql, $db);
69
70                         //get list of all update scripts minus sql extension
71                         $files = scandir('db'); 
72                         foreach ($files as $file) {
73                                 if(count($file = explode('_',$file))==5) {
74                                         $file[4] = substr($file[4],0,-3);
75                                         $update_files[$file[2]] = $file;
76                                 }
77                         }
78                         
79                         $curr_ver = $_POST['old_version'];
80                         ksort($update_files);
81                         foreach ($update_files as $up_file) {
82                                 if(version_compare($curr_ver, $up_file[4], '<')) {
83                                         update_one_ver($up_file);
84                                 }
85                         }
86                         
87                         /* reset all the accounts to English */
88 //                      $sql = "UPDATE ".$_POST['tb_prefix']."users SET language='en', creation_date=creation_date, last_login=last_login";
89 //                      @mysql_query($sql, $db);
90
91                         queryFromFile('db/language_text.sql');
92
93                         if (!$errors) {
94                                 print_progress($step);
95
96                                 unset($_POST['submit']);
97                                 store_steps(1);
98                                 print_feedback($progress);
99
100                                 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
101                                 <input type="hidden" name="step" value="3" />
102                                 <input type="hidden" name="upgrade_action" value="true" />';
103                                 echo '<input type="hidden" name="db_login" value="'.urlencode($_POST['db_login']).'" />';
104                                 echo '<input type="hidden" name="db_password" value="'.urlencode($_POST['db_password']).'" />';
105                                 echo '<input type="hidden" name="db_host" value="'.$_POST['db_host'].'" />';
106                                 echo '<input type="hidden" name="db_name" value="'.$_POST['db_name'].'" />';
107                                 echo '<input type="hidden" name="db_port" value="'.$_POST['db_port'].'" />';
108                                 echo '<input type="hidden" name="tb_prefix" value="'.$_POST['tb_prefix'].'" />';
109                                 echo '<input type="hidden" name="old_version" value="'.$_POST['old_version'].'" />';
110                                 echo '<input type="hidden" name="new_version" value="'.$_POST['new_version'].'" />';
111                                 print_hidden(2);
112                                 echo '<p align="center"><input type="submit" class="button" value=" Next &raquo; " name="submit" /></p></form>';
113                                 return;
114                         }
115                 }
116         }
117
118         print_progress($step);
119
120         unset($_POST['submit']);
121         if (isset($progress)) {
122                 print_feedback($progress);
123         }
124
125         if (isset($errors)) {
126                 print_errors($errors);
127         }
128
129
130         echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
131         <input type="hidden" name="step" value="2" />';
132         store_steps(1);
133         print_hidden(2);
134         
135         if ($found_lang) {
136 ?>
137 <table width="60%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
138 <tr>
139         <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>
140 </tr>
141 <tr>
142         <td class="row1"><small><b><label for="dir">Continue with the upgrade?</label></b></small></td>
143                 <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>
144 </tr>
145 </table><br />
146         <?php
147         }
148
149         echo '<input type="hidden" name="db_login" value="'.urlencode($_POST['db_login']).'" />';
150         echo '<input type="hidden" name="db_password" value="'.urlencode($_POST['db_password']).'" />';
151         echo '<input type="hidden" name="db_host" value="'.$_POST['db_host'].'" />';
152         echo '<input type="hidden" name="db_name" value="'.$_POST['db_name'].'" />';
153         echo '<input type="hidden" name="db_port" value="'.$_POST['db_port'].'" />';
154         echo '<input type="hidden" name="tb_prefix" value="'.$_POST['tb_prefix'].'" />';
155         echo '<input type="hidden" name="old_version" value="'.$_POST['old_version'].'" />';
156         echo '<input type="hidden" name="new_version" value="'.$_POST['new_version'].'" />';
157
158         echo '<p align="center"><input type="submit" class="button" value=" Retry " name="submit" /></p></form>';
159         return;
160 ?>