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 /* Call parent execute */
34 // plugin::execute();
36 $display= "";
38 /* Prepare templating */
39 $smarty= get_smarty();
40 $smarty->assign("proxyAccountACL", chkacl($this->acl, "proxyAccount"));
41 $smarty->assign("gosaProxyAcctFlagsACL", chkacl($this->acl, "gosaProxyAcctFlags"));
42 $smarty->assign("gosaProxyWorkingStartACL", chkacl($this->acl, "gosaProxyWorkingStart"));
43 $smarty->assign("gosaProxyWorkingStopACL", chkacl($this->acl, "gosaProxyWorkingStop"));
44 $smarty->assign("gosaProxyQuotaACL", chkacl($this->acl, "gosaProxyQuota"));
46 /* Show checkbox? */
47 if ($this->parent != NULL){
48 $smarty->assign("tabbed", "1");
49 } else {
50 $smarty->assign("tabbed", "0");
51 }
53 /* Assign radio boxes */
54 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", "");
61 } else {
62 $smarty->assign("filter$val", "");
64 /* Same as above */
65 $smarty->assign($val."state", "disabled");
66 }
67 }
69 /* Assign working time */
70 $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
71 $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
72 $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
73 $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
74 $hours= array();
75 for($i=0; $i<24; $i++){
76 $hours[]= sprintf("%02d",$i);
77 }
78 $smarty->assign("hours", $hours);
79 $smarty->assign("minutes", array("00","15","30","45"));
81 /* Assign quota values */
82 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
83 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
84 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
85 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
86 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
87 if ($this->is_account){
88 $smarty->assign("proxyState", "checked");
89 } else {
90 $smarty->assign("proxyState", "");
91 }
93 /* Prepare correct state */
94 if (!$this->is_account){
95 $smarty->assign("pstate", "disabled");
96 } else {
97 $smarty->assign("pstate", "");
98 }
100 $changeA = "";
102 if(chkacl($this->acl,"gosaProxyAcctFlags")==""){
103 $changeA .="changeState('filterF');\n";
104 }
105 $smarty->assign("Working_allowedACL","disabled");
106 if((chkacl($this->acl,"gosaProxyWorkingStart")=="")||(chkacl($this->acl,"gosaProxyWorkingStop")=="")){
107 $smarty->assign("Working_allowedACL","");
108 $changeA .= "changeState('filterT');\n";
109 }
111 $ProxyWorkingStateChange ="";
112 if(chkacl($this->acl,"gosaProxyWorkingStart")==""){
113 $ProxyWorkingStateChange.= "changeState('startHour');\n";
114 $ProxyWorkingStateChange.= "changeState('startMinute');\n";
115 }
117 if(chkacl($this->acl,"gosaProxyWorkingStop")=="") {
118 $ProxyWorkingStateChange.= "changeState('stopHour');\n";
119 $ProxyWorkingStateChange.= "changeState('stopMinute');\n";
120 }
122 $changeA .= $ProxyWorkingStateChange;
124 $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
126 $changeB = "";
127 if(chkacl($this->acl,"gosaProxyQuota")==""){
128 $changeA .= "changeState('filterB');";
129 $changeB =
130 "changeSubselectState('filterB', 'quota_size');
131 changeSubselectState('filterB', 'quota_unit');
132 changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
133 }
135 $smarty->assign("changeB",$changeB);
136 $smarty->assign("changeA",$changeA);
138 /* Show main page */
139 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
140 return($display);
141 }
143 function remove_from_parent()
144 {
145 /* Cancel if there's nothing to do here */
146 if (!$this->initially_was_account){
147 return;
148 }
150 plugin::remove_from_parent();
152 $ldap= $this->config->get_ldap_link();
153 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
154 $this->attributes, "Save");
155 $ldap->cd($this->dn);
156 $ldap->modify($this->attrs);
157 show_ldap_error($ldap->get_error());
159 /* Optionally execute a command after we're done */
160 $this->handle_post_events("remove");
161 }
163 /* Check values */
164 function check()
165 {
166 $message= array();
168 /* We've got only one value to check for positive integer or emtpy field */
169 if ($this->is_account){
170 if (isset($_POST["quota_size"])){
171 if ($_POST["quota_size"] == ""){
172 $message[]= _("Numerical value for Quota Setting is empty.");
173 }
174 else if ($_POST["quota_size"] <= 0){
175 $message[]= _("Numerical value for Quota Setting is not valid.");
176 }
177 }
178 }
180 return $message;
181 }
183 /* Save data to object */
184 function save_object()
185 {
186 /* Do we need to flip is_account state? */
187 if ($this->parent != NULL){
188 if (isset($_POST['connectivityTab'])){
189 if (isset($_POST['proxy'])){
190 if (!$this->is_account && $_POST['proxy'] == "B"){
191 $this->is_account= TRUE;
192 }
193 } else {
194 $this->is_account= FALSE;
195 }
196 }
197 }
199 /* Save flag value */
200 if ($this->is_account){
201 if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
202 $flags= "";
203 foreach(array("F", "T", "B") as $key){
204 if (isset($_POST["filter$key"])){
205 $flags.= $key;
206 }
207 }
208 if ("[$flags]" != $this->gosaProxyAcctFlags){
209 $this->is_modified= TRUE;
210 }
211 $this->gosaProxyAcctFlags= "[$flags]";
212 }
214 /* Save time values */
215 if ((chkacl ($this->acl, "gosaProxyWorkingStart") == "")&&(isset($_POST['startMinute']))){
216 $old= $this->gosaProxyWorkingStart;
217 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
218 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
219 }
221 if ((chkacl ($this->acl, "gosaProxyWorkingStop") == "")&&(isset($_POST['stopMinute']))){
222 $old= $this->gosaProxyWorkingStop;
223 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
224 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
225 }
227 /* Save quota values */
228 if (chkacl ($this->acl, "gosaProxyQuota") == ""){
229 $old= $this->gosaProxyQuota;
230 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
231 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
232 }
233 $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
234 $old= $this->gosaProxyQuotaPeriod;
235 if(isset($_POST["gosaProxyQuotaPeriod"])){
236 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
237 }
238 $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
239 }
240 }
242 }
245 /* Save to LDAP */
246 function save()
247 {
248 plugin::save();
250 /* Write back to ldap */
251 $ldap= $this->config->get_ldap_link();
252 $ldap->cd($this->dn);
253 $ldap->modify($this->attrs);
255 show_ldap_error($ldap->get_error());
257 /* Optionally execute a command after we're done */
258 if ($this->initially_was_account == $this->is_account){
259 if ($this->is_modified){
260 $this->handle_post_events("mofify");
261 }
262 } else {
263 $this->handle_post_events("add");
264 }
266 }
268 }
270 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
271 ?>