diff --git a/include/class.user.php b/include/class.user.php index a845455e6b9df52da4bb44b5bfcd9ed42b7ebf32..9a22b39616ba35dceb755633773a25133fe76615 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -243,13 +243,7 @@ class User extends UserModel { if (!($account=$this->getAccount())) return 'Guest'; - if ($account->isLocked()) - return 'Locked (Administrative)'; - - if (!$account->isConfirmed()) - return 'Locked (Pending Activation)'; - - return 'Active'; + return (string) $account->getStatus(); } function register($vars, &$errors) { @@ -546,13 +540,14 @@ class UserAccountModel extends VerySimpleModel { ), ); - const CONFIRMED = 0x0001; - const LOCKED = 0x0002; - const REQUIRE_PASSWD_RESET = 0x0004; - const FORBID_PASSWD_RESET = 0x0008; + var $_status; + + function __onload() { + $this->_status = new UserAccountStatus($this->get('status')); + } protected function hasStatus($flag) { - return 0 !== ($this->get('status') & $flag); + return $this->_status->check($flag); } protected function clearStatus($flag) { @@ -564,38 +559,38 @@ class UserAccountModel extends VerySimpleModel { } function confirm() { - $this->setStatus(self::CONFIRMED); + $this->setStatus(UserAccountStatus::CONFIRMED); return $this->save(); } function isConfirmed() { - return $this->hasStatus(self::CONFIRMED); + return $this->_status->isConfirmed(); } function lock() { - $this->setStatus(self::LOCKED); + $this->setStatus(UserAccountStatus::LOCKED); $this->save(); } function isLocked() { - return $this->hasStatus(self::LOCKED); + return $this->_status->isLocked(); } function forcePasswdReset() { - $this->setStatus(self::REQUIRE_PASSWD_RESET); + $this->setStatus(UserAccountStatus::REQUIRE_PASSWD_RESET); return $this->save(); } function isPasswdResetForced() { - return $this->hasStatus(self::REQUIRE_PASSWD_RESET); + return $this->hasStatus(UserAccountStatus::REQUIRE_PASSWD_RESET); } function isPasswdResetEnabled() { - return !$this->hasStatus(self::FORBID_PASSWD_RESET); + return !$this->hasStatus(UserAccountStatus::FORBID_PASSWD_RESET); } function getStatus() { - return $this->get('status'); + return $this->_status; } function getInfo() { @@ -733,14 +728,14 @@ class UserAccount extends UserAccountModel { if ($vars['passwd1']) { $this->set('passwd', Passwd::hash($vars['passwd'])); - $this->setStatus(self::CONFIRMED); + $this->setStatus(UserAccountStatus::CONFIRMED); } // Set flags foreach (array( - 'pwreset-flag'=> self::REQUIRE_PASSWD_RESET, - 'locked-flag'=> self::LOCKED, - 'forbid-pwchange-flag'=> self::FORBID_PASSWD_RESET + 'pwreset-flag' => UserAccountStatus::REQUIRE_PASSWD_RESET, + 'locked-flag' => UserAccountStatus::LOCKED, + 'forbid-pwchange-flag' => UserAccountStatus::FORBID_PASSWD_RESET ) as $ck=>$flag) { if ($vars[$ck]) $this->setStatus($flag); @@ -795,11 +790,11 @@ class UserAccount extends UserAccountModel { if ($vars['passwd1'] && !$vars['sendemail']) { $account->set('passwd', Passwd::hash($vars['passwd1'])); - $account->setStatus(self::CONFIRMED); + $account->setStatus(UserAccountStatus::CONFIRMED); if ($vars['pwreset-flag']) - $account->setStatus(self::REQUIRE_PASSWD_RESET); + $account->setStatus(UserAccountStatus::REQUIRE_PASSWD_RESET); if ($vars['forbid-pwreset-flag']) - $account->setStatus(self::FORBID_PASSWD_RESET); + $account->setStatus(UserAccountStatus::FORBID_PASSWD_RESET); } $account->save(true); @@ -812,6 +807,46 @@ class UserAccount extends UserAccountModel { } +class UserAccountStatus { + + var $flag; + + const CONFIRMED = 0x0001; + const LOCKED = 0x0002; + const REQUIRE_PASSWD_RESET = 0x0004; + const FORBID_PASSWD_RESET = 0x0008; + + function __construct($flag) { + $this->flag = $flag; + } + + function check($flag) { + return 0 !== ($this->flag & $flag); + } + + function isLocked() { + return $this->check(self::LOCKED); + } + + function isConfirmed() { + return $this->check(self::CONFIRMED); + } + + function __toString() { + + if (!$this->flag) + return 'Guest'; + + if ($this->isLocked()) + return 'Locked (Administrative)'; + + if (!$this->isConfirmed()) + return 'Locked (Pending Activation)'; + + return 'Active (Registered)'; + } +} + /* * Generic user list. diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php index 62361f198e57510487e798d47bde5cb077a9b85d..4bc597c15c4d2c8369d377d7ea343e9f1e2d4875 100644 --- a/include/staff/users.inc.php +++ b/include/staff/users.inc.php @@ -3,10 +3,11 @@ if(!defined('OSTSCPINC') || !$thisstaff) die('Access Denied'); $qstr=''; -$select = 'SELECT user.*, email.address as email '; +$select = 'SELECT user.*, email.address as email, account.status '; $from = 'FROM '.USER_TABLE.' user ' - . 'JOIN '.USER_EMAIL_TABLE.' email ON (user.id = email.user_id) '; + . 'LEFT JOIN '.USER_EMAIL_TABLE.' email ON (user.id = email.user_id) ' + . 'LEFT JOIN '.USER_ACCOUNT_TABLE.' account ON (account.user_id = user.id) '; $where='WHERE 1 '; @@ -100,9 +101,8 @@ else <caption><?php echo $showing; ?></caption> <thead> <tr> - <th width="300"><a <?php echo $name_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=name">Name</a></th> - <th width="300"><a <?php echo $email_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=email">Email</a></th> - <th width="100"><a <?php echo $status_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=status">Status</a></th> + <th width="350"><a <?php echo $name_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=name">Name</a></th> + <th width="250"><a <?php echo $status_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=status">Status</a></th> <th width="100"><a <?php echo $create_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=create">Created</a></th> <th width="145"><a <?php echo $update_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=update">Updated</a></th> </tr> @@ -112,9 +112,13 @@ else if($res && db_num_rows($res)): $ids=($errors && is_array($_POST['ids']))?$_POST['ids']:null; while ($row = db_fetch_array($res)) { - $name = new PersonsName($row['name']); - $status = 'Active'; + // Account status + if ($row['status']) + $status = new UserAccountStatus($row['status']); + else + $status = 'Guest'; + $sel=false; if($ids && in_array($row['id'], $ids)) $sel=true; @@ -129,7 +133,6 @@ else <small>(%d)</small>', $row['tickets']); ?> </td> - <td><?php echo $row['email']; ?></td> <td><?php echo $status; ?></td> <td><?php echo Format::db_date($row['created']); ?></td> <td><?php echo Format::db_datetime($row['updated']); ?> </td>