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 /* Assign radio boxes */
47 foreach (array("F", "T", "B", "N") as $val){
48 if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
49 $smarty->assign("filter$val", "checked");
51 /* Add state variables for on-the-fly state-changing of checkboxes */
52 $smarty->assign($val."state", "");
54 } else {
55 $smarty->assign("filter$val", "");
57 /* Same as above */
58 if($_SESSION['js']==1){
59 $smarty->assign($val."state", "disabled");
60 }else{
61 $smarty->assign($val."state", "");
62 }
63 }
64 }
66 /* Assign working time */
67 $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
68 $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
69 $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
70 $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
71 $hours= array();
72 for($i=0; $i<24; $i++){
73 $hours[]= sprintf("%02d",$i);
74 }
75 $smarty->assign("hours", $hours);
76 $smarty->assign("minutes", array("00","15","30","45"));
78 /* Assign quota values */
79 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
80 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
81 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
82 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
83 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
84 if ($this->is_account){
85 $smarty->assign("proxyState", "checked");
86 } else {
87 $smarty->assign("proxyState", "");
88 }
90 /* Prepare correct state */
91 if (!$this->is_account){
92 $smarty->assign("pstate", "disabled");
93 } else {
94 $smarty->assign("pstate", "");
95 }
97 $changeA = "";
99 if(chkacl($this->acl,"gosaProxyAcctFlags")==""){
100 $changeA .="changeState('filterF');\n";
101 }
102 $smarty->assign("Working_allowedACL","disabled");
103 if((chkacl($this->acl,"gosaProxyWorkingStart")=="")||(chkacl($this->acl,"gosaProxyWorkingStop")=="")){
104 $smarty->assign("Working_allowedACL","");
105 $changeA .= "changeState('filterT');\n";
106 }
108 $ProxyWorkingStateChange ="";
109 if(chkacl($this->acl,"gosaProxyWorkingStart")==""){
110 $ProxyWorkingStateChange.= "changeState('startHour');\n";
111 $ProxyWorkingStateChange.= "changeState('startMinute');\n";
112 }
114 if(chkacl($this->acl,"gosaProxyWorkingStop")=="") {
115 $ProxyWorkingStateChange.= "changeState('stopHour');\n";
116 $ProxyWorkingStateChange.= "changeState('stopMinute');\n";
117 }
119 $changeA .= $ProxyWorkingStateChange;
121 $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
123 $changeB = "";
124 if(chkacl($this->acl,"gosaProxyQuota")==""){
125 $changeA .= "changeState('filterB');";
126 $changeB =
127 "changeSubselectState('filterB', 'quota_size');
128 changeSubselectState('filterB', 'quota_unit');
129 changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
130 }
132 $smarty->assign("changeB",$changeB);
133 $smarty->assign("changeA",$changeA);
135 /* Show main page */
136 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
137 return($display);
138 }
140 function remove_from_parent()
141 {
142 /* Cancel if there's nothing to do here */
143 if (!$this->initially_was_account){
144 return;
145 }
147 plugin::remove_from_parent();
149 $ldap= $this->config->get_ldap_link();
150 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
151 $this->attributes, "Save");
152 $ldap->cd($this->dn);
153 $this->cleanup();
154 $ldap->modify ($this->attrs);
156 show_ldap_error($ldap->get_error());
158 /* Optionally execute a command after we're done */
159 $this->handle_post_events("remove");
160 }
162 /* Check values */
163 function check()
164 {
165 $message= array();
167 /* We've got only one value to check for positive integer or emtpy field */
168 if ($this->is_account){
169 if (isset($_POST["quota_size"])){
170 if ($_POST["quota_size"] == ""){
171 $message[]= _("Numerical value for Quota Setting is empty.");
172 }
173 else if ($_POST["quota_size"] <= 0){
174 $message[]= _("Numerical value for Quota Setting is not valid.");
175 }
176 }
177 }
179 return $message;
180 }
182 /* Save data to object */
183 function save_object()
184 {
185 /* Do we need to flip is_account state? */
186 if ($this->parent != NULL){
187 if (isset($_POST['connectivityTab'])){
188 if (isset($_POST['proxy'])){
189 if (!$this->is_account && $_POST['proxy'] == "B"){
190 $this->is_account= TRUE;
191 }
192 } else {
193 $this->is_account= FALSE;
194 }
195 }
196 }
198 if(isset($_POST['proxy'])){
199 $this->is_account = TRUE;
200 }else{
201 $this->is_account = FALSE;
202 }
204 /* Save flag value */
205 if ($this->is_account){
206 if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
207 $flags= "";
208 foreach(array("F", "T", "B") as $key){
209 if (isset($_POST["filter$key"])){
210 $flags.= $key;
211 }
212 }
213 if ("[$flags]" != $this->gosaProxyAcctFlags){
214 $this->is_modified= TRUE;
215 }
216 $this->gosaProxyAcctFlags= "[$flags]";
217 }
219 /* Save time values */
220 if ((chkacl ($this->acl, "gosaProxyWorkingStart") == "")&&(isset($_POST['startMinute']))){
221 $old= $this->gosaProxyWorkingStart;
222 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
223 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
224 }
226 if ((chkacl ($this->acl, "gosaProxyWorkingStop") == "")&&(isset($_POST['stopMinute']))){
227 $old= $this->gosaProxyWorkingStop;
228 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
229 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
230 }
232 /* Save quota values */
233 if (chkacl ($this->acl, "gosaProxyQuota") == ""){
234 $old= $this->gosaProxyQuota;
235 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
236 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
237 }
238 $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
239 $old= $this->gosaProxyQuotaPeriod;
240 if(isset($_POST["gosaProxyQuotaPeriod"])){
241 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
242 }
243 $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
244 }
245 }
247 }
250 /* Save to LDAP */
251 function save()
252 {
253 plugin::save();
255 /* Write back to ldap */
256 $ldap= $this->config->get_ldap_link();
257 $ldap->cd($this->dn);
258 $this->cleanup();
259 $ldap->modify ($this->attrs);
262 show_ldap_error($ldap->get_error());
264 /* Optionally execute a command after we're done */
265 if ($this->initially_was_account == $this->is_account){
266 if ($this->is_modified){
267 $this->handle_post_events("mofify");
268 }
269 } else {
270 $this->handle_post_events("add");
271 }
273 }
275 }
277 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
278 ?>