PluginProbe
Survey Maker by AYS / 5.2.2.4
Survey Maker by AYS v5.2.2.4
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.2.4, at includes/lists/class-survey-maker-popup-survey-list-table.php

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