function espresso_promocodes_datatables_search() { //note: this is meant ot respond to an ajax request sent by jquery datatables //and here is an example of the $_GET parameters it contains: // [action] => event_espresso_get_discount_codes_for_jquery_datatables //this is just used for wp ajax integration // [sEcho] => 9 //this value simply needs to be echoed back to the jquery data tables // [iColumns] => 6 // [sColumns] => // [iDisplayStart] => 0 // [iDisplayLength] => 10 // [sSearch] => monkey //the search string // [bRegex] => false // [sSearch_0] => //I suppose this would be filled IF we allowed them to have different searches on different column // [bRegex_0] => false // [bSearchable_0] => true // [sSearch_1] => // [bRegex_1] => false // [bSearchable_1] => true // [sSearch_2] => // [bRegex_2] => false // [bSearchable_2] => true // [sSearch_3] => // [bRegex_3] => false // [bSearchable_3] => true // [sSearch_4] => // [bRegex_4] => false // [bSearchable_4] => true // [sSearch_5] => // [bRegex_5] => false // [bSearchable_5] => true // [iSortingCols] => 1 //number of columns we're sorting on right now // [iSortCol_0] => 0 //the first column that we're sorting by... this should actually mean we're NOT sorting in this case, because 0 is not sortable // [sSortDir_0] => asc //sort by the 1st column in ascending order, except that we don't sort by that 1st column as indicated below // [bSortable_0] => false // [bSortable_1] => true // [bSortable_2] => true // [bSortable_3] => true // [bSortable_4] => true // [bSortable_5] => true // [_] => 1372206625831 $search = isset($_GET['sSearch']) ? sanitize_text_field($_GET['sSearch']) : ''; $jquery_datatable_column_to_sql_column_mapping = array(); $jquery_datatable_column_to_sql_column_mapping[] = 'id'; //the first column is actually the checkbox, which shouldn't be ordered by. $jquery_datatable_column_to_sql_column_mapping[] = 'id'; //ID $jquery_datatable_column_to_sql_column_mapping[] = 'coupon_code'; //Name if (function_exists('espresso_is_admin') && espresso_is_admin() == true) { $jquery_datatable_column_to_sql_column_mapping[] = 'wp_user'; //Author } $jquery_datatable_column_to_sql_column_mapping[] = 'coupon_code_price'; //Amount $jquery_datatable_column_to_sql_column_mapping[] = 'use_percentage'; //Percentage $jquery_datatable_column_to_sql_column_mapping[] = 'apply_to_all'; //Global $order_column = $jquery_datatable_column_to_sql_column_mapping[intval($_GET['iSortCol_0'])]; $sort_order = isset($_GET['sSortDir_0']) && $_GET['sSortDir_0'] == 'asc' ? 'asc' : 'desc'; $start = intval($_GET['iDisplayStart']); $count = intval($_GET['iDisplayLength']); global $wpdb; $where_conditions = " WHERE coupon_code LIKE '%{$search}%' OR coupon_code_description LIKE '%{$search}%' OR coupon_code_price like '%{$search}%'"; $query = "SELECT * FROM " . EVENTS_DISCOUNT_CODES_TABLE . " \n\t\t{$where_conditions}\n\t\tORDER BY {$order_column} {$sort_order} LIMIT {$start},{$count}"; $wpdb_results = $wpdb->get_results($query); $total_result = espresso_promocodes_count_total(); $total_filtered_result = $wpdb->get_var("SELECT count(id) FROM " . EVENTS_DISCOUNT_CODES_TABLE . $where_conditions); $prepared_results = espresso_promocodes_format_for_jquery_datatables($wpdb_results); $output = array('sColumns' => 'Checkbox, ID, Name, Amount, Percentage, Global', 'sEcho' => intval($_GET['sEcho']), 'iTotalRecords' => $total_result, 'iTotalDisplayRecords' => $total_filtered_result, 'aaData' => $prepared_results); //- See more at: http://www.koolkatwebdesigns.com/using-jquery-datatables-with-wordpress-and-ajax/#sthash.H0zsZy6z.dpuf echo json_encode($output); die; }
function event_espresso_discount_config_mnu() { global $wpdb; require_once "search.php"; ?> <div class="wrap"> <div id="icon-options-event" class="icon32"> </div> <h2><?php echo _e('Manage Event Promotional Codes', 'event_espresso'); ?> <?php if (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'edit' && $_REQUEST['action'] != 'new') { echo '<a href="admin.php?page=discounts&action=new" class="button add-new-h2" style="margin-left: 20px;">' . __('Add New Code', 'event_espresso') . '</a>'; } ?> </h2> <?php ob_start(); $button_style = 'button-primary'; if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'add': require_once "add_discount.php"; add_discount_to_db(); //Add the discount to the DB break; case 'new': require_once "new_discount.php"; add_new_event_discount(); //Add new discount form $button_style = 'button-secondary'; break; case 'edit': require_once "edit_discount.php"; edit_event_discount(); //Edit discount form $button_style = 'button-secondary'; break; case 'update': require_once "update_discount.php"; update_event_discount(); //Update discount in DB break; case 'delete_discount': require_once "delete_discount.php"; delete_event_discount(); //Delete discount in DB break; } } if (!empty($_REQUEST['delete_discount'])) { //This is for the delete checkboxes require_once "delete_discount.php"; delete_event_discount(); } ?> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?> "> <table id="table" class="widefat manage-discounts"> <thead> <tr> <th class="manage-column column-cb check-column" id="cb" scope="col" style="width:2.5%;"><input type="checkbox"></th> <th class="manage-column column-comments num" id="id" style="padding-top:7px; width:2.5%;" scope="col" title="Click to Sort"><?php _e('ID', 'event_espresso'); ?> </th> <th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:20%;"><?php _e('Name', 'event_espresso'); ?> </th> <?php if (function_exists('espresso_is_admin') && espresso_is_admin() == true) { ?> <th class="manage-column column-creator" id="creator" scope="col" title="Click to Sort" style="width:10%;"><?php _e('Creator', 'event_espresso'); ?> </th> <?php } ?> <th class="manage-column column-author" id="start" scope="col" title="Click to Sort" style="width:20%;"><?php _e('Amount', 'event_espresso'); ?> </th> <th class="manage-column column-date" id="begins" scope="col" title="Click to Sort" style="width:20%;"><?php _e('Percentage', 'event_espresso'); ?> </th> <th class="manage-column column-date" id="begins" scope="col" title="Click to Sort" style="width:20%;"><?php _e('Global', 'event_espresso'); ?> </th> </tr> </thead> <tbody> <tr> <td colspan=6 class='dataTables_empty' style='text-align:center'> <?php _e("Loading...", "event_espresso"); ?> </td> </tr> <!-- <?php /*foreach(espresso_promocodes_initial_jquery_datatables_data() as $row){?> <tr> <?php foreach($row as $column){ ?> <td><?php echo $column?></td> <?php } ?> </tr> <?php } */ ?> --> </tbody> </thead> </table> <div style="clear:both"> <p><input type="checkbox" name="sAll" onclick="selectAll(this)" /> <strong> <?php _e('Check All', 'event_espresso'); ?> </strong> <input name="delete_discount" type="submit" class="button-secondary" id="delete_discount" value="<?php _e('Delete Promotional Code', 'event_espresso'); ?> " style="margin:10 0 0 10px;" onclick="return confirmDelete();"> <a style="margin-left:5px"class="<?php echo $button_style; ?> " href="admin.php?page=discounts&action=new"><?php _e('Add New Promotional Code', 'event_espresso'); ?> </a></p> </div> </form> <?php $main_post_content = ob_get_clean(); espresso_choose_layout($main_post_content, event_espresso_display_right_column()); ?> </div> <script type="text/javascript"> jQuery(document).ready(function($) { /* show the table data */ var mytable = $('#table').dataTable( { "aoColumns": [ { "bSortable": false }, null, null, null, null, <?php echo function_exists('espresso_is_admin') && espresso_is_admin() == true ? 'null,' : ''; ?> null ], 'bProcessing': true, 'bServerSide': true, // "bDeferRender": true, 'sAjaxSource': ajaxurl+'?action=event_espresso_get_discount_codes_for_jquery_datatables',// - See more at: http://www.koolkatwebdesigns.com/using-jquery-datatables-with-wordpress-and-ajax/#sthash.H0zsZy6z.dpuf "iDeferLoading": <?php echo espresso_promocodes_count_total(); ?> , "bStateSave": true, "sPaginationType": "full_numbers", "oLanguage": { "sSearch": "<strong><?php _e('Live Search Filter', 'event_espresso'); ?> :</strong>", "sZeroRecords": "<?php _e('No Records Found!', 'event_espresso'); ?> ", "sProcessing": "<img src='<?php echo EVENT_ESPRESSO_PLUGINFULLURL . "images/ajax-loader.gif"; ?> '>"} } ); } ); // Add new promo code form validation jQuery(function(){ jQuery("#new-promo-code").validate( { rules: { coupon_code: "required" }, messages: { coupon_code: "Please add your promotional code" } }); }); </script> <?php }