source: trunk/emailadmin/inc/class.ui.inc.php @ 7655

Revision 7655, 15.9 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Melhorias de performance no codigo do Expresso.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
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                                        case 'imapCreateSpamFolder':
181                                                if($value == 'yes')
182                                                        $this->t->set_var('selected_'.$key,'checked="1"');
183                                                break;
184                                        case 'imapType':       
185                                        case 'smtpType':
186                                        case 'imapLoginType':
187                                                $this->t->set_var('selected_'.$key.'_'.$value,'selected="1"');
188                                                break;
189                                        case 'imapDelimiter':
190                                                if ($value == '/')
191                                                        $this->t->set_var('selected_'.$key.'_slash','selected="1"');
192                                                elseif ($value == '.')
193                                                        $this->t->set_var('selected_'.$key.'_dot','selected="1"');
194                                                break;
195                                        default:
196                                                $this->t->set_var('value_'.$key,$value);
197                                                break;
198                                }
199                        }
200                       
201                        $linkData = array
202                        (
203                                'menuaction'    => 'emailadmin.ui.saveProfile',
204                                'profileID'     => $profileID
205                        );
206                        $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
207                       
208                        $linkData = array
209                        (
210                                'menuaction'    => 'emailadmin.ui.listProfiles'
211                        );
212                        $this->t->set_var('back_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
213
214                        foreach($this->boemailadmin->getSMTPServerTypes() as $key => $value)
215                        {
216                                $this->t->set_var("lang_smtp_option_$key",$value);
217                        };
218                                               
219                        foreach($this->boemailadmin->getIMAPServerTypes() as $key => $value)
220                        {
221                                $this->t->set_var("lang_imap_option_$key",$value['description']);
222                        };
223                                               
224                        $this->t->parse("out","main");
225                        print $this->t->get('out','main');
226                }
227               
228                function listProfiles()
229                {
230                        $this->display_app_header();
231
232                        $this->t->set_file(array("body" => "listprofiles.tpl"));
233                        $this->t->set_block('body','main');
234                       
235                        $this->translate();
236
237                        $profileList = $this->boemailadmin->getProfileList();
238                       
239                        // create the data array
240                        if ($profileList)
241                        {
242                                for ($i=0; $i < count($profileList); ++$i)
243                                {
244                                        $linkData = array
245                                        (
246                                                'menuaction'    => 'emailadmin.ui.editProfile',
247                                                'nocache'       => '1',
248                                                'tabpage'       => '3',
249                                                'profileid'     => $profileList[$i]['profileID']
250                                        );
251                                        $imapServerLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['imapServer'].'</a>';
252                                       
253                                        $linkData = array
254                                        (
255                                                'menuaction'    => 'emailadmin.ui.editProfile',
256                                                'nocache'       => '1',
257                                                'tabpage'       => '1',
258                                                'profileid'     => $profileList[$i]['profileID']
259                                        );
260                                        $descriptionLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['description'].'</a>';
261                                       
262                                        $linkData = array
263                                        (
264                                                'menuaction'    => 'emailadmin.ui.editProfile',
265                                                'nocache'       => '1',
266                                                'tabpage'       => '2',
267                                                'profileid'     => $profileList[$i]['profileID']
268                                        );
269                                        $smtpServerLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['smtpServer'].'</a>';
270                                       
271                                        $linkData = array
272                                        (
273                                                'menuaction'    => 'emailadmin.ui.deleteProfile',
274                                                'profileid'     => $profileList[$i]['profileID']
275                                        );
276                                        $deleteLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).
277                                                      '" onClick="return confirm(\''.lang('Do you really want to delete this Profile').'?\')">'.
278                                                      lang('delete').'</a>';
279                                       
280                                        $data[] = array(
281                                                $descriptionLink,
282                                                $smtpServerLink,
283                                                $imapServerLink,
284                                                $deleteLink
285                                               
286                                        );
287                                }
288                        }
289
290                        // create the array containing the table header
291                        $rows = array(
292                                lang('description'),
293                                lang('smtp server name'),
294                                lang('imap/pop3 server name'),
295                                lang('delete')
296                        );
297                               
298                        // create the table html code
299                        $this->t->set_var('server_next_match',$this->nextMatchTable(
300                                $rows,
301                                $data,
302                                lang('profile list'),
303                                $_start,
304                                $_total,
305                                $_menuAction)
306                        );
307                       
308                        $linkData = array
309                        (
310                                'menuaction'    => 'emailadmin.ui.addProfile'
311                        );
312                        $this->t->set_var('add_link',$GLOBALS['phpgw']->link('/index.php',$linkData));
313
314                        $this->t->parse("out","main");
315                       
316                        print $this->t->get('out','main');
317                       
318                }
319
320                function nextMatchTable($_rows, $_data, $_description, $_start, $_total, $_menuAction)
321                {
322                        $template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
323                        $template->set_file(array("body" => "nextMatch.tpl"));
324                        $template->set_block('body','row_list','rowList');
325                        $template->set_block('body','header_row','headerRow');
326               
327                        $var = Array(
328                                'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
329                                'left_next_matchs'      => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=emailadmin.ui.listServers'),
330                                'right_next_matchs'     => $this->nextmatchs->right('/admin/groups.php',$start,$total,'menuaction=emailadmin.ui.listServers'),
331                                'lang_groups'           => lang('user groups'),
332                                'sort_name'             => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=emailadmin.ui.listServers'),
333                                'description'           => $_description,
334                                'header_edit'           => lang('Edit'),
335                                'header_delete'         => lang('Delete')
336                        );
337                        $template->set_var($var);
338                       
339                        $data = '';
340                        if(is_array($_rows))
341                        {
342                                foreach($_rows as $value)
343                                {
344                                        $data .= "<td align='center'><b>$value</b></td>";
345                                }
346                                $template->set_var('header_row_data', $data);
347                                $template->fp('headerRow','header_row',True);
348                                #$template->fp('header_row','header_row',True);
349                        }
350
351                        if(is_array($_data))
352                        {
353                                foreach($_data as $value)
354                                {
355                                        $data = '';
356                                        foreach($value as $rowData)
357                                        {
358                                                $data .= "<td align='center'>$rowData</td>";
359                                        }
360                                        $template->set_var('row_data', $data);
361                                        $template->fp('rowList','row_list',True);
362                                }
363                        }
364
365                        return $template->fp('out','body');
366                       
367                }
368
369                function saveProfile()
370                {
371                        $globalSettings = array();
372                        $smtpSettings   = array();
373                        $imapSettings   = array();
374                       
375                        // try to get the profileID
376                        if(is_int(intval($_GET['profileID'])) && !empty($_GET['profileID']))
377                        {
378                                $globalSettings['profileID'] = intval($_GET['profileID']);
379                        }
380                        $globalSettings['description'] = $_POST['globalsettings']['description'];
381                        $globalSettings['defaultDomain'] = $_POST['globalsettings']['defaultDomain'];
382                        $globalSettings['organisationName'] = $_POST['globalsettings']['organisationName'];
383                        $globalSettings['userDefinedAccounts'] = $_POST['globalsettings']['userDefinedAccounts'];
384                       
385                       
386                        // get the settings for the smtp server
387                        $smtpType = $_POST['smtpsettings']['smtpType'];
388                        foreach($this->boemailadmin->getFieldNames($smtpType,'smtp') as $key)
389                        {
390                                $smtpSettings[$key] = $_POST['smtpsettings'][$smtpType][$key];
391                        }
392                        $smtpSettings['smtpType'] = $smtpType;
393                       
394                        #_debug_array($smtpSettings);
395                       
396                        // get the settings for the imap/pop3 server
397                        $imapType = $_POST['imapsettings']['imapType'];
398                        foreach($this->boemailadmin->getFieldNames($imapType,'imap') as $key)
399                        {
400                                $imapSettings[$key] = $_POST['imapsettings'][$imapType][$key];
401                        }
402                        $imapSettings['imapType'] = $imapType;
403                       
404                        $this->boemailadmin->saveProfile($globalSettings, $smtpSettings, $imapSettings);
405                        #if ($HTTP_POST_VARS['bo_action'] == 'save_ldap' || $HTTP_GET_VARS['bo_action'] == 'save_ldap')
406                        #{
407                                $this->listProfiles();
408                        #}
409                        #else
410                        #{
411                        #       $this->editServer($HTTP_GET_VARS["serverid"],$HTTP_GET_VARS["pagenumber"]);
412                        #}
413                }
414               
415                function translate()
416                {
417                        # skeleton
418                        # $this->t->set_var('',lang(''));
419                       
420                        $this->t->set_var('lang_server_name',lang('server name'));
421                        $this->t->set_var('lang_server_description',lang('description'));
422                        $this->t->set_var('lang_edit',lang('edit'));
423                        $this->t->set_var('lang_save',lang('save'));
424                        $this->t->set_var('lang_delete',lang('delete'));
425                        $this->t->set_var('lang_back',lang('back'));
426                        $this->t->set_var('lang_remove',lang('remove'));
427                        $this->t->set_var('lang_ldap_server',lang('LDAP server'));
428                        $this->t->set_var('lang_ldap_basedn',lang('LDAP basedn'));
429                        $this->t->set_var('lang_ldap_server_admin',lang('admin dn'));
430                        $this->t->set_var('lang_ldap_server_password',lang('admin password'));
431                        $this->t->set_var('lang_add_profile',lang('add profile'));
432                        $this->t->set_var('lang_domain_name',lang('domainname'));
433                        $this->t->set_var('lang_SMTP_server_hostname_or_IP_address',lang('SMTP-Server hostname or IP address'));
434                        $this->t->set_var('lang_SMTP_server_port',lang('SMTP-Server port'));
435                        $this->t->set_var('lang_Use_SMTP_auth',lang('Use SMTP auth'));
436                        $this->t->set_var('lang_Select_type_of_SMTP_Server',lang('Select type of SMTP Server'));
437                        $this->t->set_var('lang_profile_name',lang('Profile Name'));
438                        $this->t->set_var('lang_default_domain',lang('enter your default mail domain (from: user@domain)'));
439                        $this->t->set_var('lang_organisation_name',lang('name of organisation'));
440                        $this->t->set_var('lang_user_defined_accounts',lang('users can define their own emailaccounts'));
441                        $this->t->set_var('lang_LDAP_server_hostname_or_IP_address',lang('LDAP server hostname or ip address'));
442                        $this->t->set_var('lang_LDAP_server_admin_dn',lang('LDAP server admin DN'));
443                        $this->t->set_var('lang_LDAP_server_admin_pw',lang('LDAP server admin password'));
444                        $this->t->set_var('lang_LDAP_server_base_dn',lang('LDAP server accounts DN'));
445                        $this->t->set_var('lang_use_LDAP_defaults',lang('use LDAP defaults'));
446                        $this->t->set_var('lang_LDAP_settings',lang('LDAP settings'));
447                        $this->t->set_var('lang_select_type_of_imap/pop3_server',lang('select type of IMAP/POP3 server'));
448                        $this->t->set_var('lang_pop3_server_hostname_or_IP_address',lang('POP3 server hostname or ip address'));
449                        $this->t->set_var('lang_pop3_server_port',lang('POP3 server port'));
450                        $this->t->set_var('lang_imap_server_hostname_or_IP_address',lang('IMAP server hostname or ip address'));
451                        $this->t->set_var('lang_imap_server_port',lang('IMAP server port'));
452                        $this->t->set_var('lang_use_tls_encryption',lang('use tls encryption'));
453                        $this->t->set_var('lang_use_tls_authentication',lang('use tls authentication'));
454                        $this->t->set_var('lang_sieve_settings',lang('Sieve settings'));
455                        $this->t->set_var('lang_enable_sieve',lang('enable Sieve'));
456                        $this->t->set_var('lang_sieve_server_hostname_or_ip_address',lang('Sieve server hostname or ip address'));
457                        $this->t->set_var('lang_sieve_server_port',lang('Sieve server port'));
458                        $this->t->set_var('lang_enable_cyrus_imap_administration',lang('enable Cyrus IMAP server administration'));
459                        $this->t->set_var('lang_cyrus_imap_administration',lang('Cyrus IMAP server administration'));
460                        $this->t->set_var('lang_admin_username',lang('admin username'));
461                        $this->t->set_var('lang_admin_password',lang('admin passwort'));
462                        $this->t->set_var('lang_imap_server_logintyp',lang('imap server logintyp'));
463                        $this->t->set_var('lang_standard',lang('standard'));
464                        $this->t->set_var('lang_vmailmgr',lang('Virtual MAIL ManaGeR'));
465                        $this->t->set_var('lang_pre_2001_c_client',lang('IMAP C-Client Version < 2001'));
466                        $this->t->set_var('lang_default_folders', lang('Default Folders'));
467                        $this->t->set_var('lang_trash_folder', lang('Trash Folder'));
468                        $this->t->set_var('lang_sent_folder', lang('Sent Folder'));
469                        $this->t->set_var('lang_drafts_folder', lang('Drafts Folder'));
470                        $this->t->set_var('lang_spam_folder', lang('Spam Folder'));
471                        $this->t->set_var('lang_spam_settings', lang('spam settings'));
472                        $this->t->set_var('lang_create_spam_folder', lang('create spam folder'));
473                        $this->t->set_var('lang_cyrus_user_post_spam', lang('cyrus user post spam'));
474                        # $this->t->set_var('',lang(''));
475                       
476                }
477        }
478?>
Note: See TracBrowser for help on using the repository browser.