18 require_once dirname(__FILE__).
'/../../form_question_rule/form_question_rule.inc';
44 parent::__construct($assetid);
59 1 => translate(
'core_form_rule_ends_with_true'),
60 0 => translate(
'core_form_rule_ends_with_false'),
82 static $printed_fn =
false;
84 $operator = array_get_index($rule_data,
'operator', 1);
85 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
86 $value = array_get_index($rule_data,
'value',
'');
87 $case_sensitive = array_get_index($rule_data,
'case_sensitive', 1);
95 function sq_form_validate_ends_with(answer, comparison, case_sensitive)
98 pos = answer.indexOf(comparison);
100 pos = answer.toLowerCase().indexOf(comparison.toLowerCase());
105 return (pos >= 0) && (pos == answer.length - comparison.length);
112 $comparison =
'form.elements["q'.$cq_id.
'"].value';
114 $comparison =
'"'.addslashes($value).
'"';
118 if (<?php echo ($operator == 1) ?
'!' :
''; ?>sq_form_validate_ends_with(form.elements[
"q<?php echo $q_asset->id; ?>"].value, <?php echo $comparison ?>, <?php echo (
int)$case_sensitive; ?>)) {
119 submission_errors[submission_errors.length] =
"<?php
120 if (empty($rule_data['custom_text'])) {
121 echo addslashes($this->defaultError($q_asset, $rule_data));
123 echo addslashes($rule_data['custom_text']);
129 $contents = ob_get_contents();
154 $operator = array_get_index($rule_data,
'operator', 1);
155 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
156 $value = array_get_index($rule_data,
'value',
'');
157 $case_sensitive = array_get_index($rule_data,
'case_sensitive', 1);
160 $comparison = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($cq_id);
161 $value = $comparison->getValue();
164 if (!$case_sensitive) {
165 $value = strtolower($value);
166 $answer = strtolower($answer);
173 while (($pos = strpos($answer, $value, $last_pos + 1)) !==
false) {
177 $valid = ($last_pos === strlen($answer)-strlen($value)) ? 1 : 0;
178 return $valid == $operator;
194 $operator = array_get_index($rule_data,
'operator', 1);
195 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
196 $value = array_get_index($rule_data,
'value',
'');
197 $case_sensitive = array_get_index($rule_data,
'case_sensitive', 1);
199 $string_code =
'core_form_rule_ends_with_desc_'.($operator ?
'true' :
'false');
200 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
203 $string_code .=
'_q';
204 $comparison = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($cq_id);
205 $value = $comparison->name;
207 $value = array_get_index($rule_data,
'value',
'');
210 $error_str = translate($string_code, $q_asset->name, $value).
' '.translate(
'core_form_'.($case_sensitive ?
'' :
'not_').
'case_sensitive');