Code

Added some acls to connectivity addons
[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     $this->cleanup();
154     $ldap->modify ($this->attrs); 
156     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/proxy account with dn '%s' failed."),$this->dn));
158     /* Optionally execute a command after we're done */
159     $this->handle_post_events("remove");
160   }
162   /* Check values */
163   function check()
164   {
165     /* Call common method to give check the hook */
166     $message= plugin::check();
167     
168     /* We've got only one value to check for positive integer or emtpy field */
169     if ($this->is_account){
170       if (isset($_POST["quota_size"])){
171         if ($_POST["quota_size"] == ""){
172           $message[]= _("Numerical value for Quota Setting is empty.");
173         }
174         else if ($_POST["quota_size"] <= 0){
175           $message[]= _("Numerical value for Quota Setting is not valid.");
176         }
177       }
178     }
180     return $message;
181   }
183   /* Save data to object */
184   function save_object()
185   {
186     /* Do we need to flip is_account state? */
187     if ($this->parent != NULL){
188       if (isset($_POST['connectivityTab'])){
189         if (isset($_POST['proxy'])){
190           if (!$this->is_account && $_POST['proxy'] == "B"){
191             $this->is_account= TRUE;
192           }
193         } else {
194           $this->is_account= FALSE;
195         }
196       }
197     }
199     if(isset($_POST['proxy'])){
200       $this->is_account = TRUE; 
201     }else{
202       $this->is_account = FALSE;
203     }
205     /* Save flag value */
206     if ($this->is_account){
207       if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
208         $flags= "";
209         foreach(array("F", "T", "B") as $key){
210           if (isset($_POST["filter$key"])){
211             $flags.= $key;
212           }
213         }
214         if ("[$flags]" != $this->gosaProxyAcctFlags){
215           $this->is_modified= TRUE;
216         }
217         $this->gosaProxyAcctFlags= "[$flags]";
218       }
220       /* Save time values */
221       if ((chkacl ($this->acl, "gosaProxyWorkingStart") == "")&&(isset($_POST['startMinute']))){
222         $old= $this->gosaProxyWorkingStart;
223         $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
224         $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
225       }
226       
227       if ((chkacl ($this->acl, "gosaProxyWorkingStop") == "")&&(isset($_POST['stopMinute']))){
228         $old= $this->gosaProxyWorkingStop;
229         $this->gosaProxyWorkingStop = $_POST["stopHour"]  * 60 + $_POST["stopMinute"];
230         $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
231       }
233       /* Save quota values */
234       if (chkacl ($this->acl, "gosaProxyQuota") == ""){
235         $old= $this->gosaProxyQuota;
236         if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
237           $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
238         }
239         $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
240         $old= $this->gosaProxyQuotaPeriod;
241         if(isset($_POST["gosaProxyQuotaPeriod"])){
242           $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
243         }
244         $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
245       }
246     }
248   }
251   /* Save to LDAP */
252   function save()
253   {
254     plugin::save();
256     /* Write back to ldap */
257     $ldap= $this->config->get_ldap_link();
258     $ldap->cd($this->dn);
259     $this->cleanup();
260     $ldap->modify ($this->attrs); 
262     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/proxy account with dn '%s' failed."),$this->dn));
264     /* Optionally execute a command after we're done */
265     if ($this->initially_was_account == $this->is_account){
266       if ($this->is_modified){
267         $this->handle_post_events("mofify");
268       }
269     } else {
270       $this->handle_post_events("add");
271     }
273   }
276   function plInfo()
277   {
278     return (array(  "plDescription"   => _("Intranet account settings"),
279           "plSelfModify"    => TRUE,
280           "plDepends"       => array("objectClass" => "gosaAccount"),
282           "gosaProxyID"           => _("gosaProxyID"),
283     
284           "gosaProxyFlag_F"   => _("Filter unwanted content"), 
285           "gosaProxyFlag_T"   => _("Limit proxy access"),
286           "gosaProxyFlag_B"   => _("Restrict proxy usage by quota"),
288           "gosaProxyWorkingTime"  => _("Limit proxy access"),
289           "gosaProxyQuota"        => _("Limit quota"),
290           "gosaProxyQuotaPeriod"  => _("Quota limit period")));
291   }
296 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
297 ?>