/**
  * @constructor
  *
  * @param array $data
  */
 public function __construct($data)
 {
     global $wpdb;
     $tables = ib_edu_table_names();
     $this->table_name = $tables['payments'];
     $this->lines_table = $tables['payment_lines'];
     if (!empty($data)) {
         $this->ID = $data->ID;
         $this->parent_id = $data->parent_id;
         $this->course_id = $data->course_id;
         $this->user_id = $data->user_id;
         $this->object_id = $data->object_id;
         $this->txn_id = $data->txn_id;
         $this->payment_type = $data->payment_type;
         $this->payment_gateway = $data->payment_gateway;
         $this->payment_status = $data->payment_status;
         $this->amount = $data->amount;
         $this->tax = $data->tax;
         $this->currency = $data->currency;
         $this->payment_date = $data->payment_date;
         $this->first_name = $data->first_name;
         $this->last_name = $data->last_name;
         $this->address = $data->address;
         $this->address_2 = $data->address_2;
         $this->city = $data->city;
         $this->state = $data->state;
         $this->postcode = $data->postcode;
         $this->country = $data->country;
         $this->ip = $data->ip ? inet_ntop($data->ip) : '';
     }
 }
Exemple #2
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $tables = ib_edu_table_names();
     $this->tbl_questions = $tables['questions'];
     $this->tbl_choices = $tables['choices'];
     $this->tbl_grades = $tables['grades'];
     $this->tbl_answers = $tables['answers'];
 }
Exemple #3
0
 public static function set_current_user_courses($user_id)
 {
     global $wpdb;
     if (!$user_id || !is_null(self::$current_user_courses)) {
         return;
     }
     $tables = ib_edu_table_names();
     self::$current_user_courses = $wpdb->get_col($wpdb->prepare("SELECT course_id FROM {$tables['entries']} WHERE user_id = %d AND entry_status = 'inprogress'", $user_id));
 }
Exemple #4
0
 /**
  * Constructor.
  *
  * @access private
  */
 private function __construct()
 {
     $tables = ib_edu_table_names();
     $this->payments = $tables['payments'];
     $this->entries = $tables['entries'];
     $this->questions = $tables['questions'];
     $this->choices = $tables['choices'];
     $this->answers = $tables['answers'];
     $this->grades = $tables['grades'];
 }
 /**
  * Constructor.
  *
  * @param mixed $data
  */
 public function __construct($data)
 {
     global $wpdb;
     $tables = ib_edu_table_names();
     $this->table_name = $tables['questions'];
     if (is_numeric($data)) {
         $data = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->table_name} WHERE ID = %d", $data));
     }
     if (!empty($data)) {
         $this->set_data($data);
     }
 }
 /**
  * Constructor.
  *
  * @param array $data
  */
 public function __construct($data)
 {
     $tables = ib_edu_table_names();
     $this->table_name = $tables['questions'];
     if (!empty($data)) {
         $this->ID = $data->ID;
         $this->lesson_id = $data->lesson_id;
         $this->question = $data->question;
         $this->question_type = $data->question_type;
         $this->menu_order = $data->menu_order;
     }
 }
Exemple #7
0
 public function __construct()
 {
     $tables = ib_edu_table_names();
     $this->payments = $tables['payments'];
     $this->entries = $tables['entries'];
     $this->questions = $tables['questions'];
     $this->choices = $tables['choices'];
     $this->answers = $tables['answers'];
     $this->grades = $tables['grades'];
     $this->members = $tables['members'];
     $this->tax_rates = $tables['tax_rates'];
     $this->payment_lines = $tables['payment_lines'];
 }
 /**
  * @constructor
  *
  * @param array $data
  */
 public function __construct($data)
 {
     global $wpdb;
     $tables = ib_edu_table_names();
     $this->table_name = $tables['entries'];
     if (!empty($data)) {
         $this->ID = $data->ID;
         $this->course_id = $data->course_id;
         $this->object_id = $data->object_id;
         $this->user_id = $data->user_id;
         $this->payment_id = $data->payment_id;
         $this->grade = $data->grade;
         $this->entry_origin = $data->entry_origin;
         $this->entry_status = $data->entry_status;
         $this->entry_date = $data->entry_date;
     }
 }
Exemple #9
0
/**
 * get list of students registered in a courses. 
 */
function training_wpo_get_students_by_course($id)
{
    $tables = ib_edu_table_names();
    global $wpdb;
    $data = $wpdb->get_results($wpdb->prepare("SELECT user_id, course_id FROM {$tables['payments']} WHERE  course_id=%s and payment_status='complete'", $id), OBJECT_K);
    $output = array();
    foreach ($data as $items) {
        foreach ($items as $item) {
            $user = get_user_by('id', $items->user_id);
            $output[$items->user_id] = array('id' => $items->user_id, 'name' => $user->display_name);
        }
    }
    wp_reset_postdata();
    return $output;
}
 /**
  * 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;
 }
Exemple #11
0
 /**
  * Update membership entries' status.
  *
  * @param int $user_id
  * @param string $status
  */
 public function update_membership_entries($user_id, $status)
 {
     global $wpdb;
     $tables = ib_edu_table_names();
     $wpdb->update($tables['entries'], array('entry_status' => $status), array('user_id' => $user_id, 'entry_origin' => 'membership', 'entry_status' => 'inprogress'), array('%s'), array('%d', '%s', '%s'));
 }
Exemple #12
0
 /**
  * Constructor.
  */
 protected function __construct()
 {
     $tables = ib_edu_table_names();
     $this->table = $tables['tax_rates'];
 }
 /**
  * Delete membership data when a user is deleted.
  *
  * @param int $user_id
  */
 public static function on_deleted_user($user_id)
 {
     global $wpdb;
     $tables = ib_edu_table_names();
     $wpdb->delete($tables['members'], array('user_id' => $user_id), array('%d'));
 }
 /**
  * AJAX: sort quiz questions.
  */
 public static function sort_questions()
 {
     global $wpdb;
     $lesson_id = isset($_POST['lesson_id']) ? absint($_POST['lesson_id']) : 0;
     if (!$lesson_id || !isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ibedu_quiz_' . $lesson_id)) {
         exit;
     }
     // Verify capabilities.
     if (!ib_edu_user_can_edit_lesson($lesson_id)) {
         exit;
     }
     $ids = isset($_POST['question_id']) && is_array($_POST['question_id']) ? $_POST['question_id'] : null;
     $order = isset($_POST['order']) && is_array($_POST['order']) ? $_POST['order'] : null;
     if ($ids && $order) {
         foreach ($ids as $key => $question_id) {
             if (is_numeric($question_id) && isset($order[$key]) && is_numeric($order[$key])) {
                 $tables = ib_edu_table_names();
                 $wpdb->update($tables['questions'], array('menu_order' => $order[$key]), array('ID' => $question_id, 'lesson_id' => $lesson_id), array('%d'), array('%d', '%d'));
             }
         }
     }
     exit;
 }
 /**
  * Process AJAX actions of the tax rates app.
  */
 public function ajax_taxes()
 {
     if (!isset($_GET['method'])) {
         return;
     }
     // Check capability.
     if (!current_user_can('manage_educator')) {
         return;
     }
     switch ($_GET['method']) {
         case 'add-tax-class':
         case 'edit-tax-class':
             $input = json_decode(file_get_contents('php://input'), true);
             if ($input) {
                 if (empty($input['_wpnonce']) || !wp_verify_nonce($input['_wpnonce'], 'ib_educator_tax_rates')) {
                     return;
                 }
                 $edu_tax = IB_Educator_Tax::get_instance();
                 // Get and sanitize input.
                 $data = $edu_tax->sanitize_tax_class($input);
                 if (is_wp_error($data)) {
                     http_response_code(400);
                     return;
                 }
                 // Save the tax class.
                 $edu_tax->add_tax_class($data);
                 echo json_encode($data);
             }
             break;
         case 'delete-tax-class':
             if (empty($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'ib_educator_tax_rates')) {
                 http_response_code(400);
                 return;
             }
             if (!isset($_GET['name']) || 'default' == $_GET['name']) {
                 http_response_code(400);
                 return;
             }
             IB_Educator_Tax::get_instance()->delete_tax_class($_GET['name']);
             break;
         case 'rates':
             switch ($_SERVER['REQUEST_METHOD']) {
                 case 'POST':
                 case 'PUT':
                     $input = json_decode(file_get_contents('php://input'), true);
                     if ($input) {
                         if (empty($input['_wpnonce']) || !wp_verify_nonce($input['_wpnonce'], 'ib_educator_tax_rates')) {
                             return;
                         }
                         $edu_tax = IB_Educator_Tax::get_instance();
                         $rate = $edu_tax->sanitize_tax_rate($input);
                         $rate['ID'] = $edu_tax->update_tax_rate($rate);
                         echo json_encode($rate);
                     }
                     break;
                 case 'GET':
                     if (empty($_GET['class_name'])) {
                         return;
                     }
                     $class_name = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['class_name']);
                     $edu_tax = IB_Educator_Tax::get_instance();
                     $rates = $edu_tax->get_tax_rates($class_name);
                     $edu_countries = IB_Educator_Countries::get_instance();
                     $countries = $edu_countries->get_countries();
                     if (!empty($rates)) {
                         foreach ($rates as $key => $rate) {
                             $rate = $edu_tax->sanitize_tax_rate($rate);
                             // Get country name.
                             if ($rate['country']) {
                                 if (isset($countries[$rate['country']])) {
                                     $rate['country_name'] = esc_html($countries[$rate['country']]);
                                 }
                             }
                             // Get state name.
                             if ($rate['state']) {
                                 $states = $edu_countries->get_states($rate['country']);
                                 if (isset($states[$rate['state']])) {
                                     $rate['state_name'] = esc_html($states[$rate['state']]);
                                 } else {
                                     $rate['state_name'] = $rate['state'];
                                 }
                             }
                             $rates[$key] = $rate;
                         }
                         header('Content-Type: application/json');
                         echo json_encode($rates);
                     }
                     break;
                 case 'DELETE':
                     if (empty($_GET['ID']) || empty($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'ib_educator_tax_rates')) {
                         return;
                     }
                     IB_Educator_Tax::get_instance()->delete_tax_rate($_GET['ID']);
                     break;
             }
             break;
         case 'save-rates-order':
             if (empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ib_educator_tax_rates')) {
                 return;
             }
             if (!isset($_POST['order']) || !is_array($_POST['order'])) {
                 return;
             }
             global $wpdb;
             $tables = ib_edu_table_names();
             foreach ($_POST['order'] as $id => $order) {
                 if (!is_numeric($id) || !is_numeric($order)) {
                     continue;
                 }
                 $wpdb->update($tables['tax_rates'], array('rate_order' => $order), array('id' => $id), array('%d'), array('%d'));
             }
             break;
     }
     exit;
 }