update_courses.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * GOAL: Updates courses separately
  6. *
  7. * After upgrading a previous version to Dokeos 1.6, there are only
  8. * MAX_COURSE_TRANSFER courses converted to the new format - with
  9. * MAX_COURSE_TRANSFER in install/index.php being 100 as default.
  10. *
  11. * To update the rest of the courses you need to run this script.
  12. *
  13. * @package dokeos.install
  14. * @todo remove duplication: MAX_COURSE_TRANSFER is defined here and
  15. * also in install.index.php
  16. ==============================================================================
  17. */
  18. /*
  19. ==============================================================================
  20. INIT SECTION
  21. ==============================================================================
  22. */
  23. @include '../inc/installedVersion.inc.php';
  24. require '../inc/lib/main_api.lib.php';
  25. require '../lang/english/trad4all.inc.php';
  26. require '../lang/english/install.inc.php';
  27. //load for get_config_param()
  28. require_once 'install_functions.inc.php';
  29. define('DOKEOS_COURSE_UPDATE',1);
  30. define('MAX_COURSE_TRANSFER',100);
  31. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  32. @set_time_limit(0);
  33. $update_path=trim(stripslashes($_GET['update_path']));
  34. $update_from_version=array('1.5','1.5.4','1.5.5');
  35. /*
  36. ==============================================================================
  37. INITIALISE FORM VARIABLES
  38. (If this is the first visit to this script.)
  39. Variables are read from the configuration file
  40. of the old Dokeos version (configuration.php).
  41. ==============================================================================
  42. */
  43. $updateFromConfigFile=''; // leave empty
  44. $badUpdatePath=false;
  45. if($_POST['step2'])
  46. {
  47. if(empty($_POST['updatePath']))
  48. {
  49. $_POST['step1']=1;
  50. }
  51. else
  52. {
  53. if($_POST['updatePath'][strlen($_POST['updatePath'])-1] != '/')
  54. {
  55. $_POST['updatePath'].='/';
  56. }
  57. if(!file_exists($_POST['updatePath']))
  58. {
  59. $badUpdatePath=true;
  60. $_POST['step2']=0;
  61. }
  62. elseif(!in_array(get_config_param('clarolineVersion'),$update_from_version))
  63. {
  64. $badUpdatePath=true;
  65. $_POST['step2']=0;
  66. }
  67. else
  68. {
  69. $urlAppendPath=str_replace('/main/install/update_courses.php','',api_get_self());
  70. $urlForm='http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/';
  71. $singleDbForm=get_config_param('singleDbEnabled');
  72. $dbNameForm=get_config_param('mainDbName');
  73. $dbHostForm=get_config_param('dbHost');
  74. $dbUsernameForm=get_config_param('dbLogin');
  75. $dbPassForm=get_config_param('dbPass');
  76. }
  77. }
  78. }
  79. elseif($_POST['step1'])
  80. {
  81. $_POST['updatePath']='';
  82. }
  83. ?>
  84. <html>
  85. <head>
  86. <title>-- Dokeos course update -- version <?php echo $dokeos_version; ?></title>
  87. <link rel="stylesheet" href="../css/dokeos_blue/default.css" type="text/css">
  88. </head>
  89. <body bgcolor="white" dir="<?php echo $text_dir ?>">
  90. <form method="post" action="<?php echo api_get_self(); ?>">
  91. <table cellpadding="6" cellspacing="0" border="0" width="650" bgcolor="#E6E6E6" align="center">
  92. <tr bgcolor="#4171B5"">
  93. <td valign="top">
  94. <big><font color="white">Dokeos course update - version <?php echo $dokeos_version; ?></font></big>
  95. </td>
  96. </tr>
  97. <tr bgcolor="#E6E6E6">
  98. <td>
  99. <img src="../img/bluelogo.gif" align="right" hspace="10" vspace="10">
  100. <?php
  101. /*
  102. ==============================================================================
  103. STEP 2 - COURSE UPDATE PROCESS
  104. the included files, update_db.inc.php and update_files.inc.php
  105. do the actual work of converting the course database
  106. and the files, respectively
  107. ==============================================================================
  108. */
  109. if($_POST['step2'])
  110. {
  111. include('update_db.inc.php');
  112. include('update_files.inc.php');
  113. ?>
  114. <h2>Step 2 of 2 &ndash; Course Update</h2>
  115. <?php echo sizeof($coursePath); ?> courses have been successfully updated.
  116. <br /><br />
  117. <?php if($nbr_courses > MAX_COURSE_TRANSFER): ?>
  118. <font color="red"><b>Warning:</b> You have more than <?php echo MAX_COURSE_TRANSFER; ?> courses on your Dokeos platform ! Only <?php echo MAX_COURSE_TRANSFER; ?> courses have been updated. To update the other courses, <a href="update_courses.php?update_path=<?php echo urlencode($updatePath); ?>"><font color="red">click here</font></a>.</font>
  119. <?php else: ?>
  120. <br /><br />
  121. <?php endif; ?>
  122. <br /><br /><br /><br />
  123. </form>
  124. <form method="get" action="../../">
  125. <p align="right"><input type="submit" value="Go to your Dokeos portal" /></p>
  126. <?php
  127. }
  128. /*
  129. ==============================================================================
  130. STEP 1 : CONFIGURATION
  131. ==============================================================================
  132. */
  133. else
  134. {
  135. ?>
  136. <h2>Step 1 of 2 &ndash; Configuration</h2>
  137. Please enter the path where the older version of Dokeos is installed (<?php echo implode('&nbsp;|&nbsp;',$update_from_version); ?>). The courses will be moved from that location to the Dokeos path.
  138. <br /><br />
  139. <b>Notice:</b> Please run this update script only if you've just updated (incompletely) Dokeos <?php echo implode('&nbsp;|&nbsp;',$update_from_version); ?> to Dokeos <?php echo $dokeos_version; ?>!
  140. <br /><br />
  141. <?php
  142. if($badUpdatePath)
  143. {
  144. ?>
  145. <br /><br />
  146. <div style="background-color:white; color:red; text-align:center; font-weight:bold;">
  147. Error!<br />
  148. Dokeos <?php echo implode('|',$update_from_version); ?> has not been found in that directory.
  149. </div>
  150. <?php
  151. }
  152. else
  153. {
  154. echo '<br />';
  155. }
  156. ?>
  157. <table border="0" cellpadding="5" width="100%" align="center">
  158. <tr>
  159. <td>Where are the courses to be updated: </td>
  160. <td><input type="text" name="updatePath" size="50" value="<?php echo empty($update_path)?($badUpdatePath?htmlentities($_POST['updatePath']):$_SERVER['DOCUMENT_ROOT'].'/old_version/'):htmlentities($update_path); ?>" /></td>
  161. </tr>
  162. </table>
  163. <p align="center">
  164. <input type="submit" name="step2" value="Update courses" onclick="javascript:if(this.value == 'Please Wait...') return false; else this.value='Please Wait...';" />
  165. </p>
  166. <?php
  167. }
  168. ?>
  169. </td>
  170. </tr>
  171. </table>
  172. </form>
  173. </body>
  174. </html>