public function action_edit($id = null) { $currency = Model_Currency::find($id); $val = Model_Currency::validate('edit'); if ($val->run()) { $currency->name = Input::post('name'); $currency->symbol = Input::post('symbol'); $currency->country = Input::post('country'); $currency->is_default = Input::post('is_default'); $currency->exchange_rate = Input::post('exchange_rate'); if ($currency->save()) { Session::set_flash('success', e('Updated currency #' . $id)); Response::redirect('admin/currencies'); } else { Session::set_flash('error', e('Could not update currency #' . $id)); } } else { if (Input::method() == 'POST') { $currency->name = $val->validated('name'); $currency->symbol = $val->validated('symbol'); $currency->country = $val->validated('country'); $currency->is_default = $val->validated('is_default'); $currency->exchange_rate = $val->validated('exchange_rate'); Session::set_flash('error', $val->error()); } $this->template->set_global('currency', $currency, false); } $countries = Model_Country::find('all', array('order_by' => array(array('name', 'asc')))); $this->template->set_global('countries', $countries); $this->template->set_global('yes_no', array('0' => 'No', '1' => 'Yes')); $this->template->title = "Currencies"; $this->template->content = View::forge('admin/currencies/edit'); }
/** * Fungsi inisialisasi form */ public function init() { parent::init(); $langId = Zend_Registry::get('languageId'); if ($langId != 2) { $textrealnamereg = 'Real Name'; $textconfpassreg = 'Confirm Password'; $textcountryreg = 'Country'; $textselectcountryreg = 'Choose Country'; $textreg = 'Register'; } else { $textrealnamereg = 'Nama Asli'; $textconfpassreg = 'Konfirmasi Password'; $textcountryreg = 'Negara'; $textselectcountryreg = 'Pilih Negara Anda'; $textreg = 'Daftar'; } // Form Attribute $this->setMethod('post'); $this->addAttribs(array('id' => 'inputForm', 'action' => $this->_baseUrlHelper->baseUrl() . '/registration/index')); $this->setAttrib('accept-charset', 'utf-8'); // Element Form // -> Real Name $realName = $this->createElement('text', 'realname'); $realName->setLabel($textrealnamereg)->setRequired(true)->addValidator(new Zend_Validate_StringLength(3, 20)); $this->addElement($realName); // -> Username $username = $this->createElement('text', 'username'); $username->setLabel('Username')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator(new Zend_Validate_StringLength(3, 20))->addValidator(new Zend_Validate_Db_NoRecordExists('user', 'username')); $this->addElement($username); // -> Password $password = $this->createElement('password', 'password'); $password->setLabel('Password')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim'); $this->addElement($password); // -> Password Confirm // ---> Validator password $identValidator = new Zend_Validate_Identical($_POST['password']); $identValidator->setMessages(array('notSame' => 'Value doesn\'t match!', 'missingToken' => 'Value doesn\'t match!')); $password2 = $this->createElement('password', 'password2'); $password2->setLabel($textconfpassreg)->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator($identValidator); $this->addElement($password2); // -> Email $email = $this->createElement('text', 'email'); $email->setLabel('Email:')->setRequired(true)->addValidator(new Zend_Validate_EmailAddress())->addValidator(new Zend_Validate_Db_NoRecordExists('user', 'email')); $this->addElement($email); // -> Country // ----> Model Country $countryModel = new Model_Country(); $countryData = $countryModel->getNameCountry(); $countryData[""] = $textselectcountryreg; $country = $this->createElement('select', 'country'); $country->setLabel($textcountryreg)->setRequired(true)->setMultiOptions($countryData); $this->addElement($country); // -> Captcha $publicKey = Zend_Registry::get('recaptcha_public_key'); $privateKey = Zend_Registry::get('recaptcha_private_key'); $recaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha))); $this->addElement($captcha); // -> Submit $submit = $this->createElement('submit', 'submit'); $submit->setLabel($textreg)->removeDecorator('Label'); $this->addElement($submit); }
public function action_delete($id = null) { if (Auth::has_access('country.delete') == false) { Session::set_flash("error", "Only admins may delete countries!"); Response::redirect("country/") and die; } if ($country = Model_Country::find($id)) { $country->delete(); Session::set_flash('success', 'Deleted country #' . $id); } else { Session::set_flash('error', 'Could not delete country #' . $id); } Response::redirect('country'); }
public function action_edit($id) { $partner = Model_Partner::find($id); /* @var $partner Model_Partner */ if (!$partner) { Response::redirect('/admin/404'); } $validationErrors = array(); $view = $this->setDefaultValiesToView('admin/partners/partners/edit.html.twig'); if (Input::post()) { if (Input::post('delete')) { $url = 'admin/partners'; $this->performItemDeletion($partner, $url); } if (Input::post('update')) { try { $validationErrors = $this->validateItem(); if ($validationErrors) { throw new Exception('Form validation failed'); } // Updates item $this->assignValuesFromPost($partner); // Adds terms and conditions foreach (self::$languages as $language) { // In case translation for current language is missing, copies EN translation by default if (Input::post('terms_' . $language)) { $partner->setTerms(Input::post('terms_' . $language), $language); } else { $partner->setTerms(Input::post('terms_en'), $language); } } $partner->save(); // Reloads page $session = Session::instance(); $session->set($this->updatedKey, true); Response::redirect('admin/partners/edit/' . $partner->get('id')); } catch (Exception $e) { Log::debug($e->getMessage()); $view->set('post', Input::post()); } } } $view->set('pageTitle', 'Edit Partner'); $view->set('partner', $partner); $view->set('countries', Model_Country::findAll(null, 'en')); $view->set('country', Model_Country::find($partner->get('country'))); $view->set('currencies', Model_Currency::find('all')); $view->set('validationErrors', $validationErrors); return $view; }