Code

Added \$this->cleanup before all calls of $ldap->modify
[gosa.git] / plugins / admin / ogroups / class_mailogroup.inc
1 <?php
3 class mailogroup extends plugin
4 {
5   /* plugin specific values */
6   var $mail= "";
7   var $cn= "";
9   /* attribute list for save action */
10   var $attributes= array("mail");
11   var $objectclasses= array("kolabGroupOfNames");
12   var $members= array();
15   function mailogroup ($config, $dn= NULL)
16   {
17     plugin::plugin($config, $dn);
19     /* Include config object */
20     $this->config= $config;
22     /* Save initial account state */
23     $this->initially_was_account= $this->is_account;
24   }
27   function execute()
28   {
29         /* Call parent execute */
30         plugin::execute();
32     /* Do we need to flip is_account state? */
33     if (isset($_POST['modify_state'])){
34       $this->is_account= !$this->is_account;
35     }
37     /* Show tab dialog headers */
38     if ($this->parent != NULL){
39       if ($this->is_account){
40         $display= $this->show_header(_("Remove mail account"),
41             _("This group has mail features enabled. You can disable them by clicking below."));
42       } else {
43         $display= $this->show_header(_("Create mail account"), _("This group has mail features disabled. You can enable them by clicking below."));
44         return ($display);
45       }
46     }
47     
48     /* Initialize templating engine */
49     $smarty= get_smarty();
51     /* Assign mail attribute */
52     $smarty->assign("mail", $this->mail);
53     $smarty->assign("mailACL", chkacl($this->acl, "mail"));
55     /* Show main page */
56     return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE)));
57   }
60   /* Check formular input */
61   function check()
62   {
63     $message= array();
65     if ($this->is_account){
66       $ldap= $this->config->get_ldap_link();
68       /* Check if mail address is valid */
69       if (!is_email($this->mail) || $this->mail == ""){
70         $message[]= _("Please enter a valid email address in 'Primary address' field.");
71       }
73       /* Check if mail address is already in use */
74       $ldap->cd($this->config->current['BASE']);
75       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.         ")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
76       if ($ldap->count() != 0){
77         $message[]= _("The primary address you've entered is already in use.");
78       }
79     }
81     return ($message);
82   }
85   function save()
86   {
87     $ldap= $this->config->get_ldap_link();
89     /* Call parents save to prepare $this->attrs */
90     plugin::save();
92     /* Save data to LDAP */
93     $ldap->cd($this->dn);
94     $this->cleanup();
95 $ldap->modify ($this->attrs); 
97     show_ldap_error($ldap->get_error());
99     /* Optionally execute a command after we're done */
100     if ($this->initially_was_account == $this->is_account){
101       if ($this->is_modified){
102         $this->handle_post_events("mofify");
103       }
104     } else {
105       $this->handle_post_events("add");
106     }
107   }
110   /* remove object from parent */
111   function remove_from_parent()
112   {
113     /* Cancel if there's nothing to do here */
114     if (!$this->initially_was_account){
115       return;
116     }
118     /* include global link_info */
119     $ldap= $this->config->get_ldap_link();
121     /* Remove and write to LDAP */
122     plugin::remove_from_parent();
124     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
125         $this->attributes, "Save");
126     $ldap->cd($this->dn);
127     $this->cleanup();
128 $ldap->modify ($this->attrs); 
130     show_ldap_error($ldap->get_error());
131   }
135 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
136 ?>