install.lib.php 100 KB

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