function gdlr_cer_wrapper_shortcode($atts, $content = null) { extract(shortcode_atts(array('class' => '', 'background' => '', 'border' => 'yes', 'student_code' => 'false'), $atts)); global $gdlr_lms_cer_settings, $current_user; $ret = ''; $style = ''; if (!empty($background)) { $style = ' style="background: url(\'' . $background . '\') center center no-repeat;" '; } if ($border == 'yes') { $ret .= '<div class="certificate-form-outer-wrapper">'; $ret .= '<div class="certificate-form-wrapper">'; } $ret .= '<div class="certificate-wrapper ' . $class . '" ' . $style . ' >'; if ($student_code == "true") { $payment_row = gdlr_lms_get_payment_row($gdlr_lms_cer_settings['course_id'], $current_user->ID, 'payment_info'); $payment_info = empty($payment_row->payment_info) ? array() : unserialize($payment_row->payment_info); if (!empty($payment_info['code'])) { $ret .= '<div class="certificate-student-code">' . $payment_info['code'] . '</div>'; } } $ret .= do_shortcode($content); $ret .= '</div>'; if ($border == 'yes') { $ret .= '</div>'; $ret .= '</div>'; } return $ret; }
function gdlr_lms_register_course_template($template) { global $post, $current_user; if ($post->post_type == 'course') { $template = ''; if (isset($_GET['course_type'])) { global $wpdb, $gdlr_course_settings, $gdlr_course_options, $lms_page, $payment_row; $authorization = false; $gdlr_course_options = gdlr_lms_get_course_options($post->ID); $gdlr_course_settings = gdlr_lms_get_course_content_settings($post->ID); $lms_page = empty($_GET['course_page']) ? 1 : intval($_GET['course_page']); if (!is_user_logged_in() && !empty($gdlr_course_options['allow-non-member']) && $gdlr_course_options['allow-non-member'] == 'enable' && (empty($course_options['online-course']) || $course_options['online-course'] == 'enable')) { $authorization = true; } else { if (is_user_logged_in()) { if ($current_user->ID == $post->post_author) { $authorization = true; } else { // check if purchase before $payment_row = gdlr_lms_get_payment_row($post->ID, $current_user->ID); if (!empty($payment_row)) { if ($payment_row->payment_status == 'paid') { $authorization = true; if ($lms_page - 1 > $payment_row->attendance_section) { $lms_page = $payment_row->attendance_section + 1; } if ($payment_row->attendance_section < $lms_page) { $current_date = strtotime(date('Y-m-d H:i:s')); if (!empty($gdlr_course_settings[$lms_page - 2]['wait-time']) && $lms_page > 1) { $available_date = strtotime($payment_row->attendance) + intval($gdlr_course_settings[$lms_page - 2]['wait-time']) * 86400; } else { if (!empty($gdlr_course_settings[$lms_page - 2]['wait-date']) && $lms_page > 1) { $available_date = strtotime($gdlr_course_settings[$lms_page - 2]['wait-date']); } else { $available_date = strtotime($payment_row->attendance); } } if ($lms_page > 1 && $current_date <= $available_date) { global $gdlr_time_left; $gdlr_time_left = $available_date - $current_date; } else { $wpdb->update($wpdb->prefix . 'gdlrpayment', array('attendance' => date('Y-m-d H:i:s'), 'attendance_section' => $lms_page), array('id' => $payment_row->id), array('%s', '%d'), array('%d')); $payment_row->attendance_section = $payment_row->attendance_section + 1; } } } // check whether it is free course } else { if (empty($gdlr_course_options['price-one'])) { $authorization = true; $gdlr_course_options['booked-seat'] = intval($gdlr_course_options['booked-seat']) + 1; update_post_meta($post->ID, 'gdlr-lms-course-settings', json_encode($gdlr_course_options)); $running_number = intval(get_post_meta($post->ID, 'student-booking-id', true)); $running_number = empty($running_number) ? 1 : $running_number + 1; update_post_meta($post->ID, 'student-booking-id', $running_number); $code = substr(get_user_meta($current_user->ID, 'first_name', true), 0, 1) . substr(get_user_meta($current_user->ID, 'last_name', true), 0, 1); $code .= $running_number . $gdlr_course_options['course-code'] . $post->ID; $data = serialize(array('amount' => 1, 'price' => 0, 'code' => $code)); $wpdb->insert($wpdb->prefix . 'gdlrpayment', array('course_id' => $post->ID, 'student_id' => $current_user->ID, 'author_id' => $post->post_author, 'payment_date' => date('Y-m-d H:i:s'), 'payment_status' => 'paid', 'price' => '0', 'payment_info' => $data, 'attendance' => date('Y-m-d H:i:s'), 'attendance_section' => '1'), array('%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s')); $payment_row = gdlr_lms_get_payment_row($post->ID, $current_user->ID); } } } } } if ($authorization) { if ($_GET['course_type'] == 'content') { $template .= 'single-course-content.php'; } else { if ($_GET['course_type'] == 'quiz') { $template .= 'single-course-quiz.php'; } } } } $template = empty($template) ? 'single-course.php' : $template; $template = dirname(dirname(__FILE__)) . '/' . $template; } else { if ($post->post_type == 'quiz') { if ($current_user->ID == $post->post_author) { $template = dirname(dirname(__FILE__)) . '/single-course-quiz.php'; } else { $template = get_template_directory() . '/404.php'; } } } return $template; }
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>'; }