book

				$format = <<<EOD
<form id="reservation" class="reservation" method="post" action="%FORMACTION%">
<dl>
<dt>%LABEL_ID%:</dt>
<dd>%ID% {$already_reserved} {$free}
<input type="hidden" id="reserve_id" name="reserve_id" value="%ID%" />
<dt>%LABEL_ROOM%:</dt>
<dd>%ROOM_NAME%
<input type="hidden" id="room_id" name="room_id" value="%ROOM_ID%" />
</dd>
<dt>%LABEL_USER%:</dt>
<dd>%USER_NAME%(Skype: %USER_SKYPE%)
<input type="hidden" id="user_id" name="user_id" value="%USER_ID%" />
</dd>
<dt>%LABEL_DATETIME%:</dt>
<dd>%DATETIME%
<input type="hidden" id="reservedate" name="reservedate" value="%DATE%" />
<input type="hidden" id="reservetime" name="reservetime" value="%TIME%" />
</dd>



<!--added by ye 20181018 start-->
<style type="text/css">
	#big_category {
		display: none;
	}     
	#small_category {
		display: none;
	}                                
</style>


<dt>%LABEL_LESSONTYPE%:</dt>
<dd>
<input type="radio" name="lesson_type" value="0">%DEFAULT_LESSON%<br>
<input type="radio" name="lesson_type" value="1"> %TEXT_LESSON%<br>
<input type="radio" name="lesson_type" value="2"> %FREETALK_LESSON%<br>
<input type="radio" name="lesson_type" value="3"> %OTHERLINK_LESSON%<br>
<input type="radio" name="lesson_type" value="4"> %OTHER_LESSON%
</dd>
<br>
</dl>

<div id="categories">

</div>

<div id="big_category">
<p>%BIG_CATEGORY%:</p>
<select id="big_select">
</select>
</div>


<div id="posts_list" style="display:none"></div>

<div id="small_category" style="display:none">
<p>%SMALL_CATEGORY%:</p>
<select id="small_select">
  <option value="101">scate01</option>
  <option value="102">scate01</option>
  <option value="103">scate01</option>
  <option value="104">scate01</option>
</select>
</div>

<!--added by ye 20181018 end-->
<br>

%NONCE%
<input type="hidden" id="reserveaction" name="reserveaction" value="%ACTION%" />
<input type="submit" id="reservesubmit" name="reservesubmit" value="%SUBMIT%" class="{$btnclass}" />
EOD;

				if($message_key) {
					$format .= '<div class="alert alert-success">%MESSAGE%</div>';
				}
				$format .= '</form>';

				$search = array(
						'%FORMACTION%',
						'%LABEL_ID%',
						'%ID%',
						'%LABEL_ROOM%',
						'%ROOM_NAME%',
						'%ROOM_ID%',
						'%LABEL_USER%',
						'%USER_NAME%',
						'%USER_ID%',
						'%USER_SKYPE%',
						'%LABEL_DATETIME%',
						'%DATETIME%',
						'%DATE%',
						'%TIME%',
						'%NONCE%',
						'%ACTION%',
						'%SUBMIT%',
						'%MESSAGE%',
						'%LABEL_LESSONTYPE%',
						'%DEFAULT_LESSON%',
						'%TEXT_LESSON%',
						'%FREETALK_LESSON%',
						'%OTHERLINK_LESSON%',
						'%OTHER_LESSON%',

					);
				$replace = array(
						$formaction,
						__('Reserve ID', OLBsystem::TEXTDOMAIN),
						$reserve_id,
						__('Teacher', OLBsystem::TEXTDOMAIN),
						sprintf('<a href="%s">%s</a>', $room['url'], $room['name']),
						$olb->room_id,
						__('User', OLBsystem::TEXTDOMAIN),
						$olb->operator->data['name'],
						$olb->operator->data['id'],
						$olb->operator->data['skype'],
						__('Date/Time', OLBsystem::TEXTDOMAIN),
						sprintf( '%s %s', $date, substr( $time, 0, 5 ) ),
						$date,
						$time,
						wp_nonce_field(OLBsystem::TEXTDOMAIN, 'onetimetoken', true, false),
						$action,
						$submit,
						olbFunction::showMessage($message_key),
						__('Lesson Type', OLBsystem::TEXTDOMAIN),
						__('Default Lesson', OLBsystem::TEXTDOMAIN),
						__('Text Lesson', OLBsystem::TEXTDOMAIN),
						__('Freetalk Lesson', OLBsystem::TEXTDOMAIN),
						__('Otherlink Lesson', OLBsystem::TEXTDOMAIN),
						__('Other Lesson', OLBsystem::TEXTDOMAIN),
					);
				echo str_replace($search, $replace, $format);
			}
			// エラーあり: from canReservation()
			else {
				$error = $code;
			}
		}
jQuery(document).ready(function($){
	// コマ
	$("table.edit_schedule tr.valid>td.status").on("click", function() {
		if(!$(this).hasClass('past')){
			if($(this).hasClass('open')){
				$(this).removeClass('open');
				$(this).addClass('closed');
				$(this).children('input[name^="new"]').val('close');
			}
			else if($(this).hasClass('closed')){
				$(this).removeClass('closed');
				$(this).addClass('open');
				$(this).children('input[name^="new"]').val('open');
			}
		}
	})
	// 曜日
	$("table.edit_schedule tr.head>th").on("click", function() {
		var wname = $(this).attr('class');
		var opened = $('tr.valid>td').filter('.'+wname).filter('.open');
		var closed = $('tr.valid>td').filter('.'+wname).filter('.closed').filter(function(index){
				if(!$(this).hasClass('past')){
					return true;
				}
			});
		if(opened.length == 0 || (closed.length != 0 && closed.length < opened.length)){
			$(closed).removeClass('closed');
			$(closed).addClass('open');
			$(closed).children('input[name^="new"]').val('open');
		}
		else {
			$(opened).removeClass('open');
			$(opened).addClass('closed');
			$(opened).children('input[name^="new"]').val('close');
		}
	})
	// 時間
	$("table.edit_schedule tr.valid>.times").on("click", function() {
		var opened = $(this).parent().children('td').filter('.open');
		var closed = $(this).parent().children('td').filter('.closed').filter(function(index){
				if(!$(this).hasClass('past')){
					return true;
				}
			});

		if(opened.length == 0 || (closed.length != 0 && closed.length < opened.length)){
			$(closed).removeClass('closed');
			$(closed).addClass('open');
			$(closed).children('input[name^="new"]').val('open');
		}
		else {
			$(opened).removeClass('open');
			$(opened).addClass('closed');
			$(opened).children('input[name^="new"]').val('close');
		}
	})

/*
<input type="radio" name="lesson_type" value="0">%DEFAULT_LESSON%<br>
<input type="radio" name="lesson_type" value="1"> %TEXT_LESSON%<br>
<input type="radio" name="lesson_type" value="2"> %FREETALK_LESSON%<br>
<input type="radio" name="lesson_type" value="3"> %OTHERLINK_LESSON%<br>
<input type="radio" name="lesson_type" value="4"> %OTHER_LESSON%
 */
	$('input[type="radio"][name=lesson_type]').on('click', function(e) {
		var lessonType = $('input[name=lesson_type]:checked', '#reservation').val();
		alert(lessonType);
		if(!$.isNumeric(lessonType)){
			alert("Please choose one");
		}else{
			numType = parseInt(lessonType, 10);
		}
		switch(numType){
		case 1:
		    //show current lesson
		    break;
		case 2:
		    var mes = 'We are the world!!';
		    $.ajax({
		        type: 'POST',
		        url: ajaxurl,
		        data: {
		            'action' : 'view_mes',
		            'mes' : mes,
		        },
		        success: function( response ){
        			$('#big_category').css('display', 'block');
        			$('#big_select').append(response);
		            //alert( response );
		        }
		    });
		    //show directory and text title;
		    break;
		case 3:
		alert("case 3");
	        $.ajax({
	            type: 'POST',
	            url: ajaxurl,
	            data: {
	                'action' : 'my_ajax_get_posts',
	            },
	            success: function( response ){
	                jsonData = JSON.parse( response );
	                $.each( jsonData, function( i, val ){
	                    alert( val['post_title'] );
	                    alert( val['permalink'] );
	                });
	            }
	        });
		    break;
		case 4:
		    //show input text
		    break;
		case 5:
		    //show des
		    break;
		default:
		   	break;
		}
	});

	$('select[id=big_select]').change(function() {
		var bCat = $('#big_select').val();

		    // $.ajax({
		    //     type: 'POST',
		    //     url: ajaxurl,
		    //     data: {
		    //         'action' : 'view_posts',
		    //         'bCat' : bCat,
		    //     },
		    //     success: function( response ){
      //   			$('#posts_list').css('display', 'block');
      //   			$('#posts_list').append(response);
		    //         //alert( response );
		    //     }
		    // });
	        $.ajax({
	            type: 'POST',
	            url: ajaxurl,
	            data: {
	                'action' : 'my_ajax_get_posts',
		            'bCat' : bCat,
	            },
	            success: function( response ){
	                jsonData = JSON.parse( response );
					postsHtml ="<ul>";
	                $.each( jsonData, function( i, val ){
	                    alert( val['post_title'] );
	                    alert( val['permalink'] );
						postsHtml += '<li><a href="' + val['permalink'] + ')" target="_blank">' + val['post_title'] + '</a></li>';
	                });
					postsHtml +="</ul>";
        			$('#posts_list').append(postsHtml);
        			$('#posts_list').css('display', 'block');
	            }
	        });
	});


	// $('input[type="radio"][name=lesson_type]').on('change', function(e) {
	// 	alert($('input[type="radio"][name=lesson_type]:checked').val());
	//     console.log(e.value);
	// });
})
/* ajax */
function add_my_ajaxurl() {
?>
    <script>
        var ajaxurl = '<?php echo admin_url( 'admin-ajax.php'); ?>';
    </script>
<?php
}
add_action( 'wp_head', 'add_my_ajaxurl', 1 );



function view_mes(){
    $mes = $_POST['mes'];
    echo hierarchical_category_tree(1);
    die();
}
add_action( 'wp_ajax_view_mes', 'view_mes' );
add_action( 'wp_ajax_nopriv_view_mes', 'view_mes' );


//get posts under specific category
function view_posts(){
    $catId = $_POST['bCat'];
    echo getPostsHtml($catId);
    die();
}
add_action( 'wp_ajax_view_posts', 'view_posts' );
add_action( 'wp_ajax_nopriv_view_posts', 'view_posts' );



function getPostsHtml($catId){
	global $post;
	$args = array( 'posts_per_page' => 100, 'offset'=> 1, 'category' => $catId );
	$postsHtml ="<ul>";
	$myposts = get_posts( $args );
	foreach ( $myposts as $post ) : 
		setup_postdata( $post ); 
		$postsHtml .= '<li><a href="#" onclick="showText(' . the_permalink() . '">' . the_title() . '</a></li>';
	endforeach; 
	$postsHtml .="</ul>";
	wp_reset_postdata();
}


function my_ajax_get_posts($catId){
     
    $returnObj = array();
     
    $args = array(
        'post_type' => 'post',
        'numberposts' => 5,
    );

    if(isset($catid)){
    	$args['category'] = $catId;
    }
     
    $posts = get_posts( $args );
     
    foreach( $posts as $key => $post ) {
        $returnObj[$key] = array(
            'post_title' => $post->post_title,
            'permalink' => get_permalink( $post->ID ),
            'post_id' => $post->ID ,
        );
    }
     
    echo json_encode( $returnObj );
     
    die();
}
add_action( 'wp_ajax_my_ajax_get_posts', 'my_ajax_get_posts' );
add_action( 'wp_ajax_nopriv_my_ajax_get_posts', 'my_ajax_get_posts' );



/* ajax end*/


/*get category start*/

//hierarchical_category_tree( 0 ); // the function call; 0 for all categories; or cat ID  

// function hierarchical_category_tree( $cat ) {
//     // wpse-41548 // alchymyth // a hierarchical list of all categories //

//   $next = get_categories('hide_empty=false&orderby=name&order=ASC&parent=' . $cat);
//   $catText = "";
//   if( $next ) :    
//     foreach( $next as $cat ) :
//     $catText .= '<ul><li><strong>' . $cat->name . '</strong>';
//     $catText .= ' / <a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '" ' . '>View ( '. $cat->count . ' posts )</a>  '; 
//     $catText .= ' / <a href="'. get_admin_url().'edit-tags.php?action=edit&taxonomy=category&tag_ID='.$cat->term_id.'&post_type=post" title="Edit Category">Edit</a>'; 
//     hierarchical_category_tree( $cat->term_id );
//     endforeach;    
//   endif;

//   $catText .= '</li></ul>'; 
//   $catText .= "\n";
//   return $catText;
// }


function hierarchical_category_tree( $cat ) {
    // wpse-41548 // alchymyth // a hierarchical list of all categories //

  $next = get_categories('hide_empty=false&orderby=name&order=ASC&parent=' . $cat);
  $catText = "";
  if( $next ) :    
    foreach( $next as $cat ) :
    $catText .= '<option value="' . $cat->term_id.'">' . $cat->name . '</option>';
 //   hierarchical_category_tree( $cat->term_id );
    endforeach;    
  endif;

  return $catText;
}


/*get category end*/



// echo hierarchical_term_tree();

// function hierarchical_term_tree($category = 0)
// {
//     $r = '';

//     $args = array(
//         'parent' => $category,
//     );

//     $next = get_terms('product_cat', $args);

//     if ($next) {
//         $r .= '<ul>';

//         foreach ($next as $cat) {
//             $r .= '<li><a href="' . get_term_link($cat->slug, $cat->taxonomy) . '" title="' . sprintf(__("View all products in %s"), $cat->name) . '" ' . '>' . $cat->name . ' (' . $cat->count . ')' . '</a>';
//             $r .= $cat->term_id !== 0 ? hierarchical_term_tree($cat->term_id) : null;
//         }
//         $r .= '</li>';

//         $r .= '</ul>';
//     }

//     return $r;
// }