source: companies/serpro/emailadmin/inc/class.ui.inc.php @ 903

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

Importacao inicial do Expresso do Serpro

Line 
1<?php
2        /***************************************************************************\
3        * EGroupWare - EMailAdmin                                                   *
4        * http://www.egroupware.org                                                 *
5        * Written by : Lars Kneschke [lkneschke@egroupware.org]                     *
6        * -------------------------------------------------                         *
7        * This program is free software; you can redistribute it and/or modify it   *
8        * under the terms of the GNU General Public License as published by the     *
9        * Free Software Foundation; either version 2 of the License, or (at your    *
10        * option) any later version.                                                *
11        \***************************************************************************/
12
13        class ui
14        {
15               
16                var $public_functions = array
17                (
18                        'addProfile'    => True,
19                        'css'                   => True,
20                        'deleteProfile' => True,
21                        'editProfile'   => True,
22                        'listProfiles'  => True,
23                        'saveProfile'   => True
24                );
25               
26                var $cats;
27                var $nextmatchs;
28                var $t;
29                var $boqmailldap;
30
31                function ui()
32                {
33                        $this->cats                     = CreateObject('phpgwapi.categories');
34                        $this->nextmatchs               = CreateObject('phpgwapi.nextmatchs');
35                        $this->t                        = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
36                        #$this->grants                  = $phpgw->acl->get_grants('notes');
37                        #$this->grants[$this->account]  = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
38                        $this->boemailadmin             = CreateObject('emailadmin.bo');
39                }
40               
41                function addProfile()
42                {
43                        $this->display_app_header();
44                       
45                        $this->t->set_file(array("body" => "editprofile.tpl"));
46                        $this->t->set_block('body','main');
47                       
48                        $this->translate();
49                       
50                        #$this->t->set_var('profile_name',$profileList[0]['description']);
51                        $this->t->set_var('smtpActiveTab','1');
52                        $this->t->set_var('imapActiveTab','1');
53                       
54                        $linkData = array
55                        (
56                                'menuaction'    => 'emailadmin.ui.saveProfile'
57                        );
58                        $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
59                       
60                        $linkData = array
61                        (
62                                'menuaction'    => 'emailadmin.ui.listProfiles'
63                        );
64                        $this->t->set_var('back_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
65
66                        foreach($this->boemailadmin->getSMTPServerTypes() as $key => $value)
67                        {
68                                $this->t->set_var("lang_smtp_option_$key",$value);
69                        };
70                                               
71                        foreach($this->boemailadmin->getIMAPServerTypes() as $key => $value)
72                        {
73                                $this->t->set_var("lang_imap_option_$key",$value['description']);
74                        };
75                                               
76                        $this->t->parse("out","main");
77                        print $this->t->get('out','main');
78                }
79       
80                function css()
81                {
82                        $appCSS =
83                        'th.activetab
84                        {
85                                color:#000000;
86                                background-color:#D3DCE3;
87                                border-top-width : 1px;
88                                border-top-style : solid;
89                                border-top-color : Black;
90                                border-left-width : 1px;
91                                border-left-style : solid;
92                                border-left-color : Black;
93                                border-right-width : 1px;
94                                border-right-style : solid;
95                                border-right-color : Black;
96                        }
97                       
98                        th.inactivetab
99                        {
100                                color:#000000;
101                                background-color:#E8F0F0;
102                                border-bottom-width : 1px;
103                                border-bottom-style : solid;
104                                border-bottom-color : Black;
105                        }
106                       
107                        .td_left { border-left : 1px solid Gray; border-top : 1px solid Gray; }
108                        .td_right { border-right : 1px solid Gray; border-top : 1px solid Gray; }
109                       
110                        div.activetab{ display:inline; }
111                        div.inactivetab{ display:none; }';
112                       
113                        return $appCSS;
114                }
115               
116                function deleteProfile()
117                {
118                        $this->boemailadmin->deleteProfile($_GET['profileid']);
119                        $this->listProfiles();
120                }
121               
122                function display_app_header()
123                {
124                        if(!@is_object($GLOBALS['phpgw']->js))
125                        {
126                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
127                        }
128                        $GLOBALS['phpgw']->js->validate_file('tabs','tabs');
129                        switch($_GET['menuaction'])
130                        {
131                                case 'emailadmin.ui.addProfile':
132                                case 'emailadmin.ui.editProfile':
133                                        $GLOBALS['phpgw']->js->validate_file('jscode','editProfile','emailadmin');
134                                        $GLOBALS['phpgw']->js->set_onload('javascript:initAll();');
135                                        #$GLOBALS['phpgw']->js->set_onload('smtp.init();');
136
137                                        break;
138                        }
139                        $GLOBALS['phpgw']->common->phpgw_header();
140                        echo parse_navbar();
141                }
142
143                function editProfile($_profileID='')
144                {
145                        if($_profileID != '')
146                        {
147                                $profileID = $_profileID;
148                        }
149                        elseif(is_int(intval($_GET['profileid'])) && !empty($_GET['profileid']))
150                        {
151                                $profileID = intval($_GET['profileid']);
152                        }
153                        else
154                        {
155                                return false;
156                        }
157
158                        $profileList = $this->boemailadmin->getProfileList($profileID);
159                        $profileData = $this->boemailadmin->getProfile($profileID);
160                        $this->display_app_header();
161                       
162                        $this->t->set_file(array("body" => "editprofile.tpl"));
163                        $this->t->set_block('body','main');
164                       
165                        $this->translate();
166                       
167                        foreach($profileData as $key => $value)
168                        {
169                                //print "$key $value<br>";
170                                switch($key)
171                                {
172                                        case 'imapEnableCyrusAdmin':
173                                        case 'imapEnableSieve':
174                                        case 'imapTLSAuthentication':
175                                        case 'imapTLSEncryption':
176                                        case 'smtpAuth':
177                                        case 'smtpLDAPUseDefault':
178                                        case 'userDefinedAccounts':
179                                        case 'imapoldcclient':
180                                                if($value == 'yes')
181                                                        $this->t->set_var('selected_'.$key,'checked="1"');
182                                                break;
183                                        case 'imapType':       
184                                        case 'smtpType':
185                                        case 'imapLoginType':
186                                                $this->t->set_var('selected_'.$key.'_'.$value,'selected="1"');
187                                                break;
188                                        case 'imapDelimiter':
189                                                if ($value == '/')
190                                                        $this->t->set_var('selected_'.$key.'_slash','selected="1"');
191                                                elseif ($value == '.')
192                                                        $this->t->set_var('selected_'.$key.'_dot','selected="1"');
193                                                break;
194                                        default:
195                                                $this->t->set_var('value_'.$key,$value);
196                                                break;
197                                }
198                        }
199                       
200                        $linkData = array
201                        (
202                                'menuaction'    => 'emailadmin.ui.saveProfile',
203                                'profileID'     => $profileID
204                        );
205                        $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
206                       
207                        $linkData = array
208                        (
209                                'menuaction'    => 'emailadmin.ui.listProfiles'
210                        );
211                        $this->t->set_var('back_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
212
213                        foreach($this->boemailadmin->getSMTPServerTypes() as $key => $value)
214                        {
215                                $this->t->set_var("lang_smtp_option_$key",$value);
216                        };
217                                               
218                        foreach($this->boemailadmin->getIMAPServerTypes() as $key => $value)
219                        {
220                                $this->t->set_var("lang_imap_option_$key",$value['description']);
221                        };
222                                               
223                        $this->t->parse("out","main");
224                        print $this->t->get('out','main');
225                }
226               
227                function listProfiles()
228                {
229                        $this->display_app_header();
230
231                        $this->t->set_file(array("body" => "listprofiles.tpl"));
232                        $this->t->set_block('body','main');
233                       
234                        $this->translate();
235
236                        $profileList = $this->boemailadmin->getProfileList();
237                       
238                        // create the data array
239                        if ($profileList)
240                        {
241                                for ($i=0; $i < count($profileList); $i++)
242                                {
243                                        $linkData = array
244                                        (
245                                                'menuaction'    => 'emailadmin.ui.editProfile',
246                                                'nocache'       => '1',
247                                                'tabpage'       => '3',
248                                                'profileid'     => $profileList[$i]['profileID']
249                                        );
250                                        $imapServerLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['imapServer'].'</a>';
251                                       
252                                        $linkData = array
253                                        (
254                                                'menuaction'    => 'emailadmin.ui.editProfile',
255                                                'nocache'       => '1',
256                                                'tabpage'       => '1',
257                                                'profileid'     => $profileList[$i]['profileID']
258                                        );
259                                        $descriptionLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['description'].'</a>';
260                                       
261                                        $linkData = array
262                                        (
263                                                'menuaction'    => 'emailadmin.ui.editProfile',
264                                                'nocache'       => '1',
265                                                'tabpage'       => '2',
266                                                'profileid'     => $profileList[$i]['profileID']
267                                        );
268                                        $smtpServerLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['smtpServer'].'</a>';
269                                       
270                                        $linkData = array
271                                        (
272                                                'menuaction'    => 'emailadmin.ui.deleteProfile',
273                                                'profileid'     => $profileList[$i]['profileID']
274                                        );
275                                        $deleteLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).
276                                                      '" onClick="return confirm(\''.lang('Do you really want to delete this Profile').'?\')">'.
277                                                      lang('delete').'</a>';
278                                       
279                                        $data[] = array(
280                                                $descriptionLink,
281                                                $smtpServerLink,
282                                                $imapServerLink,
283                                                $deleteLink
284                                               
285                                        );
286                                }
287                        }
288
289                        // create the array containing the table header
290                        $rows = array(
291                                lang('description'),
292                                lang('smtp server name'),
293                                lang('imap/pop3 server name'),
294                                lang('delete')
295                        );
296                               
297                        // create the table html code
298                        $this->t->set_var('server_next_match',$this->nextMatchTable(
299                                $rows,
300                                $data,
301                                lang('profile list'),
302                                $_start,
303                                $_total,
304                                $_menuAction)
305                        );
306                       
307                        $linkData = array
308                        (
309                                'menuaction'    => 'emailadmin.ui.addProfile'
310                        );
311                        $this->t->set_var('add_link',$GLOBALS['phpgw']->link('/index.php',$linkData));
312
313                        $this->t->parse("out","main");
314                       
315                        print $this->t->get('out','main');
316                       
317                }
318
319                function nextMatchTable($_rows, $_data, $_description, $_start, $_total, $_menuAction)
320                {
321                        $template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
322                        $template->set_file(array("body" => "nextMatch.tpl"));
323                        $template->set_block('body','row_list','rowList');
324                        $template->set_block('body','header_row','headerRow');
325               
326                        $var = Array(
327                                'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
328                                'left_next_matchs'      => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=emailadmin.ui.listServers'),
329                                'right_next_matchs'     => $this->nextmatchs->right('/admin/groups.php',$start,$total,'menuaction=emailadmin.ui.listServers'),
330                                'lang_groups'           => lang('user groups'),
331                                'sort_name'             => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=emailadmin.ui.listServers'),
332                                'description'           => $_description,
333                                'header_edit'           => lang('Edit'),
334                                'header_delete'         => lang('Delete')
335                        );
336                        $template->set_var($var);
337                       
338                        $data = '';
339                        if(is_array($_rows))
340                        {
341                                foreach($_rows as $value)
342                                {
343                                        $data .= "<td align='center'><b>$value</b></td>";
344                                }
345                                $template->set_var('header_row_data', $data);
346                                $template->fp('headerRow','header_row',True);
347                                #$template->fp('header_row','header_row',True);
348                        }
349
350                        if(is_array($_data))
351                        {
352                                foreach($_data as $value)
353                                {
354                                        $data = '';
355                                        foreach($value as $rowData)
356                                        {
357                                                $data .= "<td align='center'>$rowData</td>";
358                                        }
359                                        $template->set_var('row_data', $data);
360                                        $template->fp('rowList','row_list',True);
361                                }
362                        }
363
364                        return $template->fp('out','body');
365                       
366                }
367
368                function saveProfile()
369                {
370                        $globalSettings = array();
371                        $smtpSettings   = array();
372                        $imapSettings   = array();
373                       
374                        // try to get the profileID
375                        if(is_int(intval($_GET['profileID'])) && !empty($_GET['profileID']))
376                        {
377                                $globalSettings['profileID'] = intval($_GET['profileID']);
378                        }
379                        $globalSettings['description'] = $_POST['globalsettings']['description'];
380                        $globalSettings['defaultDomain'] = $_POST['globalsettings']['defaultDomain'];
381                        $globalSettings['organisationName'] = $_POST['globalsettings']['organisationName'];
382                        $globalSettings['userDefinedAccounts'] = $_POST['globalsettings']['userDefinedAccounts'];
383                       
384                       
385                        // get the settings for the smtp server
386                        $smtpType = $_POST['smtpsettings']['smtpType'];
387                        foreach($this->boemailadmin->getFieldNames($smtpType,'smtp') as $key)
388                        {
389                                $smtpSettings[$key] = $_POST['smtpsettings'][$smtpType][$key];
390                        }
391                        $smtpSettings['smtpType'] = $smtpType;
392                       
393                        #_debug_array($smtpSettings);
394                       
395                        // get the settings for the imap/pop3 server
396                        $imapType = $_POST['imapsettings']['imapType'];
397                        foreach($this->boemailadmin->getFieldNames($imapType,'imap') as $key)
398                        {
399                                $imapSettings[$key] = $_POST['imapsettings'][$imapType][$key];
400                        }
401                        $imapSettings['imapType'] = $imapType;
402                       
403                        $this->boemailadmin->saveProfile($globalSettings, $smtpSettings, $imapSettings);
404                        #if ($HTTP_POST_VARS['bo_action'] == 'save_ldap' || $HTTP_GET_VARS['bo_action'] == 'save_ldap')
405                        #{
406                                $this->listProfiles();
407                        #}
408                        #else
409                        #{
410                        #       $this->editServer($HTTP_GET_VARS["serverid"],$HTTP_GET_VARS["pagenumber"]);
411                        #}
412                }
413               
414                function translate()
415                {
416                        # skeleton
417                        # $this->t->set_var('',lang(''));
418                       
419                        $this->t->set_var('lang_server_name',lang('server name'));
420                        $this->t->set_var('lang_server_description',lang('description'));
421                        $this->t->set_var('lang_edit',lang('edit'));
422                        $this->t->set_var('lang_save',lang('save'));
423                        $this->t->set_var('lang_delete',lang('delete'));
424                        $this->t->set_var('lang_back',lang('back'));
425                        $this->t->set_var('lang_remove',lang('remove'));
426                        $this->t->set_var('lang_ldap_server',lang('LDAP server'));
427                        $this->t->set_var('lang_ldap_basedn',lang('LDAP basedn'));
428                        $this->t->set_var('lang_ldap_server_admin',lang('admin dn'));
429                        $this->t->set_var('lang_ldap_server_password',lang('admin password'));
430                        $this->t->set_var('lang_add_profile',lang('add profile'));
431                        $this->t->set_var('lang_domain_name',lang('domainname'));
432                        $this->t->set_var('lang_SMTP_server_hostname_or_IP_address',lang('SMTP-Server hostname or IP address'));
433                        $this->t->set_var('lang_SMTP_server_port',lang('SMTP-Server port'));
434                        $this->t->set_var('lang_Use_SMTP_auth',lang('Use SMTP auth'));
435                        $this->t->set_var('lang_Select_type_of_SMTP_Server',lang('Select type of SMTP Server'));
436                        $this->t->set_var('lang_profile_name',lang('Profile Name'));
437                        $this->t->set_var('lang_default_domain',lang('enter your default mail domain (from: user@domain)'));
438                        $this->t->set_var('lang_organisation_name',lang('name of organisation'));
439                        $this->t->set_var('lang_user_defined_accounts',lang('users can define their own emailaccounts'));
440                        $this->t->set_var('lang_LDAP_server_hostname_or_IP_address',lang('LDAP server hostname or ip address'));
441                        $this->t->set_var('lang_LDAP_server_admin_dn',lang('LDAP server admin DN'));
442                        $this->t->set_var('lang_LDAP_server_admin_pw',lang('LDAP server admin password'));
443                        $this->t->set_var('lang_LDAP_server_base_dn',lang('LDAP server accounts DN'));
444                        $this->t->set_var('lang_use_LDAP_defaults',lang('use LDAP defaults'));
445                        $this->t->set_var('lang_LDAP_settings',lang('LDAP settings'));
446                        $this->t->set_var('lang_select_type_of_imap/pop3_server',lang('select type of IMAP/POP3 server'));
447                        $this->t->set_var('lang_pop3_server_hostname_or_IP_address',lang('POP3 server hostname or ip address'));
448                        $this->t->set_var('lang_pop3_server_port',lang('POP3 server port'));
449                        $this->t->set_var('lang_imap_server_hostname_or_IP_address',lang('IMAP server hostname or ip address'));
450                        $this->t->set_var('lang_imap_server_port',lang('IMAP server port'));
451                        $this->t->set_var('lang_use_tls_encryption',lang('use tls encryption'));
452                        $this->t->set_var('lang_use_tls_authentication',lang('use tls authentication'));
453                        $this->t->set_var('lang_sieve_settings',lang('Sieve settings'));
454                        $this->t->set_var('lang_enable_sieve',lang('enable Sieve'));
455                        $this->t->set_var('lang_sieve_server_hostname_or_ip_address',lang('Sieve server hostname or ip address'));
456                        $this->t->set_var('lang_sieve_server_port',lang('Sieve server port'));
457                        $this->t->set_var('lang_enable_cyrus_imap_administration',lang('enable Cyrus IMAP server administration'));
458                        $this->t->set_var('lang_cyrus_imap_administration',lang('Cyrus IMAP server administration'));
459                        $this->t->set_var('lang_admin_username',lang('admin username'));
460                        $this->t->set_var('lang_admin_password',lang('admin passwort'));
461                        $this->t->set_var('lang_imap_server_logintyp',lang('imap server logintyp'));
462                        $this->t->set_var('lang_standard',lang('standard'));
463                        $this->t->set_var('lang_vmailmgr',lang('Virtual MAIL ManaGeR'));
464                        $this->t->set_var('lang_pre_2001_c_client',lang('IMAP C-Client Version < 2001'));
465                        # $this->t->set_var('',lang(''));
466                       
467                }
468        }
469?>
Note: See TracBrowser for help on using the repository browser.