From cc1833be2e19377fdd194735eb89d4c39a064030 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Mon, 27 Nov 2023 11:32:00 +0530 Subject: [PATCH] Added Feature to duplicate quiz with active paid theme --- php/admin/settings-page.php | 2848 ++++++++++++------------ php/classes/class-qmn-quiz-creator.php | 1611 +++++++------- 2 files changed, 2254 insertions(+), 2205 deletions(-) diff --git a/php/admin/settings-page.php b/php/admin/settings-page.php index 884b32cb0..8972f4700 100644 --- a/php/admin/settings-page.php +++ b/php/admin/settings-page.php @@ -1,1414 +1,1434 @@ -add_hooks(); - global $globalQuizsetting; - } - - /** - * Add Hooks - * - * Adds functions to relavent hooks and filters - * - * @since 4.1.0 - * @return void - */ - private function add_hooks() { - add_action( 'admin_init', array( $this, 'init' ) ); - add_action( 'admin_init', array( $this, 'quiz_default_global_option_init' ) ); - add_filter( - 'pre_update_option_qmn-settings', - function( $new_value ) { - $new_value['cpt_slug'] = isset( $new_value['cpt_slug'] ) ? sanitize_title( $new_value['cpt_slug'] ) : ''; - return $new_value; - }, - 10, - 2 - ); - add_action( 'admin_enqueue_scripts', array( $this, 'qsm_admin_enqueue_scripts_settings_page' ), 20 ); - } - - /** - * Loads admin scripts and style - * - * @since 7.3.5 - */ - public function qsm_admin_enqueue_scripts_settings_page( $hook ) { - if ( 'qsm_page_qmn_global_settings' !== $hook ) { - return; - } - global $mlwQuizMasterNext; - wp_enqueue_script( 'qmn_datetime_js', QSM_PLUGIN_JS_URL . '/jquery.datetimepicker.full.min.js', array(), $mlwQuizMasterNext->version, false ); - wp_enqueue_style( 'qsm_datetime_style', QSM_PLUGIN_CSS_URL . '/jquery.datetimepicker.css', array(), $mlwQuizMasterNext->version ); - } - - /** - * Prepares Settings Fields And Sections - * - * @since 4.1.0 - * @return void - */ - public function init() { - register_setting( 'qmn-settings-group', 'qmn-settings' ); - add_settings_section( 'qmn-global-section', __( 'Main Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qmn_global_settings' ); - add_settings_field( 'usage-tracker', __( 'Allow Usage Tracking?', 'quiz-master-next' ), array( $this, 'usage_tracker_field' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'enable-qsm-log', __( 'Enable QSM log', 'quiz-master-next' ), array( $this, 'enable_qsm_log' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'ip-collection', __( 'Disable collecting and storing IP addresses?', 'quiz-master-next' ), array( $this, 'ip_collection_field' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'cpt-search', __( 'Disable Quiz Posts From Being Searched?', 'quiz-master-next' ), array( $this, 'cpt_search_field' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'cpt-archive', __( 'Quiz Archive Settings', 'quiz-master-next' ), array( $this, 'cpt_archive_field' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'detele-qsm-data', __( 'Delete all the data related to QSM on deletion?', 'quiz-master-next' ), array( $this, 'qsm_delete_data' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'background-quiz-email-process', __( 'Process emails in background?', 'quiz-master-next' ), array( $this, 'qsm_background_quiz_email_process' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'cpt-slug', __( 'Quiz Url Slug', 'quiz-master-next' ), array( $this, 'cpt_slug_field' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'plural-name', __( 'Post Type Plural Name (Shown in various places such as on archive pages)', 'quiz-master-next' ), array( $this, 'plural_name_field' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'facebook-app-id', __( 'Facebook App Id', 'quiz-master-next' ), array( $this, 'facebook_app_id' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'from-name', __( 'From Name (The name emails come from)', 'quiz-master-next' ), array( $this, 'from_name' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'from-email', __( 'From Email (The email address that emails come from)', 'quiz-master-next' ), array( $this, 'from_email' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'items-per-page-question-bank', __( 'Items per page in question bank pagination', 'quiz-master-next' ), array( $this, 'items_per_page_question_bank' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'new-template-result-detail', __( 'New Template For Admin Results Details', 'quiz-master-next' ), array( $this, 'new_template_results_details' ), 'qmn_global_settings', 'qmn-global-section' ); - add_settings_field( 'results-details', __( 'Template For Admin Results Details', 'quiz-master-next' ), array( $this, 'results_details_template' ), 'qmn_global_settings', 'qmn-global-section' ); - } - - /** - * Default settings value - * - * @since 7.3.10 - * @return array - */ - public static function default_settings() { - return array( - 'form_type' => 0, - 'system' => 3, - 'score_roundoff' => 0, - 'progress_bar' => 0, - 'require_log_in' => 0, - 'pagination' => 0, - 'timer_limit' => 0, - 'enable_result_after_timer_end' => 0, - 'skip_validation_time_expire' => 0, - 'total_user_tries' => 0, - 'limit_total_entries' => 0, - 'question_from_total' => 0, - 'question_per_category' => 0, - 'contact_info_location' => 0, - 'loggedin_user_contact' => 0, - 'comment_section' => 1, - 'question_numbering' => 0, - 'show_optin' => 0, - 'show_text_html' => 0, - 'store_responses' => 1, - 'send_email' => 1, - 'disable_answer_onselect' => 0, - 'ajax_show_correct' => 0, - 'contact_disable_autofill' => 0, - 'form_disable_autofill' => 0, - 'show_category_on_front' => 0, - 'enable_quick_result_mc' => 0, - 'end_quiz_if_wrong' => 0, - 'enable_quick_correct_answer_info' => 0, - 'show_question_featured_image_in_result' => 0, - 'enable_retake_quiz_button' => 1, - 'enable_pagination_quiz' => 0, - 'enable_deselect_option' => 0, - 'disable_description_on_result' => 0, - 'disable_scroll_next_previous_click' => 0, - 'disable_first_page' => 0, - 'disable_mathjax' => 0, - 'quiz_animation' => '', - 'result_page_fb_image' => QSM_PLUGIN_URL . 'assets/icon-200x200.png', - 'randomness_order' => 0, - 'scheduled_time_start' => '', - 'scheduled_time_end' => '', - 'not_allow_after_expired_time' => 0, - 'preferred_date_format' => 'F j, Y', - 'default_answers' => 1, - 'correct_answer_logic' => 0, - ); - } - - /** - * Prepares Settings Fields of global quiz default option - * - * @since 4.1.0 - * @return void - */ - public function quiz_default_global_option_init() { - register_setting( 'qsm-quiz-settings-group', 'qsm-quiz-settings' ); - add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_general' ); - add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_quiz_submission' ); - add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_display' ); - add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_contact' ); - add_settings_field( 'quiz-type', __( 'Quiz Type', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_type' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'grading-system', __( 'Grading System', 'quiz-master-next' ), array( $this, 'qsm_global_grading_system' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'correct_answer_logic', __( 'Correct Answer Logic', 'quiz-master-next' ), array( $this, 'correct_answer_logic' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'default_answers', __( 'Default Number of Answers', 'quiz-master-next' ), array( $this, 'default_answers' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'allow-score-round-off', __( 'Allow Score Round-off', 'quiz-master-next' ), array( $this, 'qsm_global_score_roundoff' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'show-progress-bar', __( 'Show progress bar', 'quiz-master-next' ), array( $this, 'qsm_global_show_progress_bar' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'require-user-login', __( 'Require User Login', 'quiz-master-next' ), array( $this, 'qsm_global_require_user_login' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'questions-per-page', __( 'Questions Per Page', 'quiz-master-next' ), array( $this, 'qsm_global_questions_per_page' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'time-limit-in-minutes', __( 'Time Limit (in minutes)', 'quiz-master-next' ), array( $this, 'qsm_global_time_limit_in_minutes' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'force-submit-after-timer-expiry', __( 'Force submit after timer expiry', 'quiz-master-next' ), array( $this, 'qsm_global_force_submit_after_timer_expiry' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'skip-validations-when-time-expire', __( 'Skip validations when time expire', 'quiz-master-next' ), array( $this, 'qsm_global_skip_validations_when_time_expire' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'limit-attempts', __( 'Limit Attempts', 'quiz-master-next' ), array( $this, 'qsm_global_limit_attempts' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'limit-entries', __( 'Limit Entries', 'quiz-master-next' ), array( $this, 'qsm_global_limit_entries' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'limit-number-of-questions', __( 'Limit number of Questions', 'quiz-master-next' ), array( $this, 'qsm_global_limit_number_of_questions' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'limit-number-of-questions-per-category', __( 'Limit number of Questions Per Category', 'quiz-master-next' ), array( $this, 'qsm_global_limit_number_of_questions_per_category' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'quiz-dates', __( 'Quiz Dates', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_dates' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'can-submit-after-end-date', "", array( $this, 'qsm_global_do_not_allow_quiz_submission_after_the_end_datetime' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'random-questions', __( 'Random Questions', 'quiz-master-next' ), array( $this, 'qsm_global_random_questions' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'contact-form-position', __( 'Contact form position', 'quiz-master-next' ), array( $this, 'qsm_global_contact_form_position' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); - add_settings_field( 'show-contact-form-to-logged-in-users', __( 'Show contact form to logged in users', 'quiz-master-next' ), array( $this, 'qsm_global_show_contact_form_to_logged_in_users' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); - add_settings_field( 'enable-comments', __( 'Enable comments', 'quiz-master-next' ), array( $this, 'qsm_global_enable_comments' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'show-question-numbers', __( 'Show question numbers', 'quiz-master-next' ), array( $this, 'qsm_global_show_question_numbers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'show-opt-in-answers-default', __( 'Show Opt-in type Answers to user', 'quiz-master-next' ), array( $this, 'qsm_global_show_optin_answers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'show-text-html-in-answers-default', __( 'Show Text/HTML type section in result page', 'quiz-master-next' ), array( $this, 'qsm_global_show_text_html_answers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'save-responses', __( 'Submit Actions', 'quiz-master-next' ), array( $this, 'qsm_global_save_responses' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'disable-change-of-answers', __( 'Disable change of answers', 'quiz-master-next' ), array( $this, 'qsm_global_disable_change_of_answers' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'add-class-for-correct-incorrect-answers', __( 'Add class for correct/incorrect answers', 'quiz-master-next' ), array( $this, 'qsm_global_add_class_for_correct_incorrect_answers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'disable-auto-fill-for-contact-input', __( 'Disable auto fill for contact input', 'quiz-master-next' ), array( $this, 'qsm_global_disable_auto_fill_for_contact_input' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); - add_settings_field( 'disable-auto-fill-for-quiz-input', __( 'Disable auto fill for Quiz input', 'quiz-master-next' ), array( $this, 'qsm_global_disable_auto_fill_for_quiz_input' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'display-category-name-on-front-end', __( 'Display category name on front end', 'quiz-master-next' ), array( $this, 'qsm_global_display_category_name_on_front_end' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'hide-correct-answer', __( 'Hide Correct Answer', 'quiz-master-next' ), array( $this, 'qsm_global_hide_correct_answer' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'show-results-inline', __( 'Show results inline', 'quiz-master-next' ), array( $this, 'qsm_global_show_results_inline' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'end-quiz-if-there-is-wrong-answer', __( 'End quiz', 'quiz-master-next' ), array( $this, 'qsm_global_end_quiz_if_there_is_wrong_answer' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'show-correct-answer-inline', __( 'Show correct answer inline', 'quiz-master-next' ), array( $this, 'qsm_global_show_correct_answer_inline' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'retake-quiz', __( 'Retake Quiz', 'quiz-master-next' ), array( $this, 'qsm_global_retake_quiz' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); - add_settings_field( 'show-current-page-number', __( 'Show current page number', 'quiz-master-next' ), array( $this, 'qsm_global_show_current_page_number' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'show-current-page-number', __( 'Show question featured image in results page', 'quiz-master-next' ), array( $this, 'qsm_global_show_question_featured_image_in_result' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'deselect-answer', __( 'Deselect Answer', 'quiz-master-next' ), array( $this, 'qsm_global_deselect_answer' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'disable-description-on-quiz-result-page', __( 'Disable description on quiz result page?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_description_on_quiz_result_page' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'disable_mathjax', __( 'Disable MathJax?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_mathjax' ), 'qsm_default_global_option_general', 'qmn-global-section' ); - add_settings_field( 'disable-scroll-on-next-and-previous-button-click', __( 'Disable scroll on next and previous button click?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_scroll_on_next_and_previous_button_click' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'disable-first-page', __( 'Disable first page on quiz', 'quiz-master-next' ), array( $this, 'qsm_global_disable_first_page' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); - add_settings_field( 'quiz-animation', __( 'Quiz Animation', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_animation' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'logo-url', __( 'Logo URL', 'quiz-master-next' ), array( $this, 'qsm_global_logo_url' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - add_settings_field( 'preferred_date_format', __( 'Preferred Date Format', 'quiz-master-next' ), array( $this, 'preferred_date_format' ), 'qsm_default_global_option_display', 'qmn-global-section' ); - global $globalQuizsetting; - $get_default_value = self::default_settings(); - $get_saved_value = get_option( 'qsm-quiz-settings' ); - $globalQuizsetting = wp_parse_args( $get_saved_value, $get_default_value ); - } - - public static function get_global_quiz_settings() { - $get_default_value = self::default_settings(); - $get_saved_value = get_option( 'qsm-quiz-settings' ); - return wp_parse_args( $get_saved_value, $get_default_value ); - } - - /** - * Generates Section Text - * - * Generates the section text. If page has been saved, flush rewrite rules for updated post type slug - * - * @since 4.1.0 - * @return void - */ - public function global_section() { - esc_html_e( 'These settings are applied to the entire plugin and all quizzes.', 'quiz-master-next' ); - $enabled = get_option( 'qsm_multiple_category_enabled' ); - if ( 'cancelled' === $enabled ) { - ?> -
-

- -

-

-
-
- ', '' ); - ?> -

-

- -

-
- - - - - - - '; - } - - /** - * Generates Setting Field For Post Slug - * - * @since 4.1.0 - * @return void - */ - public function cpt_slug_field() { - $settings = (array) get_option( 'qmn-settings' ); - $cpt_slug = 'quiz'; - if ( isset( $settings['cpt_slug'] ) ) { - $cpt_slug = esc_attr( $settings['cpt_slug'] ); - } - echo ''; - } - - /** - * Generates Setting Field For Plural name - * - * @since 5.3.0 - * @return void - */ - public function plural_name_field() { - $settings = (array) get_option( 'qmn-settings' ); - $plural_name = __( 'Quizzes & Surveys', 'quiz-master-next' ); - if ( isset( $settings['plural_name'] ) ) { - $plural_name = esc_attr( $settings['plural_name'] ); - } - echo ''; - } - - /** - * Generates Setting Field For Exclude Search - * - * @since 4.1.0 - * @return void - */ - public function cpt_search_field() { - $settings = (array) get_option( 'qmn-settings' ); - $cpt_search = '0'; - if ( isset( $settings['cpt_search'] ) ) { - $cpt_search = esc_attr( $settings['cpt_search'] ); - } - $checked = ''; - if ( '1' == $cpt_search ) { - $checked = " checked='checked'"; - } - - echo ''; - } - - /** - * Generates Setting Field For Post Archive - * - * @since 4.1.0 - * @return void - */ - public function cpt_archive_field() { - $settings = (array) get_option( 'qmn-settings' ); - $cpt_archive = ! empty( $settings['cpt_archive'] ) ? esc_attr( $settings['cpt_archive'] ) : 0; - $cpt_link = ! empty( $settings['disable_quiz_public_link'] ) ? esc_attr( $settings['disable_quiz_public_link'] ) : 0; - ?> -
-
- -
- '; - echo ''; - echo ''; - } - - /** - * Generates Setting Field For background email process - * - * @since 7.0.3 - * @return void - */ - public function qsm_background_quiz_email_process() { - $settings = (array) get_option( 'qmn-settings' ); - $background_quiz_email_process = '1'; - if ( isset( $settings['background_quiz_email_process'] ) ) { - $background_quiz_email_process = esc_attr( $settings['background_quiz_email_process'] ); - } - - echo ''; - echo '
'; - echo ''; - } - - /** - * Generates Setting Field For Results Details Template - * - * @since 4.1.0 - * @return void - */ - public function results_details_template() { - $settings = (array) get_option( 'qmn-settings' ); - if ( isset( $settings['results_details_template'] ) ) { - $template = htmlspecialchars_decode( $settings['results_details_template'], ENT_QUOTES ); - } else { - $template = '

Quiz Results for %QUIZ_NAME%

-

%CONTACT_ALL%

-

Name Provided: %USER_NAME%

-

Business Provided: %USER_BUSINESS%

-

Phone Provided: %USER_PHONE%

-

Email Provided: %USER_EMAIL%

-

Score Received: %AMOUNT_CORRECT%/%TOTAL_QUESTIONS% or %CORRECT_SCORE%% or %POINT_SCORE% points

-

Answers Provided:

-

The user took %TIMER% to complete quiz.

-

Comments entered were: %COMMENT_SECTION%

-

The answers were as follows:

- %QUESTIONS_ANSWERS%'; - } - wp_editor( $template, 'results_template', array( - 'textarea_name' => 'qmn-settings[results_details_template]', - 'tinymce' => array( - 'toolbar1' => 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,alignjustify,link,wp_more,fullscreen,wp_adv', - 'toolbar2' => 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help', - ), - ) - ); - } - - /** - * Generates Setting Field For Usage Tracker Authorization - * - * @since 4.1.0 - * @return void - */ - public function usage_tracker_field() { - $settings = (array) get_option( 'qmn-settings' ); - $tracking_allowed = '0'; - if ( isset( $settings['tracking_allowed'] ) ) { - $tracking_allowed = esc_attr( $settings['tracking_allowed'] ); - } - $checked = ''; - if ( '2' == $tracking_allowed ) { - $checked = " checked='checked'"; - } - - echo ''; - echo "" . esc_html__( "Allow Quiz And Survey Master to anonymously track this plugin's usage and help us make this plugin better.", 'quiz-master-next' ) . ''; - } - - /** - * Generates Setting Field For QSM logs - * - * @since 8.1.9 - * @return void - */ - public function enable_qsm_log() { - $settings = (array) get_option( 'qmn-settings' ); - $enable_qsm_log = ! empty( $settings['enable_qsm_log'] ) ? esc_attr( $settings['enable_qsm_log'] ) : 0; - ?> - - - '; - echo ''; - echo ''; - echo "" . esc_html__( 'You must not restrict number of quiz attempts when this option is enabled.', 'quiz-master-next' ) . ''; - } - - /** - * Generates Settings Page - * - * @since 4.1.0 - * @return void - */ - public static function display_page() { - global $mlwQuizMasterNext; - $active_tab = 'qmn_global_settings'; - if ( isset( $_GET['tab'] ) ) { - if ( sanitize_text_field( wp_unslash( $_GET['tab'] ) ) == 'qmn_global_settings' ) { - $active_tab = 'qmn_global_settings'; - } else { - $active_tab = 'quiz-default-options'; - } - } - $g_class = $d_class = ''; - if ( 'qmn_global_settings' === $active_tab ) { - $g_class = 'nav-tab-active'; - } - if ( 'quiz-default-options' === $active_tab ) { - $d_class = 'nav-tab-active'; - } - ?> -
-

- -
- '; - echo '' . esc_html__( ' Settings have been updated!', 'quiz-master-next' ) . ''; - echo '
'; - } - if ( 'qmn_global_settings' === $active_tab ) { - settings_fields( 'qmn-settings-group' ); - do_settings_sections( 'qmn_global_settings' ); - } - if ( 'quiz-default-options' === $active_tab ) { - settings_fields( 'qsm-quiz-settings-group' ); - ?> -
- -
- -
- -
- - - - - - - - '; - echo "'; - esc_html_e( 'New Template', 'quiz-master-next' ); - echo ''; - echo '
'; - echo ''; - } - - /** - * Generates Quiz Global Field For Quiz Type - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_quiz_type() { - global $globalQuizsetting; - $qsm_form_type = ( isset( $globalQuizsetting['form_type'] ) && '' !== $globalQuizsetting['form_type'] ? $globalQuizsetting['form_type'] : '' ); - echo '
'; - } - - /** - * Generates Quiz Global Field For grading system - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_grading_system() { - global $globalQuizsetting; - $qsm_system = ( isset( $globalQuizsetting['system'] ) && '' !== $globalQuizsetting['system'] ? $globalQuizsetting['system'] : '' ); - echo '
- -
- -
- -
-
- Select the system for grading the quiz.'; - } - - /** - * Generates Quiz Global Field For Allow Score Round-off - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_score_roundoff() { - global $globalQuizsetting; - $qsm_score_roundoff = ( isset( $globalQuizsetting['score_roundoff'] ) && '' !== $globalQuizsetting['score_roundoff'] ? $globalQuizsetting['score_roundoff'] : '' ); - echo '
- -
'; - } - - /** - * Generates Quiz Global Field For Show progress bar - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_show_progress_bar() { - global $globalQuizsetting; - $qsm_progress_bar = ( isset( $globalQuizsetting['progress_bar'] ) && '' !== $globalQuizsetting['progress_bar'] ? $globalQuizsetting['progress_bar'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Require User Login - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_require_user_login() { - global $globalQuizsetting; - - $qsm_require_log_in = ( isset( $globalQuizsetting['require_log_in'] ) && '' !== $globalQuizsetting['require_log_in'] ? $globalQuizsetting['require_log_in'] : '0' ); - echo '
- -
- -
-
- Enabling this allows only logged in users to take the quiz'; - } - - /** - * Generates Quiz Global Field For Questions Per Page - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_questions_per_page() { - global $globalQuizsetting; - $qsm_pagination = isset( $globalQuizsetting['pagination'] ) && '' !== $globalQuizsetting['pagination'] ? $globalQuizsetting['pagination'] : '0'; - echo ' - Override the default pagination created on questions tab'; - } - - /** - * Generates Quiz Global Field For Time Limit (in minutes) - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_time_limit_in_minutes() { - global $globalQuizsetting; - $qsm_timer_limit = ( isset( $globalQuizsetting['timer_limit'] ) && '' !== $globalQuizsetting['timer_limit'] ? $globalQuizsetting['timer_limit'] : '0' ); - echo ' - Leave 0 for no time limit'; - } - - /** - * Generates Quiz Global Field For Force submit after timer expiry - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_force_submit_after_timer_expiry() { - global $globalQuizsetting; - $qsm_enable_result_after_timer_end = ( isset( $globalQuizsetting['enable_result_after_timer_end'] ) && '' !== $globalQuizsetting['enable_result_after_timer_end'] ? $globalQuizsetting['enable_result_after_timer_end'] : '0' ); - echo '
- -
- -
-
'; - } - /** - * Generates Quiz Global Field For Skip validations when time expire - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_skip_validations_when_time_expire() { - global $globalQuizsetting; - $qsm_skip_validation_time_expire = ( isset( $globalQuizsetting['skip_validation_time_expire'] ) && '' !== $globalQuizsetting['skip_validation_time_expire'] ? $globalQuizsetting['skip_validation_time_expire'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Limit Attempts - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_limit_attempts() { - global $globalQuizsetting; - $qsm_total_user_tries = ( isset( $globalQuizsetting['total_user_tries'] ) && '' !== $globalQuizsetting['total_user_tries'] ? $globalQuizsetting['total_user_tries'] : '0' ); - echo ' - Leave 0 for unlimited attempts'; - } - - - /** - * Generates Quiz Global Field For Limit Entries - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_limit_entries() { - global $globalQuizsetting; - $qsm_limit_total_entries = ( isset( $globalQuizsetting['limit_total_entries'] ) && '' !== $globalQuizsetting['limit_total_entries'] ? $globalQuizsetting['limit_total_entries'] : '0' ); - echo ' - Leave 0 for unlimited entries'; - - } - - /** - * Generates Quiz Global Field For Limit number of Questions - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_limit_number_of_questions() { - global $globalQuizsetting; - $qsm_question_from_total = ( isset( $globalQuizsetting['question_from_total'] ) && '' !== $globalQuizsetting['question_from_total'] ? $globalQuizsetting['question_from_total'] : '0' ); - echo ' - Leave 0 to load all questions'; - } - - - - /** - * Generates Quiz Global Field For Limit number of Questions Per Category - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_limit_number_of_questions_per_category() { - global $globalQuizsetting; - $qsm_question_per_category = ( isset( $globalQuizsetting['question_per_category'] ) && '' !== $globalQuizsetting['question_per_category'] ? $globalQuizsetting['question_per_category'] : '0' ); - echo ' - Leave 0 to load all questions. You also need to set Limit Number of questions, as well as select Question Categories'; - } - - - /** - * Generates Quiz Global Field For Contact form position - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_contact_form_position() { - global $globalQuizsetting; - $qsm_contact_info_location = ( isset( $globalQuizsetting['contact_info_location'] ) && '' !== $globalQuizsetting['contact_info_location'] ? $globalQuizsetting['contact_info_location'] : '0' ); - echo '
- -
- -
-
- Select when to display the contact form'; - } - - /** - * Generates Quiz Global Field For Show contact form to logged in users - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_show_contact_form_to_logged_in_users() { - global $globalQuizsetting; - $qsm_loggedin_user_contact = ( isset( $globalQuizsetting['loggedin_user_contact'] ) && '' !== $globalQuizsetting['loggedin_user_contact'] ? $globalQuizsetting['loggedin_user_contact'] : '0' ); - echo '
- -
- -
-
- Logged in users can edit their contact information'; - } - - /** - * Generates Quiz Global Field For Enable comments - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_enable_comments() { - global $globalQuizsetting; - $qsm_comment_section = ( isset( $globalQuizsetting['comment_section'] ) && '' !== $globalQuizsetting['comment_section'] ? $globalQuizsetting['comment_section'] : '0' ); - echo '
- -
- -
-
- Allow users to enter their comments after the quiz'; - } - - /** - * Generates Quiz Global Field For Show question numbers - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_show_question_numbers() { - global $globalQuizsetting; - $qsm_question_numbering = ( isset( $globalQuizsetting['question_numbering'] ) && '' !== $globalQuizsetting['question_numbering'] ? $globalQuizsetting['question_numbering'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Save Responses - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_save_responses() { - global $globalQuizsetting; - $qsm_store_responses = ( isset( $globalQuizsetting['store_responses'] ) && '' !== $globalQuizsetting['store_responses'] ? $globalQuizsetting['store_responses'] : '' ); - $qsm_send_email = ( isset( $globalQuizsetting['send_email'] ) && '' !== $globalQuizsetting['send_email'] ? $globalQuizsetting['send_email'] : '' ); - echo '
- - - - - - -
'; - } - - /** - * Generates Quiz Global Field For Disable change of answers - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_disable_change_of_answers() { - global $globalQuizsetting; - $qsm_disable_answer_onselect = ( isset( $globalQuizsetting['disable_answer_onselect'] ) && '' !== $globalQuizsetting['disable_answer_onselect'] ? $globalQuizsetting['disable_answer_onselect'] : '0' ); - echo '
- -
- -
-
- Works with multiple choice questions only'; - } - - /** - * Generates Quiz Global Field For Add class for correct/incorrect answers - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_add_class_for_correct_incorrect_answers() { - global $globalQuizsetting; - $qsm_ajax_show_correct = ( isset( $globalQuizsetting['ajax_show_correct'] ) && '' !== $globalQuizsetting['ajax_show_correct'] ? $globalQuizsetting['ajax_show_correct'] : '0' ); - echo '
- -
- -
-
- Works with multiple choice questions only'; - } - - /** - * Generates Quiz Global Field For Disable auto fill for contact input - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_disable_auto_fill_for_contact_input() { - global $globalQuizsetting; - $qsm_contact_disable_autofill = ( isset( $globalQuizsetting['contact_disable_autofill'] ) && '' !== $globalQuizsetting['contact_disable_autofill'] ? $globalQuizsetting['contact_disable_autofill'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Disable auto fill for Quiz input - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_disable_auto_fill_for_quiz_input() { - global $globalQuizsetting; - $qsm_form_disable_autofill = ( isset( $globalQuizsetting['form_disable_autofill'] ) && '' !== $globalQuizsetting['form_disable_autofill'] ? $globalQuizsetting['form_disable_autofill'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Display category name on front end - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_display_category_name_on_front_end() { - global $globalQuizsetting; - $qsm_show_category_on_front = ( isset( $globalQuizsetting['show_category_on_front'] ) && '' !== $globalQuizsetting['show_category_on_front'] ? $globalQuizsetting['show_category_on_front'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Show results inline - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_show_results_inline() { - global $globalQuizsetting; - $qsm_enable_quick_result_mc = ( isset( $globalQuizsetting['enable_quick_result_mc'] ) && '' !== $globalQuizsetting['enable_quick_result_mc'] ? $globalQuizsetting['enable_quick_result_mc'] : '0' ); - echo '
- -
- -
-
- Instantly displays the result for each question'; - } - - /** - * Generates Quiz Global Field For Hide Correct Answer - * - * @since 8.1.0 - * @return void - */ - public function qsm_global_hide_correct_answer() { - global $globalQuizsetting; - $qsm_hide_correct_answer = ( isset( $globalQuizsetting['hide_correct_answer'] ) && '' !== $globalQuizsetting['hide_correct_answer'] ? $globalQuizsetting['hide_correct_answer'] : '0' ); - echo '
- -
- -
-
- Hide correct answer on result page if user selected wrong answer from quiz.'; - } - - /** - * Generates Quiz Global Field For End quiz if there is wrong answer - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_end_quiz_if_there_is_wrong_answer() { - global $globalQuizsetting; - $qsm_end_quiz_if_wrong = ( isset( $globalQuizsetting['end_quiz_if_wrong'] ) && '' !== $globalQuizsetting['end_quiz_if_wrong'] ? $globalQuizsetting['end_quiz_if_wrong'] : '0' ); - echo esc_html__('If', 'quiz-master-next').' '.esc_html__(' wrong answer(s)', 'quiz-master-next').' - '.esc_html__('If this set to \'0\' then quiz will not end any incorrect number of answer.', 'quiz-master-next').''; - } - - /** - * Generates Quiz Global Field For Show correct answer inline - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_show_correct_answer_inline() { - global $globalQuizsetting; - $qsm_enable_quick_correct_answer_info = ( isset( $globalQuizsetting['enable_quick_correct_answer_info'] ) && '' !== $globalQuizsetting['enable_quick_correct_answer_info'] ? $globalQuizsetting['enable_quick_correct_answer_info'] : '0' ); - echo '
- -
- -
- -
-
- Show correct user info when inline result is enabled.'; - } - - /** - * Generates Quiz Global Field For Retake Quiz - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_retake_quiz() { - global $globalQuizsetting; - $qsm_enable_retake_quiz_button = ( isset( $globalQuizsetting['enable_retake_quiz_button'] ) && '' !== $globalQuizsetting['enable_retake_quiz_button'] ? $globalQuizsetting['enable_retake_quiz_button'] : '0' ); - echo '
- -
- -
-
- Show a button on result page to retake the quiz'; - } - - - /** - * Generates Quiz Global Field For Show current page number - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_show_current_page_number() { - global $globalQuizsetting; - $qsm_enable_pagination_quiz = ( isset( $globalQuizsetting['enable_pagination_quiz'] ) && '' !== $globalQuizsetting['enable_pagination_quiz'] ? $globalQuizsetting['enable_pagination_quiz'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Show question feature image in result - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_show_question_featured_image_in_result() { - global $globalQuizsetting; - $qsm_show_question_featured_image_in_result = ( isset( $globalQuizsetting['show_question_featured_image_in_result'] ) && '' !== $globalQuizsetting['show_question_featured_image_in_result'] ? $globalQuizsetting['show_question_featured_image_in_result'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Deselect Answer - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_deselect_answer() { - global $globalQuizsetting; - $qsm_enable_deselect_option = ( isset( $globalQuizsetting['enable_deselect_option'] ) && '' !== $globalQuizsetting['enable_deselect_option'] ? $globalQuizsetting['enable_deselect_option'] : '0' ); - echo '
- -
- -
-
- Users are able deselect an answer and leave it blank. Works with Multiple Choice and Horizintal Multiple Choice questions only'; - } - /** - * Generates Quiz Global Field For Disable description on quiz result page? - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_disable_description_on_quiz_result_page() { - global $globalQuizsetting; - $qsm_disable_description_on_result = ( isset( $globalQuizsetting['disable_description_on_result'] ) && '' !== $globalQuizsetting['disable_description_on_result'] ? $globalQuizsetting['disable_description_on_result'] : '0' ); - echo '
- -
- -
-
'; - } - /** - * Generates Quiz Global Field For Disable MathJax? - * - * @since 8.0.3 - * @return void - */ - public function qsm_global_disable_mathjax() { - global $globalQuizsetting; - $qsm_disable_mathjax = ( isset( $globalQuizsetting['disable_mathjax'] ) && '' !== $globalQuizsetting['disable_mathjax'] ? $globalQuizsetting['disable_mathjax'] : '0' ); - echo '
- -
- -
-
'; - } - /** - * Generates Quiz Global Field For Disable scroll on next and previous button click? - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_disable_scroll_on_next_and_previous_button_click() { - global $globalQuizsetting; - $qsm_disable_scroll_next_previous_click = ( isset( $globalQuizsetting['disable_scroll_next_previous_click'] ) && '' !== $globalQuizsetting['disable_scroll_next_previous_click'] ? $globalQuizsetting['disable_scroll_next_previous_click'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates Quiz Global Field For Disable First page - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_disable_first_page() { - global $globalQuizsetting; - $qsm_disable_first_page = ( isset( $globalQuizsetting['disable_first_page'] ) && '' !== $globalQuizsetting['disable_first_page'] ? $globalQuizsetting['disable_first_page'] : '0' ); - echo '
- -
- -
-
'; - } - - - /** - * Generates Quiz Global Field For Quiz Animation - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_quiz_animation() { - global $globalQuizsetting; - global $mlwQuizMasterNext; - $qsm_quiz_animation = ( isset( $globalQuizsetting['quiz_animation'] ) && '' !== $globalQuizsetting['quiz_animation'] ? $globalQuizsetting['quiz_animation'] : '' ); - $options = $mlwQuizMasterNext->pluginHelper->quiz_animation_effect(); - - echo ''; - } - - /** - * Generates Quiz Global Field For Logo URL - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_logo_url() { - global $globalQuizsetting; - $qsm_result_page_fb_image = ( isset( $globalQuizsetting['result_page_fb_image'] ) && '' !== $globalQuizsetting['result_page_fb_image'] ? $globalQuizsetting['result_page_fb_image'] : QSM_PLUGIN_URL . 'assets/icon-200x200.png' ); - echo ' - If left blank, this will default to QSM logo'; - } - - /** - * Generates Quiz Global Field For Random Questions - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_random_questions() { - global $globalQuizsetting; - $qsm_randomness_order = ( isset( $globalQuizsetting['randomness_order'] ) && '' !== $globalQuizsetting['randomness_order'] ? $globalQuizsetting['randomness_order'] : '' ); - $options = array( - array( - 'label' => __( 'Random Questions', 'quiz-master-next' ), - 'value' => 1, - ), - array( - 'label' => __( 'Random Questions And Answers', 'quiz-master-next' ), - 'value' => 2, - ), - array( - 'label' => __( 'Random Answers', 'quiz-master-next' ), - 'value' => 3, - ), - array( - 'label' => __( 'Disabled', 'quiz-master-next' ), - 'value' => 0, - ), - ); - echo ''; - } - /** - * Generates Quiz Global Field For Quiz Dates - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_quiz_dates() { - global $globalQuizsetting; - $qsm_scheduled_time_start = ( isset( $globalQuizsetting['scheduled_time_start'] ) && '' !== $globalQuizsetting['scheduled_time_start'] ? $globalQuizsetting['scheduled_time_start'] : '' ); - $qsm_scheduled_time_end = ( isset( $globalQuizsetting['scheduled_time_end'] ) && '' !== $globalQuizsetting['scheduled_time_end'] ? $globalQuizsetting['scheduled_time_end'] : '' ); - echo '
- Start Date - - If set, Quiz will be accessible only after this date -
'; - echo '
- End Date - - If set, Quiz will not be accessible after this date -
'; - wp_add_inline_script( 'qsm_admin_js', 'jQuery(function(){jQuery("#scheduled_time_start,#scheduled_time_end").datetimepicker({format: "m/d/Y H:i",step: 1});});' ); - } - /** - * Generates Quiz Global Field For Do not allow quiz submission after the end date/time - * - * @since 4.1.0 - * @return void - */ - public function qsm_global_do_not_allow_quiz_submission_after_the_end_datetime() { - global $globalQuizsetting; - $qsm_not_allow_after_expired_time = ( isset( $globalQuizsetting['not_allow_after_expired_time'] ) && '' !== $globalQuizsetting['not_allow_after_expired_time'] ? $globalQuizsetting['not_allow_after_expired_time'] : '' ); - echo '
- - -
-
'; - } - - /** - * Generates quiz global field for preferred date format - * - * @since x.x.x - * @return void - */ - public function preferred_date_format() { - - global $globalQuizsetting; - $preferred_date_format = ( isset( $globalQuizsetting['preferred_date_format'] ) ? $globalQuizsetting['preferred_date_format'] : get_option( 'date_format' ) ); - echo ''; - echo 'Set your preferred date format.'; - } - - /** - * Generates quiz global field for default answers field - * - * @since x.x.x - * @return void - */ - public function default_answers(){ - global $globalQuizsetting; - $default_answers = ( isset( $globalQuizsetting['default_answers'] ) ? $globalQuizsetting['default_answers'] : 1 ); - echo ''; - echo 'Adds number of answer fields.'; - } - - /** - * Generates quiz global field for correct answers logic field - * - * @since 7.3.15 - * @return void - */ - public function correct_answer_logic(){ - global $globalQuizsetting; - $qsm_all_correct_selected = ( isset( $globalQuizsetting['correct_answer_logic'] ) && '' !== $globalQuizsetting['correct_answer_logic'] ? $globalQuizsetting['correct_answer_logic'] : '' ); - - echo '
- -
- -
-
'; - } - /** - * Generates quiz global field to check if want to show opt-in type answers to user - * - * @since 7.3.15 - * @return void - */ - public function qsm_global_show_optin_answers() { - global $globalQuizsetting; - $qsm_question_show_optin_default = ( isset( $globalQuizsetting['show_optin'] ) && '' !== $globalQuizsetting['show_optin'] ? $globalQuizsetting['show_optin'] : '0' ); - echo '
- -
- -
-
'; - } - - /** - * Generates quiz global field to check if want to show text html type answers to user - * - * @since 8.0.7 - * @return void - */ - public function qsm_global_show_text_html_answers() { - global $globalQuizsetting; - $qsm_question_show_text_html_default = ( isset( $globalQuizsetting['show_text_html'] ) && '' !== $globalQuizsetting['show_text_html'] ? $globalQuizsetting['show_text_html'] : '0' ); - echo '
- -
- -
-
'; - } - -} - -$qmnGlobalSettingsPage = new QMNGlobalSettingsPage(); -?> +add_hooks(); + global $globalQuizsetting; + } + + /** + * Add Hooks + * + * Adds functions to relavent hooks and filters + * + * @since 4.1.0 + * @return void + */ + private function add_hooks() { + add_action( 'admin_init', array( $this, 'init' ) ); + add_action( 'admin_init', array( $this, 'quiz_default_global_option_init' ) ); + add_filter( + 'pre_update_option_qmn-settings', + function( $new_value ) { + $new_value['cpt_slug'] = isset( $new_value['cpt_slug'] ) ? sanitize_title( $new_value['cpt_slug'] ) : ''; + return $new_value; + }, + 10, + 2 + ); + add_action( 'admin_enqueue_scripts', array( $this, 'qsm_admin_enqueue_scripts_settings_page' ), 20 ); + } + + /** + * Loads admin scripts and style + * + * @since 7.3.5 + */ + public function qsm_admin_enqueue_scripts_settings_page( $hook ) { + if ( 'qsm_page_qmn_global_settings' !== $hook ) { + return; + } + global $mlwQuizMasterNext; + wp_enqueue_script( 'qmn_datetime_js', QSM_PLUGIN_JS_URL . '/jquery.datetimepicker.full.min.js', array(), $mlwQuizMasterNext->version, false ); + wp_enqueue_style( 'qsm_datetime_style', QSM_PLUGIN_CSS_URL . '/jquery.datetimepicker.css', array(), $mlwQuizMasterNext->version ); + } + + /** + * Prepares Settings Fields And Sections + * + * @since 4.1.0 + * @return void + */ + public function init() { + register_setting( 'qmn-settings-group', 'qmn-settings' ); + add_settings_section( 'qmn-global-section', __( 'Main Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qmn_global_settings' ); + add_settings_field( 'usage-tracker', __( 'Allow Usage Tracking?', 'quiz-master-next' ), array( $this, 'usage_tracker_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'enable-qsm-log', __( 'Enable QSM log', 'quiz-master-next' ), array( $this, 'enable_qsm_log' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'ip-collection', __( 'Disable collecting and storing IP addresses?', 'quiz-master-next' ), array( $this, 'ip_collection_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'cpt-search', __( 'Disable Quiz Posts From Being Searched?', 'quiz-master-next' ), array( $this, 'cpt_search_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'cpt-archive', __( 'Quiz Archive Settings', 'quiz-master-next' ), array( $this, 'cpt_archive_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'duplicate-quiz-with-theme', __( 'Duplicate Quiz Controls', 'quiz-master-next' ), array( $this, 'qsm_duplicate_quiz_with_theme' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'detele-qsm-data', __( 'Delete all the data related to QSM on deletion?', 'quiz-master-next' ), array( $this, 'qsm_delete_data' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'background-quiz-email-process', __( 'Process emails in background?', 'quiz-master-next' ), array( $this, 'qsm_background_quiz_email_process' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'cpt-slug', __( 'Quiz Url Slug', 'quiz-master-next' ), array( $this, 'cpt_slug_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'plural-name', __( 'Post Type Plural Name (Shown in various places such as on archive pages)', 'quiz-master-next' ), array( $this, 'plural_name_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'facebook-app-id', __( 'Facebook App Id', 'quiz-master-next' ), array( $this, 'facebook_app_id' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'from-name', __( 'From Name (The name emails come from)', 'quiz-master-next' ), array( $this, 'from_name' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'from-email', __( 'From Email (The email address that emails come from)', 'quiz-master-next' ), array( $this, 'from_email' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'items-per-page-question-bank', __( 'Items per page in question bank pagination', 'quiz-master-next' ), array( $this, 'items_per_page_question_bank' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'new-template-result-detail', __( 'New Template For Admin Results Details', 'quiz-master-next' ), array( $this, 'new_template_results_details' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'results-details', __( 'Template For Admin Results Details', 'quiz-master-next' ), array( $this, 'results_details_template' ), 'qmn_global_settings', 'qmn-global-section' ); + } + + /** + * Default settings value + * + * @since 7.3.10 + * @return array + */ + public static function default_settings() { + return array( + 'form_type' => 0, + 'system' => 3, + 'score_roundoff' => 0, + 'progress_bar' => 0, + 'require_log_in' => 0, + 'pagination' => 0, + 'timer_limit' => 0, + 'enable_result_after_timer_end' => 0, + 'skip_validation_time_expire' => 0, + 'total_user_tries' => 0, + 'limit_total_entries' => 0, + 'question_from_total' => 0, + 'question_per_category' => 0, + 'contact_info_location' => 0, + 'loggedin_user_contact' => 0, + 'comment_section' => 1, + 'question_numbering' => 0, + 'show_optin' => 0, + 'show_text_html' => 0, + 'store_responses' => 1, + 'send_email' => 1, + 'disable_answer_onselect' => 0, + 'ajax_show_correct' => 0, + 'contact_disable_autofill' => 0, + 'form_disable_autofill' => 0, + 'show_category_on_front' => 0, + 'enable_quick_result_mc' => 0, + 'end_quiz_if_wrong' => 0, + 'enable_quick_correct_answer_info' => 0, + 'show_question_featured_image_in_result' => 0, + 'enable_retake_quiz_button' => 1, + 'enable_pagination_quiz' => 0, + 'enable_deselect_option' => 0, + 'disable_description_on_result' => 0, + 'disable_scroll_next_previous_click' => 0, + 'disable_first_page' => 0, + 'disable_mathjax' => 0, + 'quiz_animation' => '', + 'result_page_fb_image' => QSM_PLUGIN_URL . 'assets/icon-200x200.png', + 'randomness_order' => 0, + 'scheduled_time_start' => '', + 'scheduled_time_end' => '', + 'not_allow_after_expired_time' => 0, + 'preferred_date_format' => 'F j, Y', + 'default_answers' => 1, + 'correct_answer_logic' => 0, + ); + } + + /** + * Prepares Settings Fields of global quiz default option + * + * @since 4.1.0 + * @return void + */ + public function quiz_default_global_option_init() { + register_setting( 'qsm-quiz-settings-group', 'qsm-quiz-settings' ); + add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_general' ); + add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_quiz_submission' ); + add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_display' ); + add_settings_section( 'qmn-global-section', __( 'Quiz Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qsm_default_global_option_contact' ); + add_settings_field( 'quiz-type', __( 'Quiz Type', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_type' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'grading-system', __( 'Grading System', 'quiz-master-next' ), array( $this, 'qsm_global_grading_system' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'correct_answer_logic', __( 'Correct Answer Logic', 'quiz-master-next' ), array( $this, 'correct_answer_logic' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'default_answers', __( 'Default Number of Answers', 'quiz-master-next' ), array( $this, 'default_answers' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'allow-score-round-off', __( 'Allow Score Round-off', 'quiz-master-next' ), array( $this, 'qsm_global_score_roundoff' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'show-progress-bar', __( 'Show progress bar', 'quiz-master-next' ), array( $this, 'qsm_global_show_progress_bar' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'require-user-login', __( 'Require User Login', 'quiz-master-next' ), array( $this, 'qsm_global_require_user_login' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'questions-per-page', __( 'Questions Per Page', 'quiz-master-next' ), array( $this, 'qsm_global_questions_per_page' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'time-limit-in-minutes', __( 'Time Limit (in minutes)', 'quiz-master-next' ), array( $this, 'qsm_global_time_limit_in_minutes' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'force-submit-after-timer-expiry', __( 'Force submit after timer expiry', 'quiz-master-next' ), array( $this, 'qsm_global_force_submit_after_timer_expiry' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'skip-validations-when-time-expire', __( 'Skip validations when time expire', 'quiz-master-next' ), array( $this, 'qsm_global_skip_validations_when_time_expire' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'limit-attempts', __( 'Limit Attempts', 'quiz-master-next' ), array( $this, 'qsm_global_limit_attempts' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'limit-entries', __( 'Limit Entries', 'quiz-master-next' ), array( $this, 'qsm_global_limit_entries' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'limit-number-of-questions', __( 'Limit number of Questions', 'quiz-master-next' ), array( $this, 'qsm_global_limit_number_of_questions' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'limit-number-of-questions-per-category', __( 'Limit number of Questions Per Category', 'quiz-master-next' ), array( $this, 'qsm_global_limit_number_of_questions_per_category' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'quiz-dates', __( 'Quiz Dates', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_dates' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'can-submit-after-end-date', "", array( $this, 'qsm_global_do_not_allow_quiz_submission_after_the_end_datetime' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'random-questions', __( 'Random Questions', 'quiz-master-next' ), array( $this, 'qsm_global_random_questions' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'contact-form-position', __( 'Contact form position', 'quiz-master-next' ), array( $this, 'qsm_global_contact_form_position' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); + add_settings_field( 'show-contact-form-to-logged-in-users', __( 'Show contact form to logged in users', 'quiz-master-next' ), array( $this, 'qsm_global_show_contact_form_to_logged_in_users' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); + add_settings_field( 'enable-comments', __( 'Enable comments', 'quiz-master-next' ), array( $this, 'qsm_global_enable_comments' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'show-question-numbers', __( 'Show question numbers', 'quiz-master-next' ), array( $this, 'qsm_global_show_question_numbers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'show-opt-in-answers-default', __( 'Show Opt-in type Answers to user', 'quiz-master-next' ), array( $this, 'qsm_global_show_optin_answers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'show-text-html-in-answers-default', __( 'Show Text/HTML type section in result page', 'quiz-master-next' ), array( $this, 'qsm_global_show_text_html_answers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'save-responses', __( 'Submit Actions', 'quiz-master-next' ), array( $this, 'qsm_global_save_responses' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'disable-change-of-answers', __( 'Disable change of answers', 'quiz-master-next' ), array( $this, 'qsm_global_disable_change_of_answers' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'add-class-for-correct-incorrect-answers', __( 'Add class for correct/incorrect answers', 'quiz-master-next' ), array( $this, 'qsm_global_add_class_for_correct_incorrect_answers' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'disable-auto-fill-for-contact-input', __( 'Disable auto fill for contact input', 'quiz-master-next' ), array( $this, 'qsm_global_disable_auto_fill_for_contact_input' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); + add_settings_field( 'disable-auto-fill-for-quiz-input', __( 'Disable auto fill for Quiz input', 'quiz-master-next' ), array( $this, 'qsm_global_disable_auto_fill_for_quiz_input' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'display-category-name-on-front-end', __( 'Display category name on front end', 'quiz-master-next' ), array( $this, 'qsm_global_display_category_name_on_front_end' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'hide-correct-answer', __( 'Hide Correct Answer', 'quiz-master-next' ), array( $this, 'qsm_global_hide_correct_answer' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'show-results-inline', __( 'Show results inline', 'quiz-master-next' ), array( $this, 'qsm_global_show_results_inline' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'end-quiz-if-there-is-wrong-answer', __( 'End quiz', 'quiz-master-next' ), array( $this, 'qsm_global_end_quiz_if_there_is_wrong_answer' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'show-correct-answer-inline', __( 'Show correct answer inline', 'quiz-master-next' ), array( $this, 'qsm_global_show_correct_answer_inline' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'retake-quiz', __( 'Retake Quiz', 'quiz-master-next' ), array( $this, 'qsm_global_retake_quiz' ), 'qsm_default_global_option_quiz_submission', 'qmn-global-section' ); + add_settings_field( 'show-current-page-number', __( 'Show current page number', 'quiz-master-next' ), array( $this, 'qsm_global_show_current_page_number' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'show-current-page-number', __( 'Show question featured image in results page', 'quiz-master-next' ), array( $this, 'qsm_global_show_question_featured_image_in_result' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'deselect-answer', __( 'Deselect Answer', 'quiz-master-next' ), array( $this, 'qsm_global_deselect_answer' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'disable-description-on-quiz-result-page', __( 'Disable description on quiz result page?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_description_on_quiz_result_page' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'disable_mathjax', __( 'Disable MathJax?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_mathjax' ), 'qsm_default_global_option_general', 'qmn-global-section' ); + add_settings_field( 'disable-scroll-on-next-and-previous-button-click', __( 'Disable scroll on next and previous button click?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_scroll_on_next_and_previous_button_click' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'disable-first-page', __( 'Disable first page on quiz', 'quiz-master-next' ), array( $this, 'qsm_global_disable_first_page' ), 'qsm_default_global_option_contact', 'qmn-global-section' ); + add_settings_field( 'quiz-animation', __( 'Quiz Animation', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_animation' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'logo-url', __( 'Logo URL', 'quiz-master-next' ), array( $this, 'qsm_global_logo_url' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + add_settings_field( 'preferred_date_format', __( 'Preferred Date Format', 'quiz-master-next' ), array( $this, 'preferred_date_format' ), 'qsm_default_global_option_display', 'qmn-global-section' ); + global $globalQuizsetting; + $get_default_value = self::default_settings(); + $get_saved_value = get_option( 'qsm-quiz-settings' ); + $globalQuizsetting = wp_parse_args( $get_saved_value, $get_default_value ); + } + + public static function get_global_quiz_settings() { + $get_default_value = self::default_settings(); + $get_saved_value = get_option( 'qsm-quiz-settings' ); + return wp_parse_args( $get_saved_value, $get_default_value ); + } + + /** + * Generates Section Text + * + * Generates the section text. If page has been saved, flush rewrite rules for updated post type slug + * + * @since 4.1.0 + * @return void + */ + public function global_section() { + esc_html_e( 'These settings are applied to the entire plugin and all quizzes.', 'quiz-master-next' ); + $enabled = get_option( 'qsm_multiple_category_enabled' ); + if ( 'cancelled' === $enabled ) { + ?> +
+

+ +

+

+
+
+ ', '' ); + ?> +

+

+ +

+
+ + + + + + + '; + } + + /** + * Generates Setting Field For Post Slug + * + * @since 4.1.0 + * @return void + */ + public function cpt_slug_field() { + $settings = (array) get_option( 'qmn-settings' ); + $cpt_slug = 'quiz'; + if ( isset( $settings['cpt_slug'] ) ) { + $cpt_slug = esc_attr( $settings['cpt_slug'] ); + } + echo ''; + } + + /** + * Generates Setting Field For Plural name + * + * @since 5.3.0 + * @return void + */ + public function plural_name_field() { + $settings = (array) get_option( 'qmn-settings' ); + $plural_name = __( 'Quizzes & Surveys', 'quiz-master-next' ); + if ( isset( $settings['plural_name'] ) ) { + $plural_name = esc_attr( $settings['plural_name'] ); + } + echo ''; + } + + /** + * Generates Setting Field For Exclude Search + * + * @since 4.1.0 + * @return void + */ + public function cpt_search_field() { + $settings = (array) get_option( 'qmn-settings' ); + $cpt_search = '0'; + if ( isset( $settings['cpt_search'] ) ) { + $cpt_search = esc_attr( $settings['cpt_search'] ); + } + $checked = ''; + if ( '1' == $cpt_search ) { + $checked = " checked='checked'"; + } + + echo ''; + } + + /** + * Generates Setting Field For Post Archive + * + * @since 4.1.0 + * @return void + */ + public function cpt_archive_field() { + $settings = (array) get_option( 'qmn-settings' ); + $cpt_archive = ! empty( $settings['cpt_archive'] ) ? esc_attr( $settings['cpt_archive'] ) : 0; + $cpt_link = ! empty( $settings['disable_quiz_public_link'] ) ? esc_attr( $settings['disable_quiz_public_link'] ) : 0; + ?> +
+
+ +
+ +
+ +
+ '; + echo ''; + echo ''; + } + + /** + * Generates Setting Field For background email process + * + * @since 7.0.3 + * @return void + */ + public function qsm_background_quiz_email_process() { + $settings = (array) get_option( 'qmn-settings' ); + $background_quiz_email_process = '1'; + if ( isset( $settings['background_quiz_email_process'] ) ) { + $background_quiz_email_process = esc_attr( $settings['background_quiz_email_process'] ); + } + + echo ''; + echo '
'; + echo ''; + } + + /** + * Generates Setting Field For Results Details Template + * + * @since 4.1.0 + * @return void + */ + public function results_details_template() { + $settings = (array) get_option( 'qmn-settings' ); + if ( isset( $settings['results_details_template'] ) ) { + $template = htmlspecialchars_decode( $settings['results_details_template'], ENT_QUOTES ); + } else { + $template = '

Quiz Results for %QUIZ_NAME%

+

%CONTACT_ALL%

+

Name Provided: %USER_NAME%

+

Business Provided: %USER_BUSINESS%

+

Phone Provided: %USER_PHONE%

+

Email Provided: %USER_EMAIL%

+

Score Received: %AMOUNT_CORRECT%/%TOTAL_QUESTIONS% or %CORRECT_SCORE%% or %POINT_SCORE% points

+

Answers Provided:

+

The user took %TIMER% to complete quiz.

+

Comments entered were: %COMMENT_SECTION%

+

The answers were as follows:

+ %QUESTIONS_ANSWERS%'; + } + wp_editor( $template, 'results_template', array( + 'textarea_name' => 'qmn-settings[results_details_template]', + 'tinymce' => array( + 'toolbar1' => 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,alignjustify,link,wp_more,fullscreen,wp_adv', + 'toolbar2' => 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help', + ), + ) + ); + } + + /** + * Generates Setting Field For Usage Tracker Authorization + * + * @since 4.1.0 + * @return void + */ + public function usage_tracker_field() { + $settings = (array) get_option( 'qmn-settings' ); + $tracking_allowed = '0'; + if ( isset( $settings['tracking_allowed'] ) ) { + $tracking_allowed = esc_attr( $settings['tracking_allowed'] ); + } + $checked = ''; + if ( '2' == $tracking_allowed ) { + $checked = " checked='checked'"; + } + + echo ''; + echo "" . esc_html__( "Allow Quiz And Survey Master to anonymously track this plugin's usage and help us make this plugin better.", 'quiz-master-next' ) . ''; + } + + /** + * Generates Setting Field For QSM logs + * + * @since 8.1.9 + * @return void + */ + public function enable_qsm_log() { + $settings = (array) get_option( 'qmn-settings' ); + $enable_qsm_log = ! empty( $settings['enable_qsm_log'] ) ? esc_attr( $settings['enable_qsm_log'] ) : 0; + ?> + + + '; + echo ''; + echo ''; + echo "" . esc_html__( 'You must not restrict number of quiz attempts when this option is enabled.', 'quiz-master-next' ) . ''; + } + + /** + * Generates Settings Page + * + * @since 4.1.0 + * @return void + */ + public static function display_page() { + global $mlwQuizMasterNext; + $active_tab = 'qmn_global_settings'; + if ( isset( $_GET['tab'] ) ) { + if ( sanitize_text_field( wp_unslash( $_GET['tab'] ) ) == 'qmn_global_settings' ) { + $active_tab = 'qmn_global_settings'; + } else { + $active_tab = 'quiz-default-options'; + } + } + $g_class = $d_class = ''; + if ( 'qmn_global_settings' === $active_tab ) { + $g_class = 'nav-tab-active'; + } + if ( 'quiz-default-options' === $active_tab ) { + $d_class = 'nav-tab-active'; + } + ?> +
+

+ +
+ '; + echo '' . esc_html__( ' Settings have been updated!', 'quiz-master-next' ) . ''; + echo '
'; + } + if ( 'qmn_global_settings' === $active_tab ) { + settings_fields( 'qmn-settings-group' ); + do_settings_sections( 'qmn_global_settings' ); + } + if ( 'quiz-default-options' === $active_tab ) { + settings_fields( 'qsm-quiz-settings-group' ); + ?> +
+ +
+ +
+ +
+ + + + + + + + '; + echo "'; + esc_html_e( 'New Template', 'quiz-master-next' ); + echo ''; + echo '
'; + echo ''; + } + + /** + * Generates Quiz Global Field For Quiz Type + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_quiz_type() { + global $globalQuizsetting; + $qsm_form_type = ( isset( $globalQuizsetting['form_type'] ) && '' !== $globalQuizsetting['form_type'] ? $globalQuizsetting['form_type'] : '' ); + echo '
'; + } + + /** + * Generates Quiz Global Field For grading system + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_grading_system() { + global $globalQuizsetting; + $qsm_system = ( isset( $globalQuizsetting['system'] ) && '' !== $globalQuizsetting['system'] ? $globalQuizsetting['system'] : '' ); + echo '
+ +
+ +
+ +
+
+ Select the system for grading the quiz.'; + } + + /** + * Generates Quiz Global Field For Allow Score Round-off + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_score_roundoff() { + global $globalQuizsetting; + $qsm_score_roundoff = ( isset( $globalQuizsetting['score_roundoff'] ) && '' !== $globalQuizsetting['score_roundoff'] ? $globalQuizsetting['score_roundoff'] : '' ); + echo '
+ +
'; + } + + /** + * Generates Quiz Global Field For Show progress bar + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_show_progress_bar() { + global $globalQuizsetting; + $qsm_progress_bar = ( isset( $globalQuizsetting['progress_bar'] ) && '' !== $globalQuizsetting['progress_bar'] ? $globalQuizsetting['progress_bar'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Require User Login + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_require_user_login() { + global $globalQuizsetting; + + $qsm_require_log_in = ( isset( $globalQuizsetting['require_log_in'] ) && '' !== $globalQuizsetting['require_log_in'] ? $globalQuizsetting['require_log_in'] : '0' ); + echo '
+ +
+ +
+
+ Enabling this allows only logged in users to take the quiz'; + } + + /** + * Generates Quiz Global Field For Questions Per Page + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_questions_per_page() { + global $globalQuizsetting; + $qsm_pagination = isset( $globalQuizsetting['pagination'] ) && '' !== $globalQuizsetting['pagination'] ? $globalQuizsetting['pagination'] : '0'; + echo ' + Override the default pagination created on questions tab'; + } + + /** + * Generates Quiz Global Field For Time Limit (in minutes) + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_time_limit_in_minutes() { + global $globalQuizsetting; + $qsm_timer_limit = ( isset( $globalQuizsetting['timer_limit'] ) && '' !== $globalQuizsetting['timer_limit'] ? $globalQuizsetting['timer_limit'] : '0' ); + echo ' + Leave 0 for no time limit'; + } + + /** + * Generates Quiz Global Field For Force submit after timer expiry + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_force_submit_after_timer_expiry() { + global $globalQuizsetting; + $qsm_enable_result_after_timer_end = ( isset( $globalQuizsetting['enable_result_after_timer_end'] ) && '' !== $globalQuizsetting['enable_result_after_timer_end'] ? $globalQuizsetting['enable_result_after_timer_end'] : '0' ); + echo '
+ +
+ +
+
'; + } + /** + * Generates Quiz Global Field For Skip validations when time expire + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_skip_validations_when_time_expire() { + global $globalQuizsetting; + $qsm_skip_validation_time_expire = ( isset( $globalQuizsetting['skip_validation_time_expire'] ) && '' !== $globalQuizsetting['skip_validation_time_expire'] ? $globalQuizsetting['skip_validation_time_expire'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Limit Attempts + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_limit_attempts() { + global $globalQuizsetting; + $qsm_total_user_tries = ( isset( $globalQuizsetting['total_user_tries'] ) && '' !== $globalQuizsetting['total_user_tries'] ? $globalQuizsetting['total_user_tries'] : '0' ); + echo ' + Leave 0 for unlimited attempts'; + } + + + /** + * Generates Quiz Global Field For Limit Entries + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_limit_entries() { + global $globalQuizsetting; + $qsm_limit_total_entries = ( isset( $globalQuizsetting['limit_total_entries'] ) && '' !== $globalQuizsetting['limit_total_entries'] ? $globalQuizsetting['limit_total_entries'] : '0' ); + echo ' + Leave 0 for unlimited entries'; + + } + + /** + * Generates Quiz Global Field For Limit number of Questions + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_limit_number_of_questions() { + global $globalQuizsetting; + $qsm_question_from_total = ( isset( $globalQuizsetting['question_from_total'] ) && '' !== $globalQuizsetting['question_from_total'] ? $globalQuizsetting['question_from_total'] : '0' ); + echo ' + Leave 0 to load all questions'; + } + + + + /** + * Generates Quiz Global Field For Limit number of Questions Per Category + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_limit_number_of_questions_per_category() { + global $globalQuizsetting; + $qsm_question_per_category = ( isset( $globalQuizsetting['question_per_category'] ) && '' !== $globalQuizsetting['question_per_category'] ? $globalQuizsetting['question_per_category'] : '0' ); + echo ' + Leave 0 to load all questions. You also need to set Limit Number of questions, as well as select Question Categories'; + } + + + /** + * Generates Quiz Global Field For Contact form position + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_contact_form_position() { + global $globalQuizsetting; + $qsm_contact_info_location = ( isset( $globalQuizsetting['contact_info_location'] ) && '' !== $globalQuizsetting['contact_info_location'] ? $globalQuizsetting['contact_info_location'] : '0' ); + echo '
+ +
+ +
+
+ Select when to display the contact form'; + } + + /** + * Generates Quiz Global Field For Show contact form to logged in users + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_show_contact_form_to_logged_in_users() { + global $globalQuizsetting; + $qsm_loggedin_user_contact = ( isset( $globalQuizsetting['loggedin_user_contact'] ) && '' !== $globalQuizsetting['loggedin_user_contact'] ? $globalQuizsetting['loggedin_user_contact'] : '0' ); + echo '
+ +
+ +
+
+ Logged in users can edit their contact information'; + } + + /** + * Generates Quiz Global Field For Enable comments + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_enable_comments() { + global $globalQuizsetting; + $qsm_comment_section = ( isset( $globalQuizsetting['comment_section'] ) && '' !== $globalQuizsetting['comment_section'] ? $globalQuizsetting['comment_section'] : '0' ); + echo '
+ +
+ +
+
+ Allow users to enter their comments after the quiz'; + } + + /** + * Generates Quiz Global Field For Show question numbers + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_show_question_numbers() { + global $globalQuizsetting; + $qsm_question_numbering = ( isset( $globalQuizsetting['question_numbering'] ) && '' !== $globalQuizsetting['question_numbering'] ? $globalQuizsetting['question_numbering'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Save Responses + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_save_responses() { + global $globalQuizsetting; + $qsm_store_responses = ( isset( $globalQuizsetting['store_responses'] ) && '' !== $globalQuizsetting['store_responses'] ? $globalQuizsetting['store_responses'] : '' ); + $qsm_send_email = ( isset( $globalQuizsetting['send_email'] ) && '' !== $globalQuizsetting['send_email'] ? $globalQuizsetting['send_email'] : '' ); + echo '
+ + + + + + +
'; + } + + /** + * Generates Quiz Global Field For Disable change of answers + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_disable_change_of_answers() { + global $globalQuizsetting; + $qsm_disable_answer_onselect = ( isset( $globalQuizsetting['disable_answer_onselect'] ) && '' !== $globalQuizsetting['disable_answer_onselect'] ? $globalQuizsetting['disable_answer_onselect'] : '0' ); + echo '
+ +
+ +
+
+ Works with multiple choice questions only'; + } + + /** + * Generates Quiz Global Field For Add class for correct/incorrect answers + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_add_class_for_correct_incorrect_answers() { + global $globalQuizsetting; + $qsm_ajax_show_correct = ( isset( $globalQuizsetting['ajax_show_correct'] ) && '' !== $globalQuizsetting['ajax_show_correct'] ? $globalQuizsetting['ajax_show_correct'] : '0' ); + echo '
+ +
+ +
+
+ Works with multiple choice questions only'; + } + + /** + * Generates Quiz Global Field For Disable auto fill for contact input + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_disable_auto_fill_for_contact_input() { + global $globalQuizsetting; + $qsm_contact_disable_autofill = ( isset( $globalQuizsetting['contact_disable_autofill'] ) && '' !== $globalQuizsetting['contact_disable_autofill'] ? $globalQuizsetting['contact_disable_autofill'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Disable auto fill for Quiz input + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_disable_auto_fill_for_quiz_input() { + global $globalQuizsetting; + $qsm_form_disable_autofill = ( isset( $globalQuizsetting['form_disable_autofill'] ) && '' !== $globalQuizsetting['form_disable_autofill'] ? $globalQuizsetting['form_disable_autofill'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Display category name on front end + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_display_category_name_on_front_end() { + global $globalQuizsetting; + $qsm_show_category_on_front = ( isset( $globalQuizsetting['show_category_on_front'] ) && '' !== $globalQuizsetting['show_category_on_front'] ? $globalQuizsetting['show_category_on_front'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Show results inline + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_show_results_inline() { + global $globalQuizsetting; + $qsm_enable_quick_result_mc = ( isset( $globalQuizsetting['enable_quick_result_mc'] ) && '' !== $globalQuizsetting['enable_quick_result_mc'] ? $globalQuizsetting['enable_quick_result_mc'] : '0' ); + echo '
+ +
+ +
+
+ Instantly displays the result for each question'; + } + + /** + * Generates Quiz Global Field For Hide Correct Answer + * + * @since 8.1.0 + * @return void + */ + public function qsm_global_hide_correct_answer() { + global $globalQuizsetting; + $qsm_hide_correct_answer = ( isset( $globalQuizsetting['hide_correct_answer'] ) && '' !== $globalQuizsetting['hide_correct_answer'] ? $globalQuizsetting['hide_correct_answer'] : '0' ); + echo '
+ +
+ +
+
+ Hide correct answer on result page if user selected wrong answer from quiz.'; + } + + /** + * Generates Quiz Global Field For End quiz if there is wrong answer + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_end_quiz_if_there_is_wrong_answer() { + global $globalQuizsetting; + $qsm_end_quiz_if_wrong = ( isset( $globalQuizsetting['end_quiz_if_wrong'] ) && '' !== $globalQuizsetting['end_quiz_if_wrong'] ? $globalQuizsetting['end_quiz_if_wrong'] : '0' ); + echo esc_html__('If', 'quiz-master-next').' '.esc_html__(' wrong answer(s)', 'quiz-master-next').' + '.esc_html__('If this set to \'0\' then quiz will not end any incorrect number of answer.', 'quiz-master-next').''; + } + + /** + * Generates Quiz Global Field For Show correct answer inline + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_show_correct_answer_inline() { + global $globalQuizsetting; + $qsm_enable_quick_correct_answer_info = ( isset( $globalQuizsetting['enable_quick_correct_answer_info'] ) && '' !== $globalQuizsetting['enable_quick_correct_answer_info'] ? $globalQuizsetting['enable_quick_correct_answer_info'] : '0' ); + echo '
+ +
+ +
+ +
+
+ Show correct user info when inline result is enabled.'; + } + + /** + * Generates Quiz Global Field For Retake Quiz + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_retake_quiz() { + global $globalQuizsetting; + $qsm_enable_retake_quiz_button = ( isset( $globalQuizsetting['enable_retake_quiz_button'] ) && '' !== $globalQuizsetting['enable_retake_quiz_button'] ? $globalQuizsetting['enable_retake_quiz_button'] : '0' ); + echo '
+ +
+ +
+
+ Show a button on result page to retake the quiz'; + } + + + /** + * Generates Quiz Global Field For Show current page number + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_show_current_page_number() { + global $globalQuizsetting; + $qsm_enable_pagination_quiz = ( isset( $globalQuizsetting['enable_pagination_quiz'] ) && '' !== $globalQuizsetting['enable_pagination_quiz'] ? $globalQuizsetting['enable_pagination_quiz'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Show question feature image in result + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_show_question_featured_image_in_result() { + global $globalQuizsetting; + $qsm_show_question_featured_image_in_result = ( isset( $globalQuizsetting['show_question_featured_image_in_result'] ) && '' !== $globalQuizsetting['show_question_featured_image_in_result'] ? $globalQuizsetting['show_question_featured_image_in_result'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Deselect Answer + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_deselect_answer() { + global $globalQuizsetting; + $qsm_enable_deselect_option = ( isset( $globalQuizsetting['enable_deselect_option'] ) && '' !== $globalQuizsetting['enable_deselect_option'] ? $globalQuizsetting['enable_deselect_option'] : '0' ); + echo '
+ +
+ +
+
+ Users are able deselect an answer and leave it blank. Works with Multiple Choice and Horizintal Multiple Choice questions only'; + } + /** + * Generates Quiz Global Field For Disable description on quiz result page? + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_disable_description_on_quiz_result_page() { + global $globalQuizsetting; + $qsm_disable_description_on_result = ( isset( $globalQuizsetting['disable_description_on_result'] ) && '' !== $globalQuizsetting['disable_description_on_result'] ? $globalQuizsetting['disable_description_on_result'] : '0' ); + echo '
+ +
+ +
+
'; + } + /** + * Generates Quiz Global Field For Disable MathJax? + * + * @since 8.0.3 + * @return void + */ + public function qsm_global_disable_mathjax() { + global $globalQuizsetting; + $qsm_disable_mathjax = ( isset( $globalQuizsetting['disable_mathjax'] ) && '' !== $globalQuizsetting['disable_mathjax'] ? $globalQuizsetting['disable_mathjax'] : '0' ); + echo '
+ +
+ +
+
'; + } + /** + * Generates Quiz Global Field For Disable scroll on next and previous button click? + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_disable_scroll_on_next_and_previous_button_click() { + global $globalQuizsetting; + $qsm_disable_scroll_next_previous_click = ( isset( $globalQuizsetting['disable_scroll_next_previous_click'] ) && '' !== $globalQuizsetting['disable_scroll_next_previous_click'] ? $globalQuizsetting['disable_scroll_next_previous_click'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates Quiz Global Field For Disable First page + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_disable_first_page() { + global $globalQuizsetting; + $qsm_disable_first_page = ( isset( $globalQuizsetting['disable_first_page'] ) && '' !== $globalQuizsetting['disable_first_page'] ? $globalQuizsetting['disable_first_page'] : '0' ); + echo '
+ +
+ +
+
'; + } + + + /** + * Generates Quiz Global Field For Quiz Animation + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_quiz_animation() { + global $globalQuizsetting; + global $mlwQuizMasterNext; + $qsm_quiz_animation = ( isset( $globalQuizsetting['quiz_animation'] ) && '' !== $globalQuizsetting['quiz_animation'] ? $globalQuizsetting['quiz_animation'] : '' ); + $options = $mlwQuizMasterNext->pluginHelper->quiz_animation_effect(); + + echo ''; + } + + /** + * Generates Quiz Global Field For Logo URL + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_logo_url() { + global $globalQuizsetting; + $qsm_result_page_fb_image = ( isset( $globalQuizsetting['result_page_fb_image'] ) && '' !== $globalQuizsetting['result_page_fb_image'] ? $globalQuizsetting['result_page_fb_image'] : QSM_PLUGIN_URL . 'assets/icon-200x200.png' ); + echo ' + If left blank, this will default to QSM logo'; + } + + /** + * Generates Quiz Global Field For Random Questions + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_random_questions() { + global $globalQuizsetting; + $qsm_randomness_order = ( isset( $globalQuizsetting['randomness_order'] ) && '' !== $globalQuizsetting['randomness_order'] ? $globalQuizsetting['randomness_order'] : '' ); + $options = array( + array( + 'label' => __( 'Random Questions', 'quiz-master-next' ), + 'value' => 1, + ), + array( + 'label' => __( 'Random Questions And Answers', 'quiz-master-next' ), + 'value' => 2, + ), + array( + 'label' => __( 'Random Answers', 'quiz-master-next' ), + 'value' => 3, + ), + array( + 'label' => __( 'Disabled', 'quiz-master-next' ), + 'value' => 0, + ), + ); + echo ''; + } + /** + * Generates Quiz Global Field For Quiz Dates + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_quiz_dates() { + global $globalQuizsetting; + $qsm_scheduled_time_start = ( isset( $globalQuizsetting['scheduled_time_start'] ) && '' !== $globalQuizsetting['scheduled_time_start'] ? $globalQuizsetting['scheduled_time_start'] : '' ); + $qsm_scheduled_time_end = ( isset( $globalQuizsetting['scheduled_time_end'] ) && '' !== $globalQuizsetting['scheduled_time_end'] ? $globalQuizsetting['scheduled_time_end'] : '' ); + echo '
+ Start Date + + If set, Quiz will be accessible only after this date +
'; + echo '
+ End Date + + If set, Quiz will not be accessible after this date +
'; + wp_add_inline_script( 'qsm_admin_js', 'jQuery(function(){jQuery("#scheduled_time_start,#scheduled_time_end").datetimepicker({format: "m/d/Y H:i",step: 1});});' ); + } + /** + * Generates Quiz Global Field For Do not allow quiz submission after the end date/time + * + * @since 4.1.0 + * @return void + */ + public function qsm_global_do_not_allow_quiz_submission_after_the_end_datetime() { + global $globalQuizsetting; + $qsm_not_allow_after_expired_time = ( isset( $globalQuizsetting['not_allow_after_expired_time'] ) && '' !== $globalQuizsetting['not_allow_after_expired_time'] ? $globalQuizsetting['not_allow_after_expired_time'] : '' ); + echo '
+ + +
+
'; + } + + /** + * Generates quiz global field for preferred date format + * + * @since x.x.x + * @return void + */ + public function preferred_date_format() { + + global $globalQuizsetting; + $preferred_date_format = ( isset( $globalQuizsetting['preferred_date_format'] ) ? $globalQuizsetting['preferred_date_format'] : get_option( 'date_format' ) ); + echo ''; + echo 'Set your preferred date format.'; + } + + /** + * Generates quiz global field for default answers field + * + * @since x.x.x + * @return void + */ + public function default_answers(){ + global $globalQuizsetting; + $default_answers = ( isset( $globalQuizsetting['default_answers'] ) ? $globalQuizsetting['default_answers'] : 1 ); + echo ''; + echo 'Adds number of answer fields.'; + } + + /** + * Generates quiz global field for correct answers logic field + * + * @since 7.3.15 + * @return void + */ + public function correct_answer_logic(){ + global $globalQuizsetting; + $qsm_all_correct_selected = ( isset( $globalQuizsetting['correct_answer_logic'] ) && '' !== $globalQuizsetting['correct_answer_logic'] ? $globalQuizsetting['correct_answer_logic'] : '' ); + + echo '
+ +
+ +
+
'; + } + /** + * Generates quiz global field to check if want to show opt-in type answers to user + * + * @since 7.3.15 + * @return void + */ + public function qsm_global_show_optin_answers() { + global $globalQuizsetting; + $qsm_question_show_optin_default = ( isset( $globalQuizsetting['show_optin'] ) && '' !== $globalQuizsetting['show_optin'] ? $globalQuizsetting['show_optin'] : '0' ); + echo '
+ +
+ +
+
'; + } + + /** + * Generates quiz global field to check if want to show text html type answers to user + * + * @since 8.0.7 + * @return void + */ + public function qsm_global_show_text_html_answers() { + global $globalQuizsetting; + $qsm_question_show_text_html_default = ( isset( $globalQuizsetting['show_text_html'] ) && '' !== $globalQuizsetting['show_text_html'] ? $globalQuizsetting['show_text_html'] : '0' ); + echo '
+ +
+ +
+
'; + } + +} + +$qmnGlobalSettingsPage = new QMNGlobalSettingsPage(); +?> diff --git a/php/classes/class-qmn-quiz-creator.php b/php/classes/class-qmn-quiz-creator.php index 324c0bc9c..3985fc7eb 100644 --- a/php/classes/class-qmn-quiz-creator.php +++ b/php/classes/class-qmn-quiz-creator.php @@ -1,791 +1,820 @@ -quiz_id = intval( $_REQUEST['quiz_id'] ); - } - } - - /** - * Sets quiz ID - * - * @since 3.8.1 - * @param int $quiz_id The ID of the quiz. - * @access public - * @return void - */ - public function set_id( $quiz_id ) { - $this->quiz_id = intval( $quiz_id ); - } - - /** - * Gets the quiz ID stored (for backwards compatibility) - * - * @since 5.0.0 - * @return int|false The ID of the quiz stored or false - */ - public function get_id() { - if ( $this->quiz_id ) { - return intval( $this->quiz_id ); - } else { - return false; - } - } - - /** - * Creates a new quiz with the default settings - * - * @access public - * @since 3.7.1 - * @param string $quiz_name The name of the new quiz. - * @return void - */ - public function create_quiz( $quiz_name, $theme_id, $quiz_settings = array() ) { - global $wpdb, $mlwQuizMasterNext; - $current_user = wp_get_current_user(); - $default_texts = QMNPluginHelper::get_default_texts(); - $results = $wpdb->insert( - $wpdb->prefix . 'mlw_quizzes', - array( - 'quiz_name' => $quiz_name, - 'message_before' => isset( $default_texts['message_before'] ) ? $default_texts['message_before'] : __( 'Welcome to your %QUIZ_NAME%', 'quiz-master-next' ), - 'message_after' => __( 'Thanks for submitting your response! You can edit this message on the "Results Pages" tab.
%CONTACT_ALL%
%QUESTIONS_ANSWERS%', 'quiz-master-next' ), - 'message_comment' => isset( $default_texts['message_comment'] ) ? $default_texts['message_comment'] : __( 'Please fill in the comment box below.', 'quiz-master-next' ), - 'message_end_template' => '', - 'user_email_template' => '%QUESTIONS_ANSWERS_EMAIL%', - 'admin_email_template' => '%QUESTIONS_ANSWERS_EMAIL%', - 'submit_button_text' => isset( $default_texts['submit_button_text'] ) ? $default_texts['submit_button_text'] : __( 'Submit', 'quiz-master-next' ), - 'name_field_text' => isset( $default_texts['name_field_text'] ) ? $default_texts['name_field_text'] : __( 'Name', 'quiz-master-next' ), - 'business_field_text' => isset( $default_texts['business_field_text'] ) ? $default_texts['business_field_text'] : __( 'Business', 'quiz-master-next' ), - 'email_field_text' => isset( $default_texts['email_field_text'] ) ? $default_texts['email_field_text'] : __( 'Email', 'quiz-master-next' ), - 'phone_field_text' => isset( $default_texts['phone_field_text'] ) ? $default_texts['phone_field_text'] : __( 'Phone Number', 'quiz-master-next' ), - 'comment_field_text' => isset( $default_texts['comment_field_text'] ) ? $default_texts['comment_field_text'] : __( 'Comments', 'quiz-master-next' ), - 'email_from_text' => 'Wordpress', - 'question_answer_template' => isset( $default_texts['question_answer_template'] ) ? $default_texts['question_answer_template'] : '%QUESTION%
%USER_ANSWERS_DEFAULT%', - 'leaderboard_template' => '', - 'quiz_system' => 0, - 'randomness_order' => 0, - 'loggedin_user_contact' => 0, - 'show_score' => 0, - 'send_user_email' => 0, - 'send_admin_email' => 0, - 'contact_info_location' => 0, - 'user_name' => 2, - 'user_comp' => 2, - 'user_email' => 2, - 'user_phone' => 2, - 'admin_email' => get_option( 'admin_email', 'Enter email' ), - 'comment_section' => isset( $_POST['comment_section'] ) ? sanitize_text_field( wp_unslash( $_POST['comment_section'] ) ) : 1, - 'question_from_total' => 0, - 'total_user_tries' => 0, - 'total_user_tries_text' => isset( $default_texts['total_user_tries_text'] ) ? $default_texts['total_user_tries_text'] : __( 'You have utilized all of your attempts to pass this quiz.', 'quiz-master-next' ), - 'certificate_template' => '', - 'social_media' => 0, - 'social_media_text' => __( 'I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next' ), - 'pagination' => 0, - 'pagination_text' => isset( $default_texts['next_button_text'] ) ? $default_texts['next_button_text'] : __( 'Next', 'quiz-master-next' ), - 'timer_limit' => 0, - 'quiz_stye' => '', - 'question_numbering' => 0, - 'quiz_settings' => maybe_serialize( $quiz_settings ), - 'theme_selected' => 'primary', - 'last_activity' => current_time( 'mysql' ), - 'require_log_in' => 0, - 'require_log_in_text' => isset( $default_texts['require_log_in_text'] ) ? $default_texts['require_log_in_text'] : __( 'This quiz is for logged in users only.', 'quiz-master-next' ), - 'limit_total_entries' => 0, - 'limit_total_entries_text' => isset( $default_texts['limit_total_entries_text'] ) ? $default_texts['limit_total_entries_text'] : __( 'Unfortunately, this quiz has a limited amount of entries it can recieve and has already reached that limit.', 'quiz-master-next' ), - 'scheduled_timeframe' => '', - 'scheduled_timeframe_text' => '', - 'quiz_views' => 0, - 'quiz_taken' => 0, - 'deleted' => 0, - 'quiz_author_id' => $current_user->ID, - ), - array( - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%s', - '%d', - '%d', - '%d', - '%s', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%s', - '%s', - '%d', - '%s', - '%d', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - ) - ); - if ( false !== $results ) { - $new_quiz = $wpdb->insert_id; - $quiz_post = array( - 'post_title' => $quiz_name, - 'post_content' => "[mlw_quizmaster quiz=$new_quiz]", - 'post_status' => 'draft', - 'post_author' => $current_user->ID, - 'post_type' => 'qsm_quiz', - ); - $quiz_post_id = wp_insert_post( $quiz_post ); - add_post_meta( $quiz_post_id, 'quiz_id', $new_quiz ); - - // activating selected theme - $mlwQuizMasterNext->theme_settings->activate_selected_theme( $new_quiz, $theme_id ); - - $mlwQuizMasterNext->alertManager->newAlert( __( 'Your new quiz or survey has been created successfully. To begin editing, click the Edit link.', 'quiz-master-next' ), 'success' ); - $mlwQuizMasterNext->audit_manager->new_audit( 'New Quiz/Survey Has Been Created', $new_quiz, '' ); - - /** - * Prepare quiz result & email templates. - */ - self::add_quiz_templates($new_quiz); - - // Hook called after new quiz or survey has been created. Passes quiz_id to hook - do_action( 'qmn_quiz_created', $new_quiz ); - } else { - $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0001', 'quiz-master-next' ), 'error' ); - $mlwQuizMasterNext->log_manager->add( 'Error 0001', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); - } - } - - /** - * Deletes a quiz with the given quiz_id - * - * @access public - * @since 3.7.1 - * @return void - */ - public function delete_quiz( $quiz_id, $quiz_name ) { - global $mlwQuizMasterNext; - global $wpdb; - - $qsm_delete_from_db = isset( $_POST['qsm_delete_from_db'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['qsm_delete_from_db'] ) ); - $qsm_delete_questions_from_qb = isset( $_POST['qsm_delete_question_from_qb'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['qsm_delete_question_from_qb'] ) ); - $quizzes_table = $wpdb->prefix . 'mlw_quizzes'; - - $quiz_post_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = '$quiz_id'" ); - if ( empty( $quiz_post_id ) || ! current_user_can( 'delete_post', $quiz_post_id ) ) { - $mlwQuizMasterNext->alertManager->newAlert( __( 'Sorry, you are not allowed to delete this quiz.', 'quiz-master-next' ), 'error' ); - return; - } - - $is_row_exists = $wpdb->get_var( $wpdb->prepare( "SELECT * FROM $quizzes_table WHERE quiz_id=%d", $quiz_id ) ); - - if ( $qsm_delete_from_db ) { - $qsm_delete = $wpdb->delete( - $wpdb->prefix . 'mlw_quizzes', - array( 'quiz_id' => $quiz_id ) - ); - } else { - $qsm_delete = $wpdb->update( - $wpdb->prefix . 'mlw_quizzes', - array( - 'deleted' => 1, - ), - array( 'quiz_id' => $quiz_id ), - array( - '%d', - ), - array( '%d' ) - ); - $deleted = 0; - if ( $qsm_delete_questions_from_qb ) { - $deleted = 1; - $wpdb->update( - $wpdb->prefix . 'mlw_questions', - array( - 'deleted' => $deleted, - ), - array( 'quiz_id' => $quiz_id ), - array( - '%d', - ), - array( '%d' ) - ); - } - } - - if ( empty( $is_row_exists ) ) { - $qsm_delete = 1; - } - - if ( $qsm_delete ) { - if ( ! empty( $quiz_post_id ) ) { - if ( $qsm_delete_from_db ) { - wp_delete_post( $quiz_post_id, true ); - } else { - wp_trash_post( $quiz_post_id ); - } - } - $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been deleted successfully.', 'quiz-master-next' ), 'success' ); - $mlwQuizMasterNext->audit_manager->new_audit( "Quiz/Survey Has Been Deleted: $quiz_name", $quiz_id, '' ); - } else { - $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0002', 'quiz-master-next' ), 'error' ); - $mlwQuizMasterNext->log_manager->add( 'Error 0002', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); - } - // Hook called after quiz or survey is deleted. Hook passes quiz_id to function - do_action( 'qmn_quiz_deleted', $quiz_id ); - } - - /** - * Edits the name of the quiz with the given ID - * - * @access public - * @since 3.7.1 - * @param int $quiz_id The ID of the quiz. - * @param string $quiz_name The new name of the quiz. - * @return void - */ - public function edit_quiz_name( $quiz_id, $quiz_name, $post_id ) { - global $mlwQuizMasterNext; - global $wpdb; - $results = $wpdb->update( - $wpdb->prefix . 'mlw_quizzes', - array( - 'quiz_name' => $quiz_name, - ), - array( 'quiz_id' => $quiz_id ), - array( - '%s', - ), - array( '%d' ) - ); - if ( false !== $results ) { - $quiz_data = array( - 'ID' => $post_id, - 'post_title' => $quiz_name, - ); - wp_update_post($quiz_data); - - $mlwQuizMasterNext->alertManager->newAlert( __( 'The name of your quiz or survey has been updated successfully.', 'quiz-master-next' ), 'success' ); - $mlwQuizMasterNext->audit_manager->new_audit( 'Quiz/Survey Name Has Been Edited', $quiz_id, '' ); - } else { - $error = $wpdb->last_error; - if ( empty( $error ) ) { - $error = __( 'Unknown error', 'quiz-master-next' ); - } - $mlwQuizMasterNext->alertManager->newAlert( __( 'An error occurred while trying to update the name of your quiz or survey. Please try again.', 'quiz-master-next' ), 'error' ); - $mlwQuizMasterNext->log_manager->add( 'Error when updating quiz name', "Tried {$wpdb->last_query} but got $error", 0, 'error' ); - } - - // Fires when the name of a quiz/survey is edited. - do_action( 'qsm_quiz_name_edited', $quiz_id, $quiz_name ); - - // Legacy code. - do_action( 'qmn_quiz_name_edited', $quiz_id ); - } - - /** - * Duplicates the quiz with the given ID and gives new quiz the given quiz name - * - * @access public - * @since 3.7.1 - * @return void - */ - public function duplicate_quiz( $quiz_id, $quiz_name, $is_duplicating_questions ) { - global $mlwQuizMasterNext; - global $wpdb; - - $quiz_post_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = '$quiz_id'" ); - if ( empty( $quiz_post_id ) || ! current_user_can( 'edit_post', $quiz_post_id ) ) { - $mlwQuizMasterNext->alertManager->newAlert( __( 'Sorry, you are not allowed to duplicate this quiz.', 'quiz-master-next' ), 'error' ); - return; - } - - $current_user = wp_get_current_user(); - $table_name = $wpdb->prefix . 'mlw_quizzes'; - $logic_table = $wpdb->prefix . 'mlw_logic'; - $question_term = $wpdb->prefix . 'mlw_question_terms'; - $logic_table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $logic_table ) ); - $question_term_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $question_term ) ); - $mlw_qmn_duplicate_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE quiz_id=%d", $quiz_id ) ); - $quiz_settings = maybe_unserialize( $mlw_qmn_duplicate_data->quiz_settings ); - if ( 0 == $is_duplicating_questions && isset($quiz_settings['pages']) ) { - $quiz_settings['pages'] = array(); - } - $qsm_create_quiz_system = 0; - if ( isset( $mlw_qmn_duplicate_data->system ) ) { - $qsm_create_quiz_system = $mlw_qmn_duplicate_data->system; - } elseif ( isset( $mlw_qmn_duplicate_data->quiz_system ) ) { - $qsm_create_quiz_system = $mlw_qmn_duplicate_data->quiz_system; - } - $results = $wpdb->insert( - $table_name, - array( - 'quiz_name' => $quiz_name, - 'message_before' => $mlw_qmn_duplicate_data->message_before, - 'message_after' => $mlw_qmn_duplicate_data->message_after, - 'message_comment' => $mlw_qmn_duplicate_data->message_comment, - 'message_end_template' => $mlw_qmn_duplicate_data->message_end_template, - 'user_email_template' => $mlw_qmn_duplicate_data->user_email_template, - 'admin_email_template' => $mlw_qmn_duplicate_data->admin_email_template, - 'submit_button_text' => $mlw_qmn_duplicate_data->submit_button_text, - 'name_field_text' => $mlw_qmn_duplicate_data->name_field_text, - 'business_field_text' => $mlw_qmn_duplicate_data->business_field_text, - 'email_field_text' => $mlw_qmn_duplicate_data->email_field_text, - 'phone_field_text' => $mlw_qmn_duplicate_data->phone_field_text, - 'comment_field_text' => $mlw_qmn_duplicate_data->comment_field_text, - 'email_from_text' => $mlw_qmn_duplicate_data->email_from_text, - 'question_answer_template' => $mlw_qmn_duplicate_data->question_answer_template, - 'leaderboard_template' => $mlw_qmn_duplicate_data->leaderboard_template, - 'quiz_system' => $qsm_create_quiz_system, - 'randomness_order' => $mlw_qmn_duplicate_data->randomness_order, - 'loggedin_user_contact' => $mlw_qmn_duplicate_data->loggedin_user_contact, - 'show_score' => $mlw_qmn_duplicate_data->show_score, - 'send_user_email' => $mlw_qmn_duplicate_data->send_user_email, - 'send_admin_email' => $mlw_qmn_duplicate_data->send_admin_email, - 'contact_info_location' => $mlw_qmn_duplicate_data->contact_info_location, - 'user_name' => $mlw_qmn_duplicate_data->user_name, - 'user_comp' => $mlw_qmn_duplicate_data->user_comp, - 'user_email' => $mlw_qmn_duplicate_data->user_email, - 'user_phone' => $mlw_qmn_duplicate_data->user_phone, - 'admin_email' => get_option( 'admin_email', 'Enter email' ), - 'comment_section' => $mlw_qmn_duplicate_data->comment_section, - 'question_from_total' => $mlw_qmn_duplicate_data->question_from_total, - 'total_user_tries' => $mlw_qmn_duplicate_data->total_user_tries, - 'total_user_tries_text' => $mlw_qmn_duplicate_data->total_user_tries_text, - 'certificate_template' => $mlw_qmn_duplicate_data->certificate_template, - 'social_media' => $mlw_qmn_duplicate_data->social_media, - 'social_media_text' => $mlw_qmn_duplicate_data->social_media_text, - 'pagination' => $mlw_qmn_duplicate_data->pagination, - 'pagination_text' => $mlw_qmn_duplicate_data->pagination_text, - 'timer_limit' => $mlw_qmn_duplicate_data->timer_limit, - 'quiz_stye' => $mlw_qmn_duplicate_data->quiz_stye, - 'question_numbering' => $mlw_qmn_duplicate_data->question_numbering, - 'quiz_settings' => maybe_serialize( $quiz_settings ), - 'theme_selected' => $mlw_qmn_duplicate_data->theme_selected, - 'last_activity' => gmdate( 'Y-m-d H:i:s' ), - 'require_log_in' => $mlw_qmn_duplicate_data->require_log_in, - 'require_log_in_text' => $mlw_qmn_duplicate_data->require_log_in_text, - 'limit_total_entries' => $mlw_qmn_duplicate_data->limit_total_entries, - 'limit_total_entries_text' => $mlw_qmn_duplicate_data->limit_total_entries_text, - 'scheduled_timeframe' => $mlw_qmn_duplicate_data->scheduled_timeframe, - 'scheduled_timeframe_text' => $mlw_qmn_duplicate_data->scheduled_timeframe_text, - 'quiz_views' => 0, - 'quiz_taken' => 0, - 'deleted' => 0, - 'quiz_author_id' => $current_user->ID, - ), - array( - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%s', - '%d', - '%d', - '%d', - '%s', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%s', - '%s', - '%d', - '%s', - '%d', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - ) - ); - $mlw_new_id = $wpdb->insert_id; - - // Update quiz settings - $update_quiz_settings = maybe_unserialize( $mlw_qmn_duplicate_data->quiz_settings ); - $update_pages = maybe_unserialize( $update_quiz_settings['pages'] ); - // get logic data from logic table first or else from quiz_settings - if ( ! is_null( $logic_table_exists ) ) { - $query = $wpdb->prepare( "SELECT * FROM $logic_table WHERE quiz_id = %d", $quiz_id ); - $logic_data = $wpdb->get_results( $query ); - $logic_rules = array(); - if ( ! empty( $logic_data ) ) { - foreach ( $logic_data as $data ) { - $logic_rules[] = maybe_unserialize( $data->logic ); - } - } - } else { - $logic_rules = isset( $update_quiz_settings['logic_rules'] ) ? maybe_unserialize( $update_quiz_settings['logic_rules'] ) : array(); - } - - if ( false !== $results ) { - $current_user = wp_get_current_user(); - $quiz_post = array( - 'post_title' => $quiz_name, - 'post_content' => "[mlw_quizmaster quiz=$mlw_new_id]", - 'post_status' => 'publish', - 'post_author' => $current_user->ID, - 'post_type' => 'qsm_quiz', - ); - $quiz_post_id = wp_insert_post( $quiz_post ); - add_post_meta( $quiz_post_id, 'quiz_id', $mlw_new_id ); - $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been duplicated successfully.', 'quiz-master-next' ), 'success' ); - $mlwQuizMasterNext->audit_manager->new_audit( 'New Quiz/Survey Has Been Created', $mlw_new_id, '' ); - /** - * Prepare quiz result & email templates. - */ - self::add_quiz_templates($mlw_new_id); - - do_action( 'qmn_quiz_duplicated', $quiz_id, $mlw_new_id ); - } else { - $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0011', 'quiz-master-next' ), 'error' ); - $mlwQuizMasterNext->log_manager->add( 'Error 0011', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); - } - if ( $is_duplicating_questions ) { - $table_name = $wpdb->prefix . 'mlw_questions'; - $questions = array(); - if ( is_array( $update_pages ) ) { - foreach ( $update_pages as $ids ) { - foreach ( $ids as $id ) { - $questions[] = $id; - } - } - } - $question_ids = implode( ',', $questions ); - $mlw_current_questions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $table_name WHERE question_id IN (%1s)", $question_ids ) ); - foreach ( $mlw_current_questions as $mlw_question ) { - $question_results = $wpdb->insert( - $table_name, - array( - 'quiz_id' => $mlw_new_id, - 'question_name' => $mlw_question->question_name, - 'answer_array' => $mlw_question->answer_array, - 'answer_one' => $mlw_question->answer_one, - 'answer_one_points' => $mlw_question->answer_one_points, - 'answer_two' => $mlw_question->answer_two, - 'answer_two_points' => $mlw_question->answer_two_points, - 'answer_three' => $mlw_question->answer_three, - 'answer_three_points' => $mlw_question->answer_three_points, - 'answer_four' => $mlw_question->answer_four, - 'answer_four_points' => $mlw_question->answer_four_points, - 'answer_five' => $mlw_question->answer_five, - 'answer_five_points' => $mlw_question->answer_five_points, - 'answer_six' => $mlw_question->answer_six, - 'answer_six_points' => $mlw_question->answer_six_points, - 'correct_answer' => $mlw_question->correct_answer, - 'question_answer_info' => $mlw_question->question_answer_info, - 'comments' => $mlw_question->comments, - 'hints' => $mlw_question->hints, - 'question_order' => $mlw_question->question_order, - 'question_type_new' => $mlw_question->question_type_new, - 'question_settings' => $mlw_question->question_settings, - 'category' => $mlw_question->category, - 'deleted' => 0, - ), - array( - '%d', - '%s', - '%s', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%d', - '%d', - '%s', - '%d', - '%s', - '%d', - '%s', - '%s', - '%s', - '%d', - ) - ); - foreach ( $update_pages as $pages_key => $pages_value ) { - foreach ( $pages_value as $pages_k_q => $page_q_id ) { - if ( intval($page_q_id) === intval($mlw_question->question_id) ) { - $update_pages[ $pages_key ][ $pages_k_q ] = $wpdb->insert_id; - } - } - } - // Fixed Rules Questions with new question ids - if ( is_array( $logic_rules ) ) { - foreach ( $logic_rules as $logic_key => $logic_value ) { - foreach ( $logic_value as $logic_cond_k => $logic_cond ) { - foreach ( $logic_cond as $l_cond_k => $logic_val ) { - if ( $logic_val['question'] === $mlw_question->question_id ) { - $logic_rules[ $logic_key ][ $logic_cond_k ][ $l_cond_k ]['question'] = $wpdb->insert_id; - } - } - } - } - } - // Copying categories for multiple categories table - $new_question_id = $wpdb->insert_id; - if ( ! is_null( $question_term_exists ) ) { - $query = $wpdb->prepare( "SELECT DISTINCT term_id FROM $question_term WHERE question_id = %d AND quiz_id = %d", $mlw_question->question_id, $quiz_id ); - $term_ids = $wpdb->get_results( $query, ARRAY_N ); - - if ( ! is_null( $term_ids ) ) { - foreach ( $term_ids as $term_id ) { - $wpdb->insert( - $question_term, - array( - 'question_id' => $new_question_id, - 'quiz_id' => $mlw_new_id, - 'term_id' => $term_id[0], - 'taxonomy' => 'qsm_category', - ), - array( - '%d', - '%d', - '%d', - '%s', - ) - ); - } - } - } - - if ( false === $question_results ) { - $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0020', 'quiz-master-next' ), 'error' ); - $mlwQuizMasterNext->log_manager->add( 'Error 0020', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); - } - } - $update_quiz_settings['pages'] = maybe_serialize( $update_pages ); - // saves data in logic table first or else in quiz_settings. - $value_array = array(); - if ( is_array( $logic_rules ) && ! empty( $logic_rules ) ) { - if ( is_null( $logic_table_exists ) ) { - $update_quiz_settings['logic_rules'] = maybe_serialize( $logic_rules ); - } else { - foreach ( $logic_rules as $logic_data ) { - $value_array[] = stripslashes( $wpdb->prepare( '(%d, %s)', $mlw_new_id, maybe_serialize( $logic_data ) ) ); - } - $values = implode( ',', $value_array ); - $query = "INSERT INTO `{$logic_table}` (quiz_id, logic) VALUES {$values}"; - $saved = $wpdb->query( $query ); - if ( false !== $saved ) { - update_option( "logic_rules_quiz_$mlw_new_id", gmdate( time() ) ); - $update_quiz_settings['logic_rules'] = ''; - } else { - $update_quiz_settings['logic_rules'] = maybe_serialize( $logic_rules ); - } - } - } - - $wpdb->update( - $wpdb->prefix . 'mlw_quizzes', - array( - 'quiz_settings' => maybe_serialize( $update_quiz_settings ), - ), - array( - 'quiz_id' => $mlw_new_id, - ) - ); - } - } - - public static function add_quiz_templates( $quiz_id ) { - global $mlwQuizMasterNext; - $pages = QSM_Results_Pages::load_pages( $quiz_id ); - for ( $i = 0; $i < count( $pages ); $i++ ) { - if ( ! empty($pages[ $i ]['page']) ) { - $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $pages[ $i ]['page'], "quiz-result-page-{$i}-{$quiz_id}" ); - } - } - $emails = QSM_Emails::load_emails( $quiz_id ); - for ( $i = 0; $i < count( $emails ); $i++ ) { - if ( ! empty($emails[ $i ]['content']) ) { - $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $emails[ $i ]['subject'], "quiz-email-subject-{$i}-{$quiz_id}" ); - $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $emails[ $i ]['content'], "quiz-email-content-{$i}-{$quiz_id}" ); - } - } - } - - /** - * Retrieves setting store in quiz_settings - * - * @deprecated 6.0.3 Use the get_quiz_setting function in the pluginHelper object. - * @since 3.8.1 - * @access public - * @param string $setting_name The slug of the setting. - * @return string The value of the setting - */ - public function get_setting( $setting_name ) { - global $wpdb; - $qmn_settings_array = ''; - $qmn_quiz_settings = $wpdb->get_var( $wpdb->prepare( 'SELECT quiz_settings FROM ' . $wpdb->prefix . 'mlw_quizzes' . ' WHERE quiz_id=%d', $this->quiz_id ) ); - $qmn_settings_array = maybe_unserialize( $qmn_quiz_settings ); - if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting_name ] ) ) { - return $qmn_settings_array[ $setting_name ]; - } else { - return ''; - } - - } - - /** - * Updates setting stored in quiz_settings - * - * @deprecated 6.0.3 Use the update_quiz_setting function in the pluginHelper object. - * @since 3.8.1 - * @access public - * @param string $setting_name The slug of the setting. - * @param mixed $setting_value The value for the setting. - * @return bool True if update was successful - */ - public function update_setting( $setting_name, $setting_value ) { - global $wpdb; - $qmn_quiz_settings = $wpdb->get_var( $wpdb->prepare( 'SELECT quiz_settings FROM ' . $wpdb->prefix . 'mlw_quizzes' . ' WHERE quiz_id=%d', $this->quiz_id ) ); - $qmn_settings_array = maybe_unserialize( $qmn_quiz_settings ); - if ( ! is_array( $qmn_settings_array ) ) { - $qmn_settings_array = array(); - } - $qmn_settings_array[ $setting_name ] = $setting_value; - $results = $wpdb->update( - $wpdb->prefix . 'mlw_quizzes', - array( - 'quiz_settings' => maybe_serialize( $qmn_settings_array ), - ), - array( 'quiz_id' => $this->quiz_id ), - array( - '%s', - ), - array( '%d' ) - ); - if ( false !== $results ) { - return true; - } else { - return false; - } - } - - /** - * Deletes setting stored in quiz_settings - * - * @deprecated 6.0.3 - * @since 3.8.1 - * @access public - * @return void - */ - public function delete_setting( $setting_name ) { - global $wpdb; - $qmn_quiz_settings = $wpdb->get_var( $wpdb->prepare( 'SELECT quiz_settings FROM ' . $wpdb->prefix . 'mlw_quizzes' . ' WHERE quiz_id=%d', $this->quiz_id ) ); - $qmn_settings_array = maybe_unserialize( $qmn_quiz_settings ); - if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting_name ] ) ) { - unset( $qmn_settings_array[ $setting_name ] ); - } - $results = $wpdb->update( - $wpdb->prefix . 'mlw_quizzes', - array( - 'quiz_settings' => maybe_serialize( $qmn_settings_array ), - ), - array( 'quiz_id' => $this->quiz_id ), - array( - '%s', - ), - array( '%d' ) - ); - } -} +quiz_id = intval( $_REQUEST['quiz_id'] ); + } + } + + /** + * Sets quiz ID + * + * @since 3.8.1 + * @param int $quiz_id The ID of the quiz. + * @access public + * @return void + */ + public function set_id( $quiz_id ) { + $this->quiz_id = intval( $quiz_id ); + } + + /** + * Gets the quiz ID stored (for backwards compatibility) + * + * @since 5.0.0 + * @return int|false The ID of the quiz stored or false + */ + public function get_id() { + if ( $this->quiz_id ) { + return intval( $this->quiz_id ); + } else { + return false; + } + } + + /** + * Creates a new quiz with the default settings + * + * @access public + * @since 3.7.1 + * @param string $quiz_name The name of the new quiz. + * @return void + */ + public function create_quiz( $quiz_name, $theme_id, $quiz_settings = array() ) { + global $wpdb, $mlwQuizMasterNext; + $current_user = wp_get_current_user(); + $default_texts = QMNPluginHelper::get_default_texts(); + $results = $wpdb->insert( + $wpdb->prefix . 'mlw_quizzes', + array( + 'quiz_name' => $quiz_name, + 'message_before' => isset( $default_texts['message_before'] ) ? $default_texts['message_before'] : __( 'Welcome to your %QUIZ_NAME%', 'quiz-master-next' ), + 'message_after' => __( 'Thanks for submitting your response! You can edit this message on the "Results Pages" tab.
%CONTACT_ALL%
%QUESTIONS_ANSWERS%', 'quiz-master-next' ), + 'message_comment' => isset( $default_texts['message_comment'] ) ? $default_texts['message_comment'] : __( 'Please fill in the comment box below.', 'quiz-master-next' ), + 'message_end_template' => '', + 'user_email_template' => '%QUESTIONS_ANSWERS_EMAIL%', + 'admin_email_template' => '%QUESTIONS_ANSWERS_EMAIL%', + 'submit_button_text' => isset( $default_texts['submit_button_text'] ) ? $default_texts['submit_button_text'] : __( 'Submit', 'quiz-master-next' ), + 'name_field_text' => isset( $default_texts['name_field_text'] ) ? $default_texts['name_field_text'] : __( 'Name', 'quiz-master-next' ), + 'business_field_text' => isset( $default_texts['business_field_text'] ) ? $default_texts['business_field_text'] : __( 'Business', 'quiz-master-next' ), + 'email_field_text' => isset( $default_texts['email_field_text'] ) ? $default_texts['email_field_text'] : __( 'Email', 'quiz-master-next' ), + 'phone_field_text' => isset( $default_texts['phone_field_text'] ) ? $default_texts['phone_field_text'] : __( 'Phone Number', 'quiz-master-next' ), + 'comment_field_text' => isset( $default_texts['comment_field_text'] ) ? $default_texts['comment_field_text'] : __( 'Comments', 'quiz-master-next' ), + 'email_from_text' => 'Wordpress', + 'question_answer_template' => isset( $default_texts['question_answer_template'] ) ? $default_texts['question_answer_template'] : '%QUESTION%
%USER_ANSWERS_DEFAULT%', + 'leaderboard_template' => '', + 'quiz_system' => 0, + 'randomness_order' => 0, + 'loggedin_user_contact' => 0, + 'show_score' => 0, + 'send_user_email' => 0, + 'send_admin_email' => 0, + 'contact_info_location' => 0, + 'user_name' => 2, + 'user_comp' => 2, + 'user_email' => 2, + 'user_phone' => 2, + 'admin_email' => get_option( 'admin_email', 'Enter email' ), + 'comment_section' => isset( $_POST['comment_section'] ) ? sanitize_text_field( wp_unslash( $_POST['comment_section'] ) ) : 1, + 'question_from_total' => 0, + 'total_user_tries' => 0, + 'total_user_tries_text' => isset( $default_texts['total_user_tries_text'] ) ? $default_texts['total_user_tries_text'] : __( 'You have utilized all of your attempts to pass this quiz.', 'quiz-master-next' ), + 'certificate_template' => '', + 'social_media' => 0, + 'social_media_text' => __( 'I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next' ), + 'pagination' => 0, + 'pagination_text' => isset( $default_texts['next_button_text'] ) ? $default_texts['next_button_text'] : __( 'Next', 'quiz-master-next' ), + 'timer_limit' => 0, + 'quiz_stye' => '', + 'question_numbering' => 0, + 'quiz_settings' => maybe_serialize( $quiz_settings ), + 'theme_selected' => 'primary', + 'last_activity' => current_time( 'mysql' ), + 'require_log_in' => 0, + 'require_log_in_text' => isset( $default_texts['require_log_in_text'] ) ? $default_texts['require_log_in_text'] : __( 'This quiz is for logged in users only.', 'quiz-master-next' ), + 'limit_total_entries' => 0, + 'limit_total_entries_text' => isset( $default_texts['limit_total_entries_text'] ) ? $default_texts['limit_total_entries_text'] : __( 'Unfortunately, this quiz has a limited amount of entries it can recieve and has already reached that limit.', 'quiz-master-next' ), + 'scheduled_timeframe' => '', + 'scheduled_timeframe_text' => '', + 'quiz_views' => 0, + 'quiz_taken' => 0, + 'deleted' => 0, + 'quiz_author_id' => $current_user->ID, + ), + array( + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%s', + '%d', + '%d', + '%d', + '%s', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%s', + '%s', + '%d', + '%s', + '%d', + '%s', + '%s', + '%s', + '%d', + '%d', + '%d', + '%d', + ) + ); + if ( false !== $results ) { + $new_quiz = $wpdb->insert_id; + $quiz_post = array( + 'post_title' => $quiz_name, + 'post_content' => "[mlw_quizmaster quiz=$new_quiz]", + 'post_status' => 'draft', + 'post_author' => $current_user->ID, + 'post_type' => 'qsm_quiz', + ); + $quiz_post_id = wp_insert_post( $quiz_post ); + add_post_meta( $quiz_post_id, 'quiz_id', $new_quiz ); + + // activating selected theme + $mlwQuizMasterNext->theme_settings->activate_selected_theme( $new_quiz, $theme_id ); + + $mlwQuizMasterNext->alertManager->newAlert( __( 'Your new quiz or survey has been created successfully. To begin editing, click the Edit link.', 'quiz-master-next' ), 'success' ); + $mlwQuizMasterNext->audit_manager->new_audit( 'New Quiz/Survey Has Been Created', $new_quiz, '' ); + + /** + * Prepare quiz result & email templates. + */ + self::add_quiz_templates($new_quiz); + + // Hook called after new quiz or survey has been created. Passes quiz_id to hook + do_action( 'qmn_quiz_created', $new_quiz ); + } else { + $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0001', 'quiz-master-next' ), 'error' ); + $mlwQuizMasterNext->log_manager->add( 'Error 0001', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); + } + } + + /** + * Deletes a quiz with the given quiz_id + * + * @access public + * @since 3.7.1 + * @return void + */ + public function delete_quiz( $quiz_id, $quiz_name ) { + global $mlwQuizMasterNext; + global $wpdb; + + $qsm_delete_from_db = isset( $_POST['qsm_delete_from_db'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['qsm_delete_from_db'] ) ); + $qsm_delete_questions_from_qb = isset( $_POST['qsm_delete_question_from_qb'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['qsm_delete_question_from_qb'] ) ); + $quizzes_table = $wpdb->prefix . 'mlw_quizzes'; + + $quiz_post_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = '$quiz_id'" ); + if ( empty( $quiz_post_id ) || ! current_user_can( 'delete_post', $quiz_post_id ) ) { + $mlwQuizMasterNext->alertManager->newAlert( __( 'Sorry, you are not allowed to delete this quiz.', 'quiz-master-next' ), 'error' ); + return; + } + + $is_row_exists = $wpdb->get_var( $wpdb->prepare( "SELECT * FROM $quizzes_table WHERE quiz_id=%d", $quiz_id ) ); + + if ( $qsm_delete_from_db ) { + $qsm_delete = $wpdb->delete( + $wpdb->prefix . 'mlw_quizzes', + array( 'quiz_id' => $quiz_id ) + ); + } else { + $qsm_delete = $wpdb->update( + $wpdb->prefix . 'mlw_quizzes', + array( + 'deleted' => 1, + ), + array( 'quiz_id' => $quiz_id ), + array( + '%d', + ), + array( '%d' ) + ); + $deleted = 0; + if ( $qsm_delete_questions_from_qb ) { + $deleted = 1; + $wpdb->update( + $wpdb->prefix . 'mlw_questions', + array( + 'deleted' => $deleted, + ), + array( 'quiz_id' => $quiz_id ), + array( + '%d', + ), + array( '%d' ) + ); + } + } + + if ( empty( $is_row_exists ) ) { + $qsm_delete = 1; + } + + if ( $qsm_delete ) { + if ( ! empty( $quiz_post_id ) ) { + if ( $qsm_delete_from_db ) { + wp_delete_post( $quiz_post_id, true ); + } else { + wp_trash_post( $quiz_post_id ); + } + } + $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been deleted successfully.', 'quiz-master-next' ), 'success' ); + $mlwQuizMasterNext->audit_manager->new_audit( "Quiz/Survey Has Been Deleted: $quiz_name", $quiz_id, '' ); + } else { + $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0002', 'quiz-master-next' ), 'error' ); + $mlwQuizMasterNext->log_manager->add( 'Error 0002', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); + } + // Hook called after quiz or survey is deleted. Hook passes quiz_id to function + do_action( 'qmn_quiz_deleted', $quiz_id ); + } + + /** + * Edits the name of the quiz with the given ID + * + * @access public + * @since 3.7.1 + * @param int $quiz_id The ID of the quiz. + * @param string $quiz_name The new name of the quiz. + * @return void + */ + public function edit_quiz_name( $quiz_id, $quiz_name, $post_id ) { + global $mlwQuizMasterNext; + global $wpdb; + $results = $wpdb->update( + $wpdb->prefix . 'mlw_quizzes', + array( + 'quiz_name' => $quiz_name, + ), + array( 'quiz_id' => $quiz_id ), + array( + '%s', + ), + array( '%d' ) + ); + if ( false !== $results ) { + $quiz_data = array( + 'ID' => $post_id, + 'post_title' => $quiz_name, + ); + wp_update_post($quiz_data); + + $mlwQuizMasterNext->alertManager->newAlert( __( 'The name of your quiz or survey has been updated successfully.', 'quiz-master-next' ), 'success' ); + $mlwQuizMasterNext->audit_manager->new_audit( 'Quiz/Survey Name Has Been Edited', $quiz_id, '' ); + } else { + $error = $wpdb->last_error; + if ( empty( $error ) ) { + $error = __( 'Unknown error', 'quiz-master-next' ); + } + $mlwQuizMasterNext->alertManager->newAlert( __( 'An error occurred while trying to update the name of your quiz or survey. Please try again.', 'quiz-master-next' ), 'error' ); + $mlwQuizMasterNext->log_manager->add( 'Error when updating quiz name', "Tried {$wpdb->last_query} but got $error", 0, 'error' ); + } + + // Fires when the name of a quiz/survey is edited. + do_action( 'qsm_quiz_name_edited', $quiz_id, $quiz_name ); + + // Legacy code. + do_action( 'qmn_quiz_name_edited', $quiz_id ); + } + + /** + * Duplicates the quiz with the given ID and gives new quiz the given quiz name + * + * @access public + * @since 3.7.1 + * @return void + */ + public function duplicate_quiz( $quiz_id, $quiz_name, $is_duplicating_questions ) { + global $mlwQuizMasterNext; + global $wpdb; + + $quiz_post_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = '$quiz_id'" ); + if ( empty( $quiz_post_id ) || ! current_user_can( 'edit_post', $quiz_post_id ) ) { + $mlwQuizMasterNext->alertManager->newAlert( __( 'Sorry, you are not allowed to duplicate this quiz.', 'quiz-master-next' ), 'error' ); + return; + } + + $current_user = wp_get_current_user(); + $table_name = $wpdb->prefix . 'mlw_quizzes'; + $logic_table = $wpdb->prefix . 'mlw_logic'; + $question_term = $wpdb->prefix . 'mlw_question_terms'; + $logic_table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $logic_table ) ); + $question_term_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $question_term ) ); + $mlw_qmn_duplicate_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE quiz_id=%d", $quiz_id ) ); + $quiz_settings = maybe_unserialize( $mlw_qmn_duplicate_data->quiz_settings ); + if ( 0 == $is_duplicating_questions && isset($quiz_settings['pages']) ) { + $quiz_settings['pages'] = array(); + } + $qsm_create_quiz_system = 0; + if ( isset( $mlw_qmn_duplicate_data->system ) ) { + $qsm_create_quiz_system = $mlw_qmn_duplicate_data->system; + } elseif ( isset( $mlw_qmn_duplicate_data->quiz_system ) ) { + $qsm_create_quiz_system = $mlw_qmn_duplicate_data->quiz_system; + } + $results = $wpdb->insert( + $table_name, + array( + 'quiz_name' => $quiz_name, + 'message_before' => $mlw_qmn_duplicate_data->message_before, + 'message_after' => $mlw_qmn_duplicate_data->message_after, + 'message_comment' => $mlw_qmn_duplicate_data->message_comment, + 'message_end_template' => $mlw_qmn_duplicate_data->message_end_template, + 'user_email_template' => $mlw_qmn_duplicate_data->user_email_template, + 'admin_email_template' => $mlw_qmn_duplicate_data->admin_email_template, + 'submit_button_text' => $mlw_qmn_duplicate_data->submit_button_text, + 'name_field_text' => $mlw_qmn_duplicate_data->name_field_text, + 'business_field_text' => $mlw_qmn_duplicate_data->business_field_text, + 'email_field_text' => $mlw_qmn_duplicate_data->email_field_text, + 'phone_field_text' => $mlw_qmn_duplicate_data->phone_field_text, + 'comment_field_text' => $mlw_qmn_duplicate_data->comment_field_text, + 'email_from_text' => $mlw_qmn_duplicate_data->email_from_text, + 'question_answer_template' => $mlw_qmn_duplicate_data->question_answer_template, + 'leaderboard_template' => $mlw_qmn_duplicate_data->leaderboard_template, + 'quiz_system' => $qsm_create_quiz_system, + 'randomness_order' => $mlw_qmn_duplicate_data->randomness_order, + 'loggedin_user_contact' => $mlw_qmn_duplicate_data->loggedin_user_contact, + 'show_score' => $mlw_qmn_duplicate_data->show_score, + 'send_user_email' => $mlw_qmn_duplicate_data->send_user_email, + 'send_admin_email' => $mlw_qmn_duplicate_data->send_admin_email, + 'contact_info_location' => $mlw_qmn_duplicate_data->contact_info_location, + 'user_name' => $mlw_qmn_duplicate_data->user_name, + 'user_comp' => $mlw_qmn_duplicate_data->user_comp, + 'user_email' => $mlw_qmn_duplicate_data->user_email, + 'user_phone' => $mlw_qmn_duplicate_data->user_phone, + 'admin_email' => get_option( 'admin_email', 'Enter email' ), + 'comment_section' => $mlw_qmn_duplicate_data->comment_section, + 'question_from_total' => $mlw_qmn_duplicate_data->question_from_total, + 'total_user_tries' => $mlw_qmn_duplicate_data->total_user_tries, + 'total_user_tries_text' => $mlw_qmn_duplicate_data->total_user_tries_text, + 'certificate_template' => $mlw_qmn_duplicate_data->certificate_template, + 'social_media' => $mlw_qmn_duplicate_data->social_media, + 'social_media_text' => $mlw_qmn_duplicate_data->social_media_text, + 'pagination' => $mlw_qmn_duplicate_data->pagination, + 'pagination_text' => $mlw_qmn_duplicate_data->pagination_text, + 'timer_limit' => $mlw_qmn_duplicate_data->timer_limit, + 'quiz_stye' => $mlw_qmn_duplicate_data->quiz_stye, + 'question_numbering' => $mlw_qmn_duplicate_data->question_numbering, + 'quiz_settings' => maybe_serialize( $quiz_settings ), + 'theme_selected' => $mlw_qmn_duplicate_data->theme_selected, + 'last_activity' => gmdate( 'Y-m-d H:i:s' ), + 'require_log_in' => $mlw_qmn_duplicate_data->require_log_in, + 'require_log_in_text' => $mlw_qmn_duplicate_data->require_log_in_text, + 'limit_total_entries' => $mlw_qmn_duplicate_data->limit_total_entries, + 'limit_total_entries_text' => $mlw_qmn_duplicate_data->limit_total_entries_text, + 'scheduled_timeframe' => $mlw_qmn_duplicate_data->scheduled_timeframe, + 'scheduled_timeframe_text' => $mlw_qmn_duplicate_data->scheduled_timeframe_text, + 'quiz_views' => 0, + 'quiz_taken' => 0, + 'deleted' => 0, + 'quiz_author_id' => $current_user->ID, + ), + array( + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%s', + '%d', + '%d', + '%d', + '%s', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%s', + '%s', + '%d', + '%s', + '%d', + '%s', + '%s', + '%s', + '%d', + '%d', + '%d', + '%d', + ) + ); + $mlw_new_id = $wpdb->insert_id; + + $settings = (array) get_option('qmn-settings'); + $duplicate_quiz_with_theme = !empty($settings['duplicate_quiz_with_theme']) ? esc_attr($settings['duplicate_quiz_with_theme']) : 0; + + if ('1' === $duplicate_quiz_with_theme) { + $theme_table = $wpdb->prefix . 'mlw_quiz_theme_settings'; + $old_quiz_theme_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM $theme_table WHERE quiz_id = %d AND active_theme = 1", $quiz_id)); + + if ($old_quiz_theme_data) { + $new_quiz_theme_data = array( + 'theme_id' => $old_quiz_theme_data->theme_id, + 'quiz_id' => $mlw_new_id, + 'quiz_theme_settings' => $old_quiz_theme_data->quiz_theme_settings, + 'active_theme' => 1, + ); + + $format = array( + '%d', + '%d', + '%s', + '%d', + ); + + $wpdb->insert($theme_table, $new_quiz_theme_data, $format); + $mlwQuizMasterNext->alertManager->newAlert(__('There has been an error in this action. Please share this with the developer. Error Code: 0051', 'quiz-master-next'), 'error'); + $mlwQuizMasterNext->log_manager->add('Error 0051', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error'); + } + } + + + // Update quiz settings + $update_quiz_settings = maybe_unserialize( $mlw_qmn_duplicate_data->quiz_settings ); + $update_pages = maybe_unserialize( $update_quiz_settings['pages'] ); + // get logic data from logic table first or else from quiz_settings + if ( ! is_null( $logic_table_exists ) ) { + $query = $wpdb->prepare( "SELECT * FROM $logic_table WHERE quiz_id = %d", $quiz_id ); + $logic_data = $wpdb->get_results( $query ); + $logic_rules = array(); + if ( ! empty( $logic_data ) ) { + foreach ( $logic_data as $data ) { + $logic_rules[] = maybe_unserialize( $data->logic ); + } + } + } else { + $logic_rules = isset( $update_quiz_settings['logic_rules'] ) ? maybe_unserialize( $update_quiz_settings['logic_rules'] ) : array(); + } + + if ( false !== $results ) { + $current_user = wp_get_current_user(); + $quiz_post = array( + 'post_title' => $quiz_name, + 'post_content' => "[mlw_quizmaster quiz=$mlw_new_id]", + 'post_status' => 'publish', + 'post_author' => $current_user->ID, + 'post_type' => 'qsm_quiz', + ); + $quiz_post_id = wp_insert_post( $quiz_post ); + add_post_meta( $quiz_post_id, 'quiz_id', $mlw_new_id ); + $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been duplicated successfully.', 'quiz-master-next' ), 'success' ); + $mlwQuizMasterNext->audit_manager->new_audit( 'New Quiz/Survey Has Been Created', $mlw_new_id, '' ); + /** + * Prepare quiz result & email templates. + */ + self::add_quiz_templates($mlw_new_id); + + do_action( 'qmn_quiz_duplicated', $quiz_id, $mlw_new_id ); + } else { + $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0011', 'quiz-master-next' ), 'error' ); + $mlwQuizMasterNext->log_manager->add( 'Error 0011', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); + } + if ( $is_duplicating_questions ) { + $table_name = $wpdb->prefix . 'mlw_questions'; + $questions = array(); + if ( is_array( $update_pages ) ) { + foreach ( $update_pages as $ids ) { + foreach ( $ids as $id ) { + $questions[] = $id; + } + } + } + $question_ids = implode( ',', $questions ); + $mlw_current_questions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $table_name WHERE question_id IN (%1s)", $question_ids ) ); + foreach ( $mlw_current_questions as $mlw_question ) { + $question_results = $wpdb->insert( + $table_name, + array( + 'quiz_id' => $mlw_new_id, + 'question_name' => $mlw_question->question_name, + 'answer_array' => $mlw_question->answer_array, + 'answer_one' => $mlw_question->answer_one, + 'answer_one_points' => $mlw_question->answer_one_points, + 'answer_two' => $mlw_question->answer_two, + 'answer_two_points' => $mlw_question->answer_two_points, + 'answer_three' => $mlw_question->answer_three, + 'answer_three_points' => $mlw_question->answer_three_points, + 'answer_four' => $mlw_question->answer_four, + 'answer_four_points' => $mlw_question->answer_four_points, + 'answer_five' => $mlw_question->answer_five, + 'answer_five_points' => $mlw_question->answer_five_points, + 'answer_six' => $mlw_question->answer_six, + 'answer_six_points' => $mlw_question->answer_six_points, + 'correct_answer' => $mlw_question->correct_answer, + 'question_answer_info' => $mlw_question->question_answer_info, + 'comments' => $mlw_question->comments, + 'hints' => $mlw_question->hints, + 'question_order' => $mlw_question->question_order, + 'question_type_new' => $mlw_question->question_type_new, + 'question_settings' => $mlw_question->question_settings, + 'category' => $mlw_question->category, + 'deleted' => 0, + ), + array( + '%d', + '%s', + '%s', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%d', + '%d', + '%s', + '%d', + '%s', + '%d', + '%s', + '%s', + '%s', + '%d', + ) + ); + foreach ( $update_pages as $pages_key => $pages_value ) { + foreach ( $pages_value as $pages_k_q => $page_q_id ) { + if ( intval($page_q_id) === intval($mlw_question->question_id) ) { + $update_pages[ $pages_key ][ $pages_k_q ] = $wpdb->insert_id; + } + } + } + // Fixed Rules Questions with new question ids + if ( is_array( $logic_rules ) ) { + foreach ( $logic_rules as $logic_key => $logic_value ) { + foreach ( $logic_value as $logic_cond_k => $logic_cond ) { + foreach ( $logic_cond as $l_cond_k => $logic_val ) { + if ( $logic_val['question'] === $mlw_question->question_id ) { + $logic_rules[ $logic_key ][ $logic_cond_k ][ $l_cond_k ]['question'] = $wpdb->insert_id; + } + } + } + } + } + // Copying categories for multiple categories table + $new_question_id = $wpdb->insert_id; + if ( ! is_null( $question_term_exists ) ) { + $query = $wpdb->prepare( "SELECT DISTINCT term_id FROM $question_term WHERE question_id = %d AND quiz_id = %d", $mlw_question->question_id, $quiz_id ); + $term_ids = $wpdb->get_results( $query, ARRAY_N ); + + if ( ! is_null( $term_ids ) ) { + foreach ( $term_ids as $term_id ) { + $wpdb->insert( + $question_term, + array( + 'question_id' => $new_question_id, + 'quiz_id' => $mlw_new_id, + 'term_id' => $term_id[0], + 'taxonomy' => 'qsm_category', + ), + array( + '%d', + '%d', + '%d', + '%s', + ) + ); + } + } + } + + if ( false === $question_results ) { + $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0020', 'quiz-master-next' ), 'error' ); + $mlwQuizMasterNext->log_manager->add( 'Error 0020', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); + } + } + $update_quiz_settings['pages'] = maybe_serialize( $update_pages ); + // saves data in logic table first or else in quiz_settings. + $value_array = array(); + if ( is_array( $logic_rules ) && ! empty( $logic_rules ) ) { + if ( is_null( $logic_table_exists ) ) { + $update_quiz_settings['logic_rules'] = maybe_serialize( $logic_rules ); + } else { + foreach ( $logic_rules as $logic_data ) { + $value_array[] = stripslashes( $wpdb->prepare( '(%d, %s)', $mlw_new_id, maybe_serialize( $logic_data ) ) ); + } + $values = implode( ',', $value_array ); + $query = "INSERT INTO `{$logic_table}` (quiz_id, logic) VALUES {$values}"; + $saved = $wpdb->query( $query ); + if ( false !== $saved ) { + update_option( "logic_rules_quiz_$mlw_new_id", gmdate( time() ) ); + $update_quiz_settings['logic_rules'] = ''; + } else { + $update_quiz_settings['logic_rules'] = maybe_serialize( $logic_rules ); + } + } + } + + $wpdb->update( + $wpdb->prefix . 'mlw_quizzes', + array( + 'quiz_settings' => maybe_serialize( $update_quiz_settings ), + ), + array( + 'quiz_id' => $mlw_new_id, + ) + ); + } + } + + public static function add_quiz_templates( $quiz_id ) { + global $mlwQuizMasterNext; + $pages = QSM_Results_Pages::load_pages( $quiz_id ); + for ( $i = 0; $i < count( $pages ); $i++ ) { + if ( ! empty($pages[ $i ]['page']) ) { + $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $pages[ $i ]['page'], "quiz-result-page-{$i}-{$quiz_id}" ); + } + } + $emails = QSM_Emails::load_emails( $quiz_id ); + for ( $i = 0; $i < count( $emails ); $i++ ) { + if ( ! empty($emails[ $i ]['content']) ) { + $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $emails[ $i ]['subject'], "quiz-email-subject-{$i}-{$quiz_id}" ); + $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $emails[ $i ]['content'], "quiz-email-content-{$i}-{$quiz_id}" ); + } + } + } + + /** + * Retrieves setting store in quiz_settings + * + * @deprecated 6.0.3 Use the get_quiz_setting function in the pluginHelper object. + * @since 3.8.1 + * @access public + * @param string $setting_name The slug of the setting. + * @return string The value of the setting + */ + public function get_setting( $setting_name ) { + global $wpdb; + $qmn_settings_array = ''; + $qmn_quiz_settings = $wpdb->get_var( $wpdb->prepare( 'SELECT quiz_settings FROM ' . $wpdb->prefix . 'mlw_quizzes' . ' WHERE quiz_id=%d', $this->quiz_id ) ); + $qmn_settings_array = maybe_unserialize( $qmn_quiz_settings ); + if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting_name ] ) ) { + return $qmn_settings_array[ $setting_name ]; + } else { + return ''; + } + + } + + /** + * Updates setting stored in quiz_settings + * + * @deprecated 6.0.3 Use the update_quiz_setting function in the pluginHelper object. + * @since 3.8.1 + * @access public + * @param string $setting_name The slug of the setting. + * @param mixed $setting_value The value for the setting. + * @return bool True if update was successful + */ + public function update_setting( $setting_name, $setting_value ) { + global $wpdb; + $qmn_quiz_settings = $wpdb->get_var( $wpdb->prepare( 'SELECT quiz_settings FROM ' . $wpdb->prefix . 'mlw_quizzes' . ' WHERE quiz_id=%d', $this->quiz_id ) ); + $qmn_settings_array = maybe_unserialize( $qmn_quiz_settings ); + if ( ! is_array( $qmn_settings_array ) ) { + $qmn_settings_array = array(); + } + $qmn_settings_array[ $setting_name ] = $setting_value; + $results = $wpdb->update( + $wpdb->prefix . 'mlw_quizzes', + array( + 'quiz_settings' => maybe_serialize( $qmn_settings_array ), + ), + array( 'quiz_id' => $this->quiz_id ), + array( + '%s', + ), + array( '%d' ) + ); + if ( false !== $results ) { + return true; + } else { + return false; + } + } + + /** + * Deletes setting stored in quiz_settings + * + * @deprecated 6.0.3 + * @since 3.8.1 + * @access public + * @return void + */ + public function delete_setting( $setting_name ) { + global $wpdb; + $qmn_quiz_settings = $wpdb->get_var( $wpdb->prepare( 'SELECT quiz_settings FROM ' . $wpdb->prefix . 'mlw_quizzes' . ' WHERE quiz_id=%d', $this->quiz_id ) ); + $qmn_settings_array = maybe_unserialize( $qmn_quiz_settings ); + if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting_name ] ) ) { + unset( $qmn_settings_array[ $setting_name ] ); + } + $results = $wpdb->update( + $wpdb->prefix . 'mlw_quizzes', + array( + 'quiz_settings' => maybe_serialize( $qmn_settings_array ), + ), + array( 'quiz_id' => $this->quiz_id ), + array( + '%s', + ), + array( '%d' ) + ); + } +}