PluginProbe
Survey Maker by AYS / 5.2.0.8
Survey Maker by AYS v5.2.0.8
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-surveys-list-table.php

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

3,377 lines 216.3 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 Surveys_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 /**
24 * The settings object of this plugin.
25 *
26 * @since 1.0.0
27 * @access private
28 * @var object $settings_obj The settings object of this plugin.
29 */
30 private $settings_obj;
31
32
33 private $title_length;
34
35
36 /** Class constructor */
37 public function __construct( $plugin_name ) {
38 global $wpdb;
39
40 $this->plugin_name = $plugin_name;
41
42 $this->table_name = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
43
44 $this->settings_obj = new Survey_Maker_Settings_Actions($this->plugin_name);
45
46 $this->title_length = Survey_Maker_Data::get_listtables_title_length('surveys');
47
48 parent::__construct( array(
49 'singular' => __( 'Survey', "survey-maker" ), //singular name of the listed records
50 'plural' => __( 'Surveys', "survey-maker" ), //plural name of the listed records
51 'ajax' => false //does this table support ajax?
52 ) );
53
54 add_action( 'admin_notices', array( $this, 'survey_notices' ) );
55 add_filter( 'default_hidden_columns', array( $this, 'get_hidden_columns'), 10, 2 );
56
57 }
58
59 /**
60 * Override of table nav to avoid breaking with bulk actions & according nonce field
61 */
62 public function display_tablenav( $which ) {
63 ?>
64 <div class="tablenav <?php echo esc_attr( $which ); ?>">
65
66 <div class="alignleft actions">
67 <?php $this->bulk_actions( $which ); ?>
68 </div>
69 <?php
70 $this->extra_tablenav( $which );
71 $this->pagination( $which );
72 ?>
73 <br class="clear" />
74 </div>
75 <?php
76 }
77
78 /**
79 * Disables the views for 'side' context as there's not enough free space in the UI
80 * Only displays them on screen/browser refresh. Else we'd have to do this via an AJAX DB update.
81 *
82 * @see WP_List_Table::extra_tablenav()
83 */
84 public function extra_tablenav( $which ) {
85 global $wpdb;
86 $titles_sql = "SELECT s.title, s.id
87 FROM " .$wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "survey_categories AS s
88 WHERE s.status = 'published'";
89 $cat_titles = $wpdb->get_results($titles_sql);
90
91 $users_sql = "SELECT `author_id`
92 FROM " .$wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys
93 GROUP BY author_id";
94 $users = $wpdb->get_results($users_sql,"ARRAY_A");
95 $cat_id = null;
96
97 if( isset( $_GET['filterby'] )){
98 $cat_id = absint( esc_attr( $_GET['filterby'] ) );
99 }
100
101 if( isset( $_GET['filterbyuser'] )){
102 $author_id = absint( esc_attr( $_GET['filterbyuser'] ) );
103 }
104
105 $categories_select = array();
106 foreach($cat_titles as $key => $cat_title){
107 $selected = "";
108 if($cat_id === intval($cat_title->id)){
109 $selected = "selected";
110 }
111 $categories_select[$cat_title->id]['title'] = $cat_title->title;
112 $categories_select[$cat_title->id]['selected'] = $selected;
113 $categories_select[$cat_title->id]['id'] = $cat_title->id;
114 }
115 sort($categories_select);
116 ?>
117 <div id="category-filter-div-surveylist" class="alignleft actions bulkactions">
118 <select name="filterby-<?php echo esc_attr( $which ); ?>" id="survey-category-filter-<?php echo esc_attr( $which ); ?>">
119 <option value=""><?php echo esc_html__('Select Category',"survey-maker")?></option>
120 <?php
121 foreach($categories_select as $key => $cat_title){
122 echo "<option ".esc_attr($cat_title['selected'])." value='".esc_attr($cat_title['id'])."'>".esc_attr($cat_title['title'])."</option>";
123 }
124 ?>
125 </select>
126 </div>
127 <div id="user-filter-div-surveylist" class="alignleft actions bulkactions">
128 <select name="filterbyuser-<?php echo esc_attr( $which ); ?>" id="survey-category-filter-<?php echo esc_attr( $which ); ?>">
129 <option value=""><?php echo esc_html__('Select Author',"survey-maker")?></option>
130 <?php
131 foreach($users as $user_key => $user){
132 $user_selected = ( isset($author_id) && $user['author_id'] == $author_id ) ? "selected" : "";
133 $user_data = get_userdata($user['author_id']);
134 $user_name = ($user_data !== false) ? $user_data->data->display_name : "";
135 if(!$user_name){
136 continue;
137 }
138
139 echo "<option ".esc_attr($user_selected)." value='".esc_attr($user['author_id'])."'>".esc_attr($user_name)."</option>";
140 }
141 ?>
142 </select>
143 <input type="button" id="doaction-<?php echo esc_attr( $which ); ?>" class="user-filter-apply-<?php echo esc_attr( $which ); ?> button ays-survey-question-tab-all-filter-button-<?php echo esc_attr( $which ); ?>" value="Filter">
144 </div>
145
146 <a style="margin: 0px 8px 0 0;" href="?page=<?php echo esc_attr( ( $_REQUEST['page'] ) ); ?>" class="button"><?php echo esc_html__( "Clear filters", "survey-maker" ); ?></a>
147 <?php
148 }
149
150 protected function get_views() {
151 $published_count = $this->get_statused_record_count( 'published' );
152 $draft_count = $this->get_statused_record_count( 'draft' );
153 $trashed_count = $this->get_statused_record_count( 'trashed' );
154 $all_count = $this->all_record_count();
155 $selected_all = "";
156 $selected_published = "";
157 $selected_draft = "";
158 $selected_trashed = "";
159 if( isset( $_GET['fstatus'] ) ){
160 switch( sanitize_text_field( $_GET['fstatus'] ) ){
161 case "published":
162 $selected_published = " style='font-weight:bold;' ";
163 break;
164 case "draft":
165 $selected_draft = " style='font-weight:bold;' ";
166 break;
167 case "trashed":
168 $selected_trashed = " style='font-weight:bold;' ";
169 break;
170 default:
171 $selected_all = " style='font-weight:bold;' ";
172 break;
173 }
174 }else{
175 $selected_all = " style='font-weight:bold;' ";
176 }
177 $status_links = array(
178 "all" => "<a ".$selected_all." href='?page=".esc_attr( $_REQUEST['page'] )."'>" . __( "All", "survey-maker" ) . " (".$all_count.")</a>",
179 );
180 if( intval( $published_count ) > 0 ){
181 $status_links["published"] = "<a ".$selected_published." href='?page=".esc_attr( $_REQUEST['page'] )."&fstatus=published'>" . __( "Published", "survey-maker" ) . " (".$published_count.")</a>";
182 }
183 if( intval( $draft_count ) > 0 ){
184 $status_links["draft"] = "<a ".$selected_draft." href='?page=".esc_attr( $_REQUEST['page'] )."&fstatus=draft'>" . __( "Draft", "survey-maker" ) . " (".$draft_count.")</a>";
185 }
186 if( intval( $trashed_count ) > 0 ){
187 $status_links["trashed"] = "<a ".$selected_trashed." href='?page=".esc_attr( $_REQUEST['page'] )."&fstatus=trashed'>" . __( "Trash", "survey-maker" ) . " (".$trashed_count.")</a>";
188 }
189 return $status_links;
190 }
191
192 /**
193 * Retrieve customers data from the database
194 *
195 * @param int $per_page
196 * @param int $page_number
197 *
198 * @return mixed
199 */
200 public static function get_items( $per_page = 20, $page_number = 1, $search = '' ) {
201
202 global $wpdb;
203
204 $sql = "SELECT * FROM ". $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
205
206 $where = array();
207
208 if ( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != ''){
209 $where[] = ' status = "' . esc_sql( esc_attr( $_GET['fstatus'] ) ) . '" ';
210 }else{
211 $where[] = ' status != "trashed" ';
212 }
213
214 if( $search != '' ){
215 $where[] = $search;
216 }
217
218 if(! empty( $_REQUEST['filterby'] ) && intval( $_REQUEST['filterby'] ) > 0){
219 $cat_id = intval( esc_attr( $_REQUEST['filterby'] ) );
220 $where[] = ' FIND_IN_SET( "'.$cat_id.'", `category_ids` ) ';
221 }
222
223 if(! empty( $_REQUEST['filterbyuser'] ) && intval( $_REQUEST['filterbyuser'] ) > 0){
224 $user_id = intval( esc_attr( $_REQUEST['filterbyuser'] ) );
225 $where[] = ' author_id ='.$user_id;
226 }
227
228 if ( ! empty( $where ) ){
229 $sql .= ' WHERE ' . implode( ' AND ', $where );
230 }
231
232 if ( ! empty( $_REQUEST['orderby'] ) ) {
233 $order_by = ( isset( $_REQUEST['orderby'] ) && esc_attr( $_REQUEST['orderby'] ) != '' ) ? esc_attr( $_REQUEST['orderby'] ) : 'id';
234 $order_by .= ( ! empty( $_REQUEST['order'] ) && strtolower( $_REQUEST['order'] ) == 'asc' ) ? ' ASC' : ' DESC';
235
236 $sql_orderby = sanitize_sql_orderby( $order_by );
237
238 if ( $sql_orderby ) {
239 $sql .= ' ORDER BY ' . $sql_orderby;
240 } else {
241 $sql .= ' ORDER BY ordering DESC';
242 }
243 }else{
244 $sql .= ' ORDER BY ordering DESC';
245 }
246
247 $sql .= " LIMIT $per_page";
248 $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
249
250
251 $result = $wpdb->get_results( $sql, 'ARRAY_A' );
252
253 return $result;
254 }
255
256 public function get_categories(){
257 global $wpdb;
258
259 $sql = "SELECT * FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "survey_categories WHERE status='published' ORDER BY title ASC";
260
261 $result = $wpdb->get_results($sql, 'ARRAY_A');
262
263 return $result;
264 }
265
266 public static function get_item_by_id( $id ){
267 global $wpdb;
268
269 $sql = "SELECT * FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys WHERE id=" . absint( $id );
270
271 $result = $wpdb->get_row($sql, 'ARRAY_A');
272
273 return $result;
274 }
275
276 public function add_or_edit_item(){
277 global $wpdb;
278 $table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys" );
279 $sections_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "sections" );
280 $questions_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "questions" );
281 $answers_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "answers" );
282
283 if( isset( $_POST["survey_action"] ) && wp_verify_nonce( sanitize_text_field( $_POST["survey_action"] ), 'survey_action' ) ){
284
285 $name_prefix = 'ays_';
286
287 // Save type
288 $save_type = (isset($_POST['save_type'])) ? sanitize_text_field( $_POST['save_type'] ) : '';
289
290 // Id of item
291 $id = isset( $_POST['id'] ) ? absint( sanitize_text_field( $_POST['id'] ) ) : 0;
292
293 // Ordering
294 $max_id = $this->get_max_id();
295 $ordering = ( $max_id != NULL ) ? ( $max_id + 1 ) : 1;
296
297 // Author ID
298 $user_id = get_current_user_id();
299 $author_id = isset( $_POST[ $name_prefix . 'author_id' ] ) && $_POST[ $name_prefix . 'author_id' ] != '' ? intval( sanitize_text_field( $_POST[ $name_prefix . 'author_id' ] ) ) : $user_id;
300
301 // Title
302 $title = isset( $_POST[ $name_prefix . 'title' ] ) && $_POST[ $name_prefix . 'title' ] != '' ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'title' ] ) ) : '';
303
304 if($title == ''){
305 $url = esc_url_raw( remove_query_arg( false ) );
306 $url = esc_url_raw( add_query_arg( array(
307 'status' => 'empty-title'
308 ), $url ) );
309 wp_redirect( $url );
310 }
311
312 // Description
313 $description = ''; //isset( $_POST[ $name_prefix . 'description' ] ) && $_POST[ $name_prefix . 'description' ] != '' ? stripslashes( wp_kses_post( $_POST[ $name_prefix . 'description' ] ) ) : '';
314
315 // Status
316 $status = isset( $_POST[ $name_prefix . 'status' ] ) && $_POST[ $name_prefix . 'status' ] != '' ? sanitize_text_field( $_POST[ $name_prefix . 'status' ] ) : 'published';
317
318 // Trash status
319 $trash_status = '';
320
321 // Date created
322 $date_created = isset( $_POST[ $name_prefix . 'survey_change_creation_date' ] ) && Survey_Maker_Admin::validateDate( $_POST[ $name_prefix . 'survey_change_creation_date' ] ) ? sanitize_text_field( $_POST[ $name_prefix . 'survey_change_creation_date' ] ) : current_time( 'mysql' );
323
324 // Date modified
325 $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' );
326
327 // Survey categories IDs
328 $category_ids = isset( $_POST[ $name_prefix . 'category_ids' ] ) && $_POST[ $name_prefix . 'category_ids' ] != '' ? array_map( 'sanitize_text_field', $_POST[ $name_prefix . 'category_ids' ] ) : array();
329 $category_ids = empty( $category_ids ) ? '' : implode( ',', $category_ids );
330
331 // Survey questions IDs
332 $question_ids = isset( $_POST[ $name_prefix . 'question_ids' ] ) && $_POST[ $name_prefix . 'question_ids' ] != '' ? array_map( 'sanitize_text_field', $_POST[ $name_prefix . 'question_ids' ] ) : array();
333 // $question_ids = empty( $question_ids ) ? '' : implode( ',', $question_ids );
334
335 // Survey image
336 $image = isset( $_POST[ $name_prefix . 'image' ] ) && $_POST[ $name_prefix . 'image' ] != '' ? sanitize_text_field( $_POST[ $name_prefix . 'image' ] ) : '';
337
338 // Post ID
339 $post_id = isset( $_POST[ $name_prefix . 'post_id' ] ) && ! empty( $_POST[ $name_prefix . 'post_id' ] ) ? intval( sanitize_text_field( $_POST[ $name_prefix . 'post_id' ] ) ) : 0;
340
341 // Section ids
342 $section_ids = (isset( $_POST[ $name_prefix . 'sections_ids' ] ) && $_POST[ $name_prefix . 'sections_ids' ] != '') ? array_map( 'sanitize_text_field', $_POST[ $name_prefix . 'sections_ids' ] ) : array();
343
344
345 // ======================= // ======================= // ======================= // ======================= // ======================= //
346
347 // =============================================================
348 // ====================== Styles Tab =====================
349 // ======================== START ========================
350
351
352 // Survey Theme
353 $survey_theme = (isset( $_POST[ $name_prefix . 'survey_theme' ] ) && $_POST[ $name_prefix . 'survey_theme' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_theme' ] ) ) : 'classic_light';
354
355 // Survey Color
356 $survey_color = (isset( $_POST[ $name_prefix . 'survey_color' ] ) && $_POST[ $name_prefix . 'survey_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_color' ] ) ) : '#ff5722';
357
358 // Background color
359 $survey_background_color = (isset( $_POST[ $name_prefix . 'survey_background_color' ] ) && $_POST[ $name_prefix . 'survey_background_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_background_color' ] ) ) : '#fff';
360
361 // Text Color
362 $survey_text_color = (isset( $_POST[ $name_prefix . 'survey_text_color' ] ) && $_POST[ $name_prefix . 'survey_text_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_text_color' ] ) ) : '#333';
363
364 // Loader Color
365 $survey_loader_color = (isset( $_POST[ $name_prefix . 'survey_loader_color' ] ) && $_POST[ $name_prefix . 'survey_loader_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_loader_color' ] ) ) : $survey_text_color;
366
367 // Buttons text Color
368 $survey_buttons_text_color = (isset( $_POST[ $name_prefix . 'survey_buttons_text_color' ] ) && $_POST[ $name_prefix . 'survey_buttons_text_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_text_color' ] ) ) : '#333';
369
370 // Width
371 $survey_width = (isset( $_POST[ $name_prefix . 'survey_width' ] ) && $_POST[ $name_prefix . 'survey_width' ] != '') ? absint( intval( $_POST[ $name_prefix . 'survey_width' ] ) ) : '';
372
373 // Survey Width by percentage or pixels
374 $survey_width_by_percentage_px = (isset( $_POST[ $name_prefix . 'survey_width_by_percentage_px' ] ) && $_POST[ $name_prefix . 'survey_width_by_percentage_px' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_width_by_percentage_px' ] ) ) : 'pixels';
375
376 // Mobile width
377 $survey_mobile_width = (isset( $_POST[ $name_prefix . 'survey_mobile_width' ] ) && $_POST[ $name_prefix . 'survey_mobile_width' ] != '') ? absint( intval( $_POST[ $name_prefix . 'survey_mobile_width' ] ) ) : '';
378
379 // Survey mobile width by percentage or pixels
380 $survey_mobile_width_by_percentage_px = (isset( $_POST[ $name_prefix . 'survey_mobile_width_by_percentage_px' ] ) && $_POST[ $name_prefix . 'survey_mobile_width_by_percentage_px' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_mobile_width_by_percentage_px' ] ) ) : 'pixels';
381
382 // Survey container Max-Width
383 $survey_mobile_max_width = (isset( $_POST[ $name_prefix . 'mobile_max_width' ] ) && $_POST[ $name_prefix . 'mobile_max_width' ] != '') ? absint( intval( $_POST[ $name_prefix . 'mobile_max_width' ] ) ) : '';
384
385 // Custom class for survey container
386 $survey_custom_class = (isset( $_POST[ $name_prefix . 'survey_custom_class' ] ) && $_POST[ $name_prefix . 'survey_custom_class' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_custom_class' ] ) ) : '';
387
388 // Custom CSS
389 $survey_custom_css = (isset( $_POST[ $name_prefix . 'survey_custom_css' ] ) && $_POST[ $name_prefix . 'survey_custom_css' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_custom_css' ] ) ) : '';
390
391 // Survey logo
392 $survey_logo = (isset( $_POST[ $name_prefix . 'survey_logo' ]) && $_POST[ $name_prefix . 'survey_logo' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_logo' ] ) ) : '';
393
394 // Survey Logo url
395 $survey_logo_image_url = (isset( $_POST[ $name_prefix . 'survey_logo_image_url' ] ) && $_POST[ $name_prefix . 'survey_logo_image_url' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_logo_image_url' ] ) : '';
396 $survey_logo_image_url_check = (isset( $_POST[ $name_prefix . 'survey_logo_enable_image_url' ] ) && $_POST[ $name_prefix . 'survey_logo_enable_image_url' ] == 'on') ? 'on' : 'off';
397
398 // Survey Logo position
399 $survey_logo_image_position = (isset( $_POST[ $name_prefix . 'survey_logo_pos' ] ) && $_POST[ $name_prefix . 'survey_logo_pos' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_logo_pos' ] ) : 'right';
400 // Survey Logo position mobile
401 $survey_logo_image_position_mobile = (isset( $_POST[ $name_prefix . 'survey_logo_pos_mobile' ] ) && $_POST[ $name_prefix . 'survey_logo_pos_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_logo_pos_mobile' ] ) : 'right';
402
403 // Survey Logo title
404 $survey_logo_title = (isset( $_POST[ $name_prefix . 'survey_logo_title' ] ) && $_POST[ $name_prefix . 'survey_logo_title' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_logo_title' ] ) : '';
405
406 // Survey cover photo
407 $survey_cover_photo = (isset( $_POST[ $name_prefix . 'survey_cover_photo' ]) && $_POST[ $name_prefix . 'survey_cover_photo' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_cover_photo' ] ) ) : '';
408
409 // Survey cover photo height
410 $survey_cover_photo_height = (isset( $_POST[ $name_prefix . 'survey_cover_image_height' ]) && $_POST[ $name_prefix . 'survey_cover_image_height' ] != '') ? absint(intval(( sanitize_text_field( $_POST[ $name_prefix . 'survey_cover_image_height' ])))) : 150;
411
412 // Survey cover photo mobile height
413 $survey_cover_photo_mobile_height = (isset( $_POST[ $name_prefix . 'survey_cover_photo_mobile_height' ]) && $_POST[ $name_prefix . 'survey_cover_photo_mobile_height' ] != '') ? absint(intval(( sanitize_text_field( $_POST[ $name_prefix . 'survey_cover_photo_mobile_height' ])))) : 150;
414
415 // Survey cover photo position
416 $survey_cover_photo_position = (isset( $_POST[ $name_prefix . 'survey_cover_image_pos' ]) && $_POST[ $name_prefix . 'survey_cover_image_pos' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_cover_image_pos' ]) : "center_center";
417
418 // Survey cover photo object fit
419 $survey_cover_photo_object_fit = (isset( $_POST[ $name_prefix . 'survey_cover_image_object_fit' ]) && $_POST[ $name_prefix . 'survey_cover_image_object_fit' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_cover_image_object_fit' ]) : "cover";
420
421 // Survey cover only first section
422 $survey_cover_only_first_section = (isset( $_POST[ $name_prefix . 'survey_cover_only_first_section' ] ) && $_POST[ $name_prefix . 'survey_cover_only_first_section' ] == 'on') ? 'on' : 'off';
423
424 // Survey title alignment
425 $survey_title_alignment = (isset( $_POST[ $name_prefix . 'survey_title_alignment' ] ) && $_POST[ $name_prefix . 'survey_title_alignment' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_title_alignment' ] ) : 'left';
426
427 // Survey title alignment
428 $survey_title_alignment_mobile = (isset( $_POST[ $name_prefix . 'survey_title_alignment_mobile' ] ) && $_POST[ $name_prefix . 'survey_title_alignment_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_title_alignment_mobile' ] ) : 'left';
429
430 // Survey title font size
431 $survey_title_font_size = (isset( $_POST[ $name_prefix . 'survey_title_font_size' ] ) && $_POST[ $name_prefix . 'survey_title_font_size' ] != '' && $_POST[ $name_prefix . 'survey_title_font_size' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_title_font_size' ] ))) : '30';
432
433 // Survey title font size mobile
434 $survey_title_font_size_for_mobile = (isset( $_POST[ $name_prefix . 'survey_title_font_size_for_mobile' ] ) && $_POST[ $name_prefix . 'survey_title_font_size_for_mobile' ] != '' && $_POST[ $name_prefix . 'survey_title_font_size_for_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_title_font_size_for_mobile' ] ))) : '30';
435
436 // Survey title letter spacing
437 $survey_title_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_title_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_title_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_title_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_title_letter_spacing' ] ))) : '0';
438
439 // Survey title letter spacing mobile
440 $survey_title_letter_spacing_mobile = (isset( $_POST[ $name_prefix . 'survey_title_letter_spacing_mobile' ] ) && $_POST[ $name_prefix . 'survey_title_letter_spacing_mobile' ] != '' && $_POST[ $name_prefix . 'survey_title_letter_spacing_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_title_letter_spacing_mobile' ] ))) : '0';
441
442 // Survey title box shadow
443 $survey_title_box_shadow_enable = (isset( $_POST[ $name_prefix . 'survey_title_box_shadow_enable' ] ) && $_POST[ $name_prefix . 'survey_title_box_shadow_enable' ] == 'on' ) ? 'on' : 'off';
444
445 // Survey title box shadow color
446 $survey_title_box_shadow_color = (isset( $_POST[ $name_prefix . 'survey_title_box_shadow_color' ] ) && $_POST[ $name_prefix . 'survey_title_box_shadow_color' ] != '' ) ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_title_box_shadow_color' ] ) ) : '#333';
447
448 // === Survey title box shadow offsets start ===
449 // Survey title box shadow offset x
450 $survey_title_text_shadow_x_offset = (isset( $_POST[ $name_prefix . 'title_text_shadow_x_offset' ] ) && $_POST[ $name_prefix . 'title_text_shadow_x_offset' ] != '' ) ? intval( $_POST[ $name_prefix . 'title_text_shadow_x_offset' ] ) : 0;
451 // Survey title box shadow offset y
452 $survey_title_text_shadow_y_offset = (isset( $_POST[ $name_prefix . 'title_text_shadow_y_offset' ] ) && $_POST[ $name_prefix . 'title_text_shadow_y_offset' ] != '' ) ? intval( $_POST[ $name_prefix . 'title_text_shadow_y_offset' ] ) : 0;
453 // Survey title box shadow offset z
454 $survey_title_text_shadow_z_offset = (isset( $_POST[ $name_prefix . 'title_text_shadow_z_offset' ] ) && $_POST[ $name_prefix . 'title_text_shadow_z_offset' ] != '' ) ? intval( $_POST[ $name_prefix . 'title_text_shadow_z_offset' ] ) : 10;
455 // === Survey title box shadow offsets end ===
456
457 // Survey section title font size on PC
458 $survey_section_title_font_size = (isset( $_POST[ $name_prefix . 'survey_section_title_font_size' ] ) && $_POST[ $name_prefix . 'survey_section_title_font_size' ] != '') ? absint(intval( $_POST[ $name_prefix . 'survey_section_title_font_size' ] )) : 32;
459 // Survey section title font size Mobile
460 $survey_section_title_font_size_mobile = (isset( $_POST[ $name_prefix . 'survey_section_title_font_size_mobile' ] ) && $_POST[ $name_prefix . 'survey_section_title_font_size_mobile' ] != '') ? absint(intval( $_POST[ $name_prefix . 'survey_section_title_font_size_mobile' ] )) : 32;
461
462 // Survey section title alignment
463 $survey_section_title_alignment = (isset( $_POST[ $name_prefix . 'survey_section_title_alignment' ] ) && $_POST[ $name_prefix . 'survey_section_title_alignment' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_section_title_alignment' ] ) : 'left';
464 // Survey section title alignment mobile
465 $survey_section_title_alignment_mobile = (isset( $_POST[ $name_prefix . 'survey_section_title_alignment_mobile' ] ) && $_POST[ $name_prefix . 'survey_section_title_alignment_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_section_title_alignment_mobile' ] ) : 'left';
466
467 // Survey title letter spacing
468 $survey_section_title_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_section_title_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_section_title_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_section_title_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_section_title_letter_spacing' ] ))) : '0';
469
470 // Survey title letter spacing mobile
471 $survey_section_title_letter_spacing_mobile = (isset( $_POST[ $name_prefix . 'survey_section_title_letter_spacing_mobile' ] ) && $_POST[ $name_prefix . 'survey_section_title_letter_spacing_mobile' ] != '' && $_POST[ $name_prefix . 'survey_section_title_letter_spacing_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_section_title_letter_spacing_mobile' ] ))) : '0';
472
473 // Survey section description alignment
474 $survey_section_description_alignment = (isset( $_POST[ $name_prefix . 'survey_section_description_alignment' ] ) && $_POST[ $name_prefix . 'survey_section_description_alignment' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_section_description_alignment' ] ) : 'left';
475 // Survey section description alignment mobile
476 $survey_section_description_alignment_mobile = (isset( $_POST[ $name_prefix . 'survey_section_description_alignment_mobile' ] ) && $_POST[ $name_prefix . 'survey_section_description_alignment_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_section_description_alignment_mobile' ] ) : 'left';
477
478 // Survey section description font size
479 $survey_section_description_font_size = (isset( $_POST[ $name_prefix . 'survey_section_description_font_size' ] ) && $_POST[ $name_prefix . 'survey_section_description_font_size' ] != '') ? absint(intval( $_POST[ $name_prefix . 'survey_section_description_font_size' ] )) : '14';
480
481 // Survey section description font size mobile
482 $survey_section_description_font_size_mobile = (isset( $_POST[ $name_prefix . 'survey_section_description_font_size_mobile' ] ) && $_POST[ $name_prefix . 'survey_section_description_font_size_mobile' ] != '') ? absint(intval( $_POST[ $name_prefix . 'survey_section_description_font_size_mobile' ] )) : '14';
483
484 // Survey title letter spacing
485 $survey_section_description_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_section_description_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_section_description_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_section_description_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_section_description_letter_spacing' ] ))) : '0';
486
487 // SSurvey section description letter spacing mobile
488 $survey_section_description_letter_spacing_mobile = (isset( $_POST[ $name_prefix . 'survey_section_description_letter_spacing_mobile' ] ) && $_POST[ $name_prefix . 'survey_section_description_letter_spacing_mobile' ] != '' && $_POST[ $name_prefix . 'survey_section_description_letter_spacing_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_section_description_letter_spacing_mobile' ] ))) : '0';
489
490 // =========== Questions Styles Start ===========
491
492 // Question font size
493 $survey_question_font_size = (isset( $_POST[ $name_prefix . 'survey_question_font_size' ] ) && $_POST[ $name_prefix . 'survey_question_font_size' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_font_size' ] ) ) : 16;
494
495 // Question font size mobile
496 $survey_question_font_size_mobile = (isset( $_POST[ $name_prefix . 'survey_question_font_size_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_font_size_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_font_size_mobile' ] ) ) : 16;
497
498 // Question title alignment
499 $survey_question_title_alignment = (isset( $_POST[ $name_prefix . 'survey_question_title_alignment' ] ) && $_POST[ $name_prefix . 'survey_question_title_alignment' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_title_alignment' ] ) ) : 'left';
500
501 // Question Image Width
502 $survey_question_image_width = (isset( $_POST[ $name_prefix . 'survey_question_image_width' ] ) && $_POST[ $name_prefix . 'survey_question_image_width' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_image_width' ] ) ) : '';
503 // Question Image Width mobile
504 $survey_question_image_width_mobile = (isset( $_POST[ $name_prefix . 'survey_question_image_width_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_image_width_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_image_width_mobile' ] ) ) : '';
505
506 // Question Image Height
507 $survey_question_image_height = (isset( $_POST[ $name_prefix . 'survey_question_image_height' ] ) && $_POST[ $name_prefix . 'survey_question_image_height' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_image_height' ] ) ) : '';
508 // Question Image Height mobile
509 $survey_question_image_height_mobile = (isset( $_POST[ $name_prefix . 'survey_question_image_height_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_image_height_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_image_height_mobile' ] ) ) : '';
510
511 // Question Image sizing
512 $survey_question_image_sizing = (isset( $_POST[ $name_prefix . 'survey_question_image_sizing' ] ) && $_POST[ $name_prefix . 'survey_question_image_sizing' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_image_sizing' ] ) ) : 'cover';
513 // Question Image sizing mobile
514 $survey_question_image_sizing_mobile = (isset( $_POST[ $name_prefix . 'survey_question_image_sizing_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_image_sizing_mobile' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_image_sizing_mobile' ] ) ) : 'cover';
515
516 // Question padding
517 $survey_question_padding = (isset( $_POST[ $name_prefix . 'survey_question_padding' ] ) && $_POST[ $name_prefix . 'survey_question_padding' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_padding' ] ) ) : 24;
518
519 // Question padding mobile
520 $survey_question_padding_mobile = (isset( $_POST[ $name_prefix . 'survey_question_padding_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_padding_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_padding_mobile' ] ) ) : 24;
521
522 // Question border radius
523 $survey_question_border_radius = (isset( $_POST[ $name_prefix . 'survey_question_border_radius' ] ) && $_POST[ $name_prefix . 'survey_question_border_radius' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_border_radius' ] ) ) : 8;
524
525 // Question border radius mobile
526 $survey_question_border_radius_mobile = (isset( $_POST[ $name_prefix . 'survey_question_border_radius_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_border_radius_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_border_radius_mobile' ] ) ) : 8;
527
528 // Question caption text color
529 $survey_question_caption_text_color = (isset( $_POST[ $name_prefix . 'survey_question_caption_text_color' ] ) && $_POST[ $name_prefix . 'survey_question_caption_text_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_text_color' ] ) ) : $survey_text_color;
530 // Question caption text color mobile
531 $survey_question_caption_text_color_mobile = (isset( $_POST[ $name_prefix . 'survey_question_caption_text_color_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_caption_text_color_mobile' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_text_color_mobile' ] ) ) : $survey_text_color;
532
533 // Question caption text alignment
534 $survey_question_caption_text_alignment = (isset( $_POST[ $name_prefix . 'survey_question_caption_text_alignment' ] ) && $_POST[ $name_prefix . 'survey_question_caption_text_alignment' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_text_alignment' ] ) : 'center';
535
536 // Question caption text alignment on mobile
537 $survey_question_caption_text_alignment_on_mobile = (isset( $_POST[ $name_prefix . 'survey_question_caption_text_alignment_on_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_caption_text_alignment_on_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_text_alignment_on_mobile' ] ) : 'center';
538
539 // Question font size
540 $survey_question_caption_font_size = (isset( $_POST[ $name_prefix . 'survey_question_caption_font_size' ] ) && $_POST[ $name_prefix . 'survey_question_caption_font_size' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_font_size' ] ) ) : 16;
541
542 // Question font size on mobile
543 $survey_question_caption_font_size_on_mobile = (isset( $_POST[ $name_prefix . 'survey_question_caption_font_size_on_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_caption_font_size_on_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_font_size_on_mobile' ] ) ) : 16;
544
545 // Question caption text transform
546 $survey_question_caption_text_transform = (isset( $_POST[ $name_prefix . 'survey_question_caption_text_transform' ] ) && $_POST[ $name_prefix . 'survey_question_caption_text_transform' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_text_transform' ] ) : 'none';
547 // Question caption text transform mobile
548 $survey_question_caption_text_transform_mobile = (isset( $_POST[ $name_prefix . 'survey_question_caption_text_transform_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_caption_text_transform_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_text_transform_mobile' ] ) : 'none';
549
550 // Question caption letter spacing
551 $survey_question_caption_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_question_caption_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_question_caption_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_question_caption_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_letter_spacing' ] ))) : '0';
552
553 // Question caption letter spacing mobile
554 $survey_question_caption_letter_spacing_mobile = (isset( $_POST[ $name_prefix . 'survey_question_caption_letter_spacing_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_caption_letter_spacing_mobile' ] != '' && $_POST[ $name_prefix . 'survey_question_caption_letter_spacing_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_question_caption_letter_spacing_mobile' ] ))) : '0';
555
556 // Question caption hide on mobile
557 $survey_question_caption_hide_on_mobile = (isset( $_POST[ $name_prefix . 'survey_question_caption_hide_on_mobile' ] ) && $_POST[ $name_prefix . 'survey_question_caption_hide_on_mobile' ] != '' && $_POST[ $name_prefix . 'survey_question_caption_hide_on_mobile' ] == 'on' ) ? 'on' : 'off';
558
559 // =========== Questions Styles End ===========
560
561
562
563 // =========== Answers Styles Start ===========
564
565 // Answer font size
566 $survey_answer_font_size = (isset( $_POST[ $name_prefix . 'survey_answer_font_size' ] ) && $_POST[ $name_prefix . 'survey_answer_font_size' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answer_font_size' ] ) ) : 15;
567
568 // Answer font size mobile
569 $survey_answer_font_size_on_mobile = (isset( $_POST[ $name_prefix . 'survey_answer_font_size_on_mobile' ] ) && $_POST[ $name_prefix . 'survey_answer_font_size_on_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answer_font_size_on_mobile' ] ) ) : 15;
570
571 // Answer letter spacing
572 $survey_answer_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_answer_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_answer_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_answer_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_answer_letter_spacing' ] ))) : '0';
573
574 // Answer letter spacing mobile
575 $survey_answer_letter_spacing_mobile = (isset( $_POST[ $name_prefix . 'survey_answer_letter_spacing_mobile' ] ) && $_POST[ $name_prefix . 'survey_answer_letter_spacing_mobile' ] != '' && $_POST[ $name_prefix . 'survey_answer_letter_spacing_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_answer_letter_spacing_mobile' ] ))) : '0';
576
577 // Answer view
578 $survey_answers_view = (isset( $_POST[ $name_prefix . 'survey_answers_view' ] ) && $_POST[ $name_prefix . 'survey_answers_view' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_view' ] ) ) : 'list';
579
580 // Answer view alignment
581 $survey_answers_view_alignment = (isset( $_POST[ $name_prefix . 'survey_answers_view_alignment' ] ) && $_POST[ $name_prefix . 'survey_answers_view_alignment' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_view_alignment' ] ) ) : 'space-around';
582
583 // Answer object-fit
584 $survey_answers_object_fit = (isset( $_POST[ $name_prefix . 'survey_answers_object_fit' ] ) && $_POST[ $name_prefix . 'survey_answers_object_fit' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_object_fit' ] ) ) : 'cover';
585 // Answer object-fit mobile
586 $survey_answers_object_fit_mobile = (isset( $_POST[ $name_prefix . 'survey_answers_object_fit_mobile' ] ) && $_POST[ $name_prefix . 'survey_answers_object_fit_mobile' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_object_fit_mobile' ] ) ) : 'cover';
587
588 // Answer padding
589 $survey_answers_padding = (isset( $_POST[ $name_prefix . 'survey_answers_padding' ] ) && $_POST[ $name_prefix . 'survey_answers_padding' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_padding' ] ) ) : 8;
590
591 // Answer padding mobile
592 $survey_answers_padding_mobile = (isset( $_POST[ $name_prefix . 'survey_answers_padding_mobile' ] ) && $_POST[ $name_prefix . 'survey_answers_padding_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_padding_mobile' ] ) ) : 8;
593
594 // Answer Gap
595 $survey_answers_gap = (isset( $_POST[ $name_prefix . 'survey_answers_gap' ] ) && $_POST[ $name_prefix . 'survey_answers_gap' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_gap' ] ) ) : 0;
596
597 // Answer Gap mobile
598 $survey_answers_gap_mobile = (isset( $_POST[ $name_prefix . 'survey_answers_gap_mobile' ] ) && $_POST[ $name_prefix . 'survey_answers_gap_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_gap_mobile' ] ) ) : 0;
599
600 // Answer image size
601 $survey_answers_image_size = (isset( $_POST[ $name_prefix . 'survey_answers_image_size' ] ) && $_POST[ $name_prefix . 'survey_answers_image_size' ] != '' && $_POST[ $name_prefix . 'survey_answers_image_size' ] != 0) ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_image_size' ] ) ) : 195;
602 // Answer image size mobile
603 $survey_answers_image_size_mobile = (isset( $_POST[ $name_prefix . 'survey_answers_image_size_mobile' ] ) && $_POST[ $name_prefix . 'survey_answers_image_size_mobile' ] != '' && $_POST[ $name_prefix . 'survey_answers_image_size_mobile' ] != 0) ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_answers_image_size_mobile' ] ) ) : 195;
604
605 // =========== Answers Styles End ===========
606
607
608
609 // =========== Buttons Styles Start ===========
610
611 // Buttons background color
612 $survey_buttons_bg_color = (isset( $_POST[ $name_prefix . 'survey_button_bg_color' ] ) && $_POST[ $name_prefix . 'survey_button_bg_color' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_button_bg_color' ] ) : '#fff';
613
614 // Buttons size
615 $survey_buttons_size = (isset( $_POST[ $name_prefix . 'survey_buttons_size' ] ) && $_POST[ $name_prefix . 'survey_buttons_size' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_size' ] ) ) : 'medium';
616
617 // Buttons font size
618 $survey_buttons_font_size = (isset( $_POST[ $name_prefix . 'survey_buttons_font_size' ] ) && $_POST[ $name_prefix . 'survey_buttons_font_size' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_font_size' ] ) ) : 14;
619
620 // Buttons mobile font size
621 $survey_buttons_mobile_font_size = (isset( $_POST[ $name_prefix . 'survey_buttons_mobile_font_size' ] ) && $_POST[ $name_prefix . 'survey_buttons_mobile_font_size' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_mobile_font_size' ] ) ) : 14;
622
623 // Buttons Left / Right padding
624 $survey_buttons_left_right_padding = (isset( $_POST[ $name_prefix . 'survey_buttons_left_right_padding' ] ) && $_POST[ $name_prefix . 'survey_buttons_left_right_padding' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_left_right_padding' ] ) ) : 24;
625
626 // Buttons Top / Bottom padding
627 $survey_buttons_top_bottom_padding = (isset( $_POST[ $name_prefix . 'survey_buttons_top_bottom_padding' ] ) && $_POST[ $name_prefix . 'survey_buttons_top_bottom_padding' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_top_bottom_padding' ] ) ) : 0;
628
629 // Buttons border radius
630 $survey_buttons_border_radius = (isset( $_POST[ $name_prefix . 'survey_buttons_border_radius' ] ) && $_POST[ $name_prefix . 'survey_buttons_border_radius' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_border_radius' ] ) ) : 4;
631 // Buttons border radius mobile
632 $survey_buttons_border_radius_mobile = (isset( $_POST[ $name_prefix . 'survey_buttons_border_radius_mobile' ] ) && $_POST[ $name_prefix . 'survey_buttons_border_radius_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_border_radius_mobile' ] ) ) : 4;
633
634 // Buttons alignment
635 $survey_buttons_alignment = (isset( $_POST[ $name_prefix . 'survey_buttons_alignment' ] ) && $_POST[ $name_prefix . 'survey_buttons_alignment' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_alignment' ] ) : 'left';
636 // Buttons alignment mobile
637 $survey_buttons_alignment_mobile = (isset( $_POST[ $name_prefix . 'survey_buttons_alignment_mobile' ] ) && $_POST[ $name_prefix . 'survey_buttons_alignment_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_alignment_mobile' ] ) : 'left';
638
639 // Buttons top distance
640 $survey_buttons_top_distance = (isset( $_POST[ $name_prefix . 'survey_buttons_top_distance' ] ) && $_POST[ $name_prefix . 'survey_buttons_top_distance' ] != '') ? absint( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_top_distance' ] ) ) : 10;
641 // Buttons top distance mobile
642 $survey_buttons_top_distance_mobile = (isset( $_POST[ $name_prefix . 'survey_buttons_top_distance_mobile' ] ) && $_POST[ $name_prefix . 'survey_buttons_top_distance_mobile' ] != '') ? absint( sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_top_distance_mobile' ] ) ) : 10;
643
644 // Buttons text letter spacing
645 $survey_buttons_text_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing' ] ))) : '0';
646
647 // Buttons text letter spacing mobile
648 $survey_buttons_text_letter_spacing_mobile = (isset( $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing_mobile' ] ) && $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing_mobile' ] != '' && $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_buttons_text_letter_spacing_mobile' ] ))) : '0';
649
650 // =========== Buttons Styles End ===========
651
652
653 // =============================================================
654 // ====================== Styles Tab =====================
655 // ======================== END ========================
656
657
658 // ======================= // ======================= // ======================= // ======================= // ======================= //
659
660
661 // =============================================================
662 // ===================== Start page Tab ======================
663 // ======================== START =========================
664
665
666 // Enable start page
667 $survey_enable_start_page = (isset( $_POST[ $name_prefix . 'survey_enable_start_page' ] ) && $_POST[ $name_prefix . 'survey_enable_start_page' ] == 'on') ? 'on' : 'off';
668
669 // Start page Title
670 $survey_start_page_title = isset( $_POST[ $name_prefix . 'survey_start_page_title' ] ) && $_POST[ $name_prefix . 'survey_start_page_title' ] != '' ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_start_page_title' ] ) ) : '';
671
672 // Start page Title position
673 $survey_start_page_title_pos = (isset( $_POST[ $name_prefix . 'survey_start_page_title_pos' ] ) && $_POST[ $name_prefix . 'survey_start_page_title_pos' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_start_page_title_pos' ] ) : 'center';
674 // Start page Title position mobile
675 $survey_start_page_title_pos_mobile = (isset( $_POST[ $name_prefix . 'survey_start_page_title_pos_mobile' ] ) && $_POST[ $name_prefix . 'survey_start_page_title_pos_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_start_page_title_pos_mobile' ] ) : 'center';
676
677 // Start page description
678 $survey_start_page_description = (isset( $_POST[ $name_prefix . 'survey_start_page_description' ] ) && $_POST[ $name_prefix . 'survey_start_page_description' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_start_page_description' ] ) : '';
679
680 // Start button position
681 $survey_start_page_button_pos = (isset( $_POST[ $name_prefix . 'survey_start_page_button_pos' ] ) && $_POST[ $name_prefix . 'survey_start_page_button_pos' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_start_page_button_pos' ] ) : 'left';
682 // Start button position mobile
683 $survey_start_page_button_pos_mobile = (isset( $_POST[ $name_prefix . 'survey_start_page_button_pos_mobile' ] ) && $_POST[ $name_prefix . 'survey_start_page_button_pos_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_start_page_button_pos_mobile' ] ) : 'left';
684
685 // Start page Background color
686 $survey_start_page_background_color = (isset( $_POST[ $name_prefix . 'survey_start_page_background_color' ] ) && $_POST[ $name_prefix . 'survey_start_page_background_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_start_page_background_color' ] ) ) : '#fff';
687
688 // Start page Text Color
689 $survey_start_page_text_color = (isset( $_POST[ $name_prefix . 'survey_start_page_text_color' ] ) && $_POST[ $name_prefix . 'survey_start_page_text_color' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_start_page_text_color' ] ) ) : '#333';
690
691 // Start page Custom class
692 $survey_start_page_custom_class = (isset( $_POST[ $name_prefix . 'survey_start_page_custom_class' ] ) && $_POST[ $name_prefix . 'survey_start_page_custom_class' ] != '') ? stripslashes( esc_attr( $_POST[ $name_prefix . 'survey_start_page_custom_class' ] ) ) : '';
693
694
695 // =============================================================
696 // ==================== Start page Tab ===================
697 // ======================== END ========================
698
699
700 // =============================================================
701 // ====================== Settings Tab =======================
702 // ======================== START =========================
703
704 // Show survey title
705 $survey_show_title = (isset( $_POST[ $name_prefix . 'survey_show_title' ] ) && $_POST[ $name_prefix . 'survey_show_title' ] == 'on') ? 'on' : 'off';
706
707 // Show survey section header
708 $survey_show_section_header = (isset( $_POST[ $name_prefix . 'survey_show_section_header' ] ) && $_POST[ $name_prefix . 'survey_show_section_header' ] == 'on') ? 'on' : 'off';
709
710 // Enable randomize answers
711 $survey_enable_randomize_answers = (isset( $_POST[ $name_prefix . 'survey_enable_randomize_answers' ] ) && $_POST[ $name_prefix . 'survey_enable_randomize_answers' ] == 'on') ? 'on' : 'off';
712
713 // Enable randomize questions
714 $survey_enable_randomize_questions = (isset( $_POST[ $name_prefix . 'survey_enable_randomize_questions' ] ) && $_POST[ $name_prefix . 'survey_enable_randomize_questions' ] == 'on') ? 'on' : 'off';
715
716 // Enable randomize questions
717 $survey_enable_rtl_direction = (isset( $_POST[ $name_prefix . 'survey_enable_rtl_direction' ] ) && $_POST[ $name_prefix . 'survey_enable_rtl_direction' ] == 'on') ? 'on' : 'off';
718
719 // Enable clear answer button
720 $survey_enable_clear_answer = (isset( $_POST[ $name_prefix . 'survey_enable_clear_answer' ] ) && $_POST[ $name_prefix . 'survey_enable_clear_answer' ] == 'on') ? 'on' : 'off';
721
722 // Enable previous button
723 $survey_enable_previous_button = (isset( $_POST[ $name_prefix . 'survey_enable_previous_button' ] ) && $_POST[ $name_prefix . 'survey_enable_previous_button' ] == 'on') ? 'on' : 'off';
724
725 // Disable next button
726 $survey_disable_next_button = (isset( $_POST[ $name_prefix . 'survey_disable_next_button' ] ) && $_POST[ $name_prefix . 'survey_disable_next_button' ] == 'on') ? 'on' : 'off';
727
728 // Enable Survey Start loader
729 $survey_enable_survey_start_loader = (isset( $_POST[ $name_prefix . 'survey_enable_survey_start_loader' ] ) && $_POST[ $name_prefix . 'survey_enable_survey_start_loader' ] == 'on') ? 'on' : 'off';
730 $survey_before_start_loader = (isset( $_POST[ $name_prefix . 'survey_before_start_loader' ] ) && $_POST[ $name_prefix . 'survey_before_start_loader' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_before_start_loader' ] ) ) : 'default';
731
732 // Allow HTML in answers
733 $survey_allow_html_in_answers = (isset( $_POST[ $name_prefix . 'survey_allow_html_in_answers' ] ) && $_POST[ $name_prefix . 'survey_allow_html_in_answers' ] == 'on') ? 'on' : 'off';
734
735 // ---- Buttons settings Start ---- //
736 // Finish button text
737 $survey_finish_button_each_text = (isset($_POST[ $name_prefix . 'survey_finish_button_each_text' ]) && $_POST[ $name_prefix . 'survey_finish_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_finish_button_each_text' ]) ) : 'Finish';
738 // Next button text
739 $survey_next_button_each_text = (isset($_POST[ $name_prefix . 'survey_next_button_each_text' ]) && $_POST[ $name_prefix . 'survey_next_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_next_button_each_text' ]) ) : 'Next';
740 // Previous button text
741 $survey_previous_button_each_text = (isset($_POST[ $name_prefix . 'survey_previous_button_each_text' ]) && $_POST[ $name_prefix . 'survey_previous_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_previous_button_each_text' ]) ) : 'Prev';
742 // Restart button text
743 $survey_restart_button_each_text = (isset($_POST[ $name_prefix . 'survey_restart_button_each_text' ]) && $_POST[ $name_prefix . 'survey_restart_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_restart_button_each_text' ]) ) : 'Restart';
744 // Exit button text
745 $survey_exit_button_each_text = (isset($_POST[ $name_prefix . 'survey_exit_button_each_text' ]) && $_POST[ $name_prefix . 'survey_exit_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_exit_button_each_text' ]) ) : 'Exit';
746 // Clear selection button text
747 $survey_clear_selection_button_each_text = (isset($_POST[ $name_prefix . 'survey_clear_selection_button_each_text' ]) && $_POST[ $name_prefix . 'survey_clear_selection_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_clear_selection_button_each_text' ]) ) : 'Clear selection';
748 // Start button text
749 $survey_start_button_each_text = (isset($_POST[ $name_prefix . 'survey_start_button_each_text' ]) && $_POST[ $name_prefix . 'survey_start_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_start_button_each_text' ]) ) : 'Start';
750 // Login button text
751 $survey_login_button_each_text = (isset($_POST[ $name_prefix . 'survey_login_button_each_text' ]) && $_POST[ $name_prefix . 'survey_login_button_each_text' ] != '') ? stripslashes( sanitize_text_field($_POST[ $name_prefix . 'survey_login_button_each_text' ]) ) : 'Log in';
752 // ---- Buttons settings End ---- //
753
754 // Allow HTML in section description
755 $survey_allow_html_in_section_description = (isset( $_POST[ $name_prefix . 'survey_allow_html_in_section_description' ] ) && $_POST[ $name_prefix . 'survey_allow_html_in_section_description' ] == 'on') ? 'on' : 'off';
756
757 // Enable confirmation box for leaving the page
758 $survey_enable_leave_page = (isset( $_POST[ $name_prefix . 'survey_enable_leave_page' ] ) && $_POST[ $name_prefix . 'survey_enable_leave_page' ] == 'on') ? 'on' : 'off';
759
760 // Autofill information
761 $survey_info_autofill = (isset( $_POST[ $name_prefix . 'survey_enable_info_autofill' ] ) && $_POST[ $name_prefix . 'survey_enable_info_autofill' ] == 'on') ? 'on' : 'off';
762
763 //---- Schedule Start ---- //
764
765 // Schedule the Survey
766 $survey_enable_schedule = (isset( $_POST[ $name_prefix . 'survey_enable_schedule' ] ) && $_POST[ $name_prefix . 'survey_enable_schedule' ] == 'on') ? 'on' : 'off';
767
768 // Start date
769 $survey_schedule_active = (isset( $_POST[ $name_prefix . 'survey_schedule_active' ] ) && $_POST[ $name_prefix . 'survey_schedule_active' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_schedule_active' ] ) ) : '';
770
771 // End date
772 $survey_schedule_deactive = (isset( $_POST[ $name_prefix . 'survey_schedule_deactive' ] ) && $_POST[ $name_prefix . 'survey_schedule_deactive' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_schedule_deactive' ] ) ) : '';
773
774 // Show timer
775 $survey_schedule_show_timer = (isset( $_POST[ $name_prefix . 'survey_schedule_show_timer' ] ) && $_POST[ $name_prefix . 'survey_schedule_show_timer' ] == 'on') ? 'on' : 'off';
776
777 // Show countdown / start date
778 $survey_show_timer_type = (isset( $_POST[ $name_prefix . 'survey_show_timer_type' ] ) && $_POST[ $name_prefix . 'survey_show_timer_type' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_show_timer_type' ] ) ) : 'countdown';
779
780 // Pre start message
781 $survey_schedule_pre_start_message = (isset( $_POST[ $name_prefix . 'survey_schedule_pre_start_message' ] ) && $_POST[ $name_prefix . 'survey_schedule_pre_start_message' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_schedule_pre_start_message' ] ) : __("The survey will be available soon!", "survey-maker");
782
783 // Expiration message
784 $survey_schedule_expiration_message = (isset( $_POST[ $name_prefix . 'survey_schedule_expiration_message' ] ) && $_POST[ $name_prefix . 'survey_schedule_expiration_message' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_schedule_expiration_message' ] ) : __("This survey has expired!", "survey-maker");
785
786 // Dont Show Survey
787 $survey_dont_show_survey_container = (isset( $_POST[ $name_prefix . 'survey_dont_show_survey_container' ] ) && $_POST[ $name_prefix . 'survey_dont_show_survey_container' ] == 'on') ? 'on' : 'off';
788
789 //---- Schedule End ---- //
790
791 // Survey full screen mode
792 $survey_full_screen = isset( $_POST[ $name_prefix . 'survey_enable_full_screen_mode' ] ) && $_POST[ $name_prefix . 'survey_enable_full_screen_mode' ] == 'on' ? 'on' : 'off';
793 $survey_full_screen_button_color = isset( $_POST[ $name_prefix . 'survey_full_screen_button_color' ] ) && $_POST[ $name_prefix . 'survey_full_screen_button_color' ] != '' ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_full_screen_button_color' ] ) ) : '#333';
794
795 // Survey progress bar
796 $survey_enable_progress_bar = isset( $_POST[ $name_prefix . 'survey_enable_progres_bar' ] ) && $_POST[ $name_prefix . 'survey_enable_progres_bar' ] == 'on' ? 'on' : 'off';
797 $survey_hide_section_pagination_text = isset( $_POST[ $name_prefix . 'survey_hide_section_pagination_text' ] ) && $_POST[ $name_prefix . 'survey_hide_section_pagination_text' ] == 'on' ? 'on' : 'off';
798 $survey_pagination_positioning = isset( $_POST[ $name_prefix . 'survey_pagination_positioning' ] ) && $_POST[ $name_prefix . 'survey_pagination_positioning' ] != '' ? sanitize_text_field($_POST[ $name_prefix . 'survey_pagination_positioning' ]) : 'none';
799 $survey_pagination_positioning_mobile = isset( $_POST[ $name_prefix . 'survey_pagination_positioning_mobile' ] ) && $_POST[ $name_prefix . 'survey_pagination_positioning_mobile' ] != '' ? sanitize_text_field($_POST[ $name_prefix . 'survey_pagination_positioning_mobile' ]) : 'none';
800 $survey_hide_section_bar = isset( $_POST[ $name_prefix . 'survey_hide_section_bar' ] ) && $_POST[ $name_prefix . 'survey_hide_section_bar' ] == 'on' ? 'on' : 'off';
801 $survey_progress_bar_text = isset( $_POST[ $name_prefix . 'survey_progress_bar_text' ] ) && $_POST[ $name_prefix . 'survey_progress_bar_text' ] != '' ? sanitize_text_field($_POST[ $name_prefix . 'survey_progress_bar_text' ]) : 'Page';
802 $survey_progress_bar_text_letter_spacing = (isset( $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing' ] ) && $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing' ] != '' && $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing' ] ))) : '0';
803 $survey_progress_bar_text_letter_spacing_mobile = (isset( $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing_mobile' ] ) && $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing_mobile' ] != '' && $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing_mobile' ] != '0' ) ? absint(intval(sanitize_text_field( $_POST[ $name_prefix . 'survey_progress_bar_text_letter_spacing_mobile' ] ))) : '0';
804 $survey_pagination_text_color = isset( $_POST[ $name_prefix . 'survey_pagination_text_color' ] ) && $_POST[ $name_prefix . 'survey_pagination_text_color' ] != '' ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_pagination_text_color' ] ) ) : '#333';
805 $survey_pagination_text_color_mobile = isset( $_POST[ $name_prefix . 'survey_pagination_text_color_mobile' ] ) && $_POST[ $name_prefix . 'survey_pagination_text_color_mobile' ] != '' ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_pagination_text_color_mobile' ] ) ) : '#333';
806 $survey_progress_bar_text_font_size = (isset( $_POST[ $name_prefix . 'survey_progress_bar_text_font_size' ] ) && $_POST[ $name_prefix . 'survey_progress_bar_text_font_size' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_progress_bar_text_font_size' ] ) ) : 15;
807 $survey_progress_bar_text_font_size_on_mobile = (isset( $_POST[ $name_prefix . 'survey_progress_bar_text_font_size_on_mobile' ] ) && $_POST[ $name_prefix . 'survey_progress_bar_text_font_size_on_mobile' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_progress_bar_text_font_size_on_mobile' ] ) ) : $survey_progress_bar_text_font_size;
808 $survey_progress_bar_text_transform = (isset( $_POST[ $name_prefix . 'survey_progress_bar_text_transform' ] ) && $_POST[ $name_prefix . 'survey_progress_bar_text_transform' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_progress_bar_text_transform' ] ) : 'none';
809 $survey_progress_bar_text_transform_mobile = (isset( $_POST[ $name_prefix . 'survey_progress_bar_text_transform_mobile' ] ) && $_POST[ $name_prefix . 'survey_progress_bar_text_transform_mobile' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_progress_bar_text_transform_mobile' ] ) : 'none';
810 // Survey show sections questions count
811 $survey_show_sections_questions_count = isset( $_POST[ $name_prefix . 'survey_show_questions_count' ] ) && $_POST[ $name_prefix . 'survey_show_questions_count' ] == 'on' ? 'on' : 'off';
812
813 // Survey required questions message
814 $survey_required_questions_message = isset( $_POST[ $name_prefix . 'survey_required_questions_message' ] ) && $_POST[ $name_prefix . 'survey_required_questions_message' ] != '' ? sanitize_text_field($_POST[ $name_prefix . 'survey_required_questions_message' ]) : '';
815
816 // Change the author of the current quiz
817 $survey_change_create_author = ( isset($_POST[$name_prefix . 'survey_change_create_author' ]) && $_POST[$name_prefix . 'survey_change_create_author'] != "" ) ? absint( sanitize_text_field( $_POST[$name_prefix . 'survey_change_create_author'] ) ) : '';
818
819 if ( $survey_change_create_author != "" && $survey_change_create_author > 0 ) {
820 $user = get_userdata($survey_change_create_author);
821 if ( ! is_null( $user ) && $user ) {
822 $survey_author = array(
823 'id' => $user->ID."",
824 'name' => $user->data->display_name
825 );
826 $author_id = $survey_author['id'];
827
828 } else {
829 $author_data = json_decode($author, true);
830 $survey_change_create_author = (isset( $author_data['id'] ) && $author_data['id'] != "") ? absint( sanitize_text_field( $author_data['id'] ) ) : get_current_user_id();
831 $author_id = $survey_change_create_author;
832 }
833 }
834
835
836
837 // =============================================================
838 // ====================== Settings Tab =======================
839 // ======================== END =========================
840
841
842 // ======================= // ======================= // ======================= // ======================= // ======================= //
843
844
845 // =============================================================
846 // =================== Results Settings Tab ===================
847 // ======================== START =========================
848
849
850 // Redirect after submit
851 $survey_redirect_after_submit = (isset( $_POST[ $name_prefix . 'survey_redirect_after_submit' ] ) && $_POST[ $name_prefix . 'survey_redirect_after_submit' ] == 'on') ? 'on' : 'off';
852
853 // Redirect URL
854 $survey_submit_redirect_url = (isset( $_POST[ $name_prefix . 'survey_submit_redirect_url' ] ) && $_POST[ $name_prefix . 'survey_submit_redirect_url' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_submit_redirect_url' ] ) ) : '';
855
856 // Redirect delay (sec)
857 $survey_submit_redirect_delay = (isset( $_POST[ $name_prefix . 'survey_submit_redirect_delay' ] ) && $_POST[ $name_prefix . 'survey_submit_redirect_delay' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_submit_redirect_delay' ] ) ) : '';
858
859 // Redirect in new tab
860 $survey_submit_redirect_new_tab = (isset( $_POST[ $name_prefix . 'survey_submit_redirect_new_tab' ] ) && $_POST[ $name_prefix . 'survey_submit_redirect_new_tab' ] == 'on') ? 'on' : 'off';
861
862 // Enable EXIT button
863 $survey_enable_exit_button = (isset( $_POST[ $name_prefix . 'survey_enable_exit_button' ] ) && $_POST[ $name_prefix . 'survey_enable_exit_button' ] == 'on') ? 'on' : 'off';
864
865 // Redirect URL
866 $survey_exit_redirect_url = (isset( $_POST[ $name_prefix . 'survey_exit_redirect_url' ] ) && $_POST[ $name_prefix . 'survey_exit_redirect_url' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_exit_redirect_url' ] ) ) : '';
867
868 // Enable restart button
869 $survey_enable_restart_button = (isset( $_POST[ $name_prefix . 'survey_enable_restart_button' ] ) && $_POST[ $name_prefix . 'survey_enable_restart_button' ] == 'on') ? 'on' : 'off';
870
871 // Thank you message
872 $survey_final_result_text = (isset( $_POST[ $name_prefix . 'survey_final_result_text' ] ) && $_POST[ $name_prefix . 'survey_final_result_text' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_final_result_text' ] ) : '';
873
874 // Thank you message
875 $survey_main_url = (isset( $_POST[ $name_prefix . 'survey_main_url' ] ) && $_POST[ $name_prefix . 'survey_main_url' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_main_url' ] ) : '';
876
877 // Show questions as html
878 $survey_show_questions_as_html = (isset( $_POST[ $name_prefix . 'survey_show_questions_as_html' ] ) && $_POST[ $name_prefix . 'survey_show_questions_as_html' ] == 'on') ? 'on' : 'off';
879
880 // Select survey loader
881 $survey_loader = (isset( $_POST[ $name_prefix . 'survey_loader' ] ) && $_POST[ $name_prefix . 'survey_loader' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_loader' ] ) ) : 'default';
882
883 // Social share buttons
884 $survey_social_buttons = ( isset( $_POST[ $name_prefix . 'survey_social_buttons' ] ) && $_POST[ $name_prefix . 'survey_social_buttons' ] == 'on' ) ? 'on' : 'off';
885 $survey_social_buttons_heading = ( isset( $_POST[ $name_prefix . 'survey_social_buttons_heading' ] ) && $_POST[ $name_prefix . 'survey_social_buttons_heading' ] != '' ) ? wp_kses_post($_POST[ $name_prefix . 'survey_social_buttons_heading' ]) : '';
886 $survey_social_button_ln = ( isset( $_POST[ $name_prefix . 'survey_enable_linkedin_share_button' ] ) && $_POST[ $name_prefix . 'survey_enable_linkedin_share_button' ] == 'on' ) ? 'on' : 'off';
887 $survey_social_button_fb = ( isset( $_POST[ $name_prefix . 'survey_enable_facebook_share_button' ] ) && $_POST[ $name_prefix . 'survey_enable_facebook_share_button' ] == 'on' ) ? 'on' : 'off';
888 $survey_social_button_tr = ( isset( $_POST[ $name_prefix . 'survey_enable_twitter_share_button' ] ) && $_POST[ $name_prefix . 'survey_enable_twitter_share_button' ] == 'on' ) ? 'on' : 'off';
889 $survey_social_button_vk = ( isset( $_POST[ $name_prefix . 'survey_enable_vkontakte_share_button' ] ) && $_POST[ $name_prefix . 'survey_enable_vkontakte_share_button' ] == 'on' ) ? 'on' : 'off';
890
891 // Auto numbering questions
892 $survey_auto_numbering_questions = (isset( $_POST[ $name_prefix . 'survey_show_question_numbering' ] ) && $_POST[ $name_prefix . 'survey_show_question_numbering' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_show_question_numbering' ] ) : 'none';
893
894 // =============================================================
895 // =================== Results Settings Tab ===================
896 // ======================== END ==========================
897
898
899 // ======================= // ======================= // ======================= // ======================= // ======================= //
900
901
902 // =============================================================
903 // =================== Limitation Tab ===================
904 // ======================== START =========================
905
906 // Maximum number of attempts per user
907 $survey_limit_users = (isset( $_POST[ $name_prefix . 'survey_limit_users' ] ) && $_POST[ $name_prefix . 'survey_limit_users' ] == 'on') ? 'on' : 'off';
908
909 // Detects users by IP / ID
910 $survey_limit_users_by = (isset( $_POST[ $name_prefix . 'survey_limit_users_by' ] ) && $_POST[ $name_prefix . 'survey_limit_users_by' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_limit_users_by' ] ) ) : 'ip';
911 $survey_limit_users_by = (isset( $_POST[ $name_prefix . 'survey_limit_users_by' ] ) && $_POST[ $name_prefix . 'survey_limit_users_by' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_limit_users_by' ] ) ) : 'ip';
912
913 // Attempts count
914 $survey_max_pass_count = (isset( $_POST[ $name_prefix . 'survey_max_pass_count' ] ) && $_POST[ $name_prefix . 'survey_max_pass_count' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_max_pass_count' ] ) ) : 1;
915
916 // Limitation Message
917 $survey_limitation_message = (isset( $_POST[ $name_prefix . 'survey_limitation_message' ] ) && $_POST[ $name_prefix . 'survey_limitation_message' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_limitation_message' ] ) : '';
918
919 // Redirect Url
920 $survey_redirect_url = (isset( $_POST[ $name_prefix . 'survey_redirect_url' ] ) && $_POST[ $name_prefix . 'survey_redirect_url' ] != '') ? stripslashes( sanitize_text_field( $_POST[ $name_prefix . 'survey_redirect_url' ] ) ) : '';
921
922 // Redirect delay
923 $survey_redirect_delay = (isset( $_POST[ $name_prefix . 'survey_redirection_delay' ] ) && $_POST[ $name_prefix . 'survey_redirection_delay' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_redirection_delay' ] ) ) : 0;
924
925 // Only for logged in users
926 $survey_enable_logged_users = (isset( $_POST[ $name_prefix . 'survey_enable_logged_users' ] ) && $_POST[ $name_prefix . 'survey_enable_logged_users' ] == 'on') ? 'on' : 'off';
927
928 // Message - Only for logged in users
929 $survey_logged_in_message = (isset( $_POST[ $name_prefix . 'survey_logged_in_message' ] ) && $_POST[ $name_prefix . 'survey_logged_in_message' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_logged_in_message' ] ) : '';
930
931 // Show login form
932 $survey_show_login_form = (isset( $_POST[ $name_prefix . 'survey_show_login_form' ] ) && $_POST[ $name_prefix . 'survey_show_login_form' ] == 'on') ? 'on' : 'off';
933
934 //limitation takers count
935 $survey_enable_takers_count = (isset( $_POST[ $name_prefix . 'survey_enable_tackers_count' ] ) && $_POST[ $name_prefix . 'survey_enable_tackers_count' ] == 'on') ? 'on' : 'off';
936
937 // Takers count
938 $survey_takers_count = (isset( $_POST[ $name_prefix . 'survey_tackers_count' ] ) && $_POST[ $name_prefix . 'survey_tackers_count' ] != '') ? absint ( sanitize_text_field( $_POST[ $name_prefix . 'survey_tackers_count' ] ) ) : 1;
939
940
941 // =============================================================
942 // =================== Limitation Tab ===================
943 // ======================== END ==========================
944
945 // ======================= // ======================= // ======================= // ======================= // ======================= //
946
947 // =============================================================
948 // ===================== E-Mail Tab =====================
949 // ======================== START =========================
950
951
952 // Send Mail To User
953 $survey_enable_mail_user = (isset( $_POST[ $name_prefix . 'survey_enable_mail_user' ] ) && $_POST[ $name_prefix . 'survey_enable_mail_user' ] == 'on') ? 'on' : 'off';
954
955 // Email message
956 $survey_mail_message = (isset( $_POST[ $name_prefix . 'survey_mail_message' ] ) && $_POST[ $name_prefix . 'survey_mail_message' ] != '') ? wp_kses_post( $_POST[ $name_prefix . 'survey_mail_message' ] ) : '';
957
958 // Send email to admin
959 $survey_enable_mail_admin = (isset( $_POST[ $name_prefix . 'survey_enable_mail_admin' ] ) && $_POST[ $name_prefix . 'survey_enable_mail_admin' ] == 'on') ? 'on' : 'off';
960
961 // Send email to site admin ( SuperAdmin )
962 $survey_send_mail_to_site_admin = (isset( $_POST[ $name_prefix . 'survey_send_mail_to_site_admin' ] ) && $_POST[ $name_prefix . 'survey_send_mail_to_site_admin' ] == 'on') ? 'on' : 'off';
963
964
965 // Additional emails
966 $survey_additional_emails = "";
967 if( isset( $_POST[ $name_prefix . 'survey_additional_emails' ] ) ) {
968 if(!empty( $_POST[ $name_prefix . 'survey_additional_emails' ] )) {
969 $additional_emails_arr = explode(",", $_POST[ $name_prefix . 'survey_additional_emails' ] );
970 foreach($additional_emails_arr as $email) {
971 $email = stripslashes(trim($email));
972 if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
973 $survey_additional_emails .= $email.", ";
974 }
975 }
976 $survey_additional_emails = substr($survey_additional_emails, 0, -2);
977 }
978 }
979
980 // Email message
981 $survey_mail_message_admin = (isset( $_POST[ $name_prefix . 'survey_mail_message_admin' ] ) && $_POST[ $name_prefix . 'survey_mail_message_admin' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_mail_message_admin' ] ) : '';
982
983
984 //---- Email configuration Start ---- //
985
986 // From email
987 $survey_email_configuration_from_email = (isset( $_POST[ $name_prefix . 'survey_email_configuration_from_email' ] ) && $_POST[ $name_prefix . 'survey_email_configuration_from_email' ] != '') ? stripslashes ( sanitize_email( $_POST[ $name_prefix . 'survey_email_configuration_from_email' ] ) ) : '';
988
989 // From name
990 $survey_email_configuration_from_name = (isset( $_POST[ $name_prefix . 'survey_email_configuration_from_name' ] ) && $_POST[ $name_prefix . 'survey_email_configuration_from_name' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_email_configuration_from_name' ] ) ) : '';
991
992 // Subject
993 $survey_email_configuration_from_subject = (isset( $_POST[ $name_prefix . 'survey_email_configuration_from_subject' ] ) && $_POST[ $name_prefix . 'survey_email_configuration_from_subject' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_email_configuration_from_subject' ] ) ) : '';
994
995 // Reply to email
996 $survey_email_configuration_replyto_email = (isset( $_POST[ $name_prefix . 'survey_email_configuration_replyto_email' ] ) && $_POST[ $name_prefix . 'survey_email_configuration_replyto_email' ] != '') ? stripslashes ( sanitize_email( $_POST[ $name_prefix . 'survey_email_configuration_replyto_email' ] ) ) : '';
997
998 // Reply to name
999 $survey_email_configuration_replyto_name = (isset( $_POST[ $name_prefix . 'survey_email_configuration_replyto_name' ] ) && $_POST[ $name_prefix . 'survey_email_configuration_replyto_name' ] != '') ? stripslashes ( sanitize_text_field( $_POST[ $name_prefix . 'survey_email_configuration_replyto_name' ] ) ) : '';
1000
1001 //---- Email configuration End ---- //
1002
1003 // Reply to name
1004 $survey_logo_url_new_tab = (isset( $_POST[ $name_prefix . 'survey_logo_enable_image_url_new_tab' ] ) && $_POST[ $name_prefix . 'survey_logo_enable_image_url_new_tab' ] == 'on') ? "on" : 'off';
1005
1006 // =============================================================
1007 // ===================== E-Mail Tab =====================
1008 // ======================== END ==========================
1009
1010 // Auto numbering
1011 $survey_auto_numbering = (isset( $_POST[ $name_prefix . 'survey_show_answers_numbering' ] ) && $_POST[ $name_prefix . 'survey_show_answers_numbering' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_show_answers_numbering' ] ) : 'none';
1012
1013 // Loader text
1014 $survey_loader_text = (isset( $_POST[ $name_prefix . 'survey_loader_text_value' ] ) && $_POST[ $name_prefix . 'survey_loader_text_value' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_loader_text_value' ] ) : '';
1015 // Loader Gif
1016 $survey_loader_gif = (isset( $_POST[ $name_prefix . 'survey_loader_custom_gif' ] ) && $_POST[ $name_prefix . 'survey_loader_custom_gif' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_loader_custom_gif' ] ) : '';
1017 if ($survey_loader_gif != '' && exif_imagetype( $survey_loader_gif ) != IMAGETYPE_GIF) {
1018 $survey_loader_gif = '';
1019 }
1020 $survey_loader_gif_width = (isset( $_POST[ $name_prefix . 'survey_loader_custom_gif_width' ] ) && $_POST[ $name_prefix . 'survey_loader_custom_gif_width' ] != '') ? sanitize_text_field( $_POST[ $name_prefix . 'survey_loader_custom_gif_width' ] ) : '100';
1021 if($survey_loader_gif_width <= "0"){
1022 $survey_loader_gif_width = "100";
1023 }
1024
1025 // Options
1026 $options = array(
1027 'survey_version' => SURVEY_MAKER_VERSION,
1028 // Styles Tab
1029 'survey_theme' => $survey_theme,
1030 'survey_color' => $survey_color,
1031 'survey_background_color' => $survey_background_color,
1032 'survey_text_color' => $survey_text_color,
1033 'survey_loader_color' => $survey_loader_color,
1034 'survey_buttons_text_color' => $survey_buttons_text_color,
1035 'survey_width' => $survey_width,
1036 'survey_width_by_percentage_px' => $survey_width_by_percentage_px,
1037 'survey_mobile_width' => $survey_mobile_width,
1038 'survey_mobile_width_by_percent_px' => $survey_mobile_width_by_percentage_px,
1039 'survey_mobile_max_width' => $survey_mobile_max_width,
1040 'survey_custom_class' => $survey_custom_class,
1041 'survey_custom_css' => $survey_custom_css,
1042 'survey_logo' => $survey_logo,
1043 'survey_logo_url' => $survey_logo_image_url,
1044 'survey_enable_logo_url' => $survey_logo_image_url_check,
1045 'survey_logo_image_position' => $survey_logo_image_position,
1046 'survey_logo_image_position_mobile' => $survey_logo_image_position_mobile,
1047 'survey_logo_title' => $survey_logo_title,
1048 'survey_cover_photo' => $survey_cover_photo,
1049 'survey_cover_photo_height' => $survey_cover_photo_height,
1050 'survey_cover_photo_mobile_height' => $survey_cover_photo_mobile_height,
1051 'survey_cover_photo_position' => $survey_cover_photo_position,
1052 'survey_cover_photo_object_fit' => $survey_cover_photo_object_fit,
1053 'survey_cover_only_first_section' => $survey_cover_only_first_section,
1054
1055 'survey_question_font_size' => $survey_question_font_size,
1056 'survey_question_font_size_mobile' => $survey_question_font_size_mobile,
1057 'survey_question_title_alignment' => $survey_question_title_alignment,
1058 'survey_question_image_width' => $survey_question_image_width,
1059 'survey_question_image_width_mobile' => $survey_question_image_width_mobile,
1060 'survey_question_image_height' => $survey_question_image_height,
1061 'survey_question_image_height_mobile' => $survey_question_image_height_mobile,
1062 'survey_question_image_sizing' => $survey_question_image_sizing,
1063 'survey_question_image_sizing_mobile' => $survey_question_image_sizing_mobile,
1064 'survey_question_padding' => $survey_question_padding,
1065 'survey_question_padding_mobile' => $survey_question_padding_mobile,
1066 'survey_question_border_radius' => $survey_question_border_radius,
1067 'survey_question_border_radius_mobile' => $survey_question_border_radius_mobile,
1068 'survey_question_caption_text_color' => $survey_question_caption_text_color,
1069 'survey_question_caption_text_color_mobile' => $survey_question_caption_text_color_mobile,
1070 'survey_question_caption_text_alignment' => $survey_question_caption_text_alignment,
1071 'survey_question_caption_text_alignment_on_mobile' => $survey_question_caption_text_alignment_on_mobile,
1072 'survey_question_caption_font_size' => $survey_question_caption_font_size,
1073 'survey_question_caption_font_size_on_mobile' => $survey_question_caption_font_size_on_mobile,
1074 'survey_question_caption_text_transform' => $survey_question_caption_text_transform,
1075 'survey_question_caption_text_transform_mobile' => $survey_question_caption_text_transform_mobile,
1076 'survey_question_caption_letter_spacing' => $survey_question_caption_letter_spacing,
1077 'survey_question_caption_letter_spacing_mobile' => $survey_question_caption_letter_spacing_mobile,
1078 'survey_question_caption_hide_on_mobile' => $survey_question_caption_hide_on_mobile,
1079
1080 'survey_answer_font_size' => $survey_answer_font_size,
1081 'survey_answer_font_size_on_mobile' => $survey_answer_font_size_on_mobile,
1082 'survey_answer_letter_spacing' => $survey_answer_letter_spacing,
1083 'survey_answer_letter_spacing_mobile' => $survey_answer_letter_spacing_mobile,
1084 'survey_answers_view' => $survey_answers_view,
1085 'survey_answers_view_alignment' => $survey_answers_view_alignment,
1086 'survey_answers_object_fit' => $survey_answers_object_fit,
1087 'survey_answers_object_fit_mobile' => $survey_answers_object_fit_mobile,
1088 'survey_answers_padding' => $survey_answers_padding,
1089 'survey_answers_padding_mobile' => $survey_answers_padding_mobile,
1090 'survey_answers_gap' => $survey_answers_gap,
1091 'survey_answers_gap_mobile' => $survey_answers_gap_mobile,
1092 'survey_answers_image_size' => $survey_answers_image_size,
1093 'survey_answers_image_size_mobile' => $survey_answers_image_size_mobile,
1094
1095 'survey_buttons_bg_color' => $survey_buttons_bg_color,
1096 'survey_buttons_size' => $survey_buttons_size,
1097 'survey_buttons_font_size' => $survey_buttons_font_size,
1098 'survey_buttons_mobile_font_size' => $survey_buttons_mobile_font_size,
1099 'survey_buttons_left_right_padding' => $survey_buttons_left_right_padding,
1100 'survey_buttons_top_bottom_padding' => $survey_buttons_top_bottom_padding,
1101 'survey_buttons_border_radius' => $survey_buttons_border_radius,
1102 'survey_buttons_border_radius_mobile' => $survey_buttons_border_radius_mobile,
1103 'survey_buttons_alignment' => $survey_buttons_alignment,
1104 'survey_buttons_alignment_mobile' => $survey_buttons_alignment_mobile,
1105 'survey_buttons_top_distance' => $survey_buttons_top_distance,
1106 'survey_buttons_top_distance_mobile' => $survey_buttons_top_distance_mobile,
1107 'survey_buttons_text_letter_spacing' => $survey_buttons_text_letter_spacing,
1108 'survey_buttons_text_letter_spacing_mobile' => $survey_buttons_text_letter_spacing_mobile,
1109 'survey_title_alignment' => $survey_title_alignment,
1110 'survey_title_alignment_mobile' => $survey_title_alignment_mobile,
1111 'survey_title_font_size' => $survey_title_font_size,
1112 'survey_title_font_size_for_mobile' => $survey_title_font_size_for_mobile,
1113 'survey_title_letter_spacing' => $survey_title_letter_spacing,
1114 'survey_title_letter_spacing_mobile' => $survey_title_letter_spacing_mobile,
1115 'survey_title_box_shadow_enable' => $survey_title_box_shadow_enable,
1116 'survey_title_box_shadow_color' => $survey_title_box_shadow_color,
1117 'survey_title_text_shadow_x_offset' => $survey_title_text_shadow_x_offset,
1118 'survey_title_text_shadow_y_offset' => $survey_title_text_shadow_y_offset,
1119 'survey_title_text_shadow_z_offset' => $survey_title_text_shadow_z_offset,
1120 'survey_section_title_font_size' => $survey_section_title_font_size,
1121 'survey_section_title_font_size_mobile' => $survey_section_title_font_size_mobile,
1122 'survey_section_title_alignment' => $survey_section_title_alignment,
1123 'survey_section_title_alignment_mobile' => $survey_section_title_alignment_mobile,
1124 'survey_section_title_letter_spacing' => $survey_section_title_letter_spacing,
1125 'survey_section_title_letter_spacing_mobile' => $survey_section_title_letter_spacing_mobile,
1126 'survey_section_description_alignment' => $survey_section_description_alignment,
1127 'survey_section_description_alignment_mobile' => $survey_section_description_alignment_mobile,
1128 'survey_section_description_font_size' => $survey_section_description_font_size,
1129 'survey_section_description_font_size_mobile' => $survey_section_description_font_size_mobile,
1130 'survey_section_description_letter_spacing' => $survey_section_description_letter_spacing,
1131 'survey_section_description_letter_spacing_mobile' => $survey_section_description_letter_spacing_mobile,
1132
1133 // Start page tab
1134 'survey_enable_start_page' => $survey_enable_start_page,
1135 'survey_start_page_title' => $survey_start_page_title,
1136 'survey_start_page_title_pos' => $survey_start_page_title_pos,
1137 'survey_start_page_title_pos_mobile' => $survey_start_page_title_pos_mobile,
1138 'survey_start_page_description' => $survey_start_page_description,
1139 'survey_start_page_button_pos' => $survey_start_page_button_pos,
1140 'survey_start_page_button_pos_mobile' => $survey_start_page_button_pos_mobile,
1141 'survey_start_page_background_color' => $survey_start_page_background_color,
1142 'survey_start_page_text_color' => $survey_start_page_text_color,
1143 'survey_start_page_custom_class' => $survey_start_page_custom_class,
1144
1145 // Settings Tab
1146 'survey_show_title' => $survey_show_title,
1147 'survey_show_section_header' => $survey_show_section_header,
1148 'survey_enable_randomize_answers' => $survey_enable_randomize_answers,
1149 'survey_enable_randomize_questions' => $survey_enable_randomize_questions,
1150 'survey_enable_rtl_direction' => $survey_enable_rtl_direction,
1151 'survey_enable_clear_answer' => $survey_enable_clear_answer,
1152 'survey_enable_previous_button' => $survey_enable_previous_button,
1153 'survey_disable_next_button' => $survey_disable_next_button,
1154 'survey_enable_survey_start_loader' => $survey_enable_survey_start_loader,
1155 'survey_before_start_loader' => $survey_before_start_loader,
1156 'survey_allow_html_in_answers' => $survey_allow_html_in_answers,
1157 'survey_finish_button_each_text' => $survey_finish_button_each_text,
1158 'survey_next_button_each_text' => $survey_next_button_each_text,
1159 'survey_previous_button_each_text' => $survey_previous_button_each_text,
1160 'survey_restart_button_each_text' => $survey_restart_button_each_text,
1161 'survey_exit_button_each_text' => $survey_exit_button_each_text,
1162 'survey_clear_selection_button_each_text' => $survey_clear_selection_button_each_text,
1163 'survey_start_button_each_text' => $survey_start_button_each_text,
1164 'survey_login_button_each_text' => $survey_login_button_each_text,
1165 'survey_allow_html_in_section_description' => $survey_allow_html_in_section_description,
1166 'survey_enable_leave_page' => $survey_enable_leave_page,
1167 'survey_auto_numbering' => $survey_auto_numbering,
1168 'survey_enable_info_autofill' => $survey_info_autofill,
1169 'survey_auto_numbering_questions' => $survey_auto_numbering_questions,
1170
1171 'survey_enable_schedule' => $survey_enable_schedule,
1172 'survey_schedule_active' => $survey_schedule_active,
1173 'survey_schedule_deactive' => $survey_schedule_deactive,
1174 'survey_schedule_show_timer' => $survey_schedule_show_timer,
1175 'survey_show_timer_type' => $survey_show_timer_type,
1176 'survey_schedule_pre_start_message' => $survey_schedule_pre_start_message,
1177 'survey_schedule_expiration_message'=> $survey_schedule_expiration_message,
1178 'survey_dont_show_survey_container' => $survey_dont_show_survey_container,
1179
1180 'survey_logo_url_new_tab' => $survey_logo_url_new_tab,
1181 'survey_full_screen_mode' => $survey_full_screen,
1182 'survey_full_screen_button_color' => $survey_full_screen_button_color,
1183 'survey_enable_progress_bar' => $survey_enable_progress_bar,
1184 'survey_hide_section_pagination_text' => $survey_hide_section_pagination_text,
1185 'survey_pagination_positioning' => $survey_pagination_positioning,
1186 'survey_pagination_positioning_mobile' => $survey_pagination_positioning_mobile,
1187 'survey_hide_section_bar' => $survey_hide_section_bar,
1188 'survey_progress_bar_text' => $survey_progress_bar_text,
1189 'survey_progress_bar_text_letter_spacing' => $survey_progress_bar_text_letter_spacing,
1190 'survey_progress_bar_text_letter_spacing_mobile' => $survey_progress_bar_text_letter_spacing_mobile,
1191 'survey_pagination_text_color' => $survey_pagination_text_color,
1192 'survey_pagination_text_color_mobile' => $survey_pagination_text_color_mobile,
1193 'survey_progress_bar_text_font_size' => $survey_progress_bar_text_font_size,
1194 'survey_progress_bar_text_font_size_on_mobile' => $survey_progress_bar_text_font_size_on_mobile,
1195 'survey_progress_bar_text_transform' => $survey_progress_bar_text_transform,
1196 'survey_progress_bar_text_transform_mobile' => $survey_progress_bar_text_transform_mobile,
1197 'survey_show_sections_questions_count' => $survey_show_sections_questions_count,
1198 'survey_required_questions_message' => $survey_required_questions_message,
1199 'survey_change_create_author' => $survey_change_create_author,
1200 // Result Settings Tab
1201 'survey_redirect_after_submit' => $survey_redirect_after_submit,
1202 'survey_submit_redirect_url' => $survey_submit_redirect_url,
1203 'survey_submit_redirect_delay' => $survey_submit_redirect_delay,
1204 'survey_submit_redirect_new_tab' => $survey_submit_redirect_new_tab,
1205 'survey_enable_exit_button' => $survey_enable_exit_button,
1206 'survey_exit_redirect_url' => $survey_exit_redirect_url,
1207 'survey_enable_restart_button' => $survey_enable_restart_button,
1208 'survey_final_result_text' => $survey_final_result_text,
1209 'survey_show_questions_as_html' => $survey_show_questions_as_html,
1210 'survey_main_url' => $survey_main_url,
1211 'survey_loader' => $survey_loader,
1212 'survey_loader_text' => $survey_loader_text,
1213 'survey_loader_gif' => $survey_loader_gif,
1214 'survey_loader_gif_width' => $survey_loader_gif_width,
1215 'survey_social_buttons' => $survey_social_buttons,
1216 'survey_social_buttons_heading' => $survey_social_buttons_heading,
1217 'survey_social_button_ln' => $survey_social_button_ln,
1218 'survey_social_button_fb' => $survey_social_button_fb,
1219 'survey_social_button_tr' => $survey_social_button_tr,
1220 'survey_social_button_vk' => $survey_social_button_vk,
1221
1222 // Limitation Tab
1223 'survey_limit_users' => $survey_limit_users,
1224 'survey_limit_users_by' => $survey_limit_users_by,
1225 'survey_max_pass_count' => $survey_max_pass_count,
1226 'survey_limitation_message' => $survey_limitation_message,
1227 'survey_redirect_url' => $survey_redirect_url,
1228 'survey_redirect_delay' => $survey_redirect_delay,
1229 'survey_enable_logged_users' => $survey_enable_logged_users,
1230 'survey_logged_in_message' => $survey_logged_in_message,
1231 'survey_show_login_form' => $survey_show_login_form,
1232 'survey_enable_takers_count' => $survey_enable_takers_count,
1233 'survey_takers_count' => $survey_takers_count,
1234
1235 // E-mail Tab
1236 'survey_enable_mail_user' => $survey_enable_mail_user,
1237 'survey_mail_message' => $survey_mail_message,
1238 'survey_enable_mail_admin' => $survey_enable_mail_admin,
1239 'survey_send_mail_to_site_admin' => $survey_send_mail_to_site_admin,
1240 'survey_additional_emails' => $survey_additional_emails,
1241 'survey_mail_message_admin' => $survey_mail_message_admin,
1242
1243 'survey_email_configuration_from_email' => $survey_email_configuration_from_email,
1244 'survey_email_configuration_from_name' => $survey_email_configuration_from_name,
1245 'survey_email_configuration_from_subject' => $survey_email_configuration_from_subject,
1246 'survey_email_configuration_replyto_email' => $survey_email_configuration_replyto_email,
1247 'survey_email_configuration_replyto_name' => $survey_email_configuration_replyto_name,
1248
1249 );
1250
1251 if (isset($_POST['save_type_default_options']) && $_POST['save_type_default_options'] == 'save_type_default_options') {
1252
1253 $survey_default_options = $options;
1254 $survey_default_options['survey_enable_schedule'] = 'off';
1255 unset($survey_default_options['survey_schedule_active']);
1256 unset($survey_default_options['survey_schedule_deactive']);
1257
1258 $this->settings_obj->ays_update_setting( 'survey_default_options', json_encode( $survey_default_options ) );
1259 }
1260
1261 $options = apply_filters("ays_sm_survey_page_integrations_saves", $options, array());
1262
1263
1264 if (isset($_POST[ $name_prefix . 'sections_delete' ]) && ! empty( $_POST[ $name_prefix . 'sections_delete' ] )) {
1265 $sections_delete = array_map( 'sanitize_text_field', $_POST[ $name_prefix . 'sections_delete' ] );
1266 foreach( $sections_delete as $key => $del_id ) {
1267 if( in_array( $del_id, $section_ids ) ){
1268 $del_index = array_search( $del_id, $section_ids );
1269 unset($section_ids[$del_index]);
1270 }
1271 $wpdb->delete(
1272 $sections_table,
1273 array( 'id' => intval( $del_id ) ),
1274 array( '%d' )
1275 );
1276 }
1277 }
1278
1279 if (isset($_POST[ $name_prefix . 'questions_delete' ]) && ! empty( $_POST[ $name_prefix . 'questions_delete' ] )) {
1280 $questions_delete = array_map( 'sanitize_text_field', $_POST[ $name_prefix . 'questions_delete' ] );
1281 foreach ( $questions_delete as $key => $del_id ) {
1282 if( in_array( $del_id, $question_ids ) ){
1283 $del_index = array_search( $del_id, $question_ids );
1284 unset($question_ids[$del_index]);
1285 }
1286 $wpdb->delete(
1287 $questions_table,
1288 array( 'id' => intval( $del_id ) ),
1289 array( '%d' )
1290 );
1291 }
1292 }
1293
1294 if (isset($_POST[ $name_prefix . 'answers_delete' ]) && ! empty( $_POST[ $name_prefix . 'answers_delete' ] )) {
1295 $answers_delete = array_map( 'sanitize_text_field', $_POST[ $name_prefix . 'answers_delete' ] );
1296 foreach ( $answers_delete as $key => $del_id ) {
1297 $wpdb->delete(
1298 $answers_table,
1299 array( 'id' => intval( $del_id ) ),
1300 array( '%d' )
1301 );
1302 }
1303 }
1304
1305 $question_ids_new = array();
1306 $section_ids_array = array();
1307
1308 if (isset($_POST[ $name_prefix . 'section_add' ]) && ! empty( $_POST[ $name_prefix . 'section_add' ] )) {
1309 // --------------------------- Sections Table ------------Start--------------- //
1310 // $section_ordering = 1;
1311 $textareas = array(
1312 'description',
1313 'title'
1314 );
1315
1316 //$section_add = Survey_Maker_Data::recursive_sanitize_text_field( $_POST[ $name_prefix . 'section_add' ], $textareas );
1317 array_walk_recursive($_POST[ $name_prefix . 'section_add' ] , [$this, 'survey_recursive_sanitize_data']);
1318 foreach ( $_POST[ $name_prefix . 'section_add' ] as $key => $section) {
1319
1320 //Section Title
1321 $section_title = ( isset($section['title']) && $section['title'] != '' ) ? stripslashes( $section['title'] ) : '';
1322
1323 //Section Description
1324 $section_description = ( isset($section['description']) && $section['description'] != '' ) ? stripslashes( $section['description'] ) : '';
1325
1326 //Section Ordering
1327 $section_ordering = ( isset($section['ordering']) && $section['ordering'] != '' ) ? $section['ordering'] : '';
1328
1329 // Section collapsed
1330 $section_collapsed = ( isset($section['options']['collapsed']) && $section['options']['collapsed'] != '' ) ? $section['options']['collapsed'] : 'expanded';
1331
1332 // Options
1333 $section_options = array(
1334 'collapsed' => $section_collapsed
1335 );
1336
1337 $result = $wpdb->insert(
1338 $sections_table,
1339 array(
1340 'title' => $section_title,
1341 'description' => $section_description,
1342 'ordering' => $section_ordering,
1343 'options' => json_encode( $section_options ),
1344 ),
1345 array(
1346 '%s', // title
1347 '%s', // description
1348 '%d', // ordering
1349 '%s', // options
1350 )
1351 );
1352
1353 $section_insert_id = $wpdb->insert_id;
1354 $section_ids_array[] = $section_insert_id;
1355
1356 // --------------------------- Question Table ------------Start--------------- //
1357 // $question_ordering = 1;
1358 if(isset($section['questions']) && !empty($section['questions'])){
1359 foreach ($section['questions'] as $question_id => $question) {
1360 $question_id = absint(intval($question_id));
1361
1362 $ays_question = ( isset($question['title']) && trim( $question['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $question['title'] ) : __( 'Question', "survey-maker" );
1363
1364 $type = ( isset($question['type']) && $question['type'] != '' ) ? $question['type'] : 'radio';
1365
1366 $user_variant = ( isset($question['user_variant']) && $question['user_variant'] != '' ) ? $question['user_variant'] : 'off';
1367
1368 $user_explanation = '';
1369
1370 $question_image = ( isset($question['image']) && $question['image'] != '' ) ? $question['image'] : '';
1371
1372 $required = isset( $question['options']['required'] ) ? $question['options']['required'] : 'off';
1373
1374 $question_ordering = ( isset($question['ordering']) && $question['ordering'] != '' ) ? $question['ordering'] : '';
1375
1376 // Question collapsed
1377 $question_collapsed = ( isset($question['options']['collapsed']) && $question['options']['collapsed'] != '' ) ? $question['options']['collapsed'] : 'expanded';
1378
1379 // Star options
1380 $star_1 = (isset( $question['options']['star_1'] ) && $question['options']['star_1'] != '') ? $question['options']['star_1'] : '';
1381 $star_2 = (isset( $question['options']['star_2'] ) && $question['options']['star_2'] != '') ? $question['options']['star_2'] : '';
1382 $star_scale_length = (isset( $question['options']['star_scale_length'] ) && $question['options']['star_scale_length'] != '') ? $question['options']['star_scale_length'] : '5';
1383
1384 // Enable selection count
1385 $enable_max_selection_count = isset($question['options']['enable_max_selection_count']) ? $question['options']['enable_max_selection_count'] : 'off';
1386 // Maximum selection count
1387 $max_selection_count = ( isset($question['options']['max_selection_count']) && $question['options']['max_selection_count'] != '' ) ? $question['options']['max_selection_count'] : '';
1388 // Minimum selection count
1389 $min_selection_count = ( isset($question['options']['min_selection_count']) && $question['options']['min_selection_count'] != '' ) ? $question['options']['min_selection_count'] : '';
1390
1391 // Text Limitations
1392 // Enable selection count
1393 $enable_word_limitation = (isset($question['options']['enable_word_limitation']) && $question['options']['enable_word_limitation'] == "on") ? "on" : 'off';
1394 // Limitation type
1395 $limitation_limit_by = ( isset($question['options']['limit_by']) && $question['options']['limit_by'] != '' ) ? $question['options']['limit_by'] : "";
1396 // Limitation char/word length
1397 $limitation_limit_length = ( isset($question['options']['limit_length']) && $question['options']['limit_length'] != '' ) ? $question['options']['limit_length'] : '';
1398 // Limitation char/word length
1399 $limitation_limit_counter = ( isset($question['options']['limit_counter']) && $question['options']['limit_counter'] == 'on' ) ? "on" : 'off';
1400
1401 // Number Limitations
1402 // Enable Limitation
1403 $enable_number_limitation = (isset($question['options']['enable_number_limitation']) && $question['options']['enable_number_limitation'] == "on") ? "on" : 'off';
1404 // Min number
1405 $number_min_selection = ( isset($question['options']['number_min_selection']) && $question['options']['number_min_selection'] != '' ) ? $question['options']['number_min_selection'] : "";
1406 // Max number
1407 $number_max_selection = ( isset($question['options']['number_max_selection']) && $question['options']['number_max_selection'] != '' ) ? $question['options']['number_max_selection'] : '';
1408 // Error message
1409 $number_error_message = ( isset($question['options']['number_error_message']) && $question['options']['number_error_message'] != '' ) ? $question['options']['number_error_message'] : '';
1410 // Show error message
1411 $enable_number_error_message = (isset($question['options']['enable_number_error_message']) && $question['options']['enable_number_error_message'] == "on") ? "on" : 'off';
1412 // Char length
1413 $number_limit_length = (isset($question['options']['number_limit_length']) && $question['options']['number_limit_length'] != "") ? $question['options']['number_limit_length'] : '';
1414 // Show Char length
1415 $enable_number_limit_counter = (isset($question['options']['enable_number_limit_counter']) && $question['options']['enable_number_limit_counter'] == "on") ? "on" : 'off';
1416
1417 // Input types placeholders
1418 $survey_input_type_placeholder = (isset($question['options']['placeholder']) && $question['options']['placeholder'] != "") ? $question['options']['placeholder'] : '';
1419
1420 $question_image_caption = ( isset($question['options']['image_caption']) && $question['options']['image_caption'] != '' ) ? sanitize_text_field($question['options']['image_caption']) : '';
1421 $question_image_caption_enable = ( isset($question['options']['image_caption_enable']) && $question['options']['image_caption_enable'] == 'on' ) ? 'on' : 'off';
1422
1423 // Admin note
1424 $enable_admin_note = (isset( $question['options']['enable_admin_note'] )) && $question['options']['enable_admin_note'] == 'on' ? 'on' : 'off';
1425 $admin_note = (isset( $question['options']['admin_note'] ) && $question['options']['admin_note'] != '') ? sanitize_text_field( $question['options']['admin_note'] ) : '';
1426
1427 // With editor
1428 $with_editor = ( isset($question['options']['with_editor']) && $question['options']['with_editor'] == 'on' ) ? 'on' : 'off';
1429
1430 $question_options = array(
1431 'required' => $required,
1432 'collapsed' => $question_collapsed,
1433 'star_1' => $star_1,
1434 'star_2' => $star_2,
1435 'star_scale_length' => $star_scale_length,
1436 'enable_max_selection_count' => $enable_max_selection_count,
1437 'max_selection_count' => $max_selection_count,
1438 'min_selection_count' => $min_selection_count,
1439 // Text Limitations
1440 'enable_word_limitation' => $enable_word_limitation,
1441 'limit_by' => $limitation_limit_by,
1442 'limit_length' => $limitation_limit_length,
1443 'limit_counter' => $limitation_limit_counter,
1444 // Number Limitations
1445 'enable_number_limitation' => $enable_number_limitation,
1446 'number_min_selection' => $number_min_selection,
1447 'number_max_selection' => $number_max_selection,
1448 'number_error_message' => $number_error_message,
1449 'enable_number_error_message' => $enable_number_error_message,
1450 'number_limit_length' => $number_limit_length,
1451 'enable_number_limit_counter' => $enable_number_limit_counter,
1452 'survey_input_type_placeholder' => $survey_input_type_placeholder,
1453
1454 'image_caption' => $question_image_caption,
1455 'image_caption_enable' => $question_image_caption_enable,
1456
1457 'with_editor' => $with_editor,
1458
1459 'enable_admin_note' => $enable_admin_note,
1460 'admin_note' => $admin_note,
1461 );
1462
1463 $question_result = $wpdb->update(
1464 $questions_table,
1465 array(
1466 'author_id' => $author_id,
1467 'section_id' => $section_insert_id,
1468 'category_ids' => $category_ids,
1469 'question' => $ays_question,
1470 'type' => $type,
1471 'status' => $status,
1472 'trash_status' => $trash_status,
1473 'date_created' => $date_created,
1474 'date_modified' => $date_modified,
1475 'user_variant' => $user_variant,
1476 'user_explanation' => $user_explanation,
1477 'image' => $question_image,
1478 'ordering' => $question_ordering,
1479 'options' => json_encode($question_options),
1480 ),
1481 array( 'id' => $question_id ),
1482 array(
1483 '%d', // author_id
1484 '%d', // section_id
1485 '%s', // category_ids
1486 '%s', // question
1487 '%s', // type
1488 '%s', // status
1489 '%s', // trash_status
1490 '%s', // date_created
1491 '%s', // date_modified
1492 '%s', // user_variant
1493 '%s', // user_explanation
1494 '%s', // image
1495 '%d', // ordering
1496 '%s', // options
1497 ),
1498 array( '%d' )
1499 );
1500
1501 // --------------------------- Answers Table ------------Start--------------- //
1502 // $answer_ordering = 1;
1503 if( isset( $question['answers'] ) && !empty( $question['answers'] ) ){
1504 foreach ($question['answers'] as $answer_id => $answer) {
1505 $answer_id = absint(intval($answer_id));
1506 $answer_ordering = ( isset($answer['ordering']) && $answer['ordering'] != '' ) ? $answer['ordering'] : '';
1507 $answer_title = ( isset($answer['title']) && trim( $answer['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $answer['title'] ) : __( 'Option', "survey-maker" ) . ' ' . $answer_ordering;
1508 $answer_image = '';
1509 if ( isset( $answer['image'] ) && $answer['image'] != '' ) {
1510 $answer_image = $answer['image'];
1511 }
1512 $placeholder = '';
1513 $answer_result = $wpdb->update(
1514 $answers_table,
1515 array(
1516 'question_id' => $question_id,
1517 'answer' => $answer_title,
1518 'image' => $answer_image,
1519 'ordering' => $answer_ordering,
1520 'placeholder' => $placeholder,
1521 ),
1522 array( 'id' => $answer_id ),
1523 array(
1524 '%d', // question_id
1525 '%s', // answer
1526 '%s', // image
1527 '%d', // ordering
1528 '%s', // placeholder
1529 ),
1530 array( '%d' )
1531 );
1532
1533 // $answer_ordering++;
1534 }
1535 }
1536
1537 if( isset( $question['answers_add'] ) && !empty( $question['answers_add'] ) ){
1538 foreach ($question['answers_add'] as $answer_id => $answer) {
1539 $answer_id = absint(intval($answer_id));
1540 $answer_ordering = ( isset($answer['ordering']) && $answer['ordering'] != '' ) ? $answer['ordering'] : '';
1541 $answer_title = ( isset($answer['title']) && trim( $answer['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $answer['title'] ) : __( 'Option', "survey-maker" ) . ' ' . $answer_ordering;
1542 $answer_image = '';
1543 if ( isset( $answer['image'] ) && $answer['image'] != '' ) {
1544 $answer_image = $answer['image'];
1545 }
1546 $placeholder = '';
1547 $answer_result = $wpdb->insert(
1548 $answers_table,
1549 array(
1550 'question_id' => $question_id,
1551 'answer' => $answer_title,
1552 'image' => $answer_image,
1553 'ordering' => $answer_ordering,
1554 'placeholder' => $placeholder,
1555 ),
1556 array(
1557 '%d', // question_id
1558 '%s', // answer
1559 '%s', // image
1560 '%d', // ordering
1561 '%s', // placeholder
1562 )
1563 );
1564
1565 // $answer_ordering++;
1566 }
1567 }
1568 // --------------------------- Answers Table ------------End--------------- //
1569
1570 // $question_ordering++;
1571 }
1572 }
1573
1574 // $question_ordering = 1;
1575 $question_id_array = array();
1576 if ( isset( $section['questions_add'] ) && ! empty( $section['questions_add'] ) ) {
1577 foreach ($section['questions_add'] as $question_id => $question) {
1578 $ays_question = ( isset($question['title']) && trim( $question['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $question['title'] ) : __( 'Question', "survey-maker" );
1579
1580 $type = ( isset($question['type']) && $question['type'] != '' ) ? $question['type'] : 'radio';
1581
1582 $user_variant = ( isset($question['user_variant']) && $question['user_variant'] != '' ) ? $question['user_variant'] : 'off';
1583
1584 $user_explanation = '';
1585
1586 $question_image = ( isset($question['image']) && $question['image'] != '' ) ? $question['image'] : '';
1587
1588 $required = isset( $question['options']['required'] ) ? $question['options']['required'] : 'off';
1589
1590 $question_ordering = ( isset($question['ordering']) && $question['ordering'] != '' ) ? $question['ordering'] : '';
1591
1592 // Question collapsed
1593 $question_collapsed = ( isset($question['options']['collapsed']) && $question['options']['collapsed'] != '' ) ? $question['options']['collapsed'] : 'expanded';
1594
1595 // Star options
1596 $star_1 = (isset( $question['options']['star_1'] ) && $question['options']['star_1'] != '') ? $question['options']['star_1'] : '';
1597 $star_2 = (isset( $question['options']['star_2'] ) && $question['options']['star_2'] != '') ? $question['options']['star_2'] : '';
1598 $star_scale_length = (isset( $question['options']['star_scale_length'] ) && $question['options']['star_scale_length'] != '') ? $question['options']['star_scale_length'] : '5';
1599
1600 // Enable selection count
1601 $enable_max_selection_count = isset($question['options']['enable_max_selection_count']) ? $question['options']['enable_max_selection_count'] : 'off';
1602 // Maximum selection count
1603 $max_selection_count = ( isset($question['options']['max_selection_count']) && $question['options']['max_selection_count'] != '' ) ? $question['options']['max_selection_count'] : '';
1604 // Minimum selection count
1605 $min_selection_count = ( isset($question['options']['min_selection_count']) && $question['options']['min_selection_count'] != '' ) ? $question['options']['min_selection_count'] : '';
1606
1607 // Text Limitations
1608 // Enable selection count
1609 $enable_word_limitation = (isset($question['options']['enable_word_limitation']) && $question['options']['enable_word_limitation'] == "on") ? "on" : 'off';
1610 // Limitation type
1611 $limitation_limit_by = ( isset($question['options']['limit_by']) && $question['options']['limit_by'] != '' ) ? $question['options']['limit_by'] : "";
1612 // Limitation char/word length
1613 $limitation_limit_length = ( isset($question['options']['limit_length']) && $question['options']['limit_length'] != '' ) ? $question['options']['limit_length'] : '';
1614 // Limitation char/word length
1615 $limitation_limit_counter = ( isset($question['options']['limit_counter']) && $question['options']['limit_counter'] == 'on' ) ? "on" : 'off';
1616
1617 // Number Limitations
1618 // Enable Limitation
1619 $enable_number_limitation = (isset($question['options']['enable_number_limitation']) && $question['options']['enable_number_limitation'] == "on") ? "on" : 'off';
1620 // Min number
1621 $number_min_selection = ( isset($question['options']['number_min_selection']) && $question['options']['number_min_selection'] != '' ) ? $question['options']['number_min_selection'] : "";
1622 // Max number
1623 $number_max_selection = ( isset($question['options']['number_max_selection']) && $question['options']['number_max_selection'] != '' ) ? $question['options']['number_max_selection'] : '';
1624 // Error message
1625 $number_error_message = ( isset($question['options']['number_error_message']) && $question['options']['number_error_message'] != '' ) ? $question['options']['number_error_message'] : '';
1626 // Show error message
1627 $enable_number_error_message = (isset($question['options']['enable_number_error_message']) && $question['options']['enable_number_error_message'] == "on") ? "on" : 'off';
1628 // Char length
1629 $number_limit_length = (isset($question['options']['number_limit_length']) && $question['options']['number_limit_length'] != "") ? $question['options']['number_limit_length'] : '';
1630 // Show Char length
1631 $enable_number_limit_counter = (isset($question['options']['enable_number_limit_counter']) && $question['options']['enable_number_limit_counter'] == "on") ? "on" : 'off';
1632
1633 // Input types placeholders
1634 $survey_input_type_placeholder = (isset($question['options']['placeholder']) && $question['options']['placeholder'] != "") ? $question['options']['placeholder'] : '';
1635
1636 $question_image_caption = ( isset($question['options']['image_caption']) && $question['options']['image_caption'] != '' ) ? sanitize_text_field($question['options']['image_caption']) : '';
1637 $question_image_caption_enable = ( isset($question['options']['image_caption_enable']) && $question['options']['image_caption_enable'] == 'on' ) ? 'on' : 'off';
1638
1639 // With editor
1640 $with_editor = ( isset($question['options']['with_editor']) && $question['options']['with_editor'] == 'on' ) ? 'on' : 'off';
1641
1642 // Admin note
1643 $enable_admin_note = (isset( $question['options']['enable_admin_note'] )) ? $question['options']['enable_admin_note'] : 'off';
1644 $admin_note = (isset( $question['options']['admin_note'] ) && $question['options']['admin_note'] != '') ? $question['options']['admin_note'] : '';
1645
1646 $question_options = array(
1647 'required' => $required,
1648 'collapsed' => $question_collapsed,
1649 'star_1' => $star_1,
1650 'star_2' => $star_2,
1651 'star_scale_length' => $star_scale_length,
1652 'enable_max_selection_count' => $enable_max_selection_count,
1653 'max_selection_count' => $max_selection_count,
1654 'min_selection_count' => $min_selection_count,
1655 // Text Limitations
1656 'enable_word_limitation' => $enable_word_limitation,
1657 'limit_by' => $limitation_limit_by,
1658 'limit_length' => $limitation_limit_length,
1659 'limit_counter' => $limitation_limit_counter,
1660 // Number Limitations
1661 'enable_number_limitation' => $enable_number_limitation,
1662 'number_min_selection' => $number_min_selection,
1663 'number_max_selection' => $number_max_selection,
1664 'number_error_message' => $number_error_message,
1665 'enable_number_error_message' => $enable_number_error_message,
1666 'number_limit_length' => $number_limit_length,
1667 'enable_number_limit_counter' => $enable_number_limit_counter,
1668 'survey_input_type_placeholder' => $survey_input_type_placeholder,
1669 'image_caption' => $question_image_caption,
1670 'image_caption_enable' => $question_image_caption_enable,
1671
1672 'with_editor' => $with_editor,
1673
1674 'enable_admin_note' => $enable_admin_note,
1675 'admin_note' => $admin_note,
1676 );
1677
1678 $question_result = $wpdb->insert(
1679 $questions_table,
1680 array(
1681 'author_id' => $author_id,
1682 'section_id' => $section_insert_id,
1683 'category_ids' => $category_ids,
1684 'question' => $ays_question,
1685 'type' => $type,
1686 'status' => $status,
1687 'trash_status' => $trash_status,
1688 'date_created' => $date_created,
1689 'date_modified' => $date_modified,
1690 'user_variant' => $user_variant,
1691 'user_explanation' => $user_explanation,
1692 'image' => $question_image,
1693 'ordering' => $question_ordering,
1694 'options' => json_encode($question_options),
1695 ),
1696 array(
1697 '%d', // author_id
1698 '%d', // section_id
1699 '%s', // category_ids
1700 '%s', // question
1701 '%s', // type
1702 '%s', // status
1703 '%s', // trash_status
1704 '%s', // date_created
1705 '%s', // date_modified
1706 '%s', // user_variant
1707 '%s', // user_explanation
1708 '%s', // image
1709 '%d', // ordering
1710 '%s', // options
1711 )
1712 );
1713
1714 $question_insert_id = $wpdb->insert_id;
1715 $question_ids_new[] = $question_insert_id;
1716
1717 // --------------------------- Answers Table ------------Start--------------- //
1718 // $answer_ordering = 1;
1719 if( isset( $question['answers_add'] ) && ! empty( $question['answers_add'] ) ){
1720 foreach ($question['answers_add'] as $answer_id => $answer) {
1721 $answer_ordering = ( isset($answer['ordering']) && $answer['ordering'] != '' ) ? $answer['ordering'] : '';
1722 $answer_title = ( isset($answer['title']) && trim( $answer['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $answer['title'] ) : __( 'Option', "survey-maker" ) . ' ' . $answer_ordering;
1723 $answer_image = '';
1724 if ( isset( $answer['image'] ) && $answer['image'] != '' ) {
1725 $answer_image = $answer['image'];
1726 }
1727 $placeholder = '';
1728 $answer_result = $wpdb->insert(
1729 $answers_table,
1730 array(
1731 'question_id' => $question_insert_id,
1732 'answer' => $answer_title,
1733 'image' => $answer_image,
1734 'ordering' => $answer_ordering,
1735 'placeholder' => $placeholder,
1736 ),
1737 array(
1738 '%d', // question_id
1739 '%s', // answer
1740 '%s', // image
1741 '%d', // ordering
1742 '%s', // placeholder
1743 )
1744 );
1745 // $answer_ordering++;
1746 }
1747 }
1748 // --------------------------- Answers Table ------------End--------------- //
1749 // $question_ordering++;
1750 }
1751 }
1752 // --------------------------- Question Table ------------End--------------- //
1753 // $section_ordering++;
1754 }
1755 // --------------------------- Sections Table ------------End--------------- //
1756 }
1757
1758 if (isset($_POST[ $name_prefix . 'sections' ]) && !empty( $_POST[ $name_prefix . 'sections' ] )) {
1759 // --------------------------- Sections Table ------------Start--------------- //
1760
1761 // $section_ordering = 1;
1762 $textareas = array(
1763 'description',
1764 'title'
1765 );
1766
1767 //$section_update = Survey_Maker_Data::recursive_sanitize_text_field( $_POST[ $name_prefix . 'sections' ], $textareas );
1768 $section_update = $_POST[ $name_prefix . 'sections' ];
1769
1770 foreach ( $section_update as $section_id => $section) {
1771 $section_id = absint(intval($section_id));
1772 $section_title = $section['title'];
1773 $section_description = $section['description'];
1774 $section_ordering = $section['ordering'];
1775
1776 // Section collapsed
1777 $section_collapsed = ( isset($section['options']['collapsed']) && $section['options']['collapsed'] != '' ) ? $section['options']['collapsed'] : 'expanded';
1778
1779 // Options
1780 $section_options = array(
1781 'collapsed' => $section_collapsed
1782 );
1783
1784 $result = $wpdb->update(
1785 $sections_table,
1786 array(
1787 'title' => $section_title,
1788 'description' => $section_description,
1789 'ordering' => $section_ordering,
1790 'options' => json_encode( $section_options ),
1791 ),
1792 array( 'id' => $section_id ),
1793 array(
1794 '%s', // title
1795 '%s', // description
1796 '%d', // ordering
1797 '%s', // options
1798 ),
1799 array( '%d' )
1800 );
1801
1802 // --------------------------- Question Table ------------Start--------------- //
1803 // $question_ordering = 1;
1804 if( isset( $section['questions'] ) && ! empty( $section['questions'] ) ){
1805 foreach ($section['questions'] as $question_id => $question) {
1806 $question_id = absint(intval($question_id));
1807
1808 $ays_question = ( isset($question['title']) && trim( $question['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $question['title'] ) : __( 'Question', "survey-maker" );
1809
1810 $type = ( isset($question['type']) && $question['type'] != '' ) ? $question['type'] : 'radio';
1811
1812 $user_variant = ( isset($question['user_variant']) && $question['user_variant'] != '' ) ? $question['user_variant'] : 'off';
1813
1814 $user_explanation = '';
1815
1816 $question_image = ( isset($question['image']) && $question['image'] != '' ) ? $question['image'] : '';
1817
1818 $required = isset( $question['options']['required'] ) ? $question['options']['required'] : 'off';
1819
1820 $question_ordering = ( isset($question['ordering']) && $question['ordering'] != '' ) ? $question['ordering'] : '';
1821
1822 // Question collapsed
1823 $question_collapsed = ( isset($question['options']['collapsed']) && $question['options']['collapsed'] != '' ) ? $question['options']['collapsed'] : 'expanded';
1824
1825 // Star options
1826 $star_1 = (isset( $question['options']['star_1'] ) && $question['options']['star_1'] != '') ? $question['options']['star_1'] : '';
1827 $star_2 = (isset( $question['options']['star_2'] ) && $question['options']['star_2'] != '') ? $question['options']['star_2'] : '';
1828 $star_scale_length = (isset( $question['options']['star_scale_length'] ) && $question['options']['star_scale_length'] != '') ? $question['options']['star_scale_length'] : '5';
1829
1830 // Enable selection count
1831 $enable_max_selection_count = isset($question['options']['enable_max_selection_count']) ? $question['options']['enable_max_selection_count'] : 'off';
1832 // Maximum selection count
1833 $max_selection_count = ( isset($question['options']['max_selection_count']) && $question['options']['max_selection_count'] != '' ) ? $question['options']['max_selection_count'] : '';
1834 // Minimum selection count
1835 $min_selection_count = ( isset($question['options']['min_selection_count']) && $question['options']['min_selection_count'] != '' ) ? $question['options']['min_selection_count'] : '';
1836
1837 // Text Limitations
1838 // Enable selection count
1839 $enable_word_limitation = (isset($question['options']['enable_word_limitation']) && $question['options']['enable_word_limitation'] == "on") ? "on" : 'off';
1840 // Limitation type
1841 $limitation_limit_by = ( isset($question['options']['limit_by']) && $question['options']['limit_by'] != '' ) ? $question['options']['limit_by'] : "";
1842 // Limitation char/word length
1843 $limitation_limit_length = ( isset($question['options']['limit_length']) && $question['options']['limit_length'] != '' ) ? $question['options']['limit_length'] : '';
1844 // Limitation char/word length
1845 $limitation_limit_counter = ( isset($question['options']['limit_counter']) && $question['options']['limit_counter'] == 'on' ) ? "on" : 'off';
1846
1847 // Number Limitations
1848 // Enable Limitation
1849 $enable_number_limitation = (isset($question['options']['enable_number_limitation']) && $question['options']['enable_number_limitation'] == "on") ? "on" : 'off';
1850 // Min number
1851 $number_min_selection = ( isset($question['options']['number_min_selection']) && $question['options']['number_min_selection'] != '' ) ? $question['options']['number_min_selection'] : "";
1852 // Max number
1853 $number_max_selection = ( isset($question['options']['number_max_selection']) && $question['options']['number_max_selection'] != '' ) ? $question['options']['number_max_selection'] : '';
1854 // Error message
1855 $number_error_message = ( isset($question['options']['number_error_message']) && $question['options']['number_error_message'] != '' ) ? $question['options']['number_error_message'] : '';
1856 // Show error message
1857 $enable_number_error_message = (isset($question['options']['enable_number_error_message']) && $question['options']['enable_number_error_message'] == "on") ? "on" : 'off';
1858 // Char length
1859 $number_limit_length = (isset($question['options']['number_limit_length']) && $question['options']['number_limit_length'] != "") ? $question['options']['number_limit_length'] : '';
1860 // Show Char length
1861 $enable_number_limit_counter = (isset($question['options']['enable_number_limit_counter']) && $question['options']['enable_number_limit_counter'] == "on") ? "on" : 'off';
1862
1863 // Input types placeholders
1864 $survey_input_type_placeholder = (isset($question['options']['placeholder']) && $question['options']['placeholder'] != "") ? $question['options']['placeholder'] : '';
1865
1866 $question_image_caption = ( isset($question['options']['image_caption']) && $question['options']['image_caption'] != '' ) ? sanitize_text_field($question['options']['image_caption']) : '';
1867 $question_image_caption_enable = ( isset($question['options']['image_caption_enable']) && $question['options']['image_caption_enable'] == 'on' ) ? 'on' : 'off';
1868
1869 // With editor
1870 $with_editor = ( isset($question['options']['with_editor']) && $question['options']['with_editor'] == 'on' ) ? 'on' : 'off';
1871
1872 // Admin note
1873 $enable_admin_note = (isset( $question['options']['enable_admin_note'] )) ? $question['options']['enable_admin_note'] : 'off';
1874 $admin_note = (isset( $question['options']['admin_note'] ) && $question['options']['admin_note'] != '') ? $question['options']['admin_note'] : '';
1875
1876 $question_options = array(
1877 'required' => $required,
1878 'collapsed' => $question_collapsed,
1879 'star_1' => $star_1,
1880 'star_2' => $star_2,
1881 'star_scale_length' => $star_scale_length,
1882 'enable_max_selection_count' => $enable_max_selection_count,
1883 'max_selection_count' => $max_selection_count,
1884 'min_selection_count' => $min_selection_count,
1885 // Text Limitations
1886 'enable_word_limitation' => $enable_word_limitation,
1887 'limit_by' => $limitation_limit_by,
1888 'limit_length' => $limitation_limit_length,
1889 'limit_counter' => $limitation_limit_counter,
1890 // Number Limitations
1891 'enable_number_limitation' => $enable_number_limitation,
1892 'number_min_selection' => $number_min_selection,
1893 'number_max_selection' => $number_max_selection,
1894 'number_error_message' => $number_error_message,
1895 'enable_number_error_message' => $enable_number_error_message,
1896 'number_limit_length' => $number_limit_length,
1897 'enable_number_limit_counter' => $enable_number_limit_counter,
1898 'survey_input_type_placeholder' => $survey_input_type_placeholder,
1899
1900 'image_caption' => $question_image_caption,
1901 'image_caption_enable' => $question_image_caption_enable,
1902
1903 'with_editor' => $with_editor,
1904
1905 'enable_admin_note' => $enable_admin_note,
1906 'admin_note' => $admin_note,
1907 );
1908
1909 $question_result = $wpdb->update(
1910 $questions_table,
1911 array(
1912 'author_id' => $author_id,
1913 'section_id' => $section_id,
1914 'category_ids' => $category_ids,
1915 'question' => $ays_question,
1916 'type' => $type,
1917 'status' => $status,
1918 'trash_status' => $trash_status,
1919 'date_created' => $date_created,
1920 'date_modified' => $date_modified,
1921 'user_variant' => $user_variant,
1922 'user_explanation' => $user_explanation,
1923 'image' => $question_image,
1924 'ordering' => $question_ordering,
1925 'options' => json_encode($question_options),
1926 ),
1927 array( 'id' => $question_id ),
1928 array(
1929 '%d', // author_id
1930 '%d', // section_id
1931 '%s', // category_ids
1932 '%s', // question
1933 '%s', // type
1934 '%s', // status
1935 '%s', // trash_status
1936 '%s', // date_created
1937 '%s', // date_modified
1938 '%s', // user_variant
1939 '%s', // user_explanation
1940 '%s', // image
1941 '%d', // ordering
1942 '%s', // options
1943 ),
1944 array( '%d' )
1945 );
1946
1947 // --------------------------- Answers Table ------------Start--------------- //
1948 // $answer_ordering = 1;
1949 if( isset( $question['answers'] ) && !empty( $question['answers'] ) ){
1950 foreach ($question['answers'] as $answer_id => $answer) {
1951 $answer_id = absint(intval($answer_id));
1952 $answer_ordering = ( isset($answer['ordering']) && $answer['ordering'] != '' ) ? $answer['ordering'] : '';
1953 $answer_title = ( isset($answer['title']) && trim( $answer['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $answer['title'] ) : __( 'Option', "survey-maker" ) . ' ' . $answer_ordering;
1954
1955 $answer_image = '';
1956 if ( isset( $answer['image'] ) && $answer['image'] != '' ) {
1957 $answer_image = $answer['image'];
1958 }
1959 $placeholder = '';
1960 $answer_result = $wpdb->update(
1961 $answers_table,
1962 array(
1963 'question_id' => $question_id,
1964 'answer' => $answer_title,
1965 'image' => $answer_image,
1966 'ordering' => $answer_ordering,
1967 'placeholder' => $placeholder,
1968 ),
1969 array( 'id' => $answer_id ),
1970 array(
1971 '%d', // question_id
1972 '%s', // answer
1973 '%s', // image
1974 '%d', // ordering
1975 '%s', // placeholder
1976 ),
1977 array( '%d' )
1978 );
1979
1980 // $answer_ordering++;
1981 }
1982 }
1983
1984 if( isset( $question['answers_add'] ) && !empty( $question['answers_add'] ) ){
1985 foreach ($question['answers_add'] as $answer_id => $answer) {
1986 $answer_id = absint(intval($answer_id));
1987 $answer_ordering = ( isset($answer['ordering']) && $answer['ordering'] != '' ) ? $answer['ordering'] : '';
1988 $answer_title = ( isset($answer['title']) && trim( $answer['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $answer['title'] ) : __( 'Option', "survey-maker" ) . ' ' . $answer_ordering;
1989 $answer_image = '';
1990 if ( isset( $answer['image'] ) && $answer['image'] != '' ) {
1991 $answer_image = $answer['image'];
1992 }
1993 $placeholder = '';
1994 $answer_result = $wpdb->insert(
1995 $answers_table,
1996 array(
1997 'question_id' => $question_id,
1998 'answer' => $answer_title,
1999 'image' => $answer_image,
2000 'ordering' => $answer_ordering,
2001 'placeholder' => $placeholder,
2002 ),
2003 array(
2004 '%d', // question_id
2005 '%s', // answer
2006 '%s', // image
2007 '%d', // ordering
2008 '%s', // placeholder
2009 )
2010 );
2011
2012 // $answer_ordering++;
2013 }
2014 }
2015 // --------------------------- Answers Table ------------End--------------- //
2016
2017 // $question_ordering++;
2018 }
2019 }
2020
2021 if( isset( $section['questions_add'] ) && !empty( $section['questions_add'] ) ){
2022 foreach ($section['questions_add'] as $question_id => $question) {
2023 $ays_question = ( isset($question['title']) && trim( $question['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $question['title'] ) : __( 'Question', "survey-maker" );
2024
2025 $type = ( isset($question['type']) && $question['type'] != '' ) ? $question['type'] : 'radio';
2026
2027 $user_variant = ( isset($question['user_variant']) && $question['user_variant'] != '' ) ? $question['user_variant'] : 'off';
2028
2029 $user_explanation = '';
2030
2031 $question_image = ( isset($question['image']) && $question['image'] != '' ) ? $question['image'] : '';
2032
2033 $required = isset( $question['options']['required'] ) ? $question['options']['required'] : 'off';
2034
2035 $question_ordering = ( isset($question['ordering']) && $question['ordering'] != '' ) ? $question['ordering'] : '';
2036
2037 // Question collapsed
2038 $question_collapsed = ( isset($question['options']['collapsed']) && $question['options']['collapsed'] != '' ) ? $question['options']['collapsed'] : 'expanded';
2039 $star_1 = (isset( $question['options']['star_1'] ) && $question['options']['star_1'] != '') ? $question['options']['star_1'] : '';
2040 $star_2 = (isset( $question['options']['star_2'] ) && $question['options']['star_2'] != '') ? $question['options']['star_2'] : '';
2041 $star_scale_length = (isset( $question['options']['star_scale_length'] ) && $question['options']['star_scale_length'] != '') ? $question['options']['star_scale_length'] : '5';
2042
2043 // Enable selection count
2044 $enable_max_selection_count = isset($question['options']['enable_max_selection_count']) ? $question['options']['enable_max_selection_count'] : 'off';
2045 // Maximum selection count
2046 $max_selection_count = ( isset($question['options']['max_selection_count']) && $question['options']['max_selection_count'] != '' ) ? $question['options']['max_selection_count'] : '';
2047 // Minimum selection count
2048 $min_selection_count = ( isset($question['options']['min_selection_count']) && $question['options']['min_selection_count'] != '' ) ? $question['options']['min_selection_count'] : '';
2049
2050 // Text Limitations
2051 // Enable selection count
2052 $enable_word_limitation = (isset($question['options']['enable_word_limitation']) && $question['options']['enable_word_limitation'] == "on") ? "on" : 'off';
2053 // Limitation type
2054 $limitation_limit_by = ( isset($question['options']['limit_by']) && $question['options']['limit_by'] != '' ) ? $question['options']['limit_by'] : "";
2055 // Limitation char/word length
2056 $limitation_limit_length = ( isset($question['options']['limit_length']) && $question['options']['limit_length'] != '' ) ? $question['options']['limit_length'] : '';
2057 // Limitation char/word length
2058 $limitation_limit_counter = ( isset($question['options']['limit_counter']) && $question['options']['limit_counter'] == 'on' ) ? "on" : 'off';
2059
2060 // Number Limitations
2061 // Enable Limitation
2062 $enable_number_limitation = (isset($question['options']['enable_number_limitation']) && $question['options']['enable_number_limitation'] == "on") ? "on" : 'off';
2063 // Min number
2064 $number_min_selection = ( isset($question['options']['number_min_selection']) && $question['options']['number_min_selection'] != '' ) ? $question['options']['number_min_selection'] : "";
2065 // Max number
2066 $number_max_selection = ( isset($question['options']['number_max_selection']) && $question['options']['number_max_selection'] != '' ) ? $question['options']['number_max_selection'] : '';
2067 // Error message
2068 $number_error_message = ( isset($question['options']['number_error_message']) && $question['options']['number_error_message'] != '' ) ? $question['options']['number_error_message'] : '';
2069 // Show error message
2070 $enable_number_error_message = (isset($question['options']['enable_number_error_message']) && $question['options']['enable_number_error_message'] == "on") ? "on" : 'off';
2071 // Char length
2072 $number_limit_length = (isset($question['options']['number_limit_length']) && $question['options']['number_limit_length'] != "") ? $question['options']['number_limit_length'] : '';
2073 // Show Char length
2074 $enable_number_limit_counter = (isset($question['options']['enable_number_limit_counter']) && $question['options']['enable_number_limit_counter'] == "on") ? "on" : 'off';
2075
2076 // Input types placeholders
2077 $survey_input_type_placeholder = (isset($question['options']['placeholder']) && $question['options']['placeholder'] != "") ? $question['options']['placeholder'] : '';
2078
2079 $question_image_caption = ( isset($question['options']['image_caption']) && $question['options']['image_caption'] != '' ) ? sanitize_text_field($question['options']['image_caption']) : '';
2080 $question_image_caption_enable = ( isset($question['options']['image_caption_enable']) && $question['options']['image_caption_enable'] == 'on' ) ? 'on' : 'off';
2081
2082 // With editor
2083 $with_editor = ( isset($question['options']['with_editor']) && $question['options']['with_editor'] == 'on' ) ? 'on' : 'off';
2084
2085 // Admin note
2086 $enable_admin_note = (isset( $question['options']['enable_admin_note'] )) ? $question['options']['enable_admin_note'] : 'off';
2087 $admin_note = (isset( $question['options']['admin_note'] ) && $question['options']['admin_note'] != '') ? $question['options']['admin_note'] : '';
2088
2089 $question_options = array(
2090 'required' => $required,
2091 'collapsed' => $question_collapsed,
2092 'star_1' => $star_1,
2093 'star_2' => $star_2,
2094 'star_scale_length' => $star_scale_length,
2095 'enable_max_selection_count' => $enable_max_selection_count,
2096 'max_selection_count' => $max_selection_count,
2097 'min_selection_count' => $min_selection_count,
2098 // Text Limitations
2099 'enable_word_limitation' => $enable_word_limitation,
2100 'limit_by' => $limitation_limit_by,
2101 'limit_length' => $limitation_limit_length,
2102 'limit_counter' => $limitation_limit_counter,
2103 // Number Limitations
2104 'enable_number_limitation' => $enable_number_limitation,
2105 'number_min_selection' => $number_min_selection,
2106 'number_max_selection' => $number_max_selection,
2107 'number_error_message' => $number_error_message,
2108 'enable_number_error_message' => $enable_number_error_message,
2109 'number_limit_length' => $number_limit_length,
2110 'enable_number_limit_counter' => $enable_number_limit_counter,
2111 'survey_input_type_placeholder' => $survey_input_type_placeholder,
2112
2113 'image_caption' => $question_image_caption,
2114 'image_caption_enable' => $question_image_caption_enable,
2115
2116 'with_editor' => $with_editor,
2117
2118 'enable_admin_note' => $enable_admin_note,
2119 'admin_note' => $admin_note,
2120 );
2121
2122 $question_result = $wpdb->insert(
2123 $questions_table,
2124 array(
2125 'author_id' => $author_id,
2126 'section_id' => $section_id,
2127 'category_ids' => $category_ids,
2128 'question' => $ays_question,
2129 'type' => $type,
2130 'status' => $status,
2131 'trash_status' => $trash_status,
2132 'date_created' => $date_created,
2133 'date_modified' => $date_modified,
2134 'user_variant' => $user_variant,
2135 'user_explanation' => $user_explanation,
2136 'image' => $question_image,
2137 'ordering' => $question_ordering,
2138 'options' => json_encode($question_options),
2139 ),
2140 array(
2141 '%d', // author_id
2142 '%d', // section_id
2143 '%s', // category_ids
2144 '%s', // question
2145 '%s', // type
2146 '%s', // status
2147 '%s', // trash_status
2148 '%s', // date_created
2149 '%s', // date_modified
2150 '%s', // user_variant
2151 '%s', // user_explanation
2152 '%s', // image
2153 '%d', // ordering
2154 '%s', // options
2155 )
2156 );
2157
2158 $question_new_id = $wpdb->insert_id;
2159 $question_ids_new[] = $question_new_id;
2160
2161 // --------------------------- Answers Table ------------Start--------------- //
2162 // $answer_ordering = 1;
2163 if( isset( $question['answers_add'] ) && !empty( $question['answers_add'] ) ){
2164 foreach ($question['answers_add'] as $answer_id => $answer) {
2165 $answer_id = absint(intval($answer_id));
2166 $answer_ordering = ( isset($answer['ordering']) && $answer['ordering'] != '' ) ? $answer['ordering'] : '';
2167 $answer_title = ( isset($answer['title']) && trim( $answer['title'] ) != '' ) ? Survey_Maker_Data::admin_level_sanitize( $answer['title'] ) : __( 'Option', "survey-maker" ) . ' ' . $answer_ordering;
2168 $answer_image = '';
2169 if ( isset( $answer['image'] ) && $answer['image'] != '' ) {
2170 $answer_image = $answer['image'];
2171 }
2172 $placeholder = '';
2173 $answer_result = $wpdb->insert(
2174 $answers_table,
2175 array(
2176 'question_id' => $question_new_id,
2177 'answer' => $answer_title,
2178 'image' => $answer_image,
2179 'ordering' => $answer_ordering,
2180 'placeholder' => $placeholder,
2181 ),
2182 array(
2183 '%d', // question_id
2184 '%s', // answer
2185 '%s', // image
2186 '%d', // ordering
2187 '%s', // placeholder
2188 )
2189 );
2190
2191 // $answer_ordering++;
2192 }
2193 }
2194 // --------------------------- Answers Table ------------End--------------- //
2195
2196 // $question_ordering++;
2197 }
2198 }
2199 // --------------------------- Question Table ------------End--------------- //
2200
2201 // $section_ordering++;
2202 }
2203 // --------------------------- Sections Table ------------End--------------- //
2204 }
2205
2206 $message = '';
2207 if( $id == 0 ){
2208 $sections_count = count( $section_ids_array );
2209 $questions_count = count( $question_ids_new );
2210 $section_ids = empty( $section_ids_array ) ? '' : implode( ',', $section_ids_array );
2211 $question_ids = empty( $question_ids_new ) ? '' : implode( ',', $question_ids_new );
2212 $result = $wpdb->insert(
2213 $table,
2214 array(
2215 'author_id' => $author_id,
2216 'title' => $title,
2217 'description' => $description,
2218 'category_ids' => $category_ids,
2219 'question_ids' => $question_ids,
2220 'sections_count' => $sections_count,
2221 'questions_count' => $questions_count,
2222 'image' => $image,
2223 'status' => $status,
2224 'trash_status' => $trash_status,
2225 'date_created' => $date_created,
2226 'date_modified' => $date_modified,
2227 'ordering' => $ordering,
2228 'post_id' => $post_id,
2229 'section_ids' => $section_ids,
2230 'options' => json_encode( $options ),
2231 ),
2232 array(
2233 '%d', // author_id
2234 '%s', // title
2235 '%s', // description
2236 '%s', // category_ids
2237 '%s', // question_ids
2238 '%d', // sections_count
2239 '%d', // questions_count
2240 '%s', // image
2241 '%s', // status
2242 '%s', // trash_status
2243 '%s', // date_created
2244 '%s', // date_modified
2245 '%d', // ordering
2246 '%d', // post_id
2247 '%s', // section_ids
2248 '%s', // options
2249 )
2250 );
2251
2252 $inserted_id = $wpdb->insert_id;
2253
2254 $post_type_args = array(
2255 'survey_id' => $inserted_id,
2256 'author_id' => $author_id,
2257 'survey_title' => $title,
2258 );
2259
2260 $custom_post_id = Survey_Maker_Custom_Post_Type::survey_add_custom_post($post_type_args);
2261 $message = 'created';
2262 }else{
2263 if( ! empty( $section_ids ) ){
2264 if( ! empty( $section_ids_array ) ){
2265 $section_ids = array_merge( $section_ids, $section_ids_array );
2266 }
2267 }else{
2268 if( ! empty( $section_ids_array ) ){
2269 $section_ids = array_merge( $section_ids, $section_ids_array );
2270 }
2271 }
2272 $sections_count = count( $section_ids );
2273 $section_ids = !empty( $section_ids ) ? implode(',', $section_ids) : '';
2274 // $question_ids = empty( $question_ids_new ) ? '' : implode( ',', $question_ids_new );
2275 if( ! empty( $question_ids ) ){
2276 if( ! empty( $question_ids_new ) ){
2277 $question_ids = array_merge( $question_ids, $question_ids_new );
2278 }
2279 }else{
2280 if( ! empty( $question_ids_new ) ){
2281 $question_ids = array_merge( $question_ids, $question_ids_new );
2282 }
2283 }
2284 $questions_count = count( $question_ids );
2285 $question_ids = empty( $question_ids ) ? '' : implode( ',', $question_ids );
2286
2287
2288 $result = $wpdb->update(
2289 $table,
2290 array(
2291 'author_id' => $author_id,
2292 'title' => $title,
2293 'description' => $description,
2294 'category_ids' => $category_ids,
2295 'question_ids' => $question_ids,
2296 'sections_count' => $sections_count,
2297 'questions_count' => $questions_count,
2298 'image' => $image,
2299 'status' => $status,
2300 'date_created' => $date_created,
2301 'date_modified' => $date_modified,
2302 'post_id' => $post_id,
2303 'section_ids' => $section_ids,
2304 'options' => json_encode( $options ),
2305 ),
2306 array( 'id' => $id ),
2307 array(
2308 '%d', // author_id
2309 '%s', // title
2310 '%s', // description
2311 '%s', // category_ids
2312 '%s', // question_ids
2313 '%d', // sections_count
2314 '%d', // questions_count
2315 '%s', // image
2316 '%s', // status
2317 '%s', // date_created
2318 '%s', // date_modified
2319 '%d', // post_id
2320 '%s', // section_ids
2321 '%s', // options
2322 ),
2323 array( '%d' )
2324 );
2325
2326 $inserted_id = $id;
2327 $message = 'updated';
2328 }
2329
2330 $ays_survey_tab = isset($_POST['ays_survey_tab']) ? sanitize_text_field( $_POST['ays_survey_tab'] ) : 'tab1';
2331
2332 if($message == 'created'){
2333 setcookie('ays_survey_created_new', $inserted_id, time() + 3600, '/');
2334 $custom_post_url = array(
2335 'post_type' => 'ays-survey-maker',
2336 'p' => $custom_post_id,
2337 'preview' => 'true',
2338 );
2339 $custom_post_url_ready = http_build_query($custom_post_url);
2340 $ready_url = get_home_url();
2341 $ready_url .= '/?' . $custom_post_url_ready;
2342 setcookie('ays_survey_created_new_'.$inserted_id.'_post_id', $ready_url, time() + 3600, '/');
2343 }
2344
2345 if( $result >= 0 ) {
2346 if($save_type == 'apply'){
2347 if($id == 0){
2348 $url = esc_url_raw( add_query_arg( array(
2349 "action" => "edit",
2350 "id" => $inserted_id,
2351 "tab" => $ays_survey_tab,
2352 "status" => $message
2353 ) ) );
2354 }else{
2355 $url = esc_url_raw( add_query_arg( array(
2356 "tab" => $ays_survey_tab,
2357 "status" => $message
2358 ) ) );
2359 }
2360 wp_redirect( $url );
2361 }elseif($save_type == 'save_new'){
2362 $url = remove_query_arg( array('id') );
2363 $url = esc_url_raw( add_query_arg( array(
2364 "action" => "add",
2365 "status" => $message
2366 ), $url ) );
2367 wp_redirect( $url );
2368 }else{
2369 $url = remove_query_arg( array('action', 'id') );
2370 $url = esc_url_raw( add_query_arg( array(
2371 "tab" => $ays_survey_tab,
2372 "status" => $message
2373 ), $url ) );
2374 wp_redirect( $url );
2375 }
2376 }
2377
2378 }
2379 }
2380
2381 private function get_max_id() {
2382 global $wpdb;
2383 $table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
2384
2385 $sql = "SELECT MAX(id) FROM {$table}";
2386
2387 $result = $wpdb->get_var($sql);
2388
2389 return $result;
2390 }
2391
2392 /**
2393 * Delete a customer record.
2394 *
2395 * @param int $id customer ID
2396 */
2397 public static function delete_items( $id ) {
2398 global $wpdb;
2399
2400 // ------------------------------------------------------------------
2401 // Delete related data from custom plugin tables first
2402 // ------------------------------------------------------------------
2403
2404 $questions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "questions";
2405 $sections_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "sections";
2406 $submissions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions";
2407 $submissions_questions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions_questions";
2408 $answers_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "answers";
2409 $surveys_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
2410
2411 // Fetch survey row to obtain related section/question IDs
2412 $survey_row = self::get_item_by_id( $id );
2413
2414 // Delete questions (and their submissions) belonging to the survey
2415 $question_ids = array();
2416 if ( ! empty( $survey_row['question_ids'] ) ) {
2417 $question_ids = array_map( 'absint', array_filter( explode( ',', $survey_row['question_ids'] ) ) );
2418 }
2419
2420 if ( ! empty( $question_ids ) ) {
2421 // Remove answer options for those questions
2422 $wpdb->query( "DELETE FROM {$answers_table} WHERE question_id IN (" . implode( ',', $question_ids ) . ")" );
2423 // Remove questions themselves
2424 $wpdb->query( "DELETE FROM {$questions_table} WHERE id IN (" . implode( ',', $question_ids ) . ")" );
2425 // Remove any answers users have submitted for those questions
2426 $wpdb->query( "DELETE FROM {$submissions_questions_table} WHERE question_id IN (" . implode( ',', $question_ids ) . ")" );
2427 }
2428
2429 // Delete sections belonging to the survey
2430 $section_ids = array();
2431 if ( ! empty( $survey_row['section_ids'] ) ) {
2432 $section_ids = array_map( 'absint', array_filter( explode( ',', $survey_row['section_ids'] ) ) );
2433 }
2434
2435 if ( ! empty( $section_ids ) ) {
2436 $wpdb->query( "DELETE FROM {$sections_table} WHERE id IN (" . implode( ',', $section_ids ) . ")" );
2437 }
2438
2439 // Remove submissions linked to this survey
2440 $wpdb->delete(
2441 $submissions_table,
2442 array( 'survey_id' => absint( $id ) ),
2443 array( '%d' )
2444 );
2445
2446 // Finally, delete the survey record itself
2447 $wpdb->delete(
2448 $surveys_table,
2449 array( 'id' => absint( $id ) ),
2450 array( '%d' )
2451 );
2452
2453 // ------------------------------------------------------------------
2454 // Remove associated custom post (if any)
2455 // ------------------------------------------------------------------
2456 $survey_custom_post_id = Survey_Maker_Data::get_survey_current_column( $id, 'custom_post_id', 'trashed' );
2457 if ( isset( $survey_custom_post_id ) && $survey_custom_post_id > 0 ) {
2458 $survey_custom_post_id = intval( $survey_custom_post_id );
2459 $check_custom_post_type = get_post_type( $survey_custom_post_id );
2460 if ( $check_custom_post_type === 'ays-survey-maker' ) {
2461 wp_delete_post( $survey_custom_post_id, true );
2462 }
2463 }
2464 }
2465
2466 /**
2467 * Move to trash a customer record.
2468 *
2469 * @param int $id customer ID
2470 */
2471 public static function trash_items( $id ) {
2472 global $wpdb;
2473 $db_item = self::get_item_by_id( $id );
2474
2475 $wpdb->update(
2476 $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions",
2477 array( 'status' => 'trashed' ),
2478 array( 'survey_id' => absint( $id ) ),
2479 array( '%s', '%s' ),
2480 array( '%d' )
2481 );
2482
2483 $wpdb->update(
2484 $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys",
2485 array(
2486 'status' => 'trashed',
2487 'trash_status' => $db_item['status'],
2488 ),
2489 array( 'id' => absint( $id ) ),
2490 array( '%s', '%s' ),
2491 array( '%d' )
2492 );
2493
2494 }
2495
2496 /**
2497 * Restore a customer record.
2498 *
2499 * @param int $id customer ID
2500 */
2501 public static function restore_items( $id ) {
2502 global $wpdb;
2503 $db_item = self::get_item_by_id( $id );
2504
2505 $wpdb->update(
2506 $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions",
2507 array( 'status' => 'published' ),
2508 array( 'survey_id' => absint( $id ) ),
2509 array( '%s', '%s' ),
2510 array( '%d' )
2511 );
2512
2513 $wpdb->update(
2514 $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys",
2515 array(
2516 'status' => $db_item['trash_status'],
2517 'trash_status' => '',
2518 ),
2519 array( 'id' => absint( $id ) ),
2520 array( '%s', '%s' ),
2521 array( '%d' )
2522 );
2523 }
2524
2525 /**
2526 * Duplicate a customer record.
2527 *
2528 * @param int $id customer ID
2529 */
2530 public function duplicate_items( $id ){
2531 global $wpdb;
2532 $survey_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
2533 $sections_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "sections";
2534 $questions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "questions";
2535 $answers_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "answers";
2536 $object = $this->get_item_by_id( $id );
2537 $question_id_arr = isset($object['question_ids']) && $object['question_ids'] != "" ? explode("," , $object['question_ids']) : array();
2538 $old_questions = array();
2539 $survey_id = isset($object['id']) && $object['id'] != "" ? $object['id'] : "";
2540 $section_ids = isset($object['section_ids']) && $object['section_ids'] != "" ? $object['section_ids'] : array();
2541 // Get sections
2542 $old_sections = Survey_Maker_Data::get_sections_by_survey_id($section_ids);
2543 $section_new_ids = array();
2544 // Get questions
2545 $old_questions = Survey_Maker_Data::get_question_by_ids($question_id_arr);
2546 $question_new_ids = array();
2547
2548 foreach($old_sections as $section_key => $section_value){
2549 $section_id = isset($section_value['id']) && $section_value['id'] != "" ? sanitize_text_field($section_value['id']) : "";
2550 $new_section_title = isset($section_value['title']) && $section_value['title'] != "" ? sanitize_text_field($section_value['title']) : "";
2551 $new_section_desc = isset($section_value['description']) && $section_value['description'] != "" ? sanitize_text_field($section_value['description']) : "";
2552 $new_section_ordering = isset($section_value['ordering']) && $section_value['ordering'] != "" ? intval(sanitize_text_field($section_value['ordering'])) : "";
2553 $new_section_options = isset($section_value['options']) && $section_value['options'] != "" ? sanitize_text_field($section_value['options']) : "";
2554
2555
2556 $sresult = $wpdb->insert(
2557 $sections_table,
2558 array(
2559 'title' => $new_section_title,
2560 'description' => $new_section_desc,
2561 'ordering' => $new_section_ordering,
2562 'options' => $new_section_options,
2563 ),
2564 array(
2565 '%s', // title
2566 '%s', // description
2567 '%d', // ordering
2568 '%s', // options
2569 )
2570 );
2571 $section_new_ids[] = $wpdb->insert_id;
2572 $section_new_ids_for_question[$section_id] = $wpdb->insert_id;
2573 }
2574
2575 foreach($old_questions as $question_key => $question_value){
2576 $question_id = isset($question_value->id) && $question_value->id != "" ? intval(sanitize_text_field($question_value->id)) : "";
2577 $question_answers = isset($question_value->answers) && $question_value->answers != "" ? $question_value->answers : array();
2578 $new_question_author_id = isset($question_value->author_id) && $question_value->author_id != "" ? intval(sanitize_text_field($question_value->author_id)) : "";
2579 $new_question_section_id = isset($section_new_ids_for_question[$question_value->section_id]) && $section_new_ids_for_question[$question_value->section_id] != "" ? intval(sanitize_text_field($section_new_ids_for_question[$question_value->section_id])) : "";
2580 $new_question_cat_ids = isset($question_value->category_ids) && $question_value->category_ids != "" ? sanitize_text_field($question_value->category_ids) : "";
2581 $new_question_title = isset($question_value->question) && $question_value->question != "" ? sanitize_text_field($question_value->question) : "";
2582 $new_question_type = isset($question_value->type) && $question_value->type != "" ? sanitize_text_field($question_value->type) : "";
2583 $new_question_status = isset($question_value->status) && $question_value->status != "" ? sanitize_text_field($question_value->status) : "";
2584 $new_question_create_date = current_time( 'mysql' );
2585 $new_question_modified_date = current_time( 'mysql' );
2586 $new_question_user_variant = isset($question_value->user_variant) && $question_value->user_variant != "" ? sanitize_text_field($question_value->user_variant) : "";
2587 $new_question_user_explanation = isset($question_value->user_explanation) && $question_value->user_explanation != "" ? sanitize_text_field($question_value->user_explanation) : "";
2588 $new_question_image = isset($question_value->image) && $question_value->image != "" ? sanitize_text_field($question_value->image) : "";
2589 $new_question_ordering = isset($question_value->ordering) && $question_value->ordering != "" ? intval(sanitize_text_field($question_value->ordering)) : "";
2590 $new_question_options = isset($question_value->options) && $question_value->options != "" ? sanitize_text_field($question_value->options) : "";
2591
2592 $question_result = $wpdb->insert(
2593 $questions_table,
2594 array(
2595 'author_id' => $new_question_author_id,
2596 'section_id' => $new_question_section_id,
2597 'category_ids' => $new_question_cat_ids,
2598 'question' => $new_question_title,
2599 'type' => $new_question_type,
2600 'status' => $new_question_status,
2601 'date_created' => $new_question_create_date,
2602 'date_modified' => $new_question_modified_date,
2603 'user_variant' => $new_question_user_variant,
2604 'user_explanation' => $new_question_user_explanation,
2605 'image' => $new_question_image,
2606 'ordering' => $new_question_ordering,
2607 'options' => $new_question_options,
2608 ),
2609 array(
2610 '%d', // author id
2611 '%d', // section id
2612 '%s', // category ids
2613 '%s', // title
2614 '%s', // type
2615 '%s', // status
2616 '%s', // date created
2617 '%s', // date modified
2618 '%s', // user variant
2619 '%s', // user xplanation
2620 '%s', // image
2621 '%d', // ordering
2622 '%s', // options
2623 )
2624 );
2625 $question_new_ids[] = $wpdb->insert_id;
2626 $question_new_ids_for_answers[$question_id] = $wpdb->insert_id;
2627 if(!empty($question_answers)){
2628 foreach($question_answers as $answer_key => $answer_value){
2629 $new_answer_question_id = isset($question_new_ids_for_answers[$answer_value->question_id]) && $question_new_ids_for_answers[$answer_value->question_id] != "" ? intval(sanitize_text_field($question_new_ids_for_answers[$answer_value->question_id])) : "";
2630 $new_answer_title = isset($answer_value->answer) && $answer_value->answer != "" ? sanitize_text_field($answer_value->answer) : "";
2631 $new_answer_image = isset($answer_value->image) && $answer_value->image != "" ? sanitize_text_field($answer_value->image) : "";
2632 $new_answer_ordering = isset($answer_value->ordering) && $answer_value->ordering != "" ? sanitize_text_field($answer_value->ordering) : "";
2633 $new_answer_placeholder = isset($answer_value->placeholder) && $answer_value->placeholder != "" ? sanitize_text_field($answer_value->placeholder) : "";
2634 $answer_result = $wpdb->insert(
2635 $answers_table,
2636 array(
2637 'question_id' => $new_answer_question_id,
2638 'answer' => $new_answer_title,
2639 'image' => $new_answer_image,
2640 'ordering' => $new_answer_ordering,
2641 'placeholder' => $new_answer_placeholder,
2642 ),
2643 array(
2644 '%d', // question id
2645 '%s', // title
2646 '%s', // image
2647 '%s', // ordering
2648 '%d', // placeholder
2649 )
2650 );
2651 }
2652 }
2653 }
2654
2655 $author_id = get_current_user_id();
2656
2657 $max_id = $this->get_max_id();
2658 $ordering = ( $max_id != NULL ) ? ( $max_id + 1 ) : 1;
2659
2660 $options = json_decode($object['options'], true);
2661
2662 $result = $wpdb->insert(
2663 $survey_table,
2664 array(
2665 'author_id' => $author_id,
2666 'title' => "Copy - " . $object['title'],
2667 'description' => $object['description'],
2668 'category_ids' => $object['category_ids'],
2669 'question_ids' => implode("," , $question_new_ids),
2670 'section_ids' => implode("," , $section_new_ids),
2671 'sections_count' => $object['sections_count'],
2672 'questions_count' => $object['questions_count'],
2673 'date_created' => current_time( 'mysql' ),
2674 'date_modified' => current_time( 'mysql' ),
2675 'image' => $object['image'],
2676 'status' => $object['status'],
2677 'trash_status' => $object['trash_status'],
2678 'ordering' => $ordering,
2679 'post_id' => 0,
2680 'options' => json_encode( $options, JSON_UNESCAPED_SLASHES ),
2681 ),
2682 array(
2683 '%d', // author_id
2684 '%s', // title
2685 '%s', // description
2686 '%s', // category_ids
2687 '%s', // question_ids
2688 '%s', // section ids
2689 '%d', // sections count
2690 '%d', // questions count
2691 '%s', // date_created
2692 '%s', // date_modified
2693 '%s', // image
2694 '%s', // status
2695 '%s', // trash_status
2696 '%d', // ordering
2697 '%d', // post_id
2698 '%s', // options
2699 )
2700 );
2701
2702 $inserted_id = $wpdb->insert_id;
2703 $post_type_args = array(
2704 'survey_id' => $inserted_id,
2705 'author_id' => $author_id,
2706 'survey_title' => "Copy - " . $object['title'],
2707 );
2708 $custom_post_id = Survey_Maker_Custom_Post_Type::survey_add_custom_post($post_type_args);
2709 }
2710
2711
2712
2713 /**
2714 * Returns the count of records in the database.
2715 *
2716 * @return null|string
2717 */
2718 public static function record_count() {
2719 global $wpdb;
2720 $filter = array();
2721 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
2722
2723 if( isset( $_GET['filterby'] ) && intval($_GET['filterby']) > 0){
2724 $cat_id = intval( esc_attr( $_GET['filterby'] ) );
2725 $filter[] = ' FIND_IN_SET('.$cat_id.',category_ids) ';
2726 }
2727
2728 if(! empty( $_REQUEST['filterbyuser'] ) && intval( $_REQUEST['filterbyuser'] ) > 0){
2729 $user_id = intval( esc_attr( $_REQUEST['filterbyuser'] ) );
2730 $filter[] = ' author_id ='.$user_id;
2731 }
2732
2733 if( isset( $_REQUEST['fstatus'] ) ){
2734 $fstatus = esc_attr( $_REQUEST['fstatus'] );
2735 if($fstatus !== null){
2736 $filter[] = " status = '". esc_sql( $fstatus ) ."' ";
2737 }
2738 }else{
2739 $filter[] = " status != 'trashed' ";
2740 }
2741
2742 if(count($filter) !== 0){
2743 $sql .= " WHERE ".implode(" AND ", $filter);
2744 }
2745
2746 return $wpdb->get_var( $sql );
2747 }
2748
2749 public static function all_record_count() {
2750 global $wpdb;
2751
2752 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys WHERE status != 'trashed'";
2753
2754 if( isset( $_GET['filterby'] ) && intval($_GET['filterby']) > 0){
2755 $cat_id = intval( esc_attr( $_GET['filterby'] ) );
2756 $sql .= ' AND '.$cat_id.' IN (category_ids) ';
2757 }
2758
2759 if(! empty( $_REQUEST['filterbyuser'] ) && intval( $_REQUEST['filterbyuser'] ) > 0){
2760 $user_id = intval( esc_attr( $_REQUEST['filterbyuser'] ) );
2761 $sql .= ' AND author_id ='.$user_id;
2762 }
2763
2764 return $wpdb->get_var( $sql );
2765 }
2766
2767 public static function published_questions_record_count() {
2768 global $wpdb;
2769
2770 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "questions WHERE status = 'published'";
2771
2772 return $wpdb->get_var( $sql );
2773 }
2774
2775 public static function get_statused_record_count( $status ) {
2776 global $wpdb;
2777
2778 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys WHERE status='" . esc_sql( $status ) . "'";
2779
2780 if( isset( $_GET['filterby'] ) && intval($_GET['filterby']) > 0){
2781 $cat_id = intval( esc_attr( $_GET['filterby'] ) );
2782 $sql .= ' AND '.$cat_id.' IN (category_ids) ';
2783 }
2784
2785 if(! empty( $_REQUEST['filterbyuser'] ) && intval( $_REQUEST['filterbyuser'] ) > 0){
2786 $user_id = intval( esc_attr( $_REQUEST['filterbyuser'] ) );
2787 $sql .= ' AND author_id ='.$user_id;
2788 }
2789
2790 return $wpdb->get_var( $sql );
2791 }
2792
2793 public static function get_passed_users_count( $id ) {
2794 global $wpdb;
2795 $id = absint($id);
2796 $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions WHERE survey_id=".$id;
2797
2798 return $wpdb->get_var( $sql );
2799 }
2800
2801
2802 /** Text displayed when no customer data is available */
2803 public function no_items() {
2804 Survey_Maker_Data::survey_no_items_list_tables();
2805 }
2806
2807
2808 /**
2809 * Render a column when no column specific method exist.
2810 *
2811 * @param array $item
2812 * @param string $column_name
2813 *
2814 * @return mixed
2815 */
2816 public function column_default( $item, $column_name ) {
2817 switch ( $column_name ) {
2818 case 'title':
2819 case 'category_ids':
2820 case 'shortcode':
2821 case 'code_include':
2822 case 'items_count':
2823 case 'sections_count':
2824 case 'author_id':
2825 case 'submissions_count':
2826 case 'status':
2827 case 'id':
2828 return $item[ $column_name ];
2829 break;
2830 default:
2831 return print_r( $item, true ); //Show the whole array for troubleshooting purposes
2832 }
2833 }
2834
2835 /**
2836 * Render the bulk edit checkbox
2837 *
2838 * @param array $item
2839 *
2840 * @return string
2841 */
2842 function column_cb( $item ) {
2843 return sprintf(
2844 '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['id']
2845 );
2846 }
2847
2848
2849 /**
2850 * Method for name column
2851 *
2852 * @param array $item an array of DB data
2853 *
2854 * @return string
2855 */
2856 function column_title( $item ) {
2857 if($item['status'] == 'trashed'){
2858 $delete_nonce = wp_create_nonce( $this->plugin_name . '-delete-survey' );
2859 }else{
2860 $delete_nonce = wp_create_nonce( $this->plugin_name . '-trash-survey' );
2861 }
2862
2863 $survey_title = (isset($item['title']) && $item['title'] != "") ? esc_attr(stripcslashes($item['title'])) : "";
2864 $custom_post_id = isset($item['custom_post_id']) && $item['custom_post_id'] != 0 && $item['custom_post_id'] != '' ? esc_attr($item['custom_post_id']) : 0;
2865
2866 $q = esc_attr( $survey_title );
2867
2868 $restitle = Survey_Maker_Admin::ays_restriction_string( "word", $survey_title, $this->title_length );
2869
2870 $fstatus = '';
2871 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
2872 $fstatus = '&fstatus=' . esc_attr( $_GET['fstatus'] );
2873 }
2874
2875 $title = sprintf( '<a href="?page=%s&action=%s&id=%d" title="%s">%s</a>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ), $q, $survey_title);
2876
2877 $actions = array();
2878 if($item['status'] == 'trashed'){
2879 $title = sprintf( '<a><strong>%s</strong></a>', $restitle );
2880 $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 );
2881 $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 );
2882 }else{
2883 $draft_text = '';
2884 if( $item['status'] == 'draft' && !( isset( $_GET['fstatus'] ) && $_GET['fstatus'] == 'draft' )){
2885 $draft_text = ' — ' . '<span class="post-state">' . __( "Draft", "survey-maker" ) . '</span>';
2886 }
2887 $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 );
2888
2889 $actions['edit'] = sprintf( '<a href="?page=%s&action=%s&id=%d">'. __('Edit', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ) );
2890
2891 $actions['submissions'] = sprintf( '<a href="?page=%s&survey=%d">'. __('View submissions', "survey-maker") .'</a>', esc_attr( $_REQUEST['page'] ) . '-each-submission', absint( $item['id'] ) );
2892 if($custom_post_id > 0){
2893 $actions['custom_posts'] = sprintf( '<a href="%s" target="_blank">'. __('Preview', "survey-maker") .'</a>', esc_url( add_query_arg( 'preview', 'true', get_permalink($item['custom_post_id']) ) ));
2894 }
2895 // $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 );
2896 $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 );
2897 $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 );
2898 }
2899
2900 return $title . $this->row_actions( $actions );
2901 }
2902
2903 function column_category_ids( $item ) {
2904 global $wpdb;
2905
2906 // Survey categories IDs
2907 $category_ids = isset( $item['category_ids'] ) && $item['category_ids'] != '' ? $item['category_ids'] : '';
2908 // $category_ids = $category_ids == '' ? array() : explode( ',', $category_ids );
2909
2910 if( ! empty( $category_ids ) ){
2911 $sql = "SELECT * FROM " . $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "survey_categories WHERE id IN (" . esc_sql( $category_ids ) . ")";
2912
2913 $results = $wpdb->get_results($sql, 'ARRAY_A');
2914 $category_location = array();
2915 foreach ($results as $key => $value) {
2916 $category_location[] = sprintf( '<a href="?page=%s&action=%s&id=%d" target="_blank">%s</a>', 'survey-maker-survey-categories', 'edit', $value['id'], $value['title']);
2917 }
2918
2919 $titles = implode( ', ', $category_location );
2920
2921 return $titles;
2922 }
2923
2924 return '-';
2925 }
2926
2927 function column_code_include( $item ) {
2928 $shortcode = htmlentities('[\'[ays_survey id="'.$item["id"].'"]\']');
2929 return '<input type="text" onClick="this.setSelectionRange(0, this.value.length)" readonly value="<?php echo do_shortcode('.$shortcode.'); ?>" style="max-width:100%;" />';
2930 }
2931
2932 function column_shortcode( $item ) {
2933 $shortcode = htmlentities('[ays_survey id="'.$item["id"].'"]');
2934 return '<input type="text" onClick="this.setSelectionRange(0, this.value.length)" readonly value="'.$shortcode.'" />';
2935 }
2936
2937 function column_status( $item ) {
2938 global $wpdb;
2939 $status = ucfirst( esc_attr($item['status']) );
2940 $date = date( 'Y/m/d', strtotime( esc_attr($item['date_modified']) ) );
2941 $title_date = date( 'l jS \of F Y h:i:s A', strtotime( esc_attr($item['date_modified']) ) );
2942 $html = "<p style='font-size:14px;margin:0;'>" . esc_html($status) . "</p>";
2943 $html .= "<p style=';font-size:14px;margin:0;text-decoration: dotted underline;' title='" . esc_attr($title_date) . "'>" . esc_attr($date) . "</p>";
2944 return $html;
2945 }
2946
2947 function column_author_id( $item ) {
2948 $user = get_user_by( 'id', $item['author_id'] );
2949
2950 $author_name = '';
2951 if($user !== false){
2952 if($user->data->display_name == ''){
2953 if($user->data->user_nicename == ''){
2954 $author_name = $user->data->user_login;
2955 }else{
2956 $author_name = $user->data->user_nicename;
2957 }
2958 }else{
2959 $author_name = $user->data->display_name;
2960 }
2961 }
2962 else{
2963 $author_name = '<span style="color:red;">'.__('Deleted User' , "survey-maker").'</span>';
2964 }
2965 return $author_name;
2966 }
2967
2968 function column_submissions_count( $item ) {
2969 $id = $item['id'];
2970 $passed_count = $this->get_passed_users_count( $id );
2971 $passed_count = sprintf( '<a href="?page=%s&survey=%d">'. $passed_count .'</a>', esc_attr( $_REQUEST['page'] ) . '-each-submission', absint( $item['id'] ) );
2972 $text = "<p style='font-size:14px;'>".$passed_count."</p>";
2973 return $text;
2974 }
2975
2976 function column_items_count( $item ) {
2977 global $wpdb;
2978 if(empty($item['questions_count'])){
2979 $count = 0;
2980 }else{
2981 $count = intval($item['questions_count']);
2982 }
2983 return "<p style='font-size:14px;'>" . $count . "</p>";
2984 }
2985
2986 function column_sections_count( $item ) {
2987 global $wpdb;
2988 if(empty($item['sections_count'])){
2989 $count = 0;
2990 }else{
2991 $count = intval($item['sections_count']);
2992 }
2993 return "<p style='font-size:14px;'>" . $count . "</p>";
2994 }
2995
2996 /**
2997 * Associative array of columns
2998 *
2999 * @return array
3000 */
3001 function get_columns() {
3002 $columns = array(
3003 'cb' => '<input type="checkbox" />',
3004 'title' => __( 'Title', "survey-maker" ),
3005 );
3006
3007 if( is_super_admin() ){
3008 $columns['author_id'] = __( 'Author', "survey-maker" );
3009 }
3010
3011 $columns['category_ids'] = __( 'Categories', "survey-maker" );
3012 $columns['shortcode'] = __( 'Shortcode', "survey-maker" );
3013 $columns['code_include'] = __( 'Code include', "survey-maker" );
3014 $columns['sections_count'] = __( 'Sections', "survey-maker" );
3015 $columns['items_count'] = __( 'Questions', "survey-maker" );
3016 $columns['submissions_count'] = __( 'Submissions', "survey-maker" );
3017 $columns['status'] = __( 'Status', "survey-maker" );
3018 $columns['id'] = __( 'ID', "survey-maker" );
3019
3020 if( isset( $_GET['action'] ) && ( $_GET['action'] == 'add' || $_GET['action'] == 'edit' ) ){
3021 return array();
3022 }
3023
3024 return $columns;
3025 }
3026
3027
3028 /**
3029 * Columns to make sortable.
3030 *
3031 * @return array
3032 */
3033 public function get_sortable_columns() {
3034 $sortable_columns = array(
3035 'title' => array( 'title', true ),
3036 'id' => array( 'id', true ),
3037 );
3038
3039 return $sortable_columns;
3040 }
3041
3042 /**
3043 * Columns to make hidden.
3044 *
3045 * @return array
3046 */
3047 public function get_hidden_columns() {
3048 $sortable_columns = array(
3049 'category_ids',
3050 'code_include',
3051 );
3052
3053 return $sortable_columns;
3054 }
3055
3056 /**
3057 * Returns an associative array containing the bulk action
3058 *
3059 * @return array
3060 */
3061 public function get_bulk_actions() {
3062 $actions = array(
3063 // 'bulk-duplicate' => __( 'Duplicate', "survey-maker" ),
3064 'bulk-trash' => __( 'Move to trash', "survey-maker" ),
3065 );
3066
3067 if(isset($_GET['fstatus']) && esc_attr( $_GET['fstatus'] ) == 'trashed'){
3068 $actions = array(
3069 'bulk-restore' => __( 'Restore', "survey-maker" ),
3070 'bulk-delete' => __( 'Delete Permanently', "survey-maker" ),
3071 );
3072 }
3073
3074 return $actions;
3075 }
3076
3077
3078
3079 /**
3080 * Handles data query and filter, sorting, and pagination.
3081 */
3082 public function prepare_items() {
3083 global $wpdb;
3084 $this->_column_headers = $this->get_column_info();
3085
3086 /** Process bulk action */
3087 $this->process_bulk_action();
3088
3089 $per_page = $this->get_items_per_page( 'surveys_per_page', 20 );
3090 $current_page = $this->get_pagenum();
3091 $total_items = self::record_count();
3092
3093 $this->set_pagination_args( array(
3094 'total_items' => $total_items, //WE have to calculate the total number of items
3095 'per_page' => $per_page, //WE have to determine how many items to show on a page
3096 'total_pages' => ceil( $total_items / $per_page )
3097 ) );
3098
3099 $search = ( isset( $_REQUEST['s'] ) ) ? esc_attr( $_REQUEST['s'] ) : false;
3100
3101 $do_search = ( $search ) ? sprintf( " title LIKE '%%%s%%' ", esc_sql( $wpdb->esc_like( $search ) ) ) : '';
3102
3103 $this->items = self::get_items( $per_page, $current_page, $do_search );
3104 }
3105
3106 public function process_bulk_action() {
3107
3108 //Detect when a bulk action is being triggered...
3109 if ( 'delete' === $this->current_action() ) {
3110
3111 // In our file that handles the request, verify the nonce.
3112 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
3113
3114 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-delete-survey' ) ) {
3115 die( 'Go get a life script kiddies' );
3116 }
3117 else {
3118 self::delete_items( absint( esc_attr($_GET['id']) ) );
3119
3120 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3121 // add_query_arg() return the current url
3122
3123 $add_query_args = array(
3124 "status" => 'deleted'
3125 );
3126 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3127 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3128 }
3129 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3130 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3131 wp_redirect( $url );
3132 }
3133
3134 }
3135
3136 //Detect when a bulk action is being triggered...
3137 if ( 'trash' === $this->current_action() ) {
3138
3139 // In our file that handles the request, verify the nonce.
3140 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
3141
3142 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-trash-survey' ) ) {
3143 die( 'Go get a life script kiddies' );
3144 }
3145 else {
3146 self::trash_items( absint( esc_attr($_GET['id']) ) );
3147
3148 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3149 // add_query_arg() return the current url
3150
3151 $add_query_args = array(
3152 "status" => 'trashed'
3153 );
3154 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3155 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3156 }
3157 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3158 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3159 wp_redirect( $url );
3160 }
3161
3162 }
3163
3164 //Detect when a bulk action is being triggered...
3165 if ( 'restore' === $this->current_action() ) {
3166
3167 // In our file that handles the request, verify the nonce.
3168 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
3169
3170 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-delete-survey' ) ) {
3171 die( 'Go get a life script kiddies' );
3172 }
3173 else {
3174 self::restore_items( absint( esc_attr($_GET['id']) ) );
3175
3176 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3177 // add_query_arg() return the current url
3178
3179 $add_query_args = array(
3180 "status" => 'restored'
3181 );
3182 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3183 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3184 }
3185 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3186 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3187 wp_redirect( $url );
3188 }
3189
3190 }
3191
3192 //Detect when a bulk action is being triggered...
3193 if ( 'duplicate' === $this->current_action() ) {
3194
3195 // In our file that handles the request, verify the nonce.
3196 $nonce = esc_attr( $_REQUEST['_wpnonce'] );
3197
3198 if ( ! wp_verify_nonce( $nonce, $this->plugin_name . '-trash-survey' ) ) {
3199 die( 'Go get a life script kiddies' );
3200 }
3201 else {
3202 $this->duplicate_items( absint( esc_attr($_GET['id']) ) );
3203
3204 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3205 // add_query_arg() return the current url
3206
3207 $add_query_args = array(
3208 "status" => 'duplicated'
3209 );
3210 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3211 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3212 }
3213 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3214 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3215 wp_redirect( $url );
3216 }
3217
3218 }
3219
3220 // If the delete bulk action is triggered
3221 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' ) ) {
3222
3223 $delete_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
3224
3225 // loop over the array of record IDs and delete them
3226 foreach ( $delete_ids as $id ) {
3227 self::delete_items( $id );
3228 }
3229
3230 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3231 // add_query_arg() return the current url
3232 $add_query_args = array(
3233 "status" => 'all-deleted'
3234 );
3235 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3236 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3237 }
3238 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3239 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3240 wp_redirect( $url );
3241 }
3242
3243 // If the delete bulk action is triggered
3244 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-trash' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-trash' ) ) {
3245
3246 $trash_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
3247
3248 // loop over the array of record IDs and delete them
3249 foreach ( $trash_ids as $id ) {
3250 self::trash_items( $id );
3251 }
3252
3253 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3254 // add_query_arg() return the current url
3255 $add_query_args = array(
3256 "status" => 'all-trashed'
3257 );
3258 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3259 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3260 }
3261 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3262 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3263 wp_redirect( $url );
3264 }
3265
3266 // If the delete bulk action is triggered
3267 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-restore' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-restore' ) ) {
3268
3269 $restore_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
3270
3271 // loop over the array of record IDs and delete them
3272 foreach ( $restore_ids as $id ) {
3273 self::restore_items( $id );
3274 }
3275
3276 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3277 // add_query_arg() return the current url
3278 $add_query_args = array(
3279 "status" => 'all-restored'
3280 );
3281 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3282 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3283 }
3284 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3285 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3286 wp_redirect( $url );
3287 }
3288
3289 // If the delete bulk action is triggered
3290 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-duplicate' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-duplicate' ) ) {
3291
3292 $restore_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
3293
3294 // loop over the array of record IDs and delete them
3295 foreach ( $restore_ids as $id ) {
3296 $this->duplicate_items( $id );
3297 }
3298
3299 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
3300 // add_query_arg() return the current url
3301 $add_query_args = array(
3302 "status" => 'all-duplicated'
3303 );
3304 if( isset( $_GET['fstatus'] ) && $_GET['fstatus'] != '' ){
3305 $add_query_args['fstatus'] = esc_attr( $_GET['fstatus'] );
3306 }
3307 $url = remove_query_arg( array('action', 'id', '_wpnonce') );
3308 $url = esc_url_raw( add_query_arg( $add_query_args, $url ) );
3309 wp_redirect( $url );
3310 }
3311 }
3312
3313 public function survey_notices(){
3314 $status = (isset($_REQUEST['status'])) ? esc_attr( $_REQUEST['status'] ) : '';
3315
3316 if ( empty( $status ) )
3317 return;
3318
3319 $error = false;
3320 switch ( $status ) {
3321 case 'created':
3322 $updated_message = __( 'Survey created.', "survey-maker" );
3323 break;
3324 case 'updated':
3325 $updated_message = __( 'Survey saved.', "survey-maker" );
3326 break;
3327 case 'duplicated':
3328 $updated_message = __( 'Survey duplicated.', "survey-maker" );
3329 break;
3330 case 'deleted':
3331 $updated_message = __( 'Survey deleted.', "survey-maker" );
3332 break;
3333 case 'trashed':
3334 $updated_message = __( 'Survey moved to trash.', "survey-maker" );
3335 break;
3336 case 'restored':
3337 $updated_message = __( 'Survey restored.', "survey-maker" );
3338 break;
3339 case 'all-duplicated':
3340 $updated_message = __( 'Surveys are duplicated.', "survey-maker" );
3341 break;
3342 case 'all-deleted':
3343 $updated_message = __( 'Surveys are deleted.', "survey-maker" );
3344 break;
3345 case 'all-trashed':
3346 $updated_message = __( 'Surveys are moved to trash.', "survey-maker" );
3347 break;
3348 case 'all-restored':
3349 $updated_message = __( 'Surveys are restored.', "survey-maker" );
3350 break;
3351 case 'empty-title':
3352 $error = true;
3353 $updated_message = __( 'Error: Survey title can not be empty.', "survey-maker" );
3354 break;
3355 default:
3356 break;
3357 }
3358
3359 if ( empty( $updated_message ) )
3360 return;
3361
3362 $notice_class = 'success';
3363 if( $error ){
3364 $notice_class = 'error';
3365 }
3366 ?>
3367 <div class="notice notice-<?php echo esc_attr( $notice_class ); ?> is-dismissible">
3368 <p> <?php echo esc_html($updated_message); ?> </p>
3369 </div>
3370 <?php
3371 }
3372
3373 public function survey_recursive_sanitize_data(&$item, $key) {
3374 $item = sanitize_text_field($item);
3375 }
3376 }
3377