. */ class CandExtraQuestion extends Cand { private $questionId; private $question; private $maxLength; public function __construct($candidate_id, $questionId=NULL, $question=NULL, $maxLength=NULL) { $this->candidate_id = $candidate_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; } } /* 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($cand_id) { if( $this->get_access()==Cand::ACCESS_RW ) { $querySave = NULL; $querySelect = "SELECT `answer` FROM `cand_extraanswers` WHERE `cand_id`=" . addslashes($cand_id) . " AND `question_id`=" . addslashes($this->questionId); if( @mysql_num_rows( $res=doquery($querySelect) )==0 ) { $querySave = "INSERT INTO `cand_extraanswers` (`cand_id`, `question_id`, `answer`) VALUES (" . addslashes($cand_id) . ", " . addslashes($this->questionId) . ", '" . addslashes($this->value) . "')"; }else { $row = mysql_fetch_assoc($res); if( $row['answer']!=$this->value ) { $querySave = "UPDATE `cand_extraanswers` SET `answer`='" . addslashes($this->value) . "' WHERE `cand_id`=" . addslashes($cand_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, $ApplicationID=0, &$allvalues="") { return nl2br($value); } public function get_access($new=true) { global $setup; if( get_sql_date($setup["EventDateEnd"]) < "2016-07-01" ) return false; return parent::get_access($new); } public function get_accesspublic() { global $setup; if( get_sql_date($setup["EventDateEnd"]) < "2016-07-01" ) return false; return parent::get_accesspublic(); } public function get_accesspublic_privacy($allowPublic) { global $setup; if( get_sql_date($setup["EventDateEnd"]) < "2016-07-01" ) return false; return parent::get_accesspublic_privacy($allowPublic); } } ?>