/** * Validate the fields for a given PRT node. * @param array $errors the error so far. This array is added to and returned. * @param array $fromform the submitted data to validate. * @param string $prtname the name of the PRT to validate. * @param string $nodekey the name of the node to validate. * @return array the update $errors array. */ protected function validate_prt_node($errors, $fromform, $prtname, $nodekey, $fixingdollars) { $nodegroup = $prtname . 'node[' . $nodekey . ']'; $errors = $this->validate_cas_string($errors, $fromform[$prtname . 'sans'][$nodekey], $nodegroup, $prtname . 'sans' . $nodekey, 'sansrequired'); $errors = $this->validate_cas_string($errors, $fromform[$prtname . 'tans'][$nodekey], $nodegroup, $prtname . 'tans' . $nodekey, 'tansrequired'); $answertest = new stack_ans_test_controller($fromform[$prtname . 'answertest'][$nodekey]); if ($answertest->required_atoptions()) { $opt = trim($fromform[$prtname . 'testoptions'][$nodekey]); if ('' === trim($opt)) { $errors[$nodegroup][] = stack_string('testoptionsrequired'); } else { if (strlen($opt > 255)) { $errors[$nodegroup][] = stack_string('testoptionsinvalid', stack_string('strlengtherror')); } else { // TODO capture this for later execution. list($valid, $message) = $answertest->validate_atoptions($opt); if (!$valid) { $errors[$nodegroup][] = stack_string('testoptionsinvalid', $message); } } } } foreach (array('true', 'false') as $branch) { $branchgroup = $prtname . 'nodewhen' . $branch . '[' . $nodekey . ']'; $score = $fromform[$prtname . $branch . 'score'][$nodekey]; if (!is_numeric($score) || $score < 0 || $score > 1) { $errors[$branchgroup][] = stack_string('scoreerror'); } $penalty = $fromform[$prtname . $branch . 'penalty'][$nodekey]; if ('' != $penalty && (!is_numeric($penalty) || $penalty < 0 || $penalty > 1)) { $errors[$branchgroup][] = stack_string('penaltyerror2'); } $answernote = $fromform[$prtname . $branch . 'answernote'][$nodekey]; if ('' == $answernote) { $errors[$branchgroup][] = stack_string('answernoterequired'); } else { if (strstr($answernote, '|') !== false) { $errors[$branchgroup][] = stack_string('answernote_err'); foreach ($fromform[$prtname . $branch . 'answernote'] as $key => $strin) { if ('' == trim($strin)) { $interror[$prtname . 'nodewhen' . $branch . '[' . $key . ']'][] = stack_string('answernoterequired'); } else { if (strstr($strin, '|') !== false) { $nodename = $key + 1; $interror[$prtname . 'nodewhen' . $branch . '[' . $key . ']'][] = stack_string('answernote_err'); } } } } } $errors = $this->validate_cas_text($errors, $fromform[$prtname . $branch . 'feedback'][$nodekey]['text'], $prtname . $branch . 'feedback[' . $nodekey . ']', $fixingdollars); } return $errors; }