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

Revision 7870, 18.2 KB checked in by angelo, 11 years ago (diff)

Ticket #3342 - Configurar Imap automaticamente ao instalar o Expresso pelo instalador automatico

  • 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 countProfiles(){
81                $return =  $this->boemailadmin->getProfileList();
82                (is_array($return) && count($return) > 0) ? $return = count($return) : $return = 0;
83                        return $return;
84        }
85
86       function addDefaultProfile()
87       {
88            $emailServer = $_SESSION['phpgw_info']['expressomail']['email_server'];         
89            $globalSettings = array(
90                        "profileID" => "",
91                        "description" => "Expresso",
92                        "defaultDomain" => $emailServer['defaultDomain'],
93                        "organisationName" => $emailServer['organisationName'],
94                        "userDefinedAccounts" => "0"
95            );
96
97            $smtpSettings   = array(
98                "smtpServer" => "127.0.0.1",
99                "smtpPort" => "25",
100                "smtpAuth" => "",
101                    "smtpType" => "2",
102                    "smtpLDAPServer" => "127.0.0.1",
103                    "smtpLDAPAdminDN" => $emailServer['smtpLDAPAdminDN'],
104                    "smtpLDAPAdminPW" => $emailServer['smtpLDAPAdminPW'],
105                    "smtpLDAPBaseDN" =>  $emailServer['smtpLDAPBaseDN]'],
106                    "smtpLDAPUseDefault" => "yes"
107            );
108
109            $imapSettings = array(
110                    'imapServer' => "127.0.0.1",
111                    'imapPort' => "143",
112                    'imapDelimiter' => "/",
113                    'imapType' => "3",
114                    'imapLoginType' => "standard",
115                    'imapTLSEncryption' => "1",
116                    'imapTLSAuthentication' => "",
117                    'imapoldcclient' => "",
118                    'imapEnableCyrusAdmin' => "yes",
119                    'imapAdminUsername' => "expresso-admin",
120                    'imapAdminPW' => $emailServer['imapAdminPW'],
121                    'imapEnableSieve' => "yes",
122                    'imapSieveServer' => "127.0.0.1",
123                    'imapSievePort' => "2000",
124                    'imapCreateSpamFolder' => "yes",
125                    'imapCyrusUserPostSpam' => "",
126                    'imapDefaultTrashFolder' => $emailServer['imapDefaultTrashFolder'],
127                    'imapDefaultSentFolder' => $emailServer['imapDefaultSentFolder'],
128                    'imapDefaultDraftsFolder' => $emailServer['imapDefaultDraftsFolder'],
129                    'imapDefaultSpamFolder' => $emailServer['imapDefaultSpamFolder']
130            );
131
132            $this->boemailadmin->saveProfile($globalSettings, $smtpSettings, $imapSettings);
133        }
134
135                function css()
136                {
137                        $appCSS =
138                        'th.activetab
139                        {
140                                color:#000000;
141                                background-color:#D3DCE3;
142                                border-top-width : 1px;
143                                border-top-style : solid;
144                                border-top-color : Black;
145                                border-left-width : 1px;
146                                border-left-style : solid;
147                                border-left-color : Black;
148                                border-right-width : 1px;
149                                border-right-style : solid;
150                                border-right-color : Black;
151                        }
152                       
153                        th.inactivetab
154                        {
155                                color:#000000;
156                                background-color:#E8F0F0;
157                                border-bottom-width : 1px;
158                                border-bottom-style : solid;
159                                border-bottom-color : Black;
160                        }
161                       
162                        .td_left { border-left : 1px solid Gray; border-top : 1px solid Gray; }
163                        .td_right { border-right : 1px solid Gray; border-top : 1px solid Gray; }
164                       
165                        div.activetab{ display:inline; }
166                        div.inactivetab{ display:none; }';
167                       
168                        return $appCSS;
169                }
170               
171                function deleteProfile()
172                {
173                        $this->boemailadmin->deleteProfile($_GET['profileid']);
174                        $this->listProfiles();
175                }
176               
177                function display_app_header()
178                {
179                        if(!@is_object($GLOBALS['phpgw']->js))
180                        {
181                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
182                        }
183                        $GLOBALS['phpgw']->js->validate_file('tabs','tabs');
184                        switch($_GET['menuaction'])
185                        {
186                                case 'emailadmin.ui.addProfile':
187                                case 'emailadmin.ui.editProfile':
188                                        $GLOBALS['phpgw']->js->validate_file('jscode','editProfile','emailadmin');
189                                        $GLOBALS['phpgw']->js->set_onload('javascript:initAll();');
190                                        #$GLOBALS['phpgw']->js->set_onload('smtp.init();');
191
192                                        break;
193                        }
194                        $GLOBALS['phpgw']->common->phpgw_header();
195                        echo parse_navbar();
196                }
197
198                function editProfile($_profileID='')
199                {
200                        if($_profileID != '')
201                        {
202                                $profileID = $_profileID;
203                        }
204                        elseif(is_int(intval($_GET['profileid'])) && !empty($_GET['profileid']))
205                        {
206                                $profileID = intval($_GET['profileid']);
207                        }
208                        else
209                        {
210                                return false;
211                        }
212
213                        $profileList = $this->boemailadmin->getProfileList($profileID);
214                        $profileData = $this->boemailadmin->getProfile($profileID);
215                        $this->display_app_header();
216                       
217                        $this->t->set_file(array("body" => "editprofile.tpl"));
218                        $this->t->set_block('body','main');
219                       
220                        $this->translate();
221                       
222                        foreach($profileData as $key => $value)
223                        {
224                                //print "$key $value<br>";
225                                switch($key)
226                                {
227                                        case 'imapEnableCyrusAdmin':
228                                        case 'imapEnableSieve':
229                                        case 'imapTLSAuthentication':
230                                        case 'imapTLSEncryption':
231                                        case 'smtpAuth':
232                                        case 'smtpLDAPUseDefault':
233                                        case 'userDefinedAccounts':
234                                        case 'imapoldcclient':
235                                        case 'imapCreateSpamFolder':
236                                                if($value == 'yes')
237                                                        $this->t->set_var('selected_'.$key,'checked="1"');
238                                                break;
239                                        case 'imapType':       
240                                        case 'smtpType':
241                                        case 'imapLoginType':
242                                                $this->t->set_var('selected_'.$key.'_'.$value,'selected="1"');
243                                                break;
244                                        case 'imapDelimiter':
245                                                if ($value == '/')
246                                                        $this->t->set_var('selected_'.$key.'_slash','selected="1"');
247                                                elseif ($value == '.')
248                                                        $this->t->set_var('selected_'.$key.'_dot','selected="1"');
249                                                break;
250                                        default:
251                                                $this->t->set_var('value_'.$key,$value);
252                                                break;
253                                }
254                        }
255                       
256                        $linkData = array
257                        (
258                                'menuaction'    => 'emailadmin.ui.saveProfile',
259                                'profileID'     => $profileID
260                        );
261                        $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
262                       
263                        $linkData = array
264                        (
265                                'menuaction'    => 'emailadmin.ui.listProfiles'
266                        );
267                        $this->t->set_var('back_url',$GLOBALS['phpgw']->link('/index.php',$linkData));
268
269                        foreach($this->boemailadmin->getSMTPServerTypes() as $key => $value)
270                        {
271                                $this->t->set_var("lang_smtp_option_$key",$value);
272                        };
273                                               
274                        foreach($this->boemailadmin->getIMAPServerTypes() as $key => $value)
275                        {
276                                $this->t->set_var("lang_imap_option_$key",$value['description']);
277                        };
278                                               
279                        $this->t->parse("out","main");
280                        print $this->t->get('out','main');
281                }
282               
283                function listProfiles()
284                {
285                        $this->display_app_header();
286
287                        $this->t->set_file(array("body" => "listprofiles.tpl"));
288                        $this->t->set_block('body','main');
289                       
290                        $this->translate();
291
292                        $profileList = $this->boemailadmin->getProfileList();
293                       
294                        // create the data array
295                        if ($profileList)
296                        {
297                $profileList_count = count($profileList);
298                                for ($i=0; $i < $profileList_count; ++$i)
299                                {
300                                        $linkData = array
301                                        (
302                                                'menuaction'    => 'emailadmin.ui.editProfile',
303                                                'nocache'       => '1',
304                                                'tabpage'       => '3',
305                                                'profileid'     => $profileList[$i]['profileID']
306                                        );
307                                        $imapServerLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['imapServer'].'</a>';
308                                       
309                                        $linkData = array
310                                        (
311                                                'menuaction'    => 'emailadmin.ui.editProfile',
312                                                'nocache'       => '1',
313                                                'tabpage'       => '1',
314                                                'profileid'     => $profileList[$i]['profileID']
315                                        );
316                                        $descriptionLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['description'].'</a>';
317                                       
318                                        $linkData = array
319                                        (
320                                                'menuaction'    => 'emailadmin.ui.editProfile',
321                                                'nocache'       => '1',
322                                                'tabpage'       => '2',
323                                                'profileid'     => $profileList[$i]['profileID']
324                                        );
325                                        $smtpServerLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).'">'.$profileList[$i]['smtpServer'].'</a>';
326                                       
327                                        $linkData = array
328                                        (
329                                                'menuaction'    => 'emailadmin.ui.deleteProfile',
330                                                'profileid'     => $profileList[$i]['profileID']
331                                        );
332                                        $deleteLink = '<a href="'.$GLOBALS['phpgw']->link('/index.php',$linkData).
333                                                      '" onClick="return confirm(\''.lang('Do you really want to delete this Profile').'?\')">'.
334                                                      lang('delete').'</a>';
335                                       
336                                        $data[] = array(
337                                                $descriptionLink,
338                                                $smtpServerLink,
339                                                $imapServerLink,
340                                                $deleteLink
341                                               
342                                        );
343                                }
344                        }
345
346                        // create the array containing the table header
347                        $rows = array(
348                                lang('description'),
349                                lang('smtp server name'),
350                                lang('imap/pop3 server name'),
351                                lang('delete')
352                        );
353                               
354                        // create the table html code
355                        $this->t->set_var('server_next_match',$this->nextMatchTable(
356                                $rows,
357                                $data,
358                                lang('profile list'),
359                                $_start,
360                                $_total,
361                                $_menuAction)
362                        );
363                       
364                        $linkData = array
365                        (
366                                'menuaction'    => 'emailadmin.ui.addProfile'
367                        );
368                        $this->t->set_var('add_link',$GLOBALS['phpgw']->link('/index.php',$linkData));
369
370                        $this->t->parse("out","main");
371                       
372                        print $this->t->get('out','main');
373                       
374                }
375
376                function nextMatchTable($_rows, $_data, $_description, $_start, $_total, $_menuAction)
377                {
378                        $template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
379                        $template->set_file(array("body" => "nextMatch.tpl"));
380                        $template->set_block('body','row_list','rowList');
381                        $template->set_block('body','header_row','headerRow');
382               
383                        $var = Array(
384                                'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
385                                'left_next_matchs'      => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=emailadmin.ui.listServers'),
386                                'right_next_matchs'     => $this->nextmatchs->right('/admin/groups.php',$start,$total,'menuaction=emailadmin.ui.listServers'),
387                                'lang_groups'           => lang('user groups'),
388                                'sort_name'             => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=emailadmin.ui.listServers'),
389                                'description'           => $_description,
390                                'header_edit'           => lang('Edit'),
391                                'header_delete'         => lang('Delete')
392                        );
393                        $template->set_var($var);
394                       
395                        $data = '';
396                        if(is_array($_rows))
397                        {
398                                foreach($_rows as $value)
399                                {
400                                        $data .= "<td align='center'><b>$value</b></td>";
401                                }
402                                $template->set_var('header_row_data', $data);
403                                $template->fp('headerRow','header_row',True);
404                                #$template->fp('header_row','header_row',True);
405                        }
406
407                        if(is_array($_data))
408                        {
409                                foreach($_data as $value)
410                                {
411                                        $data = '';
412                                        foreach($value as $rowData)
413                                        {
414                                                $data .= "<td align='center'>$rowData</td>";
415                                        }
416                                        $template->set_var('row_data', $data);
417                                        $template->fp('rowList','row_list',True);
418                                }
419                        }
420
421                        return $template->fp('out','body');
422                       
423                }
424
425                function saveProfile()
426                {
427                        $globalSettings = array();
428                        $smtpSettings   = array();
429                        $imapSettings   = array();
430                       
431                        // try to get the profileID
432                        if(is_int(intval($_GET['profileID'])) && !empty($_GET['profileID']))
433                        {
434                                $globalSettings['profileID'] = intval($_GET['profileID']);
435                        }
436                        $globalSettings['description'] = $_POST['globalsettings']['description'];
437                        $globalSettings['defaultDomain'] = $_POST['globalsettings']['defaultDomain'];
438                        $globalSettings['organisationName'] = $_POST['globalsettings']['organisationName'];
439                        $globalSettings['userDefinedAccounts'] = $_POST['globalsettings']['userDefinedAccounts'];
440                       
441                       
442                        // get the settings for the smtp server
443                        $smtpType = $_POST['smtpsettings']['smtpType'];
444                        foreach($this->boemailadmin->getFieldNames($smtpType,'smtp') as $key)
445                        {
446                                $smtpSettings[$key] = $_POST['smtpsettings'][$smtpType][$key];
447                        }
448                        $smtpSettings['smtpType'] = $smtpType;
449                       
450                        #_debug_array($smtpSettings);
451                       
452                        // get the settings for the imap/pop3 server
453                        $imapType = $_POST['imapsettings']['imapType'];
454                        foreach($this->boemailadmin->getFieldNames($imapType,'imap') as $key)
455                        {
456                                $imapSettings[$key] = $_POST['imapsettings'][$imapType][$key];
457                        }
458                        $imapSettings['imapType'] = $imapType;
459                       
460                        $this->boemailadmin->saveProfile($globalSettings, $smtpSettings, $imapSettings);
461                        #if ($HTTP_POST_VARS['bo_action'] == 'save_ldap' || $HTTP_GET_VARS['bo_action'] == 'save_ldap')
462                        #{
463                                $this->listProfiles();
464                        #}
465                        #else
466                        #{
467                        #       $this->editServer($HTTP_GET_VARS["serverid"],$HTTP_GET_VARS["pagenumber"]);
468                        #}
469                }
470               
471                function translate()
472                {
473                        # skeleton
474                        # $this->t->set_var('',lang(''));
475                       
476                        $this->t->set_var('lang_server_name',lang('server name'));
477                        $this->t->set_var('lang_server_description',lang('description'));
478                        $this->t->set_var('lang_edit',lang('edit'));
479                        $this->t->set_var('lang_save',lang('save'));
480                        $this->t->set_var('lang_delete',lang('delete'));
481                        $this->t->set_var('lang_back',lang('back'));
482                        $this->t->set_var('lang_remove',lang('remove'));
483                        $this->t->set_var('lang_ldap_server',lang('LDAP server'));
484                        $this->t->set_var('lang_ldap_basedn',lang('LDAP basedn'));
485                        $this->t->set_var('lang_ldap_server_admin',lang('admin dn'));
486                        $this->t->set_var('lang_ldap_server_password',lang('admin password'));
487                        $this->t->set_var('lang_add_profile',lang('add profile'));
488                        $this->t->set_var('lang_domain_name',lang('domainname'));
489                        $this->t->set_var('lang_SMTP_server_hostname_or_IP_address',lang('SMTP-Server hostname or IP address'));
490                        $this->t->set_var('lang_SMTP_server_port',lang('SMTP-Server port'));
491                        $this->t->set_var('lang_Use_SMTP_auth',lang('Use SMTP auth'));
492                        $this->t->set_var('lang_Select_type_of_SMTP_Server',lang('Select type of SMTP Server'));
493                        $this->t->set_var('lang_profile_name',lang('Profile Name'));
494                        $this->t->set_var('lang_default_domain',lang('enter your default mail domain (from: user@domain)'));
495                        $this->t->set_var('lang_organisation_name',lang('name of organisation'));
496                        $this->t->set_var('lang_user_defined_accounts',lang('users can define their own emailaccounts'));
497                        $this->t->set_var('lang_LDAP_server_hostname_or_IP_address',lang('LDAP server hostname or ip address'));
498                        $this->t->set_var('lang_LDAP_server_admin_dn',lang('LDAP server admin DN'));
499                        $this->t->set_var('lang_LDAP_server_admin_pw',lang('LDAP server admin password'));
500                        $this->t->set_var('lang_LDAP_server_base_dn',lang('LDAP server accounts DN'));
501                        $this->t->set_var('lang_use_LDAP_defaults',lang('use LDAP defaults'));
502                        $this->t->set_var('lang_LDAP_settings',lang('LDAP settings'));
503                        $this->t->set_var('lang_select_type_of_imap/pop3_server',lang('select type of IMAP/POP3 server'));
504                        $this->t->set_var('lang_pop3_server_hostname_or_IP_address',lang('POP3 server hostname or ip address'));
505                        $this->t->set_var('lang_pop3_server_port',lang('POP3 server port'));
506                        $this->t->set_var('lang_imap_server_hostname_or_IP_address',lang('IMAP server hostname or ip address'));
507                        $this->t->set_var('lang_imap_server_port',lang('IMAP server port'));
508                        $this->t->set_var('lang_use_tls_encryption',lang('use tls encryption'));
509                        $this->t->set_var('lang_use_tls_authentication',lang('use tls authentication'));
510                        $this->t->set_var('lang_sieve_settings',lang('Sieve settings'));
511                        $this->t->set_var('lang_enable_sieve',lang('enable Sieve'));
512                        $this->t->set_var('lang_sieve_server_hostname_or_ip_address',lang('Sieve server hostname or ip address'));
513                        $this->t->set_var('lang_sieve_server_port',lang('Sieve server port'));
514                        $this->t->set_var('lang_enable_cyrus_imap_administration',lang('enable Cyrus IMAP server administration'));
515                        $this->t->set_var('lang_cyrus_imap_administration',lang('Cyrus IMAP server administration'));
516                        $this->t->set_var('lang_admin_username',lang('admin username'));
517                        $this->t->set_var('lang_admin_password',lang('admin passwort'));
518                        $this->t->set_var('lang_imap_server_logintyp',lang('imap server logintyp'));
519                        $this->t->set_var('lang_standard',lang('standard'));
520                        $this->t->set_var('lang_vmailmgr',lang('Virtual MAIL ManaGeR'));
521                        $this->t->set_var('lang_pre_2001_c_client',lang('IMAP C-Client Version < 2001'));
522                        $this->t->set_var('lang_default_folders', lang('Default Folders'));
523                        $this->t->set_var('lang_trash_folder', lang('Trash Folder'));
524                        $this->t->set_var('lang_sent_folder', lang('Sent Folder'));
525                        $this->t->set_var('lang_drafts_folder', lang('Drafts Folder'));
526                        $this->t->set_var('lang_spam_folder', lang('Spam Folder'));
527                        $this->t->set_var('lang_spam_settings', lang('spam settings'));
528                        $this->t->set_var('lang_create_spam_folder', lang('create spam folder'));
529                        $this->t->set_var('lang_cyrus_user_post_spam', lang('cyrus user post spam'));
530                        # $this->t->set_var('',lang(''));
531                       
532                }
533        }
534?>
Note: See TracBrowser for help on using the repository browser.