1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
30: function renderSelectProperty($name, $possibleValues, $value, $label) {
31: global $auth;
32:
33: if (count($possibleValues) === 2 && (in_array('true', $possibleValues) && in_array('false', $possibleValues) || in_array('enabled', $possibleValues) && in_array('disabled', $possibleValues) || in_array('0', $possibleValues) && in_array('1', $possibleValues))) {
34:
35: $checked = $value == 'true' || $value == '1' || $value == 'enabled';
36: $html = new cHTMLCheckbox($name, $possibleValues[0], $name, $checked);
37: $html->setLabelText($label);
38: } else {
39:
40: $html = new cHTMLSelectElement('');
41: foreach ($possibleValues as $possibleValue) {
42: $element = new cHTMLOptionElement($possibleValue, $possibleValue);
43: if ($possibleValue == $value) {
44: $element->setSelected(true);
45: }
46: $html->appendOptionElement($element);
47: }
48: }
49:
50:
51: if (strpos($auth->auth['perm'], 'sysadmin') === false) {
52: $html->updateAttribute('disabled', 'true');
53: }
54:
55: $return = array();
56: $return['input'] = $html->render();
57: $return['label'] = '';
58:
59: return $return;
60: }
61:
62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
72: function renderLabel($text, $name, $width = 250, $seperator = ':') {
73: $label = new cHTMLLabel($text . $seperator, $name);
74: $label->setStyle('padding:3px;display:block;float:left;width:' . $width . 'px;');
75:
76: return $label->render();
77: }
78:
79: 80: 81: 82: 83: 84: 85: 86: 87:
88: function renderTextProperty($name, $value, $label) {
89: global $auth;
90:
91: $textbox = new cHTMLTextbox($name, $value, '50', '96');
92:
93: if (strpos($auth->auth['perm'], 'sysadmin') === false) {
94: $textbox->updateAttribute('disabled', 'true');
95: }
96: $return = array();
97: $return['input'] = $textbox->render();
98: $return['label'] = renderLabel($label, $name);
99:
100: return $return;
101: }
102:
103: $page = new cGuiPage('system_configuration', '', '1');
104:
105:
106: $propertyTypes = cXmlReader::xmlStringToArray(cFileHandler::read($cfg['path']['xml'] . 'system.xml'));
107: $propertyTypes = $propertyTypes['properties'];
108:
109:
110: $settings = getSystemProperties();
111:
112:
113: if (isset($_POST['action']) && $_POST['action'] == 'edit_sysconf' && $perm->have_perm_area_action($area, 'edit_sysconf')) {
114: if (strpos($auth->auth['perm'], 'sysadmin') === false) {
115: $page->displayError(i18n('You don\'t have the permission to make changes here.'));
116: } else {
117: $stored = false;
118: foreach ($propertyTypes as $type => $properties) {
119: foreach ($properties as $name => $infos) {
120:
121: $fieldName = $type . '{_}' . $name;
122: if (isset($_POST[$fieldName])) {
123: $value = $_POST[$fieldName];
124: } else {
125: $value = (isset($infos['values'][1])) ? $infos['values'][1] : 'false';
126: }
127:
128: $storedValue = $settings[$type][$name];
129: if ($storedValue != $value && (is_array($infos['values']) && $value != '' || !is_array($infos['values']))) {
130: if ($type == 'update' && $name == 'check_period' && $value < 60) {
131: $page->displayError(i18n('Update check period must be at least 60 minutes.'));
132: $stored = false;
133:
134: break 2;
135: } else {
136: setSystemProperty($type, $name, $value);
137:
138: $settings[$type][$name] = $value;
139: $stored = true;
140: }
141: }
142: }
143: }
144: if ($stored) {
145: $page->displayInfo(i18n('Changes saved'));
146: }
147: }
148: }
149:
150:
151: $form = new cGuiTableForm('system_configuration');
152: $form->addHeader(i18n('System configuration'));
153: $form->setVar('area', $area);
154: $form->setVar('frame', $frame);
155: $form->setVar('action', 'edit_sysconf');
156:
157:
158: if (strpos($auth->auth['perm'], 'sysadmin') === false) {
159: $form->setActionButton('submit', cRegistry::getBackendUrl() . 'images/but_ok_off.gif', i18n('Save changes'), 's');
160: }
161:
162: $groups = array();
163: $currentGroup = '';
164: $leftContent = '';
165:
166: foreach ($propertyTypes as $type => $properties) {
167: foreach ($properties as $name => $infos) {
168:
169:
170: if (!isset($groups[$infos['group']])) {
171: $groups[$infos['group']] = '';
172: }
173:
174:
175: if (isset($settings[$type][$name])) {
176: $value = $settings[$type][$name];
177: } else {
178: $value = '';
179: }
180:
181:
182: $fieldName = $type . '{_}' . $name;
183: if (is_array($infos['values'])) {
184: $htmlElement = renderSelectProperty($fieldName, $infos['values'], $value, i18n($infos['label']));
185: } else {
186: $htmlElement = renderTextProperty($fieldName, $value, i18n($infos['label']));
187: }
188:
189: $groups[$infos['group']] .= new cHTMLDiv($htmlElement['label'] . $htmlElement['input'], "systemSetting");
190: }
191: }
192:
193:
194: foreach ($groups as $groupName => $groupSettings) {
195: $groupName = i18n($groupName);
196: $form->add(renderLabel($groupName, '', 150, ''), $groupSettings);
197: }
198:
199:
200: if ($perm->have_perm_area_action($area, 'edit_sysconf')) {
201: $page->set('s', 'FORM', $form->render());
202: } else {
203: $page->displayCriticalError(i18n('Access denied'));
204: }
205:
206: $page->render();
207:
208: