settings.lib.php 70 KB

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