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')) { ?> | <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 . '&page=events-manager-coupons&action=edit&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 . '&page=events-manager-coupons&action=view&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 }
public static function em_event_get_post($result, $EM_Event) { $EM_Event->coupons = array(); if (!empty($_REQUEST['em_coupons']) && is_array($_REQUEST['em_coupons'])) { $EM_Event->coupons = EM_Coupons::get($_REQUEST['em_coupons']); } return $result; }