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