install_functions.inc.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. <?php
  2. /**
  3. * This function prints class=active_step $current_step=$param
  4. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  5. */
  6. function step_active($param)
  7. {
  8. global $current_step;
  9. if ($param==$current_step)
  10. {
  11. echo 'class="current_step" ';
  12. }
  13. }
  14. /**
  15. * This function displays the Step X of Y -
  16. * @return string String that says 'Step X of Y' with the right values
  17. */
  18. function display_step_sequence()
  19. {
  20. global $current_step;
  21. global $total_steps;
  22. return get_lang('Step'.$current_step).' &ndash; ';
  23. }
  24. /**
  25. * this function checks if a php extension exists or not
  26. *
  27. * @param string $extentionName name of the php extension to be checked
  28. * @param boolean $echoWhenOk true => show ok when the extension exists
  29. * @author Christophe Gesche
  30. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  31. * @version Dokeos 1.8, august 2006
  32. */
  33. function check_extension($extention_name,$return_success=false, $return_failure=false)
  34. {
  35. if(extension_loaded($extention_name))
  36. {
  37. return '<strong><font color="green">'.$return_success.'</font></strong>';
  38. }
  39. else
  40. {
  41. return '<strong><font color="red">'.$return_failure.'</font></strong>';
  42. //echo "\t<li><b>$extentionName</b> <font color=\"red\">is missing (Dokeos can work without it)</font> (<a href=\"http://www.php.net/$extentionName\" target=\"_blank\">$extentionName</a>)</li>\n";
  43. }
  44. }
  45. /**
  46. * This function checks if a php settings matches the recommended value
  47. *
  48. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  49. * @version Dokeos 1.8, august 2006
  50. */
  51. function check_php_setting($php_setting, $recommended_value, $return_success=false, $return_failure=false)
  52. {
  53. $current_php_value = get_php_setting($php_setting);
  54. if ( $current_php_value== $recommended_value)
  55. {
  56. return '<strong><font color="green">'.$current_php_value.' '.$return_success.'</font></strong>';
  57. }
  58. else
  59. {
  60. return '<strong><font color="red">'.$current_php_value.' '.$return_failure.'</font></strong>';
  61. }
  62. }
  63. /**
  64. * Enter description here...
  65. *
  66. * @param string $val a php ini value
  67. * @return boolean: ON or OFF
  68. * @author Joomla <http://www.joomla.org>
  69. */
  70. function get_php_setting($val) {
  71. $r = (ini_get($val) == '1' ? 1 : 0);
  72. return $r ? 'ON' : 'OFF';
  73. }
  74. /**
  75. * This function checks if the given folder is writable
  76. */
  77. function check_writable($folder)
  78. {
  79. if (is_writable('../'.$folder))
  80. {
  81. return '<strong><font color="green">'.get_lang('Writable').'</font></strong>';
  82. }
  83. else
  84. {
  85. return '<strong><font color="red">'.get_lang('NotWritable').'</font></strong>';
  86. }
  87. }
  88. /**
  89. * this function returns a string "FALSE" or "TRUE" according to the variable in parameter
  90. *
  91. * @param integer $var the variable to convert
  92. * @return string the string "FALSE" or "TRUE"
  93. * @author Christophe Gesche
  94. */
  95. function trueFalse($var)
  96. {
  97. return $var?'true':'false';
  98. }
  99. /**
  100. * This function returns the value of a parameter from the configuration file
  101. *
  102. * WARNING - this function relies heavily on global variables $updateFromConfigFile
  103. * and $configFile, and also changes these globals. This can be rewritten.
  104. *
  105. * @param string $param the parameter of which the value is returned
  106. * @return string the value of the parameter
  107. * @author Olivier Brouckaert
  108. */
  109. function get_config_param($param)
  110. {
  111. global $configFile, $updateFromConfigFile;
  112. $updatePath = realpath($_POST['updatePath']).'/';
  113. $updateFromInstalledVersionFile = '';
  114. if(empty($updateFromConfigFile)) //if update from previous install was requested
  115. {
  116. //try to recover old config file from dokeos 1.6.x
  117. if(file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php'))
  118. {
  119. $updateFromConfigFile='claroline/inc/conf/claro_main.conf.php';
  120. if(file_exists($updatePath.'claroline/inc/installedVersion.inc.php'))
  121. {
  122. $updateFromInstalledVersionFile = 'claroline/inc/installedVersion.inc.php';
  123. }
  124. }
  125. //try to recover old config file from dokeos 1.8.x
  126. elseif(file_exists($updatePath.'main/inc/conf/configuration.php'))
  127. {
  128. $updateFromConfigFile='main/inc/conf/configuration.php';
  129. }
  130. //give up recovering
  131. else
  132. {
  133. return null;
  134. }
  135. }
  136. //look if we already have the queried param
  137. if(is_array($configFile) && isset($configFile[$param]))
  138. {
  139. return $configFile[$param];
  140. }
  141. //the param was not found in global vars, so look into the old config file
  142. elseif(file_exists($updatePath.$updateFromConfigFile))
  143. {
  144. $configFile=array();
  145. $temp=file($updatePath.$updateFromConfigFile);
  146. $val='';
  147. if(file_exists($updatePath.$updateFromInstalledVersionFile))
  148. {
  149. $temp2 = file($updatePath.$updateFromInstalledVersionFile);
  150. $temp = array_merge($temp,$temp2);
  151. }
  152. //parse the config file (TODO clarify why it has to be so complicated)
  153. foreach($temp as $enreg)
  154. {
  155. if(strstr($enreg,'='))
  156. {
  157. $enreg=explode('=',$enreg);
  158. if($enreg[0][0] == '$')
  159. {
  160. list($enreg[1])=explode(' //',$enreg[1]);
  161. $enreg[0]=trim(str_replace('$','',$enreg[0]));
  162. $enreg[1]=str_replace('\"','"',ereg_replace('(^"|"$)','',substr(trim($enreg[1]),0,-1)));
  163. if(strtolower($enreg[1]) == 'true')
  164. {
  165. $enreg[1]=1;
  166. }
  167. if(strtolower($enreg[1]) == 'false')
  168. {
  169. $enreg[1]=0;
  170. }
  171. else
  172. {
  173. $implode_string=' ';
  174. if(!strstr($enreg[1],'." ".') && strstr($enreg[1],'.$'))
  175. {
  176. $enreg[1]=str_replace('.$','." ".$',$enreg[1]);
  177. $implode_string='';
  178. }
  179. $tmp=explode('." ".',$enreg[1]);
  180. foreach($tmp as $tmp_key=>$tmp_val)
  181. {
  182. if(eregi('^\$[a-z_][a-z0-9_]*$',$tmp_val))
  183. {
  184. $tmp[$tmp_key]=get_config_param(str_replace('$','',$tmp_val));
  185. }
  186. }
  187. $enreg[1]=implode($implode_string,$tmp);
  188. }
  189. $configFile[$enreg[0]]=$enreg[1];
  190. if($enreg[0] == $param)
  191. {
  192. $val=$enreg[1];
  193. }
  194. }
  195. }
  196. }
  197. return $val;
  198. }
  199. }
  200. /**
  201. * Get the config param from the database. If not found, return null
  202. * @param string DB Host
  203. * @param string DB login
  204. * @param string DB pass
  205. * @param string DB name
  206. * @param string Name of param we want
  207. * @return mixed The parameter value or null if not found
  208. */
  209. function get_config_param_from_db($host,$login,$pass,$db_name,$param='')
  210. {
  211. $mydb = mysql_connect($host,$login,$pass);
  212. $myconnect = mysql_select_db($db_name);
  213. $sql = "SELECT * FROM settings_current WHERE variable = '$param'";
  214. $res = mysql_query($sql);
  215. if($res===false){return null;}
  216. if(mysql_num_rows($res)>0)
  217. {
  218. $row = mysql_fetch_array($res);
  219. $value = $row['selected_value'];
  220. return $value;
  221. }
  222. return null;
  223. }
  224. /**
  225. * Return a list of language directories.
  226. * @todo function does not belong here, move to code library,
  227. * also see infocours.php which contains similar function
  228. */
  229. function get_language_folder_list($dirname)
  230. {
  231. if ($dirname[strlen($dirname)-1] != '/') $dirname .= '/';
  232. $handle = opendir($dirname);
  233. $language_list = array();
  234. while ($entries = readdir($handle))
  235. {
  236. if ($entries=='.' || $entries=='..' || $entries=='CVS' || $entries == '.svn') continue;
  237. if (is_dir($dirname.$entries))
  238. {
  239. $language_list[] = $entries;
  240. }
  241. }
  242. closedir($handle);
  243. return $language_list;
  244. }
  245. /*
  246. ==============================================================================
  247. DISPLAY FUNCTIONS
  248. ==============================================================================
  249. */
  250. /**
  251. * Displays a form (drop down menu) so the user can select
  252. * his/her preferred language.
  253. */
  254. function display_language_selection_box()
  255. {
  256. //get language list
  257. $dirname = '../lang/';
  258. $language_list = get_language_folder_list($dirname);
  259. sort($language_list);
  260. $language_to_display = $language_list;
  261. //display
  262. echo "\t\t<select name=\"language_list\">\n";
  263. $default_language = 'english';
  264. foreach ($language_to_display as $key => $value)
  265. {
  266. if ($value == $default_language) $option_end = ' selected="selected">';
  267. else $option_end = '>';
  268. echo "\t\t\t<option value=\"$value\"$option_end";
  269. echo $value;
  270. echo "</option>\n";
  271. }
  272. echo "\t\t</select>\n";
  273. }
  274. /**
  275. * This function displays a language dropdown box so that the installatioin
  276. * can be done in the language of the user
  277. */
  278. function display_language_selection()
  279. { ?>
  280. <h1><?php get_lang('WelcomeToTheDokeosInstaller');?></h1>
  281. <h2><?php echo display_step_sequence(); ?><?php echo get_lang('InstallationLanguage');?></h2>
  282. <p><?php echo get_lang('PleaseSelectInstallationProcessLanguage');?>:</p>
  283. <form id="lang_form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  284. <?php display_language_selection_box(); ?>
  285. <input type="submit" name="step1" value="<?php get_lang('Next');?> &gt;" />
  286. </form>
  287. <?php }
  288. /**
  289. * This function displays the requirements for installing Dokeos.
  290. *
  291. * @param unknown_type $installType
  292. * @param unknown_type $badUpdatePath
  293. * @param unknown_type $update_from_version
  294. *
  295. * @author unknow
  296. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  297. */
  298. function display_requirements($installType, $badUpdatePath, $update_from_version)
  299. {
  300. echo '<h2>'.display_step_sequence().get_lang('Requirements')."</h2>\n";
  301. echo '<strong>'.get_lang('ReadThoroughly').'</strong><br />';
  302. echo get_lang('MoreDetails').' <a href="../../documentation/installation_guide.html" target="_blank">'.get_lang('ReadTheInstallGuide').'</a>.<br />'."\n";
  303. // SERVER REQUIREMENTS
  304. echo '<div class="RequirementHeading"><h1>'.get_lang('ServerRequirements').'</h1>';
  305. echo '<div class="RequirementText">'.get_lang('ServerRequirementsInfo').'</div>';
  306. echo '<div class="RequirementContent">';
  307. echo '<table class="requirements">
  308. <tr>
  309. <td class="requirements-item">'.get_lang('PHPVersion').'>= 5.0</td>
  310. <td class="requirements-value">';
  311. if (phpversion() < '5.0')
  312. {
  313. echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
  314. }
  315. else
  316. {
  317. echo '<strong><font color="green">'.get_lang('PHPVersionOK'). ' '.phpversion().'</font></strong>';
  318. }
  319. echo ' </td>
  320. </tr>
  321. <tr>
  322. <td class="requirements-item">session '.get_lang('support').'</td>
  323. <td class="requirements-value">'.check_extension('session',get_lang('OK'), get_lang('ExtensionSessionsNotAvailable')).'</td>
  324. </tr>
  325. <tr>
  326. <td class="requirements-item">MySQL '.get_lang('support').'</td>
  327. <td class="requirements-value">'.check_extension('mysql',get_lang('OK'), get_lang('ExtensionMySQLNotAvailable')).'</td>
  328. </tr>
  329. <tr>
  330. <td class="requirements-item">zlib '.get_lang('support').'</td>
  331. <td class="requirements-value">'.check_extension('zlib',get_lang('OK'), get_lang('ExtensionZlibNotAvailable')).'</td>
  332. </tr>
  333. <tr>
  334. <td class="requirements-item">Regular Expressions '.get_lang('support').'</td>
  335. <td class="requirements-value">'.check_extension('pcre',get_lang('OK'), get_lang('ExtensionPCRENotAvailable')).'</td>
  336. </tr>
  337. <tr>
  338. <td class="requirements-item">XML '.get_lang('support').'</td>
  339. <td class="requirements-value">'.check_extension('xml',get_lang('OK'), get_lang('ExtensionZlibNotAvailable')).'</td>
  340. </tr>
  341. <tr>
  342. <td class="requirements-item">LDAP '.get_lang('support').'('.get_lang('Optional').')</td>
  343. <td class="requirements-value">'.check_extension('ldap',get_lang('OK'), get_lang('ExtensionLDAPNotAvailable')).'</td>
  344. </tr>
  345. <tr>
  346. <td class="requirements-item">GD '.get_lang('support').'('.get_lang('Optional').')</td>
  347. <td class="requirements-value">'.check_extension('gd',get_lang('OK'), get_lang('ExtensionGDNotAvailable')).'</td>
  348. </tr>
  349. </table>';
  350. echo ' </div>';
  351. echo '</div>';
  352. // RECOMMENDED SETTINGS
  353. // Note: these are the settings for Joomla, does this also apply for Dokeos?
  354. // Note: also add upload_max_filesize here so that large uploads are possible
  355. echo '<div class="RequirementHeading"><h1>'.get_lang('RecommendedSettings').'</h1>';
  356. echo '<div class="RequirementText">'.get_lang('RecommendedSettingsInfo').'</div>';
  357. echo '<div class="RequirementContent">';
  358. echo '<table class="requirements">
  359. <tr>
  360. <th>'.get_lang('Setting').'</th>
  361. <th>'.get_lang('Recommended').'</th>
  362. <th>'.get_lang('Actual').'</th>
  363. </tr>
  364. <tr>
  365. <td class="requirements-item"><a href="http://php.net/manual/features.safe-mode.php">Safe Mode</a></td>
  366. <td class="requirements-recommended">OFF</td>
  367. <td class="requirements-value">'.check_php_setting('safe_mode','OFF').'</td>
  368. </tr>
  369. <tr>
  370. <td class="requirements-item"><a href="http://php.net/manual/ref.errorfunc.php#ini.display-errors">Display Errors</a></td>
  371. <td class="requirements-recommended">OFF</td>
  372. <td class="requirements-value">'.check_php_setting('display_errors','OFF').'</td>
  373. </tr>
  374. <tr>
  375. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.file-uploads">File Uploads</a></td>
  376. <td class="requirements-recommended">ON</td>
  377. <td class="requirements-value">'.check_php_setting('file_uploads','ON').'</td>
  378. </tr>
  379. <tr>
  380. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-gpc">Magic Quotes GPC</a></td>
  381. <td class="requirements-recommended">ON</td>
  382. <td class="requirements-value">'.check_php_setting('magic_quotes_gpc','ON').'</td>
  383. </tr>
  384. <tr>
  385. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-runtime">Magic Quotes Runtime</a></td>
  386. <td class="requirements-recommended">OFF</td>
  387. <td class="requirements-value">'.check_php_setting('magic_quotes_runtime','OFF').'</td>
  388. </tr>
  389. <tr>
  390. <td class="requirements-item"><a href="http://php.net/manual/security.globals.php">Register Globals</a></td>
  391. <td class="requirements-recommended">OFF</td>
  392. <td class="requirements-value">'.check_php_setting('register_globals','OFF').'</td>
  393. </tr>
  394. <tr>
  395. <td class="requirements-item"><a href="http://php.net/manual/ref.session.php#ini.session.auto-start">Session auto start</a></td>
  396. <td class="requirements-recommended">OFF</td>
  397. <td class="requirements-value">'.check_php_setting('session.auto_start','OFF').'</td>
  398. </tr>
  399. <tr>
  400. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.short-open-tag">Short Open Tag</a></td>
  401. <td class="requirements-recommended">ON</td>
  402. <td class="requirements-value">'.check_php_setting('short_open_tag','ON').'</td>
  403. </tr>
  404. <tr>
  405. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.upload-max-filesize">Maximum upload file size</a></td>
  406. <td class="requirements-recommended">10M-100M</td>
  407. <td class="requirements-value">'.ini_get('upload_max_filesize').'</td>
  408. </tr>
  409. <tr>
  410. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.post-max-size">Maximum post size</a></td>
  411. <td class="requirements-recommended">10M-100M</td>
  412. <td class="requirements-value">'.ini_get('post_max_size').'</td>
  413. </tr>
  414. </table>';
  415. echo ' </div>';
  416. echo '</div>';
  417. // DIRECTORY AND FILE PERMISSIONS
  418. echo '<div class="RequirementHeading"><h1>'.get_lang('DirectoryAndFilePermissions').'</h1>';
  419. echo '<div class="RequirementText">'.get_lang('DirectoryAndFilePermissionsInfo').'</div>';
  420. echo '<div class="RequirementContent">';
  421. echo '<table class="requirements">
  422. <tr>
  423. <td class="requirements-item">dokeos/main/inc/conf/</td>
  424. <td class="requirements-value">'.check_writable('inc/conf/').'</td>
  425. </tr>
  426. <tr>
  427. <td class="requirements-item">dokeos/main/garbage/</td>
  428. <td class="requirements-value">'.check_writable('garbage/').'</td>
  429. </tr>
  430. <tr>
  431. <td class="requirements-item">dokeos/main/upload/</td>
  432. <td class="requirements-value">'.check_writable('upload/').'</td>
  433. </tr>
  434. <tr>
  435. <td class="requirements-item">dokeos/archive/</td>
  436. <td class="requirements-value">'.check_writable('../archive/').'</td>
  437. </tr>
  438. <tr>
  439. <td class="requirements-item">dokeos/courses/</td>
  440. <td class="requirements-value">'.check_writable('../courses/').'</td>
  441. </tr>
  442. <tr>
  443. <td class="requirements-item">dokeos/home/</td>
  444. <td class="requirements-value">'.check_writable('../home/').'</td>
  445. </tr>
  446. ';
  447. echo '</table>';
  448. echo ' </div>';
  449. echo '</div>';
  450. if($installType == 'update' && (empty($_POST['updatePath']) || $badUpdatePath))
  451. {
  452. if($badUpdatePath)
  453. { ?>
  454. <div style="color:red; background-color:white; font-weight:bold; text-align:center;">
  455. <?php echo get_lang('Error');?>!<br />
  456. Dokeos <?php echo implode('|',$update_from_version).get_lang('HasNotBeenFoundInThatDir'); ?>.
  457. </div>
  458. <?php }
  459. else
  460. {
  461. echo '<br />';
  462. }
  463. ?>
  464. <table border="0" cellpadding="5" align="center">
  465. <tr>
  466. <td><?php echo get_lang('OldVersionRootPath');?>:</td>
  467. <td><input type="text" name="updatePath" size="50" value="<?php echo $badUpdatePath?htmlentities($_POST['updatePath']):$_SERVER['DOCUMENT_ROOT'].'/old_version/'; ?>" /></td>
  468. </tr>
  469. <tr>
  470. <td colspan="2" align="center">
  471. <input type="submit" name="step1" value="&lt; <?php echo get_lang('Back');?>" />
  472. <input type="submit" name="step2_update" value="<?php echo get_lang('Next');?> &gt;" />
  473. </td>
  474. </tr>
  475. </table>
  476. <?php
  477. }
  478. else
  479. {
  480. $error=false;
  481. //First, attempt to set writing permissions if we don't have them yet
  482. //0xxx is an octal number, this is the required format
  483. $notwritable = array();
  484. if(!is_writable('../inc/conf'))
  485. {
  486. $notwritable[]='../inc/conf';
  487. @chmod('../inc/conf',0777);
  488. }
  489. if(!is_writable('../garbage'))
  490. {
  491. $notwritable[]='../garbage';
  492. @chmod('../garbage',0777);
  493. }
  494. if(!is_writable('../upload'))
  495. {
  496. $notwritable[]='../upload';
  497. @chmod('../upload', 0777);
  498. }
  499. if(!is_writable('../../archive'))
  500. {
  501. $notwritable[]='../../archive';
  502. @chmod('../../archive',0777);
  503. }
  504. if(!is_writable('../../courses'))
  505. {
  506. $notwritable[]='../../courses';
  507. @chmod('../../courses',0777);
  508. }
  509. if(!is_writable('../../home'))
  510. {
  511. $notwritable[]='../../home';
  512. @chmod('../../home',0777);
  513. }
  514. if(file_exists('../inc/conf/configuration.php') && !is_writable('../inc/conf/configuration.php'))
  515. {
  516. $notwritable[]='../inc/conf/configuration.php';
  517. @chmod('../inc/conf/configuration.php',0666);
  518. }
  519. //Second, if this fails, report an error
  520. //--> the user will have to adjust the permissions manually
  521. if(count($notwritable)>0)
  522. {
  523. $error=true;
  524. echo '<div style="color:#cc0033; background-color:white; font-weight:bold; text-align:center;">';
  525. echo get_lang('Warning').':<br />';
  526. printf(get_lang('NoWritePermissionPleaseReadInstallGuide'),'</font><a href="../../documentation/installation_guide.html" target="blank">','</a> <font color="#cc0033">');
  527. echo '<ul>';
  528. foreach ($notwritable as $value)
  529. {
  530. echo '<li>'.$value.'</li>';
  531. }
  532. echo '</ul>';
  533. echo '</div>';
  534. }
  535. // check wether a Dokeos configuration file already exists.
  536. elseif(file_exists('../inc/conf/configuration.php'))
  537. {
  538. echo '<div style="color:#cc0033; background-color:white; font-weight:bold; text-align:center;">';
  539. echo get_lang('WarningExistingDokeosInstallationDetected');
  540. echo '</div>';
  541. }
  542. //and now display the choice buttons (go back or install)
  543. ?>
  544. <p align="center">
  545. <input type="submit" name="step1" onclick="window.location='index.php';return false;" value="&lt; <?php echo get_lang('Previous'); ?>"/>
  546. <input type="submit" name="step2_install" value="<?php echo get_lang("NewInstallation"); ?>" <?php if($error) echo 'disabled="disabled"'; ?> />
  547. <?php
  548. //real code
  549. echo '<input type="submit" name="step2_update" value="Upgrade from Dokeos ' . implode(', ',$update_from_version) . '"';
  550. if($error) echo ' disabled="disabled"';
  551. //temporary code for alpha version, disabling upgrade
  552. //echo '<input type="submit" name="step2_update" value="Upgrading is not possible in this beta version"';
  553. //echo ' disabled="disabled"';
  554. //end temp code
  555. echo ' />';
  556. echo '</p>';
  557. }
  558. }
  559. /**
  560. * Displays the license (GNU GPL) as step 2, with
  561. * - an "I accept" button named step3 to proceed to step 3;
  562. * - a "Back" button named step1 to go back to the first step.
  563. */
  564. function display_license_agreement()
  565. {
  566. echo '<h2>'.display_step_sequence().get_lang('Licence').'</h2>';
  567. echo '<p>'.get_lang('DokeosLicenseInfo').'</p>';
  568. echo '<p><a href="../license/gpl_print.txt">'.get_lang('PrintVers').'</a></p>';
  569. ?>
  570. <table><tr><td>
  571. <p><textarea cols="75" rows="15" wrap="virtual"><?php include('../license/gpl.txt'); ?></textarea></p>
  572. </td>
  573. </tr>
  574. <tr>
  575. <td>
  576. <table width="100%">
  577. <tr>
  578. <td></td>
  579. <td align="center">
  580. <input type="submit" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" />
  581. <input type="submit" name="step3" value="<?php echo get_lang('IAccept'); ?> &gt;" />
  582. </td>
  583. </tr>
  584. </table>
  585. </td></tr></table>
  586. <?php
  587. }
  588. /**
  589. * Displays a parameter in a table row.
  590. * Used by the display_database_settings_form function.
  591. */
  592. function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = 'true')
  593. {
  594. echo "<tr>\n";
  595. echo "<td>$parameter_name&nbsp;&nbsp;</td>\n";
  596. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update)
  597. {
  598. echo '<td><input type="hidden" name="'.$form_field_name.'" value="'.htmlentities($parameter_value).'" />'.$parameter_value."</td>\n";
  599. }
  600. else
  601. {
  602. echo '<td><input type="text" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.MAX_FORM_FIELD_LENGTH.'" name="'.$form_field_name.'" value="'.htmlentities($parameter_value).'" />'."</td>\n";
  603. echo "<td>$extra_notice</td>\n";
  604. }
  605. echo "</tr>\n";
  606. }
  607. /**
  608. * Displays step 3 - a form where the user can enter the installation settings
  609. * regarding the databases - login and password, names, prefixes, single
  610. * or multiple databases, tracking or not...
  611. */
  612. function display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm)
  613. {
  614. if($installType == 'update')
  615. {
  616. $dbHostForm=get_config_param('dbHost');
  617. $dbUsernameForm=get_config_param('dbLogin');
  618. $dbPassForm=get_config_param('dbPass');
  619. $dbPrefixForm=get_config_param('dbNamePrefix');
  620. $enableTrackingForm=get_config_param('is_trackingEnabled');
  621. $singleDbForm=get_config_param('singleDbEnabled');
  622. $dbNameForm=get_config_param('mainDbName');
  623. $dbStatsForm=get_config_param('statsDbName');
  624. $dbScormForm=get_config_param('scormDbName');
  625. $dbScormExists=true;
  626. if(empty($dbScormForm))
  627. {
  628. if($singleDbForm)
  629. {
  630. $dbScormForm=$dbNameForm;
  631. }
  632. else
  633. {
  634. $dbScormForm=$dbPrefixForm.'scorm';
  635. $dbScormExists=false;
  636. }
  637. }
  638. if($singleDbForm)
  639. {
  640. $dbUserForm=$dbNameForm;
  641. }
  642. else
  643. {
  644. $dbUserForm=$dbPrefixForm.'dokeos_user';
  645. }
  646. echo "<h2>" . display_step_sequence() .get_lang("DBSetting") . "</h2>";
  647. echo get_lang("DBSettingUpgradeIntro");
  648. }else{
  649. echo "<h2>" . display_step_sequence() .get_lang("DBSetting") . "</h2>";
  650. echo get_lang("DBSettingIntro");
  651. }
  652. ?>
  653. <br /><br />
  654. </td>
  655. </tr>
  656. <tr>
  657. <td>
  658. <table width="100%">
  659. <tr>
  660. <td width="40%"><?php echo get_lang('DBHost'); ?> </td>
  661. <?php if($installType == 'update'): ?>
  662. <td width="30%"><input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?></td>
  663. <td width="30%">&nbsp;</td>
  664. <?php else: ?>
  665. <td width="30%"><input type="text" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /></td>
  666. <td width="30%"><?php echo get_lang('EG').' localhost'; ?></td>
  667. <?php endif; ?>
  668. </tr>
  669. <?php
  670. //database user username
  671. $example_login = get_lang('EG').' root';
  672. display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
  673. //database user password
  674. $example_password = get_lang('EG').' '.api_generate_password();
  675. display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password);
  676. //database prefix
  677. display_database_parameter($installType, get_lang('DbPrefixForm'), 'dbPrefixForm', $dbPrefixForm, get_lang('DbPrefixCom'));
  678. //fields for the four standard Dokeos databases
  679. display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;');
  680. display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, '&nbsp;');
  681. display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;');
  682. display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;');
  683. ?>
  684. <tr>
  685. <td><?php echo get_lang('EnableTracking'); ?> </td>
  686. <?php if($installType == 'update'): ?>
  687. <td><input type="hidden" name="enableTrackingForm" value="<?php echo $enableTrackingForm; ?>" /><?php echo $enableTrackingForm? get_lang('Yes') : get_lang('No'); ?></td>
  688. <?php else: ?>
  689. <td>
  690. <input class="checkbox" type="radio" name="enableTrackingForm" value="1" id="enableTracking1" <?php echo $enableTrackingForm?'checked="checked" ':''; ?>/> <label for="enableTracking1"><?php echo get_lang('Yes'); ?></label>
  691. <input class="checkbox" type="radio" name="enableTrackingForm" value="0" id="enableTracking0" <?php echo $enableTrackingForm?'':'checked="checked" '; ?>/> <label for="enableTracking0"><?php echo get_lang('No'); ?></label>
  692. </td>
  693. <?php endif; ?>
  694. <td>&nbsp;</td>
  695. </tr>
  696. <tr>
  697. <td><?php echo get_lang('SingleDb'); ?> </td>
  698. <?php if($installType == 'update'): ?>
  699. <td><input type="hidden" name="singleDbForm" value="<?php echo $singleDbForm; ?>" /><?php echo $singleDbForm? get_lang('One') : get_lang('Several'); ?></td>
  700. <?php else: ?>
  701. <td>
  702. <input class="checkbox" type="radio" name="singleDbForm" value="1" id="singleDb1" <?php echo $singleDbForm?'checked="checked" ':''; ?>/> <label for="singleDb1"><?php echo get_lang('One'); ?></label>
  703. <input class="checkbox" type="radio" name="singleDbForm" value="0" id="singleDb0" <?php echo $singleDbForm?'':'checked="checked" '; ?>/> <label for="singleDb0"><?php echo get_lang('Several'); ?></label>
  704. </td>
  705. <?php endif; ?>
  706. <td>&nbsp;</td>
  707. </tr>
  708. <tr>
  709. <td><input type="submit" name="step3" value="<?php echo get_lang('CheckDatabaseConnection'); ?>" /> </td>
  710. <?php if (mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm) !== false): ?>
  711. <td colspan="2">
  712. <div class="confirmation-message">
  713. <div style="float:left; margin-right:10px;">
  714. <img src="../img/message_confirmation.png" alt="Confirmation" />
  715. </div>
  716. <div style="float:left;">
  717. MySQL host info: <?php echo mysql_get_host_info(); ?><br />
  718. MySQL server version: <?php echo mysql_get_server_info(); ?><br />
  719. MySQL protocol version: <?php echo mysql_get_proto_info(); ?>
  720. </div>
  721. <div style="clear:both;"
  722. </div>
  723. </td>
  724. <?php else: ?>
  725. <td colspan="2">
  726. <div class="error-message">
  727. <div style="float:left; margin-right:10px;">
  728. <img src="../img/message_error.png" alt="Error" />
  729. </div>
  730. <div style="float:left;">
  731. <strong>MySQL error: <?php echo mysql_errno(); ?></strong><br />
  732. <?php echo mysql_error(); ?>
  733. </div>
  734. </div>
  735. </td>
  736. <?php endif; ?>
  737. </tr>
  738. <tr>
  739. <td><input type="submit" name="step2" value="&lt; <?php echo get_lang('Previous'); ?>" /></td>
  740. <td>&nbsp;</td>
  741. <td align="right"><input type="submit" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" /></td>
  742. </tr>
  743. </table>
  744. <?php
  745. }
  746. /**
  747. * Displays a parameter in a table row.
  748. * Used by the display_configuration_settings_form function.
  749. */
  750. function display_configuration_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $display_when_update = 'true')
  751. {
  752. echo "<tr>\n";
  753. echo "<td>$parameter_name&nbsp;&nbsp;</td>\n";
  754. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update)
  755. {
  756. echo '<td><input type="hidden" name="'.$form_field_name.'" value="'.htmlentities($parameter_value).'" />'.$parameter_value."</td>\n";
  757. }
  758. else
  759. {
  760. echo '<td><input type="text" size="'.FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.MAX_FORM_FIELD_LENGTH.'" name="'.$form_field_name.'" value="'.htmlentities($parameter_value).'" />'."</td>\n";
  761. }
  762. echo "</tr>\n";
  763. }
  764. /**
  765. * Displays step 4 of the installation - configuration settings about Dokeos itself.
  766. */
  767. function display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm)
  768. {
  769. if($installType != 'update')
  770. {
  771. $languageForm = $_SESSION['install_language'];
  772. }
  773. echo "<h2>" . display_step_sequence() . get_lang("CfgSetting") . "</h2>";
  774. echo '<p>'.get_lang('ConfigSettingsInfo').' <b>main/inc/conf/configuration.php</b></p>';
  775. echo "</td></tr>\n<tr><td>";
  776. echo "<table width=\"100%\">";
  777. //First parameter: language
  778. echo "<tr>\n";
  779. echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>\n";
  780. if($installType == 'update')
  781. {
  782. echo '<td><input type="hidden" name="languageForm" value="'.htmlentities($languageForm).'" />'.$languageForm."</td>\n";
  783. }
  784. else // new installation
  785. {
  786. echo '<td>';
  787. echo "<select name=\"languageForm\">\n";
  788. $dirname='../lang/';
  789. if($dir=@opendir($dirname))
  790. {
  791. while($file=readdir($dir))
  792. {
  793. if($file != '.' && $file != '..' && $file != 'CVS' && $file != '.svn' && is_dir($dirname.$file))
  794. {
  795. echo '<option value="'.$file.'"';
  796. if($file == $languageForm) echo ' selected="selected"';
  797. echo ">$file</option>\n";
  798. }
  799. }
  800. closedir($dir);
  801. }
  802. echo '</select>';
  803. echo "</td>\n";
  804. }
  805. echo "</tr>\n";
  806. //Second parameter: Dokeos URL
  807. echo "<tr>\n";
  808. echo '<td>'.get_lang('DokeosURL').' (<font color="#cc0033">'.get_lang('ThisFieldIsRequired')."</font>)&nbsp;&nbsp;</td>\n";
  809. echo '<td><input type="text" size="40" maxlength="100" name="urlForm" value="'.htmlentities($urlForm).'" />'."</td>\n";
  810. echo "</tr>\n";
  811. //Parameter 3: administrator's email
  812. display_configuration_parameter($installType, get_lang("AdminEmail"), "emailForm", $emailForm);
  813. //Parameter 4: administrator's last name
  814. display_configuration_parameter($installType, get_lang("AdminLastName"), "adminLastName", $adminLastName);
  815. //Parameter 5: administrator's first name
  816. display_configuration_parameter($installType, get_lang("AdminFirstName"), "adminFirstName", $adminFirstName);
  817. //Parameter 6: administrator's telephone
  818. display_configuration_parameter($installType, get_lang("AdminPhone"), "adminPhoneForm", $adminPhoneForm);
  819. //Parameter 7: administrator's login
  820. display_configuration_parameter($installType, get_lang("AdminLogin"), "loginForm", $loginForm, false);
  821. //Parameter 8: administrator's password
  822. display_configuration_parameter($installType, get_lang("AdminPass"), "passForm", $passForm, false);
  823. //Parameter 9: campus name
  824. display_configuration_parameter($installType, get_lang("CampusName"), "campusForm", $campusForm);
  825. //Parameter 10: institute (short) name
  826. display_configuration_parameter($installType, get_lang("InstituteShortName"), "institutionForm", $institutionForm);
  827. //Parameter 11: institute (short) name
  828. display_configuration_parameter($installType, get_lang("InstituteURL"), "institutionUrlForm", $institutionUrlForm);
  829. ?>
  830. <tr>
  831. <td><?php echo get_lang("EncryptUserPass"); ?> :</td>
  832. <?php if($installType == 'update'): ?>
  833. <td><input type="hidden" name="encryptPassForm" value="<?php echo $encryptPassForm; ?>" /><?php echo $encryptPassForm? get_lang("Yes") : get_lang("No"); ?></td>
  834. <?php else: ?>
  835. <td>
  836. <input class="checkbox" type="radio" name="encryptPassForm" value="1" id="encryptPass1" <?php echo $encryptPassForm?'checked="checked" ':''; ?>/> <label for="encryptPass1"><?php echo get_lang("Yes"); ?></label>
  837. <input class="checkbox" type="radio" name="encryptPassForm" value="0" id="encryptPass0" <?php echo $encryptPassForm?'':'checked="checked" '; ?>/> <label for="encryptPass0"><?php echo get_lang("No"); ?></label>
  838. </td>
  839. <?php endif; ?>
  840. </tr>
  841. <tr>
  842. <td><?php echo get_lang("AllowSelfReg"); ?> :</td>
  843. <?php if($installType == 'update'): ?>
  844. <td><input type="hidden" name="allowSelfReg" value="<?php echo $allowSelfReg; ?>" /><?php echo $allowSelfReg? get_lang("Yes") : get_lang("No"); ?></td>
  845. <?php else: ?>
  846. <td>
  847. <input class="checkbox" type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" <?php echo $allowSelfReg?'checked="checked" ':''; ?>/> <label for="allowSelfReg1"><?php echo get_lang("Yes").' '.get_lang("Recommended"); ?></label>
  848. <input class="checkbox" type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" <?php echo $allowSelfReg?'':'checked="checked" '; ?>/> <label for="allowSelfReg0"><?php echo get_lang("No"); ?></label>
  849. </td>
  850. <?php endif; ?>
  851. </tr>
  852. <tr>
  853. <td><?php echo get_lang("AllowSelfRegProf"); ?> :</td>
  854. <?php if($installType == 'update'): ?>
  855. <td><input type="hidden" name="allowSelfRegProf" value="<?php echo $allowSelfRegProf; ?>" /><?php echo $allowSelfRegProf? get_lang("Yes") : get_lang("No"); ?></td>
  856. <?php else: ?>
  857. <td>
  858. <input class="checkbox" type="radio" name="allowSelfRegProf" value="1" id="allowSelfRegProf1" <?php echo $allowSelfRegProf?'checked="checked" ':''; ?>/> <label for="allowSelfRegProf1"><?php echo get_lang("Yes"); ?></label>
  859. <input class="checkbox" type="radio" name="allowSelfRegProf" value="0" id="allowSelfRegProf0" <?php echo $allowSelfRegProf?'':'checked="checked" '; ?>/> <label for="allowSelfRegProf0"><?php echo get_lang("No"); ?></label>
  860. </td>
  861. <?php endif; ?>
  862. </tr>
  863. <tr>
  864. <td><input type="submit" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>" /></td>
  865. <td align="right"><input type="submit" name="step5" value="<?php echo get_lang('Next'); ?> &gt;" /></td>
  866. </tr>
  867. </table>
  868. <?php
  869. }
  870. /**
  871. * After installation is completed (step 6), this message is displayed.
  872. */
  873. function display_after_install_message($installType, $nbr_courses)
  874. {
  875. ?>
  876. <h2><?php echo display_step_sequence() . get_lang("CfgSetting"); ?></h2>
  877. <?php echo get_lang('FirstUseTip'); ?>
  878. <?php if($installType == 'update' && $nbr_courses > MAX_COURSE_TRANSFER): ?>
  879. <br><br>
  880. <font color="red"><b><?php echo get_lang('Warning');?> :</b> <?php printf(get_lang('YouHaveMoreThanXCourses'),MAX_COURSE_TRANSFER,MAX_COURSE_TRANSFER,'<a href="update_courses.php"><font color="red">','</font></a>');?></font>
  881. <?php endif; ?>
  882. <br><br>
  883. <b><?php echo get_lang('SecurityAdvice');?> :</b> <?php printf(get_lang('ToProtectYourSiteMakeXAndYReadOnly'),'main/inc/conf/configuration.php','main/install/index.php');?>
  884. <br><br><br><br>
  885. </form>
  886. <a href="../../index.php"><?php echo get_lang('GoToYourNewlyCreatedPortal'); ?></a>
  887. <?php
  888. }
  889. ?>