install.lib.php 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281
  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 bool 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. * @return bool
  1893. */
  1894. function migrate($chamiloVersion, EntityManager $manager)
  1895. {
  1896. $debug = true;
  1897. $connection = $manager->getConnection();
  1898. $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($connection);
  1899. // Table name that will store migrations log (will be created automatically,
  1900. // default name is: doctrine_migration_versions)
  1901. $config->setMigrationsTableName('version');
  1902. // Namespace of your migration classes, do not forget escape slashes, do not add last slash
  1903. $config->setMigrationsNamespace('Application\Migrations\Schema\V'.$chamiloVersion);
  1904. // Directory where your migrations are located
  1905. $config->setMigrationsDirectory(api_get_path(SYS_PATH).'app/Migrations/Schema/V'.$chamiloVersion);
  1906. // Load your migrations
  1907. $config->registerMigrationsFromDirectory($config->getMigrationsDirectory());
  1908. $migration = new \Doctrine\DBAL\Migrations\Migration($config);
  1909. $versions = $config->getMigrations();
  1910. /** @var Doctrine\DBAL\Migrations\Version $migrationItem */
  1911. foreach ($versions as $version) {
  1912. $version->getMigration()->setEntityManager($manager);
  1913. }
  1914. $to = null; // if $to == null then schema will be migrated to latest version
  1915. echo "<pre>";
  1916. try {
  1917. // Execute migration!
  1918. $migratedSQL = $migration->migrate($to);
  1919. if ($debug) {
  1920. foreach ($migratedSQL as $version => $sqlList) {
  1921. echo "VERSION: $version<br>";
  1922. echo "----------------------------------------------<br>";
  1923. $total = count($sqlList);
  1924. error_log("VERSION: $version");
  1925. error_log("# queries: ".$total);
  1926. $counter = 1;
  1927. foreach ($sqlList as $sql) {
  1928. echo "<code>$sql</code><br>";
  1929. error_log("$counter/$total : $sql");
  1930. $counter++;
  1931. }
  1932. }
  1933. echo "<br>DONE!<br>";
  1934. }
  1935. return true;
  1936. } catch (Exception $ex) {
  1937. if ($debug) {
  1938. echo "ERROR: {$ex->getMessage()}<br>";
  1939. return false;
  1940. }
  1941. }
  1942. echo "</pre>";
  1943. return false;
  1944. }
  1945. /**
  1946. * @param EntityManager $em
  1947. *
  1948. * @throws \Doctrine\DBAL\DBALException
  1949. */
  1950. function fixIds(EntityManager $em)
  1951. {
  1952. $connection = $em->getConnection();
  1953. $database = new Database();
  1954. $database->setManager($em);
  1955. $debug = true;
  1956. if ($debug) {
  1957. error_log('fixIds');
  1958. }
  1959. // Create temporary indexes to increase speed of the following operations
  1960. // Adding and removing indexes will usually take much less time than
  1961. // the execution without indexes of the queries in this function, particularly
  1962. // for large tables
  1963. $sql = "ALTER TABLE c_document ADD INDEX tmpidx_doc(c_id, id)";
  1964. $connection->executeQuery($sql);
  1965. $sql = "ALTER TABLE c_student_publication ADD INDEX tmpidx_stud (c_id, id)";
  1966. $connection->executeQuery($sql);
  1967. $sql = "ALTER TABLE c_quiz ADD INDEX tmpidx_quiz (c_id, id)";
  1968. $connection->executeQuery($sql);
  1969. $sql = "ALTER TABLE c_item_property ADD INDEX tmpidx_ip (to_group_id)";
  1970. $connection->executeQuery($sql);
  1971. $sql = "SELECT * FROM c_lp_item";
  1972. $result = $connection->fetchAll($sql);
  1973. foreach ($result as $item) {
  1974. $courseId = $item['c_id'];
  1975. $iid = isset($item['iid']) ? intval($item['iid']) : 0;
  1976. $ref = isset($item['ref']) ? intval($item['ref']) : 0;
  1977. $sql = null;
  1978. $newId = '';
  1979. switch ($item['item_type']) {
  1980. case TOOL_LINK:
  1981. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref";
  1982. $data = $connection->fetchAssoc($sql);
  1983. if ($data) {
  1984. $newId = $data['iid'];
  1985. }
  1986. break;
  1987. case TOOL_STUDENTPUBLICATION:
  1988. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  1989. $data = $connection->fetchAssoc($sql);
  1990. if ($data) {
  1991. $newId = $data['iid'];
  1992. }
  1993. break;
  1994. case TOOL_QUIZ:
  1995. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  1996. $data = $connection->fetchAssoc($sql);
  1997. if ($data) {
  1998. $newId = $data['iid'];
  1999. }
  2000. break;
  2001. case TOOL_DOCUMENT:
  2002. $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  2003. $data = $connection->fetchAssoc($sql);
  2004. if ($data) {
  2005. $newId = $data['iid'];
  2006. }
  2007. break;
  2008. case TOOL_FORUM:
  2009. $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND forum_id = $ref";
  2010. $data = $connection->fetchAssoc($sql);
  2011. if ($data) {
  2012. $newId = $data['iid'];
  2013. }
  2014. break;
  2015. case 'thread':
  2016. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND thread_id = $ref";
  2017. $data = $connection->fetchAssoc($sql);
  2018. if ($data) {
  2019. $newId = $data['iid'];
  2020. }
  2021. break;
  2022. }
  2023. if (!empty($sql) && !empty($newId) && !empty($iid)) {
  2024. $sql = "UPDATE c_lp_item SET ref = $newId WHERE iid = $iid";
  2025. $connection->executeQuery($sql);
  2026. }
  2027. }
  2028. // Set NULL if session = 0
  2029. $sql = "UPDATE c_item_property SET session_id = NULL WHERE session_id = 0";
  2030. $connection->executeQuery($sql);
  2031. // Set NULL if group = 0
  2032. $sql = "UPDATE c_item_property SET to_group_id = NULL WHERE to_group_id = 0";
  2033. $connection->executeQuery($sql);
  2034. // Set NULL if insert_user_id = 0
  2035. $sql = "UPDATE c_item_property SET insert_user_id = NULL WHERE insert_user_id = 0";
  2036. $connection->executeQuery($sql);
  2037. // Delete session data of sessions that don't exist.
  2038. $sql = "DELETE FROM c_item_property
  2039. WHERE session_id IS NOT NULL AND session_id NOT IN (SELECT id FROM session)";
  2040. $connection->executeQuery($sql);
  2041. // Delete group data of groups that don't exist.
  2042. $sql = "DELETE FROM c_item_property
  2043. WHERE to_group_id IS NOT NULL AND to_group_id NOT IN (SELECT DISTINCT id FROM c_group_info)";
  2044. $connection->executeQuery($sql);
  2045. // This updates the group_id with c_group_info.iid instead of c_group_info.id
  2046. if ($debug) {
  2047. error_log('update iids');
  2048. }
  2049. $groupTableToFix = [
  2050. 'c_group_rel_user',
  2051. 'c_group_rel_tutor',
  2052. 'c_permission_group',
  2053. 'c_role_group',
  2054. 'c_survey_invitation',
  2055. 'c_attendance_calendar_rel_group'
  2056. ];
  2057. foreach ($groupTableToFix as $table) {
  2058. $sql = "SELECT * FROM $table";
  2059. $result = $connection->fetchAll($sql);
  2060. foreach ($result as $item) {
  2061. $iid = $item['iid'];
  2062. $courseId = $item['c_id'];
  2063. $groupId = intval($item['group_id']);
  2064. // Fix group id
  2065. if (!empty($groupId)) {
  2066. $sql = "SELECT * FROM c_group_info
  2067. WHERE c_id = $courseId AND id = $groupId
  2068. LIMIT 1";
  2069. $data = $connection->fetchAssoc($sql);
  2070. if (!empty($data)) {
  2071. $newGroupId = $data['iid'];
  2072. $sql = "UPDATE $table SET group_id = $newGroupId
  2073. WHERE iid = $iid";
  2074. $connection->executeQuery($sql);
  2075. } else {
  2076. // The group does not exists clean this record
  2077. $sql = "DELETE FROM $table WHERE iid = $iid";
  2078. $connection->executeQuery($sql);
  2079. }
  2080. }
  2081. }
  2082. }
  2083. // Fix c_item_property
  2084. if ($debug) {
  2085. error_log('update c_item_property');
  2086. }
  2087. $sql = "SELECT * FROM course";
  2088. $courseList = $connection->fetchAll($sql);
  2089. if ($debug) {
  2090. error_log('Getting course list');
  2091. }
  2092. $totalCourse = count($courseList);
  2093. $counter = 0;
  2094. foreach ($courseList as $courseData) {
  2095. $courseId = $courseData['id'];
  2096. if ($debug) {
  2097. error_log('Updating course: '.$courseData['code']);
  2098. }
  2099. $sql = "SELECT * FROM c_item_property WHERE c_id = $courseId";
  2100. $result = $connection->fetchAll($sql);
  2101. foreach ($result as $item) {
  2102. $sessionId = intval($item['session_id']);
  2103. $groupId = intval($item['to_group_id']);
  2104. $iid = $item['iid'];
  2105. $ref = $item['ref'];
  2106. // Fix group id
  2107. if (!empty($groupId)) {
  2108. $sql = "SELECT * FROM c_group_info
  2109. WHERE c_id = $courseId AND id = $groupId";
  2110. $data = $connection->fetchAssoc($sql);
  2111. if (!empty($data)) {
  2112. $newGroupId = $data['iid'];
  2113. $sql = "UPDATE c_item_property SET to_group_id = $newGroupId
  2114. WHERE iid = $iid";
  2115. $connection->executeQuery($sql);
  2116. } else {
  2117. // The group does not exists clean this record
  2118. $sql = "DELETE FROM c_item_property WHERE iid = $iid";
  2119. $connection->executeQuery($sql);
  2120. }
  2121. }
  2122. $sql = '';
  2123. $newId = '';
  2124. switch ($item['tool']) {
  2125. case TOOL_LINK:
  2126. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref ";
  2127. break;
  2128. case TOOL_STUDENTPUBLICATION:
  2129. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  2130. break;
  2131. case TOOL_QUIZ:
  2132. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  2133. break;
  2134. case TOOL_DOCUMENT:
  2135. $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  2136. break;
  2137. case TOOL_FORUM:
  2138. $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND id = $ref";
  2139. break;
  2140. case 'thread':
  2141. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND id = $ref";
  2142. break;
  2143. }
  2144. if (!empty($sql) && !empty($newId)) {
  2145. $data = $connection->fetchAssoc($sql);
  2146. if (isset($data['iid'])) {
  2147. $newId = $data['iid'];
  2148. }
  2149. $sql = "UPDATE c_item_property SET ref = $newId WHERE iid = $iid";
  2150. error_log($sql);
  2151. $connection->executeQuery($sql);
  2152. }
  2153. }
  2154. if ($debug) {
  2155. // Print a status in the log once in a while
  2156. error_log("Course process #$counter/$totalCourse");
  2157. }
  2158. $counter++;
  2159. }
  2160. if ($debug) {
  2161. error_log('update gradebook_link');
  2162. }
  2163. // Fix gradebook_link
  2164. $sql = "SELECT * FROM gradebook_link";
  2165. $result = $connection->fetchAll($sql);
  2166. foreach ($result as $item) {
  2167. $courseCode = $item['course_code'];
  2168. $sql = "SELECT * FROM course WHERE code = '$courseCode'";
  2169. $courseInfo = $connection->fetchAssoc($sql);
  2170. if (empty($courseInfo)) {
  2171. continue;
  2172. }
  2173. $courseId = $courseInfo['id'];
  2174. $ref = $item['ref_id'];
  2175. $iid = $item['id'];
  2176. $sql = '';
  2177. switch ($item['type']) {
  2178. case LINK_LEARNPATH:
  2179. $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref ";
  2180. break;
  2181. case LINK_STUDENTPUBLICATION:
  2182. $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref";
  2183. break;
  2184. case LINK_EXERCISE:
  2185. $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref";
  2186. break;
  2187. case LINK_ATTENDANCE:
  2188. //$sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref";
  2189. break;
  2190. case LINK_FORUM_THREAD:
  2191. $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND thread_id = $ref";
  2192. break;
  2193. }
  2194. if (!empty($sql)) {
  2195. $data = $connection->fetchAssoc($sql);
  2196. if (isset($data) && isset($data['iid'])) {
  2197. $newId = $data['iid'];
  2198. $sql = "UPDATE gradebook_link SET ref_id = $newId
  2199. WHERE id = $iid";
  2200. $connection->executeQuery($sql);
  2201. }
  2202. }
  2203. }
  2204. if ($debug) {
  2205. error_log('update groups');
  2206. }
  2207. $sql = "SELECT * FROM groups";
  2208. $result = $connection->executeQuery($sql);
  2209. $groups = $result->fetchAll();
  2210. $oldGroups = array();
  2211. if (!empty($groups)) {
  2212. foreach ($groups as $group) {
  2213. if (empty($group['name'])) {
  2214. continue;
  2215. }
  2216. $params = [
  2217. 'name' => $group['name'],
  2218. 'description' => $group['description'],
  2219. 'group_type' => 1,
  2220. 'picture' => $group['picture_uri'],
  2221. 'url' => $group['url'],
  2222. 'visibility' => $group['visibility'],
  2223. 'updated_at' => $group['updated_on'],
  2224. 'created_at' => $group['created_on']
  2225. ];
  2226. $connection->insert('usergroup', $params);
  2227. $id = $connection->lastInsertId('id');
  2228. $oldGroups[$group['id']] = $id;
  2229. }
  2230. }
  2231. if (!empty($oldGroups)) {
  2232. error_log('Moving group files');
  2233. foreach ($oldGroups as $oldId => $newId) {
  2234. $path = get_group_picture_path_by_id(
  2235. $oldId,
  2236. 'system'
  2237. );
  2238. if (!empty($path)) {
  2239. $newPath = str_replace(
  2240. "groups/$oldId/",
  2241. "groups/$newId/",
  2242. $path['dir']
  2243. );
  2244. $command = "mv {$path['dir']} $newPath ";
  2245. error_log("Executing $command");
  2246. system($command);
  2247. }
  2248. }
  2249. $sql = "SELECT * FROM group_rel_user";
  2250. $result = $connection->executeQuery($sql);
  2251. $dataList = $result->fetchAll();
  2252. if (!empty($dataList)) {
  2253. foreach ($dataList as $data) {
  2254. if (isset($oldGroups[$data['group_id']])) {
  2255. $data['group_id'] = $oldGroups[$data['group_id']];
  2256. $userId = $data['user_id'];
  2257. $sql = "SELECT id FROM user WHERE user_id = $userId";
  2258. $userResult = $connection->executeQuery($sql);
  2259. $userInfo = $userResult->fetch();
  2260. if (empty($userInfo)) {
  2261. continue;
  2262. }
  2263. $sql = "INSERT INTO usergroup_rel_user (usergroup_id, user_id, relation_type)
  2264. VALUES ('{$data['group_id']}', '{$userId}', '{$data['relation_type']}')";
  2265. $connection->executeQuery($sql);
  2266. }
  2267. }
  2268. }
  2269. $sql = "SELECT * FROM group_rel_group";
  2270. $result = $connection->executeQuery($sql);
  2271. $dataList = $result->fetchAll();
  2272. if (!empty($dataList)) {
  2273. foreach ($dataList as $data) {
  2274. if (isset($oldGroups[$data['group_id']]) && isset($oldGroups[$data['subgroup_id']])) {
  2275. $data['group_id'] = $oldGroups[$data['group_id']];
  2276. $data['subgroup_id'] = $oldGroups[$data['subgroup_id']];
  2277. $sql = "INSERT INTO usergroup_rel_usergroup (group_id, subgroup_id, relation_type)
  2278. VALUES ('{$data['group_id']}', '{$data['subgroup_id']}', '{$data['relation_type']}')";
  2279. $connection->executeQuery($sql);
  2280. }
  2281. }
  2282. }
  2283. $sql = "SELECT * FROM announcement_rel_group";
  2284. $result = $connection->executeQuery($sql);
  2285. $dataList = $result->fetchAll();
  2286. if (!empty($dataList)) {
  2287. foreach ($dataList as $data) {
  2288. if (isset($oldGroups[$data['group_id']])) {
  2289. // Deleting relation
  2290. $sql = "DELETE FROM announcement_rel_group WHERE group_id = {$data['group_id']}";
  2291. $connection->executeQuery($sql);
  2292. // Add new relation
  2293. $data['group_id'] = $oldGroups[$data['group_id']];
  2294. $sql = "INSERT INTO announcement_rel_group(group_id, announcement_id)
  2295. VALUES ('{$data['group_id']}', '{$data['announcement_id']}')";
  2296. $connection->executeQuery($sql);
  2297. }
  2298. }
  2299. }
  2300. $sql = "SELECT * FROM group_rel_tag";
  2301. $result = $connection->executeQuery($sql);
  2302. $dataList = $result->fetchAll();
  2303. if (!empty($dataList)) {
  2304. foreach ($dataList as $data) {
  2305. if (isset($oldGroups[$data['group_id']])) {
  2306. $data['group_id'] = $oldGroups[$data['group_id']];
  2307. $sql = "INSERT INTO usergroup_rel_tag (tag_id, usergroup_id)
  2308. VALUES ('{$data['tag_id']}', '{$data['group_id']}')";
  2309. $connection->executeQuery($sql);
  2310. }
  2311. }
  2312. }
  2313. }
  2314. if ($debug) {
  2315. error_log('update extra fields');
  2316. }
  2317. // Extra fields
  2318. $extraFieldTables = [
  2319. ExtraField::USER_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_USER_FIELD),
  2320. ExtraField::COURSE_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_COURSE_FIELD),
  2321. //ExtraField::LP_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_LP_FIELD),
  2322. ExtraField::SESSION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_SESSION_FIELD),
  2323. //ExtraField::CALENDAR_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD),
  2324. //ExtraField::QUESTION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD),
  2325. //ExtraField::USER_FIELD_TYPE => //Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD),
  2326. ];
  2327. foreach ($extraFieldTables as $type => $table) {
  2328. $sql = "SELECT * FROM $table ";
  2329. if ($debug) {
  2330. error_log($sql);
  2331. }
  2332. $result = $connection->query($sql);
  2333. $fields = $result->fetchAll();
  2334. foreach ($fields as $field) {
  2335. if ($debug) {
  2336. error_log("Loading field: ".$field['field_variable']);
  2337. }
  2338. $originalId = $field['id'];
  2339. $params = [
  2340. 'extra_field_type' => $type,
  2341. 'variable' => $field['field_variable'],
  2342. 'field_type' => $field['field_type'],
  2343. 'display_text' => $field['field_display_text'],
  2344. 'default_value' => $field['field_default_value'],
  2345. 'field_order' => $field['field_order'],
  2346. 'visible' => $field['field_visible'],
  2347. 'changeable' => $field['field_changeable'],
  2348. 'filter' => $field['field_filter']
  2349. ];
  2350. $connection->insert('extra_field', $params);
  2351. $newExtraFieldId = $connection->lastInsertId();
  2352. $values = array();
  2353. $handlerId = null;
  2354. switch ($type) {
  2355. case ExtraField::USER_FIELD_TYPE:
  2356. $optionTable = Database::get_main_table(
  2357. TABLE_MAIN_USER_FIELD_OPTIONS
  2358. );
  2359. $valueTable = Database::get_main_table(
  2360. TABLE_MAIN_USER_FIELD_VALUES
  2361. );
  2362. $handlerId = 'user_id';
  2363. break;
  2364. case ExtraField::COURSE_FIELD_TYPE:
  2365. $optionTable = Database::get_main_table(
  2366. TABLE_MAIN_COURSE_FIELD_OPTIONS
  2367. );
  2368. $valueTable = Database::get_main_table(
  2369. TABLE_MAIN_COURSE_FIELD_VALUES
  2370. );
  2371. $handlerId = 'c_id';
  2372. break;
  2373. case ExtraField::SESSION_FIELD_TYPE:
  2374. $optionTable = Database::get_main_table(
  2375. TABLE_MAIN_SESSION_FIELD_OPTIONS
  2376. );
  2377. $valueTable = Database::get_main_table(
  2378. TABLE_MAIN_SESSION_FIELD_VALUES
  2379. );
  2380. $handlerId = 'session_id';
  2381. break;
  2382. }
  2383. if (!empty($optionTable)) {
  2384. $sql = "SELECT * FROM $optionTable WHERE field_id = $originalId ";
  2385. $result = $connection->query($sql);
  2386. $options = $result->fetchAll();
  2387. foreach ($options as $option) {
  2388. $params = [
  2389. 'display_text' => $option['option_display_text'],
  2390. 'field_id' => $newExtraFieldId,
  2391. 'option_order' => $option['option_order'],
  2392. 'option_value' => $option['option_value']
  2393. ];
  2394. $connection->insert('extra_field_options', $params);
  2395. }
  2396. $sql = "SELECT * FROM $valueTable WHERE field_id = $originalId ";
  2397. $result = $connection->query($sql);
  2398. $values = $result->fetchAll();
  2399. if ($debug) {
  2400. error_log("Fetch all values for field");
  2401. }
  2402. }
  2403. if (!empty($values)) {
  2404. if ($debug) {
  2405. error_log("Saving field value in new table");
  2406. }
  2407. $k = 0;
  2408. foreach ($values as $value) {
  2409. if (isset($value[$handlerId])) {
  2410. // Insert without the use of the entity as it reduces
  2411. // speed to 2 records per second (much too slow)
  2412. $params = [
  2413. 'field_id' => $newExtraFieldId,
  2414. 'value' => $value['field_value'],
  2415. 'item_id' => $value[$handlerId]
  2416. ];
  2417. $connection->insert('extra_field_values', $params);
  2418. if ($debug && ($k % 10000 == 0)) {
  2419. error_log("Saving field $k");
  2420. }
  2421. $k++;
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. if ($debug) {
  2428. error_log('Remove index');
  2429. }
  2430. // Drop temporary indexes added to increase speed of this function's queries
  2431. $sql = "ALTER TABLE c_document DROP INDEX tmpidx_doc";
  2432. $connection->executeQuery($sql);
  2433. $sql = "ALTER TABLE c_student_publication DROP INDEX tmpidx_stud";
  2434. $connection->executeQuery($sql);
  2435. $sql = "ALTER TABLE c_quiz DROP INDEX tmpidx_quiz";
  2436. $connection->executeQuery($sql);
  2437. $sql = "ALTER TABLE c_item_property DROP INDEX tmpidx_ip";
  2438. $connection->executeQuery($sql);
  2439. if ($debug) {
  2440. error_log('Finish fixId function');
  2441. }
  2442. }
  2443. /**
  2444. *
  2445. * After the schema was created (table creation), the function adds
  2446. * admin/platform information.
  2447. *
  2448. * @param EntityManager $manager
  2449. * @param string $sysPath
  2450. * @param string $encryptPassForm
  2451. * @param string $passForm
  2452. * @param string $adminLastName
  2453. * @param string $adminFirstName
  2454. * @param string $loginForm
  2455. * @param string $emailForm
  2456. * @param string $adminPhoneForm
  2457. * @param string $languageForm
  2458. * @param string $institutionForm
  2459. * @param string $institutionUrlForm
  2460. * @param string $siteName
  2461. * @param string $allowSelfReg
  2462. * @param string $allowSelfRegProf
  2463. * @param string $installationProfile Installation profile, if any was provided
  2464. */
  2465. function finishInstallation(
  2466. $manager,
  2467. $sysPath,
  2468. $encryptPassForm,
  2469. $passForm,
  2470. $adminLastName,
  2471. $adminFirstName,
  2472. $loginForm,
  2473. $emailForm,
  2474. $adminPhoneForm,
  2475. $languageForm,
  2476. $institutionForm,
  2477. $institutionUrlForm,
  2478. $siteName,
  2479. $allowSelfReg,
  2480. $allowSelfRegProf,
  2481. $installationProfile = ''
  2482. ) {
  2483. $sysPath = !empty($sysPath) ? $sysPath : api_get_path(SYS_PATH);
  2484. $connection = $manager->getConnection();
  2485. $sql = getVersionTable();
  2486. // Add version table
  2487. $connection->executeQuery($sql);
  2488. // Add tickets defaults
  2489. $ticketProject = new TicketProject();
  2490. $ticketProject
  2491. ->setId(1)
  2492. ->setName('Ticket System')
  2493. ->setInsertUserId(1);
  2494. $manager->persist($ticketProject);
  2495. $manager->flush();
  2496. $categories = array(
  2497. get_lang('TicketEnrollment') => get_lang('TicketsAboutEnrollment'),
  2498. get_lang('TicketGeneralInformation') => get_lang('TicketsAboutGeneralInformation'),
  2499. get_lang('TicketRequestAndPapework') => get_lang('TicketsAboutRequestAndPapework'),
  2500. get_lang('TicketAcademicIncidence') => get_lang('TicketsAboutAcademicIncidence'),
  2501. get_lang('TicketVirtualCampus') => get_lang('TicketsAboutVirtualCampus'),
  2502. get_lang('TicketOnlineEvaluation') => get_lang('TicketsAboutOnlineEvaluation')
  2503. );
  2504. $i = 1;
  2505. /**
  2506. * @var string $category
  2507. * @var string $description
  2508. */
  2509. foreach ($categories as $category => $description) {
  2510. // Online evaluation requires a course
  2511. $ticketCategory = new TicketCategory();
  2512. $ticketCategory
  2513. ->setId($i)
  2514. ->setName($category)
  2515. ->setDescription($description)
  2516. ->setProject($ticketProject)
  2517. ->setInsertUserId(1);
  2518. $isRequired = $i == 6;
  2519. $ticketCategory->setCourseRequired($isRequired);
  2520. $manager->persist($ticketCategory);
  2521. $manager->flush();
  2522. $i++;
  2523. }
  2524. // Default Priorities
  2525. $defaultPriorities = array(
  2526. TicketManager::PRIORITY_NORMAL => get_lang('PriorityNormal'),
  2527. TicketManager::PRIORITY_HIGH => get_lang('PriorityHigh'),
  2528. TicketManager::PRIORITY_LOW => get_lang('PriorityLow')
  2529. );
  2530. $table = Database::get_main_table(TABLE_TICKET_PRIORITY);
  2531. $i = 1;
  2532. foreach ($defaultPriorities as $code => $priority) {
  2533. $ticketPriority = new TicketPriority();
  2534. $ticketPriority
  2535. ->setId($i)
  2536. ->setName($priority)
  2537. ->setCode($code)
  2538. ->setInsertUserId(1);
  2539. $manager->persist($ticketPriority);
  2540. $manager->flush();
  2541. $i++;
  2542. }
  2543. $table = Database::get_main_table(TABLE_TICKET_STATUS);
  2544. // Default status
  2545. $defaultStatus = array(
  2546. TicketManager::STATUS_NEW => get_lang('StatusNew'),
  2547. TicketManager::STATUS_PENDING => get_lang('StatusPending'),
  2548. TicketManager::STATUS_UNCONFIRMED => get_lang('StatusUnconfirmed'),
  2549. TicketManager::STATUS_CLOSE => get_lang('StatusClose'),
  2550. TicketManager::STATUS_FORWARDED => get_lang('StatusForwarded')
  2551. );
  2552. $i = 1;
  2553. foreach ($defaultStatus as $code => $status) {
  2554. $attributes = array(
  2555. 'id' => $i,
  2556. 'code' => $code,
  2557. 'name' => $status
  2558. );
  2559. Database::insert($table, $attributes);
  2560. $i++;
  2561. }
  2562. // Inserting data.sql
  2563. $data = file_get_contents($sysPath.'main/install/data.sql');
  2564. $result = $manager->getConnection()->prepare($data);
  2565. $result->execute();
  2566. $result->closeCursor();
  2567. UserManager::setPasswordEncryption($encryptPassForm);
  2568. // Create admin user.
  2569. @UserManager::create_user(
  2570. $adminFirstName,
  2571. $adminLastName,
  2572. 1,
  2573. $emailForm,
  2574. $loginForm,
  2575. $passForm,
  2576. 'ADMIN', //$official_code = '',
  2577. $languageForm,
  2578. $adminPhoneForm,
  2579. '', //$picture_uri = '',
  2580. PLATFORM_AUTH_SOURCE,
  2581. '', //$expirationDate,
  2582. 1,
  2583. 0,
  2584. null,
  2585. '',
  2586. false, //$send_mail = false,
  2587. true //$isAdmin = false
  2588. );
  2589. // Create anonymous user.
  2590. @UserManager::create_user(
  2591. 'Joe',
  2592. 'Anonymous',
  2593. 6,
  2594. 'anonymous@localhost',
  2595. 'anon',
  2596. 'anon',
  2597. 'anonymous', //$official_code = '',
  2598. $languageForm,
  2599. '',
  2600. '', //$picture_uri = '',
  2601. PLATFORM_AUTH_SOURCE,
  2602. '',
  2603. 1,
  2604. 0,
  2605. null,
  2606. '',
  2607. false, //$send_mail = false,
  2608. false //$isAdmin = false
  2609. );
  2610. // Set default language
  2611. $sql = "UPDATE language SET available = 1 WHERE dokeos_folder = '$languageForm'";
  2612. Database::query($sql);
  2613. // Install settings
  2614. installSettings(
  2615. $institutionForm,
  2616. $institutionUrlForm,
  2617. $siteName,
  2618. $emailForm,
  2619. $adminLastName,
  2620. $adminFirstName,
  2621. $languageForm,
  2622. $allowSelfReg,
  2623. $allowSelfRegProf,
  2624. $installationProfile
  2625. );
  2626. lockSettings();
  2627. updateDirAndFilesPermissions();
  2628. // Set the latest version
  2629. $path = $sysPath.'app/Migrations/Schema/V111/';
  2630. $finder = new \Symfony\Component\Finder\Finder();
  2631. $files = $finder->files()->in($path);
  2632. // Needed for chash
  2633. createVersionTable();
  2634. foreach ($files as $version) {
  2635. $version = str_replace(['Version', '.php'], '', $version->getFilename());
  2636. $sql = "INSERT INTO version (version) VALUES ('$version')";
  2637. Database::query($sql);
  2638. }
  2639. }
  2640. /**
  2641. * Creates 'version' table
  2642. */
  2643. function createVersionTable()
  2644. {
  2645. $sql = getVersionTable();
  2646. Database::query($sql);
  2647. }
  2648. /**
  2649. * Get version creation table query
  2650. * @return string
  2651. */
  2652. function getVersionTable()
  2653. {
  2654. return 'CREATE TABLE IF NOT EXISTS version (id int unsigned NOT NULL AUTO_INCREMENT, version varchar(20), PRIMARY KEY(id), UNIQUE(version));';
  2655. }
  2656. /**
  2657. * Update settings based on installation profile defined in a JSON file
  2658. * @param string $installationProfile The name of the JSON file in main/install/profiles/ folder
  2659. *
  2660. * @return bool false on failure (no bad consequences anyway, just ignoring profile)
  2661. */
  2662. function installProfileSettings($installationProfile = '')
  2663. {
  2664. if (empty($installationProfile)) {
  2665. return false;
  2666. }
  2667. $jsonPath = api_get_path(SYS_PATH).'main/install/profiles/'.$installationProfile.'.json';
  2668. // Make sure the path to the profile is not hacked
  2669. if (!Security::check_abs_path($jsonPath, api_get_path(SYS_PATH).'main/install/profiles/')) {
  2670. return false;
  2671. }
  2672. if (!is_file($jsonPath)) {
  2673. return false;
  2674. }
  2675. if (!is_readable($jsonPath)) {
  2676. return false;
  2677. }
  2678. if (!function_exists('json_decode')) {
  2679. // The php-json extension is not available. Ignore profile.
  2680. return false;
  2681. }
  2682. $json = file_get_contents($jsonPath);
  2683. $params = json_decode($json);
  2684. if ($params === false or $params === null) {
  2685. return false;
  2686. }
  2687. $settings = $params->params;
  2688. if (!empty($params->parent)) {
  2689. installProfileSettings($params->parent);
  2690. }
  2691. foreach ($settings as $id => $param) {
  2692. $sql = "UPDATE settings_current
  2693. SET selected_value = '".$param->selected_value."'
  2694. WHERE variable = '".$param->variable."'";
  2695. if (!empty($param->subkey)) {
  2696. $sql .= " AND subkey='".$param->subkey."'";
  2697. }
  2698. Database::query($sql);
  2699. }
  2700. return true;
  2701. }
  2702. /**
  2703. * Quick function to remove a directory with its subdirectories
  2704. * @param $dir
  2705. */
  2706. function rrmdir($dir)
  2707. {
  2708. if (is_dir($dir)) {
  2709. $objects = scandir($dir);
  2710. foreach ($objects as $object) {
  2711. if ($object != "." && $object != "..") {
  2712. if (filetype($dir."/".$object) == "dir") {
  2713. @rrmdir($dir."/".$object);
  2714. } else {
  2715. @unlink($dir."/".$object);
  2716. }
  2717. }
  2718. }
  2719. reset($objects);
  2720. rmdir($dir);
  2721. }
  2722. }
  2723. function get_group_picture_path_by_id($id, $type = 'web', $preview = false, $anonymous = false)
  2724. {
  2725. switch ($type) {
  2726. case 'system': // Base: absolute system path.
  2727. $base = api_get_path(SYS_UPLOAD_PATH);
  2728. break;
  2729. case 'web': // Base: absolute web path.
  2730. default:
  2731. $base = api_get_path(WEB_UPLOAD_PATH);
  2732. break;
  2733. }
  2734. $noPicturePath = array('dir' => $base.'img/', 'file' => 'unknown.jpg');
  2735. if (empty($id) || empty($type)) {
  2736. return $anonymous ? $noPicturePath : array('dir' => '', 'file' => '');
  2737. }
  2738. $id = intval($id);
  2739. //$group_table = Database::get_main_table(TABLE_MAIN_GROUP);
  2740. $group_table = 'groups';
  2741. $sql = "SELECT picture_uri FROM $group_table WHERE id=".$id;
  2742. $res = Database::query($sql);
  2743. if (!Database::num_rows($res)) {
  2744. return $anonymous ? $noPicturePath : array('dir' => '', 'file' => '');
  2745. }
  2746. $user = Database::fetch_array($res);
  2747. $picture_filename = trim($user['picture_uri']);
  2748. if (api_get_setting('split_users_upload_directory') === 'true') {
  2749. if (!empty($picture_filename)) {
  2750. $dir = $base.'groups/'.substr($picture_filename, 0, 1).'/'.$id.'/';
  2751. } elseif ($preview) {
  2752. $dir = $base.'groups/'.substr((string) $id, 0, 1).'/'.$id.'/';
  2753. } else {
  2754. $dir = $base.'groups/'.$id.'/';
  2755. }
  2756. } else {
  2757. $dir = $base.'groups/'.$id.'/';
  2758. }
  2759. if (empty($picture_filename) && $anonymous) {
  2760. return $noPicturePath;
  2761. }
  2762. return array('dir' => $dir, 'file' => $picture_filename);
  2763. }
  2764. /**
  2765. * Control the different steps of the migration through a big switch
  2766. * @param string $fromVersion
  2767. * @param EntityManager $manager
  2768. * @param bool $processFiles
  2769. * @return bool Always returns true except if the process is broken
  2770. */
  2771. function migrateSwitch($fromVersion, $manager, $processFiles = true)
  2772. {
  2773. error_log('Starting migration process from '.$fromVersion.' ('.date('Y-m-d H:i:s').')');
  2774. echo '<a class="btn btn-default" href="javascript:void(0)" id="details_button">'.get_lang('Details').'</a><br />';
  2775. echo '<div id="details" style="display:none">';
  2776. $connection = $manager->getConnection();
  2777. $database = new Database();
  2778. $database->setManager($manager);
  2779. switch ($fromVersion) {
  2780. case '1.9.0':
  2781. // no break
  2782. case '1.9.2':
  2783. // no break
  2784. case '1.9.4':
  2785. // no break
  2786. case '1.9.6':
  2787. // no break
  2788. case '1.9.6.1':
  2789. // no break
  2790. case '1.9.8':
  2791. // no break
  2792. case '1.9.8.1':
  2793. // no break
  2794. case '1.9.8.2':
  2795. // no break
  2796. case '1.9.10':
  2797. // no break
  2798. case '1.9.10.2':
  2799. // no break
  2800. case '1.9.10.4':
  2801. // no break
  2802. case '1.9.10.6':
  2803. $database = new Database();
  2804. $database->setManager($manager);
  2805. // Fix type "enum" before running the migration with Doctrine
  2806. $connection->executeQuery("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'");
  2807. $connection->executeQuery("ALTER TABLE course_category MODIFY COLUMN auth_cat_child VARCHAR(40) DEFAULT 'TRUE'");
  2808. $connection->executeQuery("ALTER TABLE c_quiz_answer MODIFY COLUMN hotspot_type varchar(40) default NULL");
  2809. $connection->executeQuery("ALTER TABLE c_tool MODIFY COLUMN target varchar(20) NOT NULL default '_self'");
  2810. $connection->executeQuery("ALTER TABLE c_link MODIFY COLUMN on_homepage char(10) NOT NULL default '0'");
  2811. $connection->executeQuery("ALTER TABLE c_blog_rating MODIFY COLUMN rating_type char(40) NOT NULL default 'post'");
  2812. $connection->executeQuery("ALTER TABLE c_survey MODIFY COLUMN anonymous char(10) NOT NULL default '0'");
  2813. $connection->executeQuery("ALTER TABLE c_document MODIFY COLUMN filetype char(10) NOT NULL default 'file'");
  2814. $connection->executeQuery("ALTER TABLE c_student_publication MODIFY COLUMN filetype char(10) NOT NULL default 'file'");
  2815. // Migrate using the migration files located in:
  2816. // src/Chamilo/CoreBundle/Migrations/Schema/V110
  2817. $result = migrate(
  2818. 110,
  2819. $manager
  2820. );
  2821. if ($result) {
  2822. error_log('Migrations files were executed ('.date('Y-m-d H:i:s').')');
  2823. fixIds($manager);
  2824. error_log('fixIds finished ('.date('Y-m-d H:i:s').')');
  2825. $connection->executeQuery("UPDATE settings_current SET selected_value = '1.10.0' WHERE variable = 'chamilo_database_version'");
  2826. if ($processFiles) {
  2827. $fromVersionShort = '1.9';
  2828. include __DIR__.'/update-files-1.9.0-1.10.0.inc.php';
  2829. // Only updates the configuration.inc.php with the new version
  2830. include __DIR__.'/update-configuration.inc.php';
  2831. $configurationFiles = array(
  2832. 'mail.conf.php',
  2833. 'profile.conf.php',
  2834. 'course_info.conf.php',
  2835. 'add_course.conf.php',
  2836. 'events.conf.php',
  2837. 'auth.conf.php',
  2838. 'portfolio.conf.php'
  2839. );
  2840. error_log('Copy conf files');
  2841. foreach ($configurationFiles as $file) {
  2842. if (file_exists(api_get_path(SYS_CODE_PATH).'inc/conf/'.$file)) {
  2843. copy(
  2844. api_get_path(SYS_CODE_PATH).'inc/conf/'.$file,
  2845. api_get_path(CONFIGURATION_PATH).$file
  2846. );
  2847. }
  2848. }
  2849. }
  2850. error_log('Upgrade 1.10.x process concluded! ('.date('Y-m-d H:i:s').')');
  2851. } else {
  2852. error_log('There was an error during running migrations. Check error.log');
  2853. break;
  2854. }
  2855. case '1.10.0':
  2856. // no break
  2857. case '1.10.2':
  2858. // no break
  2859. case '1.10.4':
  2860. // no break
  2861. case '1.10.6':
  2862. // no break
  2863. case '1.10.8':
  2864. $database = new Database();
  2865. $database->setManager($manager);
  2866. // Migrate using the migration files located in:
  2867. // src/Chamilo/CoreBundle/Migrations/Schema/V111
  2868. $result = migrate(
  2869. 111,
  2870. $manager
  2871. );
  2872. if ($result) {
  2873. error_log('Migrations files were executed ('.date('Y-m-d H:i:s').')');
  2874. $connection->executeQuery("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'");
  2875. // Fix post_group_id
  2876. $sql = "SELECT * FROM c_student_publication where (post_group_id <> 0 or post_group_id is not null)";
  2877. $statement = $connection->executeQuery($sql);
  2878. $result = $statement->fetchAll();
  2879. foreach ($result as $row) {
  2880. $groupId = $row['post_group_id'];
  2881. $courseId = $row['c_id'];
  2882. $sessionId = $row['session_id'];
  2883. $workIid = $row['iid'];
  2884. $sql = "SELECT iid from c_group_info where c_id = $courseId and iid = $groupId";
  2885. $statement = $connection->executeQuery($sql);
  2886. $count = $statement->rowCount();
  2887. if ($count == 0) {
  2888. $sql = "SELECT iid from c_group_info where c_id = $courseId and id = $groupId";
  2889. $statement = $connection->executeQuery($sql);
  2890. $count = $statement->rowCount();
  2891. if ($count > 0) {
  2892. $rowGroup = $statement->fetch();
  2893. $newGroupId = $rowGroup['iid'];
  2894. if ($newGroupId) {
  2895. $sqlUpdate = "UPDATE c_student_publication
  2896. SET post_group_id = $newGroupId
  2897. WHERE
  2898. c_id = $courseId AND
  2899. post_group_id = $groupId AND
  2900. iid = $workIid
  2901. ";
  2902. $connection->executeQuery($sqlUpdate);
  2903. }
  2904. }
  2905. }
  2906. }
  2907. // Fix work documents that don't have c_item_property value
  2908. $sql = "SELECT * FROM c_student_publication WHERE parent_id IS NOT NULL";
  2909. $statement = $connection->executeQuery($sql);
  2910. $result = $statement->fetchAll();
  2911. foreach ($result as $row) {
  2912. $groupId = $row['post_group_id'];
  2913. $courseId = $row['c_id'];
  2914. $sessionId = $row['session_id'];
  2915. $workId = $row['id'];
  2916. $itemInfo = api_get_item_property_info(
  2917. $courseId,
  2918. 'work',
  2919. $workId,
  2920. $sessionId
  2921. );
  2922. $courseInfo = api_get_course_info_by_id($courseId);
  2923. if (empty($itemInfo)) {
  2924. api_item_property_update(
  2925. $courseInfo,
  2926. 'work',
  2927. $workId,
  2928. 'visible',
  2929. 1,
  2930. $groupId,
  2931. null,
  2932. null,
  2933. null,
  2934. $sessionId
  2935. );
  2936. }
  2937. }
  2938. $sql = "UPDATE settings_current SET selected_value = '1.11.0' WHERE variable = 'chamilo_database_version'";
  2939. $connection->executeQuery($sql);
  2940. if ($processFiles) {
  2941. $fromVersionShort = '1.10';
  2942. include __DIR__.'/update-files-1.10.0-1.11.0.inc.php';
  2943. // Only updates the configuration.inc.php with the new version
  2944. include __DIR__.'/update-configuration.inc.php';
  2945. }
  2946. error_log('Upgrade 1.11.x process concluded! ('.date('Y-m-d H:i:s').')');
  2947. } else {
  2948. error_log('There was an error during running migrations. Check error.log');
  2949. }
  2950. break;
  2951. default:
  2952. break;
  2953. }
  2954. echo '</div>';
  2955. return true;
  2956. }