예제 #1
0
 public function executeAutoRemoveMissionsOnCamp(sfWebRequest $request)
 {
     $passenger_id = $request->getParameter('passenger');
     $airport_id = $request->getParameter('airport_id');
     $camp_id = $request->getParameter('camp');
     $mission_id = $request->getParameter('mission_id');
     $camp = CampPeer::retrieveByPK($camp_id);
     $camp_airport_id = $camp->getAirportId();
     // To airport id for first mission
     $from = $request->getParameter('from');
     // indicates what should be removed, home to treatement or treatement to home mission?
     $c = new Criteria();
     $c->add(MissionPeer::PASSENGER_ID, $passenger_id);
     $c->add(MissionPeer::CAMP_ID, $camp_id);
     $c->add(MissionPeer::ID, $mission_id);
     $mission = MissionPeer::doSelectOne($c);
     $itinerary_id = $mission->getItineraryId();
     $mission->setCancelMission(0);
     // Make it hide from public
     $mission->save();
     $itinerary = ItineraryPeer::retrieveByPK($itinerary_id);
     $itinerary->setCancelItinerary(0);
     $itinerary->save();
     /*foreach($missions as $mission){
         $mission_ids[] = $mission->getId();
         $itinerary_id = $mission->getItineraryId();
         $mission->setCancelMission(0); // Make it hide from public
         $mission->save();
       }*/
     //$this->_setAutoLegCancelled($camp_airport_id, $airport_id, $mission_ids[0], 'come');
     //$this->_setAutoLegCancelled($camp_airport_id, $airport_id, $mission_ids[1], 'return');
     $this->_setAutoLegCancelled($camp_airport_id, $airport_id, $mission->getId(), $from);
     $c->clear();
     $c->add(CampPassengerPeer::CAMP_ID, $camp_id);
     $c->add(CampPassengerPeer::PASSENGER_ID, $passenger_id);
     if ($from == 'source') {
         $c->add(CampPassengerPeer::AIRPORT_ID, $airport_id);
     } else {
         $c->add(CampPassengerPeer::RETURN_AIRPORT_ID, $airport_id);
     }
     CampPassengerPeer::doDelete($c);
     return $this->redirect('camp/view?id=' . $camp_id);
 }
예제 #2
0
   <h2><?php 
echo $title . ' # ' . $mission->getExternalId() . ($leg->getLegNumber() ? ' - ' . $leg->getLegNumber() : '');
?>
</h2>

  <h3><?php 
if (isset($mission)) {
    echo 'Mission # ' . $mission->getExternalId();
}
?>
</h3>
  <div class="person-info">
    <?php 
if (isset($mission)) {
    if ($mission->getItineraryId()) {
        $iti = ItineraryPeer::retrieveByPK($mission->getItineraryId());
    }
}
?>
    <dl class="person-data">
      <dt>Itinerary ID:</dt>
      <dd>
        <?php 
if (isset($iti)) {
    echo $iti->getId();
} else {
    echo '--';
}
?>
      </dd>
      <dt>Mission Date:</dt>
예제 #3
0
 public function executePrintMissionLeg(sfWebRequest $request)
 {
     #Security
     if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Coordinator'), 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->leg = MissionLegPeer::retrieveByPK($request->getParameter('id'));
         if (isset($this->leg)) {
             $this->mission = MissionPeer::retrieveByPK($this->leg->getMissionId());
             $this->requester = RequesterPeer::retrieveByPK($this->mission->getRequesterId());
             $this->req_person = $this->requester->getPerson();
             $this->agency = $this->requester->getAgency();
             // Camp information
             if ($this->mission->getCampId()) {
                 $this->camp = CampPeer::retrieveByPK($this->mission->getCampId());
             }
             //Coordinator
             if ($this->mission->getCoordinatorId()) {
                 $this->coordinator = CoordinatorPeer::retrieveByPK($this->mission->getCoordinatorId());
                 $this->coordiPerson = PersonPeer::retrieveByPK($this->coordinator->getMember()->getPersonId());
             }
             if (isset($this->mission)) {
                 $this->itinerary = ItineraryPeer::retrieveByPK($this->mission->getItineraryId());
                 $pass = PassengerPeer::retrieveByPK($this->mission->getPassengerId());
                 //Companions information
                 $this->companions = CompanionPeer::getByPassId($this->mission->getPassengerId());
                 if (isset($pass) && $pass instanceof Passenger) {
                     $this->pass = $pass;
                     //print_r($this->pass);
                     //die();
                     $this->person = PersonPeer::retrieveByPK($pass->getPersonId());
                     $this->itinerary = $this->mission->getItinerary();
                     // Pre-define addresses for ground missions
                     $this->ground_addresses = array('patient' => '', 'facility' => '', 'lodging' => '', 'airport' => '');
                     $this->ground_addr_sel = sfConfig::get('app_ground_address_type', array());
                     if ($this->itinerary) {
                         //$this->ground_addresses['lodging'] = $this->ground_addresses['facility'] = $this->itinerary->getDestCity().', '.$this->itinerary->getDestState();
                     }
                 } else {
                     unset($this->passenger);
                 }
             }
         }
         if (isset($this->leg) && $this->leg instanceof MissionLeg) {
             if ($this->leg->getPilotId()) {
                 $this->pilot = PilotPeer::retrieveByPK($this->leg->getPilotId());
                 $this->pilot_member = MemberPeer::retrieveByPK($this->pilot->getMemberId());
                 $this->copilot = PilotPeer::retrieveByPK($this->leg->getCoPilotId());
                 $this->mission_assistant = PilotPeer::getByMemberId($this->leg->getMissAssisId());
                 $this->back_up_mission_assistant = PilotPeer::retrieveByPK($this->leg->getBackupMissAssisId());
             }
         }
         if ($this->getUser()->hasAttribute('pilotAddToLegview')) {
             $this->getUser()->setFlash("success", 'Pilot is added to this mission leg successfully !');
             $this->getUser()->getAttributeHolder()->remove('pilotAddToLegview');
         }
     }
 }
예제 #4
0
 /**
  * Show Itinerary details
  * CODE: itinerary_view
  */
 public function executeDetail(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');
     }
     $this->orginset = '';
     $this->destset = '';
     $this->orgintset = '';
     $this->desttset = '';
     if ($request->getParameter('add_passengers')) {
         $this->group_camp_id = $request->getParameter('add_passengers');
     }
     $this->mission;
     $this->mission2;
     $mission;
     $mission2;
     $this->ground_addr_sel = sfConfig::get('app_ground_address_type', array());
     $this->errors = array();
     $this->errors2 = array();
     if ($request->getParameter('id')) {
         $this->itinerary = ItineraryPeer::retrieveByPK($request->getParameter('id'));
         $this->back = $request->getReferer();
         //echo $this->itinerary->getId();
         if (strstr($this->back, '/mission/view')) {
             $this->frommission = 1;
         } else {
             $this->frommission = 0;
         }
         $this->mis = MissionPeer::getMissionByItineraryId($this->itinerary->getId(), 1);
         $mission = $this->mis;
         /*echo "<pre>";
           print_r($this->mis);
           echo "</pre>";
           die("ok");
           */
         $this->mission = $mission;
         //print_r($mission);      exit ();
         ///Show leges
         if (isset($mission)) {
             $this->mis_legs = MissionLegPeer::getbyMissId($mission->getId());
         }
         //echo "<pre>";
         //print_r($this->mis_legs);
         //echo $this->itinerary->getId();
         $this->mis2 = MissionPeer::getMissionByItineraryId($this->itinerary->getId(), 2);
         /*
         echo "<pre>";
         print_r($this->mis2);
         echo "</pre>";
         die("ok");
         */
         $mission2 = $this->mis2;
         $this->mission2 = $mission2;
         $this->ground_addresses = array('patient' => '', 'facility' => '', 'lodging' => '', 'airport' => '');
         $pass;
         $this->personnew;
         if ($this->itinerary) {
             $this->ground_addresses['lodging'] = $this->ground_addresses['facility'] = $this->itinerary->getDestCity() . ', ' . $this->itinerary->getDestState();
             $pass = PassengerPeer::retrieveByPK($this->itinerary->getPassengerId());
             $this->personnew = PersonPeer::retrieveByPK($pass->getPersonId());
         }
         if ($pass) {
             $this->ground_addresses['lodging'] = $pass->getLodgingName() . ' ' . $this->ground_addresses['lodging'];
             $this->ground_addresses['facility'] = $pass->getFacilityName() . ' ' . $this->ground_addresses['facility'];
             $this->ground_addresses['patient'] = $this->personnew->getAddress1() . ' ' . $this->personnew->getAddress2() . ' ' . $this->personnew->getCity() . ', ' . $this->personnew->getState() . ' ' . $this->personnew->getZipcode();
             $this->ground_addresses['airport'] = $this->personnew->getAddress1() . ' ' . $this->personnew->getAddress2() . ' ' . $this->personnew->getCity() . ', ' . $this->personnew->getState() . ' ' . $this->personnew->getZipcode();
         }
     }
     if ($request->isMethod('post')) {
         if ($request->getParameter('com')) {
             if ($request->getParameter('com') == 1) {
                 $mission->setComment($request->getParameter('mis_comment'));
                 $mission->save();
             } elseif ($request->getParameter('com') == 2) {
                 $mission2->setComment($request->getParameter('mist_comment'));
                 $mission2->save();
             }
             $this->getUser()->setFlash('success', 'Comment successfully saved.');
         } else {
             if ($request->getParameter('misstsave') == 1) {
                 switch ($request->getParameter('transportation')) {
                     case 'air_mission':
                         $origin_airports = (array) $request->getParameter('origint_idents');
                         $dest_airports = (array) $request->getParameter('destinationt_idents');
                         $idents = $dest_airports;
                         $tmp_arr = array();
                         foreach ($origin_airports as $i => $ident) {
                             $idents[] = $ident;
                             $v = $ident . ' to ' . $dest_airports[$i];
                             if (in_array($v, $tmp_arr)) {
                                 $this->errors2[] = 'Leg ' . $v . ' appeared more than one';
                             } else {
                                 $tmp_arr[] = $v;
                             }
                             if ($dest_airports[$i] == $ident) {
                                 $this->errors2[] = 'Leg ' . $ident . ' to ' . $dest_airports[$i] . ' is invalid';
                             }
                         }
                         $idents = array_unique($idents);
                         $c = new Criteria();
                         $c->add(AirportPeer::IDENT, $idents, Criteria::IN);
                         if (count($idents) != AirportPeer::doCount($c)) {
                             $this->errors2[] = 'Some airport idents are invalid';
                         }
                         break;
                     case 'ground_mission':
                         $origin = $request->getParameter('groundt_origin');
                         $destination = $request->getParameter('groundt_destination');
                         $orgintset = $request->getParameter('orgintset');
                         $desttset = $request->getParameter('desttset');
                         $this->desttset = $desttset;
                         $this->orgintset = $orgintset;
                         if (empty($destination) && empty($desttset)) {
                             $this->errors2[] = 'Please specify destination address';
                         }
                         if (empty($origin) && empty($orgintset)) {
                             $this->errors2[] = 'Please specify origin address';
                         } elseif ($destination == $origin && $destination != '') {
                             $this->errors2[] = 'Origin and Destination addresses conflict';
                         }
                         break;
                     case 'commercial_mission':
                         $mission_date = $request->getParameter('mission_date');
                         if (empty($mission_date)) {
                             $this->errors2[] = 'Mission date is required';
                         }
                         if ($v = $request->getParameter('airline_id')) {
                             $custom = $request->getParameter('airline_custom');
                             if ($v == 'other') {
                                 if (empty($custom)) {
                                     $this->errors2[] = 'Please type a new airline name!';
                                 }
                             } else {
                                 $airline = AirlinePeer::retrieveByPK($v = $request->getParameter('airline_id'));
                                 if (!$airline instanceof Airline) {
                                     $this->errors2[] = 'Please select airline!';
                                 }
                             }
                         } else {
                             $this->errors2[] = 'Please select airline!';
                         }
                         break;
                     default:
                         $this->errors2[] = 'Please select Transportation Type';
                 }
                 if (count($this->errors2)) {
                     # error in form
                     switch ($request->getParameter('transportation')) {
                         case 'air_mission':
                             $this->origin_idents = $origin_airports;
                             $this->dest_idents = $dest_airports;
                             break;
                         case 'ground_mission':
                             break;
                         case 'commercial_mission':
                             break;
                     }
                     $this->erer = 2;
                 } else {
                     $missioncount = MissionLegPeer::getMaxLegNumber($mission2->getId());
                     switch ($request->getParameter('transportation')) {
                         case 'air_mission':
                             $aircount = MissionLegPeer::getCountbyMissIdAndType($mission2->getId(), 'air_mission');
                             for ($i = 0; $i < sizeof($origin_airports); $i++) {
                                 $airport_o = AirportPeer::getByIdent($origin_airports[$i]);
                                 $airport_d = AirportPeer::getByIdent($dest_airports[$i]);
                                 $missioncount++;
                                 $aircount++;
                                 $mission_leg = new MissionLeg();
                                 $mission_leg->setMissionId($mission2->getId());
                                 $mission_leg->setLegNumber($missioncount);
                                 $mission_leg->setFromAirportId($airport_o->getId());
                                 $mission_leg->setToAirportId($airport_d->getId());
                                 $mission_leg->setPrefix('air' . $aircount);
                                 //$mission_leg->setBaggageWeight($request->getParameter('baggage_weight'));
                                 //$mission_leg->setBaggageDesc($request->getParameter('baggage_desc'));
                                 $mission_leg->setPassOnBoard(0);
                                 $mission_leg->setTransportation('air_mission');
                                 $mission_leg->setCancelMissionLeg(1);
                                 $mission_leg->save();
                             }
                             $this->getUser()->setFlash('success', 'Mission and Leg #' . $mission_leg->getMissionId() . '-' . $mission_leg->getLegNumber() . ' has successfully created!');
                             return $this->redirect('/itinerary/detail/' . $this->itinerary->getId());
                             break;
                         case 'ground_mission':
                             $groundcount = MissionLegPeer::getCountbyMissIdAndType($mission2->getId(), 'ground_mission');
                             $mission_leg = new MissionLeg();
                             $orgintsetsave = $request->getParameter('groundt_origin');
                             if (empty($orgintsetsave)) {
                                 $orgintsetsave = $request->getParameter('orgintset');
                             }
                             $desttsetsave = $request->getParameter('groundt_destination');
                             if (empty($desttsetsave)) {
                                 $desttsetsave = $request->getParameter('desttset');
                             }
                             $groundcount++;
                             $sas = $missioncount + 1;
                             $mission_leg->setMissionId($mission2->getId());
                             $mission_leg->setLegNumber($sas);
                             $mission_leg->setPassOnBoard(0);
                             $mission_leg->setTransportation('ground_mission');
                             $mission_leg->setGroundOrigin($orgintsetsave);
                             $mission_leg->setGroundDestination($desttsetsave);
                             $mission_leg->setPrefix('g' . $groundcount);
                             $mission_leg->setCancelMissionLeg(1);
                             $mission_leg->save();
                             $this->getUser()->setFlash('success', 'Mission and Leg #' . $mission_leg->getMissionId() . '-' . $mission_leg->getLegNumber() . ' has successfully created!');
                             return $this->redirect('/itinerary/detail/' . $this->itinerary->getId());
                             break;
                         case 'commercial_mission':
                             $comcount = MissionLegPeer::getCountbyMissIdAndType($mission2->getId(), 'commercial_mission');
                             $flight_time = $request->getParameter('flight_time');
                             if (empty($flight_time['hour']) || empty($flight_time['minute'])) {
                                 $flight_time = null;
                             }
                             $airline_id = $request->getParameter('airline_id');
                             if ($airline_id == 'other') {
                                 $airline = new Airline();
                                 $airline->setName($request->getParameter('airline_custom'));
                                 $airline->save();
                             } else {
                                 $airline = AirlinePeer::retrieveByPK($airline_id);
                                 $this->forward404Unless($airline);
                             }
                             $origins = $request->getParameter('origin');
                             $destinations = $request->getParameter('destination');
                             $flight_numbers = $request->getParameter('flight_number');
                             $departures = $request->getParameter('departure');
                             $arrivals = $request->getParameter('arrival');
                             $mission->setFlightTime($flight_time['hour'] . ':' . $flight_time['minute'] . ' ' . $flight_time['period']);
                             $missioncount++;
                             $n_leg = $missioncount;
                             foreach ($origins as $i => $origin) {
                                 if (empty($origin) || empty($destinations[$i])) {
                                     continue;
                                 }
                                 $mission_leg = new MissionLeg();
                                 $comcount++;
                                 $mission_leg->setMissionId($mission2->getId());
                                 $mission_leg->setLegNumber($n_leg++);
                                 $mission_leg->setFlightTime($flight_time ? strtotime($flight_time['hour'] . ':' . $flight_time['minute'] . ' ' . $flight_time['period']) : null);
                                 //$mission_leg->setBaggageDesc($request->getParameter('baggage_desc'));
                                 //$mission_leg->setBaggageWeight($request->getParameter('baggage_weight'));
                                 $mission_leg->setAirlineId($airline->getId());
                                 $mission_leg->setFundId($request->getParameter('fund_id'));
                                 $mission_leg->setConfirmCode($request->getParameter('confirm_code'));
                                 $mission_leg->setFlightCost($request->getParameter('flight_cost'));
                                 $mission_leg->setCommOrigin($origin);
                                 $mission_leg->setCommDest($destinations[$i]);
                                 $mission_leg->setFlightNumber($flight_numbers[$i]);
                                 $v = $departures[$i];
                                 if (empty($v['hour']) || empty($v['minute'])) {
                                     $v = null;
                                 }
                                 $mission_leg->setDeparture($v ? strtotime($v['hour'] . ':' . $v['minute'] . ' ' . $v['period']) : null);
                                 $v = $arrivals[$i];
                                 if (empty($v['hour']) || empty($v['minute'])) {
                                     $v = null;
                                 }
                                 $mission_leg->setDeparture($v ? strtotime($v['hour'] . ':' . $v['minute'] . ' ' . $v['period']) : null);
                                 $mission_leg->setTransportation('commercial_mission');
                                 $mission_leg->setPrefix('com' . $comcount);
                                 $mission_leg->setCancelMissionLeg(1);
                                 $mission_leg->save();
                                 $this->getUser()->setFlash('success', 'Mission and Leg #' . $mission_leg->getMissionId() . '-' . $mission_leg->getLegNumber() . ' has successfully created!');
                                 return $this->redirect('/itinerary/detail/' . $this->itinerary->getId());
                             }
                             break;
                     }
                 }
             } else {
                 switch ($request->getParameter('transportation')) {
                     case 'air_mission':
                         $origin_airports = (array) $request->getParameter('origin_idents');
                         $dest_airports = (array) $request->getParameter('destination_idents');
                         $idents = $dest_airports;
                         $tmp_arr = array();
                         foreach ($origin_airports as $i => $ident) {
                             $idents[] = $ident;
                             $v = $ident . ' to ' . $dest_airports[$i];
                             if (in_array($v, $tmp_arr)) {
                                 $this->errors[] = 'Leg ' . $v . ' appeared more than one';
                             } else {
                                 $tmp_arr[] = $v;
                             }
                             if ($dest_airports[$i] == $ident) {
                                 $this->errors[] = 'Leg ' . $ident . ' to ' . $dest_airports[$i] . ' is invalid';
                             }
                         }
                         $idents = array_unique($idents);
                         $c = new Criteria();
                         $c->add(AirportPeer::IDENT, $idents, Criteria::IN);
                         if (count($idents) != AirportPeer::doCount($c)) {
                             $this->errors[] = 'Some airport idents are invalid';
                         }
                         break;
                     case 'ground_mission':
                         $origin = $request->getParameter('ground_origin');
                         $destination = $request->getParameter('ground_destination');
                         //echo $destination; die();
                         $orginset = $request->getParameter('orginset');
                         $destset = $request->getParameter('destset');
                         $this->destset = $destset;
                         $this->orginset = $orginset;
                         if (empty($destination) && empty($destset)) {
                             $this->errors[] = 'Please specify destination address';
                         }
                         if (empty($origin) && empty($orginset)) {
                             $this->errors[] = 'Please specify origin address';
                         } elseif ($destination == $origin && $destination != '') {
                             $this->errors[] = 'Origin and Destination addresses conflict';
                         }
                         break;
                     case 'commercial_mission':
                         $mission_date = $request->getParameter('mission_date');
                         if (empty($mission_date)) {
                             $this->errors[] = 'Mission date is required';
                         }
                         if ($v = $request->getParameter('airline_id')) {
                             $custom = $request->getParameter('airline_custom');
                             if ($v == 'other') {
                                 if (empty($custom)) {
                                     $this->errors[] = 'Please type a new airline name!';
                                 }
                             } else {
                                 $airline = AirlinePeer::retrieveByPK($v = $request->getParameter('airline_id'));
                                 if (!$airline instanceof Airline) {
                                     $this->errors[] = 'Please select airline!';
                                 }
                             }
                         } else {
                             $this->errors[] = 'Please select airline!';
                         }
                         break;
                     default:
                         $this->errors[] = 'Please select Transportation Type';
                 }
                 if (count($this->errors)) {
                     # error in form
                     switch ($request->getParameter('transportation')) {
                         case 'air_mission':
                             $this->origin_idents = $origin_airports;
                             $this->dest_idents = $dest_airports;
                             break;
                         case 'ground_mission':
                             break;
                         case 'commercial_mission':
                             break;
                     }
                 } else {
                     $missioncount = MissionLegPeer::getMaxLegNumber($mission->getId());
                     switch ($request->getParameter('transportation')) {
                         case 'air_mission':
                             $aircount = MissionLegPeer::getCountbyMissIdAndType($mission->getId(), 'air_mission');
                             for ($i = 0; $i < sizeof($origin_airports); $i++) {
                                 $airport_o = AirportPeer::getByIdent($origin_airports[$i]);
                                 $airport_d = AirportPeer::getByIdent($dest_airports[$i]);
                                 $missioncount++;
                                 $aircount++;
                                 $mission_leg = new MissionLeg();
                                 $mission_leg->setMissionId($mission->getId());
                                 $mission_leg->setLegNumber($missioncount);
                                 $mission_leg->setFromAirportId($airport_o->getId());
                                 $mission_leg->setToAirportId($airport_d->getId());
                                 $mission_leg->setPrefix('air' . $aircount);
                                 //$mission_leg->setBaggageWeight($request->getParameter('baggage_weight'));
                                 //$mission_leg->setBaggageDesc($request->getParameter('baggage_desc'));
                                 $mission_leg->setPassOnBoard(0);
                                 $mission_leg->setTransportation('air_mission');
                                 $mission_leg->setCancelMissionLeg(1);
                                 $mission_leg->save();
                             }
                             $this->getUser()->setFlash('success', 'Mission and Leg #' . $mission_leg->getMissionId() . '-' . $mission_leg->getLegNumber() . ' has successfully created!');
                             return $this->redirect('/itinerary/detail/' . $this->itinerary->getId());
                             break;
                         case 'ground_mission':
                             $groundcount = MissionLegPeer::getCountbyMissIdAndType($mission->getId(), 'ground_mission');
                             $mission_leg = new MissionLeg();
                             $orginsetsave = $request->getParameter('ground_origin');
                             if (empty($orginsetsave)) {
                                 $orginsetsave = $request->getParameter('orginset');
                             }
                             $destsetsave = $request->getParameter('ground_destination');
                             if (empty($destsetsave)) {
                                 $destsetsave = $request->getParameter('destset');
                             }
                             $groundcount++;
                             $missioncount++;
                             $sa = $missioncount;
                             $mission_leg->setMissionId($mission->getId());
                             $mission_leg->setLegNumber($sa);
                             $mission_leg->setPassOnBoard(0);
                             $mission_leg->setTransportation('ground_mission');
                             $mission_leg->setGroundOrigin($orginsetsave);
                             $mission_leg->setGroundDestination($destsetsave);
                             $mission_leg->setPrefix('g' . $groundcount);
                             $mission_leg->setCancelMissionLeg(1);
                             $mission_leg->save();
                             $this->getUser()->setFlash('success', 'Mission and Leg #' . $mission_leg->getMissionId() . '-' . $mission_leg->getLegNumber() . ' has successfully created!');
                             return $this->redirect('/itinerary/detail/' . $this->itinerary->getId());
                             break;
                         case 'commercial_mission':
                             $comcount = MissionLegPeer::getCountbyMissIdAndType($mission->getId(), 'commercial_mission');
                             $flight_time = $request->getParameter('flight_time');
                             if (empty($flight_time['hour']) || empty($flight_time['minute'])) {
                                 $flight_time = null;
                             }
                             $airline_id = $request->getParameter('airline_id');
                             if ($airline_id == 'other') {
                                 $airline = new Airline();
                                 $airline->setName($request->getParameter('airline_custom'));
                                 $airline->save();
                             } else {
                                 $airline = AirlinePeer::retrieveByPK($airline_id);
                                 $this->forward404Unless($airline);
                             }
                             $origins = $request->getParameter('origin');
                             $destinations = $request->getParameter('destination');
                             $flight_numbers = $request->getParameter('flight_number');
                             $departures = $request->getParameter('departure');
                             $arrivals = $request->getParameter('arrival');
                             $mission->setFlightTime($flight_time['hour'] . ':' . $flight_time['minute'] . ' ' . $flight_time['period']);
                             $missioncount++;
                             $n_leg = $missioncount;
                             foreach ($origins as $i => $origin) {
                                 if (empty($origin) || empty($destinations[$i])) {
                                     continue;
                                 }
                                 $mission_leg = new MissionLeg();
                                 $comcount++;
                                 $mission_leg->setMissionId($mission->getId());
                                 $mission_leg->setLegNumber($n_leg++);
                                 $mission_leg->setFlightTime($flight_time ? strtotime($flight_time['hour'] . ':' . $flight_time['minute'] . ' ' . $flight_time['period']) : null);
                                 $mission_leg->setBaggageDesc($request->getParameter('baggage_desc'));
                                 $mission_leg->setBaggageWeight($request->getParameter('baggage_weight'));
                                 $mission_leg->setAirlineId($airline->getId());
                                 $mission_leg->setFundId($request->getParameter('fund_id'));
                                 $mission_leg->setConfirmCode($request->getParameter('confirm_code'));
                                 $mission_leg->setFlightCost($request->getParameter('flight_cost'));
                                 $mission_leg->setCommOrigin($origin);
                                 $mission_leg->setCommDest($destinations[$i]);
                                 $mission_leg->setFlightNumber($flight_numbers[$i]);
                                 $v = $departures[$i];
                                 if (empty($v['hour']) || empty($v['minute'])) {
                                     $v = null;
                                 }
                                 $mission_leg->setDeparture($v ? strtotime($v['hour'] . ':' . $v['minute'] . ' ' . $v['period']) : null);
                                 $v = $arrivals[$i];
                                 if (empty($v['hour']) || empty($v['minute'])) {
                                     $v = null;
                                 }
                                 $mission_leg->setDeparture($v ? strtotime($v['hour'] . ':' . $v['minute'] . ' ' . $v['period']) : null);
                                 $mission_leg->setTransportation('commercial_mission');
                                 $mission_leg->setPrefix('com' . $comcount);
                                 $mission_leg->setCancelMissionLeg(1);
                                 $mission_leg->save();
                                 $this->getUser()->setFlash('success', 'Mission and Leg #' . $mission_leg->getMissionId() . '-' . $mission_leg->getLegNumber() . ' has successfully created!');
                                 return $this->redirect('/itinerary/detail/' . $this->itinerary->getId());
                             }
                             break;
                     }
                 }
             }
         }
     }
     if ($request->getParameter('id')) {
         //$this->itinerary = ItineraryPeer::retrieveByPK($request->getParameter('id'));
         //$this->mis  = MissionPeer::getMissionByItineraryId($this->itinerary->getId(), 'Home');
         //$mission = $this->mis;
         if (isset($mission)) {
             $this->mis_comment = $mission->getComment();
         }
         //$this->mis_legs = MissionLegPeer::getbyMissId($mission->getId());
         if ($mission2) {
             $this->mis2_legs = MissionLegPeer::getbyMissId($mission2->getId());
             $this->mist_comment = $mission2->getComment();
         }
         $this->date_widget = new widgetFormDate(array('format_date' => array('js' => 'mm/dd/yy', 'php' => 'm/d/Y')), array('class' => 'text'));
         $this->time_widget = new widgetFormTime();
         $this->airport_list = AirportPeer::getMappable();
         $this->ground_addresses = $this->getGroundAddresses();
         $this->airlines = AirlinePeer::doSelect(new Criteria());
         $this->funds = FundPeer::doSelect(new Criteria());
         $this->miss_ids = array();
         $c = 0;
         $count = 0;
         $count2 = 0;
         if (isset($this->itinerary)) {
             $this->missions = MissionPeer::getByItiId($this->itinerary->getId());
             if (isset($this->missions)) {
                 foreach ($this->missions as $mi) {
                     $this->miss_ids[$c] = $mi->getId();
                     $legs = MissionLegPeer::getbyMissId($mi->getId());
                 }
             }
         }
         $this->title = '#' . $this->itinerary->getId() . ' Itinerary Details';
     }
 }
예제 #5
0
 /**
  * Mission
  * CODE:mission_create
  */
 public function executeEdit(sfWebRequest $request)
 {
     #security
     if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Coordinator'), 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 = MissionPeer::retrieveByPK($request->getParameter('id'));
     }
     //ziyed edited
     $itine = ItineraryPeer::retrieveByPk($this->mission->getItineraryId());
     $this->itine = $itine;
     $this->passenger = PassengerPeer::retrieveByPK($this->mission->getPassengerId());
     $this->passenger_a = $this->passenger && $this->passenger->getPerson() ? $this->passenger->getPerson()->getName() : '';
     $this->requester = RequesterPeer::retrieveByPK($this->mission->getRequesterId());
     $this->requester_a = $this->requester && $this->requester->getPerson() ? $this->requester->getPerson()->getName() : '';
     $this->agency = AgencyPeer::retrieveByPK($this->mission->getAgencyId());
     $this->agencyName = $this->agency ? $this->agency->getName() : '';
     $this->camp = CampPeer::retrieveByPK($this->mission->getCampId());
     $this->campName = $this->camp ? $this->camp->getCampName() : '';
     //end of ziyed
     $this->form = new MissionForm($this->mission);
     $this->referer = $request->getReferer();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('mission_edit'));
         $this->referer = $request->getReferer();
         /*$errors = $this->form->getErrorSchema()->getErrors();
           if (count($errors) > 0)
           echo 'List of Errors:' . '<br>';
           {
           foreach ($errors as $name => $error)
           {
           echo $name . ': ' . $error . '<BR>';
           }
           }*/
         if ($this->form->isValid()) {
             $this->mission->setMissionTypeId($this->form->getValue('mission_type_id'));
             $this->mission->setMissionDate($this->form->getValue('mission_date'));
             $this->mission->setDateRequested($this->form->getValue('date_requested'));
             $pass = PassengerPeer::retrieveByPK($this->form->getValue('passenger_id'));
             if (isset($pass)) {
                 $this->mission->setPassengerId($pass->getId());
             }
             $req = RequesterPeer::retrieveByPK($this->form->getValue('requester_id'));
             if ($req) {
                 $this->mission->setRequesterId($req->getId());
             }
             if ($this->form->getValue('agency_id') == 0) {
                 $this->mission->setAgencyId(null);
             } else {
                 $this->mission->setAgencyId($this->form->getValue('agency_id'));
             }
             if ($this->form->getValue('camp_id') == 0) {
                 $this->mission->setCampId(null);
             } else {
                 $this->mission->setCampId($this->form->getValue('camp_id'));
             }
             $coor = CoordinatorPeer::retrieveByPK($this->form->getValue('coordinator_id'));
             if (isset($coor)) {
                 $this->mission->setCoordinatorId($coor->getId());
             }
             $itId = ItineraryPeer::retrieveByPK($this->mission->getItineraryId());
             $mLeg = MissionLegPeer::getAllMissionLegByMissionId($request->getParameter('id'));
             $countLeg = MissionLegPeer::getMissionLegByMissionIdCount($request->getParameter('id'));
             $this->mission->setApptDate($this->form->getValue('appt_date'));
             $this->mission->setFlightTime($this->form->getValue('flight_time'));
             $this->mission->setTreatment($this->form->getValue('treatment'));
             $this->mission->setComment($this->form->getValue('comment'));
             $this->mission->setAppointment($this->form->getValue('appointment'));
             $this->mission->setMissionSpecificComments($this->form->getValue('mission_specific_comments'));
             if ($this->form->getValue('cancel_mission') == 0) {
                 if (isset($countLeg)) {
                     foreach ($mLeg as $ml) {
                         $ml->setCancelMissionLeg(0);
                         $ml->save();
                     }
                 }
             }
             $this->mission->setCancelMission($this->form->getValue('cancel_mission'));
             $this->mission->save();
             $this->getUser()->setFlash('success', 'Mission has succesfully edited!');
             $this->redirect('@mission_view?id=' . $this->mission->getId());
         }
     }
 }