settings.lib.php 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
  4. use Chamilo\CoreBundle\Entity\SystemTemplate;
  5. use ChamiloSession as Session;
  6. use Symfony\Component\Filesystem\Filesystem;
  7. /**
  8. * Library of the settings.php file.
  9. *
  10. * @author Julio Montoya <gugli100@gmail.com>
  11. * @author Guillaume Viguier <guillaume@viguierjust.com>
  12. *
  13. * @since Chamilo 1.8.7
  14. *
  15. * @package chamilo.admin
  16. */
  17. define('CSS_UPLOAD_PATH', api_get_path(SYS_APP_PATH).'Resources/public/css/themes/');
  18. /**
  19. * This function allows easy activating and inactivating of regions.
  20. *
  21. * @author Julio Montoya <gugli100@gmail.com> Beeznest 2012
  22. */
  23. function handleRegions()
  24. {
  25. if (isset($_POST['submit_plugins'])) {
  26. storeRegions();
  27. // Add event to the system log.
  28. $user_id = api_get_user_id();
  29. $category = $_GET['category'];
  30. Event::addEvent(
  31. LOG_CONFIGURATION_SETTINGS_CHANGE,
  32. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  33. $category,
  34. api_get_utc_datetime(),
  35. $user_id
  36. );
  37. echo Display::return_message(get_lang('The settings have been stored'), 'confirmation');
  38. }
  39. $plugin_obj = new AppPlugin();
  40. $installed_plugins = $plugin_obj->getInstalledPlugins();
  41. echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'">';
  42. echo '<table class="data_table">';
  43. echo '<tr>';
  44. echo '<th width="400px">';
  45. echo get_lang('Plugin');
  46. echo '</th><th>';
  47. echo get_lang('Regions');
  48. echo '</th>';
  49. echo '</th>';
  50. echo '</tr>';
  51. /* We display all the possible plugins and the checkboxes */
  52. $plugin_region_list = [];
  53. $my_plugin_list = $plugin_obj->getPluginRegions();
  54. foreach ($my_plugin_list as $plugin_item) {
  55. $plugin_region_list[$plugin_item] = $plugin_item;
  56. }
  57. // Removing course tool
  58. unset($plugin_region_list['course_tool_plugin']);
  59. foreach ($installed_plugins as $pluginName) {
  60. $plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$pluginName.'/plugin.php';
  61. if (file_exists($plugin_info_file)) {
  62. $plugin_info = [];
  63. require $plugin_info_file;
  64. if (isset($_GET['name']) && $_GET['name'] === $pluginName) {
  65. echo '<tr class="row_selected">';
  66. } else {
  67. echo '<tr>';
  68. }
  69. echo '<td>';
  70. echo '<h4>'.$plugin_info['title'].' <small>v'.$plugin_info['version'].'</small></h4>';
  71. echo '<p>'.$plugin_info['comment'].'</p>';
  72. echo '</td><td>';
  73. $selected_plugins = $plugin_obj->get_areas_by_plugin($pluginName);
  74. $region_list = [];
  75. $isAdminPlugin = isset($plugin_info['is_admin_plugin']) && $plugin_info['is_admin_plugin'];
  76. $isCoursePlugin = isset($plugin_info['is_course_plugin']) && $plugin_info['is_course_plugin'];
  77. if (!$isAdminPlugin && !$isCoursePlugin) {
  78. $region_list = $plugin_region_list;
  79. } else {
  80. if ($isAdminPlugin) {
  81. $region_list['menu_administrator'] = 'menu_administrator';
  82. }
  83. if ($isCoursePlugin) {
  84. $region_list['course_tool_plugin'] = 'course_tool_plugin';
  85. }
  86. }
  87. echo Display::select(
  88. 'plugin_'.$pluginName.'[]',
  89. $region_list,
  90. $selected_plugins,
  91. ['multiple' => 'multiple', 'style' => 'width:500px'],
  92. true,
  93. get_lang('none')
  94. );
  95. echo '</td></tr>';
  96. }
  97. }
  98. echo '</table>';
  99. echo '<br />';
  100. echo '<button class="btn btn-success" type="submit" name="submit_plugins">'.get_lang('Enable the selected plugins').'</button></form>';
  101. }
  102. function handleExtensions()
  103. {
  104. echo Display::page_subheader(get_lang('Configure extensions'));
  105. echo '<a class="btn btn-success" href="configure_extensions.php?display=ppt2lp" role="button">'.get_lang('Chamilo RAPID').'</a>';
  106. }
  107. /**
  108. * This function allows easy activating and inactivating of plugins.
  109. *
  110. * @todo: a similar function needs to be written to activate or inactivate additional tools.
  111. *
  112. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  113. * @author Julio Montoya <gugli100@gmail.com> Beeznest 2012
  114. */
  115. function handlePlugins()
  116. {
  117. Session::erase('plugin_data');
  118. $plugin_obj = new AppPlugin();
  119. $token = Security::get_token();
  120. if (isset($_POST['submit_plugins'])) {
  121. storePlugins();
  122. // Add event to the system log.
  123. $user_id = api_get_user_id();
  124. $category = $_GET['category'];
  125. Event::addEvent(
  126. LOG_CONFIGURATION_SETTINGS_CHANGE,
  127. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  128. $category,
  129. api_get_utc_datetime(),
  130. $user_id
  131. );
  132. echo Display::return_message(get_lang('The settings have been stored'), 'confirmation');
  133. }
  134. $all_plugins = $plugin_obj->read_plugins_from_path();
  135. $installed_plugins = $plugin_obj->getInstalledPlugins();
  136. // Plugins NOT installed
  137. echo Display::page_subheader(get_lang('Plugins'));
  138. echo '<form class="form-horizontal" name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'&sec_token='.$token.'">';
  139. echo '<table class="table table-hover table-striped table-bordered">';
  140. echo '<tr>';
  141. echo '<th width="20px">';
  142. echo get_lang('Action');
  143. echo '</th><th>';
  144. echo get_lang('Description');
  145. echo '</th>';
  146. echo '</tr>';
  147. /*$plugin_list = array();
  148. $my_plugin_list = $plugin_obj->get_plugin_regions();
  149. foreach($my_plugin_list as $plugin_item) {
  150. $plugin_list[$plugin_item] = $plugin_item;
  151. }*/
  152. $installed = '';
  153. $notInstalled = '';
  154. foreach ($all_plugins as $pluginName) {
  155. $plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$pluginName.'/plugin.php';
  156. if (file_exists($plugin_info_file)) {
  157. $plugin_info = [];
  158. require $plugin_info_file;
  159. $pluginRow = '';
  160. if (in_array($pluginName, $installed_plugins)) {
  161. $pluginRow .= '<tr class="row_selected">';
  162. } else {
  163. $pluginRow .= '<tr>';
  164. }
  165. $pluginRow .= '<td>';
  166. // Checkbox
  167. if (in_array($pluginName, $installed_plugins)) {
  168. $pluginRow .= '<input type="checkbox" name="plugin_'.$pluginName.'[]" checked="checked">';
  169. } else {
  170. $pluginRow .= '<input type="checkbox" name="plugin_'.$pluginName.'[]">';
  171. }
  172. $pluginRow .= '</td><td>';
  173. $pluginRow .= '<h4>'.$plugin_info['title'].' <small>v '.$plugin_info['version'].'</small></h4>';
  174. $pluginRow .= '<p>'.$plugin_info['comment'].'</p>';
  175. $pluginRow .= '<p>'.get_lang('Author').': '.$plugin_info['author'].'</p>';
  176. $pluginRow .= '<div class="btn-group btn-group-sm">';
  177. if (in_array($pluginName, $installed_plugins)) {
  178. $pluginRow .= Display::url(
  179. '<em class="fa fa-cogs"></em> '.get_lang('Configure'),
  180. 'configure_plugin.php?name='.$pluginName,
  181. ['class' => 'btn btn-primary']
  182. );
  183. $pluginRow .= Display::url(
  184. '<em class="fa fa-th-large"></em> '.get_lang('Regions'),
  185. 'settings.php?category=Regions&name='.$pluginName,
  186. ['class' => 'btn btn-primary']
  187. );
  188. }
  189. if (file_exists(api_get_path(SYS_PLUGIN_PATH).$pluginName.'/readme.txt')) {
  190. $pluginRow .= Display::url(
  191. "<em class='fa fa-file-text-o'></em> readme.txt",
  192. api_get_path(WEB_PLUGIN_PATH).$pluginName."/readme.txt",
  193. [
  194. 'class' => 'btn btn-primary ajax',
  195. 'data-title' => $plugin_info['title'],
  196. 'data-size' => 'lg',
  197. '_target' => '_blank',
  198. ]
  199. );
  200. }
  201. $readmeFile = api_get_path(SYS_PLUGIN_PATH).$pluginName.'/README.md';
  202. if (file_exists($readmeFile)) {
  203. $pluginRow .= Display::url(
  204. "<em class='fa fa-file-text-o'></em> README.md",
  205. api_get_path(WEB_AJAX_PATH).'plugin.ajax.php?a=md_to_html&plugin='.$pluginName,
  206. [
  207. 'class' => 'btn btn-primary ajax',
  208. 'data-title' => $plugin_info['title'],
  209. 'data-size' => 'lg',
  210. '_target' => '_blank',
  211. ]
  212. );
  213. }
  214. $pluginRow .= '</div>';
  215. $pluginRow .= '</td></tr>';
  216. if (in_array($pluginName, $installed_plugins)) {
  217. $installed .= $pluginRow;
  218. } else {
  219. $notInstalled .= $pluginRow;
  220. }
  221. }
  222. }
  223. echo $installed;
  224. echo $notInstalled;
  225. echo '</table>';
  226. echo '<div class="form-actions bottom_actions">';
  227. echo '<button class="btn btn-primary" type="submit" name="submit_plugins">';
  228. echo '<i class="fa fa-check" aria-hidden="true"></i> ';
  229. echo get_lang('Enable the selected plugins').'</button>';
  230. echo '</div>';
  231. echo '</form>';
  232. }
  233. /**
  234. * This function allows the platform admin to choose the default stylesheet.
  235. *
  236. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  237. * @author Julio Montoya <gugli100@gmail.com>, Chamilo
  238. */
  239. function handleStylesheets()
  240. {
  241. $is_style_changeable = isStyleChangeable();
  242. $allowedFileTypes = ['png'];
  243. $form = new FormValidator(
  244. 'stylesheet_upload',
  245. 'post',
  246. 'settings.php?category=Stylesheets#tabs-3'
  247. );
  248. $form->addElement(
  249. 'text',
  250. 'name_stylesheet',
  251. get_lang('Name of the stylesheet'),
  252. ['size' => '40', 'maxlength' => '40']
  253. );
  254. $form->addRule(
  255. 'name_stylesheet',
  256. get_lang('Required field'),
  257. 'required'
  258. );
  259. $form->addElement(
  260. 'file',
  261. 'new_stylesheet',
  262. get_lang('New stylesheet file')
  263. );
  264. $allowed_file_types = getAllowedFileTypes();
  265. $form->addRule(
  266. 'new_stylesheet',
  267. get_lang('Invalid extension').' ('.implode(',', $allowed_file_types).')',
  268. 'filetype',
  269. $allowed_file_types
  270. );
  271. $form->addRule(
  272. 'new_stylesheet',
  273. get_lang('Required field'),
  274. 'required'
  275. );
  276. $form->addButtonUpload(get_lang('Upload'), 'stylesheet_upload');
  277. $show_upload_form = false;
  278. $urlId = api_get_current_access_url_id();
  279. if (!is_writable(CSS_UPLOAD_PATH)) {
  280. echo Display::return_message(
  281. CSS_UPLOAD_PATH.get_lang('is not writeable'),
  282. 'error',
  283. false
  284. );
  285. } else {
  286. // Uploading a new stylesheet.
  287. if ($urlId == 1) {
  288. $show_upload_form = true;
  289. } else {
  290. if ($is_style_changeable) {
  291. $show_upload_form = true;
  292. }
  293. }
  294. }
  295. // Stylesheet upload.
  296. if (isset($_POST['stylesheet_upload'])) {
  297. if ($form->validate()) {
  298. $values = $form->exportValues();
  299. $picture_element = $form->getElement('new_stylesheet');
  300. $picture = $picture_element->getValue();
  301. $result = uploadStylesheet($values, $picture);
  302. // Add event to the system log.
  303. $user_id = api_get_user_id();
  304. $category = $_GET['category'];
  305. Event::addEvent(
  306. LOG_CONFIGURATION_SETTINGS_CHANGE,
  307. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  308. $category,
  309. api_get_utc_datetime(),
  310. $user_id
  311. );
  312. if ($result) {
  313. echo Display::return_message(get_lang('The stylesheet has been added'));
  314. }
  315. }
  316. }
  317. // Current style.
  318. $selected = $currentStyle = api_get_setting('stylesheets');
  319. $styleFromDatabase = api_get_settings_params_simple(
  320. ['variable = ? AND access_url = ?' => ['stylesheets', api_get_current_access_url_id()]]
  321. );
  322. if ($styleFromDatabase) {
  323. $selected = $currentStyle = $styleFromDatabase['selected_value'];
  324. }
  325. if (isset($_POST['preview'])) {
  326. $selected = $currentStyle = Security::remove_XSS($_POST['style']);
  327. }
  328. $themeDir = Template::getThemeDir($selected);
  329. $dir = api_get_path(SYS_PUBLIC_PATH).'css/'.$themeDir.'/images/';
  330. $url = api_get_path(WEB_CSS_PATH).'/'.$themeDir.'/images/';
  331. $logoFileName = 'header-logo.png';
  332. $newLogoFileName = 'header-logo-custom'.api_get_current_access_url_id().'.png';
  333. $webPlatformLogoPath = ChamiloApi::getPlatformLogoPath($selected);
  334. $logoForm = new FormValidator(
  335. 'logo_upload',
  336. 'post',
  337. 'settings.php?category=Stylesheets#tabs-2'
  338. );
  339. $logoForm->addHtml(
  340. Display::return_message(
  341. sprintf(
  342. get_lang('The logo must be of %s px in size and in %s format'),
  343. '250 x 70',
  344. 'PNG'
  345. ),
  346. 'info'
  347. )
  348. );
  349. if ($webPlatformLogoPath !== null) {
  350. $logoForm->addLabel(
  351. get_lang('Current logo'),
  352. '<img id="header-logo-custom" src="'.$webPlatformLogoPath.'?'.time().'">'
  353. );
  354. }
  355. $logoForm->addFile('new_logo', get_lang('Update logo'));
  356. if ($is_style_changeable) {
  357. $logoGroup = [
  358. $logoForm->addButtonUpload(get_lang('Upload'), 'logo_upload', true),
  359. $logoForm->addButtonCancel(get_lang('Reset'), 'logo_reset', true),
  360. ];
  361. $logoForm->addGroup($logoGroup);
  362. }
  363. if (isset($_POST['logo_reset'])) {
  364. if (is_file($dir.$newLogoFileName)) {
  365. unlink($dir.$newLogoFileName);
  366. echo Display::return_message(get_lang('Original logo recovered'));
  367. echo '<script>'
  368. .'$("#header-logo").attr("src","'.$url.$logoFileName.'");'
  369. .'</script>';
  370. }
  371. } elseif (isset($_POST['logo_upload'])) {
  372. $logoForm->addRule(
  373. 'new_logo',
  374. get_lang('Invalid extension').' ('.implode(',', $allowedFileTypes).')',
  375. 'filetype',
  376. $allowedFileTypes
  377. );
  378. $logoForm->addRule(
  379. 'new_logo',
  380. get_lang('Required field'),
  381. 'required'
  382. );
  383. if ($logoForm->validate()) {
  384. $imageInfo = getimagesize($_FILES['new_logo']['tmp_name']);
  385. $width = $imageInfo[0];
  386. $height = $imageInfo[1];
  387. if ($width <= 250 && $height <= 70) {
  388. if (is_file($dir.$newLogoFileName)) {
  389. unlink($dir.$newLogoFileName);
  390. }
  391. $status = move_uploaded_file(
  392. $_FILES['new_logo']['tmp_name'],
  393. $dir.$newLogoFileName
  394. );
  395. if ($status) {
  396. echo Display::return_message(get_lang('New logo uploaded'));
  397. echo '<script>'
  398. .'$("#header-logo").attr("src","'.$url.$newLogoFileName.'");'
  399. .'</script>';
  400. } else {
  401. echo Display::return_message('Error - '.get_lang('No file was uploaded.'), 'error');
  402. }
  403. } else {
  404. Display::return_message('Error - '.get_lang('Image dimensions do not match the requirements. Please check the suggestions next to the image field.'), 'error');
  405. }
  406. }
  407. }
  408. if (isset($_POST['download'])) {
  409. generateCSSDownloadLink($selected);
  410. }
  411. $form_change = new FormValidator(
  412. 'stylesheet_upload',
  413. 'post',
  414. api_get_self().'?category=Stylesheets',
  415. null,
  416. ['id' => 'stylesheets_id']
  417. );
  418. $styles = $form_change->addElement(
  419. 'selectTheme',
  420. 'style',
  421. get_lang('Name of the stylesheet')
  422. );
  423. $styles->setSelected($currentStyle);
  424. if ($is_style_changeable) {
  425. $group = [
  426. $form_change->addButtonSave(get_lang('Save settings'), 'save', true),
  427. $form_change->addButtonPreview(get_lang('Preview'), 'preview', true),
  428. $form_change->addButtonDownload(get_lang('Download'), 'download', true),
  429. ];
  430. $form_change->addGroup($group);
  431. if ($show_upload_form) {
  432. echo Display::tabs(
  433. [get_lang('Update'), get_lang('Update logo'), get_lang('New stylesheet file')],
  434. [$form_change->returnForm(), $logoForm->returnForm(), $form->returnForm()]
  435. );
  436. } else {
  437. $form_change->display();
  438. }
  439. // Little hack to update the logo image in update form when submiting
  440. if (isset($_POST['logo_reset'])) {
  441. echo '<script>'
  442. .'$("#header-logo-custom").attr("src","'.$url.$logoFileName.'");'
  443. .'</script>';
  444. } elseif (isset($_POST['logo_upload']) && is_file($dir.$newLogoFileName)) {
  445. echo '<script>'
  446. .'$("#header-logo-custom").attr("src","'.$url.$newLogoFileName.'");'
  447. .'</script>';
  448. }
  449. } else {
  450. $form_change->freeze();
  451. }
  452. }
  453. /**
  454. * Creates the folder (if needed) and uploads the stylesheet in it.
  455. *
  456. * @param array $values the values of the form
  457. * @param array $picture the values of the uploaded file
  458. *
  459. * @return bool
  460. *
  461. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  462. *
  463. * @version May 2008
  464. *
  465. * @since v1.8.5
  466. */
  467. function uploadStylesheet($values, $picture)
  468. {
  469. $result = false;
  470. // Valid name for the stylesheet folder.
  471. $style_name = api_preg_replace('/[^A-Za-z0-9]/', '', $values['name_stylesheet']);
  472. if (empty($style_name) || is_array($style_name)) {
  473. // The name of the uploaded stylesheet doesn't have the expected format
  474. return $result;
  475. }
  476. $cssToUpload = CSS_UPLOAD_PATH;
  477. // Check if a virtual instance vchamilo is used
  478. $virtualInstanceTheme = api_get_configuration_value('virtual_css_theme_folder');
  479. if (!empty($virtualInstanceTheme)) {
  480. $cssToUpload = $cssToUpload.$virtualInstanceTheme.'/';
  481. }
  482. // Create the folder if needed.
  483. if (!is_dir($cssToUpload.$style_name.'/')) {
  484. mkdir($cssToUpload.$style_name.'/', api_get_permissions_for_new_directories());
  485. }
  486. $info = pathinfo($picture['name']);
  487. if ($info['extension'] == 'zip') {
  488. // Try to open the file and extract it in the theme.
  489. $zip = new ZipArchive();
  490. if ($zip->open($picture['tmp_name'])) {
  491. // Make sure all files inside the zip are images or css.
  492. $num_files = $zip->numFiles;
  493. $valid = true;
  494. $single_directory = true;
  495. $invalid_files = [];
  496. $allowedFiles = getAllowedFileTypes();
  497. for ($i = 0; $i < $num_files; $i++) {
  498. $file = $zip->statIndex($i);
  499. if (substr($file['name'], -1) != '/') {
  500. $path_parts = pathinfo($file['name']);
  501. if (!in_array($path_parts['extension'], $allowedFiles)) {
  502. $valid = false;
  503. $invalid_files[] = $file['name'];
  504. }
  505. }
  506. if (strpos($file['name'], '/') === false) {
  507. $single_directory = false;
  508. }
  509. }
  510. if (!$valid) {
  511. $error_string = '<ul>';
  512. foreach ($invalid_files as $invalid_file) {
  513. $error_string .= '<li>'.$invalid_file.'</li>';
  514. }
  515. $error_string .= '</ul>';
  516. echo Display::return_message(
  517. get_lang('The only accepted extensions in the ZIP file are .jp(e)g, .png, .gif and .css.').$error_string,
  518. 'error',
  519. false
  520. );
  521. } else {
  522. // If the zip does not contain a single directory, extract it.
  523. if (!$single_directory) {
  524. // Extract zip file.
  525. $zip->extractTo($cssToUpload.$style_name.'/');
  526. $result = true;
  527. } else {
  528. $extraction_path = $cssToUpload.$style_name.'/';
  529. $mode = api_get_permissions_for_new_directories();
  530. for ($i = 0; $i < $num_files; $i++) {
  531. $entry = $zip->getNameIndex($i);
  532. if (substr($entry, -1) == '/') {
  533. continue;
  534. }
  535. $pos_slash = strpos($entry, '/');
  536. $entry_without_first_dir = substr($entry, $pos_slash + 1);
  537. // If there is still a slash, we need to make sure the directories are created.
  538. if (strpos($entry_without_first_dir, '/') !== false) {
  539. if (!is_dir($extraction_path.dirname($entry_without_first_dir))) {
  540. // Create it.
  541. @mkdir($extraction_path.dirname($entry_without_first_dir), $mode, true);
  542. }
  543. }
  544. $fp = $zip->getStream($entry);
  545. $ofp = fopen($extraction_path.dirname($entry_without_first_dir).'/'.basename($entry), 'w');
  546. while (!feof($fp)) {
  547. fwrite($ofp, fread($fp, 8192));
  548. }
  549. fclose($fp);
  550. fclose($ofp);
  551. }
  552. $result = true;
  553. }
  554. }
  555. $zip->close();
  556. } else {
  557. echo Display::return_message(get_lang('Error reading ZIP file').$info['extension'], 'error', false);
  558. }
  559. } else {
  560. // Simply move the file.
  561. move_uploaded_file($picture['tmp_name'], $cssToUpload.$style_name.'/'.$picture['name']);
  562. $result = true;
  563. }
  564. if ($result) {
  565. $fs = new Filesystem();
  566. $fs->mirror(
  567. CSS_UPLOAD_PATH,
  568. api_get_path(SYS_PATH).'web/css/themes/',
  569. null,
  570. ['override' => true]
  571. );
  572. }
  573. return $result;
  574. }
  575. /**
  576. * Store plugin regions.
  577. */
  578. function storeRegions()
  579. {
  580. $plugin_obj = new AppPlugin();
  581. // Get a list of all current 'Plugins' settings
  582. $installed_plugins = $plugin_obj->getInstalledPlugins();
  583. $shortlist_installed = [];
  584. if (!empty($installed_plugins)) {
  585. foreach ($installed_plugins as $plugin) {
  586. if (isset($plugin['subkey'])) {
  587. $shortlist_installed[] = $plugin['subkey'];
  588. }
  589. }
  590. }
  591. $plugin_list = $plugin_obj->read_plugins_from_path();
  592. foreach ($plugin_list as $plugin) {
  593. if (isset($_POST['plugin_'.$plugin])) {
  594. $areas_to_installed = $_POST['plugin_'.$plugin];
  595. if (!empty($areas_to_installed)) {
  596. $plugin_obj->removeAllRegions($plugin);
  597. foreach ($areas_to_installed as $region) {
  598. if (!empty($region) && $region != '-1') {
  599. $plugin_obj->add_to_region($plugin, $region);
  600. }
  601. }
  602. }
  603. }
  604. }
  605. }
  606. /**
  607. * This function allows easy activating and inactivating of plugins.
  608. *
  609. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  610. */
  611. function storePlugins()
  612. {
  613. $appPlugin = new AppPlugin();
  614. // Get a list of all current 'Plugins' settings
  615. $plugin_list = $appPlugin->read_plugins_from_path();
  616. $installed_plugins = [];
  617. foreach ($plugin_list as $plugin) {
  618. if (isset($_POST['plugin_'.$plugin])) {
  619. $appPlugin->install($plugin);
  620. $installed_plugins[] = $plugin;
  621. }
  622. }
  623. if (!empty($installed_plugins)) {
  624. $remove_plugins = array_diff($plugin_list, $installed_plugins);
  625. } else {
  626. $remove_plugins = $plugin_list;
  627. }
  628. foreach ($remove_plugins as $plugin) {
  629. $appPlugin->uninstall($plugin);
  630. }
  631. }
  632. /**
  633. * This function allows the platform admin to choose which should be the default stylesheet.
  634. *
  635. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  636. */
  637. function storeStylesheets()
  638. {
  639. // Insert the stylesheet.
  640. if (isStyle($_POST['style'])) {
  641. api_set_setting(
  642. 'stylesheets',
  643. $_POST['style'],
  644. null,
  645. 'stylesheets',
  646. api_get_current_access_url_id()
  647. );
  648. }
  649. return true;
  650. }
  651. /**
  652. * This function checks if the given style is a recognize style that exists in the css directory as
  653. * a standalone directory.
  654. *
  655. * @param string $style
  656. *
  657. * @return bool True if this style is recognized, false otherwise
  658. */
  659. function isStyle($style)
  660. {
  661. $themeList = api_get_themes();
  662. return in_array($style, array_keys($themeList));
  663. }
  664. /**
  665. * Search options
  666. * TODO: support for multiple site. aka $_configuration['access_url'] == 1.
  667. *
  668. * @author Marco Villegas <marvil07@gmail.com>
  669. */
  670. function handleSearch()
  671. {
  672. global $SettingsStored, $_configuration;
  673. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  674. $search_enabled = api_get_setting('search_enabled');
  675. $form = new FormValidator(
  676. 'search-options',
  677. 'post',
  678. api_get_self().'?category=Search'
  679. );
  680. $values = api_get_settings_options('search_enabled');
  681. $form->addElement('header', null, get_lang('Fulltext search'));
  682. $group = formGenerateElementsGroup($form, $values, 'search_enabled');
  683. // SearchEnabledComment
  684. $form->addGroup(
  685. $group,
  686. 'search_enabled',
  687. [get_lang('Fulltext search'), get_lang('This feature allows you to index most of the documents uploaded to your portal, then provide a search feature for users.<br />This feature will not index documents that have already been uploaded, so it is important to enable (if wanted) at the beginning of your implementation.<br />Once enabled, a search box will appear in the courses list of every user. Searching for a specific term will bring a list of corresponding documents, exercises or forum topics, filtered depending on the availability of these contents to the user.')],
  688. null,
  689. false
  690. );
  691. $search_enabled = api_get_setting('search_enabled');
  692. if ($form->validate()) {
  693. $formValues = $form->exportValues();
  694. setConfigurationSettingsInDatabase($formValues, $_configuration['access_url']);
  695. $search_enabled = $formValues['search_enabled'];
  696. echo Display::return_message($SettingsStored, 'confirm');
  697. }
  698. $specific_fields = get_specific_field_list();
  699. if ($search_enabled == 'true') {
  700. $values = api_get_settings_options('search_show_unlinked_results');
  701. $group = formGenerateElementsGroup(
  702. $form,
  703. $values,
  704. 'search_show_unlinked_results'
  705. );
  706. $form->addGroup(
  707. $group,
  708. 'search_show_unlinked_results',
  709. [
  710. get_lang('Full-text search: show unlinked results'),
  711. get_lang('When showing the results of a full-text search, what should be done with the results that are not accessible to the current user?'),
  712. ],
  713. null,
  714. false
  715. );
  716. $default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results');
  717. $sf_values = [];
  718. foreach ($specific_fields as $sf) {
  719. $sf_values[$sf['code']] = $sf['name'];
  720. }
  721. $url = Display::div(
  722. Display::url(
  723. get_lang('Add a specific search field'),
  724. 'specific_fields.php'
  725. ),
  726. ['class' => 'sectioncomment']
  727. );
  728. if (empty($sf_values)) {
  729. $form->addElement('label', [get_lang('Specific Field for prefilter'), $url]);
  730. } else {
  731. $form->addElement(
  732. 'select',
  733. 'search_prefilter_prefix',
  734. [get_lang('Specific Field for prefilter'), $url],
  735. $sf_values,
  736. ''
  737. );
  738. $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
  739. }
  740. }
  741. $default_values['search_enabled'] = $search_enabled;
  742. $form->addButtonSave(get_lang('Save'));
  743. $form->setDefaults($default_values);
  744. echo '<div id="search-options-form">';
  745. $form->display();
  746. echo '</div>';
  747. if ($search_enabled == 'true') {
  748. $xapianPath = api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/searchdb';
  749. /*
  750. @todo Test the Xapian connection
  751. if (extension_loaded('xapian')) {
  752. require_once 'xapian.php';
  753. try {
  754. $db = new XapianDatabase($xapianPath.'/');
  755. } catch (Exception $e) {
  756. var_dump($e->getMessage());
  757. }
  758. require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
  759. require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php';
  760. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  761. $indexable = new IndexableChunk();
  762. $indexable->addValue("content", 'Test');
  763. $di = new ChamiloIndexer();
  764. $di->connectDb(NULL, NULL, 'english');
  765. $di->addChunk($indexable);
  766. $did = $di->index();
  767. }
  768. */
  769. $xapianLoaded = Display::return_icon('bullet_green.png', get_lang('Validate'));
  770. $dir_exists = Display::return_icon('bullet_green.png', get_lang('Validate'));
  771. $dir_is_writable = Display::return_icon('bullet_green.png', get_lang('Validate'));
  772. $specific_fields_exists = Display::return_icon('bullet_green.png', get_lang('Validate'));
  773. //Testing specific fields
  774. if (empty($specific_fields)) {
  775. $specific_fields_exists = Display::return_icon(
  776. 'bullet_red.png',
  777. get_lang('Add a specific search field')
  778. );
  779. }
  780. //Testing xapian extension
  781. if (!extension_loaded('xapian')) {
  782. $xapianLoaded = Display::return_icon('bullet_red.png', get_lang('Error'));
  783. }
  784. //Testing xapian searchdb path
  785. if (!is_dir($xapianPath)) {
  786. $dir_exists = Display::return_icon('bullet_red.png', get_lang('Error'));
  787. }
  788. //Testing xapian searchdb path is writable
  789. if (!is_writable($xapianPath)) {
  790. $dir_is_writable = Display::return_icon('bullet_red.png', get_lang('Error'));
  791. }
  792. $data = [];
  793. $data[] = [get_lang('Xapian module installed'), $xapianLoaded];
  794. $data[] = [get_lang('The directory exists').' - '.$xapianPath, $dir_exists];
  795. $data[] = [get_lang('Is writable').' - '.$xapianPath, $dir_is_writable];
  796. $data[] = [get_lang('Available custom search fields'), $specific_fields_exists];
  797. showSearchSettingsTable($data);
  798. showSearchToolsStatusTable();
  799. }
  800. }
  801. /**
  802. * Wrapper for the templates.
  803. *
  804. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  805. * @author Julio Montoya.
  806. *
  807. * @version August 2008
  808. *
  809. * @since v1.8.6
  810. */
  811. function handleTemplates()
  812. {
  813. /* Drive-by fix to avoid undefined var warnings, without repeating
  814. * isset() combos all over the place. */
  815. $action = isset($_GET['action']) ? $_GET['action'] : "invalid";
  816. if ($action != 'add') {
  817. echo '<div class="actions" style="margin-left: 1px;">';
  818. echo '<a href="settings.php?category=Templates&action=add">'.
  819. Display::return_icon('new_template.png', get_lang('Add a template'), '', ICON_SIZE_MEDIUM).'</a>';
  820. echo '</div>';
  821. }
  822. if ($action == 'add' || ($action == 'edit' && is_numeric($_GET['id']))) {
  823. addEditTemplate();
  824. // Add event to the system log.
  825. $user_id = api_get_user_id();
  826. $category = $_GET['category'];
  827. Event::addEvent(
  828. LOG_CONFIGURATION_SETTINGS_CHANGE,
  829. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  830. $category,
  831. api_get_utc_datetime(),
  832. $user_id
  833. );
  834. } else {
  835. if ($action == 'delete' && is_numeric($_GET['id'])) {
  836. deleteTemplate($_GET['id']);
  837. // Add event to the system log
  838. $user_id = api_get_user_id();
  839. $category = $_GET['category'];
  840. Event::addEvent(
  841. LOG_CONFIGURATION_SETTINGS_CHANGE,
  842. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  843. $category,
  844. api_get_utc_datetime(),
  845. $user_id
  846. );
  847. }
  848. displayTemplates();
  849. }
  850. }
  851. /**
  852. * Display a sortable table with all the templates that the platform administrator has defined.
  853. *
  854. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  855. *
  856. * @version August 2008
  857. *
  858. * @since v1.8.6
  859. */
  860. function displayTemplates()
  861. {
  862. $table = new SortableTable(
  863. 'templates',
  864. 'getNumberOfTemplates',
  865. 'getTemplateData',
  866. 1
  867. );
  868. $table->set_additional_parameters(
  869. ['category' => Security::remove_XSS($_GET['category'])]
  870. );
  871. $table->set_header(0, get_lang('Image'), true, ['style' => 'width: 101px;']);
  872. $table->set_header(1, get_lang('Title'));
  873. $table->set_header(2, get_lang('Detail'), false, ['style' => 'width:50px;']);
  874. $table->set_column_filter(2, 'actionsFilter');
  875. $table->set_column_filter(0, 'searchImageFilter');
  876. $table->display();
  877. }
  878. /**
  879. * Gets the number of templates that are defined by the platform admin.
  880. *
  881. * @return int
  882. *
  883. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  884. *
  885. * @version August 2008
  886. *
  887. * @since v1.8.6
  888. */
  889. function getNumberOfTemplates()
  890. {
  891. // Database table definition.
  892. $table = Database::get_main_table('system_template');
  893. // The sql statement.
  894. $sql = "SELECT COUNT(id) AS total FROM $table";
  895. $result = Database::query($sql);
  896. $row = Database::fetch_array($result);
  897. // Returning the number of templates.
  898. return $row['total'];
  899. }
  900. /**
  901. * Gets all the template data for the sortable table.
  902. *
  903. * @param int $from the start of the limit statement
  904. * @param int $number_of_items the number of elements that have to be retrieved from the database
  905. * @param int $column the column that is
  906. * @param string $direction the sorting direction (ASC or DESC)
  907. *
  908. * @return array
  909. *
  910. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  911. *
  912. * @version August 2008
  913. *
  914. * @since v1.8.6
  915. */
  916. function getTemplateData($from, $number_of_items, $column, $direction)
  917. {
  918. // Database table definition.
  919. $table_system_template = Database::get_main_table('system_template');
  920. // The sql statement.
  921. $sql = "SELECT image as col0, title as col1, id as col2 FROM $table_system_template";
  922. $sql .= " ORDER BY col$column $direction ";
  923. $sql .= " LIMIT $from,$number_of_items";
  924. $result = Database::query($sql);
  925. $return = [];
  926. while ($row = Database::fetch_array($result)) {
  927. $row['1'] = get_lang($row['1']);
  928. $return[] = $row;
  929. }
  930. // Returning all the information for the sortable table.
  931. return $return;
  932. }
  933. /**
  934. * display the edit and delete icons in the sortable table.
  935. *
  936. * @param int $id the id of the template
  937. *
  938. * @return string code for the link to edit and delete the template
  939. *
  940. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  941. *
  942. * @version August 2008
  943. *
  944. * @since v1.8.6
  945. */
  946. function actionsFilter($id)
  947. {
  948. $return = '<a href="settings.php?category=Templates&action=edit&id='.Security::remove_XSS($id).'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
  949. $return .= '<a href="settings.php?category=Templates&action=delete&id='.Security::remove_XSS($id).'" onClick="javascript:if(!confirm('."'".get_lang('Please confirm your choice')."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  950. return $return;
  951. }
  952. /**
  953. * Display the image of the template in the sortable table.
  954. *
  955. * @param string $image the image
  956. *
  957. * @return string code for the image
  958. *
  959. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  960. *
  961. * @version August 2008
  962. *
  963. * @since v1.8.6
  964. */
  965. function searchImageFilter($image)
  966. {
  967. if (!empty($image)) {
  968. return '<img src="'.api_get_path(WEB_PUBLIC_PATH).'img/template_thumb/'.$image.'" alt="'.get_lang('Template preview').'"/>';
  969. } else {
  970. return '<img src="'.api_get_path(WEB_PUBLIC_PATH).'img/template_thumb/noimage.gif" alt="'.get_lang('NoTemplate preview').'"/>';
  971. }
  972. }
  973. /**
  974. * Add (or edit) a template. This function displays the form and also takes
  975. * care of uploading the image and storing the information in the database.
  976. *
  977. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  978. *
  979. * @version August 2008
  980. *
  981. * @since v1.8.6
  982. */
  983. function addEditTemplate()
  984. {
  985. $em = Database::getManager();
  986. $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
  987. /** @var SystemTemplate $template */
  988. $template = $id ? $em->find('ChamiloCoreBundle:SystemTemplate', $id) : new SystemTemplate();
  989. $form = new FormValidator(
  990. 'template',
  991. 'post',
  992. 'settings.php?category=Templates&action='.Security::remove_XSS($_GET['action']).'&id='.$id
  993. );
  994. // Setting the form elements: the header.
  995. if ($_GET['action'] == 'add') {
  996. $title = get_lang('Add a template');
  997. } else {
  998. $title = get_lang('Template edition');
  999. }
  1000. $form->addElement('header', '', $title);
  1001. // Setting the form elements: the title of the template.
  1002. $form->addText('title', get_lang('Title'), false);
  1003. $form->addText('comment', get_lang('Description'), false);
  1004. // Setting the form elements: the content of the template (wysiwyg editor).
  1005. $form->addHtmlEditor(
  1006. 'template_text',
  1007. get_lang('Text'),
  1008. true,
  1009. true,
  1010. ['ToolbarSet' => 'Documents', 'Width' => '100%', 'Height' => '400']
  1011. );
  1012. // Setting the form elements: the form to upload an image to be used with the template.
  1013. if (empty($template->getImage())) {
  1014. $form->addElement('file', 'template_image', get_lang('Image'), '');
  1015. }
  1016. // Setting the form elements: a little bit information about the template image.
  1017. $form->addElement('static', 'file_comment', '', get_lang('This image will represent the template in the templates list. It should be no larger than 100x70 pixels'));
  1018. // Getting all the information of the template when editing a template.
  1019. if ($_GET['action'] == 'edit') {
  1020. $defaults['template_id'] = $id;
  1021. $defaults['template_text'] = $template->getContent();
  1022. // Forcing get_lang().
  1023. $defaults['title'] = $template->getTitle();
  1024. $defaults['comment'] = $template->getComment();
  1025. // Adding an extra field: a hidden field with the id of the template we are editing.
  1026. $form->addElement('hidden', 'template_id');
  1027. // Adding an extra field: a preview of the image that is currently used.
  1028. if (!empty($template->getImage())) {
  1029. $form->addElement(
  1030. 'static',
  1031. 'template_image_preview',
  1032. '',
  1033. '<img src="'.api_get_path(WEB_PUBLIC_PATH).'img/template_thumb/'.$template->getImage()
  1034. .'" alt="'.get_lang('Template preview')
  1035. .'"/>'
  1036. );
  1037. $form->addCheckBox('delete_image', null, get_lang('Delete picture'));
  1038. } else {
  1039. $form->addElement(
  1040. 'static',
  1041. 'template_image_preview',
  1042. '',
  1043. '<img src="'.api_get_path(WEB_PUBLIC_PATH).'img/template_thumb/noimage.gif" alt="'.get_lang('NoTemplate preview').'"/>'
  1044. );
  1045. }
  1046. // Setting the information of the template that we are editing.
  1047. $form->setDefaults($defaults);
  1048. }
  1049. // Setting the form elements: the submit button.
  1050. $form->addButtonSave(get_lang('Validate'), 'submit');
  1051. // Setting the rules: the required fields.
  1052. if (empty($template->getImage())) {
  1053. $form->addRule(
  1054. 'template_image',
  1055. get_lang('Required field'),
  1056. 'required'
  1057. );
  1058. $form->addRule('title', get_lang('Required field'), 'required');
  1059. }
  1060. // if the form validates (complies to all rules) we save the information,
  1061. // else we display the form again (with error message if needed)
  1062. if ($form->validate()) {
  1063. $check = Security::check_token('post');
  1064. if ($check) {
  1065. // Exporting the values.
  1066. $values = $form->exportValues();
  1067. $isDelete = null;
  1068. if (isset($values['delete_image'])) {
  1069. $isDelete = $values['delete_image'];
  1070. }
  1071. // Upload the file.
  1072. if (!empty($_FILES['template_image']['name'])) {
  1073. $upload_ok = process_uploaded_file($_FILES['template_image']);
  1074. if ($upload_ok) {
  1075. // Try to add an extension to the file if it hasn't one.
  1076. $new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
  1077. // The upload directory.
  1078. // todo
  1079. $upload_dir = api_get_path(SYS_PATH).'home/default_platform_document/template_thumb/';
  1080. // Create the directory if it does not exist.
  1081. if (!is_dir($upload_dir)) {
  1082. mkdir($upload_dir, api_get_permissions_for_new_directories());
  1083. }
  1084. // Resize the preview image to max default and upload.
  1085. $temp = new Image($_FILES['template_image']['tmp_name']);
  1086. $picture_info = $temp->get_image_info();
  1087. $max_width_for_picture = 100;
  1088. if ($picture_info['width'] > $max_width_for_picture) {
  1089. $temp->resize($max_width_for_picture);
  1090. }
  1091. $temp->send_image($upload_dir.$new_file_name);
  1092. }
  1093. }
  1094. // Store the information in the database (as insert or as update).
  1095. $bootstrap = api_get_bootstrap_and_font_awesome();
  1096. $viewport = '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
  1097. if ($_GET['action'] == 'add') {
  1098. $templateContent = '<head>'.$viewport.'<title>'.$values['title'].'</title>'.$bootstrap.'</head>'
  1099. .$values['template_text'];
  1100. $template
  1101. ->setTitle($values['title'])
  1102. ->setComment(Security::remove_XSS($values['comment']))
  1103. ->setContent(Security::remove_XSS($templateContent, COURSEMANAGERLOWSECURITY))
  1104. ->setImage($new_file_name);
  1105. $em->persist($template);
  1106. $em->flush();
  1107. // Display a feedback message.
  1108. echo Display::return_message(
  1109. get_lang('Template added'),
  1110. 'confirm'
  1111. );
  1112. echo '<a href="settings.php?category=Templates&action=add">'.
  1113. Display::return_icon('new_template.png', get_lang('Add a template'), '', ICON_SIZE_MEDIUM).
  1114. '</a>';
  1115. } else {
  1116. $templateContent = '<head>'.$viewport.'<title>'.$values['title'].'</title>'.$bootstrap.'</head>'
  1117. .$values['template_text'];
  1118. $template
  1119. ->setTitle($values['title'])
  1120. ->setContent(Security::remove_XSS($templateContent, COURSEMANAGERLOWSECURITY));
  1121. if (!empty($new_file_name)) {
  1122. $template->setImage($new_file_name);
  1123. }
  1124. $em->persist($template);
  1125. $em->flush();
  1126. // Display a feedback message.
  1127. echo Display::return_message(get_lang('Template edited'), 'confirm');
  1128. }
  1129. }
  1130. Security::clear_token();
  1131. displayTemplates();
  1132. } else {
  1133. $token = Security::get_token();
  1134. $form->addElement('hidden', 'sec_token');
  1135. $form->setConstants(['sec_token' => $token]);
  1136. // Display the form.
  1137. $form->display();
  1138. }
  1139. }
  1140. /**
  1141. * Delete a template.
  1142. *
  1143. * @param int $id the id of the template that has to be deleted
  1144. *
  1145. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1146. *
  1147. * @version August 2008
  1148. *
  1149. * @since v1.8.6
  1150. */
  1151. function deleteTemplate($id)
  1152. {
  1153. $id = intval($id);
  1154. // First we remove the image.
  1155. $table = Database::get_main_table('system_template');
  1156. $sql = "SELECT * FROM $table WHERE id = $id";
  1157. $result = Database::query($sql);
  1158. $row = Database::fetch_array($result);
  1159. if (!empty($row['image'])) {
  1160. @unlink(api_get_path(SYS_APP_PATH).'home/default_platform_document/template_thumb/'.$row['image']);
  1161. }
  1162. // Now we remove it from the database.
  1163. $sql = "DELETE FROM $table WHERE id = $id";
  1164. Database::query($sql);
  1165. // Display a feedback message.
  1166. echo Display::return_message(get_lang('Template deleted'), 'confirm');
  1167. }
  1168. /**
  1169. * Returns the list of timezone identifiers used to populate the select
  1170. * This function is called through a call_user_func() in the generate_settings_form function.
  1171. *
  1172. * @return array List of timezone identifiers
  1173. *
  1174. * @author Guillaume Viguier <guillaume.viguier@beeznest.com>
  1175. *
  1176. * @since Chamilo 1.8.7
  1177. */
  1178. function select_timezone_value()
  1179. {
  1180. return api_get_timezones();
  1181. }
  1182. /**
  1183. * Returns an array containing the list of options used to populate the gradebook_number_decimals variable
  1184. * This function is called through a call_user_func() in the generate_settings_form function.
  1185. *
  1186. * @return array List of gradebook_number_decimals options
  1187. *
  1188. * @author Guillaume Viguier <guillaume.viguier@beeznest.com>
  1189. */
  1190. function select_gradebook_number_decimals()
  1191. {
  1192. return ['0', '1', '2'];
  1193. }
  1194. /**
  1195. * Get the options for a select element to select gradebook default grade model.
  1196. *
  1197. * @return array
  1198. */
  1199. function select_gradebook_default_grade_model_id()
  1200. {
  1201. $grade_model = new GradeModel();
  1202. $models = $grade_model->get_all();
  1203. $options = [];
  1204. $options[-1] = get_lang('none');
  1205. if (!empty($models)) {
  1206. foreach ($models as $model) {
  1207. $options[$model['id']] = $model['name'];
  1208. }
  1209. }
  1210. return $options;
  1211. }
  1212. /**
  1213. * @param array $settings
  1214. * @param array $settings_by_access_list
  1215. *
  1216. * @throws \Doctrine\ORM\ORMException
  1217. * @throws \Doctrine\ORM\OptimisticLockException
  1218. * @throws \Doctrine\ORM\TransactionRequiredException
  1219. *
  1220. * @return FormValidator
  1221. */
  1222. function generateSettingsForm($settings, $settings_by_access_list)
  1223. {
  1224. global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list;
  1225. $em = Database::getManager();
  1226. $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1227. $form = new FormValidator(
  1228. 'settings',
  1229. 'post',
  1230. 'settings.php?category='.Security::remove_XSS($_GET['category'])
  1231. );
  1232. $form->addElement(
  1233. 'hidden',
  1234. 'search_field',
  1235. (!empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null)
  1236. );
  1237. $url_id = api_get_current_access_url_id();
  1238. /*
  1239. if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) {
  1240. $group = array();
  1241. $group[] = $form->createElement('button', 'mark_all', get_lang('Select all'));
  1242. $group[] = $form->createElement('button', 'unmark_all', get_lang('Unselect all'));
  1243. $form->addGroup($group, 'buttons_in_action_right');
  1244. }*/
  1245. $default_values = [];
  1246. $url_info = api_get_access_url($url_id);
  1247. $i = 0;
  1248. $addedSettings = [];
  1249. foreach ($settings as $row) {
  1250. if (in_array($row['variable'], array_keys($settings_to_avoid))) {
  1251. continue;
  1252. }
  1253. if (in_array($row['variable'], $addedSettings)) {
  1254. continue;
  1255. }
  1256. $addedSettings[] = $row['variable'];
  1257. if (!empty($_configuration['multiple_access_urls'])) {
  1258. if (api_is_global_platform_admin()) {
  1259. if ($row['access_url_locked'] == 0) {
  1260. if ($url_id == 1) {
  1261. if ($row['access_url_changeable'] == '1') {
  1262. $form->addElement(
  1263. 'html',
  1264. '<div class="float-right"><a class="share_this_setting" data_status = "0" data_to_send = "'.$row['variable'].'" href="javascript:void(0);">'.
  1265. Display::return_icon('shared_setting.png', get_lang('Change setting visibility for the other portals'), null, ICON_SIZE_MEDIUM).'</a></div>'
  1266. );
  1267. } else {
  1268. $form->addElement(
  1269. 'html',
  1270. '<div class="float-right"><a class="share_this_setting" data_status = "1" data_to_send = "'.$row['variable'].'" href="javascript:void(0);">'.
  1271. Display::return_icon('shared_setting_na.png', get_lang('Change setting visibility for the other portals'), null, ICON_SIZE_MEDIUM).'</a></div>'
  1272. );
  1273. }
  1274. } else {
  1275. if ($row['access_url_changeable'] == '1') {
  1276. $form->addElement(
  1277. 'html',
  1278. '<div class="float-right">'.
  1279. Display::return_icon('shared_setting.png', get_lang('Change setting visibility for the other portals'), null, ICON_SIZE_MEDIUM).'</div>'
  1280. );
  1281. } else {
  1282. $form->addElement(
  1283. 'html',
  1284. '<div class="float-right">'.
  1285. Display::return_icon('shared_setting_na.png', get_lang('Change setting visibility for the other portals'), null, ICON_SIZE_MEDIUM).'</div>'
  1286. );
  1287. }
  1288. }
  1289. }
  1290. }
  1291. }
  1292. $hideme = [];
  1293. $hide_element = false;
  1294. if ($_configuration['access_url'] != 1) {
  1295. if ($row['access_url_changeable'] == 0) {
  1296. // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element.
  1297. $hide_element = true;
  1298. $hideme = ['disabled'];
  1299. } elseif ($url_info['active'] == 1) {
  1300. // We show the elements.
  1301. if (empty($row['variable'])) {
  1302. $row['variable'] = 0;
  1303. }
  1304. if (empty($row['subkey'])) {
  1305. $row['subkey'] = 0;
  1306. }
  1307. if (empty($row['category'])) {
  1308. $row['category'] = 0;
  1309. }
  1310. if (isset($settings_by_access_list[$row['variable']]) &&
  1311. isset($settings_by_access_list[$row['variable']][$row['subkey']]) &&
  1312. is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])
  1313. ) {
  1314. // We are sure that the other site have a selected value.
  1315. if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') {
  1316. $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'];
  1317. }
  1318. }
  1319. // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site.
  1320. }
  1321. }
  1322. switch ($row['type']) {
  1323. case 'textfield':
  1324. if (in_array($row['variable'], $convert_byte_to_mega_list)) {
  1325. $form->addElement(
  1326. 'text',
  1327. $row['variable'],
  1328. [
  1329. get_lang($row['title']),
  1330. get_lang($row['comment']),
  1331. get_lang('MB'),
  1332. ],
  1333. ['maxlength' => '8', 'aria-label' => get_lang($row['title'])]
  1334. );
  1335. $form->applyFilter($row['variable'], 'html_filter');
  1336. $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1);
  1337. } elseif ($row['variable'] == 'account_valid_duration') {
  1338. $form->addElement(
  1339. 'text',
  1340. $row['variable'],
  1341. [
  1342. get_lang($row['title']),
  1343. get_lang($row['comment']),
  1344. ],
  1345. ['maxlength' => '5', 'aria-label' => get_lang($row['title'])]
  1346. );
  1347. $form->applyFilter($row['variable'], 'html_filter');
  1348. // For platform character set selection:
  1349. // Conversion of the textfield to a select box with valid values.
  1350. $default_values[$row['variable']] = $row['selected_value'];
  1351. } elseif ($row['variable'] == 'platform_charset') {
  1352. break;
  1353. } else {
  1354. $hideme['class'] = 'col-md-4';
  1355. $hideme['aria-label'] = get_lang($row['title']);
  1356. $form->addElement(
  1357. 'text',
  1358. $row['variable'],
  1359. [
  1360. get_lang($row['title']),
  1361. get_lang($row['comment']),
  1362. ],
  1363. $hideme
  1364. );
  1365. $form->applyFilter($row['variable'], 'html_filter');
  1366. $default_values[$row['variable']] = $row['selected_value'];
  1367. }
  1368. break;
  1369. case 'textarea':
  1370. if ($row['variable'] == 'header_extra_content') {
  1371. $file = api_get_home_path().'header_extra_content.txt';
  1372. $value = '';
  1373. if (file_exists($file)) {
  1374. $value = file_get_contents($file);
  1375. }
  1376. $form->addElement(
  1377. 'textarea',
  1378. $row['variable'],
  1379. [get_lang($row['title']), get_lang($row['comment'])],
  1380. ['rows' => '10', 'id' => $row['variable']],
  1381. $hideme
  1382. );
  1383. $default_values[$row['variable']] = $value;
  1384. } elseif ($row['variable'] == 'footer_extra_content') {
  1385. $file = api_get_home_path().'footer_extra_content.txt';
  1386. $value = '';
  1387. if (file_exists($file)) {
  1388. $value = file_get_contents($file);
  1389. }
  1390. $form->addElement(
  1391. 'textarea',
  1392. $row['variable'],
  1393. [get_lang($row['title']), get_lang($row['comment'])],
  1394. ['rows' => '10', 'id' => $row['variable']],
  1395. $hideme
  1396. );
  1397. $default_values[$row['variable']] = $value;
  1398. } else {
  1399. $form->addElement(
  1400. 'textarea',
  1401. $row['variable'],
  1402. [get_lang($row['title']),
  1403. get_lang($row['comment']), ],
  1404. ['rows' => '10', 'id' => $row['variable']],
  1405. $hideme
  1406. );
  1407. $default_values[$row['variable']] = $row['selected_value'];
  1408. }
  1409. break;
  1410. case 'radio':
  1411. $values = api_get_settings_options($row['variable']);
  1412. $group = [];
  1413. if (is_array($values)) {
  1414. foreach ($values as $key => $value) {
  1415. $element = &$form->createElement(
  1416. 'radio',
  1417. $row['variable'],
  1418. '',
  1419. get_lang($value['display_text']),
  1420. $value['value']
  1421. );
  1422. if ($hide_element) {
  1423. $element->freeze();
  1424. }
  1425. $group[] = $element;
  1426. }
  1427. }
  1428. $form->addGroup(
  1429. $group,
  1430. $row['variable'],
  1431. [get_lang($row['title']), get_lang($row['comment'])],
  1432. null,
  1433. false
  1434. );
  1435. $default_values[$row['variable']] = $row['selected_value'];
  1436. break;
  1437. case 'checkbox':
  1438. // 1. We collect all the options of this variable.
  1439. $sql = "SELECT * FROM $table_settings_current
  1440. WHERE variable='".$row['variable']."' AND access_url = 1";
  1441. $result = Database::query($sql);
  1442. $group = [];
  1443. while ($rowkeys = Database::fetch_array($result)) {
  1444. // Profile tab option should be hidden when the social tool is enabled.
  1445. if (api_get_setting('allow_social_tool') == 'true') {
  1446. if ($rowkeys['variable'] === 'show_tabs' && $rowkeys['subkey'] === 'my_profile') {
  1447. continue;
  1448. }
  1449. }
  1450. // Hiding the gradebook option.
  1451. if ($rowkeys['variable'] === 'show_tabs' && $rowkeys['subkey'] === 'my_gradebook') {
  1452. continue;
  1453. }
  1454. $element = &$form->createElement(
  1455. 'checkbox',
  1456. $rowkeys['subkey'],
  1457. '',
  1458. get_lang($rowkeys['subkeytext'])
  1459. );
  1460. if ($row['access_url_changeable'] == 1) {
  1461. // 2. We look into the DB if there is a setting for a specific access_url.
  1462. $access_url = $_configuration['access_url'];
  1463. if (empty($access_url)) {
  1464. $access_url = 1;
  1465. }
  1466. $sql = "SELECT selected_value FROM $table_settings_current
  1467. WHERE
  1468. variable='".$rowkeys['variable']."' AND
  1469. subkey='".$rowkeys['subkey']."' AND
  1470. subkeytext='".$rowkeys['subkeytext']."' AND
  1471. access_url = $access_url";
  1472. $result_access = Database::query($sql);
  1473. $row_access = Database::fetch_array($result_access);
  1474. if ($row_access['selected_value'] === 'true' && !$form->isSubmitted()) {
  1475. $element->setChecked(true);
  1476. }
  1477. } else {
  1478. if ($rowkeys['selected_value'] === 'true' && !$form->isSubmitted()) {
  1479. $element->setChecked(true);
  1480. }
  1481. }
  1482. if ($hide_element) {
  1483. $element->freeze();
  1484. }
  1485. $group[] = $element;
  1486. }
  1487. $form->addGroup(
  1488. $group,
  1489. $row['variable'],
  1490. [get_lang($row['title']), get_lang($row['comment'])],
  1491. null
  1492. );
  1493. break;
  1494. case 'link':
  1495. $form->addElement(
  1496. 'static',
  1497. null,
  1498. [get_lang($row['title']), get_lang($row['comment'])],
  1499. get_lang('current value').' : '.$row['selected_value'],
  1500. $hideme
  1501. );
  1502. break;
  1503. case 'select':
  1504. /*
  1505. * To populate the list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed.
  1506. * The functions being called must be added to the file settings.lib.php.
  1507. */
  1508. $form->addElement(
  1509. 'select',
  1510. $row['variable'],
  1511. [get_lang($row['title']), get_lang($row['comment'])],
  1512. call_user_func('select_'.$row['variable']),
  1513. $hideme
  1514. );
  1515. $default_values[$row['variable']] = $row['selected_value'];
  1516. break;
  1517. case 'custom':
  1518. break;
  1519. case 'select_course':
  1520. $courseSelectOptions = [];
  1521. if (!empty($row['selected_value'])) {
  1522. $course = $em->find('ChamiloCoreBundle:Course', $row['selected_value']);
  1523. $courseSelectOptions[$course->getId()] = $course->getTitle();
  1524. }
  1525. $form->addElement(
  1526. 'select_ajax',
  1527. $row['variable'],
  1528. [get_lang($row['title']), get_lang($row['comment'])],
  1529. $courseSelectOptions,
  1530. ['url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course']
  1531. );
  1532. $default_values[$row['variable']] = $row['selected_value'];
  1533. break;
  1534. }
  1535. switch ($row['variable']) {
  1536. case 'pdf_export_watermark_enable':
  1537. $url = PDF::get_watermark(null);
  1538. if ($url != false) {
  1539. $delete_url = '<a href="?delete_watermark">'.get_lang('Remove picture').' '.Display::return_icon('delete.png', get_lang('Remove picture')).'</a>';
  1540. $form->addElement('html', '<div style="max-height:100px; max-width:100px; margin-left:162px; margin-bottom:10px; clear:both;"><img src="'.$url.'" style="margin-bottom:10px;" />'.$delete_url.'</div>');
  1541. }
  1542. $form->addElement('file', 'pdf_export_watermark_path', get_lang('Upload a watermark image'));
  1543. $allowed_picture_types = ['jpg', 'jpeg', 'png', 'gif'];
  1544. $form->addRule(
  1545. 'pdf_export_watermark_path',
  1546. get_lang('Only PNG, JPG or GIF images allowed').' ('.implode(',', $allowed_picture_types).')',
  1547. 'filetype',
  1548. $allowed_picture_types
  1549. );
  1550. break;
  1551. case 'timezone_value':
  1552. $timezone = $row['selected_value'];
  1553. if (empty($timezone)) {
  1554. $timezone = api_get_timezone();
  1555. }
  1556. $form->addLabel('', sprintf(get_lang('The local time in the portal timezone (%s) is %s'), $timezone, api_get_local_time()));
  1557. break;
  1558. }
  1559. } // end for
  1560. if (!empty($settings)) {
  1561. $form->setDefaults($default_values);
  1562. }
  1563. $form->addHtml('<div class="bottom_actions">');
  1564. $form->addButtonSave(get_lang('Save settings'));
  1565. $form->addHtml('</div>');
  1566. return $form;
  1567. }
  1568. /**
  1569. * Searches a platform setting in all categories except from the Plugins category.
  1570. *
  1571. * @param string $search
  1572. *
  1573. * @return array
  1574. */
  1575. function searchSetting($search)
  1576. {
  1577. if (empty($search)) {
  1578. return [];
  1579. }
  1580. $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1581. $sql = "SELECT * FROM $table_settings_current
  1582. WHERE category <> 'Plugins' ORDER BY id ASC ";
  1583. $result = Database::store_result(Database::query($sql), 'ASSOC');
  1584. $settings = [];
  1585. $search = api_strtolower($search);
  1586. if (!empty($result)) {
  1587. foreach ($result as $setting) {
  1588. $found = false;
  1589. $title = api_strtolower(get_lang($setting['title']));
  1590. // try the title
  1591. if (strpos($title, $search) === false) {
  1592. $comment = api_strtolower(get_lang($setting['comment']));
  1593. //Try the comment
  1594. if (strpos($comment, $search) === false) {
  1595. //Try the variable name
  1596. if (strpos($setting['variable'], $search) === false) {
  1597. continue;
  1598. } else {
  1599. $found = true;
  1600. }
  1601. } else {
  1602. $found = true;
  1603. }
  1604. } else {
  1605. $found = true;
  1606. }
  1607. if ($found) {
  1608. $settings[] = $setting;
  1609. }
  1610. }
  1611. }
  1612. return $settings;
  1613. }
  1614. /**
  1615. * Helper function to generates a form elements group.
  1616. *
  1617. * @param object $form The form where the elements group has to be added
  1618. * @param array $values Values to browse through
  1619. *
  1620. * @return array
  1621. */
  1622. function formGenerateElementsGroup($form, $values = [], $elementName)
  1623. {
  1624. $group = [];
  1625. if (is_array($values)) {
  1626. foreach ($values as $key => $value) {
  1627. $element = &$form->createElement('radio', $elementName, '', get_lang($value['display_text']), $value['value']);
  1628. $group[] = $element;
  1629. }
  1630. }
  1631. return $group;
  1632. }
  1633. /**
  1634. * Helper function with allowed file types for CSS.
  1635. *
  1636. * @return array Array of file types (no indexes)
  1637. */
  1638. function getAllowedFileTypes()
  1639. {
  1640. $allowedFiles = [
  1641. 'css',
  1642. 'zip',
  1643. 'jpeg',
  1644. 'jpg',
  1645. 'png',
  1646. 'gif',
  1647. 'ico',
  1648. 'psd',
  1649. 'xcf',
  1650. 'svg',
  1651. 'webp',
  1652. 'woff',
  1653. 'woff2',
  1654. ];
  1655. return $allowedFiles;
  1656. }
  1657. /**
  1658. * Helper function to set settings in the database.
  1659. *
  1660. * @param array $parameters List of values
  1661. * @param int $accessUrl The current access URL
  1662. */
  1663. function setConfigurationSettingsInDatabase($parameters, $accessUrl)
  1664. {
  1665. api_set_settings_category('Search', 'false', $accessUrl);
  1666. // Save the settings.
  1667. foreach ($parameters as $key => $value) {
  1668. api_set_setting($key, $value, null, null);
  1669. }
  1670. }
  1671. /**
  1672. * Helper function to show the status of the search settings table.
  1673. *
  1674. * @param array $data Data to show
  1675. */
  1676. function showSearchSettingsTable($data)
  1677. {
  1678. echo Display::tag('h3', get_lang('Settings'));
  1679. $table = new SortableTableFromArray($data);
  1680. $table->set_header(0, get_lang('Setting'), false);
  1681. $table->set_header(1, get_lang('Status'), false);
  1682. echo $table->display();
  1683. }
  1684. /**
  1685. * Helper function to show status table for each command line tool installed.
  1686. */
  1687. function showSearchToolsStatusTable()
  1688. {
  1689. //@todo windows support
  1690. if (api_is_windows_os() == false) {
  1691. $list_of_programs = ['pdftotext', 'ps2pdf', 'catdoc', 'html2text', 'unrtf', 'catppt', 'xls2csv'];
  1692. foreach ($list_of_programs as $program) {
  1693. $output = [];
  1694. $ret_val = null;
  1695. exec("which $program", $output, $ret_val);
  1696. if (!$output) {
  1697. $output[] = '';
  1698. }
  1699. $icon = Display::return_icon('bullet_red.png', get_lang('Not installed'));
  1700. if (!empty($output[0])) {
  1701. $icon = Display::return_icon('bullet_green.png', get_lang('Installed'));
  1702. }
  1703. $data2[] = [$program, $output[0], $icon];
  1704. }
  1705. echo Display::tag('h3', get_lang('Course Program</a>. If your course has no code, whatever the reason, invent one. For instance <i>INNOVATION</i> if the course is about Innovation Managements needed to convert files'));
  1706. $table = new SortableTableFromArray($data2);
  1707. $table->set_header(0, get_lang('Course Program</a>. If your course has no code, whatever the reason, invent one. For instance <i>INNOVATION</i> if the course is about Innovation Management'), false);
  1708. $table->set_header(1, get_lang('Path'), false);
  1709. $table->set_header(2, get_lang('Status'), false);
  1710. echo $table->display();
  1711. } else {
  1712. echo Display::return_message(
  1713. get_lang('You are using Chamilo in a Windows platform, sadly you can\'t convert documents in order to search the content using this tool'),
  1714. 'warning'
  1715. );
  1716. }
  1717. }
  1718. /**
  1719. * Helper function to generate and show CSS Zip download message.
  1720. *
  1721. * @param string $style Style path
  1722. */
  1723. function generateCSSDownloadLink($style)
  1724. {
  1725. $arch = api_get_path(SYS_ARCHIVE_PATH).$style.'.zip';
  1726. $themeDir = Template::getThemeDir($style);
  1727. $dir = api_get_path(SYS_CSS_PATH).$themeDir;
  1728. $check = Security::check_abs_path(
  1729. $dir,
  1730. api_get_path(SYS_CSS_PATH).'themes'
  1731. );
  1732. if (is_dir($dir) && $check) {
  1733. $zip = new PclZip($arch);
  1734. // Remove path prefix except the style name and put file on disk
  1735. $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir, 0, -strlen($style)));
  1736. $url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive='.str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch);
  1737. //@TODO: use more generic script to download.
  1738. $str = '<a class="btn btn-primary btn-large" href="'.$url.'">'.get_lang('Download the file').'</a>';
  1739. echo Display::return_message($str, 'normal', false);
  1740. } else {
  1741. echo Display::return_message(get_lang('The file was not found'), 'warning');
  1742. }
  1743. }
  1744. /**
  1745. * Helper function to tell if the style is changeable in the current URL.
  1746. *
  1747. * @return bool $changeable Whether the style can be changed in this URL or not
  1748. */
  1749. function isStyleChangeable()
  1750. {
  1751. $changeable = false;
  1752. $urlId = api_get_current_access_url_id();
  1753. if ($urlId) {
  1754. $style_info = api_get_settings('stylesheets', '', 1, 0);
  1755. $url_info = api_get_access_url($urlId);
  1756. if ($style_info[0]['access_url_changeable'] == 1 && $url_info['active'] == 1) {
  1757. $changeable = true;
  1758. }
  1759. } else {
  1760. $changeable = true;
  1761. }
  1762. return $changeable;
  1763. }
  1764. /**
  1765. * Get all settings of one category prepared for display in admin/settings.php.
  1766. *
  1767. * @param string $category
  1768. *
  1769. * @return array
  1770. */
  1771. function getCategorySettings($category = '')
  1772. {
  1773. $url_id = api_get_current_access_url_id();
  1774. $settings_by_access_list = [];
  1775. if ($url_id == 1) {
  1776. $settings = api_get_settings($category, 'group', $url_id);
  1777. } else {
  1778. $url_info = api_get_access_url($url_id);
  1779. if ($url_info['active'] == 1) {
  1780. $categoryToSearch = $category;
  1781. if ($category == 'search_setting') {
  1782. $categoryToSearch = '';
  1783. }
  1784. // The default settings of Chamilo
  1785. $settings = api_get_settings($categoryToSearch, 'group', 1, 0);
  1786. // The settings that are changeable from a particular site.
  1787. $settings_by_access = api_get_settings($categoryToSearch, 'group', $url_id, 1);
  1788. foreach ($settings_by_access as $row) {
  1789. if (empty($row['variable'])) {
  1790. $row['variable'] = 0;
  1791. }
  1792. if (empty($row['subkey'])) {
  1793. $row['subkey'] = 0;
  1794. }
  1795. if (empty($row['category'])) {
  1796. $row['category'] = 0;
  1797. }
  1798. // One more validation if is changeable.
  1799. if ($row['access_url_changeable'] == 1) {
  1800. $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
  1801. } else {
  1802. $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = [];
  1803. }
  1804. }
  1805. }
  1806. }
  1807. if (isset($category) && $category == 'search_setting') {
  1808. if (!empty($_REQUEST['search_field'])) {
  1809. $settings = searchSetting($_REQUEST['search_field']);
  1810. }
  1811. }
  1812. return [
  1813. 'settings' => $settings,
  1814. 'settings_by_access_list' => $settings_by_access_list,
  1815. ];
  1816. }