handle(); $err_message = array(); session_name('reservation'); session_start(); $_array = array( 'sdt', 'cur_salon_id', 'cur_year', 'cur_month', 'cur_day', 'date1', 'time1', 'date2', 'time2', 'date3', 'time3', 'salon1', 'salon2', 'salon3', 'name', 'kana', 'sex', 'mail', 'tel1', 'tel2', 'tel3', 'try_dress', 'comments', 'privchk', 'salon', 'site', 'hope_date', 'hope_date_ymd', 'hope_time'); foreach ($_GET as $key => $val) { if (!isset($_POST[$key])) { $_POST[$key] = $val; } } foreach ($_array as $val) { if (isset($_POST[$val])) { $_SESSION[$val] = $_POST[$val]; $data[$val] = $_SESSION[$val]; } else { if (isset($_SESSION[$val])) { $data[$val] = $_SESSION[$val]; } } } $hope_time = array( 0 => '----', 1 => '9時〜', 2 => '10時〜', 3 => '11時〜', 4 => '12時〜', 5 => '13時〜', 6 => '14時〜', 7 => 'サンセット', 8 => 'どの時間でも'); $coming_hope_time = array( 0 => '----', 1 => '11:00', 2 => '11:30', 3 => '12:00', 4 => '12:30', 5 => '13:00', 6 => '13:30', 7 => '14:00', 8 => '14:30', 9 => '15:00', 10 => '15:30', 11 => '16:00', 12 => '16:30', 13 => '17:00'); if (empty($data['salon1'])) { $data['salon1'] = !empty($_SESSION['salon']) ? $_SESSION['salon'] : 1; } if (empty($data['salon2'])) { $data['salon2'] = !empty($_SESSION['salon']) ? $_SESSION['salon'] : $data['salon1']; } if (empty($data['salon3'])) { $data['salon3'] = !empty($_SESSION['salon']) ? $_SESSION['salon'] : $data['salon1']; } $mode = isset($_POST['mode']) ? $_POST['mode'] : (isset($_GET['mode']) ? $_GET['mode'] : ''); $y = isset($_POST['y']) ? $_POST['y'] : (isset($_GET['y']) ? $_GET['y'] : date('Y', (time() + (24 * 60 * 60 * 2)))); $m = isset($_POST['m']) ? $_POST['m'] : (isset($_GET['m']) ? $_GET['m'] : date('n', (time() + (24 * 60 * 60 * 2)))); switch ($mode) { case 'input': _input(); break; case 'confirm': _confirm(); break; case 'regist': _regist(); break; //case 'hope1': // _hope1(); // break; //case 'hope2': // _hope2(); // break; //case 'hope3': // _hope3(); // break; //default: // _input(); // break; default: _calendar($data); } exit(); // --------------------------------------------- // 希望日1 // --------------------------------------------- function _hope1 () { global $data, $y, $m, $hope_time; $_time = mktime(0, 0, 0, $m, 1, $y); if ($_time > (time() + (24 * 60 * 60 * 2))) { $time = $_time; $prev['y'] = date('Y', mktime(0, 0, 0, $m - 1, 1, $y)); $prev['m'] = date('n', mktime(0, 0, 0, $m - 1, 1, $y)); $next['y'] = date('Y', mktime(0, 0, 0, $m + 1, 1, $y)); $next['m'] = date('n', mktime(0, 0, 0, $m + 1, 1, $y)); } else { $time = time() + (24 * 60 * 60 * 2); $prev['y'] = 0; $prev['m'] = 0; $next['y'] = date('Y', mktime(0, 0, 0, date('n', (time() + (24 * 60 * 60 * 2))) + 1, 1, date('Y', (time() + (24 * 60 * 60 * 2))))); $next['m'] = date('n', mktime(0, 0, 0, date('n', (time() + (24 * 60 * 60 * 2))) + 1, 1, date('Y', (time() + (24 * 60 * 60 * 2))))); } $calendar = createCalendar($time, $data['salon1']); require './html/hope1.html'; exit(); } // --------------------------------------------- // 希望日2 // --------------------------------------------- function _hope2 () { global $data, $y, $m, $hope_time; $_time = mktime(0, 0, 0, $m, 1, $y); if ($_time > (time() + (24 * 60 * 60 * 2))) { $time = $_time; $prev['y'] = date('Y', mktime(0, 0, 0, $m - 1, 1, $y)); $prev['m'] = date('n', mktime(0, 0, 0, $m - 1, 1, $y)); $next['y'] = date('Y', mktime(0, 0, 0, $m + 1, 1, $y)); $next['m'] = date('n', mktime(0, 0, 0, $m + 1, 1, $y)); } else { $time = time() + (24 * 60 * 60 * 2); $prev['y'] = 0; $prev['m'] = 0; $next['y'] = date('Y', mktime(0, 0, 0, date('n', (time() + (24 * 60 * 60 * 2))) + 1, 1, date('Y', (time() + (24 * 60 * 60 * 2))))); $next['m'] = date('n', mktime(0, 0, 0, date('n', (time() + (24 * 60 * 60 * 2))) + 1, 1, date('Y', (time() + (24 * 60 * 60 * 2))))); } $calendar = createCalendar($time, $data['salon2']); $_time = strtotime($_SESSION['date1'] . ' ' . $_SESSION['time1']); $hope1_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $_SESSION['time1']; require './html/hope2.html'; exit(); } // --------------------------------------------- // 希望日3 // --------------------------------------------- function _hope3 () { global $data, $y, $m, $hope_time; $_time = mktime(0, 0, 0, $m, 1, $y); if ($_time > (time() + (24 * 60 * 60 * 2))) { $time = $_time; $prev['y'] = date('Y', mktime(0, 0, 0, $m - 1, 1, $y)); $prev['m'] = date('n', mktime(0, 0, 0, $m - 1, 1, $y)); $next['y'] = date('Y', mktime(0, 0, 0, $m + 1, 1, $y)); $next['m'] = date('n', mktime(0, 0, 0, $m + 1, 1, $y)); } else { $time = time() + (24 * 60 * 60 * 2); $prev['y'] = 0; $prev['m'] = 0; $next['y'] = date('Y', mktime(0, 0, 0, date('n', (time() + (24 * 60 * 60 * 2))) + 1, 1, date('Y', (time() + (24 * 60 * 60 * 2))))); $next['m'] = date('n', mktime(0, 0, 0, date('n', (time() + (24 * 60 * 60 * 2))) + 1, 1, date('Y', (time() + (24 * 60 * 60 * 2))))); } $calendar = createCalendar($time, $data['salon3']); $_time = strtotime($_SESSION['date1'] . ' ' . $_SESSION['time1']); $hope1_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $_SESSION['time1']; $_time = strtotime($_SESSION['date2'] . ' ' . $_SESSION['time2']); $hope2_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $_SESSION['time2']; require './html/hope3.html'; exit(); } // --------------------------------------------- // 入力フォーム // --------------------------------------------- function _input () { global $data, $hope_time, $coming_hope_time; /* $_time = strtotime($_SESSION['date1'] . ' ' . $_SESSION['time1']); * $hope1_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $_SESSION['time1']; * $hope2_str = ''; * if (!empty($_SESSION['date2'])) { * $_time = strtotime($_SESSION['date2'] . ' ' . $_SESSION['time2']); * $hope2_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $_SESSION['time2']; * } * $hope3_str = ''; * if (!empty($_SESSION['date3'])) { * $_time = strtotime($_SESSION['date3'] . ' ' . $_SESSION['time3']); * $hope3_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $_SESSION['time3']; * } */ $_SESSION['sex'] = isset($_SESSION['sex']) ? $_SESSION['sex'] : 1; $_SESSION['time1'] = isset($_SESSION['time1']) ? $_SESSION['time1'] : 0; $_SESSION['time2'] = isset($_SESSION['time2']) ? $_SESSION['time2'] : 0; $_SESSION['time3'] = isset($_SESSION['time3']) ? $_SESSION['time3'] : 0; require './html/form.html'; exit(); } // --------------------------------------------- // カレンダー // --------------------------------------------- function _calendar () { global $data, $time, $hope_time; $data['cur_salon_id'] = agv($_SESSION, 'salon', 2); //$next_day = time() + 24 * 60 * 60; $next_day = time(); $data['cur_year'] = agv($_SESSION, 'cur_year', date('Y', $next_day)); $data['cur_month'] = agv($_SESSION, 'cur_month', date('m', $next_day)); $data['cur_day'] = agv($_SESSION, 'cur_day', date('d', $next_day)); $data['sdt'] = agv($_SESSION, 'sdt', ''); $data['gallery'] = _get_gallery(); require './html/calendar.html'; exit; } // --------------------------------------------- // 確認 // --------------------------------------------- function _confirm () { global $data, $hope_time, $coming_hope_time; $_time = strtotime($_SESSION['date1'] . ' ' . $coming_hope_time[$_SESSION['time1']]); $hope1_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $coming_hope_time[$_SESSION['time1']]; $hope2_str = ''; if (!empty($_SESSION['date2'])) { $_time = strtotime($_SESSION['date2'] . ' ' . $coming_hope_time[$_SESSION['time2']]); $hope2_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $coming_hope_time[$_SESSION['time2']]; } $hope3_str = ''; if (!empty($_SESSION['date3'])) { $_time = strtotime($_SESSION['date3'] . ' ' . $coming_hope_time[$_SESSION['time3']]); $hope3_str = date('m月d日', $_time) . '(' . $GLOBALS['WEEK'][date('w', $_time)] . ') ' . $coming_hope_time[$_SESSION['time3']]; } $hope_date = '未定'; if (!empty($_SESSION['hope_date'])) { $hope_date = date('Y年m月d日', strtotime($_SESSION['hope_date_ymd'])) . ' ' . $hope_time[$_SESSION['hope_time']]; } $_SESSION['salon2'] = $_SESSION['salon']; $_SESSION['salon3'] = $_SESSION['salon']; $err_message = array(); $err_message = _check_form(); if (count($err_message) > 0) { require './html/form.html'; exit(); } require './html/conf.html'; exit(); } // --------------------------------------------- // 登録 // --------------------------------------------- function _regist () { global $db, $data, $hope_time, $coming_hope_time; $db->autoCommit(false); $date1 = NULL; if (!empty($_SESSION['date1'])) { $date1 = date('Y-m-d H:i:s', strtotime($_SESSION['date1'] . ' ' . $coming_hope_time[$_SESSION['time1']])); //} else { // $_SESSION['salon'] = 0; } $date2 = NULL; if (!empty($_SESSION['date2'])) { $date2 = date('Y-m-d H:i:s', strtotime($_SESSION['date2'] . ' ' . $coming_hope_time[$_SESSION['time2']])); } else { $_SESSION['salon2'] = 0; } $date3 = NULL; if (!empty($_SESSION['date3'])) { $date3 = date('Y-m-d H:i:s', strtotime($_SESSION['date3'] . ' ' . $coming_hope_time[$_SESSION['time3']])); } else { $_SESSION['salon3'] = 0; } $_SESSION['site'] = isset($_SESSION['site']) ? $_SESSION['site'] : 0; $hope_date = '未定'; if (!empty($_SESSION['hope_date'])) { $hope_date = date('Y年m月d日', strtotime($_SESSION['hope_date_ymd'])) . ' ' . $hope_time[$_SESSION['hope_time']]; } $decide_date = NULL; if (!empty($_SESSION['sdt'])) { // date1も更新する $decide_date = $date1 = date('Y-m-d H:i:s', strtotime($_SESSION['sdt'])); } // entry $param = array( $_SESSION['name'], $_SESSION['kana'], $_SESSION['sex'], $_SESSION['mail'], $_SESSION['tel1'] . '-' . $_SESSION['tel2'] . '-' . $_SESSION['tel3'], $_SESSION['try_dress'], $_SESSION['comments'], $date1, $date2, $date3, $_SESSION['salon'], $_SESSION['salon2'], $_SESSION['salon3'], $_SESSION['site'], $hope_date, $decide_date, ); $sql = ''; $sql .= 'INSERT INTO local_reserves ( '; $sql .= ' status, name, kana, sex, mail, '; $sql .= ' tel, try_dress, comments, date1, date2, date3, '; $sql .= ' salon1, salon2, salon3, salon, switch, '; $sql .= ' site, hope_date, decide_date, updated, created '; $sql .= ' ) '; $sql .= ' VALUES (0,?,?,?,?, ?,?,?,?,?,?, ?,?,?,1,true, ?,?,?,now(),now()) '; $result = $db->query($sql, $param); if (DB::isError($result)) { $db->rollback(); print_r($result); $error_type = 2; require './html/error.html'; exit(); } $sql = "SELECT CURRVAL('local_reserves_seq_seq')"; $seq = $db->getRow($sql); if (DB::isError($seq)) { $db->rollback(); $error_type = 2; require './html/error.html'; exit(); } $seq = $seq['currval']; $salon = $GLOBALS['RESERVATION_SALON_TO_DRESS_SALON'][$_SESSION['salon']]; if ($salon > 0) { $end_date = date('Y-m-d H:i:00', strtotime($decide_date) + (1 * 60 * 60)); $sql = 'INSERT INTO plu_salon_calendars '; $sql .= '(start_date, end_date, status, salon, note, counseling) '; $sql .= 'VALUES (?, ?, 1, ?, ?, ?); '; $param = array( $decide_date, $end_date, $salon, 'カウンセリングの為予約不可', $seq, ); $result = $db->query($sql, $param); if (DB::isError($result)) { $db->rollback(); $error_type = 3; require './html/error.html'; exit; } } $db->commit(); _send($seq); $_SESSION = array(); session_destroy(); header('Location: http://www.royalkaila.com/s/reservation/finish.html'); exit(); } // --------------------------------------------- // メール送信 // --------------------------------------------- function _send ($seq) { global $data, $hope_time, $coming_hope_time; $date1 = '第一希望日なし'; $salon1 = '第一希望サロンなし'; if (!empty($_SESSION['date1'])) { $date1 = date('Y年m月d日 H時i分', strtotime($_SESSION['date1'] . ' ' . $coming_hope_time[$_SESSION['time1']])); $salon1 = $GLOBALS['RESERVATION_SALON'][$_SESSION['salon']]; } $date2 = '第二希望日なし'; $salon2 = '第二希望サロンなし'; if (!empty($_SESSION['date2'])) { $date2 = date('Y年m月d日 H時i分', strtotime($_SESSION['date2'] . ' ' . $coming_hope_time[$_SESSION['time2']])); $salon2 = $GLOBALS['RESERVATION_SALON'][$_SESSION['salon2']]; } $date3 = '第三希望日なし'; $salon3 = '第三希望サロンなし'; if (!empty($_SESSION['date3'])) { $date3 = date('Y年m月d日 H時i分', strtotime($_SESSION['date3'] . ' ' . $coming_hope_time[$_SESSION['time3']])); $salon3 = $GLOBALS['RESERVATION_SALON'][$_SESSION['salon3']]; } $hope_date = '未定'; if (!empty($_SESSION['hope_date'])) { $hope_date = date('Y年m月d日', strtotime($_SESSION['hope_date_ymd'])) . ' ' . $hope_time[$_SESSION['hope_time']]; } $decide_date = ''; if (!empty($_SESSION['sdt'])) { $decide_date = date('Y年m月d日 H:i', strtotime($_SESSION['sdt'])); $salon = $GLOBALS['RESERVATION_SALON'][$_SESSION['salon']]; } $try_dress = ''; if ($_SESSION['try_dress'] == '1') { $try_dress = 'ご試着を希望する'; } elseif ($_SESSION['try_dress'] == '2') { $try_dress = 'しない'; } $subject = '【Royal Kaila】国内サロンへの来店予約'; $fp = fopen(LOCAL_MAIL_SM_TEMPLATE, "r"); $msg = ""; while ($x = fgets($fp)) { $x = ereg_replace("%%NAME%%", $_SESSION['name'], $x); $x = ereg_replace("%%KANA%%", $_SESSION['kana'], $x); $x = ereg_replace("%%SEX%%", $_SESSION['sex'] == '1' ? '男性' : '女性', $x); $x = ereg_replace("%%TEL1%%", $_SESSION['tel1'], $x); $x = ereg_replace("%%TEL2%%", $_SESSION['tel2'], $x); $x = ereg_replace("%%TEL3%%", $_SESSION['tel3'], $x); $x = ereg_replace("%%MAIL%%", $_SESSION['mail'], $x); $x = ereg_replace("%%TRY_DRESS%%", $try_dress, $x); $x = ereg_replace("%%SALON%%", $salon, $x); $x = ereg_replace("%%DECIDE_DATE%%", $decide_date, $x); //$x = ereg_replace("%%DATE1%%", $date1, $x); //$x = ereg_replace("%%DATE2%%", $date2, $x); //$x = ereg_replace("%%DATE3%%", $date3, $x); //$x = ereg_replace("%%SALON1%%", $salon1, $x); //$x = ereg_replace("%%SALON2%%", $salon2, $x); //$x = ereg_replace("%%SALON3%%", $salon3, $x); $x = ereg_replace("%%HOPE_DATE%%", $hope_date, $x); $x = ereg_replace("%%COMMENTS%%", $_SESSION['comments'], $x); $msg .= $x; } mb_language("Japanese"); mb_internal_encoding("EUC-JP"); $return_mail = " -f " . ORDER_MAIL; mb_send_mail($_SESSION['mail'], $subject, $msg, "From:" . ORDER_MAIL, $return_mail); switch ($_SESSION['site']) { case '1': $subject = '【Royal Kaila Resort】国内サロンへの来店予約'; break; case '2': $subject = '【Royal Kaila Best】国内サロンへの来店予約'; break; case '3': $subject = '【Royal Kaila Location】国内サロンへの来店予約'; break; case '4': $subject = '【Royal Kaila Terrace】国内サロンへの来店予約'; break; case '5' : $subject = '【Premium Hawaii Beach Wedding】国内サロンへの来店予約'; break; default: break; } mb_send_mail(ORDER_MAIL, $subject, $msg, "From:" . $_SESSION['mail'], $return_mail); // mb_send_mail('08041376627@docomo.ne.jp', $subject, $msg, "From:" . 'info@exeo-japan.co.jp', $return_mail); //本多課長(エクシオからメール送信) mb_send_mail('takeshiyokohama8940@docomo.ne.jp', $subject, $msg, "From:" . 'info@exeo-japan.co.jp', $return_mail); //社長(エクシオからメール送信) mb_send_mail('suzukik@exeo-japan.jp', $subject, $msg, "From:" . 'info@exeo-japan.co.jp', $return_mail); //社長(エクシオからメール送信) } // --------------------------------------------- // 入力チェック // --------------------------------------------- function _check_form () { global $data; $err_message = array(); //// 第1希望日時 //if (empty($_SESSION['date1']) || ($_SESSION['time1'] == 0)) { // $err_message['date1'] = '第1希望日時を入力してください。'; //} //// 第2希望日時 //if (empty($_SESSION['date2']) || ($_SESSION['time2'] == 0)) { // $err_message['date2'] = '第2希望日時を入力してください。'; //} //// 第3希望日時 //if (empty($_SESSION['date3']) || ($_SESSION['time3'] == 0)) { // $err_message['date3'] = '第3希望日時を入力してください。'; //} // 撮影希望日時 if ($_SESSION['hope_date'] == 1) { if (empty($_SESSION['hope_date_ymd']) || ($_SESSION['hope_time'] == 0)) { $err_message['hope_date'] = '撮影希望日時を入力してください。'; } } // お名前 if (!$_SESSION['name']) { $err_message['name'] = 'お名前(漢字)を入力して下さい。'; } // フリガナ if (!$_SESSION['kana']) { $err_message['kana'] = 'お名前(フリガナ)を入力して下さい。'; } $_kana = mb_convert_encoding($_SESSION['kana'], 'UTF-8', 'eucJP-win'); $pattern = mb_convert_encoding("/[^ァ-ヶー  ]+/u", 'UTF-8', 'eucJP-win'); if (preg_match($pattern, $_kana)) { $err_message['kana'] = 'お名前(フリガナ)を全角カタカナで入力して下さい。'; } // メールアドレス if (!$_SESSION['mail']) { $err_message['mail'] = 'メールアドレスを入力して下さい。'; } else if (!preg_match('/^[a-zA-Z0-9_\.\-]+?@[A-Za-z0-9_\.\-]+$/', $_SESSION['mail'])) { $err_message['mail'] = 'メールアドレスを正しい形式で入力して下さい。'; } // お電話番号 if (!$_SESSION['tel1'] || !$_SESSION['tel2'] || !$_SESSION['tel3']) { $err_message['tel'] = 'お電話番号を入力して下さい。'; } else if (!preg_match("/^[0-9]{2,4}$/", $_SESSION['tel1']) || !preg_match("/^[0-9]{2,4}$/", $_SESSION['tel2']) || !preg_match("/^[0-9]{4}$/", $_SESSION['tel3'])) { $err_message['tel'] = 'お電話番号を正しい形式で入力して下さい。'; } // ドレス無料試着 if (!$_SESSION['try_dress']) { $err_message['try_dress'] = 'ドレス無料試着を選択してください。'; } elseif ($_SESSION['try_dress'] == '1') { if (in_array($_SESSION['salon'], array('1', '7', '8'))) { $err_message['try_dress'] = 'ご来店希望サロンでは、ドレス試着を承ることができません。'; } } if (!$_SESSION['privchk']) { $err_message['privchk'] = '「来店予約に関する個人情報の取扱い」に同意してください。'; } return $err_message; } function createCalendar ($_time, $salon) { $time = mktime(0, 0, 0, date('n', $_time), 1, date('Y', $_time)); $firstday = date('w', $time); $year = date('Y', $time); $month = date('n', $time); $calendar = array(); // 前月日曜日から1日まで $day = 0; while ($day < $firstday) { $_ary = array(); $_ary['date'] = ''; $_ary['class'] = ''; $_ary['status'] = 0; // 時間表示なし if ($day === 0) { $_ary['class'] = 'holi'; } $calendar[] = $_ary; $day++; } // 1日〜31日までループ for ($date = 1; $date <= 31; $date++) { if (checkdate($month, $date, $year) === TRUE) { $_time = mktime(0, 0, 0, $month, $date, $year); $_week = date('w', $_time); $_ary['date'] = $date; if ($_week == 0) { $_ary['class'] = 'holi'; } else if ($_week == 1) { $_ary['class'] = 'mon'; } else if ($_week == 2) { $_ary['class'] = 'mon'; } else if ($_week == 6) { $_ary['class'] = 'sat'; } else { $_ary['class'] = ''; } if (($month == 1) && ($date == 1)) { // 定休日:お正月 $_ary['class'] = 'holi'; $_ary['status'] = 0; // オンライン不可 } else { if ($_time < (time() + 2 * 24 * 60 * 60)) { // 2日以内 $_ary['status'] = 0; // オンライン不可 } else { // 通常のカレンダー表示 $_ary['status'] = 1; // オンライン予約可 $_ary['query'] = '?date=' . date('Y-m-d', $_time) . '&salon=' . $salon; } } $calendar[] = $_ary; } } $day = $_week; while ($day < 6) { $_ary = array(); $_ary['date'] = ''; $_ary['class'] = ''; $_ary['status'] = 0; // 時間表示なし if ($day == 5) { $_ary['class'] = 'sat'; } $calendar[] = $_ary; $day++; } return $calendar; } function _get_gallery() { global $db; $param = array(); $sql = 'SELECT * FROM local_reserves_gallery WHERE switch IS TRUE AND publish_date <= current_date ORDER BY publish_date DESC LIMIT 3; '; $gallery = $db->getAll($sql, $param); return $gallery; } function agv ($array, $key, $default = NULL) { return isset($array[$key]) ? $array[$key] : $default; } ?>