<div class="wrap">
 <h1>Register Data</h1>
 <script type="text/javascript">

function eventer_row_check_bulk_action() {

	var params = '';
	if (jQuery("#action").val() != '') {
		jQuery(".deletecheck").each(function() {
			if (jQuery(this).attr('checked') == true) {
		
				if (params == '') {
					params += jQuery(this).val();
				} else {
					params += ';' + jQuery(this).val();
				}
			}
		});
     
		jQuery("#selected_values").val(params);

		return true;
	}

	return false;
}function eventer_row_check_bulk_action1() {
document.eventer.submit();
}
</script>
 <?php


function get_saveTablename()
{
global $wpdb;
$table_name = $wpdb->prefix . 'eventer';	
return $table_name;
}
	/**
	* delete game
	**/
	function eventer_row_admin_delete($dbID) {
		
		 global $wpdb;
         $table_name = get_saveTablename();	
		$wpdb->query("DELETE FROM $table_name WHERE dbID='" . $dbID . "'");
		
	

	}

	function eventer_get_admin_pages($keyword = '') {

		global $wpdb;
		$table_name = get_saveTablename();
		$search_query="";
		$self_url =  get_bloginfo("url")."/wp-admin/admin.php?page=eventer";	
		
		$page = null;
		$per_page = 15;
	
		if(isset($_GET['pageno'])  and $_GET['pageno'] > 0) {
			$page = intval($_GET['pageno']);
		} else {
			$page = 1;
		}
        
		 $num_row = $wpdb->get_var("SELECT COUNT(g.dbID) FROM $table_name g where dbID!=0  $search_query");
		
		if (isset($per_page)) {
			$num_pages = ceil($num_row / $per_page);
		}
		
		if($page !== null) {
			$page_links = paginate_links( array(
				'base' => $self_url . '&pageno=%#%',
				'format' => '',
				'prev_text' => __('&laquo;'),
				'next_text' => __('&raquo;'),
				'total' => $num_pages,
				'current' => $page
			));

			if ($page_links) {

	?>
 <div class="tablenav-pages"> <?php echo $page_links; ?> </div>
 <?php
			}
		}
	}

	/**
	* get mochi row
	**/
	function get_eventer_data($keyword = '') {

		global $wpdb;
		$table_name = get_saveTablename();
		$search_query="";
		if (isset($_GET['EventID'])) {
        $EventID = $_GET['EventID'];	
		$search_query .= " and  EventID like '%$EventID%' ";

		}
		if (isset($_GET['emailAddress'])) {
        $search_query .= " and  emailAddress like '%$_GET[emailAddress]%' ";
		}
        $page = null;
		$per_page = 15;

		if(isset($_GET['pageno'])  and  $_GET['pageno']> 0) {
			$page = intval($_GET['pageno']);
		} else {
			$page = 1;
		}

		$start = (int)($page * $per_page) - $per_page;
	 	$sql = "SELECT  * FROM $table_name where 1=1 ORDER BY createdDate DESC LIMIT $start, $per_page";		
		$row = $wpdb->get_results($sql, ARRAY_A);
if (!empty($row)) {
			foreach($row as $data) {
			global $wpdb;
	 	 
			
	?>
 <tr id="local-<?php echo $data['dbID']; ?>">
  <th class="check-column" scope="row"><input type='checkbox' name='eventer[]' class='deletecheck' id="<?php echo $data['dbID']; ?>" value='<?php echo $data['dbID']; ?>' /></th>
  <td class="game-width column-width"><?php echo stripslashes($data['EventID'])?></td>
  <td class="game-width column-width"><?php echo stripslashes($data['emailAddress'])?></td>
  <td class="game-width column-width"><?php echo stripslashes($data['location'])?></td>
  <td class="game-category column-category"><?php echo stripslashes($data['option1'])?></td>
  <td class="game-category column-category"><?php echo stripslashes($data['option2'])?></td>
  <td class="game-category column-category"><?php echo stripslashes($data['option3'])?></td>
  <td class="game-category column-category"><?php echo stripslashes($data['option4'])?></td>
  <td class="game-category column-category"><?php echo stripslashes($data['option5'])?></td>
  <td class="game-category column-category"><?php echo stripslashes($data['option6'])?></td>
  <td class="game-category column-category"><?php echo stripslashes($data['createdDate'])?></td>
 </tr>
 <?php
			}
		} else {
	?>
 <tr>
  <td colspan="7"><?php _e('No Values') ?></td>
 </tr>
 <?php
		}	
	}

	$columns = array(
	  'cb' => '<input type="checkbox" />',
	    'EventID' => 'EventID',
	  'Event' => 'Event',
	  'Event' => 'Email',
	  'Location' => 'Location',
      'Option1' => 'Option1',
	  'Option2' => 'Option2',
	  'Option3' => 'Option3',
	  'Option4' => 'Option4',
	  'Option5' => 'Option5',
	    'Option6' => 'Option6',
	  'adddate' => 'Date',
	
	);

	register_column_headers('display-eventer-list', $columns);
	$search_keyword ="";
    if(isset($_POST['search_keyword']))
	$search_keyword = $_POST['search_keyword'];
	
	// bulk action

	if (!empty($_POST['eventer'] )) {
		foreach($_POST['eventer'] as $selected_value) {
			if ($_POST['action'] == 'delete') {
			
				eventer_row_admin_delete($selected_value);
			}
		}
	}
?>
 <div class="tablenav top">
  <div  class="alignleft actions">
   <form method="post" onsubmit="return eventer_row_check_bulk_action1();">
    <input type="hidden" name="selected_values" id="selected_values" />
    <select id="action" name="action">
     <option value="" selected="selected">
     <?php _e('Bulk Actions'); ?>
     </option>
     <option value="delete">
     <?php _e('Delete'); ?>
     </option>
    </select>
    <input type="button" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" onclick="eventer_row_check_bulk_action1()" class="button-secondary action" />
    <?php wp_nonce_field('bulk-posts'); ?>
   </form>
  </div>
  <?php echo eventer_get_admin_pages($search_keyword); ?> </div>
 <table id="mspt_property_list" class="widefat post fixed" cellspacing="0">
  <thead>
   <tr> <?php print_column_headers('display-eventer-list'); ?> </tr>
  </thead>
  <tbody>
  <form method="post" name="eventer" id="eventer" onsubmit="return eventer_row_check_bulk_action();">
   <?php get_eventer_data($search_keyword); ?>
   <input type="hidden" id="action" name="action" value="delete">
  </form>
  </tbody>
  
  <tfoot>
   <tr> <?php print_column_headers('display-eventer-list'); ?> </tr>
  </tfoot>
 </table>
</div>
