diff --git a/main/admin/settings.lib.php b/main/admin/settings.lib.php index c2c977cb6c..307e4f9335 100755 --- a/main/admin/settings.lib.php +++ b/main/admin/settings.lib.php @@ -111,18 +111,18 @@ function handle_plugins() { $plugin_obj = new AppPlugin(); $token = Security::get_token(); - if (isset($_POST['submit_plugins'])) { + if (isset($_POST['submit_plugins'])) { store_plugins(); // Add event to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; - event_system( - LOG_CONFIGURATION_SETTINGS_CHANGE, - LOG_CONFIGURATION_SETTINGS_CATEGORY, - $category, - api_get_utc_datetime(), - $user_id - ); + event_system( + LOG_CONFIGURATION_SETTINGS_CHANGE, + LOG_CONFIGURATION_SETTINGS_CATEGORY, + $category, + api_get_utc_datetime(), + $user_id + ); Display :: display_confirmation_message(get_lang('SettingsStored')); } @@ -175,12 +175,12 @@ function handle_plugins() echo '
'; if (in_array($plugin, $installed_plugins)) { - echo Display::url(get_lang('Configure'), 'configure_plugin.php?name='.$plugin, array('class' => 'btn')); - echo Display::url(get_lang('Regions'), 'settings.php?category=Regions&name='.$plugin, array('class' => 'btn')); + echo Display::url(get_lang('Configure'), 'configure_plugin.php?name='.$plugin, array('class' => 'btn')); + echo Display::url(get_lang('Regions'), 'settings.php?category=Regions&name='.$plugin, array('class' => 'btn')); } if (file_exists(api_get_path(SYS_PLUGIN_PATH).$plugin.'/readme.txt')) { - echo Display::url("readme.txt", api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt", array('class' => 'btn ajax', '_target' => '_blank')); + echo Display::url("readme.txt", api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt", array('class' => 'btn ajax', '_target' => '_blank')); } echo '
'; echo ''; @@ -198,7 +198,7 @@ function handle_plugins() * This function allows the platform admin to choose the default stylesheet * @author Patrick Cool , Ghent University * @author Julio Montoya , Chamilo -*/ + */ function handle_stylesheets() { global $_configuration; @@ -219,7 +219,6 @@ function handle_stylesheets() } $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets#tabs-2'); - //$form->addElement('header', get_lang('UploadNewStylesheet')); $form->addElement('text', 'name_stylesheet', get_lang('NameStylesheet'), array('size' => '40', 'maxlength' => '40')); $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet')); @@ -256,7 +255,13 @@ function handle_stylesheets() // Add event to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; - event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); + event_system( + LOG_CONFIGURATION_SETTINGS_CHANGE, + LOG_CONFIGURATION_SETTINGS_CATEGORY, + $category, + api_get_utc_datetime(), + $user_id + ); if ($result) { Display::display_confirmation_message(get_lang('StylesheetAdded')); @@ -467,7 +472,7 @@ function upload_stylesheet($values, $picture) */ function store_regions() { - $plugin_obj = new AppPlugin(); + $plugin_obj = new AppPlugin(); // Get a list of all current 'Plugins' settings $installed_plugins = $plugin_obj->get_installed_plugins(); @@ -502,7 +507,7 @@ function store_regions() /** * This function allows easy activating and inactivating of plugins * @author Patrick Cool , Ghent University -*/ + */ function store_plugins() { $appPlugin = new AppPlugin(); @@ -533,7 +538,7 @@ function store_plugins() /** * This function allows the platform admin to choose which should be the default stylesheet * @author Patrick Cool , Ghent University -*/ + */ function store_stylesheets() { // Insert the stylesheet. @@ -613,7 +618,7 @@ function handle_search() $sf_values = array(); foreach ($specific_fields as $sf) { - $sf_values[$sf['code']] = $sf['name']; + $sf_values[$sf['code']] = $sf['name']; } $group = array(); $url = Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class'=>'sectioncomment')); @@ -970,34 +975,34 @@ function add_edit_template() { } $temp->send_image($upload_dir.$new_file_name); } - } - - // Store the information in the database (as insert or as update). - $table_system_template = Database :: get_main_table('system_template'); - if ($_GET['action'] == 'add') { - $content_template = '{CSS}'.Database::escape_string($values['template_text']).''; - $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string($values['title'])."','".$content_template."','".Database::escape_string($new_file_name)."')"; - Database::query($sql); - - // Display a feedback message. - Display::display_confirmation_message(get_lang('TemplateAdded')); - echo ''.Display::return_icon('new_template.png', get_lang('AddTemplate'),'',ICON_SIZE_MEDIUM).''; - } else { - $content_template = '{CSS}'.Database::escape_string($values['template_text']).''; - $sql = "UPDATE $table_system_template set title = '".Database::escape_string($values['title'])."', content = '".$content_template."'"; - if (!empty($new_file_name)) { - $sql .= ", image = '".Database::escape_string($new_file_name)."'"; - } - $sql .= " WHERE id = ".intval($_GET['id']).""; - Database::query($sql); - - // Display a feedback message. - Display::display_confirmation_message(get_lang('TemplateEdited')); - } + } + + // Store the information in the database (as insert or as update). + $table_system_template = Database :: get_main_table('system_template'); + if ($_GET['action'] == 'add') { + $content_template = '{CSS}'.Database::escape_string($values['template_text']).''; + $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string($values['title'])."','".$content_template."','".Database::escape_string($new_file_name)."')"; + Database::query($sql); + + // Display a feedback message. + Display::display_confirmation_message(get_lang('TemplateAdded')); + echo ''.Display::return_icon('new_template.png', get_lang('AddTemplate'),'',ICON_SIZE_MEDIUM).''; + } else { + $content_template = '{CSS}'.Database::escape_string($values['template_text']).''; + $sql = "UPDATE $table_system_template set title = '".Database::escape_string($values['title'])."', content = '".$content_template."'"; + if (!empty($new_file_name)) { + $sql .= ", image = '".Database::escape_string($new_file_name)."'"; + } + $sql .= " WHERE id = ".intval($_GET['id']).""; + Database::query($sql); + + // Display a feedback message. + Display::display_confirmation_message(get_lang('TemplateEdited')); + } } - Security::clear_token(); - display_templates(); + Security::clear_token(); + display_templates(); } else { @@ -1118,7 +1123,7 @@ function generate_settings_form($settings, $settings_by_access_list) { $i = 0; foreach ($settings as $row) { - if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; } + if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; } if (!empty($_configuration['multiple_access_urls'])) { if (api_is_global_platform_admin()) { @@ -1126,18 +1131,18 @@ function generate_settings_form($settings, $settings_by_access_list) { if ($url_id == 1) { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '
'); + Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).''); } else { $form->addElement('html', '
'); + Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).''); } } else { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '
'. - Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).'
'); + Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).''); } else { $form->addElement('html', '
'. - Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).'
'); + Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).''); } } } @@ -1216,25 +1221,25 @@ function generate_settings_form($settings, $settings_by_access_list) { break; case 'textarea': if ($row['variable'] == 'header_extra_content') { - $file = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt'; + $file = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt'; $value = ''; if (file_exists($file)) { $value = file_get_contents($file); } $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('class'=>'span6','rows'=>'10'), $hideme); - $default_values[$row['variable']] = $value; + $default_values[$row['variable']] = $value; } elseif ($row['variable'] == 'footer_extra_content') { - $file = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt'; - $value = ''; - if (file_exists($file)) { - $value = file_get_contents($file); - } - $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10', 'class'=>'span6'), $hideme); - $default_values[$row['variable']] = $value; - } else { - $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','class'=>'span6'), $hideme); - $default_values[$row['variable']] = $row['selected_value']; - } + $file = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt'; + $value = ''; + if (file_exists($file)) { + $value = file_get_contents($file); + } + $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10', 'class'=>'span6'), $hideme); + $default_values[$row['variable']] = $value; + } else { + $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','class'=>'span6'), $hideme); + $default_values[$row['variable']] = $row['selected_value']; + } break; case 'radio': $values = api_get_settings_options($row['variable']); @@ -1258,15 +1263,15 @@ function generate_settings_form($settings, $settings_by_access_list) { $result = Database::query($sql); $group = array (); while ($rowkeys = Database::fetch_array($result)) { - //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; } + //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; } - // Profile tab option should be hidden when the social tool is enabled. - if (api_get_setting('allow_social_tool') == 'true') { - if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; } - } + // Profile tab option should be hidden when the social tool is enabled. + if (api_get_setting('allow_social_tool') == 'true') { + if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; } + } - // Hiding the gradebook option. - if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; } + // Hiding the gradebook option. + if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; } $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext'])); if ($row['access_url_changeable'] == 1) { @@ -1303,7 +1308,7 @@ function generate_settings_form($settings, $settings_by_access_list) { $default_values[$row['variable']] = $row['selected_value']; break; case 'custom': - break; + break; } switch ($row['variable']) { diff --git a/main/admin/settings.php b/main/admin/settings.php index e1c3719473..19428c4bf7 100755 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -10,8 +10,6 @@ * @package chamilo.admin */ -/* INIT SECTION */ - // Language files that need to be included. if (isset($_GET['category']) && $_GET['category'] == 'Templates') { $language_file = array('admin', 'document'); @@ -45,7 +43,12 @@ $settings_to_avoid = array( 'example_material_course_creation' => 'true' // ON by default - now we have this option when we create a course ); -$convert_byte_to_mega_list = array('dropbox_max_filesize', 'message_max_upload_filesize', 'default_document_quotum', 'default_group_quotum'); +$convert_byte_to_mega_list = array( + 'dropbox_max_filesize', + 'message_max_upload_filesize', + 'default_document_quotum', + 'default_group_quotum' +); if (isset($_POST['style'])) { Display::$preview_style = $_POST['style']; @@ -68,8 +71,8 @@ if (isset($_GET['delete_watermark'])) { } if (isset($_GET['action']) && $_GET['action'] == 'delete_grading') { - $id = intval($_GET['id']); - api_delete_setting_option($id); + $id = intval($_GET['id']); + api_delete_setting_option($id); } $form_search = new FormValidator('search_settings', 'get', api_get_self() , null, array('class'=>'well form-inline')); @@ -119,11 +122,16 @@ function get_settings($category = null) { $settings = search_setting($_REQUEST['search_field']); } } - return array('settings' => $settings, 'settings_by_access_list' => $settings_by_access_list); + return array( + 'settings' => $settings, + 'settings_by_access_list' => $settings_by_access_list + ); } // Build the form. -if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) { +if (!empty($_GET['category']) && + !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search')) +) { $my_category = isset($_GET['category']) ? $_GET['category'] : null; $settings_array = get_settings($my_category); $settings = $settings_array['settings']; @@ -139,11 +147,15 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', ' $un_mark_all = false; if (api_is_multiple_url_enabled()) { - if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['mark_all'])) { + if (isset($values['buttons_in_action_right']) && + isset($values['buttons_in_action_right']['mark_all']) + ) { $mark_all = true; } - if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['unmark_all'])) { + if (isset($values['buttons_in_action_right']) && + isset($values['buttons_in_action_right']['unmark_all']) + ) { $un_mark_all = true; } } @@ -174,7 +186,10 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', ' $settings_array = get_settings($my_category); $settings = $settings_array['settings']; $settings_by_access_list = $settings_array['settings_by_access_list']; - $form = generate_settings_form($settings, $settings_by_access_list); + $form = generate_settings_form( + $settings, + $settings_by_access_list + ); } } if (!empty($_FILES['pdf_export_watermark_path'])) { @@ -182,7 +197,10 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', ' } if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) { - $pdf_export_watermark_path_result = PDF::upload_watermark($pdf_export_watermark_path['name'], $pdf_export_watermark_path['tmp_name']); + $pdf_export_watermark_path_result = PDF::upload_watermark( + $pdf_export_watermark_path['name'], + $pdf_export_watermark_path['tmp_name'] + ); if ($pdf_export_watermark_path_result) { $message['confirmation'][] = get_lang('UplUploadSucceeded'); } else { @@ -193,16 +211,15 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', ' // Set true for allow_message_tool variable if social tool is actived foreach ($convert_byte_to_mega_list as $item) { - if (isset($values[$item])) { - $values[$item] = round($values[$item]*1024*1024); - } - } + if (isset($values[$item])) { + $values[$item] = round($values[$item]*1024*1024); + } + } if (isset($values['allow_social_tool']) && $values['allow_social_tool'] == 'true') { $values['allow_message_tool'] = 'true'; } - // The first step is to set all the variables that have type=checkbox of the category // to false as the checkbox that is unchecked is not in the $_POST data and can // therefore not be set to false. @@ -225,96 +242,115 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', ' foreach ($settings as $item) { $key = $item['variable']; - if (in_array($key, $settings_to_avoid)) { continue; } - if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; } + if (in_array($key, $settings_to_avoid)) { + continue; + } + if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { + continue; + } $key = Database::escape_string($key); - $sql = "UPDATE $table_settings_current SET selected_value = 'false' WHERE variable = '".$key."' AND access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') "; + $sql = "UPDATE $table_settings_current + SET selected_value = 'false' + WHERE variable = '".$key."' AND access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') "; $res = Database::query($sql); } - /*foreach($settings_to_avoid as $key => $value) { - api_set_setting($key, $value, null, null, $_configuration['access_url']); - }*/ - // Save the settings. $keys = array(); foreach ($values as $key => $value) { - if (strcmp($key,'MAX_FILE_SIZE')===0) { continue; } - if (in_array($key, $settings_to_avoid)) { continue; } + if (strcmp($key, 'MAX_FILE_SIZE') === 0) { + continue; + } + if (in_array($key, $settings_to_avoid)) { + continue; + } // Avoid form elements which have nothing to do with settings - if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; } + if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { + continue; + } // Treat gradebook values in separate function. //if (strpos($key, 'gradebook_score_display_custom_values') === false) { - if (!is_array($value)) { - $old_value = api_get_setting($key); - switch ($key) { - case 'header_extra_content': - file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value); - $value = api_get_home_path().'/header_extra_content.txt'; - break; - case 'footer_extra_content': - file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt', $value); - $value = api_get_home_path().'/footer_extra_content.txt'; - break; - // URL validation for some settings. - case 'InstitutionUrl': - case 'course_validation_terms_and_conditions_url': - $value = trim(Security::remove_XSS($value)); - if ($value != '') { - // Here we accept absolute URLs only. - if (strpos($value, '://') === false) { - $value = 'http://'.$value; - } - if (!api_valid_url($value, true)) { - // If the new (non-empty) URL value is invalid, then the old URL value stays. - $value = $old_value; - } + if (!is_array($value)) { + $old_value = api_get_setting($key); + switch ($key) { + case 'header_extra_content': + file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value); + $value = api_get_home_path().'/header_extra_content.txt'; + break; + case 'footer_extra_content': + file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt', $value); + $value = api_get_home_path().'/footer_extra_content.txt'; + break; + // URL validation for some settings. + case 'InstitutionUrl': + case 'course_validation_terms_and_conditions_url': + $value = trim(Security::remove_XSS($value)); + if ($value != '') { + // Here we accept absolute URLs only. + if (strpos($value, '://') === false) { + $value = 'http://'.$value; } - // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted). - break; - - // Validation against e-mail address for some settings. - case 'emailAdministrator': - $value = trim(Security::remove_XSS($value)); - if ($value != '' && !api_valid_email($value)) { - // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays. - // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted). + if (!api_valid_url($value, true)) { + // If the new (non-empty) URL value is invalid, then the old URL value stays. $value = $old_value; } - break; - } - if ($old_value != $value) $keys[] = $key; - $result = api_set_setting($key, $value, null, null, $url_id); - } else { - $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'"; - $res = Database::query($sql); - while ($row_subkeys = Database::fetch_array($res)) { - // If subkey is changed: - if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') || - (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) { - $keys[] = $key; - break; } + // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted). + break; + + // Validation against e-mail address for some settings. + case 'emailAdministrator': + $value = trim(Security::remove_XSS($value)); + if ($value != '' && !api_valid_email($value)) { + // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays. + // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted). + $value = $old_value; + } + break; + } + if ($old_value != $value) $keys[] = $key; + $result = api_set_setting($key, $value, null, null, $url_id); + } else { + $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'"; + $res = Database::query($sql); + while ($row_subkeys = Database::fetch_array($res)) { + // If subkey is changed: + if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') || + (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) { + $keys[] = $key; + break; } - foreach ($value as $subkey => $subvalue) { - $result = api_set_setting($key, 'true', $subkey, null, $url_id); - } - } + foreach ($value as $subkey => $subvalue) { + $result = api_set_setting($key, 'true', $subkey, null, $url_id); + } + } } // Add event configuration settings category to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; - event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); + event_system( + LOG_CONFIGURATION_SETTINGS_CHANGE, + LOG_CONFIGURATION_SETTINGS_CATEGORY, + $category, + api_get_utc_datetime(), + $user_id + ); // Add event configuration settings variable to the system log. if (is_array($keys) && count($keys) > 0) { foreach ($keys as $variable) { if (in_array($key, $settings_to_avoid)) { continue; } - event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_VARIABLE, $variable, api_get_utc_datetime(), $user_id); + event_system( + LOG_CONFIGURATION_SETTINGS_CHANGE, + LOG_CONFIGURATION_SETTINGS_VARIABLE, + $variable, + api_get_utc_datetime(), + $user_id + ); } } } @@ -401,7 +437,6 @@ $resultcategories[] = array('category' => 'CAS'); $resultcategories[] = array('category' => 'Shibboleth'); $resultcategories[] = array('category' => 'Facebook'); - foreach ($resultcategories as $row) { $url = array(); $url['url'] = api_get_self()."?category=".$row['category']; @@ -413,9 +448,7 @@ foreach ($resultcategories as $row) { } echo Display::actions($action_array); - echo '
'; - echo $form_search_html; if ($watermark_deleted) { @@ -461,23 +494,23 @@ if (!empty($_GET['category'])) { }); '; echo '
'; - echo ''; - - echo '
'; - handle_plugins(); - echo '
'; - - echo '
'; - DashboardManager::handle_dashboard_plugins(); - echo '
'; - - echo '
'; - handle_extensions(); - echo '
'; + echo ''; + + echo '
'; + handle_plugins(); + echo '
'; + + echo '
'; + DashboardManager::handle_dashboard_plugins(); + echo '
'; + + echo '
'; + handle_extensions(); + echo '
'; echo '
'; break; case 'Stylesheets':