Code

Removed CLI
[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 = array();
62     $week_days[0]= _("Sunday");
63     $week_days[1]= _("Monday");
64     $week_days[2]= _("Tuesday");
65     $week_days[3]= _("Wednesday");
66     $week_days[4]= _("Thursday");
67     $week_days[5]= _("Friday");
68     $week_days[6]= _("Saturday");
70     $hours = array();
71     for($i = 0 ; $i <24 ; $i++ ){
72       $hours[$i] = $i ;
73     }
74     $ui =get_userinfo();
76     $smarty = get_smarty();
77     $smarty->assign("Matrix",$this->Matrix);
78     $smarty->assign("Days"  ,$week_days);
79     $smarty->assign("Hours" ,$hours);
80     return($smarty->fetch(get_template_path("sambaLogonHours.tpl",TRUE,dirname(__FILE__))));
81   }
83   function save_object()
84   {
85     /* Get userinfo */
86     $ui = get_userinfo();
87   
88     /* Check if dialog was opened and if there were any changes */
89     if(isset($_POST['sambaLogonHoursPosted'])){
90       foreach($this->Matrix as $day_key => $days){
91         foreach($days as $hour_key => $hour){
92           if(isset($_POST['day_'.$day_key.'_'.$hour_key])){
93             $this->Matrix[$day_key][$hour_key] = 1;
94           }else{
95             $this->Matrix[$day_key][$hour_key] = 0;
96           }
97         }
98       }
99     }
100   }
101   
102   function save()
103   {
105     /* Convert Matrix to Hex */
106     $slh = "";
107     foreach($this->Matrix as $day_key => $days){
108       foreach($days as $hour_key => $hour){
109         $slh .= $hour;
110       }
111     }
113     /* Shift string to match given timezone settings */
114     $shift_by = (168 + ($this->timezone*(-1))) % 168;
115     for($i = 0 ; $i < $shift_by; $i ++){
116       $slh = $slh[167].$slh;
117       $slh = substr($slh,0,168);
118     }
119  
120     /* Rework string, because it was stored in little endian */
121     $new = '';
122     for($i = 0 ; $i < 21 ; $i ++ ){
123       $part         = strrev(substr($slh, $i * 8, 8));
124       $byte['hi']   = substr($part,0,4);
125       $byte['low']  = substr($part,4,4);
126       $new .= $byte['hi'].$byte['low'];
127     }
129     /* Convert to bin */
130     $tmp = '';
131     for($i = 0 ; $i < 21 ; $i ++){
132       $tmp .= str_pad(base_convert(substr($new,$i*8,8),2,16),2,'0',STR_PAD_LEFT);
133     }
135     /* Create uppercase HEX chars */
136     $ret = strtoupper( $tmp);
137     
138     /* All hours and days selected */
139     if(substr_count($ret,'F') == 42){
140       $ret = "";
141     }
143     return($ret);
144   }
146 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
147 ?>