Code

Updated macro class. Added check -> Empty macros can't be saved.
[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");
20   var $objectclasses= array("gosaProxyAccount");
21   var $ReadOnly = false;
23   var $uid = "";
25   function proxyAccount ($config, $dn= NULL)
26   {
27     plugin::plugin ($config, $dn);
28     
29     /* Setting uid to default */
30     if(isset($this->attrs['uid'][0])){
31       $this->uid = $this->attrs['uid'][0];
32     }
34   }
36   function execute()
37   {
38     /* Call parent execute */
39     plugin::execute();
41     $display= "";
43     /* Prepare templating */
44     $smarty= get_smarty();
46     $smarty->assign('proxyAccountACL', " disabled ");
47     
48     if((!$this->ReadOnly)&& (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))){
49       $smarty->assign('proxyAccountACL', "");
50     }
52     /* Assign radio boxes */
53     foreach (array("F", "T", "B", "N") as $val){
55       if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
56         $smarty->assign("filter$val", "checked");
58         /* Add state variables for on-the-fly state-changing of checkboxes */
59         $smarty->assign($val."state", "");
60         
61       } else {
62         $smarty->assign("filter$val", "");
64         /* Same as above */
65         if($_SESSION['js']==1){
66           $smarty->assign($val."state", "disabled");
67         }else{
68           $smarty->assign($val."state", "");
69         }
70       }
71     }
73     $tmp = $this->plInfo();
74     foreach($tmp['plProvidedAcls'] as $acl => $desc){
75       $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
76       $smarty->assign($acl."_W",$this->acl_is_writeable($acl,$this->ReadOnly));
77     }
79     /* Assign working time */
80     $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
81     $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
82     $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
83     $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
84     $hours= array();
85     for($i=0; $i<24; $i++){
86       $hours[]= sprintf("%02d",$i);
87     }
88     $smarty->assign("hours", $hours);
89     $smarty->assign("minutes", array("00","15","30","45"));
91     /* Assign quota values */
92     $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
93     $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
94     $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
95     $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
96     $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
97     if ($this->is_account){
98       $smarty->assign("proxyState", "checked");
99     } else {
100       $smarty->assign("proxyState", "");
101     }
103     /* Prepare correct state */
104     if (!$this->is_account){
105       $smarty->assign("pstate", "disabled");
106     } else {
107       $smarty->assign("pstate", "");
108     }
110     $changeA = "";
111   
112     $ProxyWorkingStateChange ="\n";
113     if($this->acl_is_writeable("gosaProxyFlagT")){
114       $changeA .= "changeState('filterT');\n";
116       $ProxyWorkingStateChange.=  "changeState('startHour'); \n";
117       $ProxyWorkingStateChange.=  "changeState('startMinute'); \n";
118       $ProxyWorkingStateChange.=  "changeState('stopHour'); \n";
119       $ProxyWorkingStateChange.=  "changeState('stopMinute'); \n";
120     }
122     if(preg_match("/F/",$this->gosaProxyAcctFlags)){
123       $changeA .= $ProxyWorkingStateChange;
124     }
125   
126     $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
128     $changeB = "";
129     if($this->acl_is_writeable("gosaProxyFlagB")){
130       $changeA .= "changeState('filterB');";
131       $changeB = 
132         "changeSubselectState('filterB', 'quota_size');
133          changeSubselectState('filterB', 'quota_unit');
134          changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
135     }
137     $smarty->assign("changeB",$changeB);
138     $smarty->assign("changeA",$changeA);
140     /* Show main page */
141     $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
142     return($display);
143   }
145   function remove_from_parent()
146   {
147     if($this->acl_is_removeable()){   
149       plugin::remove_from_parent();
151       $ldap= $this->config->get_ldap_link();
152       @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
153           $this->attributes, "Save");
154       $ldap->cd($this->dn);
155       $this->cleanup();
156       $ldap->modify ($this->attrs); 
158       show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/proxy account with dn '%s' failed."),$this->dn));
160       /* Optionally execute a command after we're done */
161       $this->handle_post_events("remove",array("uid" => $this->uid));
162     }
163   }
165   /* Check values */
166   function check()
167   {
168     /* Call common method to give check the hook */
169     $message= plugin::check();
170     
171     /* We've got only one value to check for positive integer or emtpy field */
172     if ($this->is_account){
173       if($this->acl_is_writeable("gosaProxyQuota")){
174         if (isset($_POST["quota_size"])){
175           if ($_POST["quota_size"] == "gosaProxyQuota"){
176             $message[]= _("Numerical value for Quota Setting is empty.");
177           }elseif ($_POST["quota_size"] <= 0){
178             $message[]= _("Numerical value for Quota Setting is not valid.");
179           }
180         }
181       }
182     }
184     return $message;
185   }
187   /* Save data to object */
188   function save_object()
189   {
190     /* Do we need to flip is_account state? */
191     if (isset($_POST['connectivityTab'])){
192       if (isset($_POST['proxy'])){
193         if (!$this->is_account && $_POST['proxy'] == "B"){
194           if($this->acl_is_createable()){
195             $this->is_account= TRUE;
196           }
197         }
198       } else {
199         if($this->acl_is_removeable()){
200           $this->is_account= FALSE;
201         }
202       }
203     }
205     /* Save flag value */
206     if ($this->is_account){
208       $flags= "";
209       $acl= "";
210       foreach(array("F", "T", "B") as $key){
211         if($this->acl_is_writeable("gosaProxyFlag".$key)){
212   
213           /* Add acl */
214           if (isset($_POST["filter$key"])){
215             $flags.= $key;
216           }
217         }else{
218           
219           /* Keep all flags that can't be written*/
220           if(preg_match("/".$key."/",$this->gosaProxyAcctFlags)){
221             $flags .=$key;
222           }
223         }
224       }
225       if ("[$flags]" != $this->gosaProxyAcctFlags){
226         $this->is_modified= TRUE;
227       }
228       $this->gosaProxyAcctFlags= "[$flags]";
230       /* Save time values */
231       if ($this->acl_is_writeable("gosaProxyFlagT")){
232         if(isset($_POST['startMinute'])){
233           $old= $this->gosaProxyWorkingStart;
234           $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
235           $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
236         }
238         if (isset($_POST['stopMinute'])){
239           $old= $this->gosaProxyWorkingStop;
240           $this->gosaProxyWorkingStop = $_POST["stopHour"]  * 60 + $_POST["stopMinute"];
241           $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
242         }
243       }
245       /* Save quota values */
246       if ($this->acl_is_writeable("gosaProxyFlagB")){
247         if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
248           $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
249         }
250       }
251   
252       /*Save quota period */
253       if($this->acl_is_writeable("gosaProxyFlagB")){
254         if(isset($_POST["gosaProxyQuotaPeriod"])){
255           $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
256         }
257       }
258     }
259   }
262   /* Save to LDAP */
263   function save()
264   {
265     plugin::save();
267     /* Write back to ldap */
268     $ldap= $this->config->get_ldap_link();
269     $ldap->cd($this->dn);
270     $this->cleanup();
271     $ldap->modify ($this->attrs); 
273     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/proxy account with dn '%s' failed."),$this->dn));
275     /* Optionally execute a command after we're done */
276     if ($this->initially_was_account == $this->is_account){
277       if ($this->is_modified){
278         $this->handle_post_events("modify",array("uid" => $this->uid));
279       }
280     } else {
281       $this->handle_post_events("add",array("uid" => $this->uid));
282     }
284   }
286   /* Return plugin informations for acl handling 
287       #FIME There possibly some attributes that can be combined to one acl. */
288   function plInfo()
289   {
290     return (array(
291           "plShortName"     => _("Proxy"),
292           "plDescription"   => _("Proxy account")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
293           "plSelfModify"    => TRUE,
294           "plDepends"       => array("user"),
295           "plPriority"      => 21,                                 // Position in tabs
296           "plSection"     => array("personal" => _("My account")),
297           "plCategory"    => array("users"),
298           "plOptions"       => array(),
300           "plProvidedAcls"  => array(
301             "gosaProxyFlagF"       => _("Filter unwanted content"), 
302             "gosaProxyFlagT"       => _("Limit proxy access"),
303             "gosaProxyFlagB"       => _("Restrict proxy usage by quota"))
304           ));
305   }
308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
309 ?>