Example #1
0
/**
 * Get the course meta.
 *
 * @param int $course_id
 * @param array $include
 * @return string
 */
function educator_course_meta($course_id = null, $include = null)
{
    if (!$course_id) {
        $course_id = get_the_ID();
    }
    if (!$include) {
        $include = array('lecturer', 'num_lessons', 'difficulty');
    }
    $include = apply_filters('edutheme_course_meta_include', $include);
    $meta = apply_filters('pre_educator_course_meta', '', $course_id, $include);
    if (!empty($meta)) {
        return $meta;
    }
    foreach ($include as $item) {
        switch ($item) {
            // Lecturer.
            case 'lecturer':
                $meta .= '<span class="author lecturer">' . sprintf(__('by %s', 'ib-educator'), get_the_author()) . '</span>';
                break;
                // Number of lessons.
            // Number of lessons.
            case 'num_lessons':
                $num_lessons = IB_Educator::get_instance()->get_num_lessons($course_id);
                if ($num_lessons) {
                    $meta .= '<span class="num-lessons">' . sprintf(_n('1 lesson', '%d lessons', $num_lessons, 'ib-educator'), $num_lessons) . '</span>';
                }
                break;
                // Difficulty.
            // Difficulty.
            case 'difficulty':
                $difficulty = ib_edu_get_difficulty($course_id);
                if ($difficulty) {
                    $meta .= '<span class="difficulty">' . esc_html($difficulty['label']) . '</span>';
                }
                break;
                // Categories.
            // Categories.
            case 'categories':
                $categories = get_the_term_list(get_the_ID(), 'ib_educator_category', '', __(', ', 'ib-educator'));
                if ($categories) {
                    echo '<span class="cat-links">' . $categories . '</span>';
                }
                break;
        }
    }
    return apply_filters('edutheme_course_meta', $meta);
}
 /**
  * Setup initial test data.
  * e.g., courses, payments, entries.
  * Current user: $this->admin_id
  * Lessons:
  *  - $this->lessons[0] => lecturer: $this->users['lecturer1'], course: $this->courses[0].
  *  - $this->lessons[2] => lecturer: $this->users['lecturer1'], course: $this->courses[2].
  *  - $this->lessons[3] => lecturer: $this->admin_id, course: $this->courses[3].
  * Entries:
  *  - $this->entries['current'] => student: $this->admin_id, course: $this->courses[2], status: inprogress.
  */
 public function basicSetUp()
 {
     $this->api = IB_Educator::get_instance();
     // Add users.
     // lecturer1:
     $this->users['lecturer1'] = wp_insert_user(array('user_login' => 'lecturer1', 'user_pass' => '123456', 'role' => 'lecturer'));
     // student1:
     $this->users['student1'] = wp_insert_user(array('user_login' => 'student1', 'user_pass' => '123456', 'role' => 'student'));
     // Set current user:
     global $current_user;
     $current_user = new WP_User(1);
     $current_user->set_role('administrator');
     $this->admin_id = $current_user->ID;
     // Add categories.
     $this->categories[] = $this->addCategory('Category 1');
     $this->categories[] = $this->addCategory('Category 2');
     $this->categories[] = $this->addCategory('Category 3');
     // Add courses.
     $this->courses[] = $this->addCourse('test-course-1', 'test course 1', $this->users['lecturer1'], 199.99);
     $this->courses[] = $this->addCourse('test-course-2', 'test course 2', $this->users['lecturer1'], 287.83);
     $this->courses[] = $this->addCourse('test-course-3', 'test course 3', $this->users['lecturer1'], 329.83);
     $this->courses[] = $this->addCourse('test-course-4', 'test course 4', $this->admin_id, 329.83);
     // Add lessons.
     // Lesson for course 1:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[0], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-1-lesson-1', 'title' => 'course 1 lesson 1'));
     // Lesson for course 2:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[1], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-2-lesson-1', 'title' => 'course 2 lesson 1'));
     // Lesson for course 3:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[2], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-3-lesson-1', 'title' => 'course 3 lesson 1'));
     // Lesson for course 4:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[3], 'author_id' => $this->admin_id, 'slug' => 'course-4-lesson-1', 'title' => 'course 4 lesson 1'));
     // Add payments.
     // Payment from student1 for course 1 (complete):
     $this->payments['complete'] = $this->addPayment(array('payment_type' => 'course', 'payment_status' => 'complete', 'course_id' => $this->courses[0], 'user_id' => $this->users['student1']));
     // Payment from student1 for course 2 (pending):
     $this->payments['pending'] = $this->addPayment(array('payment_type' => 'course', 'payment_status' => 'pending', 'course_id' => $this->courses[1], 'user_id' => $this->users['student1']));
     // Payment from current user for course 3 (complete):
     $this->payments['current'] = $this->addPayment(array('payment_type' => 'course', 'payment_status' => 'complete', 'course_id' => $this->courses[2], 'user_id' => $this->admin_id));
     // Add entries.
     // Entry for student1 for course 1:
     $this->entries['inprogress'] = $this->addEntry(array('payment_id' => $this->payments['complete'], 'course_id' => $this->courses[0], 'entry_status' => 'inprogress'));
     // Entry for current user for course 3:
     $this->entries['current'] = $this->addEntry(array('payment_id' => $this->payments['current'], 'course_id' => $this->courses[2], 'entry_status' => 'inprogress'));
 }
         *
         * @param null|WP_Error $errors
         * @param mixed $post
         */
        do_action('ib_educator_register_form', $errors, $post);
        ?>

			<fieldset>
				<legend><?php 
        esc_html_e('Payment Information', 'training');
        ?>
</legend>

				<?php 
        $args = array();
        $billing = IB_Educator::get_instance()->get_billing_data($user_id);
        // Get country.
        if (isset($_POST['billing_country'])) {
            $args['country'] = $_POST['billing_country'];
        } elseif (!empty($billing['country'])) {
            $args['country'] = $billing['country'];
        } else {
            $args['country'] = ib_edu_get_location('country');
        }
        // Get state.
        if (isset($_POST['billing_state'])) {
            $args['state'] = $_POST['billing_state'];
        } elseif (!empty($billing['state'])) {
            $args['state'] = $billing['state'];
        } else {
            $args['state'] = ib_edu_get_location('state');
Example #4
0
 /**
  * Edit payment action.
  */
 public static function edit_payment()
 {
     $payment_id = isset($_GET['payment_id']) ? absint($_GET['payment_id']) : 0;
     $payment = edr_get_payment($payment_id);
     $errors = array();
     if (count($_POST)) {
         // Verify nonce.
         check_admin_referer('ib_educator_edit_payment_' . $payment_id);
         // Capability check.
         if (!current_user_can('manage_educator')) {
             return;
         }
         // Payment type.
         if (isset($_POST['payment_type']) && array_key_exists($_POST['payment_type'], edr_get_payment_types())) {
             $payment->payment_type = $_POST['payment_type'];
         }
         // Student ID.
         if (empty($payment->user_id)) {
             if (!empty($_POST['student_id']) && is_numeric($_POST['student_id'])) {
                 $payment->user_id = $_POST['student_id'];
             } else {
                 $errors[] = 'empty_student_id';
             }
         }
         // Course ID.
         if (empty($payment->course_id)) {
             if (!empty($_POST['course_id']) && is_numeric($_POST['course_id'])) {
                 $payment->course_id = $_POST['course_id'];
             } elseif ('course' == $payment->payment_type) {
                 $errors[] = 'empty_course_id';
             }
         }
         // Object ID.
         if (isset($_POST['object_id']) && is_numeric($_POST['object_id'])) {
             $payment->object_id = $_POST['object_id'];
         }
         // Tax.
         if (isset($_POST['tax']) && is_numeric($_POST['tax'])) {
             $payment->tax = $_POST['tax'];
         }
         // Amount.
         if (isset($_POST['amount']) && is_numeric($_POST['amount'])) {
             $payment->amount = $_POST['amount'];
         }
         if (isset($_POST['currency'])) {
             $payment->currency = sanitize_text_field($_POST['currency']);
         }
         // Transaction ID.
         if (isset($_POST['txn_id'])) {
             $payment->txn_id = sanitize_text_field($_POST['txn_id']);
         }
         // Payment status.
         if (isset($_POST['payment_status']) && array_key_exists($_POST['payment_status'], edr_get_payment_statuses())) {
             $payment->payment_status = $_POST['payment_status'];
         }
         // Payment gateway.
         if (isset($_POST['payment_gateway'])) {
             $payment->payment_gateway = sanitize_title($_POST['payment_gateway']);
         }
         // First Name.
         if (isset($_POST['first_name'])) {
             $payment->first_name = sanitize_text_field($_POST['first_name']);
         }
         // Last Name.
         if (isset($_POST['last_name'])) {
             $payment->last_name = sanitize_text_field($_POST['last_name']);
         }
         // Address.
         if (isset($_POST['address'])) {
             $payment->address = sanitize_text_field($_POST['address']);
         }
         // Address Line 2.
         if (isset($_POST['address_2'])) {
             $payment->address_2 = sanitize_text_field($_POST['address_2']);
         }
         // City.
         if (isset($_POST['city'])) {
             $payment->city = sanitize_text_field($_POST['city']);
         }
         // Postcode.
         if (isset($_POST['postcode'])) {
             $payment->postcode = sanitize_text_field($_POST['postcode']);
         }
         // State / Province.
         if (isset($_POST['state'])) {
             $payment->state = sanitize_text_field($_POST['state']);
         }
         // Country.
         if (isset($_POST['country'])) {
             $payment->country = sanitize_text_field($_POST['country']);
         }
         if (!empty($errors)) {
             ib_edu_message('edit_payment_errors', $errors);
             return;
         }
         if ($payment->save()) {
             // Update payment meta.
             if (isset($_POST['line_id']) && is_array($_POST['line_id'])) {
                 foreach ($_POST['line_id'] as $key => $line_id) {
                     if (!is_numeric($line_id)) {
                         continue;
                     }
                     $payment->update_line(array('ID' => $line_id, 'object_id' => isset($_POST['line_object_id'][$key]) ? intval($_POST['line_object_id'][$key]) : 0, 'line_type' => isset($_POST['line_type'][$key]) ? sanitize_text_field($_POST['line_type'][$key]) : '', 'amount' => isset($_POST['line_amount'][$key]) ? sanitize_text_field($_POST['line_amount'][$key]) : 0.0, 'tax' => isset($_POST['line_tax'][$key]) ? sanitize_text_field($_POST['line_tax'][$key]) : 0.0, 'name' => isset($_POST['line_name'][$key]) ? sanitize_text_field($_POST['line_name'][$key]) : ''));
                 }
             }
             $api = IB_Educator::get_instance();
             $entry_saved = true;
             // Create entry for the student.
             // Implemented for the "course" payment type.
             if (isset($_POST['create_entry']) && !$api->get_entry(array('payment_id' => $payment->ID))) {
                 $entry = edr_get_entry();
                 $entry->course_id = $payment->course_id;
                 $entry->user_id = $payment->user_id;
                 $entry->payment_id = $payment->ID;
                 $entry->entry_status = 'inprogress';
                 $entry->entry_date = date('Y-m-d H:i:s');
                 $entry_saved = $entry->save();
                 if ($entry_saved) {
                     // Send notification email to the student.
                     $student = get_user_by('id', $payment->user_id);
                     $course = get_post($payment->course_id, OBJECT, 'display');
                     if ($student && $course) {
                         ib_edu_send_notification($student->user_email, 'student_registered', array('course_title' => $course->post_title), array('student_name' => $student->display_name, 'course_title' => $course->post_title, 'course_excerpt' => $course->post_excerpt));
                     }
                 }
             }
             // Setup membership for the student.
             if (isset($_POST['setup_membership']) && 'membership' == $payment->payment_type) {
                 $ms = Edr_Memberships::get_instance();
                 // Setup membership.
                 $ms->setup_membership($payment->user_id, $payment->object_id);
                 // Send notification email.
                 $student = get_user_by('id', $payment->user_id);
                 $membership = $ms->get_membership($payment->object_id);
                 if ($student && $membership) {
                     $user_membership = $ms->get_user_membership($student->ID);
                     $membership_meta = $ms->get_membership_meta($membership->ID);
                     $expiration = $user_membership ? $user_membership['expiration'] : 0;
                     ib_edu_send_notification($student->user_email, 'membership_register', array(), array('student_name' => $student->display_name, 'membership' => $membership->post_title, 'expiration' => $expiration ? date_i18n(get_option('date_format'), $expiration) : __('None', 'ibeducator'), 'price' => $ms->format_price($membership_meta['price'], $membership_meta['duration'], $membership_meta['period'], false)));
                 }
             }
             if ($entry_saved) {
                 wp_redirect(admin_url('admin.php?page=ib_educator_payments&edu-action=edit-payment&payment_id=' . $payment->ID . '&edu-message=saved'));
                 exit;
             }
         }
     }
 }
Example #5
0
/**
 * Can the current user edit a given lesson?
 *
 * @param int $lesson_id
 * @return bool
 */
function ib_edu_user_can_edit_lesson($lesson_id)
{
    if (current_user_can('manage_educator')) {
        return true;
    }
    $course_id = ib_edu_get_course_id($lesson_id);
    if ($course_id) {
        $api = IB_Educator::get_instance();
        return in_array($course_id, $api->get_lecturer_courses(get_current_user_id()));
    }
    return false;
}
Example #6
0
 /**
  * Prepare items.
  * Fetch and setup entries(items).
  */
 public function prepare_items()
 {
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
     $entries = null;
     $api = IB_Educator::get_instance();
     $statuses = IB_Educator_Entry::get_statuses();
     $args = array('per_page' => $this->get_items_per_page('entries_per_page', 10), 'page' => $this->get_pagenum());
     /**
      * Search by status.
      */
     if (!empty($_GET['status']) && array_key_exists($_GET['status'], $statuses)) {
         $args['entry_status'] = $_GET['status'];
     }
     // Search by ID.
     if (!empty($_GET['id'])) {
         $args['entry_id'] = $_GET['id'];
     }
     // Search by course id.
     if (!empty($_GET['course_id'])) {
         $args['course_id'] = $_GET['course_id'];
     }
     if (!empty($_GET['student'])) {
         $user = get_user_by('slug', $_GET['student']);
         if ($user) {
             $args['user_id'] = $user->ID;
         }
     }
     // Check capabilities.
     if (current_user_can('manage_educator')) {
         // Get all entries.
         $entries = $api->get_entries($args, 'ARRAY_A');
     } elseif (current_user_can('educator_edit_entries')) {
         // Get the entries for the current lecturer's courses only.
         $course_ids = $api->get_lecturer_courses(get_current_user_id());
         if (!empty($course_ids)) {
             if (empty($args['course_id']) || !in_array($args['course_id'], $course_ids)) {
                 $args['course_id'] = $course_ids;
             }
             $entries = $api->get_entries($args, 'ARRAY_A');
         }
     }
     if (!empty($entries)) {
         $this->set_pagination_args(array('total_items' => $entries['num_items'], 'per_page' => $args['per_page']));
         $this->items = $entries['rows'];
     }
 }
 /**
  * AJAX: add grade for a quiz.
  */
 public static function quiz_grade()
 {
     global $wpdb;
     $api = IB_Educator::get_instance();
     $entry_id = isset($_POST['entry_id']) ? absint($_POST['entry_id']) : 0;
     $lesson_id = isset($_POST['lesson_id']) ? absint($_POST['lesson_id']) : 0;
     // Verify nonce.
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ibedu_edit_progress_' . $entry_id)) {
         exit;
     }
     // Verify capabilities.
     if (!current_user_can('edit_ib_educator_lesson', $lesson_id)) {
         exit;
     }
     $quiz_grade = $api->get_quiz_grade($lesson_id, $entry_id);
     if (!$quiz_grade) {
         exit;
     }
     $grade = isset($_POST['grade']) ? floatval($_POST['grade']) : 0;
     $api->update_quiz_grade($quiz_grade->ID, array('grade' => $grade, 'status' => 'approved'));
     // Send notification email to the student.
     $entry = IB_Educator_Entry::get_instance($entry_id);
     $student = get_user_by('id', $entry->user_id);
     if ($student) {
         $lesson_title = get_the_title($lesson_id);
         ib_edu_send_notification($student->user_email, 'quiz_grade', array('lesson_title' => $lesson_title), array('student_name' => $student->display_name, 'lesson_title' => $lesson_title, 'grade' => ib_edu_format_grade($grade)));
     }
     echo json_encode(array('status' => 'success'));
     exit;
 }
Example #8
0
 /**
  * Charge the card using Stripe.
  * It's an AJAX action.
  */
 public function process_stripe_token()
 {
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ib_educator_stripe_token')) {
         exit('0');
     }
     if (!isset($_POST['token']) || !isset($_POST['payment_id'])) {
         exit('0');
     }
     $user = wp_get_current_user();
     if (0 == $user->ID) {
         exit('0');
     }
     $payment = edr_get_payment($_POST['payment_id']);
     if (!$payment->ID || $user->ID != $payment->user_id) {
         // The payment must exist and it must be associated with the current user.
         exit('0');
     }
     require_once IBEDUCATOR_PLUGIN_DIR . 'lib/Stripe/Stripe.php';
     $token = $_POST['token'];
     $amount = round((double) $payment->amount, 2);
     $description = sprintf(__('Payment #%d', 'ibeducator'), $payment->ID);
     if ('course' == $payment->payment_type) {
         $description .= ' , ' . get_the_title($payment->course_id);
     } elseif ('membership' == $payment->payment_type) {
         $description .= ' , ' . get_the_title($payment->object_id);
     }
     try {
         Stripe::setApiKey($this->get_option('secret_key'));
         Stripe_Charge::create(array('amount' => $amount * 100, 'currency' => $payment->currency, 'card' => $token, 'description' => $description));
         // Update the payment status.
         $payment->payment_status = 'complete';
         $payment->save();
         // Setup course or membership for the student.
         IB_Educator::get_instance()->setup_payment_item($payment);
         exit('1');
     } catch (Exception $e) {
     }
     exit('0');
 }
 /**
  * AJAX: autocomplete.
  */
 public static function ajax_autocomplete()
 {
     global $wpdb;
     if (!isset($_GET['entity'])) {
         exit;
     }
     $entity = $_GET['entity'];
     /**
      * Fires before the default autocomplete request is being processed.
      * Can be used to override autocomplete requests.
      *
      * @param string $entity
      */
     do_action('edr_autocomplete_ajax', $entity);
     if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'ib_educator_autocomplete')) {
         exit;
     }
     $response = array();
     switch ($entity) {
         case 'user':
         case 'student':
             if (!current_user_can('manage_educator')) {
                 exit;
             }
             $user_args = array();
             if (!empty($_GET['input'])) {
                 $user_args['search'] = '*' . $_GET['input'] . '*';
             }
             $user_args['number'] = 15;
             if ('student' == $entity) {
                 $user_args['role'] = 'student';
             }
             $user_query = new WP_User_Query($user_args);
             if (!empty($user_query->results)) {
                 foreach ($user_query->results as $user) {
                     $response[] = array('id' => intval($user->ID), 'name' => esc_html($user->display_name . ' (' . $user->user_nicename . ')'));
                 }
             }
             break;
         case 'entries_student':
             $user_args = array('number' => 15);
             if (current_user_can('manage_educator')) {
             } elseif (current_user_can('educator_edit_entries')) {
                 $cur_user_id = get_current_user_id();
                 $course_ids = implode(',', IB_Educator::get_instance()->get_lecturer_courses($cur_user_id));
                 $tables = ib_edu_table_names();
                 $student_ids = $wpdb->get_col("SELECT DISTINCT user_id\n\t\t\t\t\t\tFROM {$tables['entries']}\n\t\t\t\t\t\tWHERE course_id IN ({$course_ids})");
                 if (!empty($student_ids)) {
                     $user_args['include'] = $student_ids;
                 } else {
                     exit;
                 }
             } else {
                 exit;
             }
             if (!empty($_GET['input'])) {
                 $user_args['search'] = '*' . $_GET['input'] . '*';
             }
             $user_query = new WP_User_Query($user_args);
             if (!empty($user_query->results)) {
                 foreach ($user_query->results as $user) {
                     $response[] = array('slug' => esc_html($user->user_nicename), 'name' => esc_html($user->display_name . ' (' . $user->user_nicename . ')'));
                 }
             }
             break;
         case 'post':
         case 'course':
             if (!current_user_can('manage_educator')) {
                 exit;
             }
             $post_args = array();
             if (!empty($_GET['input'])) {
                 $post_args['s'] = $_GET['input'];
             }
             if ('course' == $entity) {
                 $post_args['post_type'] = 'ib_educator_course';
             }
             $post_args['post_status'] = 'publish';
             $post_args['posts_per_page'] = 15;
             $posts_query = new WP_Query($post_args);
             if ($posts_query->have_posts()) {
                 while ($posts_query->have_posts()) {
                     $posts_query->the_post();
                     $response[] = array('id' => get_the_ID(), 'title' => get_the_title());
                 }
                 wp_reset_postdata();
             }
             break;
     }
     echo json_encode($response);
     exit;
 }
Example #10
0
 /**
  * Resume entry.
  */
 public static function resume_entry()
 {
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ib_educator_resume_entry')) {
         return;
     }
     // Get the current user id.
     $user_id = get_current_user_id();
     if (!$user_id) {
         return;
     }
     // Get entry id.
     if (!isset($_POST['entry_id'])) {
         return;
     }
     $entry_id = $_POST['entry_id'];
     // Get entry.
     $entry = IB_Educator_Entry::get_instance($entry_id);
     if (!$entry) {
         return;
     }
     $ms = IB_Educator_Memberships::get_instance();
     // Check if there is an "inprogress" entry for this course.
     $api = IB_Educator::get_instance();
     $inprogress_entry = $api->get_entry(array('entry_status' => 'inprogress', 'course_id' => $entry->course_id, 'user_id' => $user_id));
     // Make sure that this entry belongs to the current user.
     // Make sure that the current membership gives access to this entry's course.
     if ($inprogress_entry || $entry->user_id != $user_id || !$ms->membership_can_access($entry->course_id, $user_id)) {
         return;
     }
     $entry->entry_status = 'inprogress';
     $entry->save();
     wp_safe_redirect(get_permalink());
 }
Example #11
0
    /**
     * Display lessons of a given course.
     *
     * @param int $course_id
     */
    function edr_display_lessons($course_id)
    {
        $syllabus = get_post_meta($course_id, '_edr_syllabus', true);
        if (is_array($syllabus) && !empty($syllabus)) {
            $lesson_ids = array();
            $lessons = array();
            foreach ($syllabus as $group) {
                if (!empty($group['lessons'])) {
                    $lesson_ids = array_merge($lesson_ids, $group['lessons']);
                }
            }
            if (!empty($lesson_ids)) {
                $tmp = get_posts(array('post_type' => 'ib_educator_lesson', 'post__in' => $lesson_ids, 'post_status' => 'publish', 'posts_per_page' => count($lesson_ids)));
                foreach ($tmp as $lesson) {
                    $lessons[$lesson->ID] = $lesson;
                }
                unset($tmp);
            }
            Edr_View::the_template('course/syllabus', array('syllabus' => $syllabus, 'lessons' => $lessons));
        } else {
            $query = IB_Educator::get_instance()->get_lessons($course_id);
            if ($query && $query->have_posts()) {
                ?>
			<section class="ib-edu-lessons">
				<h2><?php 
                _e('Lessons', 'ibeducator');
                ?>
</h2>
				<?php 
                while ($query->have_posts()) {
                    $query->the_post();
                    Edr_View::template_part('content', 'lesson');
                }
                wp_reset_postdata();
                ?>
			</section>
		<?php 
            }
        }
    }
Example #12
0
 /**
  * Get related courses.
  *
  * @param int $post_id
  * @return string
  */
 function educator_related_courses($post_id)
 {
     $terms = get_the_terms($post_id, 'ib_educator_category');
     if (!$terms || is_wp_error($terms)) {
         return;
     }
     $args = array('post_type' => 'ib_educator_course', 'posts_per_page' => 3, 'post__not_in' => array($post_id));
     $terms_ids = array();
     foreach ($terms as $term) {
         $terms_ids[] = $term->term_id;
     }
     $args['tax_query'] = array(array('taxonomy' => 'ib_educator_category', 'terms' => $terms_ids));
     $query = new WP_Query($args);
     if ($query->have_posts()) {
         $output = '<section class="related-courses">';
         $output .= '<h1>' . __('Related Courses', 'ib-educator') . '</h1>';
         $api = IB_Educator::get_instance();
         $course_id = 0;
         while ($query->have_posts()) {
             $query->the_post();
             $course_id = get_the_ID();
             $output .= '<article class="' . esc_attr(implode(' ', get_post_class('clearfix'))) . '">';
             if (has_post_thumbnail()) {
                 $output .= '<div class="post-thumb"><a href="' . esc_url(get_permalink()) . '">' . get_the_post_thumbnail($course_id, 'thumbnail') . '</a></div>';
             }
             $output .= '<div class="post-summary">' . '<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '">' . the_title('', '', false) . '</a></h2>';
             ob_start();
             the_excerpt();
             $output .= '<div class="post-excerpt">' . ob_get_clean() . '</div>';
             $output .= '<div class="post-meta">';
             if ('closed' != ib_edu_registration($course_id)) {
                 $output .= '<span class="price">' . ib_edu_format_course_price(ib_edu_get_course_price($course_id)) . '</span>';
             }
             $output .= educator_course_meta($course_id, array('num_lessons', 'difficulty'));
             $output .= '</div>';
             $output .= '</div>';
             $output .= '</article>';
         }
         wp_reset_postdata();
         $output .= '</section>';
         return $output;
     }
     return '';
 }
Example #13
0
 public static function get_instance()
 {
     _ib_edu_deprecated_function('IBEdu_API::get_instance()', '0.9.0', 'IB_Educator::get_instance()');
     return IB_Educator::get_instance();
 }
Example #14
0
 public function process_ipn()
 {
     $debug = 0;
     $log_file = IBEDUCATOR_PLUGIN_DIR . 'ipn.log';
     // Read POST data
     // reading posted data directly from $_POST causes serialization
     // issues with array data in POST. Reading raw POST data from input stream instead.
     $raw_post_data = file_get_contents('php://input');
     $raw_post_array = explode('&', $raw_post_data);
     $myPost = array();
     foreach ($raw_post_array as $keyval) {
         $keyval = explode('=', $keyval);
         if (2 == count($keyval)) {
             $myPost[$keyval[0]] = urldecode($keyval[1]);
         }
     }
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     if (function_exists('get_magic_quotes_gpc')) {
         $get_magic_quotes_exists = true;
     } else {
         $get_magic_quotes_exists = false;
     }
     foreach ($myPost as $key => $value) {
         if (true == $get_magic_quotes_exists && 1 == get_magic_quotes_gpc()) {
             $value = urlencode(stripslashes($value));
         } else {
             $value = urlencode($value);
         }
         $req .= "&{$key}={$value}";
     }
     // Post IPN data back to PayPal to validate the IPN data is genuine.
     // Without this step anyone can fake IPN data.
     if ($this->get_option('test')) {
         $paypal_url = $this->test_url;
     } else {
         $paypal_url = $this->live_url;
     }
     $ch = curl_init($paypal_url);
     if (!$ch) {
         return;
     }
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
     if ($debug) {
         curl_setopt($ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
     }
     // Set TCP timeout to 30 seconds.
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
     $res = curl_exec($ch);
     if (0 != curl_errno($ch)) {
         if (true == $debug) {
             error_log(date('[Y-m-d H:i e] ') . 'Can\'t connect to PayPal to validate IPN message: ' . curl_error($ch) . PHP_EOL, 3, $log_file);
         }
         curl_close($ch);
         exit;
     } else {
         // Log the entire HTTP response if debug is switched on.
         if ($debug) {
             error_log(date('[Y-m-d H:i e] ') . 'HTTP request of validation request:' . curl_getinfo($ch, CURLINFO_HEADER_OUT) . ' for IPN payload: ' . $req . PHP_EOL, 3, $log_file);
             error_log(date('[Y-m-d H:i e] ') . 'HTTP response of validation request: ' . $res . PHP_EOL, 3, $log_file);
         }
         curl_close($ch);
     }
     // Inspect IPN validation result and act accordingly.
     if (false !== strpos($res, 'VERIFIED')) {
         if (isset($_POST['payment_status'])) {
             $payment_id = !isset($_POST['item_number']) ? 0 : absint($_POST['item_number']);
             $currency = !isset($_POST['mc_currency']) ? '' : $_POST['mc_currency'];
             $receiver_email = !isset($_POST['receiver_email']) ? '' : $_POST['receiver_email'];
             $payment_amount = !isset($_POST['mc_gross']) ? '' : $_POST['mc_gross'];
             if ($receiver_email != $this->get_option('business_email')) {
                 return;
             }
             if (0 == $payment_id) {
                 return;
             }
             $payment = edr_get_payment($payment_id);
             if (!$payment->ID) {
                 return;
             }
             if ($payment_amount != $payment->amount) {
                 return;
             }
             if ($currency != $payment->currency) {
                 return;
             }
             switch ($_POST['payment_status']) {
                 case 'Completed':
                     // Update payment status.
                     $payment->payment_status = 'complete';
                     if (isset($_POST['txn_id'])) {
                         $payment->txn_id = sanitize_text_field($_POST['txn_id']);
                     }
                     $payment->save();
                     // Setup course or membership for the student.
                     IB_Educator::get_instance()->setup_payment_item($payment);
                     break;
                 case 'Failed':
                 case 'Expired':
                 case 'Denied':
                 case 'Voided':
                     // Update payment status.
                     $payment->payment_status = 'failed';
                     $payment->save();
                     break;
             }
         }
         if ($debug) {
             error_log(date('[Y-m-d H:i e] ') . 'Verified IPN: ' . $req . PHP_EOL, 3, $log_file);
         }
     } else {
         if (0 == strcmp($res, 'INVALID')) {
             if ($debug) {
                 error_log(date('[Y-m-d H:i e] ') . 'Invalid IPN: ' . $req . PHP_EOL, 3, $log_file);
             }
         }
     }
 }
$classes[] = 'course-item';
$categories = '';
$separator = ', ';
$title = get_the_title();
$link = get_the_permalink();
$terms = get_the_terms(get_the_id(), 'ib_educator_category');
$options = get_post_meta(get_the_id(), 'wpo_postconfig', true);
$post_id = get_the_id();
$excerpt = training_wpo_excerpt(22, '...');
if (!empty($terms) && !is_wp_error($terms)) {
    foreach ($terms as $term) {
        $categories .= $term->name . $separator;
    }
}
$categories = trim($categories, $separator);
$educator = IB_Educator::get_instance();
$lesson = $educator->get_num_lessons(get_the_id());
?>
<article id="course-<?php 
the_ID();
?>
" class="<?php 
echo esc_attr(implode(' ', $classes));
?>
"> 
	<?php 
if (has_post_thumbnail()) {
    ?>
	<div class="course-image">
		<a href="<?php 
    echo esc_url($link);
Example #16
0
/**
 * SHORTCODE: output the course prerequisites.
 */
function ib_edu_course_prerequisites($atts, $content = null)
{
    $template = IB_Educator_View::locate_template(array('shortcode-course-prerequisites.php'));
    if (!$template) {
        return;
    }
    $api = IB_Educator::get_instance();
    $prerequisites = $api->get_prerequisites(get_the_ID());
    $courses = null;
    if (!empty($prerequisites)) {
        $courses = get_posts(array('post_type' => 'ib_educator_course', 'post_status' => 'publish', 'include' => $prerequisites));
    } else {
        $courses = array();
    }
    ob_start();
    include $template;
    return ob_get_clean();
}
Example #17
0
 /**
  * Output default user register form.
  *
  * @param WP_Error $errors
  * @param WP_Post $object
  */
 public static function register_form($errors, $object)
 {
     // Get current user.
     $user = wp_get_current_user();
     $error_codes = is_wp_error($errors) ? $errors->get_error_codes() : array();
     // Determine fields that can have multiple errors.
     $has_error = self::parse_register_errors($error_codes);
     // Setup form.
     require_once IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-form.php';
     $form = new IB_Educator_Form();
     $form->default_decorators();
     if (!$user->ID) {
         // Add account details group.
         $form->add_group(array('name' => 'account', 'label' => __('Create an Account', 'ibeducator')));
         // Set values.
         $form->set_value('account_username', isset($_POST['account_username']) ? $_POST['account_username'] : '');
         $form->set_value('account_email', isset($_POST['account_email']) ? $_POST['account_email'] : '');
         // Username.
         $form->add(array('type' => 'text', 'name' => 'account_username', 'container_id' => 'account-username-field', 'label' => __('Username', 'ibeducator'), 'id' => 'account-username', 'class' => isset($has_error['account_username']) ? 'error' : '', 'required' => true), 'account');
         // Email.
         $form->add(array('type' => 'text', 'name' => 'account_email', 'container_id' => 'account-email-field', 'label' => __('Email', 'ibeducator'), 'id' => 'account-email', 'class' => isset($has_error['account_email']) ? 'error' : '', 'required' => true), 'account');
     }
     if (ib_edu_collect_billing_data($object)) {
         // Add billing details group.
         $form->add_group(array('name' => 'billing', 'label' => __('Billing Details', 'ibeducator')));
         // Set values.
         $values = IB_Educator::get_instance()->get_billing_data($user->ID);
         if (empty($values['country'])) {
             $values['country'] = ib_edu_get_location('country');
         }
         if (empty($values['state'])) {
             $values['state'] = ib_edu_get_location('state');
         }
         $values['first_name'] = $user->ID ? $user->first_name : '';
         $values['last_name'] = $user->ID ? $user->last_name : '';
         foreach ($values as $key => $value) {
             $post_key = 'billing_' . $key;
             if (isset($_POST[$post_key])) {
                 $form->set_value($post_key, $_POST[$post_key]);
             } else {
                 $form->set_value($post_key, $value);
             }
         }
         // First Name.
         $form->add(array('type' => 'text', 'name' => 'billing_first_name', 'container_id' => 'billing-first-name-field', 'label' => __('First Name', 'ibeducator'), 'id' => 'billing-first-name', 'class' => in_array('billing_first_name_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Last Name.
         $form->add(array('type' => 'text', 'name' => 'billing_last_name', 'container_id' => 'billing-last-name-field', 'label' => __('Last Name', 'ibeducator'), 'id' => 'billing-last-name', 'class' => in_array('billing_last_name_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Address.
         $form->add(array('type' => 'text', 'name' => 'billing_address', 'container_id' => 'billing-address-field', 'label' => __('Address', 'ibeducator'), 'id' => 'billing-address', 'class' => in_array('billing_address_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Address Line 2.
         $form->add(array('type' => 'text', 'name' => 'billing_address_2', 'container_id' => 'billing-address-2-field', 'label' => __('Address Line 2', 'ibeducator'), 'id' => 'billing-address-2'), 'billing');
         // City.
         $form->add(array('type' => 'text', 'name' => 'billing_city', 'container_id' => 'billing-city-field', 'label' => __('City', 'ibeducator'), 'id' => 'billing-city', 'class' => in_array('billing_city_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         $edu_countries = IB_Educator_Countries::get_instance();
         // State.
         $state_field = array('name' => 'billing_state', 'container_id' => 'billing-state-field', 'label' => __('State / Province', 'ibeducator'), 'id' => 'billing-state', 'class' => in_array('billing_state_empty', $error_codes) ? 'error' : '', 'required' => true);
         $country = $form->get_value('billing_country');
         $states = $country ? $edu_countries->get_states($country) : null;
         if ($states) {
             $state_field['type'] = 'select';
             $state_field['options'] = array_merge(array('' => '&nbsp;'), $states);
             unset($states);
         } else {
             $state_field['type'] = 'text';
         }
         $form->add($state_field, 'billing');
         // Postcode.
         $form->add(array('type' => 'text', 'name' => 'billing_postcode', 'container_id' => 'billing-postcode-field', 'label' => __('Postcode / Zip', 'ibeducator'), 'id' => 'billing-postcode', 'class' => in_array('billing_postcode_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Country.
         $form->add(array('type' => 'select', 'name' => 'billing_country', 'container_id' => 'billing-country-field', 'label' => __('Country', 'ibeducator'), 'id' => 'billing-country', 'class' => in_array('billing_country_empty', $error_codes) ? 'error' : '', 'required' => true, 'options' => array_merge(array('' => '&nbsp;'), $edu_countries->get_countries())), 'billing');
     }
     $form->display();
 }
Example #18
0
<?php

// Setup form object.
require_once IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-form.php';
$form = new IB_Educator_Form();
$form->default_decorators();
// Registration.
$form->set_value('_ib_educator_register', get_post_meta($post->ID, '_ib_educator_register', true));
$form->add(array('type' => 'select', 'name' => '_ib_educator_register', 'label' => __('Registration', 'ibeducator'), 'options' => array('open' => __('Open', 'ibeducator'), 'closed' => __('Closed', 'ibeducator')), 'default' => 'open'));
// Price.
$form->set_value('_ibedu_price', ib_edu_get_course_price($post->ID));
$form->add(array('type' => 'text', 'name' => '_ibedu_price', 'class' => '', 'id' => 'ib-educator-price', 'label' => __('Price', 'ibeducator'), 'before' => esc_html(ib_edu_get_currency_symbol(ib_edu_get_currency())) . ' '));
// Tax Class.
$edu_tax = IB_Educator_Tax::get_instance();
$form->set_value('_ib_educator_tax_class', $edu_tax->get_tax_class_for($post->ID));
$form->add(array('type' => 'select', 'name' => '_ib_educator_tax_class', 'label' => __('Tax Class', 'ibeducator'), 'options' => $edu_tax->get_tax_classes(), 'default' => 'default'));
// Difficulty.
$form->set_value('_ib_educator_difficulty', get_post_meta($post->ID, '_ib_educator_difficulty', true));
$form->add(array('type' => 'select', 'name' => '_ib_educator_difficulty', 'id' => 'ib-educator-difficulty', 'label' => __('Difficulty', 'ibeducator'), 'options' => array_merge(array('' => __('None', 'ibeducator')), ib_edu_get_difficulty_levels())));
// Prerequisite.
$courses = array('' => __('None', 'ibeducator'));
$tmp = get_posts(array('post_type' => 'ib_educator_course', 'post_status' => 'publish', 'posts_per_page' => -1));
foreach ($tmp as $course) {
    $courses[$course->ID] = $course->post_title;
}
$prerequisites = IB_Educator::get_instance()->get_prerequisites($post->ID);
$form->set_value('_ib_educator_prerequisite', array_pop($prerequisites));
$form->add(array('type' => 'select', 'name' => '_ib_educator_prerequisite', 'id' => 'ib-educator-prerequisite', 'label' => __('Prerequisite', 'ibeducator'), 'options' => $courses));
wp_nonce_field('ib_educator_course_meta_box', 'ib_educator_course_meta_box_nonce');
$form->display();
Example #19
0
/**
 *
 */
function training_wpo_get_course_lessons_index($course_id)
{
    $id = get_the_ID();
    $api = IB_Educator::get_instance();
    $lessons_query = $api->get_lessons($course_id);
    $number = 0;
    if ($lessons_query && $lessons_query->have_posts()) {
        while ($lessons_query->have_posts()) {
            $number++;
            $lessons_query->the_post();
            $student_can_study = ib_edu_student_can_study(get_the_ID());
            $options = get_post_meta(get_the_ID(), 'wpo_postconfig_other', true);
            ?>

			<div class="lesson<?php 
            if (get_the_ID() == $id) {
                ?>
 active<?php 
            }
            ?>
">
				<span class="number"><?php 
            echo esc_attr($number);
            ?>
</span>
				<span class="lesson-icon"><i class="<?php 
            echo training_wpo_related_post();
            ?>
"></i></span>
				<a class="title" href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
					<?php 
            if ($student_can_study) {
                ?>
		            <i class="zmdi zmdi-check"></i>
		         <?php 
            } else {
                ?>
		            <span class="zmdi zmdi-lock-outline"></span>
		         <?php 
            }
            ?>
		         <div class="clearfix"></div>
				<?php 
            if (isset($options['duration']) && $options['duration']) {
                ?>
		         <span class="duration"><?php 
                echo esc_attr($options['duration']);
                ?>
</span>
		   	<?php 
            }
            ?>
				</a>
			</div>
		<?php 
        }
        wp_reset_postdata();
    }
}
Example #20
0
/**
 * This template renders a quiz.
 *
 * @version 1.1.0
 */
$user_id = get_current_user_id();
if ($user_id == 0) {
    echo '<p>';
    printf(__('You must be <a href="%s">logged in</a> to take the quiz.', 'ibeducator'), esc_url(wp_login_url(get_permalink())));
    echo '</p>';
    return;
}
$lesson_id = get_the_ID();
// Get entry data for the current student. Entry status must be "inprogress".
$entry = IB_Educator::get_instance()->get_entry(array('user_id' => $user_id, 'course_id' => ib_edu_get_course_id($lesson_id), 'entry_status' => 'inprogress'));
$entry_id = $entry ? $entry->ID : 0;
if (!$entry_id && 'ib_educator_lesson' == get_post_type()) {
    return;
}
$quizzes = Edr_Manager::get('edr_quizzes');
$questions = $quizzes->get_questions($lesson_id);
?>

<?php 
if (!empty($questions)) {
    ?>
	<?php 
    $message = get_query_var('edu-message');
    if (!$message) {
        $message = ib_edu_message('quiz');
Example #21
0
<?php

$api = IB_Educator::get_instance();
// Get entry data for the current student. Entry status must be "inprogress".
$entry = $api->get_entry(array('user_id' => get_current_user_id(), 'course_id' => ib_edu_get_course_id(get_the_ID()), 'entry_status' => 'inprogress'));
if (!$entry) {
    return;
}
$lesson_id = get_the_ID();
$questions = $api->get_questions(array('lesson_id' => $lesson_id));
?>

<?php 
if ($questions) {
    ?>
	<?php 
    $message = get_query_var('edu-message');
    if (!$message) {
        $message = ib_edu_message('quiz');
    }
    if ($message) {
        switch ($message) {
            case 'empty-answers':
                echo '<div class="ib-edu-message error">' . __('Please answer all questions before submitting the quiz.', 'ibeducator') . '</div>';
                break;
            case 'quiz-submitted':
                echo '<div class="ib-edu-message success">' . __('Thank you. The quiz has been accepted.', 'ibeducator') . '</div>';
                break;
        }
    }
    $quiz_submitted = $api->is_quiz_submitted($lesson_id, $entry->ID);
Example #22
0
 /**
  * Prepare items.
  * Fetch and setup payments(items).
  */
 public function prepare_items()
 {
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
     $statuses = edr_get_payment_statuses();
     $args = array('per_page' => $this->get_items_per_page('payments_per_page', 10), 'page' => $this->get_pagenum());
     if (!empty($_GET['status']) && array_key_exists($_GET['status'], $statuses)) {
         $args['payment_status'] = array($_GET['status']);
     }
     if (!empty($_GET['id'])) {
         $args['payment_id'] = $_GET['id'];
     }
     if (!empty($_GET['payment_type'])) {
         $args['payment_type'] = $_GET['payment_type'];
     }
     $payments = IB_Educator::get_instance()->get_payments($args);
     if (!empty($payments)) {
         $this->set_pagination_args(array('total_items' => $payments['num_items'], 'per_page' => $args['per_page']));
         $this->items = $payments['rows'];
     }
 }