PluginProbe
Survey Maker by AYS / 5.2.3.7
Survey Maker by AYS v5.2.3.7
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / includes / lists / class-survey-maker-surveys-list-table.php

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

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