install.lib.php 104 KB

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