/** Edit a contact's details
  */
 public function editAction()
 {
     $form = new ContactForm();
     $form->submit->setLabel('Save');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $address = $form->getValue('address_1') . ',' . $form->getValue('address_2') . ',' . $form->getValue('town') . ',' . $form->getValue('county') . ',' . $form->getValue('postcode') . ', UK';
             $coords = $this->_geocoder->getCoordinates($address);
             if ($coords) {
                 $lat = $coords['lat'];
                 $long = $coords['lon'];
                 $pm = new Pas_Service_Geoplanet();
                 $place = $pm->reverseGeoCode($lat, $lon);
                 $woeid = $place['woeid'];
             } else {
                 $lat = NULL;
                 $lon = NULL;
                 $woeid = NULL;
             }
             $updateData = array('firstname' => $form->getValue('firstname'), 'lastname' => $form->getValue('lastname'), 'role' => $form->getValue('role'), 'dbaseID' => $form->getValue('dbaseID'), 'email_one' => $form->getValue('email_one'), 'email_two' => $form->getValue('email_two'), 'address_1' => $form->getValue('address_1'), 'address_2' => $form->getValue('address_2'), 'town' => $form->getValue('town'), 'county' => $form->getValue('county'), 'postcode' => $form->getValue('postcode'), 'identifier' => $form->getValue('identifier'), 'telephone' => $form->getValue('telephone'), 'fax' => $form->getValue('fax'), 'region' => $form->getValue('region'), 'website' => $form->getValue('website'), 'profile' => $form->getValue('profile'), 'alumni' => $form->getValue('alumni'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms(), 'latitude' => $lat, 'longitude' => $lon, 'woeid' => $woeid);
             foreach ($updateData as $key => $value) {
                 if (is_null($value) || $value == "") {
                     unset($updateData[$key]);
                 }
             }
             $contacts = new Contacts();
             $where = array();
             $where[] = $contacts->getAdapter()->quoteInto('id = ?', $this->_getParam('id'));
             $insert = $contacts->update($updateData, $where);
             $this->_flashMessenger->addMessage('Contact information for ' . $form->getValue('firstname') . ' ' . $form->getValue('lastname') . ' updated!');
             $this->_redirect($this->_redirectUrl . 'contact/id/' . $this->_getParam('id'));
         } else {
             $form->populate($formData);
         }
     } else {
         $id = (int) $this->_request->getParam('id', 0);
         if ($id > 0) {
             $contacts = new Contacts();
             $contact = $contacts->fetchRow('id=' . $id);
             $form->populate($contact->toArray());
         }
     }
 }
 /** Edit an event
  */
 public function editAction()
 {
     $form = new EventForm();
     $form->details->setLegend('Edit event');
     $form->submit->setLabel('Save event');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $address = $form->getValue('eventLocation');
             $coords = $this->_geocoder->getCoordinates($address);
             if ($coords) {
                 $lat = $coords['lat'];
                 $long = $coords['lon'];
                 $pm = new Pas_Service_Geoplanet();
                 $place = $pm->reverseGeoCode($lat, $lon);
                 $woeid = $place['woeid'];
             } else {
                 $lat = NULL;
                 $lon = NULL;
                 $woeid = NULL;
             }
             $insertdata = array('eventTitle' => $form->getValue('eventTitle'), 'eventDescription' => $form->getValue('eventDescription'), 'eventLocation' => $form->getValue('eventLocation'), 'organisation' => $form->getValue('organisation'), 'eventStartTime' => $form->getValue('eventStartTime'), 'eventEndTime' => $form->getValue('eventEndTime'), 'eventStartDate' => $form->getValue('eventStartDate'), 'eventEndDate' => $form->getValue('eventEndDate'), 'eventRegion' => $form->getValue('eventRegion'), 'eventType' => $form->getValue('eventType'), 'latitude' => $lat, 'longitude' => $long, 'adultsAttend' => $form->getValue('adultsAttend'), 'childrenAttend' => $form->getValue('childrenAttend'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms());
             foreach ($insertdata as $key => $value) {
                 if (is_null($value) || $value == "") {
                     unset($insertdata[$key]);
                 }
             }
             $events = new Events();
             $where = array();
             $where[] = $events->getAdapter()->quoteInto('id = ?', $this->_getParam('id'));
             $events->update($insertdata, $where);
             $this->_flashMessenger->addMessage('You updated: <em>' . $form->getValue('eventTitle') . '</em> successfully.');
             $this->_redirect('/admin/events/');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = (int) $this->_getParam('id', 0);
         if ($id > 0) {
             $events = new Events();
             $event = $events->fetchRow('id=' . (int) $id);
             $form->populate($event->toArray());
         }
     }
 }