.
*/
class ApplWorkshopID4 extends Appl {
private $workshops;
/* 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 = "WorkshopID4";
$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 "Time slot 2 -
2nd workshop choice";
}
/* get_print_name_short()
* Return the name of the field (caption) to be shown in a table
*/
public function get_print_name_short() {
return "Slot 2 - 2nd workshop";
}
/* 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 show_workshop($this->name, $this->value, 2, $readonly);
}
/* 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 $WORKSHOP2_SLOT, $WORKSHOP3, $WORKSHOP4, $CHAIRWS3;
if( (!$CHAIRWS3 AND ($WORKSHOP2_SLOT!="second" AND $WORKSHOP2_SLOT!="both") AND check_workshop($value, 2)==false) OR ($WORKSHOP2_SLOT=="both" AND $value>0) OR ($CHAIRWS3 AND $value>0) OR ($WORKSHOP3==$value AND $value>0) ) {
// Error
$this->error = true;
$this->error_txt = "The time slot 2 - 2nd workshop choice is invalid";
return false;
}else {
$this->value = $value;
$WORKSHOP4 = $value;
return true;
}
}
/* get()
* Return the value of this field.
* Normally the plain value is returned, if you need different behaviour,
* override this function
*/
public function get($oldvalue=false) {
$query = "SELECT `title` FROM `workshops` WHERE `id`=";
if( $oldvalue ) {
if( preg_match("/^[0-9]+$/", $this->oldvalue) ) $query.=addslashes($this->oldvalue);
else return "";
}else {
if( preg_match("/^[0-9]+$/", $this->value) ) $query.=addslashes($this->value);
else return "";
}
if( $row=@mysql_fetch_array( doquery($query) ) ) {
return $row['title'];
}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) {
global $setup;
if( $setup['SetupWSNumber']!=2 ) return self::ACCESS_NO;
elseif( $this->access>=0 ) return $this->access;
elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_workshopedit", $_SESSION['sess_functions']) ) return self::ACCESS_RW;
elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_workshopview", $_SESSION['sess_functions']) ) return self::ACCESS_R;
elseif( is_anon() && $new ) return self::ACCESS_RW;
elseif( is_before("EventDateWorkshopFix") && isset($_SESSION['access_user']) && $_SESSION['access_user'] ) return self::ACCESS_RW;
elseif( !is_before("EventDateWorkshopFix") && isset($_SESSION['access_user']) && $_SESSION['access_user'] && $new ) return self::ACCESS_RW;
elseif( !is_before("EventDateWorkshopFix") && 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();
//}
public function display($value, $ApplicationID=0, &$allvalues="") {
if( !is_array($this->workshops) ) {
$this->workshops = array();
$this->workshops[0] = "";
$query = "SELECT `id`, `title` FROM `workshops`";
if( @mysql_num_rows( $res=doquery($query) )>0 ) {
while( $row=mysql_fetch_array($res) ) {
$this->workshops[ $row['id'] ] = $row['title'];
}
}else {
debug("Failed loading workshops");
return $value;
}
}
if( array_key_exists($value, $this->workshops) )
return $this->workshops[$value];
else
return $value;
}
}
?>