Exemple #1
0
 /**
  * Bulk User Role Change
  *
  * @param string $from name of role to move from
  * @param string $to name of role to move to
  * @return bool
  */
 public function bulkRoleChange($h, $from = '', $to = '')
 {
     if (!$from || !$to) {
         return false;
     }
     // check $from and $to exist
     $unique_roles = $this->getUniqueRoles($h);
     if (!in_array($from, $unique_roles)) {
         return false;
     }
     if (!in_array($to, $unique_roles)) {
         return false;
     }
     $sql = "SELECT user_id FROM " . TABLE_USERS . " WHERE user_role = %s";
     $items = $h->db->get_results($h->db->prepare($sql, $from));
     if ($items) {
         // Change role and permissions for each user being moved
         foreach ($items as $item) {
             $user = new UserAuth();
             $user->getUser($h, $item->user_id);
             $user->role = $to;
             $new_perms = $user->getDefaultPermissions($h, $user->role);
             $user->setAllPermissions($new_perms);
             $user->updateUserBasic($h);
         }
     }
     return true;
 }
 /**
  * Check email confirmation code
  *
  * @return true;
  */
 public function checkEmailConfirmation($h)
 {
     $user_id = $h->cage->get->getInt('id');
     $conf = $h->cage->get->getAlnum('conf');
     $user = new UserAuth();
     $user->getUserBasic($h, $user_id);
     if (!$user_id || !$conf) {
         $h->messages[$h->lang['user_signin_register_emailconf_fail']] = 'red';
     }
     $sql = "SELECT user_email_conf FROM " . TABLE_USERS . " WHERE user_id = %d";
     $user_email_conf = $h->db->get_var($h->db->prepare($sql, $user_id));
     if ($conf === $user_email_conf) {
         // update role:
         $user->role = $h->vars['regStatus'];
         $h->pluginHook('user_signin_email_conf_post_role');
         // update user with new permissions:
         $new_perms = $user->getDefaultPermissions($h, $user->role);
         unset($new_perms['options']);
         // don't need this for individual users
         $user->setAllPermissions($new_perms);
         $user->updatePermissions($h);
         $user->updateUserBasic($h);
         // set email valid to 1:
         $sql = "UPDATE " . TABLE_USERS . " SET user_email_valid = %d WHERE user_id = %d";
         $h->db->query($h->db->prepare($sql, 1, $user->id));
         // notify chosen mods of new user by email:
         if ($h->vars['useEmailNotify'] == 'checked' && file_exists(PLUGINS . 'users/libs/UserFunctions.php')) {
             require_once PLUGINS . 'users/libs/UserFunctions.php';
             $uf = new UserFunctions();
             $uf->notifyMods($h, 'user', $user->role, $user->id);
         }
         $success_message = $h->lang['user_signin_register_emailconf_success'] . " <br /><b><a href='" . $h->url(array('page' => 'login')) . "'>" . $h->lang['user_signin_register_emailconf_success_login'] . "</a></b>";
         $h->messages[$success_message] = 'green';
     } else {
         $h->messages[$h->lang['user_signin_register_emailconf_fail']] = 'red';
     }
     return true;
 }