/** * Pilot Request = Mission Available for Pilot */ public function executeUpdate(sfWebRequest $request) { #security if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Pilot', 'Coordinator', 'Volunteer'), false)) { $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer()); $this->redirect('dashboard/index'); } if ($request->getParameter('id')) { $this->mission_leg = MissionLegPeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($this->mission_leg); $member = MemberPeer::retrieveByPK($this->getUser()->getMemberId()); if (!$member instanceof Member) { $this->getUser()->setFlash('warning', 'Sorry! Your permission could have been assigned. But you don\'t have member record!'); $this->redirect($request->getReferer()); } if ($member) { $pilot = $member->getPilot(); } else { $pilot = null; } $this->pilot = $pilot; if ($pilot) { $this->airport = $pilot->getAirport(); } else { $this->airport = null; } // Select Mission Assistant from pilot request $c = new Criteria(); $c->add(PilotRequestPeer::LEG_ID, $request->getParameter('id')); $c->add(PilotRequestPeer::PILOT_TYPE, "Mission Assistant"); $this->mission_assistants = PilotRequestPeer::doSelect($c); //TODO optimize //print_r($this->mission_assistants); if (isset($member)) { $this->pilot = PilotPeer::getByMemberId($member->getId()); $this->pilot_aircrafts = PilotAircraftPeer::getByMemberId($member->getId()); } $this->pre_requests = PilotRequestPeer::getByMemnerIdLegId($member->getId(), $this->mission_leg->getId()); } else { $this->getUser()->setFlash('success', 'No Mission Leg have been selected!'); } //Pilot Request if ($request->isMethod('post')) { if ($request->getParameter('other_pilot') == 1) { if ($request->getParameter('date') != null) { //die("OK"); $pilot_request = new PilotRequest(); $pilot_request->setMemberId($member->getId()); $pilot_request->setLegId($request->getParameter('id')); $pilot_request->setDate($request->getParameter('date')); $pilot_request->setPilotType($request->getParameter('pilot_type')); $pilot_request->setMissionAssistantWanted(0); $pilot_request->setIfrBackupWanted(0); $pilot_request->setAccepted(0); $pilot_request->setProcessed(0); $pilot_request->setOnHold(0); $pilot_request->setComment($request->getParameter('comment')); $pilot_request->setAircraftId($request->getParameter('aircraft')); $pilot_request->setTail($request->getParameter('tail')); $person = PersonPeer::retrieveByPK($this->getUser()->getId()); $pilot_request->setCreatedAt(date('m/d/y')); $pilot_request->save(); $mail_text = "Dear " . trim($person->getName()) . ", you have requested a mission from Angel Flight West. Your request has been sent successfully"; $this->getComponent('mail', 'missionReqCreate', array('email' => $person->getEmail(), 'name' => $person->getName(), 'subject' => 'Request Mission', 'text' => $mail_text)); $this->getUser()->setFlash('success', 'Your request has been saved on Mission Leg #' . $this->mission_leg->getId()); $this->redirect('@pilot_thanks?id=' . $request->getParameter('id')); } else { if ($request->getParameter('date') == null) { $this->date_e = 1; $this->date_other_e = 1; $this->type = $request->getParameter('pilot_type'); } } } else { if ($request->getParameter('date') != null) { //die('OK'); $pilot_request = new PilotRequest(); if (isset($member)) { $pilot_request->setMemberId($member->getId()); } $pilot_request->setLegId($request->getParameter('id')); $pilot_request->setDate($request->getParameter('date')); $pilot_request->setPilotType($request->getParameter('pilot_type')); $pilot_request->setComment($request->getParameter('comment')); $pilot_request->setProcessed(1); $pilot_request->setAircraftId($request->getParameter('aircraft')); $pilot_request->setTail($request->getParameter('tail')); if ($request->getParameter('acc_cre') == 'yes') { $pilot_request->setMissionAssistantWanted(1); $pilot_request->setMissAssisId($request->getParameter('ma_ids')); } else { $pilot_request->setMissionAssistantWanted(0); } if ($request->getParameter('IFR') == 0) { $pilot_request->setIfrBackupWanted(0); } else { $pilot_request->setIfrBackupWanted(1); } $pilot_request->setCreatedAt(date('m/d/y')); $person = PersonPeer::retrieveByPK($this->getUser()->getId()); $pilot_request->save(); $mail_text = "Dear " . trim($person->getName()) . ", you have requested a mission from Angel Flight West. Your request has been sent successfully"; $this->getComponent('mail', 'missionReqCreate', array('email' => $person->getEmail(), 'name' => $person->getName(), 'subject' => 'Request Mission', 'text' => $mail_text)); $this->getUser()->setFlash('success', 'Your request has been saved on Mission Leg #' . $this->mission_leg->getId()); $this->redirect('@pilot_thanks?id=' . $request->getParameter('id')); } else { if ($request->getParameter('date') == null) { $this->date_e = 1; $this->type = $request->getParameter('pilot_type'); } } } } }
/** * Request a group Missions * CODE:mission_request_group_create */ public function executeRequestGroupMission(sfWebRequest $request) { #security if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Pilot', 'Coordinator', 'Volunteer'), false)) { $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer()); $this->redirect('dashboard/index'); } $camp = CampPeer::retrieveByPK($request->getParameter('id')); if (isset($camp) && $camp instanceof Camp) { $this->camp_id = $camp->getId(); $missions = MissionPeer::getByCampId($camp->getId()); } $this->dates = array(); $this->home_base = null; $this->number_of_seats = null; $this->total_carry = null; $this->multi_pick = null; $this->date_choice = null; $this->comment = null; $this->request_as = null; $this->acc_cre = null; $this->pilot_ma = null; $this->IFR = null; $this->aircraft = null; $this->tail = null; $this->other_pilot = null; $miss_dates = array(); //$appt_dates = array(); //$count = 0; //$count2 = 0; foreach ($missions as $mission) { if ($mission->getMissionDate()) { $miss_dates[$mission->getMissionDate('m/d/Y')] = $mission->getMissionDate(); //$count++; //it may change $this->mission_date = $mission->getMissionDate(); $this->appt_date = $mission->getApptDate(); // } /* if($mission->getApptDate()){ $appt_dates[$count2] = $mission->getApptDate(); $count2++; }*/ $miss_id = $mission->getId(); } $this->mission_dates = array(); $this->mission_dates = $miss_dates; if (isset($miss_id)) { $legs = MissionLegPeer::getbyMissId($miss_id); $this->mission = MissionPeer::retrieveByPK($miss_id); foreach ($legs as $leg) { if ($leg->getToAirportId()) { $this->leg = $leg; $airport = AirportPeer::retrieveByPK($leg->getToAirportId()); if (isset($airport) && $airport instanceof Airport) { $this->destination_airport = $airport; } } } } /* if(isset($miss_dates[$count-1])){ $this->mission_date = $miss_dates[$count-1]; } if(isset($appt_dates[$count2-1])){ $this->appt_date = $appt_dates[$count2-1]; } */ //$this->mission_leg = MissionLegPeer::retrieveByPK($request->getParameter('id')); $member = MemberPeer::getByPersonId($this->getUser()->getId()); if (isset($member)) { $this->pilot = PilotPeer::getByMemberId($member->getId()); $this->pilot_aircrafts = PilotAircraftPeer::getByMemberId($member->getId()); $this->pre_requests = PilotRequestPeer::getByMemnerIdLegIdCamp($member->getId(), $this->leg->getId()); } if ($request->isMethod('post')) { if ($request->getParameter('id')) { //set post variables $this->dates = $request->getParameter('dates[]', array()); $this->home_base = $request->getParameter('home_base'); $this->number_of_seats = $request->getParameter('number_of_seats'); $this->total_carry = $request->getParameter('total_carry'); $this->multi_pick = $request->getParameter('multi_pick'); $this->date_choice = $request->getParameter('date_choice'); $this->comment = $request->getParameter('comment'); $this->request_as = $request->getParameter('request_as'); $this->acc_cre = $request->getParameter('acc_cre'); $this->pilot_ma = $request->getParameter('pilot_ma'); $this->IFR = $request->getParameter('IFR'); $this->aircraft = $request->getParameter('aircraft'); $this->tail = $request->getParameter('tail'); $this->other_pilot = $request->getParameter('other_pilot'); if (count($this->dates) > 0 && $request->getParameter('home_base') && $request->getParameter('number_of_seats') && $request->getParameter('total_carry')) { //check if this pilot requested this camp already? $c = $has_requested = PilotRequestPeer::getByMemberIdCampId($member->getId(), $request->getParameter('camp_id')); if (!$has_requested) { $pilot_request = new PilotRequest(); if ($member) { $pilot_request->setMemberId($member->getId()); } $pilot_request->setGroupCampId($request->getParameter('camp_id')); if ($request->getParameter('home_base')) { $airport_hb = AirportPeer::getByIdent($request->getParameter('home_base')); if (isset($airport_hb) && $airport_hb instanceof Airport) { $pilot_request->setHomeBase($airport_hb->getIdent()); } else { $this->getUser()->setFlash('warning', 'Home Base is not found!'); $this->redirect($request->getReferer()); } } if ($request->getParameter('number_of_seats')) { if (is_integer((int) $request->getParameter('number_of_seats'))) { $pilot_request->setNumberSeats((int) $request->getParameter('number_of_seats')); } else { $this->getUser()->setFlash('warning', 'Number of seats is in wrong format!'); $this->redirect($request->getReferer()); } } if ($request->getParameter('total_carry')) { if (is_int((int) $request->getParameter('total_carry'))) { $pilot_request->setTotalWeight((int) $request->getParameter('total_carry')); } else { $this->getUser()->setFlash('success', 'Total of carry value is in wrong format!'); $this->redirect($request->getReferer()); } } $pilot_request->setMultiplePick($request->getParameter('multi_pick')); $pilot_request->save(); if (count($this->dates) > 0) { #check is has Pilot Date //$has_pilot_date = PilotDatePeer::getByMemberId($member->getId()); for ($y = 0; $y < count($this->dates); $y++) { $pilot_date = new PilotDate(); $pilot_date->setMemberId($member->getId()); $pilot_date->setDate($this->dates[$y]); $pilot_date->setPilotRequestId($pilot_request->getId()); $pilot_date->save(); } } if (count($this->dates) == 0) { $pilot_request->setDate($this->dates[0]); } $pilot_request->setNumberDateAssign($request->getParameter('date_choice', 1)); $pilot_request->setPilotType($request->getParameter('request_as')); $pilot_request->setComment($request->getParameter('comment')); $pilot_request->setAircraftId($request->getParameter('aircraft')); $pilot_request->setTail($request->getParameter('tail')); //check pilot_type if ($request->getParameter('other_pilot') == 1) { ////mission assistant,earth angel $pilot_request->setMissionAssistantWanted(0); $pilot_request->setIfrBackupWanted(0); $pilot_request->setAccepted(0); $pilot_request->setProcessed(0); $pilot_request->setOnHold(0); } else { ////command pilot $pilot_request->setProcessed(1); if ($request->getParameter('acc_cre') == 1) { $pilot_request->setMissionAssistantWanted(0); #set pilot as mission assistant if ($member->getPerson()) { $pilot_request->setMissionAssistantName($member->getPerson()->getLastName() . ' ' . $member->getPerson()->getFirstName()); } } else { $pilot_request->setMissionAssistantWanted(0); #set pilot's mission assistant as mission assistant if ($request->getParameter('pilot_ma')) { $pilot_request->setMissionAssistantName($request->getParameter('pilot_ma')); } } if ($request->getParameter('IFR') == 0) { $pilot_request->setIfrBackupWanted(0); } else { $pilot_request->setIfrBackupWanted(1); } } $pilot_request->setCreatedAt(date('m/d/y')); $pilot_request->save(); $this->getUser()->setFlash('success', 'Your request has been saved on Camp ID#' . $request->getParameter('camp_id')); // $this->redirect('@pilot_thanks?id='.$request->getParameter('id')); } else { $this->getUser()->setFlash('success', 'You have already requested this Camp Mission!'); // $this->redirect('@pilot_thanks?id='.$request->getParameter('id')); } } else { if (count($this->dates) < 1) { $this->date_other_e = 1; $this->type = $request->getParameter('request_as'); } if (!$request->getParameter('home_base')) { $this->home = 1; } if (!$request->getParameter('number_of_seats')) { $this->number_of = 1; } if (!$request->getParameter('total_carry')) { $this->carry = 1; } } } } }