17 require_once SQ_LIB_PATH.
'/config/config.inc';
19 define(
'SQ_APACHE_CONF_CUSTOM_KEYWORD_KEY',
'sq_custom_keyword_key');
43 var $config_vars = Array(
44 'request_notes' => Array(
'editable' => 1,
'default' => Array()),
54 var $request_notes = Array();
63 parent::__construct();
64 $this->config_file = SQ_DATA_PATH.
'/private/conf/apache.inc';
66 if (!file_exists($this->config_file))
return;
69 require_once $this->config_file;
70 if (!empty($request_notes)) {
71 $this->request_notes = $request_notes;
88 function save($vars, $backup_existing=FALSE, $send_message=TRUE)
90 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
91 $is_root = $GLOBALS[
'SQ_SYSTEM']->userRoot();
92 $is_admin = ($is_root || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
96 trigger_localised_error(
'SYS0267', E_USER_WARNING, $this->name);
101 trigger_localised_error(
'SYS0026', E_USER_WARNING, $this->name);
105 if (file_exists($this->config_file)) {
106 require $this->config_file;
109 $changed_vars = Array();
111 foreach ($this->config_vars as $var_name => $data) {
113 $current_value = (isset($$var_name)) ? $$var_name : $data[
'default'];
114 if ($data[
'editable'] && isset($vars[$var_name]) && $current_value !== $vars[$var_name]) {
116 $value = $vars[$var_name];
118 $changed_vars[$var_name] = Array(
'old' => $current_value,
'new' => $value);
120 $value = $current_value;
130 $str =
'<'.
"?php\n".ob_get_contents().
'?'.
">\n";
133 if ($backup_existing && file_exists($this->config_file)) {
138 $old_version = $this->config_file.
'.'.$i;
139 }
while (file_exists($old_version));
141 if (!copy($this->config_file, $old_version)) {
148 echo
"----------------------------------\n".($str).
"----------------------------------\n";
150 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
152 if (!create_directory(dirname($this->config_file))) {
157 if (!string_to_file($str, $this->config_file)) {
162 if ($changed_vars && $send_message) {
163 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
165 foreach ($changed_vars as $var_name => $values) {
166 $message_body = $var_name.
' changed from '.var_export($values[
'old'], TRUE).
' to '.var_export($values[
'new'], TRUE).
"\n";
167 $config_name = ucwords(str_replace(
'_',
' ', get_class($this)));
169 'setting' => $var_name,
170 'old_value' => var_export($values[
'old'], TRUE),
171 'new_value' => var_export($values[
'new'], TRUE),
173 $message = $ms->newMessage(Array(),
'config.'.get_class($this), $msg_reps);
174 $ms->enqueueMessage($message);
196 return ($GLOBALS[
'SQ_SYSTEM']->userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
209 if (!parent::writeAccess())
return FALSE;
210 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
215 return ($GLOBALS[
'SQ_SYSTEM']->userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
234 parent::paintBackend($o);
238 $is_root = $GLOBALS[
'SQ_SYSTEM']->userRoot();
240 $class = get_class($this);
242 $o->openSection(translate(
'apache_request_notes'));
244 if (!empty($this->request_notes)) {
247 ?><table
class=
"sq-backend-table">
249 <th><?php echo translate(
'apache_note_name'); ?></th>
250 <th><?php echo translate(
'source'); ?></th>
251 <th><?php echo translate(
'value'); ?></th>
252 <th><?php echo translate(
'apache_example_usage'); ?></th>
255 ?><th style=
"text-align: center;"><?php echo translate(
'remove_question'); ?></th><?php
260 foreach (array_reverse($this->request_notes) as $note_name => $note_info) {
262 <td><?php echo $note_name; ?></td>
263 <td><?php echo $note_info[
'type']; ?></td>
264 <td> <?php echo $note_info[
'keyword']; ?></td>
267 echo
'%{'.$note_name.
'}n';
272 ?><td style=
"text-align: center;"><?php echo check_box(
'remove['.base64_encode($note_name).
']'); ?></td><?php
283 $o->openField(translate(
'new_question'));
288 $keyword_option = Array(
289 'sq_keyword_select_none' =>
'--',
290 'sq_keyword_select_user' => translate(
'apache_asset_type_user'),
291 'sq_keyword_select_asset' => translate(
'apache_asset_type_asset'),
294 combo_box(
'sq_keyword_type_option', $keyword_option, FALSE,
'none', 0,
'id="sq_asset_type_select" onchange="sqKeywordSelectUpdate(this)"');
296 $asset_type_selector = ob_get_clean();
299 <script language=
"javascript">
300 function sqKeywordSelectUpdate(typeSelector)
303 for (optionNum = 0; optionNum < typeSelector.options.length; optionNum ++) {
304 optionValue = typeSelector.options[optionNum].value;
305 if (optionValue !=
'sq_keyword_select_none') {
306 document.getElementById(optionValue).style.display =
'none';
311 if (typeSelector.value !=
'sq_keyword_select_none') {
312 document.getElementById(typeSelector.value).style.display =
'';
314 document.getElementById(typeSelector.value).parentNode.parentNode.style.display =
'';
315 document.getElementById(
'sq_request_note_new').parentNode.parentNode.style.display =
'';
317 document.getElementById(typeSelector.value).parentNode.parentNode.style.display =
'none';
318 document.getElementById(
'sq_request_note_new').parentNode.parentNode.style.display =
'none';
321 sqKeywordValueSelectUpdate(document.getElementById(typeSelector.value));
324 function sqKeywordValueSelectUpdate(keywordSelector)
327 document.getElementById(
'sq_custom_keyword').parentNode.parentNode.style.display = (keywordSelector.value ==
'sq_custom_keyword_key') ?
'' :
'none';
334 foreach (Array(
'asset',
'user') as $asset_type) {
336 $asset =
new $asset_type();
337 $options = $asset->getAvailableKeywords();
338 $options[SQ_APACHE_CONF_CUSTOM_KEYWORD_KEY] = translate(
'custom_keyword');
339 combo_box(
'sq_keyword_select_'.$asset_type, $options, FALSE,
'', 0,
'id="sq_keyword_select_'.$asset_type.
'" onchange="sqKeywordValueSelectUpdate(this)"');
340 $elements[] = ob_get_clean();
344 hidden_field(
'sq_keyword_select_none',
'');
345 $elements[] = ob_get_clean();
349 text_box(
'sq_custom_keyword',
'',
'',
'', FALSE,
'id="sq_custom_keyword"');
350 $custom_keyword_input = ob_get_clean();
354 text_box(
'sq_request_note_new',
'',
'',
'', FALSE,
'id="sq_request_note_new"');
355 $note_name_input = ob_get_clean();
358 <table
class=
"sq-backend-table">
360 <th><?php echo translate(
'source'); ?></th>
361 <td><?php echo $asset_type_selector; ?></td>
364 <th><?php echo translate(
'value'); ?></th>
365 <td><?php echo implode(
' ', $elements); ?></td>
368 <th><?php echo translate(
'keyword_name'); ?></th>
369 <td><?php echo $custom_keyword_input; ?></td>
372 <th><?php echo translate(
'apache_note_name'); ?></th>
373 <td><?php echo $note_name_input; ?></td>
376 <script language=
"javascript">
377 sqKeywordSelectUpdate(document.getElementById(
'sq_asset_type_select'));
383 $o->sectionNote(translate(
'apache_note_example'));
386 if ($write_access) $o->commitButton(
'', TRUE);
402 $class = get_class_lower($this);
405 if (isset($_POST[
'remove']) && !empty($_POST[
'remove'])) {
406 $remove_notes = array_keys($_POST[
'remove']);
407 foreach ($remove_notes as $note_name) {
408 unset($this->request_notes[base64_decode($note_name)]);
414 $this->request_notes = array_merge($new_request_note, $this->request_notes);
416 $_POST[$class][
'request_notes'] = $this->request_notes;
418 return parent::processBackend($o);
438 if ($var_name ==
'request_notes') {
439 echo
'$request_notes = '.var_export($value, 1).
';'.
"\n";
441 parent::_paintConfigVar($var_name, $value, $var_export);
459 if (!isset($data[
'sq_keyword_type_option'])) {
462 if ($data[
'sq_keyword_type_option'] ==
'sq_keyword_select_none') {
466 $new_req_note = Array();
469 $req_note_name = $data[
'sq_request_note_new'];
470 $new_req_note[
'type'] = $data[
'sq_keyword_type_option'];
471 $new_req_note[
'keyword'] = $data[$new_req_note[
'type']];
472 if ($new_req_note[
'keyword'] == SQ_APACHE_CONF_CUSTOM_KEYWORD_KEY) {
473 $new_req_note[
'keyword'] = trim(strtolower($data[
'sq_custom_keyword']));
477 $new_req_note[
'type'] = str_replace(
'sq_keyword_select_',
'', $new_req_note[
'type']);
480 if (empty($req_note_name))
return FALSE;
483 if (empty($new_req_note[
'keyword']))
return FALSE;
486 if (in_array($req_note_name, array_keys($this->request_notes))) {
487 trigger_localised_error(
'SYS0314', E_USER_NOTICE);
491 return Array($req_note_name => $new_req_note);