Code

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