Code

* Created "old" branch and moved stuff
[gosa.git] / branches / old / gosa-plugins / webdav / personal / connectivity / webdav / class_webdavAccount.inc
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);
21     
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    /* check if we are allowed to switch the checkbox.
57     */
58     $smarty->assign('webdavAccountACL', preg_replace("/w/","",$this->getacl("",$this->ReadOnly)));
59     if(($this->acl_is_removeable() && $this->is_account) ||
60         ($this->acl_is_createable() && !$this->is_account)){
61       $smarty->assign('webdavAccountACL', $this->getacl("",$this->ReadOnly));
62     }
64     $smarty->assign("use_webdav",in_array("webdav",$this->multi_boxes));
65     $smarty->assign("multiple_support",$this->multiple_support_active);
66     $display.= $smarty->fetch (get_template_path('webdav.tpl', TRUE, dirname(__FILE__)));
67     return ($display);
68   }
70   function remove_from_parent()
71   {
72     if($this->acl_is_createable() || $this->is_account){
73       /* Cancel if there's nothing to do here */
74       if (!$this->initially_was_account){
75         return;
76       }
78       plugin::remove_from_parent();
79       $ldap= $this->config->get_ldap_link();
81       $ldap->cd($this->dn);
82       @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
83           $this->attributes, "Save");
84       $this->cleanup();
85       $ldap->modify ($this->attrs); 
87       /* Log last action */
88       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
90       if (!$ldap->success()){
91         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
92       }
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['webdav'])){
106         if (!$this->is_account && $_POST['webdav'] == "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["WEBDAVStatus"])){
120       $this->WEBDAVStatus = "disabled";
121     } else {
122       $this->WEBDAVStatus = "enabled";
123     }
124   }
127   /* Save to LDAP */
128   function save()
129   {
130     if($this->acl_is_createable()){
131       plugin::save();
133       /* Write back to ldap */
134       $ldap= $this->config->get_ldap_link();
135       $ldap->cd($this->dn);
136       $this->cleanup();
137       $ldap->modify ($this->attrs); 
139       /* Log last action */
140       if($this->initially_was_account){
141         new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
142       }else{
143         new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
144       }
146       if (!$ldap->success()){
147         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
148       }
150       /* Optionally execute a command after we're done */
151       if ($this->initially_was_account == $this->is_account){
152         if ($this->is_modified){
153           $this->handle_post_events("modify",array("uid" => $this->uid));
154         }
155       } else {
156         $this->handle_post_events("add",array("uid" => $this->uid));
157       }
158     }
159   }
161   /* Return plugin informations for acl handling
162       #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
163   static function plInfo()
164   {
165     return (array(  
166           "plShortName"     => _("WebDAV"),
167           "plDescription"   => _("WebDAV account")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
168           "plSelfModify"    => TRUE,
169           "plDepends"       => array("user"),
170           "plPriority"      => 23,                                 // Position in tabs
171           "plSection"     => array("personal" => _("My account")),
172           "plCategory"    => array("users"),
173           "plOptions"       => array(),
175           "plProvidedAcls"  => array()
176           ));
177   }
179   function multiple_save_object()
180   {
181     if (isset($_POST['connectivityTab'])){
182       plugin::multiple_save_object();
184       if(isset($_POST['use_webdav'])){
185         $this->multi_boxes[] = "webdav";
186         if (isset($_POST['webdav'])){
187           if (!$this->is_account && $_POST['webdav'] == "B"){
188             if($this->acl_is_createable()){
189               $this->is_account= TRUE;
190             }
191           }
192         } else {
193           if($this->acl_is_removeable()){
194             $this->is_account= FALSE;
195           }
196         }
197       }
198     }
199   }
201   function get_multi_edit_values()
202   {
203     $ret = plugin::get_multi_edit_values();
204     if(in_array("webdav",$this->multi_boxes)){
205       $ret['is_account'] = $this->is_account;
206     }
207     return($ret);
208   }
210   function set_multi_edit_values($values)
211   {
212     plugin::set_multi_edit_values($values);
213     if(isset($values['is_account'])){
214       $this->is_account = $values['is_account'];
215     }
216   }
218   function init_multiple_support($attrs,$all)
219   {
220     plugin::init_multiple_support($attrs,$all);
221     if(isset($attrs['objectClass']) && in_array("gosaWebdavAccount",$attrs['objectClass'])){
222       $this->is_account = TRUE;
223     }
224   }
227 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
228 ?>