em-bookings.php 34 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
<?php
/**
 * Deprecated - see em-actions.php - this will be removed at some point in 6.0
 * Check if there's any admin-related actions to take for bookings. All actions are caught here.
 * @return null
 * @todo remove in 6.0
 */
function em_admin_actions_bookings() {
	global $EM_Event;	
	if( is_object($EM_Event) && !empty($_REQUEST['action']) ){
		if( $_REQUEST['action'] == 'bookings_export_csv' && wp_verify_nonce($_REQUEST['_wpnonce'],'bookings_export_csv') ){
			$EM_Event->get_bookings()->export_csv();
			exit();
		}
	}
}
add_action('admin_init','em_admin_actions_bookings',100);

/**
 * Decide what content to show in the bookings section. 
 */
function em_bookings_page(){
	//First any actions take priority
	do_action('em_bookings_admin_page');
	if( !empty($_REQUEST['_wpnonce']) ){ $_REQUEST['_wpnonce'] = $_GET['_wpnonce'] = $_POST['_wpnonce'] = esc_attr($_REQUEST['_wpnonce']); } //XSS fix just in case here too
	if( !empty($_REQUEST['action']) && substr($_REQUEST['action'],0,7) != 'booking' && $_REQUEST['action'] !== 'em_bookings_table' ){ //actions not starting with booking_
		?>
		<div class="wrap em-bookings-admin-custom-<?php esc_attr($_REQUEST['action']); ?> <?php em_template_classes('bookings-admin'); ?>">
			<div class="input">
			<?php
			do_action('em_bookings_'.$_REQUEST['action']);
			?>
			</div>
		</div>
		<?php
	}elseif( !empty($_REQUEST['booking_id']) ){
		em_bookings_single();
	}elseif( !empty($_REQUEST['person_id']) ){
		em_bookings_person();
	}elseif( !empty($_REQUEST['ticket_id']) ){
		em_bookings_ticket();
	}elseif( !empty($_REQUEST['event_id']) ){
		em_bookings_event();
	}else{
		em_bookings_dashboard();
	}
}

/**
 * Generates the bookings dashboard, showing information on all events
 */
function em_bookings_dashboard(){
	global $EM_Notices;
	?>
	<div class='em-bookings-admin-dashboard em-bookings-dashboard <?php em_template_classes('bookings-admin'); ?>'>
		<div class="input">
		<?php if( is_admin() ): ?>
  		<h1><?php esc_html_e('Event Bookings Dashboard', 'events-manager'); ?></h1>
  		<?php else: echo $EM_Notices; ?>
  		<?php endif; ?>
		<?php if( is_admin() && get_option('dbem_booking_charts_dashboard') ): ?>
		<div class="em-bookings-stats">
			<div class="inside">
				<?php \EM\Admin\Dashboard::output('dashboard'); ?>
			</div>
		</div>
		<?php endif; ?>
  		<div class="em-bookings-recent">
			<h2><?php esc_html_e('Recent Bookings','events-manager'); ?></h2>
	  		<?php
			$EM_Bookings_Table = new EM_Bookings_Table();
		    if( is_admin() ) {
			    $EM_Bookings_Table->display();
		    }else{
			    $EM_Bookings_Table->output();
		    }
	  		?>
  		</div>
  		<br class="clear" />
  		<div class="em-bookings-events">
			<h2><?php esc_html_e('Events With Bookings Enabled','events-manager'); ?></h2>
			<?php em_bookings_events_table(); ?>
			<?php do_action('em_bookings_dashboard'); ?>
		</div>
		</div>
	</div>
	<?php
}

/**
 * Shows all booking data for a single event 
 */
function em_bookings_event(){
	global $EM_Event,$EM_Person,$EM_Notices;
	//check that user can access this page
	if( is_object($EM_Event) && !$EM_Event->can_manage('manage_bookings','manage_others_bookings') ){
		?>
		<div class="wrap <?php em_template_classes('bookings-admin'); ?>">
			<h2><?php esc_html_e('Unauthorized Access','events-manager'); ?></h2>
			<p><?php esc_html_e('You do not have the rights to manage this event.','events-manager'); ?></p>
		</div>
		<?php
		return false;
	}
	$header_button_classes = is_admin() ? 'page-title-action':'button add-new-h2';
	?>
	<div class='em-bookings-admin-event <?php em_template_classes('bookings-admin'); ?>'>
		<div class="input">
			
			<?php if( is_admin() ): ?><h1 class="wp-heading-inline"><?php else: ?><h2><?php endif; ?>
  			<?php echo sprintf(__('Manage %s Bookings', 'events-manager'), "'{$EM_Event->event_name}'"); ?>
  		    <?php if( !is_admin() ): ?></h2><?php else: ?></h1><?php endif; // inverted to help IDEs ?>
  			<a href="<?php echo $EM_Event->get_permalink(); ?>" class="button button-secondary"><?php echo sprintf(__('View %s','events-manager'), __('Event', 'events-manager')) ?></a>
  			<a href="<?php echo $EM_Event->get_edit_url(); ?>" class="button button-secondary"><?php echo sprintf(__('Edit %s','events-manager'), __('Event', 'events-manager')) ?></a>
  			<?php if( locate_template('plugins/events-manager/templates/csv-event-bookings.php', false) ): //support for legacy template ?>
  			<a href='<?php echo EM_ADMIN_URL ."&amp;page=events-manager-bookings&amp;action=bookings_export_csv&amp;_wpnonce=".wp_create_nonce('bookings_export_csv')."&amp;event_id=".$EM_Event->event_id ?>' class="button button-secondary"><?php esc_html_e('Export CSV','events-manager')?></a>
  			<?php endif; ?>
  			<?php do_action('em_admin_event_booking_options_buttons'); ?>
			<hr class="wp-header-end">
			
	        <?php if( !is_admin() ) echo $EM_Notices; ?>
			<p><strong><?php esc_html_e('Event Name','events-manager'); ?></strong> : <?php echo esc_html($EM_Event->event_name); ?></p>
			<?php do_action('em_admin_event_booking_before_availibility', $EM_Event); ?>
			<p>
				<strong><?php esc_html_e('Availability','events-manager'); ?></strong> :
				<?php echo $EM_Event->get_bookings()->get_booked_spaces() . '/'. $EM_Event->get_spaces() ." ". __('Spaces confirmed','events-manager'); ?>
				<?php if( get_option('dbem_bookings_approval_reserved') ): ?>
				, <?php echo $EM_Event->get_bookings()->get_available_spaces() . '/'. $EM_Event->get_spaces() ." ". __('Available spaces','events-manager'); ?>
				<?php endif; ?>
				<?php do_action('em_admin_event_booking_availibility', $EM_Event); ?>
			</p>
			<?php do_action('em_admin_event_booking_after_availibility', $EM_Event); ?>
			<p>
				<strong><?php esc_html_e('Date','events-manager'); ?></strong> :
				<?php echo $EM_Event->output_dates(false, " - "). ' @ ' . $EM_Event->output_times(false, ' - '); ?>
			</p>
			<p>
				<strong><?php esc_html_e('Location','events-manager'); ?></strong> :
				<?php if( $EM_Event->location_id == 0 ): ?>
				<em><?php esc_html_e('No Location', 'events-manager'); ?></em>
				<?php else: ?>
				<a class="row-title" href="<?php echo admin_url(); ?>post.php?action=edit&amp;post=<?php echo $EM_Event->get_location()->post_id ?>"><?php echo ($EM_Event->get_location()->location_name); ?></a>
				<?php endif; ?>
			</p>
			<?php if( is_admin() && get_option('dbem_booking_charts_event') ): ?>
				<div class="em-bookings-stats">
					<div class="inside">
						<?php \EM\Admin\Dashboard::output('event', $EM_Event->event_id); ?>
					</div>
				</div>
			<?php endif; ?>
			<h2><?php esc_html_e('Bookings','events-manager'); ?></h2>
			<?php
			$EM_Bookings_Table = new EM_Bookings_Table();
			$EM_Bookings_Table->status = 'all';
			if( is_admin() ) {
				$EM_Bookings_Table->display();
			}else{
				$EM_Bookings_Table->output();
			}
	        ?>
			<?php do_action('em_bookings_event_footer', $EM_Event); ?>
		</div>
	</div>
	<?php
}

/**
 * Shows a ticket view
 */
function em_bookings_ticket(){
	global $EM_Ticket,$EM_Notices;
	$EM_Event = $EM_Ticket->get_event();
	//check that user can access this page
	if( is_object($EM_Ticket) && !$EM_Ticket->can_manage() ){
		?>
		<div class="wrap <?php em_template_classes('bookings-admin'); ?>">
			<h2><?php esc_html_e('Unauthorized Access','events-manager'); ?></h2>
			<p><?php esc_html_e('You do not have the rights to manage this ticket.','events-manager'); ?></p>
		</div>
		<?php
		return false;
	}
	?>
	<div class='em-bookings-admin-ticket <?php em_template_classes('bookings-admin'); ?>'>
		<div class="input">
			
			<?php if( is_admin() ): ?><h1 class="wp-heading-inline"><?php else: ?><h2><?php endif; ?>
			<?php echo sprintf(__('Ticket for %s', 'events-manager'), "'{$EM_Event->name}'"); ?><?php echo sprintf(__('Manage %s Bookings', 'events-manager'), "'{$EM_Event->event_name}'"); ?>
			<?php if( !is_admin() ): ?></h2><?php else: ?></h1><?php endif; // inverted to help IDEs ?>
	        <a href="<?php echo $EM_Event->get_edit_url(); ?>" class="button button-secondary"><?php esc_html_e('View/Edit Event','events-manager') ?></a>
	        <a href="<?php echo $EM_Event->get_bookings_url(); ?>" class="button button-secondary"><?php esc_html_e('View Event Bookings','events-manager') ?></a>
			<hr class="wp-header-end" />
				
	        <?php if( !is_admin() ) echo $EM_Notices; ?>
			<div>
				<table>
					<tr><td><?php echo __('Name','events-manager'); ?></td><td></td><td><?php echo $EM_Ticket->ticket_name; ?></td></tr>
					<tr><td><?php echo __('Description','events-manager'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td></td><td><?php echo ($EM_Ticket->ticket_description) ? $EM_Ticket->ticket_description : '-'; ?></td></tr>
					<tr><td><?php echo __('Price','events-manager'); ?></td><td></td><td><?php echo ($EM_Ticket->ticket_price) ? $EM_Ticket->ticket_price : '-'; ?></td></tr>
					<tr><td><?php echo __('Spaces','events-manager'); ?></td><td></td><td><?php echo ($EM_Ticket->ticket_spaces) ? $EM_Ticket->ticket_spaces : '-'; ?></td></tr>
					<tr><td><?php echo __('Min','events-manager'); ?></td><td></td><td><?php echo ($EM_Ticket->ticket_min) ? $EM_Ticket->ticket_min : '-'; ?></td></tr>
					<tr><td><?php echo __('Max','events-manager'); ?></td><td></td><td><?php echo ($EM_Ticket->ticket_max) ? $EM_Ticket->ticket_max : '-'; ?></td></tr>
					<tr><td><?php echo __('Start','events-manager'); ?></td><td></td><td><?php echo ($EM_Ticket->ticket_start) ? $EM_Ticket->start()->formatDefault() : '-'; ?></td></tr>
					<tr><td><?php echo __('End','events-manager'); ?></td><td></td><td><?php echo ($EM_Ticket->ticket_end) ? $EM_Ticket->end()->formatDefault() : '-'; ?></td></tr>
					<?php do_action('em_booking_admin_ticket_row', $EM_Ticket); ?>
				</table>
			</div>
			<h2><?php esc_html_e('Bookings','events-manager'); ?></h2>
			<?php
			$EM_Bookings_Table = new EM_Bookings_Table();
			$EM_Bookings_Table->status = get_option('dbem_bookings_approval') ? 'needs-attention':'confirmed';
			if( is_admin() ) {
				$EM_Bookings_Table->display();
			}else{
				$EM_Bookings_Table->output();
			}
	        ?>
			<?php do_action('em_bookings_ticket_footer', $EM_Ticket); ?>
		</div>
	</div>
	<?php	
}

/**
 * Shows a single booking for a single person. 
 */
function em_bookings_single(){
	global $EM_Booking, $EM_Notices; /* @var $EM_Booking EM_Booking */
	//check that user can access this page
	if( is_object($EM_Booking) && !$EM_Booking->can_manage() ){
		?>
		<div class="wrap <?php em_template_classes('bookings-admin'); ?>">
			<h2><?php esc_html_e('Unauthorized Access','events-manager'); ?></h2>
			<p><?php esc_html_e('You do not have the rights to manage this event.','events-manager'); ?></p>
		</div>
		<?php
		return false;
	}
	do_action('em_booking_admin', $EM_Booking);
	?>
	<div class='wrap em-bookings-admin-single <?php em_template_classes('bookings-admin'); ?>' id="em-bookings-admin-booking">
		<div class="input">
		<?php if( is_admin() ): ?><h1><?php else: ?><h2><?php endif; ?>
  			<?php esc_html_e('Edit Booking', 'events-manager'); ?>
		<?php if( !is_admin() ): ?></h2><?php else: ?></h1><?php endif; ?>
  		<?php if( !is_admin() ) echo $EM_Notices; ?>
  		<div class="metabox-holder">
	  		<div class="postbox-container" style="width:99.5%">
				<div class="postbox">
					<h3>
						<?php esc_html_e( 'Event Details', 'events-manager'); ?>
					</h3>
					<div class="inside">
						<?php
						$EM_Event = $EM_Booking->get_event();
						?>
						<table>
							<tr><td><strong><?php esc_html_e('Name','events-manager'); ?></strong></td><td><a class="row-title" href="<?php echo $EM_Event->get_bookings_url(); ?>"><?php echo ($EM_Event->event_name); ?></a></td></tr>
							<tr>
								<td><strong><?php esc_html_e('Date/Time','events-manager'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
								<td>
									<?php echo $EM_Event->output('#_EVENTDATES @ #_EVENTTIMES'); ?>
								</td>
							</tr>
						</table>
						<?php do_action('em_bookings_admin_booking_event', $EM_Event); ?>
					</div>
				</div>
				<div class="postbox">
					<h3>
						<?php esc_html_e( 'Personal Details', 'events-manager'); ?>
					</h3>
					<div class="inside">
						<div class="em-booking-person-details">
							<?php echo $EM_Booking->get_person()->display_summary(); ?>
							<?php if( $EM_Booking->is_no_user() ): ?>
							<input type="button" class="button-secondary" id="em-booking-person-modify" value="<?php esc_attr_e('Edit Details','events-manager'); ?>" />
							<?php endif; ?>
						</div>
						<?php if( $EM_Booking->is_no_user() ): ?>
						<form action="" method="post" class="em-booking-person-form">
							<div class="em-booking-person-editor" style="display:none;">
								<?php echo $EM_Booking->get_person_editor(); ?>
							    <input type='hidden' name='action' value='booking_modify_person'/>
							    <input type='hidden' name='booking_id' value='<?php echo $EM_Booking->booking_id; ?>'/>
							    <input type='hidden' name='event_id' value='<?php echo $EM_Event->event_id; ?>'/>
							    <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('booking_modify_person_'.$EM_Booking->booking_id); ?>'/>
								<input type="submit" class="button-primary em-button em-booking-person-modify-submit" id="em-booking-person-modify-submit" value="<?php esc_attr_e('Submit Changes', 'events-manager'); ?>" />
								<input type="button" id="em-booking-person-modify-cancel" class="button-secondary em-button" value="<?php esc_attr_e('Cancel','events-manager'); ?>" />
							</div>
						</form>
						<script type="text/javascript">
							jQuery(document).ready( function($){
								$('#em-booking-person-modify').on('click', function(){
									$('.em-booking-person-details').hide();
									$('.em-booking-person-editor').show();
								});
								$('#em-booking-person-modify-cancel').on('click', function(){
									$('.em-booking-person-details').show();
									$('.em-booking-person-editor').hide();
								});
							});
						</script>
						<?php endif; ?>
						<?php do_action('em_bookings_admin_booking_person', $EM_Booking); ?>
					</div>
				</div>
				<div class="postbox">
					<h3>
						<?php esc_html_e( 'Booking Details', 'events-manager'); ?>
						<?php $icons_class = is_admin() ? 'dashicons dashicons-info-outline' : 'em-icons em-icons-at'; ?>
						<span class="em-tooltip <?php echo $icons_class ?>" aria-label="UUID : <?php echo esc_attr($EM_Booking->booking_uuid); ?>" data-tippy-interactive="true"></span>
					</h3>
					<div class="inside">
						<?php
						$EM_Event = $EM_Booking->get_event();
						$shown_tickets = array();
						?>
						<div>
							<form action="" method="post" class="em-booking-single-status-info">
								<strong><?php esc_html_e('Status','events-manager'); ?> : </strong>
								<?php echo $EM_Booking->get_status(); ?>
								<input type="button" class="button-secondary em-button em-booking-submit-status-modify" id="em-booking-submit-status-modify" value="<?php esc_attr_e('Change', 'events-manager'); ?>" />
								<input type="submit" class="button-primary em-button em-booking-resend-email" id="em-booking-resend-email" value="<?php esc_attr_e('Resend Email', 'events-manager'); ?>" />
							    <input type='hidden' name='action' value='booking_resend_email'/>
							    <input type='hidden' name='booking_id' value='<?php echo $EM_Booking->booking_id; ?>'/>
							    <input type='hidden' name='event_id' value='<?php echo $EM_Event->event_id; ?>'/>
							    <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('booking_resend_email_'.$EM_Booking->booking_id); ?>'/>
							</form>
							<form action="" method="post" class="em-booking-single-status-edit">
								<strong><?php esc_html_e('Status','events-manager'); ?> : </strong>
								<select name="booking_status">
									<?php foreach($EM_Booking->status_array as $status => $status_name): ?>
									<option value="<?php echo esc_attr($status); ?>" <?php if($status == $EM_Booking->booking_status){ echo 'selected="selected"'; } ?>><?php echo esc_html($status_name); ?></option>
									<?php endforeach; ?>
								</select>
								<input type="checkbox" checked="checked" name="send_email" value="1" />
								<?php esc_html_e('Send Email','events-manager'); ?>
								<input type="submit" class="button-primary em-button em-booking-submit-status" id="em-booking-submit-status" value="<?php esc_attr_e('Submit Changes', 'events-manager'); ?>" />
								<input type="button" class="button-secondary em-button em-booking-submit-status-cancel" id="em-booking-submit-status-cancel" value="<?php esc_attr_e('Cancel', 'events-manager'); ?>" />
							    <input type='hidden' name='action' value='booking_set_status'/>
							    <input type='hidden' name='booking_id' value='<?php echo $EM_Booking->booking_id; ?>'/>
							    <input type='hidden' name='event_id' value='<?php echo $EM_Event->event_id; ?>'/>
							    <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('booking_set_status_'.$EM_Booking->booking_id); ?>'/>
								<br /><em><?php echo wp_kses_data(__('<strong>Notes:</strong> Ticket availability not taken into account when approving new bookings (i.e. you can overbook).','events-manager')); ?></em>
							</form>
							<?php do_action('em_bookings_admin_booking_details_actions', $EM_Booking); ?>
						</div>
						<form action="" method="post" class="em-booking-form">
							<table class="em-tickets em-tickets-bookings-table" cellpadding="0" cellspacing="0">
								<thead>
									<tr>
										<th><?php esc_html_e('Ticket Type','events-manager'); ?></th>
										<th><?php esc_html_e('Spaces','events-manager'); ?></th>
										<th><?php esc_html_e('Price','events-manager'); ?></th>
									</tr>
								</thead>
								<?php
									/* Show booked tickets in this booking, we'll add on the unbooked tickets here to prevent redundant code */
									$EM_Tickets_Bookings = $EM_Booking->get_tickets_bookings();
									$tickets_bookings = array(); // we'll use this ordered with all tickets
									foreach( $EM_Event->get_bookings()->get_tickets()->tickets as $ticket_id => $EM_Ticket ){
										if( empty($EM_Tickets_Bookings[$ticket_id]) ) {
											$tickets_bookings[$ticket_id] = new EM_Ticket_Bookings(array('ticket' => $EM_Ticket, 'booking' => $EM_Booking));
										}else{
											$tickets_bookings[$ticket_id] = $EM_Tickets_Bookings[$ticket_id];
										}
									}
								?>
								<?php foreach($tickets_bookings as $ticket_id => $EM_Ticket_Bookings): /* @var $EM_Ticket_Bookings EM_Ticket_Bookings */ ?>
									<?php
									$ticket_id = absint($ticket_id); // sanitize for output
									$EM_Ticket = $EM_Ticket_Bookings->get_ticket();
									// Use the following for adding extra info, most appropriate place is within the edit area
									do_action('em_bookings_admin_ticket_bookings_before', $EM_Ticket_Bookings);
									?>
									<tr class="em-ticket em-ticket-<?php echo $ticket_id; ?>">
										<td class="ticket-type">
											<a class="row-title" href="<?php echo em_add_get_params($EM_Event->get_bookings_url(), array('ticket_id'=>$ticket_id)); ?>"><?php echo $EM_Ticket_Bookings->get_ticket()->ticket_name ?></a>
										</td>
										<td>
											<span class="em-booking-single-info"><?php echo $EM_Ticket_Bookings->get_spaces(); ?></span>
											<div class="em-booking-single-edit">
												<input name="em_tickets[<?php echo $ticket_id; ?>][spaces]" class="em-ticket-select em-ticket-spaces-<?php echo $ticket_id; ?>" value="<?php echo $EM_Ticket_Bookings->get_spaces(); ?>" data-ticket-id="<?php echo $ticket_id ?>"/>
											</div>
										</td>
										<td><?php echo $EM_Ticket_Bookings->get_price(true,true); ?></td>
									</tr>
									<?php do_action('em_bookings_admin_ticket_row', $EM_Ticket_Bookings->get_ticket(), $EM_Booking, $EM_Ticket_Bookings); /* Keeping as legacy support for EM Pro < v3 */ ?>
									<tbody class="em-ticket-bookings <?php if( !has_action('em_bookings_admin_ticket_booking_row') ) echo 'hidden'; ?> em-ticket-bookings-<?php echo $ticket_id; ?>" data-ticket-id="<?php echo $ticket_id; ?>">
										<?php
											// use the following
											$shown_tickets[] = $ticket_id;
											$ticket_attendee_num = 1;
											do_action('em_bookings_admin_ticket_bookings_rows_before', $EM_Ticket_Bookings);
										?>
										<?php foreach( $EM_Ticket_Bookings as $ticket_uuid => $EM_Ticket_Booking ): /* @var EM_Ticket_Booking $EM_Ticket_Booking */ ?>
											<?php do_action('em_bookings_admin_ticket_booking_row_before', $EM_Ticket_Booking, $ticket_attendee_num); ?>
											<tr class="em-ticket-booking em-ticket-booking-<?php echo absint($EM_Ticket_Booking->ticket_booking_id); ?>"><!-- this will eventually move out into an enveloping element class for all ticket bookings of this ticket -->
												<td colspan="3">
													<div>
														<p class="em-ticket-booking-attendee-number"><?php echo sprintf(esc_html__('Attendee %d', 'events-manager'), $ticket_attendee_num); ?></p>
														<span class="em-booking-single-edit em-icon em-icon-close em-ticket-booking-remove-trigger em-tooltip" aria-label="<?php esc_html_e('Remove this ticket booking', 'events-manager'); ?>"></span>
														<?php
															// create a consistent naming structure for post vars, others can/should add stuff to the uuid part of each ticket booking
															$name = "";
															do_action('em_bookings_admin_ticket_booking_row', $EM_Ticket_Booking, $ticket_attendee_num);
														?>
														<input name="em_tickets[<?php echo $ticket_id; ?>][ticket_bookings][<?php echo esc_attr($ticket_uuid); ?>][ticket_booking_id]" type="hidden" value="<?php echo absint($EM_Ticket_Booking->ticket_booking_id); ?>">
													</div>
												</td>
											</tr>
											<?php do_action('em_bookings_admin_ticket_booking_row_after', $EM_Ticket_Booking, $ticket_attendee_num); ?>
											<?php $ticket_attendee_num++; ?>
										<?php endforeach; ?>
										<?php
											do_action('em_bookings_admin_ticket_bookings_rows_after', $EM_Ticket_Bookings); // want $ticket_attendee_num? count the tickets
										?>
										<tr class="em-ticket-booking-template">
											<td colspan="3">
												<div>
													<p class="em-ticket-booking-attendee-number"><?php echo str_replace('%d', '#NUM#', esc_html__('Attendee %d', 'events-manager')); ?></p>
													<?php do_action('em_bookings_admin_ticket_booking_row_template', $EM_Ticket, $EM_Booking); ?>
												</div>
											</td>
										</tr>
										<?php
											// Use the following for adding extra info, most appropriate place is within the edit area
											do_action('em_bookings_admin_ticket_bookings_after', $EM_Ticket_Bookings);
										?>
									</tbody>
								<?php endforeach; ?>
								
								<tfoot>
									<?php
										do_action('em_bookings_admin_ticket_totals_header');
										$price_summary = $EM_Booking->get_price_summary_array();
										//we should now have an array of information including base price, taxes and post/pre tax discounts
									?>
									<tr>
										<th><?php esc_html_e('Price','events-manager'); ?></th>
										<th><?php echo sprintf(__('%d Spaces','events-manager'), $EM_Booking->get_spaces()); ?></th>
										<th><?php echo $EM_Booking->get_price_base(true); ?></th>
									</tr>
									<?php if( count($price_summary['discounts_pre_tax']) > 0 ): ?>
										<?php foreach( $price_summary['discounts_pre_tax'] as $discount_summary ): ?>
										<tr>
											<th><?php echo $discount_summary['name']; ?></th>
											<th><?php echo $discount_summary['adjustment']; ?></th>
											<th>- <?php echo $discount_summary['amount']; ?></th>
										</tr>
										<?php endforeach; ?>
									<?php endif; ?>
									<?php if( count($price_summary['surcharges_pre_tax']) > 0 ): ?>
										<?php foreach( $price_summary['surcharges_pre_tax'] as $surcharge_summary ): ?>
										<tr>
											<th><?php echo $surcharge_summary['name']; ?></th>
											<th><?php echo $surcharge_summary['adjustment']; ?></th>
											<th><?php echo $surcharge_summary['amount']; ?></th>
										</tr>
										<?php endforeach; ?>
									<?php endif; ?>
									<?php if( !empty($price_summary['taxes']['amount'])  ): ?>
									<tr>
										<th><?php esc_html_e('Tax','events-manager'); ?></th>
										<th>
											<span class="em-booking-single-info"><?php echo $price_summary['taxes']['rate'] ?></span>
											<div class="em-booking-single-edit"><input name="booking_tax_rate" value="<?php echo esc_attr($EM_Booking->get_tax_rate()); ?>">%</div>
										</th>
										<th><?php echo $price_summary['taxes']['amount']; ?></th>
									</tr>
									<?php endif; ?>
									<?php if( count($price_summary['discounts_post_tax']) > 0 ): ?>
										<?php foreach( $price_summary['discounts_post_tax'] as $discount_summary ): ?>
										<tr>
											<th><?php echo $discount_summary['name']; ?></th>
											<th><?php echo $discount_summary['adjustment']; ?></th>
											<th>- <?php echo $discount_summary['amount']; ?></th>
										</tr>
										<?php endforeach; ?>
									<?php endif; ?>
									<?php if( count($price_summary['surcharges_post_tax']) > 0 ): ?>
										<?php foreach( $price_summary['surcharges_post_tax'] as $surcharge_summary ): ?>
										<tr>
											<th><?php echo $surcharge_summary['name']; ?></th>
											<th><?php echo $surcharge_summary['adjustment']; ?></th>
											<th><?php echo $surcharge_summary['amount']; ?></th>
										</tr>
										<?php endforeach; ?>
									<?php endif; ?>
									<tr class="em-hr">
										<th><?php esc_html_e('Total Price','events-manager'); ?></th>
										<th>&nbsp;</th>
										<th><?php echo $price_summary['total']; ?></th>
									</tr>
									<?php do_action('em_bookings_admin_ticket_totals_footer', $EM_Booking); ?>
								</tfoot>
							</table>
							<table class="em-form-fields" cellspacing="0" cellpadding="0">
								<?php if( !has_action('em_bookings_single_custom') ): //default behavior ?>
								<tr>
									<th><?php esc_html_e('Comment','events-manager'); ?></th>
									<td>
										<span class="em-booking-single-info"><?php echo esc_html($EM_Booking->booking_comment); ?></span>
										<div class="em-booking-single-edit"><textarea name="booking_comment"><?php echo esc_html($EM_Booking->booking_comment); ?></textarea></div>
									</td>
								</tr>
								<?php else: do_action('em_bookings_single_custom',$EM_Booking); //do your own thing, e.g. pro ?>
								<?php endif; ?>
							</table>
							<p class="em-booking-single-info">
								<input type="button" class="button-secondary em-button em-booking-submit-modify" id="em-booking-submit-modify" value="<?php esc_attr_e('Modify Booking', 'events-manager'); ?>" />
							</p>
							<p class="em-booking-single-edit">
								<em><?php _e('<strong>Notes:</strong> Ticket availability not taken into account (i.e. you can overbook). Emails are not resent automatically.','events-manager'); ?></em>
								<br /><br />
								<input type="submit" class="button-primary em-button em-booking-submit" id="em-booking-submit" value="<?php esc_attr_e('Submit Changes', 'events-manager'); ?>" />
								<input type="button" class="button-secondary em-button em-booking-submit-cancel" id="em-booking-submit-cancel" value="<?php esc_attr_e('Cancel', 'events-manager'); ?>" />
							    <input type='hidden' name='action' value='booking_save'/>
							    <input type='hidden' name='booking_id' value='<?php echo $EM_Booking->booking_id; ?>'/>
							    <input type='hidden' name='event_id' value='<?php echo $EM_Event->event_id; ?>'/>
							    <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('booking_save_'.$EM_Booking->booking_id); ?>'/>
							</p>
						</form>
						<script type="text/javascript">
							jQuery(document).ready( function($){
								$('#em-booking-submit-modify').on('click', function(){
									$('.em-booking-single-info').hide();
									$('.em-booking-single-edit').show();
								});
								$('#em-booking-submit-cancel').on('click', function(){
									$('.em-booking-single-info').show();
									$('.em-booking-single-edit').hide();
								});
								$('.em-booking-single-info').show();
								$('.em-booking-single-edit').hide();

								$('#em-booking-submit-status-modify').on('click', function(){
									$('.em-booking-single-status-info').hide();
									$('.em-booking-single-status-edit').show();
								});
								$('#em-booking-submit-status-cancel').on('click', function(){
									$('.em-booking-single-status-info').show();
									$('.em-booking-single-status-edit').hide();
								});
								$('.em-booking-single-status-info').show();
								$('.em-booking-single-status-edit').hide();
							});
						</script>
						<?php do_action('em_bookings_single_details_footer', $EM_Booking); ?>
					</div>
				</div>
				<div id="em-booking-notes" class="postbox">
					<h3>
						<?php esc_html_e( 'Booking Notes', 'events-manager'); ?>
					</h3>
					<div class="inside">
						<p><?php esc_html_e('You can add private notes below for internal reference that only event managers will see.','events-manager'); ?></p>
						<?php foreach( $EM_Booking->get_notes() as $note ):
							$user = new EM_Person($note['author']);
						?>
						<div>
							<?php echo sprintf(esc_html_x('%1$s - %2$s wrote','[Date] - [Name] wrote','events-manager'), date(get_option('date_format'), $note['timestamp']), $user->get_name()); ?>:
							<p style="background:#efefef; padding:5px;"><?php echo nl2br($note['note']); ?></p>
						</div>
						<?php endforeach; ?>
						<form method="post" action="" style="padding:5px;">
							<textarea class="widefat" rows="5" name="booking_note"></textarea>
							<input type="hidden" name="action" value="bookings_add_note" />
							<input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('bookings_add_note'); ?>" />
							<input type="submit" class="em-button button-primary" value="<?php esc_html_e('Add Note', 'events-manager'); ?>" />
						</form>
					</div>
				</div>
				<?php do_action('em_bookings_single_metabox_footer', $EM_Booking); ?>
			</div>
		</div>
		<br style="clear:both;" />
		<?php do_action('em_bookings_single_footer', $EM_Booking); ?>
		</div>
	</div>
	<?php
	
}

/**
 * Shows all bookings made by one person.
 */
function em_bookings_person(){	
	global $EM_Person, $EM_Notices;
	$EM_Person->get_bookings();
	$has_booking = false;
	foreach($EM_Person->get_bookings() as $EM_Booking){
		if($EM_Booking->can_manage('manage_bookings','manage_others_bookings')){
			$has_booking = true;
		}
	}
	if( !$has_booking && !current_user_can('manage_others_bookings') ){
		?>
		<div class="wrap <?php em_template_classes('bookings-admin'); ?>">
			<h2><?php esc_html_e('Unauthorized Access','events-manager'); ?></h2>
			<p><?php esc_html_e('You do not have the rights to manage this event.','events-manager'); ?></p>
		</div>
		<?php
		return false;
	}
	$header_button_classes = is_admin() ? 'page-title-action':'button add-new-h2';
	?>
	<div class='em-bookings-admin-person <?php em_template_classes('bookings-admin'); ?>'>
		<div class="input">
		<?php if( is_admin() ): ?><h1 class="wp-heading-inline"><?php else: ?><h2><?php endif; ?>
  			<?php esc_html_e('Manage Person\'s Booking', 'events-manager'); ?>
  		<?php if( is_admin() ): ?></h1><?php endif; ?>
  			<?php if( current_user_can('edit_users') ) : ?>
  			<a href="<?php echo admin_url('user-edit.php?user_id='.$EM_Person->ID); ?>" class="<?php echo $header_button_classes; ?>"><?php esc_html_e('Edit User','events-manager') ?></a>
  			<?php endif; ?>
  			<?php if( current_user_can('delete_users') ) : ?>
  			<a href="<?php echo wp_nonce_url( admin_url("users.php?action=delete&amp;user=$EM_Person->ID"), 'bulk-users' ); ?>" class="<?php echo $header_button_classes; ?>"><?php esc_html_e('Delete User','events-manager') ?></a>
  			<?php endif; ?>
		<?php if( !is_admin() ): ?></h2><?php else: ?><hr class="wp-header-end" /><?php endif; ?>
  		<?php if( !is_admin() ) echo $EM_Notices; ?>
		<?php do_action('em_bookings_person_header'); ?>
  		<div id="poststuff" class="metabox-holder has-right-sidebar">
	  		<div id="post-body">
				<div id="post-body-content">
					<div id="event_name" class="stuffbox">
						<h3>
							<?php esc_html_e( 'Personal Details', 'events-manager'); ?>
						</h3>
						<div class="inside">
							<?php echo $EM_Person->display_summary(); ?>
						</div>
					</div> 
				</div>
			</div>
		</div>
		<br style="clear:both;" />
		<?php do_action('em_bookings_person_body_1'); ?>
		<h2><?php esc_html_e('Past And Present Bookings','events-manager'); ?></h2>
		<?php
		$EM_Bookings_Table = new EM_Bookings_Table();
		$EM_Bookings_Table->status = 'all';
		$EM_Bookings_Table->scope = 'all';
		if( is_admin() ) {
			$EM_Bookings_Table->display();
		}else{
			$EM_Bookings_Table->output();
		}
  		?>
		<?php do_action('em_bookings_person_footer', $EM_Person); ?>
		</div>
	</div>
	<?php
}

function em_printable_booking_report() {
	global $EM_Event;
	//check that user can access this page
	if( isset($_GET['page']) && $_GET['page']=='events-manager-bookings' && isset($_GET['action']) && $_GET['action'] == 'bookings_report' && is_object($EM_Event)){
		if( is_object($EM_Event) && !$EM_Event->can_manage('edit_events','edit_others_events') ){
			?>
			<div class="wrap <?php em_template_classes('bookings-admin'); ?>">
				<h2><?php esc_html_e('Unauthorized Access','events-manager'); ?></h2>
				<p><?php esc_html_e('You do not have the rights to manage this event.','events-manager'); ?></p>
			</div>
			<?php
			return false;
		}
		em_locate_template('templates/bookings-event-printable.php', true);
		die();
	}
} 
add_action('admin_init', 'em_printable_booking_report');
?>