Exemplo n.º 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;
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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";
         }
     }
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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 {
                    ?>