. */ class ApplExtraQuestion extends Appl { private $questionId; private $question; private $maxLength; public function __construct($appl_id, $questionId, $question, $maxLength) { $this->appl_id = $appl_id; $this->name = "ExtraQuestion_" . $questionId; $this->compulsory = true; $this->questionId = $questionId; $this->question = $question; $this->maxLength = $maxLength; } /* get_print_name() * Return the name of the field (caption) to be shown in the application * form */ public function get_print_name() { return $this->question; } /* get_print_name_short() * Return the name of the field (caption) to be shown in a table */ public function get_print_name_short() { return $this->question; } /* get_print_value($readonly) * Return the value to be printed in the form (with text boxes etc) * @param: readonly: if the field can be changed (false) or not (true) */ public function get_print_value($readonly=false) { return ""; } /* set($value) * Check the supplied value and assign it if ok (return true), otherwise * set an error and return false * @param: value: the value to be assigned and checked * @return: true on ok, false on error */ public function set($value) { if( strlen($value)<1 || strlen($value)>$this->maxLength ) { // Error $this->error = true; $this->error_txt = "Please use maximum " . $this->maxLength . " characters to answer the required '" . $this->question . "' (you have now " . strlen($value) . " characters)"; return false; }else { $this->value = $value; return true; } } /* get() * Return the value of this field. * Normally the plain value is returned, if you need different behaviour, * override this function */ //public function get($oldvalue=false) { // if( $oldvalue ) return $this->oldvalue; // else return $this->value; //} /* Normally a field is saved to MySQL. If you don't want to save it, or want to do something else before data is saved, override this function. * Make sure you return an array (can be empty) */ public function get_sql($new=true) { return array(); } public function post_save($appl_id) { if( $this->get_access()==Appl::ACCESS_RW ) { $querySave = NULL; $querySelect = "SELECT `answer` FROM `appl_extraanswers` WHERE `appl_id`=" . addslashes($appl_id) . " AND `question_id`=" . addslashes($this->questionId); if( @mysql_num_rows( $res=doquery($querySelect) )==0 ) { $querySave = "INSERT INTO `appl_extraanswers` (`appl_id`, `question_id`, `answer`) VALUES (" . addslashes($appl_id) . ", " . addslashes($this->questionId) . ", '" . addslashes($this->value) . "')"; }else { $row = mysql_fetch_assoc($res); if( $row['answer']!=$this->value ) { $querySave = "UPDATE `appl_extraanswers` SET `answer`='" . addslashes($this->value) . "' WHERE `appl_id`=" . addslashes($appl_id) . " AND `question_id`=" . addslashes($this->questionId); } } if( $querySave!=NULL ) { return doquery($querySave); } } return true; } public function sql_columnname() { return "`" . $this->name . "`.`answer` AS `" . $this->name . "`"; } public function display($value, $PersonID=0, &$allvalues="") { return nl2br($value); } } ?>