/**
  * Main function that calls others
  *
  * @return bool
  */
 public function settings($h)
 {
     if ($h->cage->get->testPage('subpage') == 'default_perms' || $h->cage->post->testPage('subpage') == 'default_perms') {
         $this->defaultPerms($h);
         return true;
     }
     if ($h->cage->get->testPage('subpage') == 'default_settings' || $h->cage->post->testPage('subpage') == 'default_settings') {
         $this->defaultSettings($h);
         return true;
     }
     if ($h->cage->get->testPage('subpage') == 'add_user' || $h->cage->post->testPage('subpage') == 'add_user') {
         $this->addUserPage($h);
         return true;
     }
     // grab the number of pending users:
     $sql = "SELECT COUNT(user_id) FROM " . TABLE_USERS . " WHERE user_role = %s";
     $num_pending = $h->db->get_var($h->db->prepare($sql, 'pending'));
     if (!$num_pending) {
         $num_pending = "0";
     }
     $h->vars['num_pending'] = $num_pending;
     // check if all new users are automatically set to pending or not
     $user_signin_settings = $h->getSerializedSettings('user_signin');
     $h->vars['regStatus'] = $user_signin_settings['registration_status'];
     $h->vars['useEmailConf'] = $user_signin_settings['emailconf_enabled'];
     // clear variables:
     $h->vars['search_term'] = '';
     if ($h->vars['regStatus'] == 'pending') {
         $h->vars['user_filter'] = 'pending';
     } else {
         $h->vars['user_filter'] = 'all';
     }
     // Get unique statuses for Filter form:
     $h->vars['roles'] = $h->getUniqueRoles();
     $u = new UserBase();
     // if checkboxes
     if ($h->cage->get->getAlpha('type') == 'checkboxes' && $h->cage->get->keyExists('user_man')) {
         foreach ($h->cage->get->keyExists('user_man') as $id => $checked) {
             $h->message = $h->lang["user_man_checkboxes_role_changed"];
             // default "Changed role" message
             $u->id = $id;
             $u->getUserBasic($h, $id);
             $new_role = $h->cage->get->testAlnumLines('checkbox_action');
             if ($new_role != $u->role) {
                 // change role:
                 $u->role = $new_role;
                 $new_perms = $u->getDefaultPermissions($h, $new_role);
                 $u->setAllPermissions($new_perms);
                 $u->updatePermissions($h);
                 $u->updateUserBasic($h, $id);
                 $h->message = $h->lang["user_man_checkboxes_role_changed"];
                 if ($new_role == 'killspammed' || $new_role == 'deleted') {
                     $h->deleteComments($u->id);
                     // includes child comments from *other* users
                     $h->deletePosts($u->id);
                     // includes tags and votes for self-submitted posts
                     if ($h->cage->get->keyExists('addblockedlist')) {
                         $h->addToBlockedList($type = 'user', $value = $u->name, false);
                         $h->addToBlockedList($type = 'email', $value = $u->email, false);
                     }
                     $h->pluginHook('user_man_killspam_delete', '', array($u));
                     if ($new_role == 'deleted') {
                         $u->deleteUser($h);
                         $h->clearCache('db_cache', false);
                         // clears them from User Manager list
                     }
                 }
             }
         }
     }
     // if search
     $search_term = '';
     if ($h->cage->get->getAlpha('type') == 'search') {
         $search_term = $h->cage->get->sanitizeTags('search_value');
         if (strlen($search_term) < 3) {
             $h->message = $h->lang["user_man_search_too_short"];
             $h->messageType = 'red';
         } else {
             $h->vars['search_term'] = $search_term;
             // used to refill the search box after a search
             $where_clause = " WHERE user_username LIKE %s OR user_email LIKE %s";
             $sort_clause = ' ORDER BY user_date DESC';
             // ordered by registration date
             $search_term = '%' . $search_term . '%';
             $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
             $count = $h->db->get_var($h->db->prepare($count_sql, $search_term, $search_term));
             $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
             $query = $h->db->prepare($sql, $search_term, $search_term);
         }
     }
     // if filter
     $filter = '';
     if ($h->cage->get->getAlpha('type') == 'filter') {
         $filter = $h->cage->get->testAlnumLines('user_filter');
         $h->vars['user_filter'] = $filter;
         // used to refill the filter box after use
         switch ($filter) {
             case 'all':
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql));
                 $sql = "SELECT * FROM " . TABLE_USERS . $sort_clause;
                 $query = $h->db->prepare($sql);
                 break;
             case 'not_killspammed':
                 $where_clause = " WHERE user_role != %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'killspammed'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'killspammed');
                 break;
             case 'admin':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'admin'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'admin');
                 break;
             case 'supermod':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'supermod'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'supermod');
                 break;
             case 'moderator':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'moderator'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'moderator');
                 break;
             case 'member':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'member'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'member');
                 break;
             case 'pending':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'pending'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'pending');
                 break;
             case 'undermod':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'undermod'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'undermod');
                 break;
             case 'suspended':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'suspended'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'suspended');
                 break;
             case 'banned':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'banned'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'banned');
                 break;
             case 'killspammed':
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered by registration date
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'killspammed'));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'killspammed');
                 break;
             case 'newest':
                 $sort_clause = ' ORDER BY user_date DESC';
                 // same as "all"
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS;
                 $count = $h->db->get_var($h->db->prepare($count_sql));
                 $sql = "SELECT * FROM " . TABLE_USERS . $sort_clause;
                 $query = $h->db->prepare($sql);
                 break;
             case 'oldest':
                 $sort_clause = ' ORDER BY user_date ASC';
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS;
                 $count = $h->db->get_var($h->db->prepare($count_sql));
                 $sql = "SELECT * FROM " . TABLE_USERS . $sort_clause;
                 $query = $h->db->prepare($sql);
                 break;
             case 'last_visited':
                 $sort_clause = ' ORDER BY user_lastvisit DESC';
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS;
                 $count = $h->db->get_var($h->db->prepare($count_sql));
                 $sql = "SELECT * FROM " . TABLE_USERS . $sort_clause;
                 $query = $h->db->prepare($sql);
                 break;
             default:
                 $where_clause = " WHERE user_role = %s";
                 $sort_clause = ' ORDER BY user_date DESC';
                 // ordered newest first for convenience
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, $filter));
                 $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, $filter);
                 // filter = 'admin', 'member', etc.
                 break;
         }
     }
     if (!isset($query)) {
         // default list
         // if all new users are set to 'pending' show pending list as default...
         if ($h->vars['regStatus'] == 'pending') {
             $where_clause = " WHERE user_role = %s";
             $sort_clause = ' ORDER BY user_date DESC';
             $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $where_clause . $sort_clause;
             $count = $h->db->get_var($h->db->prepare($count_sql, 'pending'));
             $sql = "SELECT * FROM " . TABLE_USERS . $where_clause . $sort_clause;
             $query = $h->db->prepare($sql, 'pending');
         } else {
             $sort_clause = ' ORDER BY user_date DESC';
             // ordered by newest
             $count_sql = "SELECT count(*) AS number FROM " . TABLE_USERS . $sort_clause;
             $count = $h->db->get_var($h->db->prepare($count_sql));
             $sql = "SELECT * FROM " . TABLE_USERS . $sort_clause;
             $query = $h->db->prepare($sql);
         }
     }
     $pagedResults = $h->pagination($query, $count, 30, 'users');
     if ($pagedResults) {
         $h->vars['user_man_rows'] = $this->drawRows($h, $pagedResults, $filter, $search_term);
     } elseif ($h->vars['user_filter'] == 'pending') {
         $h->message = $h->lang['user_man_no_pending_users'];
         $h->messageType = 'green';
     }
     // Show template:
     $h->displayTemplate('user_man_main', 'user_manager');
 }
Exemplo n.º 2
0
 /**
  * Physically delete a user
  * Note: You should delete all their posts, comments, etc. first
  *
  * @param int $user_id (optional)
  */
 public function deleteUser($user_id = 0)
 {
     $userbase = new UserBase();
     return $userbase->deleteUser($this, $user_id);
 }