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

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