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

Revision 493, 14.7 KB checked in by niltonneto, 16 years ago (diff)

Correção de tradução

  • 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 = $this->ldap_functions->add_user2maillist($new_values['uid'], $add_users);
255                               
256                                /* log */
257                                if (!$result['status'])
258                                {
259                                        $return['status'] = false;
260                                        $return['msg'] .= $result['msg'];
261                                }
262                                else
263                                {
264                                        foreach($add_users as $index=>$mail)
265                                        {
266                                                $this->db_functions->write_log("added user to list", "$dn: $mail");
267                                        }
268                                }
269                        }
270                       
271                        if (count($remove_users)>0)
272                        {
273                                sort($remove_users);
274                                $result = $this->ldap_functions->remove_user2maillist($new_values['uid'], $remove_users);
275                               
276                                /* log */
277                                if (!$result['status'])
278                                {
279                                        $return['status'] = false;
280                                        $return['msg'] .= $result['msg'];
281                                }
282                                else
283                                {
284                                        foreach($remove_users as $index=>$mail)
285                                        {
286                                                $this->db_functions->write_log("removed user from list", "$dn: $mail");
287                                        }
288                                }
289                        }
290                       
291                        return $return;
292                }               
293               
294                function save_scl($new_values)
295                {
296                        // Verifica o acesso do gerente
297                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_scl_email_lists'))
298                        {
299                                $return['status'] = false;
300                                $return['msg'] = lang('You do not have access to edit email lists SCL') . '.';
301                                return $return;
302                        }
303                       
304                        $return['status'] = true;
305
306                        //Retira os uids duplicados se existir
307                        $array_tmp = array();
308                        $array_tmp = @array_unique($new_values['members']);
309                        $new_values['members'] = $array_tmp;
310                       
311                        $old_values = $this->get_scl_info($new_values['uidnumber'], $new_values['manager_context']);
312                       
313                        $diff = array_diff($new_values, $old_values);
314                        $dn = $old_values['dn'];
315                       
316                        //echo '<pre>';
317                        //print_r($new_values['participantCanSendMail']);
318                        //print_r($old_values['participantCanSendMail']);
319                       
320                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
321                        // ADD ATTRS
322                        if (($new_values['participantCanSendMail'] == 'on') && ($old_values['participantCanSendMail'] == ''))
323                        {
324                                $ldap_add['participantCanSendMail'] = "TRUE";
325                                $this->db_functions->write_log("turned on participantCanSendMail",$new_values['mail']);
326                        }
327                        if (($new_values['accountRestrictive'] == 'on') && ($old_values['accountRestrictive'] == ''))
328                        {
329                                $ldap_add['accountRestrictive'] = "mailListRestriction";
330                                $ldap_add['accountDeliveryMessage']     = 'OK';
331                                $this->db_functions->write_log("turned on mailListRestriction", $new_values['mail']);
332                        }
333                        if (count($ldap_add))
334                        {
335                                $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add);
336                                if (!$result['status'])
337                                {
338                                        $return['status'] = false;
339                                        $return['msg'] .= $result['msg'];
340                                }
341                        }
342                       
343                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
344                        // REMOVE ATTRS
345                        if (($new_values['participantCanSendMail'] != 'on') && ($old_values['participantCanSendMail'] == 'TRUE'))
346                        {
347                                $ldap_remove['participantCanSendMail']  = array();
348                                $this->db_functions->write_log("turned off participantCanSendMail",$new_values['mail']);
349                        }
350                        if (($new_values['accountRestrictive'] != 'on') && ($old_values['accountRestrictive'] == 'mailListRestriction'))
351                        {
352                                $ldap_remove['accountRestrictive']      = array();
353                                $ldap_remove['accountDeliveryMessage']  = array();
354                                $this->db_functions->write_log("turned off mailListRestriction",$new_values['mail']);
355                        }
356                        if (count($ldap_remove))
357                        {
358                                $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove);
359                                if (!$result['status'])
360                                {
361                                        $return['status'] = false;
362                                        $return['msg'] .= $result['msg'];
363                                }
364                        }
365                       
366                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
367                        // USERS
368
369                        if (!$new_values['members'])
370                                $new_values['members'] = array();
371                        if (!$old_values['members'])
372                                $old_values['members'] = array();
373
374                        $add_users = array_diff($new_values['members'], $old_values['members']);
375                        $remove_users = array_diff($old_values['members'], $new_values['members']);
376                       
377                        if (count($add_users)>0)
378                        {
379                                sort($add_users);
380                                $result = $this->ldap_functions->add_user2maillist_scl($dn, $add_users);
381                               
382                                /* log */
383                                if (!$result['status'])
384                                {
385                                        $return['status'] = false;
386                                        $return['msg'] .= $result['msg'];
387                                }
388                                else
389                                {
390                                        foreach($add_users as $index=>$mail)
391                                        {
392                                                $this->db_functions->write_log("added user to SCL","$dn: $mail",'','','');
393                                        }
394                                }
395                        }
396                       
397                        if (count($remove_users)>0)
398                        {
399                                sort($remove_users);
400                                $result = $this->ldap_functions->remove_user2maillist_scl($dn, $remove_users);
401                               
402                                /* log */
403                                if (!$result['status'])
404                                {
405                                        $return['status'] = false;
406                                        $return['msg'] .= $result['msg'];
407                                }
408                                else
409                                {
410                                        foreach($add_users as $index=>$mail)
411                                        {
412                                                $this->db_functions->write_log("removed user from SCL","$dn: $mail",'','','');
413                                        }
414                                }
415                        }
416                       
417                        return $return;
418                }                               
419               
420                function get_info($uidnumber)
421                {
422                        $maillist_info_ldap = $this->ldap_functions->get_maillist_info($uidnumber);
423                        return $maillist_info_ldap;
424                }
425
426                function get_scl_info($uidnumber)
427                {
428                        $maillist_info_ldap = $this->ldap_functions->get_maillist_scl_info($uidnumber);
429                        return $maillist_info_ldap;
430                }
431               
432                function delete($params)
433                {
434                        // Verifica o acesso do gerente
435                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_maillists'))
436                        {
437                                $return['status'] = false;
438                                $return['msg'] = lang('You do not have access to delete email lists') . '.';
439                                return $return;
440                        }
441
442                        $return['status'] = true;
443
444                        $uidnumber = $params['uidnumber'];
445                        $uid = $this->ldap_functions->uidnumber2uid($uidnumber);
446                        $mail = $this->ldap_functions->uidnumber2mail($uidnumber);
447
448                        //LDAP
449                        $result_ldap = $this->ldap_functions->delete_maillist($uidnumber, $mail);
450                        if (!$result_ldap['status'])
451                        {
452                                $return['status'] = false;
453                                $return['msg'] .= $result_ldap['msg'];
454                        }
455                       
456                        if ($return['status'] == true)
457                        {
458                                $this->db_functions->write_log('deleted email list',$uid);
459                        }
460                       
461                        return $return;
462                }
463        }
464?>
Note: See TracBrowser for help on using the repository browser.