Ejemplo n.º 1
0
 /**
  * update account levels
  *
  * @param integer $account_id
  * @param array $data_level
  * @return boolean
  */
 public function updateLevels($account_id = '', $data_level = array())
 {
     // delete not exists level
     $lvls = static::query()->where('account_id', $account_id);
     if ($lvls->count() > 0) {
         foreach ($lvls->get() as $lvl) {
             if (!in_array($lvl->level_group_id, $data_level)) {
                 \DB::delete(static::$_table_name)->where('account_id', $account_id)->where('level_id', $lvl->level_id)->execute();
             }
         }
     }
     unset($lvls, $lvl);
     // update or insert fields
     if (is_array($data_level) && !empty($data_level)) {
         foreach ($data_level as $level_group_id) {
             $result = \DB::select()->from(static::$_table_name)->where('account_id', $account_id)->where('level_group_id', $level_group_id)->execute();
             if (count($result) <= 0) {
                 // not exists, use insert.
                 \DB::insert(static::$_table_name)->set(['account_id' => $account_id, 'level_group_id' => $level_group_id])->execute();
             }
             unset($result);
         }
     }
     // clear cache
     \Extension\Cache::deleteCache('model.accountLevelPermission-checkLevelPermission-' . \Model_Sites::getSiteId(false));
     return true;
 }
Ejemplo n.º 2
0
 /**
  * add login session
  *
  * @param array $data
  */
 public function addLoginSession($data = array())
 {
     if (!isset($data['site_id'])) {
         $site_id = \Model_Sites::getSiteId(false);
     } else {
         $site_id = $data['site_id'];
     }
     unset($data['site_id']);
     // find exists last login on target site id.
     $result = \DB::select()->as_object()->from(static::$_table_name)->where('account_id', $data['account_id'])->where('site_id', $site_id)->execute();
     if (count($result) <= 0) {
         // use insert
         $insert['account_id'] = $data['account_id'];
         $insert['site_id'] = $site_id;
         $insert['account_last_login'] = time();
         $insert['account_last_login_gmt'] = \Extension\Date::localToGmt();
         if (isset($data['session_id'])) {
             $insert['account_online_code'] = $data['session_id'];
         }
         \DB::insert(static::$_table_name)->set($insert)->execute();
         unset($insert);
     } else {
         // use update
         $update['account_last_login'] = time();
         $update['account_last_login_gmt'] = \Extension\Date::localToGmt();
         if (isset($data['session_id'])) {
             $update['account_online_code'] = $data['session_id'];
         }
         \DB::update(static::$_table_name)->where('account_id', $data['account_id'])->where('site_id', $site_id)->set($update)->execute();
         unset($update);
     }
     unset($result, $site_id);
 }
Ejemplo n.º 3
0
/**
 * get admin's avatar picture.
 * 
 * @param integer $account_id
 * @return string return element ready for display avatar.
 */
function getAdminAvatar($account_id)
{
    // set default avatar
    $theme = \Theme::instance();
    $doc_root = str_replace('\\', '/', DOCROOT);
    $default_avatar_getfile = $theme->asset->get_file('default-avatar.jpg', 'img');
    $default_no_avatar = str_replace([$doc_root, \Uri::base()], '', $default_avatar_getfile);
    unset($doc_root, $default_avatar_getfile, $theme);
    if (!is_numeric($account_id) || intval($account_id) === intval(0)) {
        return $default_no_avatar;
    }
    $cache_name = 'public.themes.sys2.getAdminAvatar-' . \Model_Sites::getSiteId(false) . '-' . $account_id;
    $cache_data = \Extension\Cache::getSilence($cache_name);
    if (false === $cache_data) {
        // if never cached or cache expired.
        $result = \DB::select()->as_object()->from('accounts')->where('account_id', $account_id)->execute();
        if (count($result) > 0) {
            $row = $result->current();
            if ($row->account_avatar != null) {
                $return_val = $row->account_avatar;
                \Cache::set($cache_name, $return_val, 86400);
                unset($cache_name);
                return $return_val;
            }
        }
        if (!isset($return_val) || isset($return_val) && $return_val == null) {
            // not found account or not found avatar.
            \Cache::set($cache_name, $default_no_avatar, 86400);
            unset($cache_name);
            return $default_no_avatar;
        }
    }
    unset($cache_name);
    return $cache_data;
}
Ejemplo n.º 4
0
 /**
  * run before initialize the class
  * use this method to set new table prefix with multisite.
  */
 public static function _init()
 {
     // get current site id
     $site_id = \Model_Sites::getSiteId(false);
     if ($site_id != '1') {
         static::$_table_name = $site_id . '_' . static::$_table_name;
     }
 }
Ejemplo n.º 5
0
 /**
  * check cron to run in time
  *
  * @param array $option options avaliable: [name, second_expired, run_timestamp]
  * @param array $callback_function
  * @param array $callback_function_param
  * @return boolean
  */
 public function checkCron(array $option = array(), array $callback_function = array(), $callback_function_param = array())
 {
     // not set option name
     if (!isset($option['name'])) {
         return false;
     }
     // verify second expired.
     if (!isset($option['second_expired'])) {
         $option['second_expired'] = 86400;
     } else {
         $option['second_expired'] = (int) $option['second_expired'];
     }
     // verify run on date/time timestamp is valid and set (if not set, set to null)
     if (!isset($option['run_timestamp']) || isset($option['run_timestamp']) && !\Extension\Date::isValidTimeStamp((string) $option['run_timestamp'])) {
         $option['run_timestamp'] = null;
     }
     // check that both expired and run timestamp has value.
     if ($option['second_expired'] == 0 && $option['run_timestamp'] == null) {
         return false;
     }
     // set callback function param to be array if it is not.
     if (!is_array($callback_function_param)) {
         $callback_function_param = array($callback_function_param);
     }
     // start checking ------------------------------------------------------------------------------------------------
     $run_task = false;
     // run from specific date/time timestamp.
     if ($option['run_timestamp'] != null && $option['run_timestamp'] <= time()) {
         $run_task = true;
     } elseif ($option['second_expired'] > 0) {
         // get cache of this task name
         try {
             // get site id
             $site_id = \Model_Sites::getSiteId(false);
             $cache = \Cache::get('library.webcron-siteid' . $site_id . '-' . $option['name']);
         } catch (\CacheNotFoundException $e) {
             $cache = false;
         }
         // if never cached or cache expired
         if ($cache === false) {
             $run_task = true;
             // get site id
             $site_id = \Model_Sites::getSiteId(false);
             \Cache::set('library.webcron-siteid' . $site_id . '-' . $option['name'], 'done', $option['second_expired']);
         }
     }
     // checked pass, run the task by call to callback function.
     if ($run_task === true) {
         call_user_func_array($callback_function, $callback_function_param);
         return true;
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * register new account
  *
  * @param array $data
  * @param array $data_fields additional fields to store in account_fields table.
  * @return boolean|string return true when completed and return error text when error occured.
  */
 public static function registerAccount($data = array(), $data_fields = array())
 {
     // check required data.
     if (empty($data) || !is_array($data)) {
         return false;
     }
     // get configurations db
     $cfg = \Model_Config::getvalues(array('member_verification', 'member_disallow_username'));
     // verify disallow username.
     if (isset($cfg['member_disallow_username']['value'])) {
         $cfg['member_disallow_username']['value'] = str_replace(', ', ',', $cfg['member_disallow_username']['value']);
         $disallow_usernames = explode(',', $cfg['member_disallow_username']['value']);
         foreach ($disallow_usernames as $disallow_username) {
             if ($data['account_username'] == trim($disallow_username)) {
                 unset($cfg, $disallow_username, $disallow_usernames);
                 return \Lang::get('account_username_disallowed');
             }
         }
     }
     // check duplicate username.
     $query = static::query()->select('account_username')->where('account_username', $data['account_username']);
     if ($query->count() > 0) {
         unset($query);
         return \Lang::get('account_username_already_exists');
     }
     unset($query);
     // check duplicate email.
     $query = static::query()->select('account_email')->where('account_email', $data['account_email']);
     if ($query->count() > 0) {
         unset($query);
         return \Lang::get('account_email_already_exists');
     }
     unset($query);
     if ($cfg['member_verification']['value'] != '0') {
         // admin config need to verify.
         // generate confirm code
         $data['account_confirm_code'] = \Str::random('alnum', 6);
     }
     // send register email
     $send_result = static::instance()->sendRegisterEmail($data);
     if ($send_result !== true) {
         return $send_result;
     }
     unset($send_result);
     $data['account_password'] = static::instance()->hashPassword($data['account_password']);
     $data['account_create'] = time();
     $data['account_create_gmt'] = \Extension\Date::localToGmt();
     if ($cfg['member_verification']['value'] == '0') {
         // admin config to no need to verify.
         $data['account_status'] = '1';
     } else {
         $data['account_status'] = '0';
         if ($cfg['member_verification']['value'] == '2') {
             $data['account_status_text'] = \Lang::get('account_waiting_for_admin_verification');
         } else {
             $data['account_status_text'] = \Lang::get('account_please_confirm_registration_from_your_email');
         }
     }
     // add account to db. ----------------------------------------
     //list($account_id) = \DB::insert(static::$_table_name)->set($data); // query builder style.
     $account = static::forge($data);
     // add level to user for current site.
     $account->account_level[0] = new Model_AccountLevel();
     $account->account_level[0]->level_group_id = 3;
     $account->save();
     $account_id = $account->account_id;
     unset($account);
     // end add account to db -------------------------------------
     // add level to user.
     // loop sites to add level of this user to each site.
     $site_id = \Model_Sites::getSiteId(false);
     $list_site_option['list_for'] = 'admin';
     $list_site_option['unlimit'] = true;
     $sites = \Model_Sites::listSites($list_site_option);
     if (isset($sites['items']) && is_array($sites['items']) && !empty($sites['items'])) {
         foreach ($sites['items'] as $site) {
             if ($site->site_id != $site_id) {
                 if ($site->site_id == '1') {
                     $table_name = 'account_level';
                 } else {
                     $table_name = $site->site_id . '_account_level';
                 }
                 \DB::insert($table_name)->set(array('account_id' => $account_id, 'level_group_id' => '3'))->execute();
             }
         }
     }
     unset($list_site_option, $site, $sites, $site_id, $table_name);
     // add account fields if there is any value.
     // to add account fields data structure shoud be like this...
     // array(array('field_name' => 'website', 'field_value' => 'http://domain.tld'), array('field_name' => 'fb', 'field_value' => 'http://fb.com/myprofile'));
     // or
     // $af[0]['field_name'] = 'website';
     // $af[0]['field_value'] = 'http://domain.tld';
     // $sf[1]['field_name'] = 'fb';
     // $sf[1]['field_value'] = 'http://fb.com/myprofile';
     if (!empty($data_fields) && is_array($data_fields)) {
         foreach ($data_fields as $field) {
             $account_fields = static::forge($field);
             $account_fields->account_id = $account_id;
             $account_fields->save();
         }
         unset($account_fields, $field);
     }
     // @todo [fuelstart][account][plug] account after register plug.
     // after saved newly user data but not confirm (if require confirm).
     $plugin = new \Library\Plugins();
     if ($plugin->hasAction('AccountAfterRegister') !== false) {
         $plugin->doAction('AccountAfterRegister', ['input_data' => $data, 'input_data_fields' => $data_fields, 'inputs_post' => \Input::post()]);
     }
     unset($plugin);
     return true;
 }
Ejemplo n.º 7
0
 /**
  * record login
  * @param integer $account_id
  * @param integer $attempt 0 for failed, 1 for success
  * @param string $attempt_text attempt text
  * @return boolean
  */
 public function recordLogin($account_id = '', $attempt = '0', $attempt_text = '')
 {
     if (!is_numeric($account_id) || !is_numeric($attempt)) {
         return false;
     }
     if ($attempt_text == null) {
         $attempt_text = null;
     }
     $site_id = \Model_Sites::getSiteId(false);
     // get browser class for use instead of fuelphp agent which is does not work.
     include_once APPPATH . 'vendor' . DS . 'browser' . DS . 'lib' . DS . 'Browser.php';
     $browser = new Browser();
     // set data for insertion
     $data['account_id'] = $account_id;
     $data['site_id'] = $site_id;
     $data['login_ua'] = \Input::user_agent();
     $data['login_os'] = $browser->getPlatform();
     $data['login_browser'] = $browser->getBrowser() . ' ' . $browser->getVersion();
     $data['login_ip'] = \Input::real_ip();
     $data['login_time'] = time();
     $data['login_time_gmt'] = \Extension\Date::localToGmt();
     $data['login_attempt'] = $attempt;
     $data['login_attempt_text'] = $attempt_text;
     \DB::insert(static::$_table_name)->set($data)->execute();
     unset($browser, $data, $site_id);
     return true;
 }
Ejemplo n.º 8
0
 public function action_multiple()
 {
     $ids = \Input::post('id');
     $act = trim(\Input::post('act'));
     $redirect = $this->getAndSetSubmitRedirection();
     if (\Extension\NoCsrf::check()) {
         // if action is delete.
         if ($act == 'del') {
             // check permission.
             if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_delete_perm') == false) {
                 \Response::redirect($redirect);
             }
             if (is_array($ids)) {
                 foreach ($ids as $id) {
                     // get target level group id
                     $lvls = \DB::select()->as_object()->from(\Model_AccountLevel::getTableName())->where('account_id', $id)->execute();
                     // not found
                     if (count($lvls) <= 0) {
                         continue;
                     } else {
                         // format level group for check can i add, edit
                         $level_group = array();
                         foreach ($lvls as $lvl) {
                             $level_group[] = $lvl->level_group_id;
                         }
                     }
                     if (\Model_Accounts::forge()->canIAddEditAccount($level_group) == true) {
                         // delete account.
                         \Model_Accounts::deleteAccount($id);
                         // clear cache
                         \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $id);
                     }
                 }
             }
         } elseif ($act == 'enable') {
             // check permission.
             if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_delete_perm') == false) {
                 \Response::redirect($redirect);
             }
             if (is_array($ids)) {
                 foreach ($ids as $id) {
                     if ($id == '0') {
                         continue;
                     }
                     // get target level group id
                     $lvls = \DB::select()->as_object()->from(\Model_AccountLevel::getTableName())->where('account_id', $id)->execute();
                     // not found
                     if (count($lvls) <= 0) {
                         continue;
                     } else {
                         // format level group for check can i add, edit
                         $level_group = array();
                         foreach ($lvls as $lvl) {
                             $level_group[] = $lvl->level_group_id;
                         }
                     }
                     if (\Model_Accounts::forge()->canIAddEditAccount($level_group) == true) {
                         \DB::update(\Model_Accounts::getTableName())->where('account_id', $id)->set(['account_status' => '1', 'account_status_text' => null])->execute();
                         unset($entry);
                     }
                     // clear cache
                     \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $id);
                 }
             }
         } elseif ($act == 'disable') {
             // check permission.
             if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_delete_perm') == false) {
                 \Response::redirect($redirect);
             }
             if (is_array($ids)) {
                 foreach ($ids as $id) {
                     if ($id == '0') {
                         continue;
                     }
                     // get target level group id
                     $lvls = \DB::select()->as_object()->from(\Model_AccountLevel::getTableName())->where('account_id', $id)->execute();
                     // not found
                     if (count($lvls) <= 0) {
                         continue;
                     } else {
                         // format level group for check can i add, edit
                         $level_group = array();
                         foreach ($lvls as $lvl) {
                             $level_group[] = $lvl->level_group_id;
                         }
                     }
                     if (\Model_Accounts::forge()->canIAddEditAccount($level_group) == true) {
                         \DB::update(\Model_Accounts::getTableName())->where('account_id', $id)->set(['account_status' => '0', 'account_status_text' => null])->execute();
                     }
                     // clear cache
                     \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $id);
                 }
             }
         }
     }
     // go back
     \Response::redirect($redirect);
 }
Ejemplo n.º 9
0
 /**
  * get highest priority level of selected user.
  * 
  * @param integer $account_id account id.
  * @return mixed return object when found, return false when not found
  */
 public static function getHighestPriorityAccountLevel($account_id = '')
 {
     // get site id and set table prefix for site
     $site_id = \Model_Sites::getSiteId(false);
     $table_site_prefix = '';
     if ($site_id != '1') {
         $table_site_prefix = $site_id . '_';
     }
     unset($site_id);
     $query = \DB::select()->from($table_site_prefix . 'account_level')->as_object('\\Model_AccountLevel')->join($table_site_prefix . 'account_level_group', 'LEFT')->on($table_site_prefix . 'account_level_group.level_group_id', '=', $table_site_prefix . 'account_level.level_group_id')->where('account_id', $account_id)->order_by('level_priority', 'ASC')->execute();
     if ($query == null || $query->count() == '0') {
         return false;
     }
     $entry = $query->current();
     unset($query);
     return $entry;
 }
Ejemplo n.º 10
0
 /**
  * save
  *
  * @param array $data
  * @return boolean
  */
 public static function saveData(array $data = array())
 {
     if (empty($data)) {
         return false;
     }
     foreach ($data as $key => $value) {
         \DB::update(static::$_table_name)->value('config_value', $value)->where('config_name', $key)->execute();
     }
     // clear cache
     \Extension\Cache::deleteCache('model.config-getval-' . \Model_Sites::getSiteId(false));
     \Extension\Cache::deleteCache('model.config-getvalues-' . \Model_Sites::getSiteId(false));
     return true;
 }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
 /**
  * save permissions
  *
  * @param array $data
  * @return boolean
  */
 public static function savePermissions(array $data = array())
 {
     // loop check permission is not in db, insert it.
     foreach ($data['level_group_id'] as $key => $lv_groups) {
         foreach ($lv_groups as $level_group_id) {
             // check if permission is in db or not.
             $result = \DB::select()->from(static::$_table_name)->where('level_group_id', $level_group_id)->where('permission_page', $data['permission_page'][$key])->where('permission_action', $data['permission_action'][$key])->execute();
             if (count($result) <= 0) {
                 // not in db. insert it.
                 \DB::insert(static::$_table_name)->set(['level_group_id' => $level_group_id, 'permission_core' => $data['permission_core'], 'module_system_name' => $data['module_system_name'], 'permission_page' => $data['permission_page'][$key], 'permission_action' => $data['permission_action'][$key]])->execute();
             }
         }
     }
     // clear unused variables
     unset($key, $level_group_id, $lv_groups, $result);
     // now remove permission in db that was not checked.
     foreach ($data['permission_action'] as $key => $permission_action) {
         if (isset($data['permission_page'][$key])) {
             $result = \DB::select()->as_object()->from(static::$_table_name)->where('permission_core', $data['permission_core'])->where('module_system_name', $data['module_system_name'])->where('permission_page', $data['permission_page'][$key])->where('permission_action', $permission_action)->execute();
             if (count($result) > 0) {
                 foreach ($result as $row) {
                     if (isset($data['level_group_id'][$key])) {
                         if (!in_array($row->level_group_id, $data['level_group_id'][$key])) {
                             \DB::delete(static::$_table_name)->where('permission_id', $row->permission_id)->execute();
                         }
                     } else {
                         \DB::delete(static::$_table_name)->where('permission_id', $row->permission_id)->execute();
                     }
                 }
             }
         }
     }
     // clear unused variables
     unset($key, $permission_action, $result, $row);
     $data = array();
     // clear cache
     \Extension\Cache::deleteCache('model.accountLevelPermission-checkLevelPermission-' . \Model_Sites::getSiteId(false));
     return true;
 }
Ejemplo n.º 13
0
 public function action_index()
 {
     // is user logged in?
     if (\Model_Accounts::isMemberLogin() == false) {
         \Response::redirect(\Uri::create('account/login') . '?rdr=' . urlencode(\Uri::main()));
     }
     // load language
     \Lang::load('account');
     \Lang::load('accountlogins');
     // get account id
     $cookie_account = \Model_Accounts::forge()->getAccountCookie();
     // get account data
     $row = \Model_Accounts::find($cookie_account['account_id']);
     if ($row == null) {
         // not found user data.
         unset($row);
         \Response::redirect(\Uri::main());
     }
     $output['account'] = $row;
     // set sort variable for sortable in views.
     $next_sort = \Security::strip_tags(trim(\Input::get('sort')));
     if ($next_sort == null || $next_sort == 'DESC') {
         $next_sort = 'ASC';
     } else {
         $next_sort = 'DESC';
     }
     $output['next_sort'] = $next_sort;
     unset($next_sort);
     // list logins -----------------------------------------------------------------------------------------------------
     $option['limit'] = \Model_Config::getval('content_items_perpage');
     $option['offset'] = trim(\Input::get('page')) != null ? ((int) \Input::get('page') - 1) * $option['limit'] : 0;
     if (\Security::strip_tags(trim(\Input::get('orders'))) != null) {
         $option['orders'] = \Security::strip_tags(trim(\Input::get('orders')));
     }
     if (\Security::strip_tags(trim(\Input::get('sort'))) != null) {
         $option['sort'] = \Security::strip_tags(trim(\Input::get('sort')));
     }
     $data['account_id'] = $cookie_account['account_id'];
     $data['site_id'] = \Model_Sites::getSiteId();
     $list_logins = \Model_AccountLogins::listLogins($data, $option);
     // pagination config
     $config['pagination_url'] = \Uri::main() . \Uri::getCurrentQuerystrings(true, true, false);
     $config['total_items'] = $list_logins['total'];
     $config['per_page'] = $option['limit'];
     $config['uri_segment'] = 'page';
     $config['num_links'] = 3;
     $config['show_first'] = true;
     $config['show_last'] = true;
     $config['first-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>";
     $config['first-inactive-link'] = '<a href="#">{page}</a>';
     $config['first-marker'] = '&laquo;';
     $config['last-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>";
     $config['last-inactive-link'] = '<a href="#">{page}</a>';
     $config['last-marker'] = '&raquo;';
     $config['previous-marker'] = '&lsaquo;';
     $config['next-marker'] = '&rsaquo;';
     $pagination = \Pagination::forge('viewlogins_pagination', $config);
     $output['list_logins'] = $list_logins;
     $output['pagination'] = $pagination;
     unset($config, $data, $list_logins, $option, $pagination);
     // <head> output ----------------------------------------------------------------------------------------------
     $output['page_title'] = $this->generateTitle(\Lang::get('account_login_history'));
     // <head> output ----------------------------------------------------------------------------------------------
     return $this->generatePage('front/templates/account/viewlogins_v', $output, false);
 }