PageRenderTime 40ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/index.php

https://github.com/lsces/users
PHP | 194 lines | 167 code | 14 blank | 13 comment | 38 complexity | 65bf4ceccdd2fc9d1d1a745644296258 MD5 | raw file
  1. <?php
  2. // $Header$
  3. // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  4. // All Rights Reserved. See below for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  6. // Initialization
  7. require_once( '../../kernel/setup_inc.php' );
  8. $gBitSystem->verifyPermission( 'p_users_admin' );
  9. $feedback = array();
  10. if( isset($_REQUEST["newuser"] ) ) {
  11. $userRecord = $_REQUEST;
  12. $newUser = new RolePermUser();
  13. if( $newUser->importUser( $userRecord ) ) {
  14. $gBitSmarty->assign( 'addSuccess', "User Added Successfully" );
  15. if( empty( $_REQUEST['admin_noemail_user'] ) ) {
  16. $ret = users_admin_email_user( $userRecord );
  17. if( is_array( $ret ) ) {
  18. list($key, $val) = each($ret);
  19. $newUser->mLogs[$key] = $val;
  20. }
  21. $logHash['action_log']['title'] = $userRecord['login'];
  22. $newUser->storeActionLog( $logHash );
  23. }
  24. } else {
  25. $gBitSmarty->assign_by_ref( 'newUser', $_REQUEST );
  26. $gBitSmarty->assign( 'errors', $newUser->mErrors );
  27. }
  28. } elseif( isset( $_REQUEST["assume_user"]) && $gBitUser->hasPermission( 'p_users_admin' ) ) {
  29. $assume_user = (is_numeric( $_REQUEST["assume_user"] )) ? array( 'user_id' => $_REQUEST["assume_user"] ) : array('login' => $_REQUEST["assume_user"]) ;
  30. $userInfo = $gBitUser->getUserInfo( $assume_user );
  31. if( isset( $_REQUEST["confirm"] ) ) {
  32. $gBitUser->verifyTicket();
  33. if( $gBitUser->assumeUser( $userInfo["user_id"] ) ) {
  34. header( 'Location: '.$gBitSystem->getDefaultPage() );
  35. die;
  36. }elseif( !empty( $gBitUser->mErrors ) ){
  37. if ( !isset( $feedback['error'] ) ){
  38. $feedback['error'] = array();
  39. }
  40. $feedback['error'] = array_merge( $feedback['error'], $gBitUser->mErrors );
  41. }
  42. } else {
  43. $gBitSystem->setBrowserTitle( 'Assume User Identity' );
  44. $formHash['assume_user'] = $_REQUEST['assume_user'];
  45. $msgHash = array(
  46. 'confirm_item' => tra( 'This will log you in as the user' )." <strong>$userInfo[real_name] ($userInfo[login])</strong>",
  47. );
  48. $gBitSystem->confirmDialog( $formHash,$msgHash );
  49. }
  50. } elseif( !empty( $_REQUEST['find'] ) ) {
  51. $title = 'Find Users';
  52. }
  53. // Process actions here
  54. // Remove user or remove user from role
  55. if( isset( $_REQUEST["action"] ) ) {
  56. $formHash['action'] = $_REQUEST['action'];
  57. if( !empty( $_REQUEST['batch_user_ids'] ) && is_array( $_REQUEST['batch_user_ids'] ) ) {
  58. if( isset( $_REQUEST["confirm"] ) ) {
  59. $gBitUser->verifyTicket();
  60. $delUsers = $errDelUsers = "";
  61. $userClass = $gBitSystem->getConfig( 'user_class', 'BitPermUser' );
  62. foreach( $_REQUEST['batch_user_ids'] as $uid ) {
  63. $expungeUser = new $userClass( $uid );
  64. $userInfo = $gBitUser->getUserInfo( array( 'user_id' => $uid ) );
  65. if( $expungeUser->load() && $expungeUser->expunge() ) {
  66. $delUsers .= "<li>{$userInfo['real_name']} ({$userInfo['login']})</li>";
  67. } else {
  68. $errDelUsers .= "<li>{$userInfo['real_name']} ({$userInfo['login']})</li>";
  69. }
  70. }
  71. if( !empty( $delUsers ) ) {
  72. $feedback['success'][] = tra( 'Users deleted' ).": <ul>$delUsers</ul>";
  73. } elseif( !empty( $errDelUsers ) ) {
  74. $feedback['error'][] = tra( 'Users not deleted' ).": <ul>$errDelUsers</ul>";
  75. }
  76. } else {
  77. foreach( $_REQUEST['batch_user_ids'] as $uid ) {
  78. $userInfo = $gBitUser->getUserInfo( array( 'user_id' => $uid ) );
  79. $formHash['input'][] = '<input type="hidden" name="batch_user_ids[]" value="'.$uid.'"/>'."{$userInfo['real_name']} ({$userInfo['login']})";
  80. }
  81. $gBitSystem->setBrowserTitle( 'Delete users' );
  82. $msgHash = array(
  83. 'confirm_item' => tra( 'Are you sure you want to remove these users?' ),
  84. 'warning' => tra( 'This will permentally delete these users' ),
  85. );
  86. $gBitSystem->confirmDialog( $formHash, $msgHash );
  87. }
  88. } elseif( $_REQUEST["action"] == 'delete' || $_REQUEST["action"] == 'ban' || $_REQUEST["action"] == 'unban' ) {
  89. $formHash['user_id'] = $_REQUEST['user_id'];
  90. $userInfo = $gBitUser->getUserInfo( array( 'user_id' => $_REQUEST["user_id"] ) );
  91. if( !empty( $userInfo['user_id'] ) ) {
  92. if( isset( $_REQUEST["confirm"] ) ) {
  93. $gBitUser->verifyTicket();
  94. $userClass = $gBitSystem->getConfig( 'user_class', 'BitPermUser' );
  95. $reqUser = new $userClass( $_REQUEST["user_id"] );
  96. switch( $_REQUEST["action"] ){
  97. case 'delete':
  98. $reqUser->mDb->StartTrans();
  99. if( $reqUser->load(TRUE) && $reqUser->expunge( !empty( $_REQUEST['delete_user_content'] ) ? $_REQUEST['delete_user_content'] : NULL ) ) {
  100. $feedback['success'][] = tra( 'User deleted' )." <strong>{$userInfo['real_name']} ({$userInfo['login']})</strong>";
  101. }
  102. $reqUser->mDb->CompleteTrans();
  103. break;
  104. case 'ban':
  105. if( $reqUser->load() && $reqUser->ban() ) {
  106. $feedback['success'][] = tra( 'User banned' )." <strong>{$userInfo['real_name']} ({$userInfo['login']})</strong>";
  107. }
  108. break;
  109. case 'unban':
  110. if( $reqUser->load() && $reqUser->unban() ) {
  111. $feedback['success'][] = tra( 'User restored' )." <strong>{$userInfo['real_name']} ({$userInfo['login']})</strong>";
  112. }
  113. break;
  114. }
  115. } else {
  116. switch( $_REQUEST["action"] ){
  117. case 'delete':
  118. $formHash['input'][] = "<input type='checkbox' name='delete_user_content' value='all' checked='checked'/>".tra( 'Delete all content created by this user' );
  119. foreach( $gLibertySystem->mContentTypes as $contentTypeGuid => $contentTypeHash ) {
  120. // $formHash['input'][] = "<input type='checkbox' name='delete_user_content' checked='checked' value='$contentTypeGuid'/>Delete All User's $gLibertySystem->getContentTypeName($contentTypeHash['content_type_guid'],TRUE)";
  121. }
  122. $gBitSystem->setBrowserTitle( tra( 'Delete user' ) );
  123. $msgHash = array(
  124. 'confirm_item' => tra( 'Are you sure you want to remove the user?' ),
  125. 'warning' => tra( 'This will permentally delete the user' )." <strong>$userInfo[real_name] ($userInfo[login])</strong>",
  126. );
  127. break;
  128. case 'ban':
  129. $gBitSystem->setBrowserTitle( tra( 'Ban user' ) );
  130. $msgHash = array(
  131. 'confirm_item' => tra( 'Are you sure you want to ban this user?' ),
  132. 'warning' => tra( 'This will suspend the account for user' )." <strong>$userInfo[real_name] ($userInfo[login])</strong>",
  133. );
  134. break;
  135. case 'unban':
  136. $gBitSystem->setBrowserTitle( tra( 'Unban user' ) );
  137. $msgHash = array(
  138. 'confirm_item' => tra( 'Are you sure you want to unban this user?' ),
  139. 'warning' => tra( 'This will restore the account for user' )." <strong>$userInfo[real_name] ($userInfo[login])</strong>",
  140. );
  141. break;
  142. }
  143. $gBitSystem->confirmDialog( $formHash,$msgHash );
  144. }
  145. } else {
  146. $feedback['error'][] = tra( 'User not found' );
  147. }
  148. }
  149. if ($_REQUEST["action"] == 'removerole') {
  150. $gBitUser->removeUserFromRole($_REQUEST["user"], $_REQUEST["role"]);
  151. }
  152. }
  153. // get default role and pass it to tpl
  154. foreach( $gBitUser->getDefaultRole() as $defaultRoleId => $defaultRoleName ) {
  155. $gBitSmarty->assign('defaultRoleId', $defaultRoleId );
  156. $gBitSmarty->assign('defaultRoleName', $defaultRoleName );
  157. }
  158. // override default max_records
  159. $_REQUEST['max_records'] = !empty( $_REQUEST['max_records'] ) ? $_REQUEST['max_records'] : $gBitSystem->getConfig('max_records');
  160. $gBitUser->getList( $_REQUEST );
  161. $gBitSmarty->assign_by_ref('users', $_REQUEST["data"]);
  162. $gBitSmarty->assign_by_ref('usercount', $_REQUEST["cant"]);
  163. if (isset($_REQUEST["numrows"])) {
  164. $_REQUEST['listInfo']["numrows"] = $_REQUEST["numrows"];
  165. } else {
  166. $_REQUEST['listInfo']["numrows"] = 10;
  167. }
  168. $_REQUEST['listInfo']["URL"] = USERS_PKG_URL."admin/index.php";
  169. $gBitSmarty->assign_by_ref('listInfo', $_REQUEST['listInfo']);
  170. // invoke edit service for the add user feature
  171. $userObj = new RolePermUser();
  172. $userObj->invokeServices( 'content_edit_function' );
  173. // Get roles (list of roles)
  174. $rolelist = $gBitUser->getRoles('', '', 'role_name_asc');
  175. $gBitSmarty->assign( 'rolelist', $rolelist );
  176. $gBitSmarty->assign( 'feedback', $feedback );
  177. $gBitSmarty->assign( (!empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'userlist').'TabSelect', 'tdefault' );
  178. // Display the template
  179. $gBitSystem->display( 'bitpackage:users/users_admin.tpl', (!empty( $title ) ? $title : 'Edit Users' ) , array( 'display_mode' => 'admin' ));
  180. ?>