Code

Backport from trunk
[gosa.git] / 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= "Manage WebDAV user settings";
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_strict("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       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       /* Log last action */
139       if($this->initially_was_account){
140           new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
141       }else{
142           new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
143       }
145       if (!$ldap->success()){
146           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
147       }
149       /* Optionally execute a command after we're done */
150       if ($this->initially_was_account == $this->is_account){
151           if ($this->is_modified){
152               $this->handle_post_events("modify",array("uid" => $this->uid));
153           }
154       } else {
155           $this->handle_post_events("add",array("uid" => $this->uid));
156       }
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"     => _("WebDAV"),
166           "plDescription"   => _("WebDAV account")."&nbsp;("._("Connectivity add-on").")",
167           "plSelfModify"    => TRUE,
168           "plDepends"       => array("user"),
169           "plRequirements"=> array(
170               'ldapSchema' => array('gosaWebdavAccount' => '>=2.7'),
171               'onFailureDisablePlugin' => array(get_class())
172               ),
173           "plPriority"      => 23,                                 // Position in tabs
174           "plSection"     => array("personal" => _("My account")),
175           "plCategory"    => array("users"),
176           "plOptions"       => array(),
178           "plProvidedAcls"  => array()
179           ));
180   }
182   function multiple_save_object()
183   {
184     if (isset($_POST['connectivityTab'])){
185       plugin::multiple_save_object();
187       if(isset($_POST['use_webdav'])){
188         $this->multi_boxes[] = "webdav";
189         if (isset($_POST['webdav'])){
190           if (!$this->is_account && $_POST['webdav'] == "B"){
191             if($this->acl_is_createable()){
192               $this->is_account= TRUE;
193             }
194           }
195         } else {
196           if($this->acl_is_removeable()){
197             $this->is_account= FALSE;
198           }
199         }
200       }
201     }
202   }
204   function get_multi_edit_values()
205   {
206     $ret = plugin::get_multi_edit_values();
207     if(in_array_strict("webdav",$this->multi_boxes)){
208       $ret['is_account'] = $this->is_account;
209     }
210     return($ret);
211   }
213   function set_multi_edit_values($values)
214   {
215     plugin::set_multi_edit_values($values);
216     if(isset($values['is_account'])){
217       $this->is_account = $values['is_account'];
218     }
219   }
221   function init_multiple_support($attrs,$all)
222   {
223     plugin::init_multiple_support($attrs,$all);
224     if(isset($attrs['objectClass']) && in_array_strict("gosaWebdavAccount",$attrs['objectClass'])){
225       $this->is_account = TRUE;
226     }
227   }
230 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
231 ?>