source: trunk/expressoAdmin1_2/inc/class.maillist.inc.php @ 414

Revision 414, 14.3 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por João Alfredo.
Email: jakjr@…

  • 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        include_once('class.ldap_functions.inc.php');
13        include_once('class.db_functions.inc.php');
14        include_once('class.imap_functions.inc.php');
15        include_once('class.functions.inc.php');
16       
17        class maillist
18        {
19                var $ldap_functions;
20                var $db_functions;
21                var $imap_functions;
22                var $functions;
23                var $current_config;
24               
25               
26                function maillist()
27                {
28                        $this->ldap_functions = new ldap_functions;
29                        $this->db_functions = new db_functions;
30                        $this->imap_functions = new imap_functions;
31                        $this->functions = new functions;
32                        $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin'];
33                }
34               
35                function validate_fields($params)
36                {
37                        return $this->ldap_functions->validate_fields_maillist($params);
38                }
39               
40                function create($params)
41                {
42                        // Verifica o acesso do gerente
43                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'add_maillists'))
44                        {
45                                $return['status'] = false;
46                                $return['msg'] = 'Você não tem acesso para adicionar listas de email.';
47                                return $return;
48                        }
49                       
50                        $return['status'] = true;
51                       
52                        //Retira os mailForwardingAddress duplicados, se existir algum.
53                        $array_tmp = array();
54                        $array_tmp = array_unique($params['mailForwardingAddress']);
55                        $params['mailForwardingAddress'] = $array_tmp;
56                       
57                        // Leio o ID a ser usado na criação do objecto.
58                        $next_id = ($this->db_functions->get_next_id('accounts'));
59                        if ((!is_numeric($next_id['id'])) || (!$next_id['status']))
60                        {
61                                $return['status'] = false;
62                                $return['msg'] = "Problemas obtendo ID do usuário.\n" . $id['msg'];
63                                return $return;
64                        }
65                        else
66                        {
67                                $id = $next_id['id'];
68                        }                       
69                       
70                        // Cria array para incluir no LDAP
71                        $dn = 'uid=' . $params['uid'] . ',' . $params['context'];                       
72                       
73                        $maillist_info = array();
74                        $maillist_info['uid']                                           = $params['uid']; 
75                        $maillist_info['givenName']                                     = 'MailList';
76                        $maillist_info['sn']                                            = $params['uid'];
77                        $maillist_info['cn']                                            = $params['cn'];
78                       
79                        $maillist_info['homeDirectory']                         = '/home/false';
80                        $maillist_info['loginShell']                            = '/bin/false';
81                        $maillist_info['mail']                                          = $params['mail'];
82                        $maillist_info['objectClass'][0]                        = 'posixAccount';
83                        $maillist_info['objectClass'][1]                        = 'inetOrgPerson';
84                        $maillist_info['objectClass'][2]                        = 'shadowAccount';
85                        $maillist_info['objectClass'][3]                        = 'qmailuser';
86                        $maillist_info['objectClass'][4]                        = 'phpgwAccount';
87                        $maillist_info['objectClass'][5]                        = 'top';
88                        $maillist_info['objectClass'][6]                        = 'person';
89                        $maillist_info['objectClass'][7]                        = 'organizationalPerson';                       
90                        $maillist_info['phpgwAccountExpires']           = '-1';
91                        $maillist_info['phpgwAccountType']                      = 'l';
92                        $maillist_info['uidnumber']                                     = $id;
93                        $maillist_info['gidnumber']                                     = '0';
94                        $maillist_info['userPassword']                          = '';
95                        $maillist_info['deliveryMode']                          = 'forwardOnly';
96                       
97                        if ($params['accountStatus'] == 'on')
98                                $maillist_info['accountStatus'] = 'active';
99                       
100                        if ($params['phpgwAccountVisible'] == 'on')
101                                $maillist_info['phpgwAccountVisible'] = '-1';
102                                               
103                        $maillist_info['mailForwardingAddress'] = $params['mailForwardingAddress'];
104                       
105                        $result = $this->ldap_functions->ldap_add_entry($dn, $maillist_info);
106                        if (!$result['status'])
107                        {
108                                $return['status'] = false;
109                                $return['msg'] .= $result['msg'];
110                        }
111                       
112                        /* log */
113                        if ($return['status'] == true)
114                        {
115                                $this->db_functions->write_log('created email list',$dn);
116                               
117                                foreach($params['mailForwardingAddress'] as $index=>$mail)
118                                {
119                                        $this->db_functions->write_log("added user on email list creation", $params['cn'].':' . $mail);
120                                }
121                        }
122                       
123                        return $return;
124                }
125               
126                function save($new_values)
127                {
128                        // Verifica o acesso do gerente
129                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_maillists'))
130                        {
131                                $return['status'] = false;
132                                $return['msg'] = lang('You do not have access to edit email lists') . '.';
133                                return $return;
134                        }
135
136                        $return['status'] = true;
137
138                        $old_values = $this->get_info($new_values['uidnumber'], $new_values['manager_context']);
139                        $diff = array_diff($new_values, $old_values);
140                       
141                        $dn = 'uid=' . $old_values['uid'] . ',' . $old_values['context'];
142                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
143                        // RENAME
144                        if ($diff['context'] || $diff['uid'])
145                        {
146                                if ( (strcasecmp($old_values['uid'], $new_values['uid']) != 0) || (strcasecmp($old_values['context'], $new_values['context']) != 0) )
147                                {
148                                        $newrdn = 'uid=' . $new_values['uid'];
149                                        $newparent = $new_values['context'];
150                                        $result =  $this->ldap_functions->change_user_context($dn, $newrdn, $newparent);
151                                        if (!$result['status'])
152                                        {
153                                                $return['status'] = false;
154                                                $return['msg'] .= $result['msg'];
155                                        }
156                                        else
157                                        {
158                                                $dn = $newrdn . ',' . $newparent;
159                                                $old_dn = $old_values['uid'];
160                                                $this->db_functions->write_log("renamed list login",$old_dn . ' -> ' . $dn);
161                                        }
162                                }
163                        }
164                       
165                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
166                        // REPLACE MAIL || CN || SN
167                        if ($new_values['mail'] != $old_values['mail'])
168                        {
169                                $ldap_mod_replace['mail'] = $new_values['mail'];
170                                $this->db_functions->write_log('modified list email', $dn . ': ' . $old_values['mail'] . '->' . $new_values['mail']);
171                        }
172                        if ($new_values['cn'] != $old_values['cn'])
173                        {
174                                $ldap_mod_replace['cn'] = $new_values['cn'];
175                                $this->db_functions->write_log('modified list name', $old_values['cn'] . '->' . $new_values['cn']);
176                        }
177                        if ($diff['uid'])
178                        {
179                                $ldap_mod_replace['sn'] = $new_values['uid'];
180                        }
181                       
182                        if (count($ldap_mod_replace))
183                        {
184                                $result = $this->ldap_functions->replace_user_attributes($dn, $ldap_mod_replace);
185                                if (!$result['status'])
186                                {
187                                        $return['status'] = false;
188                                        $return['msg'] .= $result['msg'];
189                                }
190                        }
191                       
192                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
193                        // REMOVE ATTRS
194                        if (($old_values['accountStatus'] == 'active') && ($new_values['accountStatus'] != 'on'))
195                                $ldap_remove['accountStatus']   = array();
196                       
197                        if (($old_values['phpgwAccountVisible'] == '-1') && ($new_values['phpgwAccountVisible'] != 'on'))
198                                $ldap_remove['phpgwAccountVisible']     = array();
199                       
200                        if (count($ldap_remove))
201                        {
202                                $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove);
203                                if (!$result['status'])
204                                {
205                                        $return['status'] = false;
206                                        $return['msg'] .= $result['msg'];
207                                }
208                        }
209                       
210                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
211                        // ADD ATTRS
212                        if (($old_values['accountStatus'] != 'active') && ($new_values['accountStatus'] == 'on'))
213                                $ldap_add['accountStatus']      = 'active';
214                       
215                        if (($old_values['phpgwAccountVisible'] != '-1') && ($new_values['phpgwAccountVisible'] == 'on'))
216                                $ldap_add['phpgwAccountVisible'] = '-1';
217                       
218                        if (count($ldap_add))
219                        {
220                                $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add);
221                                if (!$result['status'])
222                                {
223                                        $return['status'] = false;
224                                        $return['msg'] .= $result['msg'];
225                                }
226                        }
227                       
228                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
229                        // USERS
230                        /*
231                        echo '<pre>';
232                        print_r($new_values['mailForwardingAddress']);
233                        */
234                        if (!$new_values['mailForwardingAddress'])
235                                $new_values['mailForwardingAddress'] = array();
236                        if (!$old_values['mailForwardingAddress'])
237                                $old_values['mailForwardingAddress'] = array();
238
239                        $add_users = array_diff($new_values['mailForwardingAddress'], $old_values['mailForwardingAddress']);
240                        $remove_users = array_diff($old_values['mailForwardingAddress'], $new_values['mailForwardingAddress']);
241                       
242                        if (count($add_users)>0)
243                        {
244                                sort($add_users);
245                                $result = $this->ldap_functions->add_user2maillist($new_values['uid'], $add_users);
246                               
247                                /* log */
248                                if (!$result['status'])
249                                {
250                                        $return['status'] = false;
251                                        $return['msg'] .= $result['msg'];
252                                }
253                                else
254                                {
255                                        foreach($add_users as $index=>$mail)
256                                        {
257                                                $this->db_functions->write_log("added user to list", "$dn: $mail");
258                                        }
259                                }
260                        }
261                       
262                        if (count($remove_users)>0)
263                        {
264                                sort($remove_users);
265                                $result = $this->ldap_functions->remove_user2maillist($new_values['uid'], $remove_users);
266                               
267                                /* log */
268                                if (!$result['status'])
269                                {
270                                        $return['status'] = false;
271                                        $return['msg'] .= $result['msg'];
272                                }
273                                else
274                                {
275                                        foreach($remove_users as $index=>$mail)
276                                        {
277                                                $this->db_functions->write_log("removed user from list", "$dn: $mail");
278                                        }
279                                }
280                        }
281                       
282                        return $return;
283                }               
284               
285                function save_scl($new_values)
286                {
287                        // Verifica o acesso do gerente
288                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_scl_email_lists'))
289                        {
290                                $return['status'] = false;
291                                $return['msg'] = lang('You do not have access to edit email lists SCL') . '.';
292                                return $return;
293                        }
294                       
295                        $return['status'] = true;
296
297                        //Retira os uids duplicados se existir
298                        $array_tmp = array();
299                        $array_tmp = @array_unique($new_values['members']);
300                        $new_values['members'] = $array_tmp;
301                       
302                        $old_values = $this->get_scl_info($new_values['uidnumber'], $new_values['manager_context']);
303                       
304                        $diff = array_diff($new_values, $old_values);
305                        $dn = $old_values['dn'];
306                       
307                        //echo '<pre>';
308                        //print_r($new_values['participantCanSendMail']);
309                        //print_r($old_values['participantCanSendMail']);
310                       
311                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
312                        // ADD ATTRS
313                        if (($new_values['participantCanSendMail'] == 'on') && ($old_values['participantCanSendMail'] == ''))
314                        {
315                                $ldap_add['participantCanSendMail'] = "TRUE";
316                                $this->db_functions->write_log("turned on participantCanSendMail",$new_values['mail']);
317                        }
318                        if (($new_values['accountRestrictive'] == 'on') && ($old_values['accountRestrictive'] == ''))
319                        {
320                                $ldap_add['accountRestrictive'] = "mailListRestriction";
321                                $ldap_add['accountDeliveryMessage']     = 'OK';
322                                $this->db_functions->write_log("turned on mailListRestriction", $new_values['mail']);
323                        }
324                        if (count($ldap_add))
325                        {
326                                $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add);
327                                if (!$result['status'])
328                                {
329                                        $return['status'] = false;
330                                        $return['msg'] .= $result['msg'];
331                                }
332                        }
333                       
334                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
335                        // REMOVE ATTRS
336                        if (($new_values['participantCanSendMail'] != 'on') && ($old_values['participantCanSendMail'] == 'TRUE'))
337                        {
338                                $ldap_remove['participantCanSendMail']  = array();
339                                $this->db_functions->write_log("turned off participantCanSendMail",$new_values['mail']);
340                        }
341                        if (($new_values['accountRestrictive'] != 'on') && ($old_values['accountRestrictive'] == 'mailListRestriction'))
342                        {
343                                $ldap_remove['accountRestrictive']      = array();
344                                $ldap_remove['accountDeliveryMessage']  = array();
345                                $this->db_functions->write_log("turned off mailListRestriction",$new_values['mail']);
346                        }
347                        if (count($ldap_remove))
348                        {
349                                $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove);
350                                if (!$result['status'])
351                                {
352                                        $return['status'] = false;
353                                        $return['msg'] .= $result['msg'];
354                                }
355                        }
356                       
357                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
358                        // USERS
359
360                        if (!$new_values['members'])
361                                $new_values['members'] = array();
362                        if (!$old_values['members'])
363                                $old_values['members'] = array();
364
365                        $add_users = array_diff($new_values['members'], $old_values['members']);
366                        $remove_users = array_diff($old_values['members'], $new_values['members']);
367                       
368                        if (count($add_users)>0)
369                        {
370                                sort($add_users);
371                                $result = $this->ldap_functions->add_user2maillist_scl($dn, $add_users);
372                               
373                                /* log */
374                                if (!$result['status'])
375                                {
376                                        $return['status'] = false;
377                                        $return['msg'] .= $result['msg'];
378                                }
379                                else
380                                {
381                                        foreach($add_users as $index=>$mail)
382                                        {
383                                                $this->db_functions->write_log("added user to SCL","$dn: $mail",'','','');
384                                        }
385                                }
386                        }
387                       
388                        if (count($remove_users)>0)
389                        {
390                                sort($remove_users);
391                                $result = $this->ldap_functions->remove_user2maillist_scl($dn, $remove_users);
392                               
393                                /* log */
394                                if (!$result['status'])
395                                {
396                                        $return['status'] = false;
397                                        $return['msg'] .= $result['msg'];
398                                }
399                                else
400                                {
401                                        foreach($add_users as $index=>$mail)
402                                        {
403                                                $this->db_functions->write_log("removed user from SCL","$dn: $mail",'','','');
404                                        }
405                                }
406                        }
407                       
408                        return $return;
409                }                               
410               
411                function get_info($uidnumber)
412                {
413                        $maillist_info_ldap = $this->ldap_functions->get_maillist_info($uidnumber);
414                        return $maillist_info_ldap;
415                }
416
417                function get_scl_info($uidnumber)
418                {
419                        $maillist_info_ldap = $this->ldap_functions->get_maillist_scl_info($uidnumber);
420                        return $maillist_info_ldap;
421                }
422               
423                function delete($params)
424                {
425                        // Verifica o acesso do gerente
426                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_maillists'))
427                        {
428                                $return['status'] = false;
429                                $return['msg'] = lang('You do not have access to delete email lists') . '.';
430                                return $return;
431                        }
432
433                        $return['status'] = true;
434
435                        $uidnumber = $params['uidnumber'];
436                        $uid = $this->ldap_functions->uidnumber2uid($uidnumber);
437                        $mail = $this->ldap_functions->uidnumber2mail($uidnumber);
438
439                        //LDAP
440                        $result_ldap = $this->ldap_functions->delete_maillist($uidnumber, $mail);
441                        if (!$result_ldap['status'])
442                        {
443                                $return['status'] = false;
444                                $return['msg'] .= $result_ldap['msg'];
445                        }
446                       
447                        if ($return['status'] == true)
448                        {
449                                $this->db_functions->write_log('deleted email list',$uid);
450                        }
451                       
452                        return $return;
453                }
454        }
455?>
Note: See TracBrowser for help on using the repository browser.