예제 #1
0
 public function action_new()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('New field')));
     $this->template->title = __('New Custom Field for Users');
     if ($_POST) {
         if (count(Model_UserField::get_all(FALSE)) > 65) {
             Alert::set(Alert::ERROR, __('You have reached the maximum number of custom fields allowed.'));
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'userfields', 'action' => 'index')));
         }
         $name = URL::title(Core::post('name'));
         if (strlen($name) >= 60) {
             $name = Text::limit_chars($name, 60, '');
         }
         $field = new Model_UserField();
         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, 'show_profile' => Core::post('show_profile') == 'on' ? TRUE : FALSE, 'show_register' => Core::post('show_register') == 'on' ? TRUE : FALSE, 'admin_privilege' => Core::post('admin_privilege') == 'on' ? TRUE : FALSE);
             if ($field->create($name, Core::post('type'), Core::post('values'), $options)) {
                 Core::delete_cache();
                 Alert::set(Alert::SUCCESS, sprintf(__('Field %s created'), $name));
             } else {
                 Alert::set(Alert::ERROR, sprintf(__('Field %s already exists'), $name));
             }
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'userfields', 'action' => 'index')));
     }
     $this->template->content = View::factory('oc-panel/pages/userfields/new');
 }