[gosa.git] / gosa-plugins / phpscheduleit / personal / connectivity / phpscheduleit / class_phpscheduleitAccount.inc
1 <?php
3 /*
4 This code is part of GOsa (https://gosa.gonicus.de)
5 Copyright (C) 2005 Guillaume Delecourt
6 Copuright (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 */
24 class phpscheduleitAccount extends plugin
25 {
26 /* Definitions */
27 var $plHeadline= "phpScheduleIt";
28 var $plDescription= "Manage phpScheduleIt user settings";
30 /* attribute list for save action */
31 var $attributes= array();
32 var $objectclasses= array("phpscheduleitAccount");
33 var $ReadOnly =false;
34 var $view_logged = FALSE;
36 function phpscheduleitAccount (&$config, $dn= NULL)
37 {
38 plugin::plugin ($config, $dn);
39 }
41 function execute()
42 {
43 plugin::execute();
45 /* Log view */
46 if($this->is_account && !$this->view_logged){
47 $this->view_logged = TRUE;
48 new log("view","users/".get_class($this),$this->dn);
49 }
51 /* Show tab dialog headers */
52 $display= "";
54 /* Show main page */
55 $smarty= get_smarty();
57 if ($this->is_account){
58 $smarty->assign("phpscheduleitState", "checked");
59 } else {
60 $smarty->assign("phpscheduleitState", "");
61 $smarty->assign("wstate", "disabled");
62 }
64 if((!$this->ReadOnly) && (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
65 $smarty->assign('gosaphpscheduleitACL', "");
66 }else{
67 $smarty->assign('gosaphpscheduleitACL', " disabled ");
68 }
70 $display.= $smarty->fetch (get_template_path('phpscheduleit.tpl', TRUE, dirname(__FILE__)));
71 return ($display);
72 }
74 function remove_from_parent()
75 {
76 /* Cancel if there's nothing to do here */
77 if ($this->acl_is_removeable()){
79 plugin::remove_from_parent();
80 $ldap= $this->config->get_ldap_link();
82 $ldap->cd($this->dn);
83 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
84 $this->attributes, "Save");
85 $this->cleanup();
86 $ldap->modify ($this->attrs);
87 if (!$ldap->success()){
88 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
89 }
91 if($this->is_account){
92 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
93 }
94 /* Optionally execute a command after we're done */
95 $this->handle_post_events('remove',array("uid" => $this->uid));
96 }
97 }
100 /* Save data to object */
101 function save_object()
102 {
103 /* Do we need to flip is_account state? */
104 if (isset($_POST['connectivityTab'])){
105 if (isset($_POST['phpscheduleit'])){
106 if (!$this->is_account && $_POST['phpscheduleit'] == "B"){
107 if($this->acl_is_createable()) {
108 $this->is_account= TRUE;
109 }
110 }
111 } else {
112 if($this->acl_is_removeable()){
113 $this->is_account= FALSE;
114 }
115 }
116 }
118 plugin::save_object();
119 if (isset($_POST["phpscheduleitStatus"])){
120 $this->pptpStatus = "disabled";
121 } else {
122 $this->pptpStatus = "enabled";
123 }
124 }
127 /* Save to LDAP */
128 function save()
129 {
130 plugin::save();
132 /* Write back to ldap */
133 $ldap= $this->config->get_ldap_link();
134 $ldap->cd($this->dn);
135 $this->cleanup();
136 $ldap->modify ($this->attrs);
138 if($this->initially_was_account){
139 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
140 }else{
141 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
142 }
144 if (!$ldap->success()){
145 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
146 }
148 /* Optionally execute a command after we're done */
149 if ($this->initially_was_account == $this->is_account){
150 if ($this->is_modified){
151 $this->handle_post_events("modify",array("uid" => $this->uid));
152 }
153 } else {
154 $this->handle_post_events("add",array("uid" => $this->uid));
155 }
157 }
160 /* Return plugin informations for acl handling
161 #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
162 static function plInfo()
163 {
164 return (array(
165 "plShortName" => _("phpScheduleIt"),
166 "plDescription" => _("phpScheduleIt settings")." ("._("Connectivity add-on").")",
167 "plSelfModify" => TRUE,
168 "plDepends" => array("user"),
169 "plPriority" => 29, // Position in tabs
170 "plSection" => array("personal" => _("My account")),
171 "plCategory" => array("users"),
172 "plRequirements"=> array(
173 'ldapSchema' => array('phpscheduleitAccount' => ''),
174 'onFailureDisablePlugin' => array(get_class())
175 ),
177 "plOptions" => array(),
179 "plProvidedAcls" => array()
180 ));
181 }
182 }
184 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
185 ?>