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/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

class Main_model extends CI_Model
{
	protected $__db;

	public function __construct()
	{
		parent::__construct();
		$this->__db = $this->db->database;
	}
	
	public function select($tbl, $con='', $con1='', $con2='', $con3='')
	{
		$this->db->select('*');
		$this->db->from($tbl);

		if ($con)
			$this->db->where($con);

			if ($con1)
				$this->db->where($con1);

				if ($con2)
					$this->db->where($con2);

					if ($con3)
						$this->db->where($con3);

		$q = $this->db->get();

		return $q->row();
	}

	// public function token($con='',$con1='',$con2='',$con3='')
	// {
	// 	return '_nsC2b6LYDAAAAAAAAAArs40DlF4tjb1SFxMOlCQCV2BGuU_ddY8ZhuTfKv7m76O';
	// }

	public function token($con='',$con1='',$con2='',$con3='')
	{
		// return '7xc1A3rTtFAAAAAAAAAAjSnrndtaExaSyYdyaqFzOwLPTA5CrYU2mjMviBwObLVT';
		return DROPBOX_ACCESS_TOKEN;
	}

	public function selectresult($tbl, $con='', $con1='', $con2='', $con3='')
	{
		$this->db->select('*');
		$this->db->from($tbl);

		if ($con)
			$this->db->where($con);

			if ($con1)
				$this->db->where($con1);

				if ($con2)
					$this->db->where($con2);

					if ($con3)
						$this->db->where($con3);

					$this->db->order_by("id", "desc");

		$q = $this->db->get();

		return $q->result();
	}

	public function selectase($tbl, $con='', $con1='', $con2='', $con3='')
	{
		$this->db->select('*');
		$this->db->from($tbl);

		if ($con)
			$this->db->where($con);

			if ($con1)
				$this->db->where($con1);

				if ($con2)
					$this->db->where($con2);

					if ($con3)
						$this->db->where($con3);

					$this->db->order_by("id", "asc");

		$q = $this->db->get();

		return $q->result();
	}

	public function selectresultteacher($tbl, $con='', $con1='', $con2='', $con3='')
	{
		$this->db->select('*');
		$this->db->from($tbl);

		if ($con)
			$this->db->where($con);

			if ($con1)
				$this->db->where($con1);

				if ($con2)
					$this->db->where($con2);

					if ($con3)
						$this->db->where($con3);

					$this->db->order_by("id", "desc");

		$q = $this->db->get();

		return $q->result();
	}

	public function selectresultclient($tbl, $con='', $con1='', $con2='', $con3='')
	{
		$this->db->select('*');
		$this->db->from($tbl);

		if ($con)
			$this->db->where($con);

			if ($con1)
				$this->db->where($con1);

				if ($con2)
					$this->db->where($con2);

					if ($con3)
						$this->db->where($con3);

					$this->db->order_by("id", "desc");

		$q = $this->db->get();

		return $q->result();
	}

	public function selectresultadmin($tbl, $con='', $con1='', $con2='', $con3='')
	{
		$this->db->select('*');
		$this->db->from($tbl);

		if ($con)
			$this->db->where($con);

			if ($con1)
				$this->db->where($con1);

				if ($con2)
					$this->db->where($con2);

					if ($con3)
						$this->db->where($con3);

					$this->db->order_by("id", "desc");

		$q = $this->db->get();

		return $q->result();
	}

	// public function selectresultteacher($tbl,$con='',$con1='',$con2='',$con3='')
	// {
	// 	$this->db->select('*');
	// 	$this->db->from($tbl);

	// 		$this->db->where('role_name != ','client');

	// 		if ($con1)
	// 			$this->db->where($con1);

	// 			if ($con2)
	// 				$this->db->where($con2);

	// 				if ($con3)
	// 					$this->db->where($con3);

	// 				$this->db->order_by("id", "desc");

	// 	$q = $this->db->get();
	// 	return $q->result();

	// }
	
	public function insert($table, $insert_data)
	{
		$this->db->trans_start();
		$this->db->insert($table, $insert_data);
		$this->db->trans_complete();

		if ($this->db->trans_status() === TRUE)
		{
			$this->db->trans_commit();
			
			return TRUE;
		}
		else
		{
			$this->db->trans_rollback();
		}

		return FALSE;
	}

	public function update($table, $update_data, $conditions)
	{
		if( empty( $table ) || empty( $conditions ) || !is_array( $conditions ) )
		{
			return FALSE;
		}

		$this->db->trans_start();
		$this->db->set($update_data);

		foreach( $conditions as $key => $condition )
		{
			$this->db->where($key, $condition);
		}

		$this->db->update($table);
		$this->db->trans_complete();
		
		if ($this->db->trans_status() === TRUE)
		{
			$this->db->trans_commit();
			
			return TRUE;
		}
		else
		{
			$this->db->trans_rollback();
		}

		return FALSE;
	}
	
	public function updatedata($tbl,$data,$con='')
	{
		$this->db->where($con);
		$this->db->update($tbl,$data);

		return $this->db->affected_rows();
	}

	public function get( $table, $select = NULL )
	{
		if( !empty( $select ) )
		{
			$this->db->select( $select );
		}
		
		$query = $this->db->get($table);

		if( $query->num_rows() > 0 )
		{
			return $query->result();
		}

		return array();
	}

	public function get_where( $table, $col, $match, $select = NULL )
	{
		if( !empty( $select ) )
		{
			$this->db->select( $select );
		}

		$this->db->where($col, $match);
		$query = $this->db->get($table);

		if( $query->num_rows() > 0 )
		{
			return $query->result();
		}

		return array();
	}

	public function get_where_as( $table, $conditions, $select = NULL )
	{
		if( empty( $table ) || empty( $conditions ) || !is_array( $conditions ) )
		{
			return false;
		}

		if( !empty( $select ) )
		{
			$this->db->select( $select );
		}

		foreach( $conditions as $key => $condition )
		{
			$this->db->where($key, $condition);
		}
		
		$query = $this->db->get($table);

		if( $query->num_rows() > 0 )
		{
			return $query->result();
		}

		return array();
	}

	public function delete($table, $conditions)
	{
		if( empty( $table ) || empty( $conditions ) || !is_array( $conditions ) )
		{
			return false;
		}

		$this->db->trans_start();

		foreach( $conditions as $key => $condition )
		{
			$this->db->where($key, $condition);
		}

		$this->db->delete($table);
		$this->db->trans_complete();

		if ($this->db->trans_status() === TRUE)
		{
			$this->db->trans_commit();
			
			return true;
		}
		else
		{
			$this->db->trans_rollback();
		}

		return false;
	}

	public function get_where_not_in( $table, $col, $match, $select = NULL )
	{
		if( !empty( $select ) )
		{
			$this->db->select( $select );
		}

		$this->db->where_not_in($col, $match);
		$query = $this->db->get($table);

		if( $query->num_rows() > 0 )
		{
			return $query->result();
		}

		return array();
	}

	public function check_data_exist($table,$col,$match,$select=NULL)
	{
		if( !empty( $select ) )
		{
			$this->db->select( $select );
		}

		$this->db->where($col, $match);
		$query = $this->db->get($table);

		if( $query->num_rows() > 0 )
		{
			return $query->result();
		}

		return array();
	}

	/***************************************************************************************************/

	public function is__exist( $tbl, $array )
	{
		if( is_array( $array ) )
		{
			foreach( $array as $key=> $value )
			{
				$this->db->where($key, $value);
			}
		}

		$query_c = $this->db->get($tbl);

		return ( $query_c->num_rows() > 0 ) ? TRUE : FALSE;
	}

	public function is_foreign_have($__tbl = NULL, $fk_key = NULL, $fk_val = NULL)
	{
		if( ! $__tbl && ! $fk_key && ! $fk_val )
		{
			return FALSE;
		}

		$tot_rows = 0;

		$__query = "SELECT\n
        TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME\n
        FROM\n
        INFORMATION_SCHEMA.KEY_COLUMN_USAGE\n
        WHERE\n
        REFERENCED_TABLE_SCHEMA = '". $this->__db ."' AND\n
        REFERENCED_TABLE_NAME = '". $__tbl ."'";

		$query = $this->db->query($__query);
		
		if( $query->num_rows() > 0 )
		{
			$results = $query->result();

			foreach( $results as $result )
			{
				if( $result->REFERENCED_TABLE_NAME !== $result->TABLE_NAME )
				{
					$this->db->select( $result->REFERENCED_TABLE_NAME. ".". $result->REFERENCED_COLUMN_NAME );
					$this->db->join( $result->TABLE_NAME, $result->TABLE_NAME. ".". $result->COLUMN_NAME ."=". $result->REFERENCED_TABLE_NAME. ".". $result->REFERENCED_COLUMN_NAME );
					$this->db->where( $result->REFERENCED_TABLE_NAME .".". $fk_key, $fk_val );
					$query_c = $this->db->get( $result->REFERENCED_TABLE_NAME );
	
					$tot_rows += $query_c->num_rows();
				}
				else
				{
					continue;
				}
			}

			return ( $tot_rows > 0 ) ? TRUE : FALSE;
		}

		return FALSE;
	}
// MCQ ===================

	public function all_subject_posts_count($table, $cid, $fid)
	{
		$query = $this
			->db
			->select('quiz_questions.*,mcq_subjects.id as mcq_sub_id, mcq_subjects.subject as m_subject')
			->from('quiz_questions')
			->join("mcq_subjects", "mcq_subjects.id = quiz_questions.subject_id")
			->where($fid, $cid)
			->get();

		return $query->num_rows();
	}
	
	public function all_subject_posts($limit, $start, $col, $dir, $table, $cid, $fid)
	{
		$query = $this
			->db
			->select('quiz_questions.*,mcq_subjects.id as mcq_sub_id, mcq_subjects.subject as m_subject')
			->from('quiz_questions')
			->join("mcq_subjects", "mcq_subjects.id = quiz_questions.subject_id")
			->where($fid, $cid)
			->limit($limit, $start)
			->order_by($col, $dir)
			->get();

		if ($query->num_rows() > 0) {
			return $query->result();
		} else {
			return [];
		}
	}

	public function allsubjectposts_count($table, $cid, $fid)
	{
		$query = $this
			->db
			->where($fid, $cid)
			->get($table);

		return $query->num_rows();
	}

	public function allsubjectposts($limit, $start, $col, $dir, $table, $cid, $fid)
	{
		$query = $this
			->db
			->where($fid, $cid)
			->limit($limit, $start)
			->order_by($col, $dir)
			->get($table);

		if ($query->num_rows() > 0) {
			return $query->result();
		} else {
			return [];
		}
	}


	public function posts_subj_search_count($search, $table, $title, $cid, $fid)
	{
		$query = $this
			->db
			->select('quiz_questions.*,mcq_subjects.id as mcq_sub_id, mcq_subjects.subject as m_subject')
			->from($table)
			->join("mcq_subjects", "mcq_subjects.id = quiz_questions.subject_id")
			->where($fid, $cid)
			->like('id', $search)
			->or_like($title, $search)
			->get($table);

		return $query->num_rows();
	}

	public function posts_subj_search($limit, $start, $search, $col, $dir, $table, $title, $cid, $fid)
	{
		$query = $this
			->db
			->select('quiz_questions.*,mcq_subjects.id as mcq_sub_id, mcq_subjects.subject as m_subject')
			->from($table)
			->join("mcq_subjects", "mcq_subjects.id = quiz_questions.subject_id")
			->where($fid, $cid)
			->like('id', $search)
			->or_like($title, $search)
			->limit($limit, $start)
			->order_by($col, $dir)
			->get();

		if ($query->num_rows() > 0) {
			return $query->result();
		} else {
			return [];
		}
	}
}

Anon7 - 2021