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 /* Save data to object */
120 function save_object()
121 {
122 /* Do we need to flip is_account state? */
123 if ($this->parent != NULL){
124 if (isset($_POST['connectivityTab'])){
125 if (isset($_POST['proxy'])){
126 if (!$this->is_account && $_POST['proxy'] == "B"){
127 $this->is_account= TRUE;
128 }
129 } else {
130 $this->is_account= FALSE;
131 }
132 }
133 }
135 /* Save flag value */
136 if ($this->is_account){
137 if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
138 $flags= "";
139 foreach(array("F", "T", "B") as $key){
140 if (isset($_POST["filter$key"])){
141 $flags.= $key;
142 }
143 }
144 if ("[$flags]" != $this->gosaProxyAcctFlags){
145 $this->is_modified= TRUE;
146 }
147 $this->gosaProxyAcctFlags= "[$flags]";
148 }
150 /* Save time values */
151 if (chkacl ($this->acl, "gosaProxyWorkingTime") == "" && isset($_POST['startMinute'])){
152 $old= $this->gosaProxyWorkingStart;
153 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
154 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
155 $old= $this->gosaProxyWorkingStop;
156 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
157 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
158 }
160 /* Save quota values */
161 if (chkacl ($this->acl, "gosaProxyQuota") == ""){
162 $old= $this->gosaProxyQuota;
163 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
164 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
165 }
166 $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
167 $old= $this->gosaProxyQuotaPeriod;
168 if(isset($_POST["gosaProxyQuotaPeriod"])){
169 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
170 }
171 $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
172 }
173 }
175 }
178 /* Save to LDAP */
179 function save()
180 {
181 plugin::save();
183 /* Write back to ldap */
184 $ldap= $this->config->get_ldap_link();
185 $ldap->cd($this->dn);
186 $ldap->modify($this->attrs);
188 show_ldap_error($ldap->get_error());
190 /* Optionally execute a command after we're done */
191 if ($this->initially_was_account == $this->is_account){
192 if ($this->is_modified){
193 $this->handle_post_events("mofify");
194 }
195 } else {
196 $this->handle_post_events("add");
197 }
199 }
201 }
203 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
204 ?>