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