<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('session');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
if (!$this->session->userdata('cart_items')) {
$this->session->set_userdata('cart_items', array());
}
}
public function index()
{
if ($this->session->userdata('admin_login') == true) {
$this->dashboard();
} else {
redirect(site_url('login'), 'refresh');
}
}
public function dashboard()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'dashboard';
$page_data['page_title'] = get_phrase('dashboard');
$this->load->view('backend/index.php', $page_data);
}
public function categories($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('category');
if ($param1 == 'add') {
$response = $this->crud_model->add_category();
if ($response) {
$this->session->set_flashdata('flash_message', get_phrase('data_added_successfully'));
} else {
$this->session->set_flashdata('error_message', get_phrase('category_name_already_exists'));
}
redirect(site_url('admin/categories'), 'refresh');
} elseif ($param1 == "edit") {
$response = $this->crud_model->edit_category($param2);
if ($response) {
$this->session->set_flashdata('flash_message', get_phrase('data_added_successfully'));
} else {
$this->session->set_flashdata('error_message', get_phrase('category_name_already_exists'));
}
redirect(site_url('admin/categories'), 'refresh');
} elseif ($param1 == "delete") {
$this->crud_model->delete_category($param2);
$this->session->set_flashdata('flash_message', get_phrase('data_deleted'));
redirect(site_url('admin/categories'), 'refresh');
}
$page_data['page_name'] = 'categories';
$page_data['page_title'] = get_phrase('categories');
$page_data['categories'] = $this->crud_model->get_categories($param2);
$this->load->view('backend/index', $page_data);
}
public function category_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('category');
if ($param1 == "add_category") {
$page_data['page_name'] = 'category_add';
$page_data['categories'] = $this->crud_model->get_categories()->result_array();
$page_data['page_title'] = get_phrase('add_category');
}
if ($param1 == "edit_category") {
$page_data['page_name'] = 'category_edit';
$page_data['page_title'] = get_phrase('edit_category');
$page_data['categories'] = $this->crud_model->get_categories()->result_array();
$page_data['category_id'] = $param2;
}
$this->load->view('backend/index', $page_data);
}
public function sub_categories_by_category_id($category_id = 0)
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$category_id = $this->input->post('category_id');
redirect(site_url("admin/sub_categories/$category_id"), 'refresh');
}
public function sub_category_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('category');
if ($param1 == 'add_sub_category') {
$page_data['page_name'] = 'sub_category_add';
$page_data['page_title'] = get_phrase('add_sub_category');
} elseif ($param1 == 'edit_sub_category') {
$page_data['page_name'] = 'sub_category_edit';
$page_data['page_title'] = get_phrase('edit_sub_category');
$page_data['sub_category_id'] = $param2;
}
$page_data['categories'] = $this->crud_model->get_categories();
$this->load->view('backend/index', $page_data);
}
public function instructors($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('user');
check_permission('instructor');
if ($param1 == "add") {
$this->user_model->add_user(true); // PROVIDING TRUE FOR INSTRUCTOR
redirect(site_url('admin/instructors'), 'refresh');
} elseif ($param1 == "edit") {
$this->user_model->edit_user($param2);
redirect(site_url('admin/instructors'), 'refresh');
} elseif ($param1 == "delete") {
$this->user_model->delete_user($param2);
redirect(site_url('admin/instructors'), 'refresh');
}
$page_data['page_name'] = 'instructors';
$page_data['page_title'] = get_phrase('instructor');
$page_data['instructors'] = $this->user_model->get_instructor()->result_array();
$this->load->view('backend/index', $page_data);
}
public function instructor_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('user');
check_permission('instructor');
if ($param1 == 'add_instructor_form') {
$page_data['page_name'] = 'instructor_add';
$page_data['page_title'] = get_phrase('instructor_add');
$this->load->view('backend/index', $page_data);
} elseif ($param1 == 'edit_instructor_form') {
$page_data['page_name'] = 'instructor_edit';
$page_data['user_id'] = $param2;
$page_data['page_title'] = get_phrase('instructor_edit');
$this->load->view('backend/index', $page_data);
}
}
public function users($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('user');
check_permission('student');
if ($param1 == "add") {
$this->user_model->add_user();
redirect(site_url('admin/users'), 'refresh');
} elseif ($param1 == "edit") {
$this->user_model->edit_user($param2);
redirect(site_url('admin/users'), 'refresh');
} elseif ($param1 == "delete") {
$this->user_model->delete_user($param2);
redirect(site_url('admin/users'), 'refresh');
}
$page_data['page_name'] = 'users';
$page_data['page_title'] = get_phrase('student');
$page_data['users'] = $this->user_model->get_user($param2);
$this->load->view('backend/index', $page_data);
}
public function add_shortcut_student()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('user');
check_permission('student');
$is_instructor = 0;
echo $this->user_model->add_shortcut_user($is_instructor);
}
public function user_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('user');
check_permission('student');
if ($param1 == 'add_user_form') {
$page_data['page_name'] = 'user_add';
$page_data['page_title'] = get_phrase('student_add');
$this->load->view('backend/index', $page_data);
} elseif ($param1 == 'edit_user_form') {
$page_data['page_name'] = 'user_edit';
$page_data['user_id'] = $param2;
$page_data['page_title'] = get_phrase('student_edit');
$this->load->view('backend/index', $page_data);
}
}
public function enrol_history($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('enrolment');
if ($param1 != "") {
$date_range = $this->input->get('date_range');
$date_range = explode(" - ", $date_range);
$page_data['timestamp_start'] = strtotime($date_range[0]);
$page_data['timestamp_end'] = strtotime($date_range[1]);
} else {
$first_day_of_month = "1 " . date("M") . " " . date("Y") . ' 00:00:00';
$last_day_of_month = date("t") . " " . date("M") . " " . date("Y") . ' 23:59:59';
$page_data['timestamp_start'] = strtotime($first_day_of_month);
$page_data['timestamp_end'] = strtotime($last_day_of_month);
}
$page_data['page_name'] = 'enrol_history';
$page_data['enrol_history'] = $this->crud_model->enrol_history_by_date_range($page_data['timestamp_start'], $page_data['timestamp_end']);
$page_data['page_title'] = get_phrase('enrol_history');
$this->load->view('backend/index', $page_data);
}
public function enrol_student($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('enrolment');
if ($param1 == 'enrol') {
$this->crud_model->enrol_a_student_manually();
redirect(site_url('admin/enrol_history'), 'refresh');
}
$page_data['page_name'] = 'enrol_student';
$page_data['page_title'] = get_phrase('enrol_a_student');
$this->load->view('backend/index', $page_data);
}
public function shortcut_enrol_student()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('enrolment');
echo $this->crud_model->shortcut_enrol_a_student_manually();
}
public function admin_revenue($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('revenue');
if ($param1 != "") {
$date_range = $this->input->get('date_range');
$date_range = explode(" - ", $date_range);
$page_data['timestamp_start'] = strtotime($date_range[0] . ' 00:00:00');
$page_data['timestamp_end'] = strtotime($date_range[1] . ' 23:59:59');
} else {
$page_data['timestamp_start'] = strtotime(date("m/01/Y 00:00:00"));
$page_data['timestamp_end'] = strtotime(date("m/t/Y 23:59:59"));
}
$page_data['page_name'] = 'admin_revenue';
$page_data['payment_history'] = $this->crud_model->get_revenue_by_user_type($page_data['timestamp_start'], $page_data['timestamp_end'], 'admin_revenue');
$page_data['page_title'] = get_phrase('admin_revenue');
$this->load->view('backend/index', $page_data);
}
public function instructor_revenue($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('revenue');
$page_data['page_name'] = 'instructor_revenue';
$page_data['payment_history'] = $this->crud_model->get_revenue_by_user_type("", "", 'instructor_revenue');
$page_data['page_title'] = get_phrase('instructor_revenue');
$this->load->view('backend/index', $page_data);
}
function invoice($payout_id = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'invoice';
$page_data['payout_id'] = $payout_id;
$page_data['page_title'] = get_phrase('invoice');
$this->load->view('backend/index', $page_data);
}
public function enrol_history_delete($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('enrolment');
$this->crud_model->delete_enrol_history($param1);
$this->session->set_flashdata('flash_message', get_phrase('data_deleted_successfully'));
redirect(site_url('admin/enrol_history'), 'refresh');
}
public function purchase_history()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'purchase_history';
$page_data['purchase_history'] = $this->crud_model->purchase_history();
$page_data['page_title'] = get_phrase('purchase_history');
$this->load->view('backend/index', $page_data);
}
public function system_settings($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('settings');
if ($param1 == 'system_update') {
$this->crud_model->update_system_settings();
$this->session->set_flashdata('flash_message', get_phrase('system_settings_updated'));
redirect(site_url('admin/system_settings'), 'refresh');
}
if ($param1 == 'logo_upload') {
move_uploaded_file($_FILES['logo']['tmp_name'], 'assets/backend/logo.png');
$this->session->set_flashdata('flash_message', get_phrase('backend_logo_updated'));
redirect(site_url('admin/system_settings'), 'refresh');
}
if ($param1 == 'favicon_upload') {
move_uploaded_file($_FILES['favicon']['tmp_name'], 'assets/favicon.png');
$this->session->set_flashdata('flash_message', get_phrase('favicon_updated'));
redirect(site_url('admin/system_settings'), 'refresh');
}
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['page_name'] = 'system_settings';
$page_data['page_title'] = get_phrase('system_settings');
$this->load->view('backend/index', $page_data);
}
public function frontend_settings($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('settings');
if ($param1 == 'frontend_update') {
$this->crud_model->update_frontend_settings();
$this->session->set_flashdata('flash_message', get_phrase('frontend_settings_updated'));
redirect(site_url('admin/frontend_settings'), 'refresh');
}
if ($param1 == 'recaptcha_update') {
$this->crud_model->update_recaptcha_settings();
$this->session->set_flashdata('flash_message', get_phrase('recaptcha_settings_updated'));
redirect(site_url('admin/frontend_settings'), 'refresh');
}
if ($param1 == 'banner_image_update') {
$this->crud_model->update_frontend_banner();
$this->session->set_flashdata('flash_message', get_phrase('banner_image_update'));
redirect(site_url('admin/frontend_settings'), 'refresh');
}
if ($param1 == 'light_logo') {
$this->crud_model->update_light_logo();
$this->session->set_flashdata('flash_message', get_phrase('logo_updated'));
redirect(site_url('admin/frontend_settings'), 'refresh');
}
if ($param1 == 'dark_logo') {
$this->crud_model->update_dark_logo();
$this->session->set_flashdata('flash_message', get_phrase('logo_updated'));
redirect(site_url('admin/frontend_settings'), 'refresh');
}
if ($param1 == 'small_logo') {
$this->crud_model->update_small_logo();
$this->session->set_flashdata('flash_message', get_phrase('logo_updated'));
redirect(site_url('admin/frontend_settings'), 'refresh');
}
if ($param1 == 'favicon') {
$this->crud_model->update_favicon();
$this->session->set_flashdata('flash_message', get_phrase('favicon_updated'));
redirect(site_url('admin/frontend_settings'), 'refresh');
}
$page_data['page_name'] = 'frontend_settings';
$page_data['page_title'] = get_phrase('frontend_settings');
$this->load->view('backend/index', $page_data);
}
public function payment_settings($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('settings');
if ($param1 == 'system_currency') {
$this->crud_model->update_system_currency();
redirect(site_url('admin/payment_settings'), 'refresh');
}
if ($param1 == 'paypal_settings') {
$this->crud_model->update_paypal_settings();
redirect(site_url('admin/payment_settings'), 'refresh');
}
if ($param1 == 'stripe_settings') {
$this->crud_model->update_stripe_settings();
redirect(site_url('admin/payment_settings'), 'refresh');
}
$page_data['page_name'] = 'payment_settings';
$page_data['page_title'] = get_phrase('payment_settings');
$this->load->view('backend/index', $page_data);
}
public function smtp_settings($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('settings');
if ($param1 == 'update') {
$this->crud_model->update_smtp_settings();
$this->session->set_flashdata('flash_message', get_phrase('smtp_settings_updated_successfully'));
redirect(site_url('admin/smtp_settings'), 'refresh');
}
$page_data['page_name'] = 'smtp_settings';
$page_data['page_title'] = get_phrase('smtp_settings');
$this->load->view('backend/index', $page_data);
}
public function instructor_settings($param1 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('user');
check_permission('instructor');
if ($param1 == 'update') {
$this->crud_model->update_instructor_settings();
$this->session->set_flashdata('flash_message', get_phrase('instructor_settings_updated'));
redirect(site_url('admin/instructor_settings'), 'refresh');
}
$page_data['page_name'] = 'instructor_settings';
$page_data['page_title'] = get_phrase('instructor_settings');
$this->load->view('backend/index', $page_data);
}
public function theme_settings($action = '')
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('theme');
$page_data['page_name'] = 'theme_settings';
$page_data['page_title'] = get_phrase('theme_settings');
$this->load->view('backend/index', $page_data);
}
public function theme_actions($action = "", $theme = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('theme');
if ($action == 'activate') {
$theme_to_active = $this->input->post('theme');
$installed_themes = $this->crud_model->get_installed_themes();
if (in_array($theme_to_active, $installed_themes)) {
$this->crud_model->activate_theme($theme_to_active);
echo true;
} else {
echo false;
}
} elseif ($action == 'remove') {
if ($theme == get_frontend_settings('theme')) {
$this->session->set_flashdata('error_message', get_phrase('activate_a_theme_first'));
} else {
$this->crud_model->remove_files_and_folders(APPPATH . '/views/frontend/' . $theme);
$this->crud_model->remove_files_and_folders(FCPATH . '/assets/frontend/' . $theme);
$this->session->set_flashdata('flash_message', $theme . ' ' . get_phrase('theme_removed_successfully'));
}
redirect(site_url('admin/theme_settings'), 'refresh');
}
}
public function courses()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('course');
$page_data['selected_category_id'] = isset($_GET['category_id']) ? $_GET['category_id'] : "all";
$page_data['selected_instructor_id'] = isset($_GET['instructor_id']) ? $_GET['instructor_id'] : "all";
$page_data['selected_price'] = isset($_GET['price']) ? $_GET['price'] : "all";
$page_data['selected_status'] = isset($_GET['status']) ? $_GET['status'] : "all";
// Courses query is used for deciding if there is any course or not. Check the view you will get it
$page_data['courses'] = $this->crud_model->filter_course_for_backend($page_data['selected_category_id'], $page_data['selected_instructor_id'], $page_data['selected_price'], $page_data['selected_status']);
$page_data['status_wise_courses'] = $this->crud_model->get_status_wise_courses();
$page_data['instructors'] = $this->user_model->get_instructor()->result_array();
$page_data['page_name'] = 'courses-server-side';
$page_data['categories'] = $this->crud_model->get_categories();
$page_data['page_title'] = get_phrase('active_courses');
$this->load->view('backend/index', $page_data);
}
// This function is responsible for loading the course data from server side for datatable SILENTLY
public function get_courses()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$courses = array();
// Filter portion
$filter_data['selected_category_id'] = $this->input->post('selected_category_id');
$filter_data['selected_instructor_id'] = $this->input->post('selected_instructor_id');
$filter_data['selected_price'] = $this->input->post('selected_price');
$filter_data['selected_status'] = $this->input->post('selected_status');
// Server side processing portion
$columns = array(
0 => '#',
1 => 'title',
2 => 'category',
3 => 'lesson_and_section',
4 => 'enrolled_student',
5 => 'status',
6 => 'price',
7 => 'actions',
8 => 'course_id'
);
// Coming from databale itself. Limit is the visible number of data
$limit = html_escape($this->input->post('length'));
$start = html_escape($this->input->post('start'));
$order = "";
$dir = $this->input->post('order')[0]['dir'];
$totalData = $this->lazyload->count_all_courses($filter_data);
$totalFiltered = $totalData;
// This block of code is handling the search event of datatable
if (empty($this->input->post('search')['value'])) {
$courses = $this->lazyload->courses($limit, $start, $order, $dir, $filter_data);
} else {
$search = $this->input->post('search')['value'];
$courses = $this->lazyload->course_search($limit, $start, $search, $order, $dir, $filter_data);
$totalFiltered = $this->lazyload->course_search_count($search);
}
// Fetch the data and make it as JSON format and return it.
$data = array();
if (!empty($courses)) {
foreach ($courses as $key => $row) {
$instructor_details = $this->user_model->get_all_user($row->user_id)->row_array();
$category_details = $this->crud_model->get_category_details_by_id($row->sub_category_id)->row_array();
$sections = $this->crud_model->get_section('course', $row->id);
$lessons = $this->crud_model->get_lessons('course', $row->id);
$enroll_history = $this->crud_model->enrol_history($row->id);
$status_badge = "badge-success-lighten";
if ($row->status == 'pending') {
$status_badge = "badge-danger-lighten";
} elseif ($row->status == 'draft') {
$status_badge = "badge-dark-lighten";
}
$price_badge = "badge-dark-lighten";
$price = 0;
if ($row->is_free_course == null) {
if ($row->discount_flag == 1) {
$price = currency($row->discounted_price);
} else {
$price = currency($row->price);
}
} elseif ($row->is_free_course == 1) {
$price_badge = "badge-success-lighten";
$price = get_phrase('free');
}
$view_course_on_frontend_url = site_url('home/course/' . rawurlencode(slugify($row->title)) . '/' . $row->id);
$edit_this_course_url = site_url('admin/course_form/course_edit/' . $row->id);
$section_and_lesson_url = site_url('admin/course_form/course_edit/' . $row->id);
if ($row->status == 'active') {
$course_status_changing_message = get_phrase('mark_as_pending');
if ($row->user_id != $this->session->userdata('user_id')) {
$course_status_changing_action = "showAjaxModal('" . site_url('modal/popup/mail_on_course_status_changing_modal/pending/' . $row->id . '/' . $filter_data['selected_category_id'] . '/' . $filter_data['selected_instructor_id'] . '/' . $filter_data['selected_price'] . '/' . $filter_data['selected_status']) . "', '" . $course_status_changing_message . "')";
} else {
$course_status_changing_action = "confirm_modal('" . site_url('admin/change_course_status_for_admin/pending/' . $row->id . '/' . $filter_data['selected_category_id'] . '/' . $filter_data['selected_instructor_id'] . '/' . $filter_data['selected_price'] . '/' . $filter_data['selected_status']) . "')";
}
} else {
$course_status_changing_message = get_phrase('mark_as_active');
if ($row->user_id != $this->session->userdata('user_id')) {
$course_status_changing_action = "showAjaxModal('" . site_url('modal/popup/mail_on_course_status_changing_modal/active/' . $row->id . '/' . $filter_data['selected_category_id'] . '/' . $filter_data['selected_instructor_id'] . '/' . $filter_data['selected_price'] . '/' . $filter_data['selected_status']) . "', '" . $course_status_changing_message . "')";
} else {
$course_status_changing_action = "confirm_modal('" . site_url('admin/change_course_status_for_admin/active/' . $row->id . '/' . $filter_data['selected_category_id'] . '/' . $filter_data['selected_instructor_id'] . '/' . $filter_data['selected_price'] . '/' . $filter_data['selected_status']) . "')";
}
}
$delete_course_url = "confirm_modal('" . site_url('admin/course_actions/delete/' . $row->id) . "')";
if ($row->course_type != 'scorm') {
$section_and_lesson_menu = '<li><a class="dropdown-item" href="' . $section_and_lesson_url . '">' . get_phrase("section_and_lesson") . '</a></li>';
} else {
$section_and_lesson_menu = "";
}
$course_edit_menu = '<li><a class="dropdown-item" href="' . $edit_this_course_url . '">' . get_phrase("edit_this_course") . '</a></li>';
$course_delete_menu = '<li><a class="dropdown-item" href="javascript::" onclick="' . $delete_course_url . '">' . get_phrase("delete") . '</a></li>';
$action = '
<div class="dropright dropright">
<button type="button" class="btn btn-sm btn-outline-primary btn-rounded btn-icon" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="mdi mdi-dots-vertical"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="' . $view_course_on_frontend_url . '" target="_blank">' . get_phrase("view_course_on_frontend") . '</a></li>
' . $course_edit_menu . $section_and_lesson_menu . '
<li><a class="dropdown-item" href="javascript::" onclick="' . $course_status_changing_action . '">' . $course_status_changing_message . '</a></li>
' . $course_delete_menu . '
</ul>
</div>
';
$nestedData['#'] = $key + 1;
$instructor_names = "";
if ($row->multi_instructor) {
$instructors = $this->user_model->get_multi_instructor_details_with_csv($row->user_id);
foreach ($instructors as $counterForThis => $instructor) {
$instructor_names .= $instructor['first_name'] . ' ' . $instructor['last_name'];
$instructor_names .= $counterForThis + 1 == count($instructors) ? '' : ', ';
}
} else {
$instructor_names = $instructor_details['first_name'] . ' ' . $instructor_details['last_name'];
}
$nestedData['title'] = '<strong><a href="' . site_url('admin/course_form/course_edit/' . $row->id) . '">' . $row->title . '</a></strong><br>
<small class="text-muted">' . get_phrase('instructor') . ': <b>' . $instructor_names . '</b></small>';
$nestedData['category'] = '<span class="badge badge-dark-lighten">' . $category_details['name'] . '</span>';
if ($row->course_type == 'scorm') {
$nestedData['lesson_and_section'] = '<span class="badge badge-info-lighten">' . get_phrase('scorm_course') . '</span>';
} elseif ($row->course_type == 'general') {
$nestedData['lesson_and_section'] = '
<small class="text-muted"><b>' . get_phrase('total_section') . '</b>: ' . $sections->num_rows() . '</small><br>
<small class="text-muted"><b>' . get_phrase('total_lesson') . '</b>: ' . $lessons->num_rows() . '</small>';
}
$nestedData['enrolled_student'] = '<small class="text-muted"><b>' . get_phrase('total_enrolment') . '</b>: ' . $enroll_history->num_rows() . '</small>';
$nestedData['status'] = '<span class="badge ' . $status_badge . '">' . get_phrase($row->status) . '</span>';
$nestedData['price'] = '<span class="badge ' . $price_badge . '">' . $price . '</span>';
$nestedData['actions'] = $action;
$nestedData['course_id'] = $row->id;
$data[] = $nestedData;
}
}
$json_data = array(
"draw" => intval($this->input->post('draw')),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
);
echo json_encode($json_data);
}
public function pending_courses()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('course');
$page_data['page_name'] = 'pending_courses';
$page_data['page_title'] = get_phrase('pending_courses');
$this->load->view('backend/index', $page_data);
}
public function course_actions($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('course');
if ($param1 == "add") {
$course_id = $this->crud_model->add_course();
redirect(site_url('admin/course_form/course_edit/' . $course_id), 'refresh');
} elseif ($param1 == 'add_shortcut') {
echo $this->crud_model->add_shortcut_course();
} elseif ($param1 == "edit") {
$this->crud_model->update_course($param2);
// CHECK IF LIVE CLASS ADDON EXISTS, ADD OR UPDATE IT TO ADDON MODEL
if (addon_status('live-class')) {
$this->load->model('addons/Liveclass_model', 'liveclass_model');
$this->liveclass_model->update_live_class($param2);
}
redirect(site_url('admin/course_form/course_edit/' . $param2));
} elseif ($param1 == 'delete') {
$this->is_drafted_course($param2);
$this->crud_model->delete_course($param2);
redirect(site_url('admin/courses'), 'refresh');
}
}
public function course_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('course');
if ($param1 == 'add_course') {
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['categories'] = $this->crud_model->get_categories();
$page_data['page_name'] = 'course_add';
$page_data['page_title'] = get_phrase('add_course');
$this->load->view('backend/index', $page_data);
} elseif ($param1 == 'add_course_shortcut') {
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['categories'] = $this->crud_model->get_categories();
$this->load->view('backend/admin/course_add_shortcut', $page_data);
} elseif ($param1 == 'course_edit') {
$this->is_drafted_course($param2);
$page_data['page_name'] = 'course_edit';
$page_data['course_id'] = $param2;
$page_data['page_title'] = get_phrase('edit_course');
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['categories'] = $this->crud_model->get_categories();
$this->load->view('backend/index', $page_data);
}
}
private function is_drafted_course($course_id)
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$course_details = $this->crud_model->get_course_by_id($course_id)->row_array();
if ($course_details['status'] == 'draft') {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_course'));
redirect(site_url('admin/courses'), 'refresh');
}
}
public function change_course_status($updated_status = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$course_id = $this->input->post('course_id');
$category_id = $this->input->post('category_id');
$instructor_id = $this->input->post('instructor_id');
$price = $this->input->post('price');
$status = $this->input->post('status');
if (isset($_POST['mail_subject']) && isset($_POST['mail_body'])) {
$mail_subject = $this->input->post('mail_subject');
$mail_body = $this->input->post('mail_body');
$this->email_model->send_mail_on_course_status_changing($course_id, $mail_subject, $mail_body);
}
$this->crud_model->change_course_status($updated_status, $course_id);
$this->session->set_flashdata('flash_message', get_phrase('course_status_updated'));
redirect(site_url('admin/courses?category_id=' . $category_id . '&status=' . $status . '&instructor_id=' . $instructor_id . '&price=' . $price), 'refresh');
}
public function change_course_status_for_admin($updated_status = "", $course_id = "", $category_id = "", $status = "", $instructor_id = "", $price = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$this->crud_model->change_course_status($updated_status, $course_id);
$this->session->set_flashdata('flash_message', get_phrase('course_status_updated'));
redirect(site_url('admin/courses?category_id=' . $category_id . '&status=' . $status . '&instructor_id=' . $instructor_id . '&price=' . $price), 'refresh');
}
public function sections($param1 = "", $param2 = "", $param3 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('course');
if ($param2 == 'add') {
$this->crud_model->add_section($param1);
$this->session->set_flashdata('flash_message', get_phrase('section_has_been_added_successfully'));
} elseif ($param2 == 'edit') {
$this->crud_model->edit_section($param3);
$this->session->set_flashdata('flash_message', get_phrase('section_has_been_updated_successfully'));
} elseif ($param2 == 'delete') {
$this->crud_model->delete_section($param1, $param3);
$this->session->set_flashdata('flash_message', get_phrase('section_has_been_deleted_successfully'));
}
redirect(site_url('admin/course_form/course_edit/' . $param1));
}
public function lessons($course_id = "", $param1 = "", $param2 = "")
{
// CHECK ACCESS PERMISSION
check_permission('course');
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'add') {
$this->crud_model->add_lesson();
$this->session->set_flashdata('flash_message', get_phrase('lesson_has_been_added_successfully'));
redirect('admin/course_form/course_edit/' . $course_id);
} elseif ($param1 == 'edit') {
$this->crud_model->edit_lesson($param2);
$this->session->set_flashdata('flash_message', get_phrase('lesson_has_been_updated_successfully'));
redirect('admin/course_form/course_edit/' . $course_id);
} elseif ($param1 == 'delete') {
$this->crud_model->delete_lesson($param2);
$this->session->set_flashdata('flash_message', get_phrase('lesson_has_been_deleted_successfully'));
redirect('admin/course_form/course_edit/' . $course_id);
} elseif ($param1 == 'filter') {
redirect('admin/lessons/' . $this->input->post('course_id'));
}
$page_data['page_name'] = 'lessons';
$page_data['lessons'] = $this->crud_model->get_lessons('course', $course_id);
$page_data['course_id'] = $course_id;
$page_data['page_title'] = get_phrase('lessons');
$this->load->view('backend/index', $page_data);
}
public function watch_video($slugified_title = "", $lesson_id = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$lesson_details = $this->crud_model->get_lessons('lesson', $lesson_id)->row_array();
$page_data['provider'] = $lesson_details['video_type'];
$page_data['video_url'] = $lesson_details['video_url'];
$page_data['lesson_id'] = $lesson_id;
$page_data['page_name'] = 'video_player';
$page_data['page_title'] = get_phrase('video_player');
$this->load->view('backend/index', $page_data);
}
// Language Functions
public function manage_language($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('settings');
if ($param1 == 'add_language') {
$language = trimmer($this->input->post('language'));
if ($language == 'n-a') {
$this->session->set_flashdata('error_message', get_phrase('language_name_can_not_be_empty_or_can_not_have_special_characters'));
redirect(site_url('admin/manage_language'), 'refresh');
}
saveDefaultJSONFile($language);
$this->session->set_flashdata('flash_message', get_phrase('language_added_successfully'));
redirect(site_url('admin/manage_language'), 'refresh');
}
if ($param1 == 'add_phrase') {
$new_phrase = get_phrase($this->input->post('phrase'));
$this->session->set_flashdata('flash_message', $new_phrase . ' ' . get_phrase('has_been_added_successfully'));
redirect(site_url('admin/manage_language'), 'refresh');
}
if ($param1 == 'edit_phrase') {
$page_data['edit_profile'] = $param2;
}
if ($param1 == 'delete_language') {
if (file_exists('application/language/' . $param2 . '.json')) {
unlink('application/language/' . $param2 . '.json');
$this->session->set_flashdata('flash_message', get_phrase('language_deleted_successfully'));
redirect(site_url('admin/manage_language'), 'refresh');
}
}
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['page_name'] = 'manage_language';
$page_data['page_title'] = get_phrase('multi_language_settings');
$this->load->view('backend/index', $page_data);
}
public function update_phrase_with_ajax()
{
$current_editing_language = $this->input->post('currentEditingLanguage');
$updatedValue = $this->input->post('updatedValue');
$key = $this->input->post('key');
saveJSONFile($current_editing_language, $key, $updatedValue);
echo $current_editing_language . ' ' . $key . ' ' . $updatedValue;
}
function message($param1 = 'message_home', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
// CHECK ACCESS PERMISSION
check_permission('messaging');
if ($param1 == 'send_new') {
$message_thread_code = $this->crud_model->send_new_private_message();
$this->session->set_flashdata('flash_message', get_phrase('message_sent'));
redirect(site_url('admin/message/message_read/' . $message_thread_code), 'refresh');
}
if ($param1 == 'send_reply') {
$this->crud_model->send_reply_message($param2); //$param2 = message_thread_code
$this->session->set_flashdata('flash_message', get_phrase('message_sent'));
redirect(site_url('admin/message/message_read/' . $param2), 'refresh');
}
if ($param1 == 'message_read') {
$page_data['current_message_thread_code'] = $param2; // $param2 = message_thread_code
$this->crud_model->mark_thread_messages_read($param2);
}
$page_data['message_inner_page_name'] = $param1;
$page_data['page_name'] = 'message';
$page_data['page_title'] = get_phrase('private_messaging');
$this->load->view('backend/index', $page_data);
}
/******MANAGE OWN PROFILE AND CHANGE PASSWORD***/
function manage_profile($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
if ($param1 == 'update_profile_info') {
$this->user_model->edit_user($param2);
redirect(site_url('admin/manage_profile'), 'refresh');
}
if ($param1 == 'change_password') {
$this->user_model->change_password($param2);
redirect(site_url('admin/manage_profile'), 'refresh');
}
$page_data['page_name'] = 'manage_profile';
$page_data['page_title'] = get_phrase('manage_profile');
$page_data['edit_data'] = $this->db->get_where('users', array(
'id' => $this->session->userdata('user_id')
))->result_array();
$this->load->view('backend/index', $page_data);
}
public function paypal_checkout_for_instructor_revenue()
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
$page_data['amount_to_pay'] = $this->input->post('amount_to_pay');
$page_data['payout_id'] = $this->input->post('payout_id');
$page_data['instructor_name'] = $this->input->post('instructor_name');
$page_data['production_client_id'] = $this->input->post('production_client_id');
// BEFORE, CHECK PAYOUT AMOUNTS ARE VALID
$payout_details = $this->crud_model->get_payouts($page_data['payout_id'], 'payout')->row_array();
if ($payout_details['amount'] == $page_data['amount_to_pay'] && $payout_details['status'] == 0) {
$this->load->view('backend/admin/paypal_checkout_for_instructor_revenue', $page_data);
} else {
$this->session->set_flashdata('error_message', get_phrase('invalid_payout_data'));
redirect(site_url('admin/instructor_payout'), 'refresh');
}
}
// PAYPAL CHECKOUT ACTIONS
public function paypal_payment($payout_id = "", $paypalPaymentID = "", $paypalPaymentToken = "", $paypalPayerID = "")
{
$payout_details = $this->crud_model->get_payouts($payout_id, 'payout')->row_array();
$instructor_id = $payout_details['user_id'];
$instructor_data = $this->db->get_where('users', array('id' => $instructor_id))->row_array();
$paypal_keys = json_decode($instructor_data['paypal_keys'], true);
$production_client_id = $paypal_keys[0]['production_client_id'];
$production_secret_key = $paypal_keys[0]['production_secret_key'];
// $production_client_id = 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R';
// $production_secret_key = 'EFI50pO1s1cV1cySQ85wg2Pncn4VOPxKvTLBhyeGtd1QHNac-OJFsQlS7GAwlXZSg2wtm-BOJ9Ar3XJy';
//THIS IS HOW I CHECKED THE PAYPAL PAYMENT STATUS
$status = $this->payment_model->paypal_payment($paypalPaymentID, $paypalPaymentToken, $paypalPayerID, $production_client_id, $production_secret_key);
if (!$status) {
$this->session->set_flashdata('error_message', get_phrase('an_error_occurred_during_payment'));
redirect(site_url('admin/instructor_payout'), 'refresh');
}
$this->crud_model->update_payout_status($payout_id, 'paypal');
$this->session->set_flashdata('flash_message', get_phrase('payout_updated_successfully'));
redirect(site_url('admin/instructor_payout'), 'refresh');
}
public function stripe_checkout_for_instructor_revenue($payout_id)
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
// BEFORE, CHECK PAYOUT AMOUNTS ARE VALID
$payout_details = $this->crud_model->get_payouts($payout_id, 'payout')->row_array();
if ($payout_details['amount'] > 0 && $payout_details['status'] == 0) {
$page_data['user_details'] = $this->user_model->get_user($payout_details['user_id'])->row_array();
$page_data['amount_to_pay'] = $payout_details['amount'];
$page_data['payout_id'] = $payout_details['id'];
$this->load->view('backend/admin/stripe_checkout_for_instructor_revenue', $page_data);
} else {
$this->session->set_flashdata('error_message', get_phrase('invalid_payout_data'));
redirect(site_url('admin/instructor_payout'), 'refresh');
}
}
// STRIPE CHECKOUT ACTIONS
public function stripe_payment($payout_id = "", $session_id = "")
{
$payout_details = $this->crud_model->get_payouts($payout_id, 'payout')->row_array();
$instructor_id = $payout_details['user_id'];
//THIS IS HOW I CHECKED THE STRIPE PAYMENT STATUS
$response = $this->payment_model->stripe_payment($instructor_id, $session_id, true);
if ($response['payment_status'] === 'succeeded') {
$this->crud_model->update_payout_status($payout_id, 'stripe');
$this->session->set_flashdata('flash_message', get_phrase('payout_updated_successfully'));
} else {
$this->session->set_flashdata('error_message', $response['status_msg']);
}
redirect(site_url('admin/instructor_payout'), 'refresh');
}
public function preview($course_id = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
$this->is_drafted_course($course_id);
if ($course_id > 0) {
$courses = $this->crud_model->get_course_by_id($course_id);
if ($courses->num_rows() > 0) {
$course_details = $courses->row_array();
redirect(site_url('home/lesson/' . rawurlencode(slugify($course_details['title'])) . '/' . $course_details['id']), 'refresh');
}
}
redirect(site_url('admin/courses'), 'refresh');
}
// Manage Quizes
public function quizes($course_id = "", $action = "", $quiz_id = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('course');
if ($action == 'add') {
$this->crud_model->add_quiz($course_id);
$this->session->set_flashdata('flash_message', get_phrase('quiz_has_been_added_successfully'));
} elseif ($action == 'edit') {
$this->crud_model->edit_quiz($quiz_id);
$this->session->set_flashdata('flash_message', get_phrase('quiz_has_been_updated_successfully'));
} elseif ($action == 'delete') {
$this->crud_model->delete_section($course_id, $quiz_id);
$this->session->set_flashdata('flash_message', get_phrase('quiz_has_been_deleted_successfully'));
}
redirect(site_url('admin/course_form/course_edit/' . $course_id));
}
// Manage Quize Questions
public function quiz_questions($quiz_id = "", $action = "", $question_id = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$quiz_details = $this->crud_model->get_lessons('lesson', $quiz_id)->row_array();
if ($action == 'add') {
$response = $this->crud_model->add_quiz_questions($quiz_id);
echo $response;
} elseif ($action == 'edit') {
$response = $this->crud_model->update_quiz_questions($question_id);
echo $response;
} elseif ($action == 'delete') {
$response = $this->crud_model->delete_quiz_question($question_id);
$this->session->set_flashdata('flash_message', get_phrase('question_has_been_deleted'));
redirect(site_url('admin/course_form/course_edit/' . $quiz_details['course_id']));
}
}
// software about page
function about()
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
$page_data['application_details'] = $this->crud_model->get_application_details();
$page_data['page_name'] = 'about';
$page_data['page_title'] = get_phrase('about');
$this->load->view('backend/index', $page_data);
}
public function install_theme($theme_to_install = '')
{
if ($this->session->userdata('admin_login') != 1) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('theme');
$uninstalled_themes = $this->crud_model->get_uninstalled_themes();
if (!in_array($theme_to_install, $uninstalled_themes)) {
$this->session->set_flashdata('error_message', get_phrase('this_theme_is_not_available'));
redirect(site_url('admin/theme_settings'));
}
if (!class_exists('ZipArchive')) {
$this->session->set_flashdata('error_message', get_phrase('your_server_is_unable_to_extract_the_zip_file') . '. ' . get_phrase('please_enable_the_zip_extension_on_your_server') . ', ' . get_phrase('then_try_again'));
redirect(site_url('admin/theme_settings'));
}
$zipped_file_name = $theme_to_install;
$unzipped_file_name = substr($zipped_file_name, 0, -4);
// Create update directory.
$views_directory = 'application/views/frontend';
$assets_directory = 'assets/frontend';
//Unzip theme zip file and remove zip file.
$theme_path = 'themes/' . $zipped_file_name;
$theme_zip = new ZipArchive;
$theme_result = $theme_zip->open($theme_path);
if ($theme_result === TRUE) {
$theme_zip->extractTo('themes');
$theme_zip->close();
}
// unzip the views zip file to the application>views folder
$views_path = 'themes/' . $unzipped_file_name . '/views/' . $zipped_file_name;
$views_zip = new ZipArchive;
$views_result = $views_zip->open($views_path);
if ($views_result === TRUE) {
$views_zip->extractTo($views_directory);
$views_zip->close();
}
// unzip the assets zip file to the assets/frontend folder
$assets_path = 'themes/' . $unzipped_file_name . '/assets/' . $zipped_file_name;
$assets_zip = new ZipArchive;
$assets_result = $assets_zip->open($assets_path);
if ($assets_result === TRUE) {
$assets_zip->extractTo($assets_directory);
$assets_zip->close();
}
unlink($theme_path);
$this->crud_model->remove_files_and_folders('themes/' . $unzipped_file_name);
$this->session->set_flashdata('flash_message', get_phrase('theme_imported_successfully'));
redirect(site_url('admin/theme_settings'));
}
//ADDON MANAGER PORTION STARTS HERE
public function addon($param1 = "", $param2 = "", $param3 = "")
{
if ($this->session->userdata('admin_login') != 1) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('addon');
// ADD NEW ADDON FORM
if ($param1 == 'add') {
// CHECK ACCESS PERMISSION
check_permission('addon');
$page_data['page_name'] = 'addon_add';
$page_data['page_title'] = get_phrase('add_addon');
}
if ($param1 == 'update') {
// CHECK ACCESS PERMISSION
check_permission('addon');
$page_data['page_name'] = 'addon_update';
$page_data['page_title'] = get_phrase('add_update');
}
// INSTALLING AN ADDON
if ($param1 == 'install' || $param1 == 'version_update') {
// CHECK ACCESS PERMISSION
check_permission('addon');
$this->addon_model->install_addon($param1);
}
// ACTIVATING AN ADDON
if ($param1 == 'activate') {
$update_message = $this->addon_model->addon_activate($param2);
$this->session->set_flashdata('flash_message', get_phrase($update_message));
redirect(site_url('admin/addon'), 'refresh');
}
// DEACTIVATING AN ADDON
if ($param1 == 'deactivate') {
$update_message = $this->addon_model->addon_deactivate($param2);
$this->session->set_flashdata('flash_message', get_phrase($update_message));
redirect(site_url('admin/addon'), 'refresh');
}
// REMOVING AN ADDON
if ($param1 == 'delete') {
$this->addon_model->addon_delete($param2);
$this->session->set_flashdata('flash_message', get_phrase('addon_is_deleted_successfully'));
redirect(site_url('admin/addon'), 'refresh');
}
// SHOWING LIST OF INSTALLED ADDONS
if (empty($param1)) {
$page_data['page_name'] = 'addons';
$page_data['addons'] = $this->addon_model->addon_list()->result_array();
$page_data['page_title'] = get_phrase('addon_manager');
}
$this->load->view('backend/index', $page_data);
}
public function instructor_application($param1 = "", $param2 = "")
{ // param1 is the status and param2 is the application id
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
// CHECK ACCESS PERMISSION
check_permission('instructor');
if ($param1 == 'approve' || $param1 == 'delete') {
$this->user_model->update_status_of_application($param1, $param2);
}
$page_data['page_name'] = 'application_list';
$page_data['page_title'] = get_phrase('instructor_application');
$page_data['approved_applications'] = $this->user_model->get_approved_applications();
$page_data['pending_applications'] = $this->user_model->get_pending_applications();
$this->load->view('backend/index', $page_data);
}
// INSTRUCTOR PAYOUT SECTION
public function instructor_payout($param1 = "")
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
// CHECK ACCESS PERMISSION
check_permission('instructor');
if ($param1 != "") {
$date_range = $this->input->get('date_range');
$date_range = explode(" - ", $date_range);
$page_data['timestamp_start'] = strtotime($date_range[0]);
$page_data['timestamp_end'] = strtotime($date_range[1]);
} else {
$page_data['timestamp_start'] = strtotime(date('m/01/Y'));
$page_data['timestamp_end'] = strtotime(date('m/t/Y'));
}
$page_data['page_name'] = 'instructor_payout';
$page_data['page_title'] = get_phrase('instructor_payout');
$page_data['completed_payouts'] = $this->crud_model->get_completed_payouts_by_date_range($page_data['timestamp_start'], $page_data['timestamp_end']);
$page_data['pending_payouts'] = $this->crud_model->get_pending_payouts();
$this->load->view('backend/index', $page_data);
}
// ADMINS SECTION STARTS
public function admins($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('admin');
if ($param1 == "add") {
// CHECK ACCESS PERMISSION
check_permission('admin');
$this->user_model->add_user(false, true); // PROVIDING TRUE FOR INSTRUCTOR
redirect(site_url('admin/admins'), 'refresh');
} elseif ($param1 == "edit") {
// CHECK ACCESS PERMISSION
check_permission('admin');
$this->user_model->edit_user($param2);
redirect(site_url('admin/admins'), 'refresh');
} elseif ($param1 == "delete") {
// CHECK ACCESS PERMISSION
check_permission('admin');
$this->user_model->delete_user($param2);
redirect(site_url('admin/admins'), 'refresh');
}
$page_data['page_name'] = 'admins';
$page_data['page_title'] = get_phrase('admins');
$page_data['admins'] = $this->user_model->get_admins()->result_array();
$this->load->view('backend/index', $page_data);
}
public function admin_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'add_admin_form') {
// CHECK ACCESS PERMISSION
check_permission('admin');
$page_data['page_name'] = 'admin_add';
$page_data['page_title'] = get_phrase('admin_add');
$this->load->view('backend/index', $page_data);
} elseif ($param1 == 'edit_admin_form') {
// CHECK ACCESS PERMISSION
check_permission('admin');
$page_data['page_name'] = 'admin_edit';
$page_data['user_id'] = $param2;
$page_data['page_title'] = get_phrase('admin_edit');
$this->load->view('backend/index', $page_data);
}
}
public function permissions()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('admin');
if (!isset($_GET['permission_assing_to']) || empty($_GET['permission_assing_to'])) {
$this->session->set_flashdata('error_message', get_phrase('you_have_select_an_admin_first'));
redirect(site_url('admin/admins'), 'refresh');
}
$page_data['permission_assing_to'] = $this->input->get('permission_assing_to');
$user_details = $this->user_model->get_all_user($page_data['permission_assing_to']);
if ($user_details->num_rows() == 0) {
$this->session->set_flashdata('error_message', get_phrase('invalid_admin'));
redirect(site_url('admin/admins'), 'refresh');
} else {
$user_details = $user_details->row_array();
if ($user_details['role_id'] != 1) {
$this->session->set_flashdata('error_message', get_phrase('invalid_admin'));
redirect(site_url('admin/admins'), 'refresh');
}
if (is_root_admin($user_details['id'])) {
$this->session->set_flashdata('error_message', get_phrase('you_can_not_set_permission_to_the_root_admin'));
redirect(site_url('admin/admins'), 'refresh');
}
}
$page_data['permission_assign_to'] = $user_details;
$page_data['page_name'] = 'admin_permission';
$page_data['page_title'] = get_phrase('assign_permission');
$this->load->view('backend/index', $page_data);
}
// ASSIGN PERMISSION TO ADMIN
public function assign_permission()
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('admin');
echo $this->user_model->assign_permission();
}
// REMOVING INSTRUCTOR FROM COURSE
public function remove_an_instructor($course_id, $instructor_id)
{
// CHECK ACCESS PERMISSION
check_permission('course');
$course_details = $this->crud_model->get_course_by_id($course_id)->row_array();
if ($course_details['creator'] == $instructor_id) {
$this->session->set_flashdata('error_message', get_phrase('course_creator_can_be_removed'));
redirect('admin/course_form/course_edit/' . $course_id);
}
if ($course_details['multi_instructor']) {
$instructor_ids = explode(',', $course_details['user_id']);
if (in_array($instructor_id, $instructor_ids)) {
if (count($instructor_ids) > 1) {
if (($key = array_search($instructor_id, $instructor_ids)) !== false) {
unset($instructor_ids[$key]);
$data['user_id'] = implode(",", $instructor_ids);
$this->db->where('id', $course_id);
$this->db->update('course', $data);
$this->session->set_flashdata('flash_message', get_phrase('instructor_has_been_removed'));
if ($this->session->userdata('user_id') == $instructor_id) {
redirect('admin/courses/');
} else {
redirect('admin/course_form/course_edit/' . $course_id);
}
}
} else {
$this->session->set_flashdata('error_message', get_phrase('a_course_should_have_at_least_one_instructor'));
redirect('admin/course_form/course_edit/' . $course_id);
}
} else {
$this->session->set_flashdata('error_message', get_phrase('invalid_instructor_id'));
redirect('admin/course_form/course_edit/' . $course_id);
}
} else {
$this->session->set_flashdata('error_message', get_phrase('a_course_should_have_at_least_one_instructor'));
redirect('admin/course_form/course_edit/' . $course_id);
}
}
/** Coupons functionality starts */
public function coupons($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('coupon');
if ($param1 == "add") {
// CHECK ACCESS PERMISSION
check_permission('coupon');
$response = $this->crud_model->add_coupon(); // PROVIDING TRUE FOR INSTRUCTOR
$response ? $this->session->set_flashdata('flash_message', get_phrase('coupon_added_successfully')) : $this->session->set_flashdata('error_message', get_phrase('coupon_code_already_exists'));
redirect(site_url('admin/coupons'), 'refresh');
} elseif ($param1 == "edit") {
// CHECK ACCESS PERMISSION
check_permission('coupon');
$response = $this->crud_model->edit_coupon($param2);
$response ? $this->session->set_flashdata('flash_message', get_phrase('coupon_updated_successfully')) : $this->session->set_flashdata('error_message', get_phrase('coupon_code_already_exists'));
redirect(site_url('admin/coupons'), 'refresh');
} elseif ($param1 == "delete") {
// CHECK ACCESS PERMISSION
check_permission('coupon');
$response = $this->crud_model->delete_coupon($param2);
$response ? $this->session->set_flashdata('flash_message', get_phrase('coupon_deleted_successfully')) : $this->session->set_flashdata('error_message', get_phrase('coupon_code_already_exists'));
redirect(site_url('admin/coupons'), 'refresh');
}
$page_data['page_name'] = 'coupons';
$page_data['page_title'] = get_phrase('coupons');
$page_data['coupons'] = $this->crud_model->get_coupons()->result_array();
$this->load->view('backend/index', $page_data);
}
public function coupon_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHECK ACCESS PERMISSION
check_permission('coupon');
if ($param1 == 'add_coupon_form') {
$page_data['page_name'] = 'coupon_add';
$page_data['page_title'] = get_phrase('add_coupons');
$this->load->view('backend/index', $page_data);
} elseif ($param1 == 'edit_coupon_form') {
$page_data['page_name'] = 'coupon_edit';
$page_data['coupon'] = $this->crud_model->get_coupons($param2)->row_array();
$page_data['page_title'] = get_phrase('coupon_edit');
$this->load->view('backend/index', $page_data);
}
}
// ADMINS SECTION ENDS
// AJAX PORTION
// this function is responsible for managing multiple choice question
function manage_multiple_choices_options()
{
$page_data['number_of_options'] = $this->input->post('number_of_options');
$this->load->view('backend/admin/manage_multiple_choices_options', $page_data);
}
public function ajax_get_sub_category($category_id)
{
$page_data['sub_categories'] = $this->crud_model->get_sub_categories($category_id);
return $this->load->view('backend/admin/ajax_get_sub_category', $page_data);
}
public function ajax_get_section($course_id)
{
$page_data['sections'] = $this->crud_model->get_section('course', $course_id)->result_array();
return $this->load->view('backend/admin/ajax_get_section', $page_data);
}
public function ajax_get_video_details()
{
$video_details = $this->video_model->getVideoDetails($_POST['video_url']);
echo $video_details['duration'];
}
public function ajax_sort_section()
{
$section_json = $this->input->post('itemJSON');
$this->crud_model->sort_section($section_json);
}
public function ajax_sort_lesson()
{
$lesson_json = $this->input->post('itemJSON');
$this->crud_model->sort_lesson($lesson_json);
}
public function ajax_sort_question()
{
$question_json = $this->input->post('itemJSON');
$this->crud_model->sort_question($question_json);
}
}
/application/controllers/Api.php
<?php
require APPPATH . '/libraries/TokenHandler.php';
//include Rest Controller library
require APPPATH . 'libraries/REST_Controller.php';
class Api extends REST_Controller {
protected $token;
public function __construct()
{
parent::__construct();
$this->load->database();
// creating object of TokenHandler class at first
$this->tokenHandler = new TokenHandler();
header('Content-Type: application/json');
}
// Unprotected routes will be located here.
// Fetch all the top courses
public function top_courses_get($top_course_id = "") {
$top_courses = array();
$top_courses = $this->api_model->top_courses_get($top_course_id);
$this->set_response($top_courses, REST_Controller::HTTP_OK);
}
public function app_logo_get(){
$response = array();
$response['banner_image'] = base_url('uploads/system/'.get_frontend_settings('banner_image'));
$response['light_logo'] = base_url('uploads/system/'.get_frontend_settings('light_logo'));
$response['dark_logo'] = base_url('uploads/system/'.get_frontend_settings('dark_logo'));
$response['small_logo'] = base_url('uploads/system/'.get_frontend_settings('small_logo'));
$response['favicon'] = base_url('uploads/system/'.get_frontend_settings('favicon'));
$this->set_response($response, REST_Controller::HTTP_OK);
}
// Fetch all the categories
public function categories_get($category_id = "") {
$categories = array();
$categories = $this->api_model->categories_get($category_id);
$this->set_response($categories, REST_Controller::HTTP_OK);
}
// Fetch all the courses belong to a certain category
public function category_wise_course_get() {
$category_id = $_GET['category_id'];
$courses = $this->api_model->category_wise_course_get($category_id);
$this->set_response($courses, REST_Controller::HTTP_OK);
}
// Fetch all the courses belong to a certain category
public function languages_get() {
$languages = $this->api_model->languages_get();
$this->set_response($languages, REST_Controller::HTTP_OK);
}
// Filter course
public function filter_course_get() {
$courses = $this->api_model->filter_course();
$this->set_response($courses, REST_Controller::HTTP_OK);
}
// Filter course
public function courses_by_search_string_get() {
$search_string = $_GET['search_string'];
$courses = $this->api_model->courses_by_search_string_get($search_string);
$this->set_response($courses, REST_Controller::HTTP_OK);
}
// get system settings
public function system_settings_get() {
$system_settings_data = $this->api_model->system_settings_get();
$this->set_response($system_settings_data, REST_Controller::HTTP_OK);
}
// Login Api
public function login_get() {
$userdata = $this->api_model->login_get();
if ($userdata['validity'] == 1) {
$userdata['token'] = $this->tokenHandler->GenerateToken($userdata);
}
return $this->set_response($userdata, REST_Controller::HTTP_OK);
}
public function course_object_by_id_get() {
$course = $this->api_model->course_object_by_id_get();
$this->set_response($course, REST_Controller::HTTP_OK);
}
//Protected APIs. This APIs will require Authorization.
// My Courses API
public function my_courses_get() {
$response = array();
$auth_token = $_GET['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->my_courses_get($logged_in_user_details['user_id']);
}else{
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// My Courses API
public function my_wishlist_get() {
$response = array();
$auth_token = $_GET['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->my_wishlist_get($logged_in_user_details['user_id']);
}else{
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// Get all the sections
public function sections_get() {
$response = array();
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->sections_get($course_id, $logged_in_user_details['user_id']);
}else{
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
//Get all lessons, section wise.
public function section_wise_lessons_get() {
$response = array();
$auth_token = $_GET['auth_token'];
$section_id = $_GET['section_id'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->section_wise_lessons($section_id, $logged_in_user_details['user_id']);
}else{
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// Remove from wishlist
public function toggle_wishlist_items_get() {
$auth_token = $_GET['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$status = $this->api_model->toggle_wishlist_items_get($logged_in_user_details['user_id'], $logged_in_user_details['user_id']);
}
$response['status'] = $status;
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// Lesson Details
public function lesson_details_get() {
$response = array();
$auth_token = $_GET['auth_token'];
$lesson_id = $_GET['lesson_id'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->lesson_details_get($logged_in_user_details['user_id'], $lesson_id);
}else{
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// Course Details
public function course_details_by_id_get() {
$response = array();
$course_id = $_GET['course_id'];
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$auth_token = $_GET['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
}else{
$logged_in_user_details['user_id'] = 0;
}
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->course_details_by_id_get($logged_in_user_details['user_id'], $course_id);
}else{
$response = $this->api_model->course_details_by_id_get(0, $course_id);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// submit quiz view
public function submit_quiz_post() {
$submitted_quiz_info = array();
$container = array();
$quiz_id = $this->input->post('lesson_id');
$quiz_questions = $this->crud_model->get_quiz_questions($quiz_id)->result_array();
$total_correct_answers = 0;
foreach ($quiz_questions as $quiz_question) {
$submitted_answer_status = 0;
$correct_answers = json_decode($quiz_question['correct_answers']);
$submitted_answers = array();
foreach ($this->input->post($quiz_question['id']) as $each_submission) {
if (isset($each_submission)) {
array_push($submitted_answers, $each_submission);
}
}
sort($correct_answers);
sort($submitted_answers);
if ($correct_answers == $submitted_answers) {
$submitted_answer_status = 1;
$total_correct_answers++;
}
$container = array(
"question_id" => $quiz_question['id'],
'submitted_answer_status' => $submitted_answer_status,
"submitted_answers" => json_encode($submitted_answers),
"correct_answers" => json_encode($correct_answers),
);
array_push($submitted_quiz_info, $container);
}
$page_data['submitted_quiz_info'] = $submitted_quiz_info;
$page_data['total_correct_answers'] = $total_correct_answers;
$page_data['total_questions'] = count($quiz_questions);
$this->load->view('lessons/quiz_result', $page_data);
}
public function save_course_progress_get() {
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$auth_token = $_GET['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_model->save_course_progress_get($logged_in_user_details['user_id']);
}else{
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
//Upload user image
public function upload_user_image_post() {
$response = array();
if (isset($_POST['auth_token']) && !empty($_POST['auth_token'])) {
$auth_token = $_POST['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
if (isset($_FILES['file']) && $_FILES['file']['name'] != "") {
$user_image = $this->db->get_where('users', array('id' => $logged_in_user_details['user_id']))->row('image').'.jpg';
if(file_exists('uploads/user_image/' . $user_image)){
unlink('uploads/user_image/' . $user_image);
}
$data['image'] = md5(rand(10000, 10000000));
$this->db->where('id', $logged_in_user_details['user_id']);
$this->db->update('users', $data);
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/user_image/'.$data['image'].'.jpg');
}
$response['status'] = 'success';
}
}else{
$response['status'] = 'failed';
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// update user data
public function update_userdata_post() {
$response = array();
if (isset($_POST['auth_token']) && !empty($_POST['auth_token'])) {
$auth_token = $_POST['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->update_userdata_post($logged_in_user_details['user_id']);
}
}else{
$response['status'] = 'failed';
$response['error_reason'] = get_phrase('unauthorized_login');
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// password reset
public function update_password_post() {
$response = array();
if (isset($_POST['auth_token']) && !empty($_POST['auth_token'])) {
$auth_token = $_POST['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_model->update_password_post($logged_in_user_details['user_id']);
}
}else{
$response['status'] = 'failed';
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// Get user data
public function userdata_get() {
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$auth_token = $_GET['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_model->userdata_get($logged_in_user_details['user_id']);
$response['status'] = 'success';
}else{
$response['status'] = 'failed';
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
// check whether certificate addon is installed and get certificate
public function certificate_addon_get() {
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$auth_token = $_GET['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
$user_id = $logged_in_user_details['user_id'];
$course_id = $_GET['course_id'];
$response = $this->api_model->certificate_addon_get($user_id, $course_id);
}else{
$response['status'] = 'failed';
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
/////////// Generating Token and put user data into token ///////////
//////// get data from token ////////////
public function GetTokenData()
{
$received_Token = $this->input->request_headers('Authorization');
if (isset($received_Token['Token'])) {
try
{
$jwtData = $this->tokenHandler->DecodeToken($received_Token['Token']);
return json_encode($jwtData);
}
catch (Exception $e)
{
http_response_code('401');
echo json_encode(array( "status" => false, "message" => $e->getMessage()));
exit;
}
}else{
echo json_encode(array( "status" => false, "message" => "Invalid Token"));
}
}
public function token_data_get($auth_token)
{
//$received_Token = $this->input->request_headers('Authorization');
if (isset($auth_token)) {
try
{
$jwtData = $this->tokenHandler->DecodeToken($auth_token);
return json_encode($jwtData);
}
catch (Exception $e)
{
echo 'catch';
http_response_code('401');
echo json_encode(array( "status" => false, "message" => $e->getMessage()));
exit;
}
}else{
echo json_encode(array( "status" => false, "message" => "Invalid Token"));
}
}
}
/application/controllers/Api_instructor.php
<?php
require APPPATH . '/libraries/TokenHandler.php';
//include Rest Controller library
require APPPATH . 'libraries/REST_Controller.php';
class Api_instructor extends REST_Controller {
protected $token;
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('api_instructor_model');
// creating object of TokenHandler class at first
$this->tokenHandler = new TokenHandler();
header('Content-Type: application/json');
}
public function token_data_get($auth_token)
{
if (isset($auth_token)) {
try
{
$jwtData = $this->tokenHandler->DecodeToken($auth_token);
return json_encode($jwtData);
}
catch (Exception $e)
{
echo 'catch';
http_response_code('401');
echo json_encode(array( "status" => false, "message" => $e->getMessage()));
exit;
}
}else{
echo json_encode(array( "status" => false, "message" => "Invalid Token"));
}
}
public function login_post() {
$userdata = $this->api_instructor_model->login_post();
if ($userdata['validity'] == 1) {
$userdata['token'] = $this->tokenHandler->GenerateToken($userdata);
}
return $this->set_response($userdata, REST_Controller::HTTP_OK);
}
public function change_password_post(){
$response = array();
if (isset($_POST['auth_token']) && !empty($_POST['auth_token']) && !empty($_POST['current_password']) && !empty($_POST['new_password']) && !empty($_POST['confirm_password'])) {
$auth_token = $_POST['auth_token'];
$logged_in_user_details = json_decode($this->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$response = $this->api_instructor_model->change_password_post($logged_in_user_details['user_id']);
}
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function forgot_password_post(){
$response = array();
if(isset($_POST['email']) && !empty($_POST['email'])){
$new_password = rand(10000, 100000);
$this->email_model->password_reset_email($new_password, $_POST['email']);
$this->api_instructor_model->forgot_password_post($new_password);
$response['message'] = get_phrase('new_password_successfully_has_been_send_to_your_inbox');
$response['status'] = 200;
$response['validity'] = true;
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function change_profile_photo_post(){
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$user_info = json_decode($this->token_data_get($_POST['auth_token']), true);
$response = $this->api_instructor_model->change_profile_photo_post($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function userdata_get(){
$userdata = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$auth_token = $_GET['auth_token'];
$user_info = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->userdata_get($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_userdata_post(){
$response = array();
if (isset($_POST['auth_token']) && !empty($_POST['auth_token'])) {
$user_info = json_decode($this->token_data_get($_POST['auth_token']), true);
$response = $this->api_instructor_model->update_userdata_post($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function courses_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->courses_get($user_details['user_id']);
return $this->set_response($response, REST_Controller::HTTP_OK);
}
}
public function add_course_form_get() {
$response = array();
$response = $this->api_instructor_model->add_course_form_get();
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function add_course_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$auth_token = $_POST['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->add_course_post($user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function edit_course_form_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token']) && isset($_GET['course_id']) && !empty($_GET['course_id'])){
$course_id = $_GET['course_id'];
$auth_token = $_GET['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->edit_course_form_get($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_course_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$auth_token = $_POST['auth_token'];
$course_id = $_POST['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->update_course_post($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_course_status_get(){
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$status = $_GET['status'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->update_course_status_get($course_id, $status, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function edit_course_requirements_get(){
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->edit_course_requirements_get($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_course_requirements_post(){
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$auth_token = $_POST['auth_token'];
$course_id = $_POST['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->update_course_requirements_post($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function edit_course_outcomes_get(){
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->edit_course_outcomes_get($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_course_outcomes_post(){
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$auth_token = $_POST['auth_token'];
$course_id = $_POST['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->update_course_outcomes_post($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function delete_course_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->delete_course_get($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function section_and_lesson_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token']) && isset($_GET['course_id']) && !empty($_GET['course_id'])){
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->section_and_lesson_get($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function sections_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token']) && isset($_GET['course_id']) && !empty($_GET['course_id'])){
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->sections_get($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function add_section_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token']) && isset($_POST['course_id']) && !empty($_POST['course_id'])){
$auth_token = $_POST['auth_token'];
$course_id = $_POST['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->add_section_post($course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_section_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token']) && isset($_POST['section_id']) && !empty($_POST['section_id'])){
$auth_token = $_POST['auth_token'];
$section_id = $_POST['section_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->update_section_post($section_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function delete_section_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token']) && isset($_POST['section_id']) && !empty($_POST['section_id']) && isset($_POST['course_id']) && !empty($_POST['course_id'])){
$auth_token = $_POST['auth_token'];
$course_id = $_POST['course_id'];
$section_id = $_POST['section_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->delete_section_post($section_id, $course_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function add_lesson_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token']) && isset($_POST['course_id']) && !empty($_POST['course_id']) && isset($_POST['section_id']) && !empty($_POST['section_id'])){
$auth_token = $_POST['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->add_lesson_post($user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function lesson_all_data_get(){
$response = array();
if(isset($_GET['lesson_id']) && !empty($_GET['lesson_id'])){
$response = $this->api_instructor_model->lesson_all_data_get($_GET['lesson_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_lesson_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token']) && isset($_POST['lesson_id']) && !empty($_POST['lesson_id'])){
$auth_token = $_POST['auth_token'];
$lesson_id = $_POST['lesson_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->update_lesson_post($lesson_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function delete_lesson_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token']) && isset($_GET['lesson_id']) && !empty($_GET['lesson_id'])){
$auth_token = $_GET['auth_token'];
$lesson_id = $_GET['lesson_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->delete_lesson_get($lesson_id, $user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function sort_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$auth_token = $_POST['auth_token'];
$type = $_POST['type'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->sort_post($user_details['user_id'], $type);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function course_pricing_form_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$course_id = $_GET['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->course_pricing_form_get($user_details['user_id'], $course_id);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_course_price_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$auth_token = $_POST['auth_token'];
$course_id = $_POST['course_id'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->update_course_price_post($user_details['user_id'], $course_id);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function sales_report_get(){
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->sales_report_get($user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function details_of_sales_report_get(){
$response = array();
if(isset($_GET['payment_id']) && !empty($_GET['payment_id'])){
$payment_id = $_GET['payment_id'];
$response = $this->api_instructor_model->details_of_sales_report_get($payment_id);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function payout_report_get(){
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->payout_report_get($user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function add_withdrawal_request_post() {
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$auth_token = $_POST['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->add_withdrawal_request_post($user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function delete_withdrawal_request_get() {
$response = array();
if(isset($_GET['auth_token']) && !empty($_GET['auth_token'])){
$auth_token = $_GET['auth_token'];
$user_details = json_decode($this->token_data_get($auth_token), true);
$response = $this->api_instructor_model->delete_withdrawal_request_get($user_details['user_id']);
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
}
/application/controllers/Checker.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Mobile extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->database();
//Authenticate data manipulation with the user level security key
if ($this->validate_auth_key() != 'success')
die;
}
// response of class list
function get_class()
{
$response = array();
$classes = $this->db->get('class')->result_array();
foreach ($classes as $row) {
$data['class_id'] = $row['class_id'];
$data['name'] = $row['name'];
$data['name_numeric'] = $row['name_numeric'];
$data['teacher_id'] = $row['teacher_id'];
$sections = $this->db->get_where('section', array(
'class_id' => $row['class_id']
))->result_array();
$data['sections'] = $sections;
array_push($response, $data);
}
echo json_encode($response);
}
// returns image of user, returns blank image if not found.
function get_image_url($type = '', $id = '')
{
$type = $this->input->post('user_type');
$id = $this->input->post('user_id');
$response = array();
if (file_exists('uploads/' . $type . '_image/' . $id . '.jpg'))
$response['image_url'] = base_url() . 'uploads/' . $type . '_image/' . $id . '.jpg';
else
$response['image_url'] = base_url() . 'uploads/user.jpg';
echo json_encode($response);
}
// returns system name and logo as public call
function get_system_info()
{
$response['system_name'] = $this->db->get_where('settings', array(
'type' => 'system_name'
))->row()->description;
echo json_encode($response);
}
// returns the students of a specific class according to requested class_id
// ** class_id, year required to get students from enroll table
function get_students_of_class()
{
$response = array();
$class_id = $this->input->post('class_id');
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$students = $this->db->get_where('enroll', array(
'class_id' => $class_id,
'year' => $running_year
))->result_array();
foreach ($students as $row) {
$data['student_id'] = $row['student_id'];
$data['roll'] = $row['roll'];
$data['name'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->name;
$data['birthday'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->birthday;
$data['gender'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->sex;
$data['address'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->address;
$data['phone'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->phone;
$data['email'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->email;
$data['class'] = $this->db->get_where('class', array(
'class_id' => $row['class_id']
))->row()->name;
$data['section'] = $this->db->get_where('section', array(
'section_id' => $row['section_id']
))->row()->name;
$parent_id = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->parent_id;
$data['parent_name'] = $this->db->get_where('parent', array(
'parent_id' => $parent_id
))->row()->name;
$data['image_url'] = $this->crud_model->get_image_url('student', $row['student_id']);
array_push($response, $data);
}
echo json_encode($response);
}
// get students basic info
function get_student_profile_information()
{
$response = array();
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$student_id = $this->input->post('student_id');
$roll = $this->db->get_where('enroll', array(
'student_id' => $student_id,
'year' => $running_year
))->row()->roll;
$class_id = $this->db->get_where('enroll', array(
'student_id' => $student_id,
'year' => $running_year
))->row()->class_id;
$section_id = $this->db->get_where('enroll', array(
'student_id' => $student_id,
'year' => $running_year
))->row()->section_id;
$student_profile = $this->db->get_where('student', array(
'student_id' => $student_id
))->result_array();
foreach ($student_profile as $row) {
$data['student_id'] = $row['student_id'];
$data['name'] = $row['name'];
$data['birthday'] = $row['birthday'];
$data['gender'] = $row['sex'];
$data['address'] = $row['address'];
$data['phone'] = $row['phone'];
$data['email'] = $row['email'];
$data['roll'] = $roll;
$data['class'] = $class_id;
$data['section'] = $section_id;
$data['parent_name'] = $this->db->get_where('parent', array(
'parent_id' => $row['parent_id']
))->row()->name;
$data['image_url'] = $this->crud_model->get_image_url('student', $row['student_id']);
array_push($response, $data);
}
echo json_encode($response);
}
// get student's mark info
// ** exam_id, student_id, year required to get students from mark table
function get_student_mark_information()
{
$response = array();
$mark_array = array();
$exam_id = $this->input->post('exam_id');
$student_id = $this->input->post('student_id');
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$student_marks = $this->db->get_where('mark', array(
'exam_id' => $exam_id,
'student_id' => $student_id,
'year' => $running_year
))->result_array();
$response['exam_id'] = $exam_id;
foreach ($student_marks as $row) {
$data['mark_obtained'] = $row['mark_obtained'];
$data['subject'] = $this->db->get_where('subject', array(
'subject_id' => $row['subject_id'],
'year' => $running_year
))->row()->name;
$grade = $this->crud_model->get_grade($row['mark_obtained']);
$data['grade'] = $grade['name'];
array_push($mark_array, $data);
}
$response['marks'] = $mark_array;
echo json_encode($response);
}
// teacher list of the school
function get_teachers()
{
$response = array();
$teachers = $this->db->get('teacher')->result_array();
foreach ($teachers as $row) {
$data['teacher_id'] = $row['teacher_id'];
$data['name'] = $row['name'];
$data['birthday'] = $row['birthday'];
$data['gender'] = $row['sex'];
$data['address'] = $row['address'];
$data['phone'] = $row['phone'];
$data['email'] = $row['email'];
$data['image_url'] = $this->crud_model->get_image_url('teacher', $row['teacher_id']);
array_push($response, $data);
}
echo json_encode($response);
}
// teacher profile information
function get_teacher_profile()
{
$response = array();
$teacher_id = $this->input->post('teacher_id');
$response = $this->db->get_where('teacher', array(
'teacher_id' => $teacher_id
))->row();
echo json_encode($response);
}
// get parent list
function get_parents()
{
$response = array();
$parents = $this->db->get('parent')->result_array();
foreach ($parents as $row) {
$data['parent_id'] = $row['parent_id'];
$data['name'] = $row['name'];
$data['profession'] = $row['profession'];
$data['address'] = $row['address'];
$data['phone'] = $row['phone'];
$data['email'] = $row['email'];
$data['image_url'] = $this->crud_model->get_image_url('parent', $row['parent_id']);
array_push($response, $data);
}
echo json_encode($response);
}
// get single parent profile
function get_parent_profile()
{
$response = array();
$parent_id = $this->input->post('parent_id');
$response = $this->db->get_where('parent', array(
'parent_id' => $parent_id
))->row();
echo json_encode($response);
}
// income or expense history of school of submitted month
function get_accounting()
{
$response = array();
$month = $this->input->post('month');
$year = $this->input->post('year');
$type = $this->input->post('type');
$start_timestamp = strtotime("1-" . $month . "-" . $year);
$end_timestamp = strtotime("30-" . $month . "-" . $year);
$this->db->where("timestamp >=", $start_timestamp);
$this->db->where("timestamp <=", $end_timestamp);
$this->db->where("payment_type", $type);
$response = $this->db->get('payment')->result_array();
echo json_encode($response);
}
// attendance data response
// ** timestamp, year, class_id, section_id, student_id to get attendance from attendance table
function get_attendance()
{
$response = array();
$date = $this->input->post('date');
$month = $this->input->post('month');
$year = $this->input->post('year');
$class_id = $this->input->post('class_id');
$timestamp = strtotime($date . '-' . $month . '-' . $year);
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$students = $this->db->get_where('enroll', array(
'class_id' => $class_id,
'year' => $running_year
))->result_array();
foreach ($students as $row) {
$data['student_id'] = $row['student_id'];
$data['roll'] = $row['roll'];
$data['name'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->name;
$attendance_query = $this->db->get_where('attendance', array(
'timestamp' => $timestamp,
'student_id' => $row['student_id']
));
if ($attendance_query->num_rows() > 0) {
$attendance_result_row = $attendance_query->row();
$data['status'] = $attendance_result_row->status;
} else {
$data['status'] = '0';
}
array_push($response, $data);
}
echo json_encode($response);
}
// class routine : class and weekly day wise
// ** class_id, section_id, subject_id, year to get section wise class routine from class_routine table
function get_class_routine()
{
$response = array();
$class_id = $this->input->post('class_id');
$section_id = $this->input->post('section_id');
$day = $this->input->post('day');
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$class_routines = $this->db->get_where('class_routine', array(
'class_id' => $class_id,
'section_id' => $section_id,
'day' => $day,
'year' => $running_year
))->result_array();
foreach ($class_routines as $row) {
$data['class_id'] = $row['class_id'];
$data['subject'] = $this->db->get_where('subject', array(
'subject_id' => $row['subject_id'],
'year' => $running_year
))->row()->name;
$data['time_start'] = $row['time_start'];
$data['time_end'] = $row['time_end'];
$data['time_start_min'] = $row['time_start_min'];
$data['time_end_min'] = $row['time_end_min'];
$data['day'] = $row['day'];
array_push($response, $data);
}
echo json_encode($response);
}
// get subject name of subject_id
function get_subject_name()
{
$response = array();
$subject_id = $this->input->post('subject_id');
$response = $this->db->get_where('subject', array(
'subject_id' => $subject_id
))->row();
echo json_encode($response);
}
// event calendar or noticeboard event list
function get_event_calendar()
{
$response = array();
$response = $this->db->get('noticeboard')->result_array();
echo json_encode($response);
}
// exam list
// ** year required to get exam list from exam table
function get_exam_list()
{
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$response = array();
$response = $this->db->get_where('exam', array(
'year' => $running_year
))->result_array();
echo json_encode($response);
}
// get subjects of a class
// ** class_id, year required to get subjects of a class from subject table
function get_subject_of_class()
{
$response = array();
$class_id = $this->input->post('class_id');
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$subjects = $this->db->get_where('subject', array(
'class_id' => $class_id,
'year' => $running_year
))->result_array();
foreach ($subjects as $row) {
$data['subject_id'] = $row['subject_id'];
$data['name'] = $row['name'];
$teacher_query = $this->db->get_where('teacher', array(
'teacher_id' => $row['teacher_id']
));
if ($teacher_query->num_rows() > 0) {
$teacher_query_row = $teacher_query->row();
$data['teacher_name'] = $teacher_query_row->name;
} else {
$data['teacher_name'] = '';
}
array_push($response, $data);
}
echo json_encode($response);
}
// student mark list, subject, class, exam wise
// ** exam_id, class_id, subject_id, year required to get student wise marks
function get_marks()
{
$response = array();
$exam_id = $this->input->post('exam_id');
$class_id = $this->input->post('class_id');
$subject_id = $this->input->post('subject_id');
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$marks = $this->db->get_where('mark', array(
'exam_id' => $exam_id,
'class_id' => $class_id,
'subject_id' => $subject_id,
'year' => $running_year
))->result_array();
foreach ($marks as $row) {
$data['class_id'] = $row['class_id'];
$data['student_id'] = $row['student_id'];
$data['student_name'] = $this->db->get_where('student', array(
'student_id' => $row['student_id']
))->row()->name;
$data['student_roll'] = $this->db->get_where('enroll', array(
'student_id' => $row['student_id'],
'year' => $running_year
))->row()->roll;
$data['exam_id'] = $row['exam_id'];
$data['mark_obtained'] = $row['mark_obtained'];
array_push($response, $data);
}
echo json_encode($response);
}
function get_loggedin_user_profile()
{
$response = array();
$login_type = $this->input->post('login_type');
$login_user_id = $this->input->post('login_user_id');
$user_profile = $this->db->get_where($login_type, array(
$login_type . '_id' => $login_user_id
))->result_array();
foreach ($user_profile as $row) {
$data['name'] = $row['name'];
$data['email'] = $row['email'];
$data['image_url'] = $this->crud_model->get_image_url($login_type, $login_user_id);
break;
}
array_push($response, $data);
echo json_encode($response);
}
function update_user_image()
{
$response = array();
$user_type = $this->input->post('login_type');
$user_id = $this->input->post('login_user_id');
$directory = 'uploads/' . $user_type . '_image/' . $user_id . '.jpg';
move_uploaded_file($_FILES['user_image']['tmp_name'], $directory);
$response = array(
'update_status' => 'success'
);
echo json_encode($response);
}
function update_user_info()
{
$response = array();
$user_type = $this->input->post('login_type');
$user_id = $this->input->post('login_user_id');
$data['name'] = $this->input->post('name');
$data['email'] = $this->input->post('email');
$this->db->where($user_type . '_id', $user_id);
$this->db->update($user_type, $data);
$response = array(
'update_status' => 'success'
);
echo json_encode($response);
}
function update_user_password()
{
$response = array();
$user_type = $this->input->post('login_type');
$user_id = $this->input->post('login_user_id');
$old_password = sha1($this->input->post('old_password'));
$data['password'] = sha1($this->input->post('new_password'));
// verify if old password matches
$this->db->where($user_type . '_id', $user_id);
$this->db->where('password', $old_password);
$verify_query = $this->db->get($user_type);
if ($verify_query->num_rows() > 0) {
$this->db->where($user_type . '_id', $user_id);
$this->db->update($user_type, $data);
$response = array(
'update_status' => 'success'
);
} else {
$response = array(
'update_status' => 'failed'
);
}
echo json_encode($response);
}
// total number of students
// ** year required to get total student from enrollment table
// ** timestamp, status required to get todays present students from student table
function get_total_summary()
{
$response = array();
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$this->db->where('year', $running_year);
$this->db->from('enroll');
$response['total_student'] = $this->db->count_all_results();
$response['total_teacher'] = $this->db->count_all('teacher');
$response['total_parent'] = $this->db->count_all('parent');
// student present today
$check = array(
'timestamp' => strtotime(date('d-m-Y')),
'status' => '1'
);
$query = $this->db->get_where('attendance', $check);
$present_today = $query->num_rows();
$response['total_present_today'] = $present_today;
echo json_encode($response);
}
// dummy function
function getdata()
{
$response = array();
$postvar = $this->input->post('postvar');
$response = $this->db->get_where('table', array(
'postvar' => $postvar
))->result_array();
echo json_encode($response);
}
// Parents functions : own child list, class routine, exam marks of child, invoice of child, event schedule
function get_children_of_parent()
{
$response = array();
$parent_id = $this->input->post('parent_id');
$response['children'] = $this->db->get_where('student', array(
'parent_id' => $parent_id
))->result_array();
echo json_encode($response);
}
function get_child_class_routine()
{
}
function get_child_exam_marks()
{
}
function get_child_accounting()
{
}
// Students functions : own child list, class routine, exam marks of child, invoice of child, event schedule
function get_own_subjects()
{
}
function get_own_class_routine()
{
}
function get_own_marks()
{
}
function get_single_student_accounting()
{
$response = array();
$student_id = $this->input->post("student_id");
$this->db->where("student_id", $student_id);
$response = $this->db->get('invoice')->result_array();
echo json_encode($response);
}
// user login matching with db
function login()
{
$response = array();
$email = $this->input->post("email");
$password = sha1($this->input->post("password"));
// Checking login credential for admin
$query = $this->db->get_where('admin', array(
'email' => $email,
'password' => $password
));
if ($query->num_rows() > 0) {
$row = $query->row();
$authentication_key = md5(rand(10000, 1000000));
$response['status'] = 'success';
$response['login_type'] = 'admin';
$response['login_user_id'] = $row->admin_id;
$response['name'] = $row->name;
$response['authentication_key'] = $authentication_key;
// update the new authentication key into user table
$this->db->where('admin_id', $row->admin_id);
$this->db->update('admin', array(
'authentication_key' => $authentication_key
));
echo json_encode($response);
return;
}
// Checking login credential for teacher
$query = $this->db->get_where('teacher', array(
'email' => $email,
'password' => $password
));
if ($query->num_rows() > 0) {
$row = $query->row();
$authentication_key = md5(rand(10000, 1000000));
$response['status'] = 'success';
$response['login_type'] = 'teacher';
$response['login_user_id'] = $row->teacher_id;
$response['name'] = $row->name;
$response['authentication_key'] = $authentication_key;
// update the new authentication key into user table
$this->db->where('teacher_id', $row->teacher_id);
$this->db->update('teacher', array(
'authentication_key' => $authentication_key
));
echo json_encode($response);
return;
}
// Checking login credential for student
$query = $this->db->get_where('student', array(
'email' => $email,
'password' => $password
));
if ($query->num_rows() > 0) {
$running_year = $this->db->get_where('settings', array(
'type' => 'running_year'
))->row()->description;
$row = $query->row();
$authentication_key = md5(rand(10000, 1000000));
$response['status'] = 'success';
$response['login_type'] = 'student';
$response['login_user_id'] = $row->student_id;
$response['name'] = $row->name;
$response['authentication_key'] = $authentication_key;
$response['class_id'] = $this->db->get_where('enroll', array(
'student_id' => $row->student_id,
'year' => $running_year
))->row()->class_id;
$response['section_id'] = $this->db->get_where('enroll', array(
'student_id' => $row->student_id,
'year' => $running_year
))->row()->section_id;
// update the new authentication key into user table
$this->db->where('student_id', $row->student_id);
$this->db->update('student', array(
'authentication_key' => $authentication_key
));
echo json_encode($response);
return;
}
// Checking login credential for parent
$query = $this->db->get_where('parent', array(
'email' => $email,
'password' => $password
));
if ($query->num_rows() > 0) {
$row = $query->row();
$authentication_key = md5(rand(10000, 1000000));
$response['status'] = 'success';
$response['login_type'] = 'parent';
$response['login_user_id'] = $row->parent_id;
$response['name'] = $row->name;
$response['authentication_key'] = $authentication_key;
$response['children'] = $this->db->get_where('student', array(
'parent_id' => $row->parent_id
))->result_array();
// update the new authentication key into user table
$this->db->where('parent_id', $row->parent_id);
$this->db->update('parent', array(
'authentication_key' => $authentication_key
));
echo json_encode($response);
return;
} else {
$response['status'] = 'failed';
}
echo json_encode($response);
}
// forgot password link
function reset_password()
{
$response = array();
$response['status'] = 'false';
$email = $_POST["email"];
$reset_account_type = '';
//resetting user password here
$new_password = substr(rand(100000000, 20000000000), 0, 7);
// Checking credential for admin
$query = $this->db->get_where('admin', array(
'email' => $email
));
if ($query->num_rows() > 0) {
$reset_account_type = 'admin';
$this->db->where('email', $email);
$this->db->update('admin', array(
'password' => sha1($new_password)
));
$response['status'] = 'true';
}
// Checking credential for student
$query = $this->db->get_where('student', array(
'email' => $email
));
if ($query->num_rows() > 0) {
$reset_account_type = 'student';
$this->db->where('email', $email);
$this->db->update('student', array(
'password' => sha1($new_password)
));
$response['status'] = 'true';
}
// Checking credential for teacher
$query = $this->db->get_where('teacher', array(
'email' => $email
));
if ($query->num_rows() > 0) {
$reset_account_type = 'teacher';
$this->db->where('email', $email);
$this->db->update('teacher', array(
'password' => sha1($new_password)
));
$response['status'] = 'true';
}
// Checking credential for parent
$query = $this->db->get_where('parent', array(
'email' => $email
));
if ($query->num_rows() > 0) {
$reset_account_type = 'parent';
$this->db->where('email', $email);
$this->db->update('parent', array(
'password' => sha1($new_password)
));
$response['status'] = 'true';
}
// send new password to user email
$this->email_model->password_reset_email($new_password, $reset_account_type, $email);
echo json_encode($response);
}
function get_notices()
{
$response = array();
$query = $this->db->get("noticeboard")->result_array();
foreach ($query as $row) {
$data['notice_id'] = $row['notice_id'];
$data['notice_title'] = $row['notice_title'];
$data['notice'] = $row['notice'];
$data['date'] = date('d-M-Y', $row['create_timestamp']);
array_push($response, $data);
}
echo json_encode($response);
}
// private messaging
// @ $user -> user_type-user_id -> admin-1
function get_message_threads() {
$response = array();
$user = $this->input->post('user');
$this->db->where('sender', $user);
$this->db->or_where('reciever', $user);
$threads = $this->db->get('message_thread')->result_array();
foreach ($threads as $row) {
$sender = explode('-', $row['sender']);
$receiver = explode('-', $row['reciever']);
$sender_name = $this->db->get_where($sender[0], array($sender[0].'_id' => $sender[1]))->row()->name;
$receiver_name = $this->db->get_where($receiver[0], array($receiver[0].'_id' => $receiver[1]))->row()->name;
$user_type = ($user == $row['sender']) ? $receiver[0] : $sender[0];
$user_name = ($user == $row['sender']) ? $receiver_name : $sender_name;
$user_id = ($user == $row['sender']) ? $receiver[1] : $sender[1];
if (file_exists('uploads/'.$user_type.'_image/'.$user_id.'.jpg'))
$image_url = base_url('uploads/'.$user_type.'_image/'.$user_id.'.jpg');
else
$image_url = base_url('uploads/user.jpg');
$data['message_thread_code'] = $row['message_thread_code'];
$data['user_type'] = $user_type;
$data['user_name'] = $user_name;
$data['image_url'] = $image_url;
array_push($response, $data);
}
echo json_encode($response);
}
function get_messages() {
$response = array();
$message_thread_code = $this->input->post('message_thread_code');
$this->db->where('message_thread_code', $message_thread_code);
$this->db->order_by('timestamp', 'asc');
$messages = $this->db->get('message')->result_array();
foreach ($messages as $row) {
$sender = explode('-', $row['sender']);
$sender_name = $this->db->get_where($sender[0], array($sender[0].'_id' => $sender[1]))->row()->name;
$data['sender'] = $row['sender'];
$data['sender_type'] = $sender[0];
$data['sender_id'] = $sender[1];
$data['sender_name'] = $sender_name;
$data['message'] = $row['message'];
$data['date'] = date('d M, Y', $row['timestamp']);
array_push($response, $data);
}
echo json_encode($response);
}
function get_receivers() {
$student_array = array();
$teacher_array = array();
$parent_array = array();
$admin_array = array();
$response = array();
$for_user = $this->input->post('for_user');
$for_user = explode('-', $for_user);
$type = $for_user[0];
// students
$this->db->order_by('name', 'asc');
$students = $this->db->get('student')->result_array();
foreach ($students as $row) {
$data['id'] = $row['student_id'];
$data['type'] = 'student';
$data['name'] = $row['name'];
array_push($student_array, $data);
}
// teachers
$this->db->order_by('name', 'asc');
$teachers = $this->db->get('teacher')->result_array();
foreach ($teachers as $row) {
$data['id'] = $row['teacher_id'];
$data['type'] = 'teacher';
$data['name'] = $row['name'];
array_push($teacher_array, $data);
}
// parents
$this->db->order_by('name', 'asc');
$parents = $this->db->get('parent')->result_array();
foreach ($parents as $row) {
$data['id'] = $row['parent_id'];
$data['type'] = 'parent';
$data['name'] = $row['name'];
array_push($parent_array, $data);
}
// admins
$this->db->order_by('name', 'asc');
$admins = $this->db->get('admin')->result_array();
foreach ($admins as $row) {
$data['id'] = $row['admin_id'];
$data['type'] = 'admin';
$data['name'] = $row['name'];
array_push($admin_array, $data);
}
if ($type == 'admin') {
$response = array_merge($teacher_array, $parent_array, $student_array);
echo json_encode($response);
} else if ($type == 'teacher') {
$response = array_merge($admin_array, $parent_array, $student_array);
echo json_encode($response);
} else if ($type == 'student') {
$response = array_merge($admin_array, $teacher_array);
echo json_encode($response);
} else {
$response = array_merge($admin_array, $teacher_array);
echo json_encode($response);
}
}
function send_new_message() {
$response = array();
$message = $this->input->post('message');
$receiver = $this->input->post('receiver');
$sender = $this->input->post('sender');
$timestamp = strtotime(date("Y-m-d H:i:s"));
//check if the thread between those 2 users exists, if not create new thread
$num1 = $this->db->get_where('message_thread', array('sender' => $sender, 'reciever' => $receiver))->num_rows();
$num2 = $this->db->get_where('message_thread', array('sender' => $receiver, 'reciever' => $sender))->num_rows();
if ($num1 == 0 && $num2 == 0) {
$message_thread_code = substr(md5(rand(100000000, 20000000000)), 0, 15);
$data_message_thread['message_thread_code'] = $message_thread_code;
$data_message_thread['sender'] = $sender;
$data_message_thread['reciever'] = $receiver;
$this->db->insert('message_thread', $data_message_thread);
}
if ($num1 > 0)
$message_thread_code = $this->db->get_where('message_thread', array('sender' => $sender, 'reciever' => $receiver))->row()->message_thread_code;
if ($num2 > 0)
$message_thread_code = $this->db->get_where('message_thread', array('sender' => $receiver, 'reciever' => $sender))->row()->message_thread_code;
$data_message['message_thread_code'] = $message_thread_code;
$data_message['message'] = $message;
$data_message['sender'] = $sender;
$data_message['timestamp'] = $timestamp;
$this->db->insert('message', $data_message);
$data['message_thread_code'] = $message_thread_code;
array_push($response, $data);
echo json_encode($response);
}
function send_reply() {
$message_thread_code = $this->input->post('message_thread_code');
$message = $this->input->post('message');
$timestamp = strtotime(date("Y-m-d H:i:s"));
$sender = $this->input->post('sender');
$data_message['message_thread_code'] = $message_thread_code;
$data_message['message'] = $message;
$data_message['sender'] = $sender;
$data_message['timestamp'] = $timestamp;
$this->db->insert('message', $data_message);
$data['message_thread_code'] = $message_thread_code;
echo 'success';
}
// authentication_key validation
function validate_auth_key()
{
/*
* Ignore the authentication and returns success by default to constructor
* For pubic calls: login, forget password.
* Pass post parameter 'authenticate' = 'false' to ignore the user level authentication
*/
if ($this->input->post('authenticate') == 'false')
return 'success';
$response = array();
$authentication_key = $this->input->post("authentication_key");
$user_type = $this->input->post("user_type");
$query = $this->db->get_where($user_type, array(
'authentication_key' => $authentication_key
));
if ($query->num_rows() > 0) {
$row = $query->row();
$response['status'] = 'success';
$response['login_type'] = 'admin';
if ($user_type == 'admin')
$response['login_user_id'] = $row->admin_id;
if ($user_type == 'teacher')
$response['login_user_id'] = $row->teacher_id;
if ($user_type == 'student')
$response['login_user_id'] = $row->student_id;
if ($user_type == 'parent')
$response['login_user_id'] = $row->parent_id;
$response['authentication_key'] = $authentication_key;
} else {
$response['status'] = 'failed';
}
//return json_encode($response);
return $response['status'];
}
}
/application/controllers/Home.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Home extends CI_Controller
{
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->load->database();
$this->load->library('session');
// $this->load->library('stripe');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
// CHECK CUSTOM SESSION DATA
$this->session_data();
}
public function index()
{
$this->home();
}
public function verification_code()
{
if (!$this->session->userdata('register_email')) {
redirect(site_url('home/sign_up'), 'refresh');
}
$page_data['page_name'] = "verification_code";
$page_data['page_title'] = site_phrase('verification_code');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function home()
{
$page_data['page_name'] = "home";
$page_data['page_title'] = site_phrase('home');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function shopping_cart()
{
if (!$this->session->userdata('cart_items')) {
$this->session->set_userdata('cart_items', array());
}
$page_data['page_name'] = "shopping_cart";
$page_data['page_title'] = site_phrase('shopping_cart');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function courses()
{
if (!$this->session->userdata('layout')) {
$this->session->set_userdata('layout', 'list');
}
$layout = $this->session->userdata('layout');
$selected_category_id = "all";
$selected_price = "all";
$selected_level = "all";
$selected_language = "all";
$selected_rating = "all";
// Get the category ids
if (isset($_GET['category']) && !empty($_GET['category'] && $_GET['category'] != "all")) {
$selected_category_id = $this->crud_model->get_category_id($_GET['category']);
}
// Get the selected price
if (isset($_GET['price']) && !empty($_GET['price'])) {
$selected_price = $_GET['price'];
}
// Get the selected level
if (isset($_GET['level']) && !empty($_GET['level'])) {
$selected_level = $_GET['level'];
}
// Get the selected language
if (isset($_GET['language']) && !empty($_GET['language'])) {
$selected_language = $_GET['language'];
}
// Get the selected rating
if (isset($_GET['rating']) && !empty($_GET['rating'])) {
$selected_rating = $_GET['rating'];
}
if ($selected_category_id == "all" && $selected_price == "all" && $selected_level == 'all' && $selected_language == 'all' && $selected_rating == 'all') {
if (!addon_status('scorm_course')) {
$this->db->where('course_type', 'general');
}
$this->db->where('status', 'active');
$total_rows = $this->db->get('course')->num_rows();
$config = array();
$config = pagintaion($total_rows, 6);
$config['base_url'] = site_url('home/courses/');
$this->pagination->initialize($config);
if (!addon_status('scorm_course')) {
$this->db->where('course_type', 'general');
}
$this->db->where('status', 'active');
$page_data['courses'] = $this->db->get('course', $config['per_page'], $this->uri->segment(3))->result_array();
} else {
$courses = $this->crud_model->filter_course($selected_category_id, $selected_price, $selected_level, $selected_language, $selected_rating);
$page_data['courses'] = $courses;
}
$page_data['page_name'] = "courses_page";
$page_data['page_title'] = site_phrase('courses');
$page_data['layout'] = $layout;
$page_data['selected_category_id'] = $selected_category_id;
$page_data['selected_price'] = $selected_price;
$page_data['selected_level'] = $selected_level;
$page_data['selected_language'] = $selected_language;
$page_data['selected_rating'] = $selected_rating;
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function set_layout_to_session()
{
$layout = $this->input->post('layout');
$this->session->set_userdata('layout', $layout);
}
public function course($slug = "", $course_id = "")
{
$this->access_denied_courses($course_id);
$page_data['course_id'] = $course_id;
$page_data['page_name'] = "course_page";
$page_data['page_title'] = site_phrase('course');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function instructor_page($instructor_id = "")
{
$page_data['page_name'] = "instructor_page";
$page_data['page_title'] = site_phrase('instructor_page');
$page_data['instructor_id'] = $instructor_id;
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function my_courses()
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('home'), 'refresh');
}
$page_data['page_name'] = "my_courses";
$page_data['page_title'] = site_phrase("my_courses");
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function my_messages($param1 = "", $param2 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('home'), 'refresh');
}
if ($param1 == 'read_message') {
$page_data['message_thread_code'] = $param2;
} elseif ($param1 == 'send_new') {
$message_thread_code = $this->crud_model->send_new_private_message();
$this->session->set_flashdata('flash_message', site_phrase('message_sent'));
redirect(site_url('home/my_messages/read_message/' . $message_thread_code), 'refresh');
} elseif ($param1 == 'send_reply') {
$this->crud_model->send_reply_message($param2); //$param2 = message_thread_code
$this->session->set_flashdata('flash_message', site_phrase('message_sent'));
redirect(site_url('home/my_messages/read_message/' . $param2), 'refresh');
}
$page_data['page_name'] = "my_messages";
$page_data['page_title'] = site_phrase('my_messages');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function my_notifications()
{
$page_data['page_name'] = "my_notifications";
$page_data['page_title'] = site_phrase('my_notifications');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function my_wishlist()
{
if (!$this->session->userdata('cart_items')) {
$this->session->set_userdata('cart_items', array());
}
$my_courses = $this->crud_model->get_courses_by_wishlists();
$page_data['my_courses'] = $my_courses;
$page_data['page_name'] = "my_wishlist";
$page_data['page_title'] = site_phrase('my_wishlist');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function purchase_history()
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('home'), 'refresh');
}
$total_rows = $this->crud_model->purchase_history($this->session->userdata('user_id'))->num_rows();
$config = array();
$config = pagintaion($total_rows, 10);
$config['base_url'] = site_url('home/purchase_history');
$this->pagination->initialize($config);
$page_data['per_page'] = $config['per_page'];
if (addon_status('offline_payment') == 1) :
$this->load->model('addons/offline_payment_model');
$page_data['pending_offline_payment_history'] = $this->offline_payment_model->pending_offline_payment($this->session->userdata('user_id'))->result_array();
endif;
$page_data['page_name'] = "purchase_history";
$page_data['page_title'] = site_phrase('purchase_history');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function profile($param1 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('home'), 'refresh');
}
if ($param1 == 'user_profile') {
$page_data['page_name'] = "user_profile";
$page_data['page_title'] = site_phrase('user_profile');
} elseif ($param1 == 'user_credentials') {
$page_data['page_name'] = "user_credentials";
$page_data['page_title'] = site_phrase('credentials');
} elseif ($param1 == 'user_photo') {
$page_data['page_name'] = "update_user_photo";
$page_data['page_title'] = site_phrase('update_user_photo');
}
$page_data['user_details'] = $this->user_model->get_user($this->session->userdata('user_id'));
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function update_profile($param1 = "")
{
if ($param1 == 'update_basics') {
$this->user_model->edit_user($this->session->userdata('user_id'));
redirect(site_url('home/profile/user_profile'), 'refresh');
} elseif ($param1 == "update_credentials") {
$this->user_model->update_account_settings($this->session->userdata('user_id'));
redirect(site_url('home/profile/user_credentials'), 'refresh');
} elseif ($param1 == "update_photo") {
if (isset($_FILES['user_image']) && $_FILES['user_image']['name'] != "") {
unlink('uploads/user_image/' . $this->db->get_where('users', array('id' => $this->session->userdata('user_id')))->row('image') . '.jpg');
$data['image'] = md5(rand(10000, 10000000));
$this->db->where('id', $this->session->userdata('user_id'));
$this->db->update('users', $data);
$this->user_model->upload_user_image($data['image']);
}
$this->session->set_flashdata('flash_message', site_phrase('updated_successfully'));
redirect(site_url('home/profile/user_photo'), 'refresh');
}
}
public function handleWishList($return_number = "")
{
if ($this->session->userdata('user_login') != 1) {
echo false;
} else {
if (isset($_POST['course_id'])) {
$course_id = $this->input->post('course_id');
$this->crud_model->handleWishList($course_id);
}
if ($return_number == 'true') {
echo sizeof($this->crud_model->getWishLists());
} else {
$this->load->view('frontend/' . get_frontend_settings('theme') . '/wishlist_items');
}
}
}
public function handleCartItems($return_number = "")
{
if (!$this->session->userdata('cart_items')) {
$this->session->set_userdata('cart_items', array());
}
$course_id = $this->input->post('course_id');
$previous_cart_items = $this->session->userdata('cart_items');
if (in_array($course_id, $previous_cart_items)) {
$key = array_search($course_id, $previous_cart_items);
unset($previous_cart_items[$key]);
} else {
array_push($previous_cart_items, $course_id);
}
$this->session->set_userdata('cart_items', $previous_cart_items);
if ($return_number == 'true') {
echo sizeof($previous_cart_items);
} else {
$this->load->view('frontend/' . get_frontend_settings('theme') . '/cart_items');
}
}
public function handleCartItemForBuyNowButton()
{
if (!$this->session->userdata('cart_items')) {
$this->session->set_userdata('cart_items', array());
}
$course_id = $this->input->post('course_id');
$previous_cart_items = $this->session->userdata('cart_items');
if (!in_array($course_id, $previous_cart_items)) {
array_push($previous_cart_items, $course_id);
}
$this->session->set_userdata('cart_items', $previous_cart_items);
$this->load->view('frontend/' . get_frontend_settings('theme') . '/cart_items');
}
public function refreshWishList()
{
$this->load->view('frontend/' . get_frontend_settings('theme') . '/wishlist_items');
}
public function refreshShoppingCart()
{
$page_data['coupon_code'] = $this->input->post('couponCode');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/shopping_cart_inner_view', $page_data);
}
public function isLoggedIn()
{
if ($this->session->userdata('user_login') == 1)
echo true;
else
echo false;
}
//choose payment gateway
public function payment()
{
if ($this->session->userdata('user_login') != 1)
redirect('login', 'refresh');
$page_data['total_price_of_checking_out'] = $this->session->userdata('total_price_of_checking_out');
$page_data['page_title'] = site_phrase("payment_gateway");
$this->load->view('payment/index', $page_data);
}
// SHOW PAYPAL CHECKOUT PAGE
public function paypal_checkout($payment_request = "only_for_mobile")
{
if ($this->session->userdata('user_login') != 1 && $payment_request != 'true')
redirect('home', 'refresh');
//checking price
if ($this->session->userdata('total_price_of_checking_out') == $this->input->post('total_price_of_checking_out')) :
$total_price_of_checking_out = $this->input->post('total_price_of_checking_out');
else :
$total_price_of_checking_out = $this->session->userdata('total_price_of_checking_out');
endif;
$page_data['payment_request'] = $payment_request;
$page_data['user_details'] = $this->user_model->get_user($this->session->userdata('user_id'))->row_array();
$page_data['amount_to_pay'] = $total_price_of_checking_out;
$this->load->view('frontend/' . get_frontend_settings('theme') . '/paypal_checkout', $page_data);
}
// PAYPAL CHECKOUT ACTIONS
public function paypal_payment($user_id = "", $amount_paid = "", $paymentID = "", $paymentToken = "", $payerID = "", $payment_request_mobile = "")
{
$paypal_keys = get_settings('paypal');
$paypal = json_decode($paypal_keys);
if ($paypal[0]->mode == 'sandbox') {
$paypalClientID = $paypal[0]->sandbox_client_id;
$paypalSecret = $paypal[0]->sandbox_secret_key;
} else {
$paypalClientID = $paypal[0]->production_client_id;
$paypalSecret = $paypal[0]->production_secret_key;
}
//THIS IS HOW I CHECKED THE PAYPAL PAYMENT STATUS
$status = $this->payment_model->paypal_payment($paymentID, $paymentToken, $payerID, $paypalClientID, $paypalSecret);
if (!$status) {
$this->session->set_flashdata('error_message', site_phrase('an_error_occurred_during_payment'));
redirect('home/shopping_cart', 'refresh');
}
$this->crud_model->enrol_student($user_id);
$this->crud_model->course_purchase($user_id, 'paypal', $amount_paid);
$this->email_model->course_purchase_notification($user_id, 'paypal', $amount_paid);
$this->session->set_flashdata('flash_message', site_phrase('payment_successfully_done'));
if ($payment_request_mobile == 'true') :
$course_id = $this->session->userdata('cart_items');
redirect('home/payment_success_mobile/' . $course_id[0] . '/' . $user_id . '/paid', 'refresh');
else :
$this->session->set_userdata('cart_items', array());
redirect('home/my_courses', 'refresh');
endif;
}
// SHOW STRIPE CHECKOUT PAGE
public function stripe_checkout($payment_request = "only_for_mobile")
{
if ($this->session->userdata('user_login') != 1 && $payment_request != 'true')
redirect('home', 'refresh');
//checking price
$total_price_of_checking_out = $this->session->userdata('total_price_of_checking_out');
$page_data['payment_request'] = $payment_request;
$page_data['user_details'] = $this->user_model->get_user($this->session->userdata('user_id'))->row_array();
$page_data['amount_to_pay'] = $total_price_of_checking_out;
$this->load->view('payment/stripe/stripe_checkout', $page_data);
}
// STRIPE CHECKOUT ACTIONS
public function stripe_payment($user_id = "", $payment_request_mobile = "", $session_id = "")
{
//THIS IS HOW I CHECKED THE STRIPE PAYMENT STATUS
$response = $this->payment_model->stripe_payment($user_id, $session_id);
if ($response['payment_status'] === 'succeeded') {
// STUDENT ENROLMENT OPERATIONS AFTER A SUCCESSFUL PAYMENT
$check_duplicate = $this->crud_model->check_duplicate_payment_for_stripe($response['transaction_id'], $session_id);
if ($check_duplicate == false) :
$this->crud_model->enrol_student($user_id);
$this->crud_model->course_purchase($user_id, 'stripe', $response['paid_amount'], $response['transaction_id'], $session_id);
$this->email_model->course_purchase_notification($user_id, 'stripe', $response['paid_amount']);
else :
//duplicate payment
$this->session->set_flashdata('error_message', site_phrase('session_time_out'));
redirect('home/shopping_cart', 'refresh');
endif;
if ($payment_request_mobile == 'true') :
$course_id = $this->session->userdata('cart_items');
$this->session->set_flashdata('flash_message', site_phrase('payment_successfully_done'));
redirect('home/payment_success_mobile/' . $course_id[0] . '/' . $user_id . '/paid', 'refresh');
else :
$this->session->set_userdata('cart_items', array());
$this->session->set_flashdata('flash_message', site_phrase('payment_successfully_done'));
redirect('home/my_courses', 'refresh');
endif;
} else {
if ($payment_request_mobile == 'true') :
$course_id = $this->session->userdata('cart_items');
$this->session->set_flashdata('flash_message', $response['status_msg']);
redirect('home/payment_success_mobile/' . $course_id[0] . '/' . $user_id . '/error', 'refresh');
else :
$this->session->set_flashdata('error_message', $response['status_msg']);
redirect('home/shopping_cart', 'refresh');
endif;
}
}
public function lesson($slug = "", $course_id = "", $lesson_id = "")
{
if ($this->session->userdata('user_login') != 1) {
if ($this->session->userdata('admin_login') != 1) {
redirect('home', 'refresh');
}
}
$course_details = $this->crud_model->get_course_by_id($course_id)->row_array();
if ($course_details['course_type'] == 'general') {
$sections = $this->crud_model->get_section('course', $course_id);
if ($sections->num_rows() > 0) {
$page_data['sections'] = $sections->result_array();
if ($lesson_id == "") {
$default_section = $sections->row_array();
$page_data['section_id'] = $default_section['id'];
$lessons = $this->crud_model->get_lessons('section', $default_section['id']);
if ($lessons->num_rows() > 0) {
$default_lesson = $lessons->row_array();
$lesson_id = $default_lesson['id'];
$page_data['lesson_id'] = $default_lesson['id'];
}
} else {
$page_data['lesson_id'] = $lesson_id;
$section_id = $this->db->get_where('lesson', array('id' => $lesson_id))->row()->section_id;
$page_data['section_id'] = $section_id;
}
} else {
$page_data['sections'] = array();
}
} else if ($course_details['course_type'] == 'scorm') {
$this->load->model('addons/scorm_model');
$scorm_course_data = $this->scorm_model->get_scorm_curriculum_by_course_id($course_id);
$page_data['scorm_curriculum'] = $scorm_course_data->row_array();
}
// Check if the lesson contained course is purchased by the user
if (isset($page_data['lesson_id']) && $page_data['lesson_id'] > 0 && $course_details['course_type'] == 'general') {
if ($this->session->userdata('role_id') != 1 && $course_details['user_id'] != $this->session->userdata('user_id')) {
if (!is_purchased($course_id)) {
redirect(site_url('home/course/' . slugify($course_details['title']) . '/' . $course_details['id']), 'refresh');
}
}
} else if ($course_details['course_type'] == 'scorm' && $scorm_course_data->num_rows() > 0) {
if ($this->session->userdata('role_id') != 1 && $course_details['user_id'] != $this->session->userdata('user_id')) {
if (!is_purchased($course_id)) {
redirect(site_url('home/course/' . slugify($course_details['title']) . '/' . $course_details['id']), 'refresh');
}
}
} else {
if (!is_purchased($course_id)) {
redirect(site_url('home/course/' . slugify($course_details['title']) . '/' . $course_details['id']), 'refresh');
}
}
$page_data['course_details'] = $course_details;
$page_data['course_id'] = $course_id;
$page_data['page_name'] = 'lessons';
$page_data['page_title'] = $course_details['title'];
$this->load->view('lessons/index', $page_data);
}
public function my_courses_by_category()
{
$category_id = $this->input->post('category_id');
$course_details = $this->crud_model->get_my_courses_by_category_id($category_id)->result_array();
$page_data['my_courses'] = $course_details;
$this->load->view('frontend/' . get_frontend_settings('theme') . '/reload_my_courses', $page_data);
}
public function search($search_string = "")
{
if (isset($_GET['query']) && !empty($_GET['query'])) {
$search_string = $_GET['query'];
$page_data['courses'] = $this->crud_model->get_courses_by_search_string($search_string)->result_array();
} else {
$this->session->set_flashdata('error_message', site_phrase('no_search_value_found'));
redirect(site_url(), 'refresh');
}
if (!$this->session->userdata('layout')) {
$this->session->set_userdata('layout', 'list');
}
$page_data['layout'] = $this->session->userdata('layout');
$page_data['page_name'] = 'courses_page';
$page_data['search_string'] = $search_string;
$page_data['page_title'] = site_phrase('search_results');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function my_courses_by_search_string()
{
$search_string = $this->input->post('search_string');
$course_details = $this->crud_model->get_my_courses_by_search_string($search_string)->result_array();
$page_data['my_courses'] = $course_details;
$this->load->view('frontend/' . get_frontend_settings('theme') . '/reload_my_courses', $page_data);
}
public function get_my_wishlists_by_search_string()
{
$search_string = $this->input->post('search_string');
$course_details = $this->crud_model->get_courses_of_wishlists_by_search_string($search_string);
$page_data['my_courses'] = $course_details;
$this->load->view('frontend/' . get_frontend_settings('theme') . '/reload_my_wishlists', $page_data);
}
public function reload_my_wishlists()
{
$my_courses = $this->crud_model->get_courses_by_wishlists();
$page_data['my_courses'] = $my_courses;
$this->load->view('frontend/' . get_frontend_settings('theme') . '/reload_my_wishlists', $page_data);
}
public function get_course_details()
{
$course_id = $this->input->post('course_id');
$course_details = $this->crud_model->get_course_by_id($course_id)->row_array();
echo $course_details['title'];
}
public function rate_course()
{
$data['review'] = $this->input->post('review');
$data['ratable_id'] = $this->input->post('course_id');
$data['ratable_type'] = 'course';
$data['rating'] = $this->input->post('starRating');
$data['date_added'] = strtotime(date('D, d-M-Y'));
$data['user_id'] = $this->session->userdata('user_id');
$this->crud_model->rate($data);
}
public function about_us()
{
$page_data['page_name'] = 'about_us';
$page_data['page_title'] = site_phrase('about_us');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function terms_and_condition()
{
$page_data['page_name'] = 'terms_and_condition';
$page_data['page_title'] = site_phrase('terms_and_condition');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function privacy_policy()
{
$page_data['page_name'] = 'privacy_policy';
$page_data['page_title'] = site_phrase('privacy_policy');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function cookie_policy()
{
$page_data['page_name'] = 'cookie_policy';
$page_data['page_title'] = site_phrase('cookie_policy');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
// Version 1.1
public function dashboard($param1 = "")
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
if ($param1 == "") {
$page_data['type'] = 'active';
} else {
$page_data['type'] = $param1;
}
$page_data['page_name'] = 'instructor_dashboard';
$page_data['page_title'] = site_phrase('instructor_dashboard');
$page_data['user_id'] = $this->session->userdata('user_id');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function create_course()
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
$page_data['page_name'] = 'create_course';
$page_data['page_title'] = site_phrase('create_course');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function edit_course($param1 = "", $param2 = "")
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
if ($param2 == "") {
$page_data['type'] = 'edit_course';
} else {
$page_data['type'] = $param2;
}
$page_data['page_name'] = 'manage_course_details';
$page_data['course_id'] = $param1;
$page_data['page_title'] = site_phrase('edit_course');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function course_action($param1 = "", $param2 = "")
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
if ($param1 == 'create') {
if (isset($_POST['create_course'])) {
$this->crud_model->add_course();
redirect(site_url('home/create_course'), 'refresh');
} else {
$this->crud_model->add_course('save_to_draft');
redirect(site_url('home/create_course'), 'refresh');
}
} elseif ($param1 == 'edit') {
if (isset($_POST['publish'])) {
$this->crud_model->update_course($param2, 'publish');
redirect(site_url('home/dashboard'), 'refresh');
} else {
$this->crud_model->update_course($param2, 'save_to_draft');
redirect(site_url('home/dashboard'), 'refresh');
}
}
}
public function sections($action = "", $course_id = "", $section_id = "")
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
if ($action == "add") {
$this->crud_model->add_section($course_id);
} elseif ($action == "edit") {
$this->crud_model->edit_section($section_id);
} elseif ($action == "delete") {
$this->crud_model->delete_section($course_id, $section_id);
$this->session->set_flashdata('flash_message', site_phrase('section_deleted'));
redirect(site_url("home/edit_course/$course_id/manage_section"), 'refresh');
} elseif ($action == "serialize_section") {
$container = array();
$serialization = json_decode($this->input->post('updatedSerialization'));
foreach ($serialization as $key) {
array_push($container, $key->id);
}
$json = json_encode($container);
$this->crud_model->serialize_section($course_id, $json);
}
$page_data['course_id'] = $course_id;
$page_data['course_details'] = $this->crud_model->get_course_by_id($course_id)->row_array();
return $this->load->view('frontend/' . get_frontend_settings('theme') . '/reload_section', $page_data);
}
public function manage_lessons($action = "", $course_id = "", $lesson_id = "")
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
if ($action == 'add') {
$this->crud_model->add_lesson();
$this->session->set_flashdata('flash_message', site_phrase('lesson_added'));
} elseif ($action == 'edit') {
$this->crud_model->edit_lesson($lesson_id);
$this->session->set_flashdata('flash_message', site_phrase('lesson_updated'));
} elseif ($action == 'delete') {
$this->crud_model->delete_lesson($lesson_id);
$this->session->set_flashdata('flash_message', site_phrase('lesson_deleted'));
}
redirect('home/edit_course/' . $course_id . '/manage_lesson');
}
public function lesson_editing_form($lesson_id = "", $course_id = "")
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
$page_data['type'] = 'manage_lesson';
$page_data['course_id'] = $course_id;
$page_data['lesson_id'] = $lesson_id;
$page_data['page_name'] = 'lesson_edit';
$page_data['page_title'] = site_phrase('update_lesson');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function download($filename = "")
{
$tmp = explode('.', $filename);
$fileExtension = strtolower(end($tmp));
$yourFile = base_url() . 'uploads/lesson_files/' . $filename;
$file = @fopen($yourFile, "rb");
header('Content-Description: File Transfer');
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename=' . $filename);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($yourFile));
while (!feof($file)) {
print(@fread($file, 1024 * 8));
ob_flush();
flush();
}
}
// Version 1.3 codes
public function get_enrolled_to_free_course($course_id)
{
if ($this->session->userdata('user_login') == 1) {
$this->crud_model->enrol_to_free_course($course_id, $this->session->userdata('user_id'));
redirect(site_url('home/my_courses'), 'refresh');
} else {
redirect(site_url('login'), 'refresh');
}
}
// Version 1.4 codes
public function login()
{
if ($this->session->userdata('admin_login')) {
redirect(site_url('admin'), 'refresh');
} elseif ($this->session->userdata('user_login')) {
redirect(site_url('user'), 'refresh');
}
$page_data['page_name'] = 'login';
$page_data['page_title'] = site_phrase('login');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function sign_up()
{
if ($this->session->userdata('admin_login')) {
redirect(site_url('admin'), 'refresh');
} elseif ($this->session->userdata('user_login')) {
redirect(site_url('user'), 'refresh');
}
$page_data['page_name'] = 'sign_up';
$page_data['page_title'] = site_phrase('sign_up');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function forgot_password()
{
if ($this->session->userdata('admin_login')) {
redirect(site_url('admin'), 'refresh');
} elseif ($this->session->userdata('user_login')) {
redirect(site_url('user'), 'refresh');
}
$page_data['page_name'] = 'forgot_password';
$page_data['page_title'] = site_phrase('forgot_password');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
public function submit_quiz($from = "")
{
$submitted_quiz_info = array();
$container = array();
$quiz_id = $this->input->post('lesson_id');
$quiz_questions = $this->crud_model->get_quiz_questions($quiz_id)->result_array();
$total_correct_answers = 0;
foreach ($quiz_questions as $quiz_question) {
$submitted_answer_status = 0;
$correct_answers = json_decode($quiz_question['correct_answers']);
$submitted_answers = array();
foreach ($this->input->post($quiz_question['id']) as $each_submission) {
if (isset($each_submission)) {
array_push($submitted_answers, $each_submission);
}
}
sort($correct_answers);
sort($submitted_answers);
if ($correct_answers == $submitted_answers) {
$submitted_answer_status = 1;
$total_correct_answers++;
}
$container = array(
"question_id" => $quiz_question['id'],
'submitted_answer_status' => $submitted_answer_status,
"submitted_answers" => json_encode($submitted_answers),
"correct_answers" => json_encode($correct_answers),
);
array_push($submitted_quiz_info, $container);
}
$page_data['submitted_quiz_info'] = $submitted_quiz_info;
$page_data['total_correct_answers'] = $total_correct_answers;
$page_data['total_questions'] = count($quiz_questions);
if ($from == 'mobile') {
$this->load->view('mobile/quiz_result', $page_data);
} else {
$this->load->view('lessons/quiz_result', $page_data);
}
}
private function access_denied_courses($course_id)
{
$course_details = $this->crud_model->get_course_by_id($course_id)->row_array();
if ($course_details['status'] == 'draft' && $course_details['user_id'] != $this->session->userdata('user_id')) {
$this->session->set_flashdata('error_message', site_phrase('you_do_not_have_permission_to_access_this_course'));
redirect(site_url('home'), 'refresh');
} elseif ($course_details['status'] == 'pending') {
if ($course_details['user_id'] != $this->session->userdata('user_id') && $this->session->userdata('role_id') != 1) {
$this->session->set_flashdata('error_message', site_phrase('you_do_not_have_permission_to_access_this_course'));
redirect(site_url('home'), 'refresh');
}
}
}
public function invoice($purchase_history_id = '')
{
if ($this->session->userdata('user_login') != 1) {
redirect('home', 'refresh');
}
$purchase_history = $this->crud_model->get_payment_details_by_id($purchase_history_id);
if ($purchase_history['user_id'] != $this->session->userdata('user_id')) {
redirect('home', 'refresh');
}
$page_data['payment_info'] = $purchase_history;
$page_data['page_name'] = 'invoice';
$page_data['page_title'] = 'invoice';
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
/** COURSE COMPARE STARTS */
public function compare()
{
$course_id_1 = (isset($_GET['course-id-1']) && !empty($_GET['course-id-1'])) ? $_GET['course-id-1'] : null;
$course_id_2 = (isset($_GET['course-id-2']) && !empty($_GET['course-id-2'])) ? $_GET['course-id-2'] : null;
$course_id_3 = (isset($_GET['course-id-3']) && !empty($_GET['course-id-3'])) ? $_GET['course-id-3'] : null;
$page_data['page_name'] = 'compare';
$page_data['page_title'] = site_phrase('course_compare');
$page_data['courses'] = $this->crud_model->get_courses()->result_array();
$page_data['course_1_details'] = $course_id_1 ? $this->crud_model->get_course_by_id($course_id_1)->row_array() : array();
$page_data['course_2_details'] = $course_id_2 ? $this->crud_model->get_course_by_id($course_id_2)->row_array() : array();
$page_data['course_3_details'] = $course_id_3 ? $this->crud_model->get_course_by_id($course_id_3)->row_array() : array();
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
/** COURSE COMPARE ENDS */
public function page_not_found()
{
$page_data['page_name'] = '404';
$page_data['page_title'] = site_phrase('404_page_not_found');
$this->load->view('frontend/' . get_frontend_settings('theme') . '/index', $page_data);
}
// AJAX CALL FUNCTION FOR CHECKING COURSE PROGRESS
function check_course_progress($course_id)
{
echo course_progress($course_id);
}
// This is the function for rendering quiz web view for mobile
public function quiz_mobile_web_view($lesson_id = "")
{
$data['lesson_details'] = $this->crud_model->get_lessons('lesson', $lesson_id)->row_array();
$data['page_name'] = 'quiz';
$this->load->view('mobile/index', $data);
}
// CHECK CUSTOM SESSION DATA
public function session_data()
{
// SESSION DATA FOR CART
if (!$this->session->userdata('cart_items')) {
$this->session->set_userdata('cart_items', array());
}
// SESSION DATA FOR FRONTEND LANGUAGE
if (!$this->session->userdata('language')) {
$this->session->set_userdata('language', get_settings('language'));
}
}
// SETTING FRONTEND LANGUAGE
public function site_language()
{
$selected_language = $this->input->post('language');
$this->session->set_userdata('language', $selected_language);
echo true;
}
//FOR MOBILE
public function course_purchase($auth_token = '', $course_id = '')
{
$this->load->model('jwt_model');
if (empty($auth_token) || $auth_token == "null") {
$page_data['cart_item'] = $course_id;
$page_data['user_id'] = '';
$page_data['is_login_now'] = 0;
$page_data['enroll_type'] = null;
$page_data['page_name'] = 'shopping_cart';
$this->load->view('mobile/index', $page_data);
} else {
$logged_in_user_details = json_decode($this->jwt_model->token_data_get($auth_token), true);
if ($logged_in_user_details['user_id'] > 0) {
$credential = array('id' => $logged_in_user_details['user_id'], 'status' => 1, 'role_id' => 2);
$query = $this->db->get_where('users', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$page_data['cart_item'] = $course_id;
$page_data['user_id'] = $row->id;
$page_data['is_login_now'] = 1;
$page_data['enroll_type'] = null;
$page_data['page_name'] = 'shopping_cart';
$cart_item = array($course_id);
$this->session->set_userdata('cart_items', $cart_item);
$this->session->set_userdata('user_login', '1');
$this->session->set_userdata('user_id', $row->id);
$this->session->set_userdata('role_id', $row->role_id);
$this->session->set_userdata('role', get_user_role('user_role', $row->id));
$this->session->set_userdata('name', $row->first_name . ' ' . $row->last_name);
$this->load->view('mobile/index', $page_data);
}
}
}
}
//FOR MOBILE
public function get_enrolled_to_free_course_mobile($course_id = "", $user_id = "", $get_request = "")
{
if ($get_request == "true") {
$this->crud_model->enrol_to_free_course_mobile($course_id, $user_id);
}
}
//FOR MOBILE
public function payment_success_mobile($course_id = "", $user_id = "", $enroll_type = "")
{
if ($course_id > 0 && $user_id > 0) :
$page_data['cart_item'] = $course_id;
$page_data['user_id'] = $user_id;
$page_data['is_login_now'] = 1;
$page_data['enroll_type'] = $enroll_type;
$page_data['page_name'] = 'shopping_cart';
$this->session->unset_userdata('user_id');
$this->session->unset_userdata('role_id');
$this->session->unset_userdata('role');
$this->session->unset_userdata('name');
$this->session->unset_userdata('user_login');
$this->session->unset_userdata('cart_items');
$this->load->view('mobile/index', $page_data);
endif;
}
//FOR MOBILE
public function payment_gateway_mobile($course_id = "", $user_id = "")
{
if ($course_id > 0 && $user_id > 0) :
$page_data['page_name'] = 'payment_gateway';
$this->load->view('mobile/index', $page_data);
endif;
}
}
/application/controllers/Install.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/*
* @author : Creativeitem
* date : 07 october, 2018
* Academy
* http://codecanyon.net/user/Creativeitem
* http://support.creativeitem.com
*/
ini_set('max_execution_time', 0);
ini_set('memory_limit','2048M');
class Install extends CI_Controller {
public function index() {
if ($this->router->default_controller == 'install') {
redirect(site_url('install/step0'), 'refresh');
}
redirect(site_url('login'), 'refresh');
}
function step0() {
if ($this->router->default_controller != 'install') {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'step0';
$this->load->view('install/index', $page_data);
}
function step1() {
if ($this->router->default_controller != 'install') {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'step1';
$this->load->view('install/index', $page_data);
}
function step2($param1 = '', $param2 = '') {
if ($this->router->default_controller != 'install') {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'error') {
$page_data['error'] = 'Purchase Code Verification Failed';
}
$page_data['page_name'] = 'step2';
$this->load->view('install/index', $page_data);
}
function validate_purchase_code() {
$purchase_code = $this->input->post('purchase_code');
$validation_response = TRUE;
if ($validation_response == true) {
// keeping the purchase code in users session
session_start();
$_SESSION['purchase_code'] = $purchase_code;
$_SESSION['purchase_code_verified'] = 1;
//move to step 3
redirect(site_url('install/step3'), 'refresh');
} else {
//remain on step 2 and show error
session_start();
$_SESSION['purchase_code_verified'] = 0;
redirect(site_url('install/step2/error'), 'refresh');
}
}
function step3($param1 = '', $param2 = '') {
if ($this->router->default_controller != 'install') {
redirect(site_url('login'), 'refresh');
}
$this->check_purchase_code_verification();
if ($param1 == 'error_con_fail') {
$page_data['error_con_fail'] = 'Error establishing a database conenction using your provided information. Please
recheck hostname, username, password and try again with correct information';
}
if ($param1 == 'error_nodb') {
$page_data['error_con_fail'] = 'The database you are trying to use for the application does not exist. Please create
the database first';
}
if ($param1 == 'configure_database') {
$hostname = $this->input->post('hostname');
$username = $this->input->post('username');
$password = $this->input->post('password');
$dbname = $this->input->post('dbname');
// check db connection using the above credentials
$db_connection = $this->check_database_connection($hostname, $username, $password, $dbname);
if ($db_connection == 'failed') {
redirect(site_url('install/step3/error_con_fail'), 'refresh');
} else if ($db_connection == 'db_not_exist') {
redirect(site_url('install/step3/error_nodb'), 'refresh');
} else {
// proceed to step 4
session_start();
$_SESSION['hostname'] = $hostname;
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['dbname'] = $dbname;
redirect(site_url('install/step4'), 'refresh');
}
}
$page_data['page_name'] = 'step3';
$this->load->view('install/index', $page_data);
}
function check_purchase_code_verification() {
if ($_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '127.0.0.1') {
//return 'running_locally';
} else {
session_start();
if (!isset($_SESSION['purchase_code_verified']))
redirect(site_url('install/step2'), 'refresh');
else if ($_SESSION['purchase_code_verified'] == 0)
redirect(site_url('install/step2'), 'refresh');
}
}
function check_database_connection($hostname, $username, $password, $dbname) {
$link = mysqli_connect($hostname, $username, $password, $dbname);
if (!$link) {
mysqli_close($link);
return 'failed';
}
$db_selected = mysqli_select_db($link, $dbname);
if (!$db_selected) {
mysqli_close($link);
return "db_not_exist";
}
mysqli_close($link);
return 'success';
}
function step4($param1 = '') {
if ($this->router->default_controller != 'install') {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'confirm_install') {
// write database.php
$this->configure_database();
// run sql
$this->run_blank_sql();
// redirect to admin creation page
redirect(site_url('install/finalizing_setup'), 'refresh');
}
$page_data['page_name'] = 'step4';
$this->load->view('install/index', $page_data);
}
function configure_database() {
// write database.php
$data_db = file_get_contents('./application/config/database.php');
session_start();
$data_db = str_replace('db_name', $_SESSION['dbname'], $data_db);
$data_db = str_replace('db_user', $_SESSION['username'], $data_db);
$data_db = str_replace('db_pass', $_SESSION['password'], $data_db);
$data_db = str_replace('db_host', $_SESSION['hostname'], $data_db);
file_put_contents('./application/config/database.php', $data_db);
}
function run_blank_sql() {
$this->load->database();
// Set line to collect lines that wrap
$templine = '';
// Read in entire file
$lines = file('./uploads/install.sql');
// Loop through each line
foreach ($lines as $line) {
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current templine we are creating
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query so can process this templine
if (substr(trim($line), -1, 1) == ';') {
// Perform the query
$this->db->query($templine);
// Reset temp variable to empty
$templine = '';
}
}
}
function finalizing_setup($param1 = '', $param2 = '') {
if ($this->router->default_controller != 'install') {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'setup_admin') {
$admin_data['first_name'] = html_escape($this->input->post('first_name'));
$admin_data['last_name'] = html_escape($this->input->post('last_name'));
$admin_data['email'] = html_escape($this->input->post('email'));
$admin_data['password'] = sha1($this->input->post('password'));
$social_links = array(
'facebook' => "",
'twitter' => "",
'linkedin' => ""
);
$admin_data['social_links'] = json_encode($social_links);
$admin_data['role_id'] = 1;
$admin_data['status'] = 1;
$this->load->database();
$this->db->insert('users', $admin_data);
$data['value'] = $this->input->post('system_name');
$this->db->where('key', 'system_name');
$this->db->update('settings', $data);
redirect(site_url('install/success'), 'refresh');
}
$page_data['page_name'] = 'finalizing_setup';
$this->load->view('install/index', $page_data);
}
function success($param1 = '') {
if ($this->router->default_controller != 'install') {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'login') {
$this->configure_routes();
redirect(site_url('login'), 'refresh');
}
$this->load->database();
$admin_email = $this->db->get_where('users', array('id' => 1))->row()->email;
session_start();
if (isset($_SESSION['purchase_code'])) {
$data['value'] = $_SESSION['purchase_code'];
$this->db->where('key', 'purchase_code');
$this->db->update('settings', $data);
}
session_destroy();
$page_data['admin_email'] = $admin_email;
$page_data['page_name'] = 'success';
$this->load->view('install/index', $page_data);
}
function configure_routes() {
// write routes.php
$data_routes = file_get_contents('./application/config/routes.php');
$data_routes = str_replace('install', 'home', $data_routes);
file_put_contents('./application/config/routes.php', $data_routes);
}
}
/application/controllers/Login.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->load->database();
$this->load->library('session');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
}
public function index() {
if ($this->session->userdata('admin_login')) {
redirect(site_url('admin'), 'refresh');
}elseif ($this->session->userdata('user_login')) {
redirect(site_url('user'), 'refresh');
}else {
redirect(site_url('home/login'), 'refresh');
}
}
public function validate_login($from = "") {
if($this->crud_model->check_recaptcha() == false && get_frontend_settings('recaptcha_status') == true){
$this->session->set_flashdata('error_message',get_phrase('recaptcha_verification_failed'));
redirect(site_url('home/login'), 'refresh');
}
$email = $this->input->post('email');
$password = $this->input->post('password');
$credential = array('email' => $email, 'password' => sha1($password), 'status' => 1);
// Checking login credential for admin
$query = $this->db->get_where('users', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$this->session->set_userdata('user_id', $row->id);
$this->session->set_userdata('role_id', $row->role_id);
$this->session->set_userdata('role', get_user_role('user_role', $row->id));
$this->session->set_userdata('name', $row->first_name.' '.$row->last_name);
$this->session->set_userdata('is_instructor', $row->is_instructor);
$this->session->set_flashdata('flash_message', get_phrase('welcome').' '.$row->first_name.' '.$row->last_name);
if ($row->role_id == 1) {
$this->session->set_userdata('admin_login', '1');
redirect(site_url('admin/dashboard'), 'refresh');
}else if($row->role_id == 2){
$this->session->set_userdata('user_login', '1');
redirect(site_url('home'), 'refresh');
}
}else {
$this->session->set_flashdata('error_message',get_phrase('invalid_login_credentials'));
redirect(site_url('home/login'), 'refresh');
}
}
public function register() {
if($this->crud_model->check_recaptcha() == false && get_frontend_settings('recaptcha_status') == true){
$this->session->set_flashdata('error_message',get_phrase('recaptcha_verification_failed'));
redirect(site_url('home/login'), 'refresh');
}
$data['first_name'] = html_escape($this->input->post('first_name'));
$data['last_name'] = html_escape($this->input->post('last_name'));
$data['email'] = html_escape($this->input->post('email'));
$data['password'] = sha1($this->input->post('password'));
if(empty($data['first_name']) || empty($data['last_name']) || empty($data['email']) || empty($data['password'])){
$this->session->set_flashdata('error_message',site_phrase('your_sign_up_form_is_empty').'. '.site_phrase('fill_out_the_form with_your_valid_data'));
redirect(site_url('home/sign_up'), 'refresh');
}
$verification_code = rand(100000, 200000);
$data['verification_code'] = $verification_code;
if (get_settings('student_email_verification') == 'enable') {
$data['status'] = 0;
}else {
$data['status'] = 1;
}
$data['wishlist'] = json_encode(array());
$data['watch_history'] = json_encode(array());
$data['date_added'] = strtotime(date("Y-m-d H:i:s"));
$social_links = array(
'facebook' => "",
'twitter' => "",
'linkedin' => ""
);
$data['social_links'] = json_encode($social_links);
$data['role_id'] = 2;
// Add paypal keys
$paypal_info = array();
$paypal['production_client_id'] = "";
array_push($paypal_info, $paypal);
$data['paypal_keys'] = json_encode($paypal_info);
// Add Stripe keys
$stripe_info = array();
$stripe_keys = array(
'public_live_key' => "",
'secret_live_key' => ""
);
array_push($stripe_info, $stripe_keys);
$data['stripe_keys'] = json_encode($stripe_info);
$validity = $this->user_model->check_duplication('on_create', $data['email']);
if($validity === 'unverified_user' || $validity == true) {
if($validity === true){
$this->user_model->register_user($data);
}else{
$this->user_model->register_user_update_code($data);
}
if (get_settings('student_email_verification') == 'enable') {
$this->email_model->send_email_verification_mail($data['email'], $verification_code);
if($validity === 'unverified_user'){
$this->session->set_flashdata('info_message', get_phrase('you_have_already_registered').'. '.get_phrase('please_verify_your_email_address'));
}else{
$this->session->set_flashdata('flash_message', get_phrase('your_registration_has_been_successfully_done').'. '.get_phrase('please_check_your_mail_inbox_to_verify_your_email_address').'.');
}
$this->session->set_userdata('register_email', $this->input->post('email'));
redirect(site_url('home/verification_code'), 'refresh');
}else {
$this->session->set_flashdata('flash_message', get_phrase('your_registration_has_been_successfully_done'));
redirect(site_url('home/login'), 'refresh');
}
}else {
$this->session->set_flashdata('error_message', get_phrase('you_have_already_registered'));
redirect(site_url('home/login'), 'refresh');
}
}
public function logout($from = "") {
//destroy sessions of specific userdata. We've done this for not removing the cart session
$this->session_destroy();
redirect(site_url('home/login'), 'refresh');
}
public function session_destroy() {
$this->session->unset_userdata('user_id');
$this->session->unset_userdata('role_id');
$this->session->unset_userdata('role');
$this->session->unset_userdata('name');
$this->session->unset_userdata('is_instructor');
if ($this->session->userdata('admin_login') == 1) {
$this->session->unset_userdata('admin_login');
}else {
$this->session->unset_userdata('user_login');
}
}
function forgot_password($from = "") {
if($this->crud_model->check_recaptcha() == false && get_frontend_settings('recaptcha_status') == true){
$this->session->set_flashdata('error_message',get_phrase('recaptcha_verification_failed'));
redirect(site_url('home/login'), 'refresh');
}
$email = $this->input->post('email');
//resetting user password here
$new_password = substr( md5( rand(100000000,20000000000) ) , 0,7);
// Checking credential for admin
$query = $this->db->get_where('users' , array('email' => $email));
if ($query->num_rows() > 0)
{
$this->db->where('email' , $email);
$this->db->update('users' , array('password' => sha1($new_password)));
// send new password to user email
$this->email_model->password_reset_email($new_password, $email);
$this->session->set_flashdata('flash_message', get_phrase('please_check_your_email_for_new_password'));
if ($from == 'backend') {
redirect(site_url('login'), 'refresh');
}else {
redirect(site_url('home'), 'refresh');
}
}else {
$this->session->set_flashdata('error_message', get_phrase('password_reset_failed'));
if ($from == 'backend') {
redirect(site_url('login'), 'refresh');
}else {
redirect(site_url('home'), 'refresh');
}
}
}
public function resend_verification_code(){
$email = $this->input->post('email');
$verification_code = $this->db->get_where('users', array('email' => $email))->row('verification_code');
$this->email_model->send_email_verification_mail($email, $verification_code);
return true;
}
public function verify_email_address() {
$email = $this->input->post('email');
$verification_code = $this->input->post('verification_code');
$user_details = $this->db->get_where('users', array('email' => $email, 'verification_code' => $verification_code));
if($user_details->num_rows() > 0) {
$user_details = $user_details->row_array();
$updater = array(
'status' => 1
);
$this->db->where('id', $user_details['id']);
$this->db->update('users', $updater);
$this->session->set_flashdata('flash_message', get_phrase('congratulations').'!'.get_phrase('your_email_address_has_been_successfully_verified').'.');
$this->session->set_userdata('register_email', null);
echo true;
}else{
$this->session->set_flashdata('error_message', get_phrase('the_verification_code_is_wrong').'.');
echo false;
}
}
function check_recaptcha_with_ajax(){
if($this->crud_model->check_recaptcha()){
echo true;
}else{
echo false;
}
}
}
/application/controllers/Modal.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* @author : Creativeitem
* date : 14 september, 2017
* Ekattor School Management System Pro
* http://codecanyon.net/user/Creativeitem
* http://support.creativeitem.com
*/
class Modal extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('session');
/*cache control*/
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
}
function popup($page_name = '' , $param2 = '' , $param3 = '', $param4 = '', $param5 = '', $param6 = '', $param7 = '')
{
$logged_in_user_role = strtolower($this->session->userdata('role'));
$page_data['param2'] = $param2;
$page_data['param3'] = $param3;
$page_data['param4'] = $param4;
$page_data['param5'] = $param5;
$page_data['param6'] = $param6;
$page_data['param7'] = $param7;
$this->load->view( 'backend/'.$logged_in_user_role.'/'.$page_name.'.php' ,$page_data);
}
}
/application/controllers/Updater.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/*
* @author : Creativeitem
* date : 7 October, 2018
* Academy
* http://codecanyon.net/user/Creativeitem
* http://support.creativeitem.com
*/
class Updater extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('session');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
}
/***default functin, redirects to login page if no admin logged in yet***/
public function index()
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
if ($this->session->userdata('admin_login') == 1)
redirect(site_url('admin/dashboard'), 'refresh');
}
/***** UPDATE PRODUCT *****/
function update($task = '', $purchase_code = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
// Create update directory.
$dir = 'update';
if (!is_dir($dir))
mkdir($dir, 0777, true);
$zipped_file_name = $_FILES["file_name"]["name"];
$path = 'update/' . $zipped_file_name;
if (class_exists('ZipArchive')) {
move_uploaded_file($_FILES["file_name"]["tmp_name"], $path);
// Unzip uploaded update file and remove zip file.
$zip = new ZipArchive;
$res = $zip->open($path);
$zip->extractTo('update');
$zip->close();
unlink($path);
}else{
$this->session->set_flashdata('error_message', get_phrase('your_server_is_unable_to_extract_the_zip_file').'. '.get_phrase('please_enable_the_zip_extension_on_your_server').', '.get_phrase('then_try_again'));
redirect(site_url('admin/system_settings'), 'refresh');
}
$unzipped_file_name = substr($zipped_file_name, 0, -4);
$str = file_get_contents('./update/' . $unzipped_file_name . '/update_config.json');
$json = json_decode($str, true);
if ($json['require_version'] != get_settings('version')){
$this->session->set_flashdata('error_message', get_phrase('it_looks_like_you_are_skipping_a_version').'. '.get_phrase('please_update_version').' '.$json['require_version'].' '.get_phrase('first'));
redirect(site_url('admin/system_settings'), 'refresh');
}
// Run php modifications
require './update/' . $unzipped_file_name . '/update_script.php';
// Create new directories.
if (!empty($json['directory'])) {
foreach ($json['directory'] as $directory) {
if (!is_dir($directory['name']))
mkdir($directory['name'], 0777, true);
}
}
// Create/Replace new files.
if (!empty($json['files'])) {
foreach ($json['files'] as $file)
copy($file['root_directory'], $file['update_directory']);
}
$this->session->set_flashdata('flash_message', get_phrase('product_updated_successfully'));
redirect(site_url('admin/system_settings'));
}
}
/application/controllers/User.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('session');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
// SESSION DATA FOR IS INSTRUCTOR
if (!$this->session->userdata('is_instructor')) {
$logged_in_user_details = $this->user_model->get_all_user($this->session->userdata('user_id'))->row_array();
$this->session->set_userdata('is_instructor', $logged_in_user_details['is_instructor']);
}
// THIS FUNCTION DECIDES WHTHER THE ROUTE IS REQUIRES PUBLIC INSTRUCTOR.
$this->get_protected_routes($this->router->method);
// THIS MIDDLEWARE FUNCTION CHECKS WHETHER THE USER IS TRYING TO ACCESS INSTRUCTOR STUFFS.
$this->instructor_authorization($this->router->method);
}
public function get_protected_routes($method)
{
// IF ANY FUNCTION DOES NOT REQUIRE PUBLIC INSTRUCTOR, PUT THE NAME HERE.
$unprotected_routes = ['save_course_progress'];
if (!in_array($method, $unprotected_routes)) {
if (get_settings('allow_instructor') != 1) {
redirect(site_url('home'), 'refresh');
}
}
}
public function instructor_authorization($method)
{
// IF THE USER IS NOT AN INSTRUCTOR HE/SHE CAN NEVER ACCESS THE OTHER FUNCTIONS EXCEPT FOR BELOW FUNCTIONS.
if ($this->session->userdata('is_instructor') != 1) {
$unprotected_routes = ['become_an_instructor', 'manage_profile', 'save_course_progress'];
if (!in_array($method, $unprotected_routes)) {
redirect(site_url('user/become_an_instructor'), 'refresh');
}
}
}
public function index()
{
if ($this->session->userdata('user_login') == true) {
$this->dashboard();
} else {
redirect(site_url('login'), 'refresh');
}
}
public function dashboard()
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'dashboard';
$page_data['page_title'] = get_phrase('dashboard');
$this->load->view('backend/index.php', $page_data);
}
public function courses()
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
$page_data['selected_category_id'] = isset($_GET['category_id']) ? $_GET['category_id'] : "all";
$page_data['selected_instructor_id'] = $this->session->userdata('user_id');
$page_data['selected_price'] = isset($_GET['price']) ? $_GET['price'] : "all";
$page_data['selected_status'] = isset($_GET['status']) ? $_GET['status'] : "all";
$page_data['courses'] = $this->crud_model->filter_course_for_backend($page_data['selected_category_id'], $page_data['selected_instructor_id'], $page_data['selected_price'], $page_data['selected_status']);
$page_data['page_name'] = 'courses-server-side';
$page_data['categories'] = $this->crud_model->get_categories();
$page_data['page_title'] = get_phrase('active_courses');
$this->load->view('backend/index', $page_data);
}
// This function is responsible for loading the course data from server side for datatable SILENTLY
public function get_courses()
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
$courses = array();
// Filter portion
$filter_data['selected_category_id'] = $this->input->post('selected_category_id');
$filter_data['selected_instructor_id'] = $this->input->post('selected_instructor_id');
$filter_data['selected_price'] = $this->input->post('selected_price');
$filter_data['selected_status'] = $this->input->post('selected_status');
// Server side processing portion
$columns = array(
0 => '#',
1 => 'title',
2 => 'category',
3 => 'lesson_and_section',
4 => 'enrolled_student',
5 => 'status',
6 => 'price',
7 => 'actions',
8 => 'course_id'
);
// Coming from databale itself. Limit is the visible number of data
$limit = html_escape($this->input->post('length'));
$start = html_escape($this->input->post('start'));
$order = "";
$dir = $this->input->post('order')[0]['dir'];
$totalData = $this->lazyload->count_all_courses($filter_data);
$totalFiltered = $totalData;
// This block of code is handling the search event of datatable
if (empty($this->input->post('search')['value'])) {
$courses = $this->lazyload->courses($limit, $start, $order, $dir, $filter_data);
} else {
$search = $this->input->post('search')['value'];
$courses = $this->lazyload->course_search($limit, $start, $search, $order, $dir, $filter_data);
$totalFiltered = $this->lazyload->course_search_count($search);
}
// Fetch the data and make it as JSON format and return it.
$data = array();
if (!empty($courses)) {
foreach ($courses as $key => $row) {
$instructor_details = $this->user_model->get_all_user($row->user_id)->row_array();
$category_details = $this->crud_model->get_category_details_by_id($row->sub_category_id)->row_array();
$sections = $this->crud_model->get_section('course', $row->id);
$lessons = $this->crud_model->get_lessons('course', $row->id);
$enroll_history = $this->crud_model->enrol_history($row->id);
$status_badge = "badge-success-lighten";
if ($row->status == 'pending') {
$status_badge = "badge-danger-lighten";
} elseif ($row->status == 'draft') {
$status_badge = "badge-dark-lighten";
}
$price_badge = "badge-dark-lighten";
$price = 0;
if ($row->is_free_course == null) {
if ($row->discount_flag == 1) {
$price = currency($row->discounted_price);
} else {
$price = currency($row->price);
}
} elseif ($row->is_free_course == 1) {
$price_badge = "badge-success-lighten";
$price = get_phrase('free');
}
$view_course_on_frontend_url = site_url('home/course/' . rawurlencode(slugify($row->title)) . '/' . $row->id);
$edit_this_course_url = site_url('user/course_form/course_edit/' . $row->id);
$section_and_lesson_url = site_url('user/course_form/course_edit/' . $row->id);
if ($row->status == 'active' || $row->status == 'pending') {
$course_status_changing_action = "confirm_modal('" . site_url('user/course_actions/draft/' . $row->id) . "')";
$course_status_changing_message = get_phrase('mark_as_drafted');
} else {
$course_status_changing_action = "confirm_modal('" . site_url('user/course_actions/publish/' . $row->id) . "')";
$course_status_changing_message = get_phrase('publish_this_course');
}
$delete_course_url = "confirm_modal('" . site_url('user/course_actions/delete/' . $row->id) . "')";
if ($row->course_type != 'scorm') {
$section_and_lesson_menu = '<li><a class="dropdown-item" href="' . $section_and_lesson_url . '">' . get_phrase("section_and_lesson") . '</a></li>';
} else {
$section_and_lesson_menu = "";
}
$action = '
<div class="dropright dropright">
<button type="button" class="btn btn-sm btn-outline-primary btn-rounded btn-icon" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="mdi mdi-dots-vertical"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="' . $view_course_on_frontend_url . '" target="_blank">' . get_phrase("view_course_on_frontend") . '</a></li>
<li><a class="dropdown-item" href="' . $edit_this_course_url . '">' . get_phrase("edit_this_course") . '</a></li>
' . $section_and_lesson_menu . '
<li><a class="dropdown-item" href="javascript::" onclick="' . $course_status_changing_action . '">' . $course_status_changing_message . '</a></li>
<li><a class="dropdown-item" href="javascript::" onclick="' . $delete_course_url . '">' . get_phrase("delete") . '</a></li>
</ul>
</div>
';
$nestedData['#'] = $key + 1;
$instructor_names = "";
if ($row->multi_instructor) {
$instructors = $this->user_model->get_multi_instructor_details_with_csv($row->user_id);
foreach ($instructors as $counterForThis => $instructor) {
$instructor_names .= $instructor['first_name'] . ' ' . $instructor['last_name'];
$instructor_names .= $counterForThis + 1 == count($instructors) ? '' : ', ';
}
} else {
$instructor_names = $instructor_details['first_name'] . ' ' . $instructor_details['last_name'];
}
$nestedData['title'] = '<strong><a href="' . site_url('user/course_form/course_edit/' . $row->id) . '">' . $row->title . '</a></strong><br>
<small class="text-muted">' . get_phrase('instructor') . ': <b>' . $instructor_names . '</b></small>';
$nestedData['category'] = '<span class="badge badge-dark-lighten">' . $category_details['name'] . '</span>';
if ($row->course_type == 'scorm') {
$nestedData['lesson_and_section'] = '<span class="badge badge-info-lighten">' . get_phrase('scorm_course') . '</span>';
} elseif ($row->course_type == 'general') {
$nestedData['lesson_and_section'] = '
<small class="text-muted"><b>' . get_phrase('total_section') . '</b>: ' . $sections->num_rows() . '</small><br>
<small class="text-muted"><b>' . get_phrase('total_lesson') . '</b>: ' . $lessons->num_rows() . '</small>';
}
$nestedData['enrolled_student'] = '<small class="text-muted"><b>' . get_phrase('total_enrolment') . '</b>: ' . $enroll_history->num_rows() . '</small>';
$nestedData['status'] = '<span class="badge ' . $status_badge . '">' . get_phrase($row->status) . '</span>';
$nestedData['price'] = '<span class="badge ' . $price_badge . '">' . $price . '</span>';
$nestedData['actions'] = $action;
$nestedData['course_id'] = $row->id;
$data[] = $nestedData;
}
}
$json_data = array(
"draw" => intval($this->input->post('draw')),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
);
echo json_encode($json_data);
}
public function course_actions($param1 = "", $param2 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param1 == "add") {
$course_id = $this->crud_model->add_course();
redirect(site_url('user/course_form/course_edit/' . $course_id), 'refresh');
} elseif ($param1 == "edit") {
$this->is_the_course_belongs_to_current_instructor($param2);
$this->crud_model->update_course($param2);
// CHECK IF LIVE CLASS ADDON EXISTS, ADD OR UPDATE IT TO ADDON MODEL
if (addon_status('live-class')) {
$this->load->model('addons/Liveclass_model', 'liveclass_model');
$this->liveclass_model->update_live_class($param2);
}
redirect(site_url('user/course_form/course_edit/' . $param2));
} elseif ($param1 == 'add_shortcut') {
echo $this->crud_model->add_shortcut_course();
} elseif ($param1 == 'delete') {
$this->is_the_course_belongs_to_current_instructor($param2);
$this->crud_model->delete_course($param2);
redirect(site_url('user/courses'), 'refresh');
} elseif ($param1 == 'draft') {
$this->is_the_course_belongs_to_current_instructor($param2);
$this->crud_model->change_course_status('draft', $param2);
redirect(site_url('user/courses'), 'refresh');
} elseif ($param1 == 'publish') {
$this->is_the_course_belongs_to_current_instructor($param2);
$this->crud_model->change_course_status('pending', $param2);
redirect(site_url('user/courses'), 'refresh');
}
}
public function course_form($param1 = "", $param2 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'add_course') {
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['categories'] = $this->crud_model->get_categories();
$page_data['page_name'] = 'course_add';
$page_data['page_title'] = get_phrase('add_course');
$this->load->view('backend/index', $page_data);
} elseif ($param1 == 'add_course_shortcut') {
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['categories'] = $this->crud_model->get_categories();
$this->load->view('backend/user/course_add_shortcut', $page_data);
} elseif ($param1 == 'course_edit') {
$this->is_the_course_belongs_to_current_instructor($param2);
$page_data['page_name'] = 'course_edit';
$page_data['course_id'] = $param2;
$page_data['page_title'] = get_phrase('edit_course');
$page_data['languages'] = $this->crud_model->get_all_languages();
$page_data['categories'] = $this->crud_model->get_categories();
$this->load->view('backend/index', $page_data);
}
}
public function payout_settings($param1 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'paypal_settings') {
$this->user_model->update_instructor_paypal_settings($this->session->userdata('user_id'));
$this->session->set_flashdata('flash_message', get_phrase('updated'));
redirect(site_url('user/payout_settings'), 'refresh');
}
if ($param1 == 'stripe_settings') {
$this->user_model->update_instructor_stripe_settings($this->session->userdata('user_id'));
$this->session->set_flashdata('flash_message', get_phrase('updated'));
redirect(site_url('user/payout_settings'), 'refresh');
}
$page_data['page_name'] = 'payment_settings';
$page_data['page_title'] = get_phrase('payout_settings');
$this->load->view('backend/index', $page_data);
}
public function sales_report($param1 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param1 != "") {
$date_range = $this->input->get('date_range');
$date_range = explode(" - ", $date_range);
$page_data['timestamp_start'] = strtotime($date_range[0] . ' 00:00:00');
$page_data['timestamp_end'] = strtotime($date_range[1] . ' 23:59:59');
} else {
$page_data['timestamp_start'] = strtotime(date("m/01/Y 00:00:00"));
$page_data['timestamp_end'] = strtotime(date("m/t/Y 23:59:59"));
}
$page_data['payment_history'] = $this->crud_model->get_instructor_revenue($this->session->userdata('user_id'), $page_data['timestamp_start'], $page_data['timestamp_end']);
$page_data['page_name'] = 'sales_report';
$page_data['page_title'] = get_phrase('sales_report');
$this->load->view('backend/index', $page_data);
}
public function preview($course_id = '')
{
if ($this->session->userdata('user_login') != 1)
redirect(site_url('login'), 'refresh');
$this->is_the_course_belongs_to_current_instructor($course_id);
if ($course_id > 0) {
$courses = $this->crud_model->get_course_by_id($course_id);
if ($courses->num_rows() > 0) {
$course_details = $courses->row_array();
redirect(site_url('home/lesson/' . rawurlencode(slugify($course_details['title'])) . '/' . $course_details['id']), 'refresh');
}
}
redirect(site_url('user/courses'), 'refresh');
}
public function sections($param1 = "", $param2 = "", $param3 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param2 == 'add') {
$this->is_the_course_belongs_to_current_instructor($param1);
$this->crud_model->add_section($param1);
$this->session->set_flashdata('flash_message', get_phrase('section_has_been_added_successfully'));
} elseif ($param2 == 'edit') {
$this->is_the_course_belongs_to_current_instructor($param1, $param3, 'section');
$this->crud_model->edit_section($param3);
$this->session->set_flashdata('flash_message', get_phrase('section_has_been_updated_successfully'));
} elseif ($param2 == 'delete') {
$this->is_the_course_belongs_to_current_instructor($param1, $param3, 'section');
$this->crud_model->delete_section($param1, $param3);
$this->session->set_flashdata('flash_message', get_phrase('section_has_been_deleted_successfully'));
}
redirect(site_url('user/course_form/course_edit/' . $param1));
}
public function lessons($course_id = "", $param1 = "", $param2 = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($param1 == 'add') {
$this->is_the_course_belongs_to_current_instructor($course_id);
$this->crud_model->add_lesson();
$this->session->set_flashdata('flash_message', get_phrase('lesson_has_been_added_successfully'));
redirect('user/course_form/course_edit/' . $course_id);
} elseif ($param1 == 'edit') {
$this->is_the_course_belongs_to_current_instructor($course_id, $param2, 'lesson');
$this->crud_model->edit_lesson($param2);
$this->session->set_flashdata('flash_message', get_phrase('lesson_has_been_updated_successfully'));
redirect('user/course_form/course_edit/' . $course_id);
} elseif ($param1 == 'delete') {
$this->is_the_course_belongs_to_current_instructor($course_id, $param2, 'lesson');
$this->crud_model->delete_lesson($param2);
$this->session->set_flashdata('flash_message', get_phrase('lesson_has_been_deleted_successfully'));
redirect('user/course_form/course_edit/' . $course_id);
} elseif ($param1 == 'filter') {
redirect('user/lessons/' . $this->input->post('course_id'));
}
$page_data['page_name'] = 'lessons';
$page_data['lessons'] = $this->crud_model->get_lessons('course', $course_id);
$page_data['course_id'] = $course_id;
$page_data['page_title'] = get_phrase('lessons');
$this->load->view('backend/index', $page_data);
}
// Manage Quizes
public function quizes($course_id = "", $action = "", $quiz_id = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($action == 'add') {
$this->is_the_course_belongs_to_current_instructor($course_id);
$this->crud_model->add_quiz($course_id);
$this->session->set_flashdata('flash_message', get_phrase('quiz_has_been_added_successfully'));
} elseif ($action == 'edit') {
$this->is_the_course_belongs_to_current_instructor($course_id, $quiz_id, 'quize');
$this->crud_model->edit_quiz($quiz_id);
$this->session->set_flashdata('flash_message', get_phrase('quiz_has_been_updated_successfully'));
} elseif ($action == 'delete') {
$this->is_the_course_belongs_to_current_instructor($course_id, $quiz_id, 'quize');
$this->crud_model->delete_lesson($quiz_id);
$this->session->set_flashdata('flash_message', get_phrase('quiz_has_been_deleted_successfully'));
}
redirect(site_url('user/course_form/course_edit/' . $course_id));
}
// Manage Quize Questions
public function quiz_questions($quiz_id = "", $action = "", $question_id = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
$quiz_details = $this->crud_model->get_lessons('lesson', $quiz_id)->row_array();
if ($action == 'add') {
$this->is_the_course_belongs_to_current_instructor($quiz_details['course_id'], $quiz_id, 'quize');
$response = $this->crud_model->add_quiz_questions($quiz_id);
echo $response;
} elseif ($action == 'edit') {
if ($this->db->get_where('question', array('id' => $question_id, 'quiz_id' => $quiz_id))->num_rows() <= 0) {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_quiz_question'));
redirect(site_url('user/courses'), 'refresh');
}
$response = $this->crud_model->update_quiz_questions($question_id);
echo $response;
} elseif ($action == 'delete') {
if ($this->db->get_where('question', array('id' => $question_id, 'quiz_id' => $quiz_id))->num_rows() <= 0) {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_quiz_question'));
redirect(site_url('user/courses'), 'refresh');
}
$response = $this->crud_model->delete_quiz_question($question_id);
$this->session->set_flashdata('flash_message', get_phrase('question_has_been_deleted'));
redirect(site_url('user/course_form/course_edit/' . $quiz_details['course_id']));
}
}
function manage_profile()
{
redirect(site_url('home/profile/user_profile'), 'refresh');
}
function invoice($payment_id = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'invoice';
$page_data['payment_details'] = $this->crud_model->get_payment_details_by_id($payment_id);
$page_data['page_title'] = get_phrase('invoice');
$this->load->view('backend/index', $page_data);
}
function become_an_instructor()
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
// CHEKING IF A FORM HAS BEEN SUBMITTED FOR REGISTERING AN INSTRUCTOR
if (isset($_POST) && !empty($_POST)) {
$this->user_model->post_instructor_application();
}
// CHECK USER AVAILABILITY
$user_details = $this->user_model->get_all_user($this->session->userdata('user_id'));
if ($user_details->num_rows() > 0) {
$page_data['user_details'] = $user_details->row_array();
} else {
$this->session->set_flashdata('error_message', get_phrase('user_not_found'));
$this->load->view('backend/index', $page_data);
}
$page_data['page_name'] = 'become_an_instructor';
$page_data['page_title'] = get_phrase('become_an_instructor');
$this->load->view('backend/index', $page_data);
}
// PAYOUT REPORT
public function payout_report()
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
$page_data['page_name'] = 'payout_report';
$page_data['page_title'] = get_phrase('payout_report');
$page_data['payouts'] = $this->crud_model->get_payouts($this->session->userdata('user_id'), 'user');
$page_data['total_pending_amount'] = $this->crud_model->get_total_pending_amount($this->session->userdata('user_id'));
$page_data['total_payout_amount'] = $this->crud_model->get_total_payout_amount($this->session->userdata('user_id'));
$page_data['requested_withdrawal_amount'] = $this->crud_model->get_requested_withdrawal_amount($this->session->userdata('user_id'));
$this->load->view('backend/index', $page_data);
}
// HANDLED WITHDRAWAL REQUESTS
public function withdrawal($action = "")
{
if ($this->session->userdata('user_login') != true) {
redirect(site_url('login'), 'refresh');
}
if ($action == 'request') {
$this->crud_model->add_withdrawal_request();
}
if ($action == 'delete') {
$this->crud_model->delete_withdrawal_request();
}
redirect(site_url('user/payout_report'), 'refresh');
}
// Ajax Portion
public function ajax_get_video_details()
{
$video_details = $this->video_model->getVideoDetails($_POST['video_url']);
echo $video_details['duration'];
}
// this function is responsible for managing multiple choice question
function manage_multiple_choices_options()
{
$page_data['number_of_options'] = $this->input->post('number_of_options');
$this->load->view('backend/user/manage_multiple_choices_options', $page_data);
}
// This function checks if this course belongs to current logged in instructor
function is_the_course_belongs_to_current_instructor($course_id, $id = null, $type = null)
{
$course_details = $this->crud_model->get_course_by_id($course_id)->row_array();
if ($course_details['multi_instructor']) {
$instructor_ids = explode(',', $course_details['user_id']);
if (!in_array($this->session->userdata('user_id'), $instructor_ids)) {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_course'));
redirect(site_url('user/courses'), 'refresh');
}
} else {
if ($course_details['user_id'] != $this->session->userdata('user_id')) {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_course'));
redirect(site_url('user/courses'), 'refresh');
}
}
if ($type == 'section' && $this->db->get_where('section', array('id' => $id, 'course_id' => $course_id))->num_rows() <= 0) {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_section'));
redirect(site_url('user/courses'), 'refresh');
}
if ($type == 'lesson' && $this->db->get_where('lesson', array('id' => $id, 'course_id' => $course_id))->num_rows() <= 0) {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_lesson'));
redirect(site_url('user/courses'), 'refresh');
}
if ($type == 'quize' && $this->db->get_where('lesson', array('id' => $id, 'course_id' => $course_id))->num_rows() <= 0) {
$this->session->set_flashdata('error_message', get_phrase('you_do_not_have_right_to_access_this_quize'));
redirect(site_url('user/courses'), 'refresh');
}
}
public function ajax_sort_section()
{
$section_json = $this->input->post('itemJSON');
$this->crud_model->sort_section($section_json);
}
public function ajax_sort_lesson()
{
$lesson_json = $this->input->post('itemJSON');
$this->crud_model->sort_lesson($lesson_json);
}
public function ajax_sort_question()
{
$question_json = $this->input->post('itemJSON');
$this->crud_model->sort_question($question_json);
}
// Mark this lesson as completed codes
function save_course_progress()
{
$response = $this->crud_model->save_course_progress();
echo $response;
}
// REMOVING INSTRUCTOR FROM COURSE
public function remove_an_instructor($course_id, $instructor_id)
{
$course_details = $this->crud_model->get_course_by_id($course_id)->row_array();
if ($course_details['creator'] == $instructor_id) {
$this->session->set_flashdata('error_message', get_phrase('course_creator_can_be_removed'));
redirect('admin/course_form/course_edit/' . $course_id);
}
if ($course_details['multi_instructor']) {
$instructor_ids = explode(',', $course_details['user_id']);
if (in_array($instructor_id, $instructor_ids) && in_array($this->session->userdata('user_id'), $instructor_ids)) {
if (count($instructor_ids) > 1) {
if (($key = array_search($instructor_id, $instructor_ids)) !== false) {
unset($instructor_ids[$key]);
$data['user_id'] = implode(",", $instructor_ids);
$this->db->where('id', $course_id);
$this->db->update('course', $data);
$this->session->set_flashdata('flash_message', get_phrase('instructor_has_been_removed'));
if ($this->session->userdata('user_id') == $instructor_id) {
redirect('user/courses/');
} else {
redirect('user/course_form/course_edit/' . $course_id);
}
}
} else {
$this->session->set_flashdata('error_message', get_phrase('a_course_should_have_at_least_one_instructor'));
redirect('user/course_form/course_edit/' . $course_id);
}
} else {
$this->session->set_flashdata('error_message', get_phrase('invalid_instructor_id'));
redirect('user/course_form/course_edit/' . $course_id);
}
} else {
$this->session->set_flashdata('error_message', get_phrase('a_course_should_have_at_least_one_instructor'));
redirect('user/course_form/course_edit/' . $course_id);
}
}
}
/application/controllers/Addons/