Code

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