message = '';
parent::__construct( array(
'singular' => 'submission',
'plural' => 'submissions',
'ajax' => false
) );
}
function get_num_of_active_items () {
return $this->active_items;
}
function get_num_of_del_items () {
return $this->del_items;
}
function column_default($item, $column_name){
if (isset($item[$column_name])) {
//return htmlspecialchars($item[$column_name], ENT_QUOTES);
return $item[$column_name];
} else {
return '';
}
}
function column_cb($item){
return sprintf(
'',
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
/*$2%s*/ $item['ID'] //The value of the checkbox should be the record's id
);
}
function set_message($single_message) {
$this->message=$single_message;
}
function get_message() {
if($this->message!=NULL)
return $this->message;
else
return NULL;
}
function get_columns(){
global $wpdb;
$columns = array(
'cb' => '', //Render a checkbox instead of text
'ID' => 'ID',
'form_title' => 'Form',
'form_id' => __("Form ID", 'accua-form-api'),
'pid' => __("Page ID", 'accua-form-api'),
'ip' => 'IP',
'uri' => __("Page", 'accua-form-api'),
'referrer' => __("Referrer", 'accua-form-api'),
'lang' => __("Language", 'accua-form-api'),
'created' => __("Opened", 'accua-form-api'),
'submitted' => __("Submitted", 'accua-form-api'),
);
$query = "SELECT DISTINCT afsv_field_id FROM `{$wpdb->prefix}accua_forms_submissions_values`";
$res = $wpdb->get_col($query);
$avail_fields = get_option('accua_forms_avail_fields', array());
foreach ($res as $col) {
if (empty($avail_fields[$col])) {
$columns['_field_'.$col] = $col . __("removed", 'accua-form-api');
} else {
$columns['_field_'.$col] = $avail_fields[$col]['name'];
}
}
return $columns;
}
function get_bulk_actions() {
if(isset($_GET['del']) && $_GET['del']==1) {
$actions = array(
'restore' => __('Restore', 'accua-form-api')
);
} else {
$actions = array(
'delete' => __('Move to trash', 'accua-form-api')
);
}
return $actions;
}
function prepare_items($all=false) {
global $wpdb, $hook_suffix;
$per_page = 20;
$del = isset($_GET['del']) && $_GET['del']==1;
$this->active_items = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_status >= 0");
$this->del_items = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_status < 0");
$filter = $filter_query_custom_field = "";
$search = NULL;
if(isset($_GET['_wp_http_referer'])) {
foreach (explode('&', $_GET['_wp_http_referer']) as $coppia) {
$param = explode("=", $coppia);
if($param[0]=='fid' && $param[1]!='-1') $filter .= " AND afs_form_id = '".$param[1]."' ";
if($param[0]=='pid' && $param[1]!='-1') $filter .= " AND afs_post_id = ".$param[1]. " ";
if($param[0]=='s' && $param[1]!='-1') $search = $param[1];
}
}
if(isset($_GET['fid']) && ($_GET['fid'])!=-1) {
$filter .= " AND afs_form_id = '".$_GET['fid']."' ";
}
if(isset($_GET['pid']) && ($_GET['pid']!=-1)) {
$filter .= " AND afs_post_id = ".$_GET['pid']. " ";
}
if(isset($_GET['s']) && ($_GET['s'])!=-1) {
$search = $_GET['s'];
}
$columns = $this->get_columns();
$hidden = get_hidden_columns($hook_suffix);
$sortable = array();
$this->_column_headers = array($columns, $hidden, $sortable);
$current_page = $this->get_pagenum();
$limit = ($current_page - 1) * $per_page;
$forms_data = get_option('accua_forms_saved_forms', array());
if ($del) {
$afs_status_cond = 'afs_status < 0';
} else {
$afs_status_cond = 'afs_status >= 0';
}
$searching_data = array();
if( $search != NULL && $search!= '')
{
$search = trim($search);
$query1 = " SELECT SQL_CALC_FOUND_ROWS
afs_id AS ID,
afs_form_id AS form_id,
afs_post_id AS pid,
afs_ip AS ip,
afs_uri AS uri,
afs_referrer AS referrer,
afs_lang AS lang,
afs_created AS created,
afs_submitted AS submitted
FROM `{$wpdb->prefix}accua_forms_submissions`
WHERE $afs_status_cond ".$filter."
AND (
afs_ip LIKE '%%".$search."%%'
OR afs_uri LIKE '%%".$search."%%'
OR afs_referrer LIKE '%%".$search."%%'
OR afs_lang LIKE '%%".$search."%%'
OR afs_created LIKE '%%".$search."%%'
OR afs_submitted LIKE '%%".$search."%%'
OR afs_id LIKE '%%".$search."%%'
OR afs_id
IN (
SELECT DISTINCT (afsv_sub_id)
FROM `{$wpdb->prefix}accua_forms_submissions_values`
WHERE afsv_value LIKE '%%".$search."%%')
)
ORDER BY afs_id DESC";
}
else
{
$query1 = "SELECT SQL_CALC_FOUND_ROWS
afs_id AS ID,
afs_form_id AS form_id,
afs_post_id AS pid,
afs_ip AS ip,
afs_uri AS uri,
afs_referrer AS referrer,
afs_lang AS lang,
afs_created AS created,
afs_submitted AS submitted
FROM `{$wpdb->prefix}accua_forms_submissions`
WHERE $afs_status_cond ".$filter."
ORDER BY afs_id DESC";
}
$data1 = $wpdb->get_results($query1, ARRAY_A);
$total_items = $wpdb->get_var('SELECT FOUND_ROWS()');
$data = array();
$submissions = array();
foreach ($data1 as $row) {
$fid = $row['form_id'];
if (isset($forms_data[$fid]['title']) && (trim($forms_data[$fid]['title']) !== '')) {
$row['form_title'] = htmlspecialchars($forms_data[$fid]['title']);
} else {
$row['form_title'] = $fid;
}
$sid = $row['ID'];
$data[$sid] = $row;
$submissions[] = $sid;
}
$submissions = implode(',',$submissions);
$query2 = "SELECT *
FROM `{$wpdb->prefix}accua_forms_submissions_values`
WHERE afsv_sub_id IN ($submissions) ";
$data2 = $wpdb->get_results($query2, OBJECT);
foreach ($data2 as $row) {
switch ($row->afsv_type) {
case 'file' :
$fieldid = rawurlencode($row->afsv_field_id);
$filename = rawurlencode($row->afsv_value);
$url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}";
$url = htmlspecialchars($url,ENT_QUOTES);
$filename = htmlspecialchars($row->afsv_value,ENT_QUOTES);
$fielddata = "{$filename}";
break;
default:
$fielddata = htmlspecialchars($row->afsv_value,ENT_QUOTES);;
}
$data[$row->afsv_sub_id]['_field_'.$row->afsv_field_id] = $fielddata;
}
$total_items = count($data);
if($all) {
$this->items = $data;
}
else {
$this->items = array_slice($data,(($current_page-1)*$per_page),$per_page);
}
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil($total_items/$per_page)
) );
}
function process_bulk_action() {
if('delete'=== $this->current_action()) {
$trashed = array();
if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
foreach($_GET['submission'] as $i) {
$i = (int) $i;
$trashed[$i] = $i;
}
}
if ($trashed) {
$trashed = implode(',',$trashed);
global $wpdb;
$res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
if ($res === false) {
$this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'
');
} else if ($res == 1) {
$this->set_message(__("Moved 1 submission to trash.", 'accua-form-api').'
');
} else {
$this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'
');
}
} else {
$this->set_message(__("No submission selected.", 'accua-form-api').'
');
}
} else if('restore'=== $this->current_action()) {
$restored = array();
if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
foreach($_GET['submission'] as $i) {
$i = (int) $i;
$restored[$i] = $i;
}
}
if ($restored) {
$restored = implode(',',$restored);
global $wpdb;
$res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = 0 WHERE afs_id in ( $restored )");
if ($res === false) {
$this->set_message(__("Error restoring submissions.", 'accua-form-api').'
');
} else if ($res == 1) {
$this->set_message(__("Restored 1 submission.", 'accua-form-api').'
');
} else {
$this->set_message(strtr(__("Restored %res submissions.", 'accua-form-api'), array('%res' => $res)).'
');
}
} else {
$this->set_message(__("No submission selected.", 'accua-form-api').'
');
}
}
}
}
function accua_forms_submissions_list_page($head = false){
static $listTable = null;
global $wpdb;
if ($listTable === null) {
if (isset($_POST['action'])) {
if ($_POST['action'] === 'trash' && !empty($_POST['submission']) && is_array($_POST['submission'])) {
echo "yes";
$trashed = array();
foreach($_POST['submission'] as $i) {
$i = (int) $i;
$trashed[$i] = $i;
}
$trashed=implode(',',$trashed);
$res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
if ($res === false) {
$this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'
');
} else {
$this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'
');
}
}
}
/*
wp_enqueue_script('jquery-ui-mouse');
wp_enqueue_script('jquery-ui-widget');
*/
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-sortable');
$listTable = new Accua_Forms_Submissions_List_Table();
$listTable->process_bulk_action();
$listTable->prepare_items();
}
if ($head === true) {
return;
}
?>
get_message(); ?>