source: trunk/preferences/inc/class.uiaclprefs.inc.php @ 7673

Revision 7673, 10.8 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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                                $to_remove_count = count($to_remove);
116                                for($i=0;$i<$to_remove_count;++$i) {
117                                       
118                                        if(!array_key_exists((int)$to_remove[$i],$keys_to_keep)) {
119                                                $this->acl->persist_shared_groups($to_remove[$i]);
120                                        }               
121                                        $this->acl->delete($GLOBALS['phpgw_info']['flags']['currentapp'],$to_remove[$i]);
122                                }
123                               
124                                /* Group records */
125                                //$group_variable = $_POST['g_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
126
127                                if (!$group_variable)                           
128                                        $group_variable = array();
129                               
130                                @reset($group_variable);
131                                $totalacl = array();
132                                while(list($rowinfo,$perm) = each($group_variable))     {
133                                        list($group_id,$rights) = preg_split('/_/',$rowinfo);
134                                        $totalacl[$group_id] += $rights;
135                                }
136                                @reset($totalacl);
137                                while(list($group_id,$rights) = @each($totalacl))       {
138                                        if($is_group)
139                                                $rights &= ~PHPGW_ACL_PRIVATE;
140                                        if(array_key_exists($user_id,$keys_to_keep))
141                                                if(($rights & 1) == 0) {
142                                                        $this->acl->persist_shared_groups($user_id);
143                                                }
144                                        $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$group_id,$rights);
145                                }
146
147                                /* User records */
148                                //$user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
149
150                                if (!$user_variable)                           
151                                        $user_variable = array();
152                               
153                                @reset($user_variable);
154                                $totalacl = array();
155                                while(list($rowinfo,$perm) = each($user_variable))      {
156                                        list($user_id,$rights) = preg_split('/_/',$rowinfo);
157                                        $totalacl[$user_id] += $rights;
158                                }
159                               
160                                @reset($totalacl);
161                                while(list($user_id,$rights) = @each($totalacl)) {
162                                        if($is_group)                                   
163                                                $rights &= ~ PHPGW_ACL_PRIVATE;                                 
164                                       
165                                        $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$user_id,$rights);
166                                }
167                               
168                                $this->acl->save_repository();
169                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('../'.$GLOBALS['phpgw_info']['flags']['currentapp'].'/index.php'));
170                        }
171
172                        $processed = Array();
173                       
174                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('%1 - Preferences',$GLOBALS['phpgw_info']['apps'][$acl_app]['title']).' - '.lang('acl').': '.$owner_name;
175                       
176                        if(!@is_object($GLOBALS['phpgw']->js))  {
177                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
178                        }                       
179                       
180                        $GLOBALS['phpgw']->common->phpgw_header();
181                        echo parse_navbar();
182                       
183                        $this->template = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences'));
184                        $templates = Array (
185                                        'preferences' => 'preference_acl.tpl',                         
186                                        'acl_row'     => 'preference_acl_row.tpl',
187                                        'acl_hidden'  => 'preference_acl_hidden.tpl'
188                                );
189                       
190                        $this->template->set_file($templates);
191
192                        $this->template->set_var("users_list", lang("Users List"));
193                        $this->template->set_var("attributes", lang("Attributes"));
194                        $this->template->set_var("read", lang("Read"));
195                        $this->template->set_var("add", lang("Add"));
196                        $this->template->set_var("edit", lang("Edit"));
197                        $this->template->set_var("delete", lang("Delete"));
198                        $this->template->set_var("private", lang("Private"));
199                        $this->template->set_var("remove", lang("Remove"));
200                        $this->template->set_var("cancel", lang("Cancel"));
201                       
202                        if($acl_app=='contactcenter') {
203                                $this->template->set_var("private_invisible", "style='display:none'");                         
204                        }
205                        else {
206                                $this->template->set_var("add_invisible", "");
207                                $this->template->set_var("private_invisible", "");                             
208                        }
209
210                        if ($submit)
211                                $this->template->set_var('errors',lang('ACL grants have been updated'));
212
213                        $common_hidden_vars =
214                                  '     <input type="hidden" name="owner" value="'.$owner.'">'."\n"
215                                . '     <input type="hidden" name="acl_app" value="'.$acl_app.'">'."\n";
216
217                        $var = Array(
218                                'errors'      => '',
219                                'title'       => '<br>',
220                                'action_url'  => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app=' . $acl_app),
221                                'bg_color'    => $GLOBALS['phpgw_info']['theme']['th_bg'],
222                                'submit_lang' => lang('Ok'),
223                                'common_hidden_vars_form' => $common_hidden_vars
224                        );
225
226                        $this->template->set_var($var);
227                        $this->template->set_var('common_hidden_vars',$common_hidden_vars);
228                                               
229                        // begin jakjr
230                        foreach($just_owner_array as $just_owner_array) {
231                                $id = $just_owner_array['location'];
232                                $rights = $this->acl->get_rights($id,$GLOBALS['phpgw_info']['flags']['currentapp']);
233                                $acct->get_account_name($id, $lid, $fname, $lname);
234                               
235                                if (($acct->get_type($id) == 'u') && ($owner != $id && $rights))
236                                {
237                                        $user_array['name'] = $fname . ' ' . $lname;
238                                        $this->display_option('u_',$id,$user_array['name'],$is_group);
239                                        $processed[] = $id;
240                                }       
241                                else if(($acl_app == 'calendar') && ($acct->get_type($id) == 'g') && ($owner != $id && $rights))
242                                {
243                                        $group_array['name'] = '(G) ' . $fname;
244                                        $this->display_option('g_',$id,$group_array['name'],$is_group);
245                                        $processed[] = $id;
246                                }       
247                        }
248                       
249                        unset($acct);
250                        //end jakjr
251                       
252                        $extra_parms = 'menuaction=preferences.uiaclprefs.index'
253                                . '&acl_app=' . $acl_app . '&owner='.$owner;
254
255                        $var = Array(
256                                'search'       => lang('search'),
257                                'processed'    => urlencode(serialize($processed))
258                        );
259
260                        $this->template->set_var($var);
261                        $this->template->pfp('out','preferences');
262                }
263
264               
265                function check_acl($label,$id,$acl,$rights,$right,$is_group=False)      {
266                        $this->template->set_var($acl,$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id.'_'.$right.']');
267                        $rights_set = (($rights & $right)?'':'disabled');
268                        $this->template->set_var($acl.'_selected',$rights_set);
269                }               
270               
271       
272                function display_option($label,$id,$name,$is_group)
273                {
274                       
275                        $rights = $this->acl->get_rights($id,$GLOBALS['phpgw_info']['flags']['currentapp']);
276                        $this->template->set_var('user',$name);
277                        $this->template->set_var('id',$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id);                                           
278                                               
279                       
280                        // vv This is new
281                        $grantors = $this->acl->get_ids_for_location($id,$rights,$GLOBALS['phpgw_info']['flags']['currentapp']);
282                       
283                        while(@$grantors && list($key,$grantor) = each($grantors))
284                        {
285                                if($GLOBALS['phpgw']->accounts->get_type($grantor) == 'g')
286                                {
287                                        $is_group_set = True;
288                                }
289                        }                       
290
291                                               
292                        $this->check_acl($label,$id,'read',$rights,PHPGW_ACL_READ,($is_group_set && ($rights & PHPGW_ACL_READ) && !$is_group?$is_group_set:False));
293                        $this->check_acl($label,$id,'add',$rights,PHPGW_ACL_ADD,($is_group_set && ($rights & PHPGW_ACL_ADD && !$is_group)?$is_group_set:False));
294                        $this->check_acl($label,$id,'edit',$rights,PHPGW_ACL_EDIT,($is_group_set && ($rights & PHPGW_ACL_EDIT && !$is_group)?$is_group_set:False));
295                        $this->check_acl($label,$id,'delete',$rights,PHPGW_ACL_DELETE,($is_group_set && ($rights & PHPGW_ACL_DELETE && !$is_group)?$is_group_set:False));
296                        $this->check_acl($label,$id,'private',$rights,PHPGW_ACL_PRIVATE,$is_group);
297
298                        $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));
299                        $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));
300                        $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));
301                       
302                       
303                        $this->template->parse('hiddens','acl_hidden',True);                   
304                        $this->template->parse('row','acl_row',True);   
305                       
306                }
307                                       
308        }       
309?>
Note: See TracBrowser for help on using the repository browser.