Esempio n. 1
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';
     }
 }