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);
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 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/PPTP account with dn '%s' failed."),$this->dn));
103 /* Optionally execute a command after we're done */
104 $this->handle_post_events('remove',array("uid" => $this->uid));
105 }
106 }
109 /* Save data to object */
110 function save_object()
111 {
112 /* Do we need to flip is_account state? */
113 if (isset($_POST['connectivityTab'])){
114 if (isset($_POST['pptp'])){
115 if (!$this->is_account && $_POST['pptp'] == "B"){
116 if($this->acl_is_createable()){
117 $this->is_account= TRUE;
118 }
119 }
120 } else {
121 if($this->acl_is_removeable()){
122 $this->is_account= FALSE;
123 }
124 }
125 }
127 plugin::save_object();
128 if (isset($_POST["pptpStatus"])){
129 $this->pptpStatus = "disabled";
130 } else {
131 $this->pptpStatus = "enabled";
132 }
133 }
136 /* Save to LDAP */
137 function save()
138 {
139 if($this->acl_is_createable()){
140 plugin::save();
142 /* Write back to ldap */
143 $ldap= $this->config->get_ldap_link();
144 $ldap->cd($this->dn);
145 $this->cleanup();
146 $ldap->modify ($this->attrs);
148 /* Log last action */
149 if($this->initially_was_account){
150 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
151 }else{
152 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
153 }
155 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/PPTP account with dn '%s' failed."),$this->dn));
157 /* Optionally execute a command after we're done */
158 if ($this->initially_was_account == $this->is_account){
159 if ($this->is_modified){
160 $this->handle_post_events("modify",array("uid" => $this->uid));
161 }
162 } else {
163 $this->handle_post_events("add",array("uid" => $this->uid));
164 }
165 }
166 }
169 /* Return plugin informations for acl handling */
170 function plInfo()
171 {
172 return (array(
173 "plShortName" => _("PPTP"),
174 "plDescription" => _("PPTP account")." : <u>"._("Connectivity addon")."</u>",
175 "plSelfModify" => TRUE,
176 "plDepends" => array("user"),
177 "plPriority" => 28, // Position in tabs
178 "plSection" => array("personal" => _("My account")),
179 "plCategory" => array("users"),
180 "plOptions" => array(),
182 "plProvidedAcls" => array()
183 ));
184 }
185 }
187 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
188 ?>