a097972ddc889696a482a309908a55e6cee6c384
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");
52 /* Add state variables for on-the-fly state-changing of checkboxes */
53 $smarty->assign($val."state", "");
55 } else {
56 $smarty->assign("filter$val", "");
58 /* Same as above */
59 $smarty->assign($val."state", "disabled");
60 }
61 }
63 /* Assign working time */
64 $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
65 $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
66 $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
67 $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
68 $hours= array();
69 for($i=0; $i<24; $i++){
70 $hours[]= sprintf("%02d",$i);
71 }
72 $smarty->assign("hours", $hours);
73 $smarty->assign("minutes", array("00","15","30","45"));
75 /* Assign quota values */
76 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
77 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
78 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
79 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
80 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
81 if ($this->is_account){
82 $smarty->assign("proxyState", "checked");
83 } else {
84 $smarty->assign("proxyState", "");
85 }
87 /* Prepare correct state */
88 if (!$this->is_account){
89 $smarty->assign("pstate", "disabled");
90 } else {
91 $smarty->assign("pstate", "");
92 }
94 /* Show main page */
95 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
96 return($display);
97 }
99 function remove_from_parent()
100 {
101 /* Cancel if there's nothing to do here */
102 if (!$this->initially_was_account){
103 return;
104 }
106 plugin::remove_from_parent();
108 $ldap= $this->config->get_ldap_link();
109 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
110 $this->attributes, "Save");
111 $ldap->cd($this->dn);
112 $ldap->modify($this->attrs);
113 show_ldap_error($ldap->get_error());
115 /* Optionally execute a command after we're done */
116 $this->handle_post_events("remove");
117 }
119 /* Check values */
120 function check()
121 {
122 $message= array();
124 /* We've got only one value to check for positive integer or emtpy field */
125 if ($this->is_account){
126 if (isset($_POST["quota_size"])){
127 if ($_POST["quota_size"] == ""){
128 $message[]= _("Numerical value for Quota Setting is empty.");
129 }
130 else if ($_POST["quota_size"] <= 0){
131 $message[]= _("Numerical value for Quota Setting is not valid.");
132 }
133 }
134 }
136 return $message;
137 }
139 /* Save data to object */
140 function save_object()
141 {
142 /* Do we need to flip is_account state? */
143 if ($this->parent != NULL){
144 if (isset($_POST['connectivityTab'])){
145 if (isset($_POST['proxy'])){
146 if (!$this->is_account && $_POST['proxy'] == "B"){
147 $this->is_account= TRUE;
148 }
149 } else {
150 $this->is_account= FALSE;
151 }
152 }
153 }
155 /* Save flag value */
156 if ($this->is_account){
157 if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
158 $flags= "";
159 foreach(array("F", "T", "B") as $key){
160 if (isset($_POST["filter$key"])){
161 $flags.= $key;
162 }
163 }
164 if ("[$flags]" != $this->gosaProxyAcctFlags){
165 $this->is_modified= TRUE;
166 }
167 $this->gosaProxyAcctFlags= "[$flags]";
168 }
170 /* Save time values */
171 if (chkacl ($this->acl, "gosaProxyWorkingTime") == "" && isset($_POST['startMinute'])){
172 $old= $this->gosaProxyWorkingStart;
173 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
174 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
175 $old= $this->gosaProxyWorkingStop;
176 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
177 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
178 }
180 /* Save quota values */
181 if (chkacl ($this->acl, "gosaProxyQuota") == ""){
182 $old= $this->gosaProxyQuota;
183 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
184 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
185 }
186 $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
187 $old= $this->gosaProxyQuotaPeriod;
188 if(isset($_POST["gosaProxyQuotaPeriod"])){
189 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
190 }
191 $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
192 }
193 }
195 }
198 /* Save to LDAP */
199 function save()
200 {
201 plugin::save();
203 /* Write back to ldap */
204 $ldap= $this->config->get_ldap_link();
205 $ldap->cd($this->dn);
206 $ldap->modify($this->attrs);
208 show_ldap_error($ldap->get_error());
210 /* Optionally execute a command after we're done */
211 if ($this->initially_was_account == $this->is_account){
212 if ($this->is_modified){
213 $this->handle_post_events("mofify");
214 }
215 } else {
216 $this->handle_post_events("add");
217 }
219 }
221 }
223 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
224 ?>