Code

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