source: branches/2.2/expressoAdmin1_2/inc/class.maillist.inc.php @ 585

Revision 585, 14.7 KB checked in by niltonneto, 15 years ago (diff)

Correção de algumas traduções.

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