. */ abstract class Cand { const ACCESS_RW = 2; const ACCESS_R = 1; const ACCESS_NO = 0; protected $candidate_id; protected $name; protected $value; protected $oldvalue; protected $compulsory = true; protected $error = false; protected $error_txt = ""; abstract public function __construct($candidate_id); public function __destruct() { // Destructor } abstract public function get_print_name(); abstract public function get_print_name_short(); abstract public function get_print_value($readonly=false); abstract public function set($value); public function init($value) { if( $this->set($value) ) $this->oldvalue=$value; else $this->oldvalue=""; } public function check() { $this->error = false; if( isset($_POST[ $this->name ]) ) { $this->value = stripslashes(trim($_POST[ $this->name ])); return $this->set( $this->value ); }else { $this->error = true; $this->error_txt = "The field '" . $this->name . "' is compulsory."; return false; } } public function get($oldvalue=false) { if( $oldvalue ) return htmlspecialchars($this->oldvalue); else return htmlspecialchars($this->value); } public function getpublic() { return $this->get(); } public function is_error() { return $this->error; } public function get_error() { if( $this->error ) { return $this->error_txt; }else { return ""; } } public function get_access($new=true) { if( isset($_SESSION['sess_functions']) && in_array("candidate_edit", $_SESSION['sess_functions']) ) return self::ACCESS_RW; elseif( isset($_SESSION['sess_functions']) && in_array("candidate_viewdetail", $_SESSION['sess_functions']) ) return self::ACCESS_R; elseif( is_anon() AND $new ) return self::ACCESS_RW; elseif( isset($_SESSION['access_user']) && $_SESSION['access_user'] ) return self::ACCESS_RW; else return self::ACCESS_NO; } public function get_accesspublic() { return $this->get_accesspublic_privacy(true); } /** * Determines if privacy protected fields should be visible. * - before Agora true for everybody * - after Agora true only for logged in people * - 1y7m after Agora false for everybody * @param allowPublic: should the field ever be allowed public access */ public function get_accesspublic_privacy($allowPublic) { global $setup; if( $allowPublic && is_before("EventDateEnd") ) return true; elseif( isset($_SESSION['access_user']) && $_SESSION['access_user'] ) return true; else return false; } public function get_compulsory() { return $this->compulsory; } /* * get_sql(): Returns an array $var[item]=value * @param: - * @return: array $var[item]=value */ public function get_sql($new=true) { if( $this->get_access($new)==Cand::ACCESS_RW ) return array($this->name => $this->value); else return array(); } public function get_value($new=true) { $r = array(); if( !$new ) $r['old'][$this->get_print_name()] = $this->get(true); if( $this->get_access($new)==Cand::ACCESS_RW OR ($new AND $this->get_access($new)==Cand::ACCESS_R) ) $r['new'][$this->get_print_name()] = $this->get(); return $r; } /* * Method called after successfully saving an candidate. Can be used to store data in additional tables * @param: candidate ID (in case of new candidature, this will be set to the newly created ID) * @return: true in case everything went fine, false in case of error */ public function post_save($cand_id) { return true; } } ?>