Code

Removed debug tags
[gosa.git] / plugins / personal / connectivity / class_pureftpdAccount.inc
1 <?php
3 class pureftpdAccount extends plugin
4 {
5   /* Definitions */
6   var $plHeadline= "FTP";
7   var $plDescription= "This does something";
9   /* FTP attributes */
10   var $FTPQuotaFiles = 0;
11   var $FTPQuotaMBytes = 0;
12   var $FTPUploadRatio = 0;
13   var $FTPDownloadRatio = 0;
14   var $FTPUploadBandwidth = 0;
15   var $FTPDownloadBandwidth = 0;
16   var $FTPStatus = "enabled";
17   var $FTPuid = "";
18   var $FTPgid = "";
20   /* attribute list for save action */
21   var $attributes= array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
22       "FTPUploadBandwidth","FTPDownloadBandwidth","FTPStatus","FTPuid","FTPgid");
23   var $objectclasses= array("PureFTPdUser");
24   var $ReadOnly;
26   function pureftpdAccount ($config, $dn= NULL)
27   {
28     plugin::plugin ($config, $dn);
29   }
31   function execute()
32   {
33     /* Show tab dialog headers */
34     $display= "";
36     /* Show main page */
37     $smarty= get_smarty();
39     /* Load attributes */
40     foreach($this->attributes as $val){
41       $smarty->assign("$val", $this->$val);
42     }
45     $tmp = $this->plInfo();
46     $changeState = "";
47     foreach($tmp['plProvidedAcls'] as $key => $desc){
48       $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
49       $smarty->assign($key."_W", $this->acl_is_writeable($key,$this->ReadOnly));
50   
51       if($this->acl_is_writeable($key)){
52         $changeState.= " changeState('".$key."'); \n";
53       }
54     }
55     $smarty->assign("changeState",$changeState);
58     $smarty->assign("fstate", "");
59     if ($this->is_account){
60       $smarty->assign("pureftpdState", "checked");
61       $smarty->assign("fstate", "");
62     } else {
63       $smarty->assign("pureftpdState", "");
64       if($_SESSION['js']==1){
65         if($this->acl!="#none#")
66         $smarty->assign("fstate", "disabled");
67       }else{
68         $smarty->assign("fstate", "");
69       }
70     }
71     $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
72     
73     if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) ){
74       $smarty->assign('pureftpdACL', "");
75     }else{
76       $smarty->assign('pureftpdACL', " disabled ");
77     }
79     $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
80     return ($display);
81   }
83   function remove_from_parent()
84   {
85     /* Cancel if there's nothing to do here */
86     if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
87       return;
88     }
90     plugin::remove_from_parent();
91     $ldap= $this->config->get_ldap_link();
93     $ldap->cd($this->dn);
94     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
95         $this->attributes, "Save");
96     $this->cleanup();
97     $ldap->modify ($this->attrs); 
99     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/pureftpd account with dn '%s' failed."),$this->dn));
101     /* Optionally execute a command after we're done */
102     $this->handle_post_events('remove');
103   }
106   /* Save data to object */
107   function save_object()
108   {
109     /* Do we need to flip is_account state? */
110     if (isset($_POST['connectivityTab'])){
111       if (isset($_POST['pureftpd'])){
112         if (!$this->is_account && $_POST['pureftpd'] == "B"){
113           $this->is_account= TRUE;
114         }
115       } else {
116         $this->is_account= FALSE;
117       }
118     }
120     plugin::save_object();
122     $old= $this->FTPStatus;
123     if (isset($_POST["FTPStatus"])){
124       $this->FTPStatus = "disabled";
125     } else {
126       $this->FTPStatus = "enabled";
127     }
128     $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
129   }
132   /* Check values */
133   function check()
134   {
135     /* Call common method to give check the hook */
136     $message= plugin::check();
138     /* Check for positive integer values */
139     if ($this->is_account){
141       if($this->acl_is_writeable("FTPUploadBandwidth") && !is_id($this->FTPUploadBandwidth)){
142         $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
143       }
144       if($this->acl_is_writeable("FTPDownloadBandwidth") && !is_id($this->FTPDownloadBandwidth)){
145         $message[]= _("Value specified as 'Download bandwidth' is not valid.");
146       }
148       if($this->acl_is_writeable("FTPQuotaFiles") && !is_id($this->FTPQuotaFiles)){
149         $message[]= _("Value specified as 'Quota files' is not valid.");
150       }
151       if($this->acl_is_writeable("FTPQuotaMBytes") && !is_id($this->FTPQuotaMBytes)){
152         $message[]= _("Value specified as 'Quota size' is not valid.");
153       }
154       if($this->acl_is_writeable("FTPUploadRatio") && !is_id($this->FTPUploadRatio)){
155         $message[]= _("Value specified as 'Upload ratio' is not valid.");
156       }
157       if($this->acl_is_writeable("FTPDownloadRatio") && !is_id($this->FTPDownloadRatio)){
158         $message[]= _("Value specified as 'Download ratio' is not valid.");
159       }
160     }
162     return $message;
163   }
166   /* Save to LDAP */
167   function save()
168   {
169     plugin::save();
171     $tmp = $this->plInfo();
172     foreach($tmp['plProvidedAcls'] as $key => $desc){
173       if(!$this->acl_is_writeable($key)){
174         unset($this->attrs[$key]);
175       }
176     }
178     /* Write back to ldap */
179     $ldap= $this->config->get_ldap_link();
180     $ldap->cd($this->dn);
181     $this->cleanup();
182     $ldap->modify ($this->attrs); 
184     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/pureftpd account with dn '%s' failed."),$this->dn));
186     /* Optionally execute a command after we're done */
187     if ($this->initially_was_account == $this->is_account){
188       if ($this->is_modified){
189         $this->handle_post_events("mofify");
190       }
191     } else {
192       $this->handle_post_events("add");
193     }
195   }
198   /* Return plugin informations for acl handling
199   #FIME There possibly some attributes that can be combined to one acl. */
200   function plInfo()
201   {
202     return (array(
203           "plShortName"     => _("Ftp"),
204           "plDescription"   => _("Pure ftp account"),
205           "plSelfModify"    => TRUE,
206           "plDepends"       => array("user"),
207           "plPriority"      => 8,                                 // Position in tabs
208           "plSection"       => "personal",                        // This belongs to personal
209           "plCategory"      => array("users"),
210           "plOptions"       => array(),
212           "plProvidedAcls"  => array(
213             "FTPQuotaFiles"         => _("Quota files"),
214             "FTPUploadRatio"        => _("Upload ratio"),
215             "FTPQuotaMBytes"        => _("Quota MBytes"),
216             "FTPDownloadRatio"      => _("Download ratio"),
217             "FTPUploadBandwidth"    => _("Upload bandwith"),
218             "FTPDownloadBandwidth"  => _("Download bandwith"),
219             "FTPStatus"             => _("Status"))
220           ));
221   }
224 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
225 ?>