eventlastmodifiedby = $_SESSION['login']['loginid']; $this->companyid = $_SESSION['login']['companyid']; if(has_access(calendaraddeditevents)){ $this->permission_addeditevents = true; } if(has_access(calendardeleteownevents)){ $this->permission_deleteownevents = true; } if(has_access(calendareditothersevents)){ $this->permission_editothersevents = true; } if(has_access(calendardeleteothersevents)){ $this->permission_deleteothersevents = true; } } // few checks to run before making any changes private function _PreChangeChecks(){ if($this->companyid!=$_SESSION[login][companyid]){ $this->notice[error] = "Can't modified events from different company."; return false; } if($this->permission_addeditevents==false){ $this->notice[error] = "No permission to add/edit events."; return false; } //if the user is trying to make changes to OWN event, check to make sure they have persmission if($this->eventcreatedby && $this->eventcreatedby!=$_SESSION[login][loginid] && $this->permission_addeditevents==false){ $this->notice[error] = "No permission to add/edit own events."; return false; } //if the user is trying to make changes to event created by somebody else, check to make sure they have persmission if($this->eventcreatedby && $this->eventcreatedby!=$_SESSION[login][loginid] && $this->permission_editothersevents==false){ $this->notice[error] = "No permission to edit events of others."; return false; } //let's check to make sure user has persmission to DELETE before event is marked as deleted if($this->eventdeletedby || $this->eventdeleteddate){ //make sure that eventdeleted by is properly set if(!is_numeric($this->eventdeletedby)){ $this->notice[error] = "Valid ID must be provided for user to delete."; return false; } //make sure user has permission to delete their own events before the deletion if($this->eventcreatedby==$_SESSION[login][loginid] && $this->permission_deleteownevents==false){ $this->notice[error] = "No permission to delete own events."; return false; } //make sure user has permission to delete other's events before deletion if($this->eventcreatedby!=$_SESSION[login][loginid] && $this->permission_deleteothersevents==false){ $this->notice[error] = "No permission to delete events of others."; return false; } } } public function Get($eventid=''){ if(is_numeric($eventid)){ $this->eventid = $eventid; } return $this->_GetFromDB(); } private function _GetFromDB(){ if(!is_numeric($this->eventid)){ $this->notice[error] = "Event id is required"; return false; } $get_sql= "SELECT * FROM tblevent left join tblproperty using (propertyid) WHERE eventid = $this->eventid "; $result = db_first($get_sql); d($result); if($result){ $this->companyid = $result[companyid]; $this->propertyid = $result[propertyid]; $this->eventtitle = $result[eventtitle]; $this->eventdescription = $result[eventdescription]; $this->eventdatestart = $result[eventdatestart]; $this->eventdateend = $result[eventdateend]; $this->eventtimestart = $result[eventtimestart]; $this->eventtimeend = $result[eventtimeend]; $this->eventlastmodifiedby = $result[eventlastmodifiedby]; $this->eventlastmodifiedat = $result[eventlastmodifiedat]; $this->eventcanceled = $result[eventcanceled]; $this->eventcanceledby = $result[eventcanceledby]; $this->eventcanceldate = $result[eventcanceldate]; $this->eventcancelreason = $result[eventcancelreason]; $this->eventcreatedby = $result[eventcreatedby]; $this->eventcreateddate = $result[eventcreateddate]; $this->eventdeletedby = $result[eventdeletedby]; $this->eventdeleteddate = $result[eventdeleteddate]; $this->event_showon_companycalendar = $result[event_showon_companycalendar]; $this->event_showon_mycalendar = $result[event_showon_mycalendar]; if($result[eventcreatedby]!=loginid()) { $this->eventisreadonly = 1; }else { $this->eventisreadonly = 0; } return true; } else{ return false; } } public function Create(){ return $this->_SaveToDB(); } private function _SaveToDB(){ $this->_PreChangeChecks(); if(!$this->eventtitle){ $this->notice[error] = "Event title is required"; return false; } if(!$this->eventdatestart){ $this->notice[error] = "Event start date is required"; return false; } if($this->new_showon_companycalendar==0 && $this->new_showon_mycalendar==0){ $this->notice[error] = "You must select at least one calendar to display this event on."; return false; } $save_sql = "INSERT INTO tblevent ( eventid, companyid, propertyid, eventtitle, eventdescription, eventdatestart, eventdateend, eventtimestart, eventtimeend, eventlastmodifiedby, eventcreatedby, eventcreateddate, event_showon_companycalendar, event_showon_mycalendar ) VALUES ( DEFAULT, $this->companyid,"; if($this->propertyid==""){ $save_sql .= " NULL, \n "; } else{ $save_sql .= "'".trim($this->propertyid)."', \n"; } if($this->eventtitle==""){ $save_sql .= " NULL, \n "; } else{ $save_sql .= "'".pg_escape_string(trim($this->eventtitle))."', \n"; } if($this->eventdescription==""){ $save_sql .= " NULL, \n "; } else{ $save_sql .= "'".pg_escape_string(trim($this->eventdescription))."', \n"; } if($this->eventdatestart==NULL){ $save_sql .= " NULL, \n "; } else{ $save_sql .= "'$this->eventdatestart', \n"; } if($this->eventdateend==NULL){ $save_sql .= " NULL, \n"; } else{ $save_sql .= "'$this->eventdateend', \n"; } if($this->eventtimestart==NULL){ $save_sql .= " NULL, \n"; } else{ $save_sql .= "'$this->eventtimestart', \n"; } if($this->eventtimeend==NULL){ $save_sql .= " NULL, \n"; } else{ $save_sql .= "'$this->eventtimeend', \n"; } $save_sql .= " '$this->eventlastmodifiedby', '".$_SESSION['login']['loginid']."', NOW(), ".db_number($this->new_showon_companycalendar).", ".db_number($this->new_showon_mycalendar)." ) "; db_exec($save_sql,1); $current = db_first("SELECT lastval() as eventid"); $neweventid = $current[eventid]; if(is_numeric($neweventid)){ $this->eventid = $neweventid; $this->_GetFromDB(); // ALWAYS ADD A NOTE WHEN WE CREATE A NEW EVENT insert_property_event_note($this->propertyid,loginid(),pg_escape_string(trim($this->eventdescription)),pg_escape_string(trim($this->eventtitle)),$neweventid); // create_note($id=0,$type="",$text="",$sendemailtogroups="",$emailaddresslist="",$noteissystem=1, $section="",$noteisreadonly=0) return true; } else{ return false; } } public function Update(){ return $this->_UpdateToDB(); } private function _UpdateToDB(){ //d($this); $this->_PreChangeChecks(); //d($this,"this ded"); if(!is_numeric($this->eventid)){ $this->notice[error] = "Event ID is required"; return false; } if($this->edit_showon_companycalendar==0 && $this->edit_showon_mycalendar==0 && $this->eventdeleteddate==NULL){ $this->notice[error] = "You must select at least one calendar to display this event on."; ?>