source: extensions/event_cats/admin/duplication.inc.php @ 4247

Last change on this file since 4247 was 4247, checked in by LucMorizur, 14 years ago

[Event Cats] Continue duplication management using cat_perm.php and cat_perm.tpl codes

File size: 3.7 KB
Line 
1<?php
2
3$t = read_ec_conf('reg_display');
4if ($t == '0') $reg_display = array('0', '');
5else $reg_display = explode(';', $t);
6
7$template->assign('reg_display', $reg_display);
8$template->assign('ec_conf', $ec_conf);
9
10
11
12
13
14
15// A lot of below code has simply been copied-pasted from file cat_perm.php .
16// Many thanks to people who wrote it !
17
18// +-----------------------------------------------------------------------+
19// |                          form construction                            |
20// +-----------------------------------------------------------------------+
21
22// groups denied are the groups not granted. So we need to find all groups
23// minus groups granted to find groups denied.
24
25$groups = array();
26
27$query = '
28SELECT id, name
29  FROM '.GROUPS_TABLE.'
30  ORDER BY name ASC
31;';
32$groups = simple_hash_from_query($query, 'id', 'name');
33$template->assign('all_groups', $groups);
34
35// groups granted to access the category
36$query = "
37SELECT `arg1`
38  FROM ".EVNTCATS_TABLE."
39  WHERE `code` IS NULL
40    AND `arg1` IS NOT NULL
41;";
42$group_granted_ids = array_from_query($query, 'arg1');
43$group_granted_ids = order_by_name($group_granted_ids, $groups);
44$template->assign('group_granted_ids', $group_granted_ids);
45
46
47// groups denied
48$template->assign('group_denied_ids',
49    order_by_name(array_diff(array_keys($groups), $group_granted_ids), $groups)
50  );
51
52// users...
53$users = array();
54
55$query = "
56SELECT ".$conf['user_fields']['id']." AS id,
57       ".$conf['user_fields']['username']." AS username
58  FROM ".USERS_TABLE."
59;";
60$users = simple_hash_from_query($query, 'id', 'username');
61$template->assign('all_users', $users);
62
63
64$query = "
65SELECT `arg2`
66  FROM ".EVNTCATS_TABLE."
67  WHERE `code` IS NULL
68    AND `arg2` IS NOT NULL
69;";
70$user_granted_direct_ids = array_from_query($query, 'arg2');
71$user_granted_direct_ids = order_by_name($user_granted_direct_ids, $users);
72$template->assign('user_granted_direct_ids', $user_granted_direct_ids);
73
74
75
76$user_granted_indirect_ids = array();
77if (count($group_granted_ids) > 0)
78{
79  $granted_groups = array();
80
81  $query = "
82SELECT user_id, group_id
83  FROM ".USER_GROUP_TABLE."
84  WHERE group_id IN (".implode(',', $group_granted_ids).")
85";
86  $result = pwg_query($query);
87  while ($row = mysql_fetch_array($result))
88  {
89    if (!isset($granted_groups[$row['group_id']]))
90    {
91      $granted_groups[$row['group_id']] = array();
92    }
93    array_push($granted_groups[$row['group_id']], $row['user_id']);
94  }
95
96  $user_granted_by_group_ids = array();
97
98  foreach ($granted_groups as $group_users)
99  {
100    $user_granted_by_group_ids = array_merge($user_granted_by_group_ids,
101                                             $group_users);
102  }
103  $user_granted_by_group_ids = array_unique($user_granted_by_group_ids);
104 
105 
106  $user_granted_indirect_ids = array_diff($user_granted_by_group_ids,
107                                          $user_granted_direct_ids);
108  $user_granted_indirect_ids = 
109    order_by_name($user_granted_indirect_ids, $users); 
110  foreach ($user_granted_indirect_ids as $user_id)
111  {
112    foreach ($granted_groups as $group_id => $group_users)
113    {
114      if (in_array($user_id, $group_users))
115      {
116        $template->append(
117          'user_granted_indirects',
118          array(
119            'USER'=>$users[$user_id],
120            'GROUP'=>$groups[$group_id]
121            )
122          );
123        break;
124      }
125    }
126  }
127}
128
129$user_denied_ids = array_diff(array_keys($users),
130                              $user_granted_indirect_ids,
131                              $user_granted_direct_ids);
132$user_denied_ids = order_by_name($user_denied_ids, $users);
133$template->assign('user_denied_ids', $user_denied_ids);
134
135
136
137
138
139
140
141
142
143
144
145
146/* */
147
148
149?>
Note: See TracBrowser for help on using the repository browser.