source: companies/celepar/admin/inc/class.uiapplications.inc.php @ 763

Revision 763, 14.7 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - administration                                              *
4  * http://www.egroupware.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 uiapplications
14        {
15                var $public_functions = array(
16                        'get_list' => True,
17                        'add'      => True,
18                        'edit'     => True,
19                        'delete'   => True,
20                        'register_all_hooks' => True
21                );
22
23                var $bo;
24                var $nextmatchs;
25
26                function uiapplications()
27                {
28                        $this->bo = CreateObject('admin.boapplications');
29                        $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
30                }
31
32                function get_list()
33                {
34                        if ($GLOBALS['phpgw']->acl->check('applications_access',1,'admin'))
35                        {
36                                $GLOBALS['phpgw']->redirect_link('/index.php');
37                        }
38                        $can_add    = !$GLOBALS['phpgw']->acl->check('applications_access',2,'admin');
39                        $can_edit   = !$GLOBALS['phpgw']->acl->check('applications_access',4,'admin');
40                        $can_delete = !$GLOBALS['phpgw']->acl->check('applications_access',8,'admin');
41                       
42                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Installed applications');
43                        if(!@is_object($GLOBALS['phpgw']->js))
44                        {
45                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
46                        }
47                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
48                        $GLOBALS['phpgw']->common->phpgw_header();
49                        echo parse_navbar();
50
51                        $GLOBALS['phpgw']->template->set_file(array('applications' => 'applications.tpl'));
52                        $GLOBALS['phpgw']->template->set_block('applications','list','list');
53                        $GLOBALS['phpgw']->template->set_block('applications','row','row');
54                        $GLOBALS['phpgw']->template->set_block('applications','add','add');
55                       
56                        $start = get_var('start',array('POST','GET'));
57                        $sort  = $_GET['sort'];
58                        $order = $_GET['order'];
59                        $offset = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
60
61                        $apps = $this->bo->get_list();
62                        $total = count($apps);
63
64                        $sort = $sort ? $sort : 'ASC';
65
66                        uasort($apps,create_function('$a,$b','return strcasecmp($a[\'title\'],$b[\'title\'])'.($sort != 'ASC' ? '* -1' : '').';'));
67
68                        if ($start && $offset)
69                        {
70                                $limit = $start + $offset;
71                        }
72                        elseif ($start && !$offset)
73                        {
74                                $limit = $start;
75                        }
76                        elseif(!$start && !$offset)
77                        {
78                                $limit = $total;
79                        }
80                        else
81                        {
82                                $start = 0;
83                                $limit = $offset;
84                        }
85
86                        if ($limit > $total)
87                        {
88                                $limit = $total;
89                        }
90
91                        $i = 0;
92                        $applications = array();
93                        while(list($app,$data) = @each($apps))
94                        {
95                                if($i >= $start && $i< $limit)
96                                {
97                                        $applications[$app] = $data;
98                                }
99                                $i++;
100                        }
101
102                        $GLOBALS['phpgw']->template->set_var('bg_color',$GLOBALS['phpgw_info']['theme']['bg_color']);
103                        $GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
104
105                        $GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($sort,'title','title','/index.php',lang('Title'),'&menuaction=admin.uiapplications.get_list'));
106                        $GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($total,$start));
107                        $GLOBALS['phpgw']->template->set_var('left',$this->nextmatchs->left('/index.php',$start,$total,'menuaction=admin.uiapplications.get_list'));
108                        $GLOBALS['phpgw']->template->set_var('right',$this->nextmatchs->right('index.php',$start,$total,'menuaction=admin.uiapplications.get_list'));
109
110                        $GLOBALS['phpgw']->template->set_var('lang_edit',lang('Edit'));
111                        $GLOBALS['phpgw']->template->set_var('lang_delete',lang('Delete'));
112                        $GLOBALS['phpgw']->template->set_var('lang_enabled',lang('Enabled'));
113
114                        $GLOBALS['phpgw']->template->set_var('new_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.add'));
115                        $GLOBALS['phpgw']->template->set_var('lang_note',lang('(To install new applications use<br><a href="setup/" target="setup">Setup</a> [Manage Applications] !!!)'));
116                        $GLOBALS['phpgw']->template->set_var('lang_add',lang('add'));
117
118                        foreach($applications as $app)
119                        {
120                                $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
121
122                                $GLOBALS['phpgw']->template->set_var('tr_color',$tr_color);
123                                $GLOBALS['phpgw']->template->set_var('name',$app['title']);
124
125                                $GLOBALS['phpgw']->template->set_var('edit',$can_edit ? '<a href="' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.edit&app_name=' . urlencode($app['name'])) . '&start='.$start.'"> ' . lang('Edit') . ' </a>' : '&nbsp;');
126                                $GLOBALS['phpgw']->template->set_var('delete',$can_delete ? '<a href="' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.delete&app_name=' . urlencode($app['name'])) . '&start='.$start.'"> ' . lang('Delete') . ' </a>' : '&nbsp;');
127
128                                if ($app['status'])
129                                {
130                                        $status = lang('Yes');
131                                }
132                                else
133                                {
134                                        $status = '<b>' . lang('No') . '</b>';
135                                }
136                                $GLOBALS['phpgw']->template->set_var('status',$status);
137
138                                $GLOBALS['phpgw']->template->parse('rows','row',True);
139                        }
140                        if ($can_add)
141                        {
142                                $GLOBALS['phpgw']->template->parse('addbutton','add');
143                        }
144                        else
145                        {
146                                $GLOBALS['phpgw']->template->set_var('addbutton','');
147                        }
148
149                        $GLOBALS['phpgw']->template->pparse('out','list');
150                }
151
152                function display_row($label, $value)
153                {
154                        $GLOBALS['phpgw']->template->set_var('tr_color',$this->nextmatchs->alternate_row_color());
155                        $GLOBALS['phpgw']->template->set_var('label',$label);
156                        $GLOBALS['phpgw']->template->set_var('value',$value);
157                        $GLOBALS['phpgw']->template->parse('rows','row',True);
158                }
159
160                function add()
161                {
162                        if ($GLOBALS['phpgw']->acl->check('applications_access',2,'admin'))
163                        {
164                                $GLOBALS['phpgw']->redirect_link('/index.php');
165                        }
166                        $start = get_var('start',array('POST','GET'));
167       
168                        $GLOBALS['phpgw']->template->set_file(array('application' => 'application_form.tpl'));
169                        $GLOBALS['phpgw']->template->set_block('application','form','form');
170                        $GLOBALS['phpgw']->template->set_block('application','row','row');
171                        $GLOBALS['phpgw']->template->set_block('form','delete_button');
172                        $GLOBALS['phpgw']->template->set_var('delete_button','');
173
174                        if ($_POST['cancel'])
175                        {
176                                $GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiapplications.get_list&start='.$start);
177                        }
178
179                        if ($_POST['save'])
180                        {
181                                $totalerrors = 0;
182
183                                $app_order    = $_POST['app_order'] ? $_POST['app_order'] : 0;
184                                $n_app_name   = chop($_POST['n_app_name']);
185                                $n_app_status = $_POST['n_app_status'];
186
187                                if ($this->bo->exists($n_app_name))
188                                {
189                                        $error[$totalerrors++] = lang('That application name already exists.');
190                                }
191                                if (preg_match("/\D/",$app_order))
192                                {
193                                        $error[$totalerrors++] = lang('That application order must be a number.');
194                                }
195                                if (!$n_app_name)
196                                {
197                                        $error[$totalerrors++] = lang('You must enter an application name.');
198                                }
199
200                                if (!$totalerrors)
201                                {
202                                        $this->bo->add(array(
203                                                'n_app_name'   => $n_app_name,
204                                                'n_app_status' => $n_app_status,
205                                                'app_order'    => $app_order
206                                        ));
207
208                                        $GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiapplications.get_list&start='.$start);
209                                        $GLOBALS['phpgw']->common->phpgw_exit();
210                                }
211                                else
212                                {
213                                        $GLOBALS['phpgw']->template->set_var('error','<p><center>' . $GLOBALS['phpgw']->common->error_list($error) . '</center><br>');
214                                }
215                        }
216                        else
217                        {       // else submit
218                                $GLOBALS['phpgw']->template->set_var('error','');
219                        }
220
221                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Add new application');
222                        if(!@is_object($GLOBALS['phpgw']->js))
223                        {
224                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
225                        }
226                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
227                        $GLOBALS['phpgw']->common->phpgw_header();
228                        echo parse_navbar();
229
230                        $GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
231
232                        $GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="start" value="'.$start.'">');
233                        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.add'));
234
235                        $this->display_row(lang('application name'),'<input name="n_app_name" value="' . $n_app_name . '">');
236
237                        if(!isset($n_app_status))
238                        {
239                                $n_app_status = 1;
240                        }
241
242                        $selected[$n_app_status] = ' selected';
243                        $status_html = '<option value="0"' . $selected[0] . '>' . lang('Disabled') . '</option>'
244                                . '<option value="1"' . $selected[1] . '>' . lang('Enabled') . '</option>'
245                                . '<option value="2"' . $selected[2] . '>' . lang('Enabled - Hidden from navbar') . '</option>'
246                                . '<option value="4"' . $selected[4] . '>' . lang('Enabled - Popup Window') . '</option>';
247                        $this->display_row(lang('Status'),'<select name="n_app_status">' . $status_html . '</select>');
248
249                        if (!$app_order)
250                        {
251                                $app_order = $this->bo->app_order();
252                        }
253
254                        $this->display_row(lang('Select which location this app should appear on the navbar, lowest (left) to highest (right)'),'<input name="app_order" value="' . $app_order . '">');
255
256                        $GLOBALS['phpgw']->template->set_var('lang_save_button',lang('Add'));
257                        $GLOBALS['phpgw']->template->set_var('lang_cancel_button',lang('Cancel'));
258                        $GLOBALS['phpgw']->template->pparse('phpgw_body','form');
259                }
260
261                function edit()
262                {
263                        if ($GLOBALS['phpgw']->acl->check('applications_access',4,'admin'))
264                        {
265                                $GLOBALS['phpgw']->redirect_link('/index.php');
266                        }
267                        $app_name = get_var('app_name',array('POST','GET'));
268                        $start = get_var('start',array('POST','GET'));
269
270                        $GLOBALS['phpgw']->template->set_file(array('application' => 'application_form.tpl'));
271                        $GLOBALS['phpgw']->template->set_block('application','form','form');
272                        $GLOBALS['phpgw']->template->set_block('application','row','row');
273
274                        if ($_POST['cancel'])
275                        {
276                                $GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiapplications.get_list&start='.$start);
277                        }
278                       
279                        if ($_POST['delete'])
280                        {
281                                return $this->delete();
282                        }
283
284                        if ($_POST['save'])
285                        {
286                                $totalerrors = 0;
287
288                                $app_order    = $_POST['app_order'] ? $_POST['app_order'] : 0;
289                                $n_app_status = $_POST['n_app_status'];
290
291                                if (! $totalerrors)
292                                {
293                                        $this->bo->save(array(
294                                                'n_app_status' => $n_app_status,
295                                                'app_order'    => $app_order,
296                                                'app_name' => urldecode($app_name)
297                                        ));
298
299                                        $GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiapplications.get_list&start='.$start);
300                                }
301                        }
302
303                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Edit application');
304                        if(!@is_object($GLOBALS['phpgw']->js))
305                        {
306                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
307                        }
308                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
309                        $GLOBALS['phpgw']->common->phpgw_header();
310                        echo parse_navbar();
311
312                        if ($totalerrors)
313                        {
314                                $GLOBALS['phpgw']->template->set_var('error','<p><center>' . $GLOBALS['phpgw']->common->error_list($error) . '</center><br>');
315                        }
316                        else
317                        {
318                                $GLOBALS['phpgw']->template->set_var('error','');
319                                list($n_app_name,$n_app_title,$n_app_status,$old_app_name,$app_order) = $this->bo->read($app_name);
320                        }
321                        $GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="start" value="'.$start.'">'.
322                                '<input type="hidden" name="app_name" value="' . $app_name . '">');
323                        $GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
324                        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.edit'));
325
326                        $this->display_row(lang('application name'), $n_app_name );
327
328                        $GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
329                        $GLOBALS['phpgw']->template->set_var('lang_save_button',lang('Save'));
330                        $GLOBALS['phpgw']->template->set_var('lang_cancel_button',lang('Cancel'));
331                        $GLOBALS['phpgw']->template->set_var('lang_delete_button',lang('Delete'));
332
333                        $selected[$n_app_status] = ' selected';
334                        $status_html = '<option value="0"' . $selected[0] . '>' . lang('Disabled') . '</option>'
335                                . '<option value="1"' . $selected[1] . '>' . lang('Enabled') . '</option>'
336                                . '<option value="2"' . $selected[2] . '>' . lang('Enabled - Hidden from navbar') . '</option>'
337                                . '<option value="4"' . $selected[4] . '>' . lang('Enabled - Popup Window') . '</option>';
338
339                        $this->display_row(lang("Status"),'<select name="n_app_status">' . $status_html . '</select>');
340                        $this->display_row(lang("Select which location this app should appear on the navbar, lowest (left) to highest (right)"),'<input name="app_order" value="' . $app_order . '">');
341
342                        $GLOBALS['phpgw']->template->set_var('select_status',$status_html);
343                        $GLOBALS['phpgw']->template->pparse('phpgw_body','form');
344                }
345
346                function delete()
347                {
348                        if ($GLOBALS['phpgw']->acl->check('applications_access',8,'admin'))
349                        {
350                                $GLOBALS['phpgw']->redirect_link('/index.php');
351                        }
352                        $app_name = get_var('app_name',array('POST','GET'));
353                        $start = get_var('start',array('POST','GET'));
354                       
355                        if (!$app_name || $_POST['no'] || $_POST['yes'])
356                        {
357                                if ($_POST['yes'])
358                                {
359                                        $this->bo->delete($app_name);
360                                }
361                                $GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiapplications.get_list&start='.$start);
362                        }
363
364                        $GLOBALS['phpgw']->template->set_file(array('body' => 'delete_common.tpl'));
365
366                        if(!@is_object($GLOBALS['phpgw']->js))
367                        {
368                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
369                        }
370                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
371                        $GLOBALS['phpgw']->common->phpgw_header();
372                        echo parse_navbar();
373
374                        $GLOBALS['phpgw']->template->set_var('messages',lang('Are you sure you want to delete the application %1 ?',$GLOBALS['phpgw_info']['apps'][$app_name]['title']));
375                        $GLOBALS['phpgw']->template->set_var('no',lang('No'));
376                        $GLOBALS['phpgw']->template->set_var('yes',lang('Yes'));
377                        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.delete'));
378                        $GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="start" value="'.$start.'">'.
379                                '<input type="hidden" name="app_name" value="'. urlencode($app_name) . '">');
380                        $GLOBALS['phpgw']->template->pparse('phpgw_body','body');
381                }
382               
383                function register_all_hooks()
384                {
385                        if ($GLOBALS['phpgw']->acl->check('applications_access',16,'admin'))
386                        {
387                                $GLOBALS['phpgw']->redirect_link('/index.php');
388                        }
389                        if (!is_object($GLOBALS['phpgw']->hooks))
390                        {
391                                $GLOBALS['phpgw']->hooks = CreateObject('phpgwapi.hooks');
392                        }
393                        $GLOBALS['phpgw']->hooks->register_all_hooks();
394                       
395                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
396                }
397        }
398?>
Note: See TracBrowser for help on using the repository browser.