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