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

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

338 lines 11.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_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'],
47 /*$2%s*/ $item['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 'shortcode' => __('Shortcode', 'accua-form-api'),
95 'phpcode' => __('PHP code', 'accua-form-api'),
96 'adminemail' => __('Admin Email', 'accua-form-api'),
97 'submissions' => __('Submissions', 'accua-form-api'),
98 );
99 return $columns;
100 }
101
102 function get_sortable_columns() {
103 return array(
104 'title' => array('title', false),
105 'ID' => array('ID', false),
106 'submissions' => array('submissions', false),
107 );
108 }
109
110 function get_bulk_actions() {
111 if(isset($_GET['del']) && $_GET['del']==1) {
112 $actions = array();
113 } else {
114 $actions = array(
115 'delete' => __('Move to trash', 'accua-form-api')
116 );
117 }
118 return $actions;
119 }
120
121 function set_message($single_message) {
122 $this->message=$single_message;
123 }
124
125 function get_message() {
126 if($this->message!=NULL)
127 return $this->message;
128 else
129 return NULL;
130 }
131
132 function accua_usort_numeric( $a, $b ) {
133 $result = ((int)$a[$this->accua_orderby]) - ((int)$b[$this->accua_orderby]);
134 if (!$result) {
135 $result = ((int)$a['ID']) - ((int)$b['ID']);
136 }
137 return ( $this->accua_order_asc ) ? $result : -$result;
138 }
139
140 function accua_usort_string( $a, $b ) {
141 $result = strcasecmp($a[$this->accua_orderby], $b[$this->accua_orderby]);
142 if (!$result) {
143 $result = ((int)$a['ID']) - ((int)$b['ID']);
144 }
145 return ( $this->accua_order_asc ) ? $result : -$result;
146 }
147
148 function process_bulk_action() {
149
150 $forms= $_GET['form'];
151 if('delete'===$this->current_action() ) {
152 $forms_deleted = false;
153 $forms_data = get_option('accua_forms_saved_forms', array());
154 $trash_data = get_option('accua_forms_trash_forms', array());
155
156 foreach($forms as $single_form) {
157 if(isset($forms_data[$single_form])) {
158 $trash_data[$single_form] = $forms_data[$single_form];
159 unset($forms_data[$single_form]);
160 $forms_deleted = true;
161 ?>
162 <script type="text/javascript">
163 jQuery(function($){
164 jQuery("#the-list tr:has(th.check-column input[type='checkbox'][value='<?php echo $single_form; ?>'])").fadeOut();
165 });
166 </script>
167 <?php
168 }
169 }
170 if ($forms_deleted) {
171 update_option('accua_forms_trash_forms', $trash_data);
172 update_option('accua_forms_saved_forms', $forms_data);
173 $this->set_message(__("Forms deleted", 'accua-form-api'));
174 }
175
176 }
177
178 }
179
180 function prepare_items() {
181 global $wpdb, $hook_suffix;
182 $per_page = 50;
183 $del = isset($_GET['del']) && $_GET['del']==1;
184
185 $columns = $this->get_columns();
186 $hidden = get_hidden_columns($hook_suffix);
187 $sortable = $this->get_sortable_columns();
188
189
190 $this->_column_headers = array($columns, $hidden, $sortable);
191
192 $current_page = $this->get_pagenum();
193
194 $limit = ($current_page - 1) * $per_page;
195
196 $forms_data = get_option('accua_forms_saved_forms', array());
197 $forms_trash = get_option('accua_forms_trash_forms', array());
198 $forms_default = get_option('accua_forms_default_form_data',array());
199
200 $this->active_items = count($forms_data);
201 $this->del_items = count($forms_trash);
202
203 $data = array();
204
205 if ($del) {
206 $start = $forms_trash;
207 } else {
208 $start = $forms_data;
209 }
210
211 foreach ($start as $id => $form) {
212 if (isset($form['title']) && (trim($form['title']) !== '')) {
213 $title = $form['title'];
214 } else {
215 $title = __('(no title)','accua-form-api');
216 }
217
218 if (isset($form['admin_emails_to'])) {
219 $adminemail = $form['admin_emails_to'];
220 } else {
221 $adminemail = $forms_default['admin_emails_to'] . " (default)";
222 }
223
224 $data[$id] = array (
225 'ID' => $id,
226 'title' => $title,
227 'submissions' => 0,
228 'shortcode'=> $del?'':'[accua-form fid="'.$id.'"]',
229 'phpcode'=> $del?'':"<?php accua_forms_include('$id'); ?>",
230 'adminemail' => $adminemail,
231 'deleted' => $del,
232 );
233 }
234
235 $query = "SELECT afs_form_id AS fid, count(*) AS submissions
236 FROM `{$wpdb->prefix}accua_forms_submissions`
237 WHERE afs_status >= 0
238 GROUP BY afs_form_id";
239
240 $submissions = $wpdb->get_results($query, OBJECT);
241 foreach ($submissions as $fsub) {
242 if (isset($data[$fsub->fid])) {
243 $data[$fsub->fid]['submissions'] = $fsub->submissions;
244 } else if ($del){
245 if (!isset($forms_data[$fsub->fid])) {
246 $data[$fsub->fid] = array(
247 'ID' => $fsub->fid,
248 'submissions' => $fsub->submissions,
249 'deleted' => true,
250 'shortcode' => '',
251 'phpcode' => '',
252 'adminemail' => '',
253 );
254 $this->del_items++;
255 }
256 } else if (!isset($forms_trash[$fsub->fid])) {
257 $this->del_items++;
258 }
259 }
260
261 $this->accua_order_asc = empty($_GET['order']) || ($_GET['order'] != 'desc');
262 $this->accua_orderby = (isset($_GET['orderby'])) ? $_GET['orderby'] : 'title';
263 switch($this->accua_orderby) {
264 case 'ID':
265 case 'submissions':
266 $this->accua_orderby = $_GET['orderby'];
267 usort( $data, array( &$this, 'accua_usort_numeric' ) );
268 break;
269 //case 'title':
270 default:
271 $this->accua_orderby = 'title';
272 usort( $data, array( &$this, 'accua_usort_string' ) );
273 }
274
275 $total_items = count($data);
276
277 $this->items = array_slice($data,$limit,$per_page);
278
279 $this->set_pagination_args( array(
280 'total_items' => $total_items,
281 'per_page' => $per_page,
282 'total_pages' => ceil($total_items/$per_page)
283 ) );
284
285 }
286
287 }
288
289 function accua_forms_list_page_table($head = false){
290
291 static $listTable = null;
292
293 if(isset($_GET['fid_del']))
294 {
295 $fid = $_GET['fid_del'];
296 $forms_data = get_option('accua_forms_saved_forms', array());
297 if (isset($forms_data[$fid])) {
298 $trash_data = get_option('accua_forms_trash_forms', array());
299 $trash_data[$fid] = $forms_data[$fid];
300 update_option('accua_forms_trash_forms', $trash_data);
301 unset($forms_data[$fid]);
302 update_option('accua_forms_saved_forms', $forms_data);
303 }
304 }
305
306
307 if ($listTable === null) {
308 $listTable = new Accua_Forms_List_Table();
309 $listTable->process_bulk_action();
310 $listTable->prepare_items();
311 }
312
313 if ($head === true) {
314 return;
315 }
316
317 if($listTable->get_message()!=NULL) { ?>
318 <div class="updated"><p><?php echo $listTable->get_message(); ?></p></div>
319 <?php } ?>
320 <ul class="subsubsub">
321 <li>
322 <a <?php if (!isset($_GET['del']) || ($_GET['del']!=1)) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_list">
323 <?php _e("Active", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_active_items(); ?>) |
324 </li>
325 <li>
326 <a <?php if (isset($_GET['del']) && ($_GET['del']==1)) { echo " class='current' "; } ?> href="admin.php?page=accua_forms_list&del=1">
327 <?php _e("Trash", 'accua-form-api'); ?></a> (<?php echo $listTable->get_num_of_del_items(); ?>)
328 </li>
329 </ul>
330
331 <form id="accua-forms-list-filter" method="get">
332 <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" />
333 <?php $listTable->display(); ?>
334 </form>
335 <?php /* echo '<pre>$listTable = ' htmlspecialchars(print_r($listTable, true)); ?></pre> */ ?>
336 <?php
337 }
338