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

583 lines 21.8 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'],
43 /*$2%s*/ $item['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, $get = array()) {
101 global $wpdb, $hook_suffix;
102
103 if (!$get) {
104 $get = stripslashes_deep($_GET);
105 }
106
107 $per_page = 20;
108 $del = isset($get['del']) && $get['del']==1;
109
110 $this->active_items = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_status >= 0");
111 $this->del_items = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_status < 0");
112
113 $filter = $filter_query_custom_field = "";
114 $search = '';
115
116 if(isset($get['_wp_http_referer'])) {
117 foreach (explode('&', $get['_wp_http_referer']) as $coppia) {
118 $param = explode("=", $coppia);
119 if($param[0]=='fid' && $param[1]!='-1') $filter .= $wpdb->prepare(" AND afs_form_id = '%s' ", $param[1]);
120 if($param[0]=='pid' && $param[1]!='-1') $filter .= $wpdb->prepare(" AND afs_post_id = '%s' ", $param[1]);
121 if($param[0]=='s') $search = trim($param[1]);
122 }
123 }
124
125 if(isset($get['fid']) && ($get['fid'])!=-1) {
126 $filter .= $wpdb->prepare(" AND afs_form_id = '%s' ", $get['fid']);
127 }
128 if(isset($get['pid']) && ($get['pid']!=-1)) {
129 $filter .= $wpdb->prepare(" AND afs_post_id = %d ", $get['pid']);
130 }
131
132 if(isset($get['s'])) {
133 $search = trim($get['s']);
134 }
135
136 if (isset($get['date_from']) && $get['date_from'] !== '') {
137 $filter .= $wpdb->prepare(" AND afs_submitted >= '%s' ", $get['date_from']);
138 }
139 if (isset($get['date_to']) && $get['date_to'] !== '') {
140 $filter .= $wpdb->prepare(" AND afs_submitted < '%s' ", $get['date_to']);
141 }
142
143
144 $columns = $this->get_columns();
145 $hidden = get_hidden_columns($hook_suffix);
146 $sortable = array();
147
148 $this->_column_headers = array($columns, $hidden, $sortable);
149 $current_page = $this->get_pagenum();
150
151 if ($all) {
152 $limit = '';
153 } else {
154 $limit = ($current_page - 1) * $per_page;
155 $limit = "LIMIT {$limit}, {$per_page}";
156 }
157
158 $forms_data = get_option('accua_forms_saved_forms', array());
159
160 if ($del) {
161 $afs_status_cond = 'afs_status < 0';
162 } else {
163 $afs_status_cond = 'afs_status >= 0';
164 }
165
166 $searching_data = array();
167 if($search !== '')
168 {
169 $sql_search = $wpdb->prepare("'%s'", "%$search%");
170 $query1 = " SELECT SQL_CALC_FOUND_ROWS
171 afs_id AS ID,
172 afs_form_id AS form_id,
173 afs_post_id AS pid,
174 afs_ip AS ip,
175 afs_uri AS uri,
176 afs_referrer AS referrer,
177 afs_lang AS lang,
178 afs_created AS created,
179 afs_submitted AS submitted
180 FROM `{$wpdb->prefix}accua_forms_submissions`
181 WHERE {$afs_status_cond} {$filter}
182 AND (
183 afs_ip LIKE {$sql_search}
184 OR afs_uri LIKE {$sql_search}
185 OR afs_referrer LIKE {$sql_search}
186 OR afs_lang LIKE {$sql_search}
187 OR afs_created LIKE {$sql_search}
188 OR afs_submitted LIKE {$sql_search}
189 OR afs_id LIKE {$sql_search}
190 OR afs_id
191 IN (
192 SELECT DISTINCT (afsv_sub_id)
193 FROM `{$wpdb->prefix}accua_forms_submissions_values`
194 WHERE afsv_value LIKE {$sql_search})
195 )
196 ORDER BY afs_id DESC
197 {$limit}";
198 }
199 else
200 {
201 $query1 = "SELECT SQL_CALC_FOUND_ROWS
202 afs_id AS ID,
203 afs_form_id AS form_id,
204 afs_post_id AS pid,
205 afs_ip AS ip,
206 afs_uri AS uri,
207 afs_referrer AS referrer,
208 afs_lang AS lang,
209 afs_created AS created,
210 afs_submitted AS submitted
211 FROM `{$wpdb->prefix}accua_forms_submissions`
212 WHERE {$afs_status_cond} {$filter}
213 ORDER BY afs_id DESC
214 {$limit}";
215 }
216
217 $data1 = $wpdb->get_results($query1, ARRAY_A);
218
219 $total_items = $wpdb->get_var('SELECT FOUND_ROWS()');
220
221 $data = array();
222 $submissions = array();
223 foreach ($data1 as $row) {
224 $fid = $row['form_id'];
225
226 if (isset($forms_data[$fid]['title']) && (trim($forms_data[$fid]['title']) !== '')) {
227 $row['form_title'] = htmlspecialchars($forms_data[$fid]['title']);
228 } else {
229 $row['form_title'] = $fid;
230 }
231
232 $sid = $row['ID'];
233 $data[$sid] = $row;
234 $submissions[] = $sid;
235 }
236
237 $submissions = implode(',',$submissions);
238 $query2 = "SELECT *
239 FROM `{$wpdb->prefix}accua_forms_submissions_values`
240 WHERE afsv_sub_id IN ($submissions) ";
241
242 $data2 = $wpdb->get_results($query2, OBJECT);
243
244 foreach ($data2 as $row) {
245 switch ($row->afsv_type) {
246 case 'file' :
247 $fieldid = rawurlencode($row->afsv_field_id);
248 $filename = rawurlencode($row->afsv_value);
249 $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}";
250 $url = htmlspecialchars($url,ENT_QUOTES);
251 $filename = htmlspecialchars($row->afsv_value,ENT_QUOTES);
252 $fielddata = "<a href='{$url}' target='_blank'>{$filename}</a>";
253 break;
254 case 'colorpicker':
255 if ($row->afsv_value === '') {
256 $fielddata = '';
257 } else {
258 $value_esc = htmlspecialchars($row->afsv_value,ENT_QUOTES);
259 $fielddata = "<span style='color: {$value_esc}'><font color='{$value_esc}'>&#9608;</font></span> $value_esc";
260 }
261 break;
262 case 'password':
263 case 'password-and-confirm':
264 $fielddata = '';
265 break;
266 default:
267 $fielddata = htmlspecialchars($row->afsv_value,ENT_QUOTES);
268 }
269 $data[$row->afsv_sub_id]['_field_'.$row->afsv_field_id] = $fielddata;
270 }
271
272 $this->items = $data;
273
274 $this->set_pagination_args( array(
275 'total_items' => $total_items,
276 'per_page' => $per_page,
277 'total_pages' => ceil($total_items/$per_page)
278 ) );
279
280
281 }
282
283 function process_bulk_action() {
284 if('delete'=== $this->current_action()) {
285 $trashed = array();
286 if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
287 foreach($_GET['submission'] as $i) {
288 $i = (int) $i;
289 $trashed[$i] = $i;
290 }
291 }
292 if ($trashed) {
293 $trashed = implode(',',$trashed);
294 global $wpdb;
295 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
296 if ($res === false) {
297 $this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'<br />');
298 } else if ($res == 1) {
299 $this->set_message(__("Moved 1 submission to trash.", 'accua-form-api').'<br />');
300 } else {
301 $this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'<br />');
302 }
303 } else {
304 $this->set_message(__("No submission selected.", 'accua-form-api').'<br />');
305 }
306 } else if('restore'=== $this->current_action()) {
307 $restored = array();
308 if ((!empty($_GET['submission'])) && is_array($_GET['submission'])) {
309 foreach($_GET['submission'] as $i) {
310 $i = (int) $i;
311 $restored[$i] = $i;
312 }
313 }
314 if ($restored) {
315 $restored = implode(',',$restored);
316 global $wpdb;
317 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = 0 WHERE afs_id in ( $restored )");
318 if ($res === false) {
319 $this->set_message(__("Error restoring submissions.", 'accua-form-api').'<br />');
320 } else if ($res == 1) {
321 $this->set_message(__("Restored 1 submission.", 'accua-form-api').'<br />');
322 } else {
323 $this->set_message(strtr(__("Restored %res submissions.", 'accua-form-api'), array('%res' => $res)).'<br />');
324 }
325 } else {
326 $this->set_message(__("No submission selected.", 'accua-form-api').'<br />');
327 }
328 }
329 }
330 }
331
332 function accua_forms_submissions_list_page($head = false){
333 static $listTable = null;
334
335 global $wpdb;
336 if ($listTable === null) {
337 if (isset($_POST['action'])) {
338 if ($_POST['action'] === 'trash' && !empty($_POST['submission']) && is_array($_POST['submission'])) {
339 echo "yes";
340 $trashed = array();
341 foreach($_POST['submission'] as $i) {
342 $i = (int) $i;
343 $trashed[$i] = $i;
344 }
345 $trashed=implode(',',$trashed);
346
347 $res = $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id in ( $trashed )");
348 if ($res === false) {
349 $this->set_message(__("Error moving submissions to trash.", 'accua-form-api').'<br />');
350 } else {
351 $this->set_message(strtr(__("Moved %res submissions to trash.", 'accua-form-api'), array('%res' => $res)).'<br />');
352 }
353 }
354 }
355
356 /*
357 wp_enqueue_script('jquery-ui-mouse');
358 wp_enqueue_script('jquery-ui-widget');
359 */
360
361 wp_enqueue_script('jquery');
362 wp_enqueue_script('jquery-ui-core');
363 wp_enqueue_script('jquery-ui-sortable');
364
365 $listTable = new Accua_Forms_Submissions_List_Table();
366 $listTable->process_bulk_action();
367 $listTable->prepare_items();
368 }
369
370 if ($head === true) {
371 return;
372 }
373 ?>
374 <style>
375 .tablenav.bottom {
376 float: left;
377 width: 100%;
378 }
379
380 .accua_tablenav {
381 float: left;
382 }
383
384 .esportazione {
385 margin-left:10px;
386 }
387
388 .esportazione a {
389 cursor: pointer;
390 line-height: 28px;
391 text-decoration: underline;
392 }
393 .tablenav.top {
394 clear: none;
395 float: left;
396 width: 100%;
397 }
398 </style>
399 <div id="accua_forms_submissions_list_page" class="accua_forms_admin_page wrap">
400
401 <div id="icon-users" class="icon32"><br/></div>
402
403 <h2 style="margin-bottom: 20px;" ><?php _e("Forms Submissions", 'accua-form-api'); ?></h2>
404
405 <?php $filter_form = $filter_post = $filter_search = Null ;
406 $filter = '';
407 if(isset($_GET['_wp_http_referer'])) {
408 foreach (explode('&', $_GET['_wp_http_referer']) as $coppia) {
409 $param = explode("=", $coppia);
410
411 if($param[0]=='fid' && $param[1]!='-1') { $filter_form =$param[1]; }
412 if($param[0]=='pid' && $param[1]!='-1') { $filter_post =$param[1]; }
413 if($param[0]=='s' && $param[1]!='-1') { $filter_search =$param[1]; $filter.= "&amp;s=".$filter_search; ?>
414 <script type="text/javascript">
415 <!--
416 jQuery(document).ready(function($) {
417 jQuery('#search_id-search-input').val(<?php echo json_encode($filter_search); ?>);
418 });
419 //-->
420 </script>
421 <?php
422 }
423 }
424 }
425
426 if(isset($_GET['fid']) && ($_GET['fid'])!=-1) {
427 $filter_form = $_GET['fid'];
428 }
429 if(isset($_GET['pid']) && ($_GET['pid']!=-1)) {
430 $filter_post = $_GET['pid'];
431 }
432 if(isset($_GET['s']) && ($_GET['s']!=-1)) {
433 $filter_search = $_GET['s'];
434 $filter.= "&amp;s=".$filter_search;
435 }
436
437 $del = isset($_GET['del']) && ($_GET['del']==1);
438
439 ?>
440
441 <?php if($listTable->get_message()!=NULL) { ?>
442 <div class="updated"><p><?php echo $listTable->get_message(); ?></p></div>
443 <?php } ?>
444
445 <ul class="subsubsub">
446 <li>
447 <a <?php if (!$del) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_submissions_list">
448 <?php _e("Active", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_active_items(); ?>) |
449 </li>
450 <li>
451 <a <?php if ($del) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_submissions_list&del=1">
452 <?php _e("Trash", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_del_items(); ?>)
453 </li>
454 </ul>
455
456 <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>
457 <form style="margin-top: 20px;" id="submissions-action" method="get" action="">
458 <!-- For plugins, we also need to ensure that the form posts back to our current page -->
459 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
460 <input type="hidden" name="del" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['del'])); ?>" />
461 <!-- SEARCH FORM -->
462 <?php $listTable->search_box(__("Search", 'accua-form-api'), 'search_id'); ?>
463 <!-- FINE SEARCH FORM -->
464 <!-- FILTRI -->
465 <div class="accua_tablenav">
466 <?php
467 //tutti i form salvati e non
468
469 $saved_forms_id = array();
470 $forms_data = get_option('accua_forms_saved_forms', array());
471 foreach($forms_data as $single_form_key=>$single_form){
472 $saved_forms_id[]= "'".$wpdb->escape($single_form_key)."'";
473 }
474 $saved_forms_id_string = implode(',',$saved_forms_id);
475
476 $id_del_other_forms = $wpdb->get_results("SELECT distinct afs_form_id
477 FROM {$wpdb->prefix}accua_forms_submissions WHERE afs_form_id NOT IN ($saved_forms_id_string) AND afs_status >= 0", ARRAY_A);
478
479
480 //post submissions
481 $id_posts = $wpdb->get_results("SELECT distinct afs_post_id
482 FROM {$wpdb->prefix}accua_forms_submissions WHERE afs_post_id <> 0 AND afs_status >= 0 ", ARRAY_A);
483
484
485 ?>
486
487 <span><label><?php _e("Page: ", 'accua-form-api'); ?></label><select name='pid' id='pid'>
488 <option value="-1" selected ><?php _e("Show all pages", 'accua-form-api'); ?></option>
489 <?php foreach($id_posts as $id_post){
490 echo "<option value='".$id_post['afs_post_id']."'";
491 if($filter_post==$id_post['afs_post_id']) {
492 echo " selected ";
493 $filter.= "&amp;pid=".$filter_post;
494 }
495 echo ">".get_the_title($id_post['afs_post_id'])."</option>";
496 } ?>
497 </select></span>
498 <span style="margin-left: 10px;"><label><?php _e("Forms: ", 'accua-form-api'); ?></label><select name='fid' id='fid'>
499 <option value="-1" selected > <?php _e("Show all forms", 'accua-form-api'); ?> </option>
500 <?php foreach($forms_data as $single_form_key=>$single_form){
501 echo "<option value='".$single_form_key."'";
502 if($filter_form==$single_form_key) {
503 echo " selected ";
504 $filter.= "&amp;fid=".$filter_form;
505 }
506 echo ">";
507 if($single_form['title']!=NULL)
508 echo $single_form['title']; //TITOLO
509 else
510 echo $single_form_key; //ID
511 echo "</option>";
512 }
513 ///no saved forms///
514 foreach($id_del_other_forms as $id_del_other_form) {
515 echo "<option value='".$id_del_other_form['afs_form_id']."'";
516 if($filter_form==$id_del_other_form['afs_form_id']) {
517 echo " selected ";
518 $filter.= "&amp;fid=".$filter_form;
519 }
520 echo $id_del_other_form['afs_form_id']." (del) </option>";
521 }
522
523 ?>
524 </select>
525 </span><span>
526 <input type="submit" value="<?php _e("Filter", 'accua-form-api'); ?>" class="button-secondary action" name=""></span>
527 </form>
528 </div>
529 <!-- FINE FILTRI -->
530 <script type="text/javascript">
531 <!--
532 function set_parameter(sel_column) {
533 var stringa ='';
534 var name_action = ajaxurl + "?action=accua_forms_submission_page_save_excel<?php if ($del) {echo '&del=1';} ?>";
535 if(sel_column) {
536 jQuery('#adv-settings input[type=checkbox]:checked').each(function() {
537 stringa += jQuery(this).attr("id").replace("-hide","") + "%2C";
538 });
539 }
540 else {
541 jQuery('#adv-settings input[type=checkbox]').each(function() {
542 stringa += jQuery(this).attr("id").replace("-hide","") + "%2C";
543 });
544 }
545 var search = jQuery("#search_id-search-input").val();
546 var pid = jQuery("select#pid").val();
547 var fid = jQuery("select#fid").val();
548 if (search) name_action+='&s='+search;
549 if (pid) name_action+='&pid='+pid;
550 if (fid) name_action+='&fid='+fid;
551 if(stringa) name_action+= '&accua_show_field='+stringa;
552
553 if(sel_column) { jQuery('#esporta_link_visible_column').attr("href",name_action); }
554 else jQuery('#esporta_link_all_column').attr("href",name_action);
555
556 }
557 //-->
558 </script>
559 <!-- ESPORTAZIONE -->
560
561 <div class="accua_tablenav esportazione wp-core-ui ">
562 <a onclick ="set_parameter(1);" id="esporta_link_visible_column" class="button-primary"><?php _e("Export visible columns to Excel", 'accua-form-api'); ?></a>
563 <a onclick ="set_parameter(0);" id="esporta_link_all_column" class="button-primary"><?php _e("Export all columns to Excel", 'accua-form-api'); ?></a>
564 </div>
565
566 <!-- FINE ESPORTAZIONE -->
567 <form style="margin-top: 20px;" id="submissions-action" method="get" action="">
568 <!-- Now we can render the completed list table -->
569 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
570 <input type="hidden" name="del" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['del'])); ?>" />
571 <?php $listTable->display(); ?>
572 </form>
573 <?php /* <pre>$listTable = <?php echo htmlspecialchars(print_r($listTable, true)); ?></pre> */ ?>
574 </div>
575
576 <?php
577
578 }
579
580
581
582
583