Exemplo n.º 1
0
 /**
  * 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');
                 }
             }
         }
     }
 }