PluginProbe
Contact Forms by Cimatti / 1.2
Contact Forms by Cimatti v1.2
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.2, at accua-forms-list-page.php

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