public function __construct() { global $mts_simple_booking; parent::__construct(); // CSSロード $mts_simple_booking->enqueue_style(); // 予約条件パラメータのロード $this->controls = get_option($this->domain . '_controls'); // 予約品目を読込む $this->articles = MTSSB_Article::get_all_articles(); // 本日0時0分のUNIX Time $this->today_time = strtotime(date_i18n('Y-n-j')); }
/** * 月間予約カレンダー出力 * */ 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 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; }
/** * スケジュール指定フォームの出力 */ private function _select_form() { // 全予約品目を取得する if (empty($this->articles)) { $this->articles = MTSSB_Article::get_all_articles(); } // 選択年月の上限・下限を求める $controls = get_option($this->domain . '_controls'); $this_year = date_i18n('Y'); $upyear = date_i18n('Y', mktime(0, 0, 0, date_i18n('n') + $controls['period'], 1, $this_year)) - $this_year; $downyear = $this_year - self::START_YEAR + 1; // ソート指定 $order = $this->set_order_key($_REQUEST); ?> <form method="get" action=""> <input type="hidden" name="page" value="<?php echo self::PAGE_NAME; ?> " /> <div id="list-condition-select"> <?php _e('Article:', $this->domain); ?> <select id="select_aid" class="select-article" name="aid"> <option value=""> </option> <?php foreach ($this->articles as $article_id => $article) { echo "<option value=\"{$article_id}\""; if ($article_id == $this->article_id) { echo ' selected="selected"'; } echo ">{$article['name']}</option>\n"; } ?> </select> <button class="button-secondary" name="action" value="select"><?php _e('Select Article', $this->domain); ?> </button> <?php echo $this->wpdate->date_form('select', 'select', $upyear, $downyear); ?> <button class="button-secondary" name="action" value="select"><?php _e('Change Date', $this->domain); ?> </button> </div> <div id="list-condition-out"> <button class="button-secondary" name="action" value="download"><?php _e('List Download', $this->domain); ?> </button> </div> <div class="clear"></div> <input id="list_key" type="hidden" name="orderby" value="<?php echo $order['key']; ?> "> <input id="list_direction" type="hidden" name="order" value="<?php echo $order['direction']; ?> "> </form> <?php // 前月・翌月リンクの表示 if (0 < $this->wpdate->month && $this->wpdate->day <= 0) { $this->_month_link(); } }
/** * ミックス予約カレンダー出力 * */ 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 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(); }
/** * 新規予約登録 予約品目の選択 * */ private function _select_article_page() { // 予約品目 $articles = MTSSB_Article::get_all_articles(); // 日付フォームオブジェクト生成、初期日付をセット $odate = new MTS_WPDate(); $odate->set_date(date_i18n('Y-n-j')); $article_id = key($articles); ?> <div class="wrap"> <?php screen_icon('edit'); ?> <h2><?php _e('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 } ?> <h3><?php _e('Select article', $this->domain); ?> </h3> <form id="select-article" method="get" action="<?php echo $_SERVER['REQUEST_URI']; ?> "> <input type="hidden" name="page" value="<?php echo self::PAGE_NAME; ?> " /> <table class="form-table" style="width: 100%"> <tr class="form-field"> <th> <?php _e('Booking Date', $this->domain); ?> </th> <td> <?php echo $odate->date_form('booking_new', 'bd'); ?> </td> </tr> <tr class="form-field"> <th> <?php _e('Booking Event', $this->domain); ?> </th> <td> <select id="booking-article" class="booking-select-article" name="article_id"> <?php foreach ($articles as $aid => $article) { echo "<option value=\"{$aid}\">{$article['name']}</option>\n"; } ?> </select> <select id="booking-time" class="booking-select-time" name="timetable"> <?php if (empty($articles[$article_id]['timetable'])) { echo '<option value="">' . __('Nothing', $this->domain) . "</option>\n"; } else { foreach ($articles[$article_id]['timetable'] as $time) { echo "<option value=\"{$time}\">" . date('H:i', $time) . "</option>\n"; } } ?> </select> <span id="loader-img" style="display:none"><img src="<?php echo $this->plugin_url . 'image/ajax-loader.gif'; ?> " alt="Loading" /></span> <input type="hidden" id="ajax-nonce" value="<?php echo wp_create_nonce('mtssb_get_timetable'); ?> "> </td> </tr> </table> <p><input class="button-secondary" type="submit" value="<?php _e('Add booking', $this->domain); ?> " /></P> </form> </div> <?php }
/** * 管理画面メニュー処理 * */ 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; }