PluginProbe
Survey Maker by AYS / 5.2.4.1
Survey Maker by AYS v5.2.4.1
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / admin / partials / settings / survey-maker-settings-actions.php

survey-maker-settings-actions.php in Survey Maker by AYS 5.2.4.1, at admin/partials/settings/survey-maker-settings-actions.php

304 lines 18.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class Survey_Maker_Settings_Actions {
3 private $plugin_name;
4
5 public function __construct($plugin_name) {
6 $this->plugin_name = $plugin_name;
7 }
8
9 public function store_data(){
10 global $wpdb;
11 $settings_table = $wpdb->prefix . "ayssurvey_settings";
12 $name_prefix = 'ays_';
13 if( isset($_REQUEST["settings_action"]) && wp_verify_nonce( sanitize_text_field( $_REQUEST["settings_action"] ), 'settings_action' ) ){
14 $success = 0;
15
16 $roles = (isset($_REQUEST['ays_user_roles']) && !empty($_REQUEST['ays_user_roles'])) ? array_map( 'sanitize_text_field', $_REQUEST['ays_user_roles'] ) : array('administrator');
17
18 $fields = array();
19
20 // Survey Question default type
21 $survey_default_type = (isset($_REQUEST[$name_prefix .'survey_default_type']) && $_REQUEST[$name_prefix .'survey_default_type'] != '') ? sanitize_text_field($_REQUEST[$name_prefix .'survey_default_type']) : '';
22 $survey_answer_default_count = (isset($_REQUEST[$name_prefix . 'survey_answer_default_count']) && $_REQUEST[$name_prefix . 'survey_answer_default_count'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_answer_default_count'] ) ) : 3;
23
24 // Textarea height (public)
25 $survey_textarea_height = (isset($_REQUEST[$name_prefix . 'survey_textarea_height']) && $_REQUEST[$name_prefix . 'survey_textarea_height'] != '' && $_REQUEST[$name_prefix . 'survey_textarea_height'] != 0 ) ? absint( sanitize_text_field($_REQUEST[$name_prefix . 'survey_textarea_height']) ) : 100;
26
27 // WP Editor height
28 $survey_wp_editor_height = (isset($_REQUEST[$name_prefix . 'survey_wp_editor_height']) && $_REQUEST[$name_prefix . 'survey_wp_editor_height'] != '' && $_REQUEST[$name_prefix . 'survey_wp_editor_height'] != 0) ? absint( sanitize_text_field($_REQUEST[$name_prefix . 'survey_wp_editor_height']) ) : 100 ;
29
30 // Make question required
31 $survey_make_questions_required = (isset($_REQUEST[$name_prefix . 'survey_make_questions_required']) && $_REQUEST[$name_prefix . 'survey_make_questions_required'] == 'on') ? sanitize_text_field( $_REQUEST[$name_prefix . 'survey_make_questions_required'] ) : 'off';
32
33 // Lazy loading for images
34 $survey_lazy_loading_for_images = (isset($_REQUEST[$name_prefix . 'survey_lazy_loading_for_images']) && $_REQUEST[$name_prefix . 'survey_lazy_loading_for_images'] == 'on') ? sanitize_text_field( $_REQUEST[$name_prefix . 'survey_lazy_loading_for_images'] ) : 'off';
35
36 // Do not store IP addresses
37 $survey_disable_user_ip = (isset($_REQUEST[$name_prefix . 'survey_disable_user_ip']) && $_REQUEST[$name_prefix . 'survey_disable_user_ip'] == 'on') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_disable_user_ip'] ) ) : '';
38
39 // Do not store User Names
40 $survey_disable_user_name = (isset($_REQUEST[$name_prefix . 'survey_disable_user_name']) && $_REQUEST[$name_prefix . 'survey_disable_user_name'] == 'on') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_disable_user_name'] ) ) : 'off';
41
42 // Do not store User Emails
43 $survey_disable_user_email = (isset($_REQUEST[$name_prefix . 'survey_disable_user_email']) && $_REQUEST[$name_prefix . 'survey_disable_user_email'] == 'on') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_disable_user_email'] ) ) : 'off';
44
45 $survey_submissions_title_length = (isset($_REQUEST[$name_prefix . 'survey_submissions_title_length']) && $_REQUEST[$name_prefix . 'survey_submissions_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_submissions_title_length'] ) ) : 5;
46 $survey_title_length = (isset($_REQUEST[$name_prefix . 'survey_title_length']) && $_REQUEST[$name_prefix . 'survey_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_title_length'] ) ) : 5;
47
48 $survey_categories_title_length = (isset($_REQUEST[$name_prefix . 'survey_categories_title_length']) && $_REQUEST[$name_prefix . 'survey_categories_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_categories_title_length'] ) ) : 5;
49 $survey_popups_title_length = (isset($_REQUEST[$name_prefix . 'survey_popups_title_length']) && $_REQUEST[$name_prefix . 'survey_popups_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_popups_title_length'] ) ) : 5;
50
51 //Animation top
52 $survey_animation_top = (isset($_REQUEST[$name_prefix . 'survey_animation_top']) && $_REQUEST[$name_prefix . 'survey_animation_top'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_animation_top'] ) ) : 200;
53 $survey_enable_animation_top = (isset( $_REQUEST['ays_survey_enable_animation_top'] ) && $_REQUEST['ays_survey_enable_animation_top'] ) == 'on' ? 'on' : 'off';
54
55 // Disable Survey Maker menu item notification
56 $survey_disable_survey_menu_notification = ( isset( $_REQUEST[ $name_prefix . 'survey_disable_survey_menu_notification'] ) && $_REQUEST[$name_prefix . 'survey_disable_survey_menu_notification'] ) == 'on' ? 'on' : 'off';
57
58 // Disable Submissions menu item notification
59 $survey_disable_submission_menu_notification = ( isset( $_REQUEST[ $name_prefix . 'survey_disable_submission_menu_notification'] ) && $_REQUEST[$name_prefix . 'survey_disable_submission_menu_notification'] ) == 'on' ? 'on' : 'off';
60
61 $survey_menu_badge_styles = array( 'classic', 'wp_default' );
62 $survey_menu_badge_style = ( isset( $_REQUEST[$name_prefix . 'survey_menu_badge_style'] ) && in_array( sanitize_key( $_REQUEST[$name_prefix . 'survey_menu_badge_style'] ), $survey_menu_badge_styles, true ) ) ? sanitize_key( $_REQUEST[$name_prefix . 'survey_menu_badge_style'] ) : 'classic';
63
64 // Default texts | Start
65 $wrong_shortcode_text = (isset($_REQUEST[$name_prefix . 'survey_wrong_shortcode_text']) && $_REQUEST[$name_prefix . 'survey_wrong_shortcode_text'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_wrong_shortcode_text'] )) : 'Wrong shortcode initialized';
66 $email_validation_error_text = (isset($_REQUEST[$name_prefix . 'survey_email_validation_error_text']) && $_REQUEST[$name_prefix . 'survey_email_validation_error_text'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_email_validation_error_text'] )) : 'Must be a valid email address';
67 $redirecting_after_text = (isset($_REQUEST[$name_prefix . 'survey_redirecting_after_text']) && $_REQUEST[$name_prefix . 'survey_redirecting_after_text'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_redirecting_after_text'] )) : 'Redirecting after';
68 // Default texts | End
69
70 $default_texts = array(
71 'wrong_shortcode_text' => $wrong_shortcode_text,
72 'email_validation_error_text' => $email_validation_error_text,
73 'redirecting_after_text' => $redirecting_after_text,
74 );
75 // Default texts | End
76
77 $next_button = (isset($_REQUEST[$name_prefix .'survey_next_button']) && $_REQUEST[$name_prefix .'survey_next_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_next_button']) ) : 'Next';
78 $prev_button = (isset($_REQUEST[$name_prefix .'survey_previous_button']) && $_REQUEST[$name_prefix .'survey_previous_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_previous_button']) ) : 'Prev';
79 $restart_button = (isset($_REQUEST[$name_prefix .'survey_restart_button']) && $_REQUEST[$name_prefix .'survey_restart_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_restart_button']) ) : 'Restart';
80 $clear_button = (isset($_REQUEST[$name_prefix .'survey_clear_button']) && $_REQUEST[$name_prefix .'survey_clear_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_clear_button']) ) : 'Clear selection';
81 $finish_button = (isset($_REQUEST[$name_prefix .'survey_finish_button']) && $_REQUEST[$name_prefix .'survey_finish_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_finish_button']) ) : 'Finish';
82 $exit_button = (isset($_REQUEST[$name_prefix .'survey_exit_button']) && $_REQUEST[$name_prefix .'survey_exit_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_exit_button']) ) : 'Exit';
83 $login_button = (isset($_REQUEST[$name_prefix .'survey_login_button']) && $_REQUEST[$name_prefix .'survey_login_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_login_button']) ) : 'Log in';
84 $start_button = (isset($_REQUEST[$name_prefix .'survey_start_button']) && $_REQUEST[$name_prefix .'survey_start_button'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix .'survey_start_button'] )) : 'Start';
85
86 $buttons_texts = array(
87 'next_button' => $next_button,
88 'prev_button' => $prev_button,
89 'restart_button' => $restart_button,
90 'clear_button' => $clear_button,
91 'finish_button' => $finish_button,
92 'exit_button' => $exit_button,
93 'login_button' => $login_button,
94 'start_button' => $start_button,
95 );
96
97 $options = array(
98 "survey_default_type" => $survey_default_type,
99 "survey_answer_default_count" => $survey_answer_default_count,
100 "survey_textarea_height" => $survey_textarea_height,
101 "survey_wp_editor_height" => $survey_wp_editor_height,
102 "survey_make_questions_required" => $survey_make_questions_required,
103 "survey_lazy_loading_for_images" => $survey_lazy_loading_for_images,
104
105 "survey_disable_user_ip" => $survey_disable_user_ip,
106 "survey_disable_user_name" => $survey_disable_user_name,
107 "survey_disable_user_email" => $survey_disable_user_email,
108
109 "survey_submissions_title_length" => $survey_submissions_title_length,
110 "survey_title_length" => $survey_title_length,
111 "survey_categories_title_length" => $survey_categories_title_length,
112 "survey_popups_title_length" => $survey_popups_title_length,
113
114 "survey_animation_top" => $survey_animation_top,
115 "survey_enable_animation_top" => $survey_enable_animation_top,
116 "survey_disable_survey_menu_notification" => $survey_disable_survey_menu_notification,
117 "survey_disable_submission_menu_notification" => $survey_disable_submission_menu_notification,
118 "survey_menu_badge_style" => $survey_menu_badge_style,
119 );
120
121 $fields['user_roles'] = $roles;
122 $fields['options'] = $options;
123 $fields['default_texts'] = $default_texts;
124 $fields['buttons_texts'] = $buttons_texts;
125
126 // $fields = apply_filters( 'ays_sm_settings_page_integrations_saves', $fields, $data );
127
128 foreach ($fields as $key => $value) {
129 $result = $this->ays_update_setting( $key, json_encode( $value ) );
130 if( $result ){
131 $success++;
132 }
133 }
134
135 $message = "saved";
136 if($success > 0){
137 $tab = "";
138 if( isset( $_REQUEST['ays_survey_tab'] ) ){
139 $tab = "&ays_survey_tab=".sanitize_text_field($_REQUEST['ays_survey_tab']);
140 }
141 $url = admin_url('admin.php') . "?page=survey-maker-settings" . $tab . '&status=' . $message;
142 wp_redirect( $url );
143 }
144 }
145
146 }
147
148 public function get_db_data(){
149 global $wpdb;
150 $settings_table = $wpdb->prefix . "ayssurvey_settings";
151 $sql = "SELECT * FROM ".$settings_table;
152 $results = $wpdb->get_results($sql, ARRAY_A);
153 if(count($results) > 0){
154 return $results;
155 }else{
156 return array();
157 }
158 }
159
160 public function check_settings_meta($metas){
161 global $wpdb;
162 $settings_table = $wpdb->prefix . "ayssurvey_settings";
163 foreach($metas as $meta_key){
164 $sql = "SELECT COUNT(*) FROM ".$settings_table." WHERE meta_key = '". esc_sql( $meta_key ) ."'";
165 $result = $wpdb->get_var($sql);
166 if(intval($result) == 0){
167 $this->ays_add_setting($meta_key, "", "", "");
168 }
169 }
170 return false;
171 }
172
173 public function check_setting_user_roles(){
174 global $wpdb;
175 $settings_table = $wpdb->prefix . "ayssurvey_settings";
176 $sql = "SELECT COUNT(*) FROM ".$settings_table." WHERE meta_key = 'user_roles'";
177 $result = $wpdb->get_var($sql);
178 if(intval($result) == 0){
179 $roles = json_encode(array('administrator'));
180 $this->ays_add_setting("user_roles", $roles, "", "");
181 }
182 return false;
183 }
184
185 public function ays_get_setting($meta_key){
186 global $wpdb;
187 $settings_table = $wpdb->prefix . "ayssurvey_settings";
188 $sql = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = '".$meta_key."'";
189 $result = $wpdb->get_var($sql);
190 if($result != ""){
191 return $result;
192 }
193 return false;
194 }
195
196 public function ays_add_setting($meta_key, $meta_value, $note = "", $options = ""){
197 global $wpdb;
198 $settings_table = $wpdb->prefix . "ayssurvey_settings";
199 $result = $wpdb->insert(
200 $settings_table,
201 array(
202 'meta_key' => $meta_key,
203 'meta_value' => $meta_value,
204 'note' => $note,
205 'options' => $options
206 ),
207 array( '%s', '%s', '%s', '%s' )
208 );
209 if($result >= 0){
210 return true;
211 }
212 return false;
213 }
214
215 public function ays_update_setting($meta_key, $meta_value, $note = null, $options = null){
216 global $wpdb;
217 $settings_table = $wpdb->prefix . "ayssurvey_settings";
218 $value = array(
219 'meta_value' => $meta_value,
220 );
221 $value_s = array( '%s' );
222 if($note != null){
223 $value['note'] = $note;
224 $value_s[] = '%s';
225 }
226 if($options != null){
227 $value['options'] = $options;
228 $value_s[] = '%s';
229 }
230 $result = $wpdb->update(
231 $settings_table,
232 $value,
233 array( 'meta_key' => $meta_key, ),
234 $value_s,
235 array( '%s' )
236 );
237 if($result >= 0){
238 return true;
239 }
240 return false;
241 }
242
243 public function ays_delete_setting($meta_key){
244 global $wpdb;
245 $settings_table = $wpdb->prefix . "ayssurvey_settings";
246 $wpdb->delete(
247 $settings_table,
248 array( 'meta_key' => $meta_key ),
249 array( '%s' )
250 );
251 }
252
253 public function survey_settings_notices($status){
254
255 if ( empty( $status ) )
256 return;
257
258 if ( 'saved' == $status )
259 $updated_message = __( 'Changes saved.', "survey-maker" );
260 elseif ( 'updated' == $status )
261 $updated_message = __( 'Quiz attribute .', "survey-maker" );
262 elseif ( 'deleted' == $status )
263 $updated_message = __( 'Quiz attribute deleted.', "survey-maker" );
264 elseif ( 'duration_updated' == $status )
265 $updated_message = __( 'Duration old data is successfully updated.', "survey-maker" );
266
267 if ( empty( $updated_message ) )
268 return;
269
270 ?>
271 <div class="ays-survey-admin-notice notice notice-success is-dismissible">
272 <p> <?php echo esc_html($updated_message); ?> </p>
273 </div>
274 <?php
275 }
276
277 public function message_variables_section($message_variables, $with_flags = true){
278 if( isset($message_variables) && !empty($message_variables) ){
279 $content = array();
280 foreach($message_variables as $message_variable_box_key => $message_variable_box_value){
281 $content[] = '<fieldset>';
282 $content[] = '<legend>
283 <h5>'.esc_html__( ucwords(str_replace('_', ' ', $message_variable_box_key)) ,"survey-maker").'</h5>
284 </legend>';
285 foreach($message_variable_box_value as $message_variable => $description){
286 $message_variable_input = $with_flags ? '%%' . $message_variable . '%%' : $message_variable;
287 $content[] = '<p class="vmessage">';
288 $content[] = '<strong>
289 <input type="text" onClick="this.setSelectionRange(0, this.value.length)" readonly value="'.esc_attr($message_variable_input).'"/>
290 </strong>';
291 $content[] = '<span> - </span>';
292 $content[] = '<span style="font-size:18px;">
293 '. $description .'
294 </span>';
295 $content[] = '</p>';
296 }
297 $content[] = '</fieldset>';
298 }
299 return implode('' , $content);
300 }
301 }
302
303 }
304