예제 #1
1
 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
 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
 static function submit_solution($in_shortcode = false)
 {
     global $wpdb, $user_ID, $post;
     $_course = new NamasteLMSCourseModel();
     list($homework, $course, $lesson) = NamasteLMSHomeworkModel::full_select($_GET['id']);
     // am I enrolled?
     if (!NamasteLMSStudentModel::is_enrolled($user_ID, $course->ID)) {
         wp_die(__('You are not enrolled in this course!', 'namaste'));
     }
     // unsatisfied lesson completion requirements?
     $not_completed_ids = NamasteLMSLessonModel::unsatisfied_complete_requirements($lesson);
     if (!empty($not_completed_ids)) {
         $content = '<p>' . __('Before submitting solutions on this lesson you must complete the following lessons:', 'namaste') . '</p>';
         $content .= '<ul>';
         foreach ($not_completed_ids as $id) {
             $not_completed = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE id=%d", $id));
             $content .= '<li><a href="' . get_permalink($id) . '">' . $not_completed->post_title . '</a></li>';
         }
         $content .= '</ul>';
         echo $content;
         // self :: mark_accessed();
         return true;
     }
     // now submit
     if (!empty($_POST['ok'])) {
         if (empty($_POST['content'])) {
             wp_die(__('You cannot submit an empty solution', 'namaste'));
         }
         // avoid duplicates
         $exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . NAMASTE_STUDENT_HOMEWORKS . "\n\t\t\t\tWHERE student_id=%d AND homework_id=%d AND content=%s", $user_ID, $homework->id, $_POST['content']));
         if (!$exists) {
             $file = $file_blob = '';
             if ($homework->accept_files and !empty($_FILES['file']['tmp_name'])) {
                 $file_blob = file_get_contents($_FILES['file']['tmp_name']);
                 $file = $_FILES['file']['name'];
             }
             $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_STUDENT_HOMEWORKS . " SET\n\t\t\t\t\thomework_id=%d, student_id=%d, status='pending', date_submitted=CURDATE(), \n\t\t\t\t\tcontent=%s, file=%s, fileblob=%s", $homework->id, $user_ID, $_POST['content'], $file, $file_blob));
         }
         do_action('namaste_submitted_solution', $user_ID, $homework->id);
         // insert in history
         $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HISTORY . " SET\n\t\t\t\tuser_id=%d, date=CURDATE(), datetime=NOW(), action='submitted_solution', value=%s, num_value=%d", $user_ID, sprintf(__('Submitted solution to assignment "%s"', 'namaste'), $homework->title), $homework->id));
         if (@file_exists(get_stylesheet_directory() . '/namaste/solution-submitted.php')) {
             require get_stylesheet_directory() . '/namaste/solution-submitted.php';
         } else {
             require NAMASTE_PATH . "/views/solution-submitted.php";
         }
     } else {
         if (@file_exists(get_stylesheet_directory() . '/namaste/submit-solution.php')) {
             require get_stylesheet_directory() . '/namaste/submit-solution.php';
         } else {
             require NAMASTE_PATH . "/views/submit-solution.php";
         }
     }
 }
예제 #4
0
 static function student_lessons($simplified = false, $ob = null, $dir = null, $in_shortcode = false)
 {
     global $wpdb, $user_ID;
     // student_id
     $student_id = (empty($_GET['student_id']) or !current_user_can('namaste_manage')) ? $user_ID : $_GET['student_id'];
     // select this student
     $student = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID=%d", $student_id));
     // select this course
     $course = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE id=%d", $_GET['course_id']));
     // am I enrolled?
     if (!current_user_can('namaste_manage') and !$in_shortcode) {
         $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')", $student_id, $course->ID));
         if (!$enrolled) {
             _e("You must enroll in the course first before you can see the lessons", 'namaste');
             return false;
         }
     }
     // end enrolled check
     // change student-lesson status?
     if (!empty($_POST['change_status'])) {
         $multiuser_access = 'all';
         $multiuser_access = NamasteLMSMultiUser::check_access('students_access');
         if ($multiuser_access == 'view') {
             wp_die(__('You are not allowed to do this.', 'namaste'));
         }
         $result = NamasteLMSStudentModel::lesson_status($student->ID, $_POST['lesson_id'], $_POST['status']);
         if (!$result) {
             $error = __('The lesson cannot be completed because there are unsatisfied requirements', 'namaste');
         }
     }
     // select lessons
     $_lesson = new NamasteLMSLessonModel();
     $select_ob = empty($ob) ? 'post_title' : $ob;
     $lessons = $_lesson->select($course->ID, 'array', null, $ob, $dir);
     $ids = array(0);
     foreach ($lessons as $lesson) {
         $ids[] = $lesson->ID;
     }
     $id_sql = implode(",", $ids);
     // select homeworks and match to lessons
     $homeworks = NamasteLMSHomeworkModel::select("WHERE lesson_id IN ({$id_sql})");
     // using exams? select them too
     $use_exams = get_option('namaste_use_exams');
     $exams_table = $use_exams == 'watu' ? $wpdb->prefix . 'watu_master' : $wpdb->prefix . 'watupro_master';
     $shortcode = $use_exams == 'watu' ? 'WATU' : 'WATUPRO';
     // select student-lesson relation so we can match status
     $student_lessons = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_LESSONS . "\r\n\t\t\tWHERE student_id = %d", $student_id));
     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 ($use_exams) {
             $required_exam = get_post_meta($lesson->ID, 'namaste_required_exam', true);
             if ($required_exam) {
                 $exam = $wpdb->get_row("SELECT tE.*, tP.id as post_id FROM {$exams_table} tE, {$wpdb->posts} tP\r\n\t\t\t\t\t\tWHERE tE.ID = {$required_exam} AND tP.post_content LIKE CONCAT('%[{$shortcode} ', tE.ID, ']%')\r\n\t\t\t\t\t\tAND tP.post_status='publish' AND post_title!=''");
                 $lessons[$cnt]->exam = $exam;
             }
         }
         // status
         $status = null;
         foreach ($student_lessons as $l) {
             if ($l->lesson_id == $lesson->ID) {
                 $status = $l;
             }
         }
         if (empty($status->id)) {
             $lessons[$cnt]->status = __('Not started', 'namaste');
             $lessons[$cnt]->statuscode = -1;
         } else {
             if ($status->status == 1) {
                 $lessons[$cnt]->status = __('Completed on', 'namaste') . ' ' . date(get_option('date_format'), strtotime($status->completion_date));
                 $lessons[$cnt]->statuscode = 1;
             } else {
                 // in progress
                 $lessons[$cnt]->status = "<a href='#' onclick='namasteInProgress(" . $lesson->ID . ", " . $student_id . ");return false;'>" . __('In progress', 'namaste') . "</a>";
                 $lessons[$cnt]->statuscode = 0;
             }
         }
         // end defining status
     }
     // external reorder?
     if (empty($ob)) {
         $lessons = apply_filters('namaste-reorder-lessons', $lessons);
     }
     // enqueue thickbox
     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/student-lessons.php')) {
         require get_stylesheet_directory() . '/namaste/student-lessons.php';
     } else {
         require NAMASTE_PATH . "/views/student-lessons.php";
     }
 }
예제 #5
0
 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;
 }
예제 #6
0
function academy_courses($atts)
{
    $atts = shortcode_atts(array('page' => '0'), $atts);
    $return = '';
    $numberposts = 20;
    $posts = get_posts(array('numberposts' => $numberposts, 'offset' => $atts['page'] * 1, 'post_type' => 'namaste_course', 'post_status' => 'publish'));
    foreach ($posts as $key => $post) {
        if ($key == $numberposts - 1) {
            break;
        }
        $aCourseData = getCourseDataForHomePage($post);
        if (!$aCourseData["registration_closed"]) {
            if (NamasteLMSStudentModel::is_enrolled(get_current_user_id(), $post->ID) == null) {
                $enrollBtnHTML = '<span class="btnCourse">Войти</span>';
            } else {
                $enrollBtnHTML = '<span class="btnCourse">' . __('Enroll', 'qode') . '</span>';
                $perc = get_course_progress($my_course->ID, $enrolled_one->ID);
            }
            $return .= '
			<div class="academy_course ' . $aCourseData["live_sticker"] . '" style="background: url(' . $aCourseData["image"] . '); background-size: 265px 230px;  background-repeat: no-repeat;">
				<a href="' . get_permalink($post->ID) . '">
					<span class="academy_course_text">
							<span class="academy_course_title">' . $aCourseData["title"] . '</span>
							<span class="academy_course_subtitle">
								' . $aCourseData["subtitle"] . $enrollBtnHTML . '								
							</span>
					</span>
				</a>
				<div class="courseColorBG" style= "background-color: #' . $aCourseData["category_color"] . '"></div>
			</div>';
        }
    }
    wp_reset_postdata();
    $load_more = '';
    return $return . $load_more;
}
 <?php 
                        _e('days', 'qode');
                        ?>
</div>
										<?php 
                    }
                    ?>
										<?php 
                }
                ?>
 
										
									
										
										<?php 
                if (!NamasteLMSStudentModel::is_enrolled(get_current_user_id(), $post->ID) == null) {
                    // IF USER ENROLLED IN COURSE
                    ?>
											<!-- <div class="course_single_enrolled_status  course_single_details"><?php 
                    echo do_shortcode('[namaste-enroll]');
                    ?>
</div> -->
											<?php 
                    $var = do_shortcode('[namaste-todo]');
                    if ($var && $var != "<ul></ul>") {
                        echo '<div class="course_single_course_title">' . __("Program", 'qode') . '</div><div class="course_single_programm_list  course_single_details">' . $var . '</div>';
                    }
                    ?>
										<?php 
                } else {
                    ?>