? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/sgms/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/sgms/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($username,$password)
    {
        $ip=$this->input->post('ip');
        
        $uid= $this->getSingleFieldValue('user','user_id','username',$username);
        if($uid=="")
        {
            $uid='NULL';
        }
        $logintime=$today = date("Y-m-d H:i:s");
        $password1=md5($password);
        $query= $this->db->query("select * from user where username='$username' and password='$password1'");
        $data['numrows']=$query->num_rows();
        if($query->num_rows()>0)
        {
            $lastid= $this->getSingleValue('login_details','id','username',$username);
            $clogintime= $this->getSingleValue('login_details','login_time','username',$username);
            $result= $query->row();
            $data['userid']= $result->user_id;
            $data['employee_id']= $result->employee_id;
            $data['username']=$username;
            $data['clogintime']=$logintime;
            $data['lastid']=$lastid;
            $query1= $this->db->query("select * from login_details where username='$username' and id>='$lastid'");
            $data['attempt']=($query1->num_rows())-1;
            $tblValues=array('username'=>$username,'password'=>$password1,'login_time '=>$logintime,'userid '=>$uid,'ip_address '=>$ip,'status '=>'Success');
            $datas=$this->db->insert('login_details', $tblValues);
            return $data;
        }
        else
        {
            $tblValues=array('username'=>$username,'password'=>$password,'login_time '=>$logintime,'userid '=>$uid,'failing_time '=>$logintime,'ip_address '=>$ip,'status '=>'failed');
            $datas=$this->db->insert('login_details', $tblValues);
        }
    }

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

        
    function getSingleValue($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 getSingleFieldValue($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 getSingleFieldValueTwo($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 getsinglejoinedvalue($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 buildMenu($moduleid)
    {

        $user_id=$_SESSION['sgms_userid'];
        $data = array();
        $Q= $this->db->query("select * from menu where module_id='" . $moduleid ."' and active=1 order by sort");
        $P=$this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['sgms_userid'] ."'");
        $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['sgms_userid'],'0');
                 if($check)
                 {
                    $data[]=$row;
                 }
             }
        }
        $Q->free_result();
        return $data;
    }


    function buildModule()
    {
        $flag=0;
        $homemodel=0;
        $data = array();
        $P=$this->db->query("select user_modules from user where user_id='" . $_SESSION['sgms_userid'] ."'");
        $result= $P->row();
        $permission=explode(',',$result->user_modules);
        $Q= $this->db->query("select * from modules 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['sgms_userid'],'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)
    {
        $uid=$_SESSION['sgms_userid'];
        $permission= $this->getSingleFieldValue('user','user_modules','user_id',$uid);
        $array=explode(',',$permission);
        if(in_array($menuid, $array))
        {
            return true;
        }
        else
        {
            return false;

        }
    }



    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 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_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,'asc');
        }
        $Q= $this->db->get($table1);
        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 modules.module_name,modules.module_title,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
             where modules.active = '1' and menu.active='1'
            order by modules.sort, menu.sort");
        foreach ($res->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }


    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 where menu.active=1
            order by modules.sort, menu.sort");
        foreach ($res->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    function ret_private()
    {
        $uid=$_SESSION['sgms_userid'];
        $menuid=$_SESSION['current_mode'];
        $private= $this->getSingleFieldValue('user','private','user_id',$uid);
        $permission= $this->getSingleFieldValue('user','user_modules','user_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 replacemenu($menuid)
    {
        $uid=$_SESSION['sgms_userid'];
        $permission= $this->getSingleFieldValue('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['sgms_userid'];
        $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,$userid,$check)
    {
        $this->db->select('user_modules,modules_permission');
        $this->db->from('user');
        $this->db->where('user_id', $userid);
        $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=$array_perm[$found];
        $a=decbin($val);
        $d=sprintf('%03u',$a);
        $ar = str_split($d);
     
        if($ar[$check]==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 masterid=reminder_id where creator_id=".$_SESSION['sgms_userid']." 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 get_data_srow($table,$id,$field)
    {
        $data = array();
        $this->db->where($field,$id);
        $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 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 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 insertmasterdata($userid="")
    {
        $time= date("Y-m-d H:i:s");
        $ip=$_SERVER['REMOTE_ADDR'];
        if($userid=='')
        {
            $owner_id=$_SESSION['employee_id'];
        }
        else
        {
            $owner_id=$userid;
        }
        $creator_id=$_SESSION['sgms_userid'];
        $query="insert into master (creator_id,owner_id,created_time) values ('".$creator_id."','".$owner_id."','$time')";
        $this->db->query($query);
        return mysql_insert_id();
     }

     function updatemasterdata($id,$userid='')
     {
           $time= date("Y-m-d H:i:s");
            if($userid=='')
            {
                $owner_id=$_SESSION['employee_id'];
            }
            else
            {
                $owner_id=$userid;
            }
           $tblValues=array('owner_id'=>$owner_id,
                'modified_time'=>$time
                );
          $this->db->where('masterid',$id);
          $this->db->update('master', $tblValues);
     }

    function get_activity_code($activity_category_id)
    {
        $code=$this->getSingleFieldValue('activity_category', 'activity_category_prefix', 'activity_category_id', $activity_category_id);
        $num=$this->get_num_rows('activity', 'activity_category_id', $activity_category_id);
        $num++;
        do
        {
            $activity_code = $code.$num;
            $num_rows=$this->mastermodel->get_num_rows('activity','activity_code',$activity_code);
            $num++;
        }while($num_rows!=0);
        return $activity_code;
    }

    function get_training_code($activity_id)
    {
        $code=$this->getSingleFieldValue('activity', 'activity_code', 'activity_id', $activity_id);
        $num=$this->get_num_rows('training_proposal', 'activity_id', $activity_id);
        $num++;
        $prefix_code=$this->mastermodel->getSingleFieldValue('company','prefix_code','company_id','1');
        do
        {
            $training_code= $prefix_code.'/'.date("Y").'/'.$code.'/'.$num;
            $num_rows=$this->mastermodel->get_num_rows('training_proposal','training_code',$training_code);
            $num++;
        }while($num_rows!=0);
        return $training_code;
    }

    function get_software_code($activity_id)
    {
        $code=$this->getSingleFieldValue('activity', 'activity_code', 'activity_id', $activity_id);
        $num=$this->get_num_rows('software_proposal', 'activity_id', $activity_id);
        $num++;
        $prefix_code=$this->mastermodel->getSingleFieldValue('company','prefix_code','company_id','1');
        do
        {
            $software_code= $prefix_code.'/'.date("Y").'/'.$code.'/'.$num;
            $num_rows=$this->mastermodel->get_num_rows('software_proposal','proposal_code',$software_code);
            $num++;
        }while($num_rows!=0);
        return $software_code;
    }
    
    function get_consulting_code($activity_id)
    {
        $code=$this->getSingleFieldValue('activity', 'activity_code', 'activity_id', $activity_id);
        $num=$this->get_num_rows('consulting_proposal', 'activity_id', $activity_id);
        $num++;
        $prefix_code=$this->mastermodel->getSingleFieldValue('company','prefix_code','company_id','1');
        do
        {
            $software_code= $prefix_code.'/'.date("Y").'/'.$code.'/'.$num;
            $num_rows=$this->mastermodel->get_num_rows('software_proposal','proposal_code',$software_code);
            $num++;
        }while($num_rows!=0);
        return $software_code;
    }

    function get_training_quotation_code($id)
    {
        $proposal_id=$this->getSingleFieldValue('training_proposal_details', 'training_id', 'id', $id);
        $code=$this->getSingleFieldValue('training_proposal', 'training_code', 'training_id', $proposal_id);
        $sql= "SELECT * FROM training_quotation
            WHERE customer_training_id IN (SELECT id FROM training_proposal_details
            WHERE training_id = '$proposal_id')";
        $res=mysql_query($sql);
        $num=mysql_num_rows($res);
        $num++;
        do
        {
            $training_quotation_code= $code.'/'.$num;
            $num_rows=$this->mastermodel->get_num_rows('training_quotation','quotation_code',$training_quotation_code);
            $num++;
        }while($num_rows!=0);
        return $training_quotation_code;
    }

    function get_employee_number()
    {
        $this->db->from('employee');
        $num = $this->db->count_all_results();
        $num++;
        $num+=200;
        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;
    }


        /*Common function ends here*/


        /*Search function starts here*/


    function search_activity_category($pagenum)
    {
        $data=array();
        $this->db->from('activity_category');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('activity_category');
        $this->db->limit($perpage, $start);
        $this->db->order_by('activity_category_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_expense_category($pagenum)
    {
        $data=array();
        $this->db->from('expense_category');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('expense_category');
        $this->db->limit($perpage, $start);
        $this->db->order_by('expense_category_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_activity($pagenum)
    {
        $data=array();
        $this->db->from('activity');
        $this->db->join('activity_category','activity_category.activity_category_id=activity.activity_category_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('activity');
        $this->db->join('activity_category','activity_category.activity_category_id=activity.activity_category_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('activity.activity_category_id','desc');
        $this->db->order_by('activity.activity_code','asc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_company($pagenum)
    {
        $data=array();
        $this->db->from('company');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('company');
        $this->db->limit($perpage, $start);
        $data['results']=$this->db->get();
        return $data;
    }

    function insert_activity($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $project_start= $this->accountingmodel->get_account_settings('project','main_account_settings');
        
        $tblValues=array('activity_category_id'=> $postdata['activity_category_id'],
                        'activity_name'=> $postdata['activity_name'],
                        'activity_code'=> $postdata['activity_code']);
        $this->db->insert('activity', $tblValues);
        $activity_id=mysql_insert_id();
        $num=$this->get_num_rows('activity');
        do
        {
            $account_code = $project_start+$num;
            $num_rows=$this->mastermodel->get_num_rows('chart_master','chart_account_code',$account_code);
            $num++;
        }while($num_rows!=0);
        $tblValues=array('chart_account_code'=>$account_code,
                        'chart_account_name'=>$postdata['activity_name'],
                        'chart_account_type'=>4,
                        'parent'=>0,
                        'inactive'=>0);
        $this->db->insert('chart_master', $tblValues);

        $tblValues=array('activity_account_code'=> $account_code);
        $this->db->where('activity_id', $activity_id);
        $this->db->update('activity', $tblValues);
        
        $data['resfunction']='search_activity';
        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 search_branch($pagenum)
    {
        $data=array();
        $this->db->from('branch');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('branch');
        $this->db->limit($perpage, $start);
        $data['results']=$this->db->get();
        return $data;
    }

    function search_document_category($pagenum)
    {
        $data=array();
        $this->db->from('document_category');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('document_category');
        $this->db->limit($perpage, $start);
        $this->db->order_by('document_category_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_source($pagenum)
    {
        $data=array();
        $this->db->from('source');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('source');
        $this->db->limit($perpage, $start);
        $this->db->order_by('source_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

            /*Search function ends here*/


        /*Add function starts here*/

   

         /*Update function starts here*/
        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 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();
        $this->db->last_query();
        return $num;
        
    }

    function uploadfile($postdata)
    {
         $this->db->trans_begin();
         $tbl1Values=array('customer_id'=>$postdata['customer_id'],
             'file_name'=>$postdata['file_name'],
                'file_location'=>$postdata['file_location']);
          $this->db->insert('customer_file', $tbl1Values);
          $this->db->trans_commit();
    }

    function getenumvalues($table, $column)
    {
        $sql = "SHOW COLUMNS FROM $table LIKE '$column'";
        $result = mysql_query($sql);
            if ($result) { // If the query's successful

                    $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 get_software_proposal()
    {
        $data = array();
        $this->db->join('customer',"customer.customer_id=software_proposal.customer_id");
        $this->db->where('`software_proposal`.`software_proposal_id` NOT IN (SELECT `software_proposal_id` FROM `software_placement`)', NULL, FALSE);
        $this->db->order_by('software_proposal.software_proposal_id','desc');
        $Q= $this->db->get('software_proposal');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    function get_consulting_proposal()
    {
        $data = array();
        $this->db->join('customer',"customer.customer_id=consulting_proposal.customer_id");
        $this->db->where('`consulting_proposal`.`consulting_proposal_id` NOT IN (SELECT `consulting_proposal_id` FROM `consulting_confirmation`)', NULL, FALSE);
        $this->db->order_by('consulting_proposal.consulting_proposal_id','desc');
        $Q= $this->db->get('consulting_proposal');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    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 get_training_proposal()
    {
        $data = array();
        $this->db->join('training_proposal_details',"training_proposal_details.training_id=training_proposal.training_id");
        $this->db->join('customer',"customer.customer_id=training_proposal_details.customer_id");
        $this->db->where('`training_proposal_details`.`id` NOT IN (SELECT `customer_training_id` FROM `training_quotation`)', NULL, FALSE);
        $this->db->order_by('training_proposal.training_id','desc');
        $Q= $this->db->get('training_proposal');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_training_quotation()
    {
        $data = array();
        $this->db->join('training_proposal_details','training_proposal_details.id=training_quotation.customer_training_id');
        $this->db->join('customer',"customer.customer_id=training_proposal_details.customer_id");
        $this->db->where('`training_quotation`.`training_quotation_id` NOT IN (SELECT `training_quotation_id` FROM `training_registration`)', NULL, FALSE);
        $this->db->order_by('training_quotation.training_quotation_id','desc');
        $Q= $this->db->get('training_quotation');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_training_registration()
    {
        $data = array();
        $this->db->join('training_quotation','training_quotation.training_quotation_id=training_registration.training_quotation_id');
        $this->db->join('training_proposal_details','training_proposal_details.id=training_quotation.customer_training_id');
        $this->db->join('customer',"customer.customer_id=training_proposal_details.customer_id");
        $this->db->join('refs_records',"refs_records.record_id=training_registration.training_registration_id");
        $this->db->where('`training_registration`.`training_registration_id` NOT IN (SELECT `training_registration_id` FROM `training_cancellation`)', NULL, FALSE);
        $this->db->order_by('training_quotation.training_quotation_id','desc');
        $Q= $this->db->get('training_registration');
        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('*');
         $this->db->from('chart_master');

         $this->db->join('bank_account','bank_account.account_code=chart_master.chart_account_code','left');
         $this->db->where('bank_account.bank_account_id', NULL);
         
         $this->db->order_by('chart_account_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 get_cust_emp_accounts()
    {
         $data=array();
         $sql="select chart_account_code, chart_account_name from chart_master
                   
                     join customer on customer.customer_no=chart_master.chart_account_code
                     
                     union
                   select chart_account_code, chart_account_name from chart_master
                   
                     join  employee on employee.employee_no=chart_master.chart_account_code";
            

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

    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 check_private($module_id='')
    {
        if($module_id=='')
            $module_id=$_SESSION['current_mode'];
        $perm = $this->get_data_srow('user',$_SESSION['sgms_userid'],'user_id');
        $array_private=explode(',',$perm->private);
        $array_module=explode(',',$perm->user_modules);
        $found=array_search($module_id,$array_module);
        $val=$array_private[$found];
        if($val==1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function getcustomeraddress($customer_id)
    {
        $customer = $this->get_data_srow('customer',$customer_id,'customer_id');
        $customer_address='';
        if($customer->customer_address!='')
            $customer_address.=nl2br($customer->customer_address).'<br/> ';
        if($customer->customer_pobox!='')
            $customer_address.='P.O Box: '.$customer->customer_pobox.'<br/> ';
        if($customer->customer_city!='')
            $customer_address.=$customer->customer_city.', ';
        if($customer->customer_state!='')
            $customer_address.=$customer->customer_state.', ';
        if($customer->customer_country!='')
            $customer_address.=$customer->customer_country.', ';
        return substr($customer_address,0,-2);
    }

    
    function getemployeesforshift($shift_id='')
    {
        $data = array();
        $this->db->order_by('employee.employee_id','asc');
        if($shift_id != '')
        {
            $this->db->where('`employee`.`employee_id` NOT IN (SELECT `employee_id` FROM `timesheet_work_shift_employees` where work_shift_id = '.$shift_id.')', NULL, FALSE);
        }
        $this->db->where('employee.device_no !=','0');
        $Q = $this->db->get('employee');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    
    function getemployeesforattendace()
    {
        $data = array();
        $this->db->order_by('employee.employee_id','asc');
        $this->db->where('`employee`.`employee_id` IN (SELECT `employee_id` FROM `timesheet_work_shift_employees`)', NULL, FALSE);
        $this->db->where('employee.device_no !=','0');
        $Q = $this->db->get('employee');
        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 checkforappliedleave()
    {
        $staff_list = $_SESSION['employee_id'] . ',';
        $employees = $this->mastermodel->traceemployee($_SESSION['employee_id'], $staff_list);

        $res=$this->db->query("SELECT * FROM `leave_application` where employee_id in ($employees)
                and leave_status = 'Pending' and employee_id != '".$_SESSION['employee_id']."'");
        $count=$res->num_rows();
        return $count;
     }
     
     function commonuploadfile($postdata)
    {
         $this->db->trans_begin();
         $tbl1Values=array('master_id'=>$postdata['master_id'],
             'document_type_id'=>$postdata['document_type_id'],
             'file_location'=>$postdata['file_location']);
          $this->db->insert('common_file', $tbl1Values);
          $this->db->trans_commit();
    }
}

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