Code

Added ogroups acls
[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();
32     /* Do we need to flip is_account state? */
33     if (isset($_POST['modify_state'])){
34       $this->is_account= !$this->is_account;
35     }
37     /* Show tab dialog headers */
38     if ($this->parent != NULL){
39       if ($this->is_account){
40         $display= $this->show_header(_("Remove mail account"),
41             _("This group has mail features enabled. You can disable them by clicking below."));
42       } else {
43         $display= $this->show_header(_("Create mail account"), _("This group has mail features disabled. You can enable them by clicking below."));
44         return ($display);
45       }
46     }
47     
48     /* Initialize templating engine */
49     $smarty= get_smarty();
51     /* Assign mail attribute */
52     $smarty->assign("mail", $this->mail);
53     $smarty->assign("mailACL", chkacl($this->acl, "mail"));
55     /* Show main page */
56     return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE)));
57   }
60   /* Check formular input */
61   function check()
62   {
63     /* Call common method to give check the hook */
64     $message= plugin::check();
66     if ($this->is_account){
67       $ldap= $this->config->get_ldap_link();
69       /* Check if mail address is valid */
70       if (!is_email($this->mail) || $this->mail == ""){
71         $message[]= _("Please enter a valid email address in 'Primary address' field.");
72       }
74       /* Check if mail address is already in use */
75       $ldap->cd($this->config->current['BASE']);
76       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.         ")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
77       if ($ldap->count() != 0){
78         $message[]= _("The primary address you've entered is already in use.");
79       }
80     }
82     return ($message);
83   }
86   function save()
87   {
88     $ldap= $this->config->get_ldap_link();
90     /* Call parents save to prepare $this->attrs */
91     plugin::save();
93     /* Save data to LDAP */
94     $ldap->cd($this->dn);
95     $this->cleanup();
96     $ldap->modify ($this->attrs); 
98     show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/mail with dn '%s' failed."),$this->dn));
100     /* Optionally execute a command after we're done */
101     if ($this->initially_was_account == $this->is_account){
102       if ($this->is_modified){
103         $this->handle_post_events("mofify");
104       }
105     } else {
106       $this->handle_post_events("add");
107     }
108   }
111   /* remove object from parent */
112   function remove_from_parent()
113   {
114     /* Cancel if there's nothing to do here */
115     if (!$this->initially_was_account){
116       return;
117     }
119     /* include global link_info */
120     $ldap= $this->config->get_ldap_link();
122     /* Remove and write to LDAP */
123     plugin::remove_from_parent();
125     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
126         $this->attributes, "Save");
127     $ldap->cd($this->dn);
128     $this->cleanup();
129     $ldap->modify ($this->attrs); 
131     show_ldap_error($ldap->get_error(), sprintf(_("Removing of object group/mail with dn '%s' failed."),$this->dn));
132   }
135   function getCopyDialog()
136   {
137     $str  = "";
138     $str .= _("Phone number");
139     $str .= "&nbsp;<input type='text' name='mail' value='".$this->mail."'>";
140     return($str);
141   }
144   function saveCopyDialog()
145   {
146     if(isset($_POST['mail'])){
147       $this->mail = $_POST['mail'];
148     }
149   }
152      function plInfo()
153   {
154     return (array(
155           "plShortName"   => _("Mail"),
156           "plDescription" => _("Mail group"),
157           "plSelfModify"  => FALSE,
158           "plDepends"     => array(),
159           "plPriority"    => 0,
160           "plSection"     => array("administration"),
161           "plCategory"    => array("ogroups"),
162           "plProvidedAcls"=> array(
163             "mail" => _("Mail address"))
164           ));
165   }
172 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
173 ?>