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

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