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