Code

Moved to trunk/branches/tags structure
[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     }
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     }
78     /* Prepare correct state */
79     if (!$this->is_account){
80       $smarty->assign("pstate", "disabled");
81     }
83     /* Show main page */
84     $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
85     return($display);
86   }
88   function remove_from_parent()
89   {
90     /* Cancel if there's nothing to do here */
91     if (!$this->initially_was_account){
92       return;
93     }
94     
95     plugin::remove_from_parent();
97     $ldap= $this->config->get_ldap_link();
98     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
99         $this->attributes, "Save");
100     $ldap->cd($this->dn);
101     $ldap->modify($this->attrs);
102     show_ldap_error($ldap->get_error());
104     /* Optionally execute a command after we're done */
105     $this->handle_post_events("remove");
106   }
109   /* Save data to object */
110   function save_object()
111   {
112     /* Do we need to flip is_account state? */
113     if ($this->parent != NULL){
114       if (isset($_POST['connectivityTab'])){
115         if (isset($_POST['proxy'])){
116           if (!$this->is_account && $_POST['proxy'] == "B"){
117             $this->is_account= TRUE;
118           }
119         } else {
120           $this->is_account= FALSE;
121         }
122       }
123     }
125     /* Save flag value */
126     if ($this->is_account){
127       if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
128         $flags= "";
129         foreach(array("F", "T", "B") as $key){
130           if (isset($_POST["filter$key"])){
131             $flags.= $key;
132           }
133         }
134         if ("[$flags]" != $this->gosaProxyAcctFlags){
135           $this->is_modified= TRUE;
136         }
137         $this->gosaProxyAcctFlags= "[$flags]";
138       }
140       /* Save time values */
141       if (chkacl ($this->acl, "gosaProxyWorkingTime") == "" && isset($_POST['startMinute'])){
142         $old= $this->gosaProxyWorkingStart;
143         $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
144         $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
145         $old= $this->gosaProxyWorkingStop;
146         $this->gosaProxyWorkingStop = $_POST["stopHour"]  * 60 + $_POST["stopMinute"];
147         $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
148       }
150       /* Save quota values */
151       if (chkacl ($this->acl, "gosaProxyQuota") == ""){
152         $old= $this->gosaProxyQuota;
153         $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
154         $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
155         $old= $this->gosaProxyQuotaPeriod;
156         $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
157         $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
158       }
159     }
161   }
164   /* Save to LDAP */
165   function save()
166   {
167     plugin::save();
169     /* Write back to ldap */
170     $ldap= $this->config->get_ldap_link();
171     $ldap->cd($this->dn);
172     $ldap->modify($this->attrs);
174     show_ldap_error($ldap->get_error());
176     /* Optionally execute a command after we're done */
177     if ($this->initially_was_account == $this->is_account){
178       if ($this->is_modified){
179         $this->handle_post_events("mofify");
180       }
181     } else {
182       $this->handle_post_events("add");
183     }
185   }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>