function generate_settings_form($settings, $settings_by_access_list) { global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list; $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $form = new FormValidator('settings', 'post', 'settings.php?category=' . Security::remove_XSS($_GET['category'])); $form->addElement('hidden', 'search_field', !empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null); $url_id = api_get_current_access_url_id(); if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) { $group = array(); $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll')); $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll')); $form->addGroup($group, 'buttons_in_action_right'); } $default_values = array(); $url_info = api_get_access_url($url_id); $i = 0; foreach ($settings as $row) { if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; } if (!empty($_configuration['multiple_access_urls'])) { if (api_is_global_platform_admin()) { if ($row['access_url_locked'] == 0) { if ($url_id == 1) { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "0" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</a></div>'); } else { $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "1" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</a></div>'); } } else { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</div>'); } else { $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</div>'); } } } } } $hideme = array(); $hide_element = false; if ($_configuration['access_url'] != 1) { if ($row['access_url_changeable'] == 0) { // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element. $hide_element = true; $hideme = array('disabled'); } elseif ($url_info['active'] == 1) { // We show the elements. if (empty($row['variable'])) { $row['variable'] = 0; } if (empty($row['subkey'])) { $row['subkey'] = 0; } if (empty($row['category'])) { $row['category'] = 0; } if (is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])) { // We are sure that the other site have a selected value. if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') { $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value']; } } // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site. } } switch ($row['type']) { case 'textfield': if (in_array($row['variable'], $convert_byte_to_mega_list)) { $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('class' => 'span1', 'maxlength' => '8')); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1); } elseif ($row['variable'] == 'account_valid_duration') { $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('maxlength' => '5')); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = $row['selected_value']; // For platform character set selection: Conversion of the textfield to a select box with valid values. } elseif ($row['variable'] == 'platform_charset') { $current_system_encoding = api_refine_encoding_id(trim($row['selected_value'])); $valid_encodings = array_flip(api_get_valid_encodings()); if (!isset($valid_encodings[$current_system_encoding])) { $is_alias_encoding = false; foreach ($valid_encodings as $encoding) { if (api_equal_encodings($encoding, $current_system_encoding)) { $is_alias_encoding = true; $current_system_encoding = $encoding; break; } } if (!$is_alias_encoding) { $valid_encodings[$current_system_encoding] = $current_system_encoding; } } foreach ($valid_encodings as $key => &$encoding) { if (api_is_encoding_supported($key) && Database::is_encoding_supported($key)) { $encoding = $key; } else { unset($valid_encodings[$key]); } } $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $valid_encodings); $default_values[$row['variable']] = $current_system_encoding; } else { $hideme['class'] = 'span4'; $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $hideme); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = $row['selected_value']; } break; case 'textarea': if ($row['variable'] == 'header_extra_content') { $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; } 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']; } break; case 'radio': $values = api_get_settings_options($row['variable']); $group = array(); if (is_array($values)) { foreach ($values as $key => $value) { $element =& $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']); if ($hide_element) { $element->freeze(); } $group[] = $element; } } $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '', false); //julio $default_values[$row['variable']] = $row['selected_value']; break; case 'checkbox': // 1. We collect all the options of this variable. $sql = "SELECT * FROM {$table_settings_current} WHERE variable='" . $row['variable'] . "' AND access_url = 1"; $result = Database::query($sql); $group = array(); while ($rowkeys = Database::fetch_array($result)) { //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; } } // 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) { // 2. We look into the DB if there is a setting for a specific access_url. $access_url = $_configuration['access_url']; if (empty($access_url)) { $access_url = 1; } $sql = "SELECT selected_value FROM {$table_settings_current} WHERE variable='" . $rowkeys['variable'] . "' AND subkey='" . $rowkeys['subkey'] . "' AND subkeytext='" . $rowkeys['subkeytext'] . "' AND access_url = {$access_url}"; $result_access = Database::query($sql); $row_access = Database::fetch_array($result_access); if ($row_access['selected_value'] == 'true' && !$form->isSubmitted()) { $element->setChecked(true); } } else { if ($rowkeys['selected_value'] == 'true' && !$form->isSubmitted()) { $element->setChecked(true); } } if ($hide_element) { $element->freeze(); } $group[] = $element; } $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), ''); break; case 'link': $form->addElement('static', null, array(get_lang($row['title']), get_lang($row['comment'])), get_lang('CurrentValue') . ' : ' . $row['selected_value'], $hideme); break; case 'select': /* * To populate the list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed. * The functions being called must be added to the file settings.lib.php. */ $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_' . $row['variable']), $hideme); $default_values[$row['variable']] = $row['selected_value']; break; case 'custom': break; } switch ($row['variable']) { case 'pdf_export_watermark_enable': $url = PDF::get_watermark(null); if ($url != false) { $delete_url = '<a href="?delete_watermark">' . get_lang('DelImage') . ' ' . Display::return_icon('delete.png', get_lang('DelImage')) . '</a>'; $form->addElement('html', '<div style="max-height:100px; max-width:100px; margin-left:162px; margin-bottom:10px; clear:both;"><img src="' . $url . '" style="margin-bottom:10px;" />' . $delete_url . '</div>'); } $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark')); $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif'); $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types); break; case 'timezone_value': $timezone = $row['selected_value']; if (empty($timezone)) { $timezone = _api_get_timezone(); } $form->addElement('html', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time())); break; } } // end for if (!empty($settings)) { $form->setDefaults($default_values); } $form->addElement('button', 'submit_fixed_in_bottom', get_lang('SaveSettings'), 'class="save"'); return $form; }