source: companies/serpro/admin/inc/class.uiserver.inc.php @ 903

Revision 903, 14.2 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - phpgroupware Peer Servers                                   *
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 uiserver
14        {
15                var $public_functions = array(
16                        'list_servers' => True,
17                        'edit'         => True,
18                        'add'          => True,
19                        'delete'       => True
20                );
21
22                var $start = 0;
23                var $limit = 0;
24                var $query = '';
25                var $sort  = '';
26                var $order = '';
27
28                var $debug = False;
29
30                var $bo = '';
31                var $nextmatchs = '';
32
33                function uiserver()
34                {
35                        if ($GLOBALS['phpgw']->acl->check('peer_server_access',1,'admin'))
36                        {
37                                $GLOBALS['phpgw']->redirect_link('/index.php');
38                        }
39                        $this->acl_search = !$GLOBALS['phpgw']->acl->check('peer_server_access',2,'admin');
40                        $this->acl_add    = !$GLOBALS['phpgw']->acl->check('peer_server_access',4,'admin');
41                        $this->acl_view   = !$GLOBALS['phpgw']->acl->check('peer_server_access',8,'admin');
42                        $this->acl_edit   = !$GLOBALS['phpgw']->acl->check('peer_server_access',16,'admin');
43                        $this->acl_delete = !$GLOBALS['phpgw']->acl->check('peer_server_access',32,'admin');
44
45                        $this->bo = createobject('admin.boserver',True);
46                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
47
48                        $this->start = $this->bo->start;
49                        $this->limit = $this->bo->limit;
50                        $this->query = $this->bo->query;
51                        $this->sort  = $this->bo->sort;
52                        $this->order = $this->bo->order;
53                        if($this->debug) { $this->_debug_sqsof(); }
54                        /* _debug_array($this); */
55                }
56
57                function _debug_sqsof()
58                {
59                        $data = array(
60                                'start' => $this->start,
61                                'limit' => $this->limit,
62                                'query' => $this->query,
63                                'sort'  => $this->sort,
64                                'order' => $this->order
65                        );
66                        echo '<br>UI:';
67                        _debug_array($data);
68                }
69
70                function save_sessiondata()
71                {
72                        $data = array(
73                                'start' => $this->start,
74                                'limit' => $this->limit,
75                                'query' => $this->query,
76                                'sort'  => $this->sort,
77                                'order' => $this->order
78                        );
79                        $this->bo->save_sessiondata($data);
80                }
81
82                function formatted_list($name,$list,$id='',$default=False)
83                {
84                        $select  = "\n" .'<select name="' . $name . '"' . ">\n";
85                        if($default)
86                        {
87                                $select .= '<option value="">' . lang('Please Select') . '</option>'."\n";
88                        }
89                        while (list($val,$key) = each($list))
90                        {
91                                $select .= '<option value="' . $key . '"';
92                                if ($key == $id && $id != '')
93                                {
94                                        $select .= ' selected';
95                                }
96                                $select .= '>' . lang($val) . '</option>'."\n";
97                        }
98
99                        $select .= '</select>'."\n";
100
101                        return $select;
102                }
103
104                function list_servers()
105                {
106                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Peer Servers');
107                        $GLOBALS['phpgw']->common->phpgw_header();
108                        echo parse_navbar();
109
110                        $GLOBALS['phpgw']->template->set_file(array('server_list_t' => 'listservers.tpl'));
111                        $GLOBALS['phpgw']->template->set_block('server_list_t','server_list','list');
112                        if (!$this->acl_search)
113                        {
114                                $GLOBALS['phpgw']->template->set_block('server_list_t','search','searchhandle');
115                        }
116                        if (!$this->acl_add)
117                        {
118                                $GLOBALS['phpgw']->template->set_block('server_list_t','add','addhandle');
119                        }
120
121                        $GLOBALS['phpgw']->template->set_var('lang_action',lang('Server List'));
122                        $GLOBALS['phpgw']->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiserver.edit'));
123                        $GLOBALS['phpgw']->template->set_var('lang_add',lang('Add'));
124                        $GLOBALS['phpgw']->template->set_var('lang_search',lang('Search'));
125                        $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiserver.list_servers'));
126                        $GLOBALS['phpgw']->template->set_var('lang_done',lang('Cancel'));
127                        $GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/admin/index.php'));
128
129                        if(!$this->start)
130                        {
131                                $this->start = 0;
132                        }
133
134                        if($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] &&
135                                $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
136                        {
137                                $this->limit = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
138                        }
139                        else
140                        {
141                                $this->limit = 15;
142                        }
143
144                        $this->save_sessiondata();
145                        $servers = $this->bo->list_servers();
146
147                        $left  = $this->nextmatchs->left('/index.php',$this->start,$this->bo->total,'menuaction=admin.uiserver.list_servers');
148                        $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->total,'menuaction=admin.uiserver.list_servers');
149                        $GLOBALS['phpgw']->template->set_var('left',$left);
150                        $GLOBALS['phpgw']->template->set_var('right',$right);
151
152                        $GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->total,$this->start));
153                        $GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
154
155                        $GLOBALS['phpgw']->template->set_var('sort_name',
156                                $this->nextmatchs->show_sort_order($this->sort,'server_name',$this->order,'/index.php',lang('Name'),'&menuaction=admin.uiserver.list_servers'));
157                        $GLOBALS['phpgw']->template->set_var('sort_url',
158                                $this->nextmatchs->show_sort_order($this->sort,'server_url',$this->order,'/index.php',lang('URL'),'&menuaction=admin.uiserver.list_servers'));
159                        $GLOBALS['phpgw']->template->set_var('sort_mode',
160                                $this->nextmatchs->show_sort_order($this->sort,'server_mode',$this->order,'/index.php',lang('Mode'),'&menuaction=admin.uiserver.list_servers'));
161                        $GLOBALS['phpgw']->template->set_var('sort_security',
162                                $this->nextmatchs->show_sort_order($this->sort,'server_security',$this->order,'/index.php',lang('Security'),'&menuaction=admin.uiserver.list_servers'));
163                        $GLOBALS['phpgw']->template->set_var('lang_default',lang('Default'));
164                        $GLOBALS['phpgw']->template->set_var('lang_edit',lang('Edit'));
165                        $GLOBALS['phpgw']->template->set_var('lang_delete',lang('Delete'));
166
167                        while(list($key,$server) = @each($servers))
168                        {
169                                $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
170                                $GLOBALS['phpgw']->template->set_var('tr_color',$tr_color);
171                                $server_id = $server['server_id'];
172
173                                $GLOBALS['phpgw']->template->set_var(array(
174                                        'server_name' => $GLOBALS['phpgw']->strip_html($server['server_name']),
175                                        'server_url'  => $GLOBALS['phpgw']->strip_html($server['server_url']),
176                                        'server_security' => $server['server_security'] ? strtoupper($server['server_security']) : lang('none'),
177                                        'server_mode' => strtoupper($server['server_mode'])
178                                ));
179
180                                $GLOBALS['phpgw']->template->set_var('edit','');
181                                $GLOBALS['phpgw']->template->set_var('delete','');
182                                if ($this->acl_edit)
183                                {
184                                        $GLOBALS['phpgw']->template->set_var('edit','<a href="'.$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiserver.edit&server_id=' . $server_id).
185                                                '">'.lang('Edit').'</a>');
186                                }
187                                if ($this->acl_delete)
188                                {
189                                        $GLOBALS['phpgw']->template->set_var('delete','<a href="'.$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiserver.delete&server_id=' . $server_id).
190                                                '">'.lang('Delete').'</a>');
191                                }
192                                $GLOBALS['phpgw']->template->parse('list','server_list',True);
193                        }
194
195                        $GLOBALS['phpgw']->template->parse('out','server_list_t',True);
196                        $GLOBALS['phpgw']->template->p('out');
197                }
198
199                /* This function handles add or edit */
200                function edit()
201                {
202                        if ($_POST['done'])
203                        {
204                                return $this->list_servers();
205                        }
206                        if ($_POST['delete'])
207                        {
208                                return $this->delete();
209                               
210                        }
211                        $server_id = get_var('server_id',array('POST','GET'));
212
213                        if (!$server_id && !$this->acl_add || $server_id && !$this->acl_edit)
214                        {
215                                $GLOBALS['phpgw']->redirect_link('/index.php');
216                        }
217                        $is = CreateObject('phpgwapi.interserver');
218
219                        $GLOBALS['phpgw']->template->set_file(array('form' => 'server_form.tpl'));
220
221                        if (!$this->acl_delete || !$server_id)
222                        {
223                                $GLOBALS['phpgw']->template->set_block('form','delete','deletehandle');
224                                $GLOBALS['phpgw']->template->set_var('deletehandle','');
225                        }
226                        $server = $this->bo->read($server_id);
227
228                        if ($_POST['save'])
229                        {
230                                $errorcount = 0;
231
232                                $tmp = $is->name2id($_POST['server_name']);
233                               
234                                if($tmp && $server_id != $tmp)
235                                {
236                                        $error[$errorcount++] = lang('That server name has been used already !');
237                                }
238
239                                if (!$_POST['server_name'])
240                                {
241                                        $error[$errorcount++] = lang('Please enter a name for that server !');
242                                }
243
244                                if (!$error)
245                                {
246                                        $server_info = array(
247                                                'server_name' => addslashes($_POST['server_name']),
248                                                'server_url'  => addslashes($_POST['server_url']),
249                                                'trust_level' => (int)$_POST['trust_level'],
250                                                'trust_rel'   => (int)$_POST['trust_rel'],
251                                                'username'    => addslashes($_POST['server_username']),
252                                                'password'    => $_POST['server_password'] ? $_POST['server_password'] : $server['password'],
253                                                'server_mode' => addslashes($_POST['server_mode']),
254                                                'server_security' => addslashes($_POST['server_security']),
255                                                'admin_name'  => addslashes($_POST['admin_name']),
256                                                'admin_email' => addslashes($_POST['admin_email'])
257                                        );
258                                        if($server_id)
259                                        {
260                                                $server_info['server_id'] = $server_id;
261                                        }
262                                        $newid = $this->bo->edit($server_info);
263                                        $server = $this->bo->read($newid ? $newid : $server_info['server_id']);
264                                }
265                        }
266
267                        if ($errorcount)
268                        {
269                                $GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
270                        }
271                        if (($_POST['save']) && (!$error) && (!$errorcount))
272                        {
273                                if($server_id)
274                                {
275                                        $GLOBALS['phpgw']->template->set_var('message',lang('Server %1 has been updated',$_POST['server_name']));
276                                }
277                                else
278                                {
279                                        $GLOBALS['phpgw']->template->set_var('message',lang('Server %1 has been added',$_POST['server_name']));
280                                }
281                        }
282                        if ((!$_POST['save']) && (!$error) && (!$errorcount))
283                        {
284                                $GLOBALS['phpgw']->template->set_var('message','');
285                        }
286
287                        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin').' - '.($server_id ? lang('Edit Peer Server') : lang('Add Peer Server'));
288                        $GLOBALS['phpgw']->common->phpgw_header();
289                        echo parse_navbar();
290
291                        $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiserver.edit'));
292
293                        $GLOBALS['phpgw']->template->set_var('lang_name',lang('Server name'));
294                        $GLOBALS['phpgw']->template->set_var('lang_url',lang('Server URL'));
295                        $GLOBALS['phpgw']->template->set_var('lang_trust',lang('Trust Level'));
296                        $GLOBALS['phpgw']->template->set_var('lang_relationship',lang('Trust Relationship'));
297                        $GLOBALS['phpgw']->template->set_var('lang_username',lang('Server Username'));
298                        $GLOBALS['phpgw']->template->set_var('lang_password',lang('Server Password'));
299                        $GLOBALS['phpgw']->template->set_var('lang_mode',lang('Server Type(mode)'));
300                        $GLOBALS['phpgw']->template->set_var('lang_security',lang('Security'));
301                        $GLOBALS['phpgw']->template->set_var('lang_admin_name',lang('Admin Name'));
302                        $GLOBALS['phpgw']->template->set_var('lang_admin_email',lang('Admin Email'));
303                        $GLOBALS['phpgw']->template->set_var('lang_save',lang('Save'));
304                        $GLOBALS['phpgw']->template->set_var('lang_add',lang('Add'));
305                        $GLOBALS['phpgw']->template->set_var('lang_default',lang('Default'));
306                        $GLOBALS['phpgw']->template->set_var('lang_reset',lang('Clear Form'));
307                        $GLOBALS['phpgw']->template->set_var('lang_done',lang('Cancel'));
308                        $GLOBALS['phpgw']->template->set_var('lang_delete',lang('Delete'));
309
310                        $GLOBALS['phpgw']->template->set_var('server_name',$server['server_name']);
311                        $GLOBALS['phpgw']->template->set_var('server_url',$server['server_url']);
312                        $GLOBALS['phpgw']->template->set_var('server_username',$server['username']);
313                        $GLOBALS['phpgw']->template->set_var('server_mode',$this->formatted_list('server_mode',$is->server_modes,$server['server_mode']));
314                        $GLOBALS['phpgw']->template->set_var('server_security',$this->formatted_list('server_security',$is->security_types,$server['server_security']));
315                        $GLOBALS['phpgw']->template->set_var('ssl_note', function_exists('curl_init') ? '&nbsp;' : lang('Note: SSL available only if PHP is compiled with curl support'));
316                        $GLOBALS['phpgw']->template->set_var('pass_note',$server_id ? '<br>'.lang('(Stored password will not be shown here)') : '');
317                        $GLOBALS['phpgw']->template->set_var('trust_level',$this->formatted_list('trust_level',$is->trust_levels,$server['trust_level']));
318                        $GLOBALS['phpgw']->template->set_var('trust_relationship',$this->formatted_list('trust_rel',$is->trust_relationships,$server['trust_rel'],True));
319                        $GLOBALS['phpgw']->template->set_var('admin_name',$GLOBALS['phpgw']->strip_html($server['admin_name']));
320                        $GLOBALS['phpgw']->template->set_var('admin_email',$GLOBALS['phpgw']->strip_html($server['admin_email']));
321                        $GLOBALS['phpgw']->template->set_var('server_id',$server_id);
322
323                        $GLOBALS['phpgw']->template->set_var(array(
324                                'th'      => $GLOBALS['phpgw_info']['theme']['th_bg'],
325                                'row_on'  => $GLOBALS['phpgw_info']['theme']['row_on'],
326                                'row_off' => $GLOBALS['phpgw_info']['theme']['row_off']
327                        ));
328                        $GLOBALS['phpgw']->template->pparse('phpgw_body','form');
329                }
330
331                function delete()
332                {
333                        if (!$this->acl_delete)
334                        {
335                                $GLOBALS['phpgw']->redirect_link('/index.php');
336                        }
337                        $server_id = get_var('server_id',array('POST','GET'));
338                        if ($_POST['yes'] || $_POST['no'])
339                        {
340                                if ($_POST['yes'])
341                                {
342                                        $this->bo->delete($server_id);
343                                }
344                                $GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiserver.list_servers');
345                        }
346                        else
347                        {
348                                $GLOBALS['phpgw']->common->phpgw_header();
349                                echo parse_navbar();
350
351                                $GLOBALS['phpgw']->template->set_file(array('server_delete' => 'delete_common.tpl'));
352
353                                $GLOBALS['phpgw']->template->set_var(array(
354                                        'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiserver.delete'),
355                                        'hidden_vars' => '<input type="hidden" name="server_id" value="' . $server_id . '"><script>document.yesbutton.yesbutton.focus()</script>',
356                                        'messages' => lang('Are you sure you want to delete this server?'),
357                                        'no' => lang('No'),
358                                        'yes' => lang('Yes'),
359                                ));
360                                $GLOBALS['phpgw']->template->pparse('phpgw_body','server_delete');
361                        }
362                }
363        }
364?>
Note: See TracBrowser for help on using the repository browser.