/** Edit staff profile */ public function editAction() { $form = new ContactForm(); $form->submit->setLabel('Save'); $form->removeElement('role'); $form->removeElement('alumni'); $form->removeElement('identifier'); $form->removeElement('role'); $form->removeElement('dbaseID'); $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']; } else { $lat = NULL; $lon = NULL; } $woeid = $place->woeid; $updateData = array('firstname' => $form->getValue('firstname'), 'lastname' => $form->getValue('lastname'), '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'), 'telephone' => $form->getValue('telephone'), 'fax' => $form->getValue('fax'), 'region' => $form->getValue('region'), 'website' => $form->getValue('website'), 'profile' => $form->getValue('profile'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms(), 'latitude' => $lat, 'longitude' => $lon, 'woeid' => $woeid); foreach ($updateData as $key => $value) { if (is_null($value)) { unset($updateData[$key]); } } $contacts = new Contacts(); $where = array(); $where[] = $contacts->getAdapter()->quoteInto('dbaseID = ?', $this->getIdentityForForms()); $insert = $contacts->update($updateData, $where); $this->_flashMessenger->addMessage('Contact information for ' . $form->getValue('firstname') . ' ' . $form->getValue('lastname') . ' updated!'); $this->_redirect('/users/account/'); } else { $form->populate($formData); } } else { $id = (int) $this->getIdentityForForms(); if ($id != 0) { $contacts = new Contacts(); $contact = $contacts->fetchRow('dbaseID = ' . $id); if (is_null($contact)) { throw new Exception('Admin has not yet set up a profile for you'); } else { $form->populate($contact->toArray()); } } } }
/** Edit staff profile * @access public * @return void * @throws Pas_Exception_Param */ public function editAction() { $form = new ContactForm(); $form->submit->setLabel('Save'); $form->removeElement('role'); $form->removeElement('alumni'); $form->removeElement('identifier'); $form->removeElement('role'); $form->removeElement('dbaseID'); $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']; $lon = $coords['lon']; $pm = new Pas_Service_Geo_GeoPlanet($this->_helper->config()->webservice->ydnkeys->appid); $place = $pm->reverseGeoCode($lat, $lon); $woeid = $place['woeid']; } else { $lat = null; $lon = null; $woeid = null; } $updateData = $form->getValues(); $updateData['latitude'] = $lat; $updateData['longitude'] = $lon; $updateData['woeid'] = $woeid; $where = array(); $where[] = $this->_contacts->getAdapter()->quoteInto('dbaseID = ?', $this->getIdentityForForms()); $this->_contacts->update($updateData, $where); $this->getFlash()->addMessage('Contact information updated!'); $this->redirect('/users/account/'); } else { $form->populate($formData); } } else { $contact = $this->_contacts->fetchRow($this->_contacts->select()->where('dbaseID = ' . $this->getIdentityForForms())); if (is_null($contact)) { throw new Pas_Exception_Param('Admin has not yet set up a profile for you', 500); } else { $form->populate($contact->toArray()); } } }