Beispiel #1
0
function gdlr_lms_header_signin()
{
    if (is_user_logged_in()) {
        global $current_user;
        echo '<div class="gdlr-lms-header-signin">';
        echo '<a href="' . get_author_posts_url($current_user->ID) . '" >' . $current_user->display_name . '</a>';
        echo '<span class="gdlr-separator">|</span>';
        echo '<a href="' . wp_logout_url(home_url()) . '" >' . __('Logout', 'gdlr-lms') . '</a>';
        echo '</div>';
    } else {
        echo '<div class="gdlr-lms-header-signin">';
        echo '<i class="fa fa-lock icon-lock"></i>';
        echo '<a data-rel="gdlr-lms-lightbox" data-lb-open="login-form" >' . __('Sign In', 'gdlr-lms') . '</a>';
        gdlr_lms_sign_in_lightbox_form();
        echo '<span class="gdlr-separator">|</span>';
        echo '<a href="' . esc_url(add_query_arg('register', get_permalink(), home_url())) . '">' . __('Sign Up', 'gdlr-lms') . '</a>';
        echo '</div>';
    }
}
function gdlr_lms_print_course_button($course_options, $options = array('buy', 'book', 'learn'))
{
    global $gdlr_lms_option, $current_user;
    echo '<div class="gdlr-course-button" >';
    // for non member course
    if (!empty($course_options['allow-non-member']) && $course_options['allow-non-member'] == 'enable' && (empty($course_options['online-course']) || $course_options['online-course'] == 'enable') && (in_array('buy', $options) || in_array('book', $options))) {
        $options = array('start');
        // if not logging in
    } else {
        if (!is_user_logged_in() && !in_array('finish-quiz', $options)) {
            $lightbox_open = 'login-form';
            gdlr_lms_sign_in_lightbox_form();
        } else {
            // when purchase button is available
            if (in_array('buy', $options) || in_array('book', $options)) {
                // prerequisite course
                $prerequisite = false;
                if (!empty($course_options['prerequisite-course']) && $course_options['prerequisite-course'] != 'none') {
                    $prerequisite = true;
                    $find_row = gdlr_lms_get_payment_row($course_options['prerequisite-course'], $current_user->ID);
                    $payment_status = empty($find_row) ? false : $find_row->payment_status;
                    $p_course_options = gdlr_lms_get_course_options($course_options['prerequisite-course']);
                    // if prerequisite is offline course
                    if (!empty($p_course_options['online-course']) && $p_course_options['online-course'] == 'disable') {
                        if ($payment_status == 'paid' || $payment_status == 'reserved') {
                            $prerequisite = false;
                        }
                        // for online course
                    } else {
                        if ($payment_status == 'paid' || $payment_status == 'reserved') {
                            // if prerequisite course has quiz
                            if (!empty($p_course_options['quiz']) && $p_course_options['quiz'] != 'none') {
                                $quiz_row = gdlr_lms_get_quiz_row($p_course_options['quiz'], $course_options['prerequisite-course'], $current_user->ID, 'quiz_status');
                                $quiz_status = empty($quiz_row) ? false : $quiz_row->quiz_status;
                                if ($quiz_status == 'complete' || $quiz_status == 'submitted') {
                                    $prerequisite = false;
                                }
                            } else {
                                $p_section = empty($find_row) ? -1 : intval($find_row->attendance_section);
                                $p_course_settings = gdlr_lms_get_course_content_settings($course_options['prerequisite-course']);
                                if ($p_section == sizeof($p_course_settings)) {
                                    $prerequisite = false;
                                }
                            }
                        }
                    }
                }
                // course author
                global $post;
                $is_course_author = $post->post_author == $current_user->ID;
                // print button
                if ($prerequisite) {
                    $options = array('prerequisite');
                } else {
                    $find_row = gdlr_lms_get_payment_row(get_the_ID(), $current_user->ID, 'payment_status');
                    $payment_status = empty($find_row) ? false : $find_row->payment_status;
                    // for paid and free courses
                    if ($is_course_author || empty($course_options['price']) && empty($course_options['discount-price']) || $payment_status == 'paid') {
                        if (empty($course_options['online-course']) || $course_options['online-course'] == 'enable') {
                            $options = array('start');
                        } else {
                            if ($payment_status == 'reserved') {
                                $options = array('booking-status');
                            } else {
                                if ($payment_status != 'paid' && !$is_course_author) {
                                    $options = array('book');
                                } else {
                                    $options = array();
                                }
                            }
                        }
                        // booked course
                    } else {
                        if ($payment_status == 'pending' || $payment_status == 'submitted') {
                            $options = array('proceed-payment');
                        }
                    }
                }
            }
        }
    }
    // receipt only
    if (in_array('buy', $options) && !empty($gdlr_lms_option['payment-method']) && $gdlr_lms_option['payment-method'] == 'receipt') {
        unset($options[array_search('buy', $options)]);
    }
    foreach ($options as $value) {
        switch ($value) {
            case 'buy':
                if (empty($course_options['expired-date']) || time() < strtotime($course_options['expired-date'])) {
                    echo '<a data-rel="gdlr-lms-lightbox" data-lb-open="';
                    echo empty($lightbox_open) ? 'buy-form' : $lightbox_open;
                    echo '" class="gdlr-lms-button cyan" >' . __('Buy Now', 'gdlr-lms') . '</a>';
                    if (empty($lightbox_open)) {
                        gdlr_lms_purchase_lightbox_form($course_options, 'buy');
                    }
                }
                break;
            case 'book':
                if (empty($course_options['expired-date']) || time() < strtotime($course_options['expired-date'])) {
                    echo '<a data-rel="gdlr-lms-lightbox" data-lb-open="';
                    echo empty($lightbox_open) ? 'book-form' : $lightbox_open;
                    echo '" class="gdlr-lms-button blue" >' . __('Book Now', 'gdlr-lms') . '</a>';
                    if (empty($lightbox_open)) {
                        gdlr_lms_purchase_lightbox_form($course_options, 'book');
                    }
                }
                break;
            case 'learn':
                echo '<a class="gdlr-lms-button black" href="' . get_permalink() . '" >' . __('Learn More', 'gdlr-lms') . '</a>';
                break;
            case 'start':
                echo '<a class="gdlr-lms-button cyan" href="' . esc_url(add_query_arg(array('course_type' => 'content', 'course_page' => 1), get_permalink())) . '" >';
                _e('Start the course', 'gdlr-lms');
                echo '</a>';
                break;
            case 'proceed-payment':
                global $current_user;
                echo '<a class="gdlr-lms-button cyan" href="' . esc_url(add_query_arg('type', 'book-courses', get_author_posts_url($current_user->ID))) . '" >';
                _e('Proceed to Payment', 'gdlr-lms');
                echo '</a>';
                break;
            case 'booking-status':
                global $current_user;
                echo '<a class="gdlr-lms-button cyan" href="' . esc_url(add_query_arg('type', 'free-onsite', get_author_posts_url($current_user->ID))) . '" >';
                _e('Booking Status', 'gdlr-lms');
                echo '</a>';
                break;
            case 'prerequisite':
                echo __('You have to complete ', 'gdlr-lms') . '<a href="' . get_permalink($course_options['prerequisite-course']) . '" >';
                echo get_the_title($course_options['prerequisite-course']);
                echo '</a> ' . __('before you can access to this course.', 'gdlr-lms');
                break;
            case 'quiz':
                if (!empty($course_options['quiz']) && $course_options['quiz'] != 'none') {
                    global $wpdb, $current_user;
                    $sql = 'SELECT * FROM ' . $wpdb->prefix . 'gdlrquiz ';
                    $sql .= 'WHERE quiz_id=' . $course_options['quiz'] . ' AND student_id=' . $current_user->ID . ' AND course_id=' . get_the_ID() . ' ';
                    $sql .= 'AND (quiz_status=\'complete\' OR quiz_status=\'submitted\')';
                    $old_quiz = $wpdb->get_row($sql);
                    if (!empty($old_quiz)) {
                        $quiz_val = gdlr_lms_decode_preventslashes(get_post_meta($course_options['quiz'], 'gdlr-lms-quiz-settings', true));
                        $quiz_options = empty($quiz_val) ? array() : json_decode($quiz_val, true);
                        if (!empty($quiz_options['retake-quiz']) && $quiz_options['retake-quiz'] == 'enable' && $old_quiz->retake_times < 9999 && (empty($quiz_options['retake-times']) || $old_quiz->retake_times < intval($quiz_options['retake-times']))) {
                            echo '<a class="gdlr-lms-button cyan" href="' . esc_url(add_query_arg(array('course_type' => 'quiz', 'course_page' => 1, 'retake' => 1), get_permalink())) . '" >';
                            _e('Retake a quiz', 'gdlr-lms');
                            echo '</a>';
                        }
                    } else {
                        if (is_user_logged_in()) {
                            echo '<a class="gdlr-lms-button cyan" href="' . esc_url(add_query_arg(array('course_type' => 'quiz', 'course_page' => 1), get_permalink())) . '" >';
                            _e('Take a quiz', 'gdlr-lms');
                            echo '</a>';
                        } else {
                            echo '<div class="gdlr-login-for-quiz" style="padding: 0px 20px 30px">';
                            _e('You have to register and login to the site before you can take the quiz.', 'gdlr-lms');
                            echo '</div>';
                        }
                    }
                }
                break;
            case 'finish-quiz':
                echo '<a href="' . esc_url(add_query_arg(array('course_type' => 'quiz', 'course_page' => 'finish'))) . '" ';
                echo 'data-loading="' . __('Submitting the answer', 'gdlr-lms') . '" ';
                echo 'class="gdlr-lms-button cyan finish-quiz-form-button" >';
                _e('Finish the quiz', 'gdlr-lms');
                echo '</a>';
                gdlr_lms_finish_quiz_form();
                break;
        }
    }
    echo '</div>';
}