Code

Proxy Options (filter and quota) are now disabled, if assigned checkbox state is...
[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     $display= "";
35     /* Prepare templating */
36     $smarty= get_smarty();
37     $smarty->assign("gosaProxyAcctFlagsACL", chkacl($this->acl, "gosaProxyAcctFlags"));
38     $smarty->assign("gosaProxyWorkingStartACL", chkacl($this->acl, "gosaProxyWorkingStart"));
39     $smarty->assign("gosaProxyWorkingStopACL", chkacl($this->acl, "gosaProxyWorkingStop"));
40     $smarty->assign("gosaProxyQuotaACL", chkacl($this->acl, "gosaProxyQuota"));
42     /* Show checkbox? */
43     if ($this->parent != NULL){
44       $smarty->assign("tabbed", "1");
45     }
47     /* Assign radio boxes */
48     foreach (array("F", "T", "B", "N") as $val){
49       if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
50         $smarty->assign("filter$val", "checked");
51         $smarty->assign($val."state", "");
52       } else {
53         $smarty->assign("filter$val", "");
54         $smarty->assign($val."state", "disabled");
55       }
56     }
58     /* Assign working time */
59     $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
60     $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
61     $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
62     $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
63     $hours= array();
64     for($i=0; $i<24; $i++){
65       $hours[]= sprintf("%02d",$i);
66     }
67     $smarty->assign("hours", $hours);
68     $smarty->assign("minutes", array("00","15","30","45"));
70     /* Assign quota values */
71     $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
72     $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
73     $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
74     $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
75     $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
76     if ($this->is_account){
77       $smarty->assign("proxyState", "checked");
78     } else {
79       $smarty->assign("proxyState", "");
80     }
82     /* Prepare correct state */
83     if (!$this->is_account){
84       $smarty->assign("pstate", "disabled");
85     } else {
86       $smarty->assign("pstate", "");
87     }
89     /* Show main page */
90     $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
91     return($display);
92   }
94   function remove_from_parent()
95   {
96     /* Cancel if there's nothing to do here */
97     if (!$this->initially_was_account){
98       return;
99     }
100     
101     plugin::remove_from_parent();
103     $ldap= $this->config->get_ldap_link();
104     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
105         $this->attributes, "Save");
106     $ldap->cd($this->dn);
107     $ldap->modify($this->attrs);
108     show_ldap_error($ldap->get_error());
110     /* Optionally execute a command after we're done */
111     $this->handle_post_events("remove");
112   }
115   /* Save data to object */
116   function save_object()
117   {
118     /* Do we need to flip is_account state? */
119     if ($this->parent != NULL){
120       if (isset($_POST['connectivityTab'])){
121         if (isset($_POST['proxy'])){
122           if (!$this->is_account && $_POST['proxy'] == "B"){
123             $this->is_account= TRUE;
124           }
125         } else {
126           $this->is_account= FALSE;
127         }
128       }
129     }
131     /* Save flag value */
132     if ($this->is_account){
133       if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
134         $flags= "";
135         foreach(array("F", "T", "B") as $key){
136           if (isset($_POST["filter$key"])){
137             $flags.= $key;
138           }
139         }
140         if ("[$flags]" != $this->gosaProxyAcctFlags){
141           $this->is_modified= TRUE;
142         }
143         $this->gosaProxyAcctFlags= "[$flags]";
144       }
146       /* Save time values */
147       if (chkacl ($this->acl, "gosaProxyWorkingTime") == "" && isset($_POST['startMinute'])){
148         $old= $this->gosaProxyWorkingStart;
149         $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
150         $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
151         $old= $this->gosaProxyWorkingStop;
152         $this->gosaProxyWorkingStop = $_POST["stopHour"]  * 60 + $_POST["stopMinute"];
153         $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
154       }
156       /* Save quota values */
157       if (chkacl ($this->acl, "gosaProxyQuota") == ""){
158         $old= $this->gosaProxyQuota;
159         if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
160           $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
161         }
162         $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
163         $old= $this->gosaProxyQuotaPeriod;
164         if(isset($_POST["gosaProxyQuotaPeriod"])){
165           $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
166         }
167         $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
168       }
169     }
171   }
174   /* Save to LDAP */
175   function save()
176   {
177     plugin::save();
179     /* Write back to ldap */
180     $ldap= $this->config->get_ldap_link();
181     $ldap->cd($this->dn);
182     $ldap->modify($this->attrs);
184     show_ldap_error($ldap->get_error());
186     /* Optionally execute a command after we're done */
187     if ($this->initially_was_account == $this->is_account){
188       if ($this->is_modified){
189         $this->handle_post_events("mofify");
190       }
191     } else {
192       $this->handle_post_events("add");
193     }
195   }
199 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
200 ?>