settings.php 20 KB

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