コード例 #1
1
ファイル: courses.php プロジェクト: Bnei-Baruch/Namaste
 static function enroll($is_manager)
 {
     global $wpdb, $user_ID, $user_email;
     $_course = new NamasteLMSCourseModel();
     $message = '';
     // enroll in course
     $course = $_course->select($_POST['course_id']);
     // course fee?
     $fee = get_post_meta($course->ID, 'namaste_fee', true);
     // When fee is paid, enrollment is automatic so this is just fine here
     if (!empty($fee)) {
         $fee = apply_filters('namaste-coupon-applied', $fee);
     }
     // coupon code from other plugin?
     if ($fee > 0 and !$is_manager) {
         wp_die("You can't enroll yourself in a course when there is a fee");
     }
     $enroll_mode = get_post_meta($course->ID, 'namaste_enroll_mode', true);
     // if already enrolled, just skip this altogether
     if (!NamasteLMSStudentModel::is_enrolled($user_ID, $course->ID)) {
         // depending on mode, status will be either 'pending' or 'enrolled'
         $status = $enroll_mode == 'free' ? 'enrolled' : 'pending';
         $_course->enroll($user_ID, $course->ID, $status);
         if ($enroll_mode == 'free') {
             $message = sprintf(__('You enrolled in "%s"', 'namaste'), $course->post_title);
         } else {
             $message = __('Thank you for your interest in enrolling this course. A manager will review your application.', 'namaste');
         }
     } else {
         $message = __('You have already enrolled in this course', 'namaste');
     }
     return $message;
 }
コード例 #2
0
ファイル: stripe-model.php プロジェクト: Bnei-Baruch/Namaste
 static function pay($currency)
 {
     global $wpdb, $user_ID, $user_email;
     $_course = new NamasteLMSCourseModel();
     $token = $_POST['stripeToken'];
     $course = get_post($_POST['course_id']);
     $fee = get_post_meta($course->ID, 'namaste_fee', true);
     $fee = apply_filters('namaste-coupon-applied', $fee);
     // coupon code from other plugin?
     try {
         $customer = Stripe_Customer::create(array('email' => $user_email, 'card' => $token));
         $charge = Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $fee * 100, 'currency' => $currency));
     } catch (Exception $e) {
         wp_die($e->getMessage());
     }
     // !!!!in the next version avoid this copy-paste
     // almost the same code is in models/payment.php for the paypal payments
     $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_PAYMENTS . " SET \n\t\t\t\t\t\tcourse_id=%d, user_id=%s, date=CURDATE(), amount=%s, status='completed', paycode=%s, paytype='stripe'", $_POST['course_id'], $user_ID, $fee, $token));
     do_action('namaste-paid', $user_ID, $fee, "course", $_POST['course_id']);
     // enroll accordingly to course settings - this will be placed in a method once we
     // have more payment options
     $enroll_mode = get_post_meta($course->ID, 'namaste_enroll_mode', true);
     if (!NamasteLMSStudentModel::is_enrolled($user_ID, $course->ID)) {
         $status = $enroll_mode == 'free' ? 'enrolled' : 'pending';
         $_course->enroll($user_ID, $course->ID, $status);
     }
 }
コード例 #3
0
 function complete_course($course_id, $student_id)
 {
     global $wpdb;
     $_course = new NamasteLMSCourseModel();
     $certificates = $wpdb->get_results("SELECT * FROM " . NAMASTE_CERTIFICATES . " \n\t\t\tWHERE course_ids LIKE '%|{$course_id}|%' ");
     foreach ($certificates as $certificate) {
         // see if the other courses are completed
         $courses_completed = true;
         $course_ids = explode("|", $certificate->course_ids);
         foreach ($course_ids as $cid) {
             if (empty($cid) or $cid == $course_id) {
                 continue;
             }
             if (!$_course->is_ready($cid, $student_id)) {
                 $courses_completed = false;
             }
         }
         // assign this certificate
         if ($courses_completed) {
             $wpdb->query($wpdb->prepare("INSERT IGNORE INTO " . NAMASTE_STUDENT_CERTIFICATES . " SET\n\t\t\t\t\tstudent_id=%d, certificate_id=%d, date=%s", $student_id, $certificate->id, date("Y-m-d")));
             do_action('namaste_achieved_certificate', $student_id, $certificate->id);
         }
     }
     // end foreach certificate
 }
 private static function enroll($userId, $courseId)
 {
     $_course = new NamasteLMSCourseModel();
     // enroll in course
     $course = $_course->select($courseId);
     $enroll_mode = get_post_meta($course->ID, 'namaste_enroll_mode', true);
     // if already enrolled, just skip this altogether
     $_course->enroll($userId, $course->ID, 'enrolled');
 }
コード例 #5
0
ファイル: gradebook.php プロジェクト: Bnei-Baruch/Namaste
 static function my_gradebook()
 {
     global $wpdb, $user_ID;
     $_course = new NamasteLMSCourseModel();
     $_lesson = new NamasteLMSLessonModel();
     // select my courses
     $courses = $wpdb->get_results($wpdb->prepare("SELECT tC.* FROM {$wpdb->posts} tC\n\t\tJOIN " . NAMASTE_STUDENT_COURSES . " tSC ON tSC.course_id = tC.ID AND (tSC.status = 'enrolled' OR tSC.status = 'completed')\n\t\tAND tSC.user_id=%d\r\n\t\tWHERE post_type = 'namaste_course'  AND (post_status='publish' OR post_status='draft')\r\n\t\tORDER BY post_title", $user_ID));
     $cids = array();
     foreach ($courses as $course) {
         $cids[] = $course->ID;
     }
     // make sure we are only passing course_id in which user is enrolled
     if (!empty($_GET['course_id']) and in_array($_GET['course_id'], $cids)) {
         $this_course = $_course->select($_GET['course_id']);
         $lessons = $wpdb->get_results($wpdb->prepare("SELECT tP.*, tSL.grade as grade FROM {$wpdb->posts} tP\r\n\t\t\tJOIN {$wpdb->postmeta} tM ON tM.post_id = tP.ID AND tM.meta_key = 'namaste_course'\r\n\t\t\tAND tM.meta_value = %d\n\t\t\tLEFT JOIN " . NAMASTE_STUDENT_LESSONS . " tSL ON tSL.student_id=%d AND tSL.lesson_id=tP.ID\r\n\t\t\tWHERE post_type = 'namaste_lesson'  AND (post_status='publish' OR post_status='draft') \r\n\t\t\tORDER BY post_title", $_GET['course_id'], $user_ID));
         // select all assignments
         $homeworks = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . " WHERE course_id=%d ORDER BY id", $this_course->ID));
         $hids = array(0);
         foreach ($homeworks as $homework) {
             $hids[] = $homework->id;
         }
         // select all my solutions
         $solutions = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_HOMEWORKS . " \n\t\t\t\tWHERE student_id=%d AND homework_id IN (" . implode(',', $hids) . ") ORDER BY id DESC", $user_ID));
         // match solutions to assignments
         foreach ($homeworks as $cnt => $homework) {
             $homework_solutions = array();
             foreach ($solutions as $solution) {
                 if ($homework->id == $solution->homework_id) {
                     $homework_solutions[] = $solution;
                 }
             }
             $homeworks[$cnt]->solutions = $solutions;
         }
         // match assignments to my lessons
         foreach ($lessons as $cnt => $lesson) {
             $lesson_homeworks = array();
             foreach ($homeworks as $homework) {
                 if ($homework->lesson_id == $lesson->ID) {
                     $lesson_homeworks[] = $homework;
                 }
             }
             $lessons[$cnt]->homeworks = $lesson_homeworks;
         }
     }
     if (@file_exists(get_stylesheet_directory() . '/namaste/my-gradebook.htm.php')) {
         require get_stylesheet_directory() . '/namaste/my-gradebook.html.php';
     } else {
         require NAMASTE_PATH . "/views/my-gradebook.html.php";
     }
 }
コード例 #6
0
ファイル: student-model.php プロジェクト: Bnei-Baruch/Namaste
 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";
     }
 }
コード例 #7
0
ファイル: lesson-model.php プロジェクト: Bnei-Baruch/Namaste
 static function restrict_visible_comments($comments)
 {
     global $post, $wpdb, $user_ID;
     if (!is_singular() or is_admin() or $post->post_type != 'namaste_lesson' or current_user_can('namaste_manage')) {
         return $comments;
     }
     if (!is_user_logged_in()) {
         return null;
     }
     // logged in, but is he enrolled in the course?
     $_course = new NamasteLMSCourseModel();
     $course_id = get_post_meta($post->ID, 'namaste_course', true);
     $course = $_course->select($course_id);
     $enrolled = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . NAMASTE_STUDENT_COURSES . " WHERE user_id = %d AND course_id = %d AND (status = 'enrolled' OR status='completed')", $user_ID, $course_id));
     if (!$enrolled) {
         return null;
     }
     return $comments;
 }
コード例 #8
0
ファイル: shortcodes.php プロジェクト: Bnei-Baruch/Namaste
 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;
         }
     }
 }
コード例 #9
0
 static function full_select($id)
 {
     global $wpdb;
     $_course = new NamasteLMSCourseModel();
     $_lesson = new NamasteLMSLessonModel();
     // select this homework and lesson
     $homework = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . "\n\t\t\tWHERE id=%d", $id));
     // select course
     $course = $_course->select($homework->course_id);
     // select lesson
     $lesson = $_lesson->select($course->ID, 'single', $homework->lesson_id);
     return array($homework, $course, $lesson);
 }
コード例 #10
0
ファイル: namaste-model.php プロジェクト: Bnei-Baruch/Namaste
 static function install($update = false)
 {
     global $wpdb;
     $wpdb->show_errors();
     $old_version = get_option('namaste_version');
     update_option('namaste_version', "1.34");
     if (!$update) {
         self::init();
     }
     // enrollments to courses
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_COURSES . "'") != NAMASTE_STUDENT_COURSES) {
         $sql = "CREATE TABLE `" . NAMASTE_STUDENT_COURSES . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`status` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t\t`enrollment_date` DATE NOT NULL DEFAULT '2000-01-01',\t\t\t\n\t\t\t\t\t`completion_date` DATE NOT NULL DEFAULT '2000-01-01',\n\t\t\t\t\t`comments` TEXT NOT NULL\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // assignments - let's not use custom post type for this
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_HOMEWORKS . "'") != NAMASTE_HOMEWORKS) {
         $sql = "CREATE TABLE `" . NAMASTE_HOMEWORKS . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`lesson_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`title` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t\t`description` TEXT NOT NULL,\n\t\t\t\t\t`accept_files` TINYINT NOT NULL DEFAULT 0 /* zip only */\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // student - assignments relation
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_HOMEWORKS . "'") != NAMASTE_STUDENT_HOMEWORKS) {
         $sql = "CREATE TABLE `" . NAMASTE_STUDENT_HOMEWORKS . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`homework_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`status` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t\t`date_submitted` DATE NOT NULL DEFAULT '2000-01-01',\n\t\t\t\t\t`content` TEXT NOT NULL,\n\t\t\t\t\t`file` VARCHAR(255) NOT NULL DEFAULT ''\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // assignment notes (usually used as feedback from the teacher to the student. Student can't reply)
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_HOMEWORK_NOTES . "'") != NAMASTE_HOMEWORK_NOTES) {
         $sql = "CREATE TABLE `" . NAMASTE_HOMEWORK_NOTES . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`homework_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`teacher_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`note` TEXT NOT NULL,\n\t\t\t\t\t`datetime` DATETIME NOT NULL DEFAULT '2000-01-01'\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // student to lessons relation - only save record if student has completed a lesson
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_LESSONS . "'") != NAMASTE_STUDENT_LESSONS) {
         $sql = "CREATE TABLE `" . NAMASTE_STUDENT_LESSONS . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`lesson_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`status` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`completion_date` TEXT NOT NULL\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_CERTIFICATES . "'") != NAMASTE_CERTIFICATES) {
         $sql = "CREATE TABLE `" . NAMASTE_CERTIFICATES . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t  `course_ids` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t  `title` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t  `content` TEXT NOT NULL\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_CERTIFICATES . "'") != NAMASTE_STUDENT_CERTIFICATES) {
         $sql = "CREATE TABLE `" . NAMASTE_STUDENT_CERTIFICATES . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t  `certificate_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `date` DATE NOT NULL DEFAULT '2000-01-01'\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // payment records
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_PAYMENTS . "'") != NAMASTE_PAYMENTS) {
         $sql = "CREATE TABLE `" . NAMASTE_PAYMENTS . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t  `course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `date` DATE NOT NULL DEFAULT '2001-01-01',\n\t\t\t\t  `amount` DECIMAL(8,2),\n\t\t\t\t  `status` VARCHAR(100) NOT NULL DEFAULT 'failed',\n\t\t\t\t  `paycode` VARCHAR(100) NOT NULL DEFAULT '',\n\t\t\t\t  `paytype` VARCHAR(100) NOT NULL DEFAULT 'paypal'\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // tracks the visits on a give course or lesson
     // 1 record per user/date
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_VISITS . "'") != NAMASTE_VISITS) {
         $sql = "CREATE TABLE `" . NAMASTE_VISITS . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t  `course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `lesson_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `date` DATE NOT NULL DEFAULT '2001-01-01',\n\t\t\t\t  `visits` INT UNSIGNED NOT NULL DEFAULT 0\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // history of various actions, for example points awarded and spent
     if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_HISTORY . "'") != NAMASTE_HISTORY) {
         $sql = "CREATE TABLE `" . NAMASTE_HISTORY . "` (\n\t\t\t\t  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t  `user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  `date` DATE NOT NULL DEFAULT '2001-01-01',\n\t\t\t\t  `datetime` DATETIME,\n\t\t\t\t  `action` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t  `value` VARCHAR(255) NOT NULL DEFAULT '', /* some textual value if required */\n\t\t\t\t  `num_value` INT UNSIGNED NOT NULL DEFAULT 0 /* some numeric value, for example points */\n\t\t\t\t) DEFAULT CHARSET=utf8;";
         $wpdb->query($sql);
     }
     // add extra fields in new versions
     namaste_add_db_fields(array(array("name" => "grade", "type" => "VARCHAR(100) NOT NULL DEFAULT ''"), array("name" => "fileblob", "type" => "LONGBLOB")), NAMASTE_STUDENT_HOMEWORKS);
     namaste_add_db_fields(array(array("name" => "grade", "type" => "VARCHAR(100) NOT NULL DEFAULT ''"), array("name" => "enrollment_time", "type" => "DATETIME"), array("name" => "completion_time", "type" => "DATETIME")), NAMASTE_STUDENT_COURSES);
     namaste_add_db_fields(array(array("name" => "grade", "type" => "VARCHAR(100) NOT NULL DEFAULT ''"), array("name" => "start_time", "type" => "DATETIME"), array("name" => "completion_time", "type" => "DATETIME")), NAMASTE_STUDENT_LESSONS);
     namaste_add_db_fields(array(array("name" => "award_points", "type" => "INT UNSIGNED NOT NULL DEFAULT 0"), array("name" => "editor_id", "type" => "INT UNSIGNED NOT NULL DEFAULT 0")), NAMASTE_HOMEWORKS);
     namaste_add_db_fields(array(array("name" => "editor_id", "type" => "INT UNSIGNED NOT NULL DEFAULT 0")), NAMASTE_CERTIFICATES);
     namaste_add_db_fields(array(array("name" => "for_item_type", "type" => "VARCHAR(100) NOT NULL DEFAULT '' "), array("name" => "for_item_id", "type" => "INT UNSIGNED NOT NULL DEFAULT 0")), NAMASTE_HISTORY);
     // add student role if not exists
     $res = add_role('student', 'Student', array('read' => true, 'namaste' => true));
     if (!$res) {
         // role already exists, check the capability
         $role = get_role('student');
         if (!$role->has_cap('namaste')) {
             $role->add_cap('namaste');
         }
     }
     // add manage cap to the admin / superadmin by default
     $role = get_role('administrator');
     if (!$role->has_cap('namaste_manage')) {
         $role->add_cap('namaste_manage');
     }
     // update fileblob
     if ($old_version < 1.27) {
         $wpdb->query("ALTER TABLE " . NAMASTE_STUDENT_HOMEWORKS . " CHANGE fileblob fileblob LONGBLOB");
     }
     /* This was needed only for a while but now is generated "unexpected output" during activation
        if($old_version < 1.29) {
        	  // drop student-certificate uniqueness, no longer used    	
     	  $sql = "ALTER TABLE ".NAMASTE_STUDENT_CERTIFICATES." DROP INDEX certificate_id";
     	  $wpdb->query($sql);
        }*/
     // fush rewrite rules
     NamasteLMSCourseModel::register_course_type();
     NamasteLMSLessonModel::register_lesson_type();
     flush_rewrite_rules();
     // exit;
 }
コード例 #11
0
ファイル: payment.php プロジェクト: Bnei-Baruch/Namaste
 static function paypal_ipn($wp)
 {
     global $wpdb;
     echo "<!-- NAMASTECOMMENT paypal IPN -->";
     $paypal_email = get_option("namaste_paypal_id");
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     $paypal_host = 'www.paypal.com';
     $paypal_sandbox = get_option('namaste_paypal_sandbox');
     if ($paypal_sandbox == '1') {
         $paypal_host = 'www.sandbox.paypal.com';
     }
     // post back to PayPal system to validate
     $header = "";
     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Host: " . $paypal_host . "\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($paypal_host, 80, $errno, $errstr, 30);
     if ($fp) {
         fputs($fp, $header . $req);
         $pp_response = '';
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             $pp_response .= $res;
             if (strstr($res, "VERIFIED") or $paypal_sandbox == '1') {
                 // check the payment_status is Completed
                 // check that txn_id has not been previously processed
                 // check that receiver_email is your Primary PayPal email
                 // process payment
                 $payment_completed = false;
                 $txn_id_okay = false;
                 $receiver_okay = false;
                 $payment_currency_okay = false;
                 $payment_amount_okay = false;
                 if ($_POST['payment_status'] == "Completed") {
                     $payment_completed = true;
                 } else {
                     self::log_and_exit("Payment status: {$_POST['payment_status']}");
                 }
                 // check txn_id
                 $txn_exists = $wpdb->get_var($wpdb->prepare("SELECT paycode FROM " . NAMASTE_PAYMENTS . "\n\t\t\t\t\t   WHERE paytype='paypal' AND paycode=%s", $_POST['txn_id']));
                 if (empty($txn_id)) {
                     $txn_id_okay = true;
                 } else {
                     self::log_and_exit("TXN ID exists: {$txn_id}");
                 }
                 // check receiver email
                 if ($_POST['business'] == $paypal_email) {
                     $receiver_okay = true;
                 } else {
                     self::log_and_exit("Business email is wrong: {$_POST['business']}");
                 }
                 // check payment currency
                 if ($_POST['mc_currency'] == get_option("namaste_currency")) {
                     $payment_currency_okay = true;
                 } else {
                     self::log_and_exit("Currency is {$_POST['mc_currency']}");
                 }
                 // check amount
                 $fee = get_post_meta($_GET['course_id'], 'namaste_fee', true);
                 $fee = apply_filters('namaste-coupon-applied', $fee);
                 // coupon code from other plugin?
                 if ($_POST['mc_gross'] >= $fee) {
                     $payment_amount_okay = true;
                 } else {
                     self::log_and_exit("Wrong amount: {$_POST['mc_gross']} when price is {$fee}");
                 }
                 // everything OK, insert payment and enroll
                 if ($payment_completed and $txn_id_okay and $receiver_okay and $payment_currency_okay and $payment_amount_okay) {
                     $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_PAYMENTS . " SET \n\t\t\t\t\t\t\tcourse_id=%d, user_id=%s, date=CURDATE(), amount=%s, status='completed', paycode=%s, paytype='paypal'", $_GET['course_id'], $_GET['user_id'], $fee, $_POST['txn_id']));
                     do_action('namaste-paid', $_GET['user_id'], $fee, "course", $_GET['course_id']);
                     // enroll accordingly to course settings - this will be placed in a method once we
                     // have more payment options
                     $enroll_mode = get_post_meta($_GET['course_id'], 'namaste_enroll_mode', true);
                     if (!NamasteLMSStudentModel::is_enrolled($_GET['user_id'], $_GET['course_id'])) {
                         $_course = new NamasteLMSCourseModel();
                         $status = $enroll_mode == 'free' ? 'enrolled' : 'pending';
                         $_course->enroll($_GET['user_id'], $_GET['course_id'], $status);
                     }
                     exit;
                 }
             }
         }
         fclose($fp);
         self::log_and_exit("Paypal result is not VERIFIED: {$pp_response}");
     } else {
         self::log_and_exit("Can't connect to Paypal");
     }
     exit;
 }
コード例 #12
0
ファイル: certificates.php プロジェクト: Bnei-Baruch/Namaste
    static function view_certificate()
    {
        global $wpdb, $user_ID;
        if (!current_user_can('namaste_manage') and $_GET['student_id'] != $user_ID) {
            wp_die(__('You are not allowed to access this certificate', 'namaste'));
        }
        // select certificate
        $certificate = $wpdb->get_row($wpdb->prepare("SELECT tC.*, tS.date as date, tS.id as stid \n\t\t\tFROM " . NAMASTE_CERTIFICATES . " tC JOIN " . NAMASTE_STUDENT_CERTIFICATES . " tS On tC.id = tS.certificate_id \n\t\t\tWHERE tS.student_id = %d AND tC.id=%d\n\t\t\tAND tS.id=%d", $_GET['student_id'], $_GET['id'], $_GET['my_id']));
        $output = wpautop(stripslashes($certificate->content));
        $user_info = get_userdata($_GET['student_id']);
        $name = (empty($user_info->first_name) or empty($user_info->last_name)) ? $user_info->display_name : $user_info->first_name . " " . $user_info->last_name;
        // if $name is still empty, output username
        if (empty($name)) {
            $name = $user_info->user_login;
        }
        $output = str_replace("{{name}}", $name, $output);
        $output = str_replace("{{id}}", sprintf('%08d', $certificate->stid), $output);
        if (strstr($output, "{{courses}}") or strstr($output, "{{courses-extended}}")) {
            $_course = new NamasteLMSCourseModel();
            $courses = $_course->select();
            $c_courses = array();
            foreach ($courses as $course) {
                if (strstr($certificate->course_ids, "|" . $course->ID . "|")) {
                    if (strstr($output, "{{courses-extended}}")) {
                        $c_courses[] = "<h2>" . stripslashes($course->post_title) . "</h2>" . wpautop(stripslashes($course->post_excerpt));
                    } else {
                        $c_courses[] = stripslashes($course->post_title);
                    }
                }
            }
            $courses_str = implode(", ", $c_courses);
            $output = str_replace("{{courses}}", $courses_str, $output);
            $output = str_replace("{{courses-extended}}", $courses_str, $output);
        }
        $date = date(get_option('date_format'), strtotime($certificate->date));
        $output = str_replace("{{date}}", $date, $output);
        if (get_option('namaste_generate_pdf_certificates') == "1") {
            $output = '<html>
			<head><title>' . $certificate->title . '</title>
			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
			<body><!--namaste-certificate-id-' . $certificate->id . '-namaste-certificate-id-->' . $output . '</body>
			</html>';
            //	die($output);
            $content = apply_filters('pdf-bridge-convert', $output);
            echo $content;
            exit;
        }
        // else output HTML
        ?>
		<html>
		<head><title><?php 
        echo $certificate->title;
        ?>
</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
		<body><?php 
        echo apply_filters('the_content', $output);
        ?>
</body>
		</html>
		<?php 
        exit;
    }
コード例 #13
0
ファイル: functions.php プロジェクト: Bnei-Baruch/kabacademy
function namaste_next_lesson_custom($atts)
{
    extract(shortcode_atts(array('class' => 'course-navigation-item', 'text' => 'Lesson'), $atts, 'nnlc'));
    // selects the next lesson in the course if any
    if (!is_user_logged_in()) {
        return "";
    }
    global $post, $user_ID;
    $_course = new NamasteLMSCourseModel();
    $course_id = get_post_meta($post->ID, 'namaste_course', true);
    if (empty($course_id) && $post->post_type == 'namaste_course') {
        $course_id = $post->ID;
    } elseif (empty($course_id)) {
        return "";
    }
    $required_lessons = $_course->required_lessons($course_id, $user_ID);
    $next_lesson = '';
    if (!empty($required_lessons)) {
        foreach ($required_lessons as $lesson) {
            $next_lesson = $lesson->ID;
            if (!$lesson->namaste_completed) {
                break;
            }
        }
    }
    if (empty($required_lessons)) {
        return "<a class='" . $class . "' href='" . add_query_arg(array('tab' => 'nolessons'), get_permalink($course_id)) . "'>" . $text . " " . __("(Starts soon!)", 'qode') . "</a>";
    }
    return "<a class='" . $class . "' href='" . get_permalink($next_lesson) . "'>" . $text . "</a>";
}
コード例 #14
0
*/
?>

	<?php 
get_header();
?>
	
	<div class="full_width">
	<div class="full_width_inner">



		<?php 
global $user_ID;
$is_manager = current_user_can('namaste_manage');
$_course = new NamasteLMSCourseModel();
// select all courses
$_course->register_course_type();
$courses = $_course->select();
?>
		<h1><?php 
_e('My Courses', 'namaste');
?>
</h1>

		<?php 
if (!sizeof($courses)) {
    ?>
			<p><?php 
    _e('No courses are available at this time.', 'namaste');
    ?>