Code

Hide tabs frames
[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   }
27   function execute()
28   {
29     /* Call parent execute */
30     plugin::execute();
32     
33     /* Do we need to flip is_account state? */
34     if (isset($_POST['modify_state'])){
36       /* Onyl change account state if allowed */
37       if($this->is_account && $this->acl == "#all#"){
38         $this->is_account= !$this->is_account;
39       }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
40         $this->is_account= !$this->is_account;
41       }
42     }
44     /* Show tab dialog headers */
45     if ($this->parent != NULL){
46       if ($this->is_account){
47         $display= $this->show_header(_("Remove mail account"),
48             _("This group has mail features enabled. You can disable them by clicking below."));
49       } else {
50         $display= $this->show_header(_("Create mail account"), _("This group has mail features disabled. You can enable them by clicking below."));
51         return ($display);
52       }
53     }
54     
55     /* Initialize templating engine */
56     $smarty= get_smarty();
58     /* Assign mail attribute */
59     $smarty->assign("mail", $this->mail);
60     $smarty->assign("mailACL", chkacl($this->acl, "mail"));
62     /* Show main page */
63     return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE)));
64   }
67   /* Check formular input */
68   function check()
69   {
70     /* Call common method to give check the hook */
71     $message= plugin::check();
73     if ($this->is_account){
74       $ldap= $this->config->get_ldap_link();
76       /* Check if mail address is valid */
77       if (!is_email($this->mail) || $this->mail == ""){
78         $message[]= _("Please enter a valid email address in 'Primary address' field.");
79       }
81       /* Check if mail address is already in use */
82       $ldap->cd($this->config->current['BASE']);
83       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
84       if ($ldap->count() != 0){
85         $message[]= _("The primary address you've entered is already in use.");
86       }
87     }
89     return ($message);
90   }
93   function save()
94   {
95     $ldap= $this->config->get_ldap_link();
97     /* Call parents save to prepare $this->attrs */
98     plugin::save();
100     /* Save data to LDAP */
101     $ldap->cd($this->dn);
102     $this->cleanup();
103     $ldap->modify ($this->attrs); 
105     show_ldap_error($ldap->get_error(), _("Saving mail objectgroup settings failed"));
107     /* Optionally execute a command after we're done */
108     if ($this->initially_was_account == $this->is_account){
109       if ($this->is_modified){
110         $this->handle_post_events("modify");
111       }
112     } else {
113       $this->handle_post_events("add");
114     }
115   }
118   /* remove object from parent */
119   function remove_from_parent()
120   {
121     /* Cancel if there's nothing to do here */
122     if (!$this->initially_was_account){
123       return;
124     }
126     /* include global link_info */
127     $ldap= $this->config->get_ldap_link();
129     /* Remove and write to LDAP */
130     plugin::remove_from_parent();
132     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
133         $this->attributes, "Save");
134     $ldap->cd($this->dn);
135     $this->cleanup();
136     $ldap->modify ($this->attrs); 
138     show_ldap_error($ldap->get_error(), _("Removing mail objectgroup settings failed"));
139   }
142   function getCopyDialog()
143   {
144     $str = "";
145     $smarty = get_smarty();
146     $smarty->assign("mail",     $this->mail);
147     $str = $smarty->fetch(get_template_path("paste_mail.tpl",TRUE,dirname(__FILE__)));
148     $ret = array();
149     $ret['string'] = $str;
150     $ret['status'] = "";
151     return($ret);
152   }
154   function saveCopyDialog()
155   {
156     if(isset($_POST['mail'])){
157       $this->mail = $_POST['mail'];
158     }
159   }
162 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
163 ?>