summaryrefslogtreecommitdiff
path: root/admin/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/index.php')
-rw-r--r--admin/index.php162
1 files changed, 162 insertions, 0 deletions
diff --git a/admin/index.php b/admin/index.php
new file mode 100644
index 0000000..49471a2
--- /dev/null
+++ b/admin/index.php
@@ -0,0 +1,162 @@
+<?php
+// $Header: /cvsroot/bitweaver/_bit_users/admin/index.php,v 1.1 2005/06/19 05:12:23 bitweaver Exp $
+// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+// Initialization
+require_once( '../../bit_setup_inc.php' );
+
+function batchImportUsers() {
+ global $smarty;
+ $fname = $_FILES['csvlist']['tmp_name'];
+ $fhandle = fopen($fname, "r");
+ //Get the field names
+ $fields = fgetcsv($fhandle, 1000);
+ //any?
+ if (!$fields[0]) {
+ $smarty->assign('msg', tra("The file is not a CSV file or has not a correct syntax"));
+ $gBitSystem->display( 'error.tpl' );
+ die;
+ }
+ //now load the users in a table
+ while (!feof($fhandle)) {
+ if( $data = fgetcsv($fhandle, 1000) ) {
+ for ($i = 0; $i < count($fields); $i++) {
+ @$ar[$fields[$i]] = $data[$i];
+ }
+ $userrecs[] = $ar;
+ }
+ }
+ fclose ($fhandle);
+ // any?
+ if (!is_array($userrecs)) {
+ $smarty->assign('msg', tra("No records were found. Check the file please!"));
+ $gBitSystem->display( 'error.tpl' );
+ die;
+ }
+ // Process user array
+ $added = 0;
+ $i = 1;
+ foreach ($userrecs as $u) {
+ $newUser = new BitUser();
+ //untested - spiderr
+ if( $newUser->store( $u ) ) {
+ if( !empty( $u['groups'] ) ) {
+ $grps = explode(",", $u['groups']);
+ foreach ($grps as $grp) {
+ if( $groupId = $newUser->group_exists( $grp, ROOT_USER_ID ) ) {
+ $newUser->addUserToGroup( $newUser->mUserId, $groupId );
+ }
+ }
+ }
+ $added++;
+ } else {
+ $discarded[$i] = implode( ',', $newUser->mErrors );
+ }
+ unset( $newUser );
+ $i++;
+ }
+
+ $smarty->assign('added', $added);
+ if (@is_array($discarded)) {
+ $smarty->assign('discarded', count($discarded));
+ }
+ @$smarty->assign_by_ref('discardlist', $discarded);
+}
+
+$gBitSystem->verifyPermission( 'bit_p_admin_users' );
+
+$feedback = array();
+
+// Process the form to add a user here
+if (isset($_REQUEST["newuser"])) {
+
+ $newUser = new BitPermUser();
+ // Check if the user already exists
+ if( $newUser->store( $_REQUEST ) ) {
+ $smarty->assign( 'addSuccess', "User Added Successfully" );
+ } else {
+ $smarty->assign_by_ref( 'newUser', $_REQUEST );
+ $smarty->assign( 'errors', $newUser->mErrors );
+ }
+ // if no user data entered, check if it's a batch upload
+} elseif( isset( $_REQUEST["batchimport"]) ) {
+ if( $_FILES['csvlist']['size'] && is_uploaded_file($_FILES['csvlist']['tmp_name'] ) ) {
+ batchImportUsers();
+ }
+} elseif( isset( $_REQUEST["assume_user"]) ) {
+ $userInfo = $gBitUser->getUserInfo( array( 'user_id' => $_REQUEST["assume_user"] ) );
+ if( isset( $_REQUEST["confirm"] ) ) {
+ if( $gBitUser->assumeUser( $_REQUEST["assume_user"] ) ) {
+ header( 'Location: '.USERS_PKG_URL.'my.php' );
+ die;
+ }
+ } else {
+ $gBitSystem->setBrowserTitle( 'Assumer User Identity' );
+ $formHash['assume_user'] = $_REQUEST['assume_user'];
+ $msgHash = array(
+ 'confirm_item' => tra( 'This will log you in as the user' )." <strong>$userInfo[real_name] ($userInfo[login])</strong>",
+ );
+ $gBitSystem->confirmDialog( $formHash,$msgHash );
+ }
+} elseif( !empty( $_REQUEST['find'] ) ) {
+ $title = 'Find Users';
+}
+
+// Process actions here
+// Remove user or remove user from group
+if (isset($_REQUEST["action"])) {
+
+ $formHash['action'] = $_REQUEST['action'];
+ if ($_REQUEST["action"] == 'delete') {
+ $formHash['user_id'] = $_REQUEST['user_id'];
+ $userInfo = $gBitUser->getUserInfo( array( 'user_id' => $_REQUEST["user_id"] ) );
+ if( !empty( $userInfo['user_id'] ) ) {
+ if( isset( $_REQUEST["confirm"] ) ) {
+ if( $gBitUser->expunge( $_REQUEST["user_id"] ) ) {
+ $feedback['success'][] = tra( 'User Deleted' )." <strong>$userInfo[real_name] ($userInfo[login])</strong>";
+ }
+ } else {
+ $gBitSystem->setBrowserTitle( 'Delete user' );
+ $msgHash = array(
+ 'confirm_item' => tra( 'Are you sure you want to remove the user?' ),
+ 'warning' => tra( 'This will permentally delete the user' )." <strong>$userInfo[real_name] ($userInfo[login])</strong>",
+ );
+ $gBitSystem->confirmDialog( $formHash,$msgHash );
+ }
+ } else {
+ $feedback['error'][] = tra( 'User not found' );
+ }
+ }
+ if ($_REQUEST["action"] == 'removegroup') {
+ $gBitUser->removeUserFromGroup($_REQUEST["user"], $_REQUEST["group"]);
+ }
+}
+
+// get default group and pass it to tpl
+foreach( $gBitUser->getDefaultGroup() as $defaultGroupId => $defaultGroupName ) {
+ $smarty->assign('defaultGroupId', $defaultGroupId );
+ $smarty->assign('defaultGroupName', $defaultGroupName );
+}
+
+$_REQUEST['max_records'] = 20;
+$gBitUser->getList( $_REQUEST );
+$smarty->assign_by_ref('users', $_REQUEST["data"]);
+if (isset($_REQUEST["numrows"]))
+ $_REQUEST["control"]["numrows"] = $_REQUEST["numrows"];
+else
+ $_REQUEST["control"]["numrows"] = 10;
+$_REQUEST["control"]["URL"] = USERS_PKG_URL."admin/index.php";
+$smarty->assign_by_ref('control', $_REQUEST["control"]);
+
+
+// Get groups (list of groups)
+$grouplist = $gBitUser->getGroups('', '', 'group_name_asc');
+$smarty->assign( 'grouplist', $grouplist );
+$smarty->assign( 'feedback', $feedback );
+
+$smarty->assign( (!empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'userlist').'TabSelect', 'tdefault' );
+
+// Display the template
+$gBitSystem->display( 'bitpackage:users/users_admin.tpl', (!empty( $title ) ? $title : 'Edit Users' ) );
+?>