Code

Removed show_ldap_error() calls
[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= "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     $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       if (!$ldap->success()){
84         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
85       }
87       /* Optionally execute a command after we're done */
88       $this->handle_post_events('remove',array("uid" => $this->uid));
89     }
90   }
93   /* Save data to object */
94   function save_object()
95   {
96     /* Do we need to flip is_account state? */
97     if (isset($_POST['connectivityTab'])){
98       if (isset($_POST['webdav'])){
99         if (!$this->is_account && $_POST['webdav'] == "B"){
100           if($this->acl_is_createable()){
101             $this->is_account= TRUE;
102           }
103         }
104       } else {
105         if($this->acl_is_removeable()){
106           $this->is_account= FALSE;
107         }
108       }
109     }
111     plugin::save_object();
112     if (isset($_POST["WEBDAVStatus"])){
113       $this->WEBDAVStatus = "disabled";
114     } else {
115       $this->WEBDAVStatus = "enabled";
116     }
117   }
120   /* Save to LDAP */
121   function save()
122   {
123     if($this->acl_is_createable()){
124       plugin::save();
126       /* Write back to ldap */
127       $ldap= $this->config->get_ldap_link();
128       $ldap->cd($this->dn);
129       $this->cleanup();
130       $ldap->modify ($this->attrs); 
132       /* Log last action */
133       if($this->initially_was_account){
134         new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
135       }else{
136         new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
137       }
139       if (!$ldap->success()){
140         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
141       }
143       /* Optionally execute a command after we're done */
144       if ($this->initially_was_account == $this->is_account){
145         if ($this->is_modified){
146           $this->handle_post_events("modify",array("uid" => $this->uid));
147         }
148       } else {
149         $this->handle_post_events("add",array("uid" => $this->uid));
150       }
151     }
152   }
154   /* Return plugin informations for acl handling
155       #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
156   static function plInfo()
157   {
158     return (array(  
159           "plShortName"     => _("WebDAV"),
160           "plDescription"   => _("WebDAV account")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
161           "plSelfModify"    => TRUE,
162           "plDepends"       => array("user"),
163           "plPriority"      => 23,                                 // Position in tabs
164           "plSection"     => array("personal" => _("My account")),
165           "plCategory"    => array("users"),
166           "plOptions"       => array(),
168           "plProvidedAcls"  => array()
169           ));
170   }
172   function multiple_save_object()
173   {
174     if (isset($_POST['connectivityTab'])){
175       plugin::multiple_save_object();
177       if(isset($_POST['use_webdav'])){
178         $this->multi_boxes[] = "webdav";
179         if (isset($_POST['webdav'])){
180           if (!$this->is_account && $_POST['webdav'] == "B"){
181             if($this->acl_is_createable()){
182               $this->is_account= TRUE;
183             }
184           }
185         } else {
186           if($this->acl_is_removeable()){
187             $this->is_account= FALSE;
188           }
189         }
190       }
191     }
192   }
194   function get_multi_edit_values()
195   {
196     $ret = plugin::get_multi_edit_values();
197     if(in_array("webdav",$this->multi_boxes)){
198       $ret['is_account'] = $this->is_account;
199     }
200     return($ret);
201   }
203   function set_multi_edit_values($values)
204   {
205     plugin::set_multi_edit_values($values);
206     if(isset($values['is_account'])){
207       $this->is_account = $values['is_account'];
208     }
209   }
211   function init_multiple_support($attrs,$all)
212   {
213     plugin::init_multiple_support($attrs,$all);
214     if(isset($attrs['objectClass']) && in_array("gosaWebdavAccount",$attrs['objectClass'])){
215       $this->is_account = TRUE;
216     }
217   }
220 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
221 ?>