static function view_page()
    {
        global $EM_Notices, $EM_Coupon, $wpdb;
        //check that user can access this page
        if (is_object($EM_Coupon) && !$EM_Coupon->can_manage('manage_bookings', 'manage_others_bookings')) {
            ?>
			<div class="wrap"><h2><?php 
            esc_html_e_emp('Unauthorized Access', 'dbem');
            ?>
</h2><p><?php 
            echo sprintf(esc_html__emp('You do not have the rights to manage this %s.', 'dbem'), __('coupon', 'em-pro'));
            ?>
</p></div>
			<?php 
            return false;
        } elseif (!is_object($EM_Coupon)) {
            $EM_Coupon = new EM_Coupon();
        }
        $limit = !empty($_GET['limit']) ? $_GET['limit'] : 20;
        //Default limit
        $page = !empty($_GET['pno']) ? $_GET['pno'] : 1;
        $offset = $page > 1 ? ($page - 1) * $limit : 0;
        //a bit hacky, but this is the only way at least for now
        $coupon_search = str_replace('a:1:{', '', serialize(array('coupon_code' => $EM_Coupon->coupon_code)));
        $coupon_search = substr($coupon_search, 0, strlen($coupon_search) - 1);
        $bookings = $wpdb->get_col('SELECT booking_id FROM ' . EM_BOOKINGS_TABLE . " WHERE booking_meta LIKE '%{$coupon_search}%' LIMIT {$limit} OFFSET {$offset}");
        //FIXME : coupon count not syncing correctly, using this as a fallback
        $coupons_count = $wpdb->get_var('SELECT COUNT(*) FROM ' . EM_BOOKINGS_TABLE . " WHERE booking_meta LIKE '%{$coupon_search}%'");
        $bookings_count = 0;
        $EM_Bookings = array();
        foreach ($bookings as $booking_id) {
            $EM_Booking = em_get_booking($booking_id);
            if (!empty($EM_Booking->booking_meta['coupon'])) {
                $coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
                if ($EM_Coupon->coupon_code == $coupon->coupon_code && $EM_Coupon->coupon_id == $coupon->coupon_id) {
                    $bookings_count++;
                    $EM_Bookings[] = $EM_Booking;
                }
            }
        }
        ?>
		<div class='wrap nosubsub'>
			<div class="icon32" id="icon-bookings"><br></div>
			<h2><?php 
        _e('Coupon Usage History', 'em-pro');
        ?>
</h2>
			<?php 
        echo $EM_Notices;
        ?>
			<p><?php 
        echo sprintf(__('You are viewing the details of coupon %s - <a href="%s">edit</a>', 'em-pro'), '<code>' . $EM_Coupon->coupon_code . '</code>', add_query_arg(array('action' => 'edit')));
        ?>
</p>
			<p>
				<strong><?php 
        echo __('Uses', 'em-pro');
        ?>
:</strong> 
				<?php 
        if (!empty($EM_Coupon->coupon_max)) {
            echo esc_html($coupons_count . ' / ' . $EM_Coupon->coupon_max);
        } else {
            echo esc_html($coupons_count . '/' . __('Unlimited', 'em-pro'));
        }
        ?>
			</p>
			<?php 
        if ($coupons_count >= $limit) {
            ?>
			<div class='tablenav'>
				<?php 
            $bookings_nav = em_admin_paginate($coupons_count, $limit, $page, array());
            echo $bookings_nav;
            ?>
				<div class="clear"></div>
			</div>
			<?php 
        }
        ?>
			<div class="clear"></div>
			<?php 
        if ($bookings_count > 0) {
            ?>
			<div class='table-wrap'>
				<table id='dbem-bookings-table' class='widefat post '>
					<thead>
						<tr>
							<th class='manage-column' scope='col'><?php 
            esc_html_e_emp('Event', 'dbem');
            ?>
</th>
							<th class='manage-column' scope='col'><?php 
            esc_html_e_emp('Booker', 'dbem');
            ?>
</th>
							<th class='manage-column' scope='col'><?php 
            esc_html_e_emp('Spaces', 'dbem');
            ?>
</th>
							<th><?php 
            _e('Original Total Price', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Coupon Discount', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Final Price', 'em-pro');
            ?>
</th>
							<th>&nbsp;</th>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<th class='manage-column' scope='col'><?php 
            esc_html_e_emp('Event', 'dbem');
            ?>
</th>
							<th class='manage-column' scope='col'><?php 
            esc_html_e_emp('Booker', 'dbem');
            ?>
</th>
							<th class='manage-column' scope='col'><?php 
            esc_html_e_emp('Spaces', 'dbem');
            ?>
</th>
							<th><?php 
            _e('Original Total Price', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Coupon Discount', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Final Price', 'em-pro');
            ?>
</th>
							<th>&nbsp;</th>
						</tr>
					</tfoot>
					<tbody>
						<?php 
            foreach ($EM_Bookings as $EM_Booking) {
                ?>
							<tr>
								<td><?php 
                echo $EM_Booking->output('#_BOOKINGSLINK');
                ?>
</td>
								<td><a href="<?php 
                echo EM_ADMIN_URL;
                ?>
&amp;page=events-manager-bookings&amp;person_id=<?php 
                echo $EM_Booking->person_id;
                ?>
"><?php 
                echo $EM_Booking->person->get_name();
                ?>
</a></td>
								<td><?php 
                echo $EM_Booking->get_spaces();
                ?>
</td>
								<td><?php 
                echo em_get_currency_formatted($EM_Booking->booking_meta['original_price']);
                ?>
</td>
								<td><?php 
                echo em_get_currency_formatted($EM_Booking->booking_meta['original_price'] - $EM_Booking->get_price());
                ?>
 <em>(<?php 
                echo $EM_Coupon->get_discount_text();
                ?>
)</em></td>
								<td><?php 
                echo em_get_currency_formatted($EM_Booking->get_price());
                ?>
</td>
								<td>										
									<?php 
                $edit_url = em_add_get_params($_SERVER['REQUEST_URI'], array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null));
                ?>
									<?php 
                if ($EM_Booking->can_manage()) {
                    ?>
									<a class="em-bookings-edit" href="<?php 
                    echo $edit_url;
                    ?>
"><?php 
                    esc_html_e_emp('Edit/View', 'dbem');
                    ?>
</a>
									<?php 
                }
                ?>
								</td>
							</tr>
							<?php 
            }
            ?>
					</tbody>
				</table>
			</div> <!-- table-wrap -->
			<?php 
        } else {
            ?>
			<p><?php 
            _e('Your coupon hasn\'t been used yet!', 'em-pro');
            ?>
</p>
			<?php 
        }
        ?>
		</div> <!-- wrap -->
		<?php 
    }
Example #2
0
 /**
  * @param string $replace
  * @param EM_Booking $EM_Booking
  * @param string $full_result
  * @return string
  */
 public static function placeholders($replace, $EM_Booking, $full_result)
 {
     if (empty($replace) || $replace == $full_result) {
         if ($full_result == '#_BOOKINGCOUPON') {
             $replace = '';
             if (!empty($EM_Booking->booking_meta['coupon'])) {
                 $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
                 $replace = $EM_Coupon->coupon_code . ' - ' . $EM_Coupon->get_discount_text();
             }
         } elseif ($full_result == '#_BOOKINGCOUPONCODE') {
             $replace = '';
             if (!empty($EM_Booking->booking_meta['coupon'])) {
                 $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
                 $replace = $EM_Coupon->coupon_code;
             }
         } elseif ($full_result == '#_BOOKINGCOUPONDISCOUNT') {
             $replace = '';
             if (!empty($EM_Booking->booking_meta['coupon'])) {
                 $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
                 $replace = $EM_Coupon->get_discount_text();
             }
         } elseif ($full_result == '#_BOOKINGCOUPONNAME') {
             $replace = '';
             if (!empty($EM_Booking->booking_meta['coupon'])) {
                 $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
                 $replace = $EM_Coupon->coupon_name;
             }
         } elseif ($full_result == '#_BOOKINGCOUPONDESCRIPTION') {
             $replace = '';
             if (!empty($EM_Booking->booking_meta['coupon'])) {
                 $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
                 $replace = $EM_Coupon->coupon_description;
             }
         }
     }
     return $replace;
     //no need for a filter, use the em_booking_email_placeholders filter
 }