Mibew Messenger Community
Contributions => Plugins, tips, and tricks => Topic started by: bheirman on May 31, 2010, 07:15:37 AM
-
Hi all
I modified mibew to automatically switch offline outside our opening hours. I thought I'd share it with you. This is for 1.6.3. Use at your own risk!
In libs/config.php add right before the ?>:
//BEGIN Automatic offline status by Björn
$autodaysofweekopen = "1, 2, 3, 4, 5"; //1 (for Monday) through 7 (for Sunday)
$autostartday = mktime(9,30,0); //start of working day(hour,minute,seconds)
$autostartpause = mktime(12,30,0); //start of lunch break
$autoendpause = mktime(13,30,0); //end of lunch break
$autoendday = mktime(17,0,0); //end of working day
//END Automatic offline status by Björn
In libs/operator.php replace around line 134
return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
by
//BEGIN Automatic offline status by Björn
include('config.php');
if (ereg(date("N", mktime($now)),$autodaysofweekopen)) {
$now = mktime(date(G),date(i),date(s));
if ( ( ($now > $autostartday) && ($now < $autostartpause) ) || (($now > $autoendpause) && ($now < $autoendday) ) ) {
return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
}else{
return 0;
}
}else{
return 0;
}
//END Automatic offline status by Björn
I'm not schooled as programmer, but hey, it works just fine for me ;)
-
really works
thanks a lot
very good job!
-
very nice, i was looking for something like this.
Since the company I work is also open on saturday i have changed the script a small bit.
instead of putting everything in the config file ( which will load the connect variables each time you import it ) I chose to make a different file in the libs/ dir.
libs/opening_hours.php
//BEGIN Automatic offline status
//Weekdays
$weekday_wStart=mktime(8,30,0); //General weekday starttime
$weekday_wEnd=mktime(21,0,0); //General weekday endtime
$weekday_bStart=mktime(12,30,0); //General weekday break starttime
$weekday_bEnd=mktime(13,30,0); //General weekday break endtime
//Weekends
$weekend_wStart=mktime(9,00,0); //General weekend starttime
$weekend_wEnd=mktime(18,00,0); //General weekend endtime
$weekend_bStart=mktime(11,30,0); //General weekend break starttime
$weekend_bEnd=mktime(12,30,0); //General weekend break endtime
//Monday
$work['monday']['work']=1; // Work 1=yes 0=no
$work['monday']['wStart']=$weekday_wStart; // Starting time
$work['monday']['wEnd']=$weekday_wEnd; // End time
$work['monday']['break']=0; // Break 1=yes 0=no
$work['monday']['bStart']=$weekday_bStart; // Break start time
$work['monday']['bEnd']=$weekday_bEnd; // Break end time
//Tuesday
$work['tuesday']['work']=1; // Work 1=yes 0=no
$work['tuesday']['wStart']=$weekday_wStart; // Starting time
$work['tuesday']['wEnd']=$weekday_wEnd; // End time
$work['tuesday']['break']=1; // Break 1=yes 0=no
$work['tuesday']['bStart']=$weekday_bStart; // Break start time
$work['tuesday']['bEnd']=$weekday_bEnd; // Break end time
//Wednesday
$work['wednesday']['work']=1; // Work 1=yes 0=no
$work['wednesday']['wStart']=$weekday_wStart; // Starting time
$work['wednesday']['wEnd']=$weekday_wEnd; // End time
$work['wednesday']['break']=0; // Break 1=yes 0=no
$work['wednesday']['bStart']=$weekday_bStart; // Break start time
$work['wednesday']['bEnd']=$weekday_bEnd; // Break end time
//Thursday
$work['thursday']['work']=1; // Work 1=yes 0=no
$work['thursday']['wStart']=$weekday_wStart; // Starting time
$work['thursday']['wEnd']=$weekday_wEnd; // End time
$work['thursday']['break']=0; // Break 1=yes 0=no
$work['thursday']['bStart']=$weekday_bStart; // Break start time
$work['thursday']['bEnd']=$weekday_bEnd; // Break end time
//Friday
$work['friday']['work']=1; // Work 1=yes 0=no
$work['friday']['wStart']=$weekday_wStart; // Starting time
$work['friday']['wEnd']=$weekday_wEnd; // End time
$work['friday']['break']=0; // Break 1=yes 0=no
$work['friday']['bStart']=$weekday_bStart; // Break start time
$work['friday']['bEnd']=$weekday_bEnd; // Break end time
//Saturday
$work['saturday']['work']=1; // Work 1=yes 0=no
$work['saturday']['wStart']=$weekend_wStart; // Starting time
$work['saturday']['wEnd']=$weekend_wEnd; // End time
$work['saturday']['break']=0; // Break 1=yes 0=no
$work['saturday']['bStart']=$weekend_bStart; // Break start time
$work['saturday']['bEnd']=$weekend_bEnd; // Break end time
//Sunday
$work['sunday']['work']=0; // Work 1=yes 0=no
$work['sunday']['wStart']=$weekend_wStart; // Starting time
$work['sunday']['wEnd']=$weekend_bEnd; // End time
$work['sunday']['break']=0; // Break 1=yes 0=no
$work['sunday']['bStart']=$weekend_bStart; // Break start time
$work['sunday']['bEnd']=$weekend_bEnd; // Break end time
//END Automatic offline status
and inside libs/operator.php i replaced:
return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
with
//BEGIN Automatic offline status
include('opening_hours.php');
$now = mktime(date("G"),date("i"),date("s"));
$wToday=strtolower(date("l"));
if($work[$wToday]['work']===1){
if($work[$wToday]['break']===1){
if ((($now > $work[$wToday]['wStart']) && ($now < $work[$wToday]['bStart'])) || (($now > $work[$wToday]['bEnd']) && ($now < $work[$wToday]['wEnd']))){
return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
}else{return 0;}
}else if($work[$wToday]['break']===0){
if ($now > $work[$wToday]['wStart'] && $now < $work[$wToday]['wEnd']){
return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
}else{return 0;}
}
}else{return 0;}
//END Automatic offline status
These changes makes you able to have different working hours every day and you are able to switch breaks on or off depending on the way your company is available.
I hope this will come in handy to some people.