Exemple #1
0
 /**
  * Add or edit airport
  * CODE: airport_create
  */
 public function executeUpdate(sfWebRequest $request)
 {
     # security
     if (!$this->getUser()->hasCredential(array('Administrator'), 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');
     slot('nav_menu', array('mission_coord', ''));
     $this->names = AirportPeer::getNames();
     if ($request->getParameter('id')) {
         $this->airport = AirportPeer::retrieveByPK($request->getParameter('id'));
         $this->forward404Unless($this->airport);
         $this->title = 'Edit airport';
         $success = 'Airport information has been successfully changed!';
         $this->can_edit = 1;
         $this->fbos = FboPeer::getByAirportIdSelectAll($request->getParameter('id'));
         //echo count($this->fbos); die();
     } else {
         $this->airport = new Airport();
         $this->title = 'Add new airport';
         $success = 'Airport information has been successfully created!';
     }
     $this->form = new AirportForm($this->airport);
     $this->back = $request->getReferer();
     if ($request->getParameter('leg')) {
         $this->leg_id = $request->getParameter('leg');
     }
     if ($request->isMethod('post')) {
         $this->referer = $request->getReferer();
         $this->form->bind($request->getParameter('airp'));
         if ($this->form->isValid()) {
             if ($this->form->getValue('ident') && $request->getParameter('id') != null) {
                 //old
                 $is_used = AirportPeer::retrieveByPK($request->getParameter('id'));
                 if ($this->form->getValue('ident') != $is_used->getIdent()) {
                     $this->airport->setIdent($this->form->getValue('ident'));
                 } else {
                     $this->airport->setIdent($is_used->getIdent());
                 }
             } elseif ($this->form->getValue('ident') && !$request->getParameter('id')) {
                 //new
                 $is_used = AirportPeer::getByIdent($this->form->getValue('ident'));
                 if (isset($is_used)) {
                     if ($is_used->getIdent() == $this->form->getValue('ident')) {
                         if ($request->getParameter('back') == null) {
                             $last = $request->getReferer();
                         } else {
                             $last = $request->getParameter('back');
                         }
                         if (strstr($last, 'camp/create')) {
                             $back_url = $last;
                         } elseif (strstr($last, 'fbo/create')) {
                             $back_url = $last;
                         } else {
                             $back_url = 'airport';
                         }
                         $this->getUser()->setFlash('success', 'This Airport Ident has already used. Please confirm else!');
                         $this->redirect($back_url);
                     }
                 } elseif ($this->form->getValue('ident') == 'null') {
                     $this->airport->setIdent(null);
                 } else {
                     $this->airport->setIdent($this->form->getValue('ident'));
                 }
             }
             $this->airport->setIdent($this->form->getValue('ident'));
             $this->airport->setName($this->form->getValue('name'));
             if ($this->airport->isNew()) {
                 $this->airport->setCity($this->form->getValue('city'));
                 $this->airport->setState($this->form->getValue('state'));
                 $this->airport->setLatitude($this->form->getValue('latitude'));
                 $this->airport->setLongitude($this->form->getValue('longitude'));
                 $this->airport->setRunwayLength($this->form->getValue('runway_length'));
                 if ($this->form->getValue('wing_id') == 0) {
                     $this->airport->setWingId(null);
                 } else {
                     $this->airport->setWingId($this->form->getValue('wing_id'));
                 }
                 $this->airport->setGmtOffset($this->form->getValue('gmt_offset'));
                 $this->airport->setDstOffset($this->form->getValue('dst_offset'));
                 $this->airport->setZipcode($this->form->getValue('zipcode'));
                 if ($this->form->getValue('closed') == null) {
                     $this->airport->setClosed(0);
                 } else {
                     $this->airport->setClosed($this->form->getValue('closed'));
                 }
                 $content = $this->getUser()->getName() . ' added new Airport: ' . $this->airport->getName() . ' (' . $this->airport->getIdent() . ')';
                 ActivityPeer::log($content);
             }
             $this->airport->save();
             if ($request->getParameter('back') == null) {
                 $last = $request->getReferer();
             } else {
                 $last = $request->getParameter('back');
             }
             if (strstr($last, 'camp/create')) {
                 $back_url = $last;
             } elseif (strstr($last, 'fbo/create')) {
                 $back_url = $last;
             } else {
                 $back_url = 'airport';
             }
             $this->getUser()->setFlash('success', $success);
             if ($request->getParameter('leg_id')) {
                 $back_url = '@leg_edit?id=' . $request->getParameter('leg_id');
             }
             $this->redirect($back_url);
         }
     } else {
         # Set referer URL
         $this->referer = $request->getReferer() ? $request->getReferer() : '@airport';
     }
     $this->airport = $this->airport;
 }