Code

Added logging to ogroup
[gosa.git] / plugins / 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 Timezone to be able to shift to the correct beginning */
17     if(isset($this->config->current['TIMEZONE'])){
18       $this->timezone = $this->config->current['TIMEZONE'];
19     }
21     /* Convert to bin */
22     $tmp = '';
23     for($i = 0 ; $i < strlen($slh) ; $i ++){
24       $tmp .= str_pad(base_convert($slh[$i],16,2),4,'0',STR_PAD_LEFT);
25     }
26     $slh = $tmp;
28     /* Set to default if value is empty or seams to be broken */
29     if(strlen($slh) != 168){
30       $slh = str_pad('',168 , "1");
31     }
33     /* Rework string, because it was stored in little endian */
34     $new = '';
35     for($i = 0 ; $i < 21 ; $i ++ ){
36       $part         = strrev(substr($slh, $i * 8, 8));
37       $byte['hi']   = substr($part,0,4);
38       $byte['low']  = substr($part,4,4);
39       $new .= $byte['hi'].$byte['low'];
40     }
42     /* Shift string to match given timezone settings */
43     $shift_by = (168 + $this->timezone) % 168;
44     for($i = 0 ; $i < $shift_by; $i ++){
45       $new = $new[167].$new;
46       $new = substr($new,0,168);
47     }
49     /* Create matrix */ 
50     $this->Matrix = array();
51     for($day = 0 ; $day < 7 ; $day ++ ){
52       for($hour  = 0 ; $hour < 24 ; $hour ++){
53         $bitpos  = ($day * 24 + $hour) % 168;
54         $this->Matrix[$day][$hour] = $new[$bitpos]; 
55       }
56     }
57   }
59   function execute()
60   {
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("sambaLogonHoursACL",$ui->get_permissions($this->acl_base,"user/generic","sambaLogonHours"));
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     /* Get userinfo */
87     $ui = get_userinfo();
88   
89     /* Check if dialog was opened and if there were any changes */
90     if(isset($_POST['sambaLogonHoursPosted']) && preg_match("/w/i",$ui->get_permissions($this->acl_base,"user/generic","sambaLogonHours"))){
91       foreach($this->Matrix as $day_key => $days){
92         foreach($days as $hour_key => $hour){
93           if(isset($_POST['day_'.$day_key.'_'.$hour_key])){
94             $this->Matrix[$day_key][$hour_key] = 1;
95           }else{
96             $this->Matrix[$day_key][$hour_key] = 0;
97           }
98         }
99       }
100     }
101   }
102   
103   function save()
104   {
106     /* Convert Matrix to Hex */
107     $slh = "";
108     foreach($this->Matrix as $day_key => $days){
109       foreach($days as $hour_key => $hour){
110         $slh .= $hour;
111       }
112     }
114     /* Shift string to match given timezone settings */
115     $shift_by = (168 + ($this->timezone*(-1))) % 168;
116     for($i = 0 ; $i < $shift_by; $i ++){
117       $slh = $slh[167].$slh;
118       $slh = substr($slh,0,168);
119     }
120  
121     /* Rework string, because it was stored in little endian */
122     $new = '';
123     for($i = 0 ; $i < 21 ; $i ++ ){
124       $part         = strrev(substr($slh, $i * 8, 8));
125       $byte['hi']   = substr($part,0,4);
126       $byte['low']  = substr($part,4,4);
127       $new .= $byte['hi'].$byte['low'];
128     }
130     /* Convert to bin */
131     $tmp = '';
132     for($i = 0 ; $i < 21 ; $i ++){
133       $tmp .= str_pad(base_convert(substr($new,$i*8,8),2,16),2,'0',STR_PAD_LEFT);
134     }
136     /* Create uppercase HEX chars */
137     $ret = strtoupper( $tmp);
138     
139     /* All hours and days selected */
140     if(substr_count($ret,'F') == 42){
141       $ret = "";
142     }
144     return($ret);
145   }
147 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
148 ?>