settings.php 20 KB

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