settings.lib.php 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  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('SettingsStored'), 'confirmation');
  38. }
  39. $plugin_obj = new AppPlugin();
  40. $installed_plugins = $plugin_obj->get_installed_plugins();
  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->get_plugin_regions();
  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('EnablePlugins').'</button></form>';
  101. }
  102. function handleExtensions()
  103. {
  104. echo Display::page_subheader(get_lang('ConfigureExtensions'));
  105. echo '<a class="btn btn-success" href="configure_extensions.php?display=ppt2lp" role="button">'.get_lang('Ppt2lp').'</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('SettingsStored'), 'confirmation');
  133. }
  134. $all_plugins = $plugin_obj->read_plugins_from_path();
  135. $installed_plugins = $plugin_obj->get_installed_plugins();
  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">';
  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-default']
  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-default']
  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-default 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-default 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('EnablePlugins').'</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('NameStylesheet'),
  252. ['size' => '40', 'maxlength' => '40']
  253. );
  254. $form->addRule(
  255. 'name_stylesheet',
  256. get_lang('ThisFieldIsRequired'),
  257. 'required'
  258. );
  259. $form->addElement(
  260. 'file',
  261. 'new_stylesheet',
  262. get_lang('UploadNewStylesheet')
  263. );
  264. $allowed_file_types = getAllowedFileTypes();
  265. $form->addRule(
  266. 'new_stylesheet',
  267. get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')',
  268. 'filetype',
  269. $allowed_file_types
  270. );
  271. $form->addRule(
  272. 'new_stylesheet',
  273. get_lang('ThisFieldIsRequired'),
  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('IsNotWritable'),
  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('StylesheetAdded'));
  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('TheLogoMustBeSizeXAndFormatY'),
  343. '250 x 70',
  344. 'PNG'
  345. ),
  346. 'info'
  347. )
  348. );
  349. if ($webPlatformLogoPath !== null) {
  350. $logoForm->addLabel(
  351. get_lang('CurrentLogo'),
  352. '<img id="header-logo-custom" src="'.$webPlatformLogoPath.'?'.time().'">'
  353. );
  354. }
  355. $logoForm->addFile('new_logo', get_lang('UpdateLogo'));
  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('ResetToTheOriginalLogo'));
  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('InvalidExtension').' ('.implode(',', $allowedFileTypes).')',
  375. 'filetype',
  376. $allowedFileTypes
  377. );
  378. $logoForm->addRule(
  379. 'new_logo',
  380. get_lang('ThisFieldIsRequired'),
  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('NewLogoUpdated'));
  397. echo '<script>'
  398. .'$("#header-logo").attr("src","'.$url.$newLogoFileName.'");'
  399. .'</script>';
  400. } else {
  401. echo Display::return_message('Error - '.get_lang('UplNoFileUploaded'), 'error');
  402. }
  403. } else {
  404. Display::return_message('Error - '.get_lang('InvalidImageDimensions'), '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('NameStylesheet')
  422. );
  423. $styles->setSelected($currentStyle);
  424. if ($is_style_changeable) {
  425. $group = [
  426. $form_change->addButtonSave(get_lang('SaveSettings'), '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('UpdateLogo'), get_lang('UploadNewStylesheet')],
  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('ErrorStylesheetFilesExtensionsInsideZip').$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('ErrorReadingZip').$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->get_installed_plugins();
  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->remove_all_regions($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('SearchEnabledTitle'));
  682. $group = formGenerateElementsGroup($form, $values, 'search_enabled');
  683. // SearchEnabledComment
  684. $form->addGroup(
  685. $group,
  686. 'search_enabled',
  687. [get_lang('SearchEnabledTitle'), get_lang('SearchEnabledComment')],
  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('SearchShowUnlinkedResultsTitle'),
  711. get_lang('SearchShowUnlinkedResultsComment'),
  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('AddSpecificSearchField'),
  724. 'specific_fields.php'
  725. ),
  726. ['class' => 'sectioncomment']
  727. );
  728. if (empty($sf_values)) {
  729. $form->addElement('label', [get_lang('SearchPrefilterPrefix'), $url]);
  730. } else {
  731. $form->addElement(
  732. 'select',
  733. 'search_prefilter_prefix',
  734. [get_lang('SearchPrefilterPrefix'), $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('Ok'));
  770. $dir_exists = Display::return_icon('bullet_green.png', get_lang('Ok'));
  771. $dir_is_writable = Display::return_icon('bullet_green.png', get_lang('Ok'));
  772. $specific_fields_exists = Display::return_icon('bullet_green.png', get_lang('Ok'));
  773. //Testing specific fields
  774. if (empty($specific_fields)) {
  775. $specific_fields_exists = Display::return_icon(
  776. 'bullet_red.png',
  777. get_lang('AddSpecificSearchField')
  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('XapianModuleInstalled'), $xapianLoaded];
  794. $data[] = [get_lang('DirectoryExists').' - '.$xapianPath, $dir_exists];
  795. $data[] = [get_lang('IsWritable').' - '.$xapianPath, $dir_is_writable];
  796. $data[] = [get_lang('SpecificSearchFieldsAvailable'), $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('AddTemplate'), '', 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('Actions'), 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('ConfirmYourChoice')."'".')) 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_APP_PATH).'home/default_platform_document/template_thumb/'.$image.'" alt="'.get_lang('TemplatePreview').'"/>';
  969. } else {
  970. return '<img src="'.api_get_path(WEB_APP_PATH).'home/default_platform_document/template_thumb/noimage.gif" alt="'.get_lang('NoTemplatePreview').'"/>';
  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. // Initialize the object.
  987. $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
  988. /** @var SystemTemplate $template */
  989. $template = $id ? $em->find('ChamiloCoreBundle:SystemTemplate', $id) : new SystemTemplate();
  990. $form = new FormValidator(
  991. 'template',
  992. 'post',
  993. 'settings.php?category=Templates&action='.Security::remove_XSS($_GET['action']).'&id='.$id
  994. );
  995. // Setting the form elements: the header.
  996. if ($_GET['action'] == 'add') {
  997. $title = get_lang('AddTemplate');
  998. } else {
  999. $title = get_lang('EditTemplate');
  1000. }
  1001. $form->addElement('header', '', $title);
  1002. // Setting the form elements: the title of the template.
  1003. $form->addText('title', get_lang('Title'), false);
  1004. $form->addText('comment', get_lang('Description'), false);
  1005. // Setting the form elements: the content of the template (wysiwyg editor).
  1006. $form->addHtmlEditor(
  1007. 'template_text',
  1008. get_lang('Text'),
  1009. true,
  1010. true,
  1011. ['ToolbarSet' => 'Documents', 'Width' => '100%', 'Height' => '400']
  1012. );
  1013. // Setting the form elements: the form to upload an image to be used with the template.
  1014. if (empty($template->getImage())) {
  1015. $form->addElement('file', 'template_image', get_lang('Image'), '');
  1016. }
  1017. // Setting the form elements: a little bit information about the template image.
  1018. $form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70'));
  1019. // Getting all the information of the template when editing a template.
  1020. if ($_GET['action'] == 'edit') {
  1021. $defaults['template_id'] = $id;
  1022. $defaults['template_text'] = $template->getContent();
  1023. // Forcing get_lang().
  1024. $defaults['title'] = $template->getTitle();
  1025. $defaults['comment'] = $template->getComment();
  1026. // Adding an extra field: a hidden field with the id of the template we are editing.
  1027. $form->addElement('hidden', 'template_id');
  1028. // Adding an extra field: a preview of the image that is currently used.
  1029. if (!empty($template->getImage())) {
  1030. $form->addElement(
  1031. 'static',
  1032. 'template_image_preview',
  1033. '',
  1034. '<img src="'.api_get_path(WEB_APP_PATH)
  1035. .'home/default_platform_document/template_thumb/'.$template->getImage()
  1036. .'" alt="'.get_lang('TemplatePreview')
  1037. .'"/>'
  1038. );
  1039. $form->addCheckBox('delete_image', null, get_lang('DeletePicture'));
  1040. } else {
  1041. $form->addElement(
  1042. 'static',
  1043. 'template_image_preview',
  1044. '',
  1045. '<img src="'.api_get_path(WEB_APP_PATH).'home/default_platform_document/template_thumb/noimage.gif" alt="'.get_lang('NoTemplatePreview').'"/>'
  1046. );
  1047. }
  1048. // Setting the information of the template that we are editing.
  1049. $form->setDefaults($defaults);
  1050. }
  1051. // Setting the form elements: the submit button.
  1052. $form->addButtonSave(get_lang('Ok'), 'submit');
  1053. // Setting the rules: the required fields.
  1054. if (empty($template->getImage())) {
  1055. $form->addRule(
  1056. 'template_image',
  1057. get_lang('ThisFieldIsRequired'),
  1058. 'required'
  1059. );
  1060. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  1061. }
  1062. // if the form validates (complies to all rules) we save the information,
  1063. // else we display the form again (with error message if needed)
  1064. if ($form->validate()) {
  1065. $check = Security::check_token('post');
  1066. if ($check) {
  1067. // Exporting the values.
  1068. $values = $form->exportValues();
  1069. $isDelete = null;
  1070. if (isset($values['delete_image'])) {
  1071. $isDelete = $values['delete_image'];
  1072. }
  1073. // Upload the file.
  1074. if (!empty($_FILES['template_image']['name'])) {
  1075. $upload_ok = process_uploaded_file($_FILES['template_image']);
  1076. if ($upload_ok) {
  1077. // Try to add an extension to the file if it hasn't one.
  1078. $new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
  1079. // The upload directory.
  1080. $upload_dir = api_get_path(SYS_APP_PATH).'home/default_platform_document/template_thumb/';
  1081. // Create the directory if it does not exist.
  1082. if (!is_dir($upload_dir)) {
  1083. mkdir($upload_dir, api_get_permissions_for_new_directories());
  1084. }
  1085. // Resize the preview image to max default and upload.
  1086. $temp = new Image($_FILES['template_image']['tmp_name']);
  1087. $picture_info = $temp->get_image_info();
  1088. $max_width_for_picture = 100;
  1089. if ($picture_info['width'] > $max_width_for_picture) {
  1090. $temp->resize($max_width_for_picture);
  1091. }
  1092. $temp->send_image($upload_dir.$new_file_name);
  1093. }
  1094. }
  1095. // Store the information in the database (as insert or as update).
  1096. //$bootstrap = api_get_css(api_get_path(WEB_PUBLIC_PATH).'assets/bootstrap/dist/css/bootstrap.min.css');
  1097. $viewport = '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
  1098. if ($_GET['action'] == 'add') {
  1099. $templateContent = '<head>'.$viewport.'<title>'.$values['title'].'</title></head>'
  1100. .$values['template_text'];
  1101. $template
  1102. ->setTitle($values['title'])
  1103. ->setComment(Security::remove_XSS($values['comment']))
  1104. ->setContent(Security::remove_XSS($templateContent, COURSEMANAGERLOWSECURITY))
  1105. ->setImage($new_file_name);
  1106. $em->persist($template);
  1107. $em->flush();
  1108. // Display a feedback message.
  1109. echo Display::return_message(
  1110. get_lang('TemplateAdded'),
  1111. 'confirm'
  1112. );
  1113. echo '<a href="settings.php?category=Templates&action=add">'.
  1114. Display::return_icon('new_template.png', get_lang('AddTemplate'), '', ICON_SIZE_MEDIUM).
  1115. '</a>';
  1116. } else {
  1117. $templateContent = $values['template_text'];
  1118. $template
  1119. ->setTitle($values['title'])
  1120. ->setComment(Security::remove_XSS($values['comment']))
  1121. ->setContent(Security::remove_XSS($templateContent, COURSEMANAGERLOWSECURITY));
  1122. if ($isDelete) {
  1123. $filePath = api_get_path(SYS_APP_PATH).'home/default_platform_document/template_thumb/'.$template->getImage();
  1124. if (file_exists($filePath)) {
  1125. unlink($filePath);
  1126. }
  1127. $template->setImage(null);
  1128. }
  1129. if (!empty($new_file_name)) {
  1130. $template->setImage($new_file_name);
  1131. }
  1132. $em->persist($template);
  1133. $em->flush();
  1134. // Display a feedback message.
  1135. echo Display::return_message(get_lang('TemplateEdited'), 'confirm');
  1136. }
  1137. }
  1138. Security::clear_token();
  1139. displayTemplates();
  1140. } else {
  1141. $token = Security::get_token();
  1142. $form->addElement('hidden', 'sec_token');
  1143. $form->setConstants(['sec_token' => $token]);
  1144. // Display the form.
  1145. $form->display();
  1146. }
  1147. }
  1148. /**
  1149. * Delete a template.
  1150. *
  1151. * @param int $id the id of the template that has to be deleted
  1152. *
  1153. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1154. *
  1155. * @version August 2008
  1156. *
  1157. * @since v1.8.6
  1158. */
  1159. function deleteTemplate($id)
  1160. {
  1161. $id = intval($id);
  1162. // First we remove the image.
  1163. $table = Database::get_main_table('system_template');
  1164. $sql = "SELECT * FROM $table WHERE id = $id";
  1165. $result = Database::query($sql);
  1166. $row = Database::fetch_array($result);
  1167. if (!empty($row['image'])) {
  1168. @unlink(api_get_path(SYS_APP_PATH).'home/default_platform_document/template_thumb/'.$row['image']);
  1169. }
  1170. // Now we remove it from the database.
  1171. $sql = "DELETE FROM $table WHERE id = $id";
  1172. Database::query($sql);
  1173. // Display a feedback message.
  1174. echo Display::return_message(get_lang('TemplateDeleted'), 'confirm');
  1175. }
  1176. /**
  1177. * Returns the list of timezone identifiers used to populate the select
  1178. * This function is called through a call_user_func() in the generate_settings_form function.
  1179. *
  1180. * @return array List of timezone identifiers
  1181. *
  1182. * @author Guillaume Viguier <guillaume.viguier@beeznest.com>
  1183. *
  1184. * @since Chamilo 1.8.7
  1185. */
  1186. function select_timezone_value()
  1187. {
  1188. return api_get_timezones();
  1189. }
  1190. /**
  1191. * Returns an array containing the list of options used to populate the gradebook_number_decimals variable
  1192. * This function is called through a call_user_func() in the generate_settings_form function.
  1193. *
  1194. * @return array List of gradebook_number_decimals options
  1195. *
  1196. * @author Guillaume Viguier <guillaume.viguier@beeznest.com>
  1197. */
  1198. function select_gradebook_number_decimals()
  1199. {
  1200. return ['0', '1', '2'];
  1201. }
  1202. /**
  1203. * Get the options for a select element to select gradebook default grade model.
  1204. *
  1205. * @return array
  1206. */
  1207. function select_gradebook_default_grade_model_id()
  1208. {
  1209. $grade_model = new GradeModel();
  1210. $models = $grade_model->get_all();
  1211. $options = [];
  1212. $options[-1] = get_lang('None');
  1213. if (!empty($models)) {
  1214. foreach ($models as $model) {
  1215. $options[$model['id']] = $model['name'];
  1216. }
  1217. }
  1218. return $options;
  1219. }
  1220. /**
  1221. * @param array $settings
  1222. * @param array $settings_by_access_list
  1223. *
  1224. * @throws \Doctrine\ORM\ORMException
  1225. * @throws \Doctrine\ORM\OptimisticLockException
  1226. * @throws \Doctrine\ORM\TransactionRequiredException
  1227. *
  1228. * @return FormValidator
  1229. */
  1230. function generateSettingsForm($settings, $settings_by_access_list)
  1231. {
  1232. global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list;
  1233. $em = Database::getManager();
  1234. $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1235. $form = new FormValidator(
  1236. 'settings',
  1237. 'post',
  1238. 'settings.php?category='.Security::remove_XSS($_GET['category'])
  1239. );
  1240. $form->addElement(
  1241. 'hidden',
  1242. 'search_field',
  1243. (!empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null)
  1244. );
  1245. $url_id = api_get_current_access_url_id();
  1246. /*
  1247. if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) {
  1248. $group = array();
  1249. $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll'));
  1250. $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll'));
  1251. $form->addGroup($group, 'buttons_in_action_right');
  1252. }*/
  1253. $default_values = [];
  1254. $url_info = api_get_access_url($url_id);
  1255. $i = 0;
  1256. $addedSettings = [];
  1257. foreach ($settings as $row) {
  1258. if (in_array($row['variable'], array_keys($settings_to_avoid))) {
  1259. continue;
  1260. }
  1261. if (in_array($row['variable'], $addedSettings)) {
  1262. continue;
  1263. }
  1264. $addedSettings[] = $row['variable'];
  1265. if (!empty($_configuration['multiple_access_urls'])) {
  1266. if (api_is_global_platform_admin()) {
  1267. if ($row['access_url_locked'] == 0) {
  1268. if ($url_id == 1) {
  1269. if ($row['access_url_changeable'] == '1') {
  1270. $form->addElement(
  1271. 'html',
  1272. '<div class="pull-right"><a class="share_this_setting" data_status = "0" data_to_send = "'.$row['variable'].'" href="javascript:void(0);">'.
  1273. Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting'), null, ICON_SIZE_MEDIUM).'</a></div>'
  1274. );
  1275. } else {
  1276. $form->addElement(
  1277. 'html',
  1278. '<div class="pull-right"><a class="share_this_setting" data_status = "1" data_to_send = "'.$row['variable'].'" href="javascript:void(0);">'.
  1279. Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting'), null, ICON_SIZE_MEDIUM).'</a></div>'
  1280. );
  1281. }
  1282. } else {
  1283. if ($row['access_url_changeable'] == '1') {
  1284. $form->addElement(
  1285. 'html',
  1286. '<div class="pull-right">'.
  1287. Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting'), null, ICON_SIZE_MEDIUM).'</div>'
  1288. );
  1289. } else {
  1290. $form->addElement(
  1291. 'html',
  1292. '<div class="pull-right">'.
  1293. Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting'), null, ICON_SIZE_MEDIUM).'</div>'
  1294. );
  1295. }
  1296. }
  1297. }
  1298. }
  1299. }
  1300. $hideme = [];
  1301. $hide_element = false;
  1302. if ($_configuration['access_url'] != 1) {
  1303. if ($row['access_url_changeable'] == 0) {
  1304. // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element.
  1305. $hide_element = true;
  1306. $hideme = ['disabled'];
  1307. } elseif ($url_info['active'] == 1) {
  1308. // We show the elements.
  1309. if (empty($row['variable'])) {
  1310. $row['variable'] = 0;
  1311. }
  1312. if (empty($row['subkey'])) {
  1313. $row['subkey'] = 0;
  1314. }
  1315. if (empty($row['category'])) {
  1316. $row['category'] = 0;
  1317. }
  1318. if (isset($settings_by_access_list[$row['variable']]) &&
  1319. isset($settings_by_access_list[$row['variable']][$row['subkey']]) &&
  1320. is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])
  1321. ) {
  1322. // We are sure that the other site have a selected value.
  1323. if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') {
  1324. $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'];
  1325. }
  1326. }
  1327. // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site.
  1328. }
  1329. }
  1330. switch ($row['type']) {
  1331. case 'textfield':
  1332. if (in_array($row['variable'], $convert_byte_to_mega_list)) {
  1333. $form->addElement(
  1334. 'text',
  1335. $row['variable'],
  1336. [
  1337. get_lang($row['title']),
  1338. get_lang($row['comment']),
  1339. get_lang('MB'),
  1340. ],
  1341. ['maxlength' => '8', 'aria-label' => get_lang($row['title'])]
  1342. );
  1343. $form->applyFilter($row['variable'], 'html_filter');
  1344. $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1);
  1345. } elseif ($row['variable'] == 'account_valid_duration') {
  1346. $form->addElement(
  1347. 'text',
  1348. $row['variable'],
  1349. [
  1350. get_lang($row['title']),
  1351. get_lang($row['comment']),
  1352. ],
  1353. ['maxlength' => '5', 'aria-label' => get_lang($row['title'])]
  1354. );
  1355. $form->applyFilter($row['variable'], 'html_filter');
  1356. // For platform character set selection:
  1357. // Conversion of the textfield to a select box with valid values.
  1358. $default_values[$row['variable']] = $row['selected_value'];
  1359. } elseif ($row['variable'] == 'platform_charset') {
  1360. break;
  1361. } else {
  1362. $hideme['class'] = 'col-md-4';
  1363. $hideme['aria-label'] = get_lang($row['title']);
  1364. $form->addElement(
  1365. 'text',
  1366. $row['variable'],
  1367. [
  1368. get_lang($row['title']),
  1369. get_lang($row['comment']),
  1370. ],
  1371. $hideme
  1372. );
  1373. $form->applyFilter($row['variable'], 'html_filter');
  1374. $default_values[$row['variable']] = $row['selected_value'];
  1375. }
  1376. break;
  1377. case 'textarea':
  1378. if ($row['variable'] == 'header_extra_content') {
  1379. $file = api_get_home_path().'header_extra_content.txt';
  1380. $value = '';
  1381. if (file_exists($file)) {
  1382. $value = file_get_contents($file);
  1383. }
  1384. $form->addElement(
  1385. 'textarea',
  1386. $row['variable'],
  1387. [get_lang($row['title']), get_lang($row['comment'])],
  1388. ['rows' => '10', 'id' => $row['variable']],
  1389. $hideme
  1390. );
  1391. $default_values[$row['variable']] = $value;
  1392. } elseif ($row['variable'] == 'footer_extra_content') {
  1393. $file = api_get_home_path().'footer_extra_content.txt';
  1394. $value = '';
  1395. if (file_exists($file)) {
  1396. $value = file_get_contents($file);
  1397. }
  1398. $form->addElement(
  1399. 'textarea',
  1400. $row['variable'],
  1401. [get_lang($row['title']), get_lang($row['comment'])],
  1402. ['rows' => '10', 'id' => $row['variable']],
  1403. $hideme
  1404. );
  1405. $default_values[$row['variable']] = $value;
  1406. } else {
  1407. $form->addElement(
  1408. 'textarea',
  1409. $row['variable'],
  1410. [get_lang($row['title']),
  1411. get_lang($row['comment']), ],
  1412. ['rows' => '10', 'id' => $row['variable']],
  1413. $hideme
  1414. );
  1415. $default_values[$row['variable']] = $row['selected_value'];
  1416. }
  1417. break;
  1418. case 'radio':
  1419. $values = api_get_settings_options($row['variable']);
  1420. $group = [];
  1421. if (is_array($values)) {
  1422. foreach ($values as $key => $value) {
  1423. $element = &$form->createElement(
  1424. 'radio',
  1425. $row['variable'],
  1426. '',
  1427. get_lang($value['display_text']),
  1428. $value['value']
  1429. );
  1430. if ($hide_element) {
  1431. $element->freeze();
  1432. }
  1433. $group[] = $element;
  1434. }
  1435. }
  1436. $form->addGroup(
  1437. $group,
  1438. $row['variable'],
  1439. [get_lang($row['title']), get_lang($row['comment'])],
  1440. null,
  1441. false
  1442. );
  1443. $default_values[$row['variable']] = $row['selected_value'];
  1444. break;
  1445. case 'checkbox':
  1446. // 1. We collect all the options of this variable.
  1447. $sql = "SELECT * FROM $table_settings_current
  1448. WHERE variable='".$row['variable']."' AND access_url = 1";
  1449. $result = Database::query($sql);
  1450. $group = [];
  1451. while ($rowkeys = Database::fetch_array($result)) {
  1452. // Profile tab option should be hidden when the social tool is enabled.
  1453. if (api_get_setting('allow_social_tool') == 'true') {
  1454. if ($rowkeys['variable'] === 'show_tabs' && $rowkeys['subkey'] === 'my_profile') {
  1455. continue;
  1456. }
  1457. }
  1458. // Hiding the gradebook option.
  1459. if ($rowkeys['variable'] === 'show_tabs' && $rowkeys['subkey'] === 'my_gradebook') {
  1460. continue;
  1461. }
  1462. $element = &$form->createElement(
  1463. 'checkbox',
  1464. $rowkeys['subkey'],
  1465. '',
  1466. get_lang($rowkeys['subkeytext'])
  1467. );
  1468. if ($row['access_url_changeable'] == 1) {
  1469. // 2. We look into the DB if there is a setting for a specific access_url.
  1470. $access_url = $_configuration['access_url'];
  1471. if (empty($access_url)) {
  1472. $access_url = 1;
  1473. }
  1474. $sql = "SELECT selected_value FROM $table_settings_current
  1475. WHERE
  1476. variable='".$rowkeys['variable']."' AND
  1477. subkey='".$rowkeys['subkey']."' AND
  1478. subkeytext='".$rowkeys['subkeytext']."' AND
  1479. access_url = $access_url";
  1480. $result_access = Database::query($sql);
  1481. $row_access = Database::fetch_array($result_access);
  1482. if ($row_access['selected_value'] === 'true' && !$form->isSubmitted()) {
  1483. $element->setChecked(true);
  1484. }
  1485. } else {
  1486. if ($rowkeys['selected_value'] === 'true' && !$form->isSubmitted()) {
  1487. $element->setChecked(true);
  1488. }
  1489. }
  1490. if ($hide_element) {
  1491. $element->freeze();
  1492. }
  1493. $group[] = $element;
  1494. }
  1495. $form->addGroup(
  1496. $group,
  1497. $row['variable'],
  1498. [get_lang($row['title']), get_lang($row['comment'])],
  1499. null
  1500. );
  1501. break;
  1502. case 'link':
  1503. $form->addElement(
  1504. 'static',
  1505. null,
  1506. [get_lang($row['title']), get_lang($row['comment'])],
  1507. get_lang('CurrentValue').' : '.$row['selected_value'],
  1508. $hideme
  1509. );
  1510. break;
  1511. case 'select':
  1512. /*
  1513. * 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.
  1514. * The functions being called must be added to the file settings.lib.php.
  1515. */
  1516. $form->addElement(
  1517. 'select',
  1518. $row['variable'],
  1519. [get_lang($row['title']), get_lang($row['comment'])],
  1520. call_user_func('select_'.$row['variable']),
  1521. $hideme
  1522. );
  1523. $default_values[$row['variable']] = $row['selected_value'];
  1524. break;
  1525. case 'custom':
  1526. break;
  1527. case 'select_course':
  1528. $courseSelectOptions = [];
  1529. if (!empty($row['selected_value'])) {
  1530. $course = $em->find('ChamiloCoreBundle:Course', $row['selected_value']);
  1531. $courseSelectOptions[$course->getId()] = $course->getTitle();
  1532. }
  1533. $form->addElement(
  1534. 'select_ajax',
  1535. $row['variable'],
  1536. [get_lang($row['title']), get_lang($row['comment'])],
  1537. $courseSelectOptions,
  1538. ['url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course']
  1539. );
  1540. $default_values[$row['variable']] = $row['selected_value'];
  1541. break;
  1542. }
  1543. switch ($row['variable']) {
  1544. case 'pdf_export_watermark_enable':
  1545. $url = PDF::get_watermark(null);
  1546. if ($url != false) {
  1547. $delete_url = '<a href="?delete_watermark">'.get_lang('DelImage').' '.Display::return_icon('delete.png', get_lang('DelImage')).'</a>';
  1548. $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>');
  1549. }
  1550. $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
  1551. $allowed_picture_types = ['jpg', 'jpeg', 'png', 'gif'];
  1552. $form->addRule(
  1553. 'pdf_export_watermark_path',
  1554. get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
  1555. 'filetype',
  1556. $allowed_picture_types
  1557. );
  1558. break;
  1559. case 'timezone_value':
  1560. $timezone = $row['selected_value'];
  1561. if (empty($timezone)) {
  1562. $timezone = api_get_timezone();
  1563. }
  1564. $form->addLabel('', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time()));
  1565. break;
  1566. }
  1567. } // end for
  1568. if (!empty($settings)) {
  1569. $form->setDefaults($default_values);
  1570. }
  1571. $form->addHtml('<div class="bottom_actions">');
  1572. $form->addButtonSave(get_lang('SaveSettings'));
  1573. $form->addHtml('</div>');
  1574. return $form;
  1575. }
  1576. /**
  1577. * Searches a platform setting in all categories except from the Plugins category.
  1578. *
  1579. * @param string $search
  1580. *
  1581. * @return array
  1582. */
  1583. function searchSetting($search)
  1584. {
  1585. if (empty($search)) {
  1586. return [];
  1587. }
  1588. $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1589. $sql = "SELECT * FROM $table_settings_current
  1590. WHERE category <> 'Plugins' ORDER BY id ASC ";
  1591. $result = Database::store_result(Database::query($sql), 'ASSOC');
  1592. $settings = [];
  1593. $search = api_strtolower($search);
  1594. if (!empty($result)) {
  1595. foreach ($result as $setting) {
  1596. $found = false;
  1597. $title = api_strtolower(get_lang($setting['title']));
  1598. // try the title
  1599. if (strpos($title, $search) === false) {
  1600. $comment = api_strtolower(get_lang($setting['comment']));
  1601. //Try the comment
  1602. if (strpos($comment, $search) === false) {
  1603. //Try the variable name
  1604. if (strpos($setting['variable'], $search) === false) {
  1605. continue;
  1606. } else {
  1607. $found = true;
  1608. }
  1609. } else {
  1610. $found = true;
  1611. }
  1612. } else {
  1613. $found = true;
  1614. }
  1615. if ($found) {
  1616. $settings[] = $setting;
  1617. }
  1618. }
  1619. }
  1620. return $settings;
  1621. }
  1622. /**
  1623. * Helper function to generates a form elements group.
  1624. *
  1625. * @param object $form The form where the elements group has to be added
  1626. * @param array $values Values to browse through
  1627. *
  1628. * @return array
  1629. */
  1630. function formGenerateElementsGroup($form, $values = [], $elementName)
  1631. {
  1632. $group = [];
  1633. if (is_array($values)) {
  1634. foreach ($values as $key => $value) {
  1635. $element = &$form->createElement('radio', $elementName, '', get_lang($value['display_text']), $value['value']);
  1636. $group[] = $element;
  1637. }
  1638. }
  1639. return $group;
  1640. }
  1641. /**
  1642. * Helper function with allowed file types for CSS.
  1643. *
  1644. * @return array Array of file types (no indexes)
  1645. */
  1646. function getAllowedFileTypes()
  1647. {
  1648. $allowedFiles = [
  1649. 'css',
  1650. 'zip',
  1651. 'jpeg',
  1652. 'jpg',
  1653. 'png',
  1654. 'gif',
  1655. 'ico',
  1656. 'psd',
  1657. 'xcf',
  1658. 'svg',
  1659. 'webp',
  1660. 'woff',
  1661. 'woff2',
  1662. ];
  1663. return $allowedFiles;
  1664. }
  1665. /**
  1666. * Helper function to set settings in the database.
  1667. *
  1668. * @param array $parameters List of values
  1669. * @param int $accessUrl The current access URL
  1670. */
  1671. function setConfigurationSettingsInDatabase($parameters, $accessUrl)
  1672. {
  1673. api_set_settings_category('Search', 'false', $accessUrl);
  1674. // Save the settings.
  1675. foreach ($parameters as $key => $value) {
  1676. api_set_setting($key, $value, null, null);
  1677. }
  1678. }
  1679. /**
  1680. * Helper function to show the status of the search settings table.
  1681. *
  1682. * @param array $data Data to show
  1683. */
  1684. function showSearchSettingsTable($data)
  1685. {
  1686. echo Display::tag('h3', get_lang('Settings'));
  1687. $table = new SortableTableFromArray($data);
  1688. $table->set_header(0, get_lang('Setting'), false);
  1689. $table->set_header(1, get_lang('Status'), false);
  1690. echo $table->display();
  1691. }
  1692. /**
  1693. * Helper function to show status table for each command line tool installed.
  1694. */
  1695. function showSearchToolsStatusTable()
  1696. {
  1697. //@todo windows support
  1698. if (api_is_windows_os() == false) {
  1699. $list_of_programs = ['pdftotext', 'ps2pdf', 'catdoc', 'html2text', 'unrtf', 'catppt', 'xls2csv'];
  1700. foreach ($list_of_programs as $program) {
  1701. $output = [];
  1702. $ret_val = null;
  1703. exec("which $program", $output, $ret_val);
  1704. if (!$output) {
  1705. $output[] = '';
  1706. }
  1707. $icon = Display::return_icon('bullet_red.png', get_lang('NotInstalled'));
  1708. if (!empty($output[0])) {
  1709. $icon = Display::return_icon('bullet_green.png', get_lang('Installed'));
  1710. }
  1711. $data2[] = [$program, $output[0], $icon];
  1712. }
  1713. echo Display::tag('h3', get_lang('ProgramsNeededToConvertFiles'));
  1714. $table = new SortableTableFromArray($data2);
  1715. $table->set_header(0, get_lang('Program'), false);
  1716. $table->set_header(1, get_lang('Path'), false);
  1717. $table->set_header(2, get_lang('Status'), false);
  1718. echo $table->display();
  1719. } else {
  1720. echo Display::return_message(
  1721. get_lang('YouAreUsingChamiloInAWindowsPlatformSadlyYouCantConvertDocumentsInOrderToSearchTheContentUsingThisTool'),
  1722. 'warning'
  1723. );
  1724. }
  1725. }
  1726. /**
  1727. * Helper function to generate and show CSS Zip download message.
  1728. *
  1729. * @param string $style Style path
  1730. */
  1731. function generateCSSDownloadLink($style)
  1732. {
  1733. $arch = api_get_path(SYS_ARCHIVE_PATH).$style.'.zip';
  1734. $themeDir = Template::getThemeDir($style);
  1735. $dir = api_get_path(SYS_CSS_PATH).$themeDir;
  1736. $check = Security::check_abs_path(
  1737. $dir,
  1738. api_get_path(SYS_CSS_PATH).'themes'
  1739. );
  1740. if (is_dir($dir) && $check) {
  1741. $zip = new PclZip($arch);
  1742. // Remove path prefix except the style name and put file on disk
  1743. $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, dirname($dir));
  1744. $url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive='.str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch);
  1745. //@TODO: use more generic script to download.
  1746. $str = '<a class="btn btn-primary btn-large" href="'.$url.'">'.get_lang('ClickHereToDownloadTheFile').'</a>';
  1747. echo Display::return_message($str, 'normal', false);
  1748. } else {
  1749. echo Display::return_message(get_lang('FileNotFound'), 'warning');
  1750. }
  1751. }
  1752. /**
  1753. * Helper function to tell if the style is changeable in the current URL.
  1754. *
  1755. * @return bool $changeable Whether the style can be changed in this URL or not
  1756. */
  1757. function isStyleChangeable()
  1758. {
  1759. $changeable = false;
  1760. $urlId = api_get_current_access_url_id();
  1761. if ($urlId) {
  1762. $style_info = api_get_settings('stylesheets', '', 1, 0);
  1763. $url_info = api_get_access_url($urlId);
  1764. if ($style_info[0]['access_url_changeable'] == 1 && $url_info['active'] == 1) {
  1765. $changeable = true;
  1766. }
  1767. } else {
  1768. $changeable = true;
  1769. }
  1770. return $changeable;
  1771. }
  1772. /**
  1773. * Get all settings of one category prepared for display in admin/settings.php.
  1774. *
  1775. * @param string $category
  1776. *
  1777. * @return array
  1778. */
  1779. function getCategorySettings($category = '')
  1780. {
  1781. $url_id = api_get_current_access_url_id();
  1782. $settings_by_access_list = [];
  1783. if ($url_id == 1) {
  1784. $settings = api_get_settings($category, 'group', $url_id);
  1785. } else {
  1786. $url_info = api_get_access_url($url_id);
  1787. if ($url_info['active'] == 1) {
  1788. $categoryToSearch = $category;
  1789. if ($category == 'search_setting') {
  1790. $categoryToSearch = '';
  1791. }
  1792. // The default settings of Chamilo
  1793. $settings = api_get_settings($categoryToSearch, 'group', 1, 0);
  1794. // The settings that are changeable from a particular site.
  1795. $settings_by_access = api_get_settings($categoryToSearch, 'group', $url_id, 1);
  1796. foreach ($settings_by_access as $row) {
  1797. if (empty($row['variable'])) {
  1798. $row['variable'] = 0;
  1799. }
  1800. if (empty($row['subkey'])) {
  1801. $row['subkey'] = 0;
  1802. }
  1803. if (empty($row['category'])) {
  1804. $row['category'] = 0;
  1805. }
  1806. // One more validation if is changeable.
  1807. if ($row['access_url_changeable'] == 1) {
  1808. $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
  1809. } else {
  1810. $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = [];
  1811. }
  1812. }
  1813. }
  1814. }
  1815. if (isset($category) && $category == 'search_setting') {
  1816. if (!empty($_REQUEST['search_field'])) {
  1817. $settings = searchSetting($_REQUEST['search_field']);
  1818. }
  1819. }
  1820. return [
  1821. 'settings' => $settings,
  1822. 'settings_by_access_list' => $settings_by_access_list,
  1823. ];
  1824. }