Code

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