Code

d6c9fa1f779f117ea4b2ae4cce02ffa00a05ec55
[gosa.git] / gosa-plugins / pptp / personal / connectivity / pptp / class_pptpAccount.inc
1 <?php
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2005 Guillaume Delecourt
6    Copyright (C) 2005 Benoit Mortier
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class pptpAccount extends plugin
24 {
25   /* Definitions */
26   var $plHeadline= "PPTP";
27   var $plDescription= "This does something";
29   /* attribute list for save action */
30   var $attributes= array();
31   var $objectclasses= array("pptpServerAccount");
33   var $ReadOnly = false;
34   var $view_logged = FALSE;
35   var $uid ="";
37   function pptpAccount (&$config, $dn= NULL)
38   {
39     plugin::plugin ($config, $dn);
40     
41     /* Setting uid to default */
42     if(isset($this->attrs['uid'][0])){
43       $this->uid = $this->attrs['uid'][0];
44     }
45   }
47   function execute()
48   {
49     /* Call parent execute */
50     //  plugin::execute();
52     /* Log view */
53     if($this->is_account && !$this->view_logged){
54       $this->view_logged = TRUE;
55       new log("view","users/".get_class($this),$this->dn);
56     }
58     /* Show tab dialog headers */
59     $display= "";
61     /* Show main page */
62     $smarty= get_smarty();
64     if ($this->is_account){
65       $smarty->assign("pptpState", "checked");
66     } else {
67       $smarty->assign("pptpState", "");
68       $smarty->assign("wstate", "disabled");
69     }
71     if((!$this->ReadOnly) && (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
72       $smarty->assign('gosapptpACL', "");
73     }else{
74       $smarty->assign('gosapptpACL', " disabled ");
75     }
77     $display.= $smarty->fetch (get_template_path('pptp.tpl', TRUE, dirname(__FILE__)));
78     return ($display);
79   }
81   function remove_from_parent()
82   {
83     if($this->acl_is_removeable()){
84       /* Cancel if there's nothing to do here */
85       if (!$this->initially_was_account){
86         return;
87       }
89       plugin::remove_from_parent();
90       $ldap= $this->config->get_ldap_link();
92       $ldap->cd($this->dn);
93       @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
94           $this->attributes, "Save");
95       $this->cleanup();
96       $ldap->modify ($this->attrs); 
98       /* Log last action */
99       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
101       if (!$ldap->success()){
102         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
103       }
105       /* Optionally execute a command after we're done */
106       $this->handle_post_events('remove',array("uid" => $this->uid));
107     }
108   }
111   /* Save data to object */
112   function save_object()
113   {
114     /* Do we need to flip is_account state? */
115     if (isset($_POST['connectivityTab'])){
116       if (isset($_POST['pptp'])){
117         if (!$this->is_account && $_POST['pptp'] == "B"){
118           if($this->acl_is_createable()){
119             $this->is_account= TRUE;
120           }
121         }
122       } else {
123         if($this->acl_is_removeable()){
124           $this->is_account= FALSE;
125         }
126       }
127     }
129     plugin::save_object();
130     if (isset($_POST["pptpStatus"])){
131       $this->pptpStatus = "disabled";
132     } else {
133       $this->pptpStatus = "enabled";
134     }
135   }
138   /* Save to LDAP */
139   function save()
140   {
141       plugin::save();
143       /* Write back to ldap */
144       $ldap= $this->config->get_ldap_link();
145       $ldap->cd($this->dn);
146       $this->cleanup();
147       $ldap->modify ($this->attrs); 
149       /* Log last action */
150       if($this->initially_was_account){
151           new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
152       }else{
153           new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
154       }
156       if (!$ldap->success()){
157           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
158       }
160       /* Optionally execute a command after we're done */
161       if ($this->initially_was_account == $this->is_account){
162           if ($this->is_modified){
163               $this->handle_post_events("modify",array("uid" => $this->uid));
164           }
165       } else {
166           $this->handle_post_events("add",array("uid" => $this->uid));
167       }
168   }
171   /* Return plugin informations for acl handling */ 
172   static function plInfo()
173   {
174     return (array(
175           "plShortName"     => _("PPTP"),
176           "plDescription"   => _("PPTP account")."&nbsp;("._("Connectivity add-on").")",
177           "plSelfModify"    => TRUE,
178           "plDepends"       => array("user"),
179           "plPriority"      => 28,                                 // Position in tabs
180           "plSection"     => array("personal" => _("My account")),
181           "plCategory"    => array("users"),
182           "plRequirements"=> array(
183               'ldapSchema' => array('pptpServerAccount' => ''),
184               'onFailureDisablePlugin' => array(get_class())
185               ),
186           "plOptions"       => array(),
188           "plProvidedAcls"  => array()
189           ));
190   }
193 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
194 ?>