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

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