File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/event_booking/models/Events_model.php
Back
<?php //mb_internal_encoding('utf-8'); Class Events_Model extends CI_Model{ function saveEvent($data,$files,$id=0) { $CI =& get_instance(); $CI->load->model('event_booking/Venues_model'); $msgArray = array(); if(isset($data['repeat'])){ foreach ($data['repeat'] as $key => $repeatData) { if(isset($data['repeatType'][$key]) && $data['repeatType'][$key] == 'Daily'){ if(!isset($data['stopRepeating'.$key]))$data['stopRepeating'.$key] = 1; if(!isset($data['days'][$key]))$data['days'][$key] = 0; $dateArr = getDailyDates($data['startDate'][$key],$data['repeatDays'.$key],$data['stopRepeating'.$key],$data['stop_repeat_on'][$key],$data['stop_repeat_after'][$key],$data['days'][$key],$data['exclude_dates'][$key],$data['include_dates'][$key]); foreach ($dateArr as $arr) { if(!in_array($arr, $data['startDate'][$key])) array_push($data['startDate'][$key], $arr); } } if(isset($data['repeatType'][$key]) && $data['repeatType'][$key] == 'Weekly'){ if(!isset($data['stopRepeating'.$key]))$data['stopRepeating'.$key] = 1; if(!isset($data['weeks'][$key]))$data['weeks'][$key] = 0; if(!isset($data['repeat_on'][$key]))$data['repeat_on'][$key] = array(); $dateArr = getWeeklyDates($data['startDate'][$key],$data['repeat_on'][$key],$data['stopRepeating'.$key],$data['stop_repeat_on'][$key],$data['stop_repeat_after'][$key],$data['weeks'][$key],$data['exclude_dates'][$key],$data['include_dates'][$key]); foreach ($dateArr as $arr) { if(!in_array($arr, $data['startDate'][$key])) array_push($data['startDate'][$key], $arr); } } if(isset($data['repeatType'][$key]) && $data['repeatType'][$key] == 'Monthly'){ $monthlyArray = array(); if(!isset($data['stopRepeating'.$key]))$data['stopRepeating'.$key] = 1; if(!isset($data['monthlyOnDaySelect'][$key]))$data['monthlyOnDaySelect'][$key] = 0; if($data['monthlyOnDay'][$key] == 1) $monthlyArray = $data['monthlyMonth1'][$key]; if($data['monthlyOnDay'][$key] == 2) $monthlyArray = $data['monthlyMonth2'][$key]; $dateArr = getMonthlyDates($data['startDate'][$key],$data['monthlyOnDay'][$key],$data['stop_repeat_on'][$key],$data['stop_repeat_after'][$key],$data['exclude_dates'][$key],$data['include_dates'][$key],$data['monthlyOnDay'][$key],$data['monthlyOnDaySelect'][$key],$data['monthlyOnOccurences'][$key],$data['monthlyOnWeekDaySelect'][$key],$monthlyArray); foreach ($dateArr as $arr) { if(!in_array($arr, $data['startDate'][$key])) array_push($data['startDate'][$key], $arr); } } } } foreach ($data['startDate'] as $key => $startDt) { //implode the dates from repeat date so it combined with date and be a normal string if(is_array($startDt)) $data['startDate'][$key] = implode(',',$startDt); $tmp_array = explode(",",$data['startDate'][$key]); foreach($tmp_array as $k =>$time) { $tmp_array[$k] = strtotime(str_replace('/','-',$time)); } sort($tmp_array); foreach($tmp_array as $k =>$time) { $tmp_array[$k] = date('j/n/Y',$time); } $data['startDate'][$key] = implode(',',$tmp_array); } $eventData['event_title'] = $data['event_title']; $eventData['calendar_type_id'] = $data['calendar_type_id']; if(isset($data['event_type_id'])) $eventData['event_type_id'] = $data['event_type_id']; $eventData['remark'] = $data['remark']; $eventData['status'] = $data['status']; $eventData['serializeData'] = serialize($data); $user = $this->db->get_where('users',array('username' => $data['teacher_in_charge']))->row_array(); if(!empty($user)) $eventData['teacher_in_charge'] = $user['id']; $eventData['added_on'] = date('Y-m-d H:i:s'); if($id==0) { $this->db->insert('events',$eventData); $eventId = $this->db->insert_id(); } else { $this->db->update('events',$eventData,array('id' => $id)); $eventId = $id; $this->db->delete('event_has_forms',array('event_id' => $eventId)); if(!empty($data['deletedFiles']) && $data['deletedFiles']!=''){ $deletedFiles = explode(',', $data['deletedFiles']); foreach ($deletedFiles as $key => $file) { $f = $this->db->get_where('event_has_files',array('id' => $file))->row_array(); unlink(FCPATH.'files/event_files/'.$f['file_name']); $this->db->delete('event_has_files',array('id' => $file)); } } $eventSections = $this->db->get_where('event_has_sections',array('event_id' => $id))->result_array(); foreach ($eventSections as $key => $section) { $this->db->delete('event_section_has_facilities',array('section_id' => $section['id'])); $this->db->delete('event_section_has_participants',array('section_id' => $section['id'])); $this->db->delete('event_section_has_venues',array('section_id' => $section['id'])); } $this->db->delete('event_has_sections',array('event_id' => $id)); } if(!empty($data['forms'])) { foreach ($data['forms'] as $form) { $formApprover = $this->db->get_where('forms',array('id'=>$form,'approver >'=>0))->row_array(); $formStatus = 'PENDING'; /*if(empty($formApprover))$formStatus = 'APPROVED';*/ $this->db->insert('event_has_forms',array('event_id' => $eventId,'form_id' => $form,'status' => $formStatus)); } } foreach ($files['file']['name'] as $k => $name) { if(!empty($name)) { //$fileExt = pathinfo($name, PATHINFO_EXTENSION); //$fileName = generateRandomString(10).'.'.$fileExt; move_uploaded_file($files['file']["tmp_name"][$k], str_replace('\\',"/",FCPATH."files/event_files/" .$name)); $this->db->insert('event_has_files',array('event_id' => $eventId,'file_name' => $name)); } } //foreach ($data['startDate'] as $key => $startDate) { foreach ($data['startDate'] as $key => $dates) { $datesArray = explode(',', $dates); foreach ($datesArray as $key1 => $date) { $insertArray['event_id'] = $eventId; $date = date_create_from_format('d/m/Y', $date); $insertArray['startDate'] = $date->format('Y-m-d'); if(isset($data['from_time'][$key])){ foreach ($data['from_time'][$key] as $key2 => $from_time) { $insertArray['from_time'] = $from_time; $insertArray['to_time'] = $data['to_time'][$key][$key2]; $insertArray['section_group'] = $key; $this->db->insert('event_has_sections',$insertArray); $section_id = $this->db->insert_id(); if(isset($data['venues'][$key])){ foreach ($data['venues'][$key] as $venue) { unset($venueArray); $venueArray['section_id'] = $section_id; $venueArray['venue_id'] = $venue; $check = $this->checkForVenue($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$venue); if($check == 0){ $this->db->select('eb_venues.is_enabled,eb_venues.need_approval,eb_venues.approver_user_id,venues.*'); $this->db->join('eb_venues','eb_venues.venue_id = venues.id'); $venueInfo = $this->db->get_where('venues',array('venues.id'=>$venue))->row_array(); if(empty($venueInfo['approver_user_id'])) { $venueArray['status'] = 'APPROVED'; } else { if ($eventData['teacher_in_charge']==$venueInfo['approver_user_id']) $venueArray['status'] = 'APPROVED'; else $venueArray['status'] = 'PENDING'; } $this->db->insert('event_section_has_venues',$venueArray); } else { $errorVenue = $CI->Venues_model->get_venue($venue); if(!in_array('Conflict for venue "'.$errorVenue['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"', $msgArray)) array_push($msgArray, 'Conflict for venue "'.$errorVenue['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"'); } } } if(isset($data['facilities'][$key])){ foreach ($data['facilities'][$key] as $facility) { unset($facilityArray); $facilityArray['section_id'] = $section_id; $facilityArray['facility_id'] = $facility; // $check = $this->checkForFacility($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$facility); $check=0; if($check == 0){ $this->db->select('eb_facilities.is_enabled,eb_facilities.need_approval,eb_facilities.approver_user_id,facilities.*'); $this->db->join('eb_facilities','eb_facilities.facility_id = facilities.id'); $facilityInfo = $this->db->get_where('facilities',array('facilities.id'=>$facility))->row_array(); $facilityArray['status'] = 'PENDING'; if(empty($facilityInfo['approver_user_id'])) { $facilityArray['status'] = 'APPROVED'; } else { if ($eventData['teacher_in_charge']==$facilityInfo['approver_user_id']) $facilityArray['status'] = 'APPROVED'; else $facilityArray['status'] = 'PENDING'; } $this->db->insert('event_section_has_facilities',$facilityArray); } else { $errorFacility = $this->get_facility($facility); if(!in_array('Conflict for facility "'.$errorFacility['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"', $msgArray)) array_push($msgArray, 'Conflict for facility "'.$errorFacility['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"'); } } } if(isset($data['participants'][$key])){ foreach ($data['participants'][$key] as $participant) { unset($particpantArray); $array = explode('-', $participant); $particpantArray['group_id'] = $array[0]; $particpantArray['section_id'] = $section_id; $particpantArray['participant_id'] = $array[1]; $this->db->insert('event_section_has_participants',$particpantArray); } } if(isset($data['participantOther'][$key])){ if(trim($data['participantOther'][$key])!=''){ $particpantArray['section_id'] = $section_id; $particpantArray['participant_id'] = 0; $particpantArray['other'] = $data['participantOther'][$key]; $this->db->insert('event_section_has_participants',$particpantArray); } } if(isset($data['venueOther'][$key])){ if(trim($data['venueOther'][$key])!=''){ $venueArray['section_id'] = $section_id; $venueArray['venue_id'] = 0; $venueArray['other'] = $data['venueOther'][$key]; $venueArray['status'] = 'APPROVED'; $this->db->insert('event_section_has_venues',$venueArray); } } } } else { if(isset($data['timeslot'][$key])){ foreach ($data['timeslot'][$key] as $slot) { $timeSlot = $this->db->get_where('eb_time_slots',array('id' => $slot))->row_array(); if(!empty($timeSlot)){ $insertArray['from_time'] = $timeSlot['time_from']; $insertArray['to_time'] = $timeSlot['time_to']; $insertArray['section_group'] = $key; $this->db->insert('event_has_sections',$insertArray); $section_id = $this->db->insert_id(); if(isset($data['venues'][$key])){ foreach ($data['venues'][$key] as $venue) { $venueArray['section_id'] = $section_id; $venueArray['venue_id'] = $venue; $check = $this->checkForVenue($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$venue); if($check == 0){ $this->db->select('eb_venues.*','venues.*'); $this->db->join('eb_venues','venues.id = eb_venues.venue_id','left'); $venueInfo = $this->db->get_where('venues',array('venues.id'=>$venue))->row_array(); if(empty($venueInfo['approver_user_id'])) { $venueArray['status'] = 'APPROVED'; } else { if ($eventData['teacher_in_charge']==$venueInfo['approver_user_id']) $venueArray['status'] = 'APPROVED'; else $venueArray['status'] = 'PENDING'; } $this->db->insert('event_section_has_venues',$venueArray); } else { $errorVenue = $CI->Venues_model->get_venue($venue); if(!in_array('Conflict for venue "'.$errorVenue['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"', $msgArray)) array_push($msgArray, 'Conflict for venue "'.$errorVenue['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"'); } } } if(isset($data['facilities'][$key])){ foreach ($data['facilities'][$key] as $facility) { $facilityArray['section_id'] = $section_id; $facilityArray['facility_id'] = $facility; $check = $this->checkForFacility($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$facility); $check=0; if($check == 0){ $this->db->select('eb_facilities.*','facilities.*'); $this->db->join('eb_facilities','facilities.id = eb_facilities.facility_id','left'); $facilityInfo = $this->db->get_where('facilities',array('facilities.id'=>$facility))->row_array(); if(empty($facilityInfo['approver_user_id'])) { $facilityArray['status'] = 'APPROVED'; } else { if ($eventData['teacher_in_charge']==$facilityInfo['approver_user_id']) $facilityArray['status'] = 'APPROVED'; else $facilityArray['status'] = 'PENDING'; } $this->db->insert('event_section_has_facilities',$facilityArray); } else { $errorFacility = $this->get_facility($facility); if(!in_array('Conflict for facility "'.$errorFacility['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"', $msgArray)) array_push($msgArray, 'Conflict for facility "'.$errorFacility['title'].'" and Date : "'.$date->format('d/m/Y').' '.$insertArray['from_time'].'-'.$insertArray['to_time'].'"'); } } } if(isset($data['participants'][$key])){ foreach ($data['participants'][$key] as $participant) { $array = explode('-', $participant); $particpantArray['group_id'] = $array[0]; $particpantArray['section_id'] = $section_id; $particpantArray['participant_id'] = $array[1]; $this->db->insert('event_section_has_participants',$particpantArray); } } if(isset($data['participantOther'][$key])){ if(trim($data['participantOther'][$key])!=''){ $particpantArray['section_id'] = $section_id; $particpantArray['participant_id'] = 0; $particpantArray['other'] = $data['participantOther'][$key]; $this->db->insert('event_section_has_participants',$particpantArray); } } if(isset($data['venueOther'][$key])){ if(trim($data['venueOther'][$key])!=''){ $venueArray['section_id'] = $section_id; $venueArray['venue_id'] = 0; $venueArray['other'] = $data['venueOther'][$key]; $venueArray['status'] = 'APPROVED'; $this->db->insert('event_section_has_venues',$venueArray); } } } } } } } } //} $returnA['msgs'] = $msgArray; $returnA['id'] = $eventId; $this->changeEventStatus($eventId,$data['status']); $this->checkAcceptRejectEvent($eventId,'APPROVED'); return $returnA; } function getAllEvents(){ return $this->db->get_where('events')->result_array(); } //Used in e-calendar only function get_events($postData=array()){ $ii=0; $unsetKeys = array(); $setParticipantKeys = array(); $setVenuesKeys = array(); $removeKeys = array(); if(isset($postData['searchDt']) && $postData['searchDt'] != ''){ $searchDate = explode('-',$postData['searchDt']); $fromDate=strtotime(str_replace('/', '-',$searchDate[0])); $toDate=strtotime(str_replace('/', '-',$searchDate[1])); } $this->db->select('events.event_title,events.status,events.remark,events.event_type_id,events.teacher_in_charge,calendar_type.color,calendar_type.title as calendar_type_title,calendar_type.id as calendar_type_id,event_has_sections.*,added_on'); $this->db->join('events','event_has_sections.event_id = events.id'); $this->db->join('calendar_type','calendar_type.id = events.calendar_type_id'); if(isset($postData['person_in_charge']) && $postData['person_in_charge'] > 0) $this->db->where('events.teacher_in_charge',$postData['person_in_charge']); if(isset($postData['searchEvent']) && $postData['searchEvent'] > 0) $this->db->where('event_has_sections.event_id',$postData['searchEvent']); if(isset($postData['searchDt']) && $postData['searchDt'] != '') { $this->db->where('event_has_sections.startDate >= ',date('Y-m-d',$fromDate)); $this->db->where('event_has_sections.startDate <= ',date('Y-m-d',$toDate)); } if(isset($postData['searchCalendarType']) && $postData['searchCalendarType'] != '') $this->db->where('events.calendar_type_id',$postData['searchCalendarType']); if(isset($postData['status']) && $postData['status'] != '') if(is_array($postData['status'])) $this->db->where_in('events.status',$postData['status']); else $this->db->where('events.status',$postData['status']); else $this->db->where('events.status', 'PUBLISHED'); $this->db->where('calendar_type.hide_event',0); $data = $this->db->get_where('event_has_sections')->result_array(); foreach ($data as $key => $value) { //fix full calendar error if(strlen(explode(':',$value['from_time'])[0])<2)$data[$key]['from_time']='0'.$value['from_time']; if(strlen(explode(':',$value['to_time'])[0])<2)$data[$key]['to_time']='0'.$value['to_time']; $this->db->select('facilities.*'); $this->db->join('facilities','event_section_has_facilities.facility_id = facilities.id'); $facilities = $this->db->get_where('event_section_has_facilities',array('section_id' => $value['id']))->result_array(); $this->db->select('venues.*,event_section_has_venues.venue_id,event_section_has_venues.other'); $this->db->join('venues','event_section_has_venues.venue_id = venues.id','left'); $venues = $this->db->get_where('event_section_has_venues',array('section_id' => $value['id']))->result_array(); //echo $this->db->last_query();exit; $this->db->select('participants.*,event_section_has_participants.participant_id,event_section_has_participants.other'); $this->db->join('participants','event_section_has_participants.participant_id = participants.id','left'); $participants = $this->db->get_where('event_section_has_participants',array('section_id' => $value['id']))->result_array(); $facilitiesStr = ''; $participantsStr = ''; $venuesStr = ''; $u = $this->db->get_where('users',array('id' => $value['teacher_in_charge']))->row_array(); if(!empty($_COOKIE)) { if($_COOKIE['language']=='en') { $data[$key]['applicant'] = $u['name_english']; } else { $data[$key]['applicant'] = $u['name_chinese']; } } else { $data[$key]['applicant'] = $u['name_english']; } if(!empty($venues)) foreach ($venues as $venueKey => $venue) { if($venue['other']!=''){ if(($venueKey+1) != count($venues) || $venue['venue_id']!=0){ $venuesStr .= $venue['other'].','; } else{ $venuesStr .= $venue['other']; } } if(isset($postData['venue']) && $postData['venue'] != ''){ if($postData['venue'] != $venue['venue_id']){ if(!in_array($key, $unsetKeys)) array_push($unsetKeys, $key); } else{ if(!in_array($key, $setVenuesKeys)) array_push($setVenuesKeys, $key); } } if($venue['venue_id'] > 0){ if(($venueKey+1) == count($venues)){ $venuesStr .= $venue['title']; } else{ $venuesStr .= $venue['title'].','; } } } if(!empty($facilities)) foreach ($facilities as $facilityKey => $facility) { if(($facilityKey+1) == count($facilities)){ $facilitiesStr .= $facility['title']; } else{ $facilitiesStr .= $facility['title'].', '; } } if(!empty($participants)) foreach ($participants as $participantKey => $participant) { if($participant['other']!=''){ if(($participantKey+1) == count($participants)){ $participantsStr .= $participant['other']; } else{ $participantsStr .= $participant['other'].', '; } } else { if(isset($postData['participant']) && $postData['participant'] != ''){ if($postData['participant'] != $participant['participant_id']){ if(!in_array($key, $unsetKeys)) array_push($unsetKeys, $key); } else{ if(!in_array($key, $setParticipantKeys)) array_push($setParticipantKeys, $key); } } if($participant['participant_id'] > 0){ if(($participantKey+1) == count($participants)){ $participantsStr .= $participant['title']; } else{ $participantsStr .= $participant['title'].', '; } } } } $data[$key]['participantsStr'] = $participantsStr; $data[$key]['facilitiesStr'] = $facilitiesStr; $data[$key]['venuesStr'] = $venuesStr; $eventType = $this->db->get_where('event_types',array('id' => $value['event_type_id']))->row_array(); $data[$key]['event_type'] = ''; if(!empty($eventType)) $data[$key]['event_type'] = $eventType['title']; } if(empty($postData)) return $data; //$result = array(); if((isset($postData['participant']) && $postData['participant'] != '') && (isset($postData['venue']) && $postData['venue'] != '')){ $result = array_intersect($setParticipantKeys,$setVenuesKeys); $result = array_combine($result,$result); } if((isset($postData['participant']) && $postData['participant'] != '') && (isset($postData['venue']) && $postData['venue'] == '')){ $result = array_combine($setParticipantKeys,$setParticipantKeys); } if((isset($postData['participant']) && $postData['participant'] == '') && (isset($postData['venue']) && $postData['venue'] != '')){ $result = array_combine($setVenuesKeys,$setVenuesKeys); } //pr($data);exit; if(isset($result)){ $result = array_intersect_key($data,$result); return $result; } else return $data; } function getAllEventsDT($uid=0) { $this->db->select('events.id, events.teacher_in_charge, forms.title, events.event_title,calendar_type.title as calendar_title,events.status as event_status,group_concat(forms.title) as event_forms,group_concat(event_has_sections.startDate) as dates'); if(get_cookie('language')=='en') $this->db->select('users.name_english as username'); else $this->db->select('users.name_chinese as username'); $this->db->join('event_has_sections','event_has_sections.event_id=events.id'); $this->db->join('calendar_type','calendar_type.id=events.calendar_type_id'); $this->db->join('event_has_forms','event_has_forms.event_id=events.id','left'); $this->db->join('forms','forms.id=event_has_forms.form_id','left'); $this->db->join('users','events.teacher_in_charge=users.id'); if($uid!=0) $this->db->where('events.teacher_in_charge='.$uid); $this->db->group_by('events.id'); $db = $this->db->from('events'); return $this->datatable->get($db,$_POST); } function checkForVenue($date,$from_time,$to_time,$venue,$event_id=0){ $CI =& get_instance(); $CI->load->model('even_booking/Settings_model'); $draft = false; $settings=$CI->Settings_model->get_settings(); if($settings['check_conflict_for_draft_events']==1) $draft=true; if($venue == 0)return 0; $counter = 0; $this->db->where('startDate',$date); $this->db->where('event_id !='.$event_id); $data = $this->db->get_where('event_has_sections')->result_array(); $minute_from_time = hoursToMinutes($from_time)+1; $minute_to_time = hoursToMinutes($to_time) -1; foreach ($data as $key => $value) { $dateCounter = 0; if((hoursToMinutes($value['from_time']) < $minute_from_time || hoursToMinutes($value['to_time']) > $minute_to_time)&&(hoursToMinutes($value['from_time']) > $minute_to_time || hoursToMinutes($value['to_time']) < $minute_from_time)){ //echo 'no'.$value['id']; } else{ $check = $this->db->get_where('event_section_has_venues',array('section_id' => $value['id'],'venue_id' => $venue,'status'=>'APPROVED'))->row_array(); $eventInfo= $this->db->get_where('events', array('id' => $value['event_id']))->row_array(); if($draft) { if(!empty($check)&& ($eventInfo['status']=='PUBLISHED' || $eventInfo['status']=='PENDING'|| $eventInfo['status']=='DRAFT')) { $counter = $eventInfo['id']; } } else { if(!empty($check) && $eventInfo['status']=='PUBLISHED') { $counter = $eventInfo['id']; } } } } return $counter; } function checkForParticipant($date,$from_time,$to_time,$participant,$event_id=0){ $CI =& get_instance(); $CI->load->model('even_booking/Settings_model'); $draft = false; $settings=$CI->Settings_model->get_settings(); if($settings['check_conflict_for_draft_events']==1) $draft=true; if($participant == 0)return 0; $counter = 0; $this->db->where('startDate',$date); $this->db->where('event_id !='.$event_id); $data = $this->db->get_where('event_has_sections')->result_array(); $minute_from_time = hoursToMinutes($from_time)+1; $minute_to_time = hoursToMinutes($to_time) -1; foreach ($data as $key => $value) { $dateCounter = 0; if((hoursToMinutes($value['from_time']) < $minute_from_time || hoursToMinutes($value['to_time']) > $minute_to_time)&&(hoursToMinutes($value['from_time']) > $minute_to_time || hoursToMinutes($value['to_time']) < $minute_from_time)){ //echo 'no'.$value['id']; } else{ $check = $this->db->get_where('event_section_has_participants',array('section_id' => $value['id'],'participant_id' => $participant))->row_array(); $eventInfo= $this->db->get_where('events', array('id' => $value['event_id']))->row_array(); if($draft) { if(!empty($check)&& ($eventInfo['status']=='PUBLISHED' || $eventInfo['status']=='PENDING'|| $eventInfo['status']=='DRAFT')) { $counter = $eventInfo['id']; } } else { if(!empty($check) && $eventInfo['status']=='PUBLISHED') { $counter = $eventInfo['id']; } } } } return $counter; } function checkForFacility($date,$from_time,$to_time,$facility,$event_id=0){ $CI =& get_instance(); $CI->load->model('even_booking/Settings_model'); $draft = false; $settings=$CI->Settings_model->get_settings(); if($settings['check_conflict_for_draft_events']==1) $draft=true; if($facility == 0)return 0; $counter = 0; $this->db->where('startDate',$date); $data = $this->db->get_where('event_has_sections')->result_array(); foreach ($data as $key => $value) { if($value['event_id']!=$event_id){ $dateCounter = 0; $minute_from_time = hoursToMinutes($from_time); $minute_to_time = hoursToMinutes($to_time); if((hoursToMinutes($value['from_time']) < $minute_from_time || hoursToMinutes($value['to_time']) > $minute_to_time)&&(hoursToMinutes($value['from_time']) > $minute_to_time || hoursToMinutes($value['to_time']) < $minute_from_time)){ //echo 'no'.$value['id']; } else{ $check = $this->db->get_where('event_section_has_facilities',array('section_id' => $value['id'],'facility_id' => $facility,'status'=>'APPROVED'))->row_array(); $eventInfo= $this->db->get_where('events', array('id' => $value['event_id']))->row_array(); if($draft) { if(!empty($check)&& ($eventInfo['status']=='PUBLISHED' || $eventInfo['status']=='PENDING' || $eventInfo['status']=='DRAFT')) { $counter = $eventInfo['id']; } } else { if(!empty($check) && $eventInfo['status']=='PUBLISHED') { $counter = $eventInfo['id']; } } } } } return $counter; } function deleteEvent($id) { $eventSections = $this->db->get_where('event_has_sections',array('event_id' => $id))->result_array(); foreach ($eventSections as $key => $section) { $this->db->delete('event_section_has_facilities',array('section_id' => $section['id'])); $this->db->delete('event_section_has_participants',array('section_id' => $section['id'])); $this->db->delete('event_section_has_venues',array('section_id' => $section['id'])); } $files = $this->db->get_where('event_has_files',array('event_id' => $id))->result_array(); foreach ($files as $key => $file) { if(file_exists(FCPATH.'files/event_files/'.$file['file_name'])) unlink(FCPATH.'files/event_files/'.$file['file_name']); } $this->db->delete('event_has_files',array('event_id' => $id)); $this->db->delete('event_has_forms',array('event_id' => $id)); $this->db->delete('event_has_sections',array('event_id' => $id)); $this->db->delete('events',array('id' => $id)); return true; } function getEvent($id){ //$this->db->order_by("event_has_sections.section_group","asc"); //$this->db->order_by("startDate","asc"); $this->db->select('events.*,calendar_type.approver_user_id as calendar_type_approvers'); $this->db->join('calendar_type','calendar_type.id=events.calendar_type_id'); $data = $this->db->get_where('events',array('events.id' => $id))->row_array(); //$data = $this->db->get_where('events',array('id' => $id))->row_array(); if(!empty($data)) { $returnArray = array(); $timeSlot = array(); $date = array(); $facilitiesArray = array(); $participantsArray = array(); $participantsTextArray = array(); $venuesArray = array(); $venuesTextArray = array(); $user = $this->db->get_where('users',array('id'=>$data['teacher_in_charge']))->row_array(); $data['teacher_in_charge'] = $user['username']; $this->db->order_by("event_has_sections.section_group","asc"); $this->db->order_by("event_has_sections.startDate","asc"); $sections = $this->db->get_where('event_has_sections',array('event_id' => $id))->result_array(); foreach ($sections as $key => $section) { $returnArray[$section['section_group']] = $section; if(!isset($date[$section['section_group']])) $date[$section['section_group']] = array(); if(!isset($timeSlot[$section['section_group']])) $timeSlot[$section['section_group']] = array(); if(!isset($facilitiesArray[$section['section_group']])) $facilitiesArray[$section['section_group']] = array(); if(!isset($participantsArray[$section['section_group']])) $participantsArray[$section['section_group']] = array(); if(!isset($venuesArray[$section['section_group']])) $venuesArray[$section['section_group']] = array(); if(!isset($participantsTextArray[$section['section_group']])) $participantsTextArray[$section['section_group']] = array(); if(!isset($venuesTextArray[$section['section_group']])) $venuesTextArray[$section['section_group']] = array(); $facilities = $this->db->get_where('event_section_has_facilities',array('section_id' => $section['id']))->result_array(); foreach ($facilities as $facility) { array_push($facilitiesArray[$section['section_group']], $facility['facility_id']); } $participants = $this->db->get_where('event_section_has_participants',array('section_id' => $section['id']))->result_array(); foreach ($participants as $participant) { if($participant['other']!="") array_push($participantsTextArray[$section['section_group']], $participant['other']); else array_push($participantsArray[$section['section_group']], $participant['group_id'].'-'.$participant['participant_id']); } $venues = $this->db->get_where('event_section_has_venues',array('section_id' => $section['id']))->result_array(); foreach ($venues as $venue) { if($venue['other']!="") array_push($venuesTextArray[$section['section_group']], $venue['other']); else array_push($venuesArray[$section['section_group']], $venue['venue_id']); } if(!in_array(date('d/m/Y',strtotime($section['startDate'])), $date[$section['section_group']])) array_push($date[$section['section_group']], date('d/m/Y',strtotime($section['startDate']))); if(!in_array($section['from_time'].'-'.$section['to_time'], $timeSlot[$section['section_group']])) array_push($timeSlot[$section['section_group']], $section['from_time'].'-'.$section['to_time']); //pr($returnArray[$section['section_group']]['toTime']); } $data['sectionDate'] = $date; $data['timeSlot'] = $timeSlot; $data['facilities'] = $facilitiesArray; $data['participants'] = $participantsArray; $data['venues'] = $venuesArray; $data['venuesText'] = $venuesTextArray; $data['participantsText'] = $participantsTextArray; $data['sections'] = $returnArray; $formsArray = array(); $forms = $this->db->get_where('event_has_forms',array('event_id' => $id))->result_array(); foreach ($forms as $form) { array_push($formsArray, $form['form_id']); } $data['forms'] = $formsArray; $data['files'] = $this->db->get_where('event_has_files',array('event_id' => $id))->result_array(); } return $data; } function simpleGetEvent ($id) { $event = $this->db->get_where('events',array('id' => $id))->row_array(); return $event; } function getEventSerialized ($id) { $this->db->select('serializeData'); $event = $this->db->get_where('events',array('id' => $id))->row_array(); return unserialize($event['serializeData']); } function checkConflict($data){ $errorMsgs = array(); foreach ($data['startDate'] as $key => $startDate) { foreach ($startDate as $dates) { $datesArray = explode(',', $dates); foreach ($datesArray as $key1 => $date) { $insertArray['startDate'] = date('Y-m-d',strtotime($date)); if(isset($data['from_time'][$key])){ foreach ($data['from_time'][$key] as $key2 => $from_time) { $insertArray['from_time'] = $from_time; $insertArray['to_time'] = $data['to_time'][$key][$key2]; $insertArray['section_group'] = $key; if(isset($data['venues'][$key])){ foreach ($data['venues'][$key] as $venue) { $venueArray['venue_id'] = $venue; $check = $this->checkForVenue($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$venue); if($check > 0){ $this->db->select('eb_venues.is_enabled,eb_venues.need_approval,eb_venues.approver_user_id,venues.*'); $this->db->join('eb_venues','eb_venues.venue_id = venues.id'); $checkVenue = $this->db->get_where('venues',array('id' => $venue))->row_array(); $eventInfo = $this->simpleGetEvent($check); $currmsg = 'Conflict for venue "'.$errorVenue['title'].'" and Date : "'.date('d-m-Y',strtotime($date)).' '.$postData['from_time'][$key][$key2].'-'.$postData['to_time'][$key][$key2].'" with ' . $eventInfo['event_title'] . ' organized by ' . allUsers($eventInfo['teacher_in_charge'],1); array_push($errorMsgs, $currmsg); } } } if(isset($data['facilities'][$key])){ foreach ($data['facilities'][$key] as $facility) { $facilityArray['facility_id'] = $facility; $check = $this->checkForFacility($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$facility); if($check > 0){ $this->db->select('eb_facilities.is_enabled,eb_facilities.need_approval,eb_facilities.approver_user_id,facilities.*'); $this->db->join('eb_facilities','eb_facilities.venue_id = facilities.id'); $checkFacility = $this->db->get_where('facilities',array('id' => $facility))->row_array(); $eventInfo = $this->simpleGetEvent($check); $currmsg = 'Conflict for facility "'.$errorFacility['title'].'" and Date : "'.date('d-m-Y',strtotime($date)).' '.$postData['from_time'][$key][$key2].'-'.$postData['to_time'][$key][$key2].'" with ' . $eventInfo['event_title'] . ' organized by ' . allUsers($eventInfo['teacher_in_charge'],1); array_push($errorMsgs, $currmsg); } } } } } else { if(isset($data['timeslot'][$key])){ foreach ($data['timeslot'][$key] as $slot) { $timeSlot = $this->db->get_where('eb_time_slots',array('id' => $slot))->row_array(); if(!empty($timeSlot)){ $insertArray['from_time'] = $timeSlot['time_from']; $insertArray['to_time'] = $timeSlot['time_to']; $insertArray['section_group'] = $key; if(isset($data['venues'][$key])){ foreach ($data['venues'][$key] as $venue) { $venueArray['venue_id'] = $venue; $check = $this->checkForVenue($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$venue); if($check > 0){ $this->db->select('eb_venues.is_enabled,eb_venues.need_approval,eb_venues.approver_user_id,venues.*'); $this->db->join('eb_venues','eb_venues.venue_id = venues.id'); $checkVenue = $this->db->get_where('venues',array('id' => $venue))->row_array(); $eventInfo = $this->simpleGetEvent($check); $currmsg = 'Conflict for venue "'.$errorVenue['title'].'" and Date : "'.date('d-m-Y',strtotime($date)).' '.$postData['from_time'][$key][$key2].'-'.$postData['to_time'][$key][$key2].'" with ' . $eventInfo['event_title'] . ' organized by ' . allUsers($eventInfo['teacher_in_charge'],1); array_push($errorMsgs, $currmsg); } } } if(isset($data['facilities'][$key])){ foreach ($data['facilities'][$key] as $facility) { $facilityArray['facility_id'] = $facility; $check = $this->checkForFacility($insertArray['startDate'],$insertArray['from_time'],$insertArray['to_time'],$facility); if($check > 0){ $this->db->select('eb_facilities.is_enabled,eb_facilities.need_approval,eb_facilities.approver_user_id,facilities.*'); $this->db->join('eb_facilities','eb_facilities.venue_id = facilities.id'); $checkFacility = $this->db->get_where('facilities',array('id' => $facility))->row_array(); $eventInfo = $this->simpleGetEvent($check); $currmsg = 'Conflict for facility "'.$errorFacility['title'].'" and Date : "'.date('d-m-Y',strtotime($date)).' '.$postData['from_time'][$key][$key2].'-'.$postData['to_time'][$key][$key2].'" with ' . $eventInfo['event_title'] . ' organized by ' . allUsers($eventInfo['teacher_in_charge'],1); array_push($errorMsgs, $currmsg); } } } } } } } } } } return $errorMsgs; } function get_participants(){ $this->db->order_by('participant_group.title','asc'); $groups = $this->db->get_where('participant_group')->result_array(); foreach ($groups as $key => $group) { $this->db->select('participants.*'); $this->db->order_by('participants.title','asc'); $this->db->join('participants_has_groups','participants_has_groups.participant_id = participants.id'); $groups[$key]['participants'] = $this->db->get_where('participants',array('participants_has_groups.group_id' => $group['id']))->result_array(); } return $groups; } function get_facility($id) { return $this->db->get_where('facilities',array('id' => $id))->row_array(); } function getForms($id){ $this->db->select('forms.*'); $this->db->join('forms','forms.id = calendar_type_has_forms.form_id'); return $this->db->get_where('calendar_type_has_forms',array('calendar_type_id' => $id))->result_array(); } function getEventForms($id){ $this->db->select('forms.*,event_has_forms.id as eventForm_id,event_has_forms.status'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $data = $this->db->get_where('event_has_forms',array('event_has_forms.event_id' => $id,'forms.is_enabled'=>1))->result_array(); foreach ($data as $key => $value) { $this->db->order_by('rank'); $data[$key]['questions'] = $this->db->get_where('form_has_questions',array('form_id' => $value['id']))->result_array(); foreach ($data[$key]['questions'] as $qkey => $question) { $data[$key]['questions'][$qkey]['options'] = $this->db->get_where('form_question_has_options',array('question_id' => $question['id']))->result_array(); $data[$key]['questions'][$qkey]['question_has_questions'] = $this->db->get_where('form_question_has_questions',array('question_id' => $question['id']))->result_array(); $data[$key]['questions'][$qkey]['answers'] = $this->db->get_where('form_answers',array('event_id' => $id,'form_id' => $value['id'],'question_id' => $question['id']))->row_array(); $data[$key]['questions'][$qkey]['table'] = $this->db->get_where('form_answer_has_table',array('event_id' => $id,'form_id' => $value['id'],'question_id' => $question['id']))->result_array(); foreach ($data[$key]['questions'][$qkey]['question_has_questions'] as $ks => $q) { $grid = $this->db->get_where('form_answer_has_grid',array('event_id' => $id,'form_id' => $value['id'],'question_of_question_id' => $q['id']))->row_array(); if(!empty($grid)){ $data[$key]['questions'][$qkey]['question_has_questions'][$ks]['remark'] = $grid['remark']; $data[$key]['questions'][$qkey]['question_has_questions'][$ks]['answer'] = $grid['answer']; } else { $data[$key]['questions'][$qkey]['question_has_questions'][$ks]['remark'] = ''; $data[$key]['questions'][$qkey]['question_has_questions'][$ks]['answer'] = ''; } } } } return $data; } //2016-2-23 Now all view use this instead of the above //Used in previewEvent function get_my_events($id = 0,$postData=array(),$user_id=0,$mode=0){ //postData:(null=>normal, else=>searching) user_id:(0=>all,else=>specific) mode:(0=>all, 1=unfinished, 2=>finished) //pr($postData);exit; $unsetKeys = array(); $setVenuesKeys = array(); $fromDate = ''; $toDate = ''; if(isset($postData['searchDt']) && $postData['searchDt'] != ''){ $searchDate = explode('-',$postData['searchDt']); $fromDate=strtotime(str_replace('/', '-',$searchDate[0])); $toDate=strtotime(str_replace('/', '-',$searchDate[1])); } // edited on 6/1/2016 $this->db->select('events.*,event_types.title as event_type,calendar_type.title as calendar_type,users.username,event_has_sections.id as section_id'); if (!empty($postData)) $this->db->select('event_section_has_participants.participant_id'); $this->db->join('calendar_type','calendar_type.id = events.calendar_type_id','left'); $this->db->join('event_types','event_types.id = events.event_type_id','left'); $this->db->join('event_has_sections','event_has_sections.event_id = events.id'); $this->db->order_by('event_has_sections.section_group','ASC'); if (!empty($postData)) $this->db->join('event_section_has_participants', 'event_section_has_participants.section_id = event_has_sections.id','left'); $this->db->join('users','users.id = events.teacher_in_charge','left'); if($user_id > 0) $this->db->where('events.teacher_in_charge',$user_id); else{ if(isset($postData['person_in_charge']) && $postData['person_in_charge'] > 0) $this->db->where('events.teacher_in_charge',$postData['person_in_charge']); } if(isset($postData['searchDt']) && $postData['searchDt'] != ''){ $this->db->where('event_has_sections.startDate >= ',date('Y-m-d',$fromDate)); $this->db->where('event_has_sections.startDate <= ',date('Y-m-d',$toDate)); } if(isset($postData['searchCalendarType']) && $postData['searchCalendarType'] != '') $this->db->where('events.calendar_type_id',$postData['searchCalendarType']); if(isset($postData['status']) && $postData['status'] != '') $this->db->where('events.status',$postData['status']); if($id > 0) $this->db->where('events.id',$id); if(isset($postData['participant']) && $postData['participant'] != '') $this->db->where('event_section_has_participants.participant_id',$postData['participant']); // event duplicating in my event / all event //if(isset($postData['searchDt']) && $postData['searchDt'] != '') $this->db->group_by('events.id'); $events = $this->db->get_where('events')->result_array(); foreach ($events as $key => $event) { $this->db->select('forms.*,event_has_forms.status'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $events[$key]['forms'] = $this->db->get_where('event_has_forms',array('event_id' => $event['id']))->result_array(); //$this->db->order_by('startDate'); $this->db->order_by("event_has_sections.section_group","asc"); $this->db->order_by("event_has_sections.startDate","asc"); $this->db->select("id,event_id, startDate, from_time, to_time, section_group", FALSE); $sections = $this->db->get_where('event_has_sections',array('event_id' => $event['id']))->result_array(); //pr($this->db->last_query()); //$events[$key]['sectionDatesForCompare']=array(); foreach ($sections as $sectionKey => $section) { if(!isset($events[$key]['sectionDates'][$section['section_group']])) $events[$key]['sectionDates'][$section['section_group']] = array(); $sectionStartDate =$section['startDate']; if(!in_array($sectionStartDate, $events[$key]['sectionDates'][$section['section_group']])){ array_push($events[$key]['sectionDates'][$section['section_group']], $sectionStartDate); if($mode) $events[$key]['sectionDatesForCompare'][$section['section_group']]=$sectionStartDate; } if(!isset($events[$key]['sectionTime'][$section['section_group']])) $events[$key]['sectionTime'][$section['section_group']] = array(); if(!isset($events[$key]['venues'][$section['section_group']])) $events[$key]['venues'][$section['section_group']] = array(); if(!isset($events[$key]['facilities'][$section['section_group']])) $events[$key]['facilities'][$section['section_group']] = array(); if(!isset($events[$key]['participants'][$section['section_group']])) $events[$key]['participants'][$section['section_group']] = array(); if(!in_array($section['from_time'].' - '.$section['to_time'], $events[$key]['sectionTime'][$section['section_group']])) array_push($events[$key]['sectionTime'][$section['section_group']], $section['from_time'].' - '.$section['to_time']); $this->db->select('venues.id as venue_id, venues.*,event_section_has_venues.*,eb_venues.*'); $this->db->join('venues','venues.id = event_section_has_venues.venue_id','left'); $this->db->join('eb_venues','venues.id = eb_venues.venue_id','left'); $venues = $this->db->get_where('event_section_has_venues',array('section_id' => $section['id']))->result_array(); foreach ($venues as $venue) { if($venue['other'] == ''){ if($venue['id']!=''){ if(isset($postData['venue']) && $postData['venue'] != ''){ if($postData['venue'] != $venue['venue_id']){ if(!in_array($key, $unsetKeys)) array_push($unsetKeys, $key); } else{ if(!in_array($key, $setVenuesKeys)) array_push($setVenuesKeys, $key); } } if(!in_array($venue['title'],$events[$key]['venues'][$section['section_group']])) if($venue['need_approval']==1){ if ($venue['status']=="APPROVED") $venue['status'] = "BOOKED"; array_push($events[$key]['venues'][$section['section_group']], $venue['title'] . ' ('.$venue['status'].')'); } else array_push($events[$key]['venues'][$section['section_group']], $venue['title'] ); } else{ if(!in_array('N-A',$events[$key]['venues'][$section['section_group']])) array_push($events[$key]['venues'][$section['section_group']], 'N-A'); } } else{ if(!in_array($venue['other'],$events[$key]['venues'][$section['section_group']])) array_push($events[$key]['venues'][$section['section_group']], $venue['other']); } } $this->db->select('facilities.id as facility_id, facilities.*,event_section_has_facilities.*,eb_facilities.*'); $this->db->join('facilities','facilities.id = event_section_has_facilities.facility_id','left'); $this->db->join('eb_facilities','facilities.id = eb_facilities.facility_id','left'); $facilities = $this->db->get_where('event_section_has_facilities',array('section_id' => $section['id']))->result_array(); foreach ($facilities as $facility) { if(!in_array($facility['title'],$events[$key]['facilities'][$section['section_group']])) array_push($events[$key]['facilities'][$section['section_group']], $facility['title']); } $this->db->select('participants.*,event_section_has_participants.other'); $this->db->join('participants','participants.id = event_section_has_participants.participant_id','left'); $participants = $this->db->get_where('event_section_has_participants',array('section_id' => $section['id']))->result_array(); foreach ($participants as $participant) { if($participant['other'] == ''){ if($participant['id']!=''){ if(!in_array($participant['title'],$events[$key]['participants'][$section['section_group']])) array_push($events[$key]['participants'][$section['section_group']], $participant['title']); } else{ if(!in_array('N-A',$events[$key]['participants'][$section['section_group']])) array_push($events[$key]['participants'][$section['section_group']], 'N-A'); } } else{ if(!in_array($participant['other'],$events[$key]['participants'][$section['section_group']])) array_push($events[$key]['participants'][$section['section_group']], $participant['other']); } } } if($mode>0){ $last_series = count($events[$key]['sectionDates']); $last_dates = count($events[$key]['sectionDates'][$last_series]); $currentDate = strtotime('today midnight');; if($mode==2){ //finished if($currentDate<=strtotime(str_replace('/', '-',$events[$key]['sectionDatesForCompare'][$last_series]))) unset($events[$key]); }else{ //unfinished if($currentDate>strtotime(str_replace('/', '-',$events[$key]['sectionDatesForCompare'][$last_series]))) unset($events[$key]); } } } if(isset($postData['venue']) && $postData['venue'] != ''){ $result = array_combine($setVenuesKeys,$setVenuesKeys); } if(isset($result)){ $result = array_intersect_key($events,$result); return $result; } else return $events; } function getEventsDataTable($start=0,$limit=0,$search='',$order,$dir,$where=0,$uid=0,$show_hidden=false) { $this->db->select('events.*, users.username, events.event_title as event_title,calendar_type.title as calendar_type, group_concat(event_has_sections.startDate) as dates,group_concat(forms.title),events.status as event_status,group_concat(DISTINCT concat(forms.title," => ",event_has_forms.status)) as event_forms'); if(currLang()=='en') { $this->db->select('users.name_english as teacher_in_charge'); } else { $this->db->select('users.name_chinese as teacher_in_charge'); } $this->db->from('events'); $this->db->join('calendar_type','events.calendar_type_id=calendar_type.id'); $this->db->join('event_has_sections','events.id=event_has_sections.event_id'); $this->db->join('users','users.id=events.teacher_in_charge'); $this->db->join('event_has_forms','events.id = event_has_forms.event_id','left'); $this->db->join('forms','forms.id = event_has_forms.form_id','left'); if($limit!=0) { $this->db->limit($limit, $start); } if($uid!=0) $this->db->where('events.teacher_in_charge='.$uid); if($search) { $this->db->where('events.event_title LIKE "%'.$search . '%"'); } if(is_array($where)) { $this->db->where($where); } if(!$show_hidden) { $this->db->where('calendar_type.hide_event!=1'); } $this->db->order_by('event_has_sections.startDate', 'ASC'); $this->db->order_by($order, $dir); $this->db->group_by('events.id'); $data = $this->db->get()->result_array(); $last_query = $this->db->last_query(); $last_query = substr($last_query,0,strpos($last_query,'LIMIT')); $result = $this->db->query($last_query)->result_array(); $return['count'] = count($result); $return['data'] = $data; return $return; } function getTotalEvents() { $this->db->select('count(events.id) as count'); $this->db->from('events'); $result = $this->db->get()->row_array(); return $result['count']; } function getSearchedEvents($data) { //pr($data);exit; $this->db->select('events.*'); $this->db->join('calendar_type','calendar_type.id = events.calendar_type_id','left'); $this->db->join('event_types','event_types.id = events.event_type_id','left'); $this->db->join('users','users.id = events.teacher_in_charge','left'); $this->db->join('event_has_sections','event_has_sections.event_id = events.id'); if($data['searchBox']!=''){ $likeStr = ''; $wordArray = explode(' ',$data['searchBox']); foreach ($wordArray as $value) { $likeStr .= 'events.event_title like "%'.$value.'%" OR '; $likeStr .= 'calendar_type.title like "%'.$value.'%" OR '; $likeStr .= 'event_types.title like "%'.$value.'%" OR '; $likeStr .= 'users.username like "%'.$value.'%" OR '; } $likeStr = '('.rtrim($likeStr, "OR ").')'; $this->db->where($likeStr); } if($data['searchDate']!=''){ $searchDate = explode('-', $data['searchDate']); $dateStr = '(event_has_sections.startDate >= "'.date('Y-m-d',strtotime(trim($searchDate[0]))).'" and event_has_sections.startDate <= "'.date('Y-m-d',strtotime(trim($searchDate[1]))).'")'; $this->db->where($dateStr); } $dt = $this->db->get_where('events')->result_array(); //echo $this->db->last_query(); return $dt; } function approvalEventListing($user_id=0){ $eventsArray['forms'] = array(); $eventsArray['fillingForms'] = array(); $eventsArray['venues'] = array(); $eventsArray['facilities'] = array(); $eventsArray['events'] = array(); // (calendar type) $formArray = array(); $fillingFormsArray = array(); $venueArray = array(); $facilityArray = array(); $eventArray = array(); $this->db->select('event_has_forms.form_id'); $this->db->join('events','events.id = event_has_forms.event_id'); $this->db->group_by('event_has_forms.form_id'); $userEventsForms = $this->db->get_where('event_has_forms',array('events.teacher_in_charge' => $this->session->userdata('id'),'events.status'=>'PUBLISHED'))->result_array(); $forms = $this->db->get_where('forms',array('need_approval' => 1,'FIND_IN_SET('.$user_id.',approver) !=' => 0))->result_array(); //Venues $this->db->select('eb_venues.is_enabled,eb_venues.need_approval,eb_venues.approver_user_id,venues.*'); $this->db->join('eb_venues','eb_venues.venue_id = venues.id'); $venues = $this->db->get_where('venues',array('need_approval' => 1,'FIND_IN_SET('.$user_id.',approver_user_id) !=' => 0))->result_array(); //Facilities $this->db->select('eb_facilities.is_enabled,eb_facilities.need_approval,eb_facilities.approver_user_id,facilities.*'); $this->db->join('eb_facilities','eb_facilities.facility_id = facilities.id'); $facilities = $this->db->get_where('facilities',array('need_approval' => 1,'FIND_IN_SET('.$user_id.',approver_user_id) !=' => 0))->result_array(); //Events $this->db->select('events.*,calendar_type.id as calendar_id,calendar_type.need_approval, calendar_type.approver_user_id,calendar_type.title as calendar_title'); $this->db->join('calendar_type','events.calendar_type_id=calendar_type.id','inner'); $events = $this->db->get_where('events',array('events.status' => 'PENDING','calendar_type.need_approval' => 1,))->result_array(); $this->db->select('events.id, events.serializeData'); $circular_events = $this->db->get_where('events',array('teacher_in_charge' => $this->session->userdata('id')))->result_array(); foreach ($circular_events as $event){ $data = unserialize($event['serializeData']); if(!empty($data['requireCircular']) && $data['requireCircular']==1) { $count = $this->db->query('SELECT count(*) as count FROM `circulars` where event_id = ' . $event['id'] . ' group by event_id')->row_array(); if($count['count']<1) { $data['id'] = $event['id']; $eventsArray['circular'][] = $data ; } else { $rejected = $this->db->query('SELECT * FROM `circulars` where (status = "RELEASED" OR status = "REJECTED" or status = "PENDING" or status = "SUBMITTED") and event_id = ' . $event['id'])->row_array(); if(!empty($rejected)) { $data['id'] = $event['id']; $data['event_title'] = '<b>' .$rejected['circular_name'] . ' (' . $rejected['status'] .')</b>'; $eventsArray['circular'][] = $data ; } } } } foreach ($forms as $form) $formArray[] = $form['id']; foreach ($forms as $form) $overdueFormArray[] = $form['id']; foreach ($userEventsForms as $form) $fillingFormsArray[] = $form['form_id']; foreach ($venues as $venue) $venueArray[] = $venue['id']; foreach ($facilities as $facility) $facilityArray[] = $facility['id']; foreach ($events as $event) $eventArray[] = $event['id']; if(!empty($formArray)){ $this->db->select('events.*,forms.title as form_title,forms.deadline as form_deadline,forms.id as form_id,event_has_forms.status as form_status,event_has_forms.id as update_id'); $this->db->join('events','events.id = event_has_forms.event_id'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $this->db->where('event_has_forms.status','SUBMITTED'); //$this->db->where('events.status','PENDING'); $this->db->where_in('event_has_forms.form_id',$formArray); $eventsArray['forms'] = $this->db->get_where('event_has_forms')->result_array(); //echo $this->db->last_query(); } if(!empty($overdueFormArray)){ $this->db->select('events.*,forms.title as form_title,forms.deadline as form_deadline,forms.id as form_id,event_has_forms.status as form_status,event_has_forms.id as update_id'); $this->db->join('events','events.id = event_has_forms.event_id'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $status=array('PENDING','RELEASED','REJECTED'); $this->db->where_in('event_has_forms.status',$status); $this->db->where_in('events.status','PUBLISHED'); $this->db->where_in('event_has_forms.form_id',$formArray); $eventsArray['overdueForm'] = $this->db->get_where('event_has_forms')->result_array(); } if(!empty($fillingFormsArray)){ $this->db->select('events.*,forms.title as form_title,forms.deadline as form_deadline,forms.id as form_id,event_has_forms.status as form_status,event_has_forms.id as update_id'); $this->db->join('events','events.id = event_has_forms.event_id'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $status=array('PENDING','RELEASED','REJECTED','DRAFT'); $this->db->where_in('event_has_forms.status',$status); //$this->db->where('events.status','PENDING'); $this->db->where_in('event_has_forms.form_id',$fillingFormsArray); $eventsArray['fillingForms'] = $this->db->get_where('event_has_forms',array('events.teacher_in_charge' => $this->session->userdata('id')))->result_array(); //echo $this->db->last_query(); } //pr($eventsArray['fillingForms']);exit; if(!empty($venueArray)){ $this->db->select('events.*,event_has_sections.startDate,event_has_sections.from_time,event_has_sections.to_time,venues.title as venue_title,venues.id as venue_id,event_section_has_venues.status as venue_status,event_section_has_venues.id as update_id'); $this->db->join('event_has_sections','event_has_sections.id = event_section_has_venues.section_id'); $this->db->join('events','events.id = event_has_sections.event_id'); $this->db->join('venues','venues.id = event_section_has_venues.venue_id'); $this->db->join('eb_venues','venues.id = eb_venues.venue_id','left'); $where="(events.status = 'PENDING' OR events.status = 'PUBLISHED')"; $this->db->where($where); $this->db->where('event_has_sections.startDate >=', date("Y-m-d")); $this->db->where('eb_venues.approver_user_id',$user_id); $this->db->where('event_section_has_venues.status','PENDING'); $this->db->where_in('event_section_has_venues.venue_id',$venueArray); $eventsArray['venues'] = $this->db->get_where('event_section_has_venues')->result_array(); //echo $this->db->last_query(); } if(!empty($facilityArray)){ $this->db->select('events.*,event_has_sections.startDate,event_has_sections.from_time,event_has_sections.to_time,facilities.title as facility_title,facilities.id as facility_id,event_section_has_facilities.status as facility_status,event_section_has_facilities.id as update_id'); $this->db->join('event_has_sections','event_has_sections.id = event_section_has_facilities.section_id'); $this->db->join('events','events.id = event_has_sections.event_id'); $this->db->join('facilities','facilities.id = event_section_has_facilities.facility_id'); $this->db->join('eb_facilities','facilities.id = eb_facilities.facility_id','left'); $where="(events.status = 'PENDING' OR events.status = 'PUBLISHED')"; $this->db->where($where); $this->db->where('event_has_sections.startDate >=', date("Y-m-d")); $this->db->where('eb_facilities.approver_user_id',$user_id); $this->db->where('event_section_has_facilities.status','PENDING'); $this->db->where_in('event_section_has_facilities.facility_id',$facilityArray); $eventsArray['facilities'] = $this->db->get_where('event_section_has_facilities')->result_array(); } if(!empty($eventArray)){ foreach ($events as $key => $event) { $approverList=explode(',', $event['approver_user_id']); foreach ($approverList as $approver){ if ($approver==$user_id){ array_push($eventsArray['events'], $events[$key]); } } } } // $eventsArray['events'] = $events; //pr($eventsArray);exit; return $eventsArray; // exit; } function approveForm($id){ $formLastStatus = $this->db->get_where('event_has_forms',array('id' => $id))->row_array(); $historyArray['from_status'] = $formLastStatus['status']; $historyArray['to_status'] = 'APPROVED'; $historyArray['form_id'] = $formLastStatus['form_id']; $historyArray['event_id'] = $formLastStatus['event_id']; $historyArray['user_id'] = $this->session->userdata('id'); $this->formHistory($historyArray); //$this->db->update('events',array('status'=>2),array('id'=>$formLastStatus['event_id'])); $this->db->update('event_has_forms',array('status' => 'APPROVED'),array('id' => $id)); //$this->checkAcceptRejectEvent($formLastStatus['event_id'],'APPROVED'); return true; } function rejectForm($id){ $formLastStatus = $this->db->get_where('event_has_forms',array('id' => $id))->row_array(); $historyArray['from_status'] = $formLastStatus['status']; $historyArray['to_status'] = 'REJECTED'; $historyArray['form_id'] = $formLastStatus['form_id']; $historyArray['event_id'] = $formLastStatus['event_id']; $historyArray['user_id'] = $this->session->userdata('id'); $this->formHistory($historyArray); //$this->db->update('events',array('status'=>3),array('id'=>$formLastStatus['event_id'])); $this->db->update('event_has_forms',array('status' => 'REJECTED'),array('id' => $id)); //$this->checkAcceptRejectEvent($formLastStatus['event_id'],'REJECTED'); return true; } function releaseForm($id){ $formLastStatus = $this->db->get_where('event_has_forms',array('id' => $id))->row_array(); $historyArray['from_status'] = $formLastStatus['status']; $historyArray['to_status'] = 'RELEASED'; $historyArray['form_id'] = $formLastStatus['form_id']; $historyArray['event_id'] = $formLastStatus['event_id']; $historyArray['user_id'] = $this->session->userdata('id'); $this->formHistory($historyArray); return $this->db->update('event_has_forms',array('status' => 'RELEASED'),array('id' => $id)); } function withdrawForm($id){ $formLastStatus = $this->db->get_where('event_has_forms',array('id' => $id))->row_array(); $historyArray['from_status'] = $formLastStatus['status']; $historyArray['to_status'] = 'WITHDRAW'; $historyArray['form_id'] = $formLastStatus['form_id']; $historyArray['event_id'] = $formLastStatus['event_id']; $historyArray['user_id'] = $this->session->userdata('id'); $this->formHistory($historyArray); return $this->db->update('event_has_forms',array('status' => 'WITHDRAW'),array('id' => $id)); } function approveFacility($id){ $this->db->select('events.id'); $this->db->join('event_has_sections','event_has_sections.id = event_section_has_facilities.section_id'); $this->db->join('events','events.id = event_has_sections.event_id'); $event = $this->db->get_where('event_section_has_facilities',array('event_section_has_facilities.id' => $id))->row_array(); $this->db->update('event_section_has_facilities',array('status' => 'APPROVED'),array('id' => $id)); // $this->publish_event($event['id']); $this->checkAcceptRejectEvent($event['id'],'APPROVED'); return true; } function approveVenue($id){ $this->db->select('events.id'); $this->db->join('event_has_sections','event_has_sections.id = event_section_has_venues.section_id'); $this->db->join('events','events.id = event_has_sections.event_id'); $event = $this->db->get_where('event_section_has_venues',array('event_section_has_venues.id' => $id))->row_array(); $this->db->update('event_section_has_venues',array('status' => 'APPROVED'),array('id' => $id)); // $this->publish_event($event['id']); $this->checkAcceptRejectEvent($event['id'],'APPROVED'); return true; } function rejectFacility($id){ $this->db->select('events.id'); $this->db->join('event_has_sections','event_has_sections.id = event_section_has_facilities.section_id'); $this->db->join('events','events.id = event_has_sections.event_id'); $event = $this->db->get_where('event_section_has_facilities',array('event_section_has_facilities.id' => $id))->row_array(); //$this->db->update('events',array('status'=>3),array('id'=>$event['id'])); $this->db->update('event_section_has_facilities',array('status' => 'REJECTED'),array('id' => $id)); // $this->checkAcceptRejectEvent($event['id'],'REJECTED'); return true; } function rejectVenue($id){ $this->db->select('events.id'); $this->db->join('event_has_sections','event_has_sections.id = event_section_has_venues.section_id'); $this->db->join('events','events.id = event_has_sections.event_id'); $event = $this->db->get_where('event_section_has_venues',array('event_section_has_venues.id' => $id))->row_array(); $this->db->update('event_section_has_venues',array('status' => 'REJECTED'),array('id' => $id)); echo $this->db->last_query(); // $this->checkAcceptRejectEvent($event['id'],'REJECTED'); return true; } function submitForm($data,$submit) { //pr($data);exit; foreach ($data['questions'] as $key => $question) { $question['is_submitted'] = 1; $insertArray = array(); $answerExist = array(); $updateData = array('question_id' => $question['question'],'form_id' => $question['form_id'],'event_id' => $question['event_id']); $updateData['user_id'] = $this->session->userdata('id'); $answerExist = $this->db->get_where('form_answers',$updateData)->row_array(); if(!isset($question['options'])) $question['options'] = ''; if($question['questiontype'] == 'SINGLE_LINE' || $question['questiontype'] == 'MULTIPLE_LINE' || $question['questiontype'] == 'NUMBER' || $question['questiontype'] == 'RADIO_BUTTON' || $question['questiontype'] == 'DROPDOWN' || $question['questiontype'] == 'DATETIME' || $question['questiontype'] == 'DATE' || $question['questiontype'] == 'TIME' || $question['questiontype'] == 'CHECKBOX' || $question['questiontype'] == 'SUGGESTED') { $insertArray['question_id'] = $question['question']; $insertArray['user_id'] = $this->session->userdata('id'); if(is_array($question['options'])) $question['options'] = implode(',', $question['options']); $insertArray['answer'] = $question['options']; $insertArray['form_id'] = $question['form_id']; $insertArray['event_id'] = $question['event_id']; $insertArray['is_submitted'] = $question['is_submitted']; if(empty($answerExist)){ $this->db->insert('form_answers',$insertArray); } else{ if(!empty($updateData)){ $this->db->update('form_answers',$insertArray,$updateData); } } } if($question['questiontype'] == 'TABLE') { if(isset($question['tr']) && !empty($question['tr'])) { $rank = 0; $uuu['user_id'] = $this->session->userdata('id'); $this->db->delete('form_answer_has_table',array('user_id' => $uuu['user_id'],'form_id' => $question['form_id'],'question_id' => $question['question'],'event_id' => $question['event_id'])); foreach ($question['tr'] as $key => $tr) { $rank++; foreach ($tr as $td) { $tableArray = array(); //$tableArray['user_id'] = $this->session->userdata('id'); $tableArray['question_id'] = $question['question']; $tableArray['answer'] = $td; $tableArray['rank'] = $rank; $tableArray['form_id'] = $question['form_id']; $tableArray['event_id'] = $question['event_id']; $tableArray['user_id'] = $this->session->userdata('id'); $tableArray['is_submitted'] = $question['is_submitted']; $this->db->insert('form_answer_has_table',$tableArray); } } } } if($question['questiontype'] == 'GRID') { if(isset($question['tr']) && !empty($question['tr'])) { $this->db->delete('form_answer_has_grid',array('user_id' => $this->session->userdata('id'),'form_id' => $question['form_id'],'event_id' => $question['event_id'],'question_of_question_id' => $question['question'])); $rank = 0; foreach ($question['tr'] as $key => $tr) { $rank++; $tableArray = array(); if(!isset($tr['options'])) $tr['options'] =''; if(!isset($tr['id'])) $tr['id'] =''; if(!isset($tr['remark'])) $tr['remark'] =''; $tableArray['user_id'] = $this->session->userdata('id'); $tableArray['question_id'] = $question['question']; $tableArray['question_of_question_id'] = $tr['id']; $tableArray['answer'] = $tr['options']; $tableArray['remark'] = $tr['remark']; $tableArray['rank'] = $rank; $tableArray['form_id'] = $question['form_id']; $tableArray['event_id'] = $question['event_id']; $tableArray['is_submitted'] = $question['is_submitted']; $exist = $this->db->get_where('form_answer_has_grid',array('question_id'=>$tableArray['question_id'],'question_of_question_id'=>$tableArray['question_of_question_id'],'form_id' => $tableArray['form_id'],'user_id' => $tableArray['user_id'],'event_id' => $tableArray['event_id']))->row_array(); if(empty($exist)) $this->db->insert('form_answer_has_grid',$tableArray); else $this->db->update('form_answer_has_grid',$tableArray,array('id' => $exist['id'])); } } } } $this->db->select('forms.approver,event_has_forms.*'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $formLastStatus = $this->db->get_where('event_has_forms',array('form_id' => $question['form_id'],'event_id' => $question['event_id']))->row_array(); if($submit==1) { $historyArray['from_status'] = $formLastStatus['status']; // if($formLastStatus['approver'] > 0) // $historyArray['to_status'] = 'SUBMITTED'; // else // $historyArray['to_status'] = 'APPROVED'; $historyArray['form_id'] = $question['form_id']; $historyArray['event_id'] = $question['event_id']; $historyArray['user_id'] = $this->session->userdata('id'); $formInfo=$this->db->get_where('forms',array('id' => $historyArray['form_id']))->row_array(); if ($formInfo['approver']==$historyArray['user_id']) $historyArray['to_status'] = 'APPROVED'; else{ $historyArray['to_status'] = 'SUBMITTED'; $this->sendEmailToFormApprover($question['form_id'],$question['event_id']); //send to form approver } $this->db->update('event_has_forms',array('status'=>$historyArray['to_status']),array('form_id' => $question['form_id'],'event_id' => $question['event_id'])); $this->formHistory($historyArray); } else { $this->db->update('event_has_forms',array('status'=>'DRAFT'),array('form_id' => $question['form_id'],'event_id' => $question['event_id'])); } return true; } function formHistory($array){ return $this->db->insert('event_forms_history',$array); } function changeEventStatus($eventId = 0,$status=0){ $eventSectionArray = array(); $this->db->select('event_has_sections.id'); $eventSections = $this->db->get_where('event_has_sections',array('event_id' => $eventId))->result_array(); foreach ($eventSections as $key => $section) $eventSectionArray[] = $section['id']; $this->db->select('count(event_has_forms.id) as form_count'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $this->db->where('forms.approver > 0'); $formCount = $this->db->get_where('event_has_forms',array('event_id' => $eventId))->row_array(); if(!empty($eventSectionArray)){ $this->db->select('event_section_has_facilities.id,eb_facilities.approver_user_id'); $this->db->join('facilities','facilities.id = event_section_has_facilities.facility_id'); $this->db->join('eb_facilities','facilities.id = eb_facilities.facility_id','left'); $this->db->where_in('section_id',$eventSectionArray); $facilitiesCount = $this->db->get_where('event_section_has_facilities')->result_array(); foreach ($facilitiesCount as $row) { if($row['approver_user_id'] == 0){ $this->db->update('event_section_has_facilities',array('status'=>'APPROVED'),array('id' => $row['id'])); } } $this->db->select('event_section_has_venues.id,eb_venues.approver_user_id'); $this->db->join('venues','venues.id = event_section_has_venues.venue_id'); $this->db->join('eb_venues','venues.id = eb_venues.venue_id','left'); $this->db->where_in('section_id',$eventSectionArray); $venuesCount = $this->db->get_where('event_section_has_venues')->result_array(); //echo $this->db->last_query(); //pr($eventSectionArray);pr($venuesCount);exit; foreach ($venuesCount as $row) { if($row['approver_user_id'] == 0){ $this->db->update('event_section_has_venues',array('status'=>'APPROVED'),array('id' => $row['id'])); } } } /*if(!isset($facilitiesCount['facilities_count'])){ $facilitiesCount['facilities_count'] = 0; $venuesCount['venues_count'] = 0; }*/ /*if($formCount['form_count'] == 0 && $facilitiesCount['facilities_count'] == 0 && $venuesCount['venues_count'] == 0) $status = 2; if($venuesCount['venues_count'] > 0 || $facilitiesCount['facilities_count'] > 0) $status = 0;*/ $this->db->update('events',array('status'=>$status),array('id'=>$eventId)); } function checkAcceptRejectEvent($eventId = 0,$status = ''){ if($status == 'REJECTED'){ $eventSectionArray = array(); $this->db->select('event_has_sections.id'); $eventSections = $this->db->get_where('event_has_sections',array('event_id' => $eventId))->result_array(); foreach ($eventSections as $key => $section) $eventSectionArray[] = $section['id']; $this->db->update('event_has_forms',array('status'=>'PENDING'),array('event_id' => $eventId)); if(!empty($eventSectionArray)){ $this->db->where_in('section_id',$eventSectionArray); $this->db->update('event_section_has_facilities',array('status' => 'PENDING')); $this->db->where_in('section_id',$eventSectionArray); $this->db->update('event_section_has_venues',array('status' => 'PENDING')); } } if($status == 'APPROVED'){ $eventSectionArray = array(); $this->db->select('event_has_sections.id'); $eventSections = $this->db->get_where('event_has_sections',array('event_id' => $eventId))->result_array(); foreach ($eventSections as $key => $section) $eventSectionArray[] = $section['id']; $this->db->select('count(event_has_forms.id) as form_count'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $formCount = $this->db->get_where('event_has_forms',array('event_id' => $eventId))->row_array(); $this->db->select('count(event_has_forms.id) as form_count'); $this->db->join('forms','forms.id = event_has_forms.form_id'); $this->db->where('event_has_forms.status','APPROVED'); $this->db->or_where('event_has_forms.status','SUBMITTED'); $formCheckCount = $this->db->get_where('event_has_forms',array('event_id' => $eventId))->row_array(); if(!empty($eventSectionArray)){ $this->db->select('count(event_section_has_facilities.id) as facilities_count'); $this->db->join('facilities','facilities.id = event_section_has_facilities.facility_id'); $this->db->join('eb_facilities','eb_facilities.facility_id = facilities.id'); $this->db->where('eb_facilities.approver_user_id > 0'); $this->db->where_in('section_id',$eventSectionArray); $facilitiesCount = $this->db->get_where('event_section_has_facilities')->row_array(); $this->db->select('count(event_section_has_facilities.id) as facilities_count'); $this->db->join('facilities','facilities.id = event_section_has_facilities.facility_id'); $this->db->join('eb_facilities','eb_facilities.facility_id = facilities.id'); $this->db->where_in('section_id',$eventSectionArray); $this->db->where('event_section_has_facilities.status','APPROVED'); $facilitiesCheckCount = $this->db->get_where('event_section_has_facilities')->row_array(); $this->db->select('count(event_section_has_venues.id) as venues_count'); $this->db->join('venues','venues.id = event_section_has_venues.venue_id'); $this->db->join('eb_venues','eb_venues.venue_id = venues.id'); $this->db->where('eb_venues.approver_user_id > 0'); $this->db->where_in('section_id',$eventSectionArray); $venuesCount = $this->db->get_where('event_section_has_venues')->row_array(); $this->db->select('count(event_section_has_venues.id) as venues_count'); $this->db->join('venues','venues.id = event_section_has_venues.venue_id'); $this->db->where_in('section_id',$eventSectionArray); $this->db->where('event_section_has_venues.status','APPROVED'); $venuesCheckCount = $this->db->get_where('event_section_has_venues')->row_array(); } } } function getEventVenues($event_id = 0){ $returnArray = array(); $eventSectionArray = array(); $this->db->select('event_has_sections.id'); $eventSections = $this->db->get_where('event_has_sections',array('event_id' => $event_id))->result_array(); foreach ($eventSections as $key => $section) $eventSectionArray[] = $section['id']; $this->db->select('venues.id,venues.title,event_section_has_venues.status'); $this->db->join('venues','venues.id = event_section_has_venues.venue_id'); $this->db->where_in('section_id',$eventSectionArray); $venues = $this->db->get_where('event_section_has_venues')->result_array(); foreach ($venues as $key => $venue) $returnArray[$venue['title']][] = $venue['status']; return $returnArray; } function getEventFacilities($event_id = 0){ $returnArray = array(); $eventSectionArray = array(); $this->db->select('event_has_sections.id'); $eventSections = $this->db->get_where('event_has_sections',array('event_id' => $event_id))->result_array(); foreach ($eventSections as $key => $section) $eventSectionArray[] = $section['id']; $this->db->select('facilities.id,facilities.title,event_section_has_facilities.status'); $this->db->join('facilities','facilities.id = event_section_has_facilities.facility_id'); $this->db->where_in('section_id',$eventSectionArray); $facilities = $this->db->get_where('event_section_has_facilities')->result_array(); foreach ($facilities as $key => $facility) $returnArray[$facility['title']][] = $facility['status']; return $returnArray; } //////////////Edited on 29/12/2015//////////////// function sendEmailToVenueApprover($eventId,$venue_id){ $eventData = $this->db->get_where('events', array('id' => $eventId))->row_array(); if($eventData['status']>0){ $eventData['applicant'] = $this->db->get_where('users', array('id' => $eventData['teacher_in_charge']))->row_array(); $this->db->select('eb_venues.is_enabled,eb_venues.need_approval,eb_venues.approver_user_id,venues.*'); $this->db->join('eb_venues','eb_venues.venue_id = venues.id'); $eventData['venueData'] = $this->db->get_where('venues', array('venues.id' => $venue_id))->row_array(); if ($eventData['venueData']['approver_user_id']!=$eventData['teacher_in_charge']){ if ($eventData['venueData']['need_approval']){ $eventData['venueApprover'] = $this->db->get_where('users', array('id' => $eventData['venueData']['approver_user_id']))->row_array(); $amendCount = ''; // if($eventData['amend_count']>0) // $amendCount = '-'.$eventData['amend_count']; $data=unserialize($eventData['serializeData']); //$numOfTimeSlot=sizeof($data['timeslot'][$key]); $date=explode(",", $data['startDate'][1]); if (sizeof($date)==1) $date[1]=$date[0]; if ($data['remark']==null) $data['remark']="None"; $email_data['approver_name'] = $eventData['venueApprover']['name_english']; $email_data['data'] =$data; $email_data['remark'] =$data['remark']; $email_data['sDate'] =$date[0]; $email_data['eDate'] =$date[1]; $email_data['sTime']=""; $email_data['eTime']=""; if(isset($data['timeslot'])){ $time=$this->db->get_where('eb_time_slots', array('id' => $data['timeslot'][1][0]))->row_array(); $email_data['sTime'] =$time['time_from']; $email_data['eTime'] =$time['time_to']; }else{ foreach ($data['from_time'] as $j=>$section) { foreach ($section as $k=>$timeslot) { $email_data['sTime'] = $email_data['sTime']. "," . $data['from_time'][$j][$k]; $email_data['eTime'] = $email_data['eTime'] . "," . $data['to_time'][$j][$k]; } } } $email_data['venue_name'] = $eventData['venueData']['title']; $email_data['event_name'] = $eventData['event_title']; $email_data['applicant'] = $eventData['applicant']['name_english']; $email_data['send_email_to'] = $eventData['venueApprover']['email']; $email_data['email_subject'] = 'Request for a Camplus Venue Usage Approval'; $email_data['base_url'] = base_url(); $email_data['evUrl'] = base_url().'event_booking/events/eventDashboard#ven_'.$eventId.'_'.$venue['venue_id']; //$email_data['test']=$data; // $email_data['test2']=$user_id; // $email_data['test3']=$eventData; if($_COOKIE['language']=="ch"){ $lang = $_COOKIE['language']; $email_data['approver_name'] = $eventData['venueApprover']['name_chinese']; $email_data['applicant'] = $eventData['applicant']['name_chinese']; $email_data['email_subject'] = "場地審批請求"; if ($data['remark']=="None") $email_data['remark']="不適用"; } else $lang = 'en'; $msg = $this->load->view('emails/'.$lang.'/venue_approval_email',$email_data,TRUE); $datas = array( 'subject' => $email_data['email_subject'], 'message' => $msg ); email($formData['approver']['id'],$datas['subject'],$datas['message'], base_url().'event_booking/events/eventDashboard#ven_'.$eventId.'_'.$venue['venue_id'],'EB'); } } } } function sendEmailToFacilityApprover($eventId,$facility_id){ $facilityData = $this->db->get_where('facilities', array('id' => $facility_id))->row_array(); if ($facilityData['need_approval']){ $eventInfo= $this->db->get_where('events', array('id' => $eventId))->row_array(); $data=unserialize($eventInfo['serializeData']); $date=explode(",", $data['startDate'][1]); $facilityData['applicant']=$this->db->get_where('users', array('id' => $eventInfo['teacher_in_charge']))->row_array(); $facilityData['approver']=$this->db->get_where('users', array('id' => $facilityData['approver_user_id']))->row_array(); if (sizeof($date)==1) $date[1]=$date[0]; if (!isset($facilityData['remarks'])) $facilityData['remarks']="None"; $email_data['facility_name'] =$facilityData['title']; $email_data['remark'] =$facilityData['remarks']; $email_data['approver_name'] =$facilityData['approver']['name_english']; $email_data['send_email_to'] =$facilityData['approver']['email']; $email_data['applicant_name'] =$facilityData['applicant']['name_english']; $email_data['event_name'] =$eventInfo['event_title']; $email_data['sDate'] =$date[0]; $email_data['eDate'] =$date[1]; if(isset($data['timeslot'])){ $time=$this->db->get_where('eb_time_slots', array('id' => $data['timeslot'][1][0]))->row_array(); $email_data['sTime'] =$time['time_from']; $email_data['eTime'] =$time['time_to']; }else{ foreach ($data['from_time'] as $j=>$section) { foreach ($section as $k=>$timeslot) { $email_data['sTime'] = $email_data['sTime']. "," . $data['from_time'][$j][$k]; $email_data['eTime'] = $email_data['eTime'] . "," . $data['to_time'][$j][$k]; } } } $email_data['email_subject'] = 'Request for Event Facility approval'; $email_data['base_url'] = base_url(); $email_data['facUrl'] = base_url().'event_booking/events/eventDashboard#fac_'.$eventId.'_'.$facility_id; if($_COOKIE['language']=="ch"){ $lang = $_COOKIE['language']; $email_data['approver_name'] = $formData['approver']['name_chinese']; $email_data['applicant'] = $formData['applicant']['name_chinese']; $email_data['email_subject'] = "設施審批請求"; } else $lang = 'en'; $msg = $this->load->view('emails/'.$lang.'/facility_approval_email',$email_data,TRUE); $datas = array( 'subject' => $email_data['email_subject'], 'message' => $msg ); email($formData['approver']['id'],$datas['subject'],$datas['message'], base_url().'event_booking/events/eventDashboard#fac_'.$eventId.'_'.$facility_id ,'EB'); } } function sendEmailToFormApprover($formId,$eventId){ $formData = $this->db->get_where('forms', array('id' => $formId))->row_array(); if ($formData['need_approval']){ $eventInfo= $this->db->get_where('events', array('id' => $eventId))->row_array(); $eventData=unserialize($eventInfo['serializeData']); $date=explode(",", $eventData['startDate'][1]); $formData['applicant']=$this->db->get_where('users', array('id' => $eventInfo['teacher_in_charge']))->row_array(); $formData['approver']=$this->db->get_where('users', array('id' => $formData['approver']))->row_array(); $dateDMY=explode("/", $date[0]); $deadLine=date( 'd/m/Y', strtotime( $dateDMY[1].'/'.$dateDMY[0].'/'.$dateDMY[2] . ' -'.$formData['deadline'].' day' ) ); $email_data['form_name'] =$formData['title']; $email_data['approver_name'] =$formData['approver']['name_english']; $email_data['send_email_to'] =$formData['approver']['email']; $email_data['applicant_name'] =$formData['applicant']['name_english']; $email_data['event_name'] =$eventData['event_title']; $email_data['eventDate'] =$date[0]; $email_data['deadLine'] =$deadLine; $email_data['email_subject'] = 'Request for an Event Form approval'; $email_data['base_url'] = base_url(); $email_data['efUrl'] = base_url().'event_booking/events/eventDashboard#pf_'.$eventId.'_'.$formId; if($_COOKIE['language']=="ch"){ $lang = $_COOKIE['language']; $email_data['approver_name'] = $formData['approver']['name_chinese']; $email_data['applicant_name'] = $formData['applicant']['name_chinese']; $email_data['email_subject'] = "表格審批請求"; } else $lang = 'en'; $msg = $this->load->view('emails/'.$lang.'/form_approval_email',$email_data,TRUE); $datas = array( 'subject' => $email_data['email_subject'], 'message' => $msg ); email($formData['approver']['id'],$datas['subject'],$datas['message'], base_url().'event_booking/events/eventDashboard#pf_'.$eventId.'_'.$formId,'EB'); } } function sendEmailToEventApprover($event_id){ if($event_id>0){ $eventInfo=$this->db->get_where('events',array('id'=>$event_id))->row_array(); $applicant=$this->db->get_where('users',array('id'=>$eventInfo['teacher_in_charge']))->row_array(); $calendarInfo=$this->db->get_where('calendar_type',array('id'=>$eventInfo['calendar_type_id']))->row_array(); $data=unserialize($eventInfo['serializeData']); $date=explode(",", $data['startDate'][1]); if (sizeof($date)==1) $date[1]=$date[0]; if (!isset($eventInfo['remarks'])) $eventInfo['remarks']="None"; if(isset($calendarInfo['approver_user_id'])&&$calendarInfo['need_approval']){ $eventApprovers=explode(',', $calendarInfo['approver_user_id']); if(empty($eventApprovers)) array_push($eventApprovers, $calendarInfo['approver_user_id']); foreach ($eventApprovers as $key=>$eventApprover){ $approver=$this->db->get_where('users',array('id'=>$eventApprover))->row_array(); $email_data['event_title'] =$eventInfo['event_title']; $email_data['remark'] =$eventInfo['remarks']; $email_data['approver_name'] =$approver['name_english']; $email_data['send_email_to'] =$approver['email']; $email_data['applicant_name'] =$applicant['name_english']; $email_data['sDate'] =$date[0]; $email_data['eDate'] =$date[1]; if(isset($data['timeslot'])){ $time=$this->db->get_where('eb_time_slots', array('id' => $data['timeslot'][1][0]))->row_array(); $email_data['sTime'] =$time['time_from']; $email_data['eTime'] =$time['time_to']; }else{ $email_data['sTime'] =$data['from_time'][$key][1]; $email_data['eTime'] =$data['to_time'][$key][1]; } $email_data['email_subject'] = 'Request for Event approval'; $email_data['base_url'] = base_url(); $email_data['eventUrl'] = base_url().'event_booking/events/previewEvent/'.$event_id; if($_COOKIE['language']=="ch"){ $lang = $_COOKIE['language']; $email_data['approver_name'] = $approver['name_chinese']; $email_data['applicant'] = $applicant['name_chinese']; $email_data['email_subject'] = "活動審批請求"; } else $lang = 'en'; $msg = $this->load->view('emails/'.$lang.'/event_approval_email',$email_data,TRUE); $datas = array( 'subject' => $email_data['email_subject'], 'message' => $msg ); email($formData['approver']['id'],$datas['subject'],$datas['message'], base_url().'event_booking/events/previewEvent/'.$event_id,'EB'); } } } } function sendEmails($event_id=0){ //send only when the event is published if ($event_id>0){ $eventInfo=$this->db->get_where('events',array('id'=>$event_id))->row_array(); $applicant=$eventInfo['teacher_in_charge']; $calendarInfo=$this->db->get_where('calendar_type',array('id'=>$eventInfo['calendar_type_id']))->row_array(); if(isset($calendarInfo['approver_user_id'])&&$calendarInfo['need_approval']){ $eventApprovers=explode(',', $calendarInfo['approver_user_id']); if(empty($eventApprovers)) array_push($eventApprovers, $calendarInfo['approver_user_id']); $needToSendEventEmail=true; foreach ($eventApprovers as $eventApprover){ if ($eventApprover==$applicant) $needToSendEventEmail=false; } if ($needToSendEventEmail) $this->sendEmailToEventApprover($event_id); } $sectionsInfo=$this->db->get_where('event_has_sections',array('event_id'=>$event_id))->result_array(); foreach ($sectionsInfo as $sectionInfo) { $sectionVenues=$this->db->get_where('event_section_has_venues',array('section_id'=>$sectionInfo['id']))->result_array(); $sectionFacilities=$this->db->get_where('event_section_has_facilities',array('section_id'=>$sectionInfo['id']))->result_array(); foreach($sectionVenues as $venue){ if($venue['venue_id']!=0) { $this->db->select('eb_venues.is_enabled,eb_venues.need_approval,eb_venues.approver_user_id,venues.*'); $this->db->join('eb_venues','eb_venues.venue_id = venues.id'); $venueInfo=$this->db->get_where('venues',array('venues.id'=>$venue['venue_id']))->row_array(); if($venueInfo['need_approval']&&($venueInfo['approver_user_id']!=$applicant)) $this->sendEmailToVenueApprover($event_id,$venue['venue_id']); } } foreach($sectionFacilities as $facility){ $facilityInfo=$this->db->get_where('facilities',array('id'=>$facility['facility_id']))->row_array(); if($facilityInfo['need_approval']&&($facilityInfo['approver_user_id']!=$applicant)) $this->sendEmailToFacilityApprover($event_id,$facility['facility_id']); } } } } function getUserById($id=0){ if($id>0){ $user=$this->db->get_where('users',array('id' => $id))->row_array(); return $user['username']; } else return "NULL"; } function getEventTypeById($id=0){ if($id>0){ $eventType=$this->db->get_where('event_types',array('id' => $id))->row_array(); return $eventType['title']; } else return "NULL"; } function publish_event($event_id=0){ $settings=$this->Settings_model->get_settings(); if($event_id>0){ $eventInfo=$this->db->get_where('events',array('id'=>$event_id))->row_array(); $data=array( 'status' => 'PENDING' ); //check if it's calendar type is approved if($eventInfo['status']=='APPROVED') { $calendar_approval_status=true; } else { $calendar_approval_status=false; } $calendarInfo=$this->db->get_where('calendar_type',array('id'=>$eventInfo['calendar_type_id']))->row_array(); $approvers=explode(',', $calendarInfo['approver_user_id']); if(empty($calendarInfo['approver_user_id']))$calendar_approval_status=true; foreach ($approvers as $approver){ if ($approver==$eventInfo['teacher_in_charge']) $calendar_approval_status=true; } /* if($settings['venue']==1) { //check if it's all venue is approved $this->db->select('events.id, events.event_title, events.teacher_in_charge, event_has_sections.id as section_id, venues.title, event_section_has_venues.status'); $this->db->join('event_has_sections','events.id=event_has_sections.event_id','left'); $this->db->join('event_section_has_venues','event_section_has_venues.section_id=event_has_sections.id','left'); $this->db->join('venues','event_section_has_venues.venue_id = venues.id','left'); //$this->db->group_by("venues.id"); $venues = $this->db->get_where('events',array('events.id' => $event_id))->result_array(); $venues_approval_status=true; //pr($venues); foreach ($venues as $venue) { if($venue['status']!='APPROVED') $venues_approval_status=False; //pr($venue['status']);exit; } } else { $venues_approval_status=true; } if($settings['facility']==1) { //check if it's all facility is approved $this->db->select('events.id, events.event_title, events.teacher_in_charge, event_has_sections.id as section_id, facilities.title, event_section_has_facilities.status'); $this->db->join('event_has_sections','events.id=event_has_sections.event_id','left'); $this->db->join('event_section_has_facilities','event_section_has_facilities.section_id=event_has_sections.id','left'); $this->db->join('facilities','event_section_has_facilities.facility_id = facilities.id','left'); //$this->db->group_by("facilities.id"); $facilities = $this->db->get_where('events',array('events.id' => $event_id))->result_array(); $facilities_approval_status=true; foreach ($facilities as $facility) { if($facility['status']!=NULL) { if($facility['status']!='APPROVED') $facilities_approval_status=false; } } } else { $facilities_approval_status=true; } if($facilities_approval_status) echo 'facilities_approval_status<br/>'; if($venues_approval_status) echo 'venues_approval_status<br/>';*/ if($calendar_approval_status) echo 'calendar_approval_status<br/>' ; // if($venues_approval_status && $facilities_approval_status && $calendar_approval_status) { if($calendar_approval_status) { $data=array( 'status' => 'PUBLISHED' ); } $this->db->update('events', $data, "id = $event_id"); } else return false; } function approveEvent($event_id=0){ if ($event_id>0) { $data=array( 'status' => 'APPROVED' ); $event = $this->db->get_where('events',array('id'=>$event_id))->row_array(); $msg = 'Your event has been approved.'; $link = base_url().'event_booking/events/previewEvent/'.$event_id; $module = 'EB'; email($event['teacher_in_charge'], 'Event Approved', $msg, $link,$module); //echo $this->db->last_query(); //$this->sendEmailToEventApprover($event_id); return $this->db->update('events', $data, "id = $event_id"); }else{ return false; } } function rejectEvent($event_id=0){ if ($event_id>0) { $data=array( 'status' => 'REJECTED' ); $event = $this->db->get_where('events',array('id'=>$event_id))->row_array(); $msg = 'Your event has been rejected.'; $link = base_url().'event_booking/events/previewEvent/'.$event_id; $module = 'EB'; email($event['teacher_in_charge'], 'Event Rejected', $msg, $link,$module); return $this->db->update('events', $data, "id = $event_id"); //$this->sendEmailToEventApplicant($event_id); }else{ return false; } } function withdrawEvent($event_id=0){ if ($event_id>0) { $data=array( 'status' => 'WITHDRAW' ); return $this->db->update('events', $data, "id = $event_id"); }else{ return false; } } // function needToSendVenueEmail($event_id=0, $venue_id=0){ // if ($event_id>0) { // $eventInfo= $this->db->get_where('events', array('id' => $event_id))->row_array(); // if ($venue_id>0) { // $venueInfo = $this->db->get_where('venues',array('venues.id'=>$venue_id))->row_array(); // if($eventInfo['teacher_in_charge']==$venueInfo['approver_user_id']) // return false; // else // return true; // } // else{ // $sections=$this->db->get_where('event_has_sections',array('event_id'=>$event_id))->result_array(); // foreach ($sections as $section) { // $venue_id=$this->db->get_where('event_section_has_venues',array('section_id'=>$section['id']))->row_array()['venue_id']; // $venueInfo=$this->db->get_where('venues',array('venues.id'=>$venue_id))->row_array(); // if($eventInfo['teacher_in_charge']==$venueInfo['approver_user_id']) // return false; // else // return true; // } // } // } // else // return false; // } } ?>
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.44 |
proxy
|
phpinfo
|
Settings