Example #1
0
 public function executeAutoAddMissionsOnCamp(sfWebRequest $request)
 {
     // see if there is airport exist with this name
     $airport_name = $request->getParameter('airportname');
     $airport = AirportPeer::getBySpecificAirportName($airport_name);
     // If there is no airport then insert it into airport table
     if (!$airport) {
         // @TODO Set default airport fields values
         $airport = new Airport();
         $airport->setName($airport_name);
         $airport->save();
     }
     $pass_id = $request->getParameter('passenger');
     $camp_id = $request->getParameter('camp_id');
     $camp_passenger = new CampPassenger();
     $camp_passenger->setCampId($camp_id);
     $camp_passenger->setPassengerId($pass_id);
     if (CampPassengerPeer::doCount($camp_passenger->buildCriteria())) {
         $passenger = PassengerPeer::retrieveByPK($pass_id);
         $this->getUser()->setFlash('warning', 'Passenger "' . $passenger->getPerson()->getName() . '" has already been added!');
         return $this->redirect('camp/view?id=' . $request->getParameter('camp_id'));
     }
     $camp = CampPeer::retrieveByPK($camp_id);
     $this->forward404Unless($camp);
     $note = $request->getParameter('note');
     //$camp_passenger->setAirportId($camp->getAirportId ()); // Camp Location Id
     $camp_passenger->setNote($note);
     //if ($camp_passenger->save()){
     //return $this->renderText($airport->getId());
     //}
     $mission_type = MissionTypePeer::getByName('normal');
     if (!$mission_type instanceof MissionType) {
         $mission_type = MissionTypePeer::doSelectOne(new Criteria());
         $this->forward404Unless($mission_type);
     }
     $airport = AirportPeer::getBySpecificAirportName($airport_name);
     $camp_location = $camp->getAirport();
     $itinerary = new Itinerary();
     $itinerary->setCampId($camp->getId());
     $itinerary->setPassengerId($pass_id);
     $itinerary->setDateRequested(time());
     $itinerary->setApointTime('unspecified');
     $itinerary->setMissionTypeId($mission_type->getId());
     $itinerary->setAgencyId($camp->getAgencyId());
     $itinerary->setCancelItinerary(1);
     $itinerary->save();
     // Mission 1
     $mission1 = new Mission();
     $mission1->setItineraryId($itinerary->getId());
     $mission1->setCampId($camp->getId());
     $mission1->setCancelMission(1);
     $mission1->setPassengerId($pass_id);
     $mission1->setMissionCount(1);
     $mission1->setDateRequested(time());
     $mission1->setExternalId($this->getLatestExternalId());
     $mission1->setMissionTypeId($mission_type->getId());
     $mission1->save();
     $camp_passenger->setReturnAirportId(NULL);
     // this indicates that return airport id would be camp airport id
     $camp_passenger->setAirportId($airport->getId());
     $camp_passenger->setMissionId($mission1->getId());
     $camp_passenger->save();
     $mission1_leg1 = new MissionLeg();
     $mission1_leg1->setFromAirportId($airport->getId());
     $mission1_leg1->setLegNumber(1);
     $mission1_leg1->setMissionId($mission1->getId());
     if ($camp_location) {
         $mission1_leg1->setToAirportId($camp_location->getId());
     } else {
         $mission1_leg1->setToAirportId(NULL);
     }
     $mission1_leg1->setCancelMissionLeg(1);
     $mission1_leg1->save();
     // Mission 2
     $mission2 = new Mission();
     $mission2->setItineraryId($itinerary->getId());
     $mission2->setCampId($camp->getId());
     $mission2->setCancelMission(1);
     $mission2->setPassengerId($pass_id);
     $mission2->setMissionCount(2);
     // From treatment to hme
     $mission2->setDateRequested(time());
     $mission2->setExternalId($this->getLatestExternalId());
     $mission2->setMissionTypeId($mission_type->getId());
     $mission2->save();
     $camp_passenger2 = new CampPassenger();
     $camp_passenger2->setCampId($camp_id);
     $camp_passenger2->setPassengerId($pass_id);
     $camp_passenger2->setMissionId($mission2->getId());
     $camp_passenger2->setAirportId(NULL);
     // this indicates that return airport id would be camp airport id
     $camp_passenger2->setReturnAirportId($airport->getId());
     $camp_passenger2->setNote($note);
     $camp_passenger2->save();
     $mission2_leg2 = new MissionLeg();
     if ($camp_location) {
         $mission2_leg2->setFromAirportId($camp_location->getId());
     } else {
         $mission2_leg2->setFromAirportId(NULL);
     }
     $mission2_leg2->setLegNumber(1);
     $mission2_leg2->setMissionId($mission2->getId());
     $mission2_leg2->setToAirportId($airport->getId());
     $mission2_leg2->setCancelMissionLeg(1);
     $mission2_leg2->save();
     return $this->redirect('camp/view?id=' . $camp->getId());
 }
Example #2
0
 /**
  * missionRequests save all data into corresponding tables
  * CODE:mission_request_create
  */
 public function executeSave(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');
     }
     $miss_req_session = $this->getUser()->getAttribute('miss_req');
     if (!$miss_req_session) {
         return $this->forward('passenger', 'step3');
     }
     //set Requester Person
     $req_person = new Person();
     $req_person->setFirstName($miss_req_session->getReqFirstname());
     $req_person->setLastName($miss_req_session->getReqLastname());
     $req_person->setAddress1($miss_req_session->getReqAddress1());
     $req_person->setAddress2($miss_req_session->getReqAddress2());
     $req_person->setCity($miss_req_session->getReqCity());
     $req_person->setCounty($miss_req_session->getReqCounty());
     $req_person->setState($miss_req_session->getReqState());
     $req_person->setCountry($miss_req_session->getReqCountry());
     $req_person->setZipcode($miss_req_session->getReqZipcode());
     $req_person->setEmail($miss_req_session->getReqEmail());
     $req_person->setSecondaryEmail($miss_req_session->getReqSecondaryEmail());
     $req_person->setPagerEmail($miss_req_session->getReqPagerEmail());
     $req_person->setDayPhone($miss_req_session->getReqDayPhone());
     $req_person->setDayComment($miss_req_session->getReqDayComment());
     $req_person->setEveningPhone($miss_req_session->getReqEvePhone());
     $req_person->setEveningComment($miss_req_session->getReqEveComment());
     $req_person->setMobilePhone($miss_req_session->getReqMobilePhone());
     $req_person->setMobileComment($miss_req_session->getReqMobileComment());
     $req_person->setPagerPhone($miss_req_session->getReqPagerPhone());
     $req_person->setPagerComment($miss_req_session->getReqPagerComment());
     $req_person->setOtherPhone($miss_req_session->getReqOtherPhone());
     $req_person->setOtherComment($miss_req_session->getReqOtherComment());
     $req_person->save();
     //end of Requester Person
     // set Requester Agency
     $agency = AgencyPeer::getByNamePhone(trim($miss_req_session->getAgencyName()));
     if ($agency) {
         # nothing
     } else {
         $agency = new Agency();
         $agency->setName(trim($miss_req_session->getAgencyName()));
         $agency->save();
     }
     //set Requester
     $requester = new Requester();
     $requester->setPersonId($req_person->getId());
     $requester->setAgencyId($agency->getId());
     //$requester->setDischarge($miss_req_session->getReqDischarge());
     $requester->save();
     if (isset($miss_req_session->passenger_id)) {
         $passenger = PassengerPeer::retrieveByPK($miss_req_session->passenger_id);
         if (!$passenger instanceof Passenger) {
             $passenger = new Passenger();
         }
     } else {
         $passenger = new Passenger();
     }
     if ($passenger->isNew()) {
         $person = new Person();
     } else {
         $person = $passenger->getPerson();
     }
     //set Person to Passenger
     $person->setTitle($miss_req_session->getPassTitle());
     $person->setFirstName($miss_req_session->getPassFirstName());
     $person->setLastName($miss_req_session->getPassLastName());
     $person->setGender($miss_req_session->getPassGender());
     $person->setAddress1($miss_req_session->getPassAddress1());
     $person->setAddress2($miss_req_session->getPassAddress2());
     $person->setCity($miss_req_session->getPassCity());
     $person->setState($miss_req_session->getPassState());
     $person->setZipcode($miss_req_session->getPassZipcode());
     $person->setCountry($miss_req_session->getPassCountry());
     $person->setEmail($miss_req_session->getPassEmail());
     $person->setDayPhone($miss_req_session->getPassDayPhone());
     $person->setDayComment($miss_req_session->getPassDayComment());
     $person->setEveningPhone($miss_req_session->getPassEvePhone());
     $person->setEveningComment($miss_req_session->getPassEveComment());
     $person->setMobilePhone($miss_req_session->getPassMobilePhone());
     $person->setMobileComment($miss_req_session->getPassMobileComment());
     $person->setPagerPhone($miss_req_session->getPassPagerPhone());
     $person->setPagerComment($miss_req_session->getPassPagerComment());
     $person->setOtherPhone($miss_req_session->getPassOtherPhone());
     $person->setOtherComment($miss_req_session->getPassOtherComment());
     $person->save();
     //set Passenger
     $passenger->setPersonId($person->getId());
     $passenger->setPassengerTypeId($miss_req_session->getPassType());
     $passenger->setDateOfBirth($miss_req_session->getPassDateOfBirth());
     $passenger->setIllness($miss_req_session->getIllness());
     $passenger->setFinancial($miss_req_session->getFinancial());
     $passenger->setPublicConsiderations($miss_req_session->getPassPublicCons());
     $passenger->setPrivateConsiderations($miss_req_session->getPassPrivateCons());
     $passenger->setReleasingPhysician($miss_req_session->getReleasingPhysician());
     $passenger->setReleasingPhone($miss_req_session->getReleasePhone());
     $passenger->setReleasingFax1($miss_req_session->getReleaseFax());
     $passenger->setReleasingFax1Comment($miss_req_session->getReleaseFaxComment());
     $passenger->setLodgingName($miss_req_session->getLodgingName());
     $passenger->setLodgingPhone($miss_req_session->getLodgingPhone());
     $passenger->setLodgingPhoneComment($miss_req_session->getLodgingPhoneComment());
     $passenger->setFacilityName($miss_req_session->getFacilityName());
     $passenger->setFacilityPhone($miss_req_session->getFacilityPhone());
     $passenger->setFacilityPhoneComment($miss_req_session->getFacilityPhoneComment());
     $passenger->setReleasingEmail($miss_req_session->getReleaseEmail());
     $passenger->setTreatingPhysician($miss_req_session->getTreatingPhysician());
     $passenger->setTreatingPhone($miss_req_session->getTreatingPhone());
     $passenger->setTreatingFax1($miss_req_session->getTreatingFax());
     $passenger->setTreatingFax1Comment($miss_req_session->getTreatingFaxComment());
     $passenger->setTreatingEmail($miss_req_session->getTreatingEmail());
     $passenger->setLanguageSpoken($miss_req_session->getPassLanguage());
     $passenger->setBestContactMethod($miss_req_session->getBestContact());
     $passenger->setEmergencyContactName($miss_req_session->getEmergencyName());
     $passenger->setEmergencyContactPrimaryPhone($miss_req_session->getEmergencyPhone1());
     $passenger->setEmergencyContactPrimaryComment($miss_req_session->getEmergencyPhone1Comment());
     $passenger->setEmergencyContactSecondaryPhone($miss_req_session->getEmergencyPhone2());
     $passenger->setEmergencyContactSecondaryComment($miss_req_session->getEmergencyPhone2Comment());
     $passenger->setNeedMedicalRelease($miss_req_session->getPassMedical());
     $passenger->save();
     //set Companions
     if ($passenger && $miss_req_session->getCom1Name()) {
         $person = new Person();
         $names[] = split(" ", $miss_req_session->getCom1Name());
         //echo var_dump($names); die();
         $person->setFirstName($names[0][0]);
         $person->setLastName($names[0][1]);
         $person->setDayPhone($miss_req_session->getCom1Phone());
         $person->setDayComment($miss_req_session->getCom1Comment());
         $person->save();
         $companion = new Companion();
         $companion->setPassengerId($passenger->getId());
         $companion->setName($miss_req_session->getCom1Name());
         $companion->setRelationship($miss_req_session->getCom1Relationship());
         $companion->setDateOfBirth($miss_req_session->getCom1DateOfBirth());
         $companion->setWeight($miss_req_session->getCom1Weigth());
         $companion->setCompanionPhone($miss_req_session->getCom1Phone());
         $companion->setCompanionPhoneComment($miss_req_session->getCom1Comment());
         $companion->setPersonId($person->getId());
         $companion->save();
     }
     if ($passenger && $miss_req_session->getCom2Name()) {
         $person = new Person();
         $names[] = split(" ", $miss_req_session->getCom2Name());
         //echo var_dump($names); die();
         $person->setFirstName($names[0][0]);
         $person->setLastName($names[0][1]);
         $person->setDayPhone($miss_req_session->getCom2Phone());
         $person->setDayComment($miss_req_session->getCom2Comment());
         $person->save();
         $companion = new Companion();
         $companion->setPassengerId($passenger->getId());
         $companion->setName($miss_req_session->getCom2Name());
         $companion->setRelationship($miss_req_session->getCom2Relationship());
         $companion->setDateOfBirth($miss_req_session->getCom2DateOfBirth());
         $companion->setWeight($miss_req_session->getCom2Weigth());
         $companion->setCompanionPhone($miss_req_session->getCom2Phone());
         $companion->setCompanionPhoneComment($miss_req_session->getCom2Comment());
         $companion->setPersonId($person->getId());
         $companion->save();
     }
     if ($passenger && $miss_req_session->getCom3Name()) {
         $person = new Person();
         $names[] = split(" ", $miss_req_session->getCom3Name());
         //echo var_dump($names); die();
         $person->setFirstName($names[0][0]);
         $person->setLastName($names[0][1]);
         $person->setDayPhone($miss_req_session->getCom3Phone());
         $person->setDayComment($miss_req_session->getCom3Comment());
         $person->save();
         $companion = new Companion();
         $companion->setPassengerId($passenger->getId());
         $companion->setName($miss_req_session->getCom3Name());
         $companion->setRelationship($miss_req_session->getCom3Relationship());
         $companion->setDateOfBirth($miss_req_session->getCom3DateOfBirth());
         $companion->setWeight($miss_req_session->getCom3Weigth());
         $companion->setCompanionPhone($miss_req_session->getCom3Phone());
         $companion->setCompanionPhoneComment($miss_req_session->getCom3Comment());
         $companion->setPersonId($person->getId());
         $companion->save();
     }
     if ($passenger && $miss_req_session->getCom4Name()) {
         $person = new Person();
         $names[] = split(" ", $miss_req_session->getCom4Name());
         //echo var_dump($names); die();
         $person->setFirstName($names[0][0]);
         $person->setLastName($names[0][1]);
         $person->setDayPhone($miss_req_session->getCom4Phone());
         $person->setDayComment($miss_req_session->getCom4Comment());
         $person->save();
         $companion = new Companion();
         $companion->setPassengerId($passenger->getId());
         $companion->setName($miss_req_session->getCom4Name());
         $companion->setRelationship($miss_req_session->getCom4Relationship());
         $companion->setDateOfBirth($miss_req_session->getCom4DateOfBirth());
         $companion->setWeight($miss_req_session->getCom4Weigth());
         $companion->setCompanionPhone($miss_req_session->getCom4Phone());
         $companion->setCompanionPhoneComment($miss_req_session->getCom4Comment());
         $companion->setPersonId($person->getId());
         $companion->save();
     }
     if ($passenger && $miss_req_session->getCom5Name()) {
         $person = new Person();
         $names[] = split(" ", $miss_req_session->getCom5Name());
         //echo var_dump($names); die();
         $person->setFirstName($names[0][0]);
         $person->setLastName($names[0][1]);
         $person->setDayPhone($miss_req_session->getCom5Phone());
         $person->setDayComment($miss_req_session->getCom5Comment());
         $person->save();
         $companion = new Companion();
         $companion->setPassengerId($passenger->getId());
         $companion->setName($miss_req_session->getCom5Name());
         $companion->setRelationship($miss_req_session->getCom5Relationship());
         $companion->setDateOfBirth($miss_req_session->getCom5DateOfBirth());
         $companion->setWeight($miss_req_session->getCom5Weigth());
         $companion->setCompanionPhone($miss_req_session->getCom5Phone());
         $companion->setCompanionPhoneComment($miss_req_session->getCom5Comment());
         $companion->setPersonId($person->getId());
         $companion->save();
     }
     //set Itinerary
     $itinerary = ItineraryPeer::getByMissReqId($miss_req_session->getId());
     if (!$itinerary) {
         $new_itinerary = new Itinerary();
         $new_itinerary->setDateRequested(date('m/d/Y'));
         $new_itinerary->setMissionRequestId($miss_req_session->getId());
         $new_itinerary->setMissionTypeId($miss_req_session->getMissionRequestTypeId());
         $new_itinerary->setApointTime($miss_req_session->getApptDate());
         $new_itinerary->setPassengerId($passenger->getId());
         $new_itinerary->setRequesterId($requester->getId());
         $new_itinerary->setFacility($miss_req_session->getFacilityName());
         $new_itinerary->setLodging($miss_req_session->getLodgingName());
         $new_itinerary->setOrginCity($miss_req_session->getOrginCity());
         $new_itinerary->setOrginState($miss_req_session->getOrginState());
         $new_itinerary->setDestCity($miss_req_session->getDestCity());
         $new_itinerary->setDestState($miss_req_session->getDestState());
         $new_itinerary->setWaiverNeed(0);
         $new_itinerary->setNeedMedicalRelease($miss_req_session->getPassMedical());
         $new_itinerary->setComment($miss_req_session->getComment());
         $new_itinerary->setAgencyId($agency->getId());
         $new_itinerary->save();
     }
     //set default Mission to Mission table
     //get Passenger
     //$passenger = PassengerPeer::getByPersonId($person->getId());
     $misson = new Mission();
     $misson->setRequestId($miss_req_session->getId());
     $misson->setItineraryId($new_itinerary->getId());
     $misson->setMissionTypeId($miss_req_session->getMissionRequestTypeId());
     $misson->setDateRequested($miss_req_session->getRequesterDate());
     if ($passenger) {
         $misson->setPassengerId($passenger->getId());
     }
     if ($requester) {
         $misson->setRequesterId($requester->getId());
     }
     if ($agency) {
         $misson->setAgencyId($agency->getId());
     }
     // Farazi Mission 1 externa ID
     $c = new Criteria();
     $c->add(MissionPeer::EXTERNAL_ID, NULL, Criteria::ISNOTNULL);
     $c->addDescendingOrderByColumn(MissionPeer::ID);
     $external_mission = MissionPeer::doSelectOne($c);
     $external_id = $external_mission->getExternalId();
     $currentExternalId = $external_id + 1;
     $misson->setExternalId($currentExternalId);
     $misson->setApptDate($miss_req_session->getApptDate());
     $misson->setFlightTime($miss_req_session->getFlightTime());
     $misson->setMissionDate($miss_req_session->getMissionDate());
     $misson->setMissionCount(1);
     $misson->save();
     $missLeg = new MissionLeg();
     $missLeg->setMissionId($misson->getId());
     $missLeg->setLegNumber(1);
     if ($miss_req_session->getOrginState() && $miss_req_session->getOrginZipcode()) {
         //echo $miss_req_session->getOrginState().'-'.$miss_req_session->getOrginZipcode();die();
         $fromairport = AirportPeer::getAirportByStateAndZipcode($miss_req_session->getOrginState(), $miss_req_session->getOrginZipcode());
         if ($fromairport) {
             $missLeg->setFromAirportId($fromairport->getId());
         }
     }
     if ($miss_req_session->getDestState() && $miss_req_session->getDestZipcode()) {
         //echo $miss_req_session->getDestState().'--'.$miss_req_session->getDestZipcode();die();
         $toairport = AirportPeer::getAirportByStateAndZipcode($miss_req_session->getDestState(), $miss_req_session->getDestZipcode());
         if ($toairport) {
             $missLeg->setToAirportId($toairport->getId());
         }
     }
     //echo "oder";die();
     $missLeg->setPassOnBoard(0);
     $missLeg->setWebCoordinated(0);
     $missLeg->setTransportation('air_mission');
     $missLeg->save();
     //end set Mission
     $this->getUser()->setFlash('success', 'New mission has successfully created!');
     $miss_req_session->setProcessedDate(time());
     $miss_req_session->save();
     $this->getUser()->setAttribute('miss_req', null);
     //$this->redirect('miss_req');
     //$this->getUser()->setFlash('success',$success);
     //$request->getParameter('back')
     $this->redirect('/itinerary/detail/' . $new_itinerary->getId());
 }
Example #3
0
 /**
  * Add or edit Itinerary
  * CODE: itinerary_create
  */
 public function executeUpdate(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');
     }
     $this->current_facility = "";
     $this->current_lodging = "";
     $this->current_facility_city = "";
     $this->current_facility_state = "";
     $this->current_facility_phone = "";
     $this->current_facility_phone_comment = "";
     $this->current_lodging_city = "";
     $this->current_lodging_state = "";
     $this->current_lodging_phone = "";
     $this->current_lodging_phone_comment = "";
     $this->mis2bn = false;
     $this->passenger_a = trim($this->getRequestParameter('passenger_a', '*')) == '' ? '*' : trim($this->getRequestParameter('passenger_a', '*'));
     $this->facility = trim($this->getRequestParameter('facility', '*')) == '' ? '*' : trim($this->getRequestParameter('facility', '*'));
     $this->lodging = trim($this->getRequestParameter('lodging', '*')) == '' ? '*' : trim($this->getRequestParameter('lodging', '*'));
     $this->requester_p = trim($this->getRequestParameter('requester_p', '*')) == '' ? '*' : trim($this->getRequestParameter('requester_p', '*'));
     $this->person_a = trim($this->getRequestParameter('person_a', '*')) == '' ? '*' : trim($this->getRequestParameter('person_a', '*'));
     $this->person_a_req = trim($this->getRequestParameter('person_a_req', '*')) == '' ? '*' : trim($this->getRequestParameter('person_a_req', '*'));
     $this->agency = trim($this->getRequestParameter('agency', '*')) == '' ? '*' : trim($this->getRequestParameter('agency', '*'));
     $this->hour = $request->getParameter('hour');
     $this->minut = $request->getParameter('minut');
     $this->b_weight = "";
     $this->b_type = "";
     $this->b_desc = "";
     if ($request->getParameter('id')) {
         $itine = ItineraryPeer::retrieveByPk($request->getParameter('id'));
         $mis = MissionPeer::getMissionByItineraryId($request->getParameter('id'), 1);
         $mis2 = MissionPeer::getMissionByItineraryId($request->getParameter('id'), 2);
         if (isset($mis)) {
             $this->b_weight = $mis->getBWeight();
         }
         if (isset($mis)) {
             $this->b_type = $mis->getBType();
         }
         if (isset($mis)) {
             $this->b_desc = $mis->getBDesc();
         }
         if ($mis2) {
             $this->mis2bn = true;
         } else {
             $mis2 = new Mission();
         }
         //$pp = $itine->getPassenger();
         if (isset($itine)) {
             $this->passenger_name = $itine->getPassenger()->getPerson()->getName();
             $this->current_pass_id = $itine->getPassengerId();
             $this->current_facility = $itine->getPassenger()->getFacilityName();
             $this->current_lodging = $itine->getPassenger()->getLodgingName();
             $this->companions = $itine->getPassenger()->getCompanions();
             $this->selected_companions = array();
             foreach ($mis->getMissionCompanions() as $mis_comp) {
                 $this->selected_companions[] = $mis_comp->getCompanionId();
             }
             //print_r($this->selected_companions);
         }
         $this->title = 'Edit Itinerary';
         $success = 'Itinerary has been succesfuly edited!';
         $editpassengerfac = PassengerDestPeer::getFacilityByPassengerId($this->current_pass_id, $this->current_facility);
         $editpassengerlod = PassengerDestPeer::getLodgingByPassengerId($this->current_pass_id, $this->current_lodging);
         if ($editpassengerfac) {
             $this->current_facility_city = $editpassengerfac->getFacilityCity();
             $this->current_facility_state = $editpassengerfac->getFacilityState();
             $this->current_facility_phone = $editpassengerfac->getFacPhone();
             $this->current_facility_phone_comment = $editpassengerfac->getFacilityPhoneComment();
         }
         if ($editpassengerlod) {
             $this->current_lodging_city = $editpassengerlod->getFacilityCity();
             $this->current_lodging_state = $editpassengerlod->getFacilityState();
             $this->current_lodging_phone = $editpassengerlod->getLodPhone();
             $this->current_lodging_phone_comment = $editpassengerlod->getLodPhoneComment();
         }
         if (isset($itine)) {
             $point_time = $itine->getPointTime();
             if ($point_time) {
                 $split_time = split(':', $point_time);
                 $this->hour = $split_time[0];
                 $this->minut = $split_time[1];
             }
         }
     } else {
         $itine = new Itinerary();
         $mis = new Mission();
         $mis2 = new Mission();
         //$passIti = new Passenger();
         //$itine->setWaiverNeed(1);
         //$itine->setNeedMedicalRelease(1);
         $this->title = 'Add Itinerary';
         $success = 'Itinerary has been succesfully created!';
     }
     $this->requester_a = "";
     $this->itine = $itine;
     if ($request->hasParameter('requester_a')) {
         $this->requester_a = trim($this->getRequestParameter('requester_a', '*')) == '' ? '*' : trim($this->getRequestParameter('requester_a', '*'));
     } else {
         if (isset($itine)) {
             $requester = $itine->getRequester();
             if ($requester) {
                 $this->requester_a = $requester->getPerson()->getName();
                 if ($requester->getAgency()->getName()) {
                     $this->requester_a .= ', ' . $requester->getAgency()->getName();
                 }
                 if ($requester->getTitle()) {
                     $this->requester_a .= ', ' . $requester->getTitle();
                 }
             }
         }
     }
     $this->form = new ItineraryForm($itine);
     $this->missionform1 = new MissionSmallForm($mis);
     $this->missionform2 = new MissionSmallForm($mis2);
     //$this->formI = new PassengerItiForm($passIti);
     $facandlod = new PassengerDest();
     $this->form6 = new PassengerDestForm($facandlod);
     $passenger = new Passenger();
     $this->passenger = $passenger;
     //passengers,requester uses when edit
     $c = new Criteria();
     $c->setLimit(50);
     $this->all_passengers = PassengerPeer::doSelect($c);
     $this->all_requesters = RequesterPeer::doSelect($c);
     //Passenger Form1
     $this->form1 = new PassengerPopUpForm1($passenger);
     $this->sub_title = 'Add New Passenger';
     //Passenger Form 2
     $this->form2 = new PassengerPopUpForm2();
     //Passenger Form 3
     $this->form3 = new PassengerPopUpForm3();
     //Passenger Form 4
     $this->form4 = new PassengerPopUpForm4();
     //Passenger Form 5
     $this->form5 = new PassengerPopUpForm5();
     //Requester PopUp Form  - Not Requester Passenger
     $this->persons = PersonPeer::getNotInRequester();
     $requester = new Requester();
     $this->form_req = new RequesterForm($requester);
     $companion = new Companion();
     $this->form_com = new CompanionForm($companion);
     $this->req_referer = $request->getReferer();
     $this->states = sfConfig::get('app_states');
     $this->errors = array();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('itine'));
         $this->referer = $request->getReferer();
         $k = $this->form->isValid();
         if ($k && $request->getParameter('passenger_id') && $request->getParameter('requester_id')) {
             $itine->setPassengerId($request->getParameter('passenger_id'));
             $itine->setRequesterId($request->getParameter('requester_id'));
             $itine->setDateRequested($this->form->getValue('date_requested'));
             $itine->setMissionTypeId($this->form->getValue('mission_type_id'));
             $itine->setApointTime($this->form->getValue('apoint_time'));
             if ($request->getParameter('facility')) {
                 $itine->setFacility($request->getParameter('facility'));
             }
             if ($request->getParameter('lodging')) {
                 $itine->setLodging($request->getParameter('lodging'));
             }
             if ($request->getParameter('hour') && $request->getParameter('minut') && $request->getParameter('hour') != '---' && $request->getParameter('minut') != '---') {
                 $itine->setPointTime($request->getParameter('hour') . ':' . $request->getParameter('minut') . ':00');
                 $itine->setTimetype($this->form->getValue('timetype'));
             }
             $passengerItine = PassengerPeer::retrieveByPK($request->getParameter('passenger_id'));
             if ($passengerItine instanceof Passenger) {
                 $personpasItine = $passengerItine->getPerson();
                 $origin_city = $personpasItine->getCity();
                 $origin_state = $personpasItine->getState();
                 $dest_city = $passengerItine->getFacilityCity();
                 $dest_state = $passengerItine->getFacilityState();
                 //$passengerItine->setBWeight($request->getParameter('b_weight'));
                 //$passengerItine->setBType($request->getParameter('b_type'));
                 //$passengerItine->setBDesc($request->getParameter('b_desc'));
                 $passengerItine->save();
                 //check
             }
             $itine->setOrginCity($origin_city ? $origin_city : "");
             $itine->setOrginState($origin_state ? $origin_state : "");
             $itine->setDestCity($dest_city ? $dest_city : "");
             $itine->setDestState($dest_state ? $dest_state : "");
             //$itine->setBWeight($this->form->getValue('b_weight'));
             //$itine->setBType($this->form->getValue('b_type'));
             //$itine->setBDesc($this->form->getValue('b_desc'));
             //$itine->setWaiverNeed($this->form->getValue('waiver_need'));
             //$itine->setNeedMedicalRelease($this->form->getValue('need_medical_release'));
             $itine->setComment($this->form->getValue('comment'));
             $newIti = false;
             if ($itine->isNew()) {
                 $newIti = true;
                 $itine->setCancelItinerary(1);
             }
             $itine->save();
             $companions = (array) $request->getParameter('companions');
             if (count($companions)) {
                 $c = new Criteria();
                 $c->add(CompanionPeer::ID, $companions, Criteria::IN);
                 $c->add(CompanionPeer::PASSENGER_ID, $request->getParameter('passenger_id'));
                 if (CompanionPeer::doCount($c) != count($companions)) {
                     $this->errors[] = 'Some companions not found';
                 }
             }
             $mis->setItineraryId($itine->getId());
             $mis->setMissionTypeId($this->form->getValue('mission_type_id'));
             $mis->setDateRequested($this->form->getValue('date_requested'));
             $mis->setPassengerId($request->getParameter('passenger_id'));
             $mis->setRequesterId($request->getParameter('requester_id'));
             $mis->setMissionDate($request->getParameter('mis1'));
             $mis->setBWeight($request->getParameter('b_weight'));
             $mis->setBType($request->getParameter('b_type'));
             $mis->setBDesc($request->getParameter('b_desc'));
             /*if($itine->isNew()){
                   echo $countMission; exit;
                   if(isset($countMission)){
                           foreach($misall as $misc){
                               $mLeg = MissionLegPeer::getAllMissionLegByMissionId($misc->getId());
                               $countLeg = MissionLegPeer::getMissionLegByMissionIdCount($misc->getId());
                               if(isset($countLeg)){
                                   foreach($mLeg as $ml){
                                       $ml->setCancelMissionLeg(1);
                                       $ml->save();
                                   }
                               }
                               $misc->setCancelMission(1);
                               $misc->save();
                           }
                   }
               }*/
             if ($request->getParameter('missionSelect') == 1) {
                 $mis->setApptDate($request->getParameter('appdate1'));
                 $mis->setApointTime($this->form->getValue('apoint_time'));
                 $mis->setStart(1);
             } else {
                 $mis->setStart(2);
             }
             if ($itine->getCancelItinerary() == 1) {
                 $mis->setCancelMission(1);
             }
             if (!$request->getParameter('id')) {
                 //Mission 1 externa ID
                 $c = new Criteria();
                 $c->add(MissionPeer::EXTERNAL_ID, NULL, Criteria::ISNOTNULL);
                 $c->addDescendingOrderByColumn(MissionPeer::EXTERNAL_ID);
                 $external_mission = MissionPeer::doSelectOne($c);
                 $external_id = $external_mission->getExternalId();
                 $currentExternalId = $external_id + 1;
                 $mis->setExternalId($currentExternalId);
                 // die();
             }
             $mis->setMissionCount(1);
             $mis->save();
             if ($request->getParameter('yes_no') == 1) {
                 //Mission 2 externa ID
                 if (!$request->getParameter('id')) {
                     $c = new Criteria();
                     $c->add(MissionPeer::EXTERNAL_ID, NULL, Criteria::ISNOTNULL);
                     $c->addDescendingOrderByColumn(MissionPeer::EXTERNAL_ID);
                     $external_mission = MissionPeer::doSelectOne($c);
                     $external_id = $external_mission->getExternalId();
                     $currentExternalId = $external_id + 1;
                     $mis2->setExternalId($currentExternalId);
                     // die();
                 }
                 $mis2->setItineraryId($itine->getId());
                 $mis2->setMissionTypeId($this->form->getValue('mission_type_id'));
                 $mis2->setDateRequested($this->form->getValue('date_requested'));
                 $mis2->setPassengerId($request->getParameter('passenger_id'));
                 $mis2->setRequesterId($request->getParameter('requester_id'));
                 $mis2->setMissionDate($request->getParameter('mis2'));
                 $mis2->setBWeight($request->getParameter('b_weight'));
                 $mis2->setBType($request->getParameter('b_type'));
                 $mis2->setBDesc($request->getParameter('b_desc'));
                 $mis2->setCancelMission(1);
                 if ($request->getParameter('missionSelect') == 1) {
                     $mis2->setStart(2);
                 } else {
                     $mis2->setStart(1);
                 }
                 $mis2->setMissionCount(2);
                 if ($itine->getCancelItinerary() == 1) {
                     $mis2->setCancelMission(1);
                 }
                 $mis2->save();
             }
             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;
                 }
                 $this->selected_companions = $companions;
             } else {
                 $c->clear();
                 $c->add(MissionCompanionPeer::MISSION_ID, $mis->getId());
                 MissionCompanionPeer::doDelete($c);
                 foreach ($companions as $id) {
                     $mission_companion = new MissionCompanion();
                     $mission_companion->setMissionId($mis->getId());
                     $mission_companion->setCompanionId($id);
                     $mission_companion->save();
                 }
             }
             //die();
             $this->selected_companions = $companions;
             //print_r($this->selected_companions);
             //die();
             //$team_note = TeamNotePeer::retrieveByPK($id);
             //if(!$team_note) {
             //$team_note = new TeamNote();
             //}
             //$team_note->setRoleId($id);
             //$team_note->setNote(strip_tags($note, sfConfig::get('app_allowed_note_tags')));
             //$team_note->save();
             $this->getUser()->setFlash('success', $success);
             //$request->getParameter('back')
             $this->redirect('/itinerary/detail/' . $itine->getId());
         } else {
             if (!$request->getParameter('passenger_id')) {
                 $this->need_pass = 1;
             }
             if (!$request->getParameter('requester_id')) {
                 $this->need_requester_id = 1;
             }
             //if(!$request->getParameter('facility')){
             //$this->need_facility= 1;
             //}
             //if(!$request->getParameter('lodging')){
             //$this->need_lodging = 1;
             //}
             $this->referer = $request->getParameter('back');
         }
     } else {
         # Set referer URL
         $this->referer = $request->getReferer() ? $request->getReferer() : '@itinerary';
     }
     // Block from Add person
     if ($request->getParameter('add_pass') == 'yes') {
         $this->person = new Person();
         $this->person_title = 'Step 1 : Add person';
         if ($request->getParameter('camp_id')) {
             $this->camp_id = $request->getParameter('camp_id');
         }
         $this->stepped = 1;
     }
     if ($request->getParameter('add_pass_iti') == 'yes') {
         $this->person = new Person();
         $this->person_title = 'Step 1 : Add person';
         $this->person_itine = 1;
     }
     if ($request->getParameter('add_cont') == 'yes') {
         $this->person = new Person();
         $this->person_title = 'Step 1 : Add person';
         $this->contact = 1;
     }
     if ($request->getParameter('id')) {
         $this->person = PersonPeer::retrieveByPK($request->getParameter('id'));
         $this->person_title = 'Edit person';
     } else {
         $this->person = new Person();
         $this->person_title = 'Add person';
     }
     $companion = new Companion();
     $this->form_a = new CompanionForm($companion);
     # Person Form
     $this->person_form = new PersonForm($this->person);
     $this->back = $request->getReferer();
     //session
     $this->key = $request->getParameter('key');
     if (!$this->key) {
         $this->key = rand(1000, 9999);
     }
     # Agency Form
     $agency = new Agency();
     $this->agency_title = 'Add Agency';
     $this->agency_form = new AgencyForm($agency);
     if (strstr($request->getReferer(), 'person/view')) {
         if ($this->person) {
             //session
             $referer_session = $this->getUser()->getAttribute('ref');
             if (!$referer_session) {
                 $referer_session = array($this->key => array());
                 $this->getUser()->setAttribute('ref', $referer_session);
             } elseif (!isset($referer_session[$this->key])) {
                 $a = '@person_view?id=' . $this->person->getId();
                 $referer_session[$this->key] = array('referer' => $a);
                 $this->getUser()->setAttribute('ref', $referer_session[$this->key]);
             }
         }
     }
     $this->person_referer = $request->getParameter('referer');
     if ($request->isMethod('post')) {
         $this->person_referer = $request->getParameter('referer');
         $this->person_form->bind($request->getParameter('per'));
         if ($this->person_form->isValid() && $this->person_form->getValue('first_name') && $this->person_form->getValue('last_name')) {
             $this->person->setTitle($this->person_form->getValue('title'));
             $this->person->setFirstName($this->person_form->getValue('first_name'));
             $this->person->setLastName($this->person_form->getValue('last_name'));
             $this->person->setAddress1($this->person_form->getValue('address1'));
             $this->person->setAddress2($this->person_form->getValue('address2'));
             $this->person->setCity($this->person_form->getValue('city'));
             $this->person->setCounty($this->person_form->getValue('county'));
             $this->person->setState($this->person_form->getValue('state'));
             $this->person->setCountry($this->person_form->getValue('country'));
             $this->person->setZipcode($this->person_form->getValue('zipcode'));
             $this->person->setDayPhone($this->person_form->getValue('day_phone'));
             $this->person->setDayComment($this->person_form->getValue('day_comment'));
             $this->person->setEveningPhone($this->person_form->getValue('evening_phone'));
             $this->person->setEveningComment($this->person_form->getValue('evening_comment'));
             $this->person->setMobilePhone($this->person_form->getValue('mobile_phone'));
             $this->person->setMobileComment($this->person_form->getValue('mobile_comment'));
             $this->person->setPagerPhone($this->person_form->getValue('paper_phone'));
             $this->person->setPagerComment($this->person_form->getValue('paper_comment'));
             $this->person->setOtherPhone($this->person_form->getValue('other_phone'));
             $this->person->setOtherComment($this->person_form->getValue('other_comment'));
             $this->person->setFaxPhone1($this->person_form->getValue('fax_phone1'));
             $this->person->setFaxComment1($this->person_form->getValue('fax_comment1'));
             $this->person->setAutoFax($this->person_form->getValue('auto_fax'));
             $this->person->setFaxPhone2($this->person_form->getValue('fax_phone2'));
             $this->person->setFaxComment2($this->person_form->getValue('fax_comment2'));
             $this->person->setEmail($this->person_form->getValue('email'));
             $this->person->setEmailTextOnly($this->person_form->getValue('email_text_only'));
             $this->person->setEmailBlocked($this->person_form->getValue('email_blocked'));
             $this->person->setComment($this->person_form->getValue('comment'));
             //$this->person->setBlockMailings($this->person_form->getValue('block_mailings')==0?null:$this->person_form->getValue('block_mailings'));
             $this->person->setBlockMailings($this->person_form->getValue('block_mailings'));
             $this->person->setNewsletter($this->person_form->getValue('newsletter'));
             $this->person->setGender($this->person_form->getValue('gender'));
             $this->person->setDeceased($this->person_form->getValue('deceased'));
             $this->person->setDeceasedComment($this->person_form->getValue('deceased_comment'));
             $this->person->setSecondaryEmail($this->person_form->getValue('secondary_email'));
             $this->person->setDeceasedDate($this->person_form->getValue('deceased_date'));
             $this->person->setMiddleName($this->person_form->getValue('middle_name'));
             $this->person->setSuffix($this->person_form->getValue('suffix'));
             $this->person->setNickname($this->person_form->getValue('nickname'));
             $this->person->setVeteran($this->person_form->getValue('veteran'));
             if ($this->person->isNew()) {
                 $content = $this->getUser()->getName() . ' added new Person: ' . $this->person->getFirstName();
                 ActivityPeer::log($content);
             }
             $this->person->save();
             if ($this->person->getId()) {
                 $c = new Criteria();
                 $c->add(RoleNotificationPeer::MID, 5);
                 $c->add(RoleNotificationPeer::NOTIFICATION, 1);
                 $c->addOr(RoleNotificationPeer::NOTIFICATION, 3);
                 $c->addJoin(RoleNotificationPeer::ROLE_ID, PersonRolePeer::ROLE_ID);
                 $c->addJoin(PersonRolePeer::PERSON_ID, PersonPeer::ID);
                 $personemail = PersonPeer::doSelect($c);
                 $allemail = array();
                 $pindex = 0;
                 foreach ($personemail as $getEmail) {
                     if (strlen($getEmail->getEmail()) > 0) {
                         $allemail[$pindex++] = $getEmail->getEmail();
                     } else {
                         if (strlen($getEmail->getSecondaryEmail()) > 0) {
                             $allemail[$pindex++] = $getEmail->getSecondaryEmail();
                         }
                     }
                 }
                 //$allemail[$pindex]="*****@*****.**";
                 $email['subject'] = "New Person added";
                 $link = $request->getHost() . "/person/view/" . $this->person->getId();
                 $body = "A new person added in " . $request->getHost() . "\r\n" . $this->person->getFirstName() . " " . $this->person->getLastName() . "\r\n Profile Link: " . $link;
                 $email['body'] = $body;
                 $email['sender_email'] = "*****@*****.**";
                 $this->getComponent('mail', 'sendBulk', array('subject' => $email['subject'], 'recievers' => $allemail, 'sender' => $email['sender_email'], 'body' => $email['body']));
             }
             if ($request->hasParameter('has')) {
                 $data = '';
                 if ($request->getParameter('camp_id')) {
                     $data = '&camp_id=' . $request->getParameter('camp_id');
                 }
                 $this->getUser()->setFlash('success', 'Step 1 : New Person information has been successfully created! Now you can add passenger!');
                 $this->redirect('@passenger_create?add_pass='******'has') . '&p_id=' . $this->person->getId() . $data);
             }
             if ($request->hasParameter('iti')) {
                 $this->getUser()->setFlash('success', 'Step 1 : New Person information has been successfully created! Now you can add passenger!');
                 $this->redirect('@passenger_create?add_pass_iti=' . $request->getParameter('iti') . '&p_id=' . $this->person->getId());
             }
             if ($request->hasParameter('contact')) {
                 $this->getUser()->setFlash('success', 'Step 1 : New Person information has been successfully created! Now you can add contact!');
                 $this->redirect('@contact_create?person_id=' . $this->person->getId());
             }
             $this->getUser()->setFlash('success', 'Person information has been successfully saved!');
             $last = $request->getParameter('back');
             $referer_session = $this->getUser()->getAttribute('ref');
             $back_url = '@person_view?id=' . $this->person->getId();
             $this->redirect($back_url);
         }
     } else {
         # Set referer URL
         $this->person_referer = $request->getReferer() ? $request->getReferer() : '@person';
     }
 }
Example #4
0
 /**
  * Mission
  * CODE: mission_create, mission_leg_create
  */
 public function executeUpdate(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('add_passengers')) {
         $this->group_camp_id = $request->getParameter('add_passengers');
     }
     if ($request->getParameter('id')) {
     } else {
         if ($request->isMethod('post')) {
             $main_id = $request->getParameter('main_id');
             $row_id = $request->getParameter('row_id');
             $camp_id = $request->getParameter('camp_id');
             if (isset($row_id)) {
                 $fname = $request->getParameter('pass_fname' . $row_id);
                 $lname = $request->getParameter('pass_lname' . $row_id);
                 $location = $request->getParameter('pass_loc' . $row_id);
                 $note = $request->getParameter('pass_note' . $row_id);
                 $link = $request->getParameter('pass_link' . $row_id);
             } else {
                 $main_id = $request->getParameter('person_id');
                 $fname = $request->getParameter('pass_fname');
                 $lname = $request->getParameter('pass_lname');
                 $location = $request->getParameter('pass_loc');
                 $note = $request->getParameter('pass_note');
                 $link = $request->getParameter('link');
             }
             //echo var_dump($request->getParameter('link'));die();
             #create default Itinerary to passenger
             if (isset($main_id)) {
                 $is_passenger = PassengerPeer::getByPersonId($main_id);
                 if (!$is_passenger->getRequesterId() && $camp_id) {
                     $this->getUser()->setFlash('success', 'Passenger has no Requester. Requester must be selected before create a Mission!');
                     $this->redirect('@add_passengers?id=' . $camp_id);
                 }
                 $itinerary = new Itinerary();
                 if (isset($is_passenger) && $is_passenger instanceof Passenger) {
                     $itinerary->setDateRequested(date('y/m/d'));
                     $itinerary->setApointTime('Morning');
                     $itinerary->setPassengerId($is_passenger->getId());
                     $miss_type = MissionTypePeer::getName('Camp');
                     if (isset($miss_type) && $miss_type instanceof MissionType) {
                         $itinerary->setMissionTypeId($miss_type->getId());
                     }
                     if ($is_passenger->getRequesterId()) {
                         $pass_req = $is_passenger->getRequester();
                         if (isset($pass_req) && $pass_req) {
                             if (isset($pass_req) && $pass_req instanceof Requester) {
                                 $itinerary->setRequesterId($pass_req->getId());
                             }
                         }
                     }
                     if (isset($camp_id)) {
                         $camp = CampPeer::retrieveByPK($camp_id);
                         if (isset($camp) && $camp instanceof Camp) {
                             if ($camp->getAgencyId()) {
                                 $agency = $camp->getAgency();
                                 if (isset($agency) && $agency instanceof Agency) {
                                     $itinerary->setAgencyId($agency->getId());
                                 }
                             }
                         }
                     }
                     $itinerary->setCampId($camp_id);
                     $itinerary->save();
                     if (isset($itinerary) && $itinerary instanceof Itinerary) {
                         $this->redirect('@itinerary_detail?id=' . $itinerary->getId() . '&add_passengers=' . $camp_id);
                     }
                 }
             }
         }
     }
     $this->itinerary = ItineraryPeer::retrieveByPK($request->getParameter('id'));
     $this->forward404Unless($this->itinerary);
     $itinerary =& $this->itinerary;
     $this->errors = array();
     if ($request->isMethod('post')) {
         # validation
         $mission_date = $request->getParameter('mission_date');
         if (empty($mission_date)) {
             $this->errors[] = 'Mission date is required';
         }
         $companions = (array) $request->getParameter('companions');
         if (count($companions)) {
             $c = new Criteria();
             $c->add(CompanionPeer::ID, $companions, Criteria::IN);
             $c->add(CompanionPeer::PASSENGER_ID, $this->itinerary->getPassengerId());
             if (CompanionPeer::doCount($c) != count($companions)) {
                 $this->errors[] = 'Some companions not found';
             }
         }
         #use it when add group mission
         $group_camp_id = $request->getParameter('add_passengers');
         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');
                 if (empty($destination)) {
                     $this->errors[] = 'Please specify destination address';
                 }
                 if (empty($origin)) {
                     $this->errors[] = 'Please specify origin address';
                 } elseif ($destination == $origin) {
                     $this->errors[] = 'Origin and Destination addresses conflict';
                 }
                 break;
             case 'commercial_mission':
                 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;
             }
             $this->selected_companions = $companions;
         } else {
             # Create Mission
             $mission = new Mission();
             $mission->setItineraryId($itinerary->getId());
             $mission->setMissionTypeId($itinerary->getMissionTypeId());
             $mission->setDateRequested($itinerary->getDateRequested());
             $mission->setPassengerId($itinerary->getPassengerId());
             $mission->setRequesterId($itinerary->getRequesterId());
             $mission->setCampId($itinerary->getCampId());
             $mission->setMissionDate(strtotime($request->getParameter('mission_date')));
             $mission->setMissionSpecificComments($request->getParameter('comment'));
             $mission->save();
             # Create Companions
             foreach ($companions as $id) {
                 $mission_companion = new MissionCompanion();
                 $mission_companion->setMissionId($mission->getId());
                 $mission_companion->setCompanionId($id);
                 $mission_companion->save();
             }
             # Create Legs
             switch ($request->getParameter('transportation')) {
                 case 'air_mission':
                     for ($i = 0; $i < sizeof($origin_airports); $i++) {
                         $airport_o = AirportPeer::getByIdent($origin_airports[$i]);
                         $airport_d = AirportPeer::getByIdent($dest_airports[$i]);
                         $mission_leg = new MissionLeg();
                         $mission_leg->setMissionId($mission->getId());
                         $mission_leg->setLegNumber($i + 1);
                         $mission_leg->setFromAirportId($airport_o->getId());
                         $mission_leg->setToAirportId($airport_d->getId());
                         $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->save();
                     }
                     $this->getUser()->setFlash('success', 'Mission and Leg(s) has successfully created!');
                     break;
                 case 'ground_mission':
                     $mission_leg = new MissionLeg();
                     $mission_leg->setMissionId($mission->getId());
                     $mission_leg->setLegNumber(1);
                     $mission_leg->setPassOnBoard(0);
                     $mission_leg->setTransportation('ground_mission');
                     $mission_leg->setGroundOrigin($request->getParameter('ground_origin'));
                     $mission_leg->setGroundDestination($request->getParameter('ground_destination'));
                     $mission_leg->save();
                     break;
                 case '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']);
                     $n_leg = 0;
                     foreach ($origins as $i => $origin) {
                         if (empty($origin) || empty($destinations[$i])) {
                             continue;
                         }
                         $mission_leg = new MissionLeg();
                         $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->save();
                     }
                     break;
             }
             //        $this->redirect('@create_companion?id='.$mission_leg->getId());
             if (isset($group_camp_id)) {
                 $this->redirect('@mission_view?id=' . $mission->getId() . '&add_passengers=' . $group_camp_id);
             } else {
                 $this->redirect('@mission_view?id=' . $mission->getId());
             }
         }
     }
     $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->mission = MissionPeer::getByItineraryId($this->itinerary->getId());
     $this->airport_list = AirportPeer::getMappable();
     $this->ground_addresses = $this->getGroundAddresses();
     $this->airlines = AirlinePeer::doSelect(new Criteria());
     $this->funds = FundPeer::doSelect(new Criteria());
 }