PluginProbe
Contact Forms by Cimatti / 1.2
Contact Forms by Cimatti v1.2
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / accua-forms-submissions-page.php

accua-forms-submissions-page.php in Contact Forms by Cimatti 1.2, at accua-forms-submissions-page.php

557 lines 21.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if(!class_exists('WP_List_Table')){
3 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4 }
5
6 class Accua_Forms_Submissions_List_Table extends WP_List_Table {
7
8 var $message = NULL;
9 var $active_items = 0;
10 var $del_items = 0;
11
12 function __construct(){
13 global $status, $page;
14 $this->message = '';
15 parent::__construct( array(
16 'singular' => 'submission',
17 'plural' => 'submissions',
18 'ajax' => false
19 ) );
20 }
21
22 function get_num_of_active_items () {
23 return $this->active_items;
24 }
25
26 function get_num_of_del_items () {
27 return $this->del_items;
28 }
29
30 function column_default($item, $column_name){
31 if (isset($item[$column_name])) {
32 //return htmlspecialchars($item[$column_name], ENT_QUOTES);
33 return $item[$column_name];
34 } else {
35 return '';
36 }
37 }
38
39 function column_cb($item){
40 return sprintf(
41 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
42 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
43 /*$2%s*/ $item['ID'] //The value of the checkbox should be the record's id
44 );
45 }
46
47 function set_message($single_message) {
48 $this->message=$single_message;
49 }
50
51 function get_message() {
52 if($this->message!=NULL)
53 return $this->message;
54 else
55 return NULL;
56 }
57
58 function get_columns(){
59 global $wpdb;
60 $columns = array(
61 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
62 'ID' => 'ID',
63 'form_title' => 'Form',
64 'form_id' => __("Form ID", 'accua-form-api'),
65 'pid' => __("Page ID", 'accua-form-api'),
66 'ip' => 'IP',
67 'uri' => __("Page", 'accua-form-api'),
68 'referrer' => __("Referrer", 'accua-form-api'),
69 'lang' => __("Language", 'accua-form-api'),
70 'created' => __("Opened", 'accua-form-api'),
71 'submitted' => __("Submitted", 'accua-form-api'),
72 );
73 $query = "SELECT DISTINCT afsv_field_id FROM `{$wpdb->prefix}accua_forms_submissions_values`";
74 $res = $wpdb->get_col($query);
75
76 $avail_fields = get_option('accua_forms_avail_fields', array());
77 foreach ($res as $col) {
78 if (empty($avail_fields[$col])) {
79 $columns['_field_'.$col] = $col . __("removed", 'accua-form-api');
80 } else {
81 $columns['_field_'.$col] = $avail_fields[$col]['name'];
82 }
83 }
84 return $columns;
85 }
86
87 function get_bulk_actions() {
88 if(isset($_GET['del']) && $_GET['del']==1) {
89 $actions = array(
90 'restore' => __('Restore', 'accua-form-api')
91 );
92 } else {
93 $actions = array(
94 'delete' => __('Move to trash', 'accua-form-api')
95 );
96 }
97 return $actions;
98 }
99
100 function prepare_items($all=false) {
101 global $wpdb, $hook_suffix;
102 $per_page = 20;
103 $del = isset($_GET['del']) && $_GET['del']==1;
104
105 $this->active_items = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_status >= 0");
106 $this->del_items = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_status < 0");
107
108 $filter = $filter_query_custom_field = "";
109 $search = NULL;
110
111 if(isset($_GET['_wp_http_referer'])) {
112 foreach (explode('&', $_GET['_wp_http_referer']) as $coppia) {
113 $param = explode("=", $coppia);
114 if($param[0]=='fid' && $param[1]!='-1') $filter .= " AND afs_form_id = '".$param[1]."' ";
115 if($param[0]=='pid' && $param[1]!='-1') $filter .= " AND afs_post_id = ".$param[1]. " ";
116 if($param[0]=='s' && $param[1]!='-1') $search = $param[1];
117 }
118 }
119
120 if(isset($_GET['fid']) && ($_GET['fid'])!=-1) {
121 $filter .= " AND afs_form_id = '".$_GET['fid']."' ";
122 }
123 if(isset($_GET['pid']) && ($_GET['pid']!=-1)) {
124 $filter .= " AND afs_post_id = ".$_GET['pid']. " ";
125 }
126
127 if(isset($_GET['s']) && ($_GET['s'])!=-1) {
128 $search = $_GET['s'];
129 }
130
131 $columns = $this->get_columns();
132 $hidden = get_hidden_columns($hook_suffix);
133 $sortable = array();
134
135 $this->_column_headers = array($columns, $hidden, $sortable);
136 $current_page = $this->get_pagenum();
137
138 $limit = ($current_page - 1) * $per_page;
139
140 $forms_data = get_option('accua_forms_saved_forms', array());
141
142 if ($del) {
143 $afs_status_cond = 'afs_status < 0';
144 } else {
145 $afs_status_cond = 'afs_status >= 0';
146 }
147
148 $searching_data = array();
149 if( $search != NULL && $search!= '')
150 {
151 $search = trim($search);
152 $query1 = " SELECT SQL_CALC_FOUND_ROWS
153 afs_id AS ID,
154 afs_form_id AS form_id,
155 afs_post_id AS pid,
156 afs_ip AS ip,
157 afs_uri AS uri,
158 afs_referrer AS referrer,
159 afs_lang AS lang,
160 afs_created AS created,
161 afs_submitted AS submitted
162 FROM `{$wpdb->prefix}accua_forms_submissions`
163 WHERE $afs_status_cond ".$filter."
164 AND (
165 afs_ip LIKE '%%".$search."%%'
166 OR afs_uri LIKE '%%".$search."%%'
167 OR afs_referrer LIKE '%%".$search."%%'
168 OR afs_lang LIKE '%%".$search."%%'
169 OR afs_created LIKE '%%".$search."%%'
170 OR afs_submitted LIKE '%%".$search."%%'
171 OR afs_id LIKE '%%".$search."%%'
172 OR afs_id
173 IN (
174 SELECT DISTINCT (afsv_sub_id)
175 FROM `{$wpdb->prefix}accua_forms_submissions_values`
176 WHERE afsv_value LIKE '%%".$search."%%')
177 )
178 ORDER BY afs_id DESC";
179 }
180 else
181 {
182 $query1 = "SELECT SQL_CALC_FOUND_ROWS
183 afs_id AS ID,
184 afs_form_id AS form_id,
185 afs_post_id AS pid,
186 afs_ip AS ip,
187 afs_uri AS uri,
188 afs_referrer AS referrer,
189 afs_lang AS lang,
190 afs_created AS created,
191 afs_submitted AS submitted
192 FROM `{$wpdb->prefix}accua_forms_submissions`
193 WHERE $afs_status_cond ".$filter."
194 ORDER BY afs_id DESC";
195 }
196
197 $data1 = $wpdb->get_results($query1, ARRAY_A);
198
199 $total_items = $wpdb->get_var('SELECT FOUND_ROWS()');
200
201 $data = array();
202 $submissions = array();
203 foreach ($data1 as $row) {
204 $fid = $row['form_id'];
205
206 if (isset($forms_data[$fid]['title']) && (trim($forms_data[$fid]['title']) !== '')) {
207 $row['form_title'] = htmlspecialchars($forms_data[$fid]['title']);
208 } else {
209 $row['form_title'] = $fid;
210 }
211
212 $sid = $row['ID'];
213 $data[$sid] = $row;
214 $submissions[] = $sid;
215 }
216
217 $submissions = implode(',',$submissions);
218 $query2 = "SELECT *
219 FROM `{$wpdb->prefix}accua_forms_submissions_values`
220 WHERE afsv_sub_id IN ($submissions) ";
221
222 $data2 = $wpdb->get_results($query2, OBJECT);
223
224 foreach ($data2 as $row) {
225 switch ($row->afsv_type) {
226 case 'file' :
227 $fieldid = rawurlencode($row->afsv_field_id);
228 $filename = rawurlencode($row->afsv_value);
229 $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}";
230 $url = htmlspecialchars($url,ENT_QUOTES);
231 $filename = htmlspecialchars($row->afsv_value,ENT_QUOTES);
232 $fielddata = "<a href='{$url}' target='_blank'>{$filename}</a>";
233 break;
234 default:
235 $fielddata = htmlspecialchars($row->afsv_value,ENT_QUOTES);;
236 }
237 $data[$row->afsv_sub_id]['_field_'.$row->afsv_field_id] = $fielddata;
238 }
239
240 $total_items = count($data);
241 if($all) {
242 $this->items = $data;
243 }
244 else {
245 $this->items = array_slice($data,(($current_page-1)*$per_page),$per_page);
246 }
247
248 $this->set_pagination_args( array(
249 'total_items' => $total_items,
250 'per_page' => $per_page,
251 'total_pages' => ceil($total_items/$per_page)
252 ) );
253
254
255 }
256
257 function process_bulk_action() {
258 if('delete'=== $this->current_action()) {
259 $trashed = array();
260 if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
261 foreach($_GET['submission'] as $i) {
262 $i = (int) $i;
263 $trashed[$i] = $i;
264 }
265 }
266 if ($trashed) {
267 $trashed = implode(',',$trashed);
268 global $wpdb;
269 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
270 if ($res === false) {
271 $this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'<br />');
272 } else if ($res == 1) {
273 $this->set_message(__("Moved 1 submission to trash.", 'accua-form-api').'<br />');
274 } else {
275 $this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'<br />');
276 }
277 } else {
278 $this->set_message(__("No submission selected.", 'accua-form-api').'<br />');
279 }
280 } else if('restore'=== $this->current_action()) {
281 $restored = array();
282 if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
283 foreach($_GET['submission'] as $i) {
284 $i = (int) $i;
285 $restored[$i] = $i;
286 }
287 }
288 if ($restored) {
289 $restored = implode(',',$restored);
290 global $wpdb;
291 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = 0 WHERE afs_id in ( $restored )");
292 if ($res === false) {
293 $this->set_message(__("Error restoring submissions.", 'accua-form-api').'<br />');
294 } else if ($res == 1) {
295 $this->set_message(__("Restored 1 submission.", 'accua-form-api').'<br />');
296 } else {
297 $this->set_message(strtr(__("Restored %res submissions.", 'accua-form-api'), array('%res' => $res)).'<br />');
298 }
299 } else {
300 $this->set_message(__("No submission selected.", 'accua-form-api').'<br />');
301 }
302 }
303 }
304 }
305
306 function accua_forms_submissions_list_page($head = false){
307 static $listTable = null;
308
309 global $wpdb;
310 if ($listTable === null) {
311 if (isset($_POST['action'])) {
312 if ($_POST['action'] === 'trash' && !empty($_POST['submission']) && is_array($_POST['submission'])) {
313 echo "yes";
314 $trashed = array();
315 foreach($_POST['submission'] as $i) {
316 $i = (int) $i;
317 $trashed[$i] = $i;
318 }
319 $trashed=implode(',',$trashed);
320
321 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
322 if ($res === false) {
323 $this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'<br />');
324 } else {
325 $this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'<br />');
326 }
327 }
328 }
329
330 /*
331 wp_enqueue_script('jquery-ui-mouse');
332 wp_enqueue_script('jquery-ui-widget');
333 */
334
335 wp_enqueue_script('jquery');
336 wp_enqueue_script('jquery-ui-core');
337 wp_enqueue_script('jquery-ui-sortable');
338
339 $listTable = new Accua_Forms_Submissions_List_Table();
340 $listTable->process_bulk_action();
341 $listTable->prepare_items();
342 }
343
344 if ($head === true) {
345 return;
346 }
347 ?>
348 <style>
349 .tablenav.bottom {
350 float: left;
351 width: 100%;
352 }
353
354 .accua_tablenav {
355 float: left;
356 }
357
358 .esportazione {
359 margin-left:10px;
360 }
361
362 .esportazione a {
363 cursor: pointer;
364 line-height: 28px;
365 text-decoration: underline;
366 }
367 .tablenav.top {
368 clear: none;
369 float: left;
370 width: 100%;
371 }
372 </style>
373 <div id="accua_forms_submissions_list_page" class="accua_forms_admin_page wrap">
374
375 <div id="icon-users" class="icon32"><br/></div>
376
377 <h2 style="margin-bottom: 20px;" ><?php _e("Forms Submissions", 'accua-form-api'); ?></h2>
378
379 <?php $filter_form = $filter_post = $filter_search = Null ;
380 $filter = '';
381 if(isset($_GET['_wp_http_referer'])) {
382 foreach (explode('&', $_GET['_wp_http_referer']) as $coppia) {
383 $param = explode("=", $coppia);
384
385 if($param[0]=='fid' && $param[1]!='-1') { $filter_form =$param[1]; }
386 if($param[0]=='pid' && $param[1]!='-1') { $filter_post =$param[1]; }
387 if($param[0]=='s' && $param[1]!='-1') { $filter_search =$param[1]; $filter.= "&amp;s=".$filter_search; ?>
388 <script type="text/javascript">
389 <!--
390 jQuery(document).ready(function($) {
391 jQuery('#search_id-search-input').val(<?php echo json_encode($filter_search); ?>);
392 });
393 //-->
394 </script>
395 <?php
396 }
397 }
398 }
399
400 if(isset($_GET['fid']) && ($_GET['fid'])!=-1) {
401 $filter_form = $_GET['fid'];
402 }
403 if(isset($_GET['pid']) && ($_GET['pid']!=-1)) {
404 $filter_post = $_GET['pid'];
405 }
406 if(isset($_GET['s']) && ($_GET['s']!=-1)) {
407 $filter_search = $_GET['s'];
408 $filter.= "&amp;s=".$filter_search;
409 }
410
411 $del = isset($_GET['del']) && ($_GET['del']==1);
412
413 ?>
414
415 <?php if($listTable->get_message()!=NULL) { ?>
416 <div class="updated"><p><?php echo $listTable->get_message(); ?></p></div>
417 <?php } ?>
418
419 <ul class="subsubsub">
420 <li>
421 <a <?php if (!$del) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_submissions_list">
422 <?php _e("Active", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_active_items(); ?>) |
423 </li>
424 <li>
425 <a <?php if ($del) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_submissions_list&del=1">
426 <?php _e("Trash", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_del_items(); ?>)
427 </li>
428 </ul>
429
430 <p style="clear:both;"><?php _e("Use the screen options to add or remove columns from the table below. Only the visible columns will be exported.", 'accua-form-api'); ?></p>
431 <form style="margin-top: 20px;" id="submissions-action" method="get" action="">
432 <!-- For plugins, we also need to ensure that the form posts back to our current page -->
433 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
434 <input type="hidden" name="del" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['del'])); ?>" />
435 <!-- SEARCH FORM -->
436 <?php $listTable->search_box(__("Search", 'accua-form-api'), 'search_id'); ?>
437 <!-- FINE SEARCH FORM -->
438 <!-- FILTRI -->
439 <div class="accua_tablenav">
440 <?php
441 //tutti i form salvati e non
442
443 $saved_forms_id = array();
444 $forms_data = get_option('accua_forms_saved_forms', array());
445 foreach($forms_data as $single_form_key=>$single_form){
446 $saved_forms_id[]= "'".$wpdb->escape($single_form_key)."'";
447 }
448 $saved_forms_id_string = implode(',',$saved_forms_id);
449
450 $id_del_other_forms = $wpdb->get_results("SELECT distinct afs_form_id
451 FROM {$wpdb->prefix}accua_forms_submissions WHERE afs_form_id NOT IN ($saved_forms_id_string) AND afs_status >= 0", ARRAY_A);
452
453
454 //post submissions
455 $id_posts = $wpdb->get_results("SELECT distinct afs_post_id
456 FROM {$wpdb->prefix}accua_forms_submissions WHERE afs_post_id <> 0 AND afs_status >= 0 ", ARRAY_A);
457
458
459 ?>
460
461 <span><label><?php _e("Page: ", 'accua-form-api'); ?></label><select name='pid' id='pid'>
462 <option value="-1" selected ><?php _e("Show all pages", 'accua-form-api'); ?></option>
463 <?php foreach($id_posts as $id_post){
464 echo "<option value='".$id_post['afs_post_id']."'";
465 if($filter_post==$id_post['afs_post_id']) {
466 echo " selected ";
467 $filter.= "&amp;pid=".$filter_post;
468 }
469 echo ">".get_the_title($id_post['afs_post_id'])."</option>";
470 } ?>
471 </select></span>
472 <span style="margin-left: 10px;"><label><?php _e("Forms: ", 'accua-form-api'); ?></label><select name='fid' id='fid'>
473 <option value="-1" selected > <?php _e("Show all forms", 'accua-form-api'); ?> </option>
474 <?php foreach($forms_data as $single_form_key=>$single_form){
475 echo "<option value='".$single_form_key."'";
476 if($filter_form==$single_form_key) {
477 echo " selected ";
478 $filter.= "&amp;fid=".$filter_form;
479 }
480 echo ">";
481 if($single_form['title']!=NULL)
482 echo $single_form['title']; //TITOLO
483 else
484 echo $single_form_key; //ID
485 echo "</option>";
486 }
487 ///no saved forms///
488 foreach($id_del_other_forms as $id_del_other_form) {
489 echo "<option value='".$id_del_other_form['afs_form_id']."'";
490 if($filter_form==$id_del_other_form['afs_form_id']) {
491 echo " selected ";
492 $filter.= "&amp;fid=".$filter_form;
493 }
494 echo $id_del_other_form['afs_form_id']." (del) </option>";
495 }
496
497 ?>
498 </select>
499 </span><span>
500 <input type="submit" value="<?php _e("Filter", 'accua-form-api'); ?>" class="button-secondary action" name=""></span>
501 </form>
502 </div>
503 <!-- FINE FILTRI -->
504 <script type="text/javascript">
505 <!--
506 function set_parameter(sel_column) {
507 var stringa ='';
508 var name_action = ajaxurl + "?action=accua_forms_submission_page_save_excel<?php if ($del) {echo '&del=1';} ?>";
509 if(sel_column) {
510 jQuery('#adv-settings input[type=checkbox]:checked').each(function() {
511 stringa += jQuery(this).attr("id").replace("-hide","") + "%2C";
512 });
513 }
514 else {
515 jQuery('#adv-settings input[type=checkbox]').each(function() {
516 stringa += jQuery(this).attr("id").replace("-hide","") + "%2C";
517 });
518 }
519 var search = jQuery("#search_id-search-input").val();
520 var pid = jQuery("select#pid").val();
521 var fid = jQuery("select#fid").val();
522 if (search) name_action+='&s='+search;
523 if (pid) name_action+='&pid='+pid;
524 if (fid) name_action+='&fid='+fid;
525 if(stringa) name_action+= '&accua_show_field='+stringa;
526
527 if(sel_column) { jQuery('#esporta_link_visible_column').attr("href",name_action); }
528 else jQuery('#esporta_link_all_column').attr("href",name_action);
529
530 }
531 //-->
532 </script>
533 <!-- ESPORTAZIONE -->
534
535 <div class="accua_tablenav esportazione wp-core-ui ">
536 <a onclick ="set_parameter(1);" id="esporta_link_visible_column" class="button-primary"><?php _e("Export visible columns to Excel", 'accua-form-api'); ?></a>
537 <a onclick ="set_parameter(0);" id="esporta_link_all_column" class="button-primary"><?php _e("Export all columns to Excel", 'accua-form-api'); ?></a>
538 </div>
539
540 <!-- FINE ESPORTAZIONE -->
541 <form style="margin-top: 20px;" id="submissions-action" method="get" action="">
542 <!-- Now we can render the completed list table -->
543 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
544 <input type="hidden" name="del" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['del'])); ?>" />
545 <?php $listTable->display(); ?>
546 </form>
547 <?php /* <pre>$listTable = <?php echo htmlspecialchars(print_r($listTable, true)); ?></pre> */ ?>
548 </div>
549
550 <?php
551
552 }
553
554
555
556
557