Code

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