Ejemplo n.º 1
0
    static function select_page()
    {
        global $wpdb, $EM_Pro, $EM_Notices;
        $url = empty($url) ? $_SERVER['REQUEST_URI'] : $url;
        //url to this page
        $limit = !empty($_REQUEST['limit']) && is_numeric($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
        //Default limit
        $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
        $offset = $page > 1 ? ($page - 1) * $limit : 0;
        $args = array('limit' => $limit, 'offset' => $offset);
        $coupons_mine_count = EM_Coupons::count(array('owner' => get_current_user_id()));
        $coupons_all_count = current_user_can('manage_others_bookings') ? EM_Coupons::count() : 0;
        if (!empty($_REQUEST['view']) && $_REQUEST['view'] == 'others' && current_user_can('manage_others_bookings')) {
            $coupons = EM_Coupons::get($args);
            $coupons_count = $coupons_all_count;
        } else {
            $coupons = EM_Coupons::get(array_merge($args, array('owner' => get_current_user_id())));
            $coupons_count = $coupons_mine_count;
        }
        ?>
		<div class='wrap'>
			<div class="icon32" id="icon-bookings"><br></div>
			<h2><?php 
        _e('Edit Coupons', 'em-pro');
        ?>
				<a href="<?php 
        echo add_query_arg(array('action' => 'edit'));
        ?>
" class="add-new-h2"><?php 
        esc_html_e_emp('Add New', 'dbem');
        ?>
</a>
			</h2>
			<?php 
        echo $EM_Notices;
        ?>
			<form id='coupons-filter' method='post' action=''>
				<input type='hidden' name='pno' value='<?php 
        echo $page;
        ?>
' />
				<div class="tablenav">			
					<div class="alignleft actions">
						<div class="subsubsub">
							<a href='<?php 
        echo em_add_get_params($_SERVER['REQUEST_URI'], array('view' => null, 'pno' => null));
        ?>
' <?php 
        echo empty($_REQUEST['view']) ? 'class="current"' : '';
        ?>
><?php 
        echo sprintf(esc_html__emp('My %s', 'dbem'), __('Coupons', 'em-pro'));
        ?>
 <span class="count">(<?php 
        echo $coupons_mine_count;
        ?>
)</span></a>
							<?php 
        if (current_user_can('manage_others_bookings')) {
            ?>
							&nbsp;|&nbsp;
							<a href='<?php 
            echo em_add_get_params($_SERVER['REQUEST_URI'], array('view' => 'others', 'pno' => null));
            ?>
' <?php 
            echo !empty($_REQUEST['view']) && $_REQUEST['view'] == 'others' ? 'class="current"' : '';
            ?>
><?php 
            echo sprintf(esc_html__emp('All %s', 'dbem'), __('Coupons', 'em-pro'));
            ?>
 <span class="count">(<?php 
            echo $coupons_all_count;
            ?>
)</span></a>
							<?php 
        }
        ?>
						</div>
					</div>
					<?php 
        if ($coupons_count >= $limit) {
            $coupons_nav = em_admin_paginate($coupons_count, $limit, $page);
            echo $coupons_nav;
        }
        ?>
				</div>
				<?php 
        if ($coupons_count > 0) {
            ?>
				<table class='widefat'>
					<thead>
						<tr>
							<th><?php 
            esc_html_e_emp('Name', 'dbem');
            ?>
</th>
							<th><?php 
            _e('Code', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Created By', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Description', 'em-pro');
            ?>
</th>  
							<th><?php 
            _e('Discount', 'em-pro');
            ?>
</th>   
							<th><?php 
            _e('Uses', 'em-pro');
            ?>
</th>       
						</tr>
					</thead>
					<tfoot>
						<tr>
							<th><?php 
            esc_html_e_emp('Name', 'dbem');
            ?>
</th>
							<th><?php 
            _e('Code', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Created By', 'em-pro');
            ?>
</th>
							<th><?php 
            _e('Description', 'em-pro');
            ?>
</th>  
							<th><?php 
            _e('Discount', 'em-pro');
            ?>
</th>   
							<th><?php 
            _e('Uses', 'em-pro');
            ?>
</th>
						</tr>
					</tfoot>
					<tbody>
						<?php 
            foreach ($coupons as $EM_Coupon) {
                ?>
	
							<tr>
								<td>
									<a href='<?php 
                echo admin_url('edit.php?post_type=' . EM_POST_TYPE_EVENT . '&amp;page=events-manager-coupons&amp;action=edit&amp;coupon_id=' . $EM_Coupon->coupon_id);
                ?>
'><?php 
                echo $EM_Coupon->coupon_name;
                ?>
</a>
									<div class="row-actions">
										<span class="trash"><a class="submitdelete" href="<?php 
                echo add_query_arg(array('coupon_id' => $EM_Coupon->coupon_id, 'action' => 'coupon_delete', '_wpnonce' => wp_create_nonce('coupon_delete_' . $EM_Coupon->coupon_id)));
                ?>
"><?php 
                _e('Delete', 'em-pro');
                ?>
</a></span>
									</div>
								</td>
								<td><?php 
                echo esc_html($EM_Coupon->coupon_code);
                ?>
</td>
								<td><a href="<?php 
                echo admin_url('user-edit.php?user_id=' . $EM_Coupon->get_person()->ID);
                ?>
"><?php 
                echo $EM_Coupon->get_person()->get_name();
                ?>
</a></td>
								<td><?php 
                echo esc_html($EM_Coupon->coupon_description);
                ?>
</td>  
								<td><?php 
                echo $EM_Coupon->get_discount_text();
                ?>
</td>            
								<td>
									<a href='<?php 
                echo admin_url('edit.php?post_type=' . EM_POST_TYPE_EVENT . '&amp;page=events-manager-coupons&amp;action=view&amp;coupon_id=' . $EM_Coupon->coupon_id);
                ?>
'>
									<?php 
                if (!empty($EM_Coupon->coupon_max)) {
                    echo esc_html($EM_Coupon->get_count() . '/' . $EM_Coupon->coupon_max);
                } else {
                    echo esc_html($EM_Coupon->get_count() . '/' . __('Unlimited', 'em-pro'));
                }
                ?>
									</a>
								</td>                 
							</tr>
						<?php 
            }
            ?>
					</tbody>
				</table>
				<?php 
        } else {
            ?>
				<br class="clear" />
				<p><?php 
            _e('No coupons have been inserted yet!', 'em-pro');
            ?>
</p>
				<?php 
        }
        ?>
				
				<?php 
        if (!empty($coupons_nav)) {
            echo '<div class="tablenav">' . $coupons_nav . '</div>';
        }
        ?>
			</form>

		</div> <!-- wrap -->
		<?php 
    }
Ejemplo n.º 2
0
    /**
     * Echoes a coupon code field in the footer of the cart page. Currently used in MB mode only.
     * @param EM_Multiple_Booking $EM_Booking
     */
    public static function em_cart_footer($EM_Booking)
    {
        if (!self::booking_has_coupons($EM_Booking) && EM_Coupons::count(array('limit' => 1)) > 0) {
            ?>
		<form id='em-cart-coupons-form' class="em-cart-coupons-form em-cart-actions" name='cart-coupons-form' method='post' action='<?php 
            echo apply_filters('em_checkout_coupons_form_action_url', '');
            ?>
#em-booking'>
		 	<input type='hidden' name='action' value='em_coupon_apply'/>
		 	<input type='hidden' name='_wpnonce' value='<?php 
            echo wp_create_nonce('emp_checkout');
            ?>
'/>
		 	<div>
				<input type="text" name="coupon_code" class="input em-coupon-code" />
				<button type="submit" class="em-coupon-code"><?php 
            _e('Apply Discount', 'em-pro');
            ?>
</button>
			</div>
		</form>
		<?php 
        }
        add_action('em_cart_js_footer', array('EM_Coupons', 'em_cart_gateway_js'));
        add_action('em_cart_gateway_js', array('EM_Coupons', 'em_cart_gateway_js'));
    }