settings.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * With this tool you can easily adjust non critical configuration settings.
  6. * Non critical means that changing them will not result in a broken campus.
  7. *
  8. * @author Patrick Cool
  9. * @author Julio Montoya - Multiple URL site
  10. * @package chamilo.admin
  11. */
  12. // Resetting the course id.
  13. $cidReset = true;
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. require_once 'settings.lib.php';
  16. // Setting the section (for the tabs).
  17. $this_section = SECTION_PLATFORM_ADMIN;
  18. $_SESSION['this_section'] = $this_section;
  19. // Access restrictions.
  20. api_protect_admin_script();
  21. // Submit stylesheets.
  22. if (isset($_POST['save']) && isset($_GET['category']) && $_GET['category'] === 'Stylesheets') {
  23. storeStylesheets();
  24. Display::addFlash(Display::return_message(get_lang('Saved')));
  25. }
  26. // Settings to avoid
  27. $settings_to_avoid = array(
  28. 'use_session_mode' => 'true',
  29. 'gradebook_enable' => 'false',
  30. // ON by default - now we have this option when we create a course
  31. 'example_material_course_creation' => 'true'
  32. );
  33. $convert_byte_to_mega_list = array(
  34. 'dropbox_max_filesize',
  35. 'message_max_upload_filesize',
  36. 'default_document_quotum',
  37. 'default_group_quotum'
  38. );
  39. if (isset($_POST['style'])) {
  40. Display::$preview_style = $_POST['style'];
  41. }
  42. // Database table definitions.
  43. $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  44. // Setting breadcrumbs.
  45. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  46. // Setting the name of the tool.
  47. $tool_name = get_lang('PlatformConfigSettings');
  48. if (empty($_GET['category'])) {
  49. $_GET['category'] = 'Platform';
  50. }
  51. $watermark_deleted = false;
  52. if (isset($_GET['delete_watermark'])) {
  53. $watermark_deleted = PDF::delete_watermark();
  54. Display::addFlash(Display::return_message(get_lang('FileDeleted')));
  55. }
  56. if (isset($_GET['action']) && $_GET['action'] == 'delete_grading') {
  57. $id = intval($_GET['id']);
  58. api_delete_setting_option($id);
  59. }
  60. $form_search = new FormValidator(
  61. 'search_settings',
  62. 'get',
  63. api_get_self(),
  64. null,
  65. array(),
  66. FormValidator::LAYOUT_INLINE
  67. );
  68. $form_search->addElement('text', 'search_field', null, array(
  69. 'id' => 'search_field',
  70. 'aria-label' => get_lang('Search')
  71. ));
  72. $form_search->addElement('hidden', 'category', 'search_setting');
  73. $form_search->addButtonSearch(get_lang('Search'), 'submit_button');
  74. $form_search->setDefaults(
  75. array('search_field' => isset($_REQUEST['search_field']) ? $_REQUEST['search_field'] : null)
  76. );
  77. $form_search_html = $form_search->returnForm();
  78. $url_id = api_get_current_access_url_id();
  79. $settings = null;
  80. // Build the form.
  81. if (!empty($_GET['category']) &&
  82. !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))
  83. ) {
  84. $my_category = isset($_GET['category']) ? $_GET['category'] : null;
  85. $settings_array = getCategorySettings($my_category);
  86. $settings = $settings_array['settings'];
  87. $settings_by_access_list = $settings_array['settings_by_access_list'];
  88. $form = generateSettingsForm($settings, $settings_by_access_list);
  89. if (false && $form->validate()) {
  90. $values = $form->exportValues();
  91. $mark_all = false;
  92. $un_mark_all = false;
  93. if (api_is_multiple_url_enabled()) {
  94. if (isset($values['buttons_in_action_right']) &&
  95. isset($values['buttons_in_action_right']['mark_all'])
  96. ) {
  97. $mark_all = true;
  98. }
  99. if (isset($values['buttons_in_action_right']) &&
  100. isset($values['buttons_in_action_right']['unmark_all'])
  101. ) {
  102. $un_mark_all = true;
  103. }
  104. }
  105. if ($mark_all || $un_mark_all) {
  106. if (api_is_global_platform_admin()) {
  107. $locked_settings = api_get_locked_settings();
  108. foreach ($values as $key => $value) {
  109. if (!in_array($key, $locked_settings)) {
  110. $changeable = 0;
  111. if ($mark_all) {
  112. $changeable = 1;
  113. }
  114. $params = array('variable = ?' => array($key));
  115. $data = api_get_settings_params($params);
  116. if (!empty($data)) {
  117. foreach ($data as $item) {
  118. $params = array(
  119. 'id' => $item['id'],
  120. 'access_url_changeable' => $changeable,
  121. );
  122. api_set_setting_simple($params);
  123. }
  124. }
  125. }
  126. }
  127. // Reload settings
  128. $settings_array = getCategorySettings($my_category);
  129. $settings = $settings_array['settings'];
  130. $settings_by_access_list = $settings_array['settings_by_access_list'];
  131. $form = generateSettingsForm(
  132. $settings,
  133. $settings_by_access_list
  134. );
  135. }
  136. }
  137. if (!empty($_FILES['pdf_export_watermark_path'])) {
  138. $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
  139. }
  140. if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
  141. $pdf_export_watermark_path_result = PDF::upload_watermark(
  142. $pdf_export_watermark_path['name'],
  143. $pdf_export_watermark_path['tmp_name']
  144. );
  145. if ($pdf_export_watermark_path_result) {
  146. Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded')));
  147. } else {
  148. $message = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path(SYS_CODE_PATH).'default_course_document/images';
  149. Display::addFlash(Display::return_message($message), 'warning');
  150. }
  151. unset($update_values['pdf_export_watermark_path']);
  152. }
  153. // Set true for allow_message_tool variable if social tool is actived
  154. foreach ($convert_byte_to_mega_list as $item) {
  155. if (isset($values[$item])) {
  156. $values[$item] = round($values[$item] * 1024 * 1024);
  157. }
  158. }
  159. if (isset($values['allow_social_tool']) && $values['allow_social_tool'] == 'true') {
  160. $values['allow_message_tool'] = 'true';
  161. }
  162. foreach ($settings as $item) {
  163. $key = $item['variable'];
  164. if ($key === 'prevent_multiple_simultaneous_login') {
  165. Session::write('first_user_login', 1);
  166. }
  167. if (in_array($key, $settings_to_avoid)) {
  168. continue;
  169. }
  170. if ($key == 'search_field' || $key == 'submit_fixed_in_bottom') {
  171. continue;
  172. }
  173. $key = Database::escape_string($key);
  174. $sql = "UPDATE $table_settings_current
  175. SET selected_value = 'false'
  176. WHERE
  177. variable = '".$key."' AND
  178. access_url = ".intval($url_id)." AND
  179. type IN ('checkbox', 'radio') ";
  180. $res = Database::query($sql);
  181. }
  182. // Save the settings.
  183. $keys = array();
  184. foreach ($values as $key => $value) {
  185. if (strcmp($key, 'MAX_FILE_SIZE') === 0) {
  186. continue;
  187. }
  188. if (in_array($key, $settings_to_avoid)) {
  189. continue;
  190. }
  191. // Avoid form elements which have nothing to do with settings
  192. if ($key == 'search_field' || $key == 'submit_fixed_in_bottom') {
  193. continue;
  194. }
  195. // Treat gradebook values in separate function.
  196. //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
  197. if (!is_array($value)) {
  198. $old_value = api_get_setting($key);
  199. switch ($key) {
  200. case 'header_extra_content':
  201. file_put_contents(api_get_home_path().'header_extra_content.txt', $value);
  202. $value = api_get_home_path().'header_extra_content.txt';
  203. break;
  204. case 'footer_extra_content':
  205. file_put_contents(api_get_home_path().'footer_extra_content.txt', $value);
  206. $value = api_get_home_path().'footer_extra_content.txt';
  207. break;
  208. case 'InstitutionUrl':
  209. case 'course_validation_terms_and_conditions_url':
  210. // URL validation for some settings.
  211. $value = trim(Security::remove_XSS($value));
  212. if ($value != '') {
  213. // Here we accept absolute URLs only.
  214. if (strpos($value, '://') === false) {
  215. $value = 'http://'.$value;
  216. }
  217. if (!api_valid_url($value, true)) {
  218. // If the new (non-empty) URL value is invalid, then the old URL value stays.
  219. $value = $old_value;
  220. }
  221. }
  222. // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
  223. break;
  224. case 'emailAdministrator':
  225. // Validation against e-mail address for some settings.
  226. $value = trim(Security::remove_XSS($value));
  227. if ($value != '' && !api_valid_email($value)) {
  228. // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
  229. // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
  230. $value = $old_value;
  231. }
  232. break;
  233. }
  234. if ($old_value != $value) {
  235. $keys[] = $key;
  236. }
  237. $result = api_set_setting($key, $value, null, null, $url_id);
  238. } else {
  239. $sql = "SELECT subkey FROM $table_settings_current
  240. WHERE variable = '$key'";
  241. $res = Database::query($sql);
  242. while ($row_subkeys = Database::fetch_array($res)) {
  243. // If subkey is changed:
  244. if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
  245. (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')
  246. ) {
  247. $keys[] = $key;
  248. break;
  249. }
  250. }
  251. foreach ($value as $subkey => $subvalue) {
  252. $result = api_set_setting($key, 'true', $subkey, null, $url_id);
  253. }
  254. }
  255. }
  256. // Add event configuration settings category to the system log.
  257. $user_id = api_get_user_id();
  258. $category = $_GET['category'];
  259. Event::addEvent(
  260. LOG_CONFIGURATION_SETTINGS_CHANGE,
  261. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  262. $category,
  263. api_get_utc_datetime(),
  264. $user_id
  265. );
  266. // Add event configuration settings variable to the system log.
  267. if (is_array($keys) && count($keys) > 0) {
  268. foreach ($keys as $variable) {
  269. if (in_array($key, $settings_to_avoid)) {
  270. continue;
  271. }
  272. Event::addEvent(
  273. LOG_CONFIGURATION_SETTINGS_CHANGE,
  274. LOG_CONFIGURATION_SETTINGS_VARIABLE,
  275. $variable,
  276. api_get_utc_datetime(),
  277. $user_id
  278. );
  279. }
  280. }
  281. Display::addFlash(Display::return_message(get_lang('Updated')));
  282. header('Location: '.api_get_self().'?category='.Security::remove_XSS($my_category));
  283. exit;
  284. }
  285. }
  286. $htmlHeadXtra[] = '<script>
  287. var hide_icon = "'.api_get_path(WEB_IMG_PATH).'/icons/32/shared_setting_na.png";
  288. var show_icon = "'.api_get_path(WEB_IMG_PATH).'/icons/32/shared_setting.png";
  289. var url = "'.api_get_path(WEB_AJAX_PATH).'admin.ajax.php?a=update_changeable_setting";
  290. $(function() {
  291. $(".share_this_setting").on("click", function() {
  292. var my_img = $(this).find("img");
  293. var link = $(this);
  294. $.ajax({
  295. url: url,
  296. data: {
  297. changeable: $(this).attr("data_status"),
  298. id: $(this).attr("data_to_send")
  299. },
  300. success: function(data) {
  301. if (data == 1) {
  302. if (link.attr("data_status") == 1) {
  303. my_img.attr("src", show_icon);
  304. link.attr("data_status", 0);
  305. } else {
  306. my_img.attr("src", hide_icon);
  307. link.attr("data_status", 1);
  308. }
  309. }
  310. }
  311. });
  312. });
  313. });
  314. </script>';
  315. // The action images.
  316. $action_images['platform'] = 'platform.png';
  317. $action_images['course'] = 'course.png';
  318. $action_images['session'] = 'session.png';
  319. $action_images['tools'] = 'tools.png';
  320. $action_images['user'] = 'user.png';
  321. $action_images['gradebook'] = 'gradebook.png';
  322. $action_images['ldap'] = 'ldap.png';
  323. $action_images['cas'] = 'cas.png';
  324. $action_images['security'] = 'security.png';
  325. $action_images['languages'] = 'languages.png';
  326. $action_images['tuning'] = 'tuning.png';
  327. $action_images['templates'] = 'template.png';
  328. $action_images['search'] = 'search.png';
  329. $action_images['editor'] = 'html_editor.png';
  330. $action_images['timezones'] = 'timezone.png';
  331. $action_images['extra'] = 'wizard.png';
  332. $action_images['tracking'] = 'statistics.png';
  333. $action_images['gradebook'] = 'gradebook.png';
  334. $action_images['search'] = 'search.png';
  335. $action_images['stylesheets'] = 'stylesheets.png';
  336. $action_images['templates'] = 'template.png';
  337. $action_images['plugins'] = 'plugins.png';
  338. $action_images['shibboleth'] = 'shibboleth.png';
  339. $action_images['facebook'] = 'facebook.png';
  340. $action_images['crons'] = 'crons.png';
  341. $action_images['webservices'] = 'webservices.png';
  342. $action_array = array();
  343. $resultcategories = array();
  344. $resultcategories[] = array('category' => 'Platform');
  345. $resultcategories[] = array('category' => 'Course');
  346. $resultcategories[] = array('category' => 'Session');
  347. $resultcategories[] = array('category' => 'Languages');
  348. $resultcategories[] = array('category' => 'User');
  349. $resultcategories[] = array('category' => 'Tools');
  350. $resultcategories[] = array('category' => 'Editor');
  351. $resultcategories[] = array('category' => 'Security');
  352. $resultcategories[] = array('category' => 'Tuning');
  353. $resultcategories[] = array('category' => 'Gradebook');
  354. $resultcategories[] = array('category' => 'Timezones');
  355. $resultcategories[] = array('category' => 'Tracking');
  356. $resultcategories[] = array('category' => 'Search');
  357. $resultcategories[] = array('category' => 'Stylesheets');
  358. $resultcategories[] = array('category' => 'Templates');
  359. $resultcategories[] = array('category' => 'Plugins');
  360. $resultcategories[] = array('category' => 'LDAP');
  361. $resultcategories[] = array('category' => 'CAS');
  362. $resultcategories[] = array('category' => 'Shibboleth');
  363. $resultcategories[] = array('category' => 'Facebook');
  364. $resultcategories[] = ['category' => 'Crons'];
  365. $resultcategories[] = ['category' => 'WebServices'];
  366. foreach ($resultcategories as $row) {
  367. $url = array();
  368. $url['url'] = api_get_self()."?category=".$row['category'];
  369. $url['content'] = Display::return_icon(
  370. $action_images[strtolower($row['category'])],
  371. api_ucfirst(get_lang($row['category'])),
  372. [],
  373. ICON_SIZE_MEDIUM
  374. );
  375. if (strtolower($row['category']) == strtolower($_GET['category'])) {
  376. $url['active'] = true;
  377. }
  378. $action_array[] = $url;
  379. }
  380. ob_start();
  381. if (!empty($_GET['category'])) {
  382. switch ($_GET['category']) {
  383. case 'Regions':
  384. handleRegions();
  385. break;
  386. case 'Plugins':
  387. // Displaying the extensions: Plugins.
  388. // This will be available to all the sites (access_urls).
  389. $securityToken = isset($_GET['sec_token']) ? Security::remove_XSS($_GET['sec_token']) : null;
  390. if (isset($_POST['submit_dashboard_plugins']) && Security::check_token($securityToken)) {
  391. Security::clear_token();
  392. $affected_rows = DashboardManager::store_dashboard_plugins($_POST);
  393. if ($affected_rows) {
  394. // add event to system log
  395. $user_id = api_get_user_id();
  396. $category = $_GET['category'];
  397. Event::addEvent(
  398. LOG_CONFIGURATION_SETTINGS_CHANGE,
  399. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  400. $category,
  401. api_get_utc_datetime(),
  402. $user_id
  403. );
  404. echo Display::return_message(get_lang('DashboardPluginsUpdatedSuccessfully'), 'confirmation');
  405. }
  406. }
  407. echo '<script>
  408. $(function(){
  409. $("#tabs").tabs();
  410. });
  411. </script>';
  412. echo '<div id="tabs">';
  413. echo '<ul>';
  414. echo '<li><a href="#tabs-1">'.get_lang('InstalledPlugins').'</a></li>';
  415. echo '<li><a href="#tabs-2">'.get_lang('Plugins').'</a></li>';
  416. echo '<li><a href="#tabs-3">'.get_lang('DashboardPlugins').'</a></li>';
  417. echo '<li><a href="#tabs-4">'.get_lang('ConfigureExtensions').'</a></li>';
  418. echo '</ul>';
  419. echo '<div id="tabs-1">';
  420. handlePlugins();
  421. echo '</div>';
  422. echo '<div id="tabs-2">';
  423. handlePlugins(false);
  424. echo '</div>';
  425. echo '<div id="tabs-3">';
  426. DashboardManager::handle_dashboard_plugins();
  427. echo '</div>';
  428. echo '<div id="tabs-4">';
  429. handleExtensions();
  430. echo '</div>';
  431. echo '</div>';
  432. break;
  433. case 'Stylesheets':
  434. // Displaying the extensions: Stylesheets.
  435. handleStylesheets();
  436. break;
  437. case 'Search':
  438. handleSearch();
  439. break;
  440. case 'Templates':
  441. handleTemplates();
  442. break;
  443. case 'search_setting':
  444. if (isset($_REQUEST['search_field'])) {
  445. searchSetting($_REQUEST['search_field']);
  446. $form->display();
  447. }
  448. break;
  449. default:
  450. if (isset($form)) {
  451. $form->display();
  452. }
  453. }
  454. }
  455. $content = ob_get_clean();
  456. // Including the header (banner).
  457. Display::display_header($tool_name);
  458. echo Display::actions($action_array);
  459. echo '<br />';
  460. echo $form_search_html;
  461. echo $content;
  462. Display::display_footer();