install.lib.php 68 KB

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