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-list-page.php

accua-forms-list-page.php in Contact Forms by Cimatti 1.0, at accua-forms-list-page.php

321 lines 10.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_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' => 'form',
17 'plural' => 'forms',
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 } else {
34 return '';
35 }
36 }
37
38 /*
39 function column_title($item){
40 return "<a href='admin.php?page=accua_forms_list&amp;fid=".$item['ID']."'>".$item['title']."</a>";
41 }*/
42
43 function column_cb($item){
44 return sprintf(
45 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
46 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
47 /*$2%s*/ $item['ID'] //The value of the checkbox should be the record's id
48 );
49 }
50
51 function column_title($item){
52 if ($item['deleted']) {
53 if (isset($item['title'])) {
54 $item_name = $item['title'];
55 } else {
56 $item_name = $item['ID'];
57 }
58 $actions = array(
59 'edit' => "<a href='admin.php?page=accua_forms_list&amp;fid={$item['ID']}&amp;restore=1'>".__("Restore", 'accua-form-api')."</a>",
60 );
61 return "<strong>".$item_name."</strong>".$this->row_actions($actions);
62 } else {
63 $item_name = '"'.$item['ID'].'"';
64 $actions = array(
65 'edit' => "<a href='admin.php?page=accua_forms_list&amp;fid={$item['ID']}'>".__("Edit", 'accua-form-api')."</a>"
66 . " &middot; <a href='admin.php?page=accua_forms_add&amp;clonefrom={$item['ID']}'>".__("Clone", 'accua-form-api')."</a>"
67 . " &middot; <a href='admin.php?page=accua_forms_submissions_list&amp;fid={$item['ID']}'>".__("Report", 'accua-form-api')."</a>"
68 . " &middot; <a href='admin.php?page=accua_forms_list&amp;fid_del={$item['ID']}'>".__("Trash", 'accua-form-api')."</a>",
69 );
70 return "<strong><a class='row-title' href='admin.php?page=accua_forms_list&amp;fid=".$item['ID']."'>".$item['title']."</a></strong>".$this->row_actions($actions);
71 }
72 }
73
74
75
76
77 function column_submissions($item){
78 if($item['submissions']!=0)
79 return sprintf(
80 '<a href="admin.php?page=accua_forms_submissions_list&amp;fid=%1$s">%2$s</a>',
81 /*$1%s*/ $item['ID'],
82 /*$2%s*/ $item['submissions']
83 );
84 else
85 return "0";
86 }
87
88
89 function get_columns(){
90 $columns = array(
91 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
92 'title' => __('Title', 'accua-form-api'),
93 'ID' => 'ID',
94 'basic-shortcode' => __('Basic Shortcode', 'accua-form-api'),
95 'submissions' => __('Submissions', 'accua-form-api'),
96 );
97 return $columns;
98 }
99
100 function get_sortable_columns() {
101 return array(
102 'title' => array('title', false),
103 'ID' => array('ID', false),
104 'submissions' => array('submissions', false),
105 );
106 }
107
108 function get_bulk_actions() {
109 $actions = array(
110 'delete' => 'Delete'
111 );
112 return $actions;
113 }
114
115 function set_message($single_message) {
116 $this->message=$single_message;
117 }
118
119 function get_message() {
120 if($this->message!=NULL)
121 return $this->message;
122 else
123 return NULL;
124 }
125
126 function accua_usort_numeric( $a, $b ) {
127 $result = ((int)$a[$this->accua_orderby]) - ((int)$b[$this->accua_orderby]);
128 if (!$result) {
129 $result = ((int)$a['ID']) - ((int)$b['ID']);
130 }
131 return ( $this->accua_order_asc ) ? $result : -$result;
132 }
133
134 function accua_usort_string( $a, $b ) {
135 $result = strcasecmp($a[$this->accua_orderby], $b[$this->accua_orderby]);
136 if (!$result) {
137 $result = ((int)$a['ID']) - ((int)$b['ID']);
138 }
139 return ( $this->accua_order_asc ) ? $result : -$result;
140 }
141
142 function process_bulk_action() {
143
144 $forms= $_GET['form'];
145 if('delete'===$this->current_action() ) {
146 $forms_deleted = false;
147 $forms_data = get_option('accua_forms_saved_forms', array());
148 $trash_data = get_option('accua_forms_trash_forms', array());
149
150 foreach($forms as $single_form) {
151 if(isset($forms_data[$single_form])) {
152 $trash_data[$single_form] = $forms_data[$single_form];
153 unset($forms_data[$single_form]);
154 $forms_deleted = true;
155 ?>
156 <script type="text/javascript">
157 jQuery(function($){
158 jQuery("#the-list tr:has(th.check-column input[type='checkbox'][value='<?php echo $single_form; ?>'])").fadeOut();
159 });
160 </script>
161 <?php
162 }
163 }
164 if ($forms_deleted) {
165 update_option('accua_forms_trash_forms', $trash_data);
166 update_option('accua_forms_saved_forms', $forms_data);
167 $this->set_message("Form cancellati");
168 }
169
170 }
171
172 }
173
174 function prepare_items() {
175 global $wpdb, $hook_suffix;
176 $per_page = 50;
177 $del = false;
178 if(isset($_GET['del']) && $_GET['del']==1)
179 $del = true;
180
181 $columns = $this->get_columns();
182 $hidden = get_hidden_columns($hook_suffix);
183 $sortable = $this->get_sortable_columns();
184
185
186 $this->_column_headers = array($columns, $hidden, $sortable);
187
188 $current_page = $this->get_pagenum();
189
190 $limit = ($current_page - 1) * $per_page;
191
192 $forms_data = get_option('accua_forms_saved_forms', array());
193 $forms_trash = get_option('accua_forms_trash_forms', array());
194
195 $this->active_items = count($forms_data);
196 $this->del_items = count($forms_data);
197
198 $data = array();
199
200 if ($del) {
201 $start = $forms_trash;
202 } else {
203 $start = $forms_data;
204 }
205
206 foreach ($start as $id => $form) {
207 if (isset($form['title']) && (trim($form['title']) !== '')) {
208 $title = $form['title'];
209 } else {
210 $title = __('(no title)','accua-form-api');
211 }
212
213 $data[$id] = array (
214 'ID' => $id,
215 'title' => $title,
216 'submissions' => 0,
217 'basic-shortcode'=> '[accua-form fid="'.$id.'"]',
218 'deleted' => $del,
219 );
220 }
221
222 $query = "SELECT afs_form_id AS fid, count(*) AS submissions
223 FROM `{$wpdb->prefix}accua_forms_submissions`
224 WHERE afs_status <> -1
225 GROUP BY afs_form_id";
226
227 $submissions = $wpdb->get_results($query, OBJECT);
228 foreach ($submissions as $fsub) {
229 if (isset($data[$fsub->fid])) {
230 $data[$fsub->fid]['submissions'] = $fsub->submissions;
231 } else if ($del){
232 $data[$fsub->fid] = array(
233 'ID' => $fsub->fid,
234 'submissions' => $fsub->submissions,
235 'deleted' => true,
236 'basic-shortcode'=> '[accua-form fid="'.$fsub->fid.'"]',
237 );
238 $this->del_items++;
239 } else if (!isset($forms_data[$fsub->fid])) {
240 $this->del_items++;
241 }
242 }
243
244 $this->accua_order_asc = empty($_GET['order']) || ($_GET['order'] != 'desc');
245 $this->accua_orderby = (isset($_GET['orderby'])) ? $_GET['orderby'] : 'title';
246 switch($this->accua_orderby) {
247 case 'ID':
248 case 'submissions':
249 $this->accua_orderby = $_GET['orderby'];
250 usort( $data, array( &$this, 'accua_usort_numeric' ) );
251 break;
252 //case 'title':
253 default:
254 $this->accua_orderby = 'title';
255 usort( $data, array( &$this, 'accua_usort_string' ) );
256 }
257
258 $total_items = count($data);
259
260 $this->items = array_slice($data,$limit,$per_page);
261
262 $this->set_pagination_args( array(
263 'total_items' => $total_items,
264 'per_page' => $per_page,
265 'total_pages' => ceil($total_items/$per_page)
266 ) );
267
268 }
269
270 }
271
272 function accua_forms_list_page_table($head = false){
273
274 static $listTable = null;
275
276 if(isset($_GET['fid_del']))
277 {
278 $fid = $_GET['fid_del'];
279 $forms_data = get_option('accua_forms_saved_forms', array());
280 if (isset($forms_data[$fid])) {
281 $trash_data = get_option('accua_forms_trash_forms', array());
282 $trash_data[$fid] = $forms_data[$fid];
283 update_option('accua_forms_trash_forms', $trash_data);
284 unset($forms_data[$fid]);
285 update_option('accua_forms_saved_forms', $forms_data);
286 }
287 }
288
289
290 if ($listTable === null) {
291 $listTable = new Accua_Forms_List_Table();
292 $listTable->process_bulk_action();
293 $listTable->prepare_items();
294 }
295
296 if ($head === true) {
297 return;
298 }
299
300 if($listTable->get_message()!=NULL) { ?>
301 <div class="updated"><p><?php echo $listTable->get_message(); ?></p></div>
302 <?php } ?>
303 <ul class="subsubsub">
304 <li>
305 <a <?php if (!isset($_GET['del']) || ($_GET['del']!=1)) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_list">
306 <?php _e("Active", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_active_items(); ?>) |
307 </li>
308 <li>
309 <a <?php if (isset($_GET['del']) && ($_GET['del']==1)) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_list&del=1">
310 <?php _e("Trash", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_del_items(); ?>)
311 </li>
312 </ul>
313
314 <form id="accua-forms-list-filter" method="get">
315 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
316 <?php $listTable->display(); ?>
317 </form>
318 <?php /* echo '<pre>$listTable = ' htmlspecialchars(print_r($listTable, true)); ?></pre> */ ?>
319 <?php
320 }
321