install.lib.php 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Chamilo LMS
  5. * This file contains functions used by the install and upgrade scripts.
  6. *
  7. * Ideas for future additions:
  8. * - a function get_old_version_settings to retrieve the config file settings
  9. * of older versions before upgrading.
  10. */
  11. /* CONSTANTS */
  12. define('SYSTEM_MAIN_DATABASE_FILE', 'db_main.sql');
  13. define('COUNTRY_DATA_FILENAME', 'country_data.csv');
  14. define('COURSES_HTACCESS_FILENAME', 'htaccess.dist');
  15. define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php');
  16. /* COMMON PURPOSE FUNCTIONS */
  17. /**
  18. * This function detects whether the system has been already installed.
  19. * It should be used for prevention from second running the installation
  20. * script and as a result - destroying a production system.
  21. * @return bool The detected result;
  22. * @author Ivan Tcholakov, 2010;
  23. */
  24. function is_already_installed_system() {
  25. global $new_version, $_configuration;
  26. if (empty($new_version)) {
  27. return true; // Must be initialized.
  28. }
  29. $current_config_file = api_get_path(CONFIGURATION_PATH).'configuration.php';
  30. if (!file_exists($current_config_file)) {
  31. return false; // Configuration file does not exist, install the system.
  32. }
  33. require $current_config_file;
  34. $current_version = null;
  35. if (isset($_configuration['dokeos_version'])) {
  36. $current_version = trim($_configuration['dokeos_version']);
  37. }
  38. if (empty($current_version)) {
  39. $current_version = trim($_configuration['system_version']);
  40. }
  41. // If the current version is old, upgrading is assumed, the installer goes ahead.
  42. return empty($current_version) ? false : version_compare($current_version, $new_version, '>=');
  43. }
  44. /**
  45. * This function checks if a php extension exists or not and returns an HTML status string.
  46. *
  47. * @param string Name of the PHP extension to be checked
  48. * @param string Text to show when extension is available (defaults to 'Yes')
  49. * @param string Text to show when extension is available (defaults to 'No')
  50. * @param boolean Whether this extension is optional (in this case show unavailable text in orange rather than red)
  51. * @return string HTML string reporting the status of this extension. Language-aware.
  52. * @author Christophe Gesch??
  53. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  54. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  55. * @version Dokeos 1.8.1, May 2007
  56. */
  57. function check_extension($extension_name, $return_success = 'Yes', $return_failure = 'No', $optional = false) {
  58. if (extension_loaded($extension_name)) {
  59. return Display::label($return_success, 'success');
  60. } else {
  61. if ($optional) {
  62. return Display::label($return_failure, 'warning');
  63. //return '<strong><font color="#ff9900">'.$return_failure.'</font></strong>';
  64. } else {
  65. return Display::label($return_failure, 'important');
  66. //return '<strong><font color="red">'.$return_failure.'</font></strong>';
  67. }
  68. }
  69. }
  70. /**
  71. * This function checks whether a php setting matches the recommended value
  72. *
  73. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  74. * @version Dokeos 1.8, august 2006
  75. */
  76. function check_php_setting($php_setting, $recommended_value, $return_success = false, $return_failure = false) {
  77. $current_php_value = get_php_setting($php_setting);
  78. if ($current_php_value == $recommended_value) {
  79. return Display::label($current_php_value.' '.$return_success, 'success');
  80. } else {
  81. return Display::label($current_php_value.' '.$return_success, 'important');
  82. }
  83. }
  84. /**
  85. * This function return the value of a php.ini setting if not "" or if exists, otherwise return false
  86. */
  87. function check_php_setting_exists($php_setting) {
  88. if (ini_get($php_setting) != "") {
  89. return ini_get($php_setting);
  90. }
  91. return false;
  92. }
  93. /**
  94. * Returns a textual value ('ON' or 'OFF') based on a requester 2-state ini- configuration setting.
  95. *
  96. * @param string $val a php ini value
  97. * @return boolean: ON or OFF
  98. * @author Joomla <http://www.joomla.org>
  99. */
  100. function get_php_setting($val) {
  101. return ini_get($val) == '1' ? 'ON' : 'OFF';
  102. }
  103. /**
  104. * This function returns a string "true" or "false" according to the passed parameter.
  105. *
  106. * @param integer $var The variable to present as text
  107. * @return string the string "true" or "false"
  108. * @author Christophe Gesch??
  109. */
  110. function true_false($var) {
  111. return $var ? 'true' : 'false';
  112. }
  113. /**
  114. * Removes memory and time limits as much as possible.
  115. */
  116. function remove_memory_and_time_limits() {
  117. if (function_exists('ini_set')) {
  118. ini_set('memory_limit', -1);
  119. ini_set('max_execution_time', 0);
  120. } else {
  121. error_log('Update-db script: could not change memory and time limits', 0);
  122. }
  123. }
  124. /**
  125. * Detects browser's language.
  126. * @return string Returns a language identificator, i.e. 'english', 'spanish', ...
  127. * @author Ivan Tcholakov, 2010
  128. */
  129. function detect_browser_language() {
  130. static $language_index = array(
  131. 'ar' => 'arabic',
  132. 'ast' => 'asturian',
  133. 'bg' => 'bulgarian',
  134. 'bs' => 'bosnian',
  135. 'ca' => 'catalan',
  136. 'zh' => 'simpl_chinese',
  137. 'zh-tw' => 'trad_chinese',
  138. 'cs' => 'czech',
  139. 'da' => 'danish',
  140. 'prs' => 'dari',
  141. 'de' => 'german',
  142. 'el' => 'greek',
  143. 'en' => 'english',
  144. 'es' => 'spanish',
  145. 'eo' => 'esperanto',
  146. 'eu' => 'basque',
  147. 'fa' => 'persian',
  148. 'fr' => 'french',
  149. 'fur' => 'friulian',
  150. 'gl' => 'galician',
  151. 'ka' => 'georgian',
  152. 'hr' => 'croatian',
  153. 'he' => 'hebrew',
  154. 'hi' => 'hindi',
  155. 'id' => 'indonesian',
  156. 'it' => 'italian',
  157. 'ko' => 'korean',
  158. 'lv' => 'latvian',
  159. 'lt' => 'lithuanian',
  160. 'mk' => 'macedonian',
  161. 'hu' => 'hungarian',
  162. 'ms' => 'malay',
  163. 'nl' => 'dutch',
  164. 'ja' => 'japanese',
  165. 'no' => 'norwegian',
  166. 'oc' => 'occitan',
  167. 'ps' => 'pashto',
  168. 'pl' => 'polish',
  169. 'pt' => 'portuguese',
  170. 'pt-br' => 'brazilian',
  171. 'ro' => 'romanian',
  172. 'qu' => 'quechua_cusco',
  173. 'ru' => 'russian',
  174. 'sk' => 'slovak',
  175. 'sl' => 'slovenian',
  176. 'sr' => 'serbian',
  177. 'fi' => 'finnish',
  178. 'sv' => 'swedish',
  179. 'th' => 'thai',
  180. 'tr' => 'turkish',
  181. 'uk' => 'ukrainian',
  182. 'vi' => 'vietnamese',
  183. 'sw' => 'swahili',
  184. 'yo' => 'yoruba'
  185. );
  186. $system_available_languages = & get_language_folder_list();
  187. $accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
  188. foreach ($language_index as $code => $language) {
  189. if (strpos($accept_languages, $code) === 0) {
  190. if (!empty($system_available_languages[$language])) {
  191. return $language;
  192. }
  193. }
  194. }
  195. $user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT']));
  196. foreach ($language_index as $code => $language) {
  197. if (@preg_match("/[\[\( ]{$code}[;,_\-\)]/", $user_agent)) {
  198. if (!empty($system_available_languages[$language])) {
  199. return $language;
  200. }
  201. }
  202. }
  203. return 'english';
  204. }
  205. /* FILESYSTEM RELATED FUNCTIONS */
  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 Display::label(get_lang('Writable'), 'success');
  212. } else {
  213. if ($suggestion) {
  214. return Display::label(get_lang('NotWritable'), 'info');
  215. } else {
  216. return Display::label(get_lang('NotWritable'), 'important');
  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. if(!is_readable($filename) || is_dir($filename)){
  228. return array();
  229. }
  230. $fp = fopen($filename, 'rb');
  231. $buffer = fread($fp, filesize($filename));
  232. fclose($fp);
  233. return explode('<br />', nl2br($buffer));
  234. }
  235. /**
  236. * We assume this function is called from install scripts that reside inside the install folder.
  237. */
  238. function set_file_folder_permissions() {
  239. @chmod('.', 0755); //set permissions on install dir
  240. @chmod('..', 0755); //set permissions on parent dir of install dir
  241. @chmod('country_data.csv.csv', 0755);
  242. }
  243. /**
  244. * Add's a .htaccess file to the courses directory
  245. * @param string $url_append The path from your webroot to your chamilo root
  246. */
  247. function write_courses_htaccess_file($url_append) {
  248. $content = file_get_contents(dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME);
  249. $content = str_replace('{CHAMILO_URL_APPEND_PATH}', $url_append, $content);
  250. $fp = @ fopen(api_get_path(SYS_PATH).'courses/.htaccess', 'w');
  251. if ($fp) {
  252. fwrite($fp, $content);
  253. return fclose($fp);
  254. }
  255. return false;
  256. }
  257. /**
  258. * Write the main system config file
  259. * @param string $path Path to the config file
  260. */
  261. function write_system_config_file($path) {
  262. global $dbHostForm;
  263. global $dbUsernameForm;
  264. global $dbPassForm;
  265. global $enableTrackingForm;
  266. global $singleDbForm;
  267. global $dbPrefixForm;
  268. global $dbNameForm;
  269. global $dbStatsForm;
  270. global $dbScormForm;
  271. global $dbUserForm;
  272. global $urlForm;
  273. global $pathForm;
  274. global $urlAppendPath;
  275. global $languageForm;
  276. global $encryptPassForm;
  277. global $installType;
  278. global $updatePath;
  279. global $session_lifetime;
  280. global $new_version;
  281. global $new_version_stable;
  282. $root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm)));
  283. $content = file_get_contents(dirname(__FILE__).'/'.SYSTEM_CONFIG_FILENAME);
  284. $config['{DATE_GENERATED}'] = date('r');
  285. $config['{DATABASE_HOST}'] = $dbHostForm;
  286. $config['{DATABASE_USER}'] = $dbUsernameForm;
  287. $config['{DATABASE_PASSWORD}'] = $dbPassForm;
  288. $config['TRACKING_ENABLED'] = true_false($enableTrackingForm);
  289. $config['SINGLE_DATABASE'] = true_false($singleDbForm);
  290. $config['{COURSE_TABLE_PREFIX}'] = ($singleDbForm ? 'crs_' : '');
  291. $config['{DATABASE_GLUE}'] = ($singleDbForm ? '_' : '`.`');
  292. $config['{DATABASE_PREFIX}'] = '';
  293. $config['{DATABASE_MAIN}'] = $dbNameForm;
  294. $config['{DATABASE_STATS}'] = $dbNameForm;
  295. $config['{DATABASE_SCORM}'] = $dbNameForm;
  296. $config['{DATABASE_PERSONAL}'] = $dbNameForm;
  297. $config['{ROOT_WEB}'] = $urlForm;
  298. $config['{ROOT_SYS}'] = $root_sys;
  299. $config['{URL_APPEND_PATH}'] = $urlAppendPath;
  300. $config['{PLATFORM_LANGUAGE}'] = $languageForm;
  301. $config['{SECURITY_KEY}'] = md5(uniqid(rand().time()));
  302. $config['{ENCRYPT_PASSWORD}'] = $encryptPassForm;
  303. $config['SESSION_LIFETIME'] = $session_lifetime;
  304. $config['{NEW_VERSION}'] = $new_version;
  305. $config['NEW_VERSION_STABLE'] = true_false($new_version_stable);
  306. foreach ($config as $key => $value) {
  307. $content = str_replace($key, $value, $content);
  308. }
  309. $fp = @ fopen($path, 'w');
  310. if (!$fp) {
  311. echo '<strong><font color="red">Your script doesn\'t have write access to the config directory</font></strong><br />
  312. <em>('.str_replace('\\', '/', realpath($path)).')</em><br /><br />
  313. You probably do not have write access on Chamilo root directory,
  314. i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br />
  315. Your problems can be related on two possible causes:<br />
  316. <ul>
  317. <li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li>
  318. <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>
  319. </ul>
  320. <a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br />
  321. Please go back to step 5.
  322. <p><input type="submit" name="step5" value="&lt; Back" /></p>
  323. </td></tr></table></form></body></html>';
  324. exit;
  325. }
  326. fwrite($fp, $content);
  327. fclose($fp);
  328. }
  329. /**
  330. * Returns a list of language directories.
  331. */
  332. function & get_language_folder_list() {
  333. static $result;
  334. if (!is_array($result)) {
  335. $result = array();
  336. $exceptions = array('.', '..', 'CVS', '.svn');
  337. $search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_');
  338. $replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
  339. $dirname = api_get_path(SYS_LANG_PATH);
  340. $handle = opendir($dirname);
  341. while ($entries = readdir($handle)) {
  342. if (in_array($entries, $exceptions)) {
  343. continue;
  344. }
  345. if (is_dir($dirname.$entries)) {
  346. $result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
  347. }
  348. }
  349. closedir($handle);
  350. asort($result);
  351. }
  352. return $result;
  353. }
  354. /**
  355. * TODO: my_directory_to_array() - maybe within the main API there is already a suitable function?
  356. */
  357. function my_directory_to_array($directory) {
  358. $array_items = array();
  359. if ($handle = opendir($directory)) {
  360. while (false !== ($file = readdir($handle))) {
  361. if ($file != "." && $file != "..") {
  362. if (is_dir($directory. "/" . $file)) {
  363. $array_items = array_merge($array_items, my_directory_to_array($directory. '/' . $file));
  364. $file = $directory . "/" . $file;
  365. $array_items[] = preg_replace("/\/\//si", '/', $file);
  366. }
  367. }
  368. }
  369. closedir($handle);
  370. }
  371. return $array_items;
  372. }
  373. /**
  374. * This function returns the value of a parameter from the configuration file
  375. *
  376. * WARNING - this function relies heavily on global variables $updateFromConfigFile
  377. * and $configFile, and also changes these globals. This can be rewritten.
  378. *
  379. * @param string $param the parameter of which the value is returned
  380. * @param string If we want to give the path rather than take it from POST
  381. * @return string the value of the parameter
  382. * @author Olivier Brouckaert
  383. * @author Reworked by Ivan Tcholakov, 2010
  384. */
  385. function get_config_param($param, $updatePath = '') {
  386. global $configFile, $updateFromConfigFile;
  387. // Look if we already have the queried parameter.
  388. if (is_array($configFile) && isset($configFile[$param])) {
  389. return $configFile[$param];
  390. }
  391. if (empty($updatePath) && !empty($_POST['updatePath'])) {
  392. $updatePath = $_POST['updatePath'];
  393. }
  394. if (empty($updatePath)) {
  395. $updatePath = api_get_path(SYS_PATH);
  396. }
  397. $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath)));
  398. $updateFromInstalledVersionFile = '';
  399. if (empty($updateFromConfigFile)) {
  400. // If update from previous install was requested,
  401. // try to recover old config file from dokeos 1.8.x.
  402. if (file_exists($updatePath.'main/inc/conf/configuration.php')) {
  403. $updateFromConfigFile = 'main/inc/conf/configuration.php';
  404. } elseif (file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php')) {
  405. $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php';
  406. } else {
  407. // Give up recovering.
  408. //error_log('Chamilo Notice: Could not find previous config file at '.$updatePath.'main/inc/conf/configuration.php nor at '.$updatePath.'claroline/inc/conf/claro_main.conf.php in get_config_param(). Will start new config (in '.__FILE__.', line '.__LINE__.')', 0);
  409. return null;
  410. }
  411. }
  412. if (file_exists($updatePath.$updateFromConfigFile) && !is_dir($updatePath.$updateFromConfigFile)) {
  413. // The parameter was not found among the global variables, so look into the old configuration file.
  414. // Make sure the installedVersion file is read first so it is overwritten
  415. // by the config file if the config file contains the version (from 1.8.4).
  416. $config_data_2 = array();
  417. if (file_exists($updatePath.$updateFromInstalledVersionFile)) {
  418. $config_data_2 = file_to_array($updatePath.$updateFromInstalledVersionFile);
  419. }
  420. $configFile = array();
  421. $config_data = file_to_array($updatePath.$updateFromConfigFile);
  422. $config_data = array_merge($config_data, $config_data_2);
  423. $val = '';
  424. // Parse the configuration file, statement by statement (line by line, actually).
  425. foreach ($config_data as $php_statement) {
  426. if (strpos($php_statement, '=') !== false) {
  427. // Variable assignment statement have been detected (probably).
  428. // It is expected to be as follows:
  429. // $variable = 'some_value'; // A comment that is not mandatory.
  430. // Split the statement into its left and right sides.
  431. $php_statement = explode('=', $php_statement);
  432. $variable = trim($php_statement[0]);
  433. $value = $php_statement[1];
  434. if (substr($variable, 0, 1) == '$') {
  435. // We have for sure a php variable assignment detected.
  436. // On the left side: Retrieve the pure variable's name
  437. $variable = trim(str_replace('$', '', $variable));
  438. // On the right side: Remove the comment, if it exists.
  439. list($value) = explode(' //', $value);
  440. // Remove extra whitespace, if any. Remove the trailing semicolon (;).
  441. $value = substr(trim($value), 0, -1);
  442. // Remove surroundig quotes, restore escaped quotes.
  443. $value = str_replace('\"', '"', preg_replace('/^"|"$/', '', $value));
  444. $value = str_replace('\'', '"', preg_replace('/^\'|\'$/', '', $value));
  445. if (strtolower($value) == 'true') {
  446. // A boolean true value have been recognized.
  447. $value = 1;
  448. } elseif (strtolower($value) == 'false') {
  449. // A boolean false value have been recognized.
  450. $value = 0;
  451. } else {
  452. // Probably we have a string value, but also we have to check
  453. // possible string concatenations that may include string values
  454. // and other configuration variables. I this case we have to
  455. // get the calculated result of the concatenation.
  456. $implode_string = ' ';
  457. if (!strstr($value, '." ".') && strstr($value, '.$')) {
  458. // Yes, there is concatenation, insert a special separator string.
  459. $value = str_replace('.$', '." ".$', $value);
  460. $implode_string = '';
  461. }
  462. // Split the concatenated values, if they are more than one.
  463. $sub_strings = explode('." ".', $value);
  464. // Seek for variables and retrieve their values.
  465. foreach ($sub_strings as $key => & $sub_string) {
  466. if (preg_match('/^\$[a-zA-Z_][a-zA-Z0-9_]*$/', $sub_string)) {
  467. // A variable has been detected, read it by recursive call.
  468. $sub_string = get_config_param(str_replace('$', '', $sub_string));
  469. }
  470. }
  471. // Concatenate everything into the final, the calculated string value.
  472. $value = implode($implode_string, $sub_strings);
  473. }
  474. // Cache the result value.
  475. $configFile[$variable] = $value;
  476. $a = explode("'", $variable);
  477. $key_tmp = isset($a[1]) ? $a[1] : null;
  478. if ($key_tmp == $param) {
  479. $val = $value;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. if($param == 'dbGlu' && empty($val)){
  486. return '`.`';
  487. }
  488. //Special treatment for dokeos_version parameter due to Dokeos 1.8.3 have the dokeos_version in the main/inc/installedVersion.inc.php file
  489. if ($param == 'dokeos_version') {
  490. //dokeos_version from configuration.php if empty
  491. $dokeos_version = $val;
  492. if (empty($dokeos_version)) {
  493. //checking the dokeos_version value exists in main/inc/installedVersion.inc.php
  494. if (file_exists($updatePath.'main/inc/installedVersion.inc.php')) {
  495. $updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php';
  496. require ($updateFromInstalledVersionFile); //there are only 2 variables here: $stable & $dokeos_version
  497. $stable = false;
  498. }
  499. }
  500. return $dokeos_version;
  501. } else {
  502. if (file_exists($updatePath.$updateFromConfigFile)) {
  503. return $val;
  504. } else {
  505. error_log('Config array could not be found in get_config_param()', 0);
  506. return null;
  507. }
  508. }
  509. }
  510. /* DATABASE RELATED FUNCTIONS */
  511. /**
  512. * Gets a configuration parameter from the database. Returns returns null on failure.
  513. * @param string DB Host
  514. * @param string DB login
  515. * @param string DB pass
  516. * @param string DB name
  517. * @param string Name of param we want
  518. * @return mixed The parameter value or null if not found
  519. */
  520. function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
  521. Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
  522. Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  523. Database::select_db($db_name);
  524. if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
  525. if (Database::num_rows($res) > 0) {
  526. $row = Database::fetch_array($res);
  527. return $row['selected_value'];
  528. }
  529. }
  530. return null;
  531. }
  532. /**
  533. * Connects to the database server.
  534. */
  535. function database_server_connect() {
  536. global $dbHostForm, $dbUsernameForm, $dbPassForm;
  537. if (($res = @Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm))) === false) {
  538. $no = Database::errno();
  539. $msg = Database::error();
  540. echo '<hr />#'.$no.': '.$msg.'<hr />';
  541. echo get_lang('DBServerDoesntWorkOrLoginPassIsWrong').'.<br /><br />'.
  542. get_lang('PleaseCheckTheseValues').' :<br /><br />'.
  543. '<strong>'.get_lang('DBHost').'</strong> : '.$dbHostForm.'<br />'.
  544. '<strong>'.get_lang('DBLogin').'</strong> : '.$dbUsernameForm.'<br />'.
  545. '<strong>'.get_lang('DBPassword').'</strong> : '.$dbPassForm.'<br /><br />'.
  546. get_lang('PleaseGoBackToStep').' '. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'.'.
  547. '<p><button type="submit" class="back" name="step'. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>'.
  548. '</td></tr></table></form></body></html>';
  549. exit ();
  550. }
  551. @Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  552. }
  553. /**
  554. * Database exists for the MYSQL user
  555. * @param type $database_name
  556. * @return boolean
  557. */
  558. function database_exists($database_name) {
  559. if (empty($database_name)) {
  560. return false;
  561. }
  562. $select_database = @Database::select_db($database_name);
  563. $show_database = false;
  564. $sql = "SHOW DATABASES LIKE '".addslashes($database_name)."'";
  565. $result = @Database::query($sql);
  566. if (Database::num_rows($result)) {
  567. $show_database = true;
  568. }
  569. return $select_database || $show_database;
  570. }
  571. /**
  572. * In step 3. Tests establishing connection to the database server.
  573. * If it's a single database environment the function checks if the database exist.
  574. * If the database doesn't exist we check the creation permissions.
  575. *
  576. * @return int 1 when there is no problem;
  577. * 0 when a new database is impossible to be created, then the single/multiple database configuration is impossible too
  578. * -1 when there is no connection established.
  579. */
  580. function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm) {
  581. $dbConnect = -1;
  582. //Checking user credentials
  583. if (@Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)) !== false) {
  584. $dbConnect = 1;
  585. } else {
  586. $dbConnect = -1;
  587. }
  588. return $dbConnect; //return 1, if no problems, "0" if, in case we can't create a new DB and "-1" if there is no connection.
  589. }
  590. /**
  591. * Fills the countries table with a list of countries.
  592. */
  593. function fill_track_countries_table($track_countries_table) {
  594. $file_path = dirname(__FILE__).'/'.COUNTRY_DATA_FILENAME;
  595. $countries = file($file_path);
  596. $add_country_sql = "INSERT INTO $track_countries_table (id, code, country, counter) VALUES ";
  597. foreach ($countries as $line) {
  598. $elems = explode(',',$line);
  599. $add_country_sql .= '('.intval($elems[0]).',\''.Database::escape_string($elems[1]).'\',\''.Database::escape_string($elems[2]).'\','.intval($elems[3]).'),';
  600. }
  601. $add_country_sql = substr($add_country_sql,0,-1);
  602. //$add_country_sql = "LOAD DATA INFILE '".Database::escape_string($file_path)."' INTO TABLE $track_countries_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'';";
  603. @ Database::query($add_country_sql);
  604. }
  605. /**
  606. * Creates the structure of the main database and fills it
  607. * with data. Placeholder symbols in the main database file
  608. * have to be replaced by the settings entered by the user during installation.
  609. *
  610. * @param array $installation_settings list of settings entered by the user
  611. * @param string optional path about the script for database
  612. * @return void
  613. */
  614. function load_main_database($installation_settings, $db_script = '') {
  615. if (!empty($db_script)) {
  616. if (file_exists($db_script)) {
  617. $sql_text = file_get_contents($db_script);
  618. }
  619. } else {
  620. $db_script = api_get_path(SYS_CODE_PATH).'install/'.SYSTEM_MAIN_DATABASE_FILE;
  621. if (file_exists($db_script)) {
  622. $sql_text = file_get_contents($db_script);
  623. }
  624. }
  625. //replace symbolic parameters with user-specified values
  626. foreach ($installation_settings as $key => $value) {
  627. $sql_text = str_replace($key, Database::escape_string($value), $sql_text);
  628. }
  629. parse_sql_queries($sql_text);
  630. }
  631. /**
  632. * Creates the structure of the stats database
  633. * @param string Name of the file containing the SQL script inside the install directory
  634. */
  635. function load_database_script($db_script) {
  636. $db_script = api_get_path(SYS_CODE_PATH).'install/'.$db_script;
  637. if (file_exists($db_script)) {
  638. $sql_text = file_get_contents($db_script);
  639. }
  640. parse_sql_queries($sql_text);
  641. }
  642. function parse_sql_queries($sql_text) {
  643. //split in array of sql strings
  644. $sql_instructions = array();
  645. split_sql_file($sql_instructions, $sql_text);
  646. //execute the sql instructions
  647. $count = count($sql_instructions);
  648. for ($i = 0; $i < $count; $i++) {
  649. $this_sql_query = $sql_instructions[$i]['query'];
  650. Database::query($this_sql_query);
  651. //UTF8 fix see #5678
  652. /*
  653. if (strpos(strtolower($this_sql_query), 'create table') === false) {
  654. Database::query($this_sql_query);
  655. } else {
  656. //$this_sql_query .= substr($this_sql_query, strlen($this_sql_query), strlen($this_sql_query)-1);
  657. $this_sql_query .= ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci ';
  658. Database::query($this_sql_query);
  659. }*/
  660. }
  661. }
  662. /**
  663. * Function copied and adapted from phpMyAdmin 2.6.0 PMA_splitSqlFile (also GNU GPL)
  664. * Removes comment lines and splits up large sql files into individual queries
  665. * Last revision: September 23, 2001 - gandon
  666. * @param array the splitted sql commands
  667. * @param string the sql commands
  668. * @param integer the MySQL release number (because certains php3 versions
  669. * can't get the value of a constant from within a function)
  670. * @return boolean always true
  671. */
  672. function split_sql_file(&$ret, $sql) {
  673. // do not trim, see bug #1030644
  674. //$sql = trim($sql);
  675. $sql = rtrim($sql, "\n\r");
  676. $sql_len = strlen($sql);
  677. $char = '';
  678. $string_start = '';
  679. $in_string = false;
  680. $nothing = true;
  681. $time0 = time();
  682. for ($i = 0; $i < $sql_len; ++$i) {
  683. $char = $sql[$i];
  684. // We are in a string, check for not escaped end of strings except for
  685. // backquotes that can't be escaped
  686. if ($in_string) {
  687. for (;;) {
  688. $i = strpos($sql, $string_start, $i);
  689. // No end of string found -> add the current substring to the
  690. // returned array
  691. if (!$i) {
  692. $ret[] = $sql;
  693. return true;
  694. }
  695. // Backquotes or no backslashes before quotes: it's indeed the
  696. // end of the string -> exit the loop
  697. elseif ($string_start == '`' || $sql[$i - 1] != '\\') {
  698. $string_start = '';
  699. $in_string = false;
  700. break;
  701. }
  702. // one or more Backslashes before the presumed end of string...
  703. else {
  704. // ... first checks for escaped backslashes
  705. $j = 2;
  706. $escaped_backslash = false;
  707. while ($i - $j > 0 && $sql[$i - $j] == '\\') {
  708. $escaped_backslash = !$escaped_backslash;
  709. $j++;
  710. }
  711. // ... if escaped backslashes: it's really the end of the
  712. // string -> exit the loop
  713. if ($escaped_backslash) {
  714. $string_start = '';
  715. $in_string = false;
  716. break;
  717. }
  718. // ... else loop
  719. else {
  720. $i++;
  721. }
  722. } // end if...elseif...else
  723. } // end for
  724. } // end if (in string)
  725. // lets skip comments (/*, -- and #)
  726. elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
  727. $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
  728. // didn't we hit end of string?
  729. if ($i === false) {
  730. break;
  731. }
  732. if ($char == '/') $i++;
  733. }
  734. // We are not in a string, first check for delimiter...
  735. elseif ($char == ';') {
  736. // if delimiter found, add the parsed part to the returned array
  737. $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing);
  738. $nothing = true;
  739. $sql = ltrim(substr($sql, min($i + 1, $sql_len)));
  740. $sql_len = strlen($sql);
  741. if ($sql_len) {
  742. $i = -1;
  743. } else {
  744. // The submited statement(s) end(s) here
  745. return true;
  746. }
  747. } // end elseif (is delimiter)
  748. // ... then check for start of a string,...
  749. elseif (($char == '"') || ($char == '\'') || ($char == '`')) {
  750. $in_string = true;
  751. $nothing = false;
  752. $string_start = $char;
  753. } // end elseif (is start of string)
  754. elseif ($nothing) {
  755. $nothing = false;
  756. }
  757. // loic1: send a fake header each 30 sec. to bypass browser timeout
  758. $time1 = time();
  759. if ($time1 >= $time0 + 30) {
  760. $time0 = $time1;
  761. header('X-pmaPing: Pong');
  762. } // end if
  763. } // end for
  764. // add any rest to the returned array
  765. if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) {
  766. $ret[] = array('query' => $sql, 'empty' => $nothing);
  767. }
  768. return true;
  769. } // end of the 'split_sql_file()' function
  770. /**
  771. * Get an SQL file's contents
  772. *
  773. * This function bases its parsing on the pre-set format of the specific SQL files in
  774. * the install/upgrade procedure:
  775. * Lines starting with "--" are comments (but need to be taken into account as they also hold sections names)
  776. * Other lines are considered to be one-line-per-query lines (this is checked quickly by this function)
  777. * @param string File to parse (in the current directory)
  778. * @param string Section to return
  779. * @param boolean Print (true) or hide (false) error texts when they occur
  780. */
  781. function get_sql_file_contents($file, $section, $print_errors = true) {
  782. //check given parameters
  783. if (empty($file)) {
  784. $error = "Missing name of file to parse in get_sql_file_contents()";
  785. if ($print_errors) echo $error;
  786. return false;
  787. }
  788. if (!in_array($section, array('main', 'user', 'stats', 'scorm', 'course'))) {
  789. $error = "Section '$section' is not authorized in get_sql_file_contents()";
  790. if ($print_errors) echo $error;
  791. return false;
  792. }
  793. $filepath = getcwd().'/'.$file;
  794. if (!is_file($filepath) or !is_readable($filepath)) {
  795. $error = "File $filepath not found or not readable in get_sql_file_contents()";
  796. if ($print_errors) echo $error;
  797. return false;
  798. }
  799. //read the file in an array
  800. // Empty lines should not be executed as SQL statements, because errors occur, see Task #2167.
  801. $file_contents = file($filepath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  802. if (!is_array($file_contents) or count($file_contents) < 1) {
  803. $error = "File $filepath looks empty in get_sql_file_contents()";
  804. if ($print_errors) echo $error;
  805. return false;
  806. }
  807. //prepare the resulting array
  808. $section_contents = array();
  809. $record = false;
  810. foreach ($file_contents as $index => $line) {
  811. if (substr($line, 0, 2) == '--') {
  812. //This is a comment. Check if section name, otherwise ignore
  813. $result = array();
  814. if (preg_match('/^-- xx([A-Z]*)xx/', $line, $result)) { //we got a section name here
  815. if ($result[1] == strtoupper($section)) {
  816. //we have the section we are looking for, start recording
  817. $record = true;
  818. } else {
  819. //we have another section's header. If we were recording, stop now and exit loop
  820. if ($record) {
  821. break;
  822. }
  823. $record = false;
  824. }
  825. }
  826. } else {
  827. if ($record) {
  828. if (!empty($line)) {
  829. $section_contents[] = $line;
  830. }
  831. }
  832. }
  833. }
  834. //now we have our section's SQL statements group ready, return
  835. return $section_contents;
  836. }
  837. /**
  838. * Adds a new document to the database - specific to version 1.8.0
  839. *
  840. * @param array $_course
  841. * @param string $path
  842. * @param string $filetype
  843. * @param int $filesize
  844. * @param string $title
  845. * @return id if inserted document
  846. */
  847. function add_document_180($_course, $path, $filetype, $filesize, $title, $comment = null) {
  848. $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
  849. $sql = "INSERT INTO $table_document
  850. (`path`,`filetype`,`size`,`title`, `comment`)
  851. VALUES ('$path','$filetype','$filesize','".
  852. Database::escape_string($title)."', '$comment')";
  853. if (Database::query($sql)) {
  854. //display_message("Added to database (id ".Database::insert_id().")!");
  855. return Database::insert_id();
  856. } else {
  857. //display_error("The uploaded file could not be added to the database (".Database::error().")!");
  858. return false;
  859. }
  860. }
  861. /* DISPLAY FUNCTIONS */
  862. /**
  863. * This function prints class=active_step $current_step=$param
  864. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  865. */
  866. function step_active($param) {
  867. global $current_step;
  868. if ($param == $current_step) {
  869. echo 'class="current_step" ';
  870. }
  871. }
  872. /**
  873. * This function displays the Step X of Y -
  874. * @return string String that says 'Step X of Y' with the right values
  875. */
  876. function display_step_sequence() {
  877. global $current_step;
  878. return get_lang('Step'.$current_step).' &ndash; ';
  879. }
  880. /**
  881. * Displays a drop down box for selection the preferred language.
  882. */
  883. function display_language_selection_box($name = 'language_list', $default_language = 'english') {
  884. // Reading language list.
  885. $language_list = get_language_folder_list();
  886. /*
  887. // Reduction of the number of languages shown. Enable this fragment of code for customization purposes.
  888. // Modify the language list according to your preference. Don't exclude the 'english' item.
  889. $language_to_display = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'slovenian_unicode', 'spanish');
  890. foreach ($language_list as $key => & $value) {
  891. if (!in_array($key, $language_to_display)) {
  892. unset($language_list[$key]);
  893. }
  894. }
  895. */
  896. // Sanity checks due to the possibility for customizations.
  897. if (!is_array($language_list) || empty($language_list)) {
  898. $language_list = array('english' => 'English');
  899. }
  900. // Sorting again, if it is necessary.
  901. //asort($language_list);
  902. // More sanity checks.
  903. if (!array_key_exists($default_language, $language_list)) {
  904. if (array_key_exists('english', $language_list)) {
  905. $default_language = 'english';
  906. } else {
  907. $language_keys = array_keys($language_list);
  908. $default_language = $language_keys[0];
  909. }
  910. }
  911. // Displaying the box.
  912. echo "\t\t<select name=\"$name\">\n";
  913. foreach ($language_list as $key => $value) {
  914. if ($key == $default_language) {
  915. $option_end = ' selected="selected">';
  916. } else {
  917. $option_end = '>';
  918. }
  919. echo "\t\t\t<option value=\"$key\"$option_end";
  920. echo $value;
  921. echo "</option>\n";
  922. }
  923. echo "\t\t</select>\n";
  924. }
  925. /**
  926. * This function displays a language dropdown box so that the installatioin
  927. * can be done in the language of the user
  928. */
  929. function display_language_selection() { ?>
  930. <h2><?php get_lang('WelcomeToTheDokeosInstaller'); ?></h2>
  931. <div class="RequirementHeading">
  932. <h2><?php echo display_step_sequence(); ?><?php echo get_lang('InstallationLanguage'); ?></h2>
  933. <p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
  934. <form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
  935. <?php display_language_selection_box('language_list', api_get_interface_language()); ?>
  936. <button type="submit" name="step1" class="btn next" value="<?php echo get_lang('Next'); ?>"><?php echo get_lang('Next'); ?></button>
  937. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  938. </form>
  939. </div>
  940. <?php
  941. }
  942. /**
  943. * This function displays the requirements for installing Chamilo.
  944. *
  945. * @param string $installType
  946. * @param boolean $badUpdatePath
  947. * @param string The updatePath given (if given)
  948. * @param array $update_from_version_8 The different subversions from version 1.8
  949. * @param array $update_from_version_6 The different subversions from version 1.6
  950. *
  951. * @author unknow
  952. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  953. */
  954. function display_requirements($installType, $badUpdatePath, $updatePath = '', $update_from_version_8 = array(), $update_from_version_6 = array()) {
  955. global $_setting;
  956. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Requirements')."</h2></div>";
  957. echo '<div class="RequirementText">';
  958. echo '<strong>'.get_lang('ReadThoroughly').'</strong><br />';
  959. echo get_lang('MoreDetails').' <a href="../../documentation/installation_guide.html" target="_blank">'.get_lang('ReadTheInstallGuide').'</a>.<br />'."\n";
  960. if ($installType == 'update') {
  961. echo get_lang('IfYouPlanToUpgradeFromOlderVersionYouMightWantToHaveAlookAtTheChangelog').'<br />';
  962. }
  963. echo '</div>';
  964. // SERVER REQUIREMENTS
  965. echo '<div class="RequirementHeading"><h2>'.get_lang('ServerRequirements').'</h2>';
  966. $timezone = check_php_setting_exists("date.timezone");
  967. if (!$timezone) {
  968. echo "<div class='warning-message'>".Display::return_icon('warning.png',get_lang('Warning'),'',ICON_SIZE_MEDIUM).get_lang("DateTimezoneSettingNotSet")."</div>";
  969. }
  970. echo '<div class="RequirementText">'.get_lang('ServerRequirementsInfo').'</div>';
  971. echo '<div class="RequirementContent">';
  972. echo '<table class="table">
  973. <tr>
  974. <td class="requirements-item">'.get_lang('PHPVersion').' >= '.REQUIRED_PHP_VERSION.'</td>
  975. <td class="requirements-value">';
  976. if (phpversion() < REQUIRED_PHP_VERSION) {
  977. echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
  978. } else {
  979. echo '<strong><font color="green">'.get_lang('PHPVersionOK'). ' '.phpversion().'</font></strong>';
  980. }
  981. echo '</td>
  982. </tr>
  983. <tr>
  984. <td class="requirements-item"><a href="http://php.net/manual/en/book.session.php" target="_blank">Session</a> '.get_lang('support').'</td>
  985. <td class="requirements-value">'.check_extension('session', get_lang('Yes'), get_lang('ExtensionSessionsNotAvailable')).'</td>
  986. </tr>
  987. <tr>
  988. <td class="requirements-item"><a href="http://php.net/manual/en/book.mysql.php" target="_blank">MySQL</a> '.get_lang('support').'</td>
  989. <td class="requirements-value">'.check_extension('mysql', get_lang('Yes'), get_lang('ExtensionMySQLNotAvailable')).'</td>
  990. </tr>
  991. <tr>
  992. <td class="requirements-item"><a href="http://php.net/manual/en/book.zlib.php" target="_blank">Zlib</a> '.get_lang('support').'</td>
  993. <td class="requirements-value">'.check_extension('zlib', get_lang('Yes'), get_lang('ExtensionZlibNotAvailable')).'</td>
  994. </tr>
  995. <tr>
  996. <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>
  997. <td class="requirements-value">'.check_extension('pcre', get_lang('Yes'), get_lang('ExtensionPCRENotAvailable')).'</td>
  998. </tr>
  999. <tr>
  1000. <td class="requirements-item"><a href="http://php.net/manual/en/book.xml.php" target="_blank">XML</a> '.get_lang('support').'</td>
  1001. <td class="requirements-value">'.check_extension('xml', get_lang('Yes'), get_lang('No')).'</td>
  1002. </tr>
  1003. <tr>
  1004. <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>
  1005. <td class="requirements-value">'.check_extension('mbstring', get_lang('Yes'), get_lang('ExtensionMBStringNotAvailable'), true).'</td>
  1006. </tr>
  1007. <tr>
  1008. <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>
  1009. <td class="requirements-value">'.check_extension('iconv', get_lang('Yes'), get_lang('No'), true).'</td>
  1010. </tr>
  1011. <tr>
  1012. <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>
  1013. <td class="requirements-value">'.check_extension('intl', get_lang('Yes'), get_lang('No'), true).'</td>
  1014. </tr>
  1015. <tr>
  1016. <td class="requirements-item"><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a> '.get_lang('support').'</td>
  1017. <td class="requirements-value">'.check_extension('gd', get_lang('Yes'), get_lang('ExtensionGDNotAvailable')).'</td>
  1018. </tr>
  1019. <tr>
  1020. <td class="requirements-item"><a href="http://php.net/manual/en/book.json.php" target="_blank">JSON</a> '.get_lang('support').'</td>
  1021. <td class="requirements-value">'.check_extension('json', get_lang('Yes'), get_lang('No')).'</td>
  1022. </tr>
  1023. <tr>
  1024. <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>
  1025. <td class="requirements-value">'.check_extension('ldap', get_lang('Yes'), get_lang('ExtensionLDAPNotAvailable'), true).'</td>
  1026. </tr>
  1027. <tr>
  1028. <td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  1029. <td class="requirements-value">'.check_extension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
  1030. </tr>
  1031. <tr>
  1032. <td class="requirements-item"><a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  1033. <td class="requirements-value">'.check_extension('curl', get_lang('Yes'), get_lang('No'), true).'</td>
  1034. </tr>
  1035. </table>';
  1036. echo ' </div>';
  1037. echo '</div>';
  1038. // RECOMMENDED SETTINGS
  1039. // Note: these are the settings for Joomla, does this also apply for Chamilo?
  1040. // Note: also add upload_max_filesize here so that large uploads are possible
  1041. echo '<div class="RequirementHeading"><h2>'.get_lang('RecommendedSettings').'</h2>';
  1042. echo '<div class="RequirementText">'.get_lang('RecommendedSettingsInfo').'</div>';
  1043. echo '<div class="RequirementContent">';
  1044. echo '<table class="table">
  1045. <tr>
  1046. <th>'.get_lang('Setting').'</th>
  1047. <th>'.get_lang('Recommended').'</th>
  1048. <th>'.get_lang('Actual').'</th>
  1049. </tr>
  1050. <tr>
  1051. <td class="requirements-item"><a href="http://php.net/manual/features.safe-mode.php">Safe Mode</a></td>
  1052. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1053. <td class="requirements-value">'.check_php_setting('safe_mode','OFF').'</td>
  1054. </tr>
  1055. <tr>
  1056. <td class="requirements-item"><a href="http://php.net/manual/ref.errorfunc.php#ini.display-errors">Display Errors</a></td>
  1057. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1058. <td class="requirements-value">'.check_php_setting('display_errors','OFF').'</td>
  1059. </tr>
  1060. <tr>
  1061. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.file-uploads">File Uploads</a></td>
  1062. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  1063. <td class="requirements-value">'.check_php_setting('file_uploads','ON').'</td>
  1064. </tr>
  1065. <tr>
  1066. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-gpc">Magic Quotes GPC</a></td>
  1067. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1068. <td class="requirements-value">'.check_php_setting('magic_quotes_gpc','OFF').'</td>
  1069. </tr>
  1070. <tr>
  1071. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-runtime">Magic Quotes Runtime</a></td>
  1072. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1073. <td class="requirements-value">'.check_php_setting('magic_quotes_runtime','OFF').'</td>
  1074. </tr>
  1075. <tr>
  1076. <td class="requirements-item"><a href="http://php.net/manual/security.globals.php">Register Globals</a></td>
  1077. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1078. <td class="requirements-value">'.check_php_setting('register_globals','OFF').'</td>
  1079. </tr>
  1080. <tr>
  1081. <td class="requirements-item"><a href="http://php.net/manual/ref.session.php#ini.session.auto-start">Session auto start</a></td>
  1082. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1083. <td class="requirements-value">'.check_php_setting('session.auto_start','OFF').'</td>
  1084. </tr>
  1085. <tr>
  1086. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.short-open-tag">Short Open Tag</a></td>
  1087. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1088. <td class="requirements-value">'.check_php_setting('short_open_tag','OFF').'</td>
  1089. </tr>
  1090. <tr>
  1091. <td class="requirements-item"><a href="http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly">Cookie HTTP Only</a></td>
  1092. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  1093. <td class="requirements-value">'.check_php_setting('session.cookie_httponly','ON').'</td>
  1094. </tr>
  1095. <tr>
  1096. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.upload-max-filesize">Maximum upload file size</a></td>
  1097. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M', 'success').'</td>
  1098. <td class="requirements-value">'.compare_setting_values(ini_get('upload_max_filesize'), REQUIRED_MIN_UPLOAD_MAX_FILESIZE).'</td>
  1099. </tr>
  1100. <tr>
  1101. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.post-max-size">Maximum post size</a></td>
  1102. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_POST_MAX_SIZE.'M', 'success').'</td>
  1103. <td class="requirements-value">'.compare_setting_values(ini_get('post_max_size'), REQUIRED_MIN_POST_MAX_SIZE).'</td>
  1104. </tr>
  1105. <tr>
  1106. <td class="requirements-item"><a href="http://www.php.net/manual/en/ini.core.php#ini.memory-limit">Memory Limit</a></td>
  1107. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_MEMORY_LIMIT.'M', 'success').'</td>
  1108. <td class="requirements-value">'.compare_setting_values(ini_get('memory_limit'), REQUIRED_MIN_MEMORY_LIMIT).'</td>
  1109. </tr>
  1110. </table>';
  1111. echo ' </div>';
  1112. echo '</div>';
  1113. // DIRECTORY AND FILE PERMISSIONS
  1114. echo '<div class="RequirementHeading"><h2>'.get_lang('DirectoryAndFilePermissions').'</h2>';
  1115. echo '<div class="RequirementText">'.get_lang('DirectoryAndFilePermissionsInfo').'</div>';
  1116. echo '<div class="RequirementContent">';
  1117. $course_attempt_name = '__XxTestxX__';
  1118. $course_dir = api_get_path(SYS_COURSE_PATH).$course_attempt_name;
  1119. //Just in case
  1120. @unlink($course_dir.'/test.php');
  1121. @rmdir($course_dir);
  1122. $perms_dir = array(0777, 0755, 0775, 0770, 0750, 0700);
  1123. $perms_fil = array(0666, 0644, 0664, 0660, 0640, 0600);
  1124. $course_test_was_created = false;
  1125. $dir_perm_verified = 0777;
  1126. foreach ($perms_dir as $perm) {
  1127. $r = @mkdir($course_dir, $perm);
  1128. if ($r === true) {
  1129. $dir_perm_verified = $perm;
  1130. $course_test_was_created = true;
  1131. break;
  1132. }
  1133. }
  1134. $fil_perm_verified = 0666;
  1135. $file_course_test_was_created = false;
  1136. if (is_dir($course_dir)) {
  1137. foreach ($perms_fil as $perm) {
  1138. if ($file_course_test_was_created == true) {
  1139. break;
  1140. }
  1141. $r = @touch($course_dir.'/test.php',$perm);
  1142. if ($r === true) {
  1143. $fil_perm_verified = $perm;
  1144. if (check_course_script_interpretation($course_dir, $course_attempt_name, 'test.php')) {
  1145. $file_course_test_was_created = true;
  1146. }
  1147. }
  1148. }
  1149. }
  1150. @unlink($course_dir.'/test.php');
  1151. @rmdir($course_dir);
  1152. $_SESSION['permissions_for_new_directories'] = $_setting['permissions_for_new_directories'] = $dir_perm_verified;
  1153. $_SESSION['permissions_for_new_files'] = $_setting['permissions_for_new_files'] = $fil_perm_verified;
  1154. $dir_perm = Display::label('0'.decoct($dir_perm_verified), 'info');
  1155. $file_perm = Display::label('0'.decoct($fil_perm_verified), 'info');
  1156. $courseTestLabel = Display::label(get_lang('No'), 'important');
  1157. if ($course_test_was_created && $file_course_test_was_created) {
  1158. $courseTestLabel = Display::label(get_lang('Yes'), 'success');
  1159. }
  1160. if ($course_test_was_created && !$file_course_test_was_created) {
  1161. $courseTestLabel = Display::label(
  1162. sprintf(
  1163. get_lang('InstallWarningCouldNotInterpretPHP'),
  1164. api_get_path(WEB_COURSE_PATH).$course_attempt_name.'/test.php'
  1165. ),
  1166. 'warning'
  1167. );
  1168. }
  1169. if (!$course_test_was_created && !$file_course_test_was_created) {
  1170. $courseTestLabel = Display::label(get_lang('No'), 'important');
  1171. }
  1172. echo '<table class="table">
  1173. <tr>
  1174. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'inc/conf/</td>
  1175. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'inc/conf/').'</td>
  1176. </tr>
  1177. <tr>
  1178. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'upload/users/</td>
  1179. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'upload/users/').'</td>
  1180. </tr>
  1181. <tr>
  1182. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'default_course_document/images/</td>
  1183. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'default_course_document/images/').'</td>
  1184. </tr>
  1185. <tr>
  1186. <td class="requirements-item">'.api_get_path(SYS_ARCHIVE_PATH).'</td>
  1187. <td class="requirements-value">'.check_writable(api_get_path(SYS_ARCHIVE_PATH)).'</td>
  1188. </tr>
  1189. <tr>
  1190. <td class="requirements-item">'.api_get_path(SYS_COURSE_PATH).'</td>
  1191. <td class="requirements-value">'.check_writable(api_get_path(SYS_COURSE_PATH)).' </td>
  1192. </tr>
  1193. <tr>
  1194. <td class="requirements-item">'.get_lang('CourseTestWasCreated').'</td>
  1195. <td class="requirements-value">'.$courseTestLabel.' </td>
  1196. </tr>
  1197. <tr>
  1198. <td class="requirements-item">'.get_lang('PermissionsForNewDirs').'</td>
  1199. <td class="requirements-value">'.$dir_perm.' </td>
  1200. </tr>
  1201. <tr>
  1202. <td class="requirements-item">'.get_lang('PermissionsForNewFiles').'</td>
  1203. <td class="requirements-value">'.$file_perm.' </td>
  1204. </tr>
  1205. <tr>
  1206. <td class="requirements-item">'.api_get_path(SYS_PATH).'home/</td>
  1207. <td class="requirements-value">'.check_writable(api_get_path(SYS_PATH).'home/').'</td>
  1208. </tr>
  1209. <tr>
  1210. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'css/</td>
  1211. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'css/', true).' ('.get_lang('SuggestionOnlyToEnableCSSUploadFeature').')</td>
  1212. </tr>
  1213. <tr>
  1214. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'lang/</td>
  1215. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'lang/', true).' ('.get_lang('SuggestionOnlyToEnableSubLanguageFeature').')</td>
  1216. </tr>'.
  1217. //'<tr>
  1218. // <td class="requirements-item">chamilo/searchdb/</td>
  1219. // <td class="requirements-value">'.check_writable('../searchdb/').'</td>
  1220. //</tr>'.
  1221. //'<tr>
  1222. // <td class="requirements-item">'.session_save_path().'</td>
  1223. // <td class="requirements-value">'.(is_writable(session_save_path())
  1224. // ? '<strong><font color="green">'.get_lang('Writable').'</font></strong>'
  1225. // : '<strong><font color="red">'.get_lang('NotWritable').'</font></strong>').'</td>
  1226. //</tr>'.
  1227. '';
  1228. echo ' </table>';
  1229. echo ' </div>';
  1230. echo '</div>';
  1231. if ($installType == 'update' && (empty($updatePath) || $badUpdatePath)) {
  1232. if ($badUpdatePath) { ?>
  1233. <div class="error-message">
  1234. <?php echo get_lang('Error'); ?>!<br />
  1235. Chamilo <?php echo (isset($_POST['step2_update_6']) ? implode('|', $update_from_version_6) : implode('|', $update_from_version_8)).' '.get_lang('HasNotBeenFoundInThatDir'); ?>.
  1236. </div>
  1237. <?php }
  1238. else {
  1239. echo '<br />';
  1240. }
  1241. ?>
  1242. <table border="0" cellpadding="5" align="center">
  1243. <tr>
  1244. <td><?php echo get_lang('OldVersionRootPath'); ?>:</td>
  1245. <td><input type="text" name="updatePath" size="50" value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities($updatePath) : api_get_path(SYS_SERVER_ROOT_PATH).'old_version/'; ?>" /></td>
  1246. </tr>
  1247. <tr>
  1248. <td colspan="2" align="center">
  1249. <button type="submit" class="back" name="step1" value="&lt; <?php echo get_lang('Back'); ?>" ><?php echo get_lang('Back'); ?></button>
  1250. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1251. <button type="submit" class="btn 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>
  1252. </td>
  1253. </tr>
  1254. </table>
  1255. <?php
  1256. } else {
  1257. $error = false;
  1258. // First, attempt to set writing permissions if we don't have them yet
  1259. $perm = api_get_permissions_for_new_directories();
  1260. $perm_file = api_get_permissions_for_new_files();
  1261. $notwritable = array();
  1262. $curdir = getcwd();
  1263. $checked_writable = api_get_path(CONFIGURATION_PATH);
  1264. if (!is_writable($checked_writable)) {
  1265. $notwritable[] = $checked_writable;
  1266. @chmod($checked_writable, $perm);
  1267. }
  1268. $checked_writable = api_get_path(SYS_CODE_PATH).'upload/users/';
  1269. if (!is_writable($checked_writable)) {
  1270. $notwritable[] = $checked_writable;
  1271. @chmod($checked_writable, $perm);
  1272. }
  1273. $checked_writable = api_get_path(SYS_CODE_PATH).'default_course_document/images/';
  1274. if (!is_writable($checked_writable)) {
  1275. $notwritable[] = $checked_writable;
  1276. @chmod($checked_writable, $perm);
  1277. }
  1278. $checked_writable = api_get_path(SYS_ARCHIVE_PATH);
  1279. if (!is_writable($checked_writable)) {
  1280. $notwritable[] = $checked_writable;
  1281. @chmod($checked_writable, $perm);
  1282. }
  1283. $checked_writable = api_get_path(SYS_COURSE_PATH);
  1284. if (!is_writable($checked_writable)) {
  1285. $notwritable[] = $checked_writable;
  1286. @chmod($checked_writable, $perm);
  1287. }
  1288. if ($course_test_was_created == false) {
  1289. $error = true;
  1290. }
  1291. $checked_writable = api_get_path(SYS_PATH).'home/';
  1292. if (!is_writable($checked_writable)) {
  1293. $notwritable[] = realpath($checked_writable);
  1294. @chmod($checked_writable, $perm);
  1295. }
  1296. $checked_writable = api_get_path(CONFIGURATION_PATH).'configuration.php';
  1297. if (file_exists($checked_writable) && !is_writable($checked_writable)) {
  1298. $notwritable[] = $checked_writable;
  1299. @chmod($checked_writable, $perm_file);
  1300. }
  1301. // Second, if this fails, report an error
  1302. //--> The user would have to adjust the permissions manually
  1303. if (count($notwritable) > 0) {
  1304. $error = true;
  1305. echo '<div class="error-message">';
  1306. echo '<center><h3>'.get_lang('Warning').'</h3></center>';
  1307. printf(get_lang('NoWritePermissionPleaseReadInstallGuide'), '</font>
  1308. <a href="../../documentation/installation_guide.html" target="blank">', '</a> <font color="red">');
  1309. echo '</div>';
  1310. echo '<ul>';
  1311. foreach ($notwritable as $value) {
  1312. echo '<li>'.$value.'</li>';
  1313. }
  1314. echo '</ul>';
  1315. }
  1316. // Check wether a Chamilo configuration file already exists.
  1317. elseif (file_exists(api_get_path(CONFIGURATION_PATH).'configuration.php')) {
  1318. echo '<div class="warning-message"><h4><center>';
  1319. echo get_lang('WarningExistingDokeosInstallationDetected');
  1320. echo '</center></h4></div>';
  1321. }
  1322. // And now display the choice buttons (go back or install)
  1323. ?>
  1324. <p align="center" style="padding-top:15px">
  1325. <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>
  1326. <button type="submit" name="step2_install" class="plus" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) echo 'disabled="disabled"'; ?> ><?php echo get_lang('NewInstallation'); ?></button>
  1327. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1328. <?php
  1329. // Real code
  1330. echo '<button type="submit" class="save" name="step2_update_8" value="Upgrade from Dokeos 1.8.x"';
  1331. if ($error) echo ' disabled="disabled"';
  1332. // Temporary code for alpha version, disabling upgrade
  1333. //echo '<input type="submit" name="step2_update" value="Upgrading is not possible in this beta version"';
  1334. //echo ' disabled="disabled"';
  1335. //end temp code
  1336. echo ' >'.get_lang('UpgradeFromDokeos18x').'</button>';
  1337. echo ' <button type="submit" class="save" name="step2_update_6" value="Upgrade from Dokeos 1.6.x"';
  1338. if ($error) echo ' disabled="disabled"';
  1339. echo ' >'.get_lang('UpgradeFromDokeos16x').'</button>';
  1340. echo '</p>';
  1341. }
  1342. }
  1343. /**
  1344. * Displays the license (GNU GPL) as step 2, with
  1345. * - an "I accept" button named step3 to proceed to step 3;
  1346. * - a "Back" button named step1 to go back to the first step.
  1347. */
  1348. function display_license_agreement() {
  1349. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Licence').'</h2>';
  1350. echo '<p>'.get_lang('DokeosLicenseInfo').'</p>';
  1351. echo '<p><a href="../../documentation/license.html" target="_blank">'.get_lang('PrintVers').'</a></p>';
  1352. echo '</div>';
  1353. ?>
  1354. <table>
  1355. <tr><td>
  1356. <pre style="overflow: auto; height: 150px; margin-top: 5px;" class="span7"><?php echo api_htmlentities(@file_get_contents(api_get_path(SYS_PATH).'documentation/license.txt')); ?></pre>
  1357. </td>
  1358. </tr>
  1359. <tr><td>
  1360. <p>
  1361. <label class="checkbox">
  1362. <input type="checkbox" name="accept" id="accept_licence" value="1" />
  1363. <?php echo get_lang('IAccept'); ?>
  1364. </label>
  1365. </p>
  1366. </td>
  1367. </tr>
  1368. <tr><td><p style="color:#666"><br /><?php echo get_lang('DokeosArtLicense'); ?></p></td></tr>
  1369. <tr>
  1370. <td>
  1371. <table width="100%">
  1372. <tr>
  1373. <td></td>
  1374. <td align="center">
  1375. <button type="submit" class="btn back" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
  1376. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1377. <button type="submit" class="btn next" name="step3" onclick="javascript: if(!document.getElementById('accept_licence').checked) { alert('<?php echo get_lang('YouMustAcceptLicence')?>');return false;}" value="<?php echo get_lang('Next'); ?> &gt;" ><?php echo get_lang('Next'); ?></button>
  1378. </td>
  1379. </tr>
  1380. </table>
  1381. </td>
  1382. </tr>
  1383. </table>
  1384. <!-- Contact information form -->
  1385. <div>
  1386. <a href="javascript://" class = "advanced_parameters" >
  1387. <span id="img_plus_and_minus">&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_hide.gif" alt="<?php echo get_lang('Hide') ?>" title="<?php echo get_lang('Hide')?>" style ="vertical-align:middle" />&nbsp;<?php echo get_lang('ContactInformation') ?></span>
  1388. </a>
  1389. </div>
  1390. <div id="id_contact_form" style="display:block">
  1391. <div class="normal-message"><?php echo get_lang('ContactInformationDescription') ?></div>
  1392. <div id="contact_registration">
  1393. <p><?php echo get_contact_registration_form() ?></p><br />
  1394. </div>
  1395. </div>
  1396. <?php
  1397. }
  1398. /**
  1399. * Get contact registration form
  1400. */
  1401. function get_contact_registration_form() {
  1402. $html ='
  1403. <form class="form-horizontal">
  1404. <fieldset style="width:95%;padding:15px;border:1pt solid #eee">
  1405. <div id="div_sent_information"></div>
  1406. <div class="control-group">
  1407. <label class="control-label"><span class="form_required">*</span>'.get_lang('Name').'</label>
  1408. <div class="controls"><input id="person_name" type="text" name="person_name" size="30" /></div>
  1409. </div>
  1410. <div class="control-group">
  1411. <label class="control-label"><span class="form_required">*</span>'.get_lang('Email').'</label>
  1412. <div class="controls"><input id="person_email" type="text" name="person_email" size="30" /></div>
  1413. </div>
  1414. <div class="control-group">
  1415. <label class="control-label"><span class="form_required">*</span>'.get_lang('CompanyName').'</label>
  1416. <div class="controls"><input id="company_name" type="text" name="company_name" size="30" /></div>
  1417. </div>
  1418. <div class="control-group">
  1419. <div class="control-label"><span class="form_required">*</span>'.get_lang('CompanyActivity').'</div>
  1420. <div class="controls">
  1421. <select name="company_activity" id="company_activity" >
  1422. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1423. <Option value="Advertising/Marketing/PR">Advertising/Marketing/PR</Option><Option value="Agriculture/Forestry">Agriculture/Forestry</Option>
  1424. <Option value="Architecture">Architecture</Option><Option value="Banking/Finance">Banking/Finance</Option>
  1425. <Option value="Biotech/Pharmaceuticals">Biotech/Pharmaceuticals</Option><Option value="Business Equipment">Business Equipment</Option>
  1426. <Option value="Business Services">Business Services</Option><Option value="Construction">Construction</Option>
  1427. <Option value="Consulting/Research">Consulting/Research</Option><Option value="Education">Education</Option>
  1428. <Option value="Engineering">Engineering</Option><Option value="Environmental">Environmental</Option>
  1429. <Option value="Government">Government</Option><Option value="Healthcare">Health Care</Option>
  1430. <Option value="Hospitality/Lodging/Travel">Hospitality/Lodging/Travel</Option><Option value="Insurance">Insurance</Option>
  1431. <Option value="Legal">Legal</Option><Option value="Manufacturing">Manufacturing</Option>
  1432. <Option value="Media/Entertainment">Media/Entertainment</Option><Option value="Mortgage">Mortgage</Option>
  1433. <Option value="Non-Profit">Non-Profit</Option><Option value="Real Estate">Real Estate</Option>
  1434. <Option value="Restaurant">Restaurant</Option><Option value="Retail">Retail</Option>
  1435. <Option value="Shipping/Transportation">Shipping/Transportation</Option>
  1436. <Option value="Technology">Technology</Option><Option value="Telecommunications">Telecommunications</Option>
  1437. <Option value="Other">Other</Option>
  1438. </select>
  1439. </div>
  1440. </div>
  1441. <div class="control-group">
  1442. <div class="control-label"><span class="form_required">*</span>'.get_lang('PersonRole').'</div>
  1443. <div class="controls">
  1444. <select name="person_role" id="person_role" >
  1445. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1446. <Option value="Administration">Administration</Option><Option value="CEO/President/ Owner">CEO/President/ Owner</Option>
  1447. <Option value="CFO">CFO</Option><Option value="CIO/CTO">CIO/CTO</Option>
  1448. <Option value="Consultant">Consultant</Option><Option value="Customer Service">Customer Service</Option>
  1449. <Option value="Engineer/Programmer">Engineer/Programmer</Option><Option value="Facilities/Operations">Facilities/Operations</Option>
  1450. <Option value="Finance/ Accounting Manager">Finance/ Accounting Manager</Option><Option value="Finance/ Accounting Staff">Finance/ Accounting Staff</Option>
  1451. <Option value="General Manager">General Manager</Option><Option value="Human Resources">Human Resources</Option>
  1452. <Option value="IS/IT Management">IS/IT Management</Option><Option value="IS/ IT Staff">IS/ IT Staff</Option>
  1453. <Option value="Marketing Manager">Marketing Manager</Option><Option value="Marketing Staff">Marketing Staff</Option>
  1454. <Option value="Partner/Principal">Partner/Principal</Option><Option value="Purchasing Manager">Purchasing Manager</Option>
  1455. <Option value="Sales/ Business Dev. Manager">Sales/ Business Dev. Manager</Option><Option value="Sales/ Business Dev.">Sales/ Business Dev.</Option>
  1456. <Option value="Vice President/Senior Manager">Vice President/Senior Manager</Option><Option value="Other">Other</Option>
  1457. </select>
  1458. </div>
  1459. </div>
  1460. <div class="control-group">
  1461. <div class="control-label"><span class="form_required">*</span>'.get_lang('CompanyCountry').'</div>
  1462. <div class="controls">'.get_countries_list_from_array(true).'</div>
  1463. </div>
  1464. <div class="control-group">
  1465. <div class="control-label">'.get_lang('CompanyCity').'</div>
  1466. <div class="controls">
  1467. <input type="text" id="company_city" name="company_city" size="30" />
  1468. </div>
  1469. </div>
  1470. <div class="control-group">
  1471. <div class="control-label">'.get_lang('WhichLanguageWouldYouLikeToUseWhenContactingYou').'</div>
  1472. <div class="controls">
  1473. <select id="language" name="language">
  1474. <option value="bulgarian">Bulgarian</option>
  1475. <option value="indonesian">Bahasa Indonesia</option>
  1476. <option value="bosnian">Bosanski</option>
  1477. <option value="german">Deutsch</option>
  1478. <option selected="selected" value="english">English</option>
  1479. <option value="spanish">Spanish</option>
  1480. <option value="french">Français</option>
  1481. <option value="italian">Italian</option>
  1482. <option value="hungarian">Magyar</option>
  1483. <option value="dutch">Nederlands</option>
  1484. <option value="brazilian">Português do Brasil</option>
  1485. <option value="portuguese">Português europeu</option>
  1486. <option value="slovenian">Slovenčina</option>
  1487. </select>
  1488. </div>
  1489. </div>
  1490. <div class="control-group">
  1491. <div class="control-label">'.get_lang('HaveYouThePowerToTakeFinancialDecisions').'</div>
  1492. <div class="controls">
  1493. <input type="radio" name="financial_decision" id="financial_decision1" value="1" checked />'.get_lang('Yes').'
  1494. <input type="radio" name="financial_decision" id="financial_decision2" value="0" />'.get_lang('No').'
  1495. </div>
  1496. </div>
  1497. <div class="clear"></div>
  1498. <div class="control-group">
  1499. <div class="control-label">&nbsp;</div>
  1500. <div class="controls"><button type="button" class="save" onclick="javascript:send_contact_information();" value="'.get_lang('SendInformation').'" >'.get_lang('SendInformation').'</button></div>
  1501. </div>
  1502. <div class="control-group">
  1503. <div class="control-label">&nbsp;</div>
  1504. <div class="controls"><span class="form_required">*</span><small>'.get_lang('FieldRequired').'</small></div>
  1505. </div>
  1506. </fieldset></form>';
  1507. return $html;
  1508. }
  1509. /**
  1510. * Displays a parameter in a table row.
  1511. * Used by the display_database_settings_form function.
  1512. * @param string Type of install
  1513. * @param string Name of parameter
  1514. * @param string Field name (in the HTML form)
  1515. * @param string Field value
  1516. * @param string Extra notice (to show on the right side)
  1517. * @param boolean Whether to display in update mode
  1518. * @param string Additional attribute for the <tr> element
  1519. * @return void Direct output
  1520. */
  1521. function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = true, $tr_attribute = '') {
  1522. echo "<tr ".$tr_attribute.">";
  1523. echo "<td>$parameter_name&nbsp;&nbsp;</td>";
  1524. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1525. echo '<td><input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />'.$parameter_value."</td>";
  1526. } else {
  1527. $inputtype = $form_field_name == 'dbPassForm' ? 'password' : 'text';
  1528. //Slightly limit the length of the database prefix to avoid having to cut down the databases names later on
  1529. $maxlength = $form_field_name == 'dbPrefixForm' ? '15' : MAX_FORM_FIELD_LENGTH;
  1530. if ($install_type == INSTALL_TYPE_UPDATE) {
  1531. echo '<input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />';
  1532. echo '<td>'.api_htmlentities($parameter_value)."</td>";
  1533. } else {
  1534. 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>";
  1535. echo "<td>$extra_notice</td>";
  1536. }
  1537. }
  1538. echo "</tr>";
  1539. }
  1540. /**
  1541. * Displays step 3 - a form where the user can enter the installation settings
  1542. * regarding the databases - login and password, names, prefixes, single
  1543. * or multiple databases, tracking or not...
  1544. */
  1545. function display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm) {
  1546. if ($installType == 'update') {
  1547. global $_configuration, $update_from_version_6;
  1548. if (in_array($_POST['old_version'], $update_from_version_6)) {
  1549. $dbHostForm = get_config_param('dbHost');
  1550. $dbUsernameForm = get_config_param('dbLogin');
  1551. $dbPassForm = get_config_param('dbPass');
  1552. $dbPrefixForm = get_config_param('dbNamePrefix');
  1553. $enableTrackingForm = get_config_param('is_trackingEnabled');
  1554. $singleDbForm = get_config_param('singleDbEnabled');
  1555. $dbHostForm = get_config_param('mainDbName');
  1556. $dbStatsForm = get_config_param('statsDbName');
  1557. $dbScormForm = get_config_param('scormDbName');
  1558. $dbUserForm = get_config_param('user_personal_database');
  1559. $dbScormExists = true;
  1560. } else {
  1561. $dbHostForm = $_configuration['db_host'];
  1562. $dbUsernameForm = $_configuration['db_user'];
  1563. $dbPassForm = $_configuration['db_password'];
  1564. $dbPrefixForm = $_configuration['db_prefix'];
  1565. $enableTrackingForm = $_configuration['tracking_enabled'];
  1566. $singleDbForm = $_configuration['single_database'];
  1567. $dbNameForm = $_configuration['main_database'];
  1568. $dbStatsForm = $_configuration['statistics_database'];
  1569. $dbScormForm = $_configuration['scorm_database'];
  1570. $dbUserForm = $_configuration['user_personal_database'];
  1571. $dbScormExists = true;
  1572. }
  1573. if (empty($dbScormForm)) {
  1574. if ($singleDbForm) {
  1575. $dbScormForm = $dbNameForm;
  1576. } else {
  1577. $dbScormForm = $dbPrefixForm.'scorm';
  1578. $dbScormExists = false;
  1579. }
  1580. }
  1581. if (empty($dbUserForm)) {
  1582. $dbUserForm = $singleDbForm ? $dbNameForm : $dbPrefixForm.'chamilo_user';
  1583. }
  1584. echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
  1585. echo '<div class="RequirementContent">';
  1586. echo get_lang('DBSettingUpgradeIntro');
  1587. echo '</div>';
  1588. } else {
  1589. if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix
  1590. $dbPrefixForm = '';
  1591. }
  1592. echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
  1593. echo '<div class="RequirementContent">';
  1594. echo get_lang('DBSettingIntro');
  1595. echo '</div>';
  1596. }
  1597. ?>
  1598. </td>
  1599. </tr>
  1600. <tr>
  1601. <td>
  1602. <table class="data_table_no_border">
  1603. <tr>
  1604. <td width="40%"><?php echo get_lang('DBHost'); ?> </td>
  1605. <?php if ($installType == 'update'): ?>
  1606. <td width="30%"><input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?></td>
  1607. <td width="30%">&nbsp;</td>
  1608. <?php else: ?>
  1609. <td width="30%"><input type="text" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /></td>
  1610. <td width="30%"><?php echo get_lang('EG').' localhost'; ?></td>
  1611. <?php endif; ?>
  1612. </tr>
  1613. <tr>
  1614. <?php
  1615. //database user username
  1616. $example_login = get_lang('EG').' root';
  1617. display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
  1618. //database user password
  1619. $example_password = get_lang('EG').' '.api_generate_password();
  1620. display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password);
  1621. echo '<input type="hidden" name="enableTrackingForm" value="1" />';
  1622. $style = '';
  1623. if ($installType == INSTALL_TYPE_UPDATE) {
  1624. $style = '';
  1625. }
  1626. //Database Name fix replace weird chars
  1627. if ($installType != INSTALL_TYPE_UPDATE) {
  1628. $dbNameForm = str_replace(array('-','*', '$', ' ', '.'), '', $dbNameForm);
  1629. $dbNameForm = replace_dangerous_char($dbNameForm);
  1630. }
  1631. display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;', null, 'id="optional_param1" '.$style);
  1632. //Only for updates we show this options
  1633. if ($installType == INSTALL_TYPE_UPDATE) {
  1634. display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, '&nbsp;', null, 'id="optional_param2" '.$style);
  1635. if ($installType == INSTALL_TYPE_UPDATE && in_array($_POST['old_version'], $update_from_version_6)) {
  1636. display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" '.$style);
  1637. }
  1638. display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;', null, 'id="optional_param4" '.$style);
  1639. }
  1640. ?>
  1641. <tr>
  1642. <td></td>
  1643. <td>
  1644. <button type="submit" class="btn" name="step3" value="<?php echo get_lang('CheckDatabaseConnection'); ?>" >
  1645. <?php echo get_lang('CheckDatabaseConnection'); ?></button>
  1646. </td>
  1647. </tr>
  1648. <tr>
  1649. <td>
  1650. <?php
  1651. $dbConnect = test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm);
  1652. $database_exists_text = '';
  1653. if (database_exists($dbNameForm)) {
  1654. $database_exists_text = '<div class="warning-message">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>';
  1655. } else {
  1656. if ($dbConnect == -1) {
  1657. $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm).'</div>';
  1658. } else {
  1659. //Try to create the database
  1660. $user_can_create_databases = false;
  1661. $multipleDbCheck = @Database::query("CREATE DATABASE ".mysql_real_escape_string($dbNameForm));
  1662. if ($multipleDbCheck !== false) {
  1663. $multipleDbCheck = @Database::query("DROP DATABASE IF EXISTS ".mysql_real_escape_string($dbNameForm));
  1664. $user_can_create_databases = true;
  1665. }
  1666. if ($user_can_create_databases) {
  1667. $database_exists_text = '<div class="normal-message">'.sprintf(get_lang('DatabaseXWillBeCreated'), $dbNameForm, $dbUsernameForm).'</div>';
  1668. } else {
  1669. $dbConnect = 0;
  1670. $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm).'</div>';
  1671. }
  1672. }
  1673. }
  1674. if ($dbConnect == 1): ?>
  1675. <td colspan="2">
  1676. <?php echo $database_exists_text ?>
  1677. <div id="db_status" class="confirmation-message">
  1678. Database host: <strong><?php echo Database::get_host_info(); ?></strong><br />
  1679. Database server version: <strong><?php echo Database::get_server_info(); ?></strong><br />
  1680. Database client version: <strong><?php echo Database::get_client_info(); ?></strong><br />
  1681. Database protocol version: <strong><?php echo Database::get_proto_info(); ?></strong>
  1682. <div style="clear:both;"></div>
  1683. </div>
  1684. </td>
  1685. <?php else: ?>
  1686. <td colspan="2">
  1687. <?php echo $database_exists_text ?>
  1688. <div id="db_status" style="float:left;" class="error-message">
  1689. <div style="float:left;">
  1690. <strong><?php echo get_lang('FailedConectionDatabase'); ?></strong><br />
  1691. <strong>Database error: <?php echo Database::errno(); ?></strong><br />
  1692. <?php echo Database::error().'<br />'; ?>
  1693. </div>
  1694. </div>
  1695. </td>
  1696. <?php endif; ?>
  1697. </tr>
  1698. <tr>
  1699. <td>
  1700. <button type="submit" name="step2" class="back" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
  1701. </td>
  1702. <td>&nbsp;</td>
  1703. <td align="right">
  1704. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1705. <?php if ($dbConnect == 1) { ?>
  1706. <button type="submit" class="btn next" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" /><?php echo get_lang('Next'); ?></button>
  1707. <?php } else { ?>
  1708. <button disabled="disabled" type="submit" class="btn next disabled" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" /><?php echo get_lang('Next'); ?></button>
  1709. <?php } ?>
  1710. </td>
  1711. </tr>
  1712. </table>
  1713. <?php
  1714. }
  1715. /**
  1716. * Displays a parameter in a table row.
  1717. * Used by the display_configuration_settings_form function.
  1718. */
  1719. function display_configuration_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $display_when_update = 'true') {
  1720. echo "<tr>";
  1721. echo "<td>$parameter_name</td>";
  1722. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1723. echo '<td><input type="hidden" name="'.$form_field_name.'" value="'.api_htmlentities($parameter_value, ENT_QUOTES).'" />'.$parameter_value."</td>\n";
  1724. } else {
  1725. 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";
  1726. }
  1727. echo "</tr>";
  1728. }
  1729. /**
  1730. * Displays step 4 of the installation - configuration settings about Chamilo itself.
  1731. */
  1732. function display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm) {
  1733. if ($installType != 'update' && empty($languageForm)) {
  1734. $languageForm = $_SESSION['install_language'];
  1735. }
  1736. echo '<div class="RequirementHeading">';
  1737. echo "<h2>" . display_step_sequence() . get_lang("CfgSetting") . "</h2>";
  1738. echo '</div>';
  1739. echo '<div class="RequirementContent">';
  1740. echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>main/inc/conf/configuration.php</strong></p>';
  1741. echo '</div>';
  1742. echo '<fieldset>';
  1743. echo '<legend>'.get_lang('Administrator').'</legend>';
  1744. echo '<table class="data_table_no_border">';
  1745. //Parameter 1: administrator's login
  1746. display_configuration_parameter($installType, get_lang('AdminLogin'), 'loginForm', $loginForm, $installType == 'update');
  1747. //Parameter 2: administrator's password
  1748. if ($installType != 'update') {
  1749. display_configuration_parameter($installType, get_lang('AdminPass'), 'passForm', $passForm, false);
  1750. }
  1751. //Parameters 3 and 4: administrator's names
  1752. if (api_is_western_name_order()) {
  1753. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1754. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1755. } else {
  1756. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1757. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1758. }
  1759. //Parameter 3: administrator's email
  1760. display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
  1761. //Parameter 6: administrator's telephone
  1762. display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
  1763. echo '</table>';
  1764. echo '</fieldset>';
  1765. echo '<fieldset>';
  1766. echo '<legend>'.get_lang('Platform').'</legend>';
  1767. echo '<table class="data_table_no_border">';
  1768. //First parameter: language
  1769. echo "<tr>";
  1770. echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>";
  1771. if ($installType == 'update') {
  1772. echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm."</td>";
  1773. } else { // new installation
  1774. echo '<td>';
  1775. display_language_selection_box('languageForm', $languageForm);
  1776. echo "</td>\n";
  1777. }
  1778. echo "</tr>\n";
  1779. //Second parameter: Chamilo URL
  1780. echo "<tr>";
  1781. echo '<td>'.get_lang('ChamiloURL').' (<font color="red">'.get_lang('ThisFieldIsRequired')."</font>)&nbsp;&nbsp;</td>";
  1782. if ($installType == 'update') {
  1783. echo '<td>'.api_htmlentities($urlForm, ENT_QUOTES)."</td>\n";
  1784. } else {
  1785. echo '<td><input type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities($urlForm, ENT_QUOTES).'" />'."</td>";
  1786. }
  1787. echo "</tr>";
  1788. //Parameter 9: campus name
  1789. display_configuration_parameter($installType, get_lang('CampusName'), 'campusForm', $campusForm);
  1790. //Parameter 10: institute (short) name
  1791. display_configuration_parameter($installType, get_lang('InstituteShortName'), 'institutionForm', $institutionForm);
  1792. //Parameter 11: institute (short) name
  1793. display_configuration_parameter($installType, get_lang('InstituteURL'), 'institutionUrlForm', $institutionUrlForm);
  1794. ?>
  1795. <tr>
  1796. <td><?php echo get_lang("EncryptMethodUserPass"); ?> :</td>
  1797. <?php if ($installType == 'update') { ?>
  1798. <td><input type="hidden" name="encryptPassForm" value="<?php echo $encryptPassForm; ?>" /><?php echo $encryptPassForm; ?></td>
  1799. <?php } else { ?>
  1800. <td>
  1801. <div class="control-group">
  1802. <label class="radio inline">
  1803. <input type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" <?php echo ($encryptPassForm == 'sha1') ? 'checked="checked" ': ''; ?>/><?php echo 'sha1'; ?>
  1804. </label>
  1805. <label class="radio inline">
  1806. <input type="radio" name="encryptPassForm" value="md5" id="encryptPass0" <?php echo $encryptPassForm == 1 ? 'checked="checked" ' : ''; ?>/><?php echo 'md5'; ?>
  1807. </label>
  1808. <label class="radio inline">
  1809. <input type="radio" name="encryptPassForm" value="none" id="encryptPass2" <?php echo $encryptPassForm === '0' or $encryptPassForm === 0 ? 'checked="checked" ':''; ?>/><?php echo get_lang('None'); ?>
  1810. </label>
  1811. </div>
  1812. </td>
  1813. <?php } ?>
  1814. </tr>
  1815. <tr>
  1816. <td><?php echo get_lang('AllowSelfReg'); ?> :</td>
  1817. <?php if ($installType == 'update'): ?>
  1818. <td><input type="hidden" name="allowSelfReg" value="<?php echo $allowSelfReg; ?>" /><?php echo $allowSelfReg ? get_lang('Yes') : get_lang('No'); ?></td>
  1819. <?php else: ?>
  1820. <td>
  1821. <div class="control-group">
  1822. <label class="radio inline">
  1823. <input type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" <?php echo $allowSelfReg ? 'checked="checked" ' : ''; ?>/> <?php echo get_lang('Yes'); ?>
  1824. </label>
  1825. <label class="radio inline">
  1826. <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" <?php echo $allowSelfReg ? '' : 'checked="checked" '; ?>/><?php echo get_lang('No'); ?>
  1827. </label>
  1828. </div>
  1829. </td>
  1830. <?php endif; ?>
  1831. </tr>
  1832. <tr>
  1833. <td><?php echo get_lang('AllowSelfRegProf'); ?> :</td>
  1834. <?php if ($installType == 'update'): ?>
  1835. <td><input type="hidden" name="allowSelfRegProf" value="<?php echo $allowSelfRegProf; ?>" /><?php echo $allowSelfRegProf? get_lang('Yes') : get_lang('No'); ?></td>
  1836. <?php else: ?>
  1837. <td>
  1838. <div class="control-group">
  1839. <label class="radio inline">
  1840. <input type="radio" name="allowSelfRegProf" value="1" id="allowSelfRegProf1" <?php echo $allowSelfRegProf ? 'checked="checked" ' : ''; ?>/>
  1841. <?php echo get_lang('Yes'); ?>
  1842. </label>
  1843. <label class="radio inline">
  1844. <input type="radio" name="allowSelfRegProf" value="0" id="allowSelfRegProf0" <?php echo $allowSelfRegProf ? '' : 'checked="checked" '; ?>/>
  1845. <?php echo get_lang('No'); ?>
  1846. </label>
  1847. </div>
  1848. </td>
  1849. <?php endif; ?>
  1850. </tr>
  1851. <tr>
  1852. <td>
  1853. <button type="submit" class="btn back" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>" /><?php echo get_lang('Previous'); ?></button>
  1854. </td>
  1855. <td align="right">
  1856. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1857. <button class="btn next" type="submit" name="step5" value="<?php echo get_lang('Next'); ?> &gt;" /><?php echo get_lang('Next'); ?></button></td>
  1858. </tr>
  1859. </fieldset>
  1860. </table>
  1861. <?php
  1862. }
  1863. /**
  1864. * After installation is completed (step 6), this message is displayed.
  1865. */
  1866. function display_after_install_message($installType) {
  1867. echo '<div class="RequirementContent">'.get_lang('FirstUseTip').'</div>';
  1868. echo '<div class="warning-message">';
  1869. echo '<strong>'.get_lang('SecurityAdvice').'</strong>';
  1870. echo ': ';
  1871. printf(get_lang('ToProtectYourSiteMakeXReadOnlyAndDeleteY'), 'main/inc/conf/', 'main/install/');
  1872. echo '</div>';
  1873. ?></form>
  1874. <br />
  1875. <a class="btn btn-success btn-large btn-install" href="../../index.php"><?php echo get_lang('GoToYourNewlyCreatedPortal'); ?></a>
  1876. <?php
  1877. }
  1878. /**
  1879. * This function return countries list from array (hardcoded)
  1880. * @param bool (Optional) True for returning countries list with select html
  1881. * @return array|string countries list
  1882. */
  1883. function get_countries_list_from_array($combo = false) {
  1884. $a_countries = array(
  1885. "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan",
  1886. "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
  1887. "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic", "Chad", "Chile", "China", "Colombi", "Comoros", "Congo (Brazzaville)", "Congo", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic",
  1888. "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  1889. "East Timor (Timor Timur)", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia",
  1890. "Fiji", "Finland", "France",
  1891. "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana",
  1892. "Haiti", "Honduras", "Hungary",
  1893. "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy",
  1894. "Jamaica", "Japan", "Jordan",
  1895. "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan",
  1896. "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
  1897. "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Myanmar",
  1898. "Namibia", "Nauru", "Nepa", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway",
  1899. "Oman",
  1900. "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland","Portugal",
  1901. "Qatar",
  1902. "Romania", "Russia", "Rwanda",
  1903. "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria",
  1904. "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu",
  1905. "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan",
  1906. "Vanuatu", "Vatican City", "Venezuela", "Vietnam",
  1907. "Yemen",
  1908. "Zambia", "Zimbabwe"
  1909. );
  1910. $country_select = '';
  1911. if ($combo) {
  1912. $country_select = '<select id="country" name="country">';
  1913. $country_select .= '<option value="">--- '.get_lang('SelectOne').' ---</option>';
  1914. foreach ($a_countries as $country) {
  1915. $country_select .= '<option value="'.$country.'">'.$country.'</option>';
  1916. }
  1917. $country_select .= '</select>';
  1918. return $country_select;
  1919. }
  1920. return $a_countries;
  1921. }
  1922. /**
  1923. * Lockis settings that can't be changed in other portals
  1924. */
  1925. function locking_settings() {
  1926. $access_url_locked_settings = api_get_locked_settings();
  1927. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1928. foreach ($access_url_locked_settings as $setting) {
  1929. $sql = "UPDATE $table SET access_url_locked = 1 WHERE variable = '$setting'";
  1930. Database::query($sql);
  1931. }
  1932. }
  1933. function update_dir_and_files_permissions() {
  1934. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1935. $permissions_for_new_directories = isset($_SESSION['permissions_for_new_directories']) ? $_SESSION['permissions_for_new_directories'] : 0770;
  1936. $permissions_for_new_files = isset($_SESSION['permissions_for_new_files']) ? $_SESSION['permissions_for_new_files'] : 0660;
  1937. // use decoct() to store as string
  1938. $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_directories)."' WHERE variable = 'permissions_for_new_directories'";
  1939. Database::query($sql);
  1940. $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_files)."' WHERE variable = 'permissions_for_new_files'";
  1941. Database::query($sql);
  1942. unset($_SESSION['permissions_for_new_directories']);
  1943. unset($_SESSION['permissions_for_new_files']);
  1944. }
  1945. function compare_setting_values($current_value, $wanted_value) {
  1946. $current_value_string = $current_value;
  1947. $current_value = (float)$current_value;
  1948. $wanted_value = (float)$wanted_value;
  1949. if ($current_value >= $wanted_value) {
  1950. return Display::label($current_value_string, 'success');
  1951. } else {
  1952. return Display::label($current_value_string, 'important');
  1953. }
  1954. }
  1955. function check_course_script_interpretation($course_dir, $course_attempt_name, $file = 'test.php')
  1956. {
  1957. $output = false;
  1958. //Write in file
  1959. $file_name = $course_dir.'/'.$file;
  1960. $content = '<?php echo "123"; exit;';
  1961. if (is_writable($file_name)) {
  1962. if ($handler = @fopen($file_name, "w")) {
  1963. //write content
  1964. if (fwrite($handler, $content)) {
  1965. $sock_errno = '';
  1966. $sock_errmsg = '';
  1967. $url = api_get_path(WEB_COURSE_PATH).$course_attempt_name.'/'.$file;
  1968. $parsed_url = parse_url($url);
  1969. //$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : ''; //http
  1970. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  1971. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
  1972. $port = isset($parsed_url['port']) ? $parsed_url['port'] : '80';
  1973. //Check fsockopen (doesn't work with https)
  1974. if ($fp = @fsockopen(str_replace('http://', '', $url), -1, $sock_errno, $sock_errmsg, 60)) {
  1975. $out = "GET $path HTTP/1.1\r\n";
  1976. $out .= "Host: $host\r\n";
  1977. $out .= "Connection: Close\r\n\r\n";
  1978. fwrite($fp, $out);
  1979. while (!feof($fp)) {
  1980. $result = str_replace("\r\n", '',fgets($fp, 128));
  1981. if (!empty($result) && $result == '123') {
  1982. $output = true;
  1983. }
  1984. }
  1985. fclose($fp);
  1986. //Check allow_url_fopen
  1987. } elseif (ini_get('allow_url_fopen')) {
  1988. if ($fp = @fopen($url, 'r')) {
  1989. while ($result = fgets($fp, 1024)) {
  1990. if (!empty($result) && $result == '123') {
  1991. $output = true;
  1992. }
  1993. }
  1994. fclose($fp);
  1995. }
  1996. // Check if has support for cURL
  1997. } elseif (function_exists('curl_init')) {
  1998. $ch = curl_init();
  1999. curl_setopt($ch, CURLOPT_HEADER, 0);
  2000. curl_setopt($ch, CURLOPT_URL, $url);
  2001. //curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  2002. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2003. $result = curl_exec ($ch);
  2004. if (!empty($result) && $result == '123') {
  2005. $output = true;
  2006. }
  2007. curl_close($ch);
  2008. }
  2009. }
  2010. @fclose($handler);
  2011. }
  2012. }
  2013. return $output;
  2014. }