PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/install/include/ustep2.php

https://github.com/harriswong/ATutor
PHP | 167 lines | 122 code | 29 blank | 16 comment | 17 complexity | 415ef5988671d94cbca8639675a3617d MD5 | raw file
  1. <?php
  2. /************************************************************************/
  3. /* ATutor */
  4. /************************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* http://atutor.ca */
  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. /************************************************************************/
  11. // $Id$
  12. ignore_user_abort(true);
  13. @set_time_limit(0);
  14. if (!defined('AT_INCLUDE_PATH')) { exit; }
  15. function update_one_ver($up_file) {
  16. global $progress;
  17. $update_file = implode('_',$up_file);
  18. queryFromFile('db/'.$update_file.'sql');
  19. //$progress[] = 'Successful update from version '.$up_file[2].' to '.$up_file[4];
  20. return $up_file[4];
  21. }
  22. $_POST['db_login'] = urldecode($_POST['db_login']);
  23. $_POST['db_password'] = urldecode($_POST['db_password']);
  24. unset($errors);
  25. //check DB & table connection
  26. $db = @mysql_connect($_POST['db_host'] . ':' . $_POST['db_port'], $_POST['db_login'], urldecode($_POST['db_password']));
  27. if (!$db) {
  28. $error_no = mysql_errno();
  29. if ($error_no == 2005) {
  30. $errors[] = 'Unable to connect to database server. Database with hostname '.$_POST['db_host'].' not found.';
  31. } else {
  32. $errors[] = 'Unable to connect to database server. Wrong username/password combination.';
  33. }
  34. } else {
  35. if (!mysql_select_db($_POST['db_name'], $db)) {
  36. $errors[] = 'Unable to connect to database <b>'.$_POST['db_name'].'</b>.';
  37. }
  38. $sql = "SELECT VERSION() AS version";
  39. $result = mysql_query($sql, $db);
  40. $row = mysql_fetch_assoc($result);
  41. if (version_compare($row['version'], '4.0.2', '>=') === FALSE) {
  42. $errors[] = 'MySQL version '.$row['version'].' was detected. ATutor requires version 4.0.2 or later.';
  43. }
  44. if (!$errors) {
  45. $progress[] = 'Connected to database <b>'.$_POST['db_name'].'</b> successfully.';
  46. unset($errors);
  47. //Save all the course primary language into session variables iff it has not been set.
  48. if (!isset($_SESSION['course_info'])){
  49. $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";
  50. $result = mysql_query($sql, $db);
  51. while ($row = mysql_fetch_assoc($result)){
  52. $_SESSION['course_info'][$row['course_id']] = array('char_set'=>$row['char_set'], 'language_code'=>$row['language_code']);
  53. }
  54. }
  55. $sql = "DELETE FROM ".$_POST['tb_prefix']."language_text WHERE `variable`<>'_c_template' AND `variable`<>'_c_msgs'";
  56. @mysql_query($sql, $db);
  57. $sql = "DELETE FROM ".$_POST['tb_prefix']."languages WHERE language_code<>'en'";
  58. @mysql_query($sql, $db);
  59. //get list of all update scripts minus sql extension
  60. $files = scandir('db');
  61. foreach ($files as $file) {
  62. if(count($file = explode('_',$file))==5) {
  63. $file[4] = substr($file[4],0,-3);
  64. $update_files[$file[2]] = $file;
  65. }
  66. }
  67. $curr_ver = $_POST['old_version'];
  68. ksort($update_files);
  69. foreach ($update_files as $up_file) {
  70. if(version_compare($curr_ver, $up_file[4], '<')) {
  71. update_one_ver($up_file);
  72. }
  73. }
  74. /* reset all the accounts to English */
  75. $sql = "UPDATE ".$_POST['tb_prefix']."members SET language='en', creation_date=creation_date, last_login=last_login";
  76. @mysql_query($sql, $db);
  77. /* set all the courses to 'en' as primary language if empty. added 1.4.1 */
  78. $sql = "UPDATE ".$_POST['tb_prefix']."courses SET primary_language='en' WHERE primary_language=''";
  79. @mysql_query($sql, $db);
  80. queryFromFile('db/atutor_language_text.sql');
  81. if (!$errors) {
  82. print_progress($step);
  83. unset($_POST['submit']);
  84. store_steps(1);
  85. print_feedback($progress);
  86. echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
  87. <input type="hidden" name="step" value="3" />
  88. <input type="hidden" name="upgrade_action" value="true" />';
  89. echo '<input type="hidden" name="db_login" value="'.urlencode($_POST['db_login']).'" />';
  90. echo '<input type="hidden" name="db_password" value="'.urlencode($_POST['db_password']).'" />';
  91. echo '<input type="hidden" name="db_host" value="'.$_POST['db_host'].'" />';
  92. echo '<input type="hidden" name="db_name" value="'.$_POST['db_name'].'" />';
  93. echo '<input type="hidden" name="db_port" value="'.$_POST['db_port'].'" />';
  94. echo '<input type="hidden" name="tb_prefix" value="'.$_POST['tb_prefix'].'" />';
  95. echo '<input type="hidden" name="old_version" value="'.$_POST['old_version'].'" />';
  96. echo '<input type="hidden" name="new_version" value="'.$_POST['new_version'].'" />';
  97. print_hidden(2);
  98. echo '<p align="center"><input type="submit" class="button" value=" Next &raquo; " name="submit" /></p></form>';
  99. return;
  100. }
  101. }
  102. }
  103. print_progress($step);
  104. unset($_POST['submit']);
  105. if (isset($progress)) {
  106. print_feedback($progress);
  107. }
  108. if (isset($errors)) {
  109. print_errors($errors);
  110. }
  111. echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
  112. <input type="hidden" name="step" value="2" />';
  113. store_steps(1);
  114. print_hidden(2);
  115. if ($found_lang) {
  116. ?>
  117. <table width="60%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
  118. <tr>
  119. <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>
  120. </tr>
  121. <tr>
  122. <td class="row1"><small><b><label for="dir">Continue with the upgrade?</label></b></small></td>
  123. <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>
  124. </tr>
  125. </table><br />
  126. <?php
  127. }
  128. echo '<input type="hidden" name="db_login" value="'.urlencode($_POST['db_login']).'" />';
  129. echo '<input type="hidden" name="db_password" value="'.urlencode($_POST['db_password']).'" />';
  130. echo '<input type="hidden" name="db_host" value="'.$_POST['db_host'].'" />';
  131. echo '<input type="hidden" name="db_name" value="'.$_POST['db_name'].'" />';
  132. echo '<input type="hidden" name="db_port" value="'.$_POST['db_port'].'" />';
  133. echo '<input type="hidden" name="tb_prefix" value="'.$_POST['tb_prefix'].'" />';
  134. echo '<input type="hidden" name="old_version" value="'.$_POST['old_version'].'" />';
  135. echo '<input type="hidden" name="new_version" value="'.$_POST['new_version'].'" />';
  136. echo '<p align="center"><input type="submit" class="button" value=" Retry " name="submit" /></p></form>';
  137. return;
  138. ?>