PageRenderTime 24ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/install/include/ustep2.php

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