install.lib.php 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\ExtraField;
  4. use Chamilo\TicketBundle\Entity\Project as TicketProject;
  5. use Chamilo\TicketBundle\Entity\Category as TicketCategory;
  6. use Chamilo\TicketBundle\Entity\Priority as TicketPriority;
  7. use Doctrine\ORM\EntityManager;
  8. /**
  9. * Chamilo LMS
  10. * This file contains functions used by the install and upgrade scripts.
  11. *
  12. * Ideas for future additions:
  13. * - a function get_old_version_settings to retrieve the config file settings
  14. * of older versions before upgrading.
  15. */
  16. /* CONSTANTS */
  17. define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php');
  18. /**
  19. * This function detects whether the system has been already installed.
  20. * It should be used for prevention from second running the installation
  21. * script and as a result - destroying a production system.
  22. * @return bool The detected result;
  23. * @author Ivan Tcholakov, 2010;
  24. */
  25. function isAlreadyInstalledSystem()
  26. {
  27. global $new_version, $_configuration;
  28. if (empty($new_version)) {
  29. return true; // Must be initialized.
  30. }
  31. $current_config_file = api_get_path(CONFIGURATION_PATH).'configuration.php';
  32. if (!file_exists($current_config_file)) {
  33. return false; // Configuration file does not exist, install the system.
  34. }
  35. require $current_config_file;
  36. $current_version = null;
  37. if (isset($_configuration['system_version'])) {
  38. $current_version = trim($_configuration['system_version']);
  39. }
  40. // If the current version is old, upgrading is assumed, the installer goes ahead.
  41. return empty($current_version) ? false : version_compare($current_version, $new_version, '>=');
  42. }
  43. /**
  44. * This function checks if a php extension exists or not and returns an HTML status string.
  45. *
  46. * @param string $extensionName Name of the PHP extension to be checked
  47. * @param string $returnSuccess Text to show when extension is available (defaults to 'Yes')
  48. * @param string $returnFailure Text to show when extension is available (defaults to 'No')
  49. * @param boolean $optional Whether this extension is optional (then show unavailable text in orange rather than red)
  50. * @param string $enabledTerm If this string is not null, then use to check if the corresponding parameter is = 1. If not, mention it's present but not enabled. For example, for opcache, this should be 'opcache.enable'
  51. * @return string HTML string reporting the status of this extension. Language-aware.
  52. * @author Christophe Gesch??
  53. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  54. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  55. */
  56. function checkExtension(
  57. $extensionName,
  58. $returnSuccess = 'Yes',
  59. $returnFailure = 'No',
  60. $optional = false,
  61. $enabledTerm = ''
  62. ) {
  63. if (extension_loaded($extensionName)) {
  64. if (!empty($enabledTerm)) {
  65. $isEnabled = ini_get($enabledTerm);
  66. if ($isEnabled == '1') {
  67. return Display::label($returnSuccess, 'success');
  68. } else {
  69. if ($optional) {
  70. return Display::label(get_lang('ExtensionInstalledButNotEnabled'), 'warning');
  71. } else {
  72. return Display::label(get_lang('ExtensionInstalledButNotEnabled'), 'important');
  73. }
  74. }
  75. } else {
  76. return Display::label($returnSuccess, 'success');
  77. }
  78. } else {
  79. if ($optional) {
  80. return Display::label($returnFailure, 'warning');
  81. } else {
  82. return Display::label($returnFailure, 'important');
  83. }
  84. }
  85. }
  86. /**
  87. * This function checks whether a php setting matches the recommended value
  88. * @param string $phpSetting A PHP setting to check
  89. * @param string $recommendedValue A recommended value to show on screen
  90. * @param mixed $returnSuccess What to show on success
  91. * @param mixed $returnFailure What to show on failure
  92. * @return string A label to show
  93. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  94. */
  95. function checkPhpSetting(
  96. $phpSetting,
  97. $recommendedValue,
  98. $returnSuccess = false,
  99. $returnFailure = false
  100. ) {
  101. $currentPhpValue = getPhpSetting($phpSetting);
  102. if ($currentPhpValue == $recommendedValue) {
  103. return Display::label($currentPhpValue.' '.$returnSuccess, 'success');
  104. } else {
  105. return Display::label($currentPhpValue.' '.$returnSuccess, 'important');
  106. }
  107. }
  108. /**
  109. * This function return the value of a php.ini setting if not "" or if exists,
  110. * otherwise return false
  111. * @param string $phpSetting The name of a PHP setting
  112. * @return mixed The value of the setting, or false if not found
  113. */
  114. function checkPhpSettingExists($phpSetting)
  115. {
  116. if (ini_get($phpSetting) != "") {
  117. return ini_get($phpSetting);
  118. }
  119. return false;
  120. }
  121. /**
  122. * Check if the current url is the same root_web when the multiple_access_url is enabled
  123. * @return bool
  124. */
  125. function checkAccessUrl()
  126. {
  127. if (api_get_configuration_value('multiple_access_urls') !== true) {
  128. return true;
  129. }
  130. $currentWebPath = api_get_path(WEB_PATH);
  131. $rootWeb = api_get_configuration_value('root_web');
  132. return $currentWebPath === $rootWeb;
  133. }
  134. /**
  135. * Returns a textual value ('ON' or 'OFF') based on a requester 2-state ini- configuration setting.
  136. *
  137. * @param string $val a php ini value
  138. * @return bool ON or OFF
  139. * @author Joomla <http://www.joomla.org>
  140. */
  141. function getPhpSetting($val)
  142. {
  143. return ini_get($val) == '1' ? 'ON' : 'OFF';
  144. }
  145. /**
  146. * This function returns a string "true" or "false" according to the passed parameter.
  147. *
  148. * @param integer $var The variable to present as text
  149. * @return string the string "true" or "false"
  150. * @author Christophe Gesch??
  151. */
  152. function trueFalse($var)
  153. {
  154. return $var ? 'true' : 'false';
  155. }
  156. /**
  157. * Removes memory and time limits as much as possible.
  158. */
  159. function remove_memory_and_time_limits()
  160. {
  161. if (function_exists('ini_set')) {
  162. ini_set('memory_limit', -1);
  163. ini_set('max_execution_time', 0);
  164. error_log('Update-db script: memory_limit set to -1', 0);
  165. error_log('Update-db script: max_execution_time 0', 0);
  166. } else {
  167. error_log('Update-db script: could not change memory and time limits', 0);
  168. }
  169. }
  170. /**
  171. * Detects browser's language.
  172. * @return string Returns a language identificator, i.e. 'english', 'spanish', ...
  173. * @author Ivan Tcholakov, 2010
  174. */
  175. function detect_browser_language()
  176. {
  177. static $language_index = [
  178. 'ar' => 'arabic',
  179. 'ast' => 'asturian',
  180. 'bg' => 'bulgarian',
  181. 'bs' => 'bosnian',
  182. 'ca' => 'catalan',
  183. 'zh' => 'simpl_chinese',
  184. 'zh-tw' => 'trad_chinese',
  185. 'cs' => 'czech',
  186. 'da' => 'danish',
  187. 'prs' => 'dari',
  188. 'de' => 'german',
  189. 'el' => 'greek',
  190. 'en' => 'english',
  191. 'es' => 'spanish',
  192. 'eo' => 'esperanto',
  193. 'eu' => 'basque',
  194. 'fa' => 'persian',
  195. 'fr' => 'french',
  196. 'fur' => 'friulian',
  197. 'gl' => 'galician',
  198. 'ka' => 'georgian',
  199. 'hr' => 'croatian',
  200. 'he' => 'hebrew',
  201. 'hi' => 'hindi',
  202. 'id' => 'indonesian',
  203. 'it' => 'italian',
  204. 'ko' => 'korean',
  205. 'lv' => 'latvian',
  206. 'lt' => 'lithuanian',
  207. 'mk' => 'macedonian',
  208. 'hu' => 'hungarian',
  209. 'ms' => 'malay',
  210. 'nl' => 'dutch',
  211. 'ja' => 'japanese',
  212. 'no' => 'norwegian',
  213. 'oc' => 'occitan',
  214. 'ps' => 'pashto',
  215. 'pl' => 'polish',
  216. 'pt' => 'portuguese',
  217. 'pt-br' => 'brazilian',
  218. 'ro' => 'romanian',
  219. 'qu' => 'quechua_cusco',
  220. 'ru' => 'russian',
  221. 'sk' => 'slovak',
  222. 'sl' => 'slovenian',
  223. 'sr' => 'serbian',
  224. 'fi' => 'finnish',
  225. 'sv' => 'swedish',
  226. 'th' => 'thai',
  227. 'tr' => 'turkish',
  228. 'uk' => 'ukrainian',
  229. 'vi' => 'vietnamese',
  230. 'sw' => 'swahili',
  231. 'yo' => 'yoruba'
  232. ];
  233. $system_available_languages = get_language_folder_list();
  234. $accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
  235. foreach ($language_index as $code => $language) {
  236. if (strpos($accept_languages, $code) === 0) {
  237. if (!empty($system_available_languages[$language])) {
  238. return $language;
  239. }
  240. }
  241. }
  242. $user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT']));
  243. foreach ($language_index as $code => $language) {
  244. if (@preg_match("/[\[\( ]{$code}[;,_\-\)]/", $user_agent)) {
  245. if (!empty($system_available_languages[$language])) {
  246. return $language;
  247. }
  248. }
  249. }
  250. return 'english';
  251. }
  252. /* FILESYSTEM RELATED FUNCTIONS */
  253. /**
  254. * This function checks if the given folder is writable
  255. * @param string $folder Full path to a folder
  256. * @param bool $suggestion Whether to show a suggestion or not
  257. * @return string
  258. */
  259. function check_writable($folder, $suggestion = false)
  260. {
  261. if (is_writable($folder)) {
  262. return Display::label(get_lang('Writable'), 'success');
  263. } else {
  264. if ($suggestion) {
  265. return Display::label(get_lang('NotWritable'), 'info');
  266. } else {
  267. return Display::label(get_lang('NotWritable'), 'important');
  268. }
  269. }
  270. }
  271. /**
  272. * This function checks if the given folder is readable
  273. * @param string $folder Full path to a folder
  274. * @param bool $suggestion Whether to show a suggestion or not
  275. *
  276. * @return string
  277. */
  278. function checkReadable($folder, $suggestion = false)
  279. {
  280. if (is_readable($folder)) {
  281. return Display::label(get_lang('Readable'), 'success');
  282. } else {
  283. if ($suggestion) {
  284. return Display::label(get_lang('NotReadable'), 'info');
  285. } else {
  286. return Display::label(get_lang('NotReadable'), 'important');
  287. }
  288. }
  289. }
  290. /**
  291. * This function is similar to the core file() function, except that it
  292. * works with line endings in Windows (which is not the case of file())
  293. * @param string $filename
  294. *
  295. * @return array The lines of the file returned as an array
  296. */
  297. function file_to_array($filename)
  298. {
  299. if (!is_readable($filename) || is_dir($filename)) {
  300. return [];
  301. }
  302. $fp = fopen($filename, 'rb');
  303. $buffer = fread($fp, filesize($filename));
  304. fclose($fp);
  305. return explode('<br />', nl2br($buffer));
  306. }
  307. /**
  308. * We assume this function is called from install scripts that reside inside the install folder.
  309. */
  310. function set_file_folder_permissions()
  311. {
  312. @chmod('.', 0755); //set permissions on install dir
  313. @chmod('..', 0755); //set permissions on parent dir of install dir
  314. }
  315. /**
  316. * Write the main system config file
  317. * @param string $path Path to the config file
  318. */
  319. function write_system_config_file($path)
  320. {
  321. global $dbHostForm;
  322. global $dbPortForm;
  323. global $dbUsernameForm;
  324. global $dbPassForm;
  325. global $dbNameForm;
  326. global $urlForm;
  327. global $pathForm;
  328. global $urlAppendPath;
  329. global $languageForm;
  330. global $encryptPassForm;
  331. global $session_lifetime;
  332. global $new_version;
  333. global $new_version_stable;
  334. $root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm)));
  335. $content = file_get_contents(__DIR__.'/'.SYSTEM_CONFIG_FILENAME);
  336. $config['{DATE_GENERATED}'] = date('r');
  337. $config['{DATABASE_HOST}'] = $dbHostForm;
  338. $config['{DATABASE_PORT}'] = $dbPortForm;
  339. $config['{DATABASE_USER}'] = $dbUsernameForm;
  340. $config['{DATABASE_PASSWORD}'] = $dbPassForm;
  341. $config['{DATABASE_MAIN}'] = $dbNameForm;
  342. $config['{ROOT_WEB}'] = $urlForm;
  343. $config['{ROOT_SYS}'] = $root_sys;
  344. $config['{URL_APPEND_PATH}'] = $urlAppendPath;
  345. $config['{PLATFORM_LANGUAGE}'] = $languageForm;
  346. $config['{SECURITY_KEY}'] = md5(uniqid(rand().time()));
  347. $config['{ENCRYPT_PASSWORD}'] = $encryptPassForm;
  348. $config['SESSION_LIFETIME'] = $session_lifetime;
  349. $config['{NEW_VERSION}'] = $new_version;
  350. $config['NEW_VERSION_STABLE'] = trueFalse($new_version_stable);
  351. foreach ($config as $key => $value) {
  352. $content = str_replace($key, $value, $content);
  353. }
  354. $fp = @ fopen($path, 'w');
  355. if (!$fp) {
  356. echo '<strong><font color="red">Your script doesn\'t have write access to the config directory</font></strong><br />
  357. <em>('.str_replace('\\', '/', realpath($path)).')</em><br /><br />
  358. You probably do not have write access on Chamilo root directory,
  359. i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br />
  360. Your problems can be related on two possible causes:<br />
  361. <ul>
  362. <li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li>
  363. <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>
  364. </ul>
  365. <a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br />
  366. Please go back to step 5.
  367. <p><input type="submit" name="step5" value="&lt; Back" /></p>
  368. </td></tr></table></form></body></html>';
  369. exit;
  370. }
  371. fwrite($fp, $content);
  372. fclose($fp);
  373. }
  374. /**
  375. * Returns a list of language directories.
  376. */
  377. function get_language_folder_list()
  378. {
  379. return [
  380. 'ar' => 'arabic',
  381. 'ast' => 'asturian',
  382. 'bg' => 'bulgarian',
  383. 'bs' => 'bosnian',
  384. 'ca' => 'catalan',
  385. 'zh' => 'simpl_chinese',
  386. 'zh-tw' => 'trad_chinese',
  387. 'cs' => 'czech',
  388. 'da' => 'danish',
  389. 'prs' => 'dari',
  390. 'de' => 'german',
  391. 'el' => 'greek',
  392. 'en' => 'english',
  393. 'es' => 'spanish',
  394. 'eo' => 'esperanto',
  395. 'eu' => 'basque',
  396. 'fa' => 'persian',
  397. 'fr' => 'french',
  398. 'fur' => 'friulian',
  399. 'gl' => 'galician',
  400. 'ka' => 'georgian',
  401. 'hr' => 'croatian',
  402. 'he' => 'hebrew',
  403. 'hi' => 'hindi',
  404. 'id' => 'indonesian',
  405. 'it' => 'italian',
  406. 'ko' => 'korean',
  407. 'lv' => 'latvian',
  408. 'lt' => 'lithuanian',
  409. 'mk' => 'macedonian',
  410. 'hu' => 'hungarian',
  411. 'ms' => 'malay',
  412. 'nl' => 'dutch',
  413. 'ja' => 'japanese',
  414. 'no' => 'norwegian',
  415. 'oc' => 'occitan',
  416. 'ps' => 'pashto',
  417. 'pl' => 'polish',
  418. 'pt' => 'portuguese',
  419. 'pt-br' => 'brazilian',
  420. 'ro' => 'romanian',
  421. 'qu' => 'quechua_cusco',
  422. 'ru' => 'russian',
  423. 'sk' => 'slovak',
  424. 'sl' => 'slovenian',
  425. 'sr' => 'serbian',
  426. 'fi' => 'finnish',
  427. 'sv' => 'swedish',
  428. 'th' => 'thai',
  429. 'tr' => 'turkish',
  430. 'uk' => 'ukrainian',
  431. 'vi' => 'vietnamese',
  432. 'sw' => 'swahili',
  433. 'yo' => 'yoruba'
  434. ];
  435. }
  436. /**
  437. * This function returns the value of a parameter from the configuration file
  438. *
  439. * WARNING - this function relies heavily on global variables $updateFromConfigFile
  440. * and $configFile, and also changes these globals. This can be rewritten.
  441. *
  442. * @param string $param the parameter of which the value is returned
  443. * @param string If we want to give the path rather than take it from POST
  444. * @return string the value of the parameter
  445. * @author Olivier Brouckaert
  446. * @author Reworked by Ivan Tcholakov, 2010
  447. */
  448. function get_config_param($param, $updatePath = '')
  449. {
  450. global $configFile, $updateFromConfigFile;
  451. // Look if we already have the queried parameter.
  452. if (is_array($configFile) && isset($configFile[$param])) {
  453. return $configFile[$param];
  454. }
  455. if (empty($updatePath) && !empty($_POST['updatePath'])) {
  456. $updatePath = $_POST['updatePath'];
  457. }
  458. if (empty($updatePath)) {
  459. $updatePath = api_get_path(SYS_PATH);
  460. }
  461. $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath)));
  462. $updateFromInstalledVersionFile = '';
  463. if (empty($updateFromConfigFile)) {
  464. // If update from previous install was requested,
  465. // try to recover config file from Chamilo 1.9.x
  466. if (file_exists($updatePath.'main/inc/conf/configuration.php')) {
  467. $updateFromConfigFile = 'main/inc/conf/configuration.php';
  468. } elseif (file_exists($updatePath.'app/config/configuration.php')) {
  469. $updateFromConfigFile = 'app/config/configuration.php';
  470. } else {
  471. // Give up recovering.
  472. //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);
  473. return null;
  474. }
  475. }
  476. if (file_exists($updatePath.$updateFromConfigFile) &&
  477. !is_dir($updatePath.$updateFromConfigFile)
  478. ) {
  479. require $updatePath.$updateFromConfigFile;
  480. $config = new Zend\Config\Config($_configuration);
  481. return $config->get($param);
  482. }
  483. error_log('Config array could not be found in get_config_param()', 0);
  484. return null;
  485. }
  486. /* DATABASE RELATED FUNCTIONS */
  487. /**
  488. * Gets a configuration parameter from the database. Returns returns null on failure.
  489. * @param string $param Name of param we want
  490. * @return mixed The parameter value or null if not found
  491. */
  492. function get_config_param_from_db($param = '')
  493. {
  494. if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
  495. if (Database::num_rows($res) > 0) {
  496. $row = Database::fetch_array($res);
  497. return $row['selected_value'];
  498. }
  499. }
  500. return null;
  501. }
  502. /**
  503. * Connect to the database and returns the entity manager
  504. * @param string $dbHostForm DB host
  505. * @param string $dbUsernameForm DB username
  506. * @param string $dbPassForm DB password
  507. * @param string $dbNameForm DB name
  508. * @param int $dbPortForm DB port
  509. *
  510. * @return Database
  511. */
  512. function connectToDatabase(
  513. $dbHostForm,
  514. $dbUsernameForm,
  515. $dbPassForm,
  516. $dbNameForm,
  517. $dbPortForm = 3306
  518. ) {
  519. $dbParams = [
  520. 'driver' => 'pdo_mysql',
  521. 'host' => $dbHostForm,
  522. 'port' => $dbPortForm,
  523. 'user' => $dbUsernameForm,
  524. 'password' => $dbPassForm,
  525. 'dbname' => $dbNameForm
  526. ];
  527. $database = new \Database();
  528. $database->connect($dbParams);
  529. return $database;
  530. }
  531. /* DISPLAY FUNCTIONS */
  532. /**
  533. * This function prints class=active_step $current_step=$param
  534. * @param int $param A step in the installer process
  535. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  536. */
  537. function step_active($param)
  538. {
  539. global $current_step;
  540. if ($param == $current_step) {
  541. echo 'class="current-step" ';
  542. }
  543. }
  544. /**
  545. * This function displays the Step X of Y -
  546. * @return string String that says 'Step X of Y' with the right values
  547. */
  548. function display_step_sequence()
  549. {
  550. global $current_step;
  551. return get_lang('Step'.$current_step).' &ndash; ';
  552. }
  553. /**
  554. * Displays a drop down box for selection the preferred language.
  555. */
  556. function display_language_selection_box(
  557. $name = 'language_list',
  558. $default_language = 'english'
  559. ) {
  560. // Reading language list.
  561. $language_list = get_language_folder_list();
  562. // Sanity checks due to the possibility for customizations.
  563. if (!is_array($language_list) || empty($language_list)) {
  564. $language_list = ['en' => 'English'];
  565. }
  566. // Sorting again, if it is necessary.
  567. //asort($language_list);
  568. // More sanity checks.
  569. if (!array_key_exists($default_language, $language_list)) {
  570. if (array_key_exists('en', $language_list)) {
  571. $default_language = 'en';
  572. } else {
  573. $language_keys = array_keys($language_list);
  574. $default_language = $language_keys[0];
  575. }
  576. }
  577. // Displaying the box.
  578. $html = '';
  579. $html .= "\t\t<select class='selectpicker show-tick' name=\"$name\">\n";
  580. foreach ($language_list as $key => $value) {
  581. if ($key == $default_language) {
  582. $option_end = ' selected="selected">';
  583. } else {
  584. $option_end = '>';
  585. }
  586. $html .= "\t\t\t<option value=\"$key\"$option_end";
  587. $html .= $value;
  588. $html .= "</option>\n";
  589. }
  590. $html .= "\t\t</select>\n";
  591. return $html;
  592. }
  593. /**
  594. * This function displays a language dropdown box so that the installatioin
  595. * can be done in the language of the user
  596. */
  597. function display_language_selection()
  598. {
  599. ?>
  600. <h2><?php get_lang('WelcomeToTheChamiloInstaller'); ?></h2>
  601. <div class="RequirementHeading">
  602. <h2><?php echo display_step_sequence(); ?>
  603. <?php echo get_lang('InstallationLanguage'); ?>
  604. </h2>
  605. <p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
  606. <form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
  607. <div class="form-group">
  608. <div class="col-sm-4">
  609. <?php echo display_language_selection_box('language_list', api_get_interface_language()); ?>
  610. </div>
  611. <div class="col-sm-6">
  612. <button type="submit" name="step1" class="btn btn-success" value="<?php echo get_lang('Next'); ?>">
  613. <em class="fa fa-forward"> </em>
  614. <?php echo get_lang('Next'); ?></button>
  615. </div>
  616. </div>
  617. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  618. </form>
  619. </div>
  620. <div class="RequirementHeading">
  621. <?php echo get_lang('YourLanguageNotThereContactUs'); ?>
  622. </div>
  623. <?php
  624. }
  625. /**
  626. * This function displays the requirements for installing Chamilo.
  627. *
  628. * @param string $installType
  629. * @param boolean $badUpdatePath
  630. * @param boolean $badUpdatePath
  631. * @param string $updatePath The updatePath given (if given)
  632. * @param array $update_from_version_8 The different subversions from version 1.9
  633. *
  634. * @author unknow
  635. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  636. */
  637. function display_requirements(
  638. $installType,
  639. $badUpdatePath,
  640. $updatePath = '',
  641. $update_from_version_8 = []
  642. ) {
  643. global $_setting;
  644. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Requirements')."</h2></div>";
  645. echo '<div class="RequirementText">';
  646. echo '<strong>'.get_lang('ReadThoroughly').'</strong><br />';
  647. echo get_lang('MoreDetails').' <a href="../../documentation/installation_guide.html" target="_blank">'.get_lang('ReadTheInstallationGuide').'</a>.<br />'."\n";
  648. if ($installType == 'update') {
  649. echo get_lang('IfYouPlanToUpgradeFromOlderVersionYouMightWantToHaveAlookAtTheChangelog').'<br />';
  650. }
  651. echo '</div>';
  652. $properlyAccessUrl = checkAccessUrl();
  653. if (!$properlyAccessUrl) {
  654. echo '
  655. <div class="alert alert-danger">
  656. ' . Display::return_icon('error.png', get_lang('Error'), [], ICON_SIZE_MEDIUM, true, false, true).
  657. ' '.
  658. sprintf(get_lang('InstallMultiURLDetectedNotMainURL'), api_get_configuration_value('root_web')).'
  659. </div>
  660. ';
  661. }
  662. // SERVER REQUIREMENTS
  663. echo '<div class="RequirementHeading"><h4>'.get_lang('ServerRequirements').'</h4>';
  664. $timezone = checkPhpSettingExists("date.timezone");
  665. if (!$timezone) {
  666. echo "<div class='alert alert-warning'>".
  667. Display::return_icon(
  668. 'warning.png',
  669. get_lang('Warning'),
  670. '',
  671. ICON_SIZE_MEDIUM,
  672. true,
  673. false,
  674. false
  675. ).
  676. get_lang("DateTimezoneSettingNotSet")."</div>";
  677. }
  678. echo '<div class="RequirementText">'.get_lang('ServerRequirementsInfo').'</div>';
  679. echo '<div class="RequirementContent">';
  680. echo '<table class="table">
  681. <tr>
  682. <td class="requirements-item">'.get_lang('PHPVersion').' >= '.REQUIRED_PHP_VERSION.'</td>
  683. <td class="requirements-value">';
  684. if (version_compare(phpversion(), REQUIRED_PHP_VERSION, '>=') > 1) {
  685. echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
  686. } else {
  687. echo '<strong><font color="green">'.get_lang('PHPVersionOK').' '.phpversion().'</font></strong>';
  688. }
  689. echo '</td>
  690. </tr>
  691. <tr>
  692. <td class="requirements-item"><a href="http://php.net/manual/en/book.session.php" target="_blank">Session</a> '.get_lang('Support').'</td>
  693. <td class="requirements-value">'.checkExtension('session', get_lang('Yes'), get_lang('ExtensionSessionsNotAvailable')).'</td>
  694. </tr>
  695. <tr>
  696. <td class="requirements-item"><a href="http://php.net/manual/en/book.mysql.php" target="_blank">pdo_mysql</a> '.get_lang('Support').'</td>
  697. <td class="requirements-value">'.checkExtension('pdo_mysql', get_lang('Yes'), get_lang('ExtensionMySQLNotAvailable')).'</td>
  698. </tr>
  699. <tr>
  700. <td class="requirements-item"><a href="http://php.net/manual/en/book.zip.php" target="_blank">Zip</a> '.get_lang('Support').'</td>
  701. <td class="requirements-value">'.checkExtension('zip', get_lang('Yes'), get_lang('ExtensionNotAvailable')).'</td>
  702. </tr>
  703. <tr>
  704. <td class="requirements-item"><a href="http://php.net/manual/en/book.zlib.php" target="_blank">Zlib</a> '.get_lang('Support').'</td>
  705. <td class="requirements-value">'.checkExtension('zlib', get_lang('Yes'), get_lang('ExtensionZlibNotAvailable')).'</td>
  706. </tr>
  707. <tr>
  708. <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>
  709. <td class="requirements-value">'.checkExtension('pcre', get_lang('Yes'), get_lang('ExtensionPCRENotAvailable')).'</td>
  710. </tr>
  711. <tr>
  712. <td class="requirements-item"><a href="http://php.net/manual/en/book.xml.php" target="_blank">XML</a> '.get_lang('Support').'</td>
  713. <td class="requirements-value">'.checkExtension('xml', get_lang('Yes'), get_lang('No')).'</td>
  714. </tr>
  715. <tr>
  716. <td class="requirements-item"><a href="http://php.net/manual/en/book.intl.php" target="_blank">Internationalization</a> '.get_lang('Support').'</td>
  717. <td class="requirements-value">'.checkExtension('intl', get_lang('Yes'), get_lang('No')).'</td>
  718. </tr>
  719. <tr>
  720. <td class="requirements-item"><a href="http://php.net/manual/en/book.json.php" target="_blank">JSON</a> '.get_lang('Support').'</td>
  721. <td class="requirements-value">'.checkExtension('json', get_lang('Yes'), get_lang('No')).'</td>
  722. </tr>
  723. <tr>
  724. <td class="requirements-item"><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a> '.get_lang('Support').'</td>
  725. <td class="requirements-value">'.checkExtension('gd', get_lang('Yes'), get_lang('ExtensionGDNotAvailable')).'</td>
  726. </tr>
  727. <tr>
  728. <td class="requirements-item"><a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a>'.get_lang('Support').'</td>
  729. <td class="requirements-value">'.checkExtension('curl', get_lang('Yes'), get_lang('No')).'</td>
  730. </tr>
  731. <tr>
  732. <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>
  733. <td class="requirements-value">'.checkExtension('mbstring', get_lang('Yes'), get_lang('ExtensionMBStringNotAvailable'), true).'</td>
  734. </tr>
  735. <tr>
  736. <td class="requirements-item"><a href="http://php.net/opcache" target="_blank">Zend OpCache</a> '.get_lang('Support').' ('.get_lang('Optional').')</td>
  737. <td class="requirements-value">'.checkExtension('Zend OPcache', get_lang('Yes'), get_lang('No'), true, 'opcache.enable').'</td>
  738. </tr>
  739. <tr>
  740. <td class="requirements-item"><a href="http://php.net/apcu" target="_blank">APCu</a> '.get_lang('Support').' ('.get_lang('Optional').')</td>
  741. <td class="requirements-value">'.checkExtension('apcu', get_lang('Yes'), get_lang('No'), true, 'apc.enabled').'</td>
  742. </tr>
  743. <tr>
  744. <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>
  745. <td class="requirements-value">'.checkExtension('iconv', get_lang('Yes'), get_lang('No'), true).'</td>
  746. </tr>
  747. <tr>
  748. <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>
  749. <td class="requirements-value">'.checkExtension('ldap', get_lang('Yes'), get_lang('ExtensionLDAPNotAvailable'), true).'</td>
  750. </tr>
  751. <tr>
  752. <td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang('Support').' ('.get_lang('Optional').')</td>
  753. <td class="requirements-value">'.checkExtension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
  754. </tr>
  755. </table>';
  756. echo '</div>';
  757. echo '</div>';
  758. // RECOMMENDED SETTINGS
  759. // Note: these are the settings for Joomla, does this also apply for Chamilo?
  760. // Note: also add upload_max_filesize here so that large uploads are possible
  761. echo '<div class="RequirementHeading"><h4>'.get_lang('RecommendedSettings').'</h4>';
  762. echo '<div class="RequirementText">'.get_lang('RecommendedSettingsInfo').'</div>';
  763. echo '<div class="RequirementContent">';
  764. echo '<table class="table">
  765. <tr>
  766. <th>'.get_lang('Setting').'</th>
  767. <th>'.get_lang('Recommended').'</th>
  768. <th>'.get_lang('Actual').'</th>
  769. </tr>
  770. <tr>
  771. <td class="requirements-item"><a href="http://php.net/manual/features.safe-mode.php">Safe Mode</a></td>
  772. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  773. <td class="requirements-value">'.checkPhpSetting('safe_mode', 'OFF').'</td>
  774. </tr>
  775. <tr>
  776. <td class="requirements-item"><a href="http://php.net/manual/ref.errorfunc.php#ini.display-errors">Display Errors</a></td>
  777. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  778. <td class="requirements-value">'.checkPhpSetting('display_errors', 'OFF').'</td>
  779. </tr>
  780. <tr>
  781. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.file-uploads">File Uploads</a></td>
  782. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  783. <td class="requirements-value">'.checkPhpSetting('file_uploads', 'ON').'</td>
  784. </tr>
  785. <tr>
  786. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-gpc">Magic Quotes GPC</a></td>
  787. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  788. <td class="requirements-value">'.checkPhpSetting('magic_quotes_gpc', 'OFF').'</td>
  789. </tr>
  790. <tr>
  791. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-runtime">Magic Quotes Runtime</a></td>
  792. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  793. <td class="requirements-value">'.checkPhpSetting('magic_quotes_runtime', 'OFF').'</td>
  794. </tr>
  795. <tr>
  796. <td class="requirements-item"><a href="http://php.net/manual/security.globals.php">Register Globals</a></td>
  797. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  798. <td class="requirements-value">'.checkPhpSetting('register_globals', 'OFF').'</td>
  799. </tr>
  800. <tr>
  801. <td class="requirements-item"><a href="http://php.net/manual/ref.session.php#ini.session.auto-start">Session auto start</a></td>
  802. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  803. <td class="requirements-value">'.checkPhpSetting('session.auto_start', 'OFF').'</td>
  804. </tr>
  805. <tr>
  806. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.short-open-tag">Short Open Tag</a></td>
  807. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  808. <td class="requirements-value">'.checkPhpSetting('short_open_tag', 'OFF').'</td>
  809. </tr>
  810. <tr>
  811. <td class="requirements-item"><a href="http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly">Cookie HTTP Only</a></td>
  812. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  813. <td class="requirements-value">'.checkPhpSetting('session.cookie_httponly', 'ON').'</td>
  814. </tr>
  815. <tr>
  816. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.upload-max-filesize">Maximum upload file size</a></td>
  817. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M', 'success').'</td>
  818. <td class="requirements-value">'.compare_setting_values(ini_get('upload_max_filesize'), REQUIRED_MIN_UPLOAD_MAX_FILESIZE).'</td>
  819. </tr>
  820. <tr>
  821. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.post-max-size">Maximum post size</a></td>
  822. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_POST_MAX_SIZE.'M', 'success').'</td>
  823. <td class="requirements-value">'.compare_setting_values(ini_get('post_max_size'), REQUIRED_MIN_POST_MAX_SIZE).'</td>
  824. </tr>
  825. <tr>
  826. <td class="requirements-item"><a href="http://www.php.net/manual/en/ini.core.php#ini.memory-limit">Memory Limit</a></td>
  827. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_MEMORY_LIMIT.'M', 'success').'</td>
  828. <td class="requirements-value">'.compare_setting_values(ini_get('memory_limit'), REQUIRED_MIN_MEMORY_LIMIT).'</td>
  829. </tr>
  830. </table>';
  831. echo ' </div>';
  832. echo '</div>';
  833. // DIRECTORY AND FILE PERMISSIONS
  834. echo '<div class="RequirementHeading"><h4>'.get_lang('DirectoryAndFilePermissions').'</h4>';
  835. echo '<div class="RequirementText">'.get_lang('DirectoryAndFilePermissionsInfo').'</div>';
  836. echo '<div class="RequirementContent">';
  837. $course_attempt_name = '__XxTestxX__';
  838. $course_dir = api_get_path(SYS_COURSE_PATH).$course_attempt_name;
  839. //Just in case
  840. @unlink($course_dir.'/test.php');
  841. @rmdir($course_dir);
  842. $perms_dir = [0777, 0755, 0775, 0770, 0750, 0700];
  843. $perms_fil = [0666, 0644, 0664, 0660, 0640, 0600];
  844. $course_test_was_created = false;
  845. $dir_perm_verified = 0777;
  846. foreach ($perms_dir as $perm) {
  847. $r = @mkdir($course_dir, $perm);
  848. if ($r === true) {
  849. $dir_perm_verified = $perm;
  850. $course_test_was_created = true;
  851. break;
  852. }
  853. }
  854. $fil_perm_verified = 0666;
  855. $file_course_test_was_created = false;
  856. if (is_dir($course_dir)) {
  857. foreach ($perms_fil as $perm) {
  858. if ($file_course_test_was_created == true) {
  859. break;
  860. }
  861. $r = @touch($course_dir.'/test.php', $perm);
  862. if ($r === true) {
  863. $fil_perm_verified = $perm;
  864. if (check_course_script_interpretation($course_dir, $course_attempt_name, 'test.php')) {
  865. $file_course_test_was_created = true;
  866. }
  867. }
  868. }
  869. }
  870. @unlink($course_dir.'/test.php');
  871. @rmdir($course_dir);
  872. $_SESSION['permissions_for_new_directories'] = $_setting['permissions_for_new_directories'] = $dir_perm_verified;
  873. $_SESSION['permissions_for_new_files'] = $_setting['permissions_for_new_files'] = $fil_perm_verified;
  874. $dir_perm = Display::label('0'.decoct($dir_perm_verified), 'info');
  875. $file_perm = Display::label('0'.decoct($fil_perm_verified), 'info');
  876. $courseTestLabel = Display::label(get_lang('No'), 'important');
  877. if ($course_test_was_created && $file_course_test_was_created) {
  878. $courseTestLabel = Display::label(get_lang('Yes'), 'success');
  879. }
  880. if ($course_test_was_created && !$file_course_test_was_created) {
  881. $courseTestLabel = Display::label(get_lang('Warning'), 'warning');
  882. $courseTestLabel .= '<br />'.sprintf(
  883. get_lang('InstallWarningCouldNotInterpretPHP'),
  884. api_get_path(WEB_COURSE_PATH).$course_attempt_name.'/test.php'
  885. );
  886. }
  887. if (!$course_test_was_created && !$file_course_test_was_created) {
  888. $courseTestLabel = Display::label(get_lang('No'), 'important');
  889. }
  890. $oldConf = '';
  891. if (file_exists(api_get_path(SYS_CODE_PATH).'inc/conf/configuration.php')) {
  892. $oldConf = '<tr>
  893. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'inc/conf</td>
  894. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'inc/conf').'</td>
  895. </tr>';
  896. }
  897. echo '<table class="table">
  898. '.$oldConf.'
  899. <tr>
  900. <td class="requirements-item">'.api_get_path(SYS_APP_PATH).'</td>
  901. <td class="requirements-value">'.check_writable(api_get_path(SYS_APP_PATH)).'</td>
  902. </tr>
  903. <tr>
  904. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'default_course_document/images/</td>
  905. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'default_course_document/images/').'</td>
  906. </tr>
  907. <tr>
  908. <td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'lang/</td>
  909. <td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'lang/', true).' <br />('.get_lang('SuggestionOnlyToEnableSubLanguageFeatureOrUpgradeProcess').')</td>
  910. </tr>
  911. <tr>
  912. <td class="requirements-item">'.api_get_path(SYS_PATH).'vendor/</td>
  913. <td class="requirements-value">'.checkReadable(api_get_path(SYS_PATH).'vendor').'</td>
  914. </tr>
  915. <tr>
  916. <td class="requirements-item">'.api_get_path(SYS_PUBLIC_PATH).'</td>
  917. <td class="requirements-value">'.check_writable(api_get_path(SYS_PUBLIC_PATH)).'</td>
  918. </tr>
  919. <tr>
  920. <td class="requirements-item">'.get_lang('CourseTestWasCreated').'</td>
  921. <td class="requirements-value">'.$courseTestLabel.' </td>
  922. </tr>
  923. <tr>
  924. <td class="requirements-item">'.get_lang('PermissionsForNewDirs').'</td>
  925. <td class="requirements-value">'.$dir_perm.' </td>
  926. </tr>
  927. <tr>
  928. <td class="requirements-item">'.get_lang('PermissionsForNewFiles').'</td>
  929. <td class="requirements-value">'.$file_perm.' </td>
  930. </tr>
  931. </table>';
  932. echo ' </div>';
  933. echo '</div>';
  934. if ($installType == 'update' && (empty($updatePath) || $badUpdatePath)) {
  935. if ($badUpdatePath) {
  936. ?>
  937. <div class="alert alert-warning">
  938. <?php echo get_lang('Error'); ?>!<br />
  939. Chamilo <?php echo implode('|', $update_from_version_8).' '.get_lang('HasNotBeenFoundInThatDir'); ?>.
  940. </div>
  941. <?php
  942. } else {
  943. echo '<br />';
  944. } ?>
  945. <div class="row">
  946. <div class="col-md-12">
  947. <p><?php echo get_lang('OldVersionRootPath'); ?>:
  948. <input type="text" name="updatePath" size="50" value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities($updatePath) : ''; ?>" />
  949. </p>
  950. <p>
  951. <button type="submit" class="btn btn-default" name="step1" value="<?php echo get_lang('Back'); ?>" >
  952. <em class="fa fa-backward"> <?php echo get_lang('Back'); ?></em>
  953. </button>
  954. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  955. <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;" >
  956. <em class="fa fa-forward"> </em> <?php echo get_lang('Next'); ?>
  957. </button>
  958. </p>
  959. </div>
  960. </div>
  961. <?php
  962. } else {
  963. $error = false;
  964. // First, attempt to set writing permissions if we don't have them yet
  965. $perm = octdec('0770');
  966. $perm_file = octdec('0770');
  967. $notWritable = [];
  968. $checked_writable = api_get_path(SYS_APP_PATH);
  969. if (!is_writable($checked_writable)) {
  970. $notWritable[] = $checked_writable;
  971. @chmod($checked_writable, $perm);
  972. }
  973. $checked_writable = api_get_path(SYS_PUBLIC_PATH);
  974. if (!is_writable($checked_writable)) {
  975. $notWritable[] = $checked_writable;
  976. @chmod($checked_writable, $perm);
  977. }
  978. $checked_writable = api_get_path(SYS_CODE_PATH).'default_course_document/images/';
  979. if (!is_writable($checked_writable)) {
  980. $notWritable[] = $checked_writable;
  981. @chmod($checked_writable, $perm);
  982. }
  983. if ($course_test_was_created == false) {
  984. $error = true;
  985. }
  986. $checked_writable = api_get_path(CONFIGURATION_PATH).'configuration.php';
  987. if (file_exists($checked_writable) && !is_writable($checked_writable)) {
  988. $notWritable[] = $checked_writable;
  989. @chmod($checked_writable, $perm_file);
  990. }
  991. // Second, if this fails, report an error
  992. //--> The user would have to adjust the permissions manually
  993. if (count($notWritable) > 0) {
  994. $error = true; ?>
  995. <div class="text-danger">
  996. <h3 class="text-center"><?php echo get_lang('Warning') ?></h3>
  997. <p>
  998. <?php printf(get_lang('NoWritePermissionPleaseReadInstallGuide'), '<a href="../../documentation/installation_guide.html" target="blank">', '</a>'); ?>
  999. </p>
  1000. </div>
  1001. <?php
  1002. echo '<ul>';
  1003. foreach ($notWritable as $value) {
  1004. echo '<li class="text-danger">'.$value.'</li>';
  1005. }
  1006. echo '</ul>';
  1007. } elseif (file_exists(api_get_path(CONFIGURATION_PATH).'configuration.php')) {
  1008. // Check wether a Chamilo configuration file already exists.
  1009. echo '<div class="alert alert-warning"><h4><center>';
  1010. echo get_lang('WarningExistingLMSInstallationDetected');
  1011. echo '</center></h4></div>';
  1012. }
  1013. $deprecated = [
  1014. api_get_path(SYS_CODE_PATH).'exercice/',
  1015. api_get_path(SYS_CODE_PATH).'newscorm/',
  1016. api_get_path(SYS_PLUGIN_PATH).'ticket/',
  1017. api_get_path(SYS_PLUGIN_PATH).'skype/'
  1018. ];
  1019. $deprecatedToRemove = [];
  1020. foreach ($deprecated as $deprecatedDirectory) {
  1021. if (!is_dir($deprecatedDirectory)) {
  1022. continue;
  1023. }
  1024. $deprecatedToRemove[] = $deprecatedDirectory;
  1025. }
  1026. if (count($deprecatedToRemove) > 0) {
  1027. $error = true; ?>
  1028. <p class="text-danger"><?php echo get_lang('WarningForDeprecatedDirectoriesForUpgrade') ?></p>
  1029. <ul>
  1030. <?php foreach ($deprecatedToRemove as $deprecatedDirectory) {
  1031. ?>
  1032. <li class="text-danger"><?php echo $deprecatedDirectory ?></li>
  1033. <?php
  1034. } ?>
  1035. </ul>
  1036. <?php
  1037. }
  1038. if (!$properlyAccessUrl) {
  1039. $error = true;
  1040. }
  1041. // And now display the choice buttons (go back or install)?>
  1042. <p align="center" style="padding-top:15px">
  1043. <button type="submit" name="step1" class="btn btn-default" onclick="javascript: window.location='index.php'; return false;" value="<?php echo get_lang('Previous'); ?>" >
  1044. <em class="fa fa-backward"> </em> <?php echo get_lang('Previous'); ?>
  1045. </button>
  1046. <button type="submit" name="step2_install" class="btn btn-success" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) {
  1047. echo 'disabled="disabled"';
  1048. } ?> >
  1049. <em class="fa fa-forward"> </em> <?php echo get_lang('NewInstallation'); ?>
  1050. </button>
  1051. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1052. <button type="submit" class="btn btn-default" <?php echo !$error ?: 'disabled="disabled"' ?> name="step2_update_8" value="Upgrade from Chamilo 1.9.x">
  1053. <em class="fa fa-forward" aria-hidden="true"></em> <?php echo get_lang('UpgradeVersion') ?>
  1054. </button>
  1055. </p>
  1056. <?php
  1057. }
  1058. }
  1059. /**
  1060. * Displays the license (GNU GPL) as step 2, with
  1061. * - an "I accept" button named step3 to proceed to step 3;
  1062. * - a "Back" button named step1 to go back to the first step.
  1063. */
  1064. function display_license_agreement()
  1065. {
  1066. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Licence').'</h2>';
  1067. echo '<p>'.get_lang('LMSLicenseInfo').'</p>';
  1068. echo '<p><a href="../../documentation/license.html" target="_blank">'.get_lang('PrintVers').'</a></p>';
  1069. echo '</div>'; ?>
  1070. <div class="row">
  1071. <div class="col-md-12">
  1072. <pre style="overflow: auto; height: 200px; margin-top: 5px;">
  1073. <?php echo api_htmlentities(@file_get_contents(api_get_path(SYS_PATH).'documentation/license.txt')); ?>
  1074. </pre>
  1075. <div class="checkbox">
  1076. <label>
  1077. <input type="checkbox" name="accept" id="accept_licence" value="1" />
  1078. <?php echo get_lang('IAccept'); ?>
  1079. </label>
  1080. </div>
  1081. </div>
  1082. </div>
  1083. <div class="row">
  1084. <div class="col-md-12">
  1085. <p class="alert alert-info"><?php echo get_lang('LMSMediaLicense'); ?></p>
  1086. </div>
  1087. </div>
  1088. <!-- Contact information form -->
  1089. <div class="section-parameters">
  1090. <a href="javascript://" class = "advanced_parameters" >
  1091. <span id="img_plus_and_minus">&nbsp;<i class="fa fa-eye" aria-hidden="true"></i>&nbsp;<?php echo get_lang('ContactInformation') ?></span>
  1092. </a>
  1093. </div>
  1094. <div id="id_contact_form" style="display:block">
  1095. <div class="normal-message"><?php echo get_lang('ContactInformationDescription') ?></div>
  1096. <div id="contact_registration">
  1097. <p><?php echo get_contact_registration_form() ?></p><br />
  1098. </div>
  1099. </div>
  1100. <div class="text-center">
  1101. <button type="submit" class="btn btn-default" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" >
  1102. <em class="fa fa-backward"> </em> <?php echo get_lang('Previous'); ?>
  1103. </button>
  1104. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1105. <button type="submit" id="license-next" 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;" >
  1106. <em class="fa fa-forward"> </em> <?php echo get_lang('Next'); ?>
  1107. </button>
  1108. </div>
  1109. <?php
  1110. }
  1111. /**
  1112. * Get contact registration form
  1113. */
  1114. function get_contact_registration_form()
  1115. {
  1116. $html = '
  1117. <div class="form-horizontal">
  1118. <div class="panel panel-default">
  1119. <div class="panel-body">
  1120. <div id="div_sent_information"></div>
  1121. <div class="form-group">
  1122. <label class="col-sm-3"><span class="form_required">*</span>'.get_lang('Name').'</label>
  1123. <div class="col-sm-9"><input id="person_name" class="form-control" type="text" name="person_name" size="30" /></div>
  1124. </div>
  1125. <div class="form-group">
  1126. <label class="col-sm-3"><span class="form_required">*</span>'.get_lang('Email').'</label>
  1127. <div class="col-sm-9"><input id="person_email" class="form-control" type="text" name="person_email" size="30" /></div>
  1128. </div>
  1129. <div class="form-group">
  1130. <label class="col-sm-3"><span class="form_required">*</span>'.get_lang('CompanyName').'</label>
  1131. <div class="col-sm-9"><input id="company_name" class="form-control" type="text" name="company_name" size="30" /></div>
  1132. </div>
  1133. <div class="form-group">
  1134. <label class="col-sm-3"><span class="form_required">*</span>'.get_lang('CompanyActivity').'</label>
  1135. <div class="col-sm-9">
  1136. <select class="selectpicker show-tick" name="company_activity" id="company_activity" >
  1137. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1138. <Option value="Advertising/Marketing/PR">Advertising/Marketing/PR</Option><Option value="Agriculture/Forestry">Agriculture/Forestry</Option>
  1139. <Option value="Architecture">Architecture</Option><Option value="Banking/Finance">Banking/Finance</Option>
  1140. <Option value="Biotech/Pharmaceuticals">Biotech/Pharmaceuticals</Option><Option value="Business Equipment">Business Equipment</Option>
  1141. <Option value="Business Services">Business Services</Option><Option value="Construction">Construction</Option>
  1142. <Option value="Consulting/Research">Consulting/Research</Option><Option value="Education">Education</Option>
  1143. <Option value="Engineering">Engineering</Option><Option value="Environmental">Environmental</Option>
  1144. <Option value="Government">Government</Option><Option value="Healthcare">Health Care</Option>
  1145. <Option value="Hospitality/Lodging/Travel">Hospitality/Lodging/Travel</Option><Option value="Insurance">Insurance</Option>
  1146. <Option value="Legal">Legal</Option><Option value="Manufacturing">Manufacturing</Option>
  1147. <Option value="Media/Entertainment">Media/Entertainment</Option><Option value="Mortgage">Mortgage</Option>
  1148. <Option value="Non-Profit">Non-Profit</Option><Option value="Real Estate">Real Estate</Option>
  1149. <Option value="Restaurant">Restaurant</Option><Option value="Retail">Retail</Option>
  1150. <Option value="Shipping/Transportation">Shipping/Transportation</Option>
  1151. <Option value="Technology">Technology</Option><Option value="Telecommunications">Telecommunications</Option>
  1152. <Option value="Other">Other</Option>
  1153. </select>
  1154. </div>
  1155. </div>
  1156. <div class="form-group">
  1157. <label class="col-sm-3"><span class="form_required">*</span>'.get_lang('PersonRole').'</label>
  1158. <div class="col-sm-9">
  1159. <select class="selectpicker show-tick" name="person_role" id="person_role" >
  1160. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1161. <Option value="Administration">Administration</Option><Option value="CEO/President/ Owner">CEO/President/ Owner</Option>
  1162. <Option value="CFO">CFO</Option><Option value="CIO/CTO">CIO/CTO</Option>
  1163. <Option value="Consultant">Consultant</Option><Option value="Customer Service">Customer Service</Option>
  1164. <Option value="Engineer/Programmer">Engineer/Programmer</Option><Option value="Facilities/Operations">Facilities/Operations</Option>
  1165. <Option value="Finance/ Accounting Manager">Finance/ Accounting Manager</Option><Option value="Finance/ Accounting Staff">Finance/ Accounting Staff</Option>
  1166. <Option value="General Manager">General Manager</Option><Option value="Human Resources">Human Resources</Option>
  1167. <Option value="IS/IT Management">IS/IT Management</Option><Option value="IS/ IT Staff">IS/ IT Staff</Option>
  1168. <Option value="Marketing Manager">Marketing Manager</Option><Option value="Marketing Staff">Marketing Staff</Option>
  1169. <Option value="Partner/Principal">Partner/Principal</Option><Option value="Purchasing Manager">Purchasing Manager</Option>
  1170. <Option value="Sales/ Business Dev. Manager">Sales/ Business Dev. Manager</Option><Option value="Sales/ Business Dev.">Sales/ Business Dev.</Option>
  1171. <Option value="Vice President/Senior Manager">Vice President/Senior Manager</Option><Option value="Other">Other</Option>
  1172. </select>
  1173. </div>
  1174. </div>
  1175. <div class="form-group">
  1176. <label class="col-sm-3"><span class="form_required">*</span>'.get_lang('CompanyCountry').'</label>
  1177. <div class="col-sm-9">'.get_countries_list_from_array(true).'</div>
  1178. </div>
  1179. <div class="form-group">
  1180. <label class="col-sm-3">'.get_lang('CompanyCity').'</label>
  1181. <div class="col-sm-9">
  1182. <input type="text" class="form-control" id="company_city" name="company_city" size="30" />
  1183. </div>
  1184. </div>
  1185. <div class="form-group">
  1186. <label class="col-sm-3">'.get_lang('WhichLanguageWouldYouLikeToUseWhenContactingYou').'</label>
  1187. <div class="col-sm-9">
  1188. <select class="selectpicker show-tick" id="language" name="language">
  1189. <option value="bulgarian">Bulgarian</option>
  1190. <option value="indonesian">Bahasa Indonesia</option>
  1191. <option value="bosnian">Bosanski</option>
  1192. <option value="german">Deutsch</option>
  1193. <option selected="selected" value="english">English</option>
  1194. <option value="spanish">Spanish</option>
  1195. <option value="french">Français</option>
  1196. <option value="italian">Italian</option>
  1197. <option value="hungarian">Magyar</option>
  1198. <option value="dutch">Nederlands</option>
  1199. <option value="brazilian">Português do Brasil</option>
  1200. <option value="portuguese">Português europeu</option>
  1201. <option value="slovenian">Slovenčina</option>
  1202. </select>
  1203. </div>
  1204. </div>
  1205. <div class="form-group">
  1206. <label class="col-sm-3">'.get_lang('HaveYouThePowerToTakeFinancialDecisions').'</label>
  1207. <div class="col-sm-9">
  1208. <div class="radio">
  1209. <label>
  1210. <input type="radio" name="financial_decision" id="financial_decision1" value="1" checked /> ' . get_lang('Yes').'
  1211. </label>
  1212. </div>
  1213. <div class="radio">
  1214. <label>
  1215. <input type="radio" name="financial_decision" id="financial_decision2" value="0" /> '.get_lang('No').'
  1216. </label>
  1217. </div>
  1218. </div>
  1219. </div>
  1220. <div class="clear"></div>
  1221. <div class="form-group">
  1222. <div class="col-sm-3">&nbsp;</div>
  1223. <div class="col-sm-9"><button type="button" class="btn btn-default" onclick="javascript:send_contact_information();" value="'.get_lang('SendInformation').'" ><em class="fa fa-floppy-o"></em> '.get_lang('SendInformation').'</button> <span id="loader-button"></span></div>
  1224. </div>
  1225. <div class="form-group">
  1226. <div class="col-sm-3">&nbsp;</div>
  1227. <div class="col-sm-9"><span class="form_required">*</span><small>'.get_lang('FieldRequired').'</small></div>
  1228. </div></div></div>
  1229. </div>';
  1230. return $html;
  1231. }
  1232. /**
  1233. * Displays a parameter in a table row.
  1234. * Used by the display_database_settings_form function.
  1235. * @param string Type of install
  1236. * @param string Name of parameter
  1237. * @param string Field name (in the HTML form)
  1238. * @param string Field value
  1239. * @param string Extra notice (to show on the right side)
  1240. * @param boolean Whether to display in update mode
  1241. * @param string Additional attribute for the <tr> element
  1242. * @return void Direct output
  1243. */
  1244. function displayDatabaseParameter(
  1245. $installType,
  1246. $parameterName,
  1247. $formFieldName,
  1248. $parameterValue,
  1249. $extra_notice,
  1250. $displayWhenUpdate = true,
  1251. $tr_attribute = ''
  1252. ) {
  1253. //echo "<tr ".$tr_attribute.">";
  1254. echo "<label class='col-sm-4'>$parameterName</label>";
  1255. if ($installType == INSTALL_TYPE_UPDATE && $displayWhenUpdate) {
  1256. echo '<input type="hidden" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />'.$parameterValue;
  1257. } else {
  1258. $inputType = $formFieldName == 'dbPassForm' ? 'password' : 'text';
  1259. //Slightly limit the length of the database prefix to avoid having to cut down the databases names later on
  1260. $maxLength = $formFieldName == 'dbPrefixForm' ? '15' : MAX_FORM_FIELD_LENGTH;
  1261. if ($installType == INSTALL_TYPE_UPDATE) {
  1262. echo '<input type="hidden" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />';
  1263. echo api_htmlentities($parameterValue);
  1264. } else {
  1265. echo '<div class="col-sm-5"><input type="'.$inputType.'" class="form-control" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxLength.'" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />'."</div>";
  1266. echo '<div class="col-sm-3">'.$extra_notice.'</div>';
  1267. }
  1268. }
  1269. }
  1270. /**
  1271. * Displays step 3 - a form where the user can enter the installation settings
  1272. * regarding the databases - login and password, names, prefixes, single
  1273. * or multiple databases, tracking or not...
  1274. * @param string $installType
  1275. * @param string $dbHostForm
  1276. * @param string $dbUsernameForm
  1277. * @param string $dbPassForm
  1278. * @param string $dbNameForm
  1279. * @param int $dbPortForm
  1280. * @param string $installationProfile
  1281. */
  1282. function display_database_settings_form(
  1283. $installType,
  1284. $dbHostForm,
  1285. $dbUsernameForm,
  1286. $dbPassForm,
  1287. $dbNameForm,
  1288. $dbPortForm = 3306,
  1289. $installationProfile = ''
  1290. ) {
  1291. if ($installType == 'update') {
  1292. global $_configuration;
  1293. $dbHostForm = $_configuration['db_host'];
  1294. $dbUsernameForm = $_configuration['db_user'];
  1295. $dbPassForm = $_configuration['db_password'];
  1296. $dbNameForm = $_configuration['main_database'];
  1297. $dbPortForm = isset($_configuration['db_port']) ? $_configuration['db_port'] : '';
  1298. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('DBSetting').'</h2></div>';
  1299. echo '<div class="RequirementContent">';
  1300. echo get_lang('DBSettingUpgradeIntro');
  1301. echo '</div>';
  1302. } else {
  1303. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('DBSetting').'</h2></div>';
  1304. echo '<div class="RequirementContent">';
  1305. echo get_lang('DBSettingIntro');
  1306. echo '</div>';
  1307. } ?>
  1308. <div class="panel panel-default">
  1309. <div class="panel-body">
  1310. <div class="form-group">
  1311. <label class="col-sm-4"><?php echo get_lang('DBHost'); ?> </label>
  1312. <?php if ($installType == 'update') {
  1313. ?>
  1314. <div class="col-sm-5">
  1315. <input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?>
  1316. </div>
  1317. <div class="col-sm-3"></div>
  1318. <?php
  1319. } else {
  1320. ?>
  1321. <div class="col-sm-5">
  1322. <input type="text" class="form-control" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" />
  1323. </div>
  1324. <div class="col-sm-3"><?php echo get_lang('EG').' localhost'; ?></div>
  1325. <?php
  1326. } ?>
  1327. </div>
  1328. <div class="form-group">
  1329. <label class="col-sm-4"><?php echo get_lang('DBPort'); ?> </label>
  1330. <?php if ($installType == 'update') {
  1331. ?>
  1332. <div class="col-sm-5">
  1333. <input type="hidden" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" /><?php echo $dbPortForm; ?>
  1334. </div>
  1335. <div class="col-sm-3"></div>
  1336. <?php
  1337. } else {
  1338. ?>
  1339. <div class="col-sm-5">
  1340. <input type="text" class="form-control" size="25" maxlength="50" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" />
  1341. </div>
  1342. <div class="col-sm-3"><?php echo get_lang('EG').' 3306'; ?></div>
  1343. <?php
  1344. } ?>
  1345. </div>
  1346. <div class="form-group">
  1347. <?php
  1348. //database user username
  1349. $example_login = get_lang('EG').' root';
  1350. displayDatabaseParameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login); ?>
  1351. </div>
  1352. <div class="form-group">
  1353. <?php
  1354. //database user password
  1355. $example_password = get_lang('EG').' '.api_generate_password();
  1356. displayDatabaseParameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password); ?>
  1357. </div>
  1358. <div class="form-group">
  1359. <?php
  1360. //Database Name fix replace weird chars
  1361. if ($installType != INSTALL_TYPE_UPDATE) {
  1362. $dbNameForm = str_replace(['-', '*', '$', ' ', '.'], '', $dbNameForm);
  1363. }
  1364. displayDatabaseParameter(
  1365. $installType,
  1366. get_lang('MainDB'),
  1367. 'dbNameForm',
  1368. $dbNameForm,
  1369. '&nbsp;',
  1370. null,
  1371. 'id="optional_param1"'
  1372. ); ?>
  1373. </div>
  1374. <?php if ($installType != INSTALL_TYPE_UPDATE) {
  1375. ?>
  1376. <div class="form-group">
  1377. <div class="col-sm-3"></div>
  1378. <div class="col-sm-9">
  1379. <button type="submit" class="btn btn-primary" name="step3" value="step3">
  1380. <em class="fa fa-refresh"> </em>
  1381. <?php echo get_lang('CheckDatabaseConnection'); ?>
  1382. </button>
  1383. </div>
  1384. </div>
  1385. <?php
  1386. } ?>
  1387. </div>
  1388. </div>
  1389. <?php
  1390. $database_exists_text = '';
  1391. $manager = null;
  1392. try {
  1393. $manager = connectToDatabase(
  1394. $dbHostForm,
  1395. $dbUsernameForm,
  1396. $dbPassForm,
  1397. null,
  1398. $dbPortForm
  1399. );
  1400. $databases = $manager->getConnection()->getSchemaManager()->listDatabases();
  1401. if (in_array($dbNameForm, $databases)) {
  1402. $database_exists_text = '<div class="alert alert-warning">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>';
  1403. }
  1404. } catch (Exception $e) {
  1405. $database_exists_text = $e->getMessage();
  1406. }
  1407. if ($manager && $manager->getConnection()->isConnected()): ?>
  1408. <?php echo $database_exists_text ?>
  1409. <div id="db_status" class="alert alert-success">
  1410. Database host: <strong><?php echo $manager->getConnection()->getHost(); ?></strong><br/>
  1411. Database port: <strong><?php echo $manager->getConnection()->getPort(); ?></strong><br/>
  1412. Database driver: <strong><?php echo $manager->getConnection()->getDriver()->getName(); ?></strong><br/>
  1413. </div>
  1414. <?php else: ?>
  1415. <div id="db_status" class="alert alert-danger">
  1416. <p><?php echo get_lang('FailedConectionDatabase'); ?></strong></p>
  1417. <code><?php echo $database_exists_text ?></code>
  1418. </div>
  1419. <?php endif; ?>
  1420. <div class="form-group">
  1421. <div class="col-sm-6">
  1422. <button type="submit" name="step2" class="btn btn-default pull-right" value="&lt; <?php echo get_lang('Previous'); ?>" >
  1423. <em class="fa fa-backward"> </em> <?php echo get_lang('Previous'); ?>
  1424. </button>
  1425. </div>
  1426. <div class="col-sm-6">
  1427. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1428. <?php if ($manager) {
  1429. ?>
  1430. <button type="submit" class="btn btn-success" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" >
  1431. <em class="fa fa-forward"> </em> <?php echo get_lang('Next'); ?>
  1432. </button>
  1433. <?php
  1434. } else {
  1435. ?>
  1436. <button disabled="disabled" type="submit" class="btn btn-success disabled" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" >
  1437. <em class="fa fa-forward"> </em> <?php echo get_lang('Next'); ?>
  1438. </button>
  1439. <?php
  1440. } ?>
  1441. </div>
  1442. </div>
  1443. <?php
  1444. }
  1445. function panel($content = null, $title = null, $id = null, $style = null)
  1446. {
  1447. $html = '';
  1448. if (empty($style)) {
  1449. $style = 'default';
  1450. }
  1451. if (!empty($title)) {
  1452. $panelTitle = Display::div($title, ['class' => 'panel-heading']);
  1453. $panelBody = Display::div($content, ['class' => 'panel-body']);
  1454. $panelParent = Display::div($panelTitle.$panelBody, ['id' => $id, 'class' => 'panel panel-'.$style]);
  1455. } else {
  1456. $panelBody = Display::div($html, ['class' => 'panel-body']);
  1457. $panelParent = Display::div($panelBody, ['id' => $id, 'class' => 'panel panel-'.$style]);
  1458. }
  1459. $html .= $panelParent;
  1460. return $html;
  1461. }
  1462. /**
  1463. * Displays a parameter in a table row.
  1464. * Used by the display_configuration_settings_form function.
  1465. * @param string $installType
  1466. * @param string $parameterName
  1467. * @param string $formFieldName
  1468. * @param string $parameterValue
  1469. * @param string $displayWhenUpdate
  1470. */
  1471. function display_configuration_parameter(
  1472. $installType,
  1473. $parameterName,
  1474. $formFieldName,
  1475. $parameterValue,
  1476. $displayWhenUpdate = 'true'
  1477. ) {
  1478. $html = '<div class="form-group">';
  1479. $html .= '<label class="col-sm-6 control-label">'.$parameterName.'</label>';
  1480. if ($installType == INSTALL_TYPE_UPDATE && $displayWhenUpdate) {
  1481. $html .= '<input type="hidden" name="'.$formFieldName.'" value="'.api_htmlentities($parameterValue, ENT_QUOTES).'" />'.$parameterValue;
  1482. } else {
  1483. $html .= '<div class="col-sm-6"><input class="form-control" type="text" size="'.FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.MAX_FORM_FIELD_LENGTH.'" name="'.$formFieldName.'" value="'.api_htmlentities($parameterValue, ENT_QUOTES).'" />'."</div>";
  1484. }
  1485. $html .= "</div>";
  1486. return $html;
  1487. }
  1488. /**
  1489. * Displays step 4 of the installation - configuration settings about Chamilo itself.
  1490. * @param string $installType
  1491. * @param string $urlForm
  1492. * @param string $languageForm
  1493. * @param string $emailForm
  1494. * @param string $adminFirstName
  1495. * @param string $adminLastName
  1496. * @param string $adminPhoneForm
  1497. * @param string $campusForm
  1498. * @param string $institutionForm
  1499. * @param string $institutionUrlForm
  1500. * @param string $encryptPassForm
  1501. * @param bool $allowSelfReg
  1502. * @param bool $allowSelfRegProf
  1503. * @param string $loginForm
  1504. * @param string $passForm
  1505. */
  1506. function display_configuration_settings_form(
  1507. $installType,
  1508. $urlForm,
  1509. $languageForm,
  1510. $emailForm,
  1511. $adminFirstName,
  1512. $adminLastName,
  1513. $adminPhoneForm,
  1514. $campusForm,
  1515. $institutionForm,
  1516. $institutionUrlForm,
  1517. $encryptPassForm,
  1518. $allowSelfReg,
  1519. $allowSelfRegProf,
  1520. $loginForm,
  1521. $passForm
  1522. ) {
  1523. if ($installType != 'update' && empty($languageForm)) {
  1524. $languageForm = $_SESSION['install_language'];
  1525. }
  1526. echo '<div class="RequirementHeading">';
  1527. echo "<h2>".display_step_sequence().get_lang("CfgSetting")."</h2>";
  1528. echo '</div>';
  1529. echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>app/config/configuration.php</strong></p>';
  1530. // Parameter 1: administrator's login
  1531. $html = '';
  1532. $html .= display_configuration_parameter($installType, get_lang('AdminLogin'), 'loginForm', $loginForm, $installType == 'update');
  1533. // Parameter 2: administrator's password
  1534. if ($installType != 'update') {
  1535. $html .= display_configuration_parameter($installType, get_lang('AdminPass'), 'passForm', $passForm, false);
  1536. }
  1537. // Parameters 3 and 4: administrator's names
  1538. $html .= display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1539. $html .= display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1540. //Parameter 3: administrator's email
  1541. $html .= display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
  1542. //Parameter 6: administrator's telephone
  1543. $html .= display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
  1544. echo panel($html, get_lang('Administrator'), 'administrator');
  1545. //First parameter: language
  1546. $html = '<div class="form-group">';
  1547. $html .= '<label class="col-sm-6 control-label">'.get_lang('MainLang')."</label>";
  1548. if ($installType == 'update') {
  1549. $html .= '<input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm;
  1550. } else { // new installation
  1551. $html .= '<div class="col-sm-6">';
  1552. $html .= display_language_selection_box('languageForm', $languageForm);
  1553. $html .= '</div>';
  1554. }
  1555. $html .= "</div>";
  1556. //Second parameter: Chamilo URL
  1557. $html .= '<div class="form-group">';
  1558. $html .= '<label class="col-sm-6 control-label">'.get_lang('ChamiloURL').get_lang('ThisFieldIsRequired').'</label>';
  1559. if ($installType == 'update') {
  1560. $html .= api_htmlentities($urlForm, ENT_QUOTES)."\n";
  1561. } else {
  1562. $html .= '<div class="col-sm-6">';
  1563. $html .= '<input class="form-control" type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities($urlForm, ENT_QUOTES).'" />';
  1564. $html .= '</div>';
  1565. }
  1566. $html .= '</div>';
  1567. //Parameter 9: campus name
  1568. $html .= display_configuration_parameter(
  1569. $installType,
  1570. get_lang('CampusName'),
  1571. 'campusForm',
  1572. $campusForm
  1573. );
  1574. //Parameter 10: institute (short) name
  1575. $html .= display_configuration_parameter(
  1576. $installType,
  1577. get_lang('InstituteShortName'),
  1578. 'institutionForm',
  1579. $institutionForm
  1580. );
  1581. //Parameter 11: institute (short) name
  1582. $html .= display_configuration_parameter(
  1583. $installType,
  1584. get_lang('InstituteURL'),
  1585. 'institutionUrlForm',
  1586. $institutionUrlForm
  1587. );
  1588. $html .= '<div class="form-group">
  1589. <label class="col-sm-6 control-label">' . get_lang("EncryptMethodUserPass").'</label>
  1590. <div class="col-sm-6">';
  1591. if ($installType == 'update') {
  1592. $html .= '<input type="hidden" name="encryptPassForm" value="'.$encryptPassForm.'" />'.$encryptPassForm;
  1593. } else {
  1594. $html .= '<div class="checkbox">
  1595. <label>
  1596. <input type="radio" name="encryptPassForm" value="bcrypt" id="encryptPass1" '. ($encryptPassForm == 'bcrypt' ? 'checked="checked" ' : '').'/> bcrypt
  1597. </label>';
  1598. $html .= '<label>
  1599. <input type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" '. ($encryptPassForm == 'sha1' ? 'checked="checked" ' : '').'/> sha1
  1600. </label>';
  1601. $html .= '<label>
  1602. <input type="radio" name="encryptPassForm" value="md5" id="encryptPass0" '. ($encryptPassForm == 'md5' ? 'checked="checked" ' : '').'/> md5
  1603. </label>';
  1604. $html .= '<label>
  1605. <input type="radio" name="encryptPassForm" value="none" id="encryptPass2" '. ($encryptPassForm == 'none' ? 'checked="checked" ' : '').'/>'.get_lang('None').'
  1606. </label>';
  1607. $html .= '</div>';
  1608. }
  1609. $html .= '</div></div>';
  1610. $html .= '<div class="form-group">
  1611. <label class="col-sm-6 control-label">' . get_lang('AllowSelfReg').'</label>
  1612. <div class="col-sm-6">';
  1613. if ($installType == 'update') {
  1614. if ($allowSelfReg == 'true') {
  1615. $label = get_lang('Yes');
  1616. } elseif ($allowSelfReg == 'false') {
  1617. $label = get_lang('No');
  1618. } else {
  1619. $label = get_lang('AfterApproval');
  1620. }
  1621. $html .= '<input type="hidden" name="allowSelfReg" value="'.$allowSelfReg.'" />'.$label;
  1622. } else {
  1623. $html .= '<div class="control-group">';
  1624. $html .= '<label class="checkbox-inline">
  1625. <input type="radio" name="allowSelfReg" value="true" id="allowSelfReg1" '. ($allowSelfReg == 'true' ? 'checked="checked" ' : '').' /> '.get_lang('Yes').'
  1626. </label>';
  1627. $html .= '<label class="checkbox-inline">
  1628. <input type="radio" name="allowSelfReg" value="false" id="allowSelfReg0" '. ($allowSelfReg == 'false' ? '' : 'checked="checked" ').' /> '.get_lang('No').'
  1629. </label>';
  1630. $html .= '<label class="checkbox-inline">
  1631. <input type="radio" name="allowSelfReg" value="approval" id="allowSelfReg2" '. ($allowSelfReg == 'approval' ? '' : 'checked="checked" ').' /> '.get_lang('AfterApproval').'
  1632. </label>';
  1633. $html .= '</div>';
  1634. }
  1635. $html .= '</div>';
  1636. $html .= '</div>';
  1637. $html .= '<div class="form-group">';
  1638. $html .= '<label class="col-sm-6 control-label">'.get_lang('AllowSelfRegProf').'</label>
  1639. <div class="col-sm-6">';
  1640. if ($installType == 'update') {
  1641. if ($allowSelfRegProf == 'true') {
  1642. $label = get_lang('Yes');
  1643. } else {
  1644. $label = get_lang('No');
  1645. }
  1646. $html .= '<input type="hidden" name="allowSelfRegProf" value="'.$allowSelfRegProf.'" />'.$label;
  1647. } else {
  1648. $html .= '<div class="control-group">
  1649. <label class="checkbox-inline">
  1650. <input type="radio" name="allowSelfRegProf" value="1" id="allowSelfRegProf1" '. ($allowSelfRegProf ? 'checked="checked" ' : '').'/>
  1651. ' . get_lang('Yes').'
  1652. </label>';
  1653. $html .= '<label class="checkbox-inline">
  1654. <input type="radio" name="allowSelfRegProf" value="0" id="allowSelfRegProf0" '. ($allowSelfRegProf ? '' : 'checked="checked" ').' />
  1655. '. get_lang('No').'
  1656. </label>';
  1657. $html .= '</div>';
  1658. }
  1659. $html .= '</div>
  1660. </div>';
  1661. echo panel($html, get_lang('Platform'), 'platform'); ?>
  1662. <div class='form-group'>
  1663. <div class="col-sm-6">
  1664. <button type="submit" class="btn btn-default pull-right" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>" ><em class="fa fa-backward"> </em> <?php echo get_lang('Previous'); ?></button>
  1665. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1666. </div>
  1667. <div class="col-sm-6">
  1668. <button class="btn btn-success" type="submit" name="step5" value="<?php echo get_lang('Next'); ?> &gt;" ><em class="fa fa-forward"> </em> <?php echo get_lang('Next'); ?></button>
  1669. </div>
  1670. </div>
  1671. <?php
  1672. }
  1673. /**
  1674. * After installation is completed (step 6), this message is displayed.
  1675. * @param string $installType
  1676. */
  1677. function display_after_install_message($installType)
  1678. {
  1679. echo '<div class="RequirementContent">'.get_lang('FirstUseTip').'</div>';
  1680. echo '<div class="alert alert-warning">';
  1681. echo '<strong>'.get_lang('SecurityAdvice').'</strong>';
  1682. echo ': ';
  1683. printf(get_lang('ToProtectYourSiteMakeXReadOnlyAndDeleteY'), 'app/config/', 'main/install/');
  1684. echo '</div>'; ?></form>
  1685. <br />
  1686. <a class="btn btn-success btn-block" href="../../index.php">
  1687. <?php echo get_lang('GoToYourNewlyCreatedPortal'); ?>
  1688. </a>
  1689. <?php
  1690. }
  1691. /**
  1692. * This function return countries list from array (hardcoded)
  1693. * @param bool $combo (Optional) True for returning countries list with select html
  1694. * @return array|string countries list
  1695. */
  1696. function get_countries_list_from_array($combo = false)
  1697. {
  1698. $a_countries = [
  1699. "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan",
  1700. "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
  1701. "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",
  1702. "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  1703. "East Timor (Timor Timur)", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia",
  1704. "Fiji", "Finland", "France",
  1705. "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana",
  1706. "Haiti", "Honduras", "Hungary",
  1707. "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy",
  1708. "Jamaica", "Japan", "Jordan",
  1709. "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan",
  1710. "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
  1711. "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Myanmar",
  1712. "Namibia", "Nauru", "Nepa", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway",
  1713. "Oman",
  1714. "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
  1715. "Qatar",
  1716. "Romania", "Russia", "Rwanda",
  1717. "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",
  1718. "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu",
  1719. "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan",
  1720. "Vanuatu", "Vatican City", "Venezuela", "Vietnam",
  1721. "Yemen",
  1722. "Zambia", "Zimbabwe"
  1723. ];
  1724. $country_select = '';
  1725. if ($combo) {
  1726. $country_select = '<select class="selectpicker show-tick" id="country" name="country">';
  1727. $country_select .= '<option value="">--- '.get_lang('SelectOne').' ---</option>';
  1728. foreach ($a_countries as $country) {
  1729. $country_select .= '<option value="'.$country.'">'.$country.'</option>';
  1730. }
  1731. $country_select .= '</select>';
  1732. return $country_select;
  1733. }
  1734. return $a_countries;
  1735. }
  1736. /**
  1737. * Lock settings that can't be changed in other portals
  1738. */
  1739. function lockSettings()
  1740. {
  1741. $access_url_locked_settings = api_get_locked_settings();
  1742. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1743. foreach ($access_url_locked_settings as $setting) {
  1744. $sql = "UPDATE $table SET access_url_locked = 1 WHERE variable = '$setting'";
  1745. Database::query($sql);
  1746. }
  1747. }
  1748. /**
  1749. * Update dir values
  1750. */
  1751. function updateDirAndFilesPermissions()
  1752. {
  1753. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1754. $permissions_for_new_directories = isset($_SESSION['permissions_for_new_directories']) ? $_SESSION['permissions_for_new_directories'] : 0770;
  1755. $permissions_for_new_files = isset($_SESSION['permissions_for_new_files']) ? $_SESSION['permissions_for_new_files'] : 0660;
  1756. // use decoct() to store as string
  1757. $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_directories)."'
  1758. WHERE variable = 'permissions_for_new_directories'";
  1759. Database::query($sql);
  1760. $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_files)."' WHERE variable = 'permissions_for_new_files'";
  1761. Database::query($sql);
  1762. if (isset($_SESSION['permissions_for_new_directories'])) {
  1763. unset($_SESSION['permissions_for_new_directories']);
  1764. }
  1765. if (isset($_SESSION['permissions_for_new_files'])) {
  1766. unset($_SESSION['permissions_for_new_files']);
  1767. }
  1768. }
  1769. /**
  1770. * @param $current_value
  1771. * @param $wanted_value
  1772. * @return string
  1773. */
  1774. function compare_setting_values($current_value, $wanted_value)
  1775. {
  1776. $current_value_string = $current_value;
  1777. $current_value = (float) $current_value;
  1778. $wanted_value = (float) $wanted_value;
  1779. if ($current_value >= $wanted_value) {
  1780. return Display::label($current_value_string, 'success');
  1781. } else {
  1782. return Display::label($current_value_string, 'important');
  1783. }
  1784. }
  1785. /**
  1786. * @param $course_dir
  1787. * @param $course_attempt_name
  1788. * @param string $file
  1789. * @return bool
  1790. */
  1791. function check_course_script_interpretation(
  1792. $course_dir,
  1793. $course_attempt_name,
  1794. $file = 'test.php'
  1795. ) {
  1796. $output = false;
  1797. //Write in file
  1798. $file_name = $course_dir.'/'.$file;
  1799. $content = '<?php echo "123"; exit;';
  1800. if (is_writable($file_name)) {
  1801. if ($handler = @fopen($file_name, "w")) {
  1802. //write content
  1803. if (fwrite($handler, $content)) {
  1804. $sock_errno = '';
  1805. $sock_errmsg = '';
  1806. $url = api_get_path(WEB_PATH).'app/courses/'.$course_attempt_name.'/'.$file;
  1807. $parsed_url = parse_url($url);
  1808. //$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : ''; //http
  1809. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  1810. // Patch if the host is the default host and is used through
  1811. // the IP address (sometimes the host is not taken correctly
  1812. // in this case)
  1813. if (empty($host) && !empty($_SERVER['HTTP_HOST'])) {
  1814. $host = $_SERVER['HTTP_HOST'];
  1815. $url = preg_replace('#:///#', '://'.$host.'/', $url);
  1816. }
  1817. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
  1818. $port = '';
  1819. $scheme = '';
  1820. switch ($parsed_url['scheme']) {
  1821. case 'https':
  1822. $scheme = 'ssl://';
  1823. $port = 443;
  1824. break;
  1825. case 'http':
  1826. default:
  1827. $scheme = '';
  1828. $port = 80;
  1829. }
  1830. //Check fsockopen (not sure it works with https). If that is your case, you might want to try the
  1831. // suggestion at https://support.chamilo.org/issues/8260#note-3 (although it ignores SSL peer checks)
  1832. if ($fp = @fsockopen(str_replace('http://', $scheme, $url), $port, $sock_errno, $sock_errmsg, 60)) {
  1833. $out = "GET $path HTTP/1.1\r\n";
  1834. $out .= "Host: $host\r\n";
  1835. $out .= "Connection: Close\r\n\r\n";
  1836. fwrite($fp, $out);
  1837. while (!feof($fp)) {
  1838. $result = str_replace("\r\n", '', fgets($fp, 128));
  1839. if (!empty($result) && $result == '123') {
  1840. $output = true;
  1841. }
  1842. }
  1843. fclose($fp);
  1844. } elseif (ini_get('allow_url_fopen')) {
  1845. // Check allow_url_fopen
  1846. if ($fp = @fopen($url, 'r')) {
  1847. while ($result = fgets($fp, 1024)) {
  1848. if (!empty($result) && $result == '123') {
  1849. $output = true;
  1850. }
  1851. }
  1852. fclose($fp);
  1853. }
  1854. } elseif (function_exists('curl_init')) {
  1855. // Check if has support for cURL
  1856. $ch = curl_init();
  1857. curl_setopt($ch, CURLOPT_HEADER, 0);
  1858. curl_setopt($ch, CURLOPT_URL, $url);
  1859. //curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  1860. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1861. $result = curl_exec($ch);
  1862. if (!empty($result) && $result == '123') {
  1863. $output = true;
  1864. }
  1865. curl_close($ch);
  1866. }
  1867. }
  1868. @fclose($handler);
  1869. }
  1870. }
  1871. return $output;
  1872. }
  1873. /**
  1874. * Save settings values
  1875. *
  1876. * @param string $organizationName
  1877. * @param string $organizationUrl
  1878. * @param string $siteName
  1879. * @param string $adminEmail
  1880. * @param string $adminLastName
  1881. * @param string $adminFirstName
  1882. * @param string $language
  1883. * @param string $allowRegistration
  1884. * @param string $allowTeacherSelfRegistration
  1885. * @param string $installationProfile The name of an installation profile file in main/install/profiles/
  1886. */
  1887. function installSettings(
  1888. $organizationName,
  1889. $organizationUrl,
  1890. $siteName,
  1891. $adminEmail,
  1892. $adminLastName,
  1893. $adminFirstName,
  1894. $language,
  1895. $allowRegistration,
  1896. $allowTeacherSelfRegistration,
  1897. $installationProfile = ''
  1898. ) {
  1899. $allowTeacherSelfRegistration = $allowTeacherSelfRegistration ? 'true' : 'false';
  1900. // Use PHP 5.3 to avoid issue with weird peripherical auto-installers like travis-ci
  1901. $settings = [
  1902. 'Institution' => $organizationName,
  1903. 'InstitutionUrl' => $organizationUrl,
  1904. 'siteName' => $siteName,
  1905. 'emailAdministrator' => $adminEmail,
  1906. 'administratorSurname' => $adminLastName,
  1907. 'administratorName' => $adminFirstName,
  1908. 'platformLanguage' => $language,
  1909. 'allow_registration' => $allowRegistration,
  1910. 'allow_registration_as_teacher' => $allowTeacherSelfRegistration,
  1911. ];
  1912. foreach ($settings as $variable => $value) {
  1913. $sql = "UPDATE settings_current
  1914. SET selected_value = '$value'
  1915. WHERE variable = '$variable'";
  1916. Database::query($sql);
  1917. }
  1918. installProfileSettings($installationProfile);
  1919. }
  1920. /**
  1921. * Executes DB changes based in the classes defined in
  1922. * src/Chamilo/CoreBundle/Migrations/Schema/*
  1923. *
  1924. * @param string $chamiloVersion
  1925. * @param EntityManager $manager
  1926. * @throws \Doctrine\DBAL\DBALException
  1927. * @return bool
  1928. */
  1929. function migrate($chamiloVersion, EntityManager $manager)
  1930. {
  1931. $debug = true;
  1932. $connection = $manager->getConnection();
  1933. $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($connection);
  1934. // Table name that will store migrations log (will be created automatically,
  1935. // default name is: doctrine_migration_versions)
  1936. $config->setMigrationsTableName('version');
  1937. // Namespace of your migration classes, do not forget escape slashes, do not add last slash
  1938. $config->setMigrationsNamespace('Application\Migrations\Schema\V'.$chamiloVersion);
  1939. // Directory where your migrations are located
  1940. $config->setMigrationsDirectory(api_get_path(SYS_PATH).'app/Migrations/Schema/V'.$chamiloVersion);
  1941. // Load your migrations
  1942. $config->registerMigrationsFromDirectory($config->getMigrationsDirectory());
  1943. $migration = new \Doctrine\DBAL\Migrations\Migration($config);
  1944. $versions = $config->getMigrations();
  1945. /** @var Doctrine\DBAL\Migrations\Version $migrationItem */
  1946. foreach ($versions as $version) {
  1947. $version->getMigration()->setEntityManager($manager);
  1948. }
  1949. $to = null; // if $to == null then schema will be migrated to latest version
  1950. echo "<pre>";
  1951. try {
  1952. // Execute migration!
  1953. $migratedSQL = $migration->migrate($to);
  1954. if ($debug) {
  1955. foreach ($migratedSQL as $version => $sqlList) {
  1956. echo "VERSION: $version<br>";
  1957. echo "----------------------------------------------<br>";
  1958. $total = count($sqlList);
  1959. error_log("VERSION: $version");
  1960. error_log("# queries: ".$total);
  1961. $counter = 1;
  1962. foreach ($sqlList as $sql) {
  1963. echo "<code>$sql</code><br>";
  1964. error_log("$counter/$total : $sql");
  1965. $counter++;
  1966. }
  1967. }
  1968. echo "<br>DONE!<br>";
  1969. }
  1970. return true;
  1971. } catch (Exception $ex) {
  1972. if ($debug) {
  1973. echo "ERROR: {$ex->getMessage()}<br>";
  1974. return false;
  1975. }
  1976. }
  1977. echo "</pre>";
  1978. return false;
  1979. }
  1980. /**
  1981. * @param EntityManager $em
  1982. *
  1983. * @throws \Doctrine\DBAL\DBALException
  1984. */
  1985. function fixIds(EntityManager $em)
  1986. {
  1987. $connection = $em->getConnection();
  1988. $database = new Database();
  1989. $database->setManager($em);
  1990. $debug = true;
  1991. if ($debug) {
  1992. error_log('fixIds');
  1993. }
  1994. // Create temporary indexes to increase speed of the following operations
  1995. // Adding and removing indexes will usually take much less time than
  1996. // the execution without indexes of the queries in this function, particularly
  1997. // for large tables
  1998. $sql = "ALTER TABLE c_document ADD INDEX tmpidx_doc(c_id, id)";
  1999. $connection->executeQuery($sql);
  2000. $sql = "ALTER TABLE c_student_publication ADD INDEX tmpidx_stud (c_id, id)";
  2001. $connection->executeQuery($sql);
  2002. $sql = "ALTER TABLE c_quiz ADD INDEX tmpidx_quiz (c_id, id)";
  2003. $connection->executeQuery($sql);
  2004. $sql = "ALTER TABLE c_item_property ADD INDEX tmpidx_ip (to_group_id)";
  2005. $connection->executeQuery($sql);
  2006. $sql = "SELECT * FROM c_lp_item";
  2007. $result = $connection->fetchAll($sql);
  2008. foreach ($result as $item) {
  2009. $courseId = $item['c_id'];
  2010. $iid = isset($item['iid']) ? intval($item['iid']) : 0;
  2011. $ref = isset($item['ref']) ? intval($item['ref']) : 0;
  2012. $sql = null;
  2013. $newId = '';
  2014. switch ($item['item_type']) {
  2015. case TOOL_LINK:
  2016. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref";
  2017. $data = $connection->fetchAssoc($sql);
  2018. if ($data) {
  2019. $newId = $data['iid'];
  2020. }
  2021. break;
  2022. case TOOL_STUDENTPUBLICATION:
  2023. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  2024. $data = $connection->fetchAssoc($sql);
  2025. if ($data) {
  2026. $newId = $data['iid'];
  2027. }
  2028. break;
  2029. case TOOL_QUIZ:
  2030. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  2031. $data = $connection->fetchAssoc($sql);
  2032. if ($data) {
  2033. $newId = $data['iid'];
  2034. }
  2035. break;
  2036. case TOOL_DOCUMENT:
  2037. $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  2038. $data = $connection->fetchAssoc($sql);
  2039. if ($data) {
  2040. $newId = $data['iid'];
  2041. }
  2042. break;
  2043. case TOOL_FORUM:
  2044. $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND forum_id = $ref";
  2045. $data = $connection->fetchAssoc($sql);
  2046. if ($data) {
  2047. $newId = $data['iid'];
  2048. }
  2049. break;
  2050. case 'thread':
  2051. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND thread_id = $ref";
  2052. $data = $connection->fetchAssoc($sql);
  2053. if ($data) {
  2054. $newId = $data['iid'];
  2055. }
  2056. break;
  2057. }
  2058. if (!empty($sql) && !empty($newId) && !empty($iid)) {
  2059. $sql = "UPDATE c_lp_item SET ref = $newId WHERE iid = $iid";
  2060. $connection->executeQuery($sql);
  2061. }
  2062. }
  2063. // Set NULL if session = 0
  2064. $sql = "UPDATE c_item_property SET session_id = NULL WHERE session_id = 0";
  2065. $connection->executeQuery($sql);
  2066. // Set NULL if group = 0
  2067. $sql = "UPDATE c_item_property SET to_group_id = NULL WHERE to_group_id = 0";
  2068. $connection->executeQuery($sql);
  2069. // Set NULL if insert_user_id = 0
  2070. $sql = "UPDATE c_item_property SET insert_user_id = NULL WHERE insert_user_id = 0";
  2071. $connection->executeQuery($sql);
  2072. // Delete session data of sessions that don't exist.
  2073. $sql = "DELETE FROM c_item_property
  2074. WHERE session_id IS NOT NULL AND session_id NOT IN (SELECT id FROM session)";
  2075. $connection->executeQuery($sql);
  2076. // Delete group data of groups that don't exist.
  2077. $sql = "DELETE FROM c_item_property
  2078. WHERE to_group_id IS NOT NULL AND to_group_id NOT IN (SELECT DISTINCT id FROM c_group_info)";
  2079. $connection->executeQuery($sql);
  2080. // This updates the group_id with c_group_info.iid instead of c_group_info.id
  2081. if ($debug) {
  2082. error_log('update iids');
  2083. }
  2084. $groupTableToFix = [
  2085. 'c_group_rel_user',
  2086. 'c_group_rel_tutor',
  2087. 'c_permission_group',
  2088. 'c_role_group',
  2089. 'c_survey_invitation',
  2090. 'c_attendance_calendar_rel_group'
  2091. ];
  2092. foreach ($groupTableToFix as $table) {
  2093. $sql = "SELECT * FROM $table";
  2094. $result = $connection->fetchAll($sql);
  2095. foreach ($result as $item) {
  2096. $iid = $item['iid'];
  2097. $courseId = $item['c_id'];
  2098. $groupId = intval($item['group_id']);
  2099. // Fix group id
  2100. if (!empty($groupId)) {
  2101. $sql = "SELECT * FROM c_group_info
  2102. WHERE c_id = $courseId AND id = $groupId
  2103. LIMIT 1";
  2104. $data = $connection->fetchAssoc($sql);
  2105. if (!empty($data)) {
  2106. $newGroupId = $data['iid'];
  2107. $sql = "UPDATE $table SET group_id = $newGroupId
  2108. WHERE iid = $iid";
  2109. $connection->executeQuery($sql);
  2110. } else {
  2111. // The group does not exists clean this record
  2112. $sql = "DELETE FROM $table WHERE iid = $iid";
  2113. $connection->executeQuery($sql);
  2114. }
  2115. }
  2116. }
  2117. }
  2118. // Fix c_item_property
  2119. if ($debug) {
  2120. error_log('update c_item_property');
  2121. }
  2122. $sql = "SELECT * FROM course";
  2123. $courseList = $connection->fetchAll($sql);
  2124. if ($debug) {
  2125. error_log('Getting course list');
  2126. }
  2127. $totalCourse = count($courseList);
  2128. $counter = 0;
  2129. foreach ($courseList as $courseData) {
  2130. $courseId = $courseData['id'];
  2131. if ($debug) {
  2132. error_log('Updating course: '.$courseData['code']);
  2133. }
  2134. $sql = "SELECT * FROM c_item_property WHERE c_id = $courseId";
  2135. $result = $connection->fetchAll($sql);
  2136. foreach ($result as $item) {
  2137. $sessionId = intval($item['session_id']);
  2138. $groupId = intval($item['to_group_id']);
  2139. $iid = $item['iid'];
  2140. $ref = $item['ref'];
  2141. // Fix group id
  2142. if (!empty($groupId)) {
  2143. $sql = "SELECT * FROM c_group_info
  2144. WHERE c_id = $courseId AND id = $groupId";
  2145. $data = $connection->fetchAssoc($sql);
  2146. if (!empty($data)) {
  2147. $newGroupId = $data['iid'];
  2148. $sql = "UPDATE c_item_property SET to_group_id = $newGroupId
  2149. WHERE iid = $iid";
  2150. $connection->executeQuery($sql);
  2151. } else {
  2152. // The group does not exists clean this record
  2153. $sql = "DELETE FROM c_item_property WHERE iid = $iid";
  2154. $connection->executeQuery($sql);
  2155. }
  2156. }
  2157. $sql = '';
  2158. $newId = '';
  2159. switch ($item['tool']) {
  2160. case TOOL_LINK:
  2161. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref ";
  2162. break;
  2163. case TOOL_STUDENTPUBLICATION:
  2164. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  2165. break;
  2166. case TOOL_QUIZ:
  2167. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  2168. break;
  2169. case TOOL_DOCUMENT:
  2170. $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  2171. break;
  2172. case TOOL_FORUM:
  2173. $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND id = $ref";
  2174. break;
  2175. case 'thread':
  2176. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND id = $ref";
  2177. break;
  2178. }
  2179. if (!empty($sql) && !empty($newId)) {
  2180. $data = $connection->fetchAssoc($sql);
  2181. if (isset($data['iid'])) {
  2182. $newId = $data['iid'];
  2183. }
  2184. $sql = "UPDATE c_item_property SET ref = $newId WHERE iid = $iid";
  2185. error_log($sql);
  2186. $connection->executeQuery($sql);
  2187. }
  2188. }
  2189. if ($debug) {
  2190. // Print a status in the log once in a while
  2191. error_log("Course process #$counter/$totalCourse");
  2192. }
  2193. $counter++;
  2194. }
  2195. if ($debug) {
  2196. error_log('update gradebook_link');
  2197. }
  2198. // Fix gradebook_link
  2199. $sql = "SELECT * FROM gradebook_link";
  2200. $result = $connection->fetchAll($sql);
  2201. foreach ($result as $item) {
  2202. $courseCode = $item['course_code'];
  2203. $sql = "SELECT * FROM course WHERE code = '$courseCode'";
  2204. $courseInfo = $connection->fetchAssoc($sql);
  2205. if (empty($courseInfo)) {
  2206. continue;
  2207. }
  2208. $courseId = $courseInfo['id'];
  2209. $ref = $item['ref_id'];
  2210. $iid = $item['id'];
  2211. $sql = '';
  2212. switch ($item['type']) {
  2213. case LINK_LEARNPATH:
  2214. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref ";
  2215. break;
  2216. case LINK_STUDENTPUBLICATION:
  2217. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  2218. break;
  2219. case LINK_EXERCISE:
  2220. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  2221. break;
  2222. case LINK_ATTENDANCE:
  2223. //$sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  2224. break;
  2225. case LINK_FORUM_THREAD:
  2226. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND thread_id = $ref";
  2227. break;
  2228. }
  2229. if (!empty($sql)) {
  2230. $data = $connection->fetchAssoc($sql);
  2231. if (isset($data) && isset($data['iid'])) {
  2232. $newId = $data['iid'];
  2233. $sql = "UPDATE gradebook_link SET ref_id = $newId
  2234. WHERE id = $iid";
  2235. $connection->executeQuery($sql);
  2236. }
  2237. }
  2238. }
  2239. if ($debug) {
  2240. error_log('update groups');
  2241. }
  2242. $sql = "SELECT * FROM groups";
  2243. $result = $connection->executeQuery($sql);
  2244. $groups = $result->fetchAll();
  2245. $oldGroups = [];
  2246. if (!empty($groups)) {
  2247. foreach ($groups as $group) {
  2248. if (empty($group['name'])) {
  2249. continue;
  2250. }
  2251. $params = [
  2252. 'name' => $group['name'],
  2253. 'description' => $group['description'],
  2254. 'group_type' => 1,
  2255. 'picture' => $group['picture_uri'],
  2256. 'url' => $group['url'],
  2257. 'visibility' => $group['visibility'],
  2258. 'updated_at' => $group['updated_on'],
  2259. 'created_at' => $group['created_on']
  2260. ];
  2261. $connection->insert('usergroup', $params);
  2262. $id = $connection->lastInsertId('id');
  2263. $oldGroups[$group['id']] = $id;
  2264. }
  2265. }
  2266. if (!empty($oldGroups)) {
  2267. error_log('Moving group files');
  2268. foreach ($oldGroups as $oldId => $newId) {
  2269. $path = get_group_picture_path_by_id(
  2270. $oldId,
  2271. 'system'
  2272. );
  2273. if (!empty($path)) {
  2274. $newPath = str_replace(
  2275. "groups/$oldId/",
  2276. "groups/$newId/",
  2277. $path['dir']
  2278. );
  2279. $command = "mv {$path['dir']} $newPath ";
  2280. error_log("Executing $command");
  2281. system($command);
  2282. }
  2283. }
  2284. $sql = "SELECT * FROM group_rel_user";
  2285. $result = $connection->executeQuery($sql);
  2286. $dataList = $result->fetchAll();
  2287. if (!empty($dataList)) {
  2288. foreach ($dataList as $data) {
  2289. if (isset($oldGroups[$data['group_id']])) {
  2290. $data['group_id'] = $oldGroups[$data['group_id']];
  2291. $userId = $data['user_id'];
  2292. $sql = "SELECT id FROM user WHERE user_id = $userId";
  2293. $userResult = $connection->executeQuery($sql);
  2294. $userInfo = $userResult->fetch();
  2295. if (empty($userInfo)) {
  2296. continue;
  2297. }
  2298. $sql = "INSERT INTO usergroup_rel_user (usergroup_id, user_id, relation_type)
  2299. VALUES ('{$data['group_id']}', '{$userId}', '{$data['relation_type']}')";
  2300. $connection->executeQuery($sql);
  2301. }
  2302. }
  2303. }
  2304. $sql = "SELECT * FROM group_rel_group";
  2305. $result = $connection->executeQuery($sql);
  2306. $dataList = $result->fetchAll();
  2307. if (!empty($dataList)) {
  2308. foreach ($dataList as $data) {
  2309. if (isset($oldGroups[$data['group_id']]) && isset($oldGroups[$data['subgroup_id']])) {
  2310. $data['group_id'] = $oldGroups[$data['group_id']];
  2311. $data['subgroup_id'] = $oldGroups[$data['subgroup_id']];
  2312. $sql = "INSERT INTO usergroup_rel_usergroup (group_id, subgroup_id, relation_type)
  2313. VALUES ('{$data['group_id']}', '{$data['subgroup_id']}', '{$data['relation_type']}')";
  2314. $connection->executeQuery($sql);
  2315. }
  2316. }
  2317. }
  2318. $sql = "SELECT * FROM announcement_rel_group";
  2319. $result = $connection->executeQuery($sql);
  2320. $dataList = $result->fetchAll();
  2321. if (!empty($dataList)) {
  2322. foreach ($dataList as $data) {
  2323. if (isset($oldGroups[$data['group_id']])) {
  2324. // Deleting relation
  2325. $sql = "DELETE FROM announcement_rel_group WHERE group_id = {$data['group_id']}";
  2326. $connection->executeQuery($sql);
  2327. // Add new relation
  2328. $data['group_id'] = $oldGroups[$data['group_id']];
  2329. $sql = "INSERT INTO announcement_rel_group(group_id, announcement_id)
  2330. VALUES ('{$data['group_id']}', '{$data['announcement_id']}')";
  2331. $connection->executeQuery($sql);
  2332. }
  2333. }
  2334. }
  2335. $sql = "SELECT * FROM group_rel_tag";
  2336. $result = $connection->executeQuery($sql);
  2337. $dataList = $result->fetchAll();
  2338. if (!empty($dataList)) {
  2339. foreach ($dataList as $data) {
  2340. if (isset($oldGroups[$data['group_id']])) {
  2341. $data['group_id'] = $oldGroups[$data['group_id']];
  2342. $sql = "INSERT INTO usergroup_rel_tag (tag_id, usergroup_id)
  2343. VALUES ('{$data['tag_id']}', '{$data['group_id']}')";
  2344. $connection->executeQuery($sql);
  2345. }
  2346. }
  2347. }
  2348. }
  2349. if ($debug) {
  2350. error_log('update extra fields');
  2351. }
  2352. // Extra fields
  2353. $extraFieldTables = [
  2354. ExtraField::USER_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_USER_FIELD),
  2355. ExtraField::COURSE_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_COURSE_FIELD),
  2356. //ExtraField::LP_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_LP_FIELD),
  2357. ExtraField::SESSION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_SESSION_FIELD),
  2358. //ExtraField::CALENDAR_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD),
  2359. //ExtraField::QUESTION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD),
  2360. //ExtraField::USER_FIELD_TYPE => //Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD),
  2361. ];
  2362. foreach ($extraFieldTables as $type => $table) {
  2363. $sql = "SELECT * FROM $table ";
  2364. if ($debug) {
  2365. error_log($sql);
  2366. }
  2367. $result = $connection->query($sql);
  2368. $fields = $result->fetchAll();
  2369. foreach ($fields as $field) {
  2370. if ($debug) {
  2371. error_log("Loading field: ".$field['field_variable']);
  2372. }
  2373. $originalId = $field['id'];
  2374. $params = [
  2375. 'extra_field_type' => $type,
  2376. 'variable' => $field['field_variable'],
  2377. 'field_type' => $field['field_type'],
  2378. 'display_text' => $field['field_display_text'],
  2379. 'default_value' => $field['field_default_value'],
  2380. 'field_order' => $field['field_order'],
  2381. 'visible' => $field['field_visible'],
  2382. 'changeable' => $field['field_changeable'],
  2383. 'filter' => $field['field_filter']
  2384. ];
  2385. $connection->insert('extra_field', $params);
  2386. $newExtraFieldId = $connection->lastInsertId();
  2387. $values = [];
  2388. $handlerId = null;
  2389. switch ($type) {
  2390. case ExtraField::USER_FIELD_TYPE:
  2391. $optionTable = Database::get_main_table(
  2392. TABLE_MAIN_USER_FIELD_OPTIONS
  2393. );
  2394. $valueTable = Database::get_main_table(
  2395. TABLE_MAIN_USER_FIELD_VALUES
  2396. );
  2397. $handlerId = 'user_id';
  2398. break;
  2399. case ExtraField::COURSE_FIELD_TYPE:
  2400. $optionTable = Database::get_main_table(
  2401. TABLE_MAIN_COURSE_FIELD_OPTIONS
  2402. );
  2403. $valueTable = Database::get_main_table(
  2404. TABLE_MAIN_COURSE_FIELD_VALUES
  2405. );
  2406. $handlerId = 'c_id';
  2407. break;
  2408. case ExtraField::SESSION_FIELD_TYPE:
  2409. $optionTable = Database::get_main_table(
  2410. TABLE_MAIN_SESSION_FIELD_OPTIONS
  2411. );
  2412. $valueTable = Database::get_main_table(
  2413. TABLE_MAIN_SESSION_FIELD_VALUES
  2414. );
  2415. $handlerId = 'session_id';
  2416. break;
  2417. }
  2418. if (!empty($optionTable)) {
  2419. $sql = "SELECT * FROM $optionTable WHERE field_id = $originalId ";
  2420. $result = $connection->query($sql);
  2421. $options = $result->fetchAll();
  2422. foreach ($options as $option) {
  2423. $params = [
  2424. 'display_text' => $option['option_display_text'],
  2425. 'field_id' => $newExtraFieldId,
  2426. 'option_order' => $option['option_order'],
  2427. 'option_value' => $option['option_value']
  2428. ];
  2429. $connection->insert('extra_field_options', $params);
  2430. }
  2431. $sql = "SELECT * FROM $valueTable WHERE field_id = $originalId ";
  2432. $result = $connection->query($sql);
  2433. $values = $result->fetchAll();
  2434. if ($debug) {
  2435. error_log("Fetch all values for field");
  2436. }
  2437. }
  2438. if (!empty($values)) {
  2439. if ($debug) {
  2440. error_log("Saving field value in new table");
  2441. }
  2442. $k = 0;
  2443. foreach ($values as $value) {
  2444. if (isset($value[$handlerId])) {
  2445. // Insert without the use of the entity as it reduces
  2446. // speed to 2 records per second (much too slow)
  2447. $params = [
  2448. 'field_id' => $newExtraFieldId,
  2449. 'value' => $value['field_value'],
  2450. 'item_id' => $value[$handlerId]
  2451. ];
  2452. $connection->insert('extra_field_values', $params);
  2453. if ($debug && ($k % 10000 == 0)) {
  2454. error_log("Saving field $k");
  2455. }
  2456. $k++;
  2457. }
  2458. }
  2459. }
  2460. }
  2461. }
  2462. if ($debug) {
  2463. error_log('Remove index');
  2464. }
  2465. // Drop temporary indexes added to increase speed of this function's queries
  2466. $sql = "ALTER TABLE c_document DROP INDEX tmpidx_doc";
  2467. $connection->executeQuery($sql);
  2468. $sql = "ALTER TABLE c_student_publication DROP INDEX tmpidx_stud";
  2469. $connection->executeQuery($sql);
  2470. $sql = "ALTER TABLE c_quiz DROP INDEX tmpidx_quiz";
  2471. $connection->executeQuery($sql);
  2472. $sql = "ALTER TABLE c_item_property DROP INDEX tmpidx_ip";
  2473. $connection->executeQuery($sql);
  2474. if ($debug) {
  2475. error_log('Finish fixId function');
  2476. }
  2477. }
  2478. /**
  2479. * @param string $distFile
  2480. * @param string $envFile
  2481. * @param array $params
  2482. */
  2483. function updateEnvFile($distFile, $envFile, $params)
  2484. {
  2485. $contents = file_get_contents($distFile);
  2486. $contents = str_replace(array_keys($params), array_values($params), $contents);
  2487. file_put_contents($envFile, $contents);
  2488. }
  2489. /**
  2490. *
  2491. * After the schema was created (table creation), the function adds
  2492. * admin/platform information.
  2493. * @param \Chamilo\CourseBundle\Manager\SettingsManager $settingsManager
  2494. * @param EntityManager $manager
  2495. * @param string $sysPath
  2496. * @param string $encryptPassForm
  2497. * @param string $passForm
  2498. * @param string $adminLastName
  2499. * @param string $adminFirstName
  2500. * @param string $loginForm
  2501. * @param string $emailForm
  2502. * @param string $adminPhoneForm
  2503. * @param string $languageForm
  2504. * @param string $institutionForm
  2505. * @param string $institutionUrlForm
  2506. * @param string $siteName
  2507. * @param string $allowSelfReg
  2508. * @param string $allowSelfRegProf
  2509. * @param string $installationProfile Installation profile, if any was provided
  2510. */
  2511. function finishInstallationWithContainer(
  2512. $siteManager,
  2513. $settingsManager,
  2514. $manager,
  2515. $sysPath,
  2516. $encryptPassForm,
  2517. $passForm,
  2518. $adminLastName,
  2519. $adminFirstName,
  2520. $loginForm,
  2521. $emailForm,
  2522. $adminPhoneForm,
  2523. $languageForm,
  2524. $institutionForm,
  2525. $institutionUrlForm,
  2526. $siteName,
  2527. $allowSelfReg,
  2528. $allowSelfRegProf,
  2529. $installationProfile = ''
  2530. ) {
  2531. $sysPath = !empty($sysPath) ? $sysPath : api_get_path(SYS_PATH);
  2532. $connection = $manager->getConnection();
  2533. Database::setConnection($connection);
  2534. Database::setManager($manager);
  2535. $sql = getVersionTable();
  2536. // Add version table
  2537. $connection->executeQuery($sql);
  2538. // Add tickets defaults
  2539. $ticketProject = new TicketProject();
  2540. $ticketProject
  2541. ->setId(1)
  2542. ->setName('Ticket System')
  2543. ->setInsertUserId(1);
  2544. $manager->persist($ticketProject);
  2545. $manager->flush();
  2546. $categories = [
  2547. get_lang('TicketEnrollment') => get_lang('TicketsAboutEnrollment'),
  2548. get_lang('TicketGeneralInformation') => get_lang('TicketsAboutGeneralInformation'),
  2549. get_lang('TicketRequestAndPapework') => get_lang('TicketsAboutRequestAndPapework'),
  2550. get_lang('TicketAcademicIncidence') => get_lang('TicketsAboutAcademicIncidence'),
  2551. get_lang('TicketVirtualCampus') => get_lang('TicketsAboutVirtualCampus'),
  2552. get_lang('TicketOnlineEvaluation') => get_lang('TicketsAboutOnlineEvaluation')
  2553. ];
  2554. $i = 1;
  2555. foreach ($categories as $category => $description) {
  2556. // Online evaluation requires a course
  2557. $ticketCategory = new TicketCategory();
  2558. $ticketCategory
  2559. ->setId($i)
  2560. ->setName($category)
  2561. ->setDescription($description)
  2562. ->setProject($ticketProject)
  2563. ->setInsertUserId(1);
  2564. $isRequired = $i == 6;
  2565. $ticketCategory->setCourseRequired($isRequired);
  2566. $manager->persist($ticketCategory);
  2567. $manager->flush();
  2568. $i++;
  2569. }
  2570. // Default Priorities
  2571. $defaultPriorities = [
  2572. TicketManager::PRIORITY_NORMAL => get_lang('PriorityNormal'),
  2573. TicketManager::PRIORITY_HIGH => get_lang('PriorityHigh'),
  2574. TicketManager::PRIORITY_LOW => get_lang('PriorityLow')
  2575. ];
  2576. $i = 1;
  2577. foreach ($defaultPriorities as $code => $priority) {
  2578. $ticketPriority = new TicketPriority();
  2579. $ticketPriority
  2580. ->setId($i)
  2581. ->setName($priority)
  2582. ->setCode($code)
  2583. ->setInsertUserId(1);
  2584. $manager->persist($ticketPriority);
  2585. $manager->flush();
  2586. $i++;
  2587. }
  2588. $table = Database::get_main_table(TABLE_TICKET_STATUS);
  2589. // Default status
  2590. $defaultStatus = [
  2591. TicketManager::STATUS_NEW => get_lang('StatusNew'),
  2592. TicketManager::STATUS_PENDING => get_lang('StatusPending'),
  2593. TicketManager::STATUS_UNCONFIRMED => get_lang('StatusUnconfirmed'),
  2594. TicketManager::STATUS_CLOSE => get_lang('StatusClose'),
  2595. TicketManager::STATUS_FORWARDED => get_lang('StatusForwarded')
  2596. ];
  2597. $i = 1;
  2598. foreach ($defaultStatus as $code => $status) {
  2599. $attributes = [
  2600. 'id' => $i,
  2601. 'code' => $code,
  2602. 'name' => $status
  2603. ];
  2604. Database::insert($table, $attributes);
  2605. $i++;
  2606. }
  2607. // Creating AccessUrl
  2608. $accessUrl = new \Chamilo\CoreBundle\Entity\AccessUrl();
  2609. $accessUrl
  2610. ->setUrl('http://localhost/')
  2611. ->setDescription('')
  2612. ->setActive(1)
  2613. ;
  2614. $manager->persist($accessUrl);
  2615. $manager->flush();
  2616. // Creating settings
  2617. $settingsManager->installSchemas($accessUrl);
  2618. // Inserting data
  2619. $data = file_get_contents($sysPath.'main/install/data.sql');
  2620. $result = $manager->getConnection()->prepare($data);
  2621. $result->execute();
  2622. $result->closeCursor();
  2623. /** @var Chamilo\PageBundle\Entity\Site $site */
  2624. $site = $siteManager->create();
  2625. $site->setHost('localhost');
  2626. $site->setEnabled(true);
  2627. $site->setName('localhost');
  2628. $site->setEnabledFrom(new \DateTime('now'));
  2629. $site->setEnabledTo(new \DateTime('+20 years'));
  2630. $site->setRelativePath("");
  2631. $site->setIsDefault(true);
  2632. $siteManager->save($site);
  2633. UserManager::setPasswordEncryption($encryptPassForm);
  2634. // Create admin user.
  2635. @UserManager::create_user(
  2636. $adminFirstName,
  2637. $adminLastName,
  2638. 1,
  2639. $emailForm,
  2640. $loginForm,
  2641. $passForm,
  2642. 'ADMIN', //$official_code = '',
  2643. $languageForm,
  2644. $adminPhoneForm,
  2645. '', //$picture_uri = '',
  2646. PLATFORM_AUTH_SOURCE,
  2647. '', //$expirationDate,
  2648. 1,
  2649. 0,
  2650. null,
  2651. '',
  2652. false, //$send_mail = false,
  2653. true, //$isAdmin = false
  2654. '',
  2655. false,
  2656. '',
  2657. 1
  2658. );
  2659. // Create anonymous user.
  2660. @UserManager::create_user(
  2661. 'Joe',
  2662. 'Anonymous',
  2663. 6,
  2664. 'anonymous@localhost',
  2665. 'anon',
  2666. 'anon',
  2667. 'anonymous', //$official_code = '',
  2668. $languageForm,
  2669. '',
  2670. '', //$picture_uri = '',
  2671. PLATFORM_AUTH_SOURCE,
  2672. '',
  2673. 1,
  2674. 0,
  2675. null,
  2676. '',
  2677. false, //$send_mail = false,
  2678. false, //$isAdmin = false
  2679. '',
  2680. false,
  2681. '',
  2682. 1
  2683. );
  2684. // Set default language
  2685. $sql = "UPDATE language SET available = 1 WHERE dokeos_folder = '$languageForm'";
  2686. Database::query($sql);
  2687. // Install settings
  2688. installSettings(
  2689. $institutionForm,
  2690. $institutionUrlForm,
  2691. $siteName,
  2692. $emailForm,
  2693. $adminLastName,
  2694. $adminFirstName,
  2695. $languageForm,
  2696. $allowSelfReg,
  2697. $allowSelfRegProf,
  2698. $installationProfile
  2699. );
  2700. lockSettings();
  2701. updateDirAndFilesPermissions();
  2702. // Set the latest version
  2703. $path = $sysPath.'app/Migrations/Schema/V111/';
  2704. $finder = new \Symfony\Component\Finder\Finder();
  2705. $files = $finder->files()->in($path);
  2706. // Needed for chash
  2707. createVersionTable();
  2708. foreach ($files as $version) {
  2709. $version = str_replace(['Version', '.php'], '', $version->getFilename());
  2710. $sql = "INSERT INTO version (version) VALUES ('$version')";
  2711. Database::query($sql);
  2712. }
  2713. }
  2714. /**
  2715. * Creates 'version' table
  2716. */
  2717. function createVersionTable()
  2718. {
  2719. $sql = getVersionTable();
  2720. Database::query($sql);
  2721. }
  2722. /**
  2723. * Get version creation table query
  2724. * @return string
  2725. */
  2726. function getVersionTable()
  2727. {
  2728. return 'CREATE TABLE IF NOT EXISTS version (id int unsigned NOT NULL AUTO_INCREMENT, version varchar(20), PRIMARY KEY(id), UNIQUE(version));';
  2729. }
  2730. /**
  2731. * Update settings based on installation profile defined in a JSON file
  2732. * @param string $installationProfile The name of the JSON file in main/install/profiles/ folder
  2733. *
  2734. * @return bool false on failure (no bad consequences anyway, just ignoring profile)
  2735. */
  2736. function installProfileSettings($installationProfile = '')
  2737. {
  2738. if (empty($installationProfile)) {
  2739. return false;
  2740. }
  2741. $jsonPath = api_get_path(SYS_PATH).'main/install/profiles/'.$installationProfile.'.json';
  2742. // Make sure the path to the profile is not hacked
  2743. if (!Security::check_abs_path($jsonPath, api_get_path(SYS_PATH).'main/install/profiles/')) {
  2744. return false;
  2745. }
  2746. if (!is_file($jsonPath)) {
  2747. return false;
  2748. }
  2749. if (!is_readable($jsonPath)) {
  2750. return false;
  2751. }
  2752. if (!function_exists('json_decode')) {
  2753. // The php-json extension is not available. Ignore profile.
  2754. return false;
  2755. }
  2756. $json = file_get_contents($jsonPath);
  2757. $params = json_decode($json);
  2758. if ($params === false or $params === null) {
  2759. return false;
  2760. }
  2761. $settings = $params->params;
  2762. if (!empty($params->parent)) {
  2763. installProfileSettings($params->parent);
  2764. }
  2765. foreach ($settings as $id => $param) {
  2766. $sql = "UPDATE settings_current
  2767. SET selected_value = '".$param->selected_value."'
  2768. WHERE variable = '".$param->variable."'";
  2769. if (!empty($param->subkey)) {
  2770. $sql .= " AND subkey='".$param->subkey."'";
  2771. }
  2772. Database::query($sql);
  2773. }
  2774. return true;
  2775. }
  2776. /**
  2777. * Quick function to remove a directory with its subdirectories
  2778. * @param $dir
  2779. */
  2780. function rrmdir($dir)
  2781. {
  2782. if (is_dir($dir)) {
  2783. $objects = scandir($dir);
  2784. foreach ($objects as $object) {
  2785. if ($object != "." && $object != "..") {
  2786. if (filetype($dir."/".$object) == "dir") {
  2787. @rrmdir($dir."/".$object);
  2788. } else {
  2789. @unlink($dir."/".$object);
  2790. }
  2791. }
  2792. }
  2793. reset($objects);
  2794. rmdir($dir);
  2795. }
  2796. }
  2797. function get_group_picture_path_by_id($id, $type = 'web', $preview = false, $anonymous = false)
  2798. {
  2799. switch ($type) {
  2800. case 'system': // Base: absolute system path.
  2801. $base = api_get_path(SYS_UPLOAD_PATH);
  2802. break;
  2803. case 'web': // Base: absolute web path.
  2804. default:
  2805. $base = api_get_path(WEB_UPLOAD_PATH);
  2806. break;
  2807. }
  2808. $noPicturePath = ['dir' => $base.'img/', 'file' => 'unknown.jpg'];
  2809. if (empty($id) || empty($type)) {
  2810. return $anonymous ? $noPicturePath : ['dir' => '', 'file' => ''];
  2811. }
  2812. $id = intval($id);
  2813. //$group_table = Database::get_main_table(TABLE_MAIN_GROUP);
  2814. $group_table = 'groups';
  2815. $sql = "SELECT picture_uri FROM $group_table WHERE id=".$id;
  2816. $res = Database::query($sql);
  2817. if (!Database::num_rows($res)) {
  2818. return $anonymous ? $noPicturePath : ['dir' => '', 'file' => ''];
  2819. }
  2820. $user = Database::fetch_array($res);
  2821. $picture_filename = trim($user['picture_uri']);
  2822. if (api_get_setting('split_users_upload_directory') === 'true') {
  2823. if (!empty($picture_filename)) {
  2824. $dir = $base.'groups/'.substr($picture_filename, 0, 1).'/'.$id.'/';
  2825. } elseif ($preview) {
  2826. $dir = $base.'groups/'.substr((string) $id, 0, 1).'/'.$id.'/';
  2827. } else {
  2828. $dir = $base.'groups/'.$id.'/';
  2829. }
  2830. } else {
  2831. $dir = $base.'groups/'.$id.'/';
  2832. }
  2833. if (empty($picture_filename) && $anonymous) {
  2834. return $noPicturePath;
  2835. }
  2836. return ['dir' => $dir, 'file' => $picture_filename];
  2837. }
  2838. /**
  2839. * Control the different steps of the migration through a big switch
  2840. * @param string $fromVersion
  2841. * @param EntityManager $manager
  2842. * @param bool $processFiles
  2843. * @return bool Always returns true except if the process is broken
  2844. */
  2845. function migrateSwitch($fromVersion, $manager, $processFiles = true)
  2846. {
  2847. error_log('Starting migration process from '.$fromVersion.' ('.date('Y-m-d H:i:s').')');
  2848. echo '<a class="btn btn-default" href="javascript:void(0)" id="details_button">'.get_lang('Details').'</a><br />';
  2849. echo '<div id="details" style="display:none">';
  2850. $connection = $manager->getConnection();
  2851. $database = new Database();
  2852. $database->setManager($manager);
  2853. switch ($fromVersion) {
  2854. case '1.9.0':
  2855. case '1.9.2':
  2856. case '1.9.4':
  2857. case '1.9.6':
  2858. case '1.9.6.1':
  2859. case '1.9.8':
  2860. case '1.9.8.1':
  2861. case '1.9.8.2':
  2862. case '1.9.10':
  2863. case '1.9.10.2':
  2864. case '1.9.10.4':
  2865. case '1.9.10.6':
  2866. $database = new Database();
  2867. $database->setManager($manager);
  2868. // Fix type "enum" before running the migration with Doctrine
  2869. $connection->executeQuery("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'");
  2870. $connection->executeQuery("ALTER TABLE course_category MODIFY COLUMN auth_cat_child VARCHAR(40) DEFAULT 'TRUE'");
  2871. $connection->executeQuery("ALTER TABLE c_quiz_answer MODIFY COLUMN hotspot_type varchar(40) default NULL");
  2872. $connection->executeQuery("ALTER TABLE c_tool MODIFY COLUMN target varchar(20) NOT NULL default '_self'");
  2873. $connection->executeQuery("ALTER TABLE c_link MODIFY COLUMN on_homepage char(10) NOT NULL default '0'");
  2874. $connection->executeQuery("ALTER TABLE c_blog_rating MODIFY COLUMN rating_type char(40) NOT NULL default 'post'");
  2875. $connection->executeQuery("ALTER TABLE c_survey MODIFY COLUMN anonymous char(10) NOT NULL default '0'");
  2876. $connection->executeQuery("ALTER TABLE c_document MODIFY COLUMN filetype char(10) NOT NULL default 'file'");
  2877. $connection->executeQuery("ALTER TABLE c_student_publication MODIFY COLUMN filetype char(10) NOT NULL default 'file'");
  2878. // Migrate using the migration files located in:
  2879. // src/Chamilo/CoreBundle/Migrations/Schema/V110
  2880. $result = migrate(
  2881. 110,
  2882. $manager
  2883. );
  2884. if ($result) {
  2885. error_log('Migrations files were executed ('.date('Y-m-d H:i:s').')');
  2886. fixIds($manager);
  2887. error_log('fixIds finished ('.date('Y-m-d H:i:s').')');
  2888. $connection->executeQuery("UPDATE settings_current SET selected_value = '1.10.0' WHERE variable = 'chamilo_database_version'");
  2889. if ($processFiles) {
  2890. $fromVersionShort = '1.9';
  2891. include __DIR__.'/update-files-1.9.0-1.10.0.inc.php';
  2892. // Only updates the configuration.inc.php with the new version
  2893. include __DIR__.'/update-configuration.inc.php';
  2894. $configurationFiles = [
  2895. 'mail.conf.php',
  2896. 'profile.conf.php',
  2897. 'course_info.conf.php',
  2898. 'add_course.conf.php',
  2899. 'events.conf.php',
  2900. 'auth.conf.php'
  2901. ];
  2902. error_log('Copy conf files');
  2903. foreach ($configurationFiles as $file) {
  2904. if (file_exists(api_get_path(SYS_CODE_PATH).'inc/conf/'.$file)) {
  2905. copy(
  2906. api_get_path(SYS_CODE_PATH).'inc/conf/'.$file,
  2907. api_get_path(CONFIGURATION_PATH).$file
  2908. );
  2909. }
  2910. }
  2911. }
  2912. error_log('Upgrade 1.10.x process concluded! ('.date('Y-m-d H:i:s').')');
  2913. } else {
  2914. error_log('There was an error during running migrations. Check error.log');
  2915. break;
  2916. }
  2917. // no break
  2918. case '1.10.0':
  2919. case '1.10.2':
  2920. case '1.10.4':
  2921. case '1.10.6':
  2922. case '1.10.8':
  2923. $database = new Database();
  2924. $database->setManager($manager);
  2925. // Migrate using the migration files located in:
  2926. // src/Chamilo/CoreBundle/Migrations/Schema/V111
  2927. $result = migrate(
  2928. 111,
  2929. $manager
  2930. );
  2931. if ($result) {
  2932. error_log('Migrations files were executed ('.date('Y-m-d H:i:s').')');
  2933. fixPostGroupIds($connection);
  2934. $sql = "UPDATE settings_current SET selected_value = '1.11.0' WHERE variable = 'chamilo_database_version'";
  2935. $connection->executeQuery($sql);
  2936. if ($processFiles) {
  2937. error_log('Update config files');
  2938. $fromVersionShort = '1.10';
  2939. include __DIR__.'/update-files-1.10.0-1.11.0.inc.php';
  2940. // Only updates the configuration.inc.php with the new version
  2941. include __DIR__.'/update-configuration.inc.php';
  2942. }
  2943. error_log('Upgrade 1.11.x process concluded! ('.date('Y-m-d H:i:s').')');
  2944. } else {
  2945. error_log('There was an error during running migrations. Check error.log');
  2946. }
  2947. break;
  2948. default:
  2949. break;
  2950. }
  2951. echo '</div>';
  2952. return true;
  2953. }
  2954. /**
  2955. * @param \Doctrine\DBAL\Connection $connection
  2956. */
  2957. function fixPostGroupIds($connection)
  2958. {
  2959. $connection->executeQuery("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'");
  2960. error_log('Fix c_student_publication.post_group_id');
  2961. // Fix post_group_id
  2962. $sql = "SELECT * FROM c_student_publication
  2963. WHERE (post_group_id <> 0 AND post_group_id is not null)";
  2964. $statement = $connection->executeQuery($sql);
  2965. $result = $statement->fetchAll();
  2966. foreach ($result as $row) {
  2967. $groupId = $row['post_group_id'];
  2968. $courseId = $row['c_id'];
  2969. $workIid = $row['iid'];
  2970. $sql = "SELECT iid from c_group_info
  2971. WHERE c_id = $courseId AND id = $groupId";
  2972. $statement = $connection->executeQuery($sql);
  2973. $count = $statement->rowCount();
  2974. if ($count > 0) {
  2975. $rowGroup = $statement->fetch();
  2976. $newGroupId = $rowGroup['iid'];
  2977. if ($newGroupId == $groupId) {
  2978. continue;
  2979. }
  2980. if ($newGroupId) {
  2981. $sql = "UPDATE c_student_publication
  2982. SET post_group_id = $newGroupId
  2983. WHERE
  2984. c_id = $courseId AND
  2985. iid = $workIid
  2986. ";
  2987. $connection->executeQuery($sql);
  2988. }
  2989. }
  2990. }
  2991. error_log('End - Fix c_student_publication.post_group_id');
  2992. // Delete c_student_publication from any session that doesn't exist anymore
  2993. $sql = "DELETE FROM c_student_publication
  2994. WHERE session_id NOT IN (SELECT id FROM session) AND (session_id <> 0 AND session_id is not null)";
  2995. $connection->executeQuery($sql);
  2996. error_log('Fix work documents');
  2997. // Fix work documents that don't have c_item_property value
  2998. $sql = "SELECT * FROM c_student_publication WHERE parent_id IS NOT NULL";
  2999. $statement = $connection->executeQuery($sql);
  3000. $result = $statement->fetchAll();
  3001. foreach ($result as $row) {
  3002. $groupId = $row['post_group_id'];
  3003. $courseId = $row['c_id'];
  3004. $sessionId = $row['session_id'];
  3005. $workId = $row['id'];
  3006. $itemInfo = api_get_item_property_info(
  3007. $courseId,
  3008. 'work',
  3009. $workId,
  3010. $sessionId
  3011. );
  3012. $courseInfo = api_get_course_info_by_id($courseId);
  3013. if (empty($itemInfo)) {
  3014. api_item_property_update(
  3015. $courseInfo,
  3016. 'work',
  3017. $workId,
  3018. 'visible',
  3019. 1,
  3020. $groupId,
  3021. null,
  3022. null,
  3023. null,
  3024. $sessionId
  3025. );
  3026. }
  3027. }
  3028. error_log('End - Fix work documents');
  3029. }