install.lib.php 93 KB

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