18 require_once dirname(__FILE__).
'/../../form_question_rule/form_question_rule.inc';
43 parent::__construct($assetid);
58 1 => translate(
'core_form_rule_begins_with_true'),
59 0 => translate(
'core_form_rule_begins_with_false'),
81 static $printed_fn =
false;
83 $operator = array_get_index($rule_data,
'operator', 1);
84 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
85 $value = array_get_index($rule_data,
'value',
'');
86 $case_sensitive = array_get_index($rule_data,
'case_sensitive', 1);
94 function sq_form_validate_begins_with(answer, comparison, case_sensitive)
97 return answer.indexOf(comparison) == 0;
99 return answer.toLowerCase().indexOf(comparison.toLowerCase()) == 0;
107 $comparison =
'form.elements["q'.$cq_id.
'"].value';
109 $comparison =
'"'.addslashes($value).
'"';
113 if (<?php echo ($operator == 1) ?
'!' :
''; ?>sq_form_validate_begins_with(form.elements[
"q<?php echo $q_asset->id; ?>"].value, <?php echo $comparison ?>, <?php echo (
int)$case_sensitive; ?>)) {
114 submission_errors[submission_errors.length] =
"<?php
115 if (empty($rule_data['custom_text'])) {
116 echo addslashes($this->defaultError($q_asset, $rule_data));
118 echo addslashes($rule_data['custom_text']);
124 $contents = ob_get_contents();
149 $operator = array_get_index($rule_data,
'operator', 1);
150 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
151 $value = array_get_index($rule_data,
'value',
'');
152 $case_sensitive = array_get_index($rule_data,
'case_sensitive', 1);
155 $comparison = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($cq_id);
156 if ($case_sensitive) {
157 $valid = (strpos($answer, $comparison->getValue()) === 0) ? 1 : 0;
159 $valid = (stripos(strtolower($answer), strtolower($comparison->getValue())) === 0) ? 1 : 0;
162 if ($case_sensitive) {
163 $valid = (strpos($answer, $value) === 0) ? 1 : 0;
165 $valid = (strpos(strtolower($answer), strtolower($value)) === 0) ? 1 : 0;
169 return $valid == $operator;
185 $operator = array_get_index($rule_data,
'operator', 1);
186 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
187 $value = array_get_index($rule_data,
'value',
'');
188 $case_sensitive = array_get_index($rule_data,
'case_sensitive', 1);
190 $string_code =
'core_form_rule_begins_with_desc_'.($operator ?
'true' :
'false');
191 $cq_id = array_get_index($rule_data,
'comparison_question_id', 0);
194 $string_code .=
'_q';
195 $comparison = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($cq_id);
196 $value = $comparison->name;
198 $value = array_get_index($rule_data,
'value',
'');
201 $error_str = translate($string_code, $q_asset->name, $value).
' '.translate(
'core_form_'.($case_sensitive ?
'' :
'not_').
'case_sensitive');