Code

bc50bb78e2fd46cf397e996f61c151a5e2fa98ba
[gosa.git] / plugins / personal / connectivity / class_proxyAccount.inc
1 <?php
2 class proxyAccount extends plugin
3 {
4   /* Definitions */
5   var $plHeadline= "Proxy";
6   var $plDescription= "This does something";
8   /* CLI vars */
9   var $cli_summary= "Manage users proxy account";
10   var $cli_description= "Some longer text\nfor help";
11   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
13   /* Proxy attributes */
14   var $gosaProxyAcctFlags= "[N    ]";
15   var $gosaProxyID= "";
16   var $gosaProxyWorkingStart= 420;
17   var $gosaProxyWorkingStop= 1020;
18   var $gosaProxyQuota= "5g";
19   var $gosaProxyQuotaPeriod= "m";
21   /* attribute list for save action */
22   var $attributes= array("gosaProxyID", "gosaProxyAcctFlags", "gosaProxyWorkingStart",
23       "gosaProxyWorkingStop", "gosaProxyQuota", "gosaProxyQuotaPeriod");
24   var $objectclasses= array("gosaProxyAccount");
26   function proxyAccount ($config, $dn= NULL)
27   {
28     plugin::plugin ($config, $dn);
29   }
31   function execute()
32   {
33         /* Call parent execute */
34 //      plugin::execute();
36     $display= "";
38     /* Prepare templating */
39     $smarty= get_smarty();
40     $smarty->assign("proxyAccountACL",          chkacl($this->acl, "proxyAccount"));
41     $smarty->assign("gosaProxyAcctFlagsACL",    chkacl($this->acl, "gosaProxyAcctFlags"));
42     $smarty->assign("gosaProxyWorkingStartACL", chkacl($this->acl, "gosaProxyWorkingStart"));
43     $smarty->assign("gosaProxyWorkingStopACL",  chkacl($this->acl, "gosaProxyWorkingStop"));
44     $smarty->assign("gosaProxyQuotaACL",        chkacl($this->acl, "gosaProxyQuota"));
46     /* Assign radio boxes */
47     foreach (array("F", "T", "B", "N") as $val){
48       if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
49         $smarty->assign("filter$val", "checked");
51         /* Add state variables for on-the-fly state-changing of checkboxes */
52         $smarty->assign($val."state", "");
53         
54       } else {
55         $smarty->assign("filter$val", "");
57         /* Same as above */
58         if($_SESSION['js']==1){
59           $smarty->assign($val."state", "disabled");
60         }else{
61           $smarty->assign($val."state", "");
62         }
63       }
64     }
66     /* Assign working time */
67     $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
68     $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
69     $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
70     $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
71     $hours= array();
72     for($i=0; $i<24; $i++){
73       $hours[]= sprintf("%02d",$i);
74     }
75     $smarty->assign("hours", $hours);
76     $smarty->assign("minutes", array("00","15","30","45"));
78     /* Assign quota values */
79     $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
80     $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
81     $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
82     $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
83     $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
84     if ($this->is_account){
85       $smarty->assign("proxyState", "checked");
86     } else {
87       $smarty->assign("proxyState", "");
88     }
90     /* Prepare correct state */
91     if (!$this->is_account){
92       $smarty->assign("pstate", "disabled");
93     } else {
94       $smarty->assign("pstate", "");
95     }
97     $changeA = "";
98   
99     if(chkacl($this->acl,"gosaProxyAcctFlags")==""){
100       $changeA .="changeState('filterF');\n";
101     }
102     $smarty->assign("Working_allowedACL","disabled");
103     if((chkacl($this->acl,"gosaProxyWorkingStart")=="")||(chkacl($this->acl,"gosaProxyWorkingStop")=="")){
104       $smarty->assign("Working_allowedACL","");
105       $changeA .= "changeState('filterT');\n";
106     }
108     $ProxyWorkingStateChange ="";
109     if(chkacl($this->acl,"gosaProxyWorkingStart")==""){
110       $ProxyWorkingStateChange.=  "changeState('startHour');\n";
111       $ProxyWorkingStateChange.=  "changeState('startMinute');\n";
112     }
114     if(chkacl($this->acl,"gosaProxyWorkingStop")=="")  {
115       $ProxyWorkingStateChange.=  "changeState('stopHour');\n";
116       $ProxyWorkingStateChange.=  "changeState('stopMinute');\n";
117     }
118     
119     $changeA .= $ProxyWorkingStateChange;
120   
121     $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
123     $changeB = "";
124     if(chkacl($this->acl,"gosaProxyQuota")==""){
125       $changeA .= "changeState('filterB');";
126       $changeB = 
127         "changeSubselectState('filterB', 'quota_size');
128          changeSubselectState('filterB', 'quota_unit');
129          changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
130     }
132     $smarty->assign("changeB",$changeB);
133     $smarty->assign("changeA",$changeA);
135     /* Show main page */
136     $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
137     return($display);
138   }
140   function remove_from_parent()
141   {
142     /* Cancel if there's nothing to do here */
143     if (!$this->initially_was_account){
144       return;
145     }
146     
147     plugin::remove_from_parent();
149     $ldap= $this->config->get_ldap_link();
150     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
151         $this->attributes, "Save");
152     $ldap->cd($this->dn);
153     $ldap->modify($this->attrs);
154     show_ldap_error($ldap->get_error());
156     /* Optionally execute a command after we're done */
157     $this->handle_post_events("remove");
158   }
160   /* Check values */
161   function check()
162   {
163     $message= array();
164     
165     /* We've got only one value to check for positive integer or emtpy field */
166     if ($this->is_account){
167       if (isset($_POST["quota_size"])){
168         if ($_POST["quota_size"] == ""){
169           $message[]= _("Numerical value for Quota Setting is empty.");
170         }
171         else if ($_POST["quota_size"] <= 0){
172           $message[]= _("Numerical value for Quota Setting is not valid.");
173         }
174       }
175     }
177     return $message;
178   }
180   /* Save data to object */
181   function save_object()
182   {
183     /* Do we need to flip is_account state? */
184     if ($this->parent != NULL){
185       if (isset($_POST['connectivityTab'])){
186         if (isset($_POST['proxy'])){
187           if (!$this->is_account && $_POST['proxy'] == "B"){
188             $this->is_account= TRUE;
189           }
190         } else {
191           $this->is_account= FALSE;
192         }
193       }
194     }
196     if(isset($_POST['proxy'])){
197       $this->is_account = TRUE; 
198     }else{
199       $this->is_account = FALSE;
200     }
202     /* Save flag value */
203     if ($this->is_account){
204       if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
205         $flags= "";
206         foreach(array("F", "T", "B") as $key){
207           if (isset($_POST["filter$key"])){
208             $flags.= $key;
209           }
210         }
211         if ("[$flags]" != $this->gosaProxyAcctFlags){
212           $this->is_modified= TRUE;
213         }
214         $this->gosaProxyAcctFlags= "[$flags]";
215       }
217       /* Save time values */
218       if ((chkacl ($this->acl, "gosaProxyWorkingStart") == "")&&(isset($_POST['startMinute']))){
219         $old= $this->gosaProxyWorkingStart;
220         $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
221         $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
222       }
223       
224       if ((chkacl ($this->acl, "gosaProxyWorkingStop") == "")&&(isset($_POST['stopMinute']))){
225         $old= $this->gosaProxyWorkingStop;
226         $this->gosaProxyWorkingStop = $_POST["stopHour"]  * 60 + $_POST["stopMinute"];
227         $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
228       }
230       /* Save quota values */
231       if (chkacl ($this->acl, "gosaProxyQuota") == ""){
232         $old= $this->gosaProxyQuota;
233         if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
234           $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
235         }
236         $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
237         $old= $this->gosaProxyQuotaPeriod;
238         if(isset($_POST["gosaProxyQuotaPeriod"])){
239           $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
240         }
241         $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
242       }
243     }
245   }
248   /* Save to LDAP */
249   function save()
250   {
251     plugin::save();
253     /* Write back to ldap */
254     $ldap= $this->config->get_ldap_link();
255     $ldap->cd($this->dn);
256     $ldap->modify($this->attrs);
258     show_ldap_error($ldap->get_error());
260     /* Optionally execute a command after we're done */
261     if ($this->initially_was_account == $this->is_account){
262       if ($this->is_modified){
263         $this->handle_post_events("mofify");
264       }
265     } else {
266       $this->handle_post_events("add");
267     }
269   }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>