update_courses.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * GOAL: Updates courses separately
  22. *
  23. * After upgrading a previous version to Dokeos 1.6, there are only
  24. * MAX_COURSE_TRANSFER courses converted to the new format - with
  25. * MAX_COURSE_TRANSFER in install/index.php being 100 as default.
  26. *
  27. * To update the rest of the courses you need to run this script.
  28. *
  29. * @package dokeos.install
  30. * @todo remove duplication: MAX_COURSE_TRANSFER is defined here and
  31. * also in install.index.php
  32. ==============================================================================
  33. */
  34. /*
  35. ==============================================================================
  36. INIT SECTION
  37. ==============================================================================
  38. */
  39. require('../inc/installedVersion.inc.php');
  40. require('../inc/lib/main_api.lib.php');
  41. require('../lang/english/trad4all.inc.php');
  42. require('../lang/english/install.inc.php');
  43. define('DOKEOS_COURSE_UPDATE',1);
  44. define('MAX_COURSE_TRANSFER',100);
  45. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  46. @set_time_limit(0);
  47. $update_path=trim(stripslashes($_GET['update_path']));
  48. $updateFromVersion=array('1.5','1.5.4','1.5.5');
  49. /*
  50. ==============================================================================
  51. INITIALISE FORM VARIABLES
  52. (If this is the first visit to this script.)
  53. Variables are read from the configuration file
  54. of the old Dokeos version (claro_main.conf.php).
  55. ==============================================================================
  56. */
  57. $updateFromConfigFile=''; // leave empty
  58. $badUpdatePath=false;
  59. if($_POST['step2'])
  60. {
  61. if(empty($_POST['updatePath']))
  62. {
  63. $_POST['step1']=1;
  64. }
  65. else
  66. {
  67. if($_POST['updatePath'][strlen($_POST['updatePath'])-1] != '/')
  68. {
  69. $_POST['updatePath'].='/';
  70. }
  71. if(!file_exists($_POST['updatePath']))
  72. {
  73. $badUpdatePath=true;
  74. $_POST['step2']=0;
  75. }
  76. elseif(!in_array(get_config_param('clarolineVersion'),$updateFromVersion))
  77. {
  78. $badUpdatePath=true;
  79. $_POST['step2']=0;
  80. }
  81. else
  82. {
  83. $urlAppendPath=str_replace('/main/install/update_courses.php','',$_SERVER['PHP_SELF']);
  84. $urlForm='http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/';
  85. $singleDbForm=get_config_param('singleDbEnabled');
  86. $dbNameForm=get_config_param('mainDbName');
  87. $dbHostForm=get_config_param('dbHost');
  88. $dbUsernameForm=get_config_param('dbLogin');
  89. $dbPassForm=get_config_param('dbPass');
  90. }
  91. }
  92. }
  93. elseif($_POST['step1'])
  94. {
  95. $_POST['updatePath']='';
  96. }
  97. ?>
  98. <html>
  99. <head>
  100. <title>-- Dokeos course update -- version <?php echo $dokeos_version; ?></title>
  101. <link rel="stylesheet" href="../css/default.css" type="text/css">
  102. </head>
  103. <body bgcolor="white" dir="<?php echo $text_dir ?>">
  104. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  105. <table cellpadding="6" cellspacing="0" border="0" width="650" bgcolor="#E6E6E6" align="center">
  106. <tr bgcolor="#4171B5"">
  107. <td valign="top">
  108. <big><font color="white">Dokeos course update - version <?php echo $dokeos_version; ?></font></big>
  109. </td>
  110. </tr>
  111. <tr bgcolor="#E6E6E6">
  112. <td>
  113. <img src="../img/bluelogo.gif" align="right" hspace="10" vspace="10">
  114. <?php
  115. /*
  116. ==============================================================================
  117. STEP 2 - COURSE UPDATE PROCESS
  118. the included files, update_db.inc.php and update_files.inc.php
  119. do the actual work of converting the course database
  120. and the files, respectively
  121. ==============================================================================
  122. */
  123. if($_POST['step2'])
  124. {
  125. include('update_db.inc.php');
  126. include('update_files.inc.php');
  127. ?>
  128. <h2>Step 2 of 2 &ndash; Course Update</h2>
  129. <?php echo sizeof($coursePath); ?> courses have been successfully updated.
  130. <br /><br />
  131. <?php if($nbr_courses > MAX_COURSE_TRANSFER): ?>
  132. <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>
  133. <?php else: ?>
  134. <br /><br />
  135. <?php endif; ?>
  136. <br /><br /><br /><br />
  137. </form>
  138. <form method="get" action="../../">
  139. <p align="right"><input type="submit" value="Go to your Dokeos portal" /></p>
  140. <?php
  141. }
  142. /*
  143. ==============================================================================
  144. STEP 1 : CONFIGURATION
  145. ==============================================================================
  146. */
  147. else
  148. {
  149. ?>
  150. <h2>Step 1 of 2 &ndash; Configuration</h2>
  151. Please enter the path where the older version of Dokeos is installed (<?php echo implode('&nbsp;|&nbsp;',$updateFromVersion); ?>). The courses will be moved from that location to the Dokeos path.
  152. <br /><br />
  153. <b>Notice:</b> Please run this update script only if you've just updated (incompletely) Dokeos <?php echo implode('&nbsp;|&nbsp;',$updateFromVersion); ?> to Dokeos <?php echo $dokeos_version; ?>!
  154. <br /><br />
  155. <?php
  156. if($badUpdatePath)
  157. {
  158. ?>
  159. <br /><br />
  160. <div style="background-color:white; color:red; text-align:center; font-weight:bold;">
  161. Error!<br />
  162. Dokeos <?php echo implode('|',$updateFromVersion); ?> has not been found in that directory.
  163. </div>
  164. <?php
  165. }
  166. else
  167. {
  168. echo '<br />';
  169. }
  170. ?>
  171. <table border="0" cellpadding="5" width="100%" align="center">
  172. <tr>
  173. <td>Where are the courses to be updated: </td>
  174. <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>
  175. </tr>
  176. </table>
  177. <p align="center">
  178. <input type="submit" name="step2" value="Update courses" onclick="javascript:if(this.value == 'Please Wait...') return false; else this.value='Please Wait...';" />
  179. </p>
  180. <?php
  181. }
  182. ?>
  183. </td>
  184. </tr>
  185. </table>
  186. </form>
  187. </body>
  188. </html>
  189. <?php
  190. /*
  191. ==============================================================================
  192. FUNCTIONS
  193. ==============================================================================
  194. */
  195. /**
  196. * this function returns a the value of a parameter from the configuration file
  197. *
  198. * @param string $param the parameter which the value is returned for
  199. * @return string the value of the parameter
  200. * @author Olivier Brouckaert
  201. */
  202. function get_config_param($param)
  203. {
  204. global $configFile, $updateFromConfigFile;
  205. if(empty($updateFromConfigFile))
  206. {
  207. if(file_exists($_POST['updatePath'].'main/include/config.inc.php.old'))
  208. {
  209. $updateFromConfigFile='main/include/config.inc.php.old';
  210. }
  211. elseif(file_exists($_POST['updatePath'].'main/inc/conf/claro_main.conf.php.old'))
  212. {
  213. $updateFromConfigFile='main/inc/conf/claro_main.conf.php.old';
  214. }
  215. else
  216. {
  217. return;
  218. }
  219. }
  220. if(is_array($configFile) && isset($configFile[$param]))
  221. {
  222. return $configFile[$param];
  223. }
  224. elseif(file_exists($_POST['updatePath'].$updateFromConfigFile))
  225. {
  226. $configFile=array();
  227. $temp=file($_POST['updatePath'].$updateFromConfigFile);
  228. $val='';
  229. foreach($temp as $enreg)
  230. {
  231. if(strstr($enreg,'='))
  232. {
  233. $enreg=explode('=',$enreg);
  234. if($enreg[0][0] == '$')
  235. {
  236. list($enreg[1])=explode(' //',$enreg[1]);
  237. $enreg[0]=trim(str_replace('$','',$enreg[0]));
  238. $enreg[1]=str_replace('\"','"',ereg_replace('(^"|"$)','',substr(trim($enreg[1]),0,-1)));
  239. if(strtolower($enreg[1]) == 'true')
  240. {
  241. $enreg[1]=1;
  242. }
  243. if(strtolower($enreg[1]) == 'false')
  244. {
  245. $enreg[1]=0;
  246. }
  247. else
  248. {
  249. $implode_string=' ';
  250. if(!strstr($enreg[1],'." ".') && strstr($enreg[1],'.$'))
  251. {
  252. $enreg[1]=str_replace('.$','." ".$',$enreg[1]);
  253. $implode_string='';
  254. }
  255. $tmp=explode('." ".',$enreg[1]);
  256. foreach($tmp as $tmp_key=>$tmp_val)
  257. {
  258. if(eregi('^\$[a-z_][a-z0-9_]*$',$tmp_val))
  259. {
  260. $tmp[$tmp_key]=get_config_param(str_replace('$','',$tmp_val));
  261. }
  262. }
  263. $enreg[1]=implode($implode_string,$tmp);
  264. }
  265. $configFile[$enreg[0]]=$enreg[1];
  266. if($enreg[0] == $param)
  267. {
  268. $val=$enreg[1];
  269. }
  270. }
  271. }
  272. }
  273. return $val;
  274. }
  275. }
  276. ?>