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 }
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 $message= array();
65 if ($this->is_account){
66 $ldap= $this->config->get_ldap_link();
68 /* Check if mail address is valid */
69 if (!is_email($this->mail) || $this->mail == ""){
70 $message[]= _("Please enter a valid email address in 'Primary address' field.");
71 }
73 /* Check if mail address is already in use */
74 $ldap->cd($this->config->current['BASE']);
75 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail. ")(gosaMailAlternateAddress=".$this->mail."))(!(cn=".$this->cn.")))", array("uid"));
76 if ($ldap->count() != 0){
77 $message[]= _("The primary address you've entered is already in use.");
78 }
79 }
81 return ($message);
82 }
85 function save()
86 {
87 $ldap= $this->config->get_ldap_link();
89 /* Call parents save to prepare $this->attrs */
90 plugin::save();
92 /* Save data to LDAP */
93 $ldap->cd($this->dn);
94 $ldap->modify($this->attrs);
95 show_ldap_error($ldap->get_error());
97 /* Optionally execute a command after we're done */
98 if ($this->initially_was_account == $this->is_account){
99 if ($this->is_modified){
100 $this->handle_post_events("mofify");
101 }
102 } else {
103 $this->handle_post_events("add");
104 }
105 }
108 /* remove object from parent */
109 function remove_from_parent()
110 {
111 /* Cancel if there's nothing to do here */
112 if (!$this->initially_was_account){
113 return;
114 }
116 /* include global link_info */
117 $ldap= $this->config->get_ldap_link();
119 /* Remove and write to LDAP */
120 plugin::remove_from_parent();
122 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
123 $this->attributes, "Save");
124 $ldap->cd($this->dn);
125 $ldap->modify($this->attrs);
126 show_ldap_error($ldap->get_error());
127 }
129 }
131 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
132 ?>