public function editpostAction() { if ($data = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($data['value_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($data['value_id']); $html = ''; $contact = new Contact_Model_Contact(); $contact->find($option_value->getId(), 'value_id'); if (!empty($data['file'])) { $file = pathinfo($data['file']); $filename = $file['basename']; $relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $img_dst = $folder . '/' . $filename; $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_('An error occurred while saving your picture. Please try again later.')); } else { $data['cover'] = $relative_path . '/' . $filename; } } else { if (!empty($data['remove_cover'])) { $data['cover'] = null; } } $contact->setData($data); if ($contact->getStreet() and $contact->getPostcode() and $contact->getCity()) { $latlon = Siberian_Google_Geocoding::getLatLng(array("street" => $contact->getStreet(), "postcode" => $contact->getPostcode(), "city" => $contact->getCity())); if (!empty($latlon[0]) && !empty($latlon[1])) { $contact->setLatitude($latlon[0])->setLongitude($latlon[1]); } } else { $contact->setLatitude(null)->setLongitude(null); } $contact->save(); $html = array('success' => '1', 'success_message' => $this->_('Info successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
/** * Add action for contact controller */ public function addAction() { // action body try { $translate = Zend_Registry::get('Zend_Translate'); $frmContact = new Contact_Form_Contact(); $frmContact->setAction($this->_request->getBaseUrl() . "/contact/contact/add"); $mdlAccount = new Acl_Model_Account(); $accountList = $mdlAccount->getSimpleList(); $cbAccount = $frmContact->getElement('account_id'); foreach ($accountList as $account) { $cbAccount->addMultiOption($account->id, $account->email); } $mdlCategory = new Contact_Model_Category(); $categoryList = $mdlCategory->getSimpleList(); $cbCategory = $frmContact->getElement('category_id'); foreach ($categoryList as $category) { $cbCategory->addMultiOption($category->id, $category->title); } if ($this->getRequest()->isPost()) { if ($frmContact->isValid($_POST)) { $mdlContact = new Contact_Model_Contact(); $fileName = ''; if ($frmContact->image->isUploaded()) { $ext = end(explode('.', $frmContact->image->getFileName())); $frmContact->image->addFilter('Rename', implode('_', array('cc', date('YmdHis'))) . '.' . $ext); $frmContact->image->receive(); $fileName = $frmContact->image->getFileName(null, false); chmod(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 0755); $thumb = Zend_Layout::getMvcInstance()->getView()->thumbnail(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 70, 70, DIR_MOD_CONTACT_THUMB_UPLOADS . '/', DIR_MOD_CONTACT_THUMB_UPLOADS); chmod($thumb, 0755); } $contact = $mdlContact->createRow($frmContact->getValues()); $contact->image = $fileName; $mdlContact->save($contact); $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("LBL_ITEM_CREATED_SUCCESSFULLY"))); $this->_helper->redirector("listregistered", "contact", "contact"); } } else { $fields = array(); foreach ($frmContact->getElements() as $element) { $fields[] = $element->getName(); } $frmContact->addDisplayGroup($fields, 'form', array('legend' => "CONTACT_ADD")); } $this->view->frmContact = $frmContact; } catch (Exception $e) { $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage())); $this->_helper->redirector("listregistered", "contact", "contact"); } return; }