11 namespace Fossology\UI\Page;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
25 var $groupPermissions = array(-1 =>
"None", UserDao::USER =>
"User",
26 UserDao::ADMIN =>
"Admin", UserDao::ADVISOR =>
"Advisor");
27 const NAME =
'group_manage_users';
29 function __construct()
31 parent::__construct(self::NAME, array(
32 self::TITLE => _(
"Manage Group Users"),
33 self::MENU_LIST =>
"Admin::Groups::Manage Group Users",
35 self::REQUIRES_LOGIN => TRUE
43 protected function handle(Request $request)
48 $groupMap = $userDao->getAdminGroupMap($userId, $_SESSION[
Auth::USER_LEVEL]);
49 if (empty($groupMap)) {
50 $text = _(
"You have no permission to manage any group.");
51 return $this->
render(
'include/base.html.twig', $this->mergeWithDefault(array(
'message' => $text)));
54 $dbManager = $this->
getObject(
'db.manager');
55 $group_pk = intval($request->get(
'group'));
56 if (empty($group_pk) || !array_key_exists($group_pk, $groupMap)) {
57 $group_pk = key($groupMap);
60 $gum_pk = intval($request->get(
'gum_pk'));
63 $perm = intval($request->get(
'perm'));
64 $atleastOneUserShouldBePart = $dbManager->getSingleRow(
"SELECT count(*) cnt FROM group_user_member WHERE group_fk = (SELECT group_fk FROM group_user_member WHERE group_user_member_pk = $1)",
65 array($gum_pk), $stmt = __METHOD__ .
".atleastOneUserShouldBePart");
66 if ($atleastOneUserShouldBePart[
'cnt'] <= 1) {
67 $text = _(
"Error: atleast one user should be part of a group.");
69 $this->updateGUMPermission($gum_pk, $perm,$dbManager);
71 $groupMap = $userDao->getAdminGroupMap($userId,
75 $newuser = intval($request->get(
'newuser'));
76 $newperm = intval($request->get(
'newperm'));
78 if ($newuser && $group_pk) {
80 $dbManager->prepare($stmt = __METHOD__ .
".delByGroupAndUser",
81 "delete from group_user_member where group_fk=$1 and user_fk=$2");
82 $dbManager->freeResult(
83 $dbManager->execute($stmt, array($group_pk, $newuser)));
85 $dbManager->prepare($stmt = __METHOD__ .
".insertGUP",
86 "insert into group_user_member (group_fk, user_fk, group_perm) values ($1,$2,$3)");
87 $dbManager->freeResult(
88 $dbManager->execute($stmt, array($group_pk, $newuser, $newperm)));
90 if ($newuser == $userId) {
91 $groupMap = $userDao->getAdminGroupMap($userId, $_SESSION[
Auth::USER_LEVEL]);
93 $newperm = $newuser = 0;
96 natcasesort($groupMap);
98 $onchange =
"onchange=\"js_url(this.value, '$baseUrl')\"";
99 $baseUrl .= $group_pk;
100 $vars = array(
'groupMap' => $groupMap,
101 'groupId' => $group_pk,
102 'permissionMap' => $this->groupPermissions,
103 'baseUrl' => $baseUrl,
104 'groupMapAction' => $onchange);
106 $stmt = __METHOD__ .
"getUsersWithGroup";
107 $dbManager->prepare($stmt,
"select user_pk, user_name, user_status, user_desc, group_user_member_pk, group_perm
108 FROM users LEFT JOIN group_user_member gum ON gum.user_fk=users.user_pk AND gum.group_fk=$1
109 ORDER BY user_name");
110 $result = $dbManager->execute($stmt, array($group_pk));
111 $vars[
'usersWithGroup'] = $dbManager->fetchAll($result);
112 $dbManager->freeResult($result);
114 $otherUsers = array(
'0' =>
'');
115 foreach ($vars[
'usersWithGroup'] as $row) {
116 if ($row[
'group_user_member_pk'] || $row[
'user_status']!=
'active') {
119 $otherUsers[$row[
'user_pk']] = !empty($row[
'user_desc']) ? $row[
'user_desc'].
' ('. $row[
'user_name'] .
')' : $row[
'user_name'];
122 $vars[
'existsOtherUsers'] = count($otherUsers) - 1;
123 if ($vars[
'existsOtherUsers']) {
124 $vars[
'newPermissionMap'] = $this->groupPermissions;
125 unset($vars[
'newPermissionMap'][-1]);
126 $script =
"var newpermurl;
127 function setNewPermUrl(newperm){
128 newpermurl='" . $baseUrl .
"&newperm='+newperm+'&newuser=';
130 setNewPermUrl($newperm);";
131 $scripts =
js_url() .
'<script type="text/javascript"> ' . $script .
'</script>';
132 $vars[
'otherUsers'] = $otherUsers;
137 $vars[
'scripts'] = $scripts;
139 $vars[
'message'] .= $text;
141 return $this->
render(
'admin_group_users.html.twig', $this->mergeWithDefault($vars));
144 public function updateGUMPermission($gum_pk, $perm,$dbManager)
147 $dbManager->prepare($stmt = __METHOD__ .
".delByGUM",
148 "DELETE FROM group_user_member WHERE group_user_member_pk=$1 RETURNING user_fk, group_fk");
149 $deletedEntry = $dbManager->execute($stmt, array($gum_pk));
150 $effectedUser = $dbManager->fetchArray($deletedEntry);
151 $isEffected = $dbManager->getSingleRow(
"SELECT count(*) cnt FROM users WHERE user_pk=$1 AND group_fk = $2",
152 array($effectedUser[
'user_fk'], $effectedUser[
'group_fk']), $stmt = __METHOD__ .
".isUserEffectedFromRemoval");
153 if ($isEffected[
'cnt'] == 1) {
154 $dbManager->getSingleRow(
"UPDATE users SET group_fk = (
155 SELECT group_fk FROM group_user_member WHERE user_fk = $1 AND group_perm >= 0 LIMIT 1)
157 array($effectedUser[
'user_fk']), $stmt = __METHOD__ .
".setNewGroupId");
159 $dbManager->freeResult($deletedEntry);
160 }
else if (array_key_exists($perm, $this->groupPermissions)) {
161 $dbManager->getSingleRow(
"UPDATE group_user_member SET group_perm=$1 WHERE group_user_member_pk=$2",
162 array($perm, $gum_pk), $stmt = __METHOD__ .
".updatePermInGUM");
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
render($templateName, $vars=null, $headers=null)
Traceback_uri()
Get the URI without query to this location.