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();
13 var $view_logged = FALSE;
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 if($this->is_account && !$this->view_logged){
33 $this->view_logged = TRUE;
34 new log("view","ogroups/".get_class($this),$this->dn);
35 }
38 /* Do we need to flip is_account state? */
39 if(isset($_POST['modify_state'])){
40 if($this->is_account && $this->acl_is_removeable()){
41 $this->is_account= FALSE;
42 }elseif(!$this->is_account && $this->acl_is_createable()){
43 $this->is_account= TRUE;
44 }
45 }
47 /* Show tab dialog headers */
48 if ($this->parent !== NULL){
49 if ($this->is_account){
50 $display= $this->show_disable_header(_("Remove mail account"),
51 msgPool::featuresEnabled(_("mail group")));
52 } else {
53 $display= $this->show_enable_header(_("Create mail account"),
54 msgPool::featuresDisabled(_("mail group")));
55 return ($display);
56 }
57 }
59 /* Initialize templating engine */
60 $smarty= get_smarty();
62 $tmp = $this->plInfo();
63 foreach($tmp['plProvidedAcls'] as $name => $translation){
64 $smarty->assign($name."ACL",$this->getacl("mail"));
65 }
67 /* Assign mail attribute */
68 $smarty->assign("mail", $this->mail);
70 /* Show main page */
71 return ($display.$smarty->fetch (get_template_path('mail.tpl', TRUE,dirname(__FILE__))));
72 }
75 /* Check formular input */
76 function check()
77 {
78 /* Call common method to give check the hook */
79 $message= plugin::check();
81 if ($this->is_account){
82 $ldap= $this->config->get_ldap_link();
84 /* Check if mail address is valid */
85 if (!tests::is_email($this->mail) || $this->mail == ""){
86 $message[]= msgPool::invalid(_("Mail address"),"","",_("your-name@your-domain.com"));
87 }
89 /* Check if mail address is already in use */
90 $ldap->cd($this->config->current['BASE']);
91 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
92 if ($ldap->count() != 0){
93 $message[]= msgPool::duplicated(_("Mail address"));
94 }
95 }
97 return ($message);
98 }
101 function save()
102 {
103 $ldap= $this->config->get_ldap_link();
105 /* Call parents save to prepare $this->attrs */
106 plugin::save();
108 /* Save data to LDAP */
109 $ldap->cd($this->dn);
110 $this->cleanup();
111 $ldap->modify ($this->attrs);
113 if($this->initially_was_account){
114 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
115 }else{
116 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
117 }
119 if (!$ldap->success()){
120 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
121 }
123 /* Optionally execute a command after we're done */
124 if ($this->initially_was_account == $this->is_account){
125 if ($this->is_modified){
126 $this->handle_post_events("modify");
127 }
128 } else {
129 $this->handle_post_events("add");
130 }
131 }
134 /* remove object from parent */
135 function remove_from_parent()
136 {
137 /* Cancel if there's nothing to do here */
138 if (!$this->initially_was_account){
139 return;
140 }
142 /* include global link_info */
143 $ldap= $this->config->get_ldap_link();
145 /* Remove and write to LDAP */
146 plugin::remove_from_parent();
148 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
149 $this->attributes, "Save");
150 $ldap->cd($this->dn);
151 $this->cleanup();
152 $ldap->modify ($this->attrs);
154 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
156 if (!$ldap->success()){
157 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
158 }
159 }
162 function getCopyDialog()
163 {
164 $str = "";
165 $smarty = get_smarty();
166 $smarty->assign("mail", $this->mail);
167 $str = $smarty->fetch(get_template_path("paste_mail.tpl",TRUE,dirname(__FILE__)));
168 $ret = array();
169 $ret['string'] = $str;
170 $ret['status'] = "";
171 return($ret);
172 }
175 function saveCopyDialog()
176 {
177 if(isset($_POST['mail'])){
178 $this->mail = $_POST['mail'];
179 }
180 }
183 static function plInfo()
184 {
185 return (array(
186 "plShortName" => _("Mail"),
187 "plDescription" => _("Mail group"),
188 "plSelfModify" => FALSE,
189 "plDepends" => array(),
190 "plPriority" => 4,
191 "plSection" => array("administration"),
192 "plCategory" => array("ogroups"),
193 "plProvidedAcls"=> array(
194 "mail" => _("Mail address"))
195 ));
196 }
201 }
203 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
204 ?>