settings.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  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. * @since Dokeos 1.6
  10. * @author Julio Montoya - Multiple URL site
  11. * @package chamilo.admin
  12. ==============================================================================
  13. */
  14. /*
  15. ==============================================================================
  16. INIT SECTION
  17. ==============================================================================
  18. */
  19. // name of the language file that needs to be included
  20. if ($_GET['category']=='Templates') {
  21. $language_file = array('admin','document');
  22. } else {
  23. $language_file = array('admin');
  24. }
  25. // resetting the course id
  26. $cidReset=true;
  27. // including some necessary dokeos files
  28. require_once '../inc/global.inc.php';
  29. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  30. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  31. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  32. require_once api_get_path(LIBRARY_PATH).'dashboard.lib.php';
  33. require_once 'settings.lib.php';
  34. // setting the section (for the tabs)
  35. $this_section = SECTION_PLATFORM_ADMIN;
  36. $_SESSION['this_section'] = $this_section;
  37. // Access restrictions
  38. api_protect_admin_script();
  39. // Submit Stylesheets
  40. if (isset($_POST['submit_stylesheets']))
  41. {
  42. $message = store_stylesheets();
  43. header("Location: ".api_get_self()."?category=stylesheets");
  44. exit;
  45. }
  46. // Database Table Definitions
  47. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  48. // setting breadcrumbs
  49. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  50. // setting the name of the tool
  51. $tool_name = get_lang('DokeosConfigSettings');
  52. // Build the form
  53. if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) {
  54. $form = new FormValidator('settings', 'post', 'settings.php?category='.$_GET['category']);
  55. $renderer = & $form->defaultRenderer();
  56. $renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
  57. $renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
  58. $my_category = Database::escape_string($_GET['category']);
  59. $sqlcountsettings = "SELECT COUNT(*) FROM $table_settings_current WHERE category='".$my_category."' AND type<>'checkbox'";
  60. $resultcountsettings = Database::query($sqlcountsettings);
  61. $countsetting = Database::fetch_array($resultcountsettings);
  62. if ($_configuration['access_url']==1) {
  63. $settings = api_get_settings($my_category,'group',$_configuration['access_url']);
  64. } else {
  65. $url_info = api_get_access_url($_configuration['access_url']);
  66. if ($url_info['active']==1) {
  67. //the default settings of Dokeos
  68. $settings = api_get_settings($my_category,'group',1,0);
  69. //the settings that are changeable from a particular site
  70. $settings_by_access = api_get_settings($my_category,'group',$_configuration['access_url'],1);
  71. //echo '<pre>';
  72. //print_r($settings_by_access);
  73. $settings_by_access_list=array();
  74. foreach($settings_by_access as $row)
  75. {
  76. if (empty($row['variable']))
  77. $row['variable']=0;
  78. if (empty($row['subkey']))
  79. $row['subkey']=0;
  80. if (empty($row['category']))
  81. $row['category']=0;
  82. // one more validation if is changeable
  83. if ($row['access_url_changeable']==1)
  84. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
  85. else
  86. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = array();
  87. }
  88. }
  89. }
  90. //print_r($settings_by_access_list);echo '</pre>';
  91. //$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC";
  92. //$resultsettings = Database::query($sqlsettings);
  93. //while ($row = Database::fetch_array($resultsettings))
  94. $default_values = array();
  95. foreach($settings as $row) {
  96. if ($row['variable'] == 'search_enabled') { continue; }
  97. $anchor_name = $row['variable'].(!empty($row['subkey']) ? '_'.$row['subkey'] : '');
  98. $form->addElement('html',"\n<a name=\"$anchor_name\"></a>\n");
  99. ($countsetting['0']%10) < 5 ?$b=$countsetting['0']-10:$b=$countsetting['0'];
  100. if ($i % 10 == 0 and $i<$b){
  101. $form->addElement('html','<div align="right">');
  102. $form->addElement('style_submit_button', null,get_lang('SaveSettings'), 'class="save"');
  103. $form->addElement('html','</div>');
  104. }
  105. $i++;
  106. $form->addElement('header', null, get_lang($row['title']));
  107. if ($row['access_url_changeable']=='1' && $_configuration['multiple_access_urls']==true) {
  108. $form->addElement('html', '<div style="float:right;">'.Display::return_icon('shared_setting.png',get_lang('SharedSettingIconComment')).'</div>');
  109. }
  110. $hideme=array();
  111. $hide_element=false;
  112. if ($_configuration['access_url']!=1)
  113. {
  114. if ($row['access_url_changeable']==0)
  115. {
  116. //we hide the element in other cases (checkbox, radiobutton) we 'freeze' the element
  117. $hide_element=true;
  118. $hideme=array('disabled');
  119. }
  120. elseif($url_info['active']==1)
  121. {
  122. // we show the elements
  123. if (empty($row['variable']))
  124. $row['variable']=0;
  125. if (empty($row['subkey']))
  126. $row['subkey']=0;
  127. if (empty($row['category']))
  128. $row['category']=0;
  129. if (is_array ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]))
  130. {
  131. // we are sure that the other site have a selected value
  132. if ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]['selected_value']!='')
  133. $row['selected_value'] =$settings_by_access_list[$row['variable']] [$row['subkey']] [ $row['category'] ]['selected_value'];
  134. }
  135. // there is no else because we load the default $row['selected_value'] of the main Dokeos site
  136. }
  137. }
  138. switch ($row['type']) {
  139. case 'textfield' :
  140. if ($row['variable']=='account_valid_duration') {
  141. $form->addElement('text', $row['variable'], get_lang($row['comment']),array('maxlength'=>'5'));
  142. $form->applyFilter($row['variable'],'html_filter');
  143. $default_values[$row['variable']] = $row['selected_value'];
  144. // For platform character set selection: Conversion of the textfield to a select box with valid values.
  145. } elseif ($row['variable'] == 'platform_charset') {
  146. $current_system_encoding = api_refine_encoding_id(trim($row['selected_value']));
  147. $valid_encodings = array_flip(api_get_valid_encodings());
  148. if (!isset($valid_encodings[$current_system_encoding])) {
  149. $is_alias_encoding = false;
  150. foreach ($valid_encodings as $encoding) {
  151. if (api_equal_encodings($encoding, $current_system_encoding)) {
  152. $is_alias_encoding = true;
  153. $current_system_encoding = $encoding;
  154. break;
  155. }
  156. }
  157. if (!$is_alias_encoding) {
  158. $valid_encodings[$current_system_encoding] = $current_system_encoding;
  159. }
  160. }
  161. foreach ($valid_encodings as $key => &$encoding) {
  162. if (api_is_encoding_supported($key) && Database::is_encoding_supported($key)) {
  163. $encoding = $key;
  164. } else {
  165. //$encoding = $key.' (n.a.)';
  166. unset($valid_encodings[$key]);
  167. }
  168. }
  169. $form->addElement('select', $row['variable'], get_lang($row['comment']), $valid_encodings);
  170. $default_values[$row['variable']] = $current_system_encoding;
  171. //
  172. } else {
  173. $form->addElement('text', $row['variable'], get_lang($row['comment']),$hideme);
  174. $form->applyFilter($row['variable'],'html_filter');
  175. $default_values[$row['variable']] = $row['selected_value'];
  176. }
  177. break;
  178. case 'textarea' :
  179. $form->addElement('textarea', $row['variable'], get_lang($row['comment']),$hideme);
  180. $default_values[$row['variable']] = $row['selected_value'];
  181. break;
  182. case 'radio' :
  183. $values = get_settings_options($row['variable']);
  184. $group = array ();
  185. if (is_array($values )) {
  186. foreach ($values as $key => $value) {
  187. $element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
  188. if ($hide_element) {
  189. $element->freeze();
  190. }
  191. $group[] = $element;
  192. }
  193. }
  194. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />', false);
  195. $default_values[$row['variable']] = $row['selected_value'];
  196. break;
  197. case 'checkbox';
  198. //1. we collect all the options of this variable
  199. $sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."' AND access_url = 1";
  200. $result = Database::query($sql);
  201. $group = array ();
  202. while ($rowkeys = Database::fetch_array($result)) {
  203. if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') {continue;}
  204. // profile tab option hide, if the social tool is enabled
  205. if (api_get_setting('allow_social_tool') == 'true') {
  206. if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') {continue;}
  207. }
  208. $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
  209. if ($row['access_url_changeable']==1) {
  210. //2. we look into the DB if there is a setting for a specific access_url
  211. $access_url = $_configuration['access_url'];
  212. if(empty($access_url )) $access_url =1;
  213. $sql = "SELECT selected_value FROM settings_current WHERE variable='".$rowkeys['variable']."' AND subkey='".$rowkeys['subkey']."' AND subkeytext='".$rowkeys['subkeytext']."' AND access_url = $access_url";
  214. $result_access = Database::query($sql);
  215. $row_access = Database::fetch_array($result_access);
  216. if ($row_access['selected_value'] == 'true' && ! $form->isSubmitted()) {
  217. $element->setChecked(true);
  218. }
  219. } else {
  220. if ($rowkeys['selected_value'] == 'true' && ! $form->isSubmitted()) {
  221. $element->setChecked(true);
  222. }
  223. }
  224. if ($hide_element) {
  225. $element->freeze();
  226. }
  227. $group[] = $element;
  228. }
  229. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />'."\n");
  230. break;
  231. case "link" :
  232. $form->addElement('static', null, get_lang($row['comment']), get_lang('CurrentValue').' : '.$row['selected_value'], $hideme);
  233. break;
  234. /*
  235. * To populate its list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed
  236. * The functions being called must be added to the file settings.lib.php
  237. */
  238. case "select":
  239. $form->addElement('select', $row['variable'], get_lang($row['comment']), call_user_func('select_'.$row['variable']), $hideme);
  240. $default_values[$row['variable']] = $row['selected_value'];
  241. break;
  242. }
  243. }
  244. $form->addElement('html','<div align="right">');
  245. $form->addElement('style_submit_button', null,get_lang('SaveSettings'), 'class="save"');
  246. $form->addElement('html','</div>');
  247. $form->setDefaults($default_values);
  248. if ($form->validate())
  249. {
  250. $values = $form->exportValues();
  251. // set true for allow_message_tool variable if social tool is actived
  252. if ($values['allow_social_tool'] == 'true') {
  253. $values['allow_message_tool'] = 'true';
  254. }
  255. // the first step is to set all the variables that have type=checkbox of the category
  256. // to false as the checkbox that is unchecked is not in the $_POST data and can
  257. // therefore not be set to false.
  258. // This, however, also means that if the process breaks on the third of five checkboxes, the others
  259. // will be set to false.
  260. $r = api_set_settings_category($my_category,'false',$_configuration['access_url'],array('checkbox','radio'));
  261. //$sql = "UPDATE $table_settings_current SET selected_value='false' WHERE category='$my_category' AND type='checkbox'";
  262. //$result = Database::query($sql);
  263. // Save the settings
  264. $keys = array();
  265. foreach ($values as $key => $value)
  266. {
  267. if (!is_array($value))
  268. {
  269. //$sql = "UPDATE $table_settings_current SET selected_value='".Database::escape_string($value)."' WHERE variable='$key'";
  270. //$result = Database::query($sql);
  271. if (api_get_setting($key) != $value) $keys[] = $key;
  272. $result = api_set_setting($key,$value,null,null,$_configuration['access_url']);
  273. }
  274. else
  275. {
  276. $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
  277. $res = Database::query($sql);
  278. $subkeys = array();
  279. while ($row_subkeys = Database::fetch_array($res)) {
  280. // if subkey is changed
  281. if ( (isset($value[$row_subkeys['subkey']]) && api_get_setting($key,$row_subkeys['subkey']) == 'false') ||
  282. (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key,$row_subkeys['subkey']) == 'true')) {
  283. $keys[] = $key;
  284. break;
  285. }
  286. }
  287. foreach ($value as $subkey => $subvalue)
  288. {
  289. //$sql = "UPDATE $table_settings_current SET selected_value='true' WHERE variable='$key' AND subkey = '$subkey'";
  290. //$result = Database::query($sql);
  291. $result = api_set_setting($key,'true',$subkey,null,$_configuration['access_url']);
  292. }
  293. }
  294. }
  295. // add event configuration settings category to system log
  296. $time = time();
  297. $user_id = api_get_user_id();
  298. $category = $_GET['category'];
  299. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
  300. // add event configuration settings variable to system log
  301. if (is_array($keys) && count($keys) > 0) {
  302. foreach($keys as $variable) {
  303. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_VARIABLE, $variable, $time, $user_id);
  304. }
  305. }
  306. header('Location: settings.php?action=stored&category='.Security::remove_XSS($_GET['category']));
  307. exit;
  308. }
  309. }
  310. // including the header (banner)
  311. Display :: display_header($tool_name);
  312. //api_display_tool_title($tool_name);
  313. // displaying the message that the settings have been stored
  314. if (!empty($_GET['action']) && $_GET['action'] == "stored")
  315. {
  316. Display :: display_confirmation_message(get_lang('SettingsStored'));
  317. }
  318. // the action images
  319. $action_images['platform'] = 'logo.gif';
  320. $action_images['course'] = 'course.gif';
  321. $action_images['tools'] = 'reference.gif';
  322. $action_images['user'] = 'students.gif';
  323. $action_images['gradebook'] = 'gradebook_eval_not_empty.gif';
  324. $action_images['ldap'] = 'loginmanager.gif';
  325. $action_images['security'] = 'passwordprotected.gif';
  326. $action_images['languages'] = 'forum.gif';
  327. $action_images['tuning'] = 'tuning.gif';
  328. $action_images['plugins'] = 'plugin.gif';
  329. $action_images['stylesheets'] = 'theme.gif';
  330. $action_images['templates'] = 'template.gif';
  331. $action_images['search'] = 'search.gif';
  332. $action_images['editor'] = 'html.png';
  333. $action_images['timezones'] = 'timezones.png';
  334. // grabbing the categories
  335. //$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')";
  336. //$resultcategories = Database::query($selectcategories);
  337. $resultcategories = api_get_settings_categories(array('stylesheets','Plugins', 'Templates', 'Search'));
  338. echo "\n<div class=\"actions\">";
  339. //while ($row = Database::fetch_array($resultcategories))
  340. foreach($resultcategories as $row)
  341. {
  342. echo "\n\t<a href=\"".api_get_self()."?category=".$row['category']."\">".Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category']))).api_ucfirst(get_lang($row['category']))."</a>";
  343. }
  344. echo "\n\t<a href=\"".api_get_self()."?category=Plugins\">".Display::return_icon($action_images['plugins'], api_ucfirst(get_lang('Plugins'))).api_ucfirst(get_lang('Plugins'))."</a>";
  345. echo "\n\t<a href=\"".api_get_self()."?category=stylesheets\">".Display::return_icon($action_images['stylesheets'], api_ucfirst(get_lang('Stylesheets'))).api_ucfirst(get_lang('Stylesheets'))."</a>";
  346. echo "\n\t<a href=\"".api_get_self()."?category=Templates\">".Display::return_icon($action_images['templates'], api_ucfirst(get_lang('Templates'))).api_ucfirst(get_lang('Templates'))."</a>";
  347. echo "\n\t<a href=\"".api_get_self()."?category=Search\">".Display::return_icon($action_images['search'], api_ucfirst(get_lang('Search'))).api_ucfirst(get_lang('Search'))."</a>";
  348. echo "\n</div>";
  349. if (!empty($_GET['category']))
  350. {
  351. switch ($_GET['category'])
  352. {
  353. // displaying the extensions: plugins
  354. // this will be available to all the sites (access_urls)
  355. case 'Plugins' :
  356. if (isset($_POST['submit_dashboard_plugins'])) {
  357. $affected_rows = DashboardManager::store_dashboard_plugins($_POST);
  358. if ($affected_rows) {
  359. // add event to system log
  360. $time = time();
  361. $user_id = api_get_user_id();
  362. $category = $_GET['category'];
  363. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
  364. Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
  365. }
  366. }
  367. handle_plugins();
  368. DashboardManager::handle_dashboard_plugins();
  369. break;
  370. // displaying the extensions: Stylesheets
  371. case 'stylesheets' :
  372. handle_stylesheets();
  373. break;
  374. case 'Search' :
  375. handle_search();
  376. break;
  377. case 'Templates' :
  378. handle_templates();
  379. break;
  380. default :
  381. $form->display();
  382. }
  383. }
  384. /*
  385. ==============================================================================
  386. FOOTER
  387. ==============================================================================
  388. */
  389. Display :: display_footer();