fe4ca325d24dd791811e997f9d1ef124e6a20177
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 // Create state variable for checkbox (Used in proxy.tpl)
53 $smarty->assign($val."state", "");
54 } else {
55 $smarty->assign("filter$val", "");
57 // Create state variable for checkbox (Used in proxy.tpl)
58 $smarty->assign($val."state", "disabled");
59 }
60 }
62 /* Assign working time */
63 $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
64 $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
65 $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
66 $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
67 $hours= array();
68 for($i=0; $i<24; $i++){
69 $hours[]= sprintf("%02d",$i);
70 }
71 $smarty->assign("hours", $hours);
72 $smarty->assign("minutes", array("00","15","30","45"));
74 /* Assign quota values */
75 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
76 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
77 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
78 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
79 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
80 if ($this->is_account){
81 $smarty->assign("proxyState", "checked");
82 } else {
83 $smarty->assign("proxyState", "");
84 }
86 /* Prepare correct state */
87 if (!$this->is_account){
88 $smarty->assign("pstate", "disabled");
89 } else {
90 $smarty->assign("pstate", "");
91 }
93 /* Show main page */
94 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
95 return($display);
96 }
98 function remove_from_parent()
99 {
100 /* Cancel if there's nothing to do here */
101 if (!$this->initially_was_account){
102 return;
103 }
105 plugin::remove_from_parent();
107 $ldap= $this->config->get_ldap_link();
108 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
109 $this->attributes, "Save");
110 $ldap->cd($this->dn);
111 $ldap->modify($this->attrs);
112 show_ldap_error($ldap->get_error());
114 /* Optionally execute a command after we're done */
115 $this->handle_post_events("remove");
116 }
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 }
194 }
197 /* Save to LDAP */
198 function save()
199 {
200 plugin::save();
202 /* Write back to ldap */
203 $ldap= $this->config->get_ldap_link();
204 $ldap->cd($this->dn);
205 $ldap->modify($this->attrs);
207 show_ldap_error($ldap->get_error());
209 /* Optionally execute a command after we're done */
210 if ($this->initially_was_account == $this->is_account){
211 if ($this->is_modified){
212 $this->handle_post_events("mofify");
213 }
214 } else {
215 $this->handle_post_events("add");
216 }
218 }
220 }
222 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
223 ?>