install.lib.php 91 KB

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