install.lib.php 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633
  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. <i class="fa fa-forward"> </i>
  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.mbstring.php" target="_blank">Multibyte string</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  683. <td class="requirements-value">'.checkExtension('mbstring', get_lang('Yes'), get_lang('ExtensionMBStringNotAvailable'), true).'</td>
  684. </tr>
  685. <tr>
  686. <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>
  687. <td class="requirements-value">'.checkExtension('iconv', get_lang('Yes'), get_lang('No'), true).'</td>
  688. </tr>
  689. <tr>
  690. <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>
  691. <td class="requirements-value">'.checkExtension('ldap', get_lang('Yes'), get_lang('ExtensionLDAPNotAvailable'), true).'</td>
  692. </tr>
  693. <tr>
  694. <td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  695. <td class="requirements-value">'.checkExtension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
  696. </tr>
  697. <tr>
  698. <td class="requirements-item"><a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  699. <td class="requirements-value">'.checkExtension('curl', 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. <i class="fa fa-backward"> <?php echo get_lang('Back'); ?></i>
  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. <i class="fa fa-forward"> </i> <?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. <i class="fa fa-backward"> </i> <?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. <i class="fa fa-forward"> </i> <?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 ' ><i class="fa fa-forward"> </i> '.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. </div>
  1002. </div>
  1003. <div class="row">
  1004. <div class="col-md-12">
  1005. <p class="alert alert-info"><?php echo get_lang('LMSMediaLicense'); ?></p>
  1006. <button type="submit" class="btn btn-default" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" >
  1007. <i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?>
  1008. </button>
  1009. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1010. <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;" >
  1011. <i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?>
  1012. </button>
  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" 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" 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" 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" 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. <input type="radio" name="financial_decision" id="financial_decision1" value="1" checked />'.get_lang('Yes').'
  1127. <input type="radio" name="financial_decision" id="financial_decision2" value="0" />'.get_lang('No').'
  1128. </div>
  1129. </div>
  1130. <div class="clear"></div>
  1131. <div class="form-group">
  1132. <div class="col-sm-3">&nbsp;</div>
  1133. <div class="col-sm-9"><button type="button" class="btn btn-default" onclick="javascript:send_contact_information();" value="'.get_lang('SendInformation').'" ><i class="fa fa-floppy-o"> </i> '.get_lang('SendInformation').'</button></div>
  1134. </div>
  1135. <div class="form-group">
  1136. <div class="col-sm-3">&nbsp;</div>
  1137. <div class="col-sm-9"><span class="form_required">*</span><small>'.get_lang('FieldRequired').'</small></div>
  1138. </div></div></div>
  1139. </form>';
  1140. return $html;
  1141. }
  1142. /**
  1143. * Displays a parameter in a table row.
  1144. * Used by the display_database_settings_form function.
  1145. * @param string Type of install
  1146. * @param string Name of parameter
  1147. * @param string Field name (in the HTML form)
  1148. * @param string Field value
  1149. * @param string Extra notice (to show on the right side)
  1150. * @param boolean Whether to display in update mode
  1151. * @param string Additional attribute for the <tr> element
  1152. * @return void Direct output
  1153. */
  1154. function displayDatabaseParameter(
  1155. $installType,
  1156. $parameterName,
  1157. $formFieldName,
  1158. $parameterValue,
  1159. $extra_notice,
  1160. $displayWhenUpdate = true,
  1161. $tr_attribute = ''
  1162. ) {
  1163. //echo "<tr ".$tr_attribute.">";
  1164. echo "<label class='col-sm-4'>$parameterName</label>";
  1165. if ($installType == INSTALL_TYPE_UPDATE && $displayWhenUpdate) {
  1166. echo '<input type="hidden" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />'.$parameterValue;
  1167. } else {
  1168. $inputType = $formFieldName == 'dbPassForm' ? 'password' : 'text';
  1169. //Slightly limit the length of the database prefix to avoid having to cut down the databases names later on
  1170. $maxLength = $formFieldName == 'dbPrefixForm' ? '15' : MAX_FORM_FIELD_LENGTH;
  1171. if ($installType == INSTALL_TYPE_UPDATE) {
  1172. echo '<input type="hidden" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />';
  1173. echo api_htmlentities($parameterValue);
  1174. } else {
  1175. echo '<div class="col-sm-5"><input type="'.$inputType.'" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxLength.'" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />'."</div>";
  1176. echo '<div class="col-sm-3">' . $extra_notice . '</div>';
  1177. }
  1178. }
  1179. }
  1180. /**
  1181. * Displays step 3 - a form where the user can enter the installation settings
  1182. * regarding the databases - login and password, names, prefixes, single
  1183. * or multiple databases, tracking or not...
  1184. * @param string $installType
  1185. * @param string $dbHostForm
  1186. * @param string $dbUsernameForm
  1187. * @param string $dbPassForm
  1188. * @param string $dbNameForm
  1189. * @param int $dbPortForm
  1190. * @param string $installationProfile
  1191. */
  1192. function display_database_settings_form(
  1193. $installType,
  1194. $dbHostForm,
  1195. $dbUsernameForm,
  1196. $dbPassForm,
  1197. $dbNameForm,
  1198. $dbPortForm = 3306,
  1199. $installationProfile = ''
  1200. ) {
  1201. if ($installType == 'update') {
  1202. global $_configuration;
  1203. $dbHostForm = $_configuration['db_host'];
  1204. $dbUsernameForm = $_configuration['db_user'];
  1205. $dbPassForm = $_configuration['db_password'];
  1206. $dbNameForm = $_configuration['main_database'];
  1207. $dbPortForm = isset($_configuration['db_port']) ? $_configuration['db_port'] : '';
  1208. echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
  1209. echo '<div class="RequirementContent">';
  1210. echo get_lang('DBSettingUpgradeIntro');
  1211. echo '</div>';
  1212. } else {
  1213. echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
  1214. echo '<div class="RequirementContent">';
  1215. echo get_lang('DBSettingIntro');
  1216. echo '</div>';
  1217. }
  1218. ?>
  1219. <div class="panel panel-default">
  1220. <div class="panel-body">
  1221. <div class="form-group">
  1222. <label class="col-sm-4"><?php echo get_lang('DBHost'); ?> </label>
  1223. <?php if ($installType == 'update'){ ?>
  1224. <div class="col-sm-5">
  1225. <input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?>
  1226. </div>
  1227. <div class="col-sm-3"></div>
  1228. <?php }else{ ?>
  1229. <div class="col-sm-5">
  1230. <input type="text" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" />
  1231. </div>
  1232. <div class="col-sm-3"><?php echo get_lang('EG').' localhost'; ?></div>
  1233. <?php } ?>
  1234. </div>
  1235. <div class="form-group">
  1236. <label class="col-sm-4"><?php echo get_lang('DBPort'); ?> </label>
  1237. <?php if ($installType == 'update'){ ?>
  1238. <div class="col-sm-5">
  1239. <input type="hidden" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" /><?php echo $dbPortForm; ?>
  1240. </div>
  1241. <div class="col-sm-3"></div>
  1242. <?php }else{ ?>
  1243. <div class="col-sm-5">
  1244. <input type="text" size="25" maxlength="50" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" />
  1245. </div>
  1246. <div class="col-sm-3"><?php echo get_lang('EG').' 3306'; ?></div>
  1247. <?php } ?>
  1248. </div>
  1249. <div class="form-group">
  1250. <?php
  1251. //database user username
  1252. $example_login = get_lang('EG').' root';
  1253. displayDatabaseParameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
  1254. ?>
  1255. </div>
  1256. <div class="form-group">
  1257. <?php
  1258. //database user password
  1259. $example_password = get_lang('EG').' '.api_generate_password();
  1260. displayDatabaseParameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password);
  1261. ?>
  1262. </div>
  1263. <div class="form-group">
  1264. <?php
  1265. //Database Name fix replace weird chars
  1266. if ($installType != INSTALL_TYPE_UPDATE) {
  1267. $dbNameForm = str_replace(array('-','*', '$', ' ', '.'), '', $dbNameForm);
  1268. $dbNameForm = api_replace_dangerous_char($dbNameForm);
  1269. }
  1270. displayDatabaseParameter(
  1271. $installType,
  1272. get_lang('MainDB'),
  1273. 'dbNameForm',
  1274. $dbNameForm,
  1275. '&nbsp;',
  1276. null,
  1277. 'id="optional_param1"'
  1278. );
  1279. ?>
  1280. </div>
  1281. <?php if ($installType != INSTALL_TYPE_UPDATE) { ?>
  1282. <div class="form-group">
  1283. <div class="col-sm-3"></div>
  1284. <div class="col-sm-9">
  1285. <button type="submit" class="btn btn-primary" name="step3" value="step3">
  1286. <i class="fa fa-refresh"> </i>
  1287. <?php echo get_lang('CheckDatabaseConnection'); ?>
  1288. </button>
  1289. </div>
  1290. </div>
  1291. <?php } ?>
  1292. </div>
  1293. </div>
  1294. <?php
  1295. $database_exists_text = '';
  1296. $manager = null;
  1297. try {
  1298. $manager = connectToDatabase(
  1299. $dbHostForm,
  1300. $dbUsernameForm,
  1301. $dbPassForm,
  1302. null,
  1303. $dbPortForm
  1304. );
  1305. $databases = $manager->getConnection()->getSchemaManager()->listDatabases();
  1306. if (in_array($dbNameForm, $databases)) {
  1307. $database_exists_text = '<div class="alert alert-warning">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>';
  1308. }
  1309. } catch (Exception $e) {
  1310. $database_exists_text = $e->getMessage();
  1311. }
  1312. if ($manager->getConnection()->isConnected()): ?>
  1313. <?php echo $database_exists_text ?>
  1314. <div id="db_status" class="alert alert-success">
  1315. Database host: <strong><?php echo $manager->getConnection()->getHost(); ?></strong><br />
  1316. Database port: <strong><?php echo $manager->getConnection()->getPort(); ?></strong><br />
  1317. Database driver: <strong><?php echo $manager->getConnection()->getDriver()->getName(); ?></strong><br />
  1318. </div>
  1319. <?php else: ?>
  1320. <?php echo $database_exists_text ?>
  1321. <div id="db_status" style="float:left;" class="alert alert-danger">
  1322. <div style="float:left;">
  1323. <?php echo get_lang('FailedConectionDatabase'); ?></strong>
  1324. </div>
  1325. </div>
  1326. <?php endif; ?>
  1327. <div class="form-group">
  1328. <div class="col-sm-6">
  1329. <button type="submit" name="step2" class="btn btn-default pull-right" value="&lt; <?php echo get_lang('Previous'); ?>" >
  1330. <i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?>
  1331. </button>
  1332. </div>
  1333. <div class="col-sm-6">
  1334. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1335. <?php if ($manager) { ?>
  1336. <button type="submit" class="btn btn-success" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" >
  1337. <i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?>
  1338. </button>
  1339. <?php } else { ?>
  1340. <button disabled="disabled" type="submit" class="btn btn-success disabled" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" >
  1341. <i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?>
  1342. </button>
  1343. <?php } ?>
  1344. </div>
  1345. </div>
  1346. <?php
  1347. }
  1348. function panel($content = null, $title = null, $id = null, $style = null) {
  1349. $html = '';
  1350. if (empty($style)) {
  1351. $style = 'default';
  1352. }
  1353. if (!empty($title)) {
  1354. $panelTitle = Display::div($title, array('class' => 'panel-heading'));
  1355. $panelBody = Display::div($content, array('class' => 'panel-body'));
  1356. $panelParent = Display::div($panelTitle . $panelBody, array('id' => $id, 'class' => 'panel panel-'.$style));
  1357. } else {
  1358. $panelBody = Display::div($html, array('class' => 'panel-body'));
  1359. $panelParent = Display::div($panelBody, array('id' => $id, 'class' => 'panel panel-'.$style));
  1360. }
  1361. $html .= $panelParent;
  1362. return $html;
  1363. }
  1364. /**
  1365. * Displays a parameter in a table row.
  1366. * Used by the display_configuration_settings_form function.
  1367. * @param string $installType
  1368. * @param string $parameterName
  1369. * @param string $formFieldName
  1370. * @param string $parameterValue
  1371. * @param string $displayWhenUpdate
  1372. */
  1373. function display_configuration_parameter(
  1374. $installType,
  1375. $parameterName,
  1376. $formFieldName,
  1377. $parameterValue,
  1378. $displayWhenUpdate = 'true'
  1379. ) {
  1380. $html = '<div class="form-group">';
  1381. $html .= '<label class="col-sm-6 control-label">' . $parameterName . '</label>';
  1382. if ($installType == INSTALL_TYPE_UPDATE && $displayWhenUpdate) {
  1383. $html .= '<input type="hidden" name="' . $formFieldName . '" value="'. api_htmlentities($parameterValue, ENT_QUOTES). '" />' . $parameterValue;
  1384. } else {
  1385. $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>";
  1386. }
  1387. $html .= "</div>";
  1388. return $html;
  1389. }
  1390. /**
  1391. * Displays step 4 of the installation - configuration settings about Chamilo itself.
  1392. * @param string $installType
  1393. * @param string $urlForm
  1394. * @param string $languageForm
  1395. * @param string $emailForm
  1396. * @param string $adminFirstName
  1397. * @param string $adminLastName
  1398. * @param string $adminPhoneForm
  1399. * @param string $campusForm
  1400. * @param string $institutionForm
  1401. * @param string $institutionUrlForm
  1402. * @param string $encryptPassForm
  1403. * @param bool $allowSelfReg
  1404. * @param bool $allowSelfRegProf
  1405. * @param string $loginForm
  1406. * @param string $passForm
  1407. */
  1408. function display_configuration_settings_form(
  1409. $installType,
  1410. $urlForm,
  1411. $languageForm,
  1412. $emailForm,
  1413. $adminFirstName,
  1414. $adminLastName,
  1415. $adminPhoneForm,
  1416. $campusForm,
  1417. $institutionForm,
  1418. $institutionUrlForm,
  1419. $encryptPassForm,
  1420. $allowSelfReg,
  1421. $allowSelfRegProf,
  1422. $loginForm,
  1423. $passForm
  1424. ) {
  1425. if ($installType != 'update' && empty($languageForm)) {
  1426. $languageForm = $_SESSION['install_language'];
  1427. }
  1428. echo '<div class="RequirementHeading">';
  1429. echo "<h2>" . display_step_sequence() . get_lang("CfgSetting") . "</h2>";
  1430. echo '</div>';
  1431. echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>app/config/configuration.php</strong></p>';
  1432. // Parameter 1: administrator's login
  1433. $html = '';
  1434. $html .= display_configuration_parameter($installType, get_lang('AdminLogin'), 'loginForm', $loginForm, $installType == 'update');
  1435. // Parameter 2: administrator's password
  1436. if ($installType != 'update') {
  1437. $html .= display_configuration_parameter($installType, get_lang('AdminPass'), 'passForm', $passForm, false);
  1438. }
  1439. // Parameters 3 and 4: administrator's names
  1440. $html .= display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1441. $html .= display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1442. //Parameter 3: administrator's email
  1443. $html .= display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
  1444. //Parameter 6: administrator's telephone
  1445. $html .= display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
  1446. echo panel($html, get_lang('Administrator'), 'administrator');
  1447. //echo '<table class="table">';
  1448. //First parameter: language
  1449. $html = '<div class="form-group">';
  1450. $html .= '<label class="col-sm-6 control-label">'.get_lang('MainLang')."</label>";
  1451. if ($installType == 'update') {
  1452. $html .= '<input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm;
  1453. } else { // new installation
  1454. $html .= '<div class="col-sm-6">';
  1455. $html .= display_language_selection_box('languageForm', $languageForm);
  1456. $html .= '</div>';
  1457. }
  1458. $html.= "</div>";
  1459. //Second parameter: Chamilo URL
  1460. $html .= '<div class="form-group">';
  1461. $html .= '<label class="col-sm-6 control-label">'.get_lang('ChamiloURL') .get_lang('ThisFieldIsRequired').'</label>';
  1462. if ($installType == 'update') {
  1463. $html .= api_htmlentities($urlForm, ENT_QUOTES)."\n";
  1464. } else {
  1465. $html .= '<div class="col-sm-6">';
  1466. $html .= '<input class="form-control" type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities($urlForm, ENT_QUOTES).'" />';
  1467. $html .= '</div>';
  1468. }
  1469. $html .= '</div>';
  1470. //Parameter 9: campus name
  1471. $html .= display_configuration_parameter($installType, get_lang('CampusName'), 'campusForm', $campusForm);
  1472. //Parameter 10: institute (short) name
  1473. $html .= display_configuration_parameter($installType, get_lang('InstituteShortName'), 'institutionForm', $institutionForm);
  1474. //Parameter 11: institute (short) name
  1475. $html .= display_configuration_parameter($installType, get_lang('InstituteURL'), 'institutionUrlForm', $institutionUrlForm);
  1476. $html .= '<div class="form-group">
  1477. <label class="col-sm-6 control-label">' . get_lang("EncryptMethodUserPass") . '</label>
  1478. <div class="col-sm-6">';
  1479. if ($installType == 'update') {
  1480. $html .= '<input type="hidden" name="encryptPassForm" value="'. $encryptPassForm .'" />'. $encryptPassForm;
  1481. } else {
  1482. $html .= '<div class="checkbox">
  1483. <label>
  1484. <input type="radio" name="encryptPassForm" value="bcrypt" id="encryptPass1" '. ($encryptPassForm == 'bcrypt' ? 'checked="checked" ':'') .'/> bcrypt
  1485. </label>';
  1486. $html .= '<label>
  1487. <input type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" '. ($encryptPassForm == 'sha1' ? 'checked="checked" ':'') .'/> sha1
  1488. </label>';
  1489. $html .= '<label>
  1490. <input type="radio" name="encryptPassForm" value="md5" id="encryptPass0" '. ($encryptPassForm == 'md5' ? 'checked="checked" ':'') .'/> md5
  1491. </label>';
  1492. $html .= '<label>
  1493. <input type="radio" name="encryptPassForm" value="none" id="encryptPass2" '. ($encryptPassForm == 'none' ? 'checked="checked" ':'') .'/>'. get_lang('None').'
  1494. </label>';
  1495. $html .= '</div>';
  1496. }
  1497. $html .= '</div></div>';
  1498. $html .= '<div class="form-group">
  1499. <label class="col-sm-6 control-label">' . get_lang('AllowSelfReg') . '</label>
  1500. <div class="col-sm-6">';
  1501. if ($installType == 'update') {
  1502. $html .= '<input type="hidden" name="allowSelfReg" value="'. $allowSelfReg .'" />'. $allowSelfReg ? get_lang('Yes') : get_lang('No');
  1503. } else {
  1504. $html .= '<div class="control-group">';
  1505. $html .= '<label class="checkbox-inline">
  1506. <input type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" '. ($allowSelfReg ? 'checked="checked" ' : '') . ' /> '. get_lang('Yes') .'
  1507. </label>';
  1508. $html .= '<label class="checkbox-inline">
  1509. <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" '. ($allowSelfReg ? '' : 'checked="checked" ') .' /> '. get_lang('No') .'
  1510. </label>';
  1511. $html .= '</div>';
  1512. }
  1513. $html .= '</div>';
  1514. $html .= '</div>';
  1515. $html .= '<div class="form-group">';
  1516. $html .= '<label class="col-sm-6 control-label">'. get_lang('AllowSelfRegProf') .'</label>
  1517. <div class="col-sm-6">';
  1518. if ($installType == 'update'){
  1519. $html .= '<input type="hidden" name="allowSelfRegProf" value="'. $allowSelfRegProf.'" />'. $allowSelfRegProf? get_lang('Yes') : get_lang('No');
  1520. } else {
  1521. $html .= '<div class="control-group">
  1522. <label class="checkbox-inline">
  1523. <input type="radio" name="allowSelfRegProf" value="1" id="allowSelfRegProf1" '. ($allowSelfRegProf ? 'checked="checked" ' : '') .'/>
  1524. ' . get_lang('Yes') .'
  1525. </label>';
  1526. $html .= '<label class="checkbox-inline">
  1527. <input type="radio" name="allowSelfRegProf" value="0" id="allowSelfRegProf0" '. ($allowSelfRegProf ? '' : 'checked="checked" ') .' />
  1528. '. get_lang('No') .'
  1529. </label>';
  1530. $html .= '</div>';
  1531. }
  1532. $html .= '</div>
  1533. </div>';
  1534. echo panel($html, get_lang('Platform'), 'platform');
  1535. ?>
  1536. <div class='form-group'>
  1537. <div class="col-sm-6">
  1538. <button type="submit" class="btn btn-default pull-right" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>" ><i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?></button>
  1539. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1540. </div>
  1541. <div class="col-sm-6">
  1542. <button class="btn btn-success" type="submit" name="step5" value="<?php echo get_lang('Next'); ?> &gt;" ><i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?></button>
  1543. </div>
  1544. </div>
  1545. <?php
  1546. }
  1547. /**
  1548. * After installation is completed (step 6), this message is displayed.
  1549. * @param string $installType
  1550. */
  1551. function display_after_install_message($installType)
  1552. {
  1553. echo '<div class="RequirementContent">'.get_lang('FirstUseTip').'</div>';
  1554. echo '<div class="alert alert-warning">';
  1555. echo '<strong>'.get_lang('SecurityAdvice').'</strong>';
  1556. echo ': ';
  1557. printf(get_lang('ToProtectYourSiteMakeXReadOnlyAndDeleteY'), 'app/config/', 'main/install/');
  1558. echo '</div>';
  1559. ?></form>
  1560. <br />
  1561. <a class="btn btn-success btn-large btn-install" href="../../index.php">
  1562. <?php echo get_lang('GoToYourNewlyCreatedPortal'); ?>
  1563. </a>
  1564. <?php
  1565. }
  1566. /**
  1567. * This function return countries list from array (hardcoded)
  1568. * @param bool $combo (Optional) True for returning countries list with select html
  1569. * @return array|string countries list
  1570. */
  1571. function get_countries_list_from_array($combo = false)
  1572. {
  1573. $a_countries = array(
  1574. "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan",
  1575. "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
  1576. "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",
  1577. "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  1578. "East Timor (Timor Timur)", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia",
  1579. "Fiji", "Finland", "France",
  1580. "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana",
  1581. "Haiti", "Honduras", "Hungary",
  1582. "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy",
  1583. "Jamaica", "Japan", "Jordan",
  1584. "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan",
  1585. "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
  1586. "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Myanmar",
  1587. "Namibia", "Nauru", "Nepa", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway",
  1588. "Oman",
  1589. "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland","Portugal",
  1590. "Qatar",
  1591. "Romania", "Russia", "Rwanda",
  1592. "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",
  1593. "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu",
  1594. "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan",
  1595. "Vanuatu", "Vatican City", "Venezuela", "Vietnam",
  1596. "Yemen",
  1597. "Zambia", "Zimbabwe"
  1598. );
  1599. $country_select = '';
  1600. if ($combo) {
  1601. $country_select = '<select class="selectpicker show-tick" id="country" name="country">';
  1602. $country_select .= '<option value="">--- '.get_lang('SelectOne').' ---</option>';
  1603. foreach ($a_countries as $country) {
  1604. $country_select .= '<option value="'.$country.'">'.$country.'</option>';
  1605. }
  1606. $country_select .= '</select>';
  1607. return $country_select;
  1608. }
  1609. return $a_countries;
  1610. }
  1611. /**
  1612. * Lock settings that can't be changed in other portals
  1613. */
  1614. function lockSettings()
  1615. {
  1616. $access_url_locked_settings = api_get_locked_settings();
  1617. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1618. foreach ($access_url_locked_settings as $setting) {
  1619. $sql = "UPDATE $table SET access_url_locked = 1 WHERE variable = '$setting'";
  1620. Database::query($sql);
  1621. }
  1622. }
  1623. /**
  1624. * Update dir values
  1625. */
  1626. function updateDirAndFilesPermissions()
  1627. {
  1628. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1629. $permissions_for_new_directories = isset($_SESSION['permissions_for_new_directories']) ? $_SESSION['permissions_for_new_directories'] : 0770;
  1630. $permissions_for_new_files = isset($_SESSION['permissions_for_new_files']) ? $_SESSION['permissions_for_new_files'] : 0660;
  1631. // use decoct() to store as string
  1632. $sql = "UPDATE $table SET selected_value = '0" . decoct($permissions_for_new_directories) . "'
  1633. WHERE variable = 'permissions_for_new_directories'";
  1634. Database::query($sql);
  1635. $sql = "UPDATE $table SET selected_value = '0" . decoct($permissions_for_new_files) . "' WHERE variable = 'permissions_for_new_files'";
  1636. Database::query($sql);
  1637. if (isset($_SESSION['permissions_for_new_directories'])) {
  1638. unset($_SESSION['permissions_for_new_directories']);
  1639. }
  1640. if (isset($_SESSION['permissions_for_new_files'])) {
  1641. unset($_SESSION['permissions_for_new_files']);
  1642. }
  1643. }
  1644. /**
  1645. * @param $current_value
  1646. * @param $wanted_value
  1647. * @return string
  1648. */
  1649. function compare_setting_values($current_value, $wanted_value)
  1650. {
  1651. $current_value_string = $current_value;
  1652. $current_value = (float)$current_value;
  1653. $wanted_value = (float)$wanted_value;
  1654. if ($current_value >= $wanted_value) {
  1655. return Display::label($current_value_string, 'success');
  1656. } else {
  1657. return Display::label($current_value_string, 'important');
  1658. }
  1659. }
  1660. /**
  1661. * @param $course_dir
  1662. * @param $course_attempt_name
  1663. * @param string $file
  1664. * @return bool
  1665. */
  1666. function check_course_script_interpretation($course_dir, $course_attempt_name, $file = 'test.php')
  1667. {
  1668. $output = false;
  1669. //Write in file
  1670. $file_name = $course_dir.'/'.$file;
  1671. $content = '<?php echo "123"; exit;';
  1672. if (is_writable($file_name)) {
  1673. if ($handler = @fopen($file_name, "w")) {
  1674. //write content
  1675. if (fwrite($handler, $content)) {
  1676. $sock_errno = '';
  1677. $sock_errmsg = '';
  1678. $url = api_get_path(WEB_PATH).'app/courses/'.$course_attempt_name.'/'.$file;
  1679. $parsed_url = parse_url($url);
  1680. //$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : ''; //http
  1681. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  1682. // Patch if the host is the default host and is used through
  1683. // the IP address (sometimes the host is not taken correctly
  1684. // in this case)
  1685. if (empty($host) && !empty($_SERVER['HTTP_HOST'])) {
  1686. $host = $_SERVER['HTTP_HOST'];
  1687. $url = preg_replace('#:///#', '://'.$host.'/', $url);
  1688. }
  1689. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
  1690. $port = isset($parsed_url['port']) ? $parsed_url['port'] : '80';
  1691. //Check fsockopen (doesn't work with https)
  1692. if ($fp = @fsockopen(str_replace('http://', '', $url), -1, $sock_errno, $sock_errmsg, 60)) {
  1693. $out = "GET $path HTTP/1.1\r\n";
  1694. $out .= "Host: $host\r\n";
  1695. $out .= "Connection: Close\r\n\r\n";
  1696. fwrite($fp, $out);
  1697. while (!feof($fp)) {
  1698. $result = str_replace("\r\n", '',fgets($fp, 128));
  1699. if (!empty($result) && $result == '123') {
  1700. $output = true;
  1701. }
  1702. }
  1703. fclose($fp);
  1704. //Check allow_url_fopen
  1705. } elseif (ini_get('allow_url_fopen')) {
  1706. if ($fp = @fopen($url, 'r')) {
  1707. while ($result = fgets($fp, 1024)) {
  1708. if (!empty($result) && $result == '123') {
  1709. $output = true;
  1710. }
  1711. }
  1712. fclose($fp);
  1713. }
  1714. // Check if has support for cURL
  1715. } elseif (function_exists('curl_init')) {
  1716. $ch = curl_init();
  1717. curl_setopt($ch, CURLOPT_HEADER, 0);
  1718. curl_setopt($ch, CURLOPT_URL, $url);
  1719. //curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  1720. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1721. $result = curl_exec ($ch);
  1722. if (!empty($result) && $result == '123') {
  1723. $output = true;
  1724. }
  1725. curl_close($ch);
  1726. }
  1727. }
  1728. @fclose($handler);
  1729. }
  1730. }
  1731. return $output;
  1732. }
  1733. /**
  1734. * Save settings values
  1735. *
  1736. * @param string $organizationName
  1737. * @param string $organizationUrl
  1738. * @param string $siteName
  1739. * @param string $adminEmail
  1740. * @param string $adminLastName
  1741. * @param string $adminFirstName
  1742. * @param string $language
  1743. * @param string $allowRegistration
  1744. * @param string $allowTeacherSelfRegistration
  1745. * @param string $installationProfile The name of an installation profile file in main/install/profiles/
  1746. */
  1747. function installSettings(
  1748. $organizationName,
  1749. $organizationUrl,
  1750. $siteName,
  1751. $adminEmail,
  1752. $adminLastName,
  1753. $adminFirstName,
  1754. $language,
  1755. $allowRegistration,
  1756. $allowTeacherSelfRegistration,
  1757. $installationProfile = ''
  1758. ) {
  1759. $allowRegistration = $allowRegistration ? 'true' : 'false';
  1760. $allowTeacherSelfRegistration = $allowTeacherSelfRegistration ? 'true' : 'false';
  1761. // Use PHP 5.3 to avoid issue with weird peripherical auto-installers like travis-ci
  1762. $settings = array(
  1763. 'Institution' => $organizationName,
  1764. 'InstitutionUrl' => $organizationUrl,
  1765. 'siteName' => $siteName,
  1766. 'emailAdministrator' => $adminEmail,
  1767. 'administratorSurname' => $adminLastName,
  1768. 'administratorName' => $adminFirstName,
  1769. 'platformLanguage' => $language,
  1770. 'allow_registration' => $allowRegistration,
  1771. 'allow_registration_as_teacher' => $allowTeacherSelfRegistration,
  1772. );
  1773. foreach ($settings as $variable => $value) {
  1774. $sql = "UPDATE settings_current
  1775. SET selected_value = '$value'
  1776. WHERE variable = '$variable'";
  1777. Database::query($sql);
  1778. }
  1779. installProfileSettings($installationProfile);
  1780. }
  1781. /**
  1782. * Executes DB changes based in the classes defined in
  1783. * src/Chamilo/CoreBundle/Migrations/Schema/*
  1784. *
  1785. * @param string $chamiloVersion
  1786. * @param EntityManager $manager
  1787. * @throws \Doctrine\DBAL\DBALException
  1788. */
  1789. function migrate($chamiloVersion, EntityManager $manager)
  1790. {
  1791. $debug = true;
  1792. $connection = $manager->getConnection();
  1793. $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($connection);
  1794. // Table name that will store migrations log (will be created automatically,
  1795. // default name is: doctrine_migration_versions)
  1796. $config->setMigrationsTableName('version');
  1797. // Namespace of your migration classes, do not forget escape slashes, do not add last slash
  1798. $config->setMigrationsNamespace('Application\Migrations\Schema\V'.$chamiloVersion);
  1799. // Directory where your migrations are located
  1800. $config->setMigrationsDirectory(api_get_path(SYS_PATH).'app/Migrations/Schema/V'.$chamiloVersion);
  1801. // Load your migrations
  1802. $config->registerMigrationsFromDirectory($config->getMigrationsDirectory());
  1803. $migration = new \Doctrine\DBAL\Migrations\Migration($config);
  1804. $versions = $config->getMigrations();
  1805. /** @var Doctrine\DBAL\Migrations\Version $migrationItem */
  1806. foreach ($versions as $version) {
  1807. $version->getMigration()->setEntityManager($manager);
  1808. }
  1809. $to = null;
  1810. // Retrieve SQL queries that should be run to migrate you schema to $to version,
  1811. // if $to == null - schema will be migrated to latest version
  1812. $versions = $migration->getSql($to);
  1813. if ($debug) {
  1814. $nl = '<br>';
  1815. foreach ($versions as $version => $queries) {
  1816. echo 'VERSION: '.$version.$nl;
  1817. echo '----------------------------------------------'.$nl.$nl;
  1818. foreach ($queries as $query) {
  1819. echo $query.$nl;
  1820. }
  1821. echo $nl.$nl;
  1822. }
  1823. }
  1824. try {
  1825. // Execute migration!
  1826. $migration->migrate($to);
  1827. if ($debug) {
  1828. echo 'DONE'.$nl;
  1829. }
  1830. } catch (Exception $ex) {
  1831. if ($debug) {
  1832. echo 'ERROR: '.$ex->getMessage().$nl;
  1833. }
  1834. }
  1835. }
  1836. /**
  1837. * @param EntityManager $em
  1838. *
  1839. * @throws \Doctrine\DBAL\DBALException
  1840. */
  1841. function fixIds(EntityManager $em)
  1842. {
  1843. $connection = $em->getConnection();
  1844. $sql = "SELECT * FROM c_lp_item";
  1845. $result = $connection->fetchAll($sql);
  1846. foreach ($result as $item) {
  1847. $courseId = $item['c_id'];
  1848. $iid = isset($item['iid']) ? intval($item['iid']) : 0;
  1849. $ref = isset($item['ref']) ? intval($item['ref']) : 0;
  1850. $sql = null;
  1851. $newId = '';
  1852. switch ($item['item_type']) {
  1853. case TOOL_LINK:
  1854. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref";
  1855. $data = $connection->fetchAssoc($sql);
  1856. if ($data) {
  1857. $newId = $data['iid'];
  1858. }
  1859. break;
  1860. case TOOL_STUDENTPUBLICATION:
  1861. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  1862. $data = $connection->fetchAssoc($sql);
  1863. if ($data) {
  1864. $newId = $data['iid'];
  1865. }
  1866. break;
  1867. case TOOL_QUIZ:
  1868. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  1869. $data = $connection->fetchAssoc($sql);
  1870. if ($data) {
  1871. $newId = $data['iid'];
  1872. }
  1873. break;
  1874. case TOOL_DOCUMENT:
  1875. $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  1876. $data = $connection->fetchAssoc($sql);
  1877. if ($data) {
  1878. $newId = $data['iid'];
  1879. }
  1880. break;
  1881. case TOOL_FORUM:
  1882. $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND forum_id = $ref";
  1883. $data = $connection->fetchAssoc($sql);
  1884. if ($data) {
  1885. $newId = $data['iid'];
  1886. }
  1887. break;
  1888. case 'thread':
  1889. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND thread_id = $ref";
  1890. $data = $connection->fetchAssoc($sql);
  1891. if ($data) {
  1892. $newId = $data['iid'];
  1893. }
  1894. break;
  1895. }
  1896. if (!empty($sql) && !empty($newId) && !empty($iid)) {
  1897. $sql = "UPDATE c_lp_item SET ref = $newId WHERE iid = $iid";
  1898. $connection->executeQuery($sql);
  1899. }
  1900. }
  1901. // Set NULL if session = 0
  1902. $sql = "UPDATE c_item_property SET session_id = NULL WHERE session_id = 0";
  1903. $connection->executeQuery($sql);
  1904. // Set NULL if group = 0
  1905. $sql = "UPDATE c_item_property SET to_group_id = NULL WHERE to_group_id = 0";
  1906. $connection->executeQuery($sql);
  1907. // Set NULL if insert_user_id = 0
  1908. $sql = "UPDATE c_item_property SET insert_user_id = NULL WHERE insert_user_id = 0";
  1909. $connection->executeQuery($sql);
  1910. // Delete session data of sessions that don't exist.
  1911. $sql = "DELETE FROM c_item_property
  1912. WHERE session_id IS NOT NULL AND session_id NOT IN (SELECT id FROM session)";
  1913. $connection->executeQuery($sql);
  1914. // Delete group data of groups that don't exist.
  1915. $sql = "DELETE FROM c_item_property
  1916. WHERE to_group_id IS NOT NULL AND to_group_id NOT IN (SELECT DISTINCT id FROM c_group_info)";
  1917. $connection->executeQuery($sql);
  1918. // This updates the group_id with c_group_info.iid instead of c_group_info.id
  1919. $groupTableToFix = [
  1920. 'c_group_rel_user',
  1921. 'c_group_rel_tutor',
  1922. 'c_permission_group',
  1923. 'c_role_group',
  1924. 'c_survey_invitation',
  1925. 'c_attendance_calendar_rel_group'
  1926. ];
  1927. foreach ($groupTableToFix as $table) {
  1928. $sql = "SELECT * FROM $table";
  1929. $result = $connection->fetchAll($sql);
  1930. foreach ($result as $item) {
  1931. $iid = $item['iid'];
  1932. $courseId = $item['c_id'];
  1933. $groupId = intval($item['group_id']);
  1934. // Fix group id
  1935. if (!empty($groupId)) {
  1936. $sql = "SELECT * FROM c_group_info
  1937. WHERE c_id = $courseId AND id = $groupId
  1938. LIMIT 1";
  1939. $data = $connection->fetchAssoc($sql);
  1940. if (!empty($data)) {
  1941. $newGroupId = $data['iid'];
  1942. $sql = "UPDATE $table SET group_id = $newGroupId
  1943. WHERE iid = $iid";
  1944. $connection->executeQuery($sql);
  1945. } else {
  1946. // The group does not exists clean this record
  1947. $sql = "DELETE FROM $table WHERE iid = $iid";
  1948. $connection->executeQuery($sql);
  1949. }
  1950. }
  1951. }
  1952. }
  1953. // Fix c_item_property
  1954. $sql = "SELECT * FROM c_item_property";
  1955. $result = $connection->fetchAll($sql);
  1956. foreach ($result as $item) {
  1957. $courseId = $item['c_id'];
  1958. $sessionId = intval($item['session_id']);
  1959. $groupId = intval($item['to_group_id']);
  1960. $iid = $item['iid'];
  1961. $ref = $item['ref'];
  1962. // Fix group id
  1963. if (!empty($groupId)) {
  1964. $sql = "SELECT * FROM c_group_info
  1965. WHERE c_id = $courseId AND id = $groupId";
  1966. $data = $connection->fetchAssoc($sql);
  1967. if (!empty($data)) {
  1968. $newGroupId = $data['iid'];
  1969. $sql = "UPDATE c_item_property SET to_group_id = $newGroupId
  1970. WHERE iid = $iid";
  1971. $connection->executeQuery($sql);
  1972. } else {
  1973. // The group does not exists clean this record
  1974. $sql = "DELETE FROM c_item_property WHERE iid = $iid";
  1975. $connection->executeQuery($sql);
  1976. }
  1977. }
  1978. $sql = '';
  1979. $newId = '';
  1980. switch ($item['tool']) {
  1981. case TOOL_LINK:
  1982. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref ";
  1983. break;
  1984. case TOOL_STUDENTPUBLICATION:
  1985. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  1986. break;
  1987. case TOOL_QUIZ:
  1988. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  1989. break;
  1990. case TOOL_DOCUMENT:
  1991. $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  1992. break;
  1993. case TOOL_FORUM:
  1994. $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND id = $ref";
  1995. break;
  1996. case 'thread':
  1997. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND id = $ref";
  1998. break;
  1999. }
  2000. if (!empty($sql) && !empty($newId)) {
  2001. $data = $connection->fetchAssoc($sql);
  2002. if (isset($data['iid'])) {
  2003. $newId = $data['iid'];
  2004. }
  2005. $sql = "UPDATE c_item_property SET ref = $newId WHERE iid = $iid";
  2006. $connection->executeQuery($sql);
  2007. }
  2008. }
  2009. // Fix gradebook_link
  2010. $sql = "SELECT * FROM gradebook_link";
  2011. $result = $connection->fetchAll($sql);
  2012. foreach ($result as $item) {
  2013. $courseCode = $item['course_code'];
  2014. $courseInfo = api_get_course_info($courseCode);
  2015. if (empty($courseInfo)) {
  2016. continue;
  2017. }
  2018. $courseId = $courseInfo['real_id'];
  2019. $ref = $item['ref_id'];
  2020. $iid = $item['id'];
  2021. $sql = '';
  2022. switch ($item['type']) {
  2023. case LINK_LEARNPATH:
  2024. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref ";
  2025. break;
  2026. case LINK_STUDENTPUBLICATION:
  2027. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  2028. break;
  2029. case LINK_EXERCISE:
  2030. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  2031. break;
  2032. case LINK_ATTENDANCE:
  2033. //$sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  2034. break;
  2035. case LINK_FORUM_THREAD:
  2036. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND id = $ref";
  2037. break;
  2038. }
  2039. if (!empty($sql)) {
  2040. $data = $connection->fetchAssoc($sql);
  2041. if (isset($data) && isset($data['iid'])) {
  2042. $newId = $data['iid'];
  2043. $sql = "UPDATE gradebook_link SET ref_id = $newId
  2044. WHERE id = $iid";
  2045. $connection->executeQuery($sql);
  2046. }
  2047. }
  2048. }
  2049. $sql = "SELECT * FROM groups";
  2050. $result = $connection->executeQuery($sql);
  2051. $groups = $result->fetchAll();
  2052. $oldGroups = array();
  2053. if (!empty($groups )) {
  2054. foreach ($groups as $group) {
  2055. $sql = "INSERT INTO usergroup (name, group_type, description, picture, url, visibility, updated_at, created_at)
  2056. VALUES ('{$group['name']}', '1', '{$group['description']}', '{$group['picture_uri']}', '{$group['url']}', '{$group['visibility']}', '{$group['updated_on']}', '{$group['created_on']}')";
  2057. $connection->executeQuery($sql);
  2058. $id = $connection->lastInsertId('id');
  2059. $oldGroups[$group['id']] = $id;
  2060. }
  2061. }
  2062. if (!empty($oldGroups)) {
  2063. foreach ($oldGroups as $oldId => $newId) {
  2064. $path = \GroupPortalManager::get_group_picture_path_by_id(
  2065. $oldId,
  2066. 'system'
  2067. );
  2068. if (!empty($path)) {
  2069. $newPath = str_replace(
  2070. "groups/$oldId/",
  2071. "groups/$newId/",
  2072. $path['dir']
  2073. );
  2074. $command = "mv {$path['dir']} $newPath ";
  2075. system($command);
  2076. }
  2077. }
  2078. $sql = "SELECT * FROM group_rel_user";
  2079. $result = $connection->executeQuery($sql);
  2080. $dataList = $result->fetchAll();
  2081. if (!empty($dataList)) {
  2082. foreach ($dataList as $data) {
  2083. if (isset($oldGroups[$data['group_id']])) {
  2084. $data['group_id'] = $oldGroups[$data['group_id']];
  2085. $sql = "INSERT INTO usergroup_rel_user (usergroup_id, user_id, relation_type)
  2086. VALUES ('{$data['group_id']}', '{$data['user_id']}', '{$data['relation_type']}')";
  2087. $connection->executeQuery($sql);
  2088. }
  2089. }
  2090. }
  2091. $sql = "SELECT * FROM group_rel_group";
  2092. $result = $connection->executeQuery($sql);
  2093. $dataList = $result->fetchAll();
  2094. if (!empty($dataList)) {
  2095. foreach ($dataList as $data) {
  2096. if (isset($oldGroups[$data['group_id']]) && isset($oldGroups[$data['subgroup_id']])) {
  2097. $data['group_id'] = $oldGroups[$data['group_id']];
  2098. $data['subgroup_id'] = $oldGroups[$data['subgroup_id']];
  2099. $sql = "INSERT INTO usergroup_rel_usergroup (group_id, subgroup_id, relation_type)
  2100. VALUES ('{$data['group_id']}', '{$data['subgroup_id']}', '{$data['relation_type']}')";
  2101. $connection->executeQuery($sql);
  2102. }
  2103. }
  2104. }
  2105. $sql = "SELECT * FROM announcement_rel_group";
  2106. $result = $connection->executeQuery($sql);
  2107. $dataList = $result->fetchAll();
  2108. if (!empty($dataList)) {
  2109. foreach ($dataList as $data) {
  2110. if (isset($oldGroups[$data['group_id']])) {
  2111. // Deleting relation
  2112. $sql = "DELETE FROM announcement_rel_group WHERE id = {$data['id']}";
  2113. $connection->executeQuery($sql);
  2114. // Add new relation
  2115. $data['group_id'] = $oldGroups[$data['group_id']];
  2116. $sql = "INSERT INTO announcement_rel_group(group_id, announcement_id)
  2117. VALUES ('{$data['group_id']}', '{$data['announcement_id']}')";
  2118. $connection->executeQuery($sql);
  2119. }
  2120. }
  2121. }
  2122. $sql = "SELECT * FROM group_rel_tag";
  2123. $result = $connection->executeQuery($sql);
  2124. $dataList = $result->fetchAll();
  2125. if (!empty($dataList)) {
  2126. foreach ($dataList as $data) {
  2127. if (isset($oldGroups[$data['group_id']])) {
  2128. $data['group_id'] = $oldGroups[$data['group_id']];
  2129. $sql = "INSERT INTO usergroup_rel_tag (tag_id, usergroup_id)
  2130. VALUES ('{$data['tag_id']}', '{$data['group_id']}')";
  2131. $connection->executeQuery($sql);
  2132. }
  2133. }
  2134. }
  2135. }
  2136. // Extra fields
  2137. $extraFieldTables = [
  2138. ExtraField::USER_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_USER_FIELD),
  2139. ExtraField::COURSE_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_COURSE_FIELD),
  2140. //ExtraField::LP_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_LP_FIELD),
  2141. ExtraField::SESSION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_SESSION_FIELD),
  2142. //ExtraField::CALENDAR_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD),
  2143. //ExtraField::QUESTION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD),
  2144. //ExtraField::USER_FIELD_TYPE => //Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD),
  2145. ];
  2146. foreach ($extraFieldTables as $type => $table) {
  2147. //continue;
  2148. $sql = "SELECT * FROM $table ";
  2149. $result = $connection->query($sql);
  2150. $fields = $result->fetchAll();
  2151. foreach ($fields as $field) {
  2152. $originalId = $field['id'];
  2153. $extraField = new ExtraField();
  2154. $extraField
  2155. ->setExtraFieldType($type)
  2156. ->setVariable($field['field_variable'])
  2157. ->setFieldType($field['field_type'])
  2158. ->setDisplayText($field['field_display_text'])
  2159. ->setDefaultValue($field['field_default_value'])
  2160. ->setFieldOrder($field['field_order'])
  2161. ->setVisible($field['field_visible'])
  2162. ->setChangeable($field['field_changeable'])
  2163. ->setFilter($field['field_filter']);
  2164. $em->persist($extraField);
  2165. $em->flush();
  2166. $values = array();
  2167. switch ($type) {
  2168. case ExtraField::USER_FIELD_TYPE:
  2169. $optionTable = Database::get_main_table(
  2170. TABLE_MAIN_USER_FIELD_OPTIONS
  2171. );
  2172. $valueTable = Database::get_main_table(
  2173. TABLE_MAIN_USER_FIELD_VALUES
  2174. );
  2175. $handlerId = 'user_id';
  2176. break;
  2177. case ExtraField::COURSE_FIELD_TYPE:
  2178. $optionTable = Database::get_main_table(
  2179. TABLE_MAIN_COURSE_FIELD_OPTIONS
  2180. );
  2181. $valueTable = Database::get_main_table(
  2182. TABLE_MAIN_COURSE_FIELD_VALUES
  2183. );
  2184. $handlerId = 'c_id';
  2185. break;
  2186. case ExtraField::SESSION_FIELD_TYPE:
  2187. $optionTable = Database::get_main_table(
  2188. TABLE_MAIN_SESSION_FIELD_OPTIONS
  2189. );
  2190. $valueTable = Database::get_main_table(
  2191. TABLE_MAIN_SESSION_FIELD_VALUES
  2192. );
  2193. $handlerId = 'session_id';
  2194. break;
  2195. }
  2196. if (!empty($optionTable)) {
  2197. $sql = "SELECT * FROM $optionTable WHERE field_id = $originalId ";
  2198. $result = $connection->query($sql);
  2199. $options = $result->fetchAll();
  2200. foreach ($options as $option) {
  2201. $extraFieldOption = new ExtraFieldOptions();
  2202. $extraFieldOption
  2203. ->setDisplayText($option['option_display_text'])
  2204. ->setField($extraField)
  2205. ->setOptionOrder($option['option_order'])
  2206. ->setValue($option['option_value']);
  2207. $em->persist($extraFieldOption);
  2208. $em->flush();
  2209. }
  2210. $sql = "SELECT * FROM $valueTable WHERE field_id = $originalId ";
  2211. $result = $connection->query($sql);
  2212. $values = $result->fetchAll();
  2213. }
  2214. if (!empty($values)) {
  2215. foreach ($values as $value) {
  2216. $extraFieldValue = new ExtraFieldValues();
  2217. $extraFieldValue
  2218. ->setValue($value['field_value'])
  2219. ->setField($extraField)
  2220. ->setItemId($value[$handlerId]);
  2221. $em->persist($extraFieldValue);
  2222. $em->flush();
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. /**
  2229. *
  2230. * After the schema was created (table creation), the function adds
  2231. * admin/platform information.
  2232. *
  2233. * @param EntityManager $manager
  2234. * @param string $sysPath
  2235. * @param string $encryptPassForm
  2236. * @param string $passForm
  2237. * @param string $adminLastName
  2238. * @param string $adminFirstName
  2239. * @param string $loginForm
  2240. * @param string $emailForm
  2241. * @param string $adminPhoneForm
  2242. * @param string $languageForm
  2243. * @param string $institutionForm
  2244. * @param string $institutionUrlForm
  2245. * @param string $siteName
  2246. * @param string $allowSelfReg
  2247. * @param string $allowSelfRegProf
  2248. * @param string $installationProfile Installation profile, if any was provided
  2249. */
  2250. function finishInstallation(
  2251. $manager,
  2252. $sysPath,
  2253. $encryptPassForm,
  2254. $passForm,
  2255. $adminLastName,
  2256. $adminFirstName,
  2257. $loginForm,
  2258. $emailForm,
  2259. $adminPhoneForm,
  2260. $languageForm,
  2261. $institutionForm,
  2262. $institutionUrlForm,
  2263. $siteName,
  2264. $allowSelfReg,
  2265. $allowSelfRegProf,
  2266. $installationProfile = ''
  2267. ) {
  2268. $sysPath = !empty($sysPath) ? $sysPath : api_get_path(SYS_PATH);
  2269. // Inserting data
  2270. $data = file_get_contents($sysPath.'main/install/data.sql');
  2271. $result = $manager->getConnection()->prepare($data);
  2272. $result->execute();
  2273. $result->closeCursor();
  2274. UserManager::setPasswordEncryption($encryptPassForm);
  2275. // Create admin user.
  2276. UserManager::create_user(
  2277. $adminFirstName,
  2278. $adminLastName,
  2279. 1,
  2280. $emailForm,
  2281. $loginForm,
  2282. $passForm,
  2283. 'ADMIN', //$official_code = '',
  2284. $languageForm,
  2285. $adminPhoneForm,
  2286. '', //$picture_uri = '',
  2287. PLATFORM_AUTH_SOURCE,
  2288. '',//$expirationDate,
  2289. 1,
  2290. 0,
  2291. null,
  2292. '',
  2293. false, //$send_mail = false,
  2294. true //$isAdmin = false
  2295. );
  2296. // Create anonymous user.
  2297. UserManager::create_user(
  2298. 'Joe',
  2299. 'Anonymous',
  2300. 6,
  2301. 'anonymous@localhost',
  2302. 'anon',
  2303. 'anon',
  2304. 'anonymous', //$official_code = '',
  2305. $languageForm,
  2306. '',
  2307. '', //$picture_uri = '',
  2308. PLATFORM_AUTH_SOURCE,
  2309. '',
  2310. 1,
  2311. 0,
  2312. null,
  2313. '',
  2314. false, //$send_mail = false,
  2315. false //$isAdmin = false
  2316. );
  2317. // Set default language
  2318. $sql = "UPDATE language SET available=1 WHERE dokeos_folder = '$languageForm'";
  2319. Database::query($sql);
  2320. // Install settings
  2321. installSettings(
  2322. $institutionForm,
  2323. $institutionUrlForm,
  2324. $siteName,
  2325. $emailForm,
  2326. $adminLastName,
  2327. $adminFirstName,
  2328. $languageForm,
  2329. $allowSelfReg,
  2330. $allowSelfRegProf,
  2331. $installationProfile
  2332. );
  2333. lockSettings();
  2334. updateDirAndFilesPermissions();
  2335. }
  2336. /**
  2337. * Update settings based on installation profile defined in a JSON file
  2338. * @param string $installationProfile The name of the JSON file in main/install/profiles/ folder
  2339. *
  2340. * @return bool false on failure (no bad consequences anyway, just ignoring profile)
  2341. */
  2342. function installProfileSettings($installationProfile = '')
  2343. {
  2344. if (empty($installationProfile)) {
  2345. return false;
  2346. }
  2347. $jsonPath = api_get_path(SYS_PATH).'main/install/profiles/'.$installationProfile.'.json';
  2348. // Make sure the path to the profile is not hacked
  2349. if (!Security::check_abs_path($jsonPath, api_get_path(SYS_PATH).'main/install/profiles/')) {
  2350. return false;
  2351. }
  2352. if (!is_file($jsonPath)) {
  2353. return false;
  2354. }
  2355. if (!is_readable($jsonPath)) {
  2356. return false;
  2357. }
  2358. if (!function_exists('json_decode')) {
  2359. // The php-json extension is not available. Ignore profile.
  2360. return false;
  2361. }
  2362. $json = file_get_contents($jsonPath);
  2363. $params = json_decode($json);
  2364. if ($params === false or $params === null) {
  2365. return false;
  2366. }
  2367. $settings = $params->params;
  2368. if (!empty($params->parent)) {
  2369. installProfileSettings($params->parent);
  2370. }
  2371. foreach ($settings as $id => $param) {
  2372. $sql = "UPDATE settings_current
  2373. SET selected_value = '".$param->selected_value."'
  2374. WHERE variable = '".$param->variable."'";
  2375. if (!empty($param->subkey)) {
  2376. $sql .= " AND subkey='" . $param->subkey . "'";
  2377. }
  2378. Database::query($sql);
  2379. }
  2380. return true;
  2381. }