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

Revision 6057, 10.7 KB checked in by marcosw, 12 years ago (diff)

Ticket #2398 - Compatibilizacao com PHP-5.3 em alguns módulos do expresso

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]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        {
[1409]15                var $acl;               
[2]16                var $template;
17
18                var $public_functions = array('index' => True);
19
20                function uiaclprefs()
21                {
22                        $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
[1409]23                       
[2]24                }
[1409]25               
[2]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                        }
[1409]40                                               
41                        $_SESSION['acl_app'] = $acl_app;
[2]42
[1409]43                       
[2]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'];
[1409]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')                 
[2]76                                $owner_name = lang('Group').' ('.$owner_name.')';
[1409]77                                               
[2]78                        $this->acl = CreateObject('phpgwapi.acl',(int)$owner);
[1409]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
[2]97
[1409]98                        if ($_POST['submit'])   {
[2]99                                $processed = $_POST['processed'];
[1409]100                                                               
[2]101                                $to_remove = unserialize(urldecode($processed));
102
[1409]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                                        }               
[2]120                                        $this->acl->delete($GLOBALS['phpgw_info']['flags']['currentapp'],$to_remove[$i]);
121                                }
[1409]122                               
[2]123                                /* Group records */
[1409]124                                //$group_variable = $_POST['g_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
[2]125
[1409]126                                if (!$group_variable)                           
[2]127                                        $group_variable = array();
[1409]128                               
[2]129                                @reset($group_variable);
130                                $totalacl = array();
[1409]131                                while(list($rowinfo,$perm) = each($group_variable))     {
[6057]132                                        list($group_id,$rights) = preg_split('/_/',$rowinfo);
[2]133                                        $totalacl[$group_id] += $rights;
134                                }
135                                @reset($totalacl);
[1409]136                                while(list($group_id,$rights) = @each($totalacl))       {
[2]137                                        if($is_group)
138                                                $rights &= ~PHPGW_ACL_PRIVATE;
[1409]139                                        if(array_key_exists($user_id,$keys_to_keep))
140                                                if(($rights & 1) == 0) {
141                                                        $this->acl->persist_shared_groups($user_id);
142                                                }
[2]143                                        $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$group_id,$rights);
144                                }
145
146                                /* User records */
[1409]147                                //$user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
[2]148
[1409]149                                if (!$user_variable)                           
[2]150                                        $user_variable = array();
[1409]151                               
[2]152                                @reset($user_variable);
153                                $totalacl = array();
[1409]154                                while(list($rowinfo,$perm) = each($user_variable))      {
[6057]155                                        list($user_id,$rights) = preg_split('/_/',$rowinfo);
[2]156                                        $totalacl[$user_id] += $rights;
157                                }
[1409]158                               
[2]159                                @reset($totalacl);
[1409]160                                while(list($user_id,$rights) = @each($totalacl)) {
161                                        if($is_group)                                   
162                                                $rights &= ~ PHPGW_ACL_PRIVATE;                                 
163                                       
[2]164                                        $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$user_id,$rights);
165                                }
[1409]166                               
[2]167                                $this->acl->save_repository();
[1409]168                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('../'.$GLOBALS['phpgw_info']['flags']['currentapp'].'/index.php'));
[2]169                        }
170
171                        $processed = Array();
[1409]172                       
[2]173                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('%1 - Preferences',$GLOBALS['phpgw_info']['apps'][$acl_app]['title']).' - '.lang('acl').': '.$owner_name;
[1409]174                       
175                        if(!@is_object($GLOBALS['phpgw']->js))  {
176                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
177                        }                       
178                       
[2]179                        $GLOBALS['phpgw']->common->phpgw_header();
180                        echo parse_navbar();
[1409]181                       
182                        $this->template = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences'));
[2]183                        $templates = Array (
[1409]184                                        'preferences' => 'preference_acl.tpl',                         
185                                        'acl_row'     => 'preference_acl_row.tpl',
186                                        'acl_hidden'  => 'preference_acl_hidden.tpl'
187                                );
188                       
[2]189                        $this->template->set_file($templates);
190
[1409]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
[2]209                        if ($submit)
210                                $this->template->set_var('errors',lang('ACL grants have been updated'));
211
212                        $common_hidden_vars =
[1409]213                                  '     <input type="hidden" name="owner" value="'.$owner.'">'."\n"
[2]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'],
[1409]221                                'submit_lang' => lang('Ok'),
[2]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);
[1409]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))
[2]235                                {
[1409]236                                        $user_array['name'] = $fname . ' ' . $lname;
237                                        $this->display_option('u_',$id,$user_array['name'],$is_group);
238                                        $processed[] = $id;
239                                }       
[3404]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                                }       
[2]246                        }
[1409]247                       
248                        unset($acct);
249                        //end jakjr
250                       
[2]251                        $extra_parms = 'menuaction=preferences.uiaclprefs.index'
[1409]252                                . '&acl_app=' . $acl_app . '&owner='.$owner;
[2]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
[1409]263               
264                function check_acl($label,$id,$acl,$rights,$right,$is_group=False)      {
[2]265                        $this->template->set_var($acl,$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id.'_'.$right.']');
[1409]266                        $rights_set = (($rights & $right)?'':'disabled');
[2]267                        $this->template->set_var($acl.'_selected',$rights_set);
[1409]268                }               
269               
270       
271                function display_option($label,$id,$name,$is_group)
[2]272                {
[1409]273                       
[2]274                        $rights = $this->acl->get_rights($id,$GLOBALS['phpgw_info']['flags']['currentapp']);
[1409]275                        $this->template->set_var('user',$name);
276                        $this->template->set_var('id',$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id);                                           
277                                               
278                       
[2]279                        // vv This is new
280                        $grantors = $this->acl->get_ids_for_location($id,$rights,$GLOBALS['phpgw_info']['flags']['currentapp']);
[1409]281                       
[2]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                                }
[1409]288                        }                       
[2]289
[1409]290                                               
[2]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));
[1409]300                       
301                       
302                        $this->template->parse('hiddens','acl_hidden',True);                   
303                        $this->template->parse('row','acl_row',True);   
304                       
[2]305                }
[1409]306                                       
307        }       
[2]308?>
Note: See TracBrowser for help on using the repository browser.