4d7c179ded461f579c81029d8f377cf5d72db18f
1 <?php
3 class webdavAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline= "WebDAV";
7 var $plDescription= "This does something";
9 /* attribute list for save action */
10 var $attributes= array();
11 var $objectclasses= array("gosaWebdavAccount");
12 var $ReadOnly = false;
13 var $view_logged = FALSE;
14 var $uid ="";
16 var $multiple_support =TRUE;
18 function webdavAccount (&$config, $dn= NULL)
19 {
20 plugin::plugin ($config, $dn);
22 /* Setting uid to default */
23 if(isset($this->attrs['uid'][0])){
24 $this->uid = $this->attrs['uid'][0];
25 }
26 }
28 function execute()
29 {
30 /* Call parent execute */
31 // plugin::execute();
33 /* Log view */
34 if($this->is_account && !$this->view_logged){
35 $this->view_logged = TRUE;
36 new log("view","users/".get_class($this),$this->dn);
37 }
39 /* Show tab dialog headers */
40 $display= "";
42 /* Show main page */
43 $smarty= get_smarty();
45 if ($this->is_account){
46 $smarty->assign("webdavState", "checked");
47 } else {
48 $smarty->assign("webdavState", "");
49 $smarty->assign("wstate", "disabled");
50 }
52 if ($this->parent !== NULL){
53 $smarty->assign("tabbed", 1);
54 }
56 $smarty->assign('webdavAccountACL', $this->getacl("",$this->ReadOnly));
57 $smarty->assign("use_webdav",in_array("webdav",$this->multi_boxes));
58 $smarty->assign("multiple_support",$this->multiple_support_active);
59 $display.= $smarty->fetch (get_template_path('webdav.tpl', TRUE, dirname(__FILE__)));
60 return ($display);
61 }
63 function remove_from_parent()
64 {
65 if($this->acl_is_createable() || $this->is_account){
66 /* Cancel if there's nothing to do here */
67 if (!$this->initially_was_account){
68 return;
69 }
71 plugin::remove_from_parent();
72 $ldap= $this->config->get_ldap_link();
74 $ldap->cd($this->dn);
75 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
76 $this->attributes, "Save");
77 $this->cleanup();
78 $ldap->modify ($this->attrs);
80 /* Log last action */
81 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
83 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/webDAV account with dn '%s' failed."),$this->dn));
85 /* Optionally execute a command after we're done */
86 $this->handle_post_events('remove',array("uid" => $this->uid));
87 }
88 }
91 /* Save data to object */
92 function save_object()
93 {
94 /* Do we need to flip is_account state? */
95 if (isset($_POST['connectivityTab'])){
96 if (isset($_POST['webdav'])){
97 if (!$this->is_account && $_POST['webdav'] == "B"){
98 if($this->acl_is_createable()){
99 $this->is_account= TRUE;
100 }
101 }
102 } else {
103 if($this->acl_is_removeable()){
104 $this->is_account= FALSE;
105 }
106 }
107 }
109 plugin::save_object();
110 if (isset($_POST["WEBDAVStatus"])){
111 $this->WEBDAVStatus = "disabled";
112 } else {
113 $this->WEBDAVStatus = "enabled";
114 }
115 }
118 /* Save to LDAP */
119 function save()
120 {
121 if($this->acl_is_createable()){
122 plugin::save();
124 /* Write back to ldap */
125 $ldap= $this->config->get_ldap_link();
126 $ldap->cd($this->dn);
127 $this->cleanup();
128 $ldap->modify ($this->attrs);
130 /* Log last action */
131 if($this->initially_was_account){
132 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
133 }else{
134 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
135 }
137 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/webDAV account with dn '%s' failed."),$this->dn));
139 /* Optionally execute a command after we're done */
140 if ($this->initially_was_account == $this->is_account){
141 if ($this->is_modified){
142 $this->handle_post_events("modify",array("uid" => $this->uid));
143 }
144 } else {
145 $this->handle_post_events("add",array("uid" => $this->uid));
146 }
147 }
148 }
150 /* Return plugin informations for acl handling
151 #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
152 static function plInfo()
153 {
154 return (array(
155 "plShortName" => _("WebDAV"),
156 "plDescription" => _("WebDAV account")." : <u>"._("Connectivity addon")."</u>",
157 "plSelfModify" => TRUE,
158 "plDepends" => array("user"),
159 "plPriority" => 23, // Position in tabs
160 "plSection" => array("personal" => _("My account")),
161 "plCategory" => array("users"),
162 "plOptions" => array(),
164 "plProvidedAcls" => array()
165 ));
166 }
168 function multiple_save_object()
169 {
170 if (isset($_POST['connectivityTab'])){
171 plugin::multiple_save_object();
173 if(isset($_POST['use_webdav'])){
174 $this->multi_boxes[] = "webdav";
175 if (isset($_POST['webdav'])){
176 if (!$this->is_account && $_POST['webdav'] == "B"){
177 if($this->acl_is_createable()){
178 $this->is_account= TRUE;
179 }
180 }
181 } else {
182 if($this->acl_is_removeable()){
183 $this->is_account= FALSE;
184 }
185 }
186 }
187 }
188 }
190 function get_multi_edit_values()
191 {
192 $ret = plugin::get_multi_edit_values();
193 if(in_array("webdav",$this->multi_boxes)){
194 $ret['is_account'] = $this->is_account;
195 }
196 return($ret);
197 }
199 function set_multi_edit_values($values)
200 {
201 plugin::set_multi_edit_values($values);
202 if(isset($values['is_account'])){
203 $this->is_account = $values['is_account'];
204 }
205 }
207 function init_multiple_support($attrs,$all)
208 {
209 plugin::init_multiple_support($attrs,$all);
210 if(isset($attrs['objectClass']) && in_array("gosaWebdavAccount",$attrs['objectClass'])){
211 $this->is_account = TRUE;
212 }
213 }
214 }
216 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
217 ?>