source: trunk/admin/inc/class.uiapplications.inc.php @ 2802

Revision 2802, 15.4 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Permitindo o envio de formulário por requisição background

  • Property svn:eol-style set to native
  • Property svn:executable set to *
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('/#');
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('/','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('/','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('/','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('/#');
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('/','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
258                        $GLOBALS['phpgw']->template->set_var('lang_cancel_button',lang('Cancel'));
259                        $GLOBALS['phpgw']->template->set_var( 'cancel_button', $GLOBALS[ 'phpgw' ] -> link( '/', 'menuaction=admin.uiapplications.get_list' ) );
260
261                        $GLOBALS['phpgw']->template->pparse('phpgw_body','form');
262                }
263
264                function edit()
265                {
266                        if ($GLOBALS['phpgw']->acl->check('applications_access',4,'admin'))
267                        {
268                                $GLOBALS['phpgw']->redirect_link('/#');
269                        }
270                        $app_name = get_var('app_name',array('POST','GET'));
271                        $start = get_var('start',array('POST','GET'));
272
273                        $GLOBALS['phpgw']->template->set_file(array('application' => 'application_form.tpl'));
274                        $GLOBALS['phpgw']->template->set_block('application','form','form');
275                        $GLOBALS['phpgw']->template->set_block('application','row','row');
276
277                        if ($_POST['cancel'])
278                        {
279                                $GLOBALS['phpgw']->redirect_link('/#index.php','menuaction=admin.uiapplications.get_list&start='.$start);
280                        }
281                       
282                        if ($_POST['delete'])
283                        {
284                                echo $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script' ] .= "<script>ExpressoLivre.link( '{$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.delete&start=' )}{$start}&app_name={$app_name}' );</script>";
285                                exit;
286                        }
287
288                        if ($_POST['save'])
289                        {
290                                $totalerrors = 0;
291
292                                $app_order    = $_POST['app_order'] ? $_POST['app_order'] : 0;
293                                $n_app_status = $_POST['n_app_status'];
294
295                                if (! $totalerrors)
296                                {
297                                        $this->bo->save(array(
298                                                'n_app_status' => $n_app_status,
299                                                'app_order'    => $app_order,
300                                                'app_name' => urldecode($app_name)
301                                        ));
302
303                                        $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script' ] .= "<script>ExpressoLivre.link( '{$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.get_list&start='.$start)}' );</script>";
304                                        exit;
305                                }
306                        }
307
308                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Edit application');
309                        if(!@is_object($GLOBALS['phpgw']->js))
310                        {
311                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
312                        }
313                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
314                        //$GLOBALS['phpgw']->common->phpgw_header();
315                        //echo parse_navbar();
316
317                        if ($totalerrors)
318                        {
319                                $GLOBALS['phpgw']->template->set_var('error','<p><center>' . $GLOBALS['phpgw']->common->error_list($error) . '</center><br>');
320                        }
321                        else
322                        {
323                                $GLOBALS['phpgw']->template->set_var('error','');
324                                list($n_app_name,$n_app_title,$n_app_status,$old_app_name,$app_order) = $this->bo->read($app_name);
325                        }
326                        $GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="start" value="'.$start.'">'.
327                                '<input type="hidden" name="app_name" value="' . $app_name . '">');
328                        $GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
329                        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.edit'));
330
331                        $this->display_row(lang('application name'), $n_app_name );
332
333                        $GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
334                        $GLOBALS['phpgw']->template->set_var('lang_save_button',lang('Save'));
335
336                        $GLOBALS['phpgw']->template->set_var('lang_cancel_button',lang('Cancel'));
337                        $GLOBALS['phpgw']->template->set_var( 'cancel_button', $GLOBALS[ 'phpgw' ] -> link( '/', 'menuaction=admin.uiapplications.get_list' ) );
338
339                        $GLOBALS['phpgw']->template->set_var('lang_delete_button',lang('Delete'));
340
341                        $selected[$n_app_status] = ' selected';
342                        $status_html = '<option value="0"' . $selected[0] . '>' . lang('Disabled') . '</option>'
343                                . '<option value="1"' . $selected[1] . '>' . lang('Enabled') . '</option>'
344                                . '<option value="2"' . $selected[2] . '>' . lang('Enabled - Hidden from navbar') . '</option>'
345                                . '<option value="4"' . $selected[4] . '>' . lang('Enabled - Popup Window') . '</option>';
346
347                        $this->display_row(lang("Status"),'<select name="n_app_status">' . $status_html . '</select>');
348                        $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 . '">');
349
350                        $GLOBALS['phpgw']->template->set_var('select_status',$status_html);
351                        $GLOBALS['phpgw']->template->pparse('phpgw_body','form');
352                }
353
354                function delete()
355                {
356                        if ($GLOBALS['phpgw']->acl->check('applications_access',8,'admin'))
357                        {
358                                $GLOBALS['phpgw']->redirect_link('/');
359                        }
360                        $app_name = get_var('app_name',array('POST','GET'));
361                        $start = get_var('start',array('POST','GET'));
362                       
363                        if (!$app_name || $_POST['no'] || $_POST['yes'])
364                        {
365                                if ($_POST['yes'])
366                                {
367                                        $this->bo->delete($app_name);
368                                }
369                                $GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiapplications.get_list&start='.$start);
370                        }
371
372                        $GLOBALS['phpgw']->template->set_file(array('body' => 'delete_common.tpl'));
373
374                        if(!@is_object($GLOBALS['phpgw']->js))
375                        {
376                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
377                        }
378                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
379                        //$GLOBALS['phpgw']->common->phpgw_header();
380                        //echo parse_navbar();
381
382                        $GLOBALS['phpgw']->template->set_var('messages',lang('Are you sure you want to delete the application %1 ?',$GLOBALS['phpgw_info']['apps'][$app_name]['title']));
383
384                        $GLOBALS['phpgw']->template->set_var( 'no', lang('No'));
385                        $GLOBALS['phpgw']->template->set_var( 'no_button', $GLOBALS[ 'phpgw' ] -> link( '/', 'menuaction=admin.uiapplications.get_list' ) );
386
387                        $GLOBALS['phpgw']->template->set_var('yes',lang('Yes'));
388                        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiapplications.delete'));
389                        $GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="start" value="'.$start.'">'.
390                                '<input type="hidden" name="app_name" value="'. urlencode($app_name) . '">');
391                        $GLOBALS['phpgw']->template->pparse('phpgw_body','body');
392                }
393
394                function register_all_hooks( )
395                {
396                        if ( ! $GLOBALS[ 'phpgw' ] -> acl -> check( 'applications_access', 16, 'admin' ) )
397                        {
398                                if ( ! is_object( $GLOBALS[ 'phpgw' ] -> hooks ) )
399                                        $GLOBALS[ 'phpgw' ] -> hooks = CreateObject( 'phpgwapi.hooks' );
400
401                                $GLOBALS[ 'phpgw' ] -> hooks -> register_all_hooks( );
402                        }
403
404                        $GLOBALS[ 'phpgw' ] -> redirect_link( '/' );
405                }
406        }
407?>
Note: See TracBrowser for help on using the repository browser.