public function action_update()
 {
     $name = $this->request->param('id');
     $field = new Model_Field();
     $field_data = $field->get($name);
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit') . ' ' . $name));
     $this->template->title = __('Edit Custom Field for Advertisement');
     //find all, for populating form select fields
     $categories = Model_Category::get_as_array();
     if ($_POST) {
         try {
             $options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE, 'admin_privilege' => Core::post('admin_privilege') == 'on' ? TRUE : FALSE, 'show_listing' => Core::post('show_listing') == 'on' ? TRUE : FALSE);
             if ($field->update($name, Core::post('values'), Core::post('categories'), $options)) {
                 Core::delete_cache();
                 Alert::set(Alert::SUCCESS, sprintf(__('Field %s edited'), $name));
             } else {
                 Alert::set(Alert::ERROR, sprintf(__('Field %s cannot be edited'), $name));
             }
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
     }
     $this->template->content = View::factory('oc-panel/pages/fields/update', array('field_data' => $field_data, 'name' => $name, 'categories' => $categories));
 }
Exemple #2
0
 public function action_update()
 {
     $name = $this->request->param('id');
     $field = new Model_Field();
     $field_data = $field->get($name);
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit') . ' ' . $name));
     $this->template->title = __('Edit Custom Field for Advertisement');
     //find all, for populating form select fields
     list($categories) = Model_Category::get_all();
     if ($_POST) {
         try {
             $options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE);
             if ($field->update($name, Core::post('values'), Core::post('categories'), $options)) {
                 Cache::instance()->delete_all();
                 Theme::delete_minified();
                 Alert::set(Alert::SUCCESS, __('Field edited ' . $name));
                 Request::current()->redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
             } else {
                 Alert::set(Alert::ERROR, __('Field cant be edited' . $name));
             }
         } catch (Exception $e) {
             throw new HTTP_Exception_500();
         }
     }
     $this->template->content = View::factory('oc-panel/pages/fields/update', array('field_data' => $field_data, 'name' => $name, 'categories' => $categories));
 }
Exemple #3
0
 /**
  * remove category from custom field
  * @return void 
  */
 public function action_remove_category()
 {
     if (Core::get('id_category')) {
         $name = $this->request->param('id');
         $field = new Model_Field();
         $field_data = $field->get($name);
         $category = new Model_Category(Core::get('id_category'));
         // category or custom field not found
         if (!$category->loaded() or !$field_data) {
             $this->redirect(Route::get('oc-panel')->uri(array('controller' => Request::current()->controller(), 'action' => 'index')));
         }
         // remove current category from custom field categories
         if (is_array($field_data['categories']) and ($key = array_search($category->id_category, $field_data['categories'])) !== FALSE) {
             unset($field_data['categories'][$key]);
         }
         try {
             // update custom field categories
             if ($field->update($name, $field_data['values'], $field_data['categories'], $field_data)) {
                 Core::delete_cache();
                 Alert::set(Alert::SUCCESS, sprintf(__('Field %s removed'), $name));
             } else {
                 Alert::set(Alert::ERROR, sprintf(__('Field %s cannot be removed'), $name));
             }
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         $this->redirect(Route::get('oc-panel')->uri(array('controller' => 'category', 'action' => 'update', 'id' => $category->id_category)));
     }
     $this->redirect(Route::get('oc-panel')->uri(array('controller' => Request::current()->controller(), 'action' => 'index')));
 }