Problemer efter opdatering til WP 5.3
Jeg har lidt problemer med et php script, som jeg har har kørende med et motopress hotel plugin som jeg har købt. Motopress plugin gav ingen mulighed for at udskrive en kundefaktura. Til dette formål fik jeg fingrene i dette php script, som virkede, i min back office del af hotel plugin'et indtil jeg opdaterede WP til 5.3. Er der mon nogen her der kan hjælpe mig videre. Jeg er ikke selv nogen haj til php.<?php
namespace MPHB\Views;
use \MPHB\Entities;
class BookingView {
public static function renderPriceBreakdown( Entities\Booking $booking ){
echo self::generatePriceBreakdown( $booking );
}
public static function generatePriceBreakdown( Entities\Booking $booking ){
$priceBreakdown = $booking->getPriceBreakdown();
return self::generatePriceBreakdownArray( $priceBreakdown );
}
/**
* @param array $priceBreakdown
*
* @return string
*/
public static function generatePriceBreakdownArray( $priceBreakdown ){
ob_start();
if ( !empty( $priceBreakdown ) ) :
$hasServices = false !== array_search( true, array_map( function( $roomBreakdown ) {
return isset( $roomBreakdown['services'] ) && !empty( $roomBreakdown['services']['list'] );
}, $priceBreakdown['rooms'] ) );
$useThreeColumns = $hasServices;
$unfoldByDefault = MPHB()->settings()->main()->isPriceBreakdownUnfoldedByDefault();
if (is_admin() && !MPHB()->isAjax()) {
$unfoldByDefault = false;
}
$foldedClass = $unfoldByDefault ? '' : 'mphb-hide';
$unfoldedClass = $unfoldByDefault ? 'mphb-hide' : '';
?>
<script language="javascript" type="text/javascript">
function printDiv(divID) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
//Print receipt in new window
var mywindow = window.open('', 'new div', 'height=900,width=1200');
mywindow.document.write('<html><head><title></title>');
mywindow.document.write('<style>img { max-width: 100%; height: auto; }table{width:100%;}p,label,span,table,tbody,td,tr{font-family:\"Noto Sans\",\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif}td{padding:.45em;border:1px solid #d1d1d1;border-collapse:collapse;border-spacing:0;text-align:left}.mphb-table-price-column{text-align:right}.mphb-price-breakdown-expand span{display:none}</style>');
mywindow.document.write("<link rel='stylesheet' id='alpenhouse-fonts-css' href='https://fonts.googleapis.com/css?family=Roboto+Slab%3A300%2C400%2C700%7CNoto+Sans%3A400%2C700&subset=latin%2Clatin-ext&ver=1.2.0' type='text/css' media='all' />");
mywindow.document.write('</head><body >');
mywindow.document.write("<table><tbody><tr><td style='border:none;'><img src='link-to-your-logo'></td><td style='border:none;'>Address <br/>P.O.Box: <br/>phone number<br/>email</td></tr></tbody></table><br/><br/>");
mywindow.document.write("<label>Booking ID: <span style='color:red;font-weight:bold;'>#" +$("#mphb-_id").val() + "</span></label><br/>");
mywindow.document.write("<label>Guest Name: "+$("#mphb-mphb_first_name").val()+" " + $("#mphb-mphb_last_name").val()+ "</label><br/>");
mywindow.document.write("<label>Email: "+$("#mphb-mphb_email").val()+ "</label><br/>");
mywindow.document.write("<label>Country: "+$("#mphb-mphb_country").val()+ "</label><br/>");
mywindow.document.write("<label>Phone: "+$("#mphb-mphb_phone").val()+ "</label><br/>");
var arr = $("#mphb_rooms > .inside > a").toArray();
var res ='| '; for(var i = 0;i < arr.length ; i += 2) {res += arr[i].text + ' | ';}
mywindow.document.write("<label>Rooms: "+ res + "</label><br/><br/>");
mywindow.document.write(divElements);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus();
setTimeout(function(){mywindow.print();},1000);
}
</script>
<div id="printablediv">
<table class="mphb-price-breakdown" cellspacing="0">
<tbody>
<?php foreach ( $priceBreakdown['rooms'] as $key => $roomBreakdown ) : ?>
<?php if ( isset( $roomBreakdown['room'] ) ) : ?>
<tr class="mphb-price-breakdown-group">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>">
<a href="#" class="mphb-price-breakdown-expand" title="<?php _e( 'Expand', 'motopress-hotel-booking' ); ?>">
<span class="mphb-inner-icon <?php echo esc_attr($unfoldedClass); ?>">+</span><span
class="mphb-inner-icon <?php echo esc_attr($foldedClass); ?>">−</span><?php
printf( _x( '#%d %s', 'Accommodation type in price breakdown table. Example: #1 Double Room', 'motopress-hotel-booking' ), $key + 1, $roomBreakdown['room']['type'] ); ?>
</a>
<div class="mphb-price-breakdown-rate <?php echo esc_attr($foldedClass); ?>"><?php printf( __( 'Rate: %s', 'motopress-hotel-booking' ), $roomBreakdown['room']['rate'] ); ?></div>
</td>
<td class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['total'] ); ?></td>
</tr>
<?php if ( MPHB()->settings()->main()->isAdultsAllowed() ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php
if ( MPHB()->settings()->main()->isChildrenAllowed() ) {
_e( 'Adults', 'motopress-hotel-booking' );
} else {
_e( 'Guests', 'motopress-hotel-booking' );
}
?></td>
<td><?php echo $roomBreakdown['room']['adults']; ?></td>
</tr>
<?php } ?>
<?php if ( $roomBreakdown['room']['children_capacity'] > 0 && MPHB()->settings()->main()->isChildrenAllowed() ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Children', 'motopress-hotel-booking' ); ?></td>
<td><?php echo $roomBreakdown['room']['children']; ?></td>
</tr>
<?php } ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Nights', 'motopress-hotel-booking' ); ?></td>
<td><?php echo count( $roomBreakdown['room']['list'] ); ?></td>
</tr>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Dates', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php _e( 'Amount', 'motopress-hotel-booking' ); ?></th>
</tr>
<?php foreach ( $roomBreakdown['room']['list'] as $date => $datePrice ) : ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php echo \MPHB\Utils\DateUtils::formatDateWPFront( \DateTime::createFromFormat( 'Y-m-d', $date ) ); ?></td>
<td class="mphb-table-price-column"><?php echo mphb_format_price( $datePrice ); ?></td>
</tr>
<?php endforeach; ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Dates Subtotal', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['room']['total'] ); ?></th>
</tr>
<?php if ( $roomBreakdown['room']['discount'] > 0 ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Discount', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( -$roomBreakdown['room']['discount'] ); ?></th>
</tr>
<?php } ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Accommodation Subtotal', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['room']['discount_total'] ); ?></th>
</tr>
<?php if ( isset( $roomBreakdown['taxes']['room'] ) && !empty( $roomBreakdown['taxes']['room']['list'] ) ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Accommodation Taxes', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php _e( 'Amount', 'motopress-hotel-booking' ); ?></th>
</tr>
<?php foreach ( $roomBreakdown['taxes']['room']['list'] as $roomTax ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php echo $roomTax['label']; ?></td>
<td class="mphb-table-price-column"><?php echo mphb_format_price( $roomTax['price'] ); ?></td>
</tr>
<?php } ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Accommodation Taxes Subtotal', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['taxes']['room']['total'] ); ?></th>
</tr>
<?php } ?>
<?php if ( isset( $roomBreakdown['services'] ) && !empty( $roomBreakdown['services']['list'] ) ) : ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 3 : 2 ); ?>">
<?php _e( 'Services', 'motopress-hotel-booking' ); ?>
</th>
</tr>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th><?php _e( 'Service', 'motopress-hotel-booking' ); ?></th>
<th><?php _e( 'Details', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php _e( 'Amount', 'motopress-hotel-booking' ); ?></th>
</tr>
<?php foreach ( $roomBreakdown['services']['list'] as $serviceDetails ) : ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td><?php echo $serviceDetails['title']; ?></td>
<td><?php echo $serviceDetails['details']; ?></td>
<td class="mphb-table-price-column"><?php echo mphb_format_price( $serviceDetails['total'] ); ?></td>
</tr>
<?php endforeach; ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>">
<?php _e( 'Services Subtotal', 'motopress-hotel-booking' ); ?>
</th>
<th class="mphb-table-price-column">
<?php echo mphb_format_price( $roomBreakdown['services']['total'] ); ?>
</th>
</tr>
<?php if ( isset( $roomBreakdown['taxes']['services'] ) && !empty( $roomBreakdown['taxes']['services']['list'] ) ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Service Taxes', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php _e( 'Amount', 'motopress-hotel-booking' ); ?></th>
</tr>
<?php foreach ( $roomBreakdown['taxes']['services']['list'] as $serviceTax ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php echo $serviceTax['label']; ?></td>
<td class="mphb-table-price-column"><?php echo mphb_format_price( $serviceTax['price'] ); ?></td>
</tr>
<?php } ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Service Taxes Subtotal', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['taxes']['services']['total'] ); ?></th>
</tr>
<?php } ?>
<?php endif; ?>
<?php if ( isset( $roomBreakdown['fees'] ) && !empty( $roomBreakdown['fees']['list'] ) ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Fees', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php _e( 'Amount', 'motopress-hotel-booking' ); ?></th>
</tr>
<?php foreach ( $roomBreakdown['fees']['list'] as $fee ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php echo $fee['label']; ?></td>
<td class="mphb-table-price-column"><?php echo mphb_format_price( $fee['price'] ); ?></td>
</tr>
<?php } ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Fees Subtotal', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['fees']['total'] ); ?></th>
</tr>
<?php if ( isset( $roomBreakdown['taxes']['fees'] ) && !empty( $roomBreakdown['taxes']['fees']['list'] ) ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Fee Taxes', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php _e( 'Amount', 'motopress-hotel-booking' ); ?></th>
</tr>
<?php foreach ( $roomBreakdown['taxes']['fees']['list'] as $feeTax ) { ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<td colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php echo $feeTax['label']; ?></td>
<td class="mphb-table-price-column"><?php echo mphb_format_price( $feeTax['price'] ); ?></td>
</tr>
<?php } ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Fee Taxes Subtotal', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['taxes']['fees']['total'] ); ?></th>
</tr>
<?php } ?>
<?php } ?>
<?php endif; ?>
<tr class="<?php echo esc_attr($foldedClass); ?>">
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php _e( 'Subtotal', 'motopress-hotel-booking' ); ?></th>
<th class="mphb-table-price-column"><?php echo mphb_format_price( $roomBreakdown['discount_total'] ); ?></th>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<?php if ( !empty( $priceBreakdown['coupon'] ) ) : ?>
<tr>
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>"><?php printf( __( 'Coupon: %s' ), $priceBreakdown['coupon']['code'] ); ?></th>
<td class="mphb-table-price-column">
<?php echo mphb_format_price( -1 * $priceBreakdown['coupon']['discount'] ); ?>
<a href="#" class="mphb-remove-coupon"><?php _e( 'Remove', 'motopress-hotel-booking' ); ?></a>
</td>
</tr>
<?php endif; ?>
<tr>
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>">
<?php _e( 'Total', 'motopress-hotel-booking' ); ?>
</th>
<th class="mphb-table-price-column">
<?php
echo mphb_format_price( $priceBreakdown['total'] );
?>
</th>
</tr>
<?php if ( !empty( $priceBreakdown['deposit'] ) ) : ?>
<tr>
<th colspan="<?php echo ( $useThreeColumns ? 2 : 1 ); ?>">
<?php _e( 'Deposit', 'motopress-hotel-booking' ); ?>
</th>
<th class="mphb-table-price-column">
<?php
echo mphb_format_price( $priceBreakdown['deposit'] );
?>
</th>
</tr>
<?php endif; ?>
</tfoot>
</table>
</div>
<br/>
<?php
//list your intended pages in an array
$intended_pages = array('post.php');
//get the current page name
$page_name= basename($_SERVER['PHP_SELF']);
//check if the current page is on the list
If(in_array($page_name, $intended_pages))
{
//current page is on the list so perform function
echo '<button onclick="java script:printDiv(\'printablediv\')" style="color:red;font-weight:bold;">Print Receipt <span class="dashicons dashicons-media-spreadsheet"></span></button>';
}
?>
<?php
endif;
return ob_get_clean();
}
public static function renderCheckInDateWPFormatted( Entities\Booking $booking ){
echo date_i18n( MPHB()->settings()->dateTime()->getDateFormatWP(), $booking->getCheckInDate()->getTimestamp() );
}
public static function renderCheckOutDateWPFormatted( Entities\Booking $booking ){
echo date_i18n( MPHB()->settings()->dateTime()->getDateFormatWP(), $booking->getCheckOutDate()->getTimestamp() );
}
public static function renderTotalPriceHTML( Entities\Booking $booking ){
echo mphb_format_price( $booking->getTotalPrice() );
}
}