install.lib.php 111 KB

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