. */ class ApplDateDeparture extends Appl { public function __construct($appl_id) { $this->appl_id = $appl_id; $this->name = "DateDeparture"; $this->compulsory = false; } public function get_print_name() { return "Date and time of departure"; } public function get_print_name_short() { return "Departure"; } public function get_print_value($readonly=false) { global $setup; $r = show_date($this->name, $this->value, !$readonly, 1, 31, (integer)(substr($setup['EventDateStart'],3,2)), (integer)(substr($setup['EventDateStart'],3,2)+2), substr($setup['EventDateStart'],6,4), substr($setup['EventDateStart'],6,4), false); $r .= "   ".show_time($this->name, $this->value, !$readonly, 0, 23, 0, 59, 15); return $r; } public function get($oldvalue=false) { if( $oldvalue ) return get_date($this->oldvalue); else return get_date($this->value); } public function set($value) { if( preg_match("/(^(\d){4}-(\d){2}-(\d){2} (\d){2}:(\d){2}:(\d){2}$)/", $value) AND checkdate(substr($value, 5, 2), substr($value, 8, 2), substr($value, 0, 4)) AND (substr($value, 11, 2)>="00" AND substr($value, 11, 2)<="23") AND (substr($value, 14, 2)>="00" AND substr($value, 14, 2)<="59") AND (substr($value, 17, 2)>="00" AND substr($value, 17, 2)<="59") ) { // OK $this->value = $value; return true; }else { // Error if( $_SERVER['REQUEST_METHOD']=="POST" ) $this->error = true; $this->error_txt = "The date and time of departure is invalid"; return false; } } public function check() { $this->error = false; if( strlen($_POST[$this->name."_year"])==0 OR strlen($_POST[$this->name."_month"])==0 OR strlen($_POST[$this->name."_day"])==0 ) return !$this->compulsory; elseif( $_POST[$this->name."_hour"]==-1 OR $_POST[$this->name."_minute"]==-1 ) $this->value = $_POST[$this->name."_year"]."-".$_POST[$this->name."_month"]."-".$_POST[$this->name."_day"]." 00:00:00"; else $this->value = $_POST[$this->name."_year"]."-".$_POST[$this->name."_month"]."-".$_POST[$this->name."_day"]." ".$_POST[$this->name."_hour"].":".$_POST[$this->name."_minute"].":00"; return $this->set( $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) { if( $this->access>=0 ) return $this->access; elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_participateedit", $_SESSION['sess_functions']) ) return self::ACCESS_RW; elseif( isset($_SESSION['sess_functions']) && in_array("applicationfield_participateview", $_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($new=true) { // // Return when making new application or when there is write access // if( $this->get_access($new)==Appl::ACCESS_RW OR $new ) return array($this->name => $this->value); // else return array(); //} public function display($value, $PersonID=0, &$allvalues="") { return get_date($value); } } ?>