Code

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