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');
 }
Ejemplo n.º 2
0
 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');
 }
Ejemplo n.º 3
0
 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;
 }