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_disable_header(_("Remove mail account"),
41 _("This group has mail features enabled. You can disable them by clicking below."));
42 } else {
43 $display= $this->show_enable_header(_("Create mail account"), _("This group has mail features disabled. You can enable them by clicking below."));
44 return ($display);
45 }
46 }
48 /* Initialize templating engine */
49 $smarty= get_smarty();
51 $tmp = $this->plInfo();
52 foreach($tmp['plProvidedAcls'] as $name => $translation){
53 $smarty->assign($name."ACL",$this->getacl("mail"));
54 }
56 /* Assign mail attribute */
57 $smarty->assign("mail", $this->mail);
59 /* Show main page */
60 return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE)));
61 }
64 /* Check formular input */
65 function check()
66 {
67 /* Call common method to give check the hook */
68 $message= plugin::check();
70 if ($this->is_account){
71 $ldap= $this->config->get_ldap_link();
73 /* Check if mail address is valid */
74 if (!is_email($this->mail) || $this->mail == ""){
75 $message[]= _("Please enter a valid email address in 'Primary address' field.");
76 }
78 /* Check if mail address is already in use */
79 $ldap->cd($this->config->current['BASE']);
80 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail. ")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
81 if ($ldap->count() != 0){
82 $message[]= _("The primary address you've entered is already in use.");
83 }
84 }
86 return ($message);
87 }
90 function save()
91 {
92 $ldap= $this->config->get_ldap_link();
94 /* Call parents save to prepare $this->attrs */
95 plugin::save();
97 /* Save data to LDAP */
98 $ldap->cd($this->dn);
99 $this->cleanup();
100 $ldap->modify ($this->attrs);
102 show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/mail with dn '%s' failed."),$this->dn));
104 /* Optionally execute a command after we're done */
105 if ($this->initially_was_account == $this->is_account){
106 if ($this->is_modified){
107 $this->handle_post_events("mofify");
108 }
109 } else {
110 $this->handle_post_events("add");
111 }
112 }
115 /* remove object from parent */
116 function remove_from_parent()
117 {
118 /* Cancel if there's nothing to do here */
119 if (!$this->initially_was_account){
120 return;
121 }
123 /* include global link_info */
124 $ldap= $this->config->get_ldap_link();
126 /* Remove and write to LDAP */
127 plugin::remove_from_parent();
129 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
130 $this->attributes, "Save");
131 $ldap->cd($this->dn);
132 $this->cleanup();
133 $ldap->modify ($this->attrs);
135 show_ldap_error($ldap->get_error(), sprintf(_("Removing of object group/mail with dn '%s' failed."),$this->dn));
136 }
139 function getCopyDialog()
140 {
141 $str = "";
142 $str .= _("Phone number");
143 $str .= " <input type='text' name='mail' value='".$this->mail."'>";
144 return($str);
145 }
148 function saveCopyDialog()
149 {
150 if(isset($_POST['mail'])){
151 $this->mail = $_POST['mail'];
152 }
153 }
156 function plInfo()
157 {
158 return (array(
159 "plShortName" => _("Mail"),
160 "plDescription" => _("Mail group"),
161 "plSelfModify" => FALSE,
162 "plDepends" => array(),
163 "plPriority" => 0,
164 "plSection" => array("administration"),
165 "plCategory" => array("ogroups"),
166 "plProvidedAcls"=> array(
167 "mail" => _("Mail address"))
168 ));
169 }
174 }
176 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
177 ?>