static function add_note() { global $wpdb, $user_ID; // select lesson $lesson = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID=%d", $_GET['lesson_id'])); // select student $student = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID=%d", $_GET['student_id'])); // select course $course_id = get_post_meta($lesson->ID, 'namaste_course', true); $course = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID=%d", $course_id)); // select homework $homework = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . " WHERE id=%d", $_GET['homework_id'])); if (!empty($_POST['ok']) and !empty($_POST['note'])) { // add the note $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HOMEWORK_NOTES . " SET\n\t\t\t\thomework_id=%d, student_id=%d, teacher_id=%d, note=%s, datetime=NOW()", $homework->id, $student->ID, $user_ID, $_POST['note'])); do_action('namaste_added_homework_note', $student->ID, $homework->id, $_POST['note']); // redirect back namaste_redirect("admin.php?page=namaste_lesson_homeworks&lesson_id=" . $lesson->ID . "&student_id=" . $student->ID); } if (@file_exists(get_stylesheet_directory() . '/namaste/add-note.php')) { require get_stylesheet_directory() . '/namaste/add-note.php'; } else { require NAMASTE_PATH . "/views/add-note.php"; } }
static function my_courses($simplified = false) { global $wpdb, $user_ID, $user_email; $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('admin.php?page=namaste_my_courses'); } if (!empty($_POST['enroll'])) { $mesage = self::enroll($is_manager); } // unenroll? if (!empty($_GET['unenroll'])) { NamasteLMSStudentModel::cleanup($_GET['unenroll'], $user_ID); namaste_redirect("admin.php?page=namaste_my_courses"); } // filters from other plugins like Namaste! PRO $filter_sql = ''; $filter_sql = apply_filters('namaste-course-select-sql', $filter_sql, $user_ID); // select all courses join to student courses so we can have status. $courses = $wpdb->get_results($wpdb->prepare("SELECT tSC.*, \n\t\t\ttC.post_title as post_title, tC.ID as post_id, tC.post_excerpt as post_excerpt\n\t\t\t FROM {$wpdb->posts} tC LEFT JOIN " . NAMASTE_STUDENT_COURSES . " tSC ON tC.ID = tSC.course_id\n\t\t\t AND tSC.user_id = %d WHERE tC.post_status = 'publish'\n\t\t\t AND tC.post_type='namaste_course' {$filter_sql} ORDER BY tC.post_title", $user_ID)); // external reorder? $courses = apply_filters('namaste-reorder-courses', $courses); if (!empty($currency) and !$is_manager) { foreach ($courses as $cnt => $course) { $courses[$cnt]->fee = get_post_meta($course->post_id, 'namaste_fee', true); } } $_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'); if (@file_exists(get_stylesheet_directory() . '/namaste/my_courses.php')) { require get_stylesheet_directory() . '/namaste/my_courses.php'; } else { require NAMASTE_PATH . "/views/my_courses.php"; } }
static function manage() { global $wpdb; $_course = new NamasteLMSCourseModel(); $multiuser_access = 'all'; $multiuser_access = NamasteLMSMultiUser::check_access('students_access'); // select all courses $courses = $_course->select(); $courses = apply_filters('namaste-homeworks-select-courses', $courses); // if course selected, select lessons and enrolled students if (!empty($_GET['course_id'])) { do_action('namaste-check-permissions', 'course', $_GET['course_id']); // cleanup student record if (!empty($_GET['cleanup'])) { if ($multiuser_access == 'view') { wp_die(__('You are not allowed to do this.', 'namaste')); } self::cleanup($_GET['course_id'], $_GET['student_id']); //namaste_redirect("admin.php?page=namaste_students&course_id=$_GET[course_id]&status=$_GET[status]"); } // enroll student if (!empty($_GET['enroll'])) { if ($multiuser_access == 'view') { wp_die(__('You are not allowed to do this.', 'namaste')); } // find the user $error = false; if (strstr($_GET['email'], '@')) { $student = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_email=%s", $_GET['email'])); } else { $student = get_user_by('login', $_GET['email']); } // user exists? if (empty($student->ID)) { $error = __('Sorry, I cannot find user with this email or user handle.', 'namaste'); } // allowed to use Namaste!? if (!$error and !user_can($student->ID, 'administrator') and !user_can($student->ID, 'namaste')) { $error = __("This user's role does not allow them to use Namaste! LMS. You'll have either to change their role or allow the role work with the LMS from the Settings page", 'namaste'); } // already enrolled? if (!$error) { $is_enrolled = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . NAMASTE_STUDENT_COURSES . "\n\t\t\t\t\t\t \tWHERE user_id = %d AND course_id = %d", $student->ID, $_GET['course_id'])); if ($is_enrolled) { $error = __('This user is already enrolled in the course', 'namaste'); } } // finally, enroll if (empty($error)) { $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_STUDENT_COURSES . " SET\n\t\t\t\t\t \t\t\tcourse_id = %d, user_id = %d, status = 'enrolled', \n\t\t\t\t\t \t\t\tenrollment_date = %s, completion_date = '1900-01-01', enrollment_time=%s, comments=''", $_GET['course_id'], $student->ID, date("Y-m-d", current_time('timestamp')), current_time('mysql'))); $success = __('User successfully enrolled in the course', 'namaste'); // insert in history $course = get_post($_GET['course_id']); $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HISTORY . " SET\n\t\t\t\t\t\t\t\tuser_id=%d, date=CURDATE(), datetime=NOW(), action='enrolled_course', value=%s, num_value=%d", $student->ID, sprintf(__('Enrolled in course %s. Status: %s', 'namaste'), $course->post_title, 'enrolled'), $_GET['course_id'])); // do_action('namaste_enrolled_course', $student->ID, $_GET['course_id'], true); } } // change student status if (!empty($_GET['change_status'])) { if ($multiuser_access == 'view') { wp_die(__('You are not allowed to do this.', 'namaste')); } $wpdb->query($wpdb->prepare("UPDATE " . NAMASTE_STUDENT_COURSES . " SET\n\t\t\t\t\t \t\t\tstatus=%s, completion_date=%s, completion_time=%s \n\t\t\t\t\t \t\t\tWHERE user_id=%d AND course_id=%d", $_GET['status'], date("Y-m-d", current_time('timestamp')), current_time('mysql'), $_GET['student_id'], $_GET['course_id'])); $course = get_post($_GET['course_id']); if ($_GET['status'] == 'enrolled') { do_action('namaste_enrollment_approved', $_GET['student_id'], $_GET['course_id']); $history_msg = sprintf(__('Enrollment in %s has been approved.', 'namaste'), $course->post_title); } else { do_action('namaste_enrollment_rejected', $_GET['student_id'], $_GET['course_id']); $history_msg = sprintf(__('Enrollment in %s has been rejected.', 'namaste'), $course->post_title); } // insert in history $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HISTORY . " SET\n\t\t\t\t\t\t\t\tuser_id=%d, date=CURDATE(), datetime=NOW(), action='enrolled_course', value=%s, num_value=%d", $_GET['student_id'], $history_msg, $_GET['course_id'])); namaste_redirect("admin.php?page=namaste_students&course_id={$_GET['course_id']}"); } // select lessons $_lesson = new NamasteLMSLessonModel(); $lessons = $_lesson->select($_GET['course_id']); $lids = array(0); foreach ($lessons as $lesson) { $lids[] = $lesson->ID; } // select students $page_limit = 20; $offset = empty($_GET['offset']) ? 0 : intval($_GET['offset']); $status_sql = ''; if (!empty($_GET['status']) and $_GET['status'] != 'any') { $status_sql = $wpdb->prepare(" AND tS.status=%s", $_GET['status']); } $students = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS tU.*, tS.status as namaste_status \n\t\t\t \t\tFROM {$wpdb->users} tU JOIN " . NAMASTE_STUDENT_COURSES . " tS \n\t\t\t \t\tON tS.user_id = tU.ID AND tS.course_id=%d {$status_sql}\n\t\t\t \t\tORDER BY user_nicename LIMIT %d, %d", $_GET['course_id'], $offset, $page_limit)); $count = $wpdb->get_var("SELECT FOUND_ROWS()"); // select student - to - lesson relations $completed_lessons = $wpdb->get_results("SELECT * FROM " . NAMASTE_STUDENT_LESSONS . "\n\t\t \t\t\tWHERE lesson_id IN (" . implode(',', $lids) . ")"); // match to students foreach ($students as $cnt => $student) { $student_completed_lessons = $student_incomplete_lessons = array(); foreach ($completed_lessons as $lesson) { if ($lesson->student_id == $student->ID) { if ($lesson->status) { $student_completed_lessons[] = $lesson->lesson_id; } else { $student_incomplete_lessons[] = $lesson->lesson_id; } } } $students[$cnt]->completed_lessons = $student_completed_lessons; $students[$cnt]->incomplete_lessons = $student_incomplete_lessons; } } // end if course selected wp_enqueue_script('thickbox', null, array('jquery')); wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0'); if (@file_exists(get_stylesheet_directory() . '/namaste/manage-students.php')) { require get_stylesheet_directory() . '/namaste/manage-students.php'; } else { require NAMASTE_PATH . "/views/manage-students.php"; } }
static function enroll($atts) { global $wpdb, $user_ID, $user_email, $post; if (!is_user_logged_in()) { return sprintf(__('You need to be <a href="%s">logged in</a> to enroll in this course', 'namaste'), wp_login_url(get_permalink($post->ID))); } // passed course id? if (!empty($atts['course_id'])) { $post = get_post($atts['course_id']); } $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(); } else { $stripe = ''; } if (!empty($_POST['stripe_pay'])) { NamasteStripe::pay($currency); namaste_redirect(get_permalink($post->ID)); } if (!empty($_POST['enroll'])) { // in case we use several shortcodes on the page make sure only the right course action is executed if (empty($atts['course_id']) or $atts['course_id'] == $_POST['course_id']) { $mesage = NamasteLMSCoursesController::enroll($is_manager); namaste_redirect(get_permalink($post->ID)); } } $_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); return $_course->enroll_buttons($post, $is_manager); } 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; } } }
static function manage() { global $wpdb, $user_ID; $_course = new NamasteLMSCourseModel(); $_lesson = new NamasteLMSLessonModel(); $multiuser_access = 'all'; $multiuser_access = NamasteLMSMultiUser::check_access('homework_access'); // select courses $courses = $_course->select(); $courses = apply_filters('namaste-homeworks-select-courses', $courses); // if course and lesson are selected, populate two variables for displaying titles etc if (!empty($_GET['course_id'])) { $this_course = $_course->select($_GET['course_id']); } if (!empty($_GET['lesson_id'])) { $this_lesson = $_lesson->select($_GET['course_id'], 'single', $_GET['lesson_id']); } switch (@$_GET['do']) { case 'add': // apply permissions from other plugins do_action('namaste-check-permissions', 'course', $_GET['course_id']); if (!empty($_POST['ok'])) { $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HOMEWORKS . " SET\n\t\t\t\t\t\tcourse_id=%d, lesson_id=%d, title=%s, description=%s, accept_files=%d, \n\t\t\t\t\t\taward_points=%d, editor_id=%d", $_GET['course_id'], $_GET['lesson_id'], $_POST['title'], $_POST['description'], @$_POST['accept_files'], @$_POST['award_points'], $user_ID)); $id = $wpdb->insert_id; do_action('namaste_add_homework', $id); //$_SESSION['namaste_flash'] = __('Homework added', 'namaste'); namaste_redirect("admin.php?page=namaste_homeworks&course_id={$_GET['course_id']}&lesson_id={$_GET['lesson_id']}"); } if (@file_exists(get_stylesheet_directory() . '/namaste/homework.php')) { require get_stylesheet_directory() . '/namaste/homework.php'; } else { require NAMASTE_PATH . "/views/homework.php"; } break; case 'edit': // apply permissions from other plugins do_action('namaste-check-permissions', 'homework', $_GET['id']); if ($multiuser_access == 'own') { $homework = self::select($wpdb->prepare(' WHERE id=%d ', $_GET['id'])); $homework = $homework[0]; if ($homework->editor_id != $user_ID) { wp_die(__('You are not allowed to edit or delete this assignment', 'namaste')); } } if (!empty($_POST['del'])) { self::delete($_GET['id']); //$_SESSION['namaste_flash'] = __('Homework deleted', 'namaste'); namaste_redirect("admin.php?page=namaste_homeworks&course_id={$_GET['course_id']}&lesson_id={$_GET['lesson_id']}"); } if (!empty($_POST['ok'])) { $wpdb->query($wpdb->prepare("UPDATE " . NAMASTE_HOMEWORKS . " SET\n\t\t\t\t\t\tcourse_id=%d, lesson_id=%d, title=%s, description=%s, accept_files=%d, award_points=%d\n\t\t\t\t\t\tWHERE id=%d", $_GET['course_id'], $_GET['lesson_id'], $_POST['title'], $_POST['description'], @$_POST['accept_files'], @$_POST['award_points'], $_GET['id'])); do_action('namaste_save_homework', $_GET['id']); //$_SESSION['namaste_flash'] = __('Homework saved', 'namaste'); namaste_redirect("admin.php?page=namaste_homeworks&course_id={$_GET['course_id']}&lesson_id={$_GET['lesson_id']}"); } // select homework $homework = self::select($wpdb->prepare(' WHERE id=%d ', $_GET['id'])); $homework = $homework[0]; if (@file_exists(get_stylesheet_directory() . '/namaste/homework.php')) { require get_stylesheet_directory() . '/namaste/homework.php'; } else { require NAMASTE_PATH . "/views/homework.php"; } break; default: // if course is selected, find lessons if (!empty($_GET['course_id'])) { $lessons = $_lesson->select($_GET['course_id']); } // list existing homeworks if course and lesson are selected if (!empty($_GET['course_id']) and !empty($_GET['lesson_id'])) { // apply permissions from other plugins - this allows other plugins to die here if user can't access the course do_action('namaste-check-permissions', 'course', $_GET['course_id']); $own_sql = ''; if ($multiuser_access == 'own') { $own_sql = $wpdb->prepare(" AND tH.editor_id=%d ", $user_ID); } $homeworks = $wpdb->get_results($wpdb->prepare("SELECT tH.*, COUNT(tS.id) as solutions \n\t\t\t\t\t\tFROM " . NAMASTE_HOMEWORKS . " tH LEFT JOIN " . NAMASTE_STUDENT_HOMEWORKS . " tS ON tS.homework_id = tH.id\n\t\t\t\t\t\tWHERE tH.course_id=%d AND tH.lesson_id=%d\t{$own_sql} \n\t\t\t\t\t\tGROUP BY tH.id ORDER BY tH.title", $_GET['course_id'], $_GET['lesson_id'])); } if (@file_exists(get_stylesheet_directory() . '/namaste/homeworks.php')) { require get_stylesheet_directory() . '/namaste/homeworks.php'; } else { require NAMASTE_PATH . "/views/homeworks.php"; } break; } }
static function manage() { global $wpdb, $user_ID; $multiuser_access = 'all'; $multiuser_access = NamasteLMSMultiUser::check_access('certificates_access'); $_cert = new NamasteLMSCertificateModel(); // select courses $_course = new NamasteLMSCourseModel(); $courses = $_course->select(); switch (@$_GET['action']) { case 'add': if (!empty($_POST['ok'])) { $cid = $_cert->add($_POST); do_action('namaste-certificate-saved', $cid); namaste_redirect("admin.php?page=namaste_certificates&msg=added"); } if (@file_exists(get_stylesheet_directory() . '/namaste/certificate-form.php')) { require get_stylesheet_directory() . '/namaste/certificate-form.php'; } else { require NAMASTE_PATH . "/views/certificate-form.php"; } break; case 'edit': if ($multiuser_access == 'own') { $certificate = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_CERTIFICATES . " WHERE id=%d", $_GET['id'])); if ($certificate->editor_id != $user_ID) { wp_die(__('You are not allowed to do this.', 'namaste')); } } if (!empty($_POST['del'])) { $wpdb->query($wpdb->prepare("DELETE FROM " . NAMASTE_CERTIFICATES . " WHERE id=%d", $_GET['id'])); namaste_redirect("admin.php?page=namaste_certificates&msg=deleted"); } if (!empty($_POST['ok'])) { $_cert->edit($_POST, $_GET['id']); do_action('namaste-certificate-saved', $_GET['id']); namaste_redirect("admin.php?page=namaste_certificates&msg=edited"); } $certificate = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_CERTIFICATES . " WHERE id=%d", $_GET['id'])); if (@file_exists(get_stylesheet_directory() . '/namaste/certificate-form.php')) { require get_stylesheet_directory() . '/namaste/certificate-form.php'; } else { require NAMASTE_PATH . "/views/certificate-form.php"; } break; default: $own_sql = ''; if ($multiuser_access == 'own') { $own_sql = $wpdb->prepare("WHERE editor_id=%d", $user_ID); } $certificates = $wpdb->get_results("SELECT * FROM " . NAMASTE_CERTIFICATES . " {$own_sql} ORDER BY title"); if (!empty($_GET['msg'])) { switch ($_GET['msg']) { case 'added': $msg = __('Certificate added', 'namaste'); break; case 'edited': $msg = __('Certificate saved', 'namaste'); break; case 'deleted': $msg = __('Certificate deleted', 'namaste'); break; } } // using PDF bridge? if (!empty($_POST['save_pdf_settings'])) { update_option('namaste_generate_pdf_certificates', @$_POST['generate_pdf_certificates']); } if (@file_exists(get_stylesheet_directory() . '/namaste/certificates.php')) { require get_stylesheet_directory() . '/namaste/certificates.php'; } else { require NAMASTE_PATH . "/views/certificates.php"; } break; } }
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; } } }