1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
<?php
// $Header: /cvsroot/bitweaver/_bit_users/admin/index.php,v 1.2 2005/06/28 07:46:23 spiderr 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
// jht 2005-06-22_23:51:58 flag this user store as coming from admin page -- a kludge
$_REQUEST['admin_add'] = 1;
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' ) );
?>
|