source: contrib/ProjectManager/inc/class.uiroles.inc.php @ 3594

Revision 3594, 4.7 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado o módulo ProjectManager? para a comunidade

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * ProjectManager - Roles user interface
4 *
5 * @link http://www.egroupware.org
6 * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
7 * @package projectmanager
8 * @copyright (c) 2005 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
9 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
10 * @version $Id: class.uiroles.inc.php 24830 2007-12-17 22:41:34Z ralfbecker $
11 */
12
13include_once(PHPGW_INCLUDE_ROOT.'/projectmanager/inc/class.boprojectmanager.inc.php');
14include_once(PHPGW_INCLUDE_ROOT.'/etemplate/inc/class.uietemplate.inc.php');
15
16define('PHPGW_ACL_ROLES',PHPGW_ACL_EDIT);       // maybe this gets an own ACL later
17
18/**
19 * ProjectManager UI: roles
20 */
21class uiroles extends boprojectmanager 
22{
23        /**
24         * Functions to call via menuaction
25         *
26         * @var array
27         */
28        var $public_functions = array(
29                'roles' => true,
30        );
31        var $acl2id = array(
32                'read'   => PHPGW_ACL_READ,
33                'edit'   => PHPGW_ACL_EDIT,
34                'delete' => PHPGW_ACL_DELETE,
35                'add'    => PHPGW_ACL_ADD,
36                'budget' => PHPGW_ACL_BUDGET,
37                'edit_budget' => PHPGW_ACL_EDIT_BUDGET,
38        );
39        /**
40         * Instance of the boprojectmanger class
41         *
42         * @var boprojectmanager
43         */
44        var $project;
45
46        /**
47         * Constructor, calls the constructor of the extended class
48         *
49         * @return uiroles
50         */
51        function uiroles()
52        {
53                $this->boprojectmanager(null,'roles');
54        }
55       
56        /**
57         * Create and edit roles
58         *
59         * @param array $content=null
60         */
61        function roles($content=null)
62        {
63                $tpl =& new etemplate('projectmanager.roles');
64               
65                $pm_id = is_array($content) ? $content['pm_id'] : (int) $_REQUEST['pm_id'];
66               
67                $only = !!$pm_id;
68                if (!($project_rights = $this->check_acl(PHPGW_ACL_ROLES,$pm_id)) || !$this->is_admin)
69                {
70                        $only = $project_rights ? 1 : 0;
71                        $readonlys['1[pm_id]'] = true;
72                       
73                        if (!$project_rights && !$this->is_admin)
74                        {
75                                $readonlys['edit'] = $readonlys['apply'] = true;
76                        }
77                }
78                $role_to_edit = array('pm_id' => $only);
79                $js = 'window.focus();';
80
81                if (($content['save'] || $content['apply']) && (!$pm_id && $this->is_admin || $pm_id && $project_rights))
82                {
83                        if (!$content[1]['role_title'])
84                        {
85                                $role_to_edit = $content[1];
86                                $msg = lang('Title must not be empty');
87                        }
88                        else
89                        {
90                                $role = array(
91                                        'role_id'          => (int) $content[1]['role_id'],
92                                        'role_title'       => $content[1]['role_title'],
93                                        'role_description' => $content[1]['role_description'],
94                                        'pm_id'            => $content[1]['pm_id'] || !$this->is_admin ? $pm_id : 0,
95                                        'role_acl'         => 0,
96                                );
97                                foreach($this->acl2id as $acl => $id)
98                                {
99                                        if ($content[1]['acl_'.$acl]) $role['role_acl'] |= $id;
100                                }
101                                if ($this->roles->save($role) == 0)
102                                {
103                                        $msg = lang('Role saved');
104                                       
105                                        $js = 'opener.document.eTemplate.submit();';
106
107                                        if ($content['save']) $js .= 'window.close();';
108                                }
109                                else
110                                {
111                                        $msg = lang('Error: saving role !!!');
112                                }
113                        }
114                }
115                if ($content['delete'] || $content['edit'])
116                {
117                        list($role) = $content['delete'] ? each($content['delete']) : each($content['edit']);
118                        if(!($role = $this->roles->read($role)) ||
119                                $role['pm_id'] && !$this->check_acl(PHPGW_ACL_ROLES,$role['pm_id']) ||
120                                !$role['pm_id'] && !$this->is_admin)
121                        {
122                                $msg = lang('Permission denied !!!');
123                        }
124                        elseif ($content['delete'])
125                        {
126                                if ($this->roles->delete($role))
127                                {
128                                        $msg = lang('Role deleted');
129                                        $js = 'opener.document.eTemplate.submit();';
130                                }
131                                else
132                                {
133                                        $msg = lang('Error: deleting role !!!');
134                                }
135                        }
136                        else    // edit an existing role
137                        {
138                                $role_to_edit = $role;
139                                foreach($this->acl2id as $acl => $id)
140                                {
141                                        $role_to_edit['acl_'.$acl] = $role['role_acl'] & $id;
142                                }
143                        }
144                }
145                if (($view = !($pm_id && $project_rights) && !$this->is_admin))
146                {
147                        $readonlys['save'] = $readonlys['apply'] = true;
148                }
149                $content = array(
150                        'pm_id' => $pm_id,
151                        'msg'   => $msg,
152                        'view'  => !($pm_id && $project_rights) && !$this->is_admin,
153                        'js'    => '<script>'.$js.'</script>',
154                        1       => $role_to_edit,
155                );
156                $n = 2;
157                foreach((array)$this->roles->search(array(),false,'pm_id DESC,role_acl DESC','','',false,'AND',false,array('pm_id'=>array(0,$pm_id))) as $role)
158                {
159                        foreach($this->acl2id as $acl => $id)
160                        {
161                                $role['acl_'.$acl] = $role['role_acl'] & $id;
162                        }
163                        $content[$n++] = $role;
164                       
165                        $readonlys['delete['.$role['role_id'].']'] = $readonlys['edit['.$role['role_id'].']'] =
166                                !$role['pm_id'] && !$this->is_admin || $role['pm_id'] && !$this->check_acl(PHPGW_ACL_ROLES,$role['pm_id']);
167                }
168                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('projectmanager').' - '.lang('Add or edit roles and their ACL');
169                $tpl->exec('projectmanager.uiroles.roles',$content,array(
170                        'pm_id' => $this->query_list(),
171                ),$readonlys,array(
172                        'pm_id' => $pm_id,
173                        1       => array('role_id' => $content[1]['role_id']),
174                ),2);
175        }               
176}
Note: See TracBrowser for help on using the repository browser.