install.lib.php 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Chamilo LMS
  5. * This file contains functions used by the install and upgrade scripts.
  6. *
  7. * Ideas for future additions:
  8. * - a function get_old_version_settings to retrieve the config file settings
  9. * of older versions before upgrading.
  10. */
  11. /* CONSTANTS */
  12. define('SYSTEM_MAIN_DATABASE_FILE', 'db_main.sql');
  13. define('COUNTRY_DATA_FILENAME', 'country_data.csv');
  14. define('COURSES_HTACCESS_FILENAME', 'htaccess.dist');
  15. define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php');
  16. /* COMMON PURPOSE FUNCTIONS */
  17. /**
  18. * This function detects whether the system has been already installed.
  19. * It should be used for prevention from second running the installation
  20. * script and as a result - destroying a production system.
  21. * @return bool The detected result;
  22. * @author Ivan Tcholakov, 2010;
  23. */
  24. function is_already_installed_system() {
  25. global $new_version;
  26. if (empty($new_version)) {
  27. return true; // Must be initialized.
  28. }
  29. $current_config_file = str_replace('\\', '/', realpath('../inc/conf/configuration.php'));
  30. if (!file_exists($current_config_file)) {
  31. return false; // Configuration file does not exist, install the system.
  32. }
  33. require $current_config_file;
  34. $current_version = trim($_configuration['dokeos_version']);
  35. if (empty($current_version)) {
  36. $current_version = trim($_configuration['system_version']);
  37. }
  38. // If the current version is old, upgrading is assumed, the installer goes ahead.
  39. return empty($current_version) ? false : version_compare($current_version, $new_version, '>=');
  40. }
  41. /**
  42. * This function checks if a php extension exists or not and returns an HTML status string.
  43. *
  44. * @param string Name of the PHP extension to be checked
  45. * @param string Text to show when extension is available (defaults to 'Yes')
  46. * @param string Text to show when extension is available (defaults to 'No')
  47. * @param boolean Whether this extension is optional (in this case show unavailable text in orange rather than red)
  48. * @return string HTML string reporting the status of this extension. Language-aware.
  49. * @author Christophe Gesché
  50. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  51. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  52. * @version Dokeos 1.8.1, May 2007
  53. */
  54. function check_extension($extension_name, $return_success = 'Yes', $return_failure = 'No', $optional = false) {
  55. if (extension_loaded($extension_name)) {
  56. return '<strong><font color="green">'.$return_success.'</font></strong>';
  57. } else {
  58. if ($optional) {
  59. return '<strong><font color="#ff9900">'.$return_failure.'</font></strong>';
  60. } else {
  61. return '<strong><font color="red">'.$return_failure.'</font></strong>';
  62. }
  63. }
  64. }
  65. /**
  66. * This function checks whether a php setting matches the recommended value
  67. *
  68. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  69. * @version Dokeos 1.8, august 2006
  70. */
  71. function check_php_setting($php_setting, $recommended_value, $return_success = false, $return_failure = false) {
  72. $current_php_value = get_php_setting($php_setting);
  73. if ($current_php_value == $recommended_value) {
  74. return '<strong><font color="green">'.$current_php_value.' '.$return_success.'</font></strong>';
  75. } else {
  76. return '<strong><font color="red">'.$current_php_value.' '.$return_failure.'</font></strong>';
  77. }
  78. }
  79. /**
  80. * Returns a textual value ('ON' or 'OFF') based on a requester 2-state ini- configuration setting.
  81. *
  82. * @param string $val a php ini value
  83. * @return boolean: ON or OFF
  84. * @author Joomla <http://www.joomla.org>
  85. */
  86. function get_php_setting($val) {
  87. return ini_get($val) == '1' ? 'ON' : 'OFF';
  88. }
  89. /**
  90. * This function returns a string "true" or "false" according to the passed parameter.
  91. *
  92. * @param integer $var The variable to present as text
  93. * @return string the string "true" or "false"
  94. * @author Christophe Gesché
  95. */
  96. function true_false($var) {
  97. return $var ? 'true' : 'false';
  98. }
  99. /**
  100. * Removes memory and time limits as much as possible.
  101. */
  102. function remove_memory_and_time_limits() {
  103. if (function_exists('ini_set')) {
  104. ini_set('memory_limit', -1);
  105. ini_set('max_execution_time', 0);
  106. } else {
  107. error_log('Update-db script: could not change memory and time limits', 0);
  108. }
  109. }
  110. /**
  111. * Detects browser's language.
  112. * @return string Returns a language identificator, i.e. 'english', 'spanish', ...
  113. * @author Ivan Tcholakov, 2010
  114. */
  115. function detect_browser_language() {
  116. static $language_index = array(
  117. 'ar' => 'arabic',
  118. 'ast' => 'asturian',
  119. 'bg' => 'bulgarian',
  120. 'bs' => 'bosnian',
  121. 'ca' => 'catalan',
  122. 'zh' => 'simpl_chinese',
  123. 'zh-tw' => 'trad_chinese',
  124. 'cs' => 'czech',
  125. 'da' => 'danish',
  126. 'prs' => 'dari',
  127. 'de' => 'german',
  128. 'el' => 'greek',
  129. 'en' => 'english',
  130. 'es' => 'spanish',
  131. 'eo' => 'esperanto',
  132. 'eu' => 'euskera',
  133. 'fa' => 'persian',
  134. 'fr' => 'french',
  135. 'fur' => 'friulian',
  136. 'gl' => 'galician',
  137. 'ka' => 'georgian',
  138. 'hr' => 'croatian',
  139. 'he' => 'hebrew',
  140. 'id' => 'indonesian',
  141. 'it' => 'italian',
  142. 'ko' => 'korean',
  143. 'lv' => 'latvian',
  144. 'lt' => 'lithuanian',
  145. 'mk' => 'macedonian',
  146. 'hu' => 'hungarian',
  147. 'ms' => 'malay',
  148. 'nl' => 'dutch',
  149. 'ja' => 'japanese',
  150. 'no' => 'norwegian',
  151. 'oc' => 'occitan',
  152. 'ps' => 'pashto',
  153. 'pl' => 'polish',
  154. 'pt' => 'portuguese',
  155. 'pt-br' => 'brazilian',
  156. 'ro' => 'romanian',
  157. 'qu' => 'quechua_cusco',
  158. 'ru' => 'russian',
  159. 'sk' => 'slovak',
  160. 'sl' => 'slovenian',
  161. 'sr' => 'serbian',
  162. 'fi' => 'finnish',
  163. 'sv' => 'swedish',
  164. 'th' => 'thai',
  165. 'tr' => 'turkce',
  166. 'uk' => 'ukrainian',
  167. 'vi' => 'vietnamese',
  168. 'sw' => 'swahili',
  169. 'yo' => 'yoruba'
  170. );
  171. $system_available_languages = & get_language_folder_list();
  172. $accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
  173. foreach ($language_index as $code => $language) {
  174. if (strpos($accept_languages, $code) === 0) {
  175. if (!empty($system_available_languages[$language])) {
  176. return $language;
  177. }
  178. }
  179. }
  180. $user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT']));
  181. foreach ($language_index as $code => $language) {
  182. if (preg_match("/[[( ]{$code}[;,_-)]/", $user_agent)) {
  183. if (!empty($system_available_languages[$language])) {
  184. return $language;
  185. }
  186. }
  187. }
  188. return 'english';
  189. }
  190. /* FILESYSTEM RELATED FUNCTIONS */
  191. /**
  192. * This function checks if the given folder is writable
  193. */
  194. function check_writable($folder, $suggestion = false) {
  195. if (is_writable('../'.$folder)) {
  196. return '<strong><font color="green">'.get_lang('Writable').'</font></strong>';
  197. } else {
  198. if ($suggestion) {
  199. return '<strong><font color="#ff9900">'.get_lang('NotWritable').'</font></strong>';
  200. } else {
  201. return '<strong><font color="red">'.get_lang('NotWritable').'</font></strong>';
  202. }
  203. }
  204. }
  205. /**
  206. * This function is similar to the core file() function, except that it
  207. * works with line endings in Windows (which is not the case of file())
  208. * @param string File path
  209. * @return array The lines of the file returned as an array
  210. */
  211. function file_to_array($filename) {
  212. $fp = fopen($filename, 'rb');
  213. $buffer = fread($fp, filesize($filename));
  214. fclose($fp);
  215. return explode('<br />', nl2br($buffer));
  216. }
  217. /**
  218. * We assume this function is called from install scripts that reside inside the install folder.
  219. */
  220. function set_file_folder_permissions() {
  221. @chmod('.', 0755); //set permissions on install dir
  222. @chmod('..', 0755); //set permissions on parent dir of install dir
  223. @chmod('country_data.csv.csv', 0755);
  224. }
  225. /**
  226. * Add's a .htaccess file to the courses directory
  227. * @param string $url_append The path from your webroot to your chamilo root
  228. */
  229. function write_courses_htaccess_file($url_append) {
  230. $file_path = dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME;
  231. $content = file_get_contents($file_path);
  232. $content = str_replace('{CHAMILO_URL_APPEND_PATH}', $url_append, $content);
  233. $fp = @ fopen('../../courses/.htaccess', 'w');
  234. if ($fp) {
  235. fwrite($fp, $content);
  236. return fclose($fp);
  237. }
  238. return false;
  239. }
  240. /**
  241. * Write the main system config file
  242. * @param string $path Path to the config file
  243. */
  244. function write_system_config_file($path) {
  245. global $dbHostForm;
  246. global $dbUsernameForm;
  247. global $dbPassForm;
  248. global $enableTrackingForm;
  249. global $singleDbForm;
  250. global $dbPrefixForm;
  251. global $dbNameForm;
  252. global $dbStatsForm;
  253. global $dbScormForm;
  254. global $dbUserForm;
  255. global $urlForm;
  256. global $pathForm;
  257. global $urlAppendPath;
  258. global $languageForm;
  259. global $encryptPassForm;
  260. global $installType;
  261. global $updatePath;
  262. global $session_lifetime;
  263. global $new_version;
  264. global $new_version_stable;
  265. $root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm)));
  266. $content = file_get_contents(dirname(__FILE__).'/'.SYSTEM_CONFIG_FILENAME);
  267. $config['{DATE_GENERATED}'] = date('r');
  268. $config['{DATABASE_HOST}'] = $dbHostForm;
  269. $config['{DATABASE_USER}'] = $dbUsernameForm;
  270. $config['{DATABASE_PASSWORD}'] = $dbPassForm;
  271. $config['TRACKING_ENABLED'] = true_false($enableTrackingForm);
  272. $config['SINGLE_DATABASE'] = true_false($singleDbForm);
  273. $config['{COURSE_TABLE_PREFIX}'] = ($singleDbForm ? 'crs_' : '');
  274. $config['{DATABASE_GLUE}'] = ($singleDbForm ? '_' : '`.`');
  275. $config['{DATABASE_PREFIX}'] = $dbPrefixForm;
  276. $config['{DATABASE_MAIN}'] = $dbNameForm;
  277. $config['{DATABASE_STATS}'] = (($singleDbForm && empty($dbStatsForm)) ? $dbNameForm : $dbStatsForm);
  278. $config['{DATABASE_SCORM}'] = (($singleDbForm && empty($dbScormForm)) ? $dbNameForm : $dbScormForm);
  279. $config['{DATABASE_PERSONAL}'] =(($singleDbForm && empty($dbUserForm)) ? $dbNameForm : $dbUserForm);
  280. $config['{ROOT_WEB}'] = $urlForm;
  281. $config['{ROOT_SYS}'] = $root_sys;
  282. $config['{URL_APPEND_PATH}'] = $urlAppendPath;
  283. $config['{PLATFORM_LANGUAGE}'] = $languageForm;
  284. $config['{SECURITY_KEY}'] = md5(uniqid(rand().time()));
  285. $config['{ENCRYPT_PASSWORD}'] = $encryptPassForm;
  286. $config['SESSION_LIFETIME'] = $session_lifetime;
  287. $config['{NEW_VERSION}'] = $new_version;
  288. $config['NEW_VERSION_STABLE'] = true_false($new_version_stable);
  289. foreach ($config as $key => $value) {
  290. $content = str_replace($key, $value, $content);
  291. }
  292. $fp = @ fopen($path, 'w');
  293. if (!$fp) {
  294. echo '<strong><font color="red">Your script doesn\'t have write access to the config directory</font></strong><br />
  295. <em>('.str_replace('\\', '/', realpath($path)).')</em><br /><br />
  296. You probably do not have write access on Chamilo root directory,
  297. i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br />
  298. Your problems can be related on two possible causes:<br />
  299. <ul>
  300. <li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li>
  301. <li>PHP is running in <a href="http://www.php.net/manual/en/features.safe-mode.php" target="_blank">Safe-Mode</a>. If possible, try to switch it off.</li>
  302. </ul>
  303. <a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br />
  304. Please go back to step 5.
  305. <p><input type="submit" name="step5" value="&lt; Back" /></p>
  306. </td></tr></table></form></body></html>';
  307. exit ();
  308. }
  309. fwrite($fp, $content);
  310. fclose($fp);
  311. }
  312. /**
  313. * Returns a list of language directories.
  314. */
  315. function & get_language_folder_list() {
  316. static $result;
  317. if (!is_array($result)) {
  318. $result = array();
  319. $exceptions = array('.', '..', 'CVS', '.svn');
  320. $search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_');
  321. $replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
  322. $dirname = api_get_path(SYS_LANG_PATH);
  323. $handle = opendir($dirname);
  324. while ($entries = readdir($handle)) {
  325. if (in_array($entries, $exceptions)) {
  326. continue;
  327. }
  328. if (is_dir($dirname.$entries)) {
  329. $result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
  330. }
  331. }
  332. closedir($handle);
  333. asort($result);
  334. }
  335. return $result;
  336. }
  337. /**
  338. * TODO: my_directory_to_array() - maybe within the main API there is already a suitable function?
  339. */
  340. function my_directory_to_array($directory) {
  341. $array_items = array();
  342. if ($handle = opendir($directory)) {
  343. while (false !== ($file = readdir($handle))) {
  344. if ($file != "." && $file != "..") {
  345. if (is_dir($directory. "/" . $file)) {
  346. $array_items = array_merge($array_items, my_directory_to_array($directory. '/' . $file));
  347. $file = $directory . "/" . $file;
  348. $array_items[] = preg_replace("/\/\//si", '/', $file);
  349. }
  350. }
  351. }
  352. closedir($handle);
  353. }
  354. return $array_items;
  355. }
  356. /**
  357. * This function returns the value of a parameter from the configuration file
  358. *
  359. * WARNING - this function relies heavily on global variables $updateFromConfigFile
  360. * and $configFile, and also changes these globals. This can be rewritten.
  361. *
  362. * @param string $param the parameter of which the value is returned
  363. * @param string If we want to give the path rather than take it from POST
  364. * @return string the value of the parameter
  365. * @author Olivier Brouckaert
  366. * @author Reworked by Ivan Tcholakov, 2010
  367. */
  368. function get_config_param($param, $updatePath = '') {
  369. global $configFile, $updateFromConfigFile;
  370. // Look if we already have the queried parameter.
  371. if (is_array($configFile) && isset($configFile[$param])) {
  372. return $configFile[$param];
  373. }
  374. if (empty($updatePath) && !empty($_POST['updatePath'])) {
  375. $updatePath = $_POST['updatePath'];
  376. }
  377. $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath)));
  378. $updateFromInstalledVersionFile = '';
  379. if (empty($updateFromConfigFile)) {
  380. // If update from previous install was requested,
  381. // try to recover old config file from dokeos 1.8.x.
  382. if (file_exists($updatePath.'main/inc/conf/configuration.php')) {
  383. $updateFromConfigFile = 'main/inc/conf/configuration.php';
  384. } elseif (file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php')) {
  385. $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php';
  386. } else {
  387. // Give up recovering.
  388. error_log('Could not find config file in '.$updatePath.' in get_config_param()', 0);
  389. return null;
  390. }
  391. }
  392. if (file_exists($updatePath.$updateFromConfigFile)) {
  393. // The parameter was not found among the global variables, so look into the old configuration file.
  394. // Make sure the installedVersion file is read first so it is overwritten
  395. // by the config file if the config file contains the version (from 1.8.4).
  396. $config_data_2 = array();
  397. if (file_exists($updatePath.$updateFromInstalledVersionFile)) {
  398. $config_data_2 = file_to_array($updatePath.$updateFromInstalledVersionFile);
  399. }
  400. $configFile = array();
  401. $config_data = file_to_array($updatePath.$updateFromConfigFile);
  402. $config_data = array_merge($config_data, $config_data_2);
  403. $val = '';
  404. // Parse the configuration file, statement by statement (line by line, actually).
  405. foreach ($config_data as $php_statement) {
  406. if (strpos($php_statement, '=') !== false) {
  407. // Variable assignment statement have been detected (probably).
  408. // It is expected to be as follows:
  409. // $variable = 'some_value'; // A comment that is not mandatory.
  410. // Split the statement into its left and right sides.
  411. $php_statement = explode('=', $php_statement);
  412. $variable = trim($php_statement[0]);
  413. $value = $php_statement[1];
  414. if (substr($variable, 0, 1) == '$') {
  415. // We have for sure a php variable assignment detected.
  416. // On the left side: Retrieve the pure variable's name
  417. $variable = trim(str_replace('$', '', $variable));
  418. // On the right side: Remove the comment, if it exists.
  419. list($value) = explode(' //', $value);
  420. // Remove extra whitespace, if any. Remove the trailing semicolon (;).
  421. $value = substr(trim($value), 0, -1);
  422. // Remove surroundig quotes, restore escaped quotes.
  423. $value = str_replace('\"', '"', preg_replace('/^"|"$/', '', $value));
  424. $value = str_replace('\'', '"', preg_replace('/^\'|\'$/', '', $value));
  425. if (strtolower($value) == 'true') {
  426. // A boolean true value have been recognized.
  427. $value = 1;
  428. } elseif (strtolower($value) == 'false') {
  429. // A boolean false value have been recognized.
  430. $value = 0;
  431. } else {
  432. // Probably we have a string value, but also we have to check
  433. // possible string concatenations that may include string values
  434. // and other configuration variables. I this case we have to
  435. // get the calculated result of the concatenation.
  436. $implode_string = ' ';
  437. if (!strstr($value, '." ".') && strstr($value, '.$')) {
  438. // Yes, there is concatenation, insert a special separator string.
  439. $value = str_replace('.$', '." ".$', $value);
  440. $implode_string = '';
  441. }
  442. // Split the concatenated values, if they are more than one.
  443. $sub_strings = explode('." ".', $value);
  444. // Seek for variables and retrieve their values.
  445. foreach ($sub_strings as $key => & $sub_string) {
  446. if (preg_match('/^\$[a-zA-Z_][a-zA-Z0-9_]*$/', $sub_string)) {
  447. // A variable has been detected, read it by recursive call.
  448. $sub_string = get_config_param(str_replace('$', '', $sub_string));
  449. }
  450. }
  451. // Concatenate everything into the final, the calculated string value.
  452. $value = implode($implode_string, $sub_strings);
  453. }
  454. // Cache the result value.
  455. $configFile[$variable] = $value;
  456. $a = explode("'", $variable);
  457. $key_tmp = $a[1];
  458. if ($key_tmp == $param) {
  459. $val = $value;
  460. }
  461. }
  462. }
  463. }
  464. }
  465. //Special treatment for dokeos_version parameter due to Dokeos 1.8.3 have the dokeos_version in the main/inc/installedVersion.inc.php file
  466. if ($param == 'dokeos_version') {
  467. //dokeos_version from configuration.php if empty
  468. $dokeos_version = $val;
  469. if (empty($dokeos_version)) {
  470. //checking the dokeos_version value exists in main/inc/installedVersion.inc.php
  471. if (file_exists($updatePath.'main/inc/installedVersion.inc.php')) {
  472. $updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php';
  473. require ($updateFromInstalledVersionFile); //there are only 2 variables here: $stable & $dokeos_version
  474. $stable = false;
  475. }
  476. }
  477. return $dokeos_version;
  478. } else {
  479. if (file_exists($updatePath.$updateFromConfigFile)) {
  480. return $val;
  481. } else {
  482. error_log('Config array could not be found in get_config_param()', 0);
  483. return null;
  484. }
  485. }
  486. }
  487. /* DATABASE RELATED FUNCTIONS */
  488. /**
  489. * Gets a configuration parameter from the database. Returns returns null on failure.
  490. * @param string DB Host
  491. * @param string DB login
  492. * @param string DB pass
  493. * @param string DB name
  494. * @param string Name of param we want
  495. * @return mixed The parameter value or null if not found
  496. */
  497. function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
  498. Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
  499. Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  500. Database::select_db($db_name);
  501. if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
  502. if (Database::num_rows($res) > 0) {
  503. $row = Database::fetch_array($res);
  504. return $row['selected_value'];
  505. }
  506. }
  507. return null;
  508. }
  509. /**
  510. * Connects to the database server.
  511. */
  512. function database_server_connect() {
  513. global $dbHostForm, $dbUsernameForm, $dbPassForm;
  514. if (($res = @Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm))) === false) {
  515. $no = Database::errno();
  516. $msg = Database::error();
  517. echo '<hr />#'.$no.': '.$msg.'<hr />';
  518. echo get_lang('DBServerDoesntWorkOrLoginPassIsWrong').'.<br /><br />'.
  519. get_lang('PleaseCheckTheseValues').' :<br /><br />'.
  520. '<strong>'.get_lang('DBHost').'</strong> : '.$dbHostForm.'<br />'.
  521. '<strong>'.get_lang('DBLogin').'</strong> : '.$dbUsernameForm.'<br />'.
  522. '<strong>'.get_lang('DBPassword').'</strong> : '.$dbPassForm.'<br /><br />'.
  523. get_lang('PleaseGoBackToStep').' '. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'.'.
  524. '<p><button type="submit" class="back" name="step'. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>'.
  525. '</td></tr></table></form></body></html>';
  526. exit ();
  527. }
  528. @Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  529. }
  530. /**
  531. * In step 3. Tests establishing connection to the database server. Tests also the possibility for multiple databases configuration.
  532. * @return int 1 when there is no problem;
  533. * 0 when a new database is impossible to be created, then the multiple databases configuration is impossible too;
  534. * -1 when there is no connection established.
  535. */
  536. function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm) {
  537. $dbConnect = -1;
  538. if ($singleDbForm == 1) {
  539. if (@Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)) !== false) {
  540. $dbConnect = 1;
  541. } else {
  542. $dbConnect = -1;
  543. }
  544. } elseif ($singleDbForm == 0) {
  545. if (@Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)) !== false) {
  546. @Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  547. $multipleDbCheck = @Database::query("CREATE DATABASE ".$dbPrefixForm."test_chamilo_connection");
  548. if ($multipleDbCheck !== false) {
  549. $multipleDbCheck = @Database::query("DROP DATABASE IF EXISTS ".$dbPrefixForm."test_chamilo_connection");
  550. if ($multipleDbCheck !== false) {
  551. $dbConnect = 1;
  552. } else {
  553. $dbConnect = 0;
  554. }
  555. } else {
  556. $dbConnect = 0;
  557. }
  558. } else {
  559. $dbConnect = -1;
  560. }
  561. }
  562. 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.
  563. }
  564. /**
  565. * Fills the countries table with a list of countries.
  566. */
  567. function fill_track_countries_table($track_countries_table) {
  568. $file_path = dirname(__FILE__).'/'.COUNTRY_DATA_FILENAME;
  569. $add_country_sql = "LOAD DATA INFILE '".Database::escape_string($file_path)."' INTO TABLE $track_countries_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'';";
  570. @ Database::query($add_country_sql);
  571. }
  572. /**
  573. * Creates the structure of the main database and fills it
  574. * with data. Placeholder symbols in the main database file
  575. * have to be replaced by the settings entered by the user during installation.
  576. *
  577. * @param array $installation_settings list of settings entered by the user
  578. * @param string optional path about the script for database
  579. * @return void
  580. */
  581. function load_main_database($installation_settings, $db_script = '') {
  582. if (!empty($db_script)) {
  583. $sql_text = file_get_contents($db_script);
  584. } else {
  585. $sql_text = file_get_contents(SYSTEM_MAIN_DATABASE_FILE);
  586. }
  587. //replace symbolic parameters with user-specified values
  588. foreach ($installation_settings as $key => $value) {
  589. $sql_text = str_replace($key, Database::escape_string($value), $sql_text);
  590. }
  591. //split in array of sql strings
  592. $sql_instructions = array();
  593. $success = split_sql_file($sql_instructions, $sql_text);
  594. //execute the sql instructions
  595. $count = count($sql_instructions);
  596. for ($i = 0; $i < $count; $i++) {
  597. $this_sql_query = $sql_instructions[$i]['query'];
  598. Database::query($this_sql_query);
  599. }
  600. }
  601. /**
  602. * Creates the structure of the stats database
  603. * @param string Name of the file containing the SQL script inside the install directory
  604. */
  605. function load_database_script($db_script) {
  606. $sql_text = file_get_contents($db_script);
  607. //split in array of sql strings
  608. $sql_instructions = array();
  609. $success = split_sql_file($sql_instructions, $sql_text);
  610. //execute the sql instructions
  611. $count = count($sql_instructions);
  612. for ($i = 0; $i < $count; $i++) {
  613. $this_sql_query = $sql_instructions[$i]['query'];
  614. Database::query($this_sql_query);
  615. }
  616. }
  617. /**
  618. * Function copied and adapted from phpMyAdmin 2.6.0 PMA_splitSqlFile (also GNU GPL)
  619. * Removes comment lines and splits up large sql files into individual queries
  620. * Last revision: September 23, 2001 - gandon
  621. * @param array the splitted sql commands
  622. * @param string the sql commands
  623. * @param integer the MySQL release number (because certains php3 versions
  624. * can't get the value of a constant from within a function)
  625. * @return boolean always true
  626. */
  627. function split_sql_file(&$ret, $sql) {
  628. // do not trim, see bug #1030644
  629. //$sql = trim($sql);
  630. $sql = rtrim($sql, "\n\r");
  631. $sql_len = strlen($sql);
  632. $char = '';
  633. $string_start = '';
  634. $in_string = false;
  635. $nothing = true;
  636. $time0 = time();
  637. for ($i = 0; $i < $sql_len; ++$i) {
  638. $char = $sql[$i];
  639. // We are in a string, check for not escaped end of strings except for
  640. // backquotes that can't be escaped
  641. if ($in_string) {
  642. for (;;) {
  643. $i = strpos($sql, $string_start, $i);
  644. // No end of string found -> add the current substring to the
  645. // returned array
  646. if (!$i) {
  647. $ret[] = $sql;
  648. return true;
  649. }
  650. // Backquotes or no backslashes before quotes: it's indeed the
  651. // end of the string -> exit the loop
  652. elseif ($string_start == '`' || $sql[$i - 1] != '\\') {
  653. $string_start = '';
  654. $in_string = false;
  655. break;
  656. }
  657. // one or more Backslashes before the presumed end of string...
  658. else {
  659. // ... first checks for escaped backslashes
  660. $j = 2;
  661. $escaped_backslash = false;
  662. while ($i - $j > 0 && $sql[$i - $j] == '\\') {
  663. $escaped_backslash = !$escaped_backslash;
  664. $j++;
  665. }
  666. // ... if escaped backslashes: it's really the end of the
  667. // string -> exit the loop
  668. if ($escaped_backslash) {
  669. $string_start = '';
  670. $in_string = false;
  671. break;
  672. }
  673. // ... else loop
  674. else {
  675. $i++;
  676. }
  677. } // end if...elseif...else
  678. } // end for
  679. } // end if (in string)
  680. // lets skip comments (/*, -- and #)
  681. elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
  682. $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
  683. // didn't we hit end of string?
  684. if ($i === false) {
  685. break;
  686. }
  687. if ($char == '/') $i++;
  688. }
  689. // We are not in a string, first check for delimiter...
  690. elseif ($char == ';') {
  691. // if delimiter found, add the parsed part to the returned array
  692. $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing);
  693. $nothing = true;
  694. $sql = ltrim(substr($sql, min($i + 1, $sql_len)));
  695. $sql_len = strlen($sql);
  696. if ($sql_len) {
  697. $i = -1;
  698. } else {
  699. // The submited statement(s) end(s) here
  700. return true;
  701. }
  702. } // end elseif (is delimiter)
  703. // ... then check for start of a string,...
  704. elseif (($char == '"') || ($char == '\'') || ($char == '`')) {
  705. $in_string = true;
  706. $nothing = false;
  707. $string_start = $char;
  708. } // end elseif (is start of string)
  709. elseif ($nothing) {
  710. $nothing = false;
  711. }
  712. // loic1: send a fake header each 30 sec. to bypass browser timeout
  713. $time1 = time();
  714. if ($time1 >= $time0 + 30) {
  715. $time0 = $time1;
  716. header('X-pmaPing: Pong');
  717. } // end if
  718. } // end for
  719. // add any rest to the returned array
  720. if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) {
  721. $ret[] = array('query' => $sql, 'empty' => $nothing);
  722. }
  723. return true;
  724. } // end of the 'split_sql_file()' function
  725. /**
  726. * Get an SQL file's contents
  727. *
  728. * This function bases its parsing on the pre-set format of the specific SQL files in
  729. * the install/upgrade procedure:
  730. * Lines starting with "--" are comments (but need to be taken into account as they also hold sections names)
  731. * Other lines are considered to be one-line-per-query lines (this is checked quickly by this function)
  732. * @param string File to parse (in the current directory)
  733. * @param string Section to return
  734. * @param boolean Print (true) or hide (false) error texts when they occur
  735. */
  736. function get_sql_file_contents($file, $section, $print_errors = true) {
  737. //check given parameters
  738. if (empty($file)) {
  739. $error = "Missing name of file to parse in get_sql_file_contents()";
  740. if ($print_errors) echo $error;
  741. return false;
  742. }
  743. if (!in_array($section, array('main', 'user', 'stats', 'scorm', 'course'))) {
  744. $error = "Section '$section' is not authorized in get_sql_file_contents()";
  745. if ($print_errors) echo $error;
  746. return false;
  747. }
  748. $filepath = getcwd().'/'.$file;
  749. if (!is_file($filepath) or !is_readable($filepath)) {
  750. $error = "File $filepath not found or not readable in get_sql_file_contents()";
  751. if ($print_errors) echo $error;
  752. return false;
  753. }
  754. //read the file in an array
  755. $file_contents = file($filepath);
  756. if (!is_array($file_contents) or count($file_contents) < 1) {
  757. $error = "File $filepath looks empty in get_sql_file_contents()";
  758. if ($print_errors) echo $error;
  759. return false;
  760. }
  761. //prepare the resulting array
  762. $section_contents = array();
  763. $record = false;
  764. foreach ($file_contents as $index => $line) {
  765. if (substr($line, 0, 2) == '--') {
  766. //This is a comment. Check if section name, otherwise ignore
  767. $result = array();
  768. if (preg_match('/^-- xx([A-Z]*)xx/', $line, $result)) { //we got a section name here
  769. if ($result[1] == strtoupper($section)) {
  770. //we have the section we are looking for, start recording
  771. $record = true;
  772. } else {
  773. //we have another section's header. If we were recording, stop now and exit loop
  774. if ($record) {
  775. break;
  776. }
  777. $record = false;
  778. }
  779. }
  780. } else {
  781. if ($record) {
  782. if (!empty($line)) {
  783. $section_contents[] = $line;
  784. }
  785. }
  786. }
  787. }
  788. //now we have our section's SQL statements group ready, return
  789. return $section_contents;
  790. }
  791. /**
  792. * Adds a new document to the database - specific to version 1.8.0
  793. *
  794. * @param array $_course
  795. * @param string $path
  796. * @param string $filetype
  797. * @param int $filesize
  798. * @param string $title
  799. * @return id if inserted document
  800. */
  801. function add_document_180($_course, $path, $filetype, $filesize, $title, $comment = null) {
  802. $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
  803. $sql = "INSERT INTO $table_document
  804. (`path`,`filetype`,`size`,`title`, `comment`)
  805. VALUES ('$path','$filetype','$filesize','".
  806. Database::escape_string($title)."', '$comment')";
  807. if (Database::query($sql)) {
  808. //display_message("Added to database (id ".Database::insert_id().")!");
  809. return Database::insert_id();
  810. } else {
  811. //display_error("The uploaded file could not be added to the database (".Database::error().")!");
  812. return false;
  813. }
  814. }
  815. /* DISPLAY FUNCTIONS */
  816. /**
  817. * This function prints class=active_step $current_step=$param
  818. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  819. */
  820. function step_active($param) {
  821. global $current_step;
  822. if ($param == $current_step) {
  823. echo 'class="current_step" ';
  824. }
  825. }
  826. /**
  827. * This function displays the Step X of Y -
  828. * @return string String that says 'Step X of Y' with the right values
  829. */
  830. function display_step_sequence() {
  831. global $current_step;
  832. global $total_steps;
  833. return get_lang('Step'.$current_step).' &ndash; ';
  834. }
  835. /**
  836. * Displays a drop down box for selection the preferred language.
  837. */
  838. function display_language_selection_box($name = 'language_list', $default_language = 'english') {
  839. // Reading language list.
  840. $language_list = get_language_folder_list();
  841. /*
  842. // Reduction of the number of languages shown. Enable this fragment of code for customization purposes.
  843. // Modify the language list according to your preference. Don't exclude the 'english' item.
  844. $language_to_display = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'slovenian_unicode', 'spanish');
  845. foreach ($language_list as $key => & $value) {
  846. if (!in_array($key, $language_to_display)) {
  847. unset($language_list[$key]);
  848. }
  849. }
  850. */
  851. // Sanity checks due to the possibility for customizations.
  852. if (!is_array($language_list) || empty($language_list)) {
  853. $language_list = array('english' => 'English');
  854. }
  855. // Sorting again, if it is necessary.
  856. //asort($language_list);
  857. // More sanity checks.
  858. if (!array_key_exists($default_language, $language_list)) {
  859. if (array_key_exists('english', $language_list)) {
  860. $default_language = 'english';
  861. } else {
  862. $language_keys = array_keys($language_list);
  863. $default_language = $language_keys[0];
  864. }
  865. }
  866. // Displaying the box.
  867. echo "\t\t<select name=\"$name\">\n";
  868. foreach ($language_list as $key => $value) {
  869. if ($key == $default_language) {
  870. $option_end = ' selected="selected">';
  871. } else {
  872. $option_end = '>';
  873. }
  874. echo "\t\t\t<option value=\"$key\"$option_end";
  875. echo $value;
  876. echo "</option>\n";
  877. }
  878. echo "\t\t</select>\n";
  879. }
  880. /**
  881. * This function displays a language dropdown box so that the installatioin
  882. * can be done in the language of the user
  883. */
  884. function display_language_selection() { ?>
  885. <h1><?php get_lang('WelcomeToTheDokeosInstaller'); ?></h1>
  886. <h2><?php echo display_step_sequence(); ?><?php echo get_lang('InstallationLanguage'); ?></h2>
  887. <p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
  888. <form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
  889. <?php display_language_selection_box('language_list', api_get_interface_language()); ?>
  890. <button type="submit" name="step1" class="next" value="<?php get_lang('Next'); ?> &gt;"><?php echo get_lang('Next'); ?></button>
  891. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  892. </form>
  893. <?php
  894. }
  895. /**
  896. * This function displays the requirements for installing Chamilo.
  897. *
  898. * @param string $installType
  899. * @param boolean $badUpdatePath
  900. * @param string The updatePath given (if given)
  901. * @param array $update_from_version_8 The different subversions from version 1.8
  902. * @param array $update_from_version_6 The different subversions from version 1.6
  903. *
  904. * @author unknow
  905. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  906. */
  907. function display_requirements($installType, $badUpdatePath, $updatePath = '', $update_from_version_8 = array(), $update_from_version_6 = array()) {
  908. echo '<h2>'.display_step_sequence().get_lang('Requirements')."</h2>\n";
  909. echo '<strong>'.get_lang('ReadThoroughly').'</strong><br />';
  910. echo get_lang('MoreDetails').' <a href="../../documentation/installation_guide.html" target="_blank">'.get_lang('ReadTheInstallGuide').'</a>.<br />'."\n";
  911. // SERVER REQUIREMENTS
  912. echo '<div class="RequirementHeading"><h1>'.get_lang('ServerRequirements').'</h1>';
  913. echo '<div class="RequirementText">'.get_lang('ServerRequirementsInfo').'</div>';
  914. echo '<div class="RequirementContent">';
  915. echo '<table class="requirements">
  916. <tr>
  917. <td class="requirements-item">'.get_lang('PHPVersion').'>= 5.0</td>
  918. <td class="requirements-value">';
  919. if (phpversion() < '5.0') {
  920. echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
  921. } else {
  922. echo '<strong><font color="green">'.get_lang('PHPVersionOK'). ' '.phpversion().'</font></strong>';
  923. }
  924. echo ' </td>
  925. </tr>
  926. <tr>
  927. <td class="requirements-item"><a href="http://php.net/manual/en/book.session.php" target="_blank">Session</a> '.get_lang('support').'</td>
  928. <td class="requirements-value">'.check_extension('session', get_lang('Yes'), get_lang('ExtensionSessionsNotAvailable')).'</td>
  929. </tr>
  930. <tr>
  931. <td class="requirements-item"><a href="http://php.net/manual/en/book.mysql.php" target="_blank">MySQL</a> '.get_lang('support').'</td>
  932. <td class="requirements-value">'.check_extension('mysql', get_lang('Yes'), get_lang('ExtensionMySQLNotAvailable')).'</td>
  933. </tr>
  934. <tr>
  935. <td class="requirements-item"><a href="http://php.net/manual/en/book.zlib.php" target="_blank">Zlib</a> '.get_lang('support').'</td>
  936. <td class="requirements-value">'.check_extension('zlib', get_lang('Yes'), get_lang('ExtensionZlibNotAvailable')).'</td>
  937. </tr>
  938. <tr>
  939. <td class="requirements-item"><a href="http://php.net/manual/en/book.pcre.php" target="_blank">Perl-compatible regular expressions</a> '.get_lang('support').'</td>
  940. <td class="requirements-value">'.check_extension('pcre', get_lang('Yes'), get_lang('ExtensionPCRENotAvailable')).'</td>
  941. </tr>
  942. <tr>
  943. <td class="requirements-item"><a href="http://php.net/manual/en/book.xml.php" target="_blank">XML</a> '.get_lang('support').'</td>
  944. <td class="requirements-value">'.check_extension('xml', get_lang('Yes'), get_lang('No')).'</td>
  945. </tr>
  946. <tr>
  947. <td class="requirements-item"><a href="http://php.net/manual/en/book.mbstring.php" target="_blank">Multibyte string</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  948. <td class="requirements-value">'.check_extension('mbstring', get_lang('Yes'), get_lang('ExtensionMBStringNotAvailable'), true).'</td>
  949. </tr>
  950. <tr>
  951. <td class="requirements-item"><a href="http://php.net/manual/en/book.iconv.php" target="_blank">Iconv</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  952. <td class="requirements-value">'.check_extension('iconv', get_lang('Yes'), get_lang('No'), true).'</td>
  953. </tr>
  954. <tr>
  955. <td class="requirements-item"><a href="http://php.net/manual/en/book.intl.php" target="_blank">Internationalization</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  956. <td class="requirements-value">'.check_extension('intl', get_lang('Yes'), get_lang('No'), true).'</td>
  957. </tr>
  958. <tr>
  959. <td class="requirements-item"><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a> '.get_lang('support').'</td>
  960. <td class="requirements-value">'.check_extension('gd', get_lang('Yes'), get_lang('ExtensionGDNotAvailable')).'</td>
  961. </tr>
  962. <tr>
  963. <td class="requirements-item"><a href="http://php.net/manual/en/book.json.php" target="_blank">JSON</a> '.get_lang('support').'</td>
  964. <td class="requirements-value">'.check_extension('json', get_lang('Yes'), get_lang('No')).'</td>
  965. </tr>
  966. <tr>
  967. <td class="requirements-item"><a href="http://php.net/manual/en/book.ldap.php" target="_blank">LDAP</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  968. <td class="requirements-value">'.check_extension('ldap', get_lang('Yes'), get_lang('ExtensionLDAPNotAvailable'), true).'</td>
  969. </tr>
  970. <tr>
  971. <td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  972. <td class="requirements-value">'.check_extension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
  973. </tr>
  974. </table>';
  975. echo ' </div>';
  976. echo '</div>';
  977. // RECOMMENDED SETTINGS
  978. // Note: these are the settings for Joomla, does this also apply for Chamilo?
  979. // Note: also add upload_max_filesize here so that large uploads are possible
  980. echo '<div class="RequirementHeading"><h1>'.get_lang('RecommendedSettings').'</h1>';
  981. echo '<div class="RequirementText">'.get_lang('RecommendedSettingsInfo').'</div>';
  982. echo '<div class="RequirementContent">';
  983. echo '<table class="requirements">
  984. <tr>
  985. <th>'.get_lang('Setting').'</th>
  986. <th>'.get_lang('Recommended').'</th>
  987. <th>'.get_lang('Actual').'</th>
  988. </tr>
  989. <tr>
  990. <td class="requirements-item"><a href="http://php.net/manual/features.safe-mode.php">Safe Mode</a></td>
  991. <td class="requirements-recommended">OFF</td>
  992. <td class="requirements-value">'.check_php_setting('safe_mode','OFF').'</td>
  993. </tr>
  994. <tr>
  995. <td class="requirements-item"><a href="http://php.net/manual/ref.errorfunc.php#ini.display-errors">Display Errors</a></td>
  996. <td class="requirements-recommended">OFF</td>
  997. <td class="requirements-value">'.check_php_setting('display_errors','OFF').'</td>
  998. </tr>
  999. <tr>
  1000. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.file-uploads">File Uploads</a></td>
  1001. <td class="requirements-recommended">ON</td>
  1002. <td class="requirements-value">'.check_php_setting('file_uploads','ON').'</td>
  1003. </tr>
  1004. <tr>
  1005. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-gpc">Magic Quotes GPC</a></td>
  1006. <td class="requirements-recommended">OFF</td>
  1007. <td class="requirements-value">'.check_php_setting('magic_quotes_gpc','OFF').'</td>
  1008. </tr>
  1009. <tr>
  1010. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-runtime">Magic Quotes Runtime</a></td>
  1011. <td class="requirements-recommended">OFF</td>
  1012. <td class="requirements-value">'.check_php_setting('magic_quotes_runtime','OFF').'</td>
  1013. </tr>
  1014. <tr>
  1015. <td class="requirements-item"><a href="http://php.net/manual/security.globals.php">Register Globals</a></td>
  1016. <td class="requirements-recommended">OFF</td>
  1017. <td class="requirements-value">'.check_php_setting('register_globals','OFF').'</td>
  1018. </tr>
  1019. <tr>
  1020. <td class="requirements-item"><a href="http://php.net/manual/ref.session.php#ini.session.auto-start">Session auto start</a></td>
  1021. <td class="requirements-recommended">OFF</td>
  1022. <td class="requirements-value">'.check_php_setting('session.auto_start','OFF').'</td>
  1023. </tr>
  1024. <tr>
  1025. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.short-open-tag">Short Open Tag</a></td>
  1026. <td class="requirements-recommended">OFF</td>
  1027. <td class="requirements-value">'.check_php_setting('short_open_tag','OFF').'</td>
  1028. </tr>
  1029. <tr>
  1030. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.upload-max-filesize">Maximum upload file size</a></td>
  1031. <td class="requirements-recommended">10M-100M</td>
  1032. <td class="requirements-value">'.ini_get('upload_max_filesize').'</td>
  1033. </tr>
  1034. <tr>
  1035. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.post-max-size">Maximum post size</a></td>
  1036. <td class="requirements-recommended">10M-100M</td>
  1037. <td class="requirements-value">'.ini_get('post_max_size').'</td>
  1038. </tr>
  1039. </table>';
  1040. echo ' </div>';
  1041. echo '</div>';
  1042. // DIRECTORY AND FILE PERMISSIONS
  1043. echo '<div class="RequirementHeading"><h1>'.get_lang('DirectoryAndFilePermissions').'</h1>';
  1044. echo '<div class="RequirementText">'.get_lang('DirectoryAndFilePermissionsInfo').'</div>';
  1045. echo '<div class="RequirementContent">';
  1046. echo '<table class="requirements">
  1047. <tr>
  1048. <td class="requirements-item">chamilo/main/inc/conf/</td>
  1049. <td class="requirements-value">'.check_writable('inc/conf/').'</td>
  1050. </tr>
  1051. <tr>
  1052. <td class="requirements-item">chamilo/main/upload/users/</td>
  1053. <td class="requirements-value">'.check_writable('upload/users/').'</td>
  1054. </tr>
  1055. <tr>
  1056. <td class="requirements-item">chamilo/main/default_course_document/images/</td>
  1057. <td class="requirements-value">'.check_writable('default_course_document/images/').'</td>
  1058. </tr>
  1059. <tr>
  1060. <td class="requirements-item">chamilo/archive/</td>
  1061. <td class="requirements-value">'.check_writable('../archive/').'</td>
  1062. </tr>
  1063. <tr>
  1064. <td class="requirements-item">chamilo/courses/</td>
  1065. <td class="requirements-value">'.check_writable('../courses/').'</td>
  1066. </tr>
  1067. <tr>
  1068. <td class="requirements-item">chamilo/home/</td>
  1069. <td class="requirements-value">'.check_writable('../home/').'</td>
  1070. </tr>
  1071. <tr>
  1072. <td class="requirements-item">chamilo/main/css/</td>
  1073. <td class="requirements-value">'.check_writable('css/',true).' ('.get_lang('SuggestionOnlyToEnableCSSUploadFeature').')</td>
  1074. </tr>
  1075. <tr>
  1076. <td class="requirements-item">chamilo/main/lang/</td>
  1077. <td class="requirements-value">'.check_writable('lang/',true).' ('.get_lang('SuggestionOnlyToEnableSubLanguageFeature').')</td>
  1078. </tr>'.
  1079. //'<tr>
  1080. // <td class="requirements-item">chamilo/searchdb/</td>
  1081. // <td class="requirements-value">'.check_writable('../searchdb/').'</td>
  1082. //</tr>'.
  1083. //'<tr>
  1084. // <td class="requirements-item">'.session_save_path().'</td>
  1085. // <td class="requirements-value">'.(is_writable(session_save_path())
  1086. // ? '<strong><font color="green">'.get_lang('Writable').'</font></strong>'
  1087. // : '<strong><font color="red">'.get_lang('NotWritable').'</font></strong>').'</td>
  1088. //</tr>'.
  1089. '';
  1090. echo ' </table>';
  1091. echo ' </div>';
  1092. echo '</div>';
  1093. if ($installType == 'update' && (empty($updatePath) || $badUpdatePath)) {
  1094. if ($badUpdatePath) { ?>
  1095. <div style="color:red; background-color:white; font-weight:bold; text-align:center;">
  1096. <?php echo get_lang('Error'); ?>!<br />
  1097. Chamilo <?php echo (isset($_POST['step2_update_6']) ? implode('|', $update_from_version_6) : implode('|', $update_from_version_8)).' '.get_lang('HasNotBeenFoundInThatDir'); ?>.
  1098. </div>
  1099. <?php }
  1100. else {
  1101. echo '<br />';
  1102. }
  1103. ?>
  1104. <table border="0" cellpadding="5" align="center">
  1105. <tr>
  1106. <td><?php echo get_lang('OldVersionRootPath'); ?>:</td>
  1107. <td><input type="text" name="updatePath" size="50" value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities($updatePath) : $_SERVER['DOCUMENT_ROOT'].'/old_version/'; ?>" /></td>
  1108. </tr>
  1109. <tr>
  1110. <td colspan="2" align="center">
  1111. <button type="submit" class="back" name="step1" value="&lt; <?php echo get_lang('Back'); ?>" ><?php echo get_lang('Back'); ?></button>
  1112. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1113. <button type="submit" class="next" name="<?php echo (isset($_POST['step2_update_6']) ? 'step2_update_6' : 'step2_update_8'); ?>" value="<?php echo get_lang('Next'); ?> &gt;" ><?php echo get_lang('Next'); ?></button>
  1114. </td>
  1115. </tr>
  1116. </table>
  1117. <?php
  1118. } else {
  1119. $error = false;
  1120. // First, attempt to set writing permissions if we don't have them yet
  1121. $perm = api_get_permissions_for_new_directories();
  1122. $perm_file = api_get_permissions_for_new_files();
  1123. $notwritable = array();
  1124. $curdir = getcwd();
  1125. if (!is_writable('../inc/conf')) {
  1126. $notwritable[] = realpath($curdir.'/../inc/conf');
  1127. @chmod('../inc/conf',$perm);
  1128. }
  1129. if (!is_writable('../upload/users')) {
  1130. $notwritable[] = realpath($curdir.'/../upload/users');
  1131. @chmod('../upload/users', $perm);
  1132. }
  1133. if (!is_writable('../default_course_document/images/')) {
  1134. $notwritable[] = realpath($curdir.'/../default_course_document/images/');
  1135. @chmod('../default_course_document/images/', $perm);
  1136. }
  1137. if (!is_writable('../../archive')) {
  1138. $notwritable[] = realpath($curdir.'/../../archive');
  1139. @chmod('../../archive',$perm);
  1140. }
  1141. if (!is_writable('../../courses')) {
  1142. $notwritable[] = realpath($curdir.'/../../courses');
  1143. @chmod('../../courses',$perm);
  1144. }
  1145. if (!is_writable('../../home')) {
  1146. $notwritable[] = realpath($curdir.'/../../home');
  1147. @chmod('../../home',$perm);
  1148. }
  1149. if (file_exists('../inc/conf/configuration.php') && !is_writable('../inc/conf/configuration.php')) {
  1150. $notwritable[]= realpath($curdir.'/../inc/conf/configuration.php');
  1151. @chmod('../inc/conf/configuration.php',$perm_file);
  1152. }
  1153. //Second, if this fails, report an error
  1154. //--> the user will have to adjust the permissions manually
  1155. if (count($notwritable) > 0) {
  1156. $error = true;
  1157. echo '<div style="color:red; background-color:white; font-weight:bold; text-align:center;">';
  1158. echo get_lang('Warning').':<br />';
  1159. printf(get_lang('NoWritePermissionPleaseReadInstallGuide'), '</font><a href="../../documentation/installation_guide.html" target="blank">', '</a> <font color="red">');
  1160. echo '<ul>';
  1161. foreach ($notwritable as $value) {
  1162. echo '<li>'.$value.'</li>';
  1163. }
  1164. echo '</ul>';
  1165. echo '</div>';
  1166. }
  1167. // check wether a Chamilo configuration file already exists.
  1168. elseif (file_exists('../inc/conf/configuration.php')) {
  1169. echo '<div style="color:red; background-color:white; font-weight:bold; text-align:center;">';
  1170. echo get_lang('WarningExistingDokeosInstallationDetected');
  1171. echo '</div>';
  1172. }
  1173. //and now display the choice buttons (go back or install)
  1174. ?>
  1175. <p align="center">
  1176. <button type="submit" name="step1" class="back" onclick="javascript: window.location='index.php'; return false;" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
  1177. <button type="submit" name="step2_install" class="add" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) echo 'disabled="disabled"'; ?> ><?php echo get_lang('NewInstallation'); ?></button>
  1178. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1179. <?php
  1180. //real code
  1181. echo '<button type="submit" class="save" name="step2_update_8" value="Upgrade from Dokeos 1.8.x"';
  1182. if ($error) echo ' disabled="disabled"';
  1183. //temporary code for alpha version, disabling upgrade
  1184. //echo '<input type="submit" name="step2_update" value="Upgrading is not possible in this beta version"';
  1185. //echo ' disabled="disabled"';
  1186. //end temp code
  1187. echo ' >'.get_lang('UpgradeFromDokeos18x').'</button>';
  1188. echo '<button type="submit" class="save" name="step2_update_6" value="Upgrade from Dokeos 1.6.x"';
  1189. if ($error) echo ' disabled="disabled"';
  1190. echo ' >'.get_lang('UpgradeFromDokeos16x').'</button>';
  1191. echo '</p>';
  1192. }
  1193. }
  1194. /**
  1195. * Displays the license (GNU GPL) as step 2, with
  1196. * - an "I accept" button named step3 to proceed to step 3;
  1197. * - a "Back" button named step1 to go back to the first step.
  1198. */
  1199. function display_license_agreement() {
  1200. echo '<h2>'.display_step_sequence().get_lang('Licence').'</h2>';
  1201. echo '<p>'.get_lang('DokeosLicenseInfo').'</p>';
  1202. echo '<p><a href="../../documentation/license.html" target="_blank">'.get_lang('PrintVers').'</a></p>';
  1203. ?>
  1204. <table><tr><td>
  1205. <p><textarea cols="75" rows="15" ><?php htmlentities(include('../../documentation/license.txt')); ?></textarea></p>
  1206. </td>
  1207. </tr>
  1208. <tr>
  1209. <td>
  1210. <p><?php echo get_lang('DokeosArtLicense');?></p>
  1211. </td>
  1212. </tr>
  1213. <td>
  1214. <table width="100%">
  1215. <tr>
  1216. <td></td>
  1217. <td align="center">
  1218. <button type="submit" class="back" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
  1219. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1220. <button type="submit" class="next" name="step3" value="<?php echo get_lang('IAccept'); ?> &gt;" ><?php echo get_lang('IAccept'); ?></button>
  1221. </td>
  1222. </tr>
  1223. </table>
  1224. </td></tr></table>
  1225. <?php
  1226. }
  1227. /**
  1228. * Displays a parameter in a table row.
  1229. * Used by the display_database_settings_form function.
  1230. * @param string Type of install
  1231. * @param string Name of parameter
  1232. * @param string Field name (in the HTML form)
  1233. * @param string Field value
  1234. * @param string Extra notice (to show on the right side)
  1235. * @param boolean Whether to display in update mode
  1236. * @param string Additional attribute for the <tr> element
  1237. * @return void Direct output
  1238. */
  1239. function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = true, $tr_attribute = '') {
  1240. echo "<tr ".$tr_attribute.">\n";
  1241. echo "<td>$parameter_name&nbsp;&nbsp;</td>\n";
  1242. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1243. echo '<td><input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />'.$parameter_value."</td>\n";
  1244. } else {
  1245. $inputtype = $form_field_name == 'dbPassForm' ? 'password' : 'text';
  1246. //Slightly limit the length of the database prefix to avoid having to cut down the databases names later on
  1247. $maxlength = $form_field_name == 'dbPrefixForm' ? '15' : MAX_FORM_FIELD_LENGTH;
  1248. echo '<td><input type="'.$inputtype.'" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxlength.'" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />'."</td>\n";
  1249. echo "<td>$extra_notice</td>\n";
  1250. }
  1251. echo "</tr>\n";
  1252. }
  1253. /**
  1254. * Displays step 3 - a form where the user can enter the installation settings
  1255. * regarding the databases - login and password, names, prefixes, single
  1256. * or multiple databases, tracking or not...
  1257. */
  1258. function display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm) {
  1259. if ($installType == 'update') {
  1260. global $_configuration, $update_from_version_6;
  1261. if (in_array($_POST['old_version'], $update_from_version_6)) {
  1262. $dbHostForm = get_config_param('dbHost');
  1263. $dbUsernameForm = get_config_param('dbLogin');
  1264. $dbPassForm = get_config_param('dbPass');
  1265. $dbPrefixForm = get_config_param('dbNamePrefix');
  1266. $enableTrackingForm = get_config_param('is_trackingEnabled');
  1267. $singleDbForm = get_config_param('singleDbEnabled');
  1268. $dbNameForm = get_config_param('mainDbName');
  1269. $dbStatsForm = get_config_param('statsDbName');
  1270. $dbScormForm = get_config_param('scormDbName');
  1271. $dbUserForm = get_config_param('user_personal_database');
  1272. $dbScormExists = true;
  1273. } else {
  1274. $dbHostForm = $_configuration['db_host'];
  1275. $dbUsernameForm = $_configuration['db_user'];
  1276. $dbPassForm = $_configuration['db_password'];
  1277. $dbPrefixForm = $_configuration['db_prefix'];
  1278. $enableTrackingForm = $_configuration['tracking_enabled'];
  1279. $singleDbForm = $_configuration['single_database'];
  1280. $dbNameForm = $_configuration['main_database'];
  1281. $dbStatsForm = $_configuration['statistics_database'];
  1282. $dbScormForm = $_configuration['scorm_database'];
  1283. $dbUserForm = $_configuration['user_personal_database'];
  1284. $dbScormExists = true;
  1285. }
  1286. if (empty($dbScormForm)) {
  1287. if ($singleDbForm) {
  1288. $dbScormForm = $dbNameForm;
  1289. } else {
  1290. $dbScormForm = $dbPrefixForm.'scorm';
  1291. $dbScormExists = false;
  1292. }
  1293. }
  1294. if (empty($dbUserForm)) {
  1295. $dbUserForm = $singleDbForm ? $dbNameForm : $dbPrefixForm.'chamilo_user';
  1296. }
  1297. echo '<h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2>';
  1298. echo get_lang('DBSettingUpgradeIntro');
  1299. } else {
  1300. if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix
  1301. $dbPrefixForm = 'chamilo_';
  1302. }
  1303. echo '<h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2>';
  1304. echo get_lang('DBSettingIntro');
  1305. }
  1306. ?>
  1307. <br /><br />
  1308. </td>
  1309. </tr>
  1310. <tr>
  1311. <td>
  1312. <table width="100%">
  1313. <tr>
  1314. <td width="40%"><?php echo get_lang('DBHost'); ?> </td>
  1315. <?php if ($installType == 'update'): ?>
  1316. <td width="30%"><input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?></td>
  1317. <td width="30%">&nbsp;</td>
  1318. <?php else: ?>
  1319. <td width="30%"><input type="text" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /></td>
  1320. <td width="30%"><?php echo get_lang('EG').' localhost'; ?></td>
  1321. <?php endif; ?>
  1322. </tr>
  1323. <?php
  1324. //database user username
  1325. $example_login = get_lang('EG').' root';
  1326. display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
  1327. //database user password
  1328. $example_password = get_lang('EG').' '.api_generate_password();
  1329. display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password);
  1330. //database prefix
  1331. display_database_parameter($installType, get_lang('DbPrefixForm'), 'dbPrefixForm', $dbPrefixForm, get_lang('DbPrefixCom'));
  1332. //fields for the four standard Chamilo databases
  1333. echo '<tr><td colspan="3"><a href="" onclick="javascript: show_hide_option();return false;" id="optionalparameters"><img style="vertical-align:middle;" src="../img/div_show.gif" alt="show-hide" /> '.get_lang('OptionalParameters', '').'</a></td></tr>';
  1334. display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;', null, 'id="optional_param1" style="display:none;"');
  1335. display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, '&nbsp;', null, 'id="optional_param2" style="display:none;"');
  1336. if ($installType == 'update' && in_array($_POST['old_version'], $update_from_version_6)) {
  1337. display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" style="display:none;"');
  1338. }
  1339. display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;', null, 'id="optional_param4" style="display:none;"');
  1340. ?>
  1341. <tr id="optional_param5" style="display:none;">
  1342. <td><?php echo get_lang('EnableTracking'); ?> </td>
  1343. <?php if ($installType == 'update'): ?>
  1344. <td><input type="hidden" name="enableTrackingForm" value="<?php echo $enableTrackingForm; ?>" /><?php echo $enableTrackingForm ? get_lang('Yes') : get_lang('No'); ?></td>
  1345. <?php else: ?>
  1346. <td>
  1347. <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>
  1348. <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>
  1349. </td>
  1350. <?php endif; ?>
  1351. <td>&nbsp;</td>
  1352. </tr>
  1353. <tr id="optional_param6" style="display:none;">
  1354. <td><?php echo get_lang('SingleDb'); ?> </td>
  1355. <?php if ($installType == 'update'): ?>
  1356. <td><input type="hidden" name="singleDbForm" value="<?php echo $singleDbForm; ?>" /><?php echo $singleDbForm ? get_lang('One') : get_lang('Several'); ?></td>
  1357. <?php else: ?>
  1358. <td>
  1359. <input class="checkbox" type="radio" name="singleDbForm" value="1" id="singleDb1" <?php echo $singleDbForm ? 'checked="checked" ' : ''; ?> onclick="javascript: show_hide_tracking_and_user_db(this.id);" /> <label for="singleDb1"><?php echo get_lang('One'); ?></label>
  1360. <input class="checkbox" type="radio" name="singleDbForm" value="0" id="singleDb0" <?php echo $singleDbForm ? '' : 'checked="checked" '; ?> onclick="javascript: show_hide_tracking_and_user_db(this.id);" /> <label for="singleDb0"><?php echo get_lang('Several'); ?></label>
  1361. </td>
  1362. <?php endif; ?>
  1363. <td>&nbsp;</td>
  1364. </tr>
  1365. </div>
  1366. <tr>
  1367. <td><button type="submit" class="login" name="step3" value="<?php echo get_lang('CheckDatabaseConnection'); ?>" ><?php echo get_lang('CheckDatabaseConnection'); ?></button></td>
  1368. <?php
  1369. $dbConnect = test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm);
  1370. if ($dbConnect == 1): ?>
  1371. <td colspan="2">
  1372. <div class="confirmation-message">
  1373. <!--<div style="float:left; margin-right:10px;">
  1374. <img src="../img/message_confirmation.png" alt="Confirmation" />
  1375. </div>-->
  1376. <!--<div style="float:left;">-->
  1377. Database host info: <strong><?php echo Database::get_host_info(); ?></strong><br />
  1378. Database server version: <strong><?php echo Database::get_server_info(); ?></strong><br />
  1379. Database client version: <strong><?php echo Database::get_client_info(); ?></strong><br />
  1380. Database protocol version: <strong><?php echo Database::get_proto_info(); ?></strong>
  1381. <!--</div>-->
  1382. <div style="clear:both;"></div>
  1383. </div>
  1384. </td>
  1385. <?php else: ?>
  1386. <td colspan="2">
  1387. <div style="float:left;" class="error-message">
  1388. <!--<div style="float:left; margin-right:10px;">
  1389. <img src="../img/message_error.png" alt="Error" />
  1390. </div>-->
  1391. <div style="float:left;">
  1392. <strong>Database error: <?php echo Database::errno(); ?></strong><br />
  1393. <?php echo Database::error().'<br />'; ?>
  1394. <strong><?php echo get_lang('Details').': '. get_lang('FailedConectionDatabase'); ?></strong><br />
  1395. </div>
  1396. </div>
  1397. </td>
  1398. <?php endif; ?>
  1399. </tr>
  1400. <tr>
  1401. <td><button type="submit" name="step2" class="back" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button></td>
  1402. <td>&nbsp;</td>
  1403. <td align="right"><input type="hidden" name="is_executable" id="is_executable" value="-" /><button type="submit" class="next" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" /><?php echo get_lang('Next'); ?></button></td>
  1404. </tr>
  1405. </table>
  1406. <?php
  1407. }
  1408. /**
  1409. * Displays a parameter in a table row.
  1410. * Used by the display_configuration_settings_form function.
  1411. */
  1412. function display_configuration_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $display_when_update = 'true') {
  1413. echo "<tr>\n";
  1414. echo "<td>$parameter_name&nbsp;&nbsp;</td>\n";
  1415. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1416. echo '<td><input type="hidden" name="'.$form_field_name.'" value="'.api_htmlentities($parameter_value, ENT_QUOTES).'" />'.$parameter_value."</td>\n";
  1417. } else {
  1418. echo '<td><input type="text" size="'.FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.MAX_FORM_FIELD_LENGTH.'" name="'.$form_field_name.'" value="'.api_htmlentities($parameter_value, ENT_QUOTES).'" />'."</td>\n";
  1419. }
  1420. echo "</tr>\n";
  1421. }
  1422. /**
  1423. * Displays step 4 of the installation - configuration settings about Chamilo itself.
  1424. */
  1425. function display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm) {
  1426. if ($installType != 'update' && empty($languageForm)) {
  1427. $languageForm = $_SESSION['install_language'];
  1428. }
  1429. echo "<h2>" . display_step_sequence() . get_lang("CfgSetting") . "</h2>";
  1430. echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>main/inc/conf/configuration.php</strong></p>';
  1431. echo "</td></tr>\n<tr><td>";
  1432. echo "<table width=\"100%\">";
  1433. //First parameter: language
  1434. echo "<tr>\n";
  1435. echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>\n";
  1436. if ($installType == 'update') {
  1437. echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm."</td>\n";
  1438. } else { // new installation
  1439. echo '<td>';
  1440. display_language_selection_box('languageForm', $languageForm);
  1441. echo "</td>\n";
  1442. }
  1443. echo "</tr>\n";
  1444. //Second parameter: Chamilo URL
  1445. echo "<tr>\n";
  1446. echo '<td>'.get_lang('ChamiloURL').' (<font color="red">'.get_lang('ThisFieldIsRequired')."</font>)&nbsp;&nbsp;</td>\n";
  1447. if ($installType == 'update') {
  1448. echo '<td>'.api_htmlentities($urlForm, ENT_QUOTES)."</td>\n";
  1449. } else {
  1450. echo '<td><input type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities($urlForm, ENT_QUOTES).'" />'."</td>\n";
  1451. }
  1452. echo "</tr>\n";
  1453. //Parameter 3: administrator's email
  1454. display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
  1455. //Parameters 4 and 5: administrator's names
  1456. if (api_is_western_name_order()) {
  1457. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1458. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1459. } else {
  1460. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1461. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1462. }
  1463. //Parameter 6: administrator's telephone
  1464. display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
  1465. //Parameter 7: administrator's login
  1466. display_configuration_parameter($installType, get_lang('AdminLogin'), 'loginForm', $loginForm, $installType == 'update');
  1467. //Parameter 8: administrator's password
  1468. if ($installType != 'update') {
  1469. display_configuration_parameter($installType, get_lang('AdminPass'), 'passForm', $passForm, false);
  1470. }
  1471. //Parameter 9: campus name
  1472. display_configuration_parameter($installType, get_lang('CampusName'), 'campusForm', $campusForm);
  1473. //Parameter 10: institute (short) name
  1474. display_configuration_parameter($installType, get_lang('InstituteShortName'), 'institutionForm', $institutionForm);
  1475. //Parameter 11: institute (short) name
  1476. display_configuration_parameter($installType, get_lang('InstituteURL'), 'institutionUrlForm', $institutionUrlForm);
  1477. /*
  1478. //old method
  1479. <tr>
  1480. <td><?php echo get_lang('EncryptUserPass'); ?> :</td>
  1481. <?php if($installType == 'update'): ?>
  1482. <td><input type="hidden" name="encryptPassForm" value="<?php echo $encryptPassForm; ?>" /><?php echo $encryptPassForm? get_lang('Yes') : get_lang('No'); ?></td>
  1483. <?php else: ?>
  1484. <td>
  1485. <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>
  1486. <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>
  1487. </td>
  1488. <?php endif; ?>
  1489. </tr>
  1490. */
  1491. ?>
  1492. <tr>
  1493. <td><?php echo get_lang("EncryptMethodUserPass"); ?> :</td>
  1494. <?php if ($installType == 'update'): ?>
  1495. <td><input type="hidden" name="encryptPassForm" value="<?php echo $encryptPassForm; ?>" /><?php echo $encryptPassForm; ?></td>
  1496. <?php else: ?>
  1497. <td>
  1498. <input class="checkbox" type="radio" name="encryptPassForm" value="md5" id="encryptPass0" <?php echo $encryptPassForm ? 'checked="checked" ' : ''; ?>/> <label for="encryptPass0"><?php echo 'md5'; ?></label>
  1499. <input class="checkbox" type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" <?php echo $encryptPassForm ? '' : 'checked="checked" '; ?>/> <label for="encryptPass1"><?php echo 'sha1'; ?></label>
  1500. <input class="checkbox" type="radio" name="encryptPassForm" value="none" id="encryptPass2" <?php echo $encryptPassForm ? '' : 'checked="checked" '; ?>/> <label for="encryptPass2"><?php echo get_lang('None'); ?></label>
  1501. </td>
  1502. <?php endif; ?>
  1503. </tr>
  1504. <tr>
  1505. <td><?php echo get_lang('AllowSelfReg'); ?> :</td>
  1506. <?php if ($installType == 'update'): ?>
  1507. <td><input type="hidden" name="allowSelfReg" value="<?php echo $allowSelfReg; ?>" /><?php echo $allowSelfReg ? get_lang('Yes') : get_lang('No'); ?></td>
  1508. <?php else: ?>
  1509. <td>
  1510. <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>
  1511. <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>
  1512. </td>
  1513. <?php endif; ?>
  1514. </tr>
  1515. <tr>
  1516. <td><?php echo get_lang('AllowSelfRegProf'); ?> :</td>
  1517. <?php if ($installType == 'update'): ?>
  1518. <td><input type="hidden" name="allowSelfRegProf" value="<?php echo $allowSelfRegProf; ?>" /><?php echo $allowSelfRegProf? get_lang('Yes') : get_lang('No'); ?></td>
  1519. <?php else: ?>
  1520. <td>
  1521. <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>
  1522. <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>
  1523. </td>
  1524. <?php endif; ?>
  1525. </tr>
  1526. <tr>
  1527. <td><button type="submit" class="back" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>" /><?php echo get_lang('Previous'); ?></button></td>
  1528. <td align="right"><input type="hidden" name="is_executable" id="is_executable" value="-" /><button class="next" type="submit" name="step5" value="<?php echo get_lang('Next'); ?> &gt;" /><?php echo get_lang('Next'); ?></button></td>
  1529. </tr>
  1530. </table>
  1531. <?php
  1532. }
  1533. /**
  1534. * After installation is completed (step 6), this message is displayed.
  1535. */
  1536. function display_after_install_message($installType, $nbr_courses) {
  1537. ?>
  1538. <h2><?php echo display_step_sequence() . get_lang('CfgSetting'); ?></h2>
  1539. <?php echo get_lang('FirstUseTip'); ?>
  1540. <br /><br />
  1541. <?php
  1542. echo '<div class="warning-message">';
  1543. //echo '<img src="../img/message_warning.png" style="float:left; margin-right:10px;" alt="'.get_lang('Warning').'"/>';
  1544. echo '<strong>'.get_lang('SecurityAdvice').'</strong>';
  1545. echo ': ';
  1546. printf(get_lang('ToProtectYourSiteMakeXAndYReadOnly'), 'main/inc/conf/configuration.php', 'main/install/index.php');
  1547. echo '</div>';
  1548. ?>
  1549. </form>
  1550. <a class="portal" href="../../index.php"><?php echo get_lang('GoToYourNewlyCreatedPortal'); ?></a>
  1551. <?php
  1552. }