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