18 require_once SQ_LIB_PATH.
'/config/config.inc';
19 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
46 var $config_vars = Array(
48 'SQ_CONTEXT_DEFINITIONS' => Array(
'editable' => 1,
'default' =>
'a:0:{}'),
60 var $prefix =
'config_context_';
78 $this->config_vars[
'SQ_CONTEXT_DEFINITIONS'][
'default'] = serialize(Array(
'0' => Array(
'name' =>
'Default Context')));
80 parent::__construct();
81 $this->config_file = NULL;
100 $contexts = $this->
load();
101 parent::paintBackend($o);
104 $class = get_class_lower($this);
107 if ($write_access === TRUE) {
108 $current_context = array_get_index($_POST, $this->prefix.
'selected');
109 if (!is_numeric($current_context)) {
111 $current_context = NULL;
113 $current_context = (int)$current_context;
116 if ($current_context == NULL) {
119 $editing_context = array_get_index($_POST, $this->prefix.
'editing');
120 if (!is_numeric($editing_context)) {
121 $editing_context = NULL;
123 $editing_context = (int)$editing_context;
129 $current_context = NULL;
133 $o->openSection(translate($this->prefix.
'list_of_contexts'));
135 $this->
paintSummary($o, $contexts, $write_access, $current_context);
137 $o->sectionNote(translate($this->prefix.
'note'));
142 if (($write_access === TRUE) && (is_null($current_context) === FALSE)) {
143 if (isset($contexts[$current_context]) === TRUE) {
144 $o->openSection(translate($this->prefix.
'edit_selected_context'));
150 if ($write_access) $o->commitButton(
'', TRUE);
170 <?php hidden_field($this->prefix.
'selected',
''); ?>
171 <?php hidden_field($this->prefix.
'deleted',
''); ?>
172 <table
class=
"sq-backend-table" style=
"margin-bottom: 1em">
185 $alt_context_num = 0;
189 $default_context = Array(0 => $contexts[0]);
191 uasort($contexts, create_function(
'$a,$b',
'return $a["sort_order"] - $b["sort_order"];'));
192 $contexts = $default_context + $contexts;
194 foreach ($contexts as $contextid => $context) {
195 $context_name = array_get_index($context,
'name',
'');
197 $condition_err_count = 0;
199 if ($alt_context_num === 0) {
202 <tr
class=
"sq-table-row">
203 <td
class=
"sq-backend-table-header-header" colspan=
"6">
205 echo translate($this->prefix.
'default_name'); ?>
209 <th><?php echo translate(
'edit_question'); ?></th>
210 <th><?php echo translate($this->prefix.
'context_name'); ?></th>
211 <th colspan=
"4"></th>
216 if ($current_context === (
int)$contextid) {
217 $row_class =
'sq-table-row alt';
219 $row_class =
'sq-table-row';
222 <tr
class=
"<?php echo $row_class; ?>">
223 <td
class=
"sq-backend-table-cell" align=
"center"><?php
224 if (($write_access === TRUE) && ((
int)$contextid !== $current_context)) { ?>
225 <p><a href=
"#" onclick=
"document.getElementById('<?php echo $this->prefix; ?>selected').value = <?php echo $contextid ?>; document.main_form.submit(); return false;"><?php echo trim(sq_get_icon(sq_web_path(
'lib').
'/web/images/icons/edit_mode.png', 15, 15, translate($this->prefix.
'edit_alt_text', $context_name), NULL,
' border="0"')); ?></a></p><?php
229 <td
class=
"sq-backend-table-cell">
230 <strong><?php echo $context_name; ?></strong><?php
231 if ($contextid !== 0) {
232 hidden_field($this->prefix.
'reorder[]', $contextid,
' id="'.$this->prefix.
'reorder_'.$contextid.
'"');
236 <td
class=
"sq-backend-table-cell"><?php
237 if ($contextid === 0) {
238 echo translate($this->prefix.
'default_explanation');
241 if ($context[
'at_least'] === NULL) {
242 echo translate($this->prefix.
'table_all_description', count($context[
'conditions']));
244 echo translate($this->prefix.
'table_at_least_description', $context[
'at_least'], count($context[
'conditions']));
250 foreach ($condition_text as $condition_id => $condition_text_item) {
251 ?><li><?php echo $condition_text_item;
252 $condition_errors = array_get_index($context_errors, $condition_id, Array());
253 if (count($condition_errors) > 0) {
254 $condition_err_count++;
257 foreach ($condition_errors as $condition_error) {
258 ?><li
class=
"sq-backend-warning"><?php echo $condition_error; ?></li><?php
266 $condition_level_errors = array_get_index($context_errors,
'condition', Array());
267 if (count($condition_level_errors) > 0) {
268 foreach ($context_level_errors as $context_level_error) {
269 ?><li
class=
"sq-backend-warning"><?php echo $condition_level_error; ?></li><?php
276 $context_level_errors = array_get_index($context_errors,
'context', Array());
277 if (count($context_level_errors) > 0) {
278 foreach ($context_level_errors as $context_level_error) {
279 ?><p
class=
"sq-backend-warning"><?php echo $context_level_error; ?></p><?php
283 if (count($context[
'conditions']) === 0) {
285 }
else if ($context[
'at_least'] === NULL) {
286 $valid = (count($context_errors) === 0) ? TRUE : FALSE;
288 $valid = ((count($context[
'conditions']) - $condition_err_count) >= $context[
'at_least']) ? TRUE : FALSE;
291 if ($condition_err_count > 0) {
292 if ($valid === TRUE) {
294 echo translate($this->prefix.
'invalid_cond_but_still_valid');
297 ?><p
class=
"sq-backend-warning"><?php
298 echo translate($this->prefix.
'not_enough_valid_cond_to_be_valid');
305 <td
class=
"sq-backend-table-cell" align=
"center"><?php
312 echo trim(sq_get_icon(sq_web_path(
'lib').
'/web/images/tick.gif', 15, 15, translate($this->prefix.
'valid_alt_text', $context_name), NULL,
' border="0"'));
314 echo trim(sq_get_icon(sq_web_path(
'lib').
'/web/images/cross.gif', 15, 15, translate($this->prefix.
'not_valid_alt_text', $context_name), NULL,
' border="0"'));
318 <td
class=
"sq-backend-table-cell" align=
"center"><?php
320 if ($write_access === TRUE) {
321 if ($alt_context_num > 1) {
322 ?><a href=
"#" onclick=
"return false;" class=
"reorder-up"><?php echo trim(sq_get_icon(sq_web_path(
'lib').
'/web/images/icons/up_arrow.png', 15, 15, translate($this->prefix.
'reorder_up_alt_text', $context_name), NULL,
' border="0"')); ?></a><?php
324 ?><img src=
"<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" width=
"15" height=
"15" border=
"0" /><?php
327 if (($contextid !== 0) && ($alt_context_num < count($contexts) - 1)) {
328 ?><a href=
"#" onclick=
"return false;" class=
"reorder-down"><?php echo trim(sq_get_icon(sq_web_path(
'lib').
'/web/images/icons/down_arrow.png', 15, 15, translate($this->prefix.
'reorder_down_alt_text', $context_name), NULL,
' border="0"')); ?></a><?php
330 ?><img src=
"<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" width=
"15" height=
"15" border=
"0" /><?php
335 <td
class=
"sq-backend-table-cell" align=
"center"><?php
337 if (($write_access === TRUE) && ($contextid !== 0) && (($contextid !== $current_context))) {
338 ?><p><a href=
"#" onclick=
"if (confirm('<?php echo str_replace("\n
", '\\n', translate($this->prefix.'delete_warning', $context_name)); ?>') == true) { document.getElementById('<?php echo $this->prefix; ?>deleted').value = <?php echo $contextid ?>; document.main_form.submit(); } return false;"><?php echo trim(sq_get_icon(sq_web_path(
'lib').
'/web/images/icons/delete.png', 15, 15, translate($this->prefix.
'delete_alt_text', $context_name), NULL,
' border="0"')); ?></a></p><?php
344 if ($alt_context_num === 0) {
349 <tr
class=
"sq-table-row">
350 <td
class=
"sq-backend-table-header-header" colspan=
"6">
352 echo translate($this->prefix.
'alternate_contexts'); ?>
355 if (count($contexts) > 1) {
358 <tr
class=
"sq-table-row">
359 <th><?php echo translate(
'edit_question'); ?></th>
360 <th><?php echo translate($this->prefix.
'context_name'); ?></th>
361 <th><?php echo translate($this->prefix.
'context_details'); ?></th>
362 <th style=
"text-align: center"><?php echo translate(
'valid_question'); ?></th>
363 <th style=
"text-align: center"><?php echo translate(
'reorder_question'); ?></th>
364 <th style=
"text-align: center"><?php echo translate(
'delete_question'); ?></th>
370 <tr
class=
"sq-table-row">
371 <td
class=
"sq-backend-table-cell"></td>
372 <td
class=
"sq-backend-table-cell" colspan=
"5"><?php echo translate($this->prefix.
'no_alternate_contexts'); ?></td>
383 <tr
class=
"sq-table-row">
384 <td
class=
"sq-backend-table-header-header" colspan=
"6">
386 echo translate($this->prefix.
'new_alternate_context'); ?>
391 <td colspan=
"2"><?php
394 check_box($this->prefix.
'new_alternate_context',
'1', FALSE,
'document.getElementById("'.$this->prefix.
'new_alternate_context_name").disabled = !this.checked; if (this.checked == true) { document.getElementById("'.$this->prefix.
'new_alternate_context_name").focus() };');
395 $check_box = ob_get_clean();
397 text_box($this->prefix.
'new_alternate_context_name',
'', 20, 0, FALSE,
' disabled="disabled"');
398 $text_box = ob_get_clean();
399 echo translate($this->prefix.
'new_alternate_context_line', $check_box, $text_box);
402 echo translate($this->prefix.
'lock_to_add_alternate');
406 <td colspan=
"3"></td>
434 <script type=
"text/javascript">
437 moveUp:
function(link) {
438 row = link.parentNode.parentNode;
439 switch_row = row.previousSibling;
441 while ((switch_row.nodeType != 1) || (switch_row.nodeName.toLowerCase() !=
'tr')) {
442 switch_row = switch_row.previousSibling;
445 row_tds = row.getElementsByTagName(
'td');
446 switch_row_tds = switch_row.getElementsByTagName(
'td');
447 for (var i = 0; i < row_tds.length; i++) {
449 if (row_tds[i].innerHTML.indexOf(
'class="reorder-') === -1) {
450 var temp = switch_row_tds[i].innerHTML;
451 switch_row_tds[i].innerHTML = row_tds[i].innerHTML;
452 row_tds[i].innerHTML = temp;
456 var temp_style = row.className;
457 row.className = switch_row.className;
458 switch_row.className = temp_style;
461 moveDown:
function(link) {
462 row = link.parentNode.parentNode;
463 switch_row = row.nextSibling;
465 while ((switch_row.nodeType != 1) || (switch_row.nodeName.toLowerCase() !=
'tr')) {
466 switch_row = switch_row.nextSibling;
469 row_tds = row.getElementsByTagName(
'td');
470 switch_row_tds = switch_row.getElementsByTagName(
'td');
471 for (var i = 0; i < row_tds.length; i++) {
473 if (row_tds[i].innerHTML.indexOf(
'class="reorder-') === -1) {
474 var temp = switch_row_tds[i].innerHTML;
475 switch_row_tds[i].innerHTML = row_tds[i].innerHTML;
476 row_tds[i].innerHTML = temp;
480 var temp_style = row.className;
481 row.className = switch_row.className;
482 switch_row.className = temp_style;
487 var a_tags = document.getElementsByTagName(
'a');
488 for (var i = 0; i < a_tags.length; i++) {
490 if (a_tag.className ==
'reorder-up') {
491 a_tag.onclick =
function(event) {
495 }
else if (a_tag.className ==
'reorder-down') {
496 a_tag.onclick =
function(event) {
508 $js = ob_get_clean();
527 $condition_text = Array();
529 foreach ($conditions as $condition_id => $condition_details) {
530 $options = $condition_details[
'options'];
532 switch ($condition_details[
'type']) {
533 case 'accept-language':
535 $condition_text[$condition_id] = translate($this->prefix.
'summary_cond_accept-language', $locales[$options[
'language']], number_format($options[
'min_q'], 1));
539 $translate_suffix = ((int)$options[
'match_logic'] === 1 ?
'' :
'!').$options[
'match_type'];
540 $case_sensitive_text = ((int)($options[
'case_sensitive']) === 1 ?
'' :
'not_').
'case_sensitive';
541 $condition_text[$condition_id] = translate($this->prefix.
'summary_cond_header_'.$translate_suffix, $options[
'header_name'], $options[
'match_value'], translate($case_sensitive_text));
546 $translate_suffix = ((int)$options[
'match_logic'] === 1 ?
'' :
'!').$options[
'match_type'];
547 $case_sensitive_text = ((int)($options[
'case_sensitive']) === 1 ?
'' :
'not_').
'case_sensitive';
548 $condition_text[$condition_id] = translate($this->prefix.
'summary_cond_'.$condition_details[
'type'].
'_'.$translate_suffix, $options[
'var_name'], $options[
'match_value'], translate($case_sensitive_text));
552 $translate_suffix = ((int)$options[
'match_logic'] === 1 ?
'' :
'!').$options[
'match_type'];
553 $condition_text[$condition_id] = translate($this->prefix.
'summary_cond_url_'.$translate_suffix, $options[
'match_value']);
557 $translate_suffix = ($options[
'match_type'] ===
'is' ?
'' :
'_!');
558 $condition_text[$condition_id] = translate($this->prefix.
'summary_cond_port'.$translate_suffix, $options[
'match_value']);
562 $translate_suffix = ($options[
'match_value'] === 1 ?
'' :
'_!');
563 $condition_text[$condition_id] = translate($this->prefix.
'summary_cond_secure'.$translate_suffix);
568 return $condition_text;
603 $context_errors = Array();
605 if (count($context[
'conditions']) < 1) {
606 $context_errors[
'context'][] = translate($this->prefix.
'context_has_no_conditions');
607 }
else if ((is_numeric($context[
'at_least']) === TRUE) && ($context[
'at_least'] > count($context[
'conditions']))) {
608 $context_errors[
'context'][] = translate($this->prefix.
'context_at_least_too_many', $context[
'at_least'], count($context[
'conditions']));
610 foreach ($context[
'conditions'] as $condition_id => $condition) {
611 $condition_type = $condition[
'type'];
612 $condition_options = $condition[
'options'];
614 switch ($condition_type) {
616 if ($condition_options[
'match_value'] ===
'') {
617 $context_errors[$condition_id][] = translate($this->prefix.
'error_cond_url_no_match_value');
622 if ($condition_options[
'header_name'] ===
'') {
623 $context_errors[$condition_id][] = translate($this->prefix.
'error_cond_header_no_header_name');
625 if ($condition_options[
'match_value'] ===
'') {
626 $context_errors[$condition_id][] = translate($this->prefix.
'error_cond_header_no_match_value');
632 if ($condition_options[
'var_name'] ===
'') {
633 $context_errors[$condition_id][] = translate($this->prefix.
'error_cond_no_request_var_name');
635 if ($condition_options[
'match_value'] ===
'') {
636 $context_errors[$condition_id][] = translate($this->prefix.
'error_cond_request_var_no_match_value');
643 return $context_errors;
664 text_box($this->prefix.
'name', array_get_index($contexts[$current_context],
'name',
''));
665 hidden_field($this->prefix.
'editing', (
string)$current_context);
668 if ($current_context !== 0) {
669 if (empty($contexts[$current_context][
'at_least']) === FALSE) {
670 $at_least = $contexts[$current_context][
'at_least'];
675 if (empty($contexts[$current_context][
'conditions']) === FALSE) {
676 $conditions = $contexts[$current_context][
'conditions'];
678 $conditions = Array();
681 $o->
openField(translate($this->prefix.
'minimum_matches'));
682 $list_options = Array(
683 'at_least' => translate(
'at_least'),
684 'all' => translate(
'all'),
687 if ($at_least === NULL) {
688 $default_option =
'all';
691 $default_option =
'at_least';
692 if (is_numeric($at_least) === FALSE) {
698 combo_box($this->prefix.
'min', $list_options, FALSE, $default_option, 0,
' onchange="if (this.value == \'all\') document.getElementById(\''.$this->prefix.
'at_least\').value = \'\';"');
699 $cb = ob_get_clean();
701 int_text_box($this->prefix.
'at_least', $at_least, FALSE, 3, 1, NULL, 2, FALSE, FALSE,
' onchange="if (this.value != \'\') document.getElementById(\''.$this->prefix.
'minimum_matches\').selectedIndex = 0;');
702 $tb = ob_get_clean();
703 echo translate($this->prefix.
'minimum_matches_interface', $cb, $tb);
712 $option_types = Array(
713 'accept-language' => translate($this->prefix.
'type_accept-language'),
714 'header' => translate($this->prefix.
'type_header'),
715 'url' => translate($this->prefix.
'type_url'),
716 'port' => translate($this->prefix.
'type_port'),
717 'secure' => translate($this->prefix.
'type_secure'),
718 'get' => translate($this->prefix.
'type_get'),
719 'post' => translate($this->prefix.
'type_post'),
722 $o->
openField(translate(
'new_condition_question'));
725 check_box($this->prefix.
'new_condition',
'1', FALSE,
'document.getElementById("'.$this->prefix.
'new_condition_type").disabled = !this.checked; if (this.checked == true) { document.getElementById("'.$this->prefix.
'new_condition_type").focus() };');
726 $check_box = ob_get_clean();
728 combo_box($this->prefix.
'new_condition_type', $option_types, FALSE, Array(), 0,
' disabled="disabled"');
729 $combo_box = ob_get_clean();
730 echo translate($this->prefix.
'new_condition_line', $check_box, $combo_box);
749 <table
class=
"sq-backend-table" style=
"margin-bottom: 1em">
756 <tr
class=
"sq-table-row">
757 <th><?php echo translate($this->prefix.
'condition_type'); ?></th>
758 <th><?php echo translate($this->prefix.
'condition_details'); ?></th>
759 <th style=
"text-align: center"><?php echo translate(
'delete_question'); ?></th>
761 foreach ($conditions as $condition_id => &$condition_options) {
764 $condition_type = $conditions[$condition_id][
'type'];
766 <td><p><strong><?php echo translate($this->prefix.
'type_'.$condition_type); ?></strong></p></td><?php
771 <td align=
"center"><p><strong><?php check_box($this->prefix.
'condition_delete['.$condition_id.
']',
'1', FALSE); ?></strong></p></td><?php
796 $condition_type = $conditions[$condition_id][
'type'];
797 $condition_details = $conditions[$condition_id][
'options'];
799 switch ($condition_type) {
800 case 'accept-language':
805 $current_language = $condition_details[
'language'];
807 combo_box($this->prefix.$condition_id.
'_language', $locales, FALSE, Array($current_language));
808 $language_cb = ob_get_clean();
809 echo translate($this->prefix.
'type_accept-language_param_language', $language_cb);
814 $min_q = $condition_details[
'min_q'];
815 $min_q = min($min_q, 1);
816 $min_q = max($min_q, 0);
820 if ((
float)$min_q == (
int)$min_q) {
821 $min_q = number_format($min_q, 1);
823 text_box($this->prefix.$condition_id.
'_min_q', $min_q, 5, 0, FALSE,
' onblur="val = parseFloat(this.value); if (isNaN(val)) {this.value = \'\'; } else {val = Math.min(Math.max(val, 0), 1); if (val == parseInt(this.value)) {this.value = parseInt(this.value) + \'.0\'; } }"');
824 $min_q_box = ob_get_clean();
825 echo translate($this->prefix.
'type_accept-language_param_min_q', $min_q_box);
830 echo translate($this->prefix.
'type_accept-language_param_explanation');
838 $header_name = $condition_details[
'header_name'];
839 $match_logic = $condition_details[
'match_logic'];
840 $match_type = $condition_details[
'match_type'];
841 $match_value = $condition_details[
'match_value'];
842 $case_sensitive = $condition_details[
'case_sensitive'];
844 $logic_options = Array(
845 1 => translate($this->prefix.
'type_header_option_1'),
846 0 => translate($this->prefix.
'type_header_option_0'),
849 $type_options = Array(
850 'exists' => translate($this->prefix.
'type_header_option_exists'),
851 'exact' => translate($this->prefix.
'type_header_option_exact'),
852 'begins' => translate($this->prefix.
'type_header_option_begins'),
853 'ends' => translate($this->prefix.
'type_header_option_ends'),
854 'contains' => translate($this->prefix.
'type_header_option_contains'),
858 text_box($this->prefix.$condition_id.
'_header_name', $header_name, 30);
859 $header_tb = ob_get_clean();
861 combo_box($this->prefix.$condition_id.
'_match_logic', $logic_options, FALSE, Array($match_logic));
862 $logic_cb = ob_get_clean();
864 combo_box($this->prefix.$condition_id.
'_match_type', $type_options, FALSE, Array($match_type));
865 $type_cb = ob_get_clean();
867 text_box($this->prefix.$condition_id.
'_match_value', $match_value, 30);
868 $value_tb = ob_get_clean();
870 check_box($this->prefix.$condition_id.
'_case_sensitive',
'1', $case_sensitive);
871 $case_ch = ob_get_clean();
872 echo translate($this->prefix.
'type_header_param', $header_tb, $logic_cb, $type_cb, $value_tb, $case_ch);
877 echo translate($this->prefix.
'type_header_param_explanation');
886 $var_name = $condition_details[
'var_name'];
887 $match_logic = $condition_details[
'match_logic'];
888 $match_type = $condition_details[
'match_type'];
889 $match_value = $condition_details[
'match_value'];
890 $case_sensitive = $condition_details[
'case_sensitive'];
892 $logic_options = Array(
893 1 => translate($this->prefix.
'type_header_option_1'),
894 0 => translate($this->prefix.
'type_header_option_0'),
897 $type_options = Array(
898 'exists' => translate($this->prefix.
'type_header_option_exists'),
899 'exact' => translate($this->prefix.
'type_header_option_exact'),
900 'begins' => translate($this->prefix.
'type_header_option_begins'),
901 'ends' => translate($this->prefix.
'type_header_option_ends'),
902 'contains' => translate($this->prefix.
'type_header_option_contains'),
906 text_box($this->prefix.$condition_id.
'_var_name', $var_name, 30);
907 $var_tb = ob_get_clean();
909 combo_box($this->prefix.$condition_id.
'_match_logic', $logic_options, FALSE, Array($match_logic));
910 $logic_cb = ob_get_clean();
912 combo_box($this->prefix.$condition_id.
'_match_type', $type_options, FALSE, Array($match_type));
913 $type_cb = ob_get_clean();
915 text_box($this->prefix.$condition_id.
'_match_value', $match_value, 30);
916 $value_tb = ob_get_clean();
918 check_box($this->prefix.$condition_id.
'_case_sensitive',
'1', $case_sensitive);
919 $case_ch = ob_get_clean();
920 echo translate($this->prefix.
'type_'.$condition_type.
'_param', $var_tb, $logic_cb, $type_cb, $value_tb, $case_ch);
925 echo translate($this->prefix.
'type_header_param_explanation');
933 $match_logic = $condition_details[
'match_logic'];
934 $match_type = $condition_details[
'match_type'];
935 $match_value = $condition_details[
'match_value'];
937 $logic_options = Array(
938 1 => translate($this->prefix.
'type_url_option_1'),
939 0 => translate($this->prefix.
'type_url_option_0'),
942 $type_options = Array(
943 'exact' => translate($this->prefix.
'type_url_option_exact'),
944 'begins' => translate($this->prefix.
'type_url_option_begins'),
945 'ends' => translate($this->prefix.
'type_url_option_ends'),
946 'contains' => translate($this->prefix.
'type_url_option_contains'),
950 combo_box($this->prefix.$condition_id.
'_match_logic', $logic_options, FALSE, Array($match_logic));
951 $logic_cb = ob_get_clean();
953 combo_box($this->prefix.$condition_id.
'_match_type', $type_options, FALSE, Array($match_type));
954 $type_cb = ob_get_clean();
956 text_box($this->prefix.$condition_id.
'_match_value', $match_value, 30);
957 $value_tb = ob_get_clean();
958 echo translate($this->prefix.
'type_url_param', $logic_cb, $type_cb, $value_tb);
963 echo translate($this->prefix.
'type_url_param_explanation');
971 $match_type = $condition_details[
'match_type'];
972 $port = $condition_details[
'match_value'];
974 'is' => translate($this->prefix.
'type_port_option_1'),
975 'is_not' => translate($this->prefix.
'type_port_option_0'),
978 combo_box($this->prefix.$condition_id.
'_match_type', $options, FALSE, Array($match_type));
979 $cb = ob_get_clean();
981 int_text_box($this->prefix.$condition_id.
'_match_value', $port, FALSE, 7, 0, 65535);
982 $tb = ob_get_clean();
983 echo translate($this->prefix.
'type_port_param', $cb, $tb);
988 echo translate($this->prefix.
'type_port_param_explanation');
996 $match = $condition_details[
'match_value'];
998 0 => translate($this->prefix.
'type_secure_option_0'),
999 1 => translate($this->prefix.
'type_secure_option_1'),
1002 combo_box($this->prefix.$condition_id.
'_match_value', $options, FALSE, Array($match));
1003 $cb = ob_get_clean();
1004 echo translate($this->prefix.
'type_secure_param', $cb);
1009 echo translate($this->prefix.
'type_secure_param_explanation');
1075 if (empty($_POST[
'sq_lock_release_manual']) === FALSE) {
1079 $contexts = $this->
load();
1080 $context_names = Array();
1081 foreach ($contexts as $key => $value){
1082 $context_names[] = $value[
'name'];
1085 $save_required = FALSE;
1088 $current_context = NULL;
1089 $editing_context = NULL;
1093 unset($_POST[
'sq_lock_release']);
1096 $class = get_class_lower($this);
1099 $deleted_context = array_get_index($_POST, $this->prefix.
'deleted');
1100 if (is_numeric($deleted_context) === TRUE) {
1102 unset($contexts[$deleted_context]);
1103 $active_context = $GLOBALS[
'SQ_SYSTEM']->getContextId();
1104 if ((
int)$deleted_context === (
int)$active_context) {
1105 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
1106 $new_alternate_context = $GLOBALS[
'SQ_SYSTEM']->getAlternateContext();
1107 $GLOBALS[
'SQ_SYSTEM']->changeContext($new_alternate_context);
1108 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] = $new_alternate_context;
1110 $save_required = TRUE;
1113 $_POST[
'sq_lock_release'] = TRUE;
1116 $current_context = array_get_index($_POST, $this->prefix.
'selected');
1117 if (!is_numeric($current_context)) {
1119 $current_context = NULL;
1121 $current_context = (int)$current_context;
1124 if ($current_context === NULL) {
1127 $editing_context = array_get_index($_POST, $this->prefix.
'editing');
1128 if (!is_numeric($editing_context)) {
1129 $editing_context = NULL;
1131 $editing_context = (int)$editing_context;
1134 $editing_context = NULL;
1138 $reorder_post = array_get_index($_POST, $this->prefix.
'reorder', Array());
1139 if (empty($reorder_post) === FALSE) {
1140 foreach ($reorder_post as $new_sort_order => $order_contextid) {
1141 if ((
int)$contexts[$order_contextid][
'sort_order'] !== (
int)$new_sort_order) {
1142 $contexts[$order_contextid][
'sort_order'] = $new_sort_order;
1143 $save_required = TRUE;
1153 if ($current_context === NULL) {
1154 if ((
int)array_get_index($_POST, $this->prefix.
'new_alternate_context',
'0') === 1) {
1155 $new_name = trim(array_get_index($_POST, $this->prefix.
'new_alternate_context_name',
''));
1157 if ($new_name ===
'' || in_array($new_name, $context_names)) {
1158 trigger_localised_error(
'CTX0005', E_USER_WARNING);
1162 $new_sort_order = count($contexts);
1163 $contexts[$new_key] = Array(
1164 'name' => array_get_index($_POST, $this->prefix.
'new_alternate_context_name',
''),
1165 'conditions' => Array(),
1167 'sort_order' => $new_sort_order,
1172 $_POST[$this->prefix.
'selected'] = $new_key;
1173 $save_required = TRUE;
1178 if (($current_context === NULL) && ($editing_context !== NULL)) {
1180 $new_name = trim(array_get_index($_POST, $this->prefix.
'name',
''));
1184 if ($new_name ===
'' || ($new_name != $contexts[$editing_context][
'name'] && in_array($new_name, $context_names))) {
1185 trigger_localised_error(
'CTX0006', E_USER_NOTICE, $contexts[$editing_context][
'name']);
1187 $contexts[$editing_context][
'name'] = $new_name;
1190 if ($editing_context !== 0) {
1191 if (array_get_index($_POST, $this->prefix.
'min') ===
'all') {
1194 $at_least = array_get_index($_POST, $this->prefix.
'at_least', 1);
1196 $contexts[$editing_context][
'at_least'] = $at_least;
1198 $deleted_conditions = array_get_index($_POST, $this->prefix.
'condition_delete', Array());
1199 foreach ($deleted_conditions as $condition_id => $value) {
1200 unset($contexts[$editing_context][
'conditions'][$condition_id]);
1203 foreach ($contexts[$editing_context][
'conditions'] as $condition_id => &$condition_value) {
1204 $this->
_processCondition($condition_id, $condition_value[
'type'], $condition_value[
'options']);
1208 $new_condition_flag = array_get_index($_POST, $this->prefix.
'new_condition',
'0');
1209 if ((
bool)$new_condition_flag === TRUE) {
1210 $new_condition_type = array_get_index($_POST, $this->prefix.
'new_condition_type');
1211 $new_condition = Array(
1212 'type' => $new_condition_type,
1215 switch ($new_condition_type) {
1216 case 'accept-language':
1220 $new_condition[
'options'] = Array(
1230 $new_condition[
'options'] = Array(
1231 'header_name' =>
'',
1232 'match_logic' =>
'1',
1233 'match_type' =>
'exact',
1234 'match_value' =>
'',
1235 'case_sensitive' =>
'1',
1244 $new_condition[
'options'] = Array(
1246 'match_logic' =>
'1',
1247 'match_type' =>
'exact',
1248 'match_value' =>
'',
1249 'case_sensitive' =>
'1',
1257 $new_condition[
'options'] = Array(
1258 'match_logic' =>
'1',
1259 'match_type' =>
'exact',
1260 'match_value' =>
'',
1266 $new_condition[
'options'] = Array(
1267 'match_type' =>
'is',
1268 'match_value' => 80,
1274 $new_condition[
'options'] = Array(
1281 $contexts[$editing_context][
'conditions'][] = $new_condition;
1287 $save_required = TRUE;
1302 if (empty($_POST[
'process_form']) === FALSE) {
1303 if ($save_required === TRUE) {
1305 'contexts' => $contexts,
1307 $saved = $this->
save($vars);
1312 if (empty($_POST[
'sq_lock_release']) === FALSE) {
1320 if (empty($_POST[
'sq_lock_acquire']) === FALSE) {
1326 if (($editing_context !== NULL) && ($current_context === NULL) && ($new_key === NULL)) {
1327 $_POST[$this->prefix.
'selected'] = $editing_context;
1348 switch ($condition_type) {
1349 case 'accept-language':
1351 $new_language = array_get_index($_POST, $this->prefix.$condition_id.
'_language',
'');
1352 if (isset($locales[$new_language]) === FALSE) {
1353 trigger_localised_error(
'CTX0008', E_USER_NOTICE, $new_language);
1355 $condition_options[
'language'] = $new_language;
1358 $new_q_value = array_get_index($_POST, $this->prefix.$condition_id.
'_min_q');
1359 if (is_numeric($new_q_value) === TRUE) {
1360 $new_q_value = (float)$new_q_value;
1361 if ($new_q_value > 1.0) {
1362 trigger_localised_error(
'CTX0009', E_USER_NOTICE, $new_q_value);
1365 if ($new_q_value < 0.0) {
1366 trigger_localised_error(
'CTX0010', E_USER_NOTICE, $new_q_value);
1369 $condition_options[
'min_q'] = $new_q_value;
1375 $condition_options[
'header_name'] = array_get_index($_POST, $this->prefix.$condition_id.
'_header_name',
'');
1376 $condition_options[
'case_sensitive'] = array_get_index($_POST, $this->prefix.$condition_id.
'_case_sensitive', 0);
1377 $condition_options[
'match_logic'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_logic', 1);
1378 $condition_options[
'match_type'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_type',
'exact');
1379 $condition_options[
'match_value'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_value',
'');
1384 $condition_options[
'var_name'] = array_get_index($_POST, $this->prefix.$condition_id.
'_var_name',
'');
1385 $condition_options[
'case_sensitive'] = array_get_index($_POST, $this->prefix.$condition_id.
'_case_sensitive', 0);
1386 $condition_options[
'match_logic'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_logic', 1);
1387 $condition_options[
'match_type'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_type',
'exact');
1388 $condition_options[
'match_value'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_value',
'');
1392 $condition_options[
'match_logic'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_logic', 1);
1393 $condition_options[
'match_type'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_type',
'exact');
1394 $condition_options[
'match_value'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_value',
'');
1398 $condition_options[
'match_type'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_type', 1);
1399 $condition_options[
'match_value'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_value', 80);
1403 $condition_options[
'match_value'] = array_get_index($_POST, $this->prefix.$condition_id.
'_match_value', 0);
1418 $contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts(TRUE);
1423 if (isset($contexts[0]) === FALSE) {
1424 $contexts[0] = Array(
1425 'name' =>
'Default Context',
1427 'conditions' => NULL,
1428 'sort_order' => NULL,
1453 function save($vars, $backup_existing=FALSE)
1461 $current_contextids = array_keys(array_get_index($vars,
'contexts', Array()));
1463 $new_contextids = array_diff($current_contextids, $existing_contextids);
1464 $deleted_contextids = array_diff($existing_contextids, $current_contextids);
1465 $updated_contextids = array_intersect($current_contextids, $existing_contextids);
1467 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1468 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1472 foreach ($new_contextids as $new_contextid) {
1474 $context =& $vars[
'contexts'][$new_contextid];
1476 'contextid' => $new_contextid,
1477 'name' => $context[
'name'],
1478 'conditions' => serialize($context[
'conditions']),
1479 'at_least' => $context[
'at_least'],
1480 'sort_order' => $context[
'sort_order'],
1488 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1489 trigger_localised_error(
'CTX0001', E_USER_ERROR, $bind_vars[
'name'], $e->getMessage());
1497 foreach ($updated_contextids as $updated_contextid) {
1499 $context =& $vars[
'contexts'][$updated_contextid];
1501 'contextid' => $updated_contextid,
1502 'name' => $context[
'name'],
1503 'conditions' => serialize($context[
'conditions']),
1504 'at_least' => $context[
'at_least'],
1505 'sort_order' => $context[
'sort_order'],
1513 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1514 trigger_localised_error(
'CTX0002', E_USER_ERROR, $bind_vars[
'name'], $e->getMessage());
1524 if (($ok === TRUE) && (count($deleted_contextids) > 0)) {
1527 'contextids' => $deleted_contextids,
1533 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1534 if (count($deleted_contextids) === 1) {
1535 $deleted_contextid = $deleted_contextids[0];
1536 trigger_localised_error(
'CTX0003', E_USER_ERROR, $deleted_contextid, $e->getMessage());
1538 trigger_localised_error(
'CTX0004', E_USER_ERROR, count($deleted_contextids), $e->getMessage());
1546 foreach ($new_contextids as $new_contextid) {
1547 if ($GLOBALS[
'SQ_SYSTEM']->insertContextData($new_contextid) === FALSE) {
1553 foreach ($deleted_contextids as $deleted_contextid) {
1554 if ($GLOBALS[
'SQ_SYSTEM']->deleteContextData($deleted_contextid) === FALSE) {
1561 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1563 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1566 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1580 static $options = NULL;
1582 if (empty($options) === TRUE) {
1583 include SQ_FUDGE_PATH.
'/standards_lists/languages.inc';
1584 include SQ_FUDGE_PATH.
'/standards_lists/locales.inc';
1587 foreach (array_keys($standards_lists_locales) as $locale_code) {
1588 $matches = preg_match(
'/^([a-zA-Z\_\-]+)$/', $locale_code);
1589 if ($matches === 0) {
1590 unset($standards_lists_locales[$locale_code]);
1593 $overlap = array_intersect($standards_lists_languages, $standards_lists_locales);
1595 foreach ($overlap as $code => $language) {
1596 if(isset($standards_lists_languages[$code])) {
1597 $standards_lists_languages[$code] = translate(
'non_localised_variation', $language);
1601 $options = $standards_lists_locales + $standards_lists_languages;