/** * Constructor * */ public function __construct() { parent::__construct(); // Set nonce variables $this->module_name = basename(__FILE__, '.php'); $this->nonce_name = $this->module_name . '_nonce'; $this->nonce_timetable = $this->nonce_name . '_timetable'; // Register f**k procedure to save custom fields add_action('save_post', array($this, 'save_custom_fields')); // Register f**k procedure to display MTSBB Room list view add_filter("manage_edit-" . self::POST_TYPE . "_columns", array($this, 'get_column_titles')); // カスタム投稿タイプのedit.phpに表示するカスタムカラム処理のフック add_action('manage_posts_custom_column', array($this, 'out_custom_column')); // Load JavaScript at post.php add_action("admin_print_scripts-post.php", array($this, 'post_enqueue_script')); add_action("admin_print_scripts-post-new.php", array($this, 'post_enqueue_script')); // AJAX登録 add_action('wp_ajax_mtssb_get_timetable', array($this, 'ajax_get_the_timetable')); }
/** * 月間予約カレンダー出力 * */ public function monthly_calendar($atts) { // 予約受付終了状態 if (empty($this->controls['available'])) { return $this->controls['closed_page']; } // 日時の初期設定 $this->_ready_time(); // ショートコードパラメータの初期化 $params = shortcode_atts(array('id' => '-1', 'type' => 'table', 'class' => 'monthly-calendar', 'year' => $this->this_year, 'month' => $this->this_month, 'pagination' => '1', 'caption' => '1', 'link' => '1', 'weeks' => '', 'skiptime' => '0', 'href' => '', 'calendar_id' => ''), $atts); // 予約品目の取得 $this->articles = MTSSB_Article::get_all_articles($params['id']); if (empty($this->articles)) { return __('Not found any articles of reservation.', $this->domain); } // 日付が指定されたら当該日の予約表示をする if (isset($_GET['ymd']) && (!isset($_GET['cid']) || $_GET['cid'] == $params['calendar_id'])) { $daytime = intval($_GET['ymd']); $daytime = $daytime - $daytime % 86400; if ($this->today_time <= $daytime && $daytime < $this->max_time) { return $this->_daily_schedule($daytime, $params); } } // 対象年月 $theyear = intval($params['year']); $themonth = intval($params['month']); // ページ切り替え if (isset($_GET['ym']) && (!isset($_GET['cid']) || $_GET['cid'] == $params['calendar_id'])) { $ym = explode('-', $_GET['ym']); if (count($ym) == 2) { $theyear = $ym[0] > $ym[1] ? intval($ym[0]) : intval($ym[1]); $themonth = $ym[0] > $ym[1] ? intval($ym[1]) : intval($ym[0]); } } // 対象年月チェック $thetime = mktime(0, 0, 0, $themonth, 1, $theyear); if ($thetime < $this->this_time || $this->max_time <= $thetime) { $thetime = $this->this_time; $theyear = $this->this_year; $themonth = $this->this_month; } // 対象年月のスケジュールを読込む $key_name = MTS_Simple_Booking::SCHEDULE_NAME . date_i18n('Ym', $thetime); foreach ($this->articles as $article_id => $article) { $this->schedule[$article_id] = get_post_meta($article_id, $key_name, true); } // 対象年月の予約カウントデータを読込む $this->reserved = $this->get_reserved_count($theyear, $themonth); // 曜日データのローカライズ foreach ($this->weeks as $week) { $weeknames[] = __($week); } if ($params['weeks']) { $weeks = explode(',', $params['weeks']); if (count($weeks) == 7) { $weeknames = $weeks; } } $days = (mktime(0, 0, 0, $themonth + 1, 1, $theyear) - $thetime) / 86400; $starti = date('w', $thetime); $endi = $starti + $days + 5 - date('w', mktime(0, 0, 0, $themonth, $days, $theyear)); ob_start(); ?> <div class="<?php echo $params['class']; ?> "> <table> <?php if ($params['caption'] == 1) { $this->_caption($theyear, $themonth, $thetime); } ?> <tr> <?php for ($i = 0; $i < 7; $i++) { $week = strtolower($this->weeks[$i]); echo "<th class=\"week-title {$week}\">" . $weeknames[$i] . "</th>"; } ?> </tr> <?php for ($i = 0, $day = 1 - $starti; $i <= $endi; $i++, $day++) { // 行終了 if ($i % 7 == 0) { echo (0 < $i ? "</tr>\n" : '') . "<tr>\n"; } if (0 < $day && $day <= $days) { $ymdtime = mktime(0, 0, 0, $themonth, $day, $theyear); $this->_reservation_of_the_day($ymdtime, $params); } else { echo '<td class="day-box no-day"> </td>' . "\n"; } } ?> </table> <?php $this->_prev_next_link($theyear, $themonth, $params); ?> </div><!-- reservation-table --> <?php echo apply_filters('mtssb_monthly_message_after', '', $params['type']); ?> <?php return ob_get_clean(); }
/** * 予約キャンセル実行のお知らせメール * */ public function remove_mail() { global $mts_simple_booking; $booking = $mts_simple_booking->oSubscription->getBooking(); $article = MTSSB_Article::get_the_article($booking['article_id']); $content = "予約キャンセルが実行されました。\n\n" . "[キャンセル日時] " . date_i18n('Y-m-d H:i:s') . "\n" . "[予約ID] {$booking['booking_id']}\n" . "[予約] {$booking['client']['name']} 様\n" . date_i18n('Y年n月j日 H:i ', $booking['booking_time']) . $article['name'] . "\n"; $subject = "【予約キャンセル】"; $subject = apply_filters('mtssb_mail_own_subject', $subject, 'cancel'); $send_to = $this->shop['email']; $mail_ret = true; if (!empty($send_to)) { $mail_ret = wp_mail($send_to, $subject, $content, $this->fromshop); } return $mail_ret; }
/** * 管理画面メニュー処理 * */ public function schedule_page() { $this->errflg = false; $this->message = ''; // 予約品目の読み込み $this->articles = MTSSB_Article::get_all_articles(); if (empty($this->articles)) { $this->message = __('The exhibited reservation item data has nothing.', $this->domain); } $this->article_id = key($this->articles); $this->themonth = mktime(0, 0, 0, date_i18n('n'), 1, date_i18n('Y')); if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'schedule': $this->_schedule_parameter(intval($_GET['article_id']), intval($_GET['schedule_year']), intval($_GET['schedule_month'])); break; case 'save': if (wp_verify_nonce($_POST['nonce'], self::PAGE_NAME . '-save')) { $this->article_id = intval($_POST['article_id']); $this->_schedule_update(); $this->_schedule_parameter(intval($_POST['article_id']), intval($_POST['schedule_year']), intval($_POST['schedule_month'])); $this->message = __('Schedule has been saved.', $this->domain); } else { $this->errflg = true; $this->message = "Nonce error"; } break; default: $this->errflg = true; $this->message = "Unknown action"; break; } } // 対象年月のスケジュールデータの読み込み $key_name = MTS_Simple_Booking::SCHEDULE_NAME . date_i18n('Ym', $this->themonth); $this->schedule = get_post_meta($this->article_id, $key_name, true); ?> <div class="wrap"> <?php screen_icon('edit'); ?> <h2><?php _e('Schadule Management', $this->domain); ?> </h2> <?php if (!empty($this->message)) { ?> <div class="<?php echo $this->errflg ? 'error' : 'updated'; ?> "><p><strong><?php echo $this->message; ?> </strong></p></div> <?php } ?> <?php if (!empty($this->articles)) { ?> <?php $this->_select_form(); ?> <?php $this->_schedule_form(); ?> <?php } ?> </div><!-- wrap --> <?php return; }
public function booking_page($booking_id) { $booking = $this->get_booking($booking_id); // データを読込んで編集データbookingタイプにする $this->booking = $this->array_merge_default($this->new_booking(), $booking); if ($booking) { $article = MTSSB_Article::get_the_article($this->booking['article_id']); $daytime = $this->booking['booking_time'] - $this->booking['booking_time'] % 86400; $datestr = date(__('F j, Y'), $daytime) . ' (' . __(date('D', $daytime)) . ')'; } // 予約条件パラメータのロード $count = $this->controls['count']; ?> <div class="wrap"> <div id="icon-edit" class="icon32"><br /></div> <h2><?php _e('Reservation Calendar > Day > Booking', $this->domain); ?> </h2> <?php if (!empty($booking)) { ?> <ul class="subsubsub"> <li><?php echo '<a href="?page=' . self::PAGE_NAME . "&year=" . date('Y', $daytime) . "&month=" . date('n', $daytime) . '&action=monthly">' . __('Reservation Calendar', $this->domain) . '</a>'; ?> | </li> <li><?php echo '<a href="?page=' . self::PAGE_NAME . "&dt={$daytime}\">" . __('Reservation Day', $this->domain) . '</a>'; ?> | </li> <li><?php echo '<a href="?page=' . MTS_Simple_Booking::PAGE_BOOKING . "&booking_id={$this->booking['booking_id']}&action=edit\">" . __('Edit') . '</a>'; ?> | </li> <li><?php echo sprintf("<a href=\"?page=%s&action=delete&booking_id=%d&nonce=%s\" onclick=\"return confirm('%s')\">%s</a>", self::PAGE_NAME, $this->booking['booking_id'], wp_create_nonce(self::PAGE_NAME . '_delete'), __('Do you really want to delete this booking?', $this->domain), __('Delete')); ?> </li> </ul> <div class="clear"> </div> <h3><?php echo $datestr; ?> </h3> <table class="form-table booking-detail"> <tr> <th><?php _e('Article Name', $this->domain); ?> </th> <td><?php echo $article['name']; ?> </td> </tr> <tr> <th><?php _e('Date Time', $this->domain); ?> </th> <td><?php echo $datestr . date(' H:i', $this->booking['booking_time']); ?> </td> </tr> <tr> <th><?php _e('Number', $this->domain); ?> </th> <td><?php echo $this->booking['number']; ?> </td> </tr> <tr> <th><?php _e('Name'); ?> </th> <td><?php echo empty($this->booking['client']['name']) ? __('No Name', $this->domain) : esc_html($this->booking['client']['name']); ?> </td> </tr> <tr> <th><?php _e('Furigana', $this->domain); ?> </th> <td><?php echo esc_html($this->booking['client']['furigana']); ?> </td> </tr> <tr> <th><?php _e('E-Mail', $this->domain); ?> </th> <td><?php echo esc_html($this->booking['client']['email']); ?> </td> </tr> <tr> <th><?php _e('Postcode', $this->domain); ?> </th> <td><?php echo esc_html($this->booking['client']['postcode']); ?> </td> </tr> <tr> <th><?php _e('Address', $this->domain); ?> </th> <td><?php echo esc_html($this->booking['client']['address1']) . '<br />' . esc_html($this->booking['client']['address2']); ?> </td> </tr> <tr> <th><?php _e('TEL', $this->domain); ?> </th> <td><?php echo esc_html($this->booking['client']['tel']); ?> </td> </tr> <tr> <th><?php _e('Number', $this->domain); ?> </th> <td><?php foreach ($count as $key => $val) { echo '<div class="number-person">' . __(ucwords($key), $this->domain) . '<br />' . $this->booking['client'][$key] . '</div>'; } ?> </td> </td> </tr> <tr> <th><?php _e('Message', $this->domain); ?> </th> <td><?php echo nl2br(esc_html($this->booking['note'])); ?> </td> </tr> <tr> <th><?php _e('Created', $this->domain); ?> </th> <td><?php echo $booking['created']; ?> </td> </tr> </table> <?php } else { ?> <?php _e('No Data', $this->domain); } ?> </div> <?php }
/** * 予約リストからAJAXで予約確認処理実行 * */ protected function _confirm_booking($booking_id = 0) { // 予約データを取得する $booking = $this->get_booking($booking_id); if (!$booking) { return array('result' => false, 'message' => "{$booking_id} doesn't exist."); } $this->setBooking($booking); // 予約品目の取得 $article = MTSSB_Article::get_the_article($booking['article_id']); return array('result' => true, 'booking_id' => $booking_id, 'content' => $this->_out_booking($booking, $article), 'mailform' => $this->_out_mailform($booking, $article), 'tickimg' => '<img src="' . plugins_url('image/system-tick.png', __FILE__) . '">'); }
/** * 予約データの表示 * */ protected function _out_booking($booking) { // 表示ページのURL $page_url = get_permalink(); $this->booking = $booking; $client = $booking['client']; $this->article = MTSSB_Article::get_the_article($booking['article_id']); // キャンセルが有効か確認する $canceltime = $this->_check_cancel_limit(); ob_start(); ?> <div class="content-form"> <table> <tr> <th class="subscription-header"><form method="post" action="<?php echo $page_url; ?> "> <span class="subscription-title"> <?php echo apply_filters('booking_form_date', date('Y年n月j日 H:i', $booking['booking_time']), $booking['booking_time']); echo " {$this->article['name']}"; ?> </span> <?php if ($canceltime != 0) { echo '<span class="subscription-cancel">'; if (0 < $canceltime) { echo "<button id=\"subscription-cancel-button\" type=\"submit\" " . "onclick=\"return confirm('予約をキャンセルします。よろしいですか?')\">キャンセル</button>"; } else { echo apply_filters('subscription-cancel-limit-message', 'キャンセル受付終了'); } echo '</span>'; } ?> <input type="hidden" name="booking_id" value="<?php echo $booking['booking_id']; ?> " /> <input type="hidden" name="client_email" value="<?php echo $client['email']; ?> " /> <input type="hidden" name="nonce" value="<?php echo wp_create_nonce("{$this->domain}_" . self::PAGE_NAME); ?> " /> <input type="hidden" name="action" value="send" /> </form></th> </tr> <tr> <td><table> <tr> <th><?php echo apply_filters('booking_form_people_number', '予約人数', 'subscription'); ?> </th> <td> <?php foreach ($this->controls['count'] as $key => $val) { ?> <div class="input-number"<?php echo $val != 1 ? ' style="display:none"' : ''; ?> ><?php $title = apply_filters('booking_form_count_label', __(ucwords($key), $this->domain), 'subscription'); if ($title != '') { echo "{$title} "; } echo esc_html($client[$key]); echo apply_filters('booking_form_count_note', '', $key); ?> </div><?php } ?> </td> </tr> <?php // オプション先方指定の表示 if ($this->article['addition']->isOption() && $this->article['addition']->position == 0) { $this->_out_booking_option($booking); } // 連絡先の表示 $this->_out_booking_client($client); // オプション後方指定の表示 if ($this->article['addition']->isOption() && $this->article['addition']->position == 1) { $this->_out_booking_option($booking); } ?> <tr> <td colspan="2"><?php echo apply_filters('booking_form_message_title', 'ご連絡事項'); ?> </td> </tr> <tr> <th><?php echo apply_filters('booking_form_message_title_sub', '内容'); ?> </th> <td> <?php echo nl2br(esc_html($booking['note'])); ?> </td> </tr> <?php // 請求明細の表示 if ($this->charge['charge_list'] == 1) { $this->_out_booking_bill($this->article['addition']); } ?> </table></td> </tr> </table> </div> <?php return ob_get_clean(); }
/** * 予約完了エレメントの出力 * */ protected function _out_completed($content) { $tracking = ''; // nonceコードと予約IDが渡されたか確認する if (isset($_GET['nonce']) && isset($_GET['bid'])) { // 予約データと予約品目を取得する $booking = $this->get_booking(intval($_GET['bid'])); if (isset($booking['article_id'])) { $article = MTSSB_Article::get_the_article($booking['article_id']); } // 有効でトラッキングが指定されていれば出力コードを生成する if (isset($article['addition']->tracking)) { if (wp_verify_nonce($_GET['nonce'], 'affiliate' . $booking['booking_id'])) { // 予約IDを生成する $reserve_id = apply_filters('mtssb_thanks_reserve_id', date('ymd', $booking['booking_time']) . substr("00{$booking['booking_id']}", -3)); // トラッキングコードに予約IDを埋め込む $tracking = str_replace('%RESERVE_ID%', $reserve_id, $article['addition']->tracking); } } } // booking-thanksページ if (is_page(MTS_Simple_Booking::PAGE_BOOKING_THANKS)) { return $content . $tracking; } ob_start(); ?> <div class="info-message booking-completed"> ご予約ありがとうございました。 </div> <?php return ob_get_clean() . $tracking; }
/** * ミックス予約カレンダー出力 * */ public function mix_calendar($atts = array()) { // 予約受付終了状態 if (empty($this->controls['available'])) { return $this->controls['closed_page']; } // ショートコードパラメータの初期化 $this->params = shortcode_atts(array_merge($this->calendar->commonParams(), array('class' => 'mix-calendar', 'title' => '予約カレンダー', 'anchor' => 'mix-anchor', 'time' => 'row', 'drop_off' => '0', 'space_line' => '1', 'time_cell' => '1', 'linkurl' => $this->this_page)), $atts); // 予約カレンダー対象年月 $theyear = intval($this->params['year']); $themonth = intval($this->params['month']); // 予約品目の取得 $this->articles = MTSSB_Article::get_all_articles($this->params['id']); if (empty($this->articles)) { return __('Not found any articles of reservation.', $this->domain); } // 予約品目先頭のID $current_article = current($this->articles); $this->first_article_id = $current_article['article_id']; // カレンダーから日付リンクが指定された $link_daytime = 0; if (isset($_REQUEST['ymd']) && (!isset($_REQUEST['cid']) || $_REQUEST['cid'] == $this->params['calendar_id'])) { $link_daytime = intval($_REQUEST['ymd']); } // パラメータで年月日が指定された if (0 < $this->params['day']) { $link_daytime = mktime(0, 0, 0, $this->params['month'], $this->params['day'], $this->params['year']); } // 予約の日付が指定されたら時間割カレンダーを表示する。ただしWidgetの月表示を除く。 if ($this->params['widget'] != 1 && $link_daytime) { $calendar = $this->_day_mix_calendar($link_daytime); if ($calendar) { return $calendar; } } // フロントエンドからのページ切り替え if ($link_daytime) { $theyear = date_i18n('Y', $link_daytime); $themonth = date_i18n('n', $link_daytime); } elseif (isset($_REQUEST['utm'])) { $theyear = date_i18n('Y', intval($_REQUEST['utm'])); $themonth = date_i18n('n', intval($_REQUEST['utm'])); } elseif (isset($_REQUEST['ym'])) { $ym = explode('-', $_REQUEST['ym']); if (count($ym) == 2) { $theyear = $ym[0] > $ym[1] ? intval($ym[0]) : intval($ym[1]); $themonth = $ym[0] > $ym[1] ? intval($ym[1]) : intval($ym[0]); } } // 対象年月でなければ当月とする $this->calendar->calendarTime = mktime(0, 0, 0, $themonth, 1, $theyear); if (!$this->calendar->isMonthly($this->calendar->calendarTime)) { $this->calendar->calendarTime = $this->calendar->monthTime; $theyear = $this->calendar->thisYear; $themonth = $this->calendar->thisMonth; } // 対象年月の予約カウントデータを読込む $this->reserved = $this->get_reserved_count($theyear, $themonth); // カレンダー先頭のUnixtime $caltime = $this->calendar->calendarTime - (7 + date_i18n('w', $this->calendar->calendarTime) - $this->calendar->startOfWeek) % 7 * 86400; // カレンダー月翌月のUnixtime $nextime = mktime(0, 0, 0, $themonth + 1, 1, $theyear); // アンカー指定 $anchor = $this->params['anchor'] && !$this->params['widget'] ? sprintf(' id="%s"', $this->params['anchor']) : ''; ob_start(); ?> <div<?php echo sprintf('%s class="%s"', $anchor, $this->params['class']); ?> > <?php echo apply_filters('mtssb_calendar_before', '', array('cid' => $this->params['calendar_id'])); // タイトル表示 echo $this->view->calendarTitle($this->params); ?> <table> <?php // キャプション・月リンク表示 echo $this->view->captionPagination($this->params, $this->calendar); // 曜日ヘッダー表示 echo $this->view->weekHeader($caltime, $this->params['weeks']); // カレンダー表示 for ($i = 0; $caltime < $nextime || 0 < $i; $i = ($i + 1) % 7, $caltime += 86400) { if ($i == 0) { echo "<tr>\n"; } if ($caltime < $this->calendar->calendarTime || $nextime <= $caltime) { $this->_mixout_noday(); } else { $this->_mixout_daybox($caltime); } if ($i == 6) { echo "</tr>\n"; } } ?> </table> <?php if ($this->params['pagination'] == 1 || $this->params['pagination'] == 3) { echo $this->view->pagination($this->params, $this->calendar); } echo apply_filters('mtssb_calendar_after', '', array('cid' => $this->params['calendar_id'])); ?> </div> <?php return ob_get_clean(); }
/** * その他データのアップデート * */ private function _update_data($tbl_version) { global $wpdb; // スケジュールデータをoptionsからpostsへ移動する if ($tbl_version == '1.0' && '1.2' < self::VERSION) { // 予約品目を読込む $articles = MTSSB_Article::get_all_articles(); // 対象年月のスケジュールデータの読み込み $sql = "SELECT *\n\t\t\t\t\tFROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name REGEXP '{$this->domain}_[[:digit:]]{6}'\n\t\t\t\t\tORDER BY option_name"; $schedules = $wpdb->get_results($sql, ARRAY_A); // スケジュールデータのunserialize foreach ($schedules as &$schedule) { $schedule['option_value'] = unserialize($schedule['option_value']); } // 品目毎にスケジュールデータを移動する foreach ($articles as $article_id => $article) { foreach ($schedules as &$schedule) { $aid = 'A' . $article_id; // 当該品目のスケジュールデータがあればコピーする if (isset($schedule['option_value'][$aid])) { $data = $schedule['option_value'][$aid]; $key_name = MTS_Simple_Booking::SCHEDULE_NAME . substr($schedule['option_name'], 19); update_post_meta($article_id, $key_name, $data); } } } // optionsのスケジュールデータを削除する //foreach ($schedules as &$schedule) { // delete_option($schedule['option_name']); //} } }
/** * 予約データの料金を計算し料金データを戻す * */ public function make_bill() { $article_id = $this->booking['article_id']; $article = MTSSB_Article::get_the_article($article_id); if (empty($article)) { return null; } // 施設情報の読み込み $shop = get_option($this->domain . '_premise'); $charge = get_option($this->domain . '_charge'); $client = $this->booking['client']; // 勘定書データの作成 $bill = new MTS_Bill(); $bill->article_name = $article['name']; $bill->customer_name = $client['name']; $bill->shop_name = $shop['name']; // 人数の設定 $bill->number->adult = $client['adult']; $bill->number->child = $client['child']; $bill->number->baby = $client['baby']; // 通貨単位 $bill->currency_code = $charge['currency_code']; // 基本料金 $bill->basic_charge = $article['price']->booking; // 単価 $bill->amount->adult = $article['price']->adult; $bill->amount->child = $article['price']->child; $bill->amount->baby = $article['price']->baby; // 消費税方式・税率 $bill->tax_type = isset($charge['tax_notation']) ? $charge['tax_notation'] : 0; $bill->tax = isset($charge['consumption_tax']) ? $charge['consumption_tax'] : 0; // オプション料金 (予約品目にオプション使用が設定されている場合) $option_items = array(); if ($article['addition']) { foreach ($this->booking['options'] as $oOption) { $val = $oOption->getValue(); // オプション入力値 $number = $bill->get_number($oOption->whose); // オプション料金対象 if (!empty($val) && $number != 0) { $label = $oOption->getLabel(); // 日本語オプションラベル名 $price = $oOption->getPrice(); // オプション単価 $option_item = array(); switch ($oOption->getType()) { case 'number': // 全員が指定された場合は入力数を注文数とする if ($oOption->whose == 'all') { $number = $val; // それ以外は人数と入力数を比較し小さい方を注文数とする } else { $number = $val < $number ? $val : $number; } if ($price != 0) { $option_items[] = array('name' => $label, 'number' => $number, 'price' => $price); } break; case 'text': if ($price != 0) { $option_items[] = array('name' => $label, 'number' => $number, 'price' => $price); } break; case 'radio': case 'select': $fields = $oOption->getField(); // 料金設定されている場合は明細に追加する if (!empty($fields[$val]['price'])) { $option_items[] = array('name' => $label . ' ' . $fields[$val]['label'], 'number' => $number, 'price' => $fields[$val]['price']); } break; case 'check': $checks = explode(',', $val); $fields = $oOption->getField(); // 選択肢が料金設定されている場合は明細に追加する foreach ($checks as $check) { if (array_key_exists($check, $fields) && !empty($fields[$check]['price'])) { $option_items[] = array('name' => $label . ' ' . $fields[$check]['label'], 'number' => $number, 'price' => $fields[$check]['price']); } } break; //case 'date': 日付オプションは料金計算対象外とする //case 'date': 日付オプションは料金計算対象外とする default: break; } } } } $bill->option_items = $option_items; return $bill; }
/** * 月リスト予約カレンダー出力 * */ public function listMonthlyCalendar($atts) { // 予約受付終了状態 if (empty($this->controls['available'])) { return $this->controls['closed_page']; } // ショートコードパラメータの初期化 $this->params = shortcode_atts(array_merge($this->calendar->commonParams(), array('class' => 'list-monthly-calendar', 'title' => '予約カレンダー', 'xaxis' => '')), $atts); // カレンダーID指定の確認 if (isset($_GET['cid']) && $_GET['cid'] != $params['calendar_id']) { return ''; } // 予約日が指定された場合は時間割カレンダーを表示する $dayTime = $this->calendar->defDayTime($this->params); if ($dayTime) { return $this->_dayTimetable($dayTime); } // カレンダー表示月を決定する(yyyy年mm月1日) $this->calendar->defCalendarTime($this->params); // 予約品目の取得 $this->articles = MTSSB_Article::get_all_articles($this->params['id']); if (empty($this->articles)) { return __('Not found any articles of reservation.', $this->domain); } // 対象年月のスケジュールを読込む foreach ($this->articles as $articleId => &$article) { $key_name = MTS_Simple_Booking::SCHEDULE_NAME . date_i18n('Ym', $this->calendar->calendarTime); $article['schedule'] = get_post_meta($articleId, $key_name, true); } // 対象年月の予約カウントデータを読込む $this->reserved = $this->get_reserved_count($this->calendar->calendarYear, $this->calendar->calendarMonth); // アンカー指定 $anchor = $this->params['anchor'] && !$this->params['widget'] ? sprintf(' id="%s"', $this->params['anchor']) : ''; ob_start(); ?> <div<?php echo sprintf('%s class="%s"', $anchor, $this->params['class']); ?> > <?php echo apply_filters('mtssb_calendar_before', '', $this->params['calendar_id']); // タイトル表示 echo $this->view->calendarTitle($this->params); ?> <table> <?php // キャプション・月リンク表示 echo $this->view->captionPagination($this->params, $this->calendar); if (empty($this->params['xaxis'])) { $this->_articleInColumns(); } ?> </table> <?php if ($this->params['pagination'] == 1 || $this->params['pagination'] == 3) { echo $this->view->pagination($this->params, $this->calendar); } echo apply_filters('mtssb_calendar_after', '', $this->params['calendar_id']); ?> </div> <?php return ob_get_clean(); }
/** * 指定日付、予約品目の予約状況 */ public function booking_day_info($day_time, $article_id, $method) { $dayTime = $day_time - $day_time % 86400; // 指定日の予約数データを取得する $count = $this->get_reserved_day_count($dayTime); // 予約品目データを取得する $article = MTSSB_Article::get_the_article(intval($article_id)); // 対象年月のスケジュールを読込む $key_name = MTS_Simple_Booking::SCHEDULE_NAME . date_i18n('Ym', $dayTime); $schedule = get_post_meta($article_id, $key_name, true); $day = date_i18n('d', $dayTime); // 時間毎の予約数 $bookingTable = $this->_setCount($article_id, $article['restriction'], $article['timetable'], $dayTime, $count); // 保存の際のチェック用予約数データ要求 if ($method == 'data') { // 予約数の設定 return array('day_time' => $dayTime, 'booking_table' => $bookingTable, 'restriction' => $article['restriction'], 'max' => intval($article[$article['restriction']]), 'open' => isset($schedule[$day]['open']) ? intval($schedule[$day]['open']) : -1, 'delta' => isset($schedule[$day]['delta']) ? intval($schedule[$day]['delta']) : 0); } ob_start(); echo sprintf('<h3>%s</h3>', $article['name']); // 予約日 echo sprintf('<p><span class="booking-admin-header">予約日</span>:%s</p>', date_i18n('Y年n月j日 (D)', $dayTime)); // 受付数 echo sprintf('<p><span class="booking-admin-header">上限数</span>:%d</p>', $article[$article['restriction']]); // スケジュール echo '<p><span class="booking-admin-header">スケジュール</span>:'; if (isset($schedule[$day]['open'])) { echo sprintf('予約 [%s] 調整数 [%d] 注記 [%s]', $schedule[$day]['open'] ? '受付中' : '中止', $schedule[$day]['delta'], empty($schedule[$day]['note']) ? 'なし' : $schedule[$day]['note']); } else { echo '未設定です。'; } echo '</p>'; // 時間割予約済み数 echo '<table>'; echo '<tr><th class="booking-admin-time">時間</th><th class="booking-admin-count">予約数</th></tr>'; foreach ($bookingTable as $hour => $number) { echo sprintf('<tr><td>%s</td><td>%d</td></tr>', date('H:i', $hour), $number); } return ob_get_clean(); }
/** * 予約受付の日時、対象品目の確認 * */ protected function _booking_acceptance() { // 予約受付中か確認 if ($this->controls['available'] != 1) { $this->err_message = $this->_err_message('UNAVAILABLE'); return false; } // 予約受付期間内か確認 if ($this->thetime < $this->start_time || $this->max_time <= $this->thetime) { $this->err_message = $this->_err_message('OUT_OF_PERIOD'); return false; } // 予約スケジュールデータを取得する $key_name = MTS_Simple_Booking::SCHEDULE_NAME . date_i18n('Ym', $this->thetime); $schedule = get_post_meta($this->article_id, $key_name, true); // スケジュールが登録されており予約を受け付けているか確認する $day = date_i18n('d', $this->thetime); if (!empty($schedule[$day])) { $this->schedule = $schedule[$day]; if ($this->schedule['open'] != 1) { $this->err_message = $this->_err_message('UNACCEPTABLE_DAY'); return false; } } else { // スケジュールが登録されていない場合 $this->err_message = $this->_err_message('UNAVAILABLE'); return false; } // 予約品目データを取得する $this->article = MTSSB_Article::get_the_article($this->article_id); // 予約時間の確認 if (!in_array($this->thetime % 86400, $this->article['timetable'])) { $this->err_message = $this->_err_message('UNACCEPTABLE_TIME'); return false; } // オプション有無の処理セット(オプション利用指定かつオプションデータ有) if ($this->article['addition'] && !empty($this->option)) { $this->option_available = true; } return true; }
/** * 管理画面メニュー処理 * */ public function booking_page() { $this->errflg = false; $this->message = ''; // 予約品目 $this->articles = MTSSB_Article::get_all_articles(); if (isset($_POST['action'])) { $action = $_POST['action']; if (!wp_verify_nonce($_POST['nonce'], self::PAGE_NAME . "_{$action}")) { die("Nonce error!"); } // 予約データを正規化し、登録データを取得する $this->booking = $this->normalize_booking($_POST['booking']); switch ($action) { case 'add': $booking_id = $this->add_booking(); if ($booking_id) { $this->message = __('Booking data has been added.', $this->domain); $this->booking = $this->new_booking($this->booking['booking_time'] - $this->booking['booking_time'] % 86400, $this->booking['article_id']); } else { $this->message = __('Booking data has been failed to add.', $this->domain); $this->errflg = true; } break; case 'save': $booking_id = $this->save_booking(); if ($booking_id) { $this->message = __('Booking data has been saved.', $this->domain); $this->booking['booking_id'] = $booking_id; } else { $this->message = __('Booking data has been failed to save.', $this->domain); $this->errflg = true; } break; default: break; } } else { if (isset($_GET['action']) && $_GET['action'] == 'edit') { // 格納データを操作データオブジェクトに移す $this->booking = $this->array_merge_default($this->new_booking(), $this->get_booking(intval($_REQUEST['booking_id']))); } else { $daytime = isset($_GET['dt']) ? intval($_GET['dt']) : 0; $article_id = isset($_GET['article_id']) ? intval($_GET['article_id']) : 0; $this->booking = $this->new_booking($daytime, $article_id); } } $action = $this->booking['booking_id'] ? 'save' : 'add'; ?> <div class="wrap columns-2"> <?php screen_icon('edit'); ?> <h2><?php echo $action == 'save' ? __('Edit Booking', $this->domain) : __('Add Booking', $this->domain); ?> </h2> <?php if (!empty($this->message)) { ?> <div class="<?php echo $this->errflg ? 'error' : 'updated'; ?> "><p><strong><?php echo $this->message; ?> </strong></p></div> <?php } ?> <form id="add-booking" method="post" action="?page=<?php echo self::PAGE_NAME; ?> "> <div id="poststuff"> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <?php $this->_postbox_booking(); ?> </div> <div id="postbox-container-1" class="postbox-container"> <!-- div id="side-sortables" class="meta-box-sortables ui-sortable" --> <div id="addsubmitdiv" class="postbox"> <h3><?php echo $action == 'save' ? __('Edit Booking', $this->domain) : __('Add Booking', $this->domain); ?> </h3> <div class="inside"> <div id="minor-publishing"> <div id="misc-publishing-actions"> <div class="misc-pub-section"> <label for="booking-confirmed"><?php _e('Booking Confirmation:', $this->domain); ?> </label> <input type="hidden" name="booking[confirmed]" value="0" /> <input id="booking-confirmed" type="checkbox" name="booking[confirmed]" value="1"<?php echo $this->booking['confirmed'] ? ' checked="checked"' : ''; ?> /> </div> </div> </div> <div id="major-publishing-actions"> <?php if ($action == 'save') { ?> <div id="delete-action"> <a href="?page=simple-booking-list&booking_id=<?php echo $this->booking['booking_id']; ?> &action=delete&nonce=<?php echo wp_create_nonce('simple-booking-list_delete'); ?> " onclick="return confirm('<?php _e('Do you really want to delete this booking?', $this->domain); ?> ')"><?php _e('Delete'); ?> </a> </div><?php } ?> <div id="publishing-action"> <input id="publish" class="button-primary" type="submit" value="<?php echo $action == 'save' ? __('Save Booking', $this->domain) : __('Add Booking', $this->domain); ?> " name="save"> </div> <div class="clear"> </div> </div> <div class="clear"> </div> </div> </div> <!-- /div --> </div> <div id="postbox-container-2" class="postbox-container"> <?php $this->_postbox_options(); ?> <?php $this->_postbox_client(); ?> <?php $this->_postbox_note(); ?> </div> </div> </div> <input type="hidden" name="action" value="<?php echo $action; ?> " /> <input type="hidden" name="nonce" value="<?php echo wp_create_nonce(self::PAGE_NAME . "_{$action}"); ?> " /> </form> </div><!-- wrap --> <?php return; }
public function booking_page($booking_id) { global $mts_simple_booking; $this->booking = $booking = $this->get_booking($booking_id); // データを読込んで編集データbookingタイプにする //$this->booking = $this->array_merge_default($this->new_booking(), $booking); if ($booking) { $article = MTSSB_Article::get_the_article($booking['article_id']); $daytime = $booking['booking_time'] - $booking['booking_time'] % 86400; $datestr = date_i18n(__('F j, Y'), $daytime) . ' (' . __(date_i18n('D', $daytime)) . ')'; } // 予約条件パラメータのロード $count = $this->controls['count']; // 支払データのロード $charge = get_option($this->domain . '_charge'); if ($charge['charge_list']) { $bill = $this->make_bill(); $currency = ' ' . ($bill->currency_code == 'JPY' ? __('Yen', $this->domain) : __('US dollar', $this->domain)); } ?> <div class="wrap"> <div id="icon-edit" class="icon32"><br /></div> <h2><?php _e('Reservation Calendar > Day > Booking', $this->domain); ?> </h2> <?php if (!empty($booking)) { ?> <ul class="subsubsub"> <li><?php echo '<a href="?page=' . self::PAGE_NAME . "&year=" . date_i18n('Y', $daytime) . "&month=" . date_i18n('n', $daytime) . '&action=monthly">' . __('Reservation Calendar', $this->domain) . '</a>'; ?> | </li> <li><?php echo '<a href="?page=' . self::PAGE_NAME . "&dt={$daytime}\">" . __('Reservation Day', $this->domain) . '</a>'; ?> | </li> <li><?php echo '<a href="?page=' . MTS_Simple_Booking::PAGE_BOOKING . "&booking_id={$booking['booking_id']}&action=edit\">" . __('Edit') . '</a>'; ?> | </li> <li><?php echo sprintf("<a href=\"?page=%s&action=delete&booking_id=%d&nonce=%s\" onclick=\"return confirm('%s')\">%s</a>", self::PAGE_NAME, $booking['booking_id'], wp_create_nonce(self::PAGE_NAME . '_delete'), __('Do you really want to delete this booking?', $this->domain), __('Delete')); ?> </li> </ul> <div class="clear"> </div> <h3><?php echo $datestr; ?> </h3> <table class="form-table booking-detail"> <tr> <th><?php _e('Article Name', $this->domain); ?> </th> <td><?php echo $article['name']; ?> </td> </tr> <tr> <th><?php _e('Date Time', $this->domain); ?> </th> <td><?php echo $datestr . date_i18n(' H:i', $booking['booking_time']); ?> </td> </tr> <tr> <th><?php _e('Number', $this->domain); ?> </th> <td><?php echo $booking['number']; ?> </td> </tr> <tr> <th><?php _e('Options', $this->domain); ?> </th> <td><?php foreach ($booking['options'] as $option) { echo $option->getLabel() . ' : '; echo $option->type == 'textarea' ? nl2br(esc_textarea($option->getText())) : esc_html($option->getText()); echo '<br />'; } ?> </td> </tr> <tr> <th><?php _e('Company', $this->domain); ?> </th> <td><?php echo esc_html($booking['client']['company']); ?> </td> </tr> <tr> <th><?php _e('Name'); ?> </th> <td><?php echo empty($booking['client']['name']) ? __('No Name', $this->domain) : esc_html($booking['client']['name']); ?> </td> </tr> <tr> <th><?php _e('Furigana', $this->domain); ?> </th> <td><?php echo esc_html($booking['client']['furigana']); ?> </td> </tr> <?php if ($booking['client']['birthday']->isSetDate()) { ?> <tr> <th><?php _e('Birthday', $this->domain); ?> </th> <td><?php echo $booking['client']['birthday']->get_date('j'); ?> </td> </tr><?php } ?> <?php if (!empty($booking['client']['gender'])) { ?> <tr> <th><?php _e('Gender', $this->domain); ?> </th> <td><?php echo $booking['client']['gender'] == 'male' ? __('Male', $this->domain) : __('Female', $this->domain); ?> </td> </tr><?php } ?> <tr> <th><?php _e('E-Mail', $this->domain); ?> </th> <td><?php echo esc_html($booking['client']['email']); ?> </td> </tr> <tr> <th><?php _e('Postcode', $this->domain); ?> </th> <td><?php echo esc_html($booking['client']['postcode']); ?> </td> </tr> <tr> <th><?php _e('Address', $this->domain); ?> </th> <td><?php echo esc_html($booking['client']['address1']) . '<br />' . esc_html($booking['client']['address2']); ?> </td> </tr> <tr> <th><?php _e('TEL', $this->domain); ?> </th> <td><?php echo esc_html($booking['client']['tel']); ?> </td> </tr> <tr> <th><?php echo apply_filters('booking_form_newuse', __('Newuse', $this->domain), 'admin'); ?> </th> <td><?php echo empty($booking['client']['newuse']) ? '' : ($booking['client']['newuse'] == 1 ? apply_filters('booking_form_newuse_yes', __('Yes')) : apply_filters('booking_form_newuse_no', __('No'))); ?> </td> </tr> <tr> <th><?php _e('Number', $this->domain); ?> </th> <td><?php foreach ($count as $key => $val) { echo '<div class="number-person">' . apply_filters('booking_form_count_label', __(ucwords($key), $this->domain), 'calendar_admin') . '<br />' . $booking['client'][$key] . '</div>'; } ?> </td> </td> </tr> <tr> <th><?php _e('Message', $this->domain); ?> </th> <td><?php echo nl2br(esc_html($booking['note'])); ?> </td> </tr> <?php if ($charge['charge_list']) { ?> <tr> <th><?php _e('Bill', $this->domain); ?> </th> <td> <table> <tr> <th class="bill-th">明細</th> <td class="bill-td"> <table class="bill-details"> <?php // 予約料金の表示 if (0 < $bill->basic_charge) { $name = apply_filters('booking_form_charge_booking', $bill->article_name . ' 料金', 'calendar_admin'); $this->_out_bill_row($name, 1, $bill->basic_charge, $currency); } // 人数料金の表示 foreach (array('adult', 'child', 'baby') as $type) { if ($bill->number->{$type} != 0) { $name = apply_filters('booking_form_charge_count', $bill->article_name . ' ', 'calendar_admin') . apply_filters('booking_form_count_label', __(ucwords($type), $this->domain), 'calendar_admin'); $this->_out_bill_row($name, $bill->number->{$type}, $bill->amount->{$type}, $currency); } } // オプション料金の表示 foreach ($bill->option_items as $item) { $this->_out_bill_row($item['name'], $item['number'], $item['price'], $currency); } ?> </table> </td> <tr> <?php if (0 < $charge['tax_notation']) { ?> <th class="bill-th">合計</th> <td class="bill-td"><div class="bill-total"><?php echo number_format($bill->get_total()) . $currency; ?> </div></td> </tr> <tr> <th class="bill-th"><?php echo $charge['tax_notation'] == 1 ? '内' : ''; ?> 消費税(<?php echo $bill->tax; ?> %)</th> <td class="bill-td"><div class="bill-tax"><?php echo number_format($bill->get_amount_tax($charge['tax_notation'] == 1)) . $currency; ?> </div></td> </tr> <tr><?php } ?> <th class="bill-th">総合計</th> <td class="bill-td"><div class="bill-total"><?php echo number_format($bill->get_total() + ($charge['tax_notation'] == 1 ? 0 : $bill->get_amount_tax())) . $currency; ?> </div></td> </tr> </table> </td> </tr> <tr> <th><?php _e('PayPal Transaction ID', $this->domain); ?> </th> <td><?php echo isset($booking['client']['transaction_id']) ? $booking['client']['transaction_id'] : ''; ?> </td> </tr><?php } ?> <tr> <th><?php _e('Created', $this->domain); ?> </th> <td><?php echo $booking['created']; ?> </td> </tr> <tr> <th><?php _e('User Agent', $this->domain); ?> </th> <td><?php echo isset($booking['client']['user_agent']) ? esc_html($booking['client']['user_agent']) : ''; ?> </td> </tr> <tr> <th><?php _e('Remote Address', $this->domain); ?> </th> <td><?php echo isset($booking['client']['remote_addr']) ? esc_html($booking['client']['remote_addr']) : ''; ?> </td> </tr> </table> <?php } else { ?> <?php _e('No Data', $this->domain); } ?> </div> <?php }