. */ class CandNationality extends Cand { public function __construct($candidate_id) { $this->candidate_id = $candidate_id; $this->name = "Nationality"; $this->compulsory = true; } public function get_print_name() { return "Nationality"; } public function get_print_name_short() { return "Nationality"; } public function get_print_value($readonly=false) { $r = ""; return $r; } public function set($value) { if( isset($_POST['Visa']) && $_POST['Visa']=="yes" ) $this->compulsory = true; if( !preg_match("/(^(\d)+$)/", $value) ) $value=0; $query="SELECT `Code` FROM `countrycodes` WHERE `Code`=".addslashes($value); $numrows = @mysql_num_rows( doquery($query) ); if( $numrows!=1 AND $value!=0 ) { // Not found in the list, but something selected $this->error = true; $this->error_txt = "The nationality specified is not valid. Make sure you select one from the list"; return false; }elseif( $this->compulsory AND ($numrows!=1 OR $value==0) ) { // Field compulsory, but nothing provided $this->error = true; $this->error_txt = "The nationality is compulsory"; return false; }else { $this->value = $value; return true; } } public function get($oldvalue=false) { $query="SELECT `Name` FROM `countrycodes` WHERE `Code`="; if( $oldvalue ) { if( strlen($this->oldvalue)==0 ) return "unknown"; $query.=addslashes($this->oldvalue); }else { if( strlen($this->value)==0 ) return "unknown"; $query.=addslashes($this->value); } if( $row=@mysql_fetch_array( doquery($query) ) ) { return ucwords(strtolower($row['Name'])); }else { return "!ERROR!"; } } /* The default access for a field is that 'admin', 'chair', 'localorg' and 'edit' people can edit the field, as well as a logged in user. * Users with only 'view' can only view the field, and all others are denied access * Override this function if you want different access */ 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() && $new ) return self::ACCESS_RW; elseif( isset($_SESSION['access_user']) && $_SESSION['access_user'] && $new ) return self::ACCESS_RW; elseif( isset($_SESSION['access_user']) && $_SESSION['access_user'] ) return self::ACCESS_R; else return self::ACCESS_NO; } /* 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() { // return array(); //} } ?>