install.lib.php 85 KB

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