settings.lib.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  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. }