install_functions.inc.php 37 KB

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