install.lib.php 111 KB

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