KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /var/www/parasoffline.edukrypt.in/application/modules/admin/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/parasoffline.edukrypt.in/application/modules/admin/controllers/Regfile.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Regfile extends Admin_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->model(['Permission_model']);
	}

	public function check()
	{
		$this->mViewData['p_type']  = "list";
		$this->mViewData['message'] = $this->session->flashdata('upload_success');

		$admin_id = $this->session->userdata('user_id');

		$query_c  = $this->db->where('admin_id', $admin_id)->get('courses');

		$courses = [];

		if ($query_c->num_rows() > 0) {
			$courses  = $query_c->result();
		}

		$query_u  = $this->db->select('id')->where('admin_id', $admin_id)->get('users');

		$users = [];

		if ($query_u->num_rows() > 0) {
			$users  = $query_u->result();
		}

		$this->mViewData['courses'] = $courses;
		$this->mViewData['users']   = $users;
		$this->mTitle .= 'Permission | Regfiles List';

		$this->render('regfile/permission_list');
	}

	public function check2()
	{
		$crud = $this->generate_crud('regfiles');

		$crud->set_relation('admin_id', 'admin_users', 'username');
		$crud->set_relation('lecture_id', 'lectures', 'file_name');
		$crud->where('regfiles.admin_id', $this->session->userdata('user_id'));
		//$crud->set_relation_n_n('lectures',null, 'lectures', 'lecture_id', 'id', 'file_name');
		$crud->columns('pos', 'lecture_id', 'str_dt', 'end_dt', 'noofplay', 'user_id', 'admin_id', 'reg_dt');

		$crud->display_as('admin_id', 'Admin');
		$crud->display_as('pos', 'Position');
		$crud->display_as('lecture_id', 'Lecture');

		$crud->unset_add();
		$crud->unset_edit();
		$this->mTitle .= 'Regfiles';
		$this->render_crud();
	}

	// Full Course Permission 
	public function course()
	{
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {

			$users = $this->input->post('users');
			$totalFile = count($this->input->post('checkbox1'));
			if ($totalFile <= 0) {
				$this->session->set_flashdata('regfile_err', 'Please select lecture form the list...!');
				redirect('admin/regfile/course');
			}

			$admin_id = $this->session->userdata('user_id');
			$file_id = $this->input->post('checkbox1');
			$noofplay = $this->input->post('noofplay');
			$str_dt = $this->input->post('str_dt');
			$end_dt = $this->input->post('end_dt');
			$permission_type = $this->input->post('permission_type');
			$reg_dt = date('Y-m-d');

			// last Position Find
			$this->db->order_by("pos", "desc");
			$query = $this->db->get('regfiles', 1);

			if (isset($query->result_array()[0])) {
				$pos = $query->result_array()[0]['pos'] + 0;
			} else {
				$pos = 0;
			}
			// Total File Selected

			foreach ($users as $user) {

				for ($i = 0; $i < $totalFile; $i++) {

					// Get Lectures Details
					$this->db->where('id', $file_id[$i]);
					$lectureQuery = $this->db->get('lectures', 1);
					if ($lectureQuery->num_rows() < 1) {
						$this->session->set_flashdata('regfile_err', 'Lecture not fount!');
						redirect('admin/regfile/course');
					}

					// Total Duration
					$duration = $lectureQuery->result_array()[0]['duration'];
					$total = ($noofplay *  $duration);
					$remain = ($noofplay *  $duration);

					$this->db->where("lecture_id", $file_id[$i]);
					$this->db->where("user_id", $user);
					$this->db->where("admin_id", $admin_id);
					$query = $this->db->get('regfiles', 1);

					if ($query->num_rows() != 0) {
						$id = $query->result_array()[0]['id'];

						$data = array(
							'lecture_id' => $file_id[$i],
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $noofplay,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'permission_type' => $permission_type,
							'last_update' => uniqid('', true),
							'action' => '1',
						);

						$this->db->where('id', $id);
						$this->db->update('regfiles', $data);
					} else {
						$pos = $pos + 1;
						$data = array(
							'lecture_id' => $file_id[$i],
							'admin_id' => $admin_id,
							'user_id' => $user,
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $noofplay,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'reg_dt' => $reg_dt,
							'permission_type' => $permission_type,
							'last_update' => uniqid('', true),
							'pos' => $pos,
							'action' => '0',
						);

						$this->db->insert('regfiles', $data);
					}
				}
			}


			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('regfile_success', 'Well done! You successfully Registred Files.');
				redirect('admin/regfile/course');
			}
		} else {
			// StyleSheets
			$this->mStylesheets['datatable'] = array();
			$this->mViewData['message'] = $this->session->flashdata('regfile_success');
			$this->mViewData['err_message'] = $this->session->flashdata('regfile_err');
			$clients = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('users');
			$this->mViewData['client'] = $clients->result();
			$courses = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('courses');
			$this->mViewData['course'] = $courses->result();
			$query2 = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('tags');
			$this->mViewData['groups']  = $query2->result();

			$this->mTitle = 'Course Registration';
			$this->render('regfile/file_course');
		}
	}

	public function subject()
	{

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {

			$users = $this->input->post('users');
			$totalFile = count($this->input->post('checkbox1'));
			if ($totalFile <= 0) {
				$this->session->set_flashdata('regfile_err', 'Please select lecture form the list...!');
				redirect('admin/regfile/subject');
			};

			$admin_id = $this->session->userdata('user_id');
			$file_id = $this->input->post('checkbox1');
			$noofplay = $this->input->post('noofplay');
			$str_dt = $this->input->post('str_dt');
			$end_dt = $this->input->post('end_dt');
			$permission_type     = $this->input->post('permission_type');
			$reg_dt = date('Y-m-d');

			// last Position Find
			$this->db->order_by("pos", "desc");
			$query = $this->db->get('regfiles', 1);

			if (isset($query->result_array()[0])) {
				$pos = $query->result_array()[0]['pos'] + 0;
			} else {
				$pos = 0;
			}

			// Total File Selected
			foreach ($users as $user) {

				for ($i = 0; $i < $totalFile; $i++) {

					// Get Lectures Details
					$this->db->where('id', $file_id[$i]);
					$lectureQuery = $this->db->get('lectures', 1);
					if ($lectureQuery->num_rows() < 1) {
						$this->session->set_flashdata('regfile_err', 'Lecture not fount!');
						redirect('admin/regfile/course');
					}

					// Total Duration
					$duration = $lectureQuery->result_array()[0]['duration'];
					$total = ($noofplay *  $duration);
					$remain = ($noofplay *  $duration);

					$this->db->where("lecture_id", $file_id[$i]);
					$this->db->where("user_id", $user);
					$this->db->where("admin_id", $admin_id);
					$query = $this->db->get('regfiles', 1);

					if ($query->num_rows() != 0) {
						$id = $query->result_array()[0]['id'];

						$data = array(
							'lecture_id' => $file_id[$i],
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $noofplay,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'permission_type' => $permission_type,
							'last_update' => uniqid('', true),
							'action' => '1',
						);

						$this->db->where('id', $id);
						$this->db->update('regfiles', $data);
					} else {
						$pos = $pos + 1;
						$data = array(
							'lecture_id' => $file_id[$i],
							'admin_id' => $admin_id,
							'user_id' => $user,
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $noofplay,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'reg_dt' => $reg_dt,
							'permission_type' => $permission_type,
							'last_update' => uniqid('', true),
							'pos' => $pos,
							'action' => '0',
						);

						$this->db->insert('regfiles', $data);
					}
				}
			}

			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('regfile_success', 'Well done! You successfully Registred Files.');
				redirect('admin/regfile/subject');
			}
		} else {
			// StyleSheets
			$this->mStylesheets['datatable'] = array();
			$this->mViewData['message'] = $this->session->flashdata('regfile_success');
			$this->mViewData['err_message'] = $this->session->flashdata('regfile_err');
			$clients = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('users');
			$this->mViewData['client'] = $clients->result();
			$courses = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('courses');
			$this->mViewData['course'] = $courses->result();
			$query2 = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('tags');
			$this->mViewData['groups']  = $query2->result();
			$this->mTitle = 'Subject Registration';
			$this->render('regfile/file_subject');
		}
	}

	// Course Crud
	public function file()
	{
		// print_r($_POST);exit;
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			$totalFile  = count($this->input->post('checkbox1'));
			$totalFile1 = count($this->input->post('checkbox2'));
			$totalFile2 = count($this->input->post('checkbox3'));

			if ($totalFile <= 0 && $totalFile1 <= 0 && $totalFile2 <= 0) {
				$this->session->set_flashdata('regfile_err', 'Please select atleast lecture, quiz or documents form these list...!');
				redirect('admin/regfile/file');
			}

			$user_id    = $this->input->post('users');
			$admin_id   = $this->session->userdata('user_id');
			$file_id    = $this->input->post('checkbox1');
			$quiz_id    = $this->input->post('checkbox2');
			$doc_id     = $this->input->post('checkbox3');
			$no_of_file = $this->input->post('noofplay');
			$str_dt     = $this->input->post('str_dt');
			$end_dt     = $this->input->post('end_dt');
			$permission_type     = $this->input->post('permission_type');
			$reg_dt     = date('Y-m-d');

			$last_updated = uniqid();

			// last Position Find
			$this->db->order_by("pos", "desc");
			$query = $this->db->get('regfiles', 1);

			if (isset($query->result_array()[0])) {
				$pos = $query->result_array()[0]['pos'] + 0;
			} else {
				$pos = 0;
			}

			$total_aff = 0;
			// Total File Selected

			foreach ($user_id as $user_id2) {
				for ($i = 0; $i < $totalFile; $i++) {

					// Get Lectures Details
					$this->db->where('id', $file_id[$i]);
					$lectureQuery = $this->db->get('lectures', 1);
					if ($lectureQuery->num_rows() < 1) {
						$this->session->set_flashdata('regfile_err', 'Lecture not fount!');
						redirect('admin/regfile/file');
					}

					// Total Duration
					$duration = $lectureQuery->result_array()[0]['duration'];
					$total = ($no_of_file *  $duration);
					$remain = ($no_of_file *  $duration);

					$this->db->where("lecture_id", $file_id[$i]);
					$this->db->where("user_id", $user_id2);
					$this->db->where("admin_id", $admin_id);
					$query = $this->db->get('regfiles', 1);

					if ($query->num_rows() != 0) {
						$id = $query->result_array()[0]['id'];
						$data = array(
							'lecture_id' => $file_id[$i],
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $no_of_file,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'last_update' => $last_updated,
							'permission_type' => $permission_type,
							'action' => '1',
						);

						$this->db->where('id', $id);
						$this->db->update('regfiles', $data);
					} else {
						$pos = $pos + 1;
						$data = array(
							'lecture_id' => $file_id[$i],
							'admin_id' => $admin_id,
							'user_id' => $user_id2,
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $no_of_file,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'reg_dt' => $reg_dt,
							'last_update' => $last_updated,
							'permission_type' => $permission_type,
							'pos' => $pos,
							'action' => '0',
						);

						$this->db->insert('regfiles', $data);
						$total_aff += $this->db->affected_rows();
					}
				}

				for ($i = 0; $i < $totalFile1; $i++) {
					$this->db->where("lecture_id", $quiz_id[$i]);
					$this->db->where("user_id", $user_id2);
					$this->db->where("admin_id", $admin_id);
					$query = $this->db->get('regfiles', 1);

					if ($query->num_rows() != 0) {
						$id = $query->result_array()[0]['id'];

						$data_q = array(
							'lecture_id' => $quiz_id[$i],
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $no_of_file,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'last_update' => $last_updated,
							'permission_type' => $permission_type,
							'action' => '1',
						);

						$this->db->where('id', $id);
						$this->db->update('regfiles', $data_q);
					} else {
						$pos = $pos + 1;

						$data_q = array(
							'lecture_id' => $quiz_id[$i],
							'admin_id' => $admin_id,
							'user_id' => $user_id2,
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $no_of_file,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'reg_dt' => $reg_dt,
							'last_update' => $last_updated,
							'permission_type' => $permission_type,
							'pos' => $pos,
							'action' => '0',
						);

						$result = $this->db->insert('regfiles', $data_q);

						$total_aff += $this->db->affected_rows();
					}
				}

				for ($i = 0; $i < $totalFile2; $i++) {
					$this->db->where("lecture_id", $doc_id[$i]);
					$this->db->where("user_id", $user_id2);
					$this->db->where("admin_id", $admin_id);
					$query = $this->db->get('regfiles', 1);

					if ($query->num_rows() != 0) {
						$id = $query->result_array()[0]['id'];

						$data_d = array(
							'lecture_id' => $doc_id[$i],
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $no_of_file,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'last_update' => $last_updated,
							'permission_type' => $permission_type,
							'action' => '1',
						);

						$this->db->where('id', $id);
						$this->db->update('regfiles', $data_d);
					} else {
						$pos = $pos + 1;

						$data_d = array(
							'lecture_id' => $doc_id[$i],
							'admin_id' => $admin_id,
							'user_id' => $user_id2,
							'str_dt' => $str_dt,
							'end_dt' => $end_dt,
							'noofplay' => $no_of_file,
							'total_duration' => $total,
							'remain_duration' => $remain,
							'reg_dt' => $reg_dt,
							'last_update' => $last_updated,
							'permission_type' => $permission_type,
							'pos' => $pos,
							'action' => '0',
						);

						$this->db->insert('regfiles', $data_d);
						$total_aff += $this->db->affected_rows();
					}
				}
			}

			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('regfile_success', 'Well done! You successfully Registred total ' . $total_aff . ' Files.');
				redirect('admin/regfile/file');
			}
		} else {
			// StyleSheets
			$this->mStylesheets['datatable'] = array();

			$query2 = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('tags');

			$this->mScripts['foot'] = array(
				'assets_dt/datatables/jquery.dataTables.min.js',
				'assets_dt/datatables/dataTables.bootstrap.js'
			);
			$this->mViewData['message'] = $this->session->flashdata('regfile_success');
			$this->mViewData['err_message'] = $this->session->flashdata('regfile_err');
			$clients = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('users');
			$this->mViewData['client'] = $clients->result();
			$courses = $this->db->where('admin_id', $this->session->userdata('user_id'))->get('courses');
			$this->mViewData['course'] = $courses->result();
			$this->mViewData['groups']  = $query2->result();
			$this->mTitle = 'File Registration';
			$this->render('regfile/file');
		}
	}


	public function get_subject_video()
	{
		if ($this->input->post('subject_id') != '') {

			// SELECT t1.subject,t1.admin_id,t2.chapter,t3.file_name,t3.name,t3.id as lectureId  from subjects as t1 INNER JOIN chapters as t2 on t1.id = t2.subject_id INNER JOIN lectures as t3 on t2.id = t3.chapter_id and t1.id = 198 and  t1.admin_id = 21 and course_id=212

			$cid = $this->input->post('subject_id');

			$this->db->select('subjects.subject,chapters.chapter,chapters.admin_id,chapters.subject_id,lectures.id as lecturesId,lectures.file_name,lectures.name,lectures.chapter_id,lectures.e_type');
			$this->db->from('subjects');
			$this->db->join('chapters', 'subjects.id = chapters.subject_id');
			$this->db->join('lectures', 'chapters.id = lectures.chapter_id');
			$this->db->where('chapters.subject_id', $cid);
			$this->db->where('lectures.admin_id', $this->session->userdata('user_id'));
			$query = $this->db->get();

			foreach ($query->result() as $result) {
				echo '<tr id="tr' . $result->lecturesId . '">';
				echo '<td><input  type="checkbox" class="checkbox1" id="checkbox' . $result->lecturesId . '" name="checkbox1[]" value="' . $result->lecturesId . '"/></td>';
				echo '<td>' . $result->lecturesId . '</td>';
				echo '<td>' . $result->file_name . '</td>';
				echo '<td>' . $result->name . '</td>';
				echo '<td>' . $result->e_type . '</td>';
				echo '</tr>';
			}
		}
	}



	public function get_group_users()
	{
		if ($this->input->post('group_id') != '') {
			$group_ids = $this->input->post('group_id');

			$this->db->select('users.id,users.username');
			$this->db->from('users');
			$this->db->where('admin_id', $this->session->userdata('user_id'));
			// $this->db->like('tags', 'tags.id = users.tag_id');
			//$iddd = ",".$group_id.",";

			$i = 1;
			foreach ($group_ids as $group_id) {
				if ($i == 1) {
					$this->db->where("CONCAT(',', tag_id, ',') LIKE '%,$group_id,%'");
				} else {
					$this->db->or_where("CONCAT(',', tag_id, ',') LIKE '%,$group_id,%'");
				}
				$i++;
			}
			//$this->db->where("CONCAT(',', tag_id, ',') LIKE '%,$group_id,%'");
			// $this->db->where('tags.id', $group_id);

			$query = $this->db->get();
			//print_r($this->db->last_query());exit;

			foreach ($query->result() as $result) {
				echo "<option value='$result->id'>" . $result->username . "</option>";
			}
		}
	}

	public function get_course_video()
	{
		if ($this->input->post('course_id') != '') {
			// select t1.id,t1.subject,t1.course_id,c.chapter,c.id,l.file_name,l.name,l.id from subjects as t1 INNER join chapters as c on c.subject_id = t1.id INNER join lectures as l on c.id = l.chapter_id and course_id = 212

			$cid = $this->input->post('course_id');

			$this->db->select('subjects.subject,chapters.chapter,chapters.admin_id,chapters.subject_id,lectures.id as lecturesId,lectures.file_name,lectures.name,lectures.chapter_id,lectures.e_type');
			$this->db->from('subjects');
			$this->db->join('chapters', 'subjects.id = chapters.subject_id');
			$this->db->join('lectures', 'chapters.id = lectures.chapter_id');
			$this->db->where('subjects.course_id', $cid);
			$this->db->where('lectures.admin_id', $this->session->userdata('user_id'));
			$query = $this->db->get();

			foreach ($query->result() as $result) {
				echo '<tr id="tr' . $result->lecturesId . '">';
				echo '<td><input type="checkbox" class="checkbox1" id="checkbox' . $result->lecturesId . '" name="checkbox1[]" value="' . $result->lecturesId . '"/></td>';
				echo '<td>' . $result->lecturesId . '</td>';
				echo '<td>' . $result->file_name . '</td>';
				echo '<td>' . $result->name . '</td>';
				echo '<td>' . $result->e_type . '</td>';
				echo '</tr>';
			}
		}
	}

	public function get_chapter()
	{
		if ($this->input->post('subject_id') != '') {
			$sid = $this->input->post('subject_id');
			$this->db->where('subject_id', $sid);
			$this->db->where('admin_id', $this->session->userdata('user_id'));
			$query = $this->db->get('chapters');

			foreach ($query->result() as $result) {
				echo '<option value="' . $result->id . '">' . $result->chapter . '</option>';
			}
		}
	}


	public function get_lecture()
	{
		if ($this->input->post('chapter_id') != '') {
			$lid = $this->input->post('chapter_id');

			$this->db->where_in('chapter_id', $lid);
			$this->db->where('admin_id', $this->session->userdata('user_id'));
			$this->db->where('e_type', 'video');
			$query = $this->db->get('lectures');

			foreach ($query->result() as $result) {
				echo '<tr>';
				echo '<td><input type="checkbox" class="_check_in" name="checkbox1[]" value="' . $result->id . '"/></td>';
				echo '<td>' . $result->pos . '</td>';
				echo '<td>' . $result->file_name . '</td>';
				echo '<td>' . $result->name . '</td>';
				echo '<td>' . $result->e_type . '</td>';
				echo '</tr>';
			}
		}
	}

	public function get_quizes()
	{
		if ($this->input->post('chapter_id') != '') {
			$lid = $this->input->post('chapter_id');

			$this->db->where_in('chapter_id', $lid);
			$this->db->where('admin_id', $this->session->userdata('user_id'));
			$this->db->where('e_type', 'mcq');
			$query = $this->db->get('lectures');

			foreach ($query->result() as $result) {
				echo '<tr>';
				echo '<td><input type="checkbox" class="_check_in_q" name="checkbox2[]" value="' . $result->id . '"/></td>';
				echo '<td>' . $result->pos . '</td>';
				echo '<td>' . $result->file_name . '</td>';
				echo '<td>' . $result->name . '</td>';
				echo '<td>' . $result->e_type . '</td>';
				echo '</tr>';
			}
		}
	}

	public function get_documents()
	{
		if ($this->input->post('chapter_id') != '') {
			$lid = $this->input->post('chapter_id');

			$this->db->where_in('chapter_id', $lid);
			$this->db->where('admin_id', $this->session->userdata('user_id'));
			$this->db->where('e_type', 'doc');
			$query = $this->db->get('lectures');

			foreach ($query->result() as $result) {
				echo '<tr>';
				echo '<td><input type="checkbox" class="_check_in_d" name="checkbox3[]" value="' . $result->id . '"/></td>';
				echo '<td>' . $result->pos . '</td>';
				echo '<td>' . $result->file_name . '</td>';
				echo '<td>' . $result->name . '</td>';
				echo '<td>' . $result->e_type . '</td>';
				echo '</tr>';
			}
		}
	}

	public function get_subject()
	{

		if ($this->input->post('course_id') != '') {
			$cid = $this->input->post('course_id');
			$this->db->where('course_id', $cid);
			$this->db->where('admin_id', $this->session->userdata('user_id'));
			$query = $this->db->get('subjects');

			foreach ($query->result() as $result) {
				echo '<option value="' . $result->id . '">' . $result->subject . '</option>';
			}
		}
	}

	public function check_permission_posts()
	{
		$columns = array(
			0 => 'id',
			1 => 'pos',
			2 => 'lecture',
			3 => 'e_type',
			4 => 'admin',
			5 => 'course',
			6 => 'subject',
			7 => 'chapter',
			8 => 'str_date',
			9 => 'end_date',
			10 => 'noplay',
			11 => 'total_duration',
			12 => 'remain_duration',
			13 => 'user_id',
			14 => 'reg_date',
		);

		if ($this->session->userdata('user_id') == 1) {
			$admin_id = null;
		} else {
			$admin_id = $this->session->userdata('user_id');
		}

		$course_id  = $this->input->post('course_id');
		$subject_id = $this->input->post('subject_id');
		$chapter_id = $this->input->post('chapter_id');
		$e_type = $this->input->post('e_type');
		$user_id    = $this->input->post('user_id');

		$limit = $this->input->post('length');
		$start = $this->input->post('start');
		$order = $columns[$this->input->post('order')[0]['column']];
		$dir   = $this->input->post('order')[0]['dir'];

		$totalData     = $this->Permission_model->check_permission_posts_count($course_id, $subject_id, $chapter_id, $admin_id, $e_type, $user_id);
		$totalFiltered = $totalData;

		if (empty($this->input->post('search')['value'])) {
			$posts = $this->Permission_model->check_permission_posts($limit, $start, $order, $dir, $course_id, $subject_id, $chapter_id, $admin_id, $e_type, $user_id);
		} else {
			$search = $this->input->post('search')['value'];
			$posts =  $this->Permission_model->check_permission_posts_search($limit, $start, $search, $order, $dir, $course_id, $subject_id, $chapter_id, $admin_id, $e_type, $user_id);
			$totalFiltered = $this->Permission_model->check_permission_posts_search_count($search, $course_id, $subject_id, $chapter_id, $admin_id, $e_type, $user_id);
		}

		$data = array();

		if (!empty($posts)) {
			$i = 1;

			foreach ($posts as $post) {
				$nestedData['id'] = '<input type="checkbox" class="_check_in" value="' . $post->id . '">';
				$i++;

				$nestedData['user_id']       = '<span style="font-size: 12px;">' . $post->user_id . '</span>';
				// $nestedData['pos']     = '<span style="font-size: 12px;">' . $post->pos . '</span>';
				$nestedData['lecture'] = '<span style="font-size: 12px;">' . $post->lecture . '</span>';
				$nestedData['permission_type'] = '<span style="font-size: 12px;">' . $post->permission_type . '</span>';
				$nestedData['e_type'] = '<span style="font-size: 12px;">' . $post->e_type . '</span>';
				$nestedData['chapter']       = '<span style="font-size: 12px;">' . $post->chapter . '</span>';
				$nestedData['str_date']       = '<span style="font-size: 12px;">' . $post->str_dt . '</span>';

				$nestedData['end_date']        = '<span style="font-size: 12px;">' . $post->end_dt . '</span>';
				$nestedData['noplay']       = '<span style="font-size: 12px;">' . $post->noofplay . '</span>';
				$nestedData['total']       = '<span style="font-size: 12px;">' . $post->total_duration . '</span>';
				$nestedData['remain']       = '<span style="font-size: 12px;">' . $post->remain_duration . '</span>';

				$nestedData['reg_date']    = '<span style="font-size: 12px;">' . date('m F Y', strtotime($post->reg_dt)) . '</span>';

				$nestedData['Actions'] = "<a class='btn btn-danger btn-sm' href='" . base_url('admin/regfile/delete_check_permission/' . $post->id) . "' title='Delete'>Trash</a>";

				$data[] = $nestedData;
			}
		}

		$json_data = array(
			"draw"            => intval($this->input->post('draw')),
			"recordsTotal"    => intval($totalData),
			"recordsFiltered" => intval($totalFiltered),
			"data"            => $data
			// "data"            => $this->db->last_query()
		);

		echo json_encode($json_data);
	}

	public function delete_check_permission($lec_id = null)
	{
		if (empty($lec_id)) {
			redirect('admin/lecture/index', 'refresh');
		}

		if ($this->session->userdata('user_id') == 1) {
			$admin_id = null;
		} else {
			$admin_id = $this->session->userdata('user_id');
		}

		$this->db->where('regfiles.id', $lec_id);

		if (!empty($admin_id)) {
			$this->db->where('regfiles.admin_id', $admin_id);
		}

		$query = $this->db->get('regfiles', 1);

		if ($query->num_rows() > 0) {
			$this->db->where('regfiles.id', $lec_id);

			if (!empty($admin_id)) {
				$this->db->where('regfiles.admin_id', $admin_id);
			}

			$this->db->delete('regfiles');

			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Record deleted!</div>');
				redirect('admin/regfile/check', 'refresh');
			}
		}

		$this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">Record did not found!</div>');
		redirect('admin/regfile/check', 'refresh');
	}

	public function delete_check_permission_all()
	{
		$arr = [];

		if (empty($this->session->userdata('user_id'))) {
			$arr['status']      = 0;
			$arr['message']     = '<div class="alert alert-danger" role="alert">You session has expired!,/div>';
			$arr['redirect_to'] = base_url('admin/login');

			goto D_L_A;
		}

		if ($this->session->userdata('user_id') == 1) {
			$admin_id = null;
		} else {
			$admin_id = $this->session->userdata('user_id');
		}

		$lectures = $this->input->post('lectures');

		if ($lectures) {
			$affected_rows = 0;

			foreach ($lectures as $lecture) {
				$this->db->where('regfiles.id', $lecture);

				if (!empty($admin_id)) {
					$this->db->where('regfiles.admin_id', $admin_id);
				}

				$this->db->delete('regfiles');

				$affected_rows += $this->db->affected_rows();
			}

			if ($affected_rows > 0) {
				$arr['status']      = 1;
				$arr['message']     = '';

				$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">' . $affected_rows . ' record successfully deleted!</div>');

				goto D_L_A;
			}

			$arr['status']      = 0;
			$arr['message']     = '<div class="alert alert-danger" role="alert">Something went wrong!/div>';
		}

		D_L_A:
		echo json_encode($arr);
	}

	public function get_subject_by_id()
	{
		$arr = [];

		if (empty($this->session->userdata('user_id'))) {
			$arr['status']      = 0;
			$arr['message']     = '<span class="text-danger">You session has expired!,</span>';
			$arr['redirect_to'] = base_url('admin/login');

			goto GSBI;
		}

		if ($this->session->userdata('user_id') == 1) {
			$admin_id = null;
		} else {
			$admin_id = $this->session->userdata('user_id');
		}

		$course_id = $this->input->post('course_id');

		if ($course_id) {
			$this->db->select('subjects.id, subjects.subject');
			$this->db->where('subjects.course_id', $course_id);

			if (!empty($admin_id)) {
				$this->db->where('subjects.admin_id', $admin_id);
			}

			$query_c = $this->db->get('subjects');

			if ($query_c->num_rows() > 0) {
				$results = $query_c->result();

				$arr['status']      = 1;
				$arr['return_data'] = $results;
				$arr['message']     = '<span class="text-success">Subjects feched successfully!</span>';

				goto GSBI;
			}

			$arr['status']      = 1;
			$arr['message']     = '<span class="text-danger">Records did not found!</span>';
			$arr['return_data'] = [];
		}

		GSBI:
		echo json_encode($arr);
	}

	public function get_chapter_by_id()
	{
		$arr = [];

		if (empty($this->session->userdata('user_id'))) {
			$arr['status']      = 0;
			$arr['message']     = '<span class="text-danger">You session has expired!,</span>';
			$arr['redirect_to'] = base_url('admin/login');

			goto GCBI;
		}

		if ($this->session->userdata('user_id') == 1) {
			$admin_id = null;
		} else {
			$admin_id = $this->session->userdata('user_id');
		}

		$subject_id = $this->input->post('subject_id');

		if ($subject_id) {
			$this->db->select('chapters.id, chapters.chapter');
			$this->db->where('chapters.subject_id', $subject_id);

			if (!empty($admin_id)) {
				$this->db->where('chapters.admin_id', $admin_id);
			}

			$query_c = $this->db->get('chapters');

			if ($query_c->num_rows() > 0) {
				$results = $query_c->result();

				$arr['status']      = 1;
				$arr['return_data'] = $results;
				$arr['message']     = '<span class="text-success">Chapters feched successfully!</span>';

				goto GCBI;
			}

			$arr['status']      = 0;
			$arr['message']     = '<span class="text-danger">Records did not found!</span>';
			$arr['return_data'] = [];
		}

		GCBI:
		echo json_encode($arr);
	}
}

Anon7 - 2021