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

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