Code

59fdb60ef8ce24000dbdc102a315a9ae81be5242
[gosa.git] / plugins / personal / connectivity / 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   function webdavAccount (&$config, $dn= NULL)
17   {
18     plugin::plugin ($config, $dn);
19     
20     /* Setting uid to default */
21     if(isset($this->attrs['uid'][0])){
22       $this->uid = $this->attrs['uid'][0];
23     }
24   }
26   function execute()
27   {
28         /* Call parent execute */
29 //      plugin::execute();
31     /* Log view */
32     if($this->is_account && !$this->view_logged){
33       $this->view_logged = TRUE;
34       new log("view","users/".get_class($this),$this->dn);
35     }
37     /* Show tab dialog headers */
38     $display= "";
40     /* Show main page */
41     $smarty= get_smarty();
43     if ($this->is_account){
44       $smarty->assign("webdavState", "checked");
45     } else {
46       $smarty->assign("webdavState", "");
47       $smarty->assign("wstate", "disabled");
48     }
50     if ($this->parent !== NULL){
51       $smarty->assign("tabbed", 1);
52     }
54     if((!$this->ReadOnly) && (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
55       $smarty->assign('webdavAccountACL', "");
56     }else{
57       $smarty->assign('webdavAccountACL', " disabled ");
58     }
60     $display.= $smarty->fetch (get_template_path('webdav.tpl', TRUE, dirname(__FILE__)));
61     return ($display);
62   }
64   function remove_from_parent()
65   {
66     if($this->acl_is_createable() || $this->is_account){
67       /* Cancel if there's nothing to do here */
68       if (!$this->initially_was_account){
69         return;
70       }
72       plugin::remove_from_parent();
73       $ldap= $this->config->get_ldap_link();
75       $ldap->cd($this->dn);
76       @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
77           $this->attributes, "Save");
78       $this->cleanup();
79       $ldap->modify ($this->attrs); 
81       /* Log last action */
82       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
84       show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/webDAV account with dn '%s' failed."),$this->dn));
86       /* Optionally execute a command after we're done */
87       $this->handle_post_events('remove',array("uid" => $this->uid));
88     }
89   }
92   /* Save data to object */
93   function save_object()
94   {
95     /* Do we need to flip is_account state? */
96     if (isset($_POST['connectivityTab'])){
97       if (isset($_POST['webdav'])){
98         if (!$this->is_account && $_POST['webdav'] == "B"){
99           if($this->acl_is_createable()){
100             $this->is_account= TRUE;
101           }
102         }
103       } else {
104         if($this->acl_is_removeable()){
105           $this->is_account= FALSE;
106         }
107       }
108     }
110     plugin::save_object();
111     if (isset($_POST["WEBDAVStatus"])){
112       $this->WEBDAVStatus = "disabled";
113     } else {
114       $this->WEBDAVStatus = "enabled";
115     }
116   }
119   /* Save to LDAP */
120   function save()
121   {
122     if($this->acl_is_createable()){
123       plugin::save();
125       /* Write back to ldap */
126       $ldap= $this->config->get_ldap_link();
127       $ldap->cd($this->dn);
128       $this->cleanup();
129       $ldap->modify ($this->attrs); 
131       /* Log last action */
132       if($this->initially_was_account){
133         new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
134       }else{
135         new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
136       }
138       show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/webDAV account with dn '%s' failed."),$this->dn));
140       /* Optionally execute a command after we're done */
141       if ($this->initially_was_account == $this->is_account){
142         if ($this->is_modified){
143           $this->handle_post_events("modify",array("uid" => $this->uid));
144         }
145       } else {
146         $this->handle_post_events("add",array("uid" => $this->uid));
147       }
148     }
149   }
151   /* Return plugin informations for acl handling
152       #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
153   static function plInfo()
154   {
155     return (array(  
156           "plShortName"     => _("WebDAV"),
157           "plDescription"   => _("WebDAV account")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
158           "plSelfModify"    => TRUE,
159           "plDepends"       => array("user"),
160           "plPriority"      => 23,                                 // Position in tabs
161           "plSection"     => array("personal" => _("My account")),
162           "plCategory"    => array("users"),
163           "plOptions"       => array(),
165           "plProvidedAcls"  => array()
166           ));
167   }
170 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
171 ?>