Code

1e5f7457f9658038f591a2d4aa352a78a3bedd55
[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   /* CLI vars */
10   var $cli_summary= "Manage users ftp account";
11   var $cli_description= "Some longer text\nfor help";
12   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
14   /* FTP attributes */
15   var $FTPQuotaFiles = 0;
16   var $FTPQuotaMBytes = 0;
17   var $FTPUploadRatio = 0;
18   var $FTPDownloadRatio = 0;
19   var $FTPUploadBandwidth = 0;
20   var $FTPDownloadBandwidth = 0;
21   var $FTPStatus = "enabled";
22   var $FTPuid = "";
23   var $FTPgid = "";
25   /* attribute list for save action */
26   var $attributes= array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
27       "FTPUploadBandwidth","FTPDownloadBandwidth","FTPStatus","FTPuid","FTPgid");
28   var $objectclasses= array("PureFTPdUser");
30   function pureftpdAccount ($config, $dn= NULL)
31   {
32     plugin::plugin ($config, $dn);
33   }
35   function execute()
36   {
37         /* Call parent execute */
38 //      plugin::execute();
40     /* Show tab dialog headers */
41     $display= "";
43     /* Show main page */
44     $smarty= get_smarty();
46     /* Load attributes */
47     foreach($this->attributes as $val){
48       $smarty->assign("$val", $this->$val);
49       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
50     }
51     if ($this->is_account){
52       $smarty->assign("pureftpdState", "checked");
53       $smarty->assign("fstate", "");
54     } else {
55       $smarty->assign("pureftpdState", "");
56       if($_SESSION['js']==1){
57         $smarty->assign("fstate", "disabled");
58       }else{
59         $smarty->assign("fstate", "");
60       }
61     }
62     $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
64     $smarty->assign("pureftpdACL", chkacl($this->acl, 'pureftpd'));
66     $changeState = "";
67     foreach($this->attributes as $attr){
68       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
69       if(chkacl($this->acl,$attr)==""){
70         $changeState .= "changeState('".$attr."');\n";
71       }
72     }
73     $smarty->assign("changeState",$changeState);
74     $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
75     return ($display);
76   }
78   function remove_from_parent()
79   {
80     /* Cancel if there's nothing to do here */
81     if (!$this->initially_was_account){
82       return;
83     }
85     plugin::remove_from_parent();
86     $ldap= $this->config->get_ldap_link();
88     $ldap->cd($this->dn);
89     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
90         $this->attributes, "Save");
91     $ldap->modify($this->attrs);
92     show_ldap_error($ldap->get_error());
94     /* Optionally execute a command after we're done */
95     $this->handle_post_events('remove');
96   }
99   /* Save data to object */
100   function save_object()
101   {
102     /* Do we need to flip is_account state? */
103     if (isset($_POST['connectivityTab'])){
104       if (isset($_POST['pureftpd'])){
105         if (!$this->is_account && $_POST['pureftpd'] == "B"){
106           $this->is_account= TRUE;
107         }
108       } else {
109         $this->is_account= FALSE;
110       }
111     }
113     plugin::save_object();
115     $old= $this->FTPStatus;
116     if (isset($_POST["FTPStatus"])){
117       $this->FTPStatus = "disabled";
118     } else {
119       $this->FTPStatus = "enabled";
120     }
121     $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
122   }
125   /* Check values */
126   function check()
127   {
128     $message= array();
130     /* Check for positive integer values */
131     if ($this->is_account){
132       if ((!is_id($this->FTPUploadBandwidth))&&(chkacl($this->acl,"FTPUploadBandwidth")=="")){
133         $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
134       }
135       if ((!is_id($this->FTPDownloadBandwidth))&&(chkacl($this->acl,"FTPDownloadBandwidth")=="")){
136         $message[]= _("Value specified as 'Download bandwidth' is not valid.");
137       }
138       if ((!is_id($this->FTPQuotaFiles))&&(chkacl($this->acl,"FTPQuotaFiles")=="")){
139         $message[]= _("Value specified as 'Files' is not valid.");
140       }
141       if ((!is_id($this->FTPQuotaMBytes))&&(chkacl($this->acl,"FTPQuotaMBytes")=="")){
142         $message[]= _("Value specified as 'Size' is not valid.");
143       }
144       if ((!is_id($this->FTPUploadRatio) || !is_id($this->FTPDownloadRatio))&&(chkacl($this->acl,"FTPUploadRatio")=="")&&(chkacl($this->acl,"FTPDownloadRatio")=="")){
145         $message[]= _("Value specified as 'Ratio' is not valid.");
146       }
147     }
149     return $message;
150   }
153   /* Save to LDAP */
154   function save()
155   {
156     plugin::save();
158     foreach($this->attributes as $attr){
159       if(chkacl($this->acl,$attr)!=""){
160         unset($this->attrs[$attr]);
161       }
162     }
164     /* Write back to ldap */
165     $ldap= $this->config->get_ldap_link();
166     $ldap->cd($this->dn);
167     $ldap->modify($this->attrs);
168     show_ldap_error($ldap->get_error());
170     /* Optionally execute a command after we're done */
171     if ($this->initially_was_account == $this->is_account){
172       if ($this->is_modified){
173         $this->handle_post_events("mofify");
174       }
175     } else {
176       $this->handle_post_events("add");
177     }
179   }
183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
184 ?>