aboutsummaryrefslogtreecommitdiff
path: root/admin.php
blob: c5484807e32085cc0710172d2cc32be3845c4544 (plain)
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
<?php
/***************************************************************************
 Copyright (C) 2007 - 2008 SemanticScuttle project (fork from Scuttle)
 http://sourceforge.net/projects/semanticscuttle/


 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ***************************************************************************/

require_once('header.inc.php');

/* Service creation: only useful services are created */
$userservice = & ServiceFactory :: getServiceInstance('UserService');
$bookmark2tagservice = & ServiceFactory :: getServiceInstance('Bookmark2Tagservice');
$bookmarkservice = & ServiceFactory :: getServiceInstance('BookmarkService');
$tag2tagservice = & ServiceFactory :: getServiceInstance('Tag2TagService');
$templateservice = & ServiceFactory :: getServiceInstance('TemplateService');

/* Managing current logged user */
$currentUser = $userservice->getCurrentObjectUser();

// Header variables
$tplVars['subtitle'] = T_('Manage users');
$tplVars['loadjs'] = true;
$tplVars['sidebar_blocks'] = array('users' );

if ( !$userservice->isLoggedOn() ) {
	header('Location: '. createURL('login', ''));
	exit();
}

if ( !$currentUser->isAdmin() ) {
	header('Location: '. createURL('bookmarks', $currentUser->getUsername()));
	exit();
}

@list($url, $action, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;

if ( $action
&& strpos($_SERVER['HTTP_REFERER'], ROOT.'admin.php') === 0  // Prevent CSRF attacks
) {
	switch ( $action ) {
		case 'delete':
			if ( $user && ($userinfo = $userservice->getUserByUsername($user)) ) {
				$uId = $userinfo['uId'];

				$tag2tagservice->removeLinkedTags('','','',$uId);
				$userservice->deleteUser($uId);
				$bookmark2tagservice->deleteTagsForUser($uId);
				// XXX: don't delete bookmarks before tags, else tags can't be deleted !!!
				$bookmarkservice->deleteBookmarksForUser($uId);

				$tplVars['msg'] = sprintf(T_('%s and all his bookmarks and tags were deleted.'), $user);
			}
			break;
		default:
			// DO NOTHING
	}
}

$templatename = 'userlist.tpl';
$users =& $userservice->getObjectUsers();

if ( !is_array($users) ) {
	$users = array();
}

$tplVars['users'] =& $users;

$templateservice->loadTemplate($templatename, $tplVars);
?>