Code

5d23c1051953d42c2ccb78e959b533ce3fed0552
[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();
31     /* Do we need to flip is_account state? */
32     if (isset($_POST['modify_state'])){
33       $this->is_account= !$this->is_account;
34     }
36     /* Show tab dialog headers */
37     if ($this->parent != NULL){
38       if ($this->is_account){
39         $display= $this->show_header(_("Remove mail account"),
40             _("This group has mail features enabled. You can disable them by clicking below."));
41       } else {
42         $display= $this->show_header(_("Create mail account"), _("This group has mail features disabled. You can enable them by clicking below."));
43         return ($display);
44       }
45     }
46     
47     /* Initialize templating engine */
48     $smarty= get_smarty();
50     /* Assign mail attribute */
51     $smarty->assign("mail", $this->mail);
52     $smarty->assign("mailACL", chkacl($this->acl, "mail"));
54     /* Show main page */
55     return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE)));
56   }
59   /* Check formular input */
60   function check()
61   {
62     $message= array();
64     if ($this->is_account){
65       $ldap= $this->config->get_ldap_link();
67       /* Check if mail address is valid */
68       if (!is_email($this->mail) || $this->mail == ""){
69         $message[]= _("Please enter a valid email address in 'Primary address' field.");
70       }
72       /* Check if mail address is already in use */
73       $ldap->cd($this->config->current['BASE']);
74       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.         ")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
75       if ($ldap->count() != 0){
76         $message[]= _("The primary address you've entered is already in use.");
77       }
78     }
80     return ($message);
81   }
84   function save()
85   {
86     $ldap= $this->config->get_ldap_link();
88     /* Call parents save to prepare $this->attrs */
89     plugin::save();
91     /* Save data to LDAP */
92     $ldap->cd($this->dn);
93     $ldap->modify($this->attrs);
94     show_ldap_error($ldap->get_error());
96     /* Optionally execute a command after we're done */
97     if ($this->initially_was_account == $this->is_account){
98       if ($this->is_modified){
99         $this->handle_post_events("mofify");
100       }
101     } else {
102       $this->handle_post_events("add");
103     }
104   }
107   /* remove object from parent */
108   function remove_from_parent()
109   {
110     /* Cancel if there's nothing to do here */
111     if (!$this->initially_was_account){
112       return;
113     }
115     /* include global link_info */
116     $ldap= $this->config->get_ldap_link();
118     /* Remove and write to LDAP */
119     plugin::remove_from_parent();
121     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
122         $this->attributes, "Save");
123     $ldap->cd($this->dn);
124     $ldap->modify($this->attrs);
125     show_ldap_error($ldap->get_error());
126   }
130 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
131 ?>