<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
require_once('../lib/dbclass.php');

extract($_POST);
$data = $_REQUEST;


if ($data['Assembly'] == 0 && $data['District'] == 0 && $data['Panchayat'] > 0) {
    $Panchayat = $data['Panchayat'];


    $dataassem        = findQuery("select * from tbl_panchayat where status=0 and id=$Panchayat");
    $data['Assembly'] = $dataassem[0]['assembly_id'];
    $assembly         = $data['Assembly'];

    $datadis          = findQuery("select * from tbl_assembly where status=0 and id=$assembly");
    $data['District'] = $datadis[0]['district'];
}

if ($data['Panchayat'] == 0) {
    $dataassem        = findQuery('select * from tbl_assembly where district=0');
    $data['Assembly'] = $dataassem[0]['id'];



    $datapan           = findQuery('select * from tbl_panchayat where assembly_id=0');
    $data['Panchayat'] = $datapan[0]['id'];

    $datawrd      = findQuery('select * from tbl_ward where panchayat_id=0');
    $data['Ward'] = $datawrd[0]['id'];

    $data['District'] = $data['District'];
}

$data['Photo'] = '';

if ($data['isphoto']) {
    if ($data['isphoto'] == 1) {
        $target_dir       = 'images/';
        $random           = rand(0, 999999);
        $filename         = sha1($image . $random);
        $target_file_name = $target_dir . $filename;
        $img_name         = basename($_FILES['image']['name']);

        if (move_uploaded_file($_FILES['image']['tmp_name'], $target_file_name)) {
        } else {
            $message = 'False';
            $data2[] = ['error' => 'Some Error Occured While Uploading Photo'];
            echo json_encode(['Status' => $message, 'data' => $data2]);

            return;
        }







        $data['Photo'] = $filename;
    }
}

unset($data['isphoto']);
$id = saveArray('tbl_customer', $data, 0);






if ($id > 0) {
    $message = 'True';
    $data2   = $id;
} else {
    $message = 'False';
    $data2   = 0;
}

echo json_encode(['Status' => $message, 'data' => $data2]);








return;
?>	   


