Vous êtes sur la page 1sur 5

<?

php error_reporting(0); ini_set('display_errors', 0); ob_start(); session_sta


rt(); include("../config/config.php"); include_once("../include/function.php");
?>
<?php
$salon= trim($_GET['salon']);
$bookslot= get_salon_meta($salon, "p_booking_slot_size");
$wx_arr= json_decode(get_staff_meta($_GET['staff'], "work_hours"));
$main_arr=array();
foreach ($wx_arr as $key => $value) {
$single_arr=array();
foreach ($value as $v) {
array_push($single_arr, $v);
}
array_push($main_arr, $single_arr);
}
//print_r($main_arr);
$time_arr=array();
$dayx=date("w", strtotime($_GET['date']))-1;
$start=timetomin($main_arr[$dayx][2]);
$end=timetomin($main_arr[$dayx][3]);
$b_start=timetomin($main_arr[$dayx][5]);
$b_end=timetomin($main_arr[$dayx][6]);
//echo "|".mintotime($end);



if($main_arr[$dayx][4]=='no'){
for($i=$start;$i<$end;($i=$i+intval($bookslot))){
if(($i+intval($_GET['time']))<intval($end)){
array_push($time_arr,mintotime($i));
}
}
}
if($main_arr[$dayx][4]=='yes'){
for($i=$start;$i<$b_start;($i=$i+intval($bookslot))){
if(($i+intval($_GET['time']))<intval($b_start)){
array_push($time_arr,mintotime($i));
}
}
for($i=$b_end;$i<$end;($i=$i+intval($bookslot))){
if(($i+intval($_GET['time']))<intval($end)){
array_push($time_arr,mintotime($i));
}
}
}
$freeslot=array();
//print_r($time_arr);
//echo count($time_arr);
//echo $_GET['time'];
$the_date=date("Y-m-d", strtotime($_GET['date']));
$resxx=mysql_query("SELECT * FROM `salon_appointment` WHERE `start_date` LIKE
'%$the_date%' AND `staff`='staff$_GET[staff]' AND `status`='active'");
while($dataxx= mysql_fetch_array($resxx)){

$duration=timetomin(date("H:i", strtotime($dataxx['start_date'])));

$serv_arr= array_filter(array_unique(explode(",",$dataxx['service'])));

foreach ($serv_arr as $sa){

// Ross added code: trying to get the full code not one character.
$code = explode(':', $sa);
if($code[1]=="N"){
$s_arr=get_the_service($code[0]);
if($s_arr['padding_before']!="0") {

//print_r($code[0]);
$s_arr=get_the_service($code[0]);
$start=$duration+intval($s_arr['padding_before']);
//print $start;
$depth=intval($s_arr['duration'])-intval($s_arr['padding_before'])-intval($s_
arr['padding_after']);
$duration=$duration+intval($s_arr['duration']);
//print $duration;
array_push($freeslot, array(mintotime($start),mintotime($start+$depth),$depth
));
}
}
else{
$s_arr=get_the_service_by_name($sa);

if($s_arr['padding_before']!="0") {

//print_r($code[0]);
$s_arr=get_the_service($code[0]);
$start=$duration+intval($s_arr['padding_before']);
//print $start;
$depth=intval($s_arr['duration'])-intval($s_arr['padding_before'])-intval($s_
arr['padding_after']);
$duration=$duration+intval($s_arr['duration']);
//print $duration;
array_push($freeslot, array(mintotime($start),mintotime($start+$depth),$depth
));
}

}


}

}
$booked=array();
$the_date=date("Y-m-d", strtotime($_GET['date']));
$resxx=mysql_query("SELECT * FROM `salon_appointment` WHERE `start_date` LIKE
'%$the_date%' AND `staff`='staff$_GET[staff]' AND `status`='active'");
while($dataxx= mysql_fetch_array($resxx)){
array_push($booked, array((intval(timetomin(date("H:i", strtotime($dataxx['start
_date']))))-intval($_GET['time'])),timetomin(date("H:i", strtotime($dataxx['end_
date'])))));
//print intval(timetomin(date("H:i", strtotime($dataxx['start_date']))))-intval(
$_GET['time'])."-".timetomin(date("H:i", strtotime($dataxx['end_date'])))."<br>"
;
}
$e = count($time_arr);
for($i=0;$i<$e;$i++){
foreach ($booked as $b){
//print $b[0]."<br>";
$b1 = intval($b[0]);
$b2 = intval($b[1]);
//echo $time_arr[$i]."Value ".timetomin($time_arr[$i])."- Higher than
$b1, lower than $b2<br>";
if((timetomin($time_arr[$i])>intval($b[0]))&&(timetomin($time_arr[$i])<intv
al($b[1]))){
$time_arr=array_diff($time_arr, array($time_arr[$i]));
}
}
}
$ftarr=array();
foreach($freeslot as $fs){
//print_r($fs);
if(intval($_GET['time'])<=$fs[2]){
//array_push($ftarr,$fs[0]);
// array_push($time_arr, $fs[0]);
for($i= timetomin($fs[0]); $i<=timetomin($fs[1]);$i=$i+$_GET['time']){
if(($i+intval($_GET['time']))<=timetomin($fs[1])){
//echo mintotime($i)." ";
array_push($ftarr,mintotime($i));
array_push($time_arr, mintotime($i));

}
}
}
}
// if(intval(timetomin(date("H:i", strtotime($dataxx['start_date']));
$the_date=date("Y-m-d", strtotime($_GET['date']));
$resxx=mysql_query("SELECT * FROM `salon_appointment` WHERE `start_date` LIKE
'%$the_date%' AND `staff`='staff$_GET[staff]' AND `status`='active'");
while($dataxx= mysql_fetch_array($resxx)){

//foreach($ftarr as $fts){
// $fts= timetomin($fts);
// $s=intval(timetomin(date("H:i", strtotime($dataxx['start_date']))));
// $e=intval(timetomin(date("H:i", strtotime($dataxx['end_date']))));
//
// if($fts==$s){
// echo "ss ";
// $time_arr=array_diff($time_arr, array(mintotime($fts)));
// }
//
//}

foreach($freeslot as $ftarr){
$s=intval(timetomin(date("H:i", strtotime($dataxx['start_date']))));
$e=intval(timetomin(date("H:i", strtotime($dataxx['end_date']))));
//print "$ftarr[0], $ftarr[1] SHigher:".$s." ELower:".$e."THAN:".timetomin($ftar
r[0])." ".timetomin($ftarr[1])."<br>";
if($s>=timetomin($ftarr[0])&&($e<=timetomin($ftarr[1]))){
foreach($ftarr as $fts){
//print timetomin($fts)."<br>";
if((timetomin($fts)>=$s)&&(timetomin($fts)<=$e)){
$time_arr=array_diff($time_arr, array($fts));
}
}


}



}



}
//print_r($ftarr);
sort($time_arr);
?>
<?php //print_r($_GET) ?>
<div class="apointype" >
<?php
foreach ($time_arr as $timex){
//Allow same day appointments
$now = date("H:i");
$nowdate = date("Y-m-d");
$current = timetomin($now);
$button = timetomin($timex);
if ($nowdate == $the_date) {
if ($button <= $current) {
}
if ($button > $current) { ?>
<a href="#" class="avldates" onclick="$('.avldates').removeAttr('style'); $(th
is).css('background','#57aad1'); $('#apx_time').val('<?=timetomin($timex)?>');">
<?=$timex?></a> <?php } } ?>


<?php if ($nowdate != $the_date) { ?>
<a href="#" class="avldates" onclick="$('.avldates').removeAttr('style'); $(thi
s).css('background','#57aad1'); $('#apx_time').val('<?=timetomin($timex)?>');"><
?=$timex?></a>
<?php } } ?>
</div>
<div class="ap-bu">
<button class="button5 back-button" type="button" onclick="prev_step()">Back</bu
tton>
<button class="button5 next-step" type="button" onclick="next_step()">Next Step<
/button>
</div>

Vous aimerez peut-être aussi