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

Revision 7673, 16.0 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

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