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

Revision 180, 16.9 KB checked in by niltonneto, 16 years ago (diff)
  • 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
113                        if (!count($total) && $GLOBALS['query'] != '')
114                        {
115                                $p->set_var('message',lang('No matches found'));
116                        }
117                        else if ($total)
118                        {
119                                if ($this->functions->check_acl($manager_lid,'edit_maillists'))
120                                {
121                                        $can_edit = True;
122                                }
123                                if ($this->functions->check_acl($manager_lid,'delete_maillists'))
124                                {
125                                        $can_delete = True;
126                                }
127
128                                foreach($maillists_info as $maillist)
129                                {
130                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
131                                        $var = array(
132                                                'tr_color'              => $tr_color,
133                                                'row_uid'               => $maillist['uid'],
134                                                'row_name'      => $maillist['name'],
135                                                'row_email'     => $maillist['email']
136                                        );
137                                        $p->set_var($var);
138
139                                        if ($can_edit)
140                                        {
141                                                $p->set_var('edit_link',$this->row_action('edit','maillists',$maillist['uidnumber'],$maillist['uid']));
142                                                $p->set_var('scl_link',$this->row_action('scl','maillists',$maillist['uidnumber'],$maillist['uid']));
143                                        }
144                                        else
145                                        {
146                                                $p->set_var('edit_link','&nbsp;');
147                                                $p->set_var('scl_link','&nbsp;');
148                                        }
149
150                                        if ($can_delete)
151                                        {
152                                                $p->set_var('delete_link',"<a href='#' onClick='javascript:delete_maillist(\"".$maillist['uid']."\",\"".$maillist['uidnumber']."\");'>Excluir</a>");
153                                        }
154                                        else
155                                                $p->set_var('delete_link','&nbsp;');
156                                       
157                                        $p->fp('rows','row',True);
158                                }
159                        }
160                        $p->parse('rows','row_empty',True);
161                        $p->set_var($var);
162                        $p->pfp('out','list');                 
163                }
164               
165                function add_maillists()
166                {
167                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
168
169                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
170                        $manager_acl = $this->functions->read_acl($manager_lid);
171                        $manager_contexts = $manager_acl['contexts'];
172
173                        // Verifica se tem acesso a este modulo
174                        if (!$this->functions->check_acl($manager_lid,'add_maillists'))
175                        {
176                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
177                        }
178
179                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
180                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
181                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Email List');
182                        $GLOBALS['phpgw']->common->phpgw_header();
183                       
184                        // Set o template
185                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
186                        $p->set_file(Array('create_maillist' => 'maillists_form.tpl'));
187
188                        // Obtem combos das organizações.
189                        foreach ($manager_contexts as $index=>$context)
190                                $combo_manager_org .= $this->functions->get_organizations($context);
191                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], '', true, true);                       
192                       
193                        // Seta variaveis utilizadas pelo tpl.
194                        $var = Array(
195                                'color_bg1'                                     => "#E8F0F0",
196                                'color_bg2'                                     => "#D3DCE3",
197                                'type'                                          => 'create_maillist',
198                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
199                                'uid'                                           => 'lista-',
200                                'accountStatus_checked'         => 'CHECKED',
201                                'restrictionsOnEmailLists'      => $this->current_config['expressoAdmin_restrictionsOnEmailLists'],
202                                'lang_back'                                     => lang('Back'),
203                                'lang_save'                                     => lang('save'),
204                                'lang_maillist_organization'=> lang('Maillist Organization'),
205                                'lang_search_organization'      => lang('Search Organiztion'),
206                                'lang_search_user'                      => lang('Search user'),
207                                'lang_organizations'            => lang('Organizations'),
208                                'lang_maillist_uid'                     => lang('Maillist login'),
209                                'lang_maillist_mail'            => lang('Maillist Mail'),
210                                'lang_maillist_name'            => lang('Maillist name'),
211                                'lang_maillist_users'           => lang('Maillist users'),
212                                'lang_add_user'                         => lang('Add User'),
213                                'lang_rem_user'                         => lang('Remove User'),
214                                'lang_all_users'                        => lang('Show users from all sub-organizations'),
215                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimaillists.list_maillists'),
216                                'combo_manager_org'                     => $combo_manager_org,
217                                'combo_all_orgs'                        => $combo_all_orgs,
218                                'defaultDomain'                         => $this->current_config['expressoAdmin_defaultDomain']
219                        );
220                        $p->set_var($var);
221                       
222                        $p->pfp('out','create_maillist');
223                }
224               
225                function edit_maillists()
226                {
227                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
228
229                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
230                        $manager_acl = $this->functions->read_acl($manager_lid);
231                        $manager_contexts = $manager_acl['contexts'];
232
233                        // Verifica se tem acesso a este modulo
234                        if (!$this->functions->check_acl($manager_lid,'edit_maillists'))
235                        {
236                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
237                        }
238                       
239                        // GET all infomations about the group.
240                        $maillist_info = $this->maillist->get_info($_GET['uidnumber']);
241                       
242                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
243                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
244                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Email Lists');
245                        $GLOBALS['phpgw']->common->phpgw_header();
246
247                        // Set o template
248                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
249                        $p->set_file(Array('edit_maillist' => 'maillists_form.tpl'));
250
251                        // Obtem combos das organizações.
252                        foreach ($manager_contexts as $index=>$context)
253                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($maillist_info['context'])));
254                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($maillist_info['context'])), true, true);                       
255
256                        // Usuarios da lista.
257                        $user_count = 0;
258                        if (count($maillist_info['mailForwardingAddress_info']) > 0)
259                        {
260                                foreach ($maillist_info['mailForwardingAddress_info'] as $mail=>$userinfo)
261                                {
262                                        $array_users[$mail] = $userinfo['cn'];
263                                        $array_users_uid[$mail] = $userinfo['uid'];
264                                        $array_users_type[$mail] = $userinfo['type'];
265                                }
266                                natcasesort($array_users);
267                                foreach ($array_users as $mail=>$cn)
268                                {
269                                        $user_count++;
270                                        if ($array_users_type[$mail] == 'u')
271                                        {
272                                                $users .= "<option value=" . $mail . ">" . $cn .  " [" . $array_users_uid[$mail] . "]</option>";
273                                        }
274                                        elseif ($array_users_type[$mail] == 'l')
275                                        {
276                                                $lists .= "<option value=" . $mail . ">" . $cn .  " [" . $array_users_uid[$mail] . "]</option>";
277                                        }
278                                        else
279                                        {
280                                                $mail_not_found .= "<option value=" . $mail . ">" . $cn .  " [" . $array_users_uid[$mail] . "]</option>";
281                                        }
282                                }
283                               
284                                if ($mail_not_found != '')
285                                {
286                                        $opt_tmp_mail_not_found = '<option  value="-1" disabled>--------------------&nbsp;&nbsp;&nbsp;&nbsp;E-mails não encontrados&nbsp;&nbsp;&nbsp;&nbsp;------------------ </option>'."\n";
287                                        $ea_select_usersInMaillist .= $opt_tmp_mail_not_found . $mail_not_found;
288                                }
289                                if ($lists != '')
290                                {
291                                        $opt_tmp_lists  = '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;Listas&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";
292                                        $ea_select_usersInMaillist .= $opt_tmp_lists . $lists;
293                                }
294                                $opt_tmp_users  = '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;Usuários&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
295                                $ea_select_usersInMaillist .= $opt_tmp_users . $users;
296                        }
297
298                        // Seta variaveis utilizadas pelo tpl.
299                        $var = Array(
300                                'color_bg1'                                             => "#E8F0F0",
301                                'color_bg2'                                             => "#D3DCE3",
302                                'type'                                                  => 'edit_maillist',
303                                'ldap_context'                                  => $GLOBALS['phpgw_info']['server']['ldap_context'],
304                                'lang_back'                                             => lang('Back'),
305                                'lang_save'                                             => lang('save'),
306                                'lang_maillist_organization'    => lang('Maillist Organization'),
307                                'lang_search_organization'              => lang('Search Organiztion'),
308                                'lang_search_user'                              => lang('Search user'),
309                                'lang_organizations'                    => lang('Organizations'),
310                                'lang_maillist_uid'                             => lang('Maillist login'),
311                                'lang_maillist_mail'                    => lang('Maillist Mail'),
312                                'lang_maillist_name'                    => lang('Maillist name'),
313                                'lang_maillist_users'                   => lang('Maillist users'),
314                                'lang_add_user'                                 => lang('Add User'),
315                                'lang_rem_user'                                 => lang('Remove User'),
316                                'lang_all_users'                                => lang('Select users from all sub-organizations'),
317                                'back_url'                                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimaillists.list_maillists'),
318                                'combo_manager_org'                             => $combo_manager_org,
319                                'combo_all_orgs'                                => $combo_all_orgs,
320                                'uidnumber'                                             => $_GET['uidnumber'],
321                                'uid'                                                   => $maillist_info['uid'],
322                                'mail'                                                  => $maillist_info['mail'],
323                                'cn'                                                    => $maillist_info['cn'],
324                                'user_count'                                    => $user_count,
325                                'accountStatus_checked'                 => $maillist_info['accountStatus'] == 'active' ? 'CHECKED' : '',
326                                'phpgwAccountVisible_checked'   => $maillist_info['phpgwAccountVisible'] == '-1' ? 'CHECKED' : '',
327                                'ea_select_usersInMaillist'             => $ea_select_usersInMaillist,
328                                'defaultDomain'                                 => $this->current_config['expressoAdmin_defaultDomain']
329                        );
330                        $p->set_var($var);
331                       
332                        $p->pfp('out','edit_maillist');
333                }
334               
335                function scl_maillists()
336                {
337                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
338                       
339                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
340                        $manager_acl = $this->functions->read_acl($manager_lid);
341                        $manager_contexts = $manager_acl['contexts'];
342                                               
343                        // Verifica se tem acesso a este modulo
344                        if (!$this->functions->check_acl($manager_lid,'edit_maillists'))
345                        {
346                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
347                        }
348                       
349                        // GET all infomations about the group.
350                        $maillist_info = $this->maillist->get_scl_info($_GET['uidnumber']);
351                       
352                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
353                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
354                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sending Control List');
355                        $GLOBALS['phpgw']->common->phpgw_header();
356
357                        // Set o template
358                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
359                        $p->set_file(Array('sql_maillist' => 'maillists_scl.tpl'));
360
361                        // Pega combo das organizações e seleciona a org da lista.
362                        // $org = $this->functions->get_organizations($manager_context, trim(strtolower($maillist_info['context'])));
363                        foreach ($manager_contexts as $index=>$context)
364                                $sectors .= $this->functions->get_organizations($context, trim(strtolower($maillist_info['context'])) );
365
366                        // Usuarios de senders.
367                        if (count($maillist_info['senders_info']) > 0)
368                        {
369                                foreach ($maillist_info['senders_info'] as $uidnumber=>$senderinfo)
370                                {
371                                        $array_senders[$uidnumber] = $senderinfo['cn'];
372                                }
373                                natcasesort($array_senders);
374                                foreach ($array_senders as $uidnumber=>$cn)
375                                {
376                                        $ea_select_users_SCL_Maillist .= "<option value=" . $uidnumber . ">" . $cn . " [" . $maillist_info['senders_info'][$uidnumber]['mail'] . "]</option>";
377                                }
378                        }
379
380                        // Seta variaveis utilizadas pelo tpl.
381                        $var = Array(
382                                'color_bg1'                                             => "#E8F0F0",
383                                'color_bg2'                                             => "#D3DCE3",
384                                'type'                                                  => 'edit_maillist',
385                                'ldap_context'                                  => $GLOBALS['phpgw_info']['server']['ldap_context'],
386                                'dn'                                                    => $maillist_info['dn'],
387                                'lang_back'                                             => lang('Back'),
388                                'lang_save'                                             => lang('save'),
389                                'lang_org'                                              => lang('Organizations'),
390                                'lang_maillist_uid'                             => lang('Maillist login'),
391                                'lang_maillist_mail'                    => lang('Maillist Mail'),
392                                'lang_maillist_name'                    => lang('Maillist name'),
393                                'lang_maillist_users'                   => lang('Maillist users'),
394                                'lang_add_user'                                 => lang('Add User'),
395                                'lang_rem_user'                                 => lang('Remove User'),
396                                'lang_all_users'                                => lang('Show users from all sub-organizations'),
397                                'back_url'                                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimaillists.list_maillists'),
398                                'combo_org'                                             => $sectors,
399                                'uidnumber'                                             => $_GET['uidnumber'],
400                                'uid'                                                   => $maillist_info['uid'],
401                                'mail'                                                  => $maillist_info['mail'],
402                                'cn'                                                    => $maillist_info['cn'],
403                                'accountRestrictive_checked'    => $maillist_info['accountRestrictive'] == 'mailListRestriction' ? 'CHECKED' : '',
404                                'participantCanSendMail_checked'=> $maillist_info['participantCanSendMail'] == 'TRUE' ? 'CHECKED' : '',
405                                'ea_select_users_SCL_Maillist'  => $ea_select_users_SCL_Maillist
406                        );
407                        $p->set_var($var);
408                       
409                        $p->pfp('out','sql_maillist');
410                }
411               
412                function row_action($action,$type,$uidnumber,$maillist_uid)
413                {
414                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
415                                'menuaction'            => 'expressoAdmin1_2.uimaillists.'.$action.'_'.$type,
416                                'uidnumber'                     => $uidnumber,
417                                'maillist_uid'          => $maillist_uid
418                        )).'"> '.lang($action).' </a>';
419                }
420               
421                function css()
422                {
423                        $appCSS = '';
424                        return $appCSS;
425                }
426        }
427?>
Note: See TracBrowser for help on using the repository browser.