install.lib.php 69 KB

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