. */ class ApplCountryCode extends Appl { private $countries; public function __construct($appl_id) { $this->appl_id = $appl_id; $this->name = "CountryCode"; $this->compulsory = false; $this->countries = false; } public function get_print_name() { return "Country"; } public function get_print_name_short() { return "Country"; } public function get_print_value($readonly=false) { $r = ""; return $r; } public function set($value) { 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; }else { $this->value = $value; return true; } } public function get($oldvalue=false) { $query="SELECT `Name` FROM `CountryCodes` WHERE `Code`=0"; if( $oldvalue ) $query.=addslashes($this->oldvalue); else $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( $this->access>=0 ) return $this->access; elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_addressedit", $_SESSION['sess_functions']) ) return self::ACCESS_RW; elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_addressview", $_SESSION['sess_functions']) ) return self::ACCESS_R; elseif( isset($_SESSION['access_user']) && $_SESSION['access_user'] ) return self::ACCESS_RW; elseif( $new ) return self::ACCESS_RW; 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(); //} public function display($value, $PersonID=0, &$allvalues="") { if( !is_array($this->countries) ) { $this->countries = array(); $query = "SELECT `Code`, `Name` FROM `CountryCodes`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { while( $row=mysql_fetch_array($res) ) { $this->countries[ $row['Code'] ] = ucwords(strtolower($row['Name'])); } }else { debug("Failed loading countries"); return $value; } } if( array_key_exists($value, $this->countries) ) return $this->countries[$value]; else return $value; } } ?>