<?php
session_start();
include("../../config/database.php");
error_reporting(0);
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
    $id                     = $_GET['id'];
    $emp_zone               = "";
    if(isset($_GET['emp_zone']))
    {
      $emp_zone                     = $_GET['emp_zone'];  
    }
    $id_qry                 = "";
    if($id>0)
    {
        $id_qry                 = " and `id` !='$id' ";
    }
    $emp_name               = ucwords(strtolower(mysql_real_escape_string($_GET['emp_name'])));
    $emp_name_alias         = mysql_real_escape_string($_GET['emp_name_alias']);
    $desiganation           = strtoupper(mysql_real_escape_string($_GET['desiganation']));
    $gender		            = mysql_real_escape_string($_GET['gender']);
    $head_qtrer	            = mysql_real_escape_string($_GET['head_qtrer']);
    $state		            = mysql_real_escape_string($_GET['state']);
    $aadhar_no	            = mysql_real_escape_string($_GET['aadhar_no']);
    $account_no	            = mysql_real_escape_string($_GET['account_no']);
    $check_qry				= mysql_query(" SELECT * FROM `tbl_emp_records` WHERE `status`='0' and (`account_no`='$account_no' || `aadhar_no`='$aadhar_no') $id_qry ")or die(mysql_error());
    if(mysql_num_rows($check_qry)==0)
    {
        if($_GET['emp_code']=='0')
        {
            $state_qry				= mysql_query(" SELECT `state_code` FROM `state` WHERE `state_name`='$state' ")or die(mysql_error());
            $state_data				= mysql_fetch_array($state_qry);

            $sql_code				= mysql_query(" SELECT `emp_code` FROM `tbl_emp_records` WHERE `emp_code`!='' and `state`='$state' order by `id` DESC ");
            if(mysql_num_rows($sql_code)>0)
            {
                $data_code			= mysql_fetch_array($sql_code);
                $emp_code_arr		= explode("-",$data_code['emp_code']);

                $emp_code			= $state_data['state_code']."-".($emp_code_arr[1]+1);
            }
            else
            {
                $emp_code			= $state_data['state_code']."-"."1";
            }             
        }
        else
        {
          $emp_code		    	= $_GET['emp_code'];
        }
        $tsi	            	= mysql_real_escape_string($_GET['tsi']);
        $tso		            = mysql_real_escape_string($_GET['tso']);
        $asm		            = mysql_real_escape_string($_GET['asm']);
        $st_head	            = mysql_real_escape_string($_GET['st_head']);
        $fnct_head	            = mysql_real_escape_string($_GET['fnct_head']);
        $dob		            = date("Y-m-d",strtotime($_GET['dob']));
        $mobil_no	            = mysql_real_escape_string($_GET['mobil_no']);
        $marital_st	            = mysql_real_escape_string($_GET['marital_st']);
        $fname		            = mysql_real_escape_string($_GET['fname']);

        $uan_no					= mysql_real_escape_string($_GET['uan_no']);
        $bank_name	            = mysql_real_escape_string($_GET['bank_name']);
        $bank_name_alias        = mysql_real_escape_string($_GET['bank_name_alias']);
        $branch_name            = mysql_real_escape_string($_GET['branch_name']);
        $branch_city	        = mysql_real_escape_string($_GET['branch_city']);
        $branch_ifsc            = strtoupper(mysql_real_escape_string($_GET['branch_ifsc']));

        $salary_rate            = mysql_real_escape_string($_GET['salary_rate']);
        $da_rate	            = mysql_real_escape_string($_GET['da_rate']);
        $phone_rate	            = mysql_real_escape_string($_GET['phone_rate']);
        $ta_rate				= mysql_real_escape_string($_GET['ta_rate']);
        $travel_exp				= mysql_real_escape_string($_GET['travel_exp']);
        $payment_status         = mysql_real_escape_string($_GET['payment_status']);
        $uan_status             = mysql_real_escape_string($_GET['uan_status']);
        $payment_status_2       = mysql_real_escape_string($_GET['payment_status_2']);
        $uan_status_2           = mysql_real_escape_string($_GET['uan_status_2']);

        $jul_sal            	= mysql_real_escape_string($_GET['jul_sal']);
        $jul_paid       	    = mysql_real_escape_string($_GET['jul_paid']);
        $jul_code    	        = mysql_real_escape_string($_GET['jul_code']);
        $jul_dis_name           = mysql_real_escape_string($_GET['jul_dis_name']);
        $jul_status	            = "Pendding";
        if(isset($_GET['jul_status']))
        {
         $jul_status	        = mysql_real_escape_string($_GET['jul_status']);
        }

        $aug_sal	            = mysql_real_escape_string($_GET['aug_sal']);
        $aug_paid	            = mysql_real_escape_string($_GET['aug_paid']);
        $aug_code	            = mysql_real_escape_string($_GET['aug_code']);
        $aug_dis_name           = mysql_real_escape_string($_GET['aug_dis_name']);
        $aug_status	            = "Pendding";
        if(isset($_GET['aug_status']))
        {
         $aug_status	        = mysql_real_escape_string($_GET['aug_status']);
        }

        $sept_sal	            = mysql_real_escape_string($_GET['sept_sal']);
        $sept_paid              = mysql_real_escape_string($_GET['sept_paid']);
        $sept_code              = mysql_real_escape_string($_GET['sept_code']);
        $sept_dis_name          = mysql_real_escape_string($_GET['sept_dis_name']);
        $sep_status	            = "Pendding";
        if(isset($_GET['sep_status']))
        {
         $sep_status	        = mysql_real_escape_string($_GET['sep_status']);
        }

        $oct_sal	            = mysql_real_escape_string($_GET['oct_sal']);
        $oct_paid               = mysql_real_escape_string($_GET['oct_paid']);
        $oct_code               = mysql_real_escape_string($_GET['oct_code']);
        $oct_dis_name           = mysql_real_escape_string($_GET['oct_dis_name']);
        $oct_status	            = "Pendding";
        if(isset($_GET['oct_status']))
        {
         $oct_status	        = mysql_real_escape_string($_GET['oct_status']);
        }
        $remark					= mysql_real_escape_string($_GET['remark']);
        $front_photo			= '';
        $back_photo				= '';
        $sql_img				= '';
        if(!empty($_FILES['front_photo']['name']))
        {
            $front_photo        = rand().$_FILES['front_photo']['name'];
            $sql_img			.= " , `front_photo`='$front_photo' ";
            move_uploaded_file($_FILES['front_photo']['tmp_name'],"page_image/".$front_photo);
        }
        if(!empty($_FILES['back_photo']['name']))
        {
            $back_photo         = rand().$_FILES['back_photo']['name'];
            if(!empty($sql_img))
            {
                $sql_img		.= " , ";
            }
            $sql_img			.= " `back_photo`='$back_photo' ";
            move_uploaded_file($_FILES['back_photo']['tmp_name'],"page_image/".$back_photo);
        }
        if($_SESSION['userid']==4)
        {
            $sql_img		 .= ", `jul_status`='$jul_status', `aug_status`='$aug_status', `sep_status`='$sep_status' ";
        }
        if($id>0)
        {
            $sql    = mysql_query("update `tbl_emp_records` set  `emp_zone`='$emp_zone', `emp_code`='$emp_code', `emp_name`='$emp_name', `emp_name_alias`='$emp_name_alias', `desiganation`='$desiganation', `gender`='$gender', `head_qtrer`='$head_qtrer', `state`='$state', `tsi`='$tsi', `tso`='$tso', `asm`='$asm', `st_head`='$st_head', `fnct_head`='$fnct_head', `dob`='$dob', `mobil_no`='$mobil_no', `marital_st`='$marital_st', `fname`='$fname', `aadhar_no`='$aadhar_no', `uan_no`='$uan_no' ,`bank_name`='$bank_name', `bank_name_alias`='$bank_name_alias', `branch_name`='$branch_name', `branch_city`='$branch_city', `branch_ifsc`='$branch_ifsc', `account_no`='$account_no', `salary_rate`='$salary_rate', `da_rate`='$da_rate', `phone_rate`='$phone_rate',`ta_rate`='$ta_rate',`travel_exp`='$travel_exp',`jul_sal`='$jul_sal', `jul_paid`='$jul_paid', `jul_code`='$jul_code', `jul_dis_name`='$jul_dis_name', `aug_sal`='$aug_sal', `aug_paid`='$aug_paid', `aug_code`='$aug_code', `aug_dis_name`='$aug_dis_name', `sept_sal`='$sept_sal', `sept_paid`='$sept_paid', `sept_code`='$sept_code', `sept_dis_name`='$sept_dis_name',`oct_sal`='$oct_sal',`oct_paid`='$oct_paid',`oct_code`='$oct_code',`oct_dis_name`='$oct_dis_name',`oct_status`='$oct_status',`remark`='$remark',`payment_status`='$payment_status', `uan_status`='$uan_status',`payment_status_2`='$payment_status_2', `uan_status_2`='$uan_status_2' $sql_img where `id`='$id' ")or die(mysql_error());
            echo 0;
        }
        else
        {
            $sql    = mysql_query("insert into `tbl_emp_records` set `emp_zone`='$emp_zone', `emp_code`='$emp_code', `emp_name`='$emp_name', `emp_name_alias`='$emp_name_alias', `desiganation`='$desiganation', `gender`='$gender', `head_qtrer`='$head_qtrer', `state`='$state', `tsi`='$tsi', `tso`='$tso', `asm`='$asm', `st_head`='$st_head', `fnct_head`='$fnct_head', `dob`='$dob', `mobil_no`='$mobil_no', `marital_st`='$marital_st', `fname`='$fname', `aadhar_no`='$aadhar_no', `uan_no`='$uan_no' ,`bank_name`='$bank_name', `bank_name_alias`='$bank_name_alias', `branch_name`='$branch_name', `branch_city`='$branch_city', `branch_ifsc`='$branch_ifsc', `account_no`='$account_no', `salary_rate`='$salary_rate', `da_rate`='$da_rate', `phone_rate`='$phone_rate',`ta_rate`='$ta_rate',`travel_exp`='$travel_exp',`jul_sal`='$jul_sal', `jul_paid`='$jul_paid', `jul_code`='$jul_code', `jul_dis_name`='$jul_dis_name', `aug_sal`='$aug_sal', `aug_paid`='$aug_paid', `aug_code`='$aug_code', `aug_dis_name`='$aug_dis_name', `sept_sal`='$sept_sal', `sept_paid`='$sept_paid', `sept_code`='$sept_code', `sept_dis_name`='$sept_dis_name',`oct_sal`='$oct_sal',`oct_paid`='$oct_paid',`oct_code`='$oct_code',`oct_dis_name`='$oct_dis_name',`oct_status`='$oct_status',`remark`='$remark',`payment_status`='$payment_status', `uan_status`='$uan_status',`payment_status_2`='$payment_status_2', `uan_status_2`='$uan_status_2' $sql_img  ")or die(mysql_error());
            echo 1;
        }
    }
    else
    {
        $data		= mysql_fetch_array($check_qry);
        if($data['aadhar_no']==$aadhar_no)
        {
            echo 2;
        }
       else if($data['account_no']==$account_no)
        {
            echo 3;
        }
    }
mysql_close();
?>