Exemplo n.º 1
0
 public function action_add()
 {
     // set redirect url
     $redirect = $this->getAndSetSubmitRedirection();
     // check permission
     if (\Model_AccountLevelPermission::checkAdminPermission('siteman_perm', 'siteman_add_perm') == false) {
         \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string()))));
         \Response::redirect($redirect);
     }
     // read flash message for display errors.
     $form_status = \Session::get_flash('form_status');
     if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) {
         $output['form_status'] = $form_status['form_status'];
         $output['form_status_message'] = $form_status['form_status_message'];
     }
     unset($form_status);
     // set default form value
     $output['site_status'] = '1';
     // if form submitted
     if (\Input::method() == 'POST') {
         // store data for save
         $data['site_name'] = \Security::htmlentities(trim(\Input::post('site_name')));
         $data['site_domain'] = str_replace(array('http://', '/'), '', mb_strtolower(\Security::strip_tags(trim(\Input::post('site_domain')))));
         $data['site_status'] = (int) trim(\Input::post('site_status'));
         $validate = \Validation::forge();
         $validate->add_callable(new \Extension\FsValidate());
         $validate->add('site_name', \Lang::get('siteman_site_name'), array(), array('required'));
         $validate->add('site_domain', \Lang::get('siteman_site_domain'), array(), array('required'))->add_rule('uniqueDB', 'sites.site_domain');
         if (!\Extension\NoCsrf::check()) {
             // validate token failed
             $output['form_status'] = 'error';
             $output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token');
         } elseif (!$validate->run()) {
             // validate failed
             $output['form_status'] = 'error';
             $output['form_status_message'] = $validate->show_errors();
         } else {
             // save
             $result = \Model_Sites::addSite($data);
             if ($result === true) {
                 if (\Session::get_flash('form_status', null, false) == null) {
                     \Session::set_flash('form_status', array('form_status' => 'success', 'form_status_message' => \Lang::get('siteman_added_please_login_to_new_site_and_go_config_user_roles_and_permission')));
                 }
                 \Response::redirect($redirect);
             } else {
                 $output['form_status'] = 'error';
                 $output['form_status_message'] = $result;
             }
         }
         // re-populate form
         $output['site_name'] = \Input::post('site_name');
         $output['site_domain'] = \Input::post('site_domain');
         $output['site_status'] = \Input::post('site_status');
     }
     // <head> output ----------------------------------------------------------------------------------------------
     $output['page_title'] = $this->generateTitle(\Lang::get('siteman_multisite_manager'));
     // <head> output ----------------------------------------------------------------------------------------------
     // breadcrumb -------------------------------------------------------------------------------------------------
     $page_breadcrumb = [];
     $page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')];
     $page_breadcrumb[1] = ['name' => \Lang::get('siteman_multisite_manager'), 'url' => \Uri::create('admin/siteman')];
     $page_breadcrumb[2] = ['name' => \Lang::get('siteman_add'), 'url' => \Uri::main()];
     $output['page_breadcrumb'] = $page_breadcrumb;
     unset($page_breadcrumb);
     // breadcrumb -------------------------------------------------------------------------------------------------
     return $this->generatePage('admin/templates/siteman/form_v', $output, false);
 }