install.lib.php 104 KB

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