Commit 610629d7cc4e212c4185bdb181a174fcf1500dba

Authored by bryndivey
1 parent 4e9bb39e

Added enable/disable features to user management


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5957 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/users/User.inc
@@ -31,6 +31,8 @@ @@ -31,6 +31,8 @@
31 31
32 require_once(KT_LIB_DIR . '/database/dbutil.inc'); 32 require_once(KT_LIB_DIR . '/database/dbutil.inc');
33 require_once(KT_LIB_DIR . '/ktentity.inc'); 33 require_once(KT_LIB_DIR . '/ktentity.inc');
  34 +
  35 +define('ADMIN_USER_ID', 1);
34 36
35 class User extends KTEntity { 37 class User extends KTEntity {
36 /** user's login name */ 38 /** user's login name */
plugins/ktcore/admin/userManagement.php
@@ -628,6 +628,52 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { @@ -628,6 +628,52 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
628 return implode(', ', $aGroupNames); 628 return implode(', ', $aGroupNames);
629 } 629 }
630 630
  631 +
  632 +
  633 + // change enabled / disabled status of users
  634 + function do_change_enabled() {
  635 + $this->startTransaction();
  636 +
  637 + $iLicenses = 0;
  638 + if (KTPluginUtil::pluginIsActive('ktdms.wintools')) {
  639 + require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php');
  640 + $iLicenses = BaobabKeyUtil::getLicenseCount();
  641 + }
  642 +
  643 + // "-2" to account for admin/anonymous
  644 + $iEnabledUsers = User::getNumberEnabledUsers() - 2;
  645 +
  646 + foreach(KTUtil::arrayGet($_REQUEST, 'disable_user', array()) as $sUserId => $v) {
  647 + $oUser = User::get((int)$sUserId);
  648 + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); }
  649 + $oUser->setDisabled(True);
  650 + $res = $oUser->update();
  651 + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); }
  652 + $iEnabledUsers--;
  653 + }
  654 +
  655 + foreach(KTUtil::arrayGet($_REQUEST, 'enable_user', array()) as $sUserId => $v) {
  656 + // check that we haven't hit max user limit
  657 + if($iLicenses !== 0 && $iEnabledUsers >= $iLicenses) {
  658 + // if so, add to error messages, but commit transaction (break this loop)
  659 + $_SESSION['KTErrorMessage'][] = _kt('You may only have ') . $iLicenses . _kt(' users enabled at one time.');
  660 + break;
  661 + }
  662 +
  663 + // else enable user
  664 + $oUser = User::get((int)$sUserId);
  665 + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); }
  666 + $oUser->setDisabled(False);
  667 + $res = $oUser->update();
  668 + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); }
  669 + $iEnabledUsers++;
  670 + }
  671 +
  672 + $this->commitTransaction();
  673 + $this->successRedirectToMain(_kt('Users updated'));
  674 +
  675 + }
  676 +
631 } 677 }
632 678
633 ?> 679 ?>
templates/ktcore/principals/useradmin.smarty
@@ -54,7 +54,7 @@ very slow if you have many users).{/i18n}</p> @@ -54,7 +54,7 @@ very slow if you have many users).{/i18n}</p>
54 {/foreach} 54 {/foreach}
55 55
56 <div class="form_actions"> 56 <div class="form_actions">
57 - <input type="submit" value="{i18n}search for users{/i18n}" /> 57 + <input type="submit" value="{i18n}Search For Users{/i18n}" />
58 </div class="form_actions"> 58 </div class="form_actions">
59 </fieldset> 59 </fieldset>
60 </form> 60 </form>
@@ -62,13 +62,18 @@ very slow if you have many users).{/i18n}&lt;/p&gt; @@ -62,13 +62,18 @@ very slow if you have many users).{/i18n}&lt;/p&gt;
62 {if ($no_search === true)} 62 {if ($no_search === true)}
63 {else} 63 {else}
64 {if (!empty($search_results))} 64 {if (!empty($search_results))}
  65 +
  66 +<br />
  67 +<form action="{$smarty.server.PHP_SELF}" method="post">
65 <table class="kt_collection narrow" cellspacing="0" cellpadding="5"> 68 <table class="kt_collection narrow" cellspacing="0" cellpadding="5">
66 <thead> 69 <thead>
67 <tr> 70 <tr>
68 <th>{i18n}Name{/i18n}</th> 71 <th>{i18n}Name{/i18n}</th>
69 <th>{i18n}Username{/i18n}</th> 72 <th>{i18n}Username{/i18n}</th>
70 <th>{i18n}Edit{/i18n}</th> 73 <th>{i18n}Edit{/i18n}</th>
71 - <th>{i18n}Delete{/i18n}</th> 74 + <th>{i18n}Enabled{/i18n}</th>
  75 + <th>{i18n}Enable{/i18n}</th>
  76 + <th>{i18n}Disable{/i18n}</th>
72 <th>{i18n}Group Memberships{/i18n}</th> 77 <th>{i18n}Group Memberships{/i18n}</th>
73 <th>{i18n}Current Groups{/i18n}</th> 78 <th>{i18n}Current Groups{/i18n}</th>
74 </tr> 79 </tr>
@@ -80,7 +85,25 @@ very slow if you have many users).{/i18n}&lt;/p&gt; @@ -80,7 +85,25 @@ very slow if you have many users).{/i18n}&lt;/p&gt;
80 <td>{$oUser->getName()}</td> 85 <td>{$oUser->getName()}</td>
81 <td>{$oUser->getUsername()}</td> 86 <td>{$oUser->getUsername()}</td>
82 <td><a href="{addQS}action=editUser&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}" class="ktAction ktEdit">{i18n}Edit{/i18n}</a></td> 87 <td><a href="{addQS}action=editUser&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}" class="ktAction ktEdit">{i18n}Edit{/i18n}</a></td>
83 - <td><a href="{addQS}action=deleteuser&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}" class="ktAction ktDelete">{i18n}Delete{/i18n}</a></td> 88 + <td class="centered">
  89 + {if ($oUser->getDisabled())}
  90 + <span class="ktAction ktDenied" title="{i18n}Disabled{/i18n}">{i18n}Disabled{/i18n}</a>
  91 + {else}
  92 + <span class="ktAction ktAllowed" title="{i18n}Enabled{/i18n}">{i18n}Enabled{/i18n}</a>
  93 + {/if}
  94 + </td>
  95 +
  96 + <td class="centered">
  97 + {if ($oUser->getDisabled() && $oUser->getId() != ADMIN_USER_ID)}<input type="checkbox" name="enable_user[{$oUser->getId()}]" value="1" />
  98 + {else}&mdash;{/if}
  99 + </td>
  100 +
  101 + <td class="centered">
  102 + {if (!$oUser->getDisabled() && $oUser->getId() != ADMIN_USER_ID)}<input type="checkbox" name="disable_user[{$oUser->getId()}]" value="1" />
  103 + {else}&mdash;{/if}
  104 + </td>
  105 +
  106 +
84 <td><a href="{addQS}action=editgroups&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}">{i18n}Manage Groups{/i18n}</a></td> 107 <td><a href="{addQS}action=editgroups&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}">{i18n}Manage Groups{/i18n}</a></td>
85 <td class="title"><span class="descriptiveText">{$context->getGroupStringForUser($oUser)}</span></td> 108 <td class="title"><span class="descriptiveText">{$context->getGroupStringForUser($oUser)}</span></td>
86 </tr> 109 </tr>
@@ -88,7 +111,11 @@ very slow if you have many users).{/i18n}&lt;/p&gt; @@ -88,7 +111,11 @@ very slow if you have many users).{/i18n}&lt;/p&gt;
88 111
89 </tbody> 112 </tbody>
90 </table> 113 </table>
91 - 114 +<div class="form_actions">
  115 +<input type="hidden" name="action" value="change_enabled" />
  116 +<input type="submit" value="{i18n}Apply Changes{/i18n}" />
  117 +</div>
  118 +</form>
92 {else} 119 {else}
93 <div class="ktError"><p>{i18n}No results for your search.{/i18n}</p></div> 120 <div class="ktError"><p>{i18n}No results for your search.{/i18n}</p></div>
94 121