PluginProbe
Survey Maker by AYS / 5.2.3.7
Survey Maker by AYS v5.2.3.7
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / includes / lists / class-survey-maker-popup-survey-list-table.php

class-survey-maker-popup-survey-list-table.php in Survey Maker by AYS 5.2.3.7, at includes/lists/class-survey-maker-popup-survey-list-table.php

1,126 lines 52.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ob_start();
3 class Popup_Survey_List_Table extends WP_List_Table {
4
5 /**
6 * The ID of this plugin.
7 *
8 * @since 1.0.0
9 * @access private
10 * @var string $plugin_name The ID of this plugin.
11 */
12 private $plugin_name;
13
14 /**
15 * The table name in database of the survey categories.
16 *
17 * @since 1.0.0
18 * @access private
19 * @var string $table_name The table name in database of the survey categories.
20 */
21 private $table_name;
22
23 private $title_length;
24
25 /** Class constructor */
26 public function __construct( $plugin_name ) {
27 global $wpdb;
28
29 $this->plugin_name = $plugin_name;
30
31 $this->table_name = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys";
32
33 $this->title_length = Survey_Maker_Data::get_listtables_title_length('popup_surveys');
34
35 parent::__construct( array(
36 'singular' => __( 'Popup Survey', "survey-maker" ), //singular name of the listed records
37 'plural' => __( 'Popup Surveys', "survey-maker" ), //plural name of the listed records
38 'ajax' => false //does this table support ajax?
39 ) );
40
41 add_action( 'admin_notices', array( $this, 'popup_survey_notices' ) );
42 }
43
44 /**
45 * Override of table nav to avoid breaking with bulk actions & according nonce field
46 */
47 public function display_tablenav( $which ) {
48 ?>
49 <div class="tablenav <?php echo esc_attr( $which ); ?>">
50
51 <div class="alignleft actions">
52 <?php $this->bulk_actions( $which ); ?>
53 </div>
54 <?php
55 $this->pagination( $which );
56 ?>
57 <br class="clear" />
58 </div>
59 <?php
60 }
61
62 protected function get_views() {
63 $published_count = $this->get_statused_record_count( 'published' );
64 $draft_count = $this->get_statused_record_count( 'draft' );
65 $trashed_count = $this->get_statused_record_count( 'trashed' );
66 $all_count = $this->all_record_count();
67 $selected_all = "";
68 $selected_published = "";
69 $selected_draft = "";
70 $selected_trashed = "";
71 if( isset( $_GET['fstatus'] ) ){
72 switch( sanitize_text_field( $_GET['fstatus'] ) ){
73 case "published":
74 $selected_published = " style='font-weight:bold;' ";
75 break;
76 case "draft":
77 $selected_draft = " style='font-weight:bold;' ";
78 break;
79 case "trashed":
80 $selected_trashed = " style='font-weight:bold;' ";
81 break;
82 default:
83 $selected_all = " style='font-weight:bold;' ";
84 break;
85 }
86 }else{
87 $selected_all = " style='font-weight:bold;' ";
88 }
89 $status_links = array(
90 "all" => "<a ".$selected_all." href='?page=".esc_attr( $_REQUEST['page'] )."'>" . __( "All", "survey-maker" ) . " (".$all_count.")</a>",
91 );
92 if( intval( $published_count ) > 0 ){
93 $status_links["published"] = "<a ".$selected_published." href='?page=".esc_attr( $_REQUEST['page'] )."&fstatus=published'>" . __( "Published", "survey-maker" ) . " (".$published_count.")</a>";
94 }
95 if( intval( $draft_count ) > 0 ){
96 $status_links["draft"] = "<a ".$selected_draft." href='?page=".esc_attr( $_REQUEST['page'] )."&fstatus=draft'>" . __( "Draft", "survey-maker" ) . " (".$draft_count.")</a>";
97 }
98 if( intval( $trashed_count ) > 0 ){
99 $status_links["trashed"] = "<a ".$selected_trashed." href='?page=".esc_attr( $_REQUEST['page'] )."&fstatus=trashed'>" . __( "Trash", "survey-maker" ) . " (".$trashed_count.")</a>";
100 }
101 return $status_links;
102 }
103
104
105 /**
106 * Retrieve customers data from the database
107 *
108 * @param int $per_page
109 * @param int $page_number
110 *
111 * @return mixed
112 */
113 public static function get_items( $per_page = 20, $page_number = 1 ) {
114
115 global $wpdb;
116
117 $sql = "SELECT * FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys";
118
119 $where = array();
120
121 if ( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != ''){
122 $where[] = ' status = "' . esc_sql( sanitize_text_field( $_GET['fstatus'] ) ) . '" ';
123 }else{
124 $where[] = ' status != "trashed" ';
125 }
126
127 // if( $search != '' ){
128 // $where[] = $search;
129 // }
130
131 // if( ! Survey_Maker_Data::survey_maker_capabilities_for_editing() ){
132 $current_user = get_current_user_id();
133 $where[] = " author_id = ".$current_user." ";
134 // }
135
136 if ( ! empty( $where ) ){
137 $sql .= ' WHERE ' . implode( ' AND ', $where );
138 }
139
140 if ( ! empty( $_REQUEST['orderby'] ) ) {
141 $order_by = ( isset( $_REQUEST['orderby'] ) && sanitize_text_field( $_REQUEST['orderby'] ) != '' ) ? sanitize_text_field( $_REQUEST['orderby'] ) : 'id';
142 $order_by .= ( ! empty( $_REQUEST['order'] ) && strtolower( $_REQUEST['order'] ) == 'asc' ) ? ' ASC' : ' DESC';
143
144 $sql_orderby = sanitize_sql_orderby( $order_by );
145
146 if ( $sql_orderby ) {
147 $sql .= ' ORDER BY ' . $sql_orderby;
148 } else {
149 $sql .= ' ORDER BY ordering DESC';
150 }
151 }else{
152 $sql .= ' ORDER BY id DESC';
153 }
154
155 $sql .= " LIMIT $per_page";
156 $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
157
158 $result = $wpdb->get_results( $sql, 'ARRAY_A' );
159 return $result;
160 }
161
162 public static function get_item_by_id( $id ) {
163 global $wpdb;
164
165 $sql = "SELECT * FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys WHERE id=" . esc_sql( intval( $id ) );
166
167 $result = $wpdb->get_row( $sql, 'ARRAY_A' );
168
169
170
171 return $result;
172 }
173
174 public function get_surveys(){
175 global $wpdb;
176
177 $sql = "SELECT * FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys WHERE status='published' ORDER BY id DESC";
178
179 $result = $wpdb->get_results($sql, 'ARRAY_A');
180
181 return $result;
182 }
183
184 public function add_or_edit_item(){
185 global $wpdb;
186 $table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys";
187
188 if( isset( $_POST["popup_survey_action"] ) && wp_verify_nonce( $_POST["popup_survey_action"], 'popup_survey_action' ) ){
189
190 $name_prefix = 'ays_';
191
192 // Save type
193 $save_type = (isset($_POST['save_type'])) ? $_POST['save_type'] : '';
194
195 // Id of item
196 $id = isset( $_POST['id'] ) ? absint( intval( $_POST['id'] ) ) : 0;
197
198 // Title
199 $title = isset( $_POST[ $name_prefix . 'title' ] ) && $_POST[ $name_prefix . 'title' ] != '' ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'title' ] ) ) : 'Survey popup';
200
201 // Show popup title
202 $survey_popup_enable_show_title = isset( $_POST[ $name_prefix . 'survey_popup_enable_show_title' ] ) && $_POST[ $name_prefix . 'survey_popup_enable_show_title' ] == 'on' ? 'on' : 'off';
203
204 // Popup title font size
205 $survey_popup_title_font_size = isset( $_POST[ $name_prefix . 'survey_popup_title_font_size' ] ) && $_POST[ $name_prefix . 'survey_popup_title_font_size' ] != '' ? absint( sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_font_size' ] ) ) : 25;
206
207 // Popup title font size on mobile
208 $survey_popup_title_mobile_font_size = isset( $_POST[ $name_prefix . 'survey_popup_title_mobile_font_size' ] ) && $_POST[ $name_prefix . 'survey_popup_title_mobile_font_size' ] != '' ? absint( sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_mobile_font_size' ] ) ) : 25;
209
210 // Popup title bg color
211 $survey_popup_title_bg_color = (isset( $_POST[$name_prefix . 'survey_popup_title_bg_color'] ) && $_POST[$name_prefix . 'survey_popup_title_bg_color'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_bg_color' ] ) : '#00000000';
212 // Popup title bg color mobile
213 $survey_popup_title_bg_color_mobile = (isset( $_POST[$name_prefix . 'survey_popup_title_bg_color_mobile'] ) && $_POST[$name_prefix . 'survey_popup_title_bg_color_mobile'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_bg_color_mobile' ] ) : '#00000000';
214
215 // Popup title text color
216 $survey_popup_title_text_color = (isset( $_POST[$name_prefix . 'survey_popup_title_text_color'] ) && $_POST[$name_prefix . 'survey_popup_title_text_color'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_text_color' ] ) : '#ffffff';
217 // Popup title text color mobile
218 $survey_popup_title_text_color_mobile = (isset( $_POST[$name_prefix . 'survey_popup_title_text_color_mobile'] ) && $_POST[$name_prefix . 'survey_popup_title_text_color_mobile'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_text_color_mobile' ] ) : '#ffffff';
219
220 // Popup title alignment
221 $survey_popup_title_alignment = (isset( $_POST[$name_prefix . 'survey_popup_title_alignment'] ) && $_POST[$name_prefix . 'survey_popup_title_alignment'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_alignment' ] ) : 'left';
222
223 // Popup title alignment
224 $survey_popup_title_alignment_on_mobile = (isset( $_POST[$name_prefix . 'survey_popup_title_alignment_on_mobile'] ) && $_POST[$name_prefix . 'survey_popup_title_alignment_on_mobile'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_alignment_on_mobile' ] ) : 'left';
225
226 // Popup title transform
227 $survey_popup_title_transform = (isset( $_POST[$name_prefix . 'survey_popup_title_transform'] ) && $_POST[$name_prefix . 'survey_popup_title_transform'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_transform' ] ) : 'none';
228 // Popup title transform
229 $survey_popup_title_transform_mobile = (isset( $_POST[$name_prefix . 'survey_popup_title_transform_mobile'] ) && $_POST[$name_prefix . 'survey_popup_title_transform_mobile'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_transform_mobile' ] ) : 'none';
230
231 // Popup title letter spacing
232 $survey_popup_title_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_popup_title_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_popup_title_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_popup_title_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_letter_spacing' ] ))) : '0';
233
234 // Popup title letter spacing on mobile
235 $survey_popup_title_letter_spacing_on_mobile = (isset( $_POST[ $name_prefix . 'survey_popup_title_letter_spacing_on_mobile' ] ) && $_POST[ $name_prefix . 'survey_popup_title_letter_spacing_on_mobile' ] != '' && $_POST[ $name_prefix . 'survey_popup_title_letter_spacing_on_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_letter_spacing_on_mobile' ] ))) : '0';
236
237 // Hide popup title on mobile
238 $survey_popup_hide_title_on_mobile = (isset( $_POST[$name_prefix . 'survey_popup_hide_title_on_mobile'] ) && $_POST[$name_prefix . 'survey_popup_hide_title_on_mobile'] == 'on') ? 'on' : 'off';
239
240 // Title border radius
241 $survey_popup_title_border_radius = isset( $_POST[ $name_prefix . 'survey_popup_title_border_radius' ] ) && $_POST[ $name_prefix . 'survey_popup_title_border_radius' ] != '' ? absint( sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_border_radius' ] ) ) : 0;
242 // Title border radius mobile
243 $survey_popup_title_border_radius_mobile = isset( $_POST[ $name_prefix . 'survey_popup_title_border_radius_mobile' ] ) && $_POST[ $name_prefix . 'survey_popup_title_border_radius_mobile' ] != '' ? absint( sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_title_border_radius_mobile' ] ) ) : 0;
244
245 if($title == ''){
246 $url = esc_url_raw( remove_query_arg( false ) );
247 wp_redirect( $url );
248 }
249
250 // Author ID
251 $user_id = get_current_user_id();
252 $author_id = isset( $_POST[ $name_prefix . 'author_id' ] ) && $_POST[ $name_prefix . 'author_id' ] != '' ? intval( sanitize_text_field( $_POST[ $name_prefix . 'author_id' ] ) ) : $user_id;
253
254 // Status
255 $status = isset( $_POST[ $name_prefix . 'status' ] ) && $_POST[ $name_prefix . 'status' ] == 'on' ? 'published' : 'unpublished';
256
257 // Trash status
258 $trash_status = '';
259
260 // Date created
261 $date_created = isset( $_POST[ $name_prefix . 'date_created' ] ) && Survey_Maker_Admin::validateDate( $_POST[ $name_prefix . 'date_created' ] ) ? sanitize_text_field( $_POST[ $name_prefix . 'date_created' ] ) : current_time( 'mysql' );
262
263 // Date modified
264 $date_modified = isset( $_POST[ $name_prefix . 'date_modified' ] ) && Survey_Maker_Admin::validateDate( $_POST[ $name_prefix . 'date_modified' ] ) ? sanitize_text_field( $_POST[ $name_prefix . 'date_modified' ] ) : current_time( 'mysql' );
265
266 // Survey_id
267 $survey_id = isset( $_POST[ $name_prefix . 'survey_id' ] ) && $_POST[ $name_prefix . 'survey_id' ] != '' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_id' ] ) : '';
268
269 // Show All
270 $show_all = isset( $_POST[$name_prefix . 'survey_show_all'] ) && $_POST[$name_prefix . 'survey_show_all'] != '' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_show_all' ] ) : 'all';
271
272 // Width
273 $survey_width = (isset( $_POST[ $name_prefix . 'popup_survey_width' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_width' ] ) != '') ? absint( sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_width' ] ) ) : '';
274 // Width by percentage or pixels
275 $survey_width_by_percentage_px = (isset( $_POST[ $name_prefix . 'popup_survey_width_by_percentage_px' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_width_by_percentage_px' ] ) != '' && $survey_width != '') ? sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_width_by_percentage_px' ] ) : 'pixels';
276
277 // Mobile width
278 $survey_width_mobile = (isset( $_POST[ $name_prefix . 'popup_survey_width_mobile' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_width_mobile' ] ) != '') ? absint( sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_width_mobile' ] ) ) : '';
279 // Mobile width by percentage or pixels
280 $survey_width_mobile_by_percentage_px = (isset( $_POST[ $name_prefix . 'popup_survey_width_mobile_by_percentage_px' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_width_mobile_by_percentage_px' ] ) != '' && $survey_width_mobile != '') ? sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_width_mobile_by_percentage_px' ] ) : 'pixels';
281
282 // Height
283 $survey_heigth = (isset( $_POST[ $name_prefix . 'popup_survey_height' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_height' ] ) != '') ? absint( sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_height' ] ) ) : '';
284 // Height by percentage or pixels
285 $survey_heigth_by_percentage_px = (isset( $_POST[ $name_prefix . 'popup_survey_height_by_percentage_px' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_height_by_percentage_px' ] ) != '' && $survey_heigth != '') ? sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_height_by_percentage_px' ] ) : 'pixels';
286
287 // Height mobile
288 $survey_heigth_mobile = (isset( $_POST[ $name_prefix . 'popup_survey_height_mobile' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_height_mobile' ] ) != '') ? absint( sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_height_mobile' ] ) ) : '';
289 // Mobile height by percentage or pixels
290 $survey_heigth_mobile_by_percentage_px = (isset( $_POST[ $name_prefix . 'popup_survey_height_mobile_by_percentage_px' ] ) && trim( $_POST[ $name_prefix . 'popup_survey_height_mobile_by_percentage_px' ] ) != '' && $survey_heigth_mobile != '') ? sanitize_text_field( $_POST[ $name_prefix . 'popup_survey_height_mobile_by_percentage_px' ] ) : 'pixels';
291
292 // popup_position
293 $popup_position = (isset( $_POST[$name_prefix . 'survey_popup_position'] ) && $_POST[$name_prefix . 'survey_popup_position'] != 'center-center') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_position' ] ) : 'center-center';
294
295 // popup_margin
296 $popup_margin = (isset( $_POST[$name_prefix . 'survey_popup_margin'] ) && $_POST[$name_prefix . 'survey_popup_margin'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_margin' ] ) : '';
297
298 // //Popup trigger
299 $popup_trigger = (isset( $_POST[$name_prefix . 'survey_popup_trigger'] ) && $_POST[$name_prefix . 'survey_popup_trigger'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_trigger' ] ) : 'on_load';
300
301 // Popup close after finish
302 $survey_enable_popup_close_after_finish = isset( $_POST[ $name_prefix . 'survey_enable_popup_close_after_finish' ] ) && $_POST[ $name_prefix . 'survey_enable_popup_close_after_finish' ] == 'on' ? 'on' : 'off';
303 $survey_popup_close_after_finish_delay = (isset($_POST[ $name_prefix . 'survey_popup_close_after_finish_delay' ]) && $_POST[ $name_prefix . 'survey_popup_close_after_finish_delay' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_close_after_finish_delay' ] ) ) : '';
304
305 //Popup selector
306 $popup_selector = (isset( $_POST[$name_prefix . 'survey_popup_selector'] ) && $_POST[$name_prefix . 'survey_popup_selector'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_selector' ] ) : '';
307
308 // // Popup background color
309 $popup_bg_color = (isset( $_POST[$name_prefix . 'survey_popup_bg_color'] ) && $_POST[$name_prefix . 'survey_popup_bg_color'] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_bg_color' ] ) : '#ffffff';
310
311 // Popup background color | Mobile
312 $popup_bg_color_mobile = (isset( $_POST[$name_prefix . 'survey_popup_bg_color_mobile'] ) && $_POST[$name_prefix . 'survey_popup_bg_color_mobile'] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_popup_bg_color_mobile' ] ) ) : '#ffffff';
313
314 $hide_popup = isset( $_POST[ $name_prefix . 'survey_hide_popup' ] ) && $_POST[ $name_prefix . 'survey_hide_popup' ] == 'on' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_hide_popup' ] ) : 'off';
315
316 // Hide Popup after close
317 $hide_popup_after_close = isset( $_POST[ $name_prefix . 'survey_hide_popup_after_close' ] ) && $_POST[ $name_prefix . 'survey_hide_popup_after_close' ] == 'on' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_hide_popup_after_close' ] ) : 'off';
318
319 // Popup full screen mode
320 $survey_popup_full_screen = isset( $_POST[ $name_prefix . 'survey_enable_popup_full_screen_mode' ] ) && $_POST[ $name_prefix . 'survey_enable_popup_full_screen_mode' ] == 'on' ? 'on' : 'off';
321
322 // Close by pressing the ESC
323 $survey_popup_enable_close_by_esc = isset( $_POST[ $name_prefix . 'survey_popup_enable_close_by_esc' ] ) && $_POST[ $name_prefix . 'survey_popup_enable_close_by_esc' ] == 'on' ? 'on' : 'off';
324
325 // Hide Popup on mobile
326 $hide_popup_on_mobile = isset( $_POST[ $name_prefix . 'survey_hide_popup_on_mobile' ] ) && $_POST[ $name_prefix . 'survey_hide_popup_on_mobile' ] == 'on' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_hide_popup_on_mobile' ] ) : 'off';
327
328 // Hide Popup on PC
329 $hide_popup_on_pc = isset( $_POST[ $name_prefix . 'survey_hide_popup_on_pc' ] ) && $_POST[ $name_prefix . 'survey_hide_popup_on_pc' ] == 'on' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_hide_popup_on_pc' ] ) : 'off';
330
331 // Hide Popup on tablet
332 $hide_popup_on_tablet = isset( $_POST[ $name_prefix . 'survey_hide_popup_on_tablet' ] ) && $_POST[ $name_prefix . 'survey_hide_popup_on_tablet' ] == 'on' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_hide_popup_on_tablet' ] ) : 'off';
333
334 // Close by clicking outside the box
335 $close_popup_overlay_outside_click = isset( $_POST[ $name_prefix . 'survey_close_popup_overlay_outside_click' ] ) && $_POST[ $name_prefix . 'survey_close_popup_overlay_outside_click' ] == 'on' ? sanitize_text_field( $_POST[ $name_prefix . 'survey_close_popup_overlay_outside_click' ] ) : 'off';
336
337 // Options
338 $options = array(
339 "popup_enable_show_title" => $survey_popup_enable_show_title,
340 "popup_title_font_size" => $survey_popup_title_font_size,
341 "popup_title_mobile_font_size" => $survey_popup_title_mobile_font_size,
342 "popup_title_bg_color" => $survey_popup_title_bg_color,
343 "popup_title_bg_color_mobile" => $survey_popup_title_bg_color_mobile,
344 "popup_title_text_color" => $survey_popup_title_text_color,
345 "popup_title_text_color_mobile" => $survey_popup_title_text_color_mobile,
346 "popup_title_alignment" => $survey_popup_title_alignment,
347 "popup_title_alignment_on_mobile" => $survey_popup_title_alignment_on_mobile,
348 "popup_title_transform" => $survey_popup_title_transform,
349 "popup_title_transform_mobile" => $survey_popup_title_transform_mobile,
350 "popup_title_letter_spacing" => $survey_popup_title_letter_spacing,
351 "popup_title_letter_spacing_on_mobile" => $survey_popup_title_letter_spacing_on_mobile,
352 "popup_hide_title_on_mobile" => $survey_popup_hide_title_on_mobile,
353 "popup_title_border_radius" => $survey_popup_title_border_radius,
354 "popup_title_border_radius_mobile" => $survey_popup_title_border_radius_mobile,
355 "width" => $survey_width,
356 "width_by_percentage_px" => $survey_width_by_percentage_px,
357 "width_mobile" => $survey_width_mobile,
358 "width_mobile_by_percentage_px" => $survey_width_mobile_by_percentage_px,
359 "height" => $survey_heigth,
360 "height_by_percentage_px" => $survey_heigth_by_percentage_px,
361 "height_mobile" => $survey_heigth_mobile,
362 "height_mobile_by_percentage_px" => $survey_heigth_mobile_by_percentage_px,
363 "popup_position" => $popup_position,
364 "popup_margin" => $popup_margin,
365 "popup_trigger" => $popup_trigger,
366 "enable_popup_close_after_finish" => $survey_enable_popup_close_after_finish,
367 "popup_close_after_finish_delay" => $survey_popup_close_after_finish_delay,
368 "popup_selector" => $popup_selector,
369 'hide_popup' => $hide_popup,
370 'hide_popup_after_close' => $hide_popup_after_close,
371 'full_screen_mode' => $survey_popup_full_screen,
372 'popup_enable_close_by_esc' => $survey_popup_enable_close_by_esc,
373 'popup_bg_color' => $popup_bg_color,
374 'popup_bg_color_mobile' => $popup_bg_color_mobile,
375 'hide_popup_on_mobile' => $hide_popup_on_mobile,
376 'hide_popup_on_pc' => $hide_popup_on_pc,
377 'hide_popup_on_tablet' => $hide_popup_on_tablet,
378 'close_popup_overlay_outside_click' => $close_popup_overlay_outside_click,
379 );
380
381 $message = '';
382 if( $id == 0 ){
383 $result = $wpdb->insert(
384 $table,
385 array(
386 'survey_id' => $survey_id,
387 'title' => $title,
388 "show_all" => $show_all,
389 'status' => $status,
390 'trash_status' => $trash_status,
391 'author_id' => $author_id,
392 'date_created' => $date_created,
393 'date_modified' => $date_modified,
394 'options' => json_encode( $options ),
395 ),
396 array(
397 '%d', // survey_id
398 '%s', // title
399 '%s', // show_all
400 '%s', // status
401 '%s', // trash_status
402 '%d', // author_id
403 '%s', // date_created
404 '%s', // date_modified
405 '%s', // options
406 )
407 );
408
409 $inserted_id = $wpdb->insert_id;
410 $message = 'created';
411 }else{
412 $result = $wpdb->update(
413 $table,
414 array(
415 'survey_id' => $survey_id,
416 'title' => $title,
417 "show_all" => $show_all,
418 'status' => $status,
419 'trash_status' => $trash_status,
420 'author_id' => $author_id,
421 'date_created' => $date_created,
422 'date_modified' => $date_modified,
423 'options' => json_encode( $options ),
424 ),
425 array( 'id' => $id ),
426 array(
427 '%d', // survey_id
428 '%s', // title
429 '%s', // show_all
430 '%s', // status
431 '%s', // trash_status
432 '%d', // author_id
433 '%s', // date_created
434 '%s', // date_modified
435 '%s', // options
436 ),
437 array( '%d' )
438 );
439
440 $inserted_id = $id;
441 $message = 'updated';
442 }
443
444 if( $result >= 0 ) {
445 if($save_type == 'apply'){
446 if($id == 0){
447 $url = esc_url_raw( add_query_arg( array(
448 "action" => "edit",
449 "id" => $inserted_id,
450 "status" => $message
451 ) ) );
452 }else{
453 $url = esc_url_raw( add_query_arg( array(
454 "status" => $message
455 ) ) );
456 }
457 wp_redirect( $url );
458 }elseif($save_type == 'save_new'){
459 $url = remove_query_arg( array('id') );
460 $url = esc_url_raw( add_query_arg( array(
461 "action" => "add",
462 "status" => $message
463 ), $url ) );
464 wp_redirect( $url );
465 }else{
466 $url = remove_query_arg( array('action', 'id') );
467 $url = esc_url_raw( add_query_arg( array(
468 "status" => $message
469 ), $url ) );
470 wp_redirect( $url );
471 }
472 }
473 }
474 }
475
476 /**
477 * Delete a customer record.
478 *
479 * @param int $id customer ID
480 */
481 public static function delete_items( $id ) {
482 global $wpdb;
483
484 $wpdb->delete(
485 $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys",
486 array( 'id' => $id ),
487 array( '%d' )
488 );
489
490 }
491
492 /**
493 * Move to trash a customer record.
494 *
495 * @param int $id customer ID
496 */
497 public static function trash_items( $id ) {
498 global $wpdb;
499 $db_item = self::get_item_by_id( $id );
500
501 $wpdb->update(
502 $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys",
503 array(
504 'status' => 'trashed',
505 'trash_status' => $db_item['status'],
506 ),
507 array( 'id' => $id ),
508 array( '%s', '%s' ),
509 array( '%d' )
510 );
511
512 }
513
514 /**
515 * Restore a customer record.
516 *
517 * @param int $id customer ID
518 */
519 public static function restore_items( $id ) {
520 global $wpdb;
521 $db_item = self::get_item_by_id( $id );
522
523 $wpdb->update(
524 $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys",
525 array(
526 'status' => $db_item['trash_status'],
527 'trash_status' => '',
528 ),
529 array( 'id' => $id ),
530 array( '%s', '%s' ),
531 array( '%d' )
532 );
533 }
534
535 /*
536 * Returns the count of records in the database.
537 *
538 * @return null|string
539 */
540 public static function record_count() {
541 global $wpdb;
542 $filter = array();
543 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys";
544
545 if( isset( $_REQUEST['fstatus'] ) ){
546 $fstatus = sanitize_text_field( $_REQUEST['fstatus'] );
547 if($fstatus !== null){
548 $filter[] = " status = '". esc_sql( $fstatus ) ."' ";
549 }
550 }else{
551 $filter[] = " status != 'trashed' ";
552 }
553
554 // if( ! Survey_Maker_Data::survey_maker_capabilities_for_editing() ){
555 $current_user = get_current_user_id();
556 $filter[] = " author_id = ".$current_user." ";
557 // }
558
559 if(count($filter) !== 0){
560 $sql .= " WHERE ".implode(" AND ", $filter);
561 }
562
563 return $wpdb->get_var( $sql );
564 }
565
566 public static function all_record_count() {
567 global $wpdb;
568
569 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys WHERE status != 'trashed'";
570
571 // if( ! Survey_Maker_Data::survey_maker_capabilities_for_editing() ){
572 $current_user = get_current_user_id();
573 $sql .= " AND author_id = ".$current_user." ";
574 // }
575
576 return $wpdb->get_var( $sql );
577 }
578
579 public static function get_statused_record_count( $status ) {
580 global $wpdb;
581
582 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys WHERE status='" . esc_sql( $status ) . "'";
583
584 // if( ! Survey_Maker_Data::survey_maker_capabilities_for_editing() ){
585 $current_user = get_current_user_id();
586 $sql .= " AND author_id = ".$current_user." ";
587 // }
588
589 return $wpdb->get_var( $sql );
590 }
591
592 public function publish_unpublish_popup_survey( $id, $action ) {
593 global $wpdb;
594 $table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys";
595
596 if ( is_null($id) ) {
597 return false;
598 }
599
600 if ($action == 'unpublish') {
601 $status = 'unpublished';
602 $message = 'unpublished';
603 }else{
604 $status = 'published';
605 $message = 'published';
606 }
607
608 $pb_result = $wpdb->update(
609 $table,
610 array(
611 "status" => $status
612 ),
613 array( "id" => $id ),
614 array( "%s" ),
615 array( "%d" )
616 );
617
618 $url = esc_url_raw( remove_query_arg(array("action", "id", "_wpnonce")) ) . "&status=" . $message . "&type=success";
619 wp_redirect( $url );
620 }
621
622
623 /** Text displayed when no customer data is available */
624 public function no_items() {
625 Survey_Maker_Data::survey_no_items_list_tables('popup surveys');
626 }
627
628
629 /**
630 * Render a column when no column specific method exist.
631 *
632 * @param array $item
633 * @param string $column_name
634 *
635 * @return mixed
636 */
637 public function column_default( $item, $column_name ) {
638 switch ( $column_name ) {
639 case 'title':
640 case 'survey_id':
641 case 'id':
642 return $item[ $column_name ];
643 break;
644 default:
645 return print_r( $item, true ); //Show the whole array for troubleshooting purposes
646 }
647 }
648
649 /**
650 * Render the bulk edit checkbox
651 *
652 * @param array $item
653 *
654 * @return string
655 */
656 function column_cb( $item ) {
657
658 // if(intval($item['id']) === 1){
659 // return;
660 // }
661
662 return sprintf(
663 '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['id']
664 );
665 }
666
667
668 /**
669 * Method for name column
670 *
671 * @param array $item an array of DB data
672 *
673 * @return string
674 */
675 function column_title( $item ) {
676 $unpublish_nonce = wp_create_nonce( $this->plugin_name . "-unpublish-popup-survey" );
677 $publish_nonce = wp_create_nonce( $this->plugin_name . "-publish-popup-survey" );
678
679 if($item['status'] == 'trashed'){
680 $delete_nonce = wp_create_nonce( $this->plugin_name . '-delete-popup-survey' );
681 }else{
682 $delete_nonce = wp_create_nonce( $this->plugin_name . '-trash-popup-survey' );
683 }
684
685 if (isset($item['status']) && $item['status'] == 'published') {
686 $publish_button = 'unpublish';
687 $publish_button_val = sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">'. __('Unpublish', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ), 'unpublish', absint( $item['id'] ), $unpublish_nonce );
688 }else{
689 $publish_button = 'publish';
690 $publish_button_val = sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">'. __('Publish', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ), 'publish', absint( $item['id'] ), $publish_nonce );
691 }
692
693 $survey_title = stripcslashes( $item['title'] );
694
695 $q = esc_attr( $survey_title );
696
697 $restitle = Survey_Maker_Admin::ays_restriction_string( "word", $survey_title, $this->title_length );
698
699 $fstatus = '';
700 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
701 $fstatus = '&fstatus=' . sanitize_text_field( $_GET['fstatus'] );
702 }
703
704 $title = sprintf( '<a href="?page=%s&action=%s&id=%d" title="%s">%s</a>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ), $q, stripcslashes($item['title']));
705
706 $actions = array();
707 if($item['status'] == 'trashed'){
708 $title = sprintf( '<strong><a>%s</a></strong>', $restitle );
709 $actions['restore'] = sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s'.$fstatus.'">'. __('Restore', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ), 'restore', absint( $item['id'] ), $delete_nonce );
710 $actions['delete'] = sprintf( '<a class="ays_confirm_del" data-message="%s" href="?page=%s&action=%s&id=%s&_wpnonce=%s'.$fstatus.'">'. __('Delete Permanently', "survey-maker") .'</a>', $restitle, esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['id'] ), $delete_nonce );
711 }else{
712 $draft_text = '';
713 if( $item['status'] == 'draft' && !( isset( $_GET['fstatus'] ) && $_GET['fstatus'] == 'draft' )){
714 $draft_text = ' — ' . '<span class="post-state">' . __( "Draft", "survey-maker" ) . '</span>';
715 }
716 $title = sprintf( '<strong><a href="?page=%s&action=%s&id=%d" title="%s">%s</a>%s</strong>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ), $q, $restitle, $draft_text );
717
718 $actions['edit'] = sprintf( '<a href="?page=%s&action=%s&id=%d">'. __('Edit', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ) );
719
720 $actions[$publish_button] = $publish_button_val;
721 // $actions['duplicate'] = sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s'.$fstatus.'">'. __('Duplicate', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ), 'duplicate', absint( $item['id'] ), $delete_nonce );
722 $actions['trash'] = sprintf( '<a href="?page=%s&action=%s&id=%s&_wpnonce=%s'.$fstatus.'">'. __('Move to trash', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ), 'trash', absint( $item['id'] ), $delete_nonce );
723 }
724
725 return $title . $this->row_actions( $actions );
726 }
727
728 function column_survey_id( $item ) {
729 global $wpdb;
730 $sql = "SELECT * FROM {$wpdb->prefix}ayssurvey_surveys WHERE id=" . absint( intval( $item["survey_id"] ) );
731
732 $survey = $wpdb->get_row( $sql );
733
734 if($survey !== null){
735 return $survey->title;
736 }else{
737 return '';
738 }
739
740 }
741
742 function column_status( $item ) {
743 global $wpdb;
744 $status = ucfirst( $item['status'] );
745 $date = date( 'Y/m/d', strtotime( $item['date_modified'] ) );
746 $title_date = date( 'l jS \of F Y h:i:s A', strtotime( $item['date_modified'] ) );
747 $html = "<p style='font-size:14px;margin:0;'>" . $status . "</p>";
748 $html .= "<p style=';font-size:14px;margin:0;text-decoration: dotted underline;' title='" . $title_date . "'>" . $date . "</p>";
749 return $html;
750 }
751
752 function column_author_id( $item ) {
753 $user = get_user_by( 'id', $item['author_id'] );
754 $author_name = '';
755 if($user->data->display_name == ''){
756 if($user->data->user_nicename == ''){
757 $author_name = $user->data->user_login;
758 }else{
759 $author_name = $user->data->user_nicename;
760 }
761 }else{
762 $author_name = $user->data->display_name;
763 }
764 return $author_name;
765 }
766
767
768
769 /**
770 * Associative array of columns
771 *
772 * @return array
773 */
774 function get_columns() {
775 $columns = array(
776 'cb' => '<input type="checkbox" />',
777 'title' => __( 'Title', "survey-maker" ),
778 );
779
780 // if( Survey_Maker_Data::survey_maker_capabilities_for_editing() ){
781 $columns['author_id'] = __( 'Author', "survey-maker" );
782 // }
783
784 $columns['survey_id'] = __( 'Survey', "survey-maker" );
785 $columns['status'] = __( 'Status', "survey-maker" );
786 $columns['id'] = __( 'ID', "survey-maker" );
787
788 if( isset( $_GET['action'] ) && ( $_GET['action'] == 'add' || $_GET['action'] == 'edit' ) ){
789 return array();
790 }
791
792 return $columns;
793 }
794
795
796 /**
797 * Columns to make sortable.
798 *
799 * @return array
800 */
801 public function get_sortable_columns() {
802 $sortable_columns = array(
803 'title' => array( 'title', true ),
804 'id' => array( 'id', true ),
805 );
806
807 return $sortable_columns;
808 }
809
810 /**
811 * Returns an associative array containing the bulk action
812 *
813 * @return array
814 */
815 public function get_bulk_actions() {
816 $actions = array(
817 // 'bulk-duplicate' => __( 'Duplicate', "survey-maker" ),
818 'bulk-trash' => __( 'Move to trash', "survey-maker" ),
819 );
820
821 if(isset($_GET['fstatus']) && sanitize_text_field( $_GET['fstatus'] ) == 'trashed'){
822 $actions = array(
823 'bulk-restore' => __( 'Restore', "survey-maker" ),
824 'bulk-delete' => __( 'Delete Permanently', "survey-maker" ),
825 );
826 }
827
828 return $actions;
829 }
830
831 /**
832 * Handles data query and filter, sorting, and pagination.
833 */
834 public function prepare_items() {
835
836 $this->_column_headers = $this->get_column_info();
837
838 /** Process bulk action */
839 $this->process_bulk_action();
840
841 $per_page = $this->get_items_per_page( 'popup_survey_per_page', 20 );
842 $current_page = $this->get_pagenum();
843 $total_items = self::record_count();
844
845 $this->set_pagination_args( array(
846 'total_items' => $total_items, //WE have to calculate the total number of items
847 'per_page' => $per_page //WE have to determine how many items to show on a page
848 ) );
849
850 $this->items = self::get_items( $per_page, $current_page );
851 }
852
853 public function process_bulk_action() {
854
855 //Detect when a bulk action is being triggered...
856 if ( 'delete' === $this->current_action() ) {
857
858 // In our file that handles the request, verify the nonce.
859 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
860
861 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-delete-popup-survey' ) ) {
862 die( 'Go get a life script kiddies' );
863 }
864 else {
865 self::delete_items( absint( $_GET['id'] ) );
866
867 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
868 // add_query_arg() return the current url
869
870 $add_query_args = array(
871 "status" => 'deleted'
872 );
873 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
874 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
875 }
876 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
877 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
878 wp_redirect( $url );
879 }
880
881 }
882
883 //Detect when a bulk action is being triggered...
884 if ( 'trash' === $this->current_action() ) {
885
886 // In our file that handles the request, verify the nonce.
887 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
888
889 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-trash-popup-survey' ) ) {
890 die( 'Go get a life script kiddies' );
891 }
892 else {
893 self::trash_items( absint( $_GET['id'] ) );
894
895 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
896 // add_query_arg() return the current url
897
898 $add_query_args = array(
899 "status" => 'trashed'
900 );
901 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
902 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
903 }
904 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
905 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
906 wp_redirect( $url );
907 }
908
909 }
910
911 //Detect when a bulk action is being triggered...
912 if ( 'restore' === $this->current_action() ) {
913
914 // In our file that handles the request, verify the nonce.
915 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
916
917 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-delete-popup-survey' ) ) {
918 die( 'Go get a life script kiddies' );
919 }
920 else {
921 self::restore_items( absint( $_GET['id'] ) );
922
923 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
924 // add_query_arg() return the current url
925
926 $add_query_args = array(
927 "status" => 'restored'
928 );
929 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
930 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
931 }
932 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
933 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
934 wp_redirect( $url );
935 }
936
937 }
938
939 //Detect when a bulk action is being triggered...
940 if ( 'duplicate' === $this->current_action() ) {
941
942 // In our file that handles the request, verify the nonce.
943 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
944
945 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-trash-popup-survey' ) ) {
946 die( 'Go get a life script kiddies' );
947 }
948 else {
949 self::duplicate_items( absint( $_GET['id'] ) );
950
951 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
952 // add_query_arg() return the current url
953
954 $add_query_args = array(
955 "status" => 'duplicated'
956 );
957 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
958 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
959 }
960 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
961 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
962 wp_redirect( $url );
963 }
964
965 }
966
967 // If the delete bulk action is triggered
968 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' ) ) {
969
970 $delete_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
971
972 // loop over the array of record IDs and delete them
973 foreach ( $delete_ids as $id ) {
974 self::delete_items( $id );
975 }
976
977 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
978 // add_query_arg() return the current url
979 $add_query_args = array(
980 "status" => 'all-deleted'
981 );
982 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
983 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
984 }
985 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
986 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
987 wp_redirect( $url );
988 }
989
990 // If the delete bulk action is triggered
991 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-trash' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-trash' ) ) {
992
993 $trash_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
994
995 // loop over the array of record IDs and delete them
996 foreach ( $trash_ids as $id ) {
997 self::trash_items( $id );
998 }
999
1000 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
1001 // add_query_arg() return the current url
1002 $add_query_args = array(
1003 "status" => 'all-trashed'
1004 );
1005 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
1006 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
1007 }
1008 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
1009 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
1010 wp_redirect( $url );
1011 }
1012
1013 // If the delete bulk action is triggered
1014 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-restore' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-restore' ) ) {
1015
1016 $restore_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
1017
1018 // loop over the array of record IDs and delete them
1019 foreach ( $restore_ids as $id ) {
1020 self::restore_items( $id );
1021 }
1022
1023 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
1024 // add_query_arg() return the current url
1025 $add_query_args = array(
1026 "status" => 'all-restored'
1027 );
1028 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
1029 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
1030 }
1031 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
1032 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
1033 wp_redirect( $url );
1034 }
1035
1036 // If the delete bulk action is triggered
1037 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-duplicate' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-duplicate' ) ) {
1038
1039 $restore_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
1040
1041 // loop over the array of record IDs and delete them
1042 foreach ( $restore_ids as $id ) {
1043 self::duplicate_items( $id );
1044 }
1045
1046 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
1047 // add_query_arg() return the current url
1048 $add_query_args = array(
1049 "status" => 'all-duplicated'
1050 );
1051 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
1052 $add_query_args['fstatus'] = sanitize_text_field( $_GET['fstatus'] );
1053 }
1054 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
1055 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
1056 wp_redirect( $url );
1057 }
1058 }
1059
1060 public function popup_survey_notices(){
1061 $status = (isset($_REQUEST['status'])) ? sanitize_text_field( $_REQUEST['status'] ) : '';
1062
1063 if ( empty( $status ) )
1064 return;
1065
1066 $error = false;
1067 switch ( $status ) {
1068 case 'created':
1069 $updated_message = esc_html( __( 'Popup created.', "survey-maker" ) );
1070 break;
1071 case 'updated':
1072 $updated_message = esc_html( __( 'Popup saved.', "survey-maker" ) );
1073 break;
1074 case 'duplicated':
1075 $updated_message = esc_html( __( 'Popup duplicated.', "survey-maker" ) );
1076 break;
1077 case 'deleted':
1078 $updated_message = esc_html( __( 'Popup deleted.', "survey-maker" ) );
1079 break;
1080 case 'trashed':
1081 $updated_message = esc_html( __( 'Popup moved to trash.', "survey-maker" ) );
1082 break;
1083 case 'restored':
1084 $updated_message = esc_html( __( 'Popup restored.', "survey-maker" ) );
1085 break;
1086 case 'all-duplicated':
1087 $updated_message = esc_html( __( 'Popups are duplicated.', "survey-maker" ) );
1088 break;
1089 case 'all-deleted':
1090 $updated_message = esc_html( __( 'Popups are deleted.', "survey-maker" ) );
1091 break;
1092 case 'all-trashed':
1093 $updated_message = esc_html( __( 'Popups are moved to trash.', "survey-maker" ) );
1094 break;
1095 case 'all-restored':
1096 $updated_message = esc_html( __( 'Popups are restored.', "survey-maker" ) );
1097 break;
1098 case 'published':
1099 $updated_message = esc_html( __( 'Popups are published.', "survey-maker" ) );
1100 break;
1101 case 'unpublished':
1102 $updated_message = esc_html( __( 'Popups are unpublished.', "survey-maker" ) );
1103 break;
1104 case 'empty-title':
1105 $error = true;
1106 $updated_message = esc_html( __( 'Error: Popup title can not be empty.', "survey-maker" ) );
1107 break;
1108 default:
1109 break;
1110 }
1111
1112 if ( empty( $updated_message ) )
1113 return;
1114
1115 $notice_class = 'success';
1116 if( $error ){
1117 $notice_class = 'error';
1118 }
1119 ?>
1120 <div class="notice notice-<?php echo esc_attr($notice_class); ?> is-dismissible">
1121 <p> <?php echo esc_html($updated_message); ?> </p>
1122 </div>
1123 <?php
1124 }
1125 }
1126