source: trunk/phpgwapi/inc/class.applications.inc.php @ 6847

Revision 6847, 9.7 KB checked in by gustavo, 12 years ago (diff)

Ticket #2977 - Modulo rest estava ativo aparecendo nas aplicações dos gerentes

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare API - Applications manager functions                          *
4        * This file written by Mark Peters <skeeter@phpgroupware.org>              *
5        * Copyright (C) 2001 Mark Peters                                           *
6        * ------------------------------------------------------------------------ *
7        * This library is part of the eGroupWare API                               *
8        * http://www.egroupware.org/api                                            *
9        * ------------------------------------------------------------------------ *
10        * This library is free software; you can redistribute it and/or modify it  *
11        * under the terms of the GNU Lesser General Public License as published by *
12        * the Free Software Foundation; either version 2.1 of the License,         *
13        * or any later version.                                                    *
14        * This library is distributed in the hope that it will be useful, but      *
15        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
16        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
17        * See the GNU Lesser General Public License for more details.              *
18        * You should have received a copy of the GNU Lesser General Public License *
19        * along with this library; if not, write to the Free Software Foundation,  *
20        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
21        \**************************************************************************/
22
23
24        /*!
25        @class applications
26        @abstract functions for managing and installing apps
27        @discussion Author: skeeter
28        */
29        class applications
30        {
31                var $account_id;
32                var $data = Array();
33                var $db;
34                var $public_functions = array(
35                        'list_methods' => True,
36                        'read'         => True
37                );
38                var $xmlrpc_methods = array();
39
40                /**************************************************************************\
41                * Standard constructor for setting $this->account_id                       *
42                \**************************************************************************/
43
44                /*!
45                @function applications
46                @abstract standard constructor for setting $this->account_id
47                @param $account_id account id
48                */
49                function applications($account_id = '')
50                {
51                        $this->db = $GLOBALS['phpgw']->db;
52                        $this->account_id = get_account_id($account_id);
53
54                        $this->xmlrpc_methods[] = array(
55                                'name'        => 'read',
56                                'description' => 'Return a list of applications the current user has access to'
57                        );
58                }
59
60                function NOT_list_methods($_type='xmlrpc')
61                {
62                        /*
63                          This handles introspection or discovery by the logged in client,
64                          in which case the input might be an array.  The server always calls
65                          this function to fill the server dispatch map using a string.
66                        */
67                        if (is_array($_type))
68                        {
69                                $_type = $_type['type'] ? $_type['type'] : $_type[0];
70                        }
71                        switch($_type)
72                        {
73                                case 'xmlrpc':
74                                        $xml_functions = array(
75                                                'read' => array(
76                                                        'function'  => 'read',
77                                                        'signature' => array(array(xmlrpcStruct)),
78                                                        'docstring' => lang('Returns struct of users application access')
79                                                ),
80                                                'list_methods' => array(
81                                                        'function'  => 'list_methods',
82                                                        'signature' => array(array(xmlrpcStruct,xmlrpcString)),
83                                                        'docstring' => lang('Read this list of methods.')
84                                                )
85                                        );
86                                        return $xml_functions;
87                                        break;
88                                case 'soap':
89                                        return $this->soap_functions;
90                                        break;
91                                default:
92                                        return array();
93                                        break;
94                        }
95                }
96
97                /**************************************************************************\
98                * These are the standard $this->account_id specific functions              *
99                \**************************************************************************/
100
101                /*!
102                @function read_repository
103                @abstract read from repository
104                @discussion private should only be called from withing this class
105                */
106                function read_repository()
107                {
108                        if (!isset($GLOBALS['phpgw_info']['apps']) ||
109                                !is_array($GLOBALS['phpgw_info']['apps']))
110                        {
111                                $this->read_installed_apps();
112                        }
113                        $this->data = Array();
114                        if(!$this->account_id)
115                        {
116                                return False;
117                        }
118                        $apps = $GLOBALS['phpgw']->acl->get_user_applications($this->account_id);
119                        foreach($GLOBALS['phpgw_info']['apps'] as $app => $data)
120                        {
121                                if (isset($apps[$app]) && $apps[$app])
122                                {
123                                        $this->data[$app] = array(
124                                                'title'   => $GLOBALS['phpgw_info']['apps'][$app]['title'],
125                                                'name'    => $app,
126                                                'enabled' => True,
127                                                'status'  => $GLOBALS['phpgw_info']['apps'][$app]['status'],
128                                                'id'      => $GLOBALS['phpgw_info']['apps'][$app]['id']
129                                        );
130                                }
131                        }
132                        return $this->data;
133                }
134
135                /*!
136                @function read()
137                @abstract read from the repository
138                @discussion pubic function that is used to determine what apps a user has rights to
139                */
140                function read()
141                {
142                        if (!count($this->data))
143                        {
144                                $this->read_repository();
145                        }
146                        return $this->data;
147                }
148                /*!
149                @function add
150                @abstract add an app to a user profile
151                @discussion
152                @param $apps array containing apps to add for a user
153                */
154                function add($apps)
155                {
156                        if(is_array($apps))
157                        {
158                                foreach($apps as $app)
159                                {
160                                        $this->data[$app] = array(
161                                                'title'   => $GLOBALS['phpgw_info']['apps'][$app]['title'],
162                                                'name'    => $app,
163                                                'enabled' => True,
164                                                'status'  => $GLOBALS['phpgw_info']['apps'][$app]['status'],
165                                                'id'      => $GLOBALS['phpgw_info']['apps'][$app]['id']
166                                        );
167                                }
168                        }
169                        elseif(gettype($apps))
170                        {
171                                $this->data[$apps] = array(
172                                        'title'   => $GLOBALS['phpgw_info']['apps'][$apps]['title'],
173                                        'name'    => $apps,
174                                        'enabled' => True,
175                                        'status'  => $GLOBALS['phpgw_info']['apps'][$apps]['status'],
176                                        'id'      => $GLOBALS['phpgw_info']['apps'][$apps]['id']
177                                );
178                        }
179                        return $this->data;
180                }
181                /*!
182                @function delete
183                @abstract delete an app from a user profile
184                @discussion
185                @param $appname appname to remove
186                */
187                function delete($appname)
188                {
189                        if($this->data[$appname])
190                        {
191                                unset($this->data[$appname]);
192                        }
193                        return $this->data;
194                }
195                /*!
196                @function update_data
197                @abstract update the array(?)
198                @discussion
199                @param $data update the repository array(?)
200                */
201                function update_data($data)
202                {
203                        $this->data = $data;
204                        return $this->data;
205                }
206                /*!
207                @function save_repository()
208                @abstract save the repository
209                @discussion
210                */
211                function save_repository()
212                {
213                        $num_rows = $GLOBALS['phpgw']->acl->delete_repository("%%", 'run', $this->account_id);
214                        foreach($this->data as $app => $data)
215                        {
216                                if(!$this->is_system_enabled($app))
217                                {
218                                        continue;
219                                }
220                                $GLOBALS['phpgw']->acl->add_repository($app,'run',$this->account_id,1);
221                        }
222                        return $this->data;
223                }
224
225                /**************************************************************************\
226                * These are the non-standard $this->account_id specific functions          *
227                \**************************************************************************/
228
229                function app_perms()
230                {
231                        if (!count($this->data))
232                        {
233                                $this->read_repository();
234                        }
235                        foreach ($this->data as $app => $data)
236                        {
237                                $apps[] = $this->data[$app]['name'];
238                        }
239                        return $apps;
240                }
241
242                function read_account_specific()
243                {
244                        if (!is_array($GLOBALS['phpgw_info']['apps']))
245                        {
246                                $this->read_installed_apps();
247                        }
248                        if ($app_list = $GLOBALS['phpgw']->acl->get_app_list_for_id('run',1,$this->account_id))
249                        {
250                                foreach($app_list as $app)
251                                {
252                                        if ($this->is_system_enabled($app))
253                                        {
254                                                $this->data[$app] = array(
255                                                        'title'   => $GLOBALS['phpgw_info']['apps'][$app]['title'],
256                                                        'name'    => $app,
257                                                        'enabled' => True,
258                                                        'status'  => $GLOBALS['phpgw_info']['apps'][$app]['status'],
259                                                        'id'      => $GLOBALS['phpgw_info']['apps'][$app]['id']
260                                                );
261                                        }
262                                }
263                        }
264                        return $this->data;
265                }
266
267                /**************************************************************************\
268                * These are the generic functions. Not specific to $this->account_id       *
269                \**************************************************************************/
270
271                /*!
272                @function read_installed_apps()
273                @abstract populate array with a list of installed apps
274                */
275                function read_installed_apps()
276                {
277                        //jakjr: so vai ao banco, caso o array de apps esteja vazio.
278                        if (empty($GLOBALS['phpgw_info']['apps']))
279                        {
280                                $this->db->query('select * from phpgw_applications where app_enabled != 3 and app_name!= \'rest\' order by app_order asc',__LINE__,__FILE__);
281                                if($this->db->num_rows())
282                                {
283                                        while ($this->db->next_record())
284                                        {
285                                                $title = $app_name = $this->db->f('app_name');
286
287                                                if (@is_array($GLOBALS['phpgw_info']['user']['preferences']) &&
288                                                    ($t = lang($app_name)) != $app_name.'*')
289                                                {
290                                                        $title = $t;
291                                                }
292                                                $GLOBALS['phpgw_info']['apps'][$this->db->f('app_name')] = Array(
293                                                        'title'   => $title,
294                                                        'name'    => $this->db->f('app_name'),
295                                                        'enabled' => True,
296                                                        'status'  => $this->db->f('app_enabled'),
297                                                        'id'      => (int)$this->db->f('app_id'),
298                                                        'order'   => (int)$this->db->f('app_order'),
299                                                        'version' => $this->db->f('app_version')
300                                                );
301                                        }
302                                }
303                        }
304                }
305                /*!
306                @function is_system_enabled
307                @abstract check if an app is enabled
308                @param $appname name of the app to check for
309                */
310                function is_system_enabled($appname)
311                {
312                        if(!is_array($GLOBALS['phpgw_info']['apps']))
313                        {
314                                $this->read_installed_apps();
315                        }
316                        if ($GLOBALS['phpgw_info']['apps'][$appname]['enabled'])
317                        {
318                                return True;
319                        }
320                        else
321                        {
322                                return False;
323                        }
324                }
325
326                function id2name($id)
327                {
328                        foreach($GLOBALS['phpgw_info']['apps'] as $appname => $app)
329                        {
330                                if((int)$app['id'] == (int)$id)
331                                {
332                                        return $appname;
333                                }
334                        }
335                        return '';
336                }
337
338                function name2id($appname)
339                {
340                        if(is_array($GLOBALS['phpgw_info']['apps'][$appname]))
341                        {
342                                return $GLOBALS['phpgw_info']['apps'][$appname]['id'];
343                        }
344                        return 0;
345                }
346        }
347?>
Note: See TracBrowser for help on using the repository browser.