install.lib.php 128 KB

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