Code

Fixed a couple of static/non-static error messages
[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();
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)));
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 (!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     show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/mail with dn '%s' failed."),$this->dn));
120     /* Optionally execute a command after we're done */
121     if ($this->initially_was_account == $this->is_account){
122       if ($this->is_modified){
123         $this->handle_post_events("modify");
124       }
125     } else {
126       $this->handle_post_events("add");
127     }
128   }
131   /* remove object from parent */
132   function remove_from_parent()
133   {
134     /* Cancel if there's nothing to do here */
135     if (!$this->initially_was_account){
136       return;
137     }
139     /* include global link_info */
140     $ldap= $this->config->get_ldap_link();
142     /* Remove and write to LDAP */
143     plugin::remove_from_parent();
145     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
146         $this->attributes, "Save");
147     $ldap->cd($this->dn);
148     $this->cleanup();
149     $ldap->modify ($this->attrs); 
151     new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
153     show_ldap_error($ldap->get_error(), sprintf(_("Removing of object group/mail with dn '%s' failed."),$this->dn));
154   }
157   function getCopyDialog()
158   {
159     $str = "";
160     $smarty = get_smarty();
161     $smarty->assign("mail",     $this->mail);
162     $str = $smarty->fetch(get_template_path("paste_mail.tpl",TRUE,dirname(__FILE__)));
163     $ret = array();
164     $ret['string'] = $str;
165     $ret['status'] = "";
166     return($ret);
167   }
170   function saveCopyDialog()
171   {
172     if(isset($_POST['mail'])){
173       $this->mail = $_POST['mail'];
174     }
175   }
178    static function plInfo()
179   {
180     return (array(
181           "plShortName"   => _("Mail"),
182           "plDescription" => _("Mail group"),
183           "plSelfModify"  => FALSE,
184           "plDepends"     => array(),
185           "plPriority"    => 4,
186           "plSection"     => array("administration"),
187           "plCategory"    => array("ogroups"),
188           "plProvidedAcls"=> array(
189             "mail" => _("Mail address"))
190           ));
191   }
198 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
199 ?>