Code

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