PluginProbe
Contact Forms by Cimatti / 1.3
Contact Forms by Cimatti v1.3
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.3, at accua-forms-submissions-page.php

565 lines 21.4 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 case 'colorpicker':
235 if ($row->afsv_value === '') {
236 $fielddata = '';
237 } else {
238 $value_esc = htmlspecialchars($row->afsv_value,ENT_QUOTES);
239 $fielddata = "<span style='color: {$value_esc}'><font color='{$value_esc}'>&#9608;</font></span> $value_esc";
240 }
241 break;
242 default:
243 $fielddata = htmlspecialchars($row->afsv_value,ENT_QUOTES);
244 }
245 $data[$row->afsv_sub_id]['_field_'.$row->afsv_field_id] = $fielddata;
246 }
247
248 $total_items = count($data);
249 if($all) {
250 $this->items = $data;
251 }
252 else {
253 $this->items = array_slice($data,(($current_page-1)*$per_page),$per_page);
254 }
255
256 $this->set_pagination_args( array(
257 'total_items' => $total_items,
258 'per_page' => $per_page,
259 'total_pages' => ceil($total_items/$per_page)
260 ) );
261
262
263 }
264
265 function process_bulk_action() {
266 if('delete'=== $this->current_action()) {
267 $trashed = array();
268 if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
269 foreach($_GET['submission'] as $i) {
270 $i = (int) $i;
271 $trashed[$i] = $i;
272 }
273 }
274 if ($trashed) {
275 $trashed = implode(',',$trashed);
276 global $wpdb;
277 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
278 if ($res === false) {
279 $this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'<br />');
280 } else if ($res == 1) {
281 $this->set_message(__("Moved 1 submission to trash.", 'accua-form-api').'<br />');
282 } else {
283 $this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'<br />');
284 }
285 } else {
286 $this->set_message(__("No submission selected.", 'accua-form-api').'<br />');
287 }
288 } else if('restore'=== $this->current_action()) {
289 $restored = array();
290 if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
291 foreach($_GET['submission'] as $i) {
292 $i = (int) $i;
293 $restored[$i] = $i;
294 }
295 }
296 if ($restored) {
297 $restored = implode(',',$restored);
298 global $wpdb;
299 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = 0 WHERE afs_id in ( $restored )");
300 if ($res === false) {
301 $this->set_message(__("Error restoring submissions.", 'accua-form-api').'<br />');
302 } else if ($res == 1) {
303 $this->set_message(__("Restored 1 submission.", 'accua-form-api').'<br />');
304 } else {
305 $this->set_message(strtr(__("Restored %res submissions.", 'accua-form-api'), array('%res' => $res)).'<br />');
306 }
307 } else {
308 $this->set_message(__("No submission selected.", 'accua-form-api').'<br />');
309 }
310 }
311 }
312 }
313
314 function accua_forms_submissions_list_page($head = false){
315 static $listTable = null;
316
317 global $wpdb;
318 if ($listTable === null) {
319 if (isset($_POST['action'])) {
320 if ($_POST['action'] === 'trash' && !empty($_POST['submission']) && is_array($_POST['submission'])) {
321 echo "yes";
322 $trashed = array();
323 foreach($_POST['submission'] as $i) {
324 $i = (int) $i;
325 $trashed[$i] = $i;
326 }
327 $trashed=implode(',',$trashed);
328
329 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
330 if ($res === false) {
331 $this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'<br />');
332 } else {
333 $this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'<br />');
334 }
335 }
336 }
337
338 /*
339 wp_enqueue_script('jquery-ui-mouse');
340 wp_enqueue_script('jquery-ui-widget');
341 */
342
343 wp_enqueue_script('jquery');
344 wp_enqueue_script('jquery-ui-core');
345 wp_enqueue_script('jquery-ui-sortable');
346
347 $listTable = new Accua_Forms_Submissions_List_Table();
348 $listTable->process_bulk_action();
349 $listTable->prepare_items();
350 }
351
352 if ($head === true) {
353 return;
354 }
355 ?>
356 <style>
357 .tablenav.bottom {
358 float: left;
359 width: 100%;
360 }
361
362 .accua_tablenav {
363 float: left;
364 }
365
366 .esportazione {
367 margin-left:10px;
368 }
369
370 .esportazione a {
371 cursor: pointer;
372 line-height: 28px;
373 text-decoration: underline;
374 }
375 .tablenav.top {
376 clear: none;
377 float: left;
378 width: 100%;
379 }
380 </style>
381 <div id="accua_forms_submissions_list_page" class="accua_forms_admin_page wrap">
382
383 <div id="icon-users" class="icon32"><br/></div>
384
385 <h2 style="margin-bottom: 20px;" ><?php _e("Forms Submissions", 'accua-form-api'); ?></h2>
386
387 <?php $filter_form = $filter_post = $filter_search = Null ;
388 $filter = '';
389 if(isset($_GET['_wp_http_referer'])) {
390 foreach (explode('&', $_GET['_wp_http_referer']) as $coppia) {
391 $param = explode("=", $coppia);
392
393 if($param[0]=='fid' && $param[1]!='-1') { $filter_form =$param[1]; }
394 if($param[0]=='pid' && $param[1]!='-1') { $filter_post =$param[1]; }
395 if($param[0]=='s' && $param[1]!='-1') { $filter_search =$param[1]; $filter.= "&amp;s=".$filter_search; ?>
396 <script type="text/javascript">
397 <!--
398 jQuery(document).ready(function($) {
399 jQuery('#search_id-search-input').val(<?php echo json_encode($filter_search); ?>);
400 });
401 //-->
402 </script>
403 <?php
404 }
405 }
406 }
407
408 if(isset($_GET['fid']) && ($_GET['fid'])!=-1) {
409 $filter_form = $_GET['fid'];
410 }
411 if(isset($_GET['pid']) && ($_GET['pid']!=-1)) {
412 $filter_post = $_GET['pid'];
413 }
414 if(isset($_GET['s']) && ($_GET['s']!=-1)) {
415 $filter_search = $_GET['s'];
416 $filter.= "&amp;s=".$filter_search;
417 }
418
419 $del = isset($_GET['del']) && ($_GET['del']==1);
420
421 ?>
422
423 <?php if($listTable->get_message()!=NULL) { ?>
424 <div class="updated"><p><?php echo $listTable->get_message(); ?></p></div>
425 <?php } ?>
426
427 <ul class="subsubsub">
428 <li>
429 <a <?php if (!$del) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_submissions_list">
430 <?php _e("Active", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_active_items(); ?>) |
431 </li>
432 <li>
433 <a <?php if ($del) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_submissions_list&del=1">
434 <?php _e("Trash", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_del_items(); ?>)
435 </li>
436 </ul>
437
438 <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>
439 <form style="margin-top: 20px;" id="submissions-action" method="get" action="">
440 <!-- For plugins, we also need to ensure that the form posts back to our current page -->
441 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
442 <input type="hidden" name="del" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['del'])); ?>" />
443 <!-- SEARCH FORM -->
444 <?php $listTable->search_box(__("Search", 'accua-form-api'), 'search_id'); ?>
445 <!-- FINE SEARCH FORM -->
446 <!-- FILTRI -->
447 <div class="accua_tablenav">
448 <?php
449 //tutti i form salvati e non
450
451 $saved_forms_id = array();
452 $forms_data = get_option('accua_forms_saved_forms', array());
453 foreach($forms_data as $single_form_key=>$single_form){
454 $saved_forms_id[]= "'".$wpdb->escape($single_form_key)."'";
455 }
456 $saved_forms_id_string = implode(',',$saved_forms_id);
457
458 $id_del_other_forms = $wpdb->get_results("SELECT distinct afs_form_id
459 FROM {$wpdb->prefix}accua_forms_submissions WHERE afs_form_id NOT IN ($saved_forms_id_string) AND afs_status >= 0", ARRAY_A);
460
461
462 //post submissions
463 $id_posts = $wpdb->get_results("SELECT distinct afs_post_id
464 FROM {$wpdb->prefix}accua_forms_submissions WHERE afs_post_id <> 0 AND afs_status >= 0 ", ARRAY_A);
465
466
467 ?>
468
469 <span><label><?php _e("Page: ", 'accua-form-api'); ?></label><select name='pid' id='pid'>
470 <option value="-1" selected ><?php _e("Show all pages", 'accua-form-api'); ?></option>
471 <?php foreach($id_posts as $id_post){
472 echo "<option value='".$id_post['afs_post_id']."'";
473 if($filter_post==$id_post['afs_post_id']) {
474 echo " selected ";
475 $filter.= "&amp;pid=".$filter_post;
476 }
477 echo ">".get_the_title($id_post['afs_post_id'])."</option>";
478 } ?>
479 </select></span>
480 <span style="margin-left: 10px;"><label><?php _e("Forms: ", 'accua-form-api'); ?></label><select name='fid' id='fid'>
481 <option value="-1" selected > <?php _e("Show all forms", 'accua-form-api'); ?> </option>
482 <?php foreach($forms_data as $single_form_key=>$single_form){
483 echo "<option value='".$single_form_key."'";
484 if($filter_form==$single_form_key) {
485 echo " selected ";
486 $filter.= "&amp;fid=".$filter_form;
487 }
488 echo ">";
489 if($single_form['title']!=NULL)
490 echo $single_form['title']; //TITOLO
491 else
492 echo $single_form_key; //ID
493 echo "</option>";
494 }
495 ///no saved forms///
496 foreach($id_del_other_forms as $id_del_other_form) {
497 echo "<option value='".$id_del_other_form['afs_form_id']."'";
498 if($filter_form==$id_del_other_form['afs_form_id']) {
499 echo " selected ";
500 $filter.= "&amp;fid=".$filter_form;
501 }
502 echo $id_del_other_form['afs_form_id']." (del) </option>";
503 }
504
505 ?>
506 </select>
507 </span><span>
508 <input type="submit" value="<?php _e("Filter", 'accua-form-api'); ?>" class="button-secondary action" name=""></span>
509 </form>
510 </div>
511 <!-- FINE FILTRI -->
512 <script type="text/javascript">
513 <!--
514 function set_parameter(sel_column) {
515 var stringa ='';
516 var name_action = ajaxurl + "?action=accua_forms_submission_page_save_excel<?php if ($del) {echo '&del=1';} ?>";
517 if(sel_column) {
518 jQuery('#adv-settings input[type=checkbox]:checked').each(function() {
519 stringa += jQuery(this).attr("id").replace("-hide","") + "%2C";
520 });
521 }
522 else {
523 jQuery('#adv-settings input[type=checkbox]').each(function() {
524 stringa += jQuery(this).attr("id").replace("-hide","") + "%2C";
525 });
526 }
527 var search = jQuery("#search_id-search-input").val();
528 var pid = jQuery("select#pid").val();
529 var fid = jQuery("select#fid").val();
530 if (search) name_action+='&s='+search;
531 if (pid) name_action+='&pid='+pid;
532 if (fid) name_action+='&fid='+fid;
533 if(stringa) name_action+= '&accua_show_field='+stringa;
534
535 if(sel_column) { jQuery('#esporta_link_visible_column').attr("href",name_action); }
536 else jQuery('#esporta_link_all_column').attr("href",name_action);
537
538 }
539 //-->
540 </script>
541 <!-- ESPORTAZIONE -->
542
543 <div class="accua_tablenav esportazione wp-core-ui ">
544 <a onclick ="set_parameter(1);" id="esporta_link_visible_column" class="button-primary"><?php _e("Export visible columns to Excel", 'accua-form-api'); ?></a>
545 <a onclick ="set_parameter(0);" id="esporta_link_all_column" class="button-primary"><?php _e("Export all columns to Excel", 'accua-form-api'); ?></a>
546 </div>
547
548 <!-- FINE ESPORTAZIONE -->
549 <form style="margin-top: 20px;" id="submissions-action" method="get" action="">
550 <!-- Now we can render the completed list table -->
551 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
552 <input type="hidden" name="del" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['del'])); ?>" />
553 <?php $listTable->display(); ?>
554 </form>
555 <?php /* <pre>$listTable = <?php echo htmlspecialchars(print_r($listTable, true)); ?></pre> */ ?>
556 </div>
557
558 <?php
559
560 }
561
562
563
564
565