Code

Updated acls
[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   /* Proxy attributes */
9   var $gosaProxyAcctFlags= "[N    ]";
10   var $gosaProxyID= "";
11   var $gosaProxyWorkingStart= 420;
12   var $gosaProxyWorkingStop= 1020;
13   var $gosaProxyQuota= "5g";
14   var $gosaProxyQuotaPeriod= "m";
16   /* attribute list for save action */
17   var $attributes= array("gosaProxyID", "gosaProxyAcctFlags", "gosaProxyWorkingStart",
18       "gosaProxyWorkingStop", "gosaProxyQuota", "gosaProxyQuotaPeriod");
19   var $objectclasses= array("gosaProxyAccount");
21   function proxyAccount ($config, $dn= NULL)
22   {
23     plugin::plugin ($config, $dn);
24   }
26   function execute()
27   {
28         /* Call parent execute */
29 //      plugin::execute();
31     $display= "";
33     /* Prepare templating */
34     $smarty= get_smarty();
35     $smarty->assign("proxyAccountACL",          chkacl($this->acl, "proxyAccount"));
36     $smarty->assign("gosaProxyAcctFlagsACL",    chkacl($this->acl, "gosaProxyAcctFlags"));
37     $smarty->assign("gosaProxyWorkingStartACL", chkacl($this->acl, "gosaProxyWorkingStart"));
38     $smarty->assign("gosaProxyWorkingStopACL",  chkacl($this->acl, "gosaProxyWorkingStop"));
39     $smarty->assign("gosaProxyQuotaACL",        chkacl($this->acl, "gosaProxyQuota"));
41     /* Assign radio boxes */
42     foreach (array("F", "T", "B", "N") as $val){
43       if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
44         $smarty->assign("filter$val", "checked");
46         /* Add state variables for on-the-fly state-changing of checkboxes */
47         $smarty->assign($val."state", "");
48         
49       } else {
50         $smarty->assign("filter$val", "");
52         /* Same as above */
53         if($_SESSION['js']==1){
54           $smarty->assign($val."state", "disabled");
55         }else{
56           $smarty->assign($val."state", "");
57         }
58       }
59     }
61     /* Assign working time */
62     $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
63     $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
64     $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
65     $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
66     $hours= array();
67     for($i=0; $i<24; $i++){
68       $hours[]= sprintf("%02d",$i);
69     }
70     $smarty->assign("hours", $hours);
71     $smarty->assign("minutes", array("00","15","30","45"));
73     /* Assign quota values */
74     $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
75     $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
76     $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
77     $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
78     $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
79     if ($this->is_account){
80       $smarty->assign("proxyState", "checked");
81     } else {
82       $smarty->assign("proxyState", "");
83     }
85     /* Prepare correct state */
86     if (!$this->is_account){
87       $smarty->assign("pstate", "disabled");
88     } else {
89       $smarty->assign("pstate", "");
90     }
92     $changeA = "";
93   
94     if(chkacl($this->acl,"gosaProxyAcctFlags")==""){
95       $changeA .="changeState('filterF');\n";
96     }
97     $smarty->assign("Working_allowedACL","disabled");
98     if((chkacl($this->acl,"gosaProxyWorkingStart")=="")||(chkacl($this->acl,"gosaProxyWorkingStop")=="")){
99       $smarty->assign("Working_allowedACL","");
100       $changeA .= "changeState('filterT');\n";
101     }
103     $ProxyWorkingStateChange ="";
104     if(chkacl($this->acl,"gosaProxyWorkingStart")==""){
105       $ProxyWorkingStateChange.=  "changeState('startHour');\n";
106       $ProxyWorkingStateChange.=  "changeState('startMinute');\n";
107     }
109     if(chkacl($this->acl,"gosaProxyWorkingStop")=="")  {
110       $ProxyWorkingStateChange.=  "changeState('stopHour');\n";
111       $ProxyWorkingStateChange.=  "changeState('stopMinute');\n";
112     }
113     
114     $changeA .= $ProxyWorkingStateChange;
115   
116     $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
118     $changeB = "";
119     if(chkacl($this->acl,"gosaProxyQuota")==""){
120       $changeA .= "changeState('filterB');";
121       $changeB = 
122         "changeSubselectState('filterB', 'quota_size');
123          changeSubselectState('filterB', 'quota_unit');
124          changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
125     }
127     $smarty->assign("changeB",$changeB);
128     $smarty->assign("changeA",$changeA);
130     /* Show main page */
131     $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
132     return($display);
133   }
135   function remove_from_parent()
136   {
137     /* Cancel if there's nothing to do here */
138     if (!$this->initially_was_account){
139       return;
140     }
141     
142     plugin::remove_from_parent();
144     $ldap= $this->config->get_ldap_link();
145     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
146         $this->attributes, "Save");
147     $ldap->cd($this->dn);
148     $this->cleanup();
149     $ldap->modify ($this->attrs); 
151     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/proxy account with dn '%s' failed."),$this->dn));
153     /* Optionally execute a command after we're done */
154     $this->handle_post_events("remove");
155   }
157   /* Check values */
158   function check()
159   {
160     /* Call common method to give check the hook */
161     $message= plugin::check();
162     
163     /* We've got only one value to check for positive integer or emtpy field */
164     if ($this->is_account){
165       if (isset($_POST["quota_size"])){
166         if ($_POST["quota_size"] == ""){
167           $message[]= _("Numerical value for Quota Setting is empty.");
168         }
169         else if ($_POST["quota_size"] <= 0){
170           $message[]= _("Numerical value for Quota Setting is not valid.");
171         }
172       }
173     }
175     return $message;
176   }
178   /* Save data to object */
179   function save_object()
180   {
181     /* Do we need to flip is_account state? */
182     if ($this->parent != NULL){
183       if (isset($_POST['connectivityTab'])){
184         if (isset($_POST['proxy'])){
185           if (!$this->is_account && $_POST['proxy'] == "B"){
186             $this->is_account= TRUE;
187           }
188         } else {
189           $this->is_account= FALSE;
190         }
191       }
192     }
194     if(isset($_POST['proxy'])){
195       $this->is_account = TRUE; 
196     }else{
197       $this->is_account = FALSE;
198     }
200     /* Save flag value */
201     if ($this->is_account){
202       if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
203         $flags= "";
204         foreach(array("F", "T", "B") as $key){
205           if (isset($_POST["filter$key"])){
206             $flags.= $key;
207           }
208         }
209         if ("[$flags]" != $this->gosaProxyAcctFlags){
210           $this->is_modified= TRUE;
211         }
212         $this->gosaProxyAcctFlags= "[$flags]";
213       }
215       /* Save time values */
216       if ((chkacl ($this->acl, "gosaProxyWorkingStart") == "")&&(isset($_POST['startMinute']))){
217         $old= $this->gosaProxyWorkingStart;
218         $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
219         $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
220       }
221       
222       if ((chkacl ($this->acl, "gosaProxyWorkingStop") == "")&&(isset($_POST['stopMinute']))){
223         $old= $this->gosaProxyWorkingStop;
224         $this->gosaProxyWorkingStop = $_POST["stopHour"]  * 60 + $_POST["stopMinute"];
225         $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
226       }
228       /* Save quota values */
229       if (chkacl ($this->acl, "gosaProxyQuota") == ""){
230         $old= $this->gosaProxyQuota;
231         if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
232           $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
233         }
234         $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
235         $old= $this->gosaProxyQuotaPeriod;
236         if(isset($_POST["gosaProxyQuotaPeriod"])){
237           $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
238         }
239         $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
240       }
241     }
243   }
246   /* Save to LDAP */
247   function save()
248   {
249     plugin::save();
251     /* Write back to ldap */
252     $ldap= $this->config->get_ldap_link();
253     $ldap->cd($this->dn);
254     $this->cleanup();
255     $ldap->modify ($this->attrs); 
257     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/proxy account with dn '%s' failed."),$this->dn));
259     /* Optionally execute a command after we're done */
260     if ($this->initially_was_account == $this->is_account){
261       if ($this->is_modified){
262         $this->handle_post_events("mofify");
263       }
264     } else {
265       $this->handle_post_events("add");
266     }
268   }
270   /* Return plugin informations for acl handling 
271       #FIME There possibly some attributes that can be combined to one acl. */
272   function plInfo()
273   {
274     return (array(  "plDescription"   => _("Intranet account settings"),
275           "plSelfModify"    => TRUE,
276           "plDepends"       => array("objectClass" => "gosaAccount"),
278           "gosaProxyID"           => "!!! FIXME "._("gosaProxyID"),
279     
280           "gosaProxyFlag_F"   => _("Filter unwanted content"), 
281           "gosaProxyFlag_T"   => _("Limit proxy access"),
282           "gosaProxyFlag_B"   => _("Restrict proxy usage by quota"),
284           "gosaProxyWorkingTime"  => _("Limit proxy access"),
285           "gosaProxyQuota"        => _("Limit quota"),
286           "gosaProxyQuotaPeriod"  => _("Quota limit period")));
287   }
292 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
293 ?>