PluginProbe
Survey Maker by AYS / 5.2.2.7
Survey Maker by AYS v5.2.2.7
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.2.7, at includes/lists/class-survey-maker-surveys-list-table.php

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