Ask your WordPress questions! Pay money and get answers fast! (more info)

WP_List_Table - Add Bulk Delete and Delete function WordPress

  • SOLVED

Hi There,

I have a WP_List_Table plugin that I am using that does not have the ability to delete singularly or via bulk. Could you please see the code below and tell me what I need to add?


<?php
/*
Plugin Name: Job Application List
*/

if( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}

class Job_Application_List_Table extends WP_List_Table {

function __construct(){

global $status, $page;

parent::__construct( array(
'singular' => __( 'application', 'mylisttable' ), //singular name of the listed records
'plural' => __( 'applications', 'mylisttable' ), //plural name of the listed records
'ajax' => false //does this table support ajax?
));

add_action( 'admin_head', array( &$this, 'admin_header' ) );

}

function admin_header() {

$page = ( isset($_GET['page'] ) ) ? esc_attr( $_GET['page'] ) : false;

if( 'my_list_test' != $page ) {
return;
}

echo '<style type="text/css">';
echo '.wp-list-table .column-id { width: 5%; }';
echo '.wp-list-table .column-booktitle { width: 40%; }';
echo '.wp-list-table .column-author { width: 35%; }';
echo '.wp-list-table .column-isbn { width: 20%;}';
echo '</style>';

}

function no_items() {
_e( 'No applications found.' );
}

function column_default( $item, $column_name ) {
switch( $column_name ) {
case 'date_submitted':
case 'job_pos':
case 'first_names':
case 'last_name':
case 'preferred_name':
case 'email_address':
case 'mobile':
return $item->$column_name;
default:
return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
}
}

function get_sortable_columns() {
$sortable_columns = array(
'date_submitted' => array('date_submitted',false),
'job_pos' => array('job_pos',false),
'first_names' => array('first_names',false),
'last_name' => array('last_name',false),
'email_address' => array('email_address',false),
'mobile' => array('mobile',false)
);
return $sortable_columns;
}

function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'date_submitted' => __( 'Submitted', 'mylisttable' ),
'job_pos' => __( 'Position', 'mylisttable' ),
'first_names' => __( 'First Names', 'mylisttable' ),
'last_name' => __( 'Last Name', 'mylisttable' ),
'email_address' => __( 'Email Address', 'mylisttable' ),
'mobile' => __( 'Mobile', 'mylisttable' )
);
return $columns;
}

function usort_reorder( $a, $b ) {
// If no sort, default to title
$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'date_submitted';
// If no order, default to asc
$order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';
// Determine sort order
$result = strcmp( $a[$orderby], $b[$orderby] );
// Send final sort direction to usort
return ( $order === 'asc' ) ? $result : -$result;
}

function column_date_submitted($item){
$actions = array(
'edit' => sprintf('<a href="?page=view_application&application=%s">View</a>', $item->id),
'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>','delete',$item->id)
);

return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );
}

function get_bulk_actions() {
$actions = array(
'delete' => 'Delete'
);
return $actions;
}

function column_cb($item) {
return sprintf(
'<input type="checkbox" name="application[]" value="%s" />', $item->id
);
}

function prepare_items() {

global $wpdb, $_wp_column_headers;
$screen = get_current_screen();

$where_search = "";
if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {
$search = $_REQUEST['s'];
$where_search = "WHERE job_pos LIKE '%{$search}%'
OR first_names LIKE '%{$search}%'
OR last_name LIKE '%{$search}%'
OR email_address LIKE '%{$search}%'
";
}

$query = "SELECT
id,
date_submitted,
job_pos,
first_names,
last_name,
email_address,
mobile
FROM wp_job_applications
{$where_search}
";

$orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'ASC';
$order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : '';

if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }

$totalitems = $wpdb->query($query);
$perpage = 20;
$paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';
if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }
$totalpages = ceil($totalitems/$perpage);
if(!empty($paged) && !empty($perpage)){
$offset=($paged-1)*$perpage;
$query.=' LIMIT '.(int)$offset.','.(int)$perpage;
}

$this->set_pagination_args( array(
"total_items" => $totalitems,
"total_pages" => $totalpages,
"per_page" => $perpage,
) );

$columns = $this->get_columns();
$_wp_column_headers[$screen->id]=$columns;

// echo $query;

$this->items = $wpdb->get_results($query);

}

} //class



function my_add_menu_items(){

$hook = add_menu_page( 'Job Applications', 'Job Applications', 'edit_posts', 'job_application_list', 'render_job_application_list', null, 150 );
add_action( "load-$hook", 'application_add_options' );

add_submenu_page( null, 'Edit Application', 'Edit Application', 'edit_posts', 'view_application', 'render_view_application' );

}

function application_add_options() {
global $myListTable;
$option = 'per_page';
$args = array(
'label' => 'Applications',
'default' => 10,
'option' => 'applications_per_page'
);
add_screen_option( $option, $args );
$myListTable = new Job_Application_List_Table();
}
add_action( 'admin_menu', 'my_add_menu_items' );



function render_job_application_list(){
global $myListTable;
echo '<div class="wrap"><h2>Job Applications</h2>';

echo '<form method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php">';
echo '<input type="submit" name="Submit" value="Export List To CSV" />';
echo '</form>';

$myListTable->prepare_items();
?>
<form method="post">
<input type="hidden" name="page" value="ttest_list_table">
<?php
$myListTable->search_box( 'search', 'search_id' );

$myListTable->display();

echo '</form></div>';
}

function addToRenderShifts( $application, $day ) {

$message = '';

$day_id = str_replace(' ', '_', strtolower( $day ) );

if ( isset($application[$day_id]) ) {
$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . ":</span> Yes</div>";
}
if ( isset($application[$day_id . '_morning_shifts']) ) {
$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Morning Shifts:</span> Yes</div>";
}
if ( isset($application[$day_id . '_afternoon_shifts']) ) {
$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Afternoon Shifts:</span> Yes</div>";
}
if ( isset($application[$day_id . '_night_shift']) ) {
$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift:</span> Yes</div>";
}
if ( isset($application[$day_id . '_night_shift_alt']) ) {
$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift Alt:</span> Yes</div>";
}
if ( isset($application[$day_id . '_tea_shifts']) ) {
$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Tea Shifts:</span> Yes</div>";
}

return $message;

}

function render_application_data($application) {

$message = '';

$message .= "<div class=\"field\"><span class=\"label\">Job Position" . ": </span>" . $application['job_pos'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Last Name" . ": </span>" . $application['last_name'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">First Names" . ": </span>" . $application['first_names'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Preferred Name" . ": </span>" . $application['preferred_name'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Date of Birth" . ": </span>" . $application['dob'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Your Address" . ": </span>" . $application['your_address'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">State" . ": </span>" . $application['state'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Postcode" . ": </span>" . $application['postcode'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Daytime Phone Number" . ": </span>" . $application['daytime_phone_number'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Mobile" . ": </span>" . $application['mobile'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Email Address" . ": </span>" . $application['email_address'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Are you of an Aboriginal or Torres Strait Islander background?" . ": </span>" . $application['aboriginal_torres'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Do you speak a language/s other than English at home?" . ": </span>" . $application['other_languages'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">If yes, what language is that?" . ": </span>" . $application['languages_list'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Are you legally entitled to work in Australia/New Zealand?" . ": </span>" . $application['legally_entitled'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Please provide details of your Visa" . ": </span>" . $application['visa_details'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">When does your visa expire?" . ": </span>" . $application['visa_expire'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Drivers License Number" . ": </span>" . $application['drivers_license_number'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">State of issue" . ": </span>" . $application['license_state_of_issue'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Class" . ": </span>" . $application['license_class'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Expiry Date" . ": </span>" . $application['license_expiry_date'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Type" . ": </span>" . $application['license_type'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Have you ever been disqualified from driving?" . ": </span>" . $application['disqualified_driving'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['disqualified_driving_details'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Do you own a reliable vehicle?" . ": </span>" . $application['reliable_vehicle'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Do you have a criminal record, or have a charge pending before any court?" . ": </span>" . $application['criminal_record'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['criminal_record_details'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Have you claimed workers compensation in the last five (5) years?" . ": </span>" . $application['workers_comp'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['workers_comp_details'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Do you have a medical condition that could interfere with your ability to<br />perform the duties of the position?" . ": </span>" . $application['medical_conditions'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['medical_conditions_details'] . "</div>";
if (isset($application['hear_about_position'])) {
$message .= "<div class=\"field\"><span class=\"label\">How did you hear about this position at Nulsen?" . ": </span>" . $application['hear_about_position'] . "</div>";
}
if (isset($application['hear_about_from_where'])) {
$message .= "<div class=\"field\"><span class=\"label\">Further information on source" . ": </span>" . $application['hear_about_from_where'] . "</div>";
}
if (isset($application['dsc_worked_12_months'])) {
$message .= "<div class=\"field\"><span class=\"label\">Are you currently working or have you ever worked with the Western Australian Disability Services Commission (DSC) in the last 12 months?" . ": </span>" . $application['dsc_worked_12_months'] . "</div>";
}
if (isset($application['dsc_capacity_employed'])) {
$message .= "<div class=\"field\"><span class=\"label\">If yes, in what capacity were you employed with DSC?" . ": </span>" . $application['dsc_capacity_employed'] . "</div>";
}
if (isset($application['dsc_date_terminated'])) {
$message .= "<div class=\"field\"><span class=\"label\">If you resigned or your employment was terminated with DSC, on what date did your employment end with them?" . ": </span>" . $application['dsc_date_terminated'] . "</div>";
}
$message .= "<div class=\"field\"><span class=\"label\">Have you applied for a position with Nulsen before?" . ": </span>" . $application['applied_before'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Qualification 01" . ": </span>" . $application['qualification_01'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 01" . ": </span>" . $application['institution_01'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Year Completed 01" . ": </span>" . $application['year_completed_01'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Qualification 02" . ": </span>" . $application['qualification_02'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 02" . ": </span>" . $application['institution_02'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">Year Completed 02" . ": </span>" . $application['year_completed_02'] . "</div>";
$message .= "<div class=\"field\"><span class=\"label\">How many years of relevant work experience do you have?" . ": </span>" . $application['work_experience'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If you\'re applying for a role as a support worker or nurse, what shifts can you work?" . ": </span>" . $application['shifts_anytime'] . "</div>";

// if ( $job_options_support_worker == 'Yes' ) {
$message .= addToRenderShifts( $application, 'Monday' );
$message .= addToRenderShifts( $application, 'Tuesday' );
$message .= addToRenderShifts( $application, 'Wednesday' );
$message .= addToRenderShifts( $application, 'Thursday' );
$message .= addToRenderShifts( $application, 'Friday' );
$message .= addToRenderShifts( $application, 'Saturday' );
$message .= addToRenderShifts( $application, 'Sunday' );
$message .= addToRenderShifts( $application, 'Public Holidays' );
// }

$message .= "<div class=\"field\"><span class=\"label\">Do you have previous experience working within the disability services area?" . ": </span>" . $application['experience_disability_services'] . "</div>";
if (isset($application['page_url'])) {
$message .= "<div class=\"field\"><span class=\"label\">Page sent from" . ": </span>" . $application['page_url'] . "</div>";
}
if (isset($application['page_referrer'])) {
$message .= "<div class=\"field\"><span class=\"label\">Page referred from" . ": </span>" . $application['page_referrer'] . "</div>";
}

echo $message;

}

function render_view_application(){
?>

<div class="wrap">

<h2>View Application</h2>

<?php
global $wpdb, $_wp_column_headers;

if (isset($_GET['application']) && !empty($_GET['application']) ) {

$query = "SELECT
*
FROM wp_job_applications
WHERE
id='" . $_GET['application'] . "'
";

$result = $wpdb->get_row($query);

$application = unserialize($result->application_data);

foreach ($application as $key => $value ) {
if (empty($value)) {
$application[$key] = '<em>Not submitted</em>';
}
}

unset($application['submit']);

echo "<style type=\"text/css\">
span.label {display: block; font-weight: bold;}

div.field {margin: 0 0 10px; border-bottom: 1px solid #eee; padding: 0 0 10px;}

form.buttons { float: left; }

form.buttons input,
a.button {
display: block;
float: left;
cursor: pointer;
font-family: sans-serif;
margin-left: 4px;
padding: 3px 8px;
position: relative;
top: -3px;
text-decoration: none;
font-size: 12px;
border: 0 none;
background: #f1f1f1;
color: #21759b;
margin: 10px 4px 20px;
line-height: 15px;
padding: 3px 10px;
white-space: nowrap;
-webkit-border-radius: 10px;
}

form.buttons input:hover {
color: #d54e21;
}

div.clear { clear: both; }

</style>";

echo '<form class="buttons" method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php?application=' . $_GET['application'] . '">';
echo '<input type="submit" name="Submit" value="Export To CSV" />';
echo '</form>';

echo '<form class="buttons" method="post" name="print" target="_blank" action="' . plugin_dir_url(__FILE__) . 'print.php?application=' . $_GET['application'] . '">';
echo '<input type="submit" name="Submit" value="Print" />';
echo '</form>';

if (!empty($result->cv_path)) {
echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cv_path . '" title="Download CV">Download CV</a>';
}

if (!empty($result->cl_path)) {
echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cl_path . '" title="Download Cover Letter">Download Cover Letter</a>';
}

echo '<div class="clear"></div>';

render_application_data($application);

}
?>

</div>

<?php
}


Answers (2)

2015-12-01

Firoja_Imtosupport answers:

Hi Just go to http://wordpress.stackexchange.com/questions/76374/wp-list-tables-bulk-actions link, it is exactly what you want.
Let me know if anything is not understood


Firoja_Imtosupport comments:

Also check http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/#bulk


Firoja_Imtosupport comments:

Hello,

Is this issue resolved? or with some one, else i can look in to it


midsummas comments:

Hi Firoja,

I haven't heard anyting back from Arnav so nope not yet.

Cheers,

Les


Firoja_Imtosupport comments:

Hello Les,

Please replace your code with below: Also note only singular delete near View button will work by this code, For Bulk delete i am checking. Just confirm this works fine for you and i can proceed

<?php

/*

Plugin Name: Job Application List

*/

error_reporting(0);

if( ! class_exists( 'WP_List_Table' ) ) {

require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

}



class Job_Application_List_Table extends WP_List_Table {



function __construct(){



global $status, $page;



parent::__construct( array(

'singular' => __( 'application', 'mylisttable' ), //singular name of the listed records

'plural' => __( 'applications', 'mylisttable' ), //plural name of the listed records

'ajax' => false //does this table support ajax?

));



add_action( 'admin_head', array( &$this, 'admin_header' ) );



}

function admin_header() {



$page = ( isset($_GET['page'] ) ) ? esc_attr( $_GET['page'] ) : false;



if( 'my_list_test' != $page ) {

return;

}



echo '<style type="text/css">';

echo '.wp-list-table .column-id { width: 5%; }';

echo '.wp-list-table .column-booktitle { width: 40%; }';

echo '.wp-list-table .column-author { width: 35%; }';

echo '.wp-list-table .column-isbn { width: 20%;}';

echo '</style>';



}



function no_items() {

_e( 'No applications found.' );

}



function column_default( $item, $column_name ) {

switch( $column_name ) {

case 'date_submitted':

case 'job_pos':

case 'first_names':

case 'last_name':

case 'preferred_name':

case 'email_address':

case 'mobile':

return $item->$column_name;

default:

//return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes

}

}



function get_sortable_columns() {

$sortable_columns = array(

'date_submitted' => array('date_submitted',false),

'job_pos' => array('job_pos',false),

'first_names' => array('first_names',false),

'last_name' => array('last_name',false),

'email_address' => array('email_address',false),

'mobile' => array('mobile',false)

);

return $sortable_columns;

}



function get_columns(){

$columns = array(

'cb' => '<input type="checkbox" />',

'date_submitted' => __( 'Submitted', 'mylisttable' ),

'job_pos' => __( 'Position', 'mylisttable' ),

'first_names' => __( 'First Names', 'mylisttable' ),

'last_name' => __( 'Last Name', 'mylisttable' ),

'email_address' => __( 'Email Address', 'mylisttable' ),

'mobile' => __( 'Mobile', 'mylisttable' )

);

return $columns;

}



function usort_reorder( $a, $b ) {

// If no sort, default to title

$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'date_submitted';

// If no order, default to asc

$order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';

// Determine sort order

$result = strcmp( $a[$orderby], $b[$orderby] );

// Send final sort direction to usort

return ( $order === 'asc' ) ? $result : -$result;

}



function column_date_submitted($item){

$actions = array(

'edit' => sprintf('<a href="?page=view_application&application=%s">View</a>', $item->id),

'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>',$item->id,$item->id)

);



return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );

}



function get_bulk_actions() {
$actions = array();
/*$actions = array(

'delete' => 'Delete'

);*/
$actions['delete'] = __( 'Delete' );
return $actions;

}



function column_cb($item) {

return sprintf(

'<input type="checkbox" name="application[]" value="%s" />', $item->id

);

}



function prepare_items() {



global $wpdb, $_wp_column_headers;

$screen = get_current_screen();



$where_search = "";

if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {

$search = $_REQUEST['s'];

$where_search = "WHERE job_pos LIKE '%{$search}%'

OR first_names LIKE '%{$search}%'

OR last_name LIKE '%{$search}%'

OR email_address LIKE '%{$search}%'

";

}



$query = "SELECT

id,

date_submitted,

job_pos,

first_names,

last_name,

email_address,

mobile

FROM wp_job_applications

{$where_search}

";



$orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'ASC';

$order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : '';



if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }



$totalitems = $wpdb->query($query);

$perpage = 20;

$paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';

if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }

$totalpages = ceil($totalitems/$perpage);

if(!empty($paged) && !empty($perpage)){

$offset=($paged-1)*$perpage;

$query.=' LIMIT '.(int)$offset.','.(int)$perpage;

}



$this->set_pagination_args( array(

"total_items" => $totalitems,

"total_pages" => $totalpages,

"per_page" => $perpage,

) );



$columns = $this->get_columns();

$_wp_column_headers[$screen->id]=$columns;



// echo $query;



$this->items = $wpdb->get_results($query);



}



} //class







function my_add_menu_items(){



$hook = add_menu_page( 'Job Applications', 'Job Applications', 'edit_posts', 'job_application_list', 'render_job_application_list', null, 150 );

add_action( "load-$hook", 'application_add_options' );



add_submenu_page( null, 'Edit Application', 'Edit Application', 'edit_posts', 'view_application', 'render_view_application' );



}



function application_add_options() {

global $myListTable;

$option = 'per_page';

$args = array(

'label' => 'Applications',

'default' => 10,

'option' => 'applications_per_page'

);

add_screen_option( $option, $args );

$myListTable = new Job_Application_List_Table();

}

add_action( 'admin_menu', 'my_add_menu_items' );







function render_job_application_list(){

global $myListTable;

echo '<div class="wrap"><h2>Job Applications</h2>';



echo '<form method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php">';

echo '<input type="submit" name="Submit" value="Export List To CSV" />';

echo '</form>';



$myListTable->prepare_items();

?>

<form method="post" name="frmmain">

<input type="hidden" name="page" value="ttest_list_table">

<?php

$myListTable->search_box( 'search', 'search_id' );



$myListTable->display();



echo '</form></div>';

}



function addToRenderShifts( $application, $day ) {



$message = '';



$day_id = str_replace(' ', '_', strtolower( $day ) );



if ( isset($application[$day_id]) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . ":</span> Yes</div>";

}

if ( isset($application[$day_id . '_morning_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Morning Shifts:</span> Yes</div>";

}

if ( isset($application[$day_id . '_afternoon_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Afternoon Shifts:</span> Yes</div>";

}

if ( isset($application[$day_id . '_night_shift']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift:</span> Yes</div>";

}

if ( isset($application[$day_id . '_night_shift_alt']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift Alt:</span> Yes</div>";

}

if ( isset($application[$day_id . '_tea_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Tea Shifts:</span> Yes</div>";

}



return $message;



}



function render_application_data($application) {



$message = '';



$message .= "<div class=\"field\"><span class=\"label\">Job Position" . ": </span>" . $application['job_pos'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Last Name" . ": </span>" . $application['last_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">First Names" . ": </span>" . $application['first_names'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Preferred Name" . ": </span>" . $application['preferred_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Date of Birth" . ": </span>" . $application['dob'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Your Address" . ": </span>" . $application['your_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State" . ": </span>" . $application['state'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Postcode" . ": </span>" . $application['postcode'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Daytime Phone Number" . ": </span>" . $application['daytime_phone_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Mobile" . ": </span>" . $application['mobile'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Email Address" . ": </span>" . $application['email_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you of an Aboriginal or Torres Strait Islander background?" . ": </span>" . $application['aboriginal_torres'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you speak a language/s other than English at home?" . ": </span>" . $application['other_languages'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, what language is that?" . ": </span>" . $application['languages_list'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you legally entitled to work in Australia/New Zealand?" . ": </span>" . $application['legally_entitled'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Please provide details of your Visa" . ": </span>" . $application['visa_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">When does your visa expire?" . ": </span>" . $application['visa_expire'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Drivers License Number" . ": </span>" . $application['drivers_license_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State of issue" . ": </span>" . $application['license_state_of_issue'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Class" . ": </span>" . $application['license_class'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Expiry Date" . ": </span>" . $application['license_expiry_date'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Type" . ": </span>" . $application['license_type'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you ever been disqualified from driving?" . ": </span>" . $application['disqualified_driving'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['disqualified_driving_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you own a reliable vehicle?" . ": </span>" . $application['reliable_vehicle'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a criminal record, or have a charge pending before any court?" . ": </span>" . $application['criminal_record'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['criminal_record_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you claimed workers compensation in the last five (5) years?" . ": </span>" . $application['workers_comp'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['workers_comp_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a medical condition that could interfere with your ability to<br />perform the duties of the position?" . ": </span>" . $application['medical_conditions'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['medical_conditions_details'] . "</div>";

if (isset($application['hear_about_position'])) {

$message .= "<div class=\"field\"><span class=\"label\">How did you hear about this position at Nulsen?" . ": </span>" . $application['hear_about_position'] . "</div>";

}

if (isset($application['hear_about_from_where'])) {

$message .= "<div class=\"field\"><span class=\"label\">Further information on source" . ": </span>" . $application['hear_about_from_where'] . "</div>";

}

if (isset($application['dsc_worked_12_months'])) {

$message .= "<div class=\"field\"><span class=\"label\">Are you currently working or have you ever worked with the Western Australian Disability Services Commission (DSC) in the last 12 months?" . ": </span>" . $application['dsc_worked_12_months'] . "</div>";

}

if (isset($application['dsc_capacity_employed'])) {

$message .= "<div class=\"field\"><span class=\"label\">If yes, in what capacity were you employed with DSC?" . ": </span>" . $application['dsc_capacity_employed'] . "</div>";

}

if (isset($application['dsc_date_terminated'])) {

$message .= "<div class=\"field\"><span class=\"label\">If you resigned or your employment was terminated with DSC, on what date did your employment end with them?" . ": </span>" . $application['dsc_date_terminated'] . "</div>";

}

$message .= "<div class=\"field\"><span class=\"label\">Have you applied for a position with Nulsen before?" . ": </span>" . $application['applied_before'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 01" . ": </span>" . $application['qualification_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 01" . ": </span>" . $application['institution_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 01" . ": </span>" . $application['year_completed_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 02" . ": </span>" . $application['qualification_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 02" . ": </span>" . $application['institution_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 02" . ": </span>" . $application['year_completed_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">How many years of relevant work experience do you have?" . ": </span>" . $application['work_experience'] . "</div>";



$message .= "<div class=\"field\"><span class=\"label\">If you\'re applying for a role as a support worker or nurse, what shifts can you work?" . ": </span>" . $application['shifts_anytime'] . "</div>";



// if ( $job_options_support_worker == 'Yes' ) {

$message .= addToRenderShifts( $application, 'Monday' );

$message .= addToRenderShifts( $application, 'Tuesday' );

$message .= addToRenderShifts( $application, 'Wednesday' );

$message .= addToRenderShifts( $application, 'Thursday' );

$message .= addToRenderShifts( $application, 'Friday' );

$message .= addToRenderShifts( $application, 'Saturday' );

$message .= addToRenderShifts( $application, 'Sunday' );

$message .= addToRenderShifts( $application, 'Public Holidays' );

// }



$message .= "<div class=\"field\"><span class=\"label\">Do you have previous experience working within the disability services area?" . ": </span>" . $application['experience_disability_services'] . "</div>";

if (isset($application['page_url'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page sent from" . ": </span>" . $application['page_url'] . "</div>";

}

if (isset($application['page_referrer'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page referred from" . ": </span>" . $application['page_referrer'] . "</div>";

}



echo $message;



}



function render_view_application(){

?>



<div class="wrap">



<h2>View Application</h2>



<?php

global $wpdb, $_wp_column_headers;



if (isset($_GET['application']) && !empty($_GET['application']) ) {

$query = "SELECT

*

FROM wp_job_applications

WHERE

id='" . $_GET['application'] . "'

";


$result = $wpdb->get_row($query);


//$applicationdata=$this->addItem($result->application_data,$result->date_submitted);
$a = unserialize($result->application_data);
$a['date_submitted'] = $result->date_submitted;
$applicationdata=serialize($a);
$application = unserialize($applicationdata);



foreach ($application as $key => $value ) {

if (empty($value)) {

$application[$key] = 'Not submitted';

}
else{
$table='wp_job_applications';
$where=" WHERE
id='". $_GET['application']."'";
//$wpdb->delete( $table, $where, $where_format = null );
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id = %d
"
,$_GET['application']));
//header('Location: '.$_SERVER['REQUEST_URI']);

}

}



unset($application['submit']);



echo "<style type=\"text/css\">

span.label {display: block; font-weight: bold;}



div.field {margin: 0 0 10px; border-bottom: 1px solid #eee; padding: 0 0 10px;}



form.buttons { float: left; }



form.buttons input,

a.button {

display: block;

float: left;

cursor: pointer;

font-family: sans-serif;

margin-left: 4px;

padding: 3px 8px;

position: relative;

top: -3px;

text-decoration: none;

font-size: 12px;

border: 0 none;

background: #f1f1f1;

color: #21759b;

margin: 10px 4px 20px;

line-height: 15px;

padding: 3px 10px;

white-space: nowrap;

-webkit-border-radius: 10px;

}



form.buttons input:hover {

color: #d54e21;

}



div.clear { clear: both; }



</style>";



echo '<form class="buttons" method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Export To CSV" />';

echo '</form>';



echo '<form class="buttons" method="post" name="print" target="_blank" action="' . plugin_dir_url(__FILE__) . 'print.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Print" />';

echo '</form>';



if (!empty($result->cv_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cv_path . '" title="Download CV">Download CV</a>';

}



if (!empty($result->cl_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cl_path . '" title="Download Cover Letter">Download Cover Letter</a>';

}



echo '<div class="clear"></div>';



render_application_data($application);



}

?>



</div>



<?php

}

Thanks


Firoja_Imtosupport comments:

Hi Les,

Please find below code, Just replace your plugin with this, I am very sure it will work flawlessly

<?php

/*

Plugin Name: Job Application List

*/

error_reporting(0);

if( ! class_exists( 'WP_List_Table' ) ) {

require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

}



class Job_Application_List_Table extends WP_List_Table {



function __construct(){



global $status, $page;



parent::__construct( array(

'singular' => __( 'application', 'mylisttable' ), //singular name of the listed records

'plural' => __( 'applications', 'mylisttable' ), //plural name of the listed records

'ajax' => false //does this table support ajax?

));



add_action( 'admin_head', array( &$this, 'admin_header' ) );



}

function admin_header() {



$page = ( isset($_GET['page'] ) ) ? esc_attr( $_GET['page'] ) : false;



if( 'my_list_test' != $page ) {

return;

}



echo '<style type="text/css">';

echo '.wp-list-table .column-id { width: 5%; }';

echo '.wp-list-table .column-booktitle { width: 40%; }';

echo '.wp-list-table .column-author { width: 35%; }';

echo '.wp-list-table .column-isbn { width: 20%;}';

echo '</style>';



}



function no_items() {

_e( 'No applications found.' );

}



function column_default( $item, $column_name ) {

switch( $column_name ) {

case 'date_submitted':

case 'job_pos':

case 'first_names':

case 'last_name':

case 'preferred_name':

case 'email_address':

case 'mobile':

return $item->$column_name;

default:

//return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes

}

}



function get_sortable_columns() {

$sortable_columns = array(

'date_submitted' => array('date_submitted',false),

'job_pos' => array('job_pos',false),

'first_names' => array('first_names',false),

'last_name' => array('last_name',false),

'email_address' => array('email_address',false),

'mobile' => array('mobile',false)

);

return $sortable_columns;

}



function get_columns(){

$columns = array(

'cb' => '<input type="checkbox" />',

'date_submitted' => __( 'Submitted', 'mylisttable' ),

'job_pos' => __( 'Position', 'mylisttable' ),

'first_names' => __( 'First Names', 'mylisttable' ),

'last_name' => __( 'Last Name', 'mylisttable' ),

'email_address' => __( 'Email Address', 'mylisttable' ),

'mobile' => __( 'Mobile', 'mylisttable' )

);

return $columns;

}



function usort_reorder( $a, $b ) {

// If no sort, default to title

$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'date_submitted';

// If no order, default to asc

$order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';

// Determine sort order

$result = strcmp( $a[$orderby], $b[$orderby] );

// Send final sort direction to usort

return ( $order === 'asc' ) ? $result : -$result;

}



function column_date_submitted($item){

$actions = array(

'edit' => sprintf('<a href="?page=view_application&application=%s">View</a>', $item->id),

'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>',$item->id,$item->id)

);



return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );

}



function get_bulk_actions() {
//$actions = array();
$actions = array(

'bulk-delete' => 'Delete'

);

//$actions['bulk-delete'] = __( 'Delete' );
return $actions;

}



function column_cb($item) {

return sprintf(

'<input type="checkbox" name="application[]" value="%s" />', $item->id

);

}



function prepare_items() {



global $wpdb, $_wp_column_headers;

$screen = get_current_screen();

$this->process_bulk_action();

$where_search = "";

if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {

$search = $_REQUEST['s'];

$where_search = "WHERE job_pos LIKE '%{$search}%'

OR first_names LIKE '%{$search}%'

OR last_name LIKE '%{$search}%'

OR email_address LIKE '%{$search}%'

";

}



$query = "SELECT

id,

date_submitted,

job_pos,

first_names,

last_name,

email_address,

mobile

FROM wp_job_applications

{$where_search}

";



$orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'ASC';

$order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : '';



if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }



$totalitems = $wpdb->query($query);

$perpage = 20;

$paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';

if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }

$totalpages = ceil($totalitems/$perpage);

if(!empty($paged) && !empty($perpage)){

$offset=($paged-1)*$perpage;

$query.=' LIMIT '.(int)$offset.','.(int)$perpage;

}



$this->set_pagination_args( array(

"total_items" => $totalitems,

"total_pages" => $totalpages,

"per_page" => $perpage,

) );



$columns = $this->get_columns();

$_wp_column_headers[$screen->id]=$columns;



// echo $query;



$this->items = $wpdb->get_results($query);



}

public function process_bulk_action() {

// If the delete bulk action is triggered
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
) {
$delete_ids = esc_sql( $_POST['application'] );
// loop over the array of record IDs and delete them
foreach ( $delete_ids as $did ) {
global $wpdb;
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id='".$did."'"));
}

wp_redirect( esc_url( add_query_arg() ) );
exit;
}

}

} //class

function my_add_menu_items(){



$hook = add_menu_page( 'Job Applications', 'Job Applications', 'edit_posts', 'job_application_list', 'render_job_application_list', null, 150 );

add_action( "load-$hook", 'application_add_options' );



add_submenu_page( null, 'Edit Application', 'Edit Application', 'edit_posts', 'view_application', 'render_view_application' );



}



function application_add_options() {

global $myListTable;

$option = 'per_page';

$args = array(

'label' => 'Applications',

'default' => 10,

'option' => 'applications_per_page'

);

add_screen_option( $option, $args );

$myListTable = new Job_Application_List_Table();

}

add_action( 'admin_menu', 'my_add_menu_items' );







function render_job_application_list(){

global $myListTable;

echo '<div class="wrap"><h2>Job Applications</h2>';



echo '<form method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php">';

echo '<input type="submit" name="Submit" value="Export List To CSV" />';

echo '</form>';



$myListTable->prepare_items();

?>

<form method="post" name="frmmain">

<input type="hidden" name="page" value="ttest_list_table">

<?php

$myListTable->search_box( 'search', 'search_id' );



$myListTable->display();



echo '</form></div>';

}



function addToRenderShifts( $application, $day ) {



$message = '';



$day_id = str_replace(' ', '_', strtolower( $day ) );



if ( isset($application[$day_id]) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . ":</span> Yes</div>";

}

if ( isset($application[$day_id . '_morning_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Morning Shifts:</span> Yes</div>";

}

if ( isset($application[$day_id . '_afternoon_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Afternoon Shifts:</span> Yes</div>";

}

if ( isset($application[$day_id . '_night_shift']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift:</span> Yes</div>";

}

if ( isset($application[$day_id . '_night_shift_alt']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift Alt:</span> Yes</div>";

}

if ( isset($application[$day_id . '_tea_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Tea Shifts:</span> Yes</div>";

}



return $message;



}



function render_application_data($application) {



$message = '';



$message .= "<div class=\"field\"><span class=\"label\">Job Position" . ": </span>" . $application['job_pos'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Last Name" . ": </span>" . $application['last_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">First Names" . ": </span>" . $application['first_names'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Preferred Name" . ": </span>" . $application['preferred_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Date of Birth" . ": </span>" . $application['dob'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Your Address" . ": </span>" . $application['your_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State" . ": </span>" . $application['state'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Postcode" . ": </span>" . $application['postcode'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Daytime Phone Number" . ": </span>" . $application['daytime_phone_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Mobile" . ": </span>" . $application['mobile'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Email Address" . ": </span>" . $application['email_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you of an Aboriginal or Torres Strait Islander background?" . ": </span>" . $application['aboriginal_torres'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you speak a language/s other than English at home?" . ": </span>" . $application['other_languages'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, what language is that?" . ": </span>" . $application['languages_list'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you legally entitled to work in Australia/New Zealand?" . ": </span>" . $application['legally_entitled'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Please provide details of your Visa" . ": </span>" . $application['visa_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">When does your visa expire?" . ": </span>" . $application['visa_expire'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Drivers License Number" . ": </span>" . $application['drivers_license_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State of issue" . ": </span>" . $application['license_state_of_issue'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Class" . ": </span>" . $application['license_class'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Expiry Date" . ": </span>" . $application['license_expiry_date'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Type" . ": </span>" . $application['license_type'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you ever been disqualified from driving?" . ": </span>" . $application['disqualified_driving'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['disqualified_driving_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you own a reliable vehicle?" . ": </span>" . $application['reliable_vehicle'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a criminal record, or have a charge pending before any court?" . ": </span>" . $application['criminal_record'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['criminal_record_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you claimed workers compensation in the last five (5) years?" . ": </span>" . $application['workers_comp'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['workers_comp_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a medical condition that could interfere with your ability to<br />perform the duties of the position?" . ": </span>" . $application['medical_conditions'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['medical_conditions_details'] . "</div>";

if (isset($application['hear_about_position'])) {

$message .= "<div class=\"field\"><span class=\"label\">How did you hear about this position at Nulsen?" . ": </span>" . $application['hear_about_position'] . "</div>";

}

if (isset($application['hear_about_from_where'])) {

$message .= "<div class=\"field\"><span class=\"label\">Further information on source" . ": </span>" . $application['hear_about_from_where'] . "</div>";

}

if (isset($application['dsc_worked_12_months'])) {

$message .= "<div class=\"field\"><span class=\"label\">Are you currently working or have you ever worked with the Western Australian Disability Services Commission (DSC) in the last 12 months?" . ": </span>" . $application['dsc_worked_12_months'] . "</div>";

}

if (isset($application['dsc_capacity_employed'])) {

$message .= "<div class=\"field\"><span class=\"label\">If yes, in what capacity were you employed with DSC?" . ": </span>" . $application['dsc_capacity_employed'] . "</div>";

}

if (isset($application['dsc_date_terminated'])) {

$message .= "<div class=\"field\"><span class=\"label\">If you resigned or your employment was terminated with DSC, on what date did your employment end with them?" . ": </span>" . $application['dsc_date_terminated'] . "</div>";

}

$message .= "<div class=\"field\"><span class=\"label\">Have you applied for a position with Nulsen before?" . ": </span>" . $application['applied_before'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 01" . ": </span>" . $application['qualification_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 01" . ": </span>" . $application['institution_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 01" . ": </span>" . $application['year_completed_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 02" . ": </span>" . $application['qualification_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 02" . ": </span>" . $application['institution_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 02" . ": </span>" . $application['year_completed_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">How many years of relevant work experience do you have?" . ": </span>" . $application['work_experience'] . "</div>";



$message .= "<div class=\"field\"><span class=\"label\">If you\'re applying for a role as a support worker or nurse, what shifts can you work?" . ": </span>" . $application['shifts_anytime'] . "</div>";



// if ( $job_options_support_worker == 'Yes' ) {

$message .= addToRenderShifts( $application, 'Monday' );

$message .= addToRenderShifts( $application, 'Tuesday' );

$message .= addToRenderShifts( $application, 'Wednesday' );

$message .= addToRenderShifts( $application, 'Thursday' );

$message .= addToRenderShifts( $application, 'Friday' );

$message .= addToRenderShifts( $application, 'Saturday' );

$message .= addToRenderShifts( $application, 'Sunday' );

$message .= addToRenderShifts( $application, 'Public Holidays' );

// }



$message .= "<div class=\"field\"><span class=\"label\">Do you have previous experience working within the disability services area?" . ": </span>" . $application['experience_disability_services'] . "</div>";

if (isset($application['page_url'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page sent from" . ": </span>" . $application['page_url'] . "</div>";

}

if (isset($application['page_referrer'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page referred from" . ": </span>" . $application['page_referrer'] . "</div>";

}



echo $message;



}



function render_view_application(){

?>



<div class="wrap">



<h2>View Application</h2>



<?php

global $wpdb, $_wp_column_headers;

if (isset($_GET['application']) && !empty($_GET['application']) ) {

$query = "SELECT

*

FROM wp_job_applications

WHERE

id='" . $_GET['application'] . "'

";


$result = $wpdb->get_row($query);


//$applicationdata=$this->addItem($result->application_data,$result->date_submitted);
$a = unserialize($result->application_data);
$a['date_submitted'] = $result->date_submitted;
$applicationdata=serialize($a);
$application = unserialize($applicationdata);



foreach ($application as $key => $value ) {

if (empty($value)) {

$application[$key] = 'Not submitted';

}
else{
$table='wp_job_applications';
$where=" WHERE
id='". $_GET['application']."'";
//$wpdb->delete( $table, $where, $where_format = null );
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id = %d
"
,$_GET['application']));
//header('Location: '.$_SERVER['REQUEST_URI']);

}

}



unset($application['submit']);



echo "<style type=\"text/css\">

span.label {display: block; font-weight: bold;}



div.field {margin: 0 0 10px; border-bottom: 1px solid #eee; padding: 0 0 10px;}



form.buttons { float: left; }



form.buttons input,

a.button {

display: block;

float: left;

cursor: pointer;

font-family: sans-serif;

margin-left: 4px;

padding: 3px 8px;

position: relative;

top: -3px;

text-decoration: none;

font-size: 12px;

border: 0 none;

background: #f1f1f1;

color: #21759b;

margin: 10px 4px 20px;

line-height: 15px;

padding: 3px 10px;

white-space: nowrap;

-webkit-border-radius: 10px;

}



form.buttons input:hover {

color: #d54e21;

}



div.clear { clear: both; }



</style>";



echo '<form class="buttons" method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Export To CSV" />';

echo '</form>';



echo '<form class="buttons" method="post" name="print" target="_blank" action="' . plugin_dir_url(__FILE__) . 'print.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Print" />';

echo '</form>';



if (!empty($result->cv_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cv_path . '" title="Download CV">Download CV</a>';

}



if (!empty($result->cl_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cl_path . '" title="Download Cover Letter">Download Cover Letter</a>';

}



echo '<div class="clear"></div>';



render_application_data($application);



}

?>



</div>



<?php

}

Thanks,
FK


midsummas comments:

Hi FK,

I think we're almost there, the bulk delete works but the individual delete on hover send the page to the View page. Basically individually delete seems to still call the actual listing whereas bulk delete works fine.

Cheers,

Les


Firoja_Imtosupport comments:

Hi Les,

Please can you tell me how are you deleting individual record? I mean using Delete button besides View button?


Firoja_Imtosupport comments:

Hi Les,

i have checked once again, code given works fine for single delete also, Please verify once again. If you still see single delete is not working let me know

Thanks
FK


Firoja_Imtosupport comments:

Hi Les,

Any update?


midsummas comments:

Hi Firoja,

Not good... Both the View and Delete buttons are removing items from my WPList Table.

I have removed your code for now. There is something with the edit/delete functions that is not right.

Les


midsummas comments:

Hi Firoja,

Should I ask someone else?

Cheers,

Les


Firoja_Imtosupport comments:

Hi Les,

Just if single delete is working , i will check for view and give updated code, in some time


Firoja_Imtosupport comments:

Hi,

Please replace your code with below:

<?php

/*

Plugin Name: Job Application List

*/

error_reporting(0);

if( ! class_exists( 'WP_List_Table' ) ) {

require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

}



class Job_Application_List_Table extends WP_List_Table {



function __construct(){



global $status, $page;



parent::__construct( array(

'singular' => __( 'application', 'mylisttable' ), //singular name of the listed records

'plural' => __( 'applications', 'mylisttable' ), //plural name of the listed records

'ajax' => false //does this table support ajax?

));



add_action( 'admin_head', array( &$this, 'admin_header' ) );



}

function admin_header() {



$page = ( isset($_GET['page'] ) ) ? esc_attr( $_GET['page'] ) : false;



if( 'my_list_test' != $page ) {

return;

}



echo '<style type="text/css">';

echo '.wp-list-table .column-id { width: 5%; }';

echo '.wp-list-table .column-booktitle { width: 40%; }';

echo '.wp-list-table .column-author { width: 35%; }';

echo '.wp-list-table .column-isbn { width: 20%;}';

echo '</style>';



}



function no_items() {

_e( 'No applications found.' );

}



function column_default( $item, $column_name ) {

switch( $column_name ) {

case 'date_submitted':

case 'job_pos':

case 'first_names':

case 'last_name':

case 'preferred_name':

case 'email_address':

case 'mobile':

return $item->$column_name;

default:

//return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes

}

}



function get_sortable_columns() {

$sortable_columns = array(

'date_submitted' => array('date_submitted',false),

'job_pos' => array('job_pos',false),

'first_names' => array('first_names',false),

'last_name' => array('last_name',false),

'email_address' => array('email_address',false),

'mobile' => array('mobile',false)

);

return $sortable_columns;

}



function get_columns(){

$columns = array(

'cb' => '<input type="checkbox" />',

'date_submitted' => __( 'Submitted', 'mylisttable' ),

'job_pos' => __( 'Position', 'mylisttable' ),

'first_names' => __( 'First Names', 'mylisttable' ),

'last_name' => __( 'Last Name', 'mylisttable' ),

'email_address' => __( 'Email Address', 'mylisttable' ),

'mobile' => __( 'Mobile', 'mylisttable' )

);

return $columns;

}



function usort_reorder( $a, $b ) {

// If no sort, default to title

$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'date_submitted';

// If no order, default to asc

$order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';

// Determine sort order

$result = strcmp( $a[$orderby], $b[$orderby] );

// Send final sort direction to usort

return ( $order === 'asc' ) ? $result : -$result;

}



function column_date_submitted($item){

$actions = array(

'edit' => sprintf('<a href="?page=view_application&onlyv=view&application=%s">View</a>', $item->id),

'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>',$item->id,$item->id)

);



return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );

}



function get_bulk_actions() {
//$actions = array();
$actions = array(

'bulk-delete' => 'Delete'

);

//$actions['bulk-delete'] = __( 'Delete' );
return $actions;

}



function column_cb($item) {

return sprintf(

'<input type="checkbox" name="application[]" value="%s" />', $item->id

);

}



function prepare_items() {



global $wpdb, $_wp_column_headers;

$screen = get_current_screen();

$this->process_bulk_action();

$where_search = "";

if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {

$search = $_REQUEST['s'];

$where_search = "WHERE job_pos LIKE '%{$search}%'

OR first_names LIKE '%{$search}%'

OR last_name LIKE '%{$search}%'

OR email_address LIKE '%{$search}%'

";

}



$query = "SELECT

id,

date_submitted,

job_pos,

first_names,

last_name,

email_address,

mobile

FROM wp_job_applications

{$where_search}

";



$orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'ASC';

$order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : '';



if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }



$totalitems = $wpdb->query($query);

$perpage = 20;

$paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';

if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }

$totalpages = ceil($totalitems/$perpage);

if(!empty($paged) && !empty($perpage)){

$offset=($paged-1)*$perpage;

$query.=' LIMIT '.(int)$offset.','.(int)$perpage;

}



$this->set_pagination_args( array(

"total_items" => $totalitems,

"total_pages" => $totalpages,

"per_page" => $perpage,

) );



$columns = $this->get_columns();

$_wp_column_headers[$screen->id]=$columns;



// echo $query;



$this->items = $wpdb->get_results($query);



}

public function process_bulk_action() {

// If the delete bulk action is triggered
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
) {
$delete_ids = esc_sql( $_POST['application'] );
// loop over the array of record IDs and delete them
foreach ( $delete_ids as $did ) {
global $wpdb;
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id='".$did."'"));
}

wp_redirect( esc_url( add_query_arg() ) );
exit;
}

}

} //class

function my_add_menu_items(){



$hook = add_menu_page( 'Job Applications', 'Job Applications', 'edit_posts', 'job_application_list', 'render_job_application_list', null, 150 );

add_action( "load-$hook", 'application_add_options' );



add_submenu_page( null, 'Edit Application', 'Edit Application', 'edit_posts', 'view_application', 'render_view_application' );



}



function application_add_options() {

global $myListTable;

$option = 'per_page';

$args = array(

'label' => 'Applications',

'default' => 10,

'option' => 'applications_per_page'

);

add_screen_option( $option, $args );

$myListTable = new Job_Application_List_Table();

}

add_action( 'admin_menu', 'my_add_menu_items' );







function render_job_application_list(){

global $myListTable;

echo '<div class="wrap"><h2>Job Applications</h2>';



echo '<form method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php">';

echo '<input type="submit" name="Submit" value="Export List To CSV" />';

echo '</form>';



$myListTable->prepare_items();

?>

<form method="post" name="frmmain">

<input type="hidden" name="page" value="ttest_list_table">

<?php

$myListTable->search_box( 'search', 'search_id' );



$myListTable->display();



echo '</form></div>';

}



function addToRenderShifts( $application, $day ) {



$message = '';



$day_id = str_replace(' ', '_', strtolower( $day ) );



if ( isset($application[$day_id]) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . ":</span> Yes</div>";

}

if ( isset($application[$day_id . '_morning_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Morning Shifts:</span> Yes</div>";

}

if ( isset($application[$day_id . '_afternoon_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Afternoon Shifts:</span> Yes</div>";

}

if ( isset($application[$day_id . '_night_shift']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift:</span> Yes</div>";

}

if ( isset($application[$day_id . '_night_shift_alt']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift Alt:</span> Yes</div>";

}

if ( isset($application[$day_id . '_tea_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Tea Shifts:</span> Yes</div>";

}



return $message;



}



function render_application_data($application) {



$message = '';



$message .= "<div class=\"field\"><span class=\"label\">Job Position" . ": </span>" . $application['job_pos'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Last Name" . ": </span>" . $application['last_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">First Names" . ": </span>" . $application['first_names'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Preferred Name" . ": </span>" . $application['preferred_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Date of Birth" . ": </span>" . $application['dob'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Your Address" . ": </span>" . $application['your_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State" . ": </span>" . $application['state'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Postcode" . ": </span>" . $application['postcode'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Daytime Phone Number" . ": </span>" . $application['daytime_phone_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Mobile" . ": </span>" . $application['mobile'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Email Address" . ": </span>" . $application['email_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you of an Aboriginal or Torres Strait Islander background?" . ": </span>" . $application['aboriginal_torres'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you speak a language/s other than English at home?" . ": </span>" . $application['other_languages'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, what language is that?" . ": </span>" . $application['languages_list'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you legally entitled to work in Australia/New Zealand?" . ": </span>" . $application['legally_entitled'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Please provide details of your Visa" . ": </span>" . $application['visa_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">When does your visa expire?" . ": </span>" . $application['visa_expire'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Drivers License Number" . ": </span>" . $application['drivers_license_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State of issue" . ": </span>" . $application['license_state_of_issue'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Class" . ": </span>" . $application['license_class'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Expiry Date" . ": </span>" . $application['license_expiry_date'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Type" . ": </span>" . $application['license_type'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you ever been disqualified from driving?" . ": </span>" . $application['disqualified_driving'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['disqualified_driving_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you own a reliable vehicle?" . ": </span>" . $application['reliable_vehicle'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a criminal record, or have a charge pending before any court?" . ": </span>" . $application['criminal_record'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['criminal_record_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you claimed workers compensation in the last five (5) years?" . ": </span>" . $application['workers_comp'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['workers_comp_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a medical condition that could interfere with your ability to<br />perform the duties of the position?" . ": </span>" . $application['medical_conditions'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['medical_conditions_details'] . "</div>";

if (isset($application['hear_about_position'])) {

$message .= "<div class=\"field\"><span class=\"label\">How did you hear about this position at Nulsen?" . ": </span>" . $application['hear_about_position'] . "</div>";

}

if (isset($application['hear_about_from_where'])) {

$message .= "<div class=\"field\"><span class=\"label\">Further information on source" . ": </span>" . $application['hear_about_from_where'] . "</div>";

}

if (isset($application['dsc_worked_12_months'])) {

$message .= "<div class=\"field\"><span class=\"label\">Are you currently working or have you ever worked with the Western Australian Disability Services Commission (DSC) in the last 12 months?" . ": </span>" . $application['dsc_worked_12_months'] . "</div>";

}

if (isset($application['dsc_capacity_employed'])) {

$message .= "<div class=\"field\"><span class=\"label\">If yes, in what capacity were you employed with DSC?" . ": </span>" . $application['dsc_capacity_employed'] . "</div>";

}

if (isset($application['dsc_date_terminated'])) {

$message .= "<div class=\"field\"><span class=\"label\">If you resigned or your employment was terminated with DSC, on what date did your employment end with them?" . ": </span>" . $application['dsc_date_terminated'] . "</div>";

}

$message .= "<div class=\"field\"><span class=\"label\">Have you applied for a position with Nulsen before?" . ": </span>" . $application['applied_before'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 01" . ": </span>" . $application['qualification_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 01" . ": </span>" . $application['institution_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 01" . ": </span>" . $application['year_completed_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 02" . ": </span>" . $application['qualification_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 02" . ": </span>" . $application['institution_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 02" . ": </span>" . $application['year_completed_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">How many years of relevant work experience do you have?" . ": </span>" . $application['work_experience'] . "</div>";



$message .= "<div class=\"field\"><span class=\"label\">If you\'re applying for a role as a support worker or nurse, what shifts can you work?" . ": </span>" . $application['shifts_anytime'] . "</div>";



// if ( $job_options_support_worker == 'Yes' ) {

$message .= addToRenderShifts( $application, 'Monday' );

$message .= addToRenderShifts( $application, 'Tuesday' );

$message .= addToRenderShifts( $application, 'Wednesday' );

$message .= addToRenderShifts( $application, 'Thursday' );

$message .= addToRenderShifts( $application, 'Friday' );

$message .= addToRenderShifts( $application, 'Saturday' );

$message .= addToRenderShifts( $application, 'Sunday' );

$message .= addToRenderShifts( $application, 'Public Holidays' );

// }



$message .= "<div class=\"field\"><span class=\"label\">Do you have previous experience working within the disability services area?" . ": </span>" . $application['experience_disability_services'] . "</div>";

if (isset($application['page_url'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page sent from" . ": </span>" . $application['page_url'] . "</div>";

}

if (isset($application['page_referrer'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page referred from" . ": </span>" . $application['page_referrer'] . "</div>";

}



echo $message;



}



function render_view_application(){

?>



<div class="wrap">



<h2>View Application</h2>



<?php

global $wpdb, $_wp_column_headers;

if (isset($_GET['application']) && !empty($_GET['application']) ) {

$query = "SELECT

*

FROM wp_job_applications

WHERE

id='" . $_GET['application'] . "'

";


$result = $wpdb->get_row($query);


//$applicationdata=$this->addItem($result->application_data,$result->date_submitted);

$a = unserialize($result->application_data);
$a['date_submitted'] = $result->date_submitted;
$applicationdata=serialize($a);
$application = unserialize($applicationdata);



foreach ($application as $key => $value ) {

if (empty($value)) {

$application[$key] = 'Not submitted';

}
else{
if($_GET['onlyv']!="view"){
$table='wp_job_applications';
$where=" WHERE
id='". $_GET['application']."'";
//$wpdb->delete( $table, $where, $where_format = null );
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id = %d
"
,$_GET['application']));
//header('Location: '.$_SERVER['REQUEST_URI']);

}
}

}



unset($application['submit']);



echo "<style type=\"text/css\">

span.label {display: block; font-weight: bold;}



div.field {margin: 0 0 10px; border-bottom: 1px solid #eee; padding: 0 0 10px;}



form.buttons { float: left; }



form.buttons input,

a.button {

display: block;

float: left;

cursor: pointer;

font-family: sans-serif;

margin-left: 4px;

padding: 3px 8px;

position: relative;

top: -3px;

text-decoration: none;

font-size: 12px;

border: 0 none;

background: #f1f1f1;

color: #21759b;

margin: 10px 4px 20px;

line-height: 15px;

padding: 3px 10px;

white-space: nowrap;

-webkit-border-radius: 10px;

}



form.buttons input:hover {

color: #d54e21;

}



div.clear { clear: both; }



</style>";



echo '<form class="buttons" method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Export To CSV" />';

echo '</form>';



echo '<form class="buttons" method="post" name="print" target="_blank" action="' . plugin_dir_url(__FILE__) . 'print.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Print" />';

echo '</form>';



if (!empty($result->cv_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cv_path . '" title="Download CV">Download CV</a>';

}



if (!empty($result->cl_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cl_path . '" title="Download Cover Letter">Download Cover Letter</a>';

}



echo '<div class="clear"></div>';



render_application_data($application);



}

?>



</div>



<?php

}


Firoja_Imtosupport comments:

Hi Les,

Please find code, i have cleaned it, removing comments

<?php

/*

Plugin Name: Job Application List

*/
error_reporting(0);

if( ! class_exists( 'WP_List_Table' ) ) {

require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

}
class Job_Application_List_Table extends WP_List_Table {
function __construct(){
global $status, $page;
parent::__construct( array(

'singular' => __( 'application', 'mylisttable' ), //singular name of the listed records

'plural' => __( 'applications', 'mylisttable' ), //plural name of the listed records

'ajax' => false //does this table support ajax?

));
add_action( 'admin_head', array( &$this, 'admin_header' ) );
}

function admin_header() {
$page = ( isset($_GET['page'] ) ) ? esc_attr( $_GET['page'] ) : false;

if( 'my_list_test' != $page ) {

return;

}

echo '<style type="text/css">';

echo '.wp-list-table .column-id { width: 5%; }';

echo '.wp-list-table .column-booktitle { width: 40%; }';

echo '.wp-list-table .column-author { width: 35%; }';

echo '.wp-list-table .column-isbn { width: 20%;}';

echo '</style>';
}
function no_items() {

_e( 'No applications found.' );

}

function column_default( $item, $column_name ) {

switch( $column_name ) {

case 'date_submitted':

case 'job_pos':

case 'first_names':

case 'last_name':

case 'preferred_name':

case 'email_address':

case 'mobile':

return $item->$column_name;

default:

}

}
function get_sortable_columns() {

$sortable_columns = array(

'date_submitted' => array('date_submitted',false),

'job_pos' => array('job_pos',false),

'first_names' => array('first_names',false),

'last_name' => array('last_name',false),

'email_address' => array('email_address',false),

'mobile' => array('mobile',false)

);

return $sortable_columns;

}
function get_columns(){

$columns = array(

'cb' => '<input type="checkbox" />',

'date_submitted' => __( 'Submitted', 'mylisttable' ),

'job_pos' => __( 'Position', 'mylisttable' ),

'first_names' => __( 'First Names', 'mylisttable' ),

'last_name' => __( 'Last Name', 'mylisttable' ),

'email_address' => __( 'Email Address', 'mylisttable' ),

'mobile' => __( 'Mobile', 'mylisttable' )

);

return $columns;

}
function usort_reorder( $a, $b ) {

// If no sort, default to title

$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'date_submitted';

// If no order, default to asc

$order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';

// Determine sort order

$result = strcmp( $a[$orderby], $b[$orderby] );

// Send final sort direction to usort

return ( $order === 'asc' ) ? $result : -$result;

}
function column_date_submitted($item){

$actions = array(

'edit' => sprintf('<a href="?page=view_application&onlyv=view&application=%s">View</a>', $item->id),

'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>',$item->id,$item->id)

);

return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );

}

function get_bulk_actions() {
$actions = array(

'bulk-delete' => 'Delete'

);
return $actions;

}

function column_cb($item) {

return sprintf(

'<input type="checkbox" name="application[]" value="%s" />', $item->id

);

}
function prepare_items() {

global $wpdb, $_wp_column_headers;

$screen = get_current_screen();

$this->process_bulk_action();

$where_search = "";

if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {

$search = $_REQUEST['s'];

$where_search = "WHERE job_pos LIKE '%{$search}%'

OR first_names LIKE '%{$search}%'

OR last_name LIKE '%{$search}%'

OR email_address LIKE '%{$search}%'

";

}

$query = "SELECT

id,

date_submitted,

job_pos,

first_names,

last_name,

email_address,

mobile

FROM wp_job_applications

{$where_search}

";

$orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'ASC';

$order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : '';

if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }

$totalitems = $wpdb->query($query);

$perpage = 20;

$paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';

if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }

$totalpages = ceil($totalitems/$perpage);

if(!empty($paged) && !empty($perpage)){

$offset=($paged-1)*$perpage;

$query.=' LIMIT '.(int)$offset.','.(int)$perpage;

}

$this->set_pagination_args( array(

"total_items" => $totalitems,

"total_pages" => $totalpages,

"per_page" => $perpage,

) );

$columns = $this->get_columns();

$_wp_column_headers[$screen->id]=$columns;

$this->items = $wpdb->get_results($query);


}

public function process_bulk_action() {
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
) {
$delete_ids = esc_sql( $_POST['application'] );
// loop over the array of record IDs and delete them
foreach ( $delete_ids as $did ) {
global $wpdb;
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id='".$did."'"));
}

wp_redirect( esc_url( add_query_arg() ) );
exit;
}

}

} //class

function my_add_menu_items(){

$hook = add_menu_page( 'Job Applications', 'Job Applications', 'edit_posts', 'job_application_list', 'render_job_application_list', null, 150 );

add_action( "load-$hook", 'application_add_options' );

add_submenu_page( null, 'Edit Application', 'Edit Application', 'edit_posts', 'view_application', 'render_view_application' );

}
function application_add_options() {

global $myListTable;

$option = 'per_page';

$args = array(

'label' => 'Applications',

'default' => 10,

'option' => 'applications_per_page'

);

add_screen_option( $option, $args );

$myListTable = new Job_Application_List_Table();

}

add_action( 'admin_menu', 'my_add_menu_items' );

function render_job_application_list(){

global $myListTable;

echo '<div class="wrap"><h2>Job Applications</h2>';

echo '<form method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php">';

echo '<input type="submit" name="Submit" value="Export List To CSV" />';

echo '</form>';

$myListTable->prepare_items();

?>

<form method="post" name="frmmain">
<input type="hidden" name="page" value="ttest_list_table">
<?php
$myListTable->search_box( 'search', 'search_id' );
$myListTable->display();

echo '</form></div>';

}
function addToRenderShifts( $application, $day ) {
$message = '';
$day_id = str_replace(' ', '_', strtolower( $day ) );

if ( isset($application[$day_id]) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . ":</span> Yes</div>";

}
if ( isset($application[$day_id . '_morning_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Morning Shifts:</span> Yes</div>";

}
if ( isset($application[$day_id . '_afternoon_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Afternoon Shifts:</span> Yes</div>";

}
if ( isset($application[$day_id . '_night_shift']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift:</span> Yes</div>";

}
if ( isset($application[$day_id . '_night_shift_alt']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift Alt:</span> Yes</div>";

}
if ( isset($application[$day_id . '_tea_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Tea Shifts:</span> Yes</div>";

}

return $message;
}

function render_application_data($application) {

$message = '';

$message .= "<div class=\"field\"><span class=\"label\">Job Position" . ": </span>" . $application['job_pos'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Last Name" . ": </span>" . $application['last_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">First Names" . ": </span>" . $application['first_names'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Preferred Name" . ": </span>" . $application['preferred_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Date of Birth" . ": </span>" . $application['dob'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Your Address" . ": </span>" . $application['your_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State" . ": </span>" . $application['state'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Postcode" . ": </span>" . $application['postcode'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Daytime Phone Number" . ": </span>" . $application['daytime_phone_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Mobile" . ": </span>" . $application['mobile'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Email Address" . ": </span>" . $application['email_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you of an Aboriginal or Torres Strait Islander background?" . ": </span>" . $application['aboriginal_torres'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you speak a language/s other than English at home?" . ": </span>" . $application['other_languages'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, what language is that?" . ": </span>" . $application['languages_list'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you legally entitled to work in Australia/New Zealand?" . ": </span>" . $application['legally_entitled'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Please provide details of your Visa" . ": </span>" . $application['visa_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">When does your visa expire?" . ": </span>" . $application['visa_expire'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Drivers License Number" . ": </span>" . $application['drivers_license_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State of issue" . ": </span>" . $application['license_state_of_issue'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Class" . ": </span>" . $application['license_class'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Expiry Date" . ": </span>" . $application['license_expiry_date'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Type" . ": </span>" . $application['license_type'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you ever been disqualified from driving?" . ": </span>" . $application['disqualified_driving'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['disqualified_driving_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you own a reliable vehicle?" . ": </span>" . $application['reliable_vehicle'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a criminal record, or have a charge pending before any court?" . ": </span>" . $application['criminal_record'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['criminal_record_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you claimed workers compensation in the last five (5) years?" . ": </span>" . $application['workers_comp'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['workers_comp_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a medical condition that could interfere with your ability to<br />perform the duties of the position?" . ": </span>" . $application['medical_conditions'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['medical_conditions_details'] . "</div>";

if (isset($application['hear_about_position'])) {

$message .= "<div class=\"field\"><span class=\"label\">How did you hear about this position at Nulsen?" . ": </span>" . $application['hear_about_position'] . "</div>";

}

if (isset($application['hear_about_from_where'])) {

$message .= "<div class=\"field\"><span class=\"label\">Further information on source" . ": </span>" . $application['hear_about_from_where'] . "</div>";

}

if (isset($application['dsc_worked_12_months'])) {

$message .= "<div class=\"field\"><span class=\"label\">Are you currently working or have you ever worked with the Western Australian Disability Services Commission (DSC) in the last 12 months?" . ": </span>" . $application['dsc_worked_12_months'] . "</div>";

}

if (isset($application['dsc_capacity_employed'])) {

$message .= "<div class=\"field\"><span class=\"label\">If yes, in what capacity were you employed with DSC?" . ": </span>" . $application['dsc_capacity_employed'] . "</div>";

}

if (isset($application['dsc_date_terminated'])) {

$message .= "<div class=\"field\"><span class=\"label\">If you resigned or your employment was terminated with DSC, on what date did your employment end with them?" . ": </span>" . $application['dsc_date_terminated'] . "</div>";

}

$message .= "<div class=\"field\"><span class=\"label\">Have you applied for a position with Nulsen before?" . ": </span>" . $application['applied_before'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 01" . ": </span>" . $application['qualification_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 01" . ": </span>" . $application['institution_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 01" . ": </span>" . $application['year_completed_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 02" . ": </span>" . $application['qualification_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 02" . ": </span>" . $application['institution_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 02" . ": </span>" . $application['year_completed_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">How many years of relevant work experience do you have?" . ": </span>" . $application['work_experience'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If you\'re applying for a role as a support worker or nurse, what shifts can you work?" . ": </span>" . $application['shifts_anytime'] . "</div>";



// if ( $job_options_support_worker == 'Yes' ) {

$message .= addToRenderShifts( $application, 'Monday' );

$message .= addToRenderShifts( $application, 'Tuesday' );

$message .= addToRenderShifts( $application, 'Wednesday' );

$message .= addToRenderShifts( $application, 'Thursday' );

$message .= addToRenderShifts( $application, 'Friday' );

$message .= addToRenderShifts( $application, 'Saturday' );

$message .= addToRenderShifts( $application, 'Sunday' );

$message .= addToRenderShifts( $application, 'Public Holidays' );


$message .= "<div class=\"field\"><span class=\"label\">Do you have previous experience working within the disability services area?" . ": </span>" . $application['experience_disability_services'] . "</div>";

if (isset($application['page_url'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page sent from" . ": </span>" . $application['page_url'] . "</div>";

}

if (isset($application['page_referrer'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page referred from" . ": </span>" . $application['page_referrer'] . "</div>";

}

echo $message;
}

function render_view_application(){

?>
<div class="wrap">

<h2>View Application</h2>

<?php

global $wpdb, $_wp_column_headers;

if (isset($_GET['application']) && !empty($_GET['application']) ) {

$query = "SELECT

*

FROM wp_job_applications

WHERE

id='" . $_GET['application'] . "'

";


$result = $wpdb->get_row($query);

$a = unserialize($result->application_data);
$a['date_submitted'] = $result->date_submitted;
$applicationdata=serialize($a);
$application = unserialize($applicationdata);

foreach ($application as $key => $value ) {

if (empty($value)) {

$application[$key] = 'Not submitted';

}
else{
if($_GET['onlyv']!="view"){
$table='wp_job_applications';
$where=" WHERE
id='". $_GET['application']."'";
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id = %d
"
,$_GET['application']));

}
}

}

unset($application['submit']);

echo "<style type=\"text/css\">

span.label {display: block; font-weight: bold;}



div.field {margin: 0 0 10px; border-bottom: 1px solid #eee; padding: 0 0 10px;}



form.buttons { float: left; }



form.buttons input,

a.button {

display: block;

float: left;

cursor: pointer;

font-family: sans-serif;

margin-left: 4px;

padding: 3px 8px;

position: relative;

top: -3px;

text-decoration: none;

font-size: 12px;

border: 0 none;

background: #f1f1f1;

color: #21759b;

margin: 10px 4px 20px;

line-height: 15px;

padding: 3px 10px;

white-space: nowrap;

-webkit-border-radius: 10px;

}



form.buttons input:hover {

color: #d54e21;

}



div.clear { clear: both; }



</style>";

echo '<form class="buttons" method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Export To CSV" />';

echo '</form>';



echo '<form class="buttons" method="post" name="print" target="_blank" action="' . plugin_dir_url(__FILE__) . 'print.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Print" />';

echo '</form>';



if (!empty($result->cv_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cv_path . '" title="Download CV">Download CV</a>';

}

if (!empty($result->cl_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cl_path . '" title="Download Cover Letter">Download Cover Letter</a>';

}
echo '<div class="clear"></div>';

render_application_data($application);

}

?>

</div>

<?php

}


midsummas comments:

Ok Bulk Delete is back and working as it was before. The single delete unfortunately still is not. If it won't work, then bulk delete is fine because I can just tick select the one I want. I am pretty sure there is something wrong here:

function column_date_submitted($item){

$actions = array(

'edit' => sprintf('<a href="?page=view_application&application=%s">View</a>', $item->id),

'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>','delete',$item->id)

);



return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );

}



function get_bulk_actions() {

$actions = array(

'delete' => 'Delete'

);

return $actions;

}


I think the <a href="?page=view_application&application=%s"> of the line 'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>','delete',$item->id) is having issues as it should not be sending the page to the view_application function...

Can we send the link elsewhere? Say back to the start of the table then maybe it might actually activate the delete call?

Cheers,

Les


Firoja_Imtosupport comments:

Hi Les,

i think you have not used my given full code, because in my given code below function is already changed.
function column_date_submitted($item){
$actions = array(
'edit' => sprintf('<a href="?page=view_application&application=%s">View</a>', $item->id),



'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>','delete',$item->id)
);
return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );
}


midsummas comments:

Hi Firoja,

What you have just pasted there is exactly the same as what I pasted in my code section...

Les


Firoja_Imtosupport comments:

Hi Les,

Please read my text propely, I am saying You are not using my whole given code your given function is already changed, and i pasted your code not mine


Firoja_Imtosupport comments:

Please use this code as it is:
<?php

/*

Plugin Name: Job Application List

*/
error_reporting(0);

if( ! class_exists( 'WP_List_Table' ) ) {

require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

}
class Job_Application_List_Table extends WP_List_Table {
function __construct(){
global $status, $page;
parent::__construct( array(

'singular' => __( 'application', 'mylisttable' ), //singular name of the listed records

'plural' => __( 'applications', 'mylisttable' ), //plural name of the listed records

'ajax' => false //does this table support ajax?

));
add_action( 'admin_head', array( &$this, 'admin_header' ) );
}

function admin_header() {
$page = ( isset($_GET['page'] ) ) ? esc_attr( $_GET['page'] ) : false;

if( 'my_list_test' != $page ) {

return;

}

echo '<style type="text/css">';

echo '.wp-list-table .column-id { width: 5%; }';

echo '.wp-list-table .column-booktitle { width: 40%; }';

echo '.wp-list-table .column-author { width: 35%; }';

echo '.wp-list-table .column-isbn { width: 20%;}';

echo '</style>';
}
function no_items() {

_e( 'No applications found.' );

}

function column_default( $item, $column_name ) {

switch( $column_name ) {

case 'date_submitted':

case 'job_pos':

case 'first_names':

case 'last_name':

case 'preferred_name':

case 'email_address':

case 'mobile':

return $item->$column_name;

default:

}

}
function get_sortable_columns() {

$sortable_columns = array(

'date_submitted' => array('date_submitted',false),

'job_pos' => array('job_pos',false),

'first_names' => array('first_names',false),

'last_name' => array('last_name',false),

'email_address' => array('email_address',false),

'mobile' => array('mobile',false)

);

return $sortable_columns;

}
function get_columns(){

$columns = array(

'cb' => '<input type="checkbox" />',

'date_submitted' => __( 'Submitted', 'mylisttable' ),

'job_pos' => __( 'Position', 'mylisttable' ),

'first_names' => __( 'First Names', 'mylisttable' ),

'last_name' => __( 'Last Name', 'mylisttable' ),

'email_address' => __( 'Email Address', 'mylisttable' ),

'mobile' => __( 'Mobile', 'mylisttable' )

);

return $columns;

}
function usort_reorder( $a, $b ) {

// If no sort, default to title

$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'date_submitted';

// If no order, default to asc

$order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';

// Determine sort order

$result = strcmp( $a[$orderby], $b[$orderby] );

// Send final sort direction to usort

return ( $order === 'asc' ) ? $result : -$result;

}
function column_date_submitted($item){

$actions = array(

'edit' => sprintf('<a href="?page=view_application&onlyv=view&application=%s">View</a>', $item->id),

'delete' => sprintf('<a href="?page=view_application&application=%s">Delete</a>',$item->id,$item->id)

);

return sprintf('%1$s %2$s', $item->date_submitted, $this->row_actions($actions) );

}

function get_bulk_actions() {
$actions = array(

'bulk-delete' => 'Delete'

);
return $actions;

}

function column_cb($item) {

return sprintf(

'<input type="checkbox" name="application[]" value="%s" />', $item->id

);

}
function prepare_items() {

global $wpdb, $_wp_column_headers;

$screen = get_current_screen();

$this->process_bulk_action();

$where_search = "";

if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {

$search = $_REQUEST['s'];

$where_search = "WHERE job_pos LIKE '%{$search}%'

OR first_names LIKE '%{$search}%'

OR last_name LIKE '%{$search}%'

OR email_address LIKE '%{$search}%'

";

}

$query = "SELECT

id,

date_submitted,

job_pos,

first_names,

last_name,

email_address,

mobile

FROM wp_job_applications

{$where_search}

";

$orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'ASC';

$order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : '';

if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }

$totalitems = $wpdb->query($query);

$perpage = 20;

$paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';

if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }

$totalpages = ceil($totalitems/$perpage);

if(!empty($paged) && !empty($perpage)){

$offset=($paged-1)*$perpage;

$query.=' LIMIT '.(int)$offset.','.(int)$perpage;

}

$this->set_pagination_args( array(

"total_items" => $totalitems,

"total_pages" => $totalpages,

"per_page" => $perpage,

) );

$columns = $this->get_columns();

$_wp_column_headers[$screen->id]=$columns;

$this->items = $wpdb->get_results($query);


}

public function process_bulk_action() {
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
) {
$delete_ids = esc_sql( $_POST['application'] );
// loop over the array of record IDs and delete them
foreach ( $delete_ids as $did ) {
global $wpdb;
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id='".$did."'"));
}

wp_redirect( esc_url( add_query_arg() ) );
exit;
}

}

} //class

function my_add_menu_items(){

$hook = add_menu_page( 'Job Applications', 'Job Applications', 'edit_posts', 'job_application_list', 'render_job_application_list', null, 150 );

add_action( "load-$hook", 'application_add_options' );

add_submenu_page( null, 'Edit Application', 'Edit Application', 'edit_posts', 'view_application', 'render_view_application' );

}
function application_add_options() {

global $myListTable;

$option = 'per_page';

$args = array(

'label' => 'Applications',

'default' => 10,

'option' => 'applications_per_page'

);

add_screen_option( $option, $args );

$myListTable = new Job_Application_List_Table();

}

add_action( 'admin_menu', 'my_add_menu_items' );

function render_job_application_list(){

global $myListTable;

echo '<div class="wrap"><h2>Job Applications</h2>';

echo '<form method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php">';

echo '<input type="submit" name="Submit" value="Export List To CSV" />';

echo '</form>';

$myListTable->prepare_items();

?>

<form method="post" name="frmmain">
<input type="hidden" name="page" value="ttest_list_table">
<?php
$myListTable->search_box( 'search', 'search_id' );
$myListTable->display();

echo '</form></div>';

}
function addToRenderShifts( $application, $day ) {
$message = '';
$day_id = str_replace(' ', '_', strtolower( $day ) );

if ( isset($application[$day_id]) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . ":</span> Yes</div>";

}
if ( isset($application[$day_id . '_morning_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Morning Shifts:</span> Yes</div>";

}
if ( isset($application[$day_id . '_afternoon_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Afternoon Shifts:</span> Yes</div>";

}
if ( isset($application[$day_id . '_night_shift']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift:</span> Yes</div>";

}
if ( isset($application[$day_id . '_night_shift_alt']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Night Shift Alt:</span> Yes</div>";

}
if ( isset($application[$day_id . '_tea_shifts']) ) {

$message .= "<div class=\"field\"><span class=\"label\">Available " . $day . " Tea Shifts:</span> Yes</div>";

}

return $message;
}

function render_application_data($application) {

$message = '';

$message .= "<div class=\"field\"><span class=\"label\">Job Position" . ": </span>" . $application['job_pos'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Last Name" . ": </span>" . $application['last_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">First Names" . ": </span>" . $application['first_names'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Preferred Name" . ": </span>" . $application['preferred_name'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Date of Birth" . ": </span>" . $application['dob'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Your Address" . ": </span>" . $application['your_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State" . ": </span>" . $application['state'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Postcode" . ": </span>" . $application['postcode'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Daytime Phone Number" . ": </span>" . $application['daytime_phone_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Mobile" . ": </span>" . $application['mobile'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Email Address" . ": </span>" . $application['email_address'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you of an Aboriginal or Torres Strait Islander background?" . ": </span>" . $application['aboriginal_torres'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you speak a language/s other than English at home?" . ": </span>" . $application['other_languages'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, what language is that?" . ": </span>" . $application['languages_list'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Are you legally entitled to work in Australia/New Zealand?" . ": </span>" . $application['legally_entitled'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Please provide details of your Visa" . ": </span>" . $application['visa_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">When does your visa expire?" . ": </span>" . $application['visa_expire'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Drivers License Number" . ": </span>" . $application['drivers_license_number'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">State of issue" . ": </span>" . $application['license_state_of_issue'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Class" . ": </span>" . $application['license_class'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Expiry Date" . ": </span>" . $application['license_expiry_date'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Type" . ": </span>" . $application['license_type'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you ever been disqualified from driving?" . ": </span>" . $application['disqualified_driving'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['disqualified_driving_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you own a reliable vehicle?" . ": </span>" . $application['reliable_vehicle'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a criminal record, or have a charge pending before any court?" . ": </span>" . $application['criminal_record'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['criminal_record_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Have you claimed workers compensation in the last five (5) years?" . ": </span>" . $application['workers_comp'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['workers_comp_details'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Do you have a medical condition that could interfere with your ability to<br />perform the duties of the position?" . ": </span>" . $application['medical_conditions'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If yes, please provide details" . ": </span>" . $application['medical_conditions_details'] . "</div>";

if (isset($application['hear_about_position'])) {

$message .= "<div class=\"field\"><span class=\"label\">How did you hear about this position at Nulsen?" . ": </span>" . $application['hear_about_position'] . "</div>";

}

if (isset($application['hear_about_from_where'])) {

$message .= "<div class=\"field\"><span class=\"label\">Further information on source" . ": </span>" . $application['hear_about_from_where'] . "</div>";

}

if (isset($application['dsc_worked_12_months'])) {

$message .= "<div class=\"field\"><span class=\"label\">Are you currently working or have you ever worked with the Western Australian Disability Services Commission (DSC) in the last 12 months?" . ": </span>" . $application['dsc_worked_12_months'] . "</div>";

}

if (isset($application['dsc_capacity_employed'])) {

$message .= "<div class=\"field\"><span class=\"label\">If yes, in what capacity were you employed with DSC?" . ": </span>" . $application['dsc_capacity_employed'] . "</div>";

}

if (isset($application['dsc_date_terminated'])) {

$message .= "<div class=\"field\"><span class=\"label\">If you resigned or your employment was terminated with DSC, on what date did your employment end with them?" . ": </span>" . $application['dsc_date_terminated'] . "</div>";

}

$message .= "<div class=\"field\"><span class=\"label\">Have you applied for a position with Nulsen before?" . ": </span>" . $application['applied_before'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 01" . ": </span>" . $application['qualification_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 01" . ": </span>" . $application['institution_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 01" . ": </span>" . $application['year_completed_01'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Qualification 02" . ": </span>" . $application['qualification_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Institution where you studied 02" . ": </span>" . $application['institution_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">Year Completed 02" . ": </span>" . $application['year_completed_02'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">How many years of relevant work experience do you have?" . ": </span>" . $application['work_experience'] . "</div>";

$message .= "<div class=\"field\"><span class=\"label\">If you\'re applying for a role as a support worker or nurse, what shifts can you work?" . ": </span>" . $application['shifts_anytime'] . "</div>";



// if ( $job_options_support_worker == 'Yes' ) {

$message .= addToRenderShifts( $application, 'Monday' );

$message .= addToRenderShifts( $application, 'Tuesday' );

$message .= addToRenderShifts( $application, 'Wednesday' );

$message .= addToRenderShifts( $application, 'Thursday' );

$message .= addToRenderShifts( $application, 'Friday' );

$message .= addToRenderShifts( $application, 'Saturday' );

$message .= addToRenderShifts( $application, 'Sunday' );

$message .= addToRenderShifts( $application, 'Public Holidays' );


$message .= "<div class=\"field\"><span class=\"label\">Do you have previous experience working within the disability services area?" . ": </span>" . $application['experience_disability_services'] . "</div>";

if (isset($application['page_url'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page sent from" . ": </span>" . $application['page_url'] . "</div>";

}

if (isset($application['page_referrer'])) {

$message .= "<div class=\"field\"><span class=\"label\">Page referred from" . ": </span>" . $application['page_referrer'] . "</div>";

}

echo $message;
}

function render_view_application(){

?>
<div class="wrap">

<h2>View Application</h2>

<?php

global $wpdb, $_wp_column_headers;

if (isset($_GET['application']) && !empty($_GET['application']) ) {

$query = "SELECT

*

FROM wp_job_applications

WHERE

id='" . $_GET['application'] . "'

";


$result = $wpdb->get_row($query);

$a = unserialize($result->application_data);
$a['date_submitted'] = $result->date_submitted;
$applicationdata=serialize($a);
$application = unserialize($applicationdata);

foreach ($application as $key => $value ) {

if (empty($value)) {

$application[$key] = 'Not submitted';

}
else{
if($_GET['onlyv']!="view"){
$table='wp_job_applications';
$where=" WHERE
id='". $_GET['application']."'";
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_job_applications
WHERE id = %d
"
,$_GET['application']));

}
}

}

unset($application['submit']);

echo "<style type=\"text/css\">

span.label {display: block; font-weight: bold;}



div.field {margin: 0 0 10px; border-bottom: 1px solid #eee; padding: 0 0 10px;}



form.buttons { float: left; }



form.buttons input,

a.button {

display: block;

float: left;

cursor: pointer;

font-family: sans-serif;

margin-left: 4px;

padding: 3px 8px;

position: relative;

top: -3px;

text-decoration: none;

font-size: 12px;

border: 0 none;

background: #f1f1f1;

color: #21759b;

margin: 10px 4px 20px;

line-height: 15px;

padding: 3px 10px;

white-space: nowrap;

-webkit-border-radius: 10px;

}



form.buttons input:hover {

color: #d54e21;

}



div.clear { clear: both; }



</style>";

echo '<form class="buttons" method="post" name="csv_export" action="' . plugin_dir_url(__FILE__) . 'export-to-csv.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Export To CSV" />';

echo '</form>';



echo '<form class="buttons" method="post" name="print" target="_blank" action="' . plugin_dir_url(__FILE__) . 'print.php?application=' . $_GET['application'] . '">';

echo '<input type="submit" name="Submit" value="Print" />';

echo '</form>';



if (!empty($result->cv_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cv_path . '" title="Download CV">Download CV</a>';

}

if (!empty($result->cl_path)) {

echo '<a class="button" target="_blank" href="' . get_bloginfo('url') . '/wp-content/applications/' . $result->cl_path . '" title="Download Cover Letter">Download Cover Letter</a>';

}
echo '<div class="clear"></div>';

render_application_data($application);

}

?>

</div>

<?php

}


midsummas comments:

Hi Firoja,

That is exactly the same code I used. You're not reading what I said earlier which was that I copied those lines from the code you gave me. I have used your FULL code both times and it is still not deleting single lines.

Les


Firoja_Imtosupport comments:

Hi Les,

Please give me screenshot on mouseover of view button, which will clear misunderstanding


Firoja_Imtosupport comments:

Hi Les,

You can share screenshot here

Thanks
Firoja


midsummas comments:

Here you go Firoja.