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

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