install.lib.php 128 KB

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