public static function run() { // create permission table. (user's permission) $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('account_permission') . "` (\n `permission_id` int(11) NOT NULL AUTO_INCREMENT,\n `account_id` int(11) NOT NULL COMMENT 'refer to accounts.account_id',\n `permission_core` int(1) NOT NULL DEFAULT '0' COMMENT '1=core permission, 0=modules permission',\n `module_system_name` varchar(255) DEFAULT NULL COMMENT 'module system name',\n `permission_page` varchar(255) NOT NULL,\n `permission_action` varchar(255) DEFAULT NULL,\n PRIMARY KEY (`permission_id`),\n KEY `account_id` (`account_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='contain user''s permission for each admin page and action.' AUTO_INCREMENT=1 ;"; \DB::query($sql)->execute(); unset($sql); // loop sites to create permission table. $sites = \Model_Sites::find('all'); if ($sites != null) { foreach ($sites as $row) { $table_name = 'account_permission'; if ($row->site_id != '1') { $table_name = $row->site_id . '_' . $table_name; } if (!\DBUtil::table_exists($table_name)) { $sql = 'CREATE TABLE IF NOT EXISTS ' . \DB::table_prefix($table_name) . ' LIKE ' . \DB::table_prefix('account_permission'); \DB::query($sql)->execute(); unset($sql); } } } unset($row, $sites); return true; }
public function action_index() { // check permission if (\Model_AccountLevelPermission::checkAdminPermission('config_global', 'config_global') == false) { \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string())))); \Response::redirect(\Uri::create('admin')); } // get timezone list for select box \Config::load('timezone', 'timezone'); $output['timezone_list'] = \Config::get('timezone.timezone', array()); // 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); $allowed_field = array(); // load config to form. $result = \DB::select('*')->from(\Model_Config::getTableName())->as_object('Model_Config')->where('config_core', '1')->execute(); if ((is_array($result) || is_object($result)) && !empty($result)) { foreach ($result as $row) { $allowed_field[] = $row->config_name; $output[$row->config_name] = $row->config_value; } } unset($result, $row); // if form submitted if (\Input::method() == 'POST') { // store data to variable for update to db. $data = array(); foreach (\Input::post() as $key => $value) { if (in_array($key, $allowed_field)) { $data[$key] = $value; } } unset($allowed_field); // check again for some required default value config data. // tab website $data['site_name'] = \Security::htmlentities($data['site_name']); $data['page_title_separator'] = \Security::htmlentities($data['page_title_separator']); // tab account if (!isset($data['member_allow_register']) || $data['member_allow_register'] != '1') { $data['member_allow_register'] = '0'; } if (!isset($data['member_register_notify_admin']) || $data['member_register_notify_admin'] != '1') { $data['member_register_notify_admin'] = '0'; } if (!isset($data['simultaneous_login']) || $data['simultaneous_login'] != '1') { $data['simultaneous_login'] = '******'; } if (!is_numeric($data['member_max_login_fail'])) { $data['member_max_login_fail'] = '10'; } if (!is_numeric($data['member_login_fail_wait_time'])) { $data['member_login_fail_wait_time'] = '30'; } if (!is_numeric($data['member_login_remember_length'])) { $data['member_login_remember_length'] = '30'; } if (!is_numeric($data['member_confirm_wait_time'])) { $data['member_confirm_wait_time'] = '10'; } if (!isset($data['member_email_change_need_confirm']) || $data['member_email_change_need_confirm'] != '1') { $data['member_email_change_need_confirm'] = '0'; } if (!isset($data['allow_avatar']) || $data['allow_avatar'] != '1') { $data['allow_avatar'] = '0'; } if (!is_numeric($data['avatar_size'])) { $data['avatar_size'] = '200'; } if (empty($data['avatar_allowed_types'])) { $data['avatar_allowed_types'] = 'jpg|jpeg'; } if ($data['avatar_path'] == null) { unset($data['avatar_path']); } // tab email if ($data['mail_protocol'] == null) { $data['mail_protocol'] = 'mail'; } if (!is_numeric($data['mail_smtp_port'])) { $data['mail_smtp_port'] = '0'; } // tab content if (!is_numeric($data['content_items_perpage'])) { $data['content_items_perpage'] = '10'; } if (!is_numeric($data['content_admin_items_perpage'])) { $data['content_admin_items_perpage'] = '10'; } // tab media if (empty($data['media_allowed_types'])) { $data['media_allowed_types'] = 'avi|doc|docx|flv|gif|jpeg|jpg|mid|midi|mov|mp3|mpeg|mpg|pdf|png|swf|xls|xlsx|zip'; } // tab ftp if (!is_numeric($data['ftp_port'])) { $data['ftp_port'] = '21'; } if (!isset($data['ftp_passive']) || $data['ftp_passive'] != 'false') { $data['ftp_passive'] = 'true'; } // validate form. $validate = \Validation::forge(); 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 { // try to save config. $result = \Model_Config::saveData($data); // save change site name to sites table $site_id = \Model_Sites::getSiteId(false); $entry = \Model_Sites::find($site_id); $entry->site_name = $data['site_name']; $entry->save(); unset($entry, $site_id); if ($result === true) { \Session::set_flash('form_status', array('form_status' => 'success', 'form_status_message' => \Lang::get('admin_saved'))); \Response::redirect(\Uri::main()); } else { $output['form_status'] = 'error'; $output['form_status_message'] = $result; } } // re-populate form. foreach ($data as $key => $value) { $output[$key] = html_entity_decode($value); } } // <head> output ---------------------------------------------------------------------------------------------- $output['page_title'] = $this->generateTitle(\Lang::get('config_global_configuration')); // <head> output ---------------------------------------------------------------------------------------------- // breadcrumb ------------------------------------------------------------------------------------------------- $page_breadcrumb = []; $page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')]; $page_breadcrumb[1] = ['name' => \Lang::get('config_global_configuration'), 'url' => \Uri::create('admin/config')]; $output['page_breadcrumb'] = $page_breadcrumb; unset($page_breadcrumb); // breadcrumb ------------------------------------------------------------------------------------------------- return $this->generatePage('admin/templates/config/index_v', $output, false); }
public function action_edit($site_id = '') { // set redirect url $redirect = $this->getAndSetSubmitRedirection(); // check permission if (\Model_AccountLevelPermission::checkAdminPermission('siteman_perm', 'siteman_edit_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); // get selected site data $row = \Model_Sites::find($site_id); $output['site_id'] = $site_id; if ($row == null) { // not found selected site data. unset($output, $row); \Response::redirect($redirect); } // loop set form field. foreach ($row as $key => $value) { $output[$key] = $value; } // if form submitted if (\Input::method() == 'POST') { // store data for save $data['site_id'] = $site_id; $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')); 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::editSite($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('admin_saved'))); } \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_edit'), 'url' => \Uri::main()]; $output['page_breadcrumb'] = $page_breadcrumb; unset($page_breadcrumb); // breadcrumb ------------------------------------------------------------------------------------------------- return $this->generatePage('admin/templates/siteman/form_v', $output, false); }