Code

Fixed logging for open groupware account
[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, $parent= NULL)
16   {
17     plugin::plugin($config, $dn, $parent);
19     /* Include config object */
20     $this->config= $config;
22     /* Save initial account state */
23     $this->initially_was_account= $this->is_account;
24     
25     if($this->is_account){
26       @log::log("view","ogroups/".get_class($this),$this->dn);
27     }
28   }
31   function execute()
32   {
33     /* Call parent execute */
34     plugin::execute();
36     /* Do we need to flip is_account state? */
37     if(isset($_POST['modify_state'])){
38       if($this->is_account && $this->acl_is_removeable()){
39         $this->is_account= FALSE;
40       }elseif(!$this->is_account && $this->acl_is_createable()){
41         $this->is_account= TRUE;
42       }
43     }
45     /* Show tab dialog headers */
46     if ($this->parent != NULL){
47       if ($this->is_account){
48         $display= $this->show_disable_header(_("Remove mail account"),
49             _("This group has mail features enabled. You can disable them by clicking below."));
50       } else {
51         $display= $this->show_enable_header(_("Create mail account"), _("This group has mail features disabled. You can enable them by clicking below."));
52         return ($display);
53       }
54     }
55     
56     /* Initialize templating engine */
57     $smarty= get_smarty();
59     $tmp = $this->plInfo();
60     foreach($tmp['plProvidedAcls'] as $name => $translation){
61       $smarty->assign($name."ACL",$this->getacl("mail"));
62     }
64     /* Assign mail attribute */
65     $smarty->assign("mail", $this->mail);
67     /* Show main page */
68     return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE)));
69   }
72   /* Check formular input */
73   function check()
74   {
75     /* Call common method to give check the hook */
76     $message= plugin::check();
78     if ($this->is_account){
79       $ldap= $this->config->get_ldap_link();
81       /* Check if mail address is valid */
82       if (!is_email($this->mail) || $this->mail == ""){
83         $message[]= _("Please enter a valid email address in 'Primary address' field.");
84       }
86       /* Check if mail address is already in use */
87       $ldap->cd($this->config->current['BASE']);
88       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
89       if ($ldap->count() != 0){
90         $message[]= _("The primary address you've entered is already in use.");
91       }
92     }
94     return ($message);
95   }
98   function save()
99   {
100     $ldap= $this->config->get_ldap_link();
102     /* Call parents save to prepare $this->attrs */
103     plugin::save();
105     /* Save data to LDAP */
106     $ldap->cd($this->dn);
107     $this->cleanup();
108     $ldap->modify ($this->attrs); 
110     if($this->initially_was_account){
111       @log::log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
112     }else{
113       @log::log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
114     }
116     show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/mail with dn '%s' failed."),$this->dn));
118     /* Optionally execute a command after we're done */
119     if ($this->initially_was_account == $this->is_account){
120       if ($this->is_modified){
121         $this->handle_post_events("modify");
122       }
123     } else {
124       $this->handle_post_events("add");
125     }
126   }
129   /* remove object from parent */
130   function remove_from_parent()
131   {
132     /* Cancel if there's nothing to do here */
133     if (!$this->initially_was_account){
134       return;
135     }
137     /* include global link_info */
138     $ldap= $this->config->get_ldap_link();
140     /* Remove and write to LDAP */
141     plugin::remove_from_parent();
143     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
144         $this->attributes, "Save");
145     $ldap->cd($this->dn);
146     $this->cleanup();
147     $ldap->modify ($this->attrs); 
149     @log::log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
151     show_ldap_error($ldap->get_error(), sprintf(_("Removing of object group/mail with dn '%s' failed."),$this->dn));
152   }
155   function getCopyDialog()
156   {
157     $str = "";
158     $smarty = get_smarty();
159     $smarty->assign("mail",     $this->mail);
160     $str = $smarty->fetch(get_template_path("paste_mail.tpl",TRUE,dirname(__FILE__)));
161     $ret = array();
162     $ret['string'] = $str;
163     $ret['status'] = "";
164     return($ret);
165   }
168   function saveCopyDialog()
169   {
170     if(isset($_POST['mail'])){
171       $this->mail = $_POST['mail'];
172     }
173   }
176    function plInfo()
177   {
178     return (array(
179           "plShortName"   => _("Mail"),
180           "plDescription" => _("Mail group"),
181           "plSelfModify"  => FALSE,
182           "plDepends"     => array(),
183           "plPriority"    => 4,
184           "plSection"     => array("administration"),
185           "plCategory"    => array("ogroups"),
186           "plProvidedAcls"=> array(
187             "mail" => _("Mail address"))
188           ));
189   }
196 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
197 ?>