Code

Fixed ogroup saving
[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   var $uid = "";
28   function proxyAccount ($config, $dn= NULL, $parent= NULL)
29   {
30     plugin::plugin ($config, $dn, $parent);
31     
32     /* Setting uid to default */
33     if(isset($this->attrs['uid'][0])){
34       $this->uid = $this->attrs['uid'][0];
35     }
37   }
39   function execute()
40   {
41         /* Call parent execute */
42 //      plugin::execute();
44     $display= "";
46     /* Prepare templating */
47     $smarty= get_smarty();
48     $smarty->assign("proxyAccountACL",          chkacl($this->acl, "proxyAccount"));
49     $smarty->assign("gosaProxyAcctFlagsACL",    chkacl($this->acl, "gosaProxyAcctFlags"));
50     $smarty->assign("gosaProxyWorkingStartACL", chkacl($this->acl, "gosaProxyWorkingStart"));
51     $smarty->assign("gosaProxyWorkingStopACL",  chkacl($this->acl, "gosaProxyWorkingStop"));
52     $smarty->assign("gosaProxyQuotaACL",        chkacl($this->acl, "gosaProxyQuota"));
54     /* Assign radio boxes */
55     foreach (array("F", "T", "B", "N") as $val){
56       if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
57         $smarty->assign("filter$val", "checked");
59         /* Add state variables for on-the-fly state-changing of checkboxes */
60         $smarty->assign($val."state", "");
61         
62       } else {
63         $smarty->assign("filter$val", "");
65         /* Same as above */
66         if($_SESSION['js']==1){
67           $smarty->assign($val."state", "disabled");
68         }else{
69           $smarty->assign($val."state", "");
70         }
71       }
72     }
74     /* Assign working time */
75     $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
76     $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
77     $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
78     $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
79     $hours= array();
80     for($i=0; $i<24; $i++){
81       $hours[]= sprintf("%02d",$i);
82     }
83     $smarty->assign("hours", $hours);
84     $smarty->assign("minutes", array("00","15","30","45"));
86     /* Assign quota values */
87     $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
88     $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
89     $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
90     $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
91     $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
92     if ($this->is_account){
93       $smarty->assign("proxyState", "checked");
94     } else {
95       $smarty->assign("proxyState", "");
96     }
98     /* Prepare correct state */
99     if (!$this->is_account){
100       $smarty->assign("pstate", "disabled");
101     } else {
102       $smarty->assign("pstate", "");
103     }
105     $changeA = "";
106   
107     if(chkacl($this->acl,"gosaProxyAcctFlags")==""){
108       $changeA .="changeState('filterF');\n";
109     }
110     $smarty->assign("Working_allowedACL","disabled");
111     if((chkacl($this->acl,"gosaProxyWorkingStart")=="")||(chkacl($this->acl,"gosaProxyWorkingStop")=="")){
112       $smarty->assign("Working_allowedACL","");
113       $changeA .= "changeState('filterT');\n";
114     }
116     $ProxyWorkingStateChange ="";
117     if(chkacl($this->acl,"gosaProxyWorkingStart")==""){
118       $ProxyWorkingStateChange.=  "changeState('startHour');\n";
119       $ProxyWorkingStateChange.=  "changeState('startMinute');\n";
120     }
122     if(chkacl($this->acl,"gosaProxyWorkingStop")=="")  {
123       $ProxyWorkingStateChange.=  "changeState('stopHour');\n";
124       $ProxyWorkingStateChange.=  "changeState('stopMinute');\n";
125     }
126     
127     $changeA .= $ProxyWorkingStateChange;
128   
129     $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
131     $changeB = "";
132     if(chkacl($this->acl,"gosaProxyQuota")==""){
133       $changeA .= "changeState('filterB');";
134       $changeB = 
135         "changeSubselectState('filterB', 'quota_size');
136          changeSubselectState('filterB', 'quota_unit');
137          changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
138     }
140     $smarty->assign("changeB",$changeB);
141     $smarty->assign("changeA",$changeA);
143     /* Show main page */
144     $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
145     return($display);
146   }
148   function remove_from_parent()
149   {
150     /* Cancel if there's nothing to do here */
151     if (!$this->initially_was_account){
152       return;
153     }
154     
155     plugin::remove_from_parent();
157     $ldap= $this->config->get_ldap_link();
158     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
159         $this->attributes, "Save");
160     $ldap->cd($this->dn);
161     $this->cleanup();
162     $ldap->modify ($this->attrs); 
164     show_ldap_error($ldap->get_error(), _("Removing proxy account failed"));
166     /* Optionally execute a command after we're done */
167     $this->handle_post_events("remove",array("uid" => $this->uid));
168   }
170   /* Check values */
171   function check()
172   {
173     /* Call common method to give check the hook */
174     $message= plugin::check();
175     
176     /* We've got only one value to check for positive integer or emtpy field */
177     if ($this->is_account){
178       if (isset($_POST["quota_size"])){
179         if ($_POST["quota_size"] == ""){
180           $message[]= _("Numerical value for Quota Setting is empty.");
181         }
182         else if ($_POST["quota_size"] <= 0){
183           $message[]= _("Numerical value for Quota Setting is not valid.");
184         }
185       }
186     }
188     return $message;
189   }
191   /* Save data to object */
192   function save_object()
193   {
194     /* Do we need to flip is_account state? */
195     if ($this->parent != NULL){
196       if (isset($_POST['connectivityTab'])){
197         if (isset($_POST['proxy'])){
198           if (!$this->is_account && $_POST['proxy'] == "B"){
199             $this->is_account= TRUE;
200           }
201         } else {
202           $this->is_account= FALSE;
203         }
204       }
205     }
207     if(isset($_POST['proxy'])){
208       $this->is_account = TRUE; 
209     }else{
210       $this->is_account = FALSE;
211     }
213     /* Save flag value */
214     if ($this->is_account){
215       if (chkacl ($this->acl, "gosaProxyAcctFlags") == ""){
216         $flags= "";
217         foreach(array("F", "T", "B") as $key){
218           if (isset($_POST["filter$key"])){
219             $flags.= $key;
220           }
221         }
222         if ("[$flags]" != $this->gosaProxyAcctFlags){
223           $this->is_modified= TRUE;
224         }
225         $this->gosaProxyAcctFlags= "[$flags]";
226       }
228       /* Save time values */
229       if ((chkacl ($this->acl, "gosaProxyWorkingStart") == "")&&(isset($_POST['startMinute']))){
230         $old= $this->gosaProxyWorkingStart;
231         $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
232         $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
233       }
234       
235       if ((chkacl ($this->acl, "gosaProxyWorkingStop") == "")&&(isset($_POST['stopMinute']))){
236         $old= $this->gosaProxyWorkingStop;
237         $this->gosaProxyWorkingStop = $_POST["stopHour"]  * 60 + $_POST["stopMinute"];
238         $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
239       }
241       /* Save quota values */
242       if (chkacl ($this->acl, "gosaProxyQuota") == ""){
243         $old= $this->gosaProxyQuota;
244         if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
245           $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
246         }
247         $this->is_modified= ($old != $this->gosaProxyQuota)?TRUE:$this->is_modified;
248         $old= $this->gosaProxyQuotaPeriod;
249         if(isset($_POST["gosaProxyQuotaPeriod"])){
250           $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
251         }
252         $this->is_modified= ($old != $this->gosaProxyQuotaPeriod)?TRUE:$this->is_modified;
253       }
254     }
256   }
259   /* Save to LDAP */
260   function save()
261   {
262     plugin::save();
264     /* Write back to ldap */
265     $ldap= $this->config->get_ldap_link();
266     $ldap->cd($this->dn);
267     $this->cleanup();
268     $ldap->modify ($this->attrs); 
270     show_ldap_error($ldap->get_error(), _("Saving proxy account failed"));
272     /* Optionally execute a command after we're done */
273     if ($this->initially_was_account == $this->is_account){
274       if ($this->is_modified){
275         $this->handle_post_events("modify",array("uid" => $this->uid));
276       }
277     } else {
278       $this->handle_post_events("add",array("uid" => $this->uid));
279     }
281   }
285 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
286 ?>