Code

Closes #292 Updated template to allow usage of checkboxes for resolution also when...
[gosa.git] / plugins / personal / samba / class_sambaLogonHours.inc
1 <?php
3 require_once("class_timezones.inc");
5 class sambaLogonHours extends plugin
6 {
8   var $sambaLogonHours = "";
9   var $Matrix          = array();
10   var $timezone        = 0; 
11   var $config;
13   function sambaLogonHours ($config, $dn, $slh)
14   {
15     plugin::plugin($config,$dn);
16     $this->sambaLogonHours = $slh;
18     /* Get default timezone */
19     $zone = get_default_timezone();
20     $this->timezone = $zone['value'];
22     /* Convert to bin */
23     $tmp = '';
24     for($i = 0 ; $i < strlen($slh) ; $i ++){
25       $tmp .= str_pad(base_convert($slh[$i],16,2),4,'0',STR_PAD_LEFT);
26     }
27     $slh = $tmp;
29     /* Set to default if value is empty or seams to be broken */
30     if(strlen($slh) != 168){
31       $slh = str_pad('',168 , "1");
32     }
34     /* Rework string, because it was stored in little endian */
35     $new = '';
36     for($i = 0 ; $i < 21 ; $i ++ ){
37       $part         = strrev(substr($slh, $i * 8, 8));
38       $byte['hi']   = substr($part,0,4);
39       $byte['low']  = substr($part,4,4);
40       $new .= $byte['hi'].$byte['low'];
41     }
43     /* Shift string to match given timezone settings */
44     $shift_by = (168 + $this->timezone) % 168;
45     for($i = 0 ; $i < $shift_by; $i ++){
46       $new = $new[167].$new;
47       $new = substr($new,0,168);
48     }
50     /* Create matrix */ 
51     $this->Matrix = array();
52     for($day = 0 ; $day < 7 ; $day ++ ){
53       for($hour  = 0 ; $hour < 24 ; $hour ++){
54         $bitpos  = ($day * 24 + $hour) % 168;
55         $this->Matrix[$day][$hour] = $new[$bitpos]; 
56       }
57     }
58   }
60   function execute()
61   {
63     $week_days = array();
64     $week_days[0]= _("Sunday");
65     $week_days[1]= _("Monday");
66     $week_days[2]= _("Tuesday");
67     $week_days[3]= _("Wednesday");
68     $week_days[4]= _("Thursday");
69     $week_days[5]= _("Friday");
70     $week_days[6]= _("Saturday");
72     $hours = array();
73     for($i = 0 ; $i <24 ; $i++ ){
74       $hours[$i] = $i ;
75     }
77     $smarty = get_smarty();
78     $smarty->assign("Matrix",$this->Matrix);
79     $smarty->assign("Days"  ,$week_days);
80     $smarty->assign("Hours" ,$hours);
81     return($smarty->fetch(get_template_path("sambaLogonHours.tpl",TRUE,dirname(__FILE__))));
82   }
84   function save_object()
85   {
86     /* Check if dialog was opened and if there were any changes */
87     if(isset($_POST['sambaLogonHoursPosted'])){
88       foreach($this->Matrix as $day_key => $days){
89         foreach($days as $hour_key => $hour){
90           if(isset($_POST['day_'.$day_key.'_'.$hour_key])){
91             $this->Matrix[$day_key][$hour_key] = 1;
92           }else{
93             $this->Matrix[$day_key][$hour_key] = 0;
94           }
95         }
96       }
97     }
98   }
99   
100   function save()
101   {
103     /* Convert Matrix to Hex */
104     $slh = "";
105     foreach($this->Matrix as $day_key => $days){
106       foreach($days as $hour_key => $hour){
107         $slh .= $hour;
108       }
109     }
111     /* Shift string to match given timezone settings */
112     $shift_by = (168 + ($this->timezone*(-1))) % 168;
113     for($i = 0 ; $i < $shift_by; $i ++){
114       $slh = $slh[167].$slh;
115       $slh = substr($slh,0,168);
116     }
117  
118     /* Rework string, because it was stored in little endian */
119     $new = '';
120     for($i = 0 ; $i < 21 ; $i ++ ){
121       $part         = strrev(substr($slh, $i * 8, 8));
122       $byte['hi']   = substr($part,0,4);
123       $byte['low']  = substr($part,4,4);
124       $new .= $byte['hi'].$byte['low'];
125     }
127     /* Convert to bin */
128     $tmp = '';
129     for($i = 0 ; $i < 21 ; $i ++){
130       $tmp .= str_pad(base_convert(substr($new,$i*8,8),2,16),2,'0',STR_PAD_LEFT);
131     }
133     /* Create uppercase HEX chars */
134     $ret = strtoupper( $tmp);
135     
136     /* All hours and days selected */
137     if(substr_count($ret,'F') == 42){
138       $ret = "";
139     }
141     return($ret);
142   }
144 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
145 ?>