PluginProbe
Survey Maker by AYS / 5.2.2.1
Survey Maker by AYS v5.2.2.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 / includes / class-survey-maker-activator.php

class-survey-maker-activator.php in Survey Maker by AYS 5.2.2.1, at includes/class-survey-maker-activator.php

919 lines 44.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 global $ays_survey_db_version;
3 $ays_survey_db_version = '1.0.4';
4
5 /**
6 * Fired during plugin activation
7 *
8 * @link https://ays-pro.com/
9 * @since 1.0.0
10 *
11 * @package Survey_Maker
12 * @subpackage Survey_Maker/includes
13 */
14
15 /**
16 * Fired during plugin activation.
17 *
18 * This class defines all code necessary to run during the plugin's activation.
19 *
20 * @since 1.0.0
21 * @package Survey_Maker
22 * @subpackage Survey_Maker/includes
23 * @author Survey Maker team <[email protected]>
24 */
25 class Survey_Maker_Activator {
26
27 /**
28 * Short Description. (use period)
29 *
30 * Long Description.
31 *
32 * @since 1.0.0
33 */
34 private static function activate() {
35 global $wpdb;
36 global $ays_survey_db_version;
37 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
38
39 $installed_ver = get_option( "ays_survey_db_version" );
40 $surveys_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'surveys';
41 $questions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'questions';
42 $sections_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'sections';
43 $survey_categories_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'survey_categories';
44 $question_categories_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'question_categories';
45 $answers_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'answers';
46 $submissions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'submissions';
47 $submissions_questions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'submissions_questions';
48 $settings_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'settings';
49 $popup_surveys_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . 'popup_surveys';
50 $charset_collate = $wpdb->get_charset_collate();
51
52 if($installed_ver != $ays_survey_db_version) {
53
54 $sql = "CREATE TABLE `".$surveys_table."` (
55 `id` INT(16) UNSIGNED NOT NULL AUTO_INCREMENT,
56 `author_id` INT(16) UNSIGNED NOT NULL DEFAULT '0',
57 `title` TEXT NOT NULL,
58 `description` TEXT NOT NULL DEFAULT '',
59 `category_ids` TEXT NOT NULL DEFAULT '',
60 `question_ids` TEXT NOT NULL DEFAULT '',
61 `section_ids` TEXT NOT NULL DEFAULT '',
62 `sections_count` INT(11) NOT NULL DEFAULT '0',
63 `questions_count` INT(11) NOT NULL DEFAULT '0',
64 `date_created` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
65 `date_modified` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
66 `image` TEXT NOT NULL DEFAULT '',
67 `status` VARCHAR(256) NOT NULL DEFAULT 'published',
68 `trash_status` VARCHAR(256) NOT NULL DEFAULT '',
69 `ordering` INT(16) NOT NULL,
70 `post_id` INT(16) UNSIGNED DEFAULT NULL,
71 `custom_post_id` INT(16) UNSIGNED DEFAULT NULL,
72 `options` TEXT NOT NULL DEFAULT '',
73 PRIMARY KEY (`id`)
74 )$charset_collate;";
75
76 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
77 WHERE table_schema = '".DB_NAME."' AND table_name = '".$surveys_table."' ";
78 $results = $wpdb->get_results($sql_schema);
79
80 if(empty($results)){
81 $wpdb->query( $sql );
82 }else{
83 dbDelta( $sql );
84 }
85
86 $sql = "CREATE TABLE `".$questions_table."` (
87 `id` INT(16) UNSIGNED NOT NULL AUTO_INCREMENT,
88 `author_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
89 `section_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
90 `category_ids` TEXT NOT NULL DEFAULT '',
91 `question` TEXT NOT NULL DEFAULT '',
92 `type` VARCHAR(256) NOT NULL DEFAULT '',
93 `status` VARCHAR(256) NOT NULL DEFAULT 'published',
94 `trash_status` VARCHAR(256) NOT NULL DEFAULT '',
95 `date_created` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
96 `date_modified` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
97 `user_variant` TEXT NULL DEFAULT '',
98 `user_explanation` TEXT NULL DEFAULT '',
99 `image` TEXT NOT NULL DEFAULT '',
100 `ordering` INT(11) NOT NULL DEFAULT '1',
101 `options` TEXT NOT NULL DEFAULT '',
102 PRIMARY KEY (`id`)
103 )$charset_collate;";
104
105 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
106 WHERE table_schema = '".DB_NAME."' AND table_name = '".$questions_table."' ";
107 $results = $wpdb->get_results($sql_schema);
108
109 if(empty($results)){
110 $wpdb->query( $sql );
111 }else{
112 dbDelta( $sql );
113 }
114
115 $sql = "CREATE TABLE `".$survey_categories_table."` (
116 `id` INT(16) UNSIGNED NOT NULL AUTO_INCREMENT,
117 `title` VARCHAR(256) NOT NULL DEFAULT '',
118 `description` TEXT NOT NULL DEFAULT '',
119 `status` VARCHAR(256) NOT NULL DEFAULT 'published',
120 `trash_status` VARCHAR(256) NOT NULL DEFAULT '',
121 `date_created` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
122 `date_modified` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
123 `options` TEXT NOT NULL DEFAULT '',
124 PRIMARY KEY (`id`)
125 )$charset_collate;";
126
127 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
128 WHERE table_schema = '".DB_NAME."' AND table_name = '".$survey_categories_table."' ";
129 $results = $wpdb->get_results($sql_schema);
130
131 if(empty($results)){
132 $wpdb->query( $sql );
133 }else{
134 dbDelta( $sql );
135 }
136
137 $sql = "CREATE TABLE `".$sections_table."` (
138 `id` INT(16) UNSIGNED NOT NULL AUTO_INCREMENT,
139 `title` VARCHAR(256) NOT NULL DEFAULT '',
140 `description` TEXT NOT NULL DEFAULT '',
141 `ordering` INT(11) NOT NULL DEFAULT '1',
142 `options` TEXT NOT NULL DEFAULT '',
143 PRIMARY KEY (`id`)
144 )$charset_collate;";
145
146 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
147 WHERE table_schema = '".DB_NAME."' AND table_name = '".$sections_table."' ";
148 $results = $wpdb->get_results($sql_schema);
149
150 if(empty($results)){
151 $wpdb->query( $sql );
152 }else{
153 dbDelta( $sql );
154 }
155
156 $sql = "CREATE TABLE `".$question_categories_table."` (
157 `id` INT(16) UNSIGNED NOT NULL AUTO_INCREMENT,
158 `title` VARCHAR(256) NOT NULL DEFAULT '',
159 `description` TEXT NOT NULL DEFAULT '',
160 `status` VARCHAR(256) NOT NULL DEFAULT 'published',
161 `trash_status` VARCHAR(256) NOT NULL DEFAULT '',
162 `date_created` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
163 `date_modified` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
164 `options` TEXT NOT NULL DEFAULT '',
165 PRIMARY KEY (`id`)
166 )$charset_collate;";
167
168 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
169 WHERE table_schema = '".DB_NAME."' AND table_name = '".$question_categories_table."' ";
170 $results = $wpdb->get_results($sql_schema);
171
172 if(empty($results)){
173 $wpdb->query( $sql );
174 }else{
175 dbDelta( $sql );
176 }
177
178 $sql = "CREATE TABLE `".$answers_table."` (
179 `id` INT(150) UNSIGNED NOT NULL AUTO_INCREMENT,
180 `question_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
181 `answer` TEXT NOT NULL DEFAULT '',
182 `image` TEXT NOT NULL DEFAULT '',
183 `ordering` INT(11) NOT NULL DEFAULT '1',
184 `placeholder` TEXT NOT NULL DEFAULT '',
185 PRIMARY KEY (`id`)
186 )$charset_collate;";
187
188 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
189 WHERE table_schema = '".DB_NAME."' AND table_name = '".$answers_table."' ";
190 $results = $wpdb->get_results($sql_schema);
191
192 if(empty($results)){
193 $wpdb->query( $sql );
194 }else{
195 dbDelta( $sql );
196 }
197
198 $sql = "CREATE TABLE `".$submissions_table."` (
199 `id` INT(11) NOT NULL AUTO_INCREMENT,
200 `survey_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
201 `questions_ids` TEXT NOT NULL DEFAULT '',
202 `user_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
203 `user_ip` VARCHAR(256) NOT NULL DEFAULT '',
204 `user_name` TEXT NOT NULL DEFAULT '',
205 `user_email` TEXT NOT NULL DEFAULT '',
206 `start_date` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
207 `end_date` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
208 `submission_date` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
209 `duration` VARCHAR(256) NOT NULL DEFAULT '0',
210 `questions_count` VARCHAR(256) NOT NULL DEFAULT '0',
211 `unique_code` VARCHAR(256) NOT NULL DEFAULT '',
212 `read` tinyint(3) NOT NULL DEFAULT 0,
213 `status` VARCHAR(256) NOT NULL DEFAULT 'published',
214 `options` TEXT NOT NULL DEFAULT '',
215 PRIMARY KEY (`id`)
216 )$charset_collate;";
217
218 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
219 WHERE table_schema = '".DB_NAME."' AND table_name = '".$submissions_table."' ";
220 $results = $wpdb->get_results($sql_schema);
221
222 if(empty($results)){
223 $wpdb->query( $sql );
224 }else{
225 dbDelta( $sql );
226 }
227
228 $sql = "CREATE TABLE `".$submissions_questions_table."` (
229 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
230 `submission_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
231 `question_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
232 `section_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
233 `survey_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
234 `user_id` INT(11) NOT NULL DEFAULT '0',
235 `answer_id` INT(11) NOT NULL DEFAULT '0',
236 `user_answer` TEXT NOT NULL DEFAULT '',
237 `user_variant` TEXT NOT NULL DEFAULT '',
238 `user_explanation` TEXT NOT NULL DEFAULT '',
239 `type` TEXT NOT NULL DEFAULT '',
240 `options` TEXT NOT NULL DEFAULT '',
241 PRIMARY KEY (`id`)
242 )$charset_collate;";
243
244 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
245 WHERE table_schema = '".DB_NAME."' AND table_name = '".$submissions_questions_table."' ";
246 $results = $wpdb->get_results($sql_schema);
247
248 if(empty($results)){
249 $wpdb->query( $sql );
250 }else{
251 dbDelta( $sql );
252 }
253
254 $sql = "CREATE TABLE `".$settings_table."` (
255 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
256 `meta_key` TEXT NOT NULL DEFAULT '',
257 `meta_value` TEXT NOT NULL DEFAULT '',
258 `note` TEXT NOT NULL DEFAULT '',
259 `options` TEXT NOT NULL DEFAULT '',
260 PRIMARY KEY (`id`)
261 )$charset_collate;";
262
263 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
264 WHERE table_schema = '".DB_NAME."' AND table_name = '".$settings_table."' ";
265 $results = $wpdb->get_results($sql_schema);
266
267 if(empty($results)){
268 $wpdb->query( $sql );
269 }else{
270 dbDelta( $sql );
271 }
272
273 $sql = "CREATE TABLE `".$popup_surveys_table."` (
274 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
275 `survey_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
276 `title` TEXT NOT NULL,
277 `show_all` VARCHAR(20) NOT NULL,
278 `status` VARCHAR(256) NOT NULL DEFAULT 'published',
279 `trash_status` VARCHAR(256) NOT NULL DEFAULT '',
280 `author_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
281 `date_created` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
282 `date_modified` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00',
283 `options` TEXT NOT NULL DEFAULT '',
284 PRIMARY KEY (`id`)
285 )$charset_collate;";
286
287 $sql_schema = "SELECT * FROM INFORMATION_SCHEMA.TABLES
288 WHERE table_schema = '".DB_NAME."' AND table_name = '".$popup_surveys_table."' ";
289 $results = $wpdb->get_results($sql_schema);
290
291 if(empty($results)){
292 $wpdb->query( $sql );
293 }else{
294 dbDelta( $sql );
295 }
296
297 update_option( 'ays_survey_db_version', $ays_survey_db_version );
298
299 $survey_categories = $wpdb->get_var( "SELECT COUNT(*) FROM " . $survey_categories_table );
300 if( intval($survey_categories) == 0 ){
301 $wpdb->query("TRUNCATE TABLE `{$survey_categories_table}`");
302 $wpdb->insert( $survey_categories_table, array(
303 'title' => 'Uncategorized',
304 'description' => '',
305 'status' => 'published',
306 'date_created' => current_time( 'mysql' ),
307 'date_modified' => current_time( 'mysql' ),
308 ) );
309 }
310
311 $question_categories = $wpdb->get_var( "SELECT COUNT(*) FROM " . $question_categories_table );
312 if( intval($question_categories) == 0 ){
313 $wpdb->query("TRUNCATE TABLE `{$question_categories_table}`");
314 $wpdb->insert( $question_categories_table, array(
315 'title' => 'Uncategorized',
316 'description' => '',
317 'status' => 'published',
318 'date_created' => current_time( 'mysql' ),
319 'date_modified' => current_time( 'mysql' ),
320 ) );
321 }
322
323 $survey_questions = $wpdb->get_var("SELECT COUNT(*) FROM " . $questions_table);
324 $surveys_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $surveys_table);
325 $sections_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $sections_table);
326 if($survey_questions == 0 && $surveys_count == 0 && $sections_count == 0){
327 $user_id = get_current_user_id();
328 $default_options = array(
329 // Styles Tab
330 'survey_theme' => 'classic_light',
331 'survey_color' => 'rgb(255, 87, 34)', // #673ab7
332 'survey_background_color' => '#fff',
333 'survey_text_color' => '#333',
334 'survey_loader_color' => '#333',
335 'survey_buttons_text_color' => '#333',
336 'survey_title_letter_spacing_mobile' => 0,
337 'survey_width' => '700',
338 'survey_width_by_percentage_px' => 'pixels',
339 'survey_mobile_max_width' => '',
340 'survey_custom_class' => '',
341 'survey_custom_css' => '',
342 'survey_logo' => '',
343
344 'survey_question_font_size' => 16,
345 'survey_question_image_width' => '',
346 'survey_question_image_width_mobile' => '',
347 'survey_question_title_alignment' => 'left',
348 'survey_question_image_height' => '',
349 'survey_question_image_height_mobile' => '',
350 'survey_question_image_sizing' => 'cover',
351 'survey_question_image_sizing_mobile' => 'cover',
352 'survey_question_padding' => 24,
353 'survey_question_padding_mobile' => 24,
354 'survey_question_border_radius' => 8,
355 'survey_question_border_radius_mobile' => 8,
356 'survey_question_caption_text_color' => '#333',
357 'survey_question_caption_text_color_mobile' => '#333',
358 'survey_question_caption_text_alignment' => 'center',
359 'survey_question_caption_text_alignment_on_mobile' => 'center',
360 'survey_question_caption_font_size' => 16,
361 'survey_question_caption_font_size_on_mobile' => 16,
362 'survey_question_caption_text_transform' => 'none',
363 'survey_question_caption_text_transform_mobile' => 'none',
364 'survey_question_caption_letter_spacing' => 0,
365 'survey_question_caption_letter_spacing_mobile' => 0,
366 'survey_question_caption_hide_on_mobile' => 'off',
367
368 'survey_answer_font_size' => 15,
369 'survey_answer_font_size_on_mobile' => 15,
370 'survey_answer_letter_spacing' => 0,
371 'survey_answer_letter_spacing_mobile' => 0,
372 'survey_answers_view' => 'grid',
373 'survey_answers_view_alignment' => 'flex-start',
374 'survey_answers_object_fit' => 'cover',
375 'survey_answers_object_fit_mobile' => 'cover',
376 'survey_answers_padding' => 8,
377 'survey_answers_padding_mobile' => 8,
378 'survey_answers_gap' => 0,
379 'survey_answers_gap_mobile' => 0,
380
381 'survey_buttons_size' => 'medium',
382 'survey_buttons_font_size' => 14,
383 'survey_buttons_left_right_padding' => 20,
384 'survey_buttons_top_bottom_padding' => 0,
385 'survey_buttons_border_radius' => 3,
386 'survey_buttons_border_radius_mobile' => 3,
387 'survey_buttons_alignment' => 'left',
388 'survey_buttons_alignment_mobile' => 'left',
389 'survey_buttons_top_distance' => 10,
390 'survey_buttons_top_distance_mobile' => 10,
391 'survey_buttons_text_letter_spacing' => 0,
392 'survey_buttons_text_letter_spacing_mobile' => 0,
393 // Settings Tab
394 'survey_show_title' => 'off',
395 'survey_show_section_header' => 'on',
396 'survey_enable_randomize_answers' => 'off',
397 'survey_enable_randomize_questions' => 'off',
398 'survey_enable_clear_answer' => 'on',
399 'survey_enable_previous_button' => 'on',
400 'survey_disable_next_button' => 'off',
401 'survey_enable_survey_start_loader' => 'on',
402 'survey_before_start_loader' => 'default',
403 'survey_allow_html_in_answers' => 'off',
404 'survey_enable_leave_page' => 'on',
405 'survey_enable_info_autofill' => 'off',
406 'survey_enable_schedule' => 'off',
407 'survey_schedule_active' => current_time( 'mysql' ),
408 'survey_schedule_deactive' => current_time( 'mysql' ),
409 'survey_schedule_show_timer' => 'off',
410 'survey_show_timer_type' => 'countdown',
411 'survey_schedule_pre_start_message' => __("The survey will be available soon!", "survey-maker"),
412 'survey_schedule_expiration_message' => __("This survey has expired!", "survey-maker"),
413 'survey_auto_numbering' => 'none',
414 // Result Settings Tab
415 'survey_redirect_after_submit' => 'off',
416 'survey_submit_redirect_url' => '',
417 'survey_submit_redirect_delay' => '',
418 'survey_submit_redirect_new_tab' => 'off',
419 'survey_enable_exit_button' => 'off',
420 'survey_exit_redirect_url' => '',
421 'survey_enable_restart_button' => 'on',
422 'survey_final_result_text' => '',
423 'survey_show_questions_as_html' => 'on',
424 'survey_loader' => 'ripple',
425 // Limitation Tab
426 'survey_limit_users' => 'off',
427 'survey_limit_users_by' => 'ip',
428 'survey_max_pass_count' => 1,
429 'survey_limitation_message' => '',
430 'survey_redirect_url' => '',
431 'survey_redirect_delay' => 0,
432 'survey_enable_logged_users' => 'off',
433 'survey_logged_in_message' => '',
434 'survey_show_login_form' => 'off',
435 'survey_enable_takers_count' => 'off',
436 'survey_takers_count' => 1,
437 // E-Mail Tab
438 'survey_enable_mail_user' => 'off',
439 'survey_mail_message' => '',
440 'survey_enable_mail_admin' => 'off',
441 'survey_send_mail_to_site_admin' => 'on',
442 'survey_additional_emails' => '',
443 'survey_mail_message_admin' => '',
444 'survey_email_configuration_from_email' => '',
445 'survey_email_configuration_from_name' => '',
446 'survey_email_configuration_from_subject' => '',
447 'survey_email_configuration_replyto_email' => '',
448 'survey_email_configuration_replyto_name' => '',
449 );
450 // Survey
451 $survey_default = array(
452 array(
453 'author_id' => $user_id,
454 'title' => 'Customer Satisfaction Survey Template',
455 'description' => '',
456 'category_ids' => '1',
457 'question_ids' => '1,2,3,4,5,6,7',
458 'section_ids' => '1,2,3,4',
459 'sections_count' => '4',
460 'questions_count' => '7',
461 'date_created' => current_time( 'mysql' ),
462 'date_modified' => current_time( 'mysql' ),
463 'image' => '',
464 'status' => 'published',
465 'ordering' => '1',
466 'post_id' => '0',
467 'options' => json_encode($default_options),
468 )
469 );
470 // Sections
471 $sections_default = array(
472 array(
473 array(
474 'title' => "Customer Satisfaction Survey Template",
475 'description' => "Please help us improve our products/services by completing this questionnaire.",
476 'ordering' => 1,
477 'options' => json_encode( array("collapses" => "expanded") ),
478 ),
479 array(
480 'title' => "Part 2/4: Service/Product Assessment",
481 'description' => "",
482 'ordering' => 2,
483 'options' => json_encode( array("collapses" => "expanded") ),
484 ),
485 array(
486 'title' => "Part 3/4:Customer Care",
487 'description' => "",
488 'ordering' => 3,
489 'options' => json_encode( array("collapses" => "expanded") ),
490 ),
491 array(
492 'title' => "Part 4/4: Additional Feedback",
493 'description' => "",
494 'ordering' => 4,
495 'options' => json_encode( array("collapses" => "expanded") ),
496 ),
497 )
498 );
499 // Questions options
500 $question_options = array(
501 'required' => "off",
502 'collapsed' => "expanded",
503 'enable_max_selection_count' => "off",
504 'max_selection_count' => "",
505 'min_selection_count' => "",
506 'with_editor' => "off",
507 );
508
509 $question_options_req_on = array(
510 'required' => "on",
511 'collapsed' => "expanded",
512 'enable_max_selection_count' => "off",
513 'max_selection_count' => "",
514 'min_selection_count' => "",
515 'with_editor' => "off",
516 );
517
518 // Questions
519 $questions_default = array(
520 array(
521 array(
522 'author_id' => $user_id,
523 'section_id' => 1,
524 'category_ids' => "1",
525 'question' => "Would you recommend this company to a friend or colleague?",
526 'type' => "yesorno",
527 'status' => "published",
528 'trash_status' => "",
529 'date_created' => current_time( 'mysql' ),
530 'date_modified' => current_time( 'mysql' ),
531 'user_variant' => "off",
532 'user_explanation' => "",
533 'image' => "",
534 'ordering' => 1,
535 'options' => json_encode($question_options),
536 ),
537 array(
538 'author_id' => $user_id,
539 'section_id' => 1,
540 'category_ids' => "1",
541 'question' => "Overall, how satisfied or dissatisfied are you with our company?",
542 'type' => "radio",
543 'status' => "published",
544 'trash_status' => "",
545 'date_created' => current_time( 'mysql' ),
546 'date_modified' => current_time( 'mysql' ),
547 'user_variant' => "off",
548 'user_explanation' => "",
549 'image' => "",
550 'ordering' => 2,
551 'options' => json_encode($question_options),
552 ),
553 array(
554 'author_id' => $user_id,
555 'section_id' => 2,
556 'category_ids' => "1",
557 'question' => "Which of the following words would you use to describe our products/services? Select all that apply.",
558 'type' => "checkbox",
559 'status' => "published",
560 'trash_status' => "",
561 'date_created' => current_time( 'mysql' ),
562 'date_modified' => current_time( 'mysql' ),
563 'user_variant' => "on",
564 'user_explanation' => "",
565 'image' => "",
566 'ordering' => 1,
567 'options' => json_encode($question_options),
568 ),
569 array(
570 'author_id' => $user_id,
571 'section_id' => 2,
572 'category_ids' => "1",
573 'question' => "How would you rate the quality of the website? (from 1 to 10)",
574 'type' => "number",
575 'status' => "published",
576 'trash_status' => "",
577 'date_created' => current_time( 'mysql' ),
578 'date_modified' => current_time( 'mysql' ),
579 'user_variant' => "off",
580 'user_explanation' => "",
581 'image' => "",
582 'ordering' => 2,
583 'options' => json_encode($question_options_req_on),
584 ),
585 array(
586 'author_id' => $user_id,
587 'section_id' => 3,
588 'category_ids' => "1",
589 'question' => "How responsive have we been to your questions or concerns about our products/services?",
590 'type' => "select",
591 'status' => "published",
592 'trash_status' => "",
593 'date_created' => current_time( 'mysql' ),
594 'date_modified' => current_time( 'mysql' ),
595 'user_variant' => "off",
596 'user_explanation' => "",
597 'image' => "",
598 'ordering' => 1,
599 'options' => json_encode($question_options),
600 ),
601 array(
602 'author_id' => $user_id,
603 'section_id' => 3,
604 'category_ids' => "1",
605 'question' => "At what email address would you like to be contacted?",
606 'type' => "email",
607 'status' => "published",
608 'trash_status' => "",
609 'date_created' => current_time( 'mysql' ),
610 'date_modified' => current_time( 'mysql' ),
611 'user_variant' => "off",
612 'user_explanation' => "",
613 'image' => "",
614 'ordering' => 1,
615 'options' => json_encode($question_options),
616 ),
617 array(
618 'author_id' => $user_id,
619 'section_id' => 4,
620 'category_ids' => "1",
621 'question' => "Do you have any other comments, questions, or concerns?",
622 'type' => "text",
623 'status' => "published",
624 'trash_status' => "",
625 'date_created' => current_time( 'mysql' ),
626 'date_modified' => current_time( 'mysql' ),
627 'user_variant' => "off",
628 'user_explanation' => "",
629 'image' => "",
630 'ordering' => 2,
631 'options' => json_encode($question_options),
632 ),
633 )
634 );
635
636 $answers_default = array(
637 array(
638 // question 1
639 array(
640 'question_id' => 1,
641 'answer' => "Yes",
642 'image' => "",
643 'ordering' => 1,
644 'placeholder' => "",
645 ),
646 array(
647 'question_id' => 1,
648 'answer' => "No",
649 'image' => "",
650 'ordering' => 2,
651 'placeholder' => "",
652 ),
653 array(
654 'question_id' => 1,
655 'answer' => "Maybe",
656 'image' => "",
657 'ordering' => 3,
658 'placeholder' => "",
659 ),
660 // question 2
661 array(
662 'question_id' => 2,
663 'answer' => "Very satisfied",
664 'image' => "",
665 'ordering' => 1,
666 'placeholder' => "",
667 ),
668 array(
669 'question_id' => 2,
670 'answer' => "Somewhat satisfied",
671 'image' => "",
672 'ordering' => 2,
673 'placeholder' => "",
674 ),
675 array(
676 'question_id' => 2,
677 'answer' => "Somewhat dissatisfied",
678 'image' => "",
679 'ordering' => 3,
680 'placeholder' => "",
681 ),
682 array(
683 'question_id' => 2,
684 'answer' => "Very dissatisfied",
685 'image' => "",
686 'ordering' => 4,
687 'placeholder' => "",
688 ),
689 array(
690 'question_id' => 2,
691 'answer' => "Neither satisfied nor dissatisfied",
692 'image' => "",
693 'ordering' => 5,
694 'placeholder' => "",
695 ),
696 // question 3
697 array(
698 'question_id' => 3,
699 'answer' => "Reliable",
700 'image' => "",
701 'ordering' => 1,
702 'placeholder' => "",
703 ),
704 array(
705 'question_id' => 3,
706 'answer' => "High quality",
707 'image' => "",
708 'ordering' => 2,
709 'placeholder' => "",
710 ),
711 array(
712 'question_id' => 3,
713 'answer' => "Useful",
714 'image' => "",
715 'ordering' => 3,
716 'placeholder' => "",
717 ),
718 array(
719 'question_id' => 3,
720 'answer' => "Good value for money",
721 'image' => "",
722 'ordering' => 4,
723 'placeholder' => "",
724 ),
725 array(
726 'question_id' => 3,
727 'answer' => "Unique",
728 'image' => "",
729 'ordering' => 5,
730 'placeholder' => "",
731 ),
732 array(
733 'question_id' => 3,
734 'answer' => "Overpriced",
735 'image' => "",
736 'ordering' => 6,
737 'placeholder' => "",
738 ),
739 array(
740 'question_id' => 3,
741 'answer' => "Ineffective",
742 'image' => "",
743 'ordering' => 7,
744 'placeholder' => "",
745 ),
746 array(
747 'question_id' => 3,
748 'answer' => "Poor quality",
749 'image' => "",
750 'ordering' => 8,
751 'placeholder' => "",
752 ),
753 array(
754 'question_id' => 3,
755 'answer' => "Unreliable",
756 'image' => "",
757 'ordering' => 9,
758 'placeholder' => "",
759 ),
760 array(
761 'question_id' => 3,
762 'answer' => "Impractical",
763 'image' => "",
764 'ordering' => 10,
765 'placeholder' => "",
766 ),
767 // question 4 is a short type
768 // question 5
769 array(
770 'question_id' => 5,
771 'answer' => "Extremely responsive",
772 'image' => "",
773 'ordering' => 1,
774 'placeholder' => "",
775 ),
776 array(
777 'question_id' => 5,
778 'answer' => "Very responsive",
779 'image' => "",
780 'ordering' => 2,
781 'placeholder' => "",
782 ),
783 array(
784 'question_id' => 5,
785 'answer' => "Somewhat responsive",
786 'image' => "",
787 'ordering' => 3,
788 'placeholder' => "",
789 ),
790 array(
791 'question_id' => 5,
792 'answer' => "Not so responsive",
793 'image' => "",
794 'ordering' => 4,
795 'placeholder' => "",
796 ),
797 array(
798 'question_id' => 5,
799 'answer' => "Not at all responsive",
800 'image' => "",
801 'ordering' => 5,
802 'placeholder' => "",
803 ),
804 array(
805 'question_id' => 5,
806 'answer' => "Not applicable",
807 'image' => "",
808 'ordering' => 6,
809 'placeholder' => "",
810 ),
811 // question 6 is an email type
812 // question 7 is a paragraph type
813 )
814 );
815 foreach($survey_default as $key => $survey){
816 foreach($sections_default[$key] as $section_key => $section){
817 $wpdb->insert($sections_table, $section);
818 }
819 foreach($questions_default[$key] as $section_key => $section){
820 $wpdb->insert($questions_table, $section);
821 }
822 foreach($answers_default[$key] as $answer_key => $answer){
823 $wpdb->insert($answers_table, $answer);
824 }
825 $wpdb->insert($surveys_table, $survey);
826
827 $inserted_id = $wpdb->insert_id;
828 $post_type_args = array(
829 'survey_id' => $inserted_id,
830 'author_id' => $user_id,
831 'survey_title' => $survey['title'],
832 );
833 $custom_post_id = Survey_Maker_Custom_Post_Type::survey_add_custom_post($post_type_args);
834
835
836 }
837 }
838 }
839
840 $metas = array(
841 "user_roles",
842 "mailchimp",
843 "monitor",
844 "slack",
845 "active_camp",
846 "zapier",
847 "default_texts",
848 "buttons_texts",
849 "survey_default_options",
850 "options",
851 "buttons_texts"
852 );
853
854 foreach($metas as $meta_key){
855 $meta_val = "";
856 if($meta_key == "user_roles"){
857 $meta_val = json_encode(array('administrator'));
858 }
859 $sql = "SELECT COUNT(*) FROM `".$settings_table."` WHERE `meta_key` = '". esc_sql( $meta_key ) ."'";
860 $result = $wpdb->get_var($sql);
861 if(intval($result) == 0){
862 $result = $wpdb->insert(
863 $settings_table,
864 array(
865 'meta_key' => $meta_key,
866 'meta_value' => $meta_val,
867 'note' => "",
868 'options' => ""
869 ),
870 array( '%s', '%s', '%s', '%s' )
871 );
872 }
873 }
874
875 $terms_activation = get_option('survey_maker_show_agree_terms');
876 $first_activation = get_option('survey_maker_first_time_activation_page', false);
877
878 if ( !$terms_activation && $first_activation ) {
879 self::ays_survey_activator_request( 'activator' );
880 update_option('survey_maker_agree_terms', 'true');
881 update_option('survey_maker_show_agree_terms', 'hide');
882 }
883
884 }
885
886 public static function ays_survey_update_db_check() {
887 global $ays_survey_db_version;
888 $is_plugin_downloaded = get_option('ays_survey_db_version', false) === false;
889
890 if ($is_plugin_downloaded) {
891 update_option('survey_maker_first_time_activation_page', true);
892 }
893
894 if ( get_site_option( 'ays_survey_db_version' ) != $ays_survey_db_version ) {
895 self::activate();
896 }
897 }
898
899 public static function ays_survey_activator_request($cta){
900 $curl = curl_init();
901
902 $api_url = "https://poll-plugin.com/survey-maker/";
903
904 $data = array(
905 'type' => 'survey-maker',
906 'cta' => $cta,
907 );
908
909 wp_remote_post( $api_url, array(
910 'timeout' => 30,
911 'body' => wp_json_encode(array(
912 'type' => 'survey-maker',
913 'cta' => $cta,
914 )),
915 ) );
916 }
917
918 }
919