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

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