source: trunk/preferences/inc/class.uiaclprefs2.inc.php @ 2

Revision 2, 9.2 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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 uiaclprefs2
14        {
15                var $acl;               
16                var $template;
17
18                var $public_functions = array('index' => True);
19
20                function uiaclprefs2()
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                                for($i=0;$i<count($to_remove);$i++)                             
104                                        $this->acl->delete($GLOBALS['phpgw_info']['flags']['currentapp'],$to_remove[$i]);
105                               
106                                /* Group records */
107                                $group_variable = $_POST['g_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
108
109                                if (!$group_variable)                           
110                                        $group_variable = array();
111                               
112                                @reset($group_variable);
113                                $totalacl = array();
114                                while(list($rowinfo,$perm) = each($group_variable))     {
115                                        list($group_id,$rights) = split('_',$rowinfo);
116                                        $totalacl[$group_id] += $rights;
117                                }
118                                @reset($totalacl);
119                                while(list($group_id,$rights) = @each($totalacl))       {
120                                        if($is_group)
121                                                $rights &= ~PHPGW_ACL_PRIVATE;
122                                        $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$group_id,$rights);
123                                }
124
125                                /* User records */
126                                $user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
127
128                                if (!$user_variable)                           
129                                        $user_variable = array();
130                               
131                                @reset($user_variable);
132                                $totalacl = array();
133                                while(list($rowinfo,$perm) = each($user_variable))      {
134                                        list($user_id,$rights) = split('_',$rowinfo);
135                                        $totalacl[$user_id] += $rights;
136                                }
137                               
138                                @reset($totalacl);
139                                while(list($user_id,$rights) = @each($totalacl)) {
140                                        if($is_group)                                   
141                                                $rights &= ~ PHPGW_ACL_PRIVATE;                                 
142                                       
143                                        $this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$user_id,$rights);
144                                }
145                               
146                                $this->acl->save_repository();
147                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('../'.$GLOBALS['phpgw_info']['flags']['currentapp'].'/index.php'));
148                        }
149
150                        $processed = Array();
151                       
152                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('%1 - Preferences',$GLOBALS['phpgw_info']['apps'][$acl_app]['title']).' - '.lang('acl').': '.$owner_name;
153                       
154                        if(!@is_object($GLOBALS['phpgw']->js))  {
155                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
156                        }                       
157                       
158                        $GLOBALS['phpgw']->common->phpgw_header();
159                        echo parse_navbar();
160                       
161                        $this->template = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences'));
162                        $templates = Array (
163                                        'preferences' => 'preference_acl.tpl',                         
164                                        'acl_row'     => 'preference_acl_row.tpl',
165                                        'acl_hidden'  => 'preference_acl_hidden.tpl'
166                                );
167                       
168                        $this->template->set_file($templates);
169
170                        if ($submit)
171                                $this->template->set_var('errors',lang('ACL grants have been updated'));
172
173                        $common_hidden_vars =
174                                  '     <input type="hidden" name="owner" value="'.$owner.'">'."\n"
175                                . '     <input type="hidden" name="acl_app" value="'.$acl_app.'">'."\n";
176
177                        $var = Array(
178                                'errors'      => '',
179                                'title'       => '<br>',
180                                'action_url'  => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs2.index&acl_app=' . $acl_app),
181                                'bg_color'    => $GLOBALS['phpgw_info']['theme']['th_bg'],
182                                'submit_lang' => lang('Ok'),
183                                'common_hidden_vars_form' => $common_hidden_vars
184                        );
185
186                        $this->template->set_var($var);
187                        $this->template->set_var('common_hidden_vars',$common_hidden_vars);
188                                               
189                        // begin jakjr
190                        foreach($just_owner_array as $just_owner_array) {
191                                $id = $just_owner_array['location'];
192                                $rights = $this->acl->get_rights($id,$GLOBALS['phpgw_info']['flags']['currentapp']);
193                                $acct->get_account_name($id, $lid, $fname, $lname);
194                               
195                                if (($acct->get_type($id) == 'u') && ($owner != $id && $rights))
196                                {
197                                        $user_array['name'] = $fname . ' ' . $lname;
198                                        $this->display_option('u_',$id,$user_array['name'],$is_group);
199                                        $processed[] = $id;
200                                }       
201                                //else
202                                //{
203                        //              $group_array['name'] = '(G) ' . $fname;
204                        //              $this->display_option('g_',$id,$group_array['name'],$is_group);
205                        //              $processed[] = $id;
206                        //      }       
207                        }
208                       
209                        unset($acct);
210                        //end jakjr
211                       
212                        $extra_parms = 'menuaction=preferences.uiaclprefs.index'
213                                . '&acl_app=' . $acl_app . '&owner='.$owner;
214
215                        $var = Array(
216                                'search'       => lang('search'),
217                                'processed'    => urlencode(serialize($processed))
218                        );
219
220                        $this->template->set_var($var);
221                        $this->template->pfp('out','preferences');
222                }
223
224               
225                function check_acl($label,$id,$acl,$rights,$right,$is_group=False)      {
226                        $this->template->set_var($acl,$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id.'_'.$right.']');
227                        $rights_set = (($rights & $right)?'':'disabled');
228                        $this->template->set_var($acl.'_selected',$rights_set);
229                }               
230               
231       
232                function display_option($label,$id,$name,$is_group)
233                {
234                       
235                        $rights = $this->acl->get_rights($id,$GLOBALS['phpgw_info']['flags']['currentapp']);
236                        $this->template->set_var('user',$name);
237                        $this->template->set_var('id',$label.$GLOBALS['phpgw_info']['flags']['currentapp'].'['.$id);                                           
238                                               
239                       
240                        // vv This is new
241                        $grantors = $this->acl->get_ids_for_location($id,$rights,$GLOBALS['phpgw_info']['flags']['currentapp']);
242                       
243                        while(@$grantors && list($key,$grantor) = each($grantors))
244                        {
245                                if($GLOBALS['phpgw']->accounts->get_type($grantor) == 'g')
246                                {
247                                        $is_group_set = True;
248                                }
249                        }                       
250
251                                               
252                        $this->check_acl($label,$id,'read',$rights,PHPGW_ACL_READ,($is_group_set && ($rights & PHPGW_ACL_READ) && !$is_group?$is_group_set:False));
253                        $this->check_acl($label,$id,'add',$rights,PHPGW_ACL_ADD,($is_group_set && ($rights & PHPGW_ACL_ADD && !$is_group)?$is_group_set:False));
254                        $this->check_acl($label,$id,'edit',$rights,PHPGW_ACL_EDIT,($is_group_set && ($rights & PHPGW_ACL_EDIT && !$is_group)?$is_group_set:False));
255                        $this->check_acl($label,$id,'delete',$rights,PHPGW_ACL_DELETE,($is_group_set && ($rights & PHPGW_ACL_DELETE && !$is_group)?$is_group_set:False));
256                        $this->check_acl($label,$id,'private',$rights,PHPGW_ACL_PRIVATE,$is_group);
257
258                        $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));
259                        $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));
260                        $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));
261                       
262                       
263                        $this->template->parse('hiddens','acl_hidden',True);                   
264                        $this->template->parse('row','acl_row',True);   
265                       
266                }
267                                       
268        }       
269?>
Note: See TracBrowser for help on using the repository browser.