source: trunk/expressoAdmin1_2/inc/class.uimaillists.inc.php @ 309

Revision 309, 17.1 KB checked in by niltonneto, 16 years ago (diff)

Sincronização com versão publicada em 04/06/2008.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /*************************************************************************************\
3        * Expresso Administração                                                                                                     *
4        * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br)        *
5        * -----------------------------------------------------------------------------------*
6        *  This program is free software; you can redistribute it and/or modify it                       *
7        *  under the terms of the GNU General Public License as published by the                         *
8        *  Free Software Foundation; either version 2 of the License, or (at your                        *
9        *  option) any later version.                                                                                                            *
10        \*************************************************************************************/
11
12        class uimaillists
13        {
14                var $public_functions = array
15                (
16                        'list_maillists'        => True,
17                        'add_maillists'         => True,
18                        'edit_maillists'        => True,
19                        'scl_maillists'         => True,
20                        'css'                           => True
21                );
22
23                var $nextmatchs;
24                var $functions;
25                       
26                function uimaillists()
27                {
28                        $this->maillist         = CreateObject('expressoAdmin1_2.maillist');
29                        $this->functions        = CreateObject('expressoAdmin1_2.functions');
30                        $this->nextmatchs       = CreateObject('phpgwapi.nextmatchs');
31
32                        $c = CreateObject('phpgwapi.config','expressoAdmin1_2');
33                        $c->read_repository();
34                        $this->current_config = $c->config_data;
35
36                        if(!@is_object($GLOBALS['phpgw']->js))
37                        {
38                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
39                        }
40                        $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao
41                        $GLOBALS['phpgw']->js->validate_file('jscode','expressoadmin','expressoAdmin1_2');
42                        $GLOBALS['phpgw']->js->validate_file('jscode','maillists','expressoAdmin1_2');
43                }
44               
45                function list_maillists()
46                {
47                       
48                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
49                        $manager_acl = $this->functions->read_acl($manager_lid);
50                        $manager_contexts = $manager_acl['contexts'];
51                        foreach ($manager_acl['contexts_display'] as $index=>$tmp_context)
52                        {
53                                $context_display .= '<br>'.$tmp_context;
54                        }
55                       
56                        // Verifica se tem acesso a este modulo
57                        if (!$this->functions->check_acl($manager_lid,'list_maillists'))
58                        {
59                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
60                        }
61
62                        if(isset($_POST['query']))
63                        {
64                                // limit query to limit characters
65                                if(eregi('^[a-z_0-9_%-].+$',$_POST['query']))
66                                        $GLOBALS['query'] = $_POST['query'];
67                        }
68
69                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
70                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
71                       
72                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Email Lists');
73                        $GLOBALS['phpgw']->common->phpgw_header();
74
75                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
76                        $p->set_file(array('maillists'   => 'maillists.tpl'));
77                        $p->set_block('maillists','list','list');
78                        $p->set_block('maillists','row','row');
79                        $p->set_block('maillists','row_empty','row_empty');
80                       
81                        // Seta as variaveis padroes.
82                        $var = Array(
83                                'th_bg'                                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
84                                'back_url'                                      => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
85                                'add_action'                            => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimaillists.add_maillists'),
86                                'add_email_lists_disabled'      => $this->functions->check_acl($manager_lid,'add_maillists') ? '' : 'disabled',
87                                'context_display'                       => $context_display,
88                                'lang_email_lists_uid'          => lang('Email Lists Logins'),
89                                'lang_email_lists_names'        => lang('Email Lists Names'),
90                                'lang_add_email_lists'          => lang('Add Email Lists'),
91                                'lang_edit'                             => lang('Edit'),
92                                'lang_scl'                              => 'SCL',
93                                'lang_delete'                           => 'Excluir',
94                                'lang_view'                                     => lang('View'),
95                                'lang_back'                                     => lang('back'),
96                                'lang_context'                          => lang('context'),
97                                'lang_email'                            => lang('E-mail'),
98                                'lang_search'                           => lang('search')
99                        );
100                        $p->set_var($var);
101
102                        // Save query
103                        $p->set_var('query', $GLOBALS['query']);
104                       
105                        //Admin make a search
106                        if ($GLOBALS['query'] != '')
107                        {
108                                $maillists_info = $this->functions->get_list('maillists', $GLOBALS['query'], $manager_contexts);
109                        }
110                        $total = count($maillists_info);
111
112                        if (!count($total) && $GLOBALS['query'] != '')
113                        {
114                                $p->set_var('message',lang('No matches found'));
115                        }
116                        else if ($total)
117                        {
118                                if ($this->functions->check_acl($manager_lid,'edit_maillists'))
119                                {
120                                        $can_edit = True;
121                                }
122                                if ($this->functions->check_acl($manager_lid,'delete_maillists'))
123                                {
124                                        $can_delete = True;
125                                }
126                                if ($this->functions->check_acl($manager_lid,'edit_scl_email_lists'))
127                                {
128                                        $can_edit_scl = True;
129                                }
130
131
132                                foreach($maillists_info as $maillist)
133                                {
134                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
135                                        $var = array(
136                                                'tr_color'              => $tr_color,
137                                                'row_uid'               => $maillist['uid'],
138                                                'row_name'      => $maillist['name'],
139                                                'row_email'     => $maillist['email']
140                                        );
141                                        $p->set_var($var);
142
143                                        if ($can_edit)
144                                        {
145                                                $p->set_var('edit_link',$this->row_action('edit','maillists',$maillist['uidnumber'],$maillist['uid']));
146                                        }
147                                        else
148                                        {
149                                                $p->set_var('edit_link','&nbsp;');
150                                        }
151
152                                        if ( ($can_edit_scl) && ($this->current_config['expressoAdmin_scl']) )
153                                        {
154                                                $p->set_var('scl_link',$this->row_action('scl','maillists',$maillist['uidnumber'],$maillist['uid']));
155                                        }
156                                        else
157                                        {
158                                                $p->set_var('scl_link','&nbsp;');
159                                        }
160
161                                        if ($can_delete)
162                                        {
163                                                $p->set_var('delete_link',"<a href='#' onClick='javascript:delete_maillist(\"".$maillist['uid']."\",\"".$maillist['uidnumber']."\");'>Excluir</a>");
164                                        }
165                                        else
166                                                $p->set_var('delete_link','&nbsp;');
167                                       
168                                        $p->fp('rows','row',True);
169                                }
170                        }
171                        $p->parse('rows','row_empty',True);
172                        $p->set_var($var);
173                        $p->pfp('out','list');                 
174                }
175               
176                function add_maillists()
177                {
178                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
179
180                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
181                        $manager_acl = $this->functions->read_acl($manager_lid);
182                        $manager_contexts = $manager_acl['contexts'];
183
184                        // Verifica se tem acesso a este modulo
185                        if (!$this->functions->check_acl($manager_lid,'add_maillists'))
186                        {
187                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
188                        }
189
190                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
191                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
192                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Email List');
193                        $GLOBALS['phpgw']->common->phpgw_header();
194                       
195                        // Set o template
196                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
197                        $p->set_file(Array('create_maillist' => 'maillists_form.tpl'));
198
199                        // Obtem combos das organizações.
200                        foreach ($manager_contexts as $index=>$context)
201                                $combo_manager_org .= $this->functions->get_organizations($context);
202                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], '', true, true, true);                 
203                       
204                        // Seta variaveis utilizadas pelo tpl.
205                        $var = Array(
206                                'color_bg1'                                     => "#E8F0F0",
207                                'color_bg2'                                     => "#D3DCE3",
208                                'type'                                          => 'create_maillist',
209                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
210                                'uid'                                           => 'lista-',
211                                'accountStatus_checked'         => 'CHECKED',
212                                'restrictionsOnEmailLists'      => $this->current_config['expressoAdmin_restrictionsOnEmailLists'],
213                                'lang_back'                                     => lang('Back'),
214                                'lang_save'                                     => lang('save'),
215                                'lang_maillist_organization'=> lang('Maillist Organization'),
216                                'lang_search_organization'      => lang('Search Organiztion'),
217                                'lang_search_user'                      => lang('Search user'),
218                                'lang_organizations'            => lang('Organizations'),
219                                'lang_maillist_uid'                     => lang('Maillist login'),
220                                'lang_maillist_mail'            => lang('Maillist Mail'),
221                                'lang_maillist_name'            => lang('Maillist name'),
222                                'lang_maillist_users'           => lang('Maillist users'),
223                                'lang_add_user'                         => lang('Add User'),
224                                'lang_rem_user'                         => lang('Remove User'),
225                                'lang_all_users'                        => lang('Show users from all sub-organizations'),
226                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimaillists.list_maillists'),
227                                'combo_manager_org'                     => $combo_manager_org,
228                                'combo_all_orgs'                        => $combo_all_orgs,
229                                'defaultDomain'                         => $this->current_config['expressoAdmin_defaultDomain']
230                        );
231                        $p->set_var($var);
232                       
233                        $p->pfp('out','create_maillist');
234                }
235               
236                function edit_maillists()
237                {
238                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
239
240                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
241                        $manager_acl = $this->functions->read_acl($manager_lid);
242                        $manager_contexts = $manager_acl['contexts'];
243
244                        // Verifica se tem acesso a este modulo
245                        if (!$this->functions->check_acl($manager_lid,'edit_maillists'))
246                        {
247                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
248                        }
249                       
250                        // GET all infomations about the group.
251                        $maillist_info = $this->maillist->get_info($_GET['uidnumber']);
252                       
253                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
254                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
255                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Email Lists');
256                        $GLOBALS['phpgw']->common->phpgw_header();
257
258                        // Set o template
259                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
260                        $p->set_file(Array('edit_maillist' => 'maillists_form.tpl'));
261
262                        // Obtem combos das organizações.
263                        foreach ($manager_contexts as $index=>$context)
264                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($maillist_info['context'])));
265                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($maillist_info['context'])), true, true, true);                 
266
267                        // Usuarios da lista.
268                        $user_count = 0;
269                        if (count($maillist_info['mailForwardingAddress_info']) > 0)
270                        {
271                                foreach ($maillist_info['mailForwardingAddress_info'] as $mail=>$userinfo)
272                                {
273                                        $array_users[$mail] = $userinfo['cn'];
274                                        $array_users_uid[$mail] = $userinfo['uid'];
275                                        $array_users_type[$mail] = $userinfo['type'];
276                                }
277                                natcasesort($array_users);
278                                foreach ($array_users as $mail=>$cn)
279                                {
280                                        $user_count++;
281                                        if ($array_users_type[$mail] == 'u')
282                                        {
283                                                $users .= "<option value=" . $mail . ">" . $cn .  " [" . $array_users_uid[$mail] . "]</option>";
284                                        }
285                                        elseif ($array_users_type[$mail] == 'l')
286                                        {
287                                                $lists .= "<option value=" . $mail . ">" . $cn .  " [" . $array_users_uid[$mail] . "]</option>";
288                                        }
289                                        else
290                                        {
291                                                $mail_not_found .= "<option value=" . $mail . ">" . $cn .  " [" . $array_users_uid[$mail] . "]</option>";
292                                        }
293                                }
294                               
295                                if ($mail_not_found != '')
296                                {
297                                        $opt_tmp_mail_not_found = '<option  value="-1" disabled>--------------------&nbsp;&nbsp;&nbsp;&nbsp;E-mails não encontrados&nbsp;&nbsp;&nbsp;&nbsp;------------------ </option>'."\n";
298                                        $ea_select_usersInMaillist .= $opt_tmp_mail_not_found . $mail_not_found;
299                                }
300                                if ($lists != '')
301                                {
302                                        $opt_tmp_lists  = '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;Listas&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";
303                                        $ea_select_usersInMaillist .= $opt_tmp_lists . $lists;
304                                }
305                                $opt_tmp_users  = '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;Usuários&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
306                                $ea_select_usersInMaillist .= $opt_tmp_users . $users;
307                        }
308
309                        // Seta variaveis utilizadas pelo tpl.
310                        $var = Array(
311                                'color_bg1'                                             => "#E8F0F0",
312                                'color_bg2'                                             => "#D3DCE3",
313                                'type'                                                  => 'edit_maillist',
314                                'ldap_context'                                  => $GLOBALS['phpgw_info']['server']['ldap_context'],
315                                'lang_back'                                             => lang('Back'),
316                                'lang_save'                                             => lang('save'),
317                                'lang_maillist_organization'    => lang('Maillist Organization'),
318                                'lang_search_organization'              => lang('Search Organiztion'),
319                                'lang_search_user'                              => lang('Search user'),
320                                'lang_organizations'                    => lang('Organizations'),
321                                'lang_maillist_uid'                             => lang('Maillist login'),
322                                'lang_maillist_mail'                    => lang('Maillist Mail'),
323                                'lang_maillist_name'                    => lang('Maillist name'),
324                                'lang_maillist_users'                   => lang('Maillist users'),
325                                'lang_add_user'                                 => lang('Add User'),
326                                'lang_rem_user'                                 => lang('Remove User'),
327                                'lang_all_users'                                => lang('Select users from all sub-organizations'),
328                                'back_url'                                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimaillists.list_maillists'),
329                                'combo_manager_org'                             => $combo_manager_org,
330                                'combo_all_orgs'                                => $combo_all_orgs,
331                                'uidnumber'                                             => $_GET['uidnumber'],
332                                'uid'                                                   => $maillist_info['uid'],
333                                'mail'                                                  => $maillist_info['mail'],
334                                'cn'                                                    => $maillist_info['cn'],
335                                'user_count'                                    => $user_count,
336                                'accountStatus_checked'                 => $maillist_info['accountStatus'] == 'active' ? 'CHECKED' : '',
337                                'phpgwAccountVisible_checked'   => $maillist_info['phpgwAccountVisible'] == '-1' ? 'CHECKED' : '',
338                                'ea_select_usersInMaillist'             => $ea_select_usersInMaillist,
339                                'defaultDomain'                                 => $this->current_config['expressoAdmin_defaultDomain']
340                        );
341                        $p->set_var($var);
342                       
343                        $p->pfp('out','edit_maillist');
344                }
345               
346                function scl_maillists()
347                {
348                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
349                       
350                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
351                        $manager_acl = $this->functions->read_acl($manager_lid);
352                        $manager_contexts = $manager_acl['contexts'];
353                                               
354                        // Verifica se tem acesso a este modulo
355                        if (!$this->functions->check_acl($manager_lid,'edit_maillists'))
356                        {
357                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
358                        }
359                       
360                        // GET all infomations about the group.
361                        $maillist_info = $this->maillist->get_scl_info($_GET['uidnumber']);
362                       
363                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
364                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
365                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sending Control List');
366                        $GLOBALS['phpgw']->common->phpgw_header();
367
368                        // Set o template
369                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
370                        $p->set_file(Array('sql_maillist' => 'maillists_scl.tpl'));
371
372                        // Pega combo das organizações e seleciona a org da lista.
373                        // $org = $this->functions->get_organizations($manager_context, trim(strtolower($maillist_info['context'])));
374                        foreach ($manager_contexts as $index=>$context)
375                                $sectors .= $this->functions->get_organizations($context, trim(strtolower($maillist_info['context'])) );
376
377                        // Usuarios de senders.
378                        if (count($maillist_info['senders_info']) > 0)
379                        {
380                                foreach ($maillist_info['senders_info'] as $mail=>$senderinfo)
381                                {
382                                        $array_senders[$mail] = $senderinfo['cn'];
383                                }
384                                natcasesort($array_senders);
385                                foreach ($array_senders as $mail=>$cn)
386                                {
387                                        $ea_select_users_SCL_Maillist .= "<option value=" . $mail . ">" . $cn . " [" . $mail . "]</option>";
388                                }
389                        }
390
391                        // Seta variaveis utilizadas pelo tpl.
392                        $var = Array(
393                                'color_bg1'                                             => "#E8F0F0",
394                                'color_bg2'                                             => "#D3DCE3",
395                                'type'                                                  => 'edit_maillist',
396                                'ldap_context'                                  => $GLOBALS['phpgw_info']['server']['ldap_context'],
397                                'dn'                                                    => $maillist_info['dn'],
398                                'lang_back'                                             => lang('Back'),
399                                'lang_save'                                             => lang('save'),
400                                'lang_org'                                              => lang('Organizations'),
401                                'lang_maillist_uid'                             => lang('Maillist login'),
402                                'lang_maillist_mail'                    => lang('Maillist Mail'),
403                                'lang_maillist_name'                    => lang('Maillist name'),
404                                'lang_maillist_users'                   => lang('Maillist users'),
405                                'lang_add_user'                                 => lang('Add User'),
406                                'lang_rem_user'                                 => lang('Remove User'),
407                                'lang_all_users'                                => lang('Show users from all sub-organizations'),
408                                'back_url'                                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimaillists.list_maillists'),
409                                'combo_org'                                             => $sectors,
410                                'uidnumber'                                             => $_GET['uidnumber'],
411                                'uid'                                                   => $maillist_info['uid'],
412                                'mail'                                                  => $maillist_info['mail'],
413                                'cn'                                                    => $maillist_info['cn'],
414                                'accountRestrictive_checked'    => $maillist_info['accountRestrictive'] == 'mailListRestriction' ? 'CHECKED' : '',
415                                'participantCanSendMail_checked'=> $maillist_info['participantCanSendMail'] == 'TRUE' ? 'CHECKED' : '',
416                                'ea_select_users_SCL_Maillist'  => $ea_select_users_SCL_Maillist
417                        );
418                        $p->set_var($var);
419                       
420                        $p->pfp('out','sql_maillist');
421                }
422               
423                function row_action($action,$type,$uidnumber,$maillist_uid)
424                {
425                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
426                                'menuaction'            => 'expressoAdmin1_2.uimaillists.'.$action.'_'.$type,
427                                'uidnumber'                     => $uidnumber,
428                                'maillist_uid'          => $maillist_uid
429                        )).'"> '.lang($action).' </a>';
430                }
431               
432                function css()
433                {
434                        $appCSS = '';
435                        return $appCSS;
436                }
437        }
438?>
Note: See TracBrowser for help on using the repository browser.