? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/www/savoyglobal.net/sibs_draft/system/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/www/savoyglobal.net/sibs_draft/system/application/models/mastermodel.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class mastermodel extends Model {

    function mastermodel() {
        parent::Model();
        $this->load->model('customermodel');
    }

    function getmicrotime() {

        list($usec, $sec) = explode(" ", microtime());
        return ((float) $usec + (float) $sec);
    }

    function get_data_joined($table1, $table2, $field1, $field2, $id = '', $field = '', $sortfield = "") {
        $data = array();
        if ($id != '')
            $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_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 getdatas($table, $sortfield = "") {
        $data = array();
        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 getSingleFieldValue($table, $field, $condition, $value) {
        //echo "select ". $field. " from ". $table . " where ". $condition . "='". $value ."'";

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

    function number_rows($tabname, $field1 = '', $value1 = '', $field2 = '', $value2 = '', $field3 = '', $value3 = '') {
        $data = array();
        $this->db->from($tabname);
        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 getcustomers() {


        $query = "SELECT IFNULL(customer_corp_info.insured,customer_personal_ind.insured) as insured, customers.id as customer_id,customers.code as code
		     ,customers.id,staffpersonaldetails.id as staffid,customers.type as type,customer_corp_info.business_activity as business
		     FROM customer_corp_info
		     RIGHT JOIN customers  ON (customer_corp_info.customer_id = customers.id)
		     LEFT JOIN customer_personal_ind ON(customer_personal_ind.customer_id = customers.id)
		     INNER JOIN customer_contact ON (customer_contact.customer_id = customers.id)
		     LEFT JOIN city ON (customer_contact.city = city.id)
		     LEFT JOIN country ON (customer_contact.country = country.id)
		     INNER JOIN customer_account ON (customer_account.customer_id = customers.id) AND (city.country_id = country.id)
		     left JOIN staffcustomer ON (staffcustomer.customerid = customers.id)
		     left JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id)  Group by customers.id order by customers.id desc ";

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

    function add($table) {
        $res = $this->db->insert($table, $_POST);
        $cnt = $this->db->insert_id();

        if ($table == 'country') {
            $result = $this->db->query("select * from default_currency");
            $count = $result->num_rows();
            if ($count == 0) {
                $this->db->query("insert into default_currency values ('$cnt')");
            }
        }


        if ($res > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function getemployeesforshift($shift_id = '', $mode = '') {
        $data = array();
        $wherecondition = " ";
        if ($shift_id != '' && $mode != '') {
            $wherecondition = " where `staffemployeedetails`.`staffid` $mode (SELECT `employee_id` FROM `timesheet_work_shift_employees` where work_shift_id = '$shift_id')";
        } else if ($mode != '') {
            $wherecondition = " where `staffemployeedetails`.`staffid` $mode (SELECT `employee_id` FROM `timesheet_work_shift_employees`)";
        }
        $Q = $this->db->query("select staffid as employee_id, name as employee_name from  staffemployeedetails join staffpersonaldetails ON staffemployeedetails.staffid = staffpersonaldetails.id  $wherecondition");

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

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

        $Q = $this->db->query("select device_no , name as employee_name from  staffemployeedetails join staffpersonaldetails ON staffemployeedetails.staffid = staffpersonaldetails.id where staffpersonaldetails.id in (select employee_id from timesheet_work_shift_employees)");

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

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

        $Q = $this->db->query("select device_no as employee_id , name as employee_name , employeeid as employee_no from  staffemployeedetails join staffpersonaldetails ON staffemployeedetails.staffid = staffpersonaldetails.id where staffpersonaldetails.id in (select employee_id from timesheet_work_shift_employees)");
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function addcover($table) 
    {
        $this->db->trans_begin();
        $res = $this->db->insert($table, $_POST);
        $mysql_id = $this->db->insert_id();
        $count = $mysql_id;
        $covername = $_POST['cover'];
        do 
        {
            $cover_code = 'CVR'  . $count;
            $num_rows_chart = $this->mastermodel->number_rows('chart_master', 'account_code', $cover_code);
            $count++;
        } while ($num_rows_chart != 0) ;
       
        
        $parent = $this->accountingsmodel->get_subaccount_setting('cover');
        
        $chart_type=$this->getSingleFieldValue('chart_master', 'chart_type', 'id', $parent);

        $tblValues = array('account_code' => $cover_code, 'account_name' => $covername
            , 'chart_type' => $chart_type, 'parent' => $parent, 'inactive' => 0);
        $this->db->insert('chart_master', $tblValues);

        $tblValues = array('cover_code' => $cover_code);
        $this->db->where('id', $mysql_id);
        $this->db->update('covers', $tblValues);
        
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            return 0;
        } else {
            $this->db->trans_commit();
            return 1;
        }
    }

    function addcity() {


        $country_id = $this->input->post('country_id');
        $cityname = $this->input->post('cityname');
        $citycode = $this->input->post('citycode');
        $tblValues = array('country_id' => $country_id, 'cityname' => $cityname, 'citycode' => $citycode);
        $query = $this->db->insert('city', $tblValues);
        $cnt = mysql_insert_id();




        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function view($table, $page = "", $per_page = "") {
        if ($page) {
            $start = ($page - 1) * $per_page;
        } else {
            $start = 0;
        }
        //$this->db->order_by("id", "desc");
        $this->db->limit($per_page, $start);
        $data['results'] = $this->db->get($table);
        return $data['results'];
    }

    function get_workshift() {
        
    }

    function viewnew($table, $page = "", $per_page = "") {
        $data = array();

        if ($page) {
            $start = ($page - 1) * $per_page;
        } else {
            $start = 0;
        }

        $this->db->limit($per_page, $start);
        $limit = 'order by id desc limit ' . $start . ',' . $per_page;

        $staffids = $this->tracestaff();
//                print_r($staffids);
        $staffids = implode(',', $staffids);




        if ($this->ret_private()) {
            if ($table == 'staffpersonaldetails')
                $staffid = 'id';
            else
                $staffid = 'staffid';


            switch ($_SESSION['modename']) {
                case 'Claims':

                    $data['results'] = $this->db->query("select distinct c.id,c.claimsref,c.claimspolicyno,c.policyid from $table c join policynote p on c.policyid=p.id join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids) $limit");
                    break;
                case 'Policies':

                    if ($table != 'policynote') {

                        if ($table == 'cancellation')
                            $get = 'canrefno';
                        elseif ($table == 'declaration')
                            $get = 'certificate_refno';
                        elseif ($table == 'endorsement')
                            $get = 'endrefno';
                        else
                            $get = 'renrefno';
                        // echo "select distinct e.id,e.$get,e.policyid from $table e join policynote p on e.policyid=p.id  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids)";
                        $data['results'] = $this->db->query("select distinct e.id,e.$get,e.policyid from $table e join policynote p on e.policyid=p.id  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids) $limit");
                    }
                    else {
// echo "select distinct p.id,p.quotation_ref,p.recdate,p.policyno from $table  p  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids)";
                        $data['results'] = $this->db->query("select distinct p.id,p.quotation_ref,p.recdate,p.policyno from $table  p  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids) $limit");
                    }
                    break;
                case 'Documents':

                    $data['results'] = $this->db->query("select * from $table b join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids) $limit");

                    break;
                case 'Sales':

                    //  echo "select * from $table  where  staffid in ($staffids) $limit".'<br/>';
                    $data['results'] = $this->db->query("select * from $table  where  staffid in ($staffids) $limit");
                    break;
                case 'HR':
                    if ($table == 'commissionsettings')
                        $data['results'] = $this->db->query("SELECT * FROM $table c  join staffemployeedetails se on se.designationid=c.designationid where se.staffid in($staffids) $limit");
                    else
                        $data['results'] = $this->db->query("select * from $table  where  $staffid in ($staffids) $limit");
                    break;
                case 'Master':

                    $data['results'] = $this->db->query("select * from $table $limit");
                    break;
                default:
                    $data['results'] = $this->db->query("select * from $table");
                    break;
            }
        }
        else {

            $data['results'] = $this->db->query("select * from $table $limit");
        }



        return $data['results'];
    }

    function count_all($table) {
        return $this->db->count_all($table);
    }

    function count_alldata($table) {
        $data = array();
        $staffids = $this->tracestaff();
        $staffids = implode(',', $staffids);

        if ($this->ret_private()) {
            if ($table == 'staffpersonaldetails')
                $staffid = 'id';
            else
                $staffid = 'staffid';


            switch ($_SESSION['modename']) {
                case 'Claims':

                    $data['results'] = $this->db->query("select * from $table c join policynote p on c.policyid=p.id join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids)");
                    break;
                case 'Policies':

                    if ($table != 'policynote') {

                        if ($table == 'cancellation')
                            $get = 'canrefno';
                        elseif ($table == 'declaration')
                            $get = 'certificate_refno';
                        elseif ($table == 'endorsement')
                            $get = 'endrefno';
                        else
                            $get = 'renrefno';

                        // echo "select distinct e.id,e.$get,e.policyid from $table e join policynote p on e.policyid=p.id  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids)";
                        $data['results'] = $this->db->query("select distinct e.id,e.$get,e.policyid from $table e join policynote p on e.policyid=p.id  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids) ");
                    }
                    else {
                        //echo "select * from $table  p  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids)";
                        $data['results'] = $this->db->query("select distinct p.id,p.quotation_ref,p.recdate,p.policyno from $table  p  join broking_slip b on p.quotation_ref=b.quotation_ref join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids)");
                    }
                    break;
                case 'Documents':

                    $data['results'] = $this->db->query("select * from $table b join staffcustomer s on b.customer_id=s.customerid where  s.staffid in ($staffids)");

                    break;
                case 'Sales':
                    //  echo "select * from $table  where  staffid in ($staffids)";
                    $data['results'] = $this->db->query("select * from $table  where  staffid in ($staffids)");
                    break;
                case 'HR':
                    if ($table == 'commissionsettings')
                        $data['results'] = $this->db->query("SELECT * FROM $table c  join staffemployeedetails se on se.designationid=c.designationid where se.staffid in($staffids)");
                    else
                        $data['results'] = $this->db->query("select * from $table  where  $staffid in ($staffids)");
                    break;
                case 'Master':

                    $data['results'] = $this->db->query("select * from $table");
                    break;
                default:
                    $data['results'] = $this->db->query("select * from $table");
                    break;
            }
        }
        else {

            $data['results'] = $this->db->query("select * from $table ");
        }


        $count = $data['results']->num_rows();
        //   echo '<br/>'.$count;
        return $count;
    }

    function deletedata($table, $id) {
        if ($table == 'timesheet_work_shift')
            $back = $this->db->delete($table, array('work_shift_id' => $id));
        else
            $back = $this->db->delete($table, array('id' => $id));
        if ($table == 'country') {
            $res = $this->db->query("select * from default_currency");
            $count = $res->num_rows();
            if ($count == 0) {
                $result = $this->db->query("select id from country");
                foreach ($result->result_array() as $row)
                    $a = $row['id'];
                $this->db->query("insert into default_currency values ('$a')");
            }
        }
        return $back;
    }

    function deletemycompanydata($table, $id) {

        $back = $this->db->delete($table, array('id' => $id));
        $back = $this->db->delete('mycompany_contact', array('mycompany_id' => $id));

        return $back;
    }

    function get_data($table, $id, $field, $sortfield = "") {
        $data = array();
        $this->db->where($field, $id);
        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_data_new($table, $id, $field) {

        $data = array();

        $qry = "select * from $table where $field=$id";
        $Q = $this->db->query($qry);

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

        $Q->free_result();
        return $data;
    }

    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 showfilesinview($table, $id, $field, $coloumn) {
        $data = array();

        $sql = "select s.documentname,s.subdirname,s.id,`$coloumn` from sub_directory s join $table on s.id=$coloumn where $field = '$id' order by s.id desc";
        $Q = $this->db->query($sql);
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_multi_count($query) {

        $Q = $this->db->query($query);
        return $Q->num_rows();
    }

    function get_multiple_data($table, $id, $id1) {
        $data = array();

        $this->db->where('segment_id', $id1);
        $this->db->where('branch_id', $id);


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

    function insertwarranty() {
        $warranty = $this->db->escape_str($_POST['warranty']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("insert into warranty (cover_id,warranty,description) values('$_POST[cover_id]','$warranty','$description')");

        if ($query > 0) {

            return 1;
        } else {
            return 0;
        }
    }

    function insertcondition() {
        $condition = $this->db->escape_str($_POST['condition']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("insert into conditions (cover_id,conditions,description) values('$_POST[cover_id]','$condition','$description')");

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function insertexclusion() {
        $exclusion = $this->db->escape_str($_POST['exclusion']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("insert into exclusion (cover_id,exclusion,description) values('$_POST[cover_id]','$exclusion','$description')");

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function insertextension() {
        $extension = $this->db->escape_str($_POST['extension']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("insert into extension (cover_id,extension,description) values('$_POST[cover_id]','$extension','$description')");

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function insertexcess() {
        $excess = $this->db->escape_str($_POST['excess']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("insert into excess (cover_id,excess,description) values('$_POST[cover_id]','$excess]','$description')");

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function insertdeductible() {
        $deductible = $this->db->escape_str($_POST['deductible']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("insert into deductible (cover_id,deductible,description) values('$_POST[cover_id]','$deductible','$description')");

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function insertspcondition() {
        $specialcondition = $this->db->escape_str($_POST['specialcondition']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("insert into specialconditions (cover_id,specialcondition,description) values('$_POST[cover_id]','$specialcondition','$description')");

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatecover() {
        $cover = $this->db->escape_str($_POST['cover']);

        $query = $this->db->query("update covers set segment_id='$_POST[segment_id]',cover='$cover' where id='$_POST[coverid]'");


        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatesegment() {
        $segment = $this->db->escape_str($_POST['segment']);
        $query = $this->db->query("update segment_insurances set segment='$segment' where id='$_POST[segmentid]'");

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatecountry($table) {
        $countryname = $this->db->escape_str($_POST['countryname']);
        $countrycode = $this->db->escape_str($_POST['countrycode']);
        $countryisd = $this->db->escape_str($_POST['countryisd']);
        $currencyname = $this->db->escape_str($_POST['currencyname']);
        $currencycode = $this->db->escape_str($_POST['currencycode']);
        $query = $this->db->query("update country set countryname='$countryname',countrycode='$countrycode',countryisd='$countryisd',currencyname='$currencyname',currencycode='$currencycode' where id='$_POST[countryid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatecity() {
        $cityname = $this->db->escape_str($_POST['cityname']);
        $citycode = $this->db->escape_str($_POST['citycode']);
        $query = $this->db->query("update city set country_id='$_POST[country_id]',cityname='$cityname',citycode='$citycode' where id='$_POST[cityid]'");


        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function get_data_srow($table, $id, $field, $sortfield = "") {
        $data = array();
        $this->db->where($field, $id);
        if (!empty($sortfield)) {
            $this->db->order_by($sortfield, 'asc');
        }
        $Q = $this->db->get($table);
        $row = $Q->row();

        return $row;
    }

    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 updatecondition($table) {
        $condition = $this->db->escape_str($_POST['condition']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("update $table set conditions='$condition',description='$description',cover_id='$_POST[cover_id]' where id='$_POST[conditionid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatespcondition($table) {
        $specialcondition = $this->db->escape_str($_POST['specialcondition']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("update $table set specialcondition='$specialcondition',description='$description',cover_id='$_POST[cover_id]' where id='$_POST[spconditionid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updateextension($table) {
        $extension = $this->db->escape_str($_POST['extension']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("update $table set extension='$extension',description='$description',cover_id='$_POST[cover_id]' where id='$_POST[extensionid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updateexclusion($table) {
        $exclusion = $this->db->escape_str($_POST['exclusion']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("update $table set exclusion='$exclusion',description='$description',cover_id='$_POST[cover_id]' where id='$_POST[exclusionid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatedeductible($table) {
        $deductible = $this->db->escape_str($_POST['deductible']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("update $table set deductible='$deductible',description='$description',cover_id='$_POST[cover_id]' where id='$_POST[deductibleid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updateexcess($table) {
        $excess = $this->db->escape_str($_POST['excess']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("update $table set excess='$excess',description='$description]',cover_id='$_POST[cover_id]' where id='$_POST[excessid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatewarranty($table) {
        $warranty = $this->db->escape_str($_POST['warranty']);
        $description = $this->db->escape_str($_POST['description']);
        $query = $this->db->query("update $table set warranty='$warranty',description='$description',cover_id='$_POST[cover_id]' where id='$_POST[warrantyid]'");
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function addinsurance() {
        $company_name = $this->db->escape_str($_POST['company_name']);
        $company_code = $this->db->escape_str($_POST['company_code']);
        $po_box = $this->db->escape_str($_POST['po_box']);
        $office_phone = $this->db->escape_str($_POST['office_phone']);
        $office_email = $this->db->escape_str($_POST['office_email']);
        $office_fax = $this->db->escape_str($_POST['office_fax']);
        $address = $this->db->escape_str($_POST['address']);
        $credential = $this->db->escape_str($_POST['credential']);
        // $commission=$this->db->escape_str($_POST['commission']);

        $company_code = $this->mastermodel->get_account_code('INS','100','insurance_company','company_code');
        $query = $this->db->query("insert into insurance_company (`company_name`, `company_code`, `po_box`, `country_id`, `city_id`, `office_phone`, `office_email`, `office_fax`, `address`, `credential`)
            values('$company_name', '$company_code', '$_POST[po_box]', '$_POST[country_id]', '$_POST[city_id]', '$office_phone', '$office_email', '$office_fax', '$address', '$credential')");
        $compny_id = mysql_insert_id();
        $company_id = $compny_id;
        //insert  Inc Company Bank Account to chart_master
        $parent = $this->accountingsmodel->get_subaccount_setting('company');
        
        $chart_type=$this->getSingleFieldValue('chart_master', 'chart_type', 'id', $parent);
        $tblValues = array('account_code' => $company_code, 'account_name' => $company_name
            , 'chart_type' => $chart_type, 'parent' => $parent, 'inactive' => 0);
        $this->db->insert('chart_master', $tblValues);
        $name[1] = $this->db->escape_str($_POST['txt_conName_1']);
        $department[1] = $this->db->escape_str($_POST['txt_conDept_1']);
        $mobile[1] = $this->db->escape_str($_POST['txt_conMob_1']);
        $phone[1] = $this->db->escape_str($_POST['txt_conPho_1']);
        $email[1] = $this->db->escape_str($_POST['txt_conEmail_1']);
        $designation[1] = $this->db->escape_str($_POST['txt_conDesig_1']);



        $x = 2;
        while (isset($_POST['txt_conName_' . $x])) {
            $name[$x] = $this->db->escape_str($_POST['txt_conName_' . $x]);
            $department[$x] = $this->db->escape_str($_POST['txt_conDept_' . $x]);
            $mobile[$x] = $this->db->escape_str($_POST['txt_conMob_' . $x]);
            $phone[$x] = $this->db->escape_str($_POST['txt_conPho_' . $x]);
            $email[$x] = $this->db->escape_str($_POST['txt_conEmail_' . $x]);
            $designation[$x] = $this->db->escape_str($_POST['txt_conDesig_' . $x]);
            $x++;
        }

        $i = 1;
        while ($x != 1) {
            $query = $this->db->query("insert into insurance_contact(`company_id`,`name`,`department`,`mobile`,`phone`,`email`,`designation`) values ('$company_id','$name[$i]','$department[$i]','$mobile[$i]','$phone[$i]','$email[$i]','$designation[$i]')");

            $x--;
            $i++;
        }

        $year[1] = $this->db->escape_str($_POST['txt_CreYear_1']);
        $premium[1] = $this->db->escape_str($_POST['txt_CrePremium_1']);

        $y = 2;
        while (isset($_POST['txt_CreYear_' . $y])) {
            $year[$y] = $this->db->escape_str($_POST['txt_CreYear_' . $y]);
            $premium[$y] = $this->db->escape_str($_POST['txt_CrePremium_' . $y]);

            $y++;
        }

        $j = 1;
        while ($y != 1) {
            $query = $this->db->query("insert into insurance_grosspremium(`company_id`,`year`,`premium`) values ('$company_id','$year[$j]','$premium[$j]')");

            $y--;
            $j++;
        }


        if (isset($_POST['coverid_com'])) {
            $coveridcom = $_POST['coverid_com'];
            $new = $_POST['new'];
            $renewal = $_POST['renewal'];
            for ($kj = 0; $kj < sizeof($_POST['coverid_com']); $kj++) {

                $query = $this->db->query("insert into insurance_commission(`company_id`,`cover_id`,`new`,`renewal`) values ('$company_id','$coveridcom[$kj]','$new[$kj]','$renewal[$kj]')");
            }
        }
    }

    function editinsurance() {
        $company_name = $this->db->escape_str($_POST['company_name']);
        $po_box = $this->db->escape_str($_POST['po_box']);
        $office_phone = $this->db->escape_str($_POST['office_phone']);
        $office_email = $this->db->escape_str($_POST['office_email']);
        $office_fax = $this->db->escape_str($_POST['office_fax']);
        $address = $this->db->escape_str($_POST['address']);
        $credential = $this->db->escape_str($_POST['credential']);
        //  $commission=$this->db->escape_str($_POST['commission']);
        $company_id = $_POST['company_id'];
        $query = $this->db->query("update insurance_company set `company_name`='$company_name',`po_box`='$po_box',`country_id`='$_POST[country_id]', `city_id`='$_POST[city_id]',`office_phone`='$office_phone',`office_email`='$office_email', `office_fax`='$office_fax',`address`='$address',`credential`='$credential'
        where id='$company_id'");
        $numrows = $this->db->query("select  * from insurance_grosspremium where company_id='$company_id'");
        $numcount = $numrows->num_rows();
        $numcont = $this->db->query("select  * from insurance_contact where company_id='$company_id'");
        $numcontact = $numcont->num_rows();
        $query = $this->db->query("delete from insurance_contact where company_id='$company_id'");

        $x = 1;
        while (isset($_POST['txt_conName_' . $x])) {
            $name[$x] = $this->db->escape_str($_POST['txt_conName_' . $x]);
            $mobile[$x] = $this->db->escape_str($_POST['txt_conMob_' . $x]);
            $department[$x] = $this->db->escape_str($_POST['txt_conDept_' . $x]);
            $phone[$x] = $this->db->escape_str($_POST['txt_conPho_' . $x]);
            $email[$x] = $this->db->escape_str($_POST['txt_conEmail_' . $x]);
            $designation[$x] = $this->db->escape_str($_POST['txt_conDesig_' . $x]);

            if ($x <= $numcontact) {
                $id[$x] = $_POST['hidc_' . $x];
                $query = $this->db->query("insert into insurance_contact(`company_id`,`name`,`department`,`mobile`,`phone`,`email`,`designation`) values ('$company_id','$name[$x]','$department[$x]','$mobile[$x]','$phone[$x]','$email[$x]','$designation[$x]')");
            } else {
                if (!empty($_POST['txt_conName_' . $x])) {
                    $query = $this->db->query("insert into insurance_contact(`company_id`,`name`,`mobile`,`phone`,`email`,`designation`) values ('$company_id','$name[$x]','$mobile[$x]','$phone[$x]','$email[$x]','$designation[$x]')");
                }
            }

            $x++;
        }

        $y = 1;
        while (isset($_POST['txt_CreYear_' . $y])) {
            $year[$y] = $this->db->escape_str($_POST['txt_CreYear_' . $y]);
            $premium[$y] = $this->db->escape_str($_POST['txt_CrePremium_' . $y]);
            if ($y <= $numcount) {
                $id[$y] = $_POST['hidg_' . $y];
                $query = $this->db->query("update insurance_grosspremium set `company_id`='$company_id',`year`='$year[$y]',`premium`='$premium[$y]' where id='$id[$y]' ");
            } else {
                if (!empty($_POST['txt_CreYear_' . $y])) {
                    $query = $this->db->query("insert into insurance_grosspremium(`company_id`,`year`,`premium`) values ('$company_id','$year[$y]','$premium[$y]')");
                }
            }



            $y++;
        }


        if (isset($_POST['coverid_com'])) {

            $coveridcom = $_POST['coverid_com'];
            $new = $_POST['new'];
            $renewal = $_POST['renewal'];
            for ($kj = 0; $kj < sizeof($_POST['coverid_com']); $kj++) {

                $query = $this->db->query("update  insurance_commission set `new`='$new[$kj]',`renewal`='$renewal[$kj]' where `company_id`='$company_id' and `cover_id`='$coveridcom[$kj]'");
            }
        }
    }

    function adddirectory($dirname) {
        $dirname = mysql_escape_string($dirname);
        $query = $this->db->query("insert into directory (`dirname`) values('$dirname')");
    }

    function addsubdirectory($parent_id, $fieldid, $subdir) {
        $menuid = $_SESSION['current_mode'];
        // $parent_id=$this->get_data_srow('directory',$dirname,'dirname');

        $query = $this->db->query("insert into sub_directory (`parentdir`,`subdirname`,`folder_for`,`fieldid`) values('$parent_id','$subdir','$menuid','$fieldid')");
    }

    function inserttemplate() {


        $input = 0;
        $area = 0;
        $combo = 0;

        if (isset($_POST['labelname']) && isset($_POST['fieldtype'])) {
            $cover_id = $_POST['cover_id'];

            $template_type = $this->db->escape_str($_POST['template_id']);
            $fieldtype = $this->db->escape_str($_POST['fieldtype']);


            $labelname = $this->db->escape_str($_POST['labelname']);
            $name = $this->db->escape_str($_POST['name']);

            $query = $this->db->query("insert into template (`name`,`cover_id`,`template_type`) values('$name','$cover_id','$template_type')");
            $template_id = mysql_insert_id();
            for ($i = 0; $i < sizeof($fieldtype); $i++) {
                if ($fieldtype[$i] == 'text') {
                    $textOrder = $_POST['textorder'];
                    $value = $this->db->escape_str($_POST['myInputs' . $textOrder[$input]]);
                    $input++;
                } else if ($fieldtype[$i] == 'textarea') {
                    $areaOrder = $_POST['areaorder'];
                    $value = $this->db->escape_str($_POST['myTextAreas' . $areaOrder[$area]]);
                    $area++;
                } else if ($fieldtype[$i] == 'combobox') {
                    $comboOrder = $_POST['comboorder'];
                    $comboval = $this->db->escape_str($_POST['combotext' . $comboOrder[$combo]]);
                    //echo $comboval;
                    $value = $comboval;
                    $combo++;
                } else {

                    $value = "";
                }

                $query = $this->db->query("insert into template_form (`template_id`,`labelname`,`value`,`fieldtype`) values('$template_id','$labelname[$i]','$value','$fieldtype[$i]')");

                // $template_form_id=mysql_insert_id();
//         if($fieldtype[$i]=='combobox')
//         {
//             $comboOrder=$_POST['comboorder'];
//             $comboval=$_POST['combotext'.$comboOrder[$combo]];
//             $comboval=explode('/',$comboval);
//             for($j=0;$j<sizeof($comboval)-1;$j++)
//             {
//
//           $query=$this->db->query("insert into combobox_value (`template_form_id`,`value`) values('$template_form_id','$comboval[$j]')");
//
//             }
//             $combo++;
//         }
            }
        }
    }

    function updatetemplate() {

        $input = 0;
        $area = 0;
        $combo = 0;
        if (isset($_POST['labelname']) && isset($_POST['fieldtype'])) {
            $cover_id = $_POST['cover_id'];

            $template_type = $_POST['template_id'];
            $fieldtype = $this->db->escape_str($_POST['fieldtype']);


            $labelname = $this->db->escape_str($_POST['labelname']);
            $templateid = $_POST['templateid'];
            $name = $this->db->escape_str($_POST['name']);

            $query = $this->db->query("update template set `name`='$name',`cover_id`='$cover_id',`template_type`='$template_type' where id='$templateid'");
            // $template_id=mysql_insert_id();
            $query = $this->db->query("delete from template_form where template_id='$templateid'");
            for ($i = 0; $i < sizeof($fieldtype); $i++) {
                if ($fieldtype[$i] == 'text') {
                    $textOrder = $_POST['textorder'];
                    $value = $this->db->escape_str($_POST['myInputs' . $textOrder[$input]]);
                    $input++;
                } else if ($fieldtype[$i] == 'textarea') {
                    $areaOrder = $_POST['areaorder'];
                    $value = $this->db->escape_str($_POST['myTextAreas' . $areaOrder[$area]]);
                    $area++;
                } else if ($fieldtype[$i] == 'combobox') {
                    $comboOrder = $_POST['comboorder'];
                    $comboval = $this->db->escape_str($_POST['combotext' . $comboOrder[$combo]]);

                    $value = $comboval;
                    $combo++;
                } else {

                    $value = "";
                }

                $query = $this->db->query("insert into template_form (`template_id`,`labelname`,`value`,`fieldtype`) values('$templateid','$labelname[$i]','$value','$fieldtype[$i]')");


//         $template_form_id=mysql_insert_id();
//
//         if($fieldtype[$i]=='combobox')
//         {
//             $comboOrder=$_POST['comboorder'];
//             $comboval=$_POST['combotext'.$comboOrder[$combo]];
//             echo $comboval;
//             $comboval=explode('/',$comboval);
//             print_r($comboval);
//
//             for($j=0;$j<sizeof($comboval)-1;$j++)
//             {
//
//           $query=$this->db->query("insert into combobox_value(`template_form_id`,`value`) values ('$template_form_id','$comboval[$j]')");
//
//             }
//            $combo++;
//         }
            }
        }
    }

    function search_data($searchopt, $searchtext = "", $count = "", $page = "", $per_page = "") {
        $data = array();

        if ($page)
            $start = ($page - 1) * $per_page;
        else
            $start = 0;

        $seropt = explode('~', $searchopt);
        if ($seropt[0] != 'covers') {



            if ($count == 'true') {
                $this->db->like($seropt[1], $searchtext);
                $this->db->order_by("id", "desc");
                $data['results'] = $this->db->get($seropt[0]);
                return $data['results']->num_rows();
            } else {

                $this->db->like($seropt[1], $searchtext);
                $this->db->order_by("id", "desc");
                $this->db->limit($per_page, $start);
                $data['results'] = $this->db->get($seropt[0]);
                return $data['results'];
            }
        } else {

            if ($count == 'true') {
                $data['results'] = $this->db->query("select * from $seropt[1] where cover_id in (select id from $seropt[0] where cover like '%$searchtext%' order by id desc)");
                return $data['results']->num_rows();
            } else {

                $data['results'] = $this->db->query("select * from $seropt[1] where cover_id in (select id from $seropt[0] where cover like '%$searchtext%') order by id desc limit $start,$per_page");
                return $data['results'];
            }
        }
    }

    function search_insurance($searchopt, $searchtext = "", $count = "", $page = "", $per_page = "") {
        $data = array();
        if ($page)
            $start = ($page - 1) * $per_page;
        else
            $start = 0;
        $seropt = explode('~', $searchopt);

        if ($seropt[0] == 'cover' || $seropt[0] == 'segment') {

            if ($count == 'true') {
                $this->db->like($seropt[0], $searchtext);

                $data['results'] = $this->db->get($seropt[1]);

                return $data['results']->num_rows();
            } else {
                $this->db->like($seropt[0], $searchtext);
                $this->db->order_by("id", "desc");
                $this->db->limit($per_page, $start);
                $data['results'] = $this->db->get($seropt[1]);
                return $data['results'];
            }
        } else {
            if ($count == 'true') {
                $data['results'] = $this->db->query("select * from $seropt[1] where segment_id in (select id from segment_insurances where segment like '%$searchtext%' order by id desc)");

                return $data['results']->num_rows();
            } else {
                $data['results'] = $this->db->query("select * from $seropt[1] where segment_id in (select id from segment_insurances where segment like '%$searchtext%') order by id desc limit $start,$per_page");

                return $data['results'];
            }
        }
    }

    function search_address($searchopt, $searchtext = "", $count = "", $page = "", $per_page = "") {
        $data = array();
        if ($page)
            $start = ($page - 1) * $per_page;
        else
            $start = 0;
        $seropt = explode('~', $searchopt);

        if ($searchopt == 'city~country') {
            if ($count == 'true') {
                $data['results'] = $this->db->query("select * from city where country_id in (select id from country where countryname like '%$searchtext%' order by id desc )");

                return $data['results']->num_rows();
            } else {
                $data['results'] = $this->db->query("select * from city where country_id in (select id from country where countryname like '%$searchtext%') order by id desc limit $start,$per_page");

                return $data['results'];
            }
        } else {
            if ($count == 'true') {
                $this->db->like($seropt[0], $searchtext);

                $data['results'] = $this->db->get($seropt[1]);

                return $data['results']->num_rows();
            } else {
                $this->db->like($seropt[0], $searchtext);
                $this->db->order_by("id", "desc");
                $this->db->limit($per_page, $start);
                $data['results'] = $this->db->get($seropt[1]);

                return $data['results'];
            }
        }
    }

    function search_company($searchopt, $searchtext = "", $count = "", $page = "", $per_page = "") {
        $data = array();
        if ($page)
            $start = ($page - 1) * $per_page;
        else
            $start = 0;
        $seropt = explode('~', $searchopt);

        if ($seropt[1] == 'insurance_company') {
            if ($count == 'true') {
                $this->db->like($seropt[0], $searchtext);

                $data['results'] = $this->db->get($seropt[1]);

                return $data['results']->num_rows();
            } else {
                $this->db->like($seropt[0], $searchtext);
                $this->db->order_by("id", "desc");
                $this->db->limit($per_page, $start);
                $data['results'] = $this->db->get($seropt[1]);

                return $data['results'];
            }
        } else {
            if ($count == 'true') {
                $data['results'] = $this->db->query("select * from insurance_company where $seropt[2] in (select $seropt[3] from $seropt[1] where $seropt[0] like '%$searchtext%' order by id desc )");

                return $data['results']->num_rows();
            } else {
                $data['results'] = $this->db->query("select * from insurance_company where $seropt[2] in (select $seropt[3] from $seropt[1] where $seropt[0] like '%$searchtext%') order by id desc limit $start,$per_page");
                return $data['results'];
            }
        }
    }

    function search_template($searchopt, $searchtext = "", $count = "", $page = "", $per_page = "") {
        $data = array();
        if ($page)
            $start = ($page - 1) * $per_page;
        else
            $start = 0;
        $seropt = explode('~', $searchopt);

        if ($seropt[1] == 'template') {
            if ($count == 'true') {

                $this->db->like($seropt[0], $searchtext);

                $data['results'] = $this->db->get($seropt[1]);

                return $data['results']->num_rows();
            } else {
                $this->db->like($seropt[0], $searchtext);
                $this->db->order_by("id", "desc");
                $this->db->limit($per_page, $start);
                $data['results'] = $this->db->get($seropt[1]);

                return $data['results'];
            }
        } else {
            if ($count == 'true') {


                $data['results'] = $this->db->query("select * from template where $seropt[2] in (select $seropt[3] from $seropt[1] where $seropt[0] like '%$searchtext%' order by id desc )");

                return $data['results']->num_rows();
            } else {

                $data['results'] = $this->db->query("select * from template where $seropt[2] in (select $seropt[3] from $seropt[1] where $seropt[0] like '%$searchtext%') order by id desc limit $start,$per_page");

                return $data['results'];
            }
        }
    }

    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 getmoduledata() {
        $data = array();
        $res = $this->db->query("select modules.module_name,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort,menu.imagepath from modules join menu on modules.module_id=menu.module_id order  by modules.sort");
        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function getcoverdata() {
        $data = array();
        $res = $this->db->query("select s.segment,c.cover,c.segment_id,c.id from segment_insurances s join covers c on s.id=c.segment_id ");
        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function getcompanycoverdata($cid) {
        $data = array();
        $res = $this->db->query("select s.segment,c.cover,c.segment_id,c.id,i.new,i.renewal,i.company_id from segment_insurances s join covers c on s.id=c.segment_id join insurance_commission i on c.id=i.cover_id and i.company_id='$cid' ");
        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function GetSingleReminder($id) {

        $res = $this->db->query("select * from reminder where id='$id'");
        return $res;
    }

    function Get_today_reminder() {
        $data = array();
        $tdate = date('Y-m-d');
        //  echo "select * from reminder where beforedt >= datediff(remind_date,now()) and datediff(remind_date,now())>=0";
        $res = $this->db->query("select * from reminder where userid=" . $_SESSION['userid'] . " and beforedt >= datediff(remind_date,now()) and datediff(remind_date,now())>=0");
        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function Get_today_activity($pageno) {
        $data = array();
        $tdate = date('Y-m-d');
        $limit = (($pageno - 1) * 5);

        $res = $this->db->query("select * from events where alert >= datediff(startdate ,now()) and datediff(enddate ,now())>=0 and userid=" . $_SESSION['userid'] . "  limit " . $limit . "," . 5);
        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function Get_today_schedulde() {
        $data = array();
        $tdate = date('Y-m-d');
        //  echo "select * from reminder where beforedt >= datediff(remind_date,now()) and datediff(remind_date,now())>=0";
        $res = $this->db->query("select * from activities where beforedt >= datediff(date,now()) and datediff(date,now())>=0");
        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function getfolderlistmodel($parentId, $companyid) {
        if ($parentId == 'default') {
            $result = $this->db->query("select * from sub_directory where fieldid='$companyid'");
        } else if ($parentId != '') {
            $result = $this->db->query("select * from sub_directory where parentdir='$parentId' and fieldid='$companyid'");
        } else {
            $result = $this->db->query("select * from sub_directory where parentdir='1' and fieldid='$companyid'");
        }
        return $result->result_array();
    }

    function renamefolder($dirid, $dirname) {
        $data = array(
            'subdirname' => $dirname,
        );

        $this->db->where('id', $dirid);
        $this->db->update('sub_directory', $data);
    }

    function deletefiles($table, $id) {
        $this->db->delete($table, array('fileid' => $id));
    }

    function checkfileowner($table, $id) {
        $this->db->where('fileid', $id);
        $Q = $this->db->get($table);
        return $Q->num_rows();
    }

    function block_duplicates($table, $field, $value) {

        $this->db->where($field, $value);
        $this->db->from($table);
        $count = $this->db->count_all_results();

        if ($count >= 1) {

            return 1;
        } else {
            return 0;
        }
    }

    function get_cover($pid) {

        $sql = "SELECT covers.cover,IFNULL(customer_personal_ind.insured, customer_corp_info.insured) as CustomerName
 FROM customer_corp_info RIGHT JOIN customers ON (customer_corp_info.customer_id = customers.id) LEFT JOIN customer_personal_ind
 ON (customer_personal_ind.customer_id = customers.id) INNER JOIN broking_slip ON (broking_slip.customer_id = customers.id)
 INNER JOIN covers ON (broking_slip.cover_id = covers.id) INNER JOIN policynote ON (policynote.quotation_ref = broking_slip.quotation_ref)
    WHERE policynote.id=$pid";

        $query = $this->db->query($sql);
        return $query->row();
    }

    function check_permissions($check) {
        $uid = $_SESSION['userid'];
        $menuid = $_SESSION['current_mode'];

        $permission_type = $this->customermodel->getSingleFieldValue('users', 'edit_del_permission', 'id', $uid);
        $permission = $this->customermodel->getSingleFieldValue('users', 'permission', 'id', $uid);

        $array = explode(',', $permission_type);
        $array2 = explode(',', $permission);
        $fount = array_search($menuid, $array2);
        $val = $array[$fount];
//        echo count($array).'/';
//        echo count($array2).'/';
//   echo $fount;
        $a = decbin($val);
        $d = sprintf('%04u', $a);
        $ar = str_split($d);


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

    function chk_url_permission($menuid) {
        $uid = $_SESSION['userid'];
        $permission = $this->customermodel->getSingleFieldValue('users', 'permission', 'id', $uid);
        $array = explode(',', $permission);
        if (in_array($menuid, $array)) {
            return true;
        } else {
            return false;
        }
    }

    function replacemenu($menuid) {
        $uid = $_SESSION['userid'];
        $permission = $this->customermodel->getSingleFieldValue('users', 'permission', 'id', $uid);
        $array = explode(',', $permission);
        if (in_array($menuid, $array)) {
            return $menuid;
        } else {
            return false;
        }
    }

    function ret_private() {

        $uid = $_SESSION['userid'];

        $menuid = $_SESSION['current_mode'];

        $private = $this->customermodel->getSingleFieldValue('users', 'private', 'id', $uid);
        $permission = $this->customermodel->getSingleFieldValue('users', 'permission', 'id', $uid);
        $array = explode(',', $private);
        $array2 = explode(',', $permission);
        $fount = array_search($menuid, $array2);
        $val = $array[$fount];




        if ($val == 2) {
            return true;
        } else {
            return false;
        }
    }

    function ret_cust_private() {

        $uid = $_SESSION['userid'];

        $menuid = 14;

        $private = $this->customermodel->getSingleFieldValue('users', 'private', 'id', $uid);
        $permission = $this->customermodel->getSingleFieldValue('users', 'permission', 'id', $uid);
        $array = explode(',', $private);
        $array2 = explode(',', $permission);
        $fount = array_search($menuid, $array2);
        $val = $array[$fount];
        if ($val == 2) {
            return 2;
        } elseif ($val == 1) {
            return 1;
        } else {
            return 0;
        }
    }

    function tracestaff() {


        $staffid = $_SESSION['staffid'];
//echo $staffid;

        $directname = $this->get_data_new('staffemployeedetails', $staffid, 'reportingtostaffid');
        // echo count($directname);
        $newstaff[] = $staffid;
        $repstaff[] = $staffid;

        if (count($directname) != 0) {


            foreach ($directname as $name) {
                $staffid = $name['staffid'];

                $newstaff[] = $staffid;
            }

            $repstaff[] = $newstaff[0];


            while (count($newstaff)) {

                $directnames = $this->get_data_new('staffemployeedetails', $newstaff[0], 'reportingtostaffid');
                foreach ($directnames as $names) {
                    $staffid = $names['staffid'];
                    $newstaff[] = $staffid;
                    $repstaff[] = $staffid;
                }

                $first = array_shift($newstaff);
            }
        }
        //$repstaff[]=$_SESSION['staffid'];
        $result = array_unique($repstaff);
        return $result;
    }

    function getleavedata($value) {



        $data = array();

        $Q = $this->db->query("select * from leavetype where (gender='Both'or gender='" . $value . "')");
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_branchname($id) {
        $sql = "select cityname from city inner join staffemployeedetails on staffemployeedetails.branchid = city.id and staffemployeedetails.staffid = '" . $id . "'";
        $res = mysql_query($sql);
        $row = mysql_fetch_array($res);

        return $row['cityname'];
    }

    function get_newbranchname($id) {
        $sql = "select branchname from ourbranch inner join staffemployeedetails on staffemployeedetails.branchid = ourbranch.id and staffemployeedetails.staffid = '" . $id . "'";
        $res = mysql_query($sql);
        $row = mysql_fetch_array($res);

        return $row['branchname'];
    }

    function addtomybranch() {

        $sql = "insert into ourbranch values('','$_POST[branchname]','$_POST[address]','$_POST[country]','$_POST[city]','$_POST[phone]','$_POST[website]','$_POST[email]','$_POST[fax]','$_POST[code]','$_POST[footers]')";
        $query = $this->db->query($sql);

        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function Get_ourbranch_data($id) {
        $res = $this->db->query("select * from ourbranch where id='" . $id . "'");
        $result = $res->row();
        return $res;
    }

    function GetOurBranch($pageno, $field, $value = "") {


        $limit = (($pageno - 1) * 10);
        $data = array();
        $sql = "select * from ourbranch where " . $field . " like '" . $value . "%' limit " . $limit . "," . 10;
        // echo $sql;
        $res = $this->db->query($sql);
        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function updateourbranch() {
        $id = $this->input->post('my_cid');
        $branchname = $this->input->post('branchname');
        $address = $this->input->post('address');
        $phone = $this->input->post('phone');
        $website = $this->input->post('website');
        $email = $this->input->post('email');
        $fax = $this->input->post('fax');
        $code = $this->input->post('code');
        $city = $this->input->post('city');
        $country = $this->input->post('country');
        $footer = $this->input->post('footers');

        $res = $this->db->query("update ourbranch set branchname='" . $branchname . "',address='" . $address . "',country='" . $country . "',city='" . $city . "',phone='" . $phone . "',email='" . $email . "',website='" . $website . "',fax='" . $fax . "',code='" . $code . "',footer='" . $footer . "' where id='" . $id . "'");
    }

    function addtomycompany() {

        $res = $this->db->query("select * from mycompany");
        $count = $res->num_rows();

        if ($count == 0) {
            $logo = $offerfile = $_FILES['logoup']['name'];
            $fyear = $this->input->post('fyear');
            $query = $this->db->query("insert into mycompany values('','$_POST[companyname]','$_POST[address]','$_POST[phone]','$_POST[website]','$_POST[email]','$_POST[fax]','$fyear','$logo')");
            $compny_id = mysql_insert_id();
            $company_id = $compny_id;
            $name[1] = $this->db->escape_str($_POST['txt_conName_1']);
            $mobile[1] = $this->db->escape_str($_POST['txt_conMob_1']);
            $phone[1] = $this->db->escape_str($_POST['txt_conPho_1']);
            $email[1] = $this->db->escape_str($_POST['txt_conEmail_1']);
            $designation[1] = $this->db->escape_str($_POST['txt_conDesig_1']);



            $x = 2;
            while (isset($_POST['txt_conName_' . $x])) {
                $name[$x] = $this->db->escape_str($_POST['txt_conName_' . $x]);
                $mobile[$x] = $this->db->escape_str($_POST['txt_conMob_' . $x]);
                $phone[$x] = $this->db->escape_str($_POST['txt_conPho_' . $x]);
                $email[$x] = $this->db->escape_str($_POST['txt_conEmail_' . $x]);
                $designation[$x] = $this->db->escape_str($_POST['txt_conDesig_' . $x]);
                $x++;
            }

            $i = 1;
            while ($x != 1) {
                $query = $this->db->query("insert into mycompany_contact(`mycompany_id`,`name`,`mobile`,`phone`,`email`,`designation`) values ('$company_id','$name[$i]','$mobile[$i]','$phone[$i]','$email[$i]','$designation[$i]')");

                $x--;
                $i++;
            }
        }
        if ($query > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    function updatemycompany() {
        $ids = $this->input->post('my_cid');
        $companyname = $this->input->post('companyname');
        $address = $this->input->post('address');
        $phone = $this->input->post('phone');
        $website = $this->input->post('website');
        $email = $this->input->post('email');
        $fax = $this->input->post('fax');
        $logo = $_FILES['logoup']['name'];
        $oldlogo = $this->input->post('oldlogo');
        $fyear = $this->input->post('fyear');

        if ($logo != "") {
            if (file_exists('./logo/' . $oldlogo))
                unlink('./logo/' . $oldlogo);
        }
        else {
            $logo = $oldlogo;
        }
        // echo "update mycompany set company='" . $companyname . "',address='" . $address. "',phone='" .$phone."',email='" . $email. "',website='" . $website . "',fax='" .$fax."',logo_name='" .$logo."' where id='" . $id . "'";
        $res = $this->db->query("update mycompany set company='" . $companyname . "',address='" . $address . "',phone='" . $phone . "',email='" . $email . "',website='" . $website . "',fax='" . $fax . "',fyear='" . $fyear . "',filename='" . $logo . "' where id='" . $ids . "'");
        $numcont = $this->db->query("select  * from mycompany_contact where mycompany_id='$ids'");
        $numcontact = $numcont->num_rows();
        $query = $this->db->query("delete from mycompany_contact where mycompany_id='$ids'");

        $x = 1;
        while (isset($_POST['txt_conName_' . $x])) {
            $name[$x] = $this->db->escape_str($_POST['txt_conName_' . $x]);
            $mobile[$x] = $this->db->escape_str($_POST['txt_conMob_' . $x]);
            $phone[$x] = $this->db->escape_str($_POST['txt_conPho_' . $x]);
            $email22[$x] = $this->db->escape_str($_POST['txt_conEmail_' . $x]);
            $designation[$x] = $this->db->escape_str($_POST['txt_conDesig_' . $x]);
            $ids = $this->input->post('my_cid');

            if ($x <= $numcontact) {
                $id[$x] = $_POST['hidc_' . $x];

                $query = $this->db->query("insert into mycompany_contact(`mycompany_id`,`name`,`mobile`,`phone`,`email`,`designation`) values ('$ids','$name[$x]','$mobile[$x]','$phone[$x]','$email22[$x]','$designation[$x]')");
            } else {
                if (!empty($_POST['txt_conName_' . $x])) {

                    $query = $this->db->query("insert into mycompany_contact(`mycompany_id`,`name`,`mobile`,`phone`,`email`,`designation`) values ('$ids','$name[$x]','$mobile[$x]','$phone[$x]','$email22[$x]','$designation[$x]')");
                }
            }

            $x++;
        }
    }

    function Get_mycompany($id) {
        $res = $this->db->query("select * from mycompany where id='" . $id . "'");
        $result = $res->row();
        return $res;
    }

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

    function getsub_acc($table) {
        $data = array();

        $Q = $this->db->query("select * from  $table order by `chart_type`");
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

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

        $Q = $this->db->query("select * from  chart_master where parent=0 order by `chart_type`");
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

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

        $Q = $this->db->query("select * from  chart_master where parent!=0 order by `chart_type`");
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function checkexistence($table, $field, $value) {

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

    function uploadform($data, $path, $fieldid, $table, $dname) {
        $parent_id = $_POST['dirid'];
        if (!empty($data)) {
            $adname = split(',', $dname);
            $i = 0;

            foreach ($data as $file) {
                $filename = $file['name'];

                if (!isset($adname[$i]))
                    $adname[$i] = "";

                $folder_for = $_SESSION['current_mode'];
                $query = $this->db->query("insert into sub_directory (`parentdir`,`subdirname`,`folder_for`,`fieldid`,`documentname`) values('$parent_id','$file[name]','$folder_for','$fieldid','$adname[$i]')");

                $fid = mysql_insert_id();

                $query = $this->db->query("insert into $table  values ('','$fieldid','$filename','$fid')");
                $i++;
            }
            if ($query > 0) {
                return 1;
            } else {
                return 0;
            }
        }
    }

    function defaultcurrency() {
        $Q = $this->db->query("select * from default_currency");
        $res = $Q->row();
        return $res->currency_id;
    }

    function checkcovercodeexist($coverid) {
        $res = $this->db->query("select * from covers where id='$coverid'");
        $resl = $res->row();
        if ($res->num_rows() < 1)
            $result = 0;
        else
            $result = $resl->cover;


        return $result;
    }

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

    function listcustomeraccounts(){
        $data = array();
        $this->db->select('chart_master.account_code,chart_master.account_name');
        $this->db->from('chart_master');
        $this->db->join('customers', 'customers.code=chart_master.account_code');
        $this->db->order_by('chart_type', "asc");

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

        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    function listchartofaccounts() {
        $data = array();
        $this->db->select('chart_master.account_code,chart_master.account_name,chart_master.id');
        $this->db->from('chart_master');
        $this->db->join('bank_accounts', 'bank_accounts.account_code=chart_master.account_code', 'left');
        $this->db->where('bank_accounts.id', NULL);

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

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

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

    function insert_device_attendance() {
        unset($_POST['isrishti123']);
        $i = 0;
        foreach ($_POST as $value) {
            $res = $this->db->query("insert into timesheet_attendance values ('',$value,'0')");
            if ($res == 1) {
                $i++;
            }
        }
        return $i;
    }

    function traceemployee($employee_id, $staff_list) {
        $employee_list = $this->mastermodel->get_data('staffemployeedetails', $employee_id, 'reportingtostaffid');
        foreach ($employee_list as $list) {
            if ($list['staffid'] != $employee_id && $list['reportingtostaffid'] != 0) {
                $staff_list .= $list['staffid'] . ',';
                $this->traceemployee($list['staffid'], $staff_list);
            }
        }

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

    function getfootervalue() {
        $sql = "select footer from ourbranch join staffemployeedetails on staffemployeedetails.branchid = ourbranch.id join users on users.staff_id = staffemployeedetails.staffid where users.id= '" . $_SESSION['userid'] . "'";
        $data = $this->db->query($sql);
        $result = $data->row();
        if ($data->num_rows() > 0) {
            return $result->footer;
        } else {
            $sql = "select footer from ourbranch  limit 1";
            $data = $this->db->query($sql);
            $result = $data->row();
            return $result->footer;
        }
    }
    
    function get_account_code($prefix_code,$starting,$table,$field) {
        $this->db->like($field, $prefix_code);
        $Q = $this->db->get($table);
        $num = $Q->num_rows();
        $count = $starting+$num+1;
        do 
        {
            $master_code = $prefix_code . $count;
            $num_rows_chart = $this->mastermodel->number_rows('chart_master', 'account_code', $master_code);
            $num_rows_table = $this->mastermodel->number_rows($table, $field, $master_code);
            $count++;
        } while ($num_rows_chart != 0 || $num_rows_table != 0) ;
        return $master_code;
    }
    
    function get_report_list()
    {
        $this->db->select('*')
                 ->from('report');
        $result = $this->db->get();
        
        return $result->result_array();
    }

}

/* End of file mastermodel.php */
/* Location: ./system/application/models/mastermodel.php */

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