Code

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