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