Exemplo n.º 1
0
 static function my_courses()
 {
     if (!is_user_logged_in()) {
         return __('This content is for logged in users.', 'namaste');
     }
     // call the simplified version
     ob_start();
     NamasteLMSCoursesController::my_courses(true);
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
Exemplo n.º 2
0
function namaste_enroll()
{
    global $wpdb, $user_ID, $user_email, $post;
    if (!is_user_logged_in()) {
        $content = '';
        $required_lessons_ids = get_post_meta($post->ID, 'namaste_required_lessons', true);
        if (!is_array($required_lessons_ids)) {
            $required_lessons_ids = array();
        }
        if (!empty($required_lessons_ids)) {
            sort($required_lessons_ids);
            $content .= "<ul class='not-auth-todo-list'>\n";
            foreach ($required_lessons_ids as $lesson) {
                $content .= "<li>" . get_the_title($lesson);
                $content .= "</li>\n";
            }
            $content .= "</ul>";
        }
        return $content;
    }
    $enrolled = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_COURSES . " WHERE user_id = %d AND course_id = %d", $user_ID, $post->ID));
    if (empty($enrolled->id)) {
        $currency = get_option('namaste_currency');
        $is_manager = current_user_can('namaste_manage');
        $_course = new NamasteLMSCourseModel();
        // stripe integration goes right on this page
        $accept_stripe = get_option('namaste_accept_stripe');
        $accept_paypal = get_option('namaste_accept_paypal');
        $accept_other_payment_methods = get_option('namaste_accept_other_payment_methods');
        if ($accept_stripe) {
            $stripe = NamasteStripe::load();
        }
        if (!empty($_POST['stripe_pay'])) {
            NamasteStripe::pay($currency);
            namaste_redirect($_SERVER['REQUEST_URI']);
        }
        if (!empty($_POST['enroll'])) {
            echo " <script type='text/javascript'> location.reload(true); </script>";
            $mesage = NamasteLMSCoursesController::enroll($is_manager);
            namaste_redirect($_SERVER['REQUEST_URI']);
        }
        $_course->currency = $currency;
        $_course->accept_other_payment_methods = $accept_other_payment_methods;
        $_course->accept_paypal = $accept_paypal;
        $_course->accept_stripe = $accept_stripe;
        $_course->stripe = $stripe;
        wp_enqueue_script('thickbox', null, array('jquery'));
        wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0');
        $post->post_id = $post->ID;
        $post->fee = get_post_meta($post->ID, 'namaste_fee', true);
        $content = $_course->enroll_buttons($post, $is_manager);
        $content = str_replace('<form method="post">', '<form method="post" id="namaste-enroll-form">', $content);
        $content = str_replace('</form>', '</form><a id="enroll-not-auth" class="upperCase" href="#">' . __('Enroll', 'qode') . '<span>»</span></a><script>(function($){
    $("#share-social-buttons").addClass("not-logged");

    $("#enroll-not-auth").on("click", function(e){
        e.preventDefault();
        $("#namaste-enroll-form").submit();
    });
})(jQuery);</script>', $content);
        return $content;
    } else {
        switch ($enrolled->status) {
            case 'enrolled':
                return __('You are enrolled in this course.', 'namaste');
                break;
            case 'pending':
                return __('Your enroll request is received. Waiting for manager approval.', 'namaste');
                break;
            case 'completed':
                return __('You have completed this course.', 'namaste');
                break;
            case 'rejected':
                return __('Your enrollment request is rejected.', 'namaste');
                break;
        }
    }
}