tiki-assignuser.php 4.78 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6
//
7 8
// 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.
changi67's avatar
changi67 committed
9
// $Id$
10

11 12
// This script is used to assign groups to a particular user
// ASSIGN USER TO GROUPS
13 14
require_once ('tiki-setup.php');

15
$auto_query_args = array('sort_mode', 'offset', 'find', 'assign_user', 'group', 'maxRecords');
16

17
$access->check_permission_either(array('tiki_p_admin_users', 'tiki_p_subscribe_groups'));
18

19 20 21 22 23 24 25 26 27 28 29 30
if (!isset($_REQUEST["assign_user"]) || ($tiki_p_admin != 'y' && $tiki_p_admin_users != 'y')) {
	$_REQUEST['assign_user'] = $user;
	$userChoice = 'y';
	$smarty->assign_by_ref('userChoice', $userChoice);
} else {
	if (!$userlib->user_exists($_REQUEST['assign_user'])) {
		$smarty->assign('msg', tra("User doesn't exist"));
		$smarty->display("error.tpl");
		die;
	}
	$userChoice = '';
	$smarty->assign_by_ref('assign_user', $_REQUEST['assign_user']);
31 32
}

33
$assign_user = $_REQUEST["assign_user"];
34

35
if (isset($_REQUEST["action"])) {
36
	check_ticket('admin-assign-user');
changi67's avatar
changi67 committed
37

38 39 40 41
	if (!isset($_REQUEST["group"])) {
		$smarty->assign('msg', tra("You have to indicate a group"));
		$smarty->display("error.tpl");
		die;
mose's avatar
mose committed
42
	}
43 44 45
	if ($userChoice == 'y') {
		$gps = $userlib->get_groups(0, -1, 'groupName_asc', '', '', '', '', $userChoice);
		$groups = array();
46
		foreach ($gps['data'] as $g) {
47 48 49 50 51
			$groups[$g['groupName']] = $g;
		}
	} elseif ($tiki_p_admin != 'y') {
		$groups = $userlib->get_user_groups_inclusion($user);
	}
52
	if ($_REQUEST["action"] == 'assign') {
mose's avatar
mose committed
53 54 55 56
		if (!$userlib->group_exists($_REQUEST["group"])) {
			$smarty->assign('msg', tra("This group is invalid"));
			$smarty->display("error.tpl");
			die;
57
		}
58
		if ($tiki_p_admin_users == 'y' ||($tiki_p_admin_users == 'y' && array_key_exists($_REQUEST["group"], $groups))) {
59
			$userlib->assign_user_to_group($_REQUEST["assign_user"], $_REQUEST["group"]);
60
			$logslib->add_log('perms', sprintf("Assigned %s in group %s", $_REQUEST["assign_user"], $_REQUEST["group"]));
changi67's avatar
changi67 committed
61
		}
62
	} elseif ($_REQUEST["action"] == 'removegroup' && ($tiki_p_admin == 'y' || ($tiki_p_admin_users == 'y' && array_key_exists($_REQUEST["group"], $groups)))) {
63 64
		$access->check_authenticity();
		$userlib->remove_user_from_group($_REQUEST["assign_user"], $_REQUEST["group"]);
65
		$logslib->add_log('perms', sprintf("Removed %s from group %s", $_REQUEST["assign_user"], $_REQUEST["group"]));
66
	}
67 68
}

69
if (isset($_REQUEST['set_default'])) {
70
	$userlib->set_default_group($_REQUEST['login'], $_REQUEST['defaultgroup']);
71 72
}

73
$user_info = $userlib->get_user_info($assign_user, true);
74
$smarty->assign_by_ref('user_info', $user_info);
75 76 77 78 79 80
if (!empty($_REQUEST['save'])) {
	foreach ($_REQUEST as $r => $v) {
		if (strpos($r, 'new_') === 0) {
			$g = substr($r, 4);
			if ($_REQUEST['new_'.$g] != $_REQUEST['old_'.$g]) {
				$t = strtotime($_REQUEST['new_'.$g]);
changi67's avatar
changi67 committed
81
				$t = $tikilib->make_time(date('H', $t), date('i', $t), 0, date('m', $t), date('d', $t), date('Y', $t));
82 83 84 85 86
				if ($t !== false) {
					$g_info = $userlib->get_groupId_info($g);
					$userlib->extend_membership($assign_user, $g_info['groupName'], 0, $t);
				}
			}
changi67's avatar
changi67 committed
87 88
		}
	}
89 90 91
}
$dates = $userlib->get_user_groups_date($user_info['userId']);
$smarty->assign_by_ref('dates', $dates);
92

93
if (!isset($_REQUEST["sort_mode"])) {
94
	$sort_mode = 'groupName_asc';
95
} else {
96 97 98 99
	$sort_mode = $_REQUEST["sort_mode"];
}

$smarty->assign_by_ref('sort_mode', $sort_mode);
100 101 102 103

// If offset is set use it if not then use offset =0
// use the maxRecords php variable to set the limit
// if sortMode is not set then use lastModif_desc
104 105
if (!isset($_REQUEST["offset"])) {
	$offset = 0;
106
} else {
107
	$offset = $_REQUEST["offset"];
108 109
}

110 111 112 113
$smarty->assign_by_ref('offset', $offset);

if (isset($_REQUEST["find"])) {
	$find = $_REQUEST["find"];
114
} else {
115
	$find = '';
116
}
117 118
$smarty->assign('find', $find);

119 120 121 122
if (isset($_REQUEST['maxRecords'])) {
	$maxRecords = $_REQUEST['maxRecords'];
}

123
if ($tiki_p_admin != 'y' && $userChoice != 'y') {
124
	$ingroups = $userlib->get_user_groups_inclusion($user);
125 126 127 128 129 130
	foreach ($user_info['groups'] as $grp=>$i) {
		if (!isset($ingroups[$grp])) {
			unset($user_info['groups'][$grp]);
		}
	}
} else
131
	$ingroups = '';
132
$users = $userlib->get_groups($offset, $maxRecords, $sort_mode, $find, '', 'y', $ingroups, $userChoice);
133

134 135 136
foreach ($users['data'] as $key=>$gr) {
	if (isset($user_info['groups'][$gr['groupName']])) {
		$users['data'][$key]['what'] = $user_info['groups'][$gr['groupName']];
137 138
	}
}
139

140
$smarty->assign_by_ref('cant_pages', $users["cant"]);
141 142

// Get users (list of users)
143
$smarty->assign_by_ref('users', $users["data"]);
144

145
ask_ticket('admin-assign-user');
146

147 148 149
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

150
// Display the template
151
$smarty->assign('mid', 'tiki-assignuser.tpl');
152
$smarty->display("tiki.tpl");