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