handle(); $err_message = array(); session_name('reservation'); session_start(); $date = isset($_GET['date']) ? $_GET['date'] : ''; $salon = isset($_GET['salon']) ? $_GET['salon'] : ''; if (empty($date) || empty($salon)) { require './html/error.html'; exit; } $_time = strtotime($date); $start = $date . ' 00:00:00'; $end = $date . ' 23:59:59'; $prev = 0; if (($_time - (24 * 60 * 60)) > (time() + (24 * 60 * 60 * 2))) { $prev = '?date=' . date('Y-m-d', ($_time - (24 * 60 * 60))) . '&salon=' . $salon; } $next = '?date=' . date('Y-m-d', ($_time + (24 * 60 * 60))) . '&salon=' . $salon; $today = date('Y年n月j日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ')'; $back = '?mode=hope1&year=' . date('Y', $_time) . '&m=' . date('n', $_time); $dummy_disp_hanni = time() + (86400 * 60) ; $_time_list[1] = array( '13:00', '15:30', '13:30', '16:00', '14:00', '16:30', '14:30', '17:00', '15:00', '17:30', ); $_time_list[2] = array( '11:00', '14:30', '11:30', '15:00', '12:00', '15:30', '12:30', '16:00', '13:00', '16:30', '13:30', '17:00', '14:00', ); $_time_list[3] = array( '11:00', '14:30', '11:30', '15:00', '12:00', '15:30', '12:30', '16:00', '13:00', '16:30', '13:30', '17:00', '14:00', ); $_time_list[4] = array( '11:00', '14:30', '11:30', '15:00', '12:00', '15:30', '12:30', '16:00', '13:00', '16:30', '13:30', '17:00', '14:00', ); $_time_list[5] = array( '11:00', '14:30', '11:30', '15:00', '12:00', '15:30', '12:30', '16:00', '13:00', '16:30', '13:30', '17:00', '14:00', ); $_time_list[6] = array( '11:00', '14:30', '11:30', '15:00', '12:00', '15:30', '12:30', '16:00', '13:00', '16:30', '13:30', '17:00', '14:00', ); $_time_list[101] = array( '13:00', '14:30', '13:30', '15:00', '14:00', '15:30', ); $_time_list[7] = array( '11:00', '14:30', '11:30', '15:00', '12:00', '15:30', '12:30', '16:00', '13:00', '16:30', '13:30', '17:00', '14:00', ); $sql = "SELECT * FROM local_reserves "; $sql .= "WHERE decide_date > ? "; $sql .= "AND decide_date < ? "; $sql .= "AND salon = ? "; $sql .= "AND switch IS TRUE "; $sql .= "ORDER BY decide_date ASC;"; $reserves = $db->getAll($sql, array($start, $end, $salon)); switch ($salon) { case 5 : $_salon = 1; break; case 2 : $_salon = 2; break; case 3 : $_salon = 4; break; case 4 : $_salon = 5; break; case 6 : $_salon = 3; break; default : $_salon = 0; } $calendars = array(); if ($_salon > 0) { $param = array( $_salon, $date, ); $sql = 'SELECT * FROM plu_salon_calendars '; $sql .= 'WHERE status NOT IN (9) '; $sql .= 'AND salon = ? '; $sql .= "AND to_char(start_date, 'yyyy-mm-dd') = ? "; $calendars = $db->getAll($sql, $param); } $time_list = array(); $holiday = isHoliday($date); $dm_idx = 0; $index_salon = $salon ; if( $salon == 1 and (date('w', $_time) == 0 or date('w', $_time) == 6)){ $index_salon = 101 ; } foreach ($_time_list[$index_salon] as $val) { $ng = 1; $_ary = array(); foreach ($reserves as $val2) { if (strtotime($val2['decide_date']) == strtotime($date . ' ' . $val)) { $ng = 0; } } foreach ($calendars as $val2) { if (date('H', strtotime($val2['start_date'])) == date('H', strtotime($date . ' ' . $val))) { $ng = 0; } } if ($salon == 6) { if (strtotime($date) <= mktime(0, 0, 0, 9, 1, 2015)) { $ng = 0; } } if ($salon == 7) { if (strtotime($date) <= mktime(0, 0, 0, 12, 1, 2015)) { $ng = 0; } if (in_array(date('w', $_time), array(3, 4))) { $ng = 0; } } /* if (($salon == 3) && (date('w', $_time) == 1)) { if ($holiday) { $ng = 0; } } */ if (($salon == 5) && in_array(date('w', $_time), array(1, 2))) { if ($holiday) { $ng = 0; } } if (($salon == 4) && in_array(date('w', $_time), array(1, 2))) { if ($holiday) { $ng = 0; } } /* if($salon == 1){ if (date('w', $_time) == 0 or date('w', $_time) == 6) { if ($val == '10:00' or $val == '10:30' or $val == '11:00' or $val == '11:30' or $val == '16:00' or $val == '16:30' or $val == '17:00' or $val == '17:30') { $ng = 0; } } } */ if($ng == 1 and $dummy_disp_hanni > $_time){ $ng = setDummyTime($date, $dm_idx, $_time, $salon); } $_ary['time'] = $val; $_ary['status'] = $ng; $_ary['query'] = '?mode=hope2&salon1=' . $salon . '&date1=' . $date . '&time1=' . $val; $time_list[] = $_ary; $dm_idx = $dm_idx + 1 ; } $i = 0; require './html/time1.html'; exit; function isHoliday($date) { $holidays_url = sprintf( 'http://www.google.com/calendar/feeds/%s/public/full-noattendees?start-min=%s&start-max=%s&max-results=%d&alt=json', 'outid3el0qkcrsuf89fltf7a4qbacgt9@import.calendar.google.com', // 'japanese@holiday.calendar.google.com', $date, date("Y-m-d", strtotime("$date +1 day")), 1 ); if ($results = file_get_contents($holidays_url)) { $results = json_decode($results); if (isset($results->feed->entry)) { return FALSE; } } return TRUE; } function setDummyTime($date, $dm_idx, $_time, $salon) { $def_dummy_rev_time = array('2,9','7,1','7,8','1,6','5,2','3,8','3,1','3,7','4,8','3,6','7,5'); $ng = 1; $day_idx = intval(date("j", $_time)) + intval($salon); //dummy予約 if($day_idx > 9){ $tmp_idx = substr((string)($day_idx), 1, 1) ; }else{ $tmp_idx = $day_idx ; } $tmp_ary = split(",",$def_dummy_rev_time[$tmp_idx]); if($tmp_ary[0] == $dm_idx or $tmp_ary[1] == $dm_idx){ $ng = 0; } return $ng; }