Code

Removed show_ldap_error() calls
[gosa.git] / gosa-plugins / mail / admin / ogroups / mail / 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();
13   var $view_logged = FALSE;
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   }
27   function execute()
28   {
29     /* Call parent execute */
30     plugin::execute();
32     if($this->is_account && !$this->view_logged){
33       $this->view_logged = TRUE;
34       new log("view","ogroups/".get_class($this),$this->dn);
35     }
38     /* Do we need to flip is_account state? */
39     if(isset($_POST['modify_state'])){
40       if($this->is_account && $this->acl_is_removeable()){
41         $this->is_account= FALSE;
42       }elseif(!$this->is_account && $this->acl_is_createable()){
43         $this->is_account= TRUE;
44       }
45     }
47     /* Show tab dialog headers */
48     if ($this->parent !== NULL){
49       if ($this->is_account){
50         $display= $this->show_disable_header(_("Remove mail account"),
51             _("This group has mail features enabled. You can disable them by clicking below."));
52       } else {
53         $display= $this->show_enable_header(_("Create mail account"), _("This group has mail features disabled. You can enable them by clicking below."));
54         return ($display);
55       }
56     }
57     
58     /* Initialize templating engine */
59     $smarty= get_smarty();
61     $tmp = $this->plInfo();
62     foreach($tmp['plProvidedAcls'] as $name => $translation){
63       $smarty->assign($name."ACL",$this->getacl("mail"));
64     }
66     /* Assign mail attribute */
67     $smarty->assign("mail", $this->mail);
69     /* Show main page */
70     return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE,dirname(__FILE__))));
71   }
74   /* Check formular input */
75   function check()
76   {
77     /* Call common method to give check the hook */
78     $message= plugin::check();
80     if ($this->is_account){
81       $ldap= $this->config->get_ldap_link();
83       /* Check if mail address is valid */
84       if (!tests::is_email($this->mail) || $this->mail == ""){
85         $message[]= _("Please enter a valid email address in 'Primary address' field.");
86       }
88       /* Check if mail address is already in use */
89       $ldap->cd($this->config->current['BASE']);
90       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
91       if ($ldap->count() != 0){
92         $message[]= _("The primary address you've entered is already in use.");
93       }
94     }
96     return ($message);
97   }
100   function save()
101   {
102     $ldap= $this->config->get_ldap_link();
104     /* Call parents save to prepare $this->attrs */
105     plugin::save();
107     /* Save data to LDAP */
108     $ldap->cd($this->dn);
109     $this->cleanup();
110     $ldap->modify ($this->attrs); 
112     if($this->initially_was_account){
113       new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
114     }else{
115       new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
116     }
118     if (!$ldap->success()){
119       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
120     }
122     /* Optionally execute a command after we're done */
123     if ($this->initially_was_account == $this->is_account){
124       if ($this->is_modified){
125         $this->handle_post_events("modify");
126       }
127     } else {
128       $this->handle_post_events("add");
129     }
130   }
133   /* remove object from parent */
134   function remove_from_parent()
135   {
136     /* Cancel if there's nothing to do here */
137     if (!$this->initially_was_account){
138       return;
139     }
141     /* include global link_info */
142     $ldap= $this->config->get_ldap_link();
144     /* Remove and write to LDAP */
145     plugin::remove_from_parent();
147     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
148         $this->attributes, "Save");
149     $ldap->cd($this->dn);
150     $this->cleanup();
151     $ldap->modify ($this->attrs); 
153     new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
155     if (!$ldap->success()){
156       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
157     }
158   }
161   function getCopyDialog()
162   {
163     $str = "";
164     $smarty = get_smarty();
165     $smarty->assign("mail",     $this->mail);
166     $str = $smarty->fetch(get_template_path("paste_mail.tpl",TRUE,dirname(__FILE__)));
167     $ret = array();
168     $ret['string'] = $str;
169     $ret['status'] = "";
170     return($ret);
171   }
174   function saveCopyDialog()
175   {
176     if(isset($_POST['mail'])){
177       $this->mail = $_POST['mail'];
178     }
179   }
182    static function plInfo()
183   {
184     return (array(
185           "plShortName"   => _("Mail"),
186           "plDescription" => _("Mail group"),
187           "plSelfModify"  => FALSE,
188           "plDepends"     => array(),
189           "plPriority"    => 4,
190           "plSection"     => array("administration"),
191           "plCategory"    => array("ogroups"),
192           "plProvidedAcls"=> array(
193             "mail" => _("Mail address"))
194           ));
195   }
202 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
203 ?>