. */ require_once("./include/SendMailPage.php"); class ApplGym extends Appl { /* Constructor * Make sure you set the name, and, when needed, if the field is * compulsory */ public function __construct($appl_id) { $this->appl_id = $appl_id; $this->name = "Gym"; $this->compulsory = true; } /* get_print_name() * Return the name of the field (caption) to be shown in the application * form */ public function get_print_name() { return "Gym"; } /* get_print_name_short() * Return the name of the field (caption) to be shown in a table */ public function get_print_name_short() { return "Gym"; } /* 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) { global $setup; $query = "SELECT `Gym`, COUNT(`Gym`) AS `count` FROM `applications` WHERE `Accepted`='yes' OR `Accepted`='arrived' OR `Accepted`='pending' OR `Accepted`='confirmed' GROUP BY `Gym`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { $placestaken = array(); while( $row = mysql_fetch_array($res) ) { $placestaken[ $row['Gym'] ] = $row['count']; } $r = ""; return $r; }else { return "Unable to load number of free places, please contact the ".SendMailPage::getLink("webmaster", "webmaster")."."; } } public function init($value) { $this->value = $value; $this->oldvalue = $value; } /* 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) { global $setup; $query = "SELECT `Gym`, COUNT(`Gym`) AS `count` FROM `applications` WHERE `Accepted`='yes' OR `Accepted`='arrived' OR `Accepted`='pending' OR `Accepted`='confirmed' GROUP BY `Gym`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { $placestaken = array(); while( $row = mysql_fetch_array($res) ) { $placestaken[ $row['Gym'] ] = $row['count']; } if( $this->value==$value AND $value>0 ) { // no change, and there is a value, always ok return true; }elseif( $placestaken[$value]<$setup['CapacityGym'.$value] ) { // still places in this gym $this->value = $value; return true; }else { $this->error = true; $this->error_txt = "Gym is invalid. Please select from the list"; return false; } }else { $this->error = true; $this->error_txt = "Unable to load number of free places, please contact the ".SendMailPage::getLink("webmaster", "webmaster")."."; return false; } } /* get() * Return the value of this field. * Normally the plain value is returned, if you need different behaviour, * override this function */ //public function get() { // return $this->value; //} /* 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) { global $setup; if( $setup['ApplShowGymSelector']==false || $setup['ShowParticipantList']==false ) return self::ACCESS_NO; elseif( $this->access>=0 ) return $this->access; elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_optionedit", $_SESSION['sess_functions']) ) return self::ACCESS_RW; elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_optionview", $_SESSION['sess_functions']) ) return self::ACCESS_R; elseif( (isset($_SESSION['access_user']) && $_SESSION['access_user']) || $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(); //} } ?>