Code

Updated Template
[gosa.git] / plugins / personal / samba / class_sambaLogonHours.inc
1 <?php
3 class sambaLogonHours extends plugin
4 {
6   var $sambaLogonHours = "";
7   var $Matrix          = array();
8   
9   var $config;
11   function sambaLogonHours ($config, $dn, $slh)
12   {
13     plugin::plugin($config,$dn);
15     /* Convert to bin */
16     $tmp = '';
17     for($i = 0 ; $i < strlen($slh) ; $i ++){
18       $tmp .= str_pad(base_convert($slh[$i],16,2),4,'0',STR_PAD_LEFT);
19     }
20     $slh = $tmp;
21     $this->sambaLogonHours = $slh;
23     /* Set to default if value is empty or seams to be broken */
24     if(strlen($slh) != 168){
25       $slh = str_pad('',168 , "1");
26     }
28     /* Create matrix */ 
29     $this->Matrix = array();
30     for($day = 0 ; $day < 7 ; $day ++ ){
31       for($hour  = 0 ; $hour < 24 ; $hour ++){
32         $bitpos  = ($day * 24 + $hour) % 168;
33         $this->Matrix[$day][$hour] = $slh[$bitpos]; 
34       }
35     }
36   }
38   function execute()
39   {
40     $week_days = array();
41     $week_days[0]= _("Sunday");
42     $week_days[1]= _("Monday");
43     $week_days[2]= _("Tuesday");
44     $week_days[3]= _("Wednesday");
45     $week_days[4]= _("Thursday");
46     $week_days[5]= _("Friday");
47     $week_days[6]= _("Saturday");
49     $hours = array();
50     for($i = 0 ; $i <24 ; $i++ ){
51       $hours[$i] = $i ;
52     }
54     $smarty = get_smarty();
55     $smarty->assign("Matrix",$this->Matrix);
56     $smarty->assign("Days"  ,$week_days);
57     $smarty->assign("Hours" ,$hours);
58     return($smarty->fetch(get_template_path("sambaLogonHours.tpl",TRUE,dirname(__FILE__))));
59   }
61   function save_object()
62   {
63     /* Check if dialog was opened and if there were any changes */
64     if(isset($_POST['sambaLogonHoursPosted'])){
65       foreach($this->Matrix as $day_key => $days){
66         foreach($days as $hour_key => $hour){
67           if(isset($_POST['day_'.$day_key.'_'.$hour_key])){
68             $this->Matrix[$day_key][$hour_key] = 1;
69           }else{
70             $this->Matrix[$day_key][$hour_key] = 0;
71           }
72         }
73       }
74     }
75   }
76   
77   function save()
78   {
79     /* Convert Matrix to Hex */
80     $ret = "";
81     foreach($this->Matrix as $day_key => $days){
82       $four_bit = '';
83       foreach($days as $hour_key => $hour){
84         $four_bit .= $hour;
85         if(strlen($four_bit) == 4){
86           $ret .= base_convert($four_bit,2,16);
87           $four_bit ='';
88         }
89       }
90     }
91     
92     /* All hours and days selected */
93     if(substr_count($ret,'f') == 42){
94       $ret ="";
95     }
96   
97     return($ret);
98   }
99 }
100 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
101 ?>