/** * Searches for camps * CODE:camp_create */ public function executeUpdate(sfWebRequest $request) { 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'); } sfContext::getInstance()->getConfiguration()->loadHelpers('Partial'); $this->agencies = AgencyPeer::getForSelectParent(); $this->agency = trim($this->getRequestParameter('agency', '*')) == '' ? '*' : trim($this->getRequestParameter('agency', '*')); $this->airport = trim($this->getRequestParameter('airport', '*')) == '' ? '*' : trim($this->getRequestParameter('airport', '*')); $this->airports = AirportPeer::doSelect(new Criteria()); if ($request->getParameter('id')) { $camp = CampPeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($camp); if (isset($camp)) { if ($camp->getAgencyId()) { $agency = AgencyPeer::retrieveByPK($camp->getAgencyId()); if (isset($agency)) { $this->agency_id = $agency->getId(); } } if ($camp->getAirportId()) { $airport = AirportPeer::retrieveByPK($camp->getAirportId()); if (isset($airport)) { $this->airport_id = $airport->getId(); } } } $this->title = 'Edit camp'; $success = 'Camp information has been successfully changed!'; slot('nav_menu', array('mission_coord', '')); } else { $camp = new Camp(); if ($request->getParameter('agency_id')) { $this->agency_id = $request->getParameter('agency_id'); } $this->title = 'Add new camp'; $success = 'Camp information has been successfully created!'; slot('nav_menu', array('mission_coord', 'add-camp')); } //Agency PopUp Form $agency = new Agency(); $this->form_a = new AgencyForm($agency); $this->a_referer = $request->getReferer(); //Aiport PopUp Form $airport = new Airport(); $this->form_airport = new AirportForm($airport); $this->airport_referer = $request->getReferer(); $this->form = new CampForm($camp); if ($request->isMethod('post')) { $this->referer = $request->getParameter('referer'); $this->form->bind($request->getParameter('camp')); $ma = ''; foreach ($this->form as $pass_key => $pass_data) { $ma .= $pass_data . '|'; } if ($this->form->isValid() && $request->getParameter('agency') != null) { if ($request->getParameter('agency')) { $agency = AgencyPeer::getByName($request->getParameter('agency')); } if (isset($agency) && $agency instanceof Agency) { $camp->setAgencyId($agency->getId()); } //$aId = $camp->getAirportId(); //$aInd = $request->getParameter('airport'); $airport = AirportPeer::getByIdent($request->getParameter('airport')); /*if(!empty($aId)){ if(!empty($aInd)){ $camp->setAirportId($airport->getId()); } else{ $camp->setAirportId($aId); } }else{ if($airport) $camp->setAirportId($airport->getId()); }*/ /*if($request->getParameter('airport')){ $camp->setAirportId(null); }else{ $airport = AirportPeer::getByIdent($request->getParameter('airport')); if(isset($airport) instanceof Airport){ $camp->setAirportId($airport->getId()); } }*/ //$camp->setAirport($request->getParameter('airport_name')); $camp->setAirport($airport); $camp->setSession($this->form->getValue('session')); $camp->setCampName($this->form->getValue('camp_name')); $camp->setArrivalDate($this->form->getValue('arrival_date')); $camp->setDepartureDate($this->form->getValue('departure_date')); $camp->setArrivalComment($this->form->getValue('arrival_comment')); $camp->setDepartureComment($this->form->getValue('departure_comment')); $camp->setComment($this->form->getValue('comment')); if ($camp->isNew()) { $content = $this->getUser()->getName() . ' added new Camp: ' . $camp->getCampName(); ActivityPeer::log($content); } $camp->save(); $this->getUser()->setFlash('success', $success); if ($this->form->isNew()) { $this->redirect('camp/view?id=' . $camp->getId()); } else { $this->redirect('camp/index?showlist=true'); } //add passengers to camp then create new mission, legs //missions assocated with camps that will be a group mission } else { if ($request->getParameter('agency_id') == null) { $this->getUser()->setFlash('warning', 'Please choose Agency!'); } } } else { # Set referer URL $this->referer = $request->getReferer() ? $request->getReferer() : '@camp'; //echo $this->referer; exit (); } $this->camp = $camp; }