1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * phpGroupWare - Preferences * |
---|
4 | * http://www.phpgroupware.org * |
---|
5 | * -------------------------------------------- * |
---|
6 | * This program is free software; you can redistribute it and/or modify it * |
---|
7 | * under the terms of the GNU General Public License as published by the * |
---|
8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
9 | * option) any later version. * |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | |
---|
13 | class uiaclprefs |
---|
14 | { |
---|
15 | var $acl; |
---|
16 | var $template; |
---|
17 | |
---|
18 | var $public_functions = array('index' => True); |
---|
19 | |
---|
20 | function uiaclprefs() |
---|
21 | { |
---|
22 | $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs'); |
---|
23 | |
---|
24 | } |
---|
25 | |
---|
26 | function index() |
---|
27 | { |
---|
28 | $acl_app = get_var('acl_app',array('POST','GET')); |
---|
29 | $owner = get_var('owner',array('POST','GET')); |
---|
30 | |
---|
31 | if (! $acl_app) |
---|
32 | { |
---|
33 | $acl_app = 'preferences'; |
---|
34 | $acl_app_not_passed = True; |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | $GLOBALS['phpgw']->translation->add_app($acl_app); |
---|
39 | } |
---|
40 | |
---|
41 | $_SESSION['acl_app'] = $acl_app; |
---|
42 | |
---|
43 | |
---|
44 | $GLOBALS['phpgw_info']['flags']['currentapp'] = $acl_app; |
---|
45 | |
---|
46 | if ($acl_app_not_passed) |
---|
47 | { |
---|
48 | if(is_object($GLOBALS['phpgw']->log)) |
---|
49 | { |
---|
50 | $GLOBALS['phpgw']->log->message(array( |
---|
51 | 'text' => 'F-BadmenuactionVariable, failed to pass acl_app.', |
---|
52 | 'line' => __LINE__, |
---|
53 | 'file' => __FILE__ |
---|
54 | )); |
---|
55 | $GLOBALS['phpgw']->log->commit(); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | if ($GLOBALS['phpgw_info']['server']['deny_user_grants_access'] && !isset($GLOBALS['phpgw_info']['user']['apps']['admin'])) |
---|
60 | { |
---|
61 | echo '<center><b>' . lang('Access not permitted') . '</b></center>'; |
---|
62 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | if((!isset($owner) || empty($owner)) || !$GLOBALS['phpgw_info']['user']['apps']['admin']) |
---|
67 | $owner = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
68 | |
---|
69 | $_SESSION['owner'] = $owner; |
---|
70 | |
---|
71 | |
---|
72 | $acct = CreateObject('phpgwapi.accounts',$owner); |
---|
73 | $owner_name = $acct->id2name($owner); // get owner name for title |
---|
74 | |
---|
75 | if($is_group = $acct->get_type($owner) == 'g') |
---|
76 | $owner_name = lang('Group').' ('.$owner_name.')'; |
---|
77 | |
---|
78 | $this->acl = CreateObject('phpgwapi.acl',(int)$owner); |
---|
79 | |
---|
80 | // begin jakjr |
---|
81 | $repository = $this->acl->read_repository(); //get all lines of the owner |
---|
82 | $cont = 0; |
---|
83 | $just_owner_array = array(); |
---|
84 | foreach($repository as $repository) |
---|
85 | { |
---|
86 | // Pega os valores do array que são da aplicação corrente, do dono corrente e verifica se a camplo acl_location é diferente de run, que não é necessário aqui. |
---|
87 | if (($repository['appname'] == $GLOBALS['phpgw_info']['flags']['currentapp']) && ($repository['account'] == $owner) && ($repository['locations'] != 'run')) |
---|
88 | { |
---|
89 | $just_owner_array[$cont] = $repository; |
---|
90 | $cont++; |
---|
91 | } |
---|
92 | } |
---|
93 | //echo '<pre>'; |
---|
94 | //print_r($just_owner_array); |
---|
95 | //echo '</pre>'; |
---|
96 | // end jakjr |
---|
97 | |
---|
98 | if ($_POST['submit']) { |
---|
99 | $processed = $_POST['processed']; |
---|
100 | |
---|
101 | $to_remove = unserialize(urldecode($processed)); |
---|
102 | |
---|
103 | /* User records */ |
---|
104 | $user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']]; |
---|
105 | /* Group records */ |
---|
106 | $group_variable = $_POST['g_'.$GLOBALS['phpgw_info']['flags']['currentapp']]; |
---|
107 | $keys_to_keep = array(); |
---|
108 | if(!empty($user_variable)) { |
---|
109 | foreach($user_variable as $key_user=>$value) { |
---|
110 | $temp = explode("_",$key_user); |
---|
111 | $keys_to_keep[(int)$temp[0]] = 1; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | for($i=0;$i<count($to_remove);$i++) { |
---|
116 | |
---|
117 | if(!array_key_exists((int)$to_remove[$i],$keys_to_keep)) { |
---|
118 | $this->acl->persist_shared_groups($to_remove[$i]); |
---|
119 | } |
---|
120 | $this->acl->delete($GLOBALS['phpgw_info']['flags']['currentapp'],$to_remove[$i]); |
---|
121 | } |
---|
122 | |
---|
123 | /* Group records */ |
---|
124 | //$group_variable = $_POST['g_'.$GLOBALS['phpgw_info']['flags']['currentapp']]; |
---|
125 | |
---|
126 | if (!$group_variable) |
---|
127 | $group_variable = array(); |
---|
128 | |
---|
129 | @reset($group_variable); |
---|
130 | $totalacl = array(); |
---|
131 | while(list($rowinfo,$perm) = each($group_variable)) { |
---|
132 | list($group_id,$rights) = split('_',$rowinfo); |
---|
133 | $totalacl[$group_id] += $rights; |
---|
134 | } |
---|
135 | @reset($totalacl); |
---|
136 | while(list($group_id,$rights) = @each($totalacl)) { |
---|
137 | if($is_group) |
---|
138 | $rights &= ~PHPGW_ACL_PRIVATE; |
---|
139 | if(array_key_exists($user_id,$keys_to_keep)) |
---|
140 | if(($rights & 1) == 0) { |
---|
141 | $this->acl->persist_shared_groups($user_id); |
---|
142 | } |
---|
143 | $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$group_id,$rights); |
---|
144 | } |
---|
145 | |
---|
146 | /* User records */ |
---|
147 | //$user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']]; |
---|
148 | |
---|
149 | if (!$user_variable) |
---|
150 | $user_variable = array(); |
---|
151 | |
---|
152 | @reset($user_variable); |
---|
153 | $totalacl = array(); |
---|
154 | while(list($rowinfo,$perm) = each($user_variable)) { |
---|
155 | list($user_id,$rights) = split('_',$rowinfo); |
---|
156 | $totalacl[$user_id] += $rights; |
---|
157 | } |
---|
158 | |
---|
159 | @reset($totalacl); |
---|
160 | while(list($user_id,$rights) = @each($totalacl)) { |
---|
161 | if($is_group) |
---|
162 | $rights &= ~ PHPGW_ACL_PRIVATE; |
---|
163 | |
---|
164 | $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$user_id,$rights); |
---|
165 | } |
---|
166 | |
---|
167 | $this->acl->save_repository(); |
---|
168 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('../'.$GLOBALS['phpgw_info']['flags']['currentapp'].'/index.php')); |
---|
169 | } |
---|
170 | |
---|
171 | $processed = Array(); |
---|
172 | |
---|
173 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('%1 - Preferences',$GLOBALS['phpgw_info']['apps'][$acl_app]['title']).' - '.lang('acl').': '.$owner_name; |
---|
174 | |
---|
175 | if(!@is_object($GLOBALS['phpgw']->js)) { |
---|
176 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
177 | } |
---|
178 | |
---|
179 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
180 | echo parse_navbar(); |
---|
181 | |
---|
182 | $this->template = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences')); |
---|
183 | $templates = Array ( |
---|
184 | 'preferences' => 'preference_acl.tpl', |
---|
185 | 'acl_row' => 'preference_acl_row.tpl', |
---|
186 | 'acl_hidden' => 'preference_acl_hidden.tpl' |
---|
187 | ); |
---|
188 | |
---|
189 | $this->template->set_file($templates); |
---|
190 | |
---|
191 | $this->template->set_var("users_list", lang("Users List")); |
---|
192 | $this->template->set_var("attributes", lang("Attributes")); |
---|
193 | $this->template->set_var("read", lang("Read")); |
---|
194 | $this->template->set_var("add", lang("Add")); |
---|
195 | $this->template->set_var("edit", lang("Edit")); |
---|
196 | $this->template->set_var("delete", lang("Delete")); |
---|
197 | $this->template->set_var("private", lang("Private")); |
---|
198 | $this->template->set_var("remove", lang("Remove")); |
---|
199 | $this->template->set_var("cancel", lang("Cancel")); |
---|
200 | |
---|
201 | if($acl_app=='contactcenter') { |
---|
202 | $this->template->set_var("private_invisible", "style='display:none'"); |
---|
203 | } |
---|
204 | else { |
---|
205 | $this->template->set_var("add_invisible", ""); |
---|
206 | $this->template->set_var("private_invisible", ""); |
---|
207 | } |
---|
208 | |
---|
209 | if ($submit) |
---|
210 | $this->template->set_var('errors',lang('ACL grants have been updated')); |
---|
211 | |
---|
212 | $common_hidden_vars = |
---|
213 | ' <input type="hidden" name="owner" value="'.$owner.'">'."\n" |
---|
214 | . ' <input type="hidden" name="acl_app" value="'.$acl_app.'">'."\n"; |
---|
215 | |
---|
216 | $var = Array( |
---|
217 | 'errors' => '', |
---|
218 | 'title' => '<br>', |
---|
219 | 'action_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app=' . $acl_app), |
---|
220 | 'bg_color' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
221 | 'submit_lang' => lang('Ok'), |
---|
222 | 'common_hidden_vars_form' => $common_hidden_vars |
---|
223 | ); |
---|
224 | |
---|
225 | $this->template->set_var($var); |
---|
226 | $this->template->set_var('common_hidden_vars',$common_hidden_vars); |
---|
227 | |
---|
228 | // begin jakjr |
---|
229 | foreach($just_owner_array as $just_owner_array) { |
---|
230 | $id = $just_owner_array['location']; |
---|
231 | $rights = $this->acl->get_rights($id,$GLOBALS['phpgw_info']['flags']['currentapp']); |
---|
232 | $acct->get_account_name($id, $lid, $fname, $lname); |
---|
233 | |
---|
234 | if (($acct->get_type($id) == 'u') && ($owner != $id && $rights)) |
---|
235 | { |
---|
236 | $user_array['name'] = $fname . ' ' . $lname; |
---|
237 | $this->display_option('u_',$id,$user_array['name'],$is_group); |
---|
238 | $processed[] = $id; |
---|
239 | } |
---|
240 | else if(($acl_app == 'calendar') && ($acct->get_type($id) == 'g') && ($owner != $id && $rights)) |
---|
241 | { |
---|
242 | $group_array['name'] = '(G) ' . $fname; |
---|
243 | $this->display_option('g_',$id,$group_array['name'],$is_group); |
---|
244 | $processed[] = $id; |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | unset($acct); |
---|
249 | //end jakjr |
---|
250 | |
---|
251 | $extra_parms = 'menuaction=preferences.uiaclprefs.index' |
---|
252 | . '&acl_app=' . $acl_app . '&owner='.$owner; |
---|
253 | |
---|
254 | $var = Array( |
---|
255 | 'search' => lang('search'), |
---|
256 | 'processed' => urlencode(serialize($processed)) |
---|
257 | ); |
---|
258 | |
---|
259 | $this->template->set_var($var); |
---|
260 | $this->template->pfp('out','preferences'); |
---|
261 | } |
---|
262 | |
---|
263 | |
---|
264 | function check_acl($label,$id,$acl,$rights,$right,$is_group=False) { |
---|
265 | $this->template->set_var($acl,$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id.'_'.$right.']'); |
---|
266 | $rights_set = (($rights & $right)?'':'disabled'); |
---|
267 | $this->template->set_var($acl.'_selected',$rights_set); |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | function display_option($label,$id,$name,$is_group) |
---|
272 | { |
---|
273 | |
---|
274 | $rights = $this->acl->get_rights($id,$GLOBALS['phpgw_info']['flags']['currentapp']); |
---|
275 | $this->template->set_var('user',$name); |
---|
276 | $this->template->set_var('id',$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id); |
---|
277 | |
---|
278 | |
---|
279 | // vv This is new |
---|
280 | $grantors = $this->acl->get_ids_for_location($id,$rights,$GLOBALS['phpgw_info']['flags']['currentapp']); |
---|
281 | |
---|
282 | while(@$grantors && list($key,$grantor) = each($grantors)) |
---|
283 | { |
---|
284 | if($GLOBALS['phpgw']->accounts->get_type($grantor) == 'g') |
---|
285 | { |
---|
286 | $is_group_set = True; |
---|
287 | } |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | $this->check_acl($label,$id,'read',$rights,PHPGW_ACL_READ,($is_group_set && ($rights & PHPGW_ACL_READ) && !$is_group?$is_group_set:False)); |
---|
292 | $this->check_acl($label,$id,'add',$rights,PHPGW_ACL_ADD,($is_group_set && ($rights & PHPGW_ACL_ADD && !$is_group)?$is_group_set:False)); |
---|
293 | $this->check_acl($label,$id,'edit',$rights,PHPGW_ACL_EDIT,($is_group_set && ($rights & PHPGW_ACL_EDIT && !$is_group)?$is_group_set:False)); |
---|
294 | $this->check_acl($label,$id,'delete',$rights,PHPGW_ACL_DELETE,($is_group_set && ($rights & PHPGW_ACL_DELETE && !$is_group)?$is_group_set:False)); |
---|
295 | $this->check_acl($label,$id,'private',$rights,PHPGW_ACL_PRIVATE,$is_group); |
---|
296 | |
---|
297 | $this->check_acl($label,$id,'custom_1',$rights,PHPGW_ACL_CUSTOM_1,($is_group_set && ($rights & PHPGW_ACL_CUSTOM_1) && !$is_group?$is_group_set:False)); |
---|
298 | $this->check_acl($label,$id,'custom_2',$rights,PHPGW_ACL_CUSTOM_2,($is_group_set && ($rights & PHPGW_ACL_CUSTOM_2) && !$is_group?$is_group_set:False)); |
---|
299 | $this->check_acl($label,$id,'custom_3',$rights,PHPGW_ACL_CUSTOM_3,($is_group_set && ($rights & PHPGW_ACL_CUSTOM_3) && !$is_group?$is_group_set:False)); |
---|
300 | |
---|
301 | |
---|
302 | $this->template->parse('hiddens','acl_hidden',True); |
---|
303 | $this->template->parse('row','acl_row',True); |
---|
304 | |
---|
305 | } |
---|
306 | |
---|
307 | } |
---|
308 | ?> |
---|