<?php


include ('db.php');
session_start();


//if($_SERVER['REQUEST_METHOD']=="POST"){
//    print_r($_POST); 
//}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
//    print_r($_POST);
    print_r($_FILES);
    //    echo $_REQUEST['name'];

    $photo = $_FILES['pic']['name'];
   /* $tempname = $_FILES['pic']['tmp_name'];
    $div = explode('.', $photo);
    $file_ext = strtolower(end($div));
    $appName = preg_replace('/\s+/', '_', $_REQUEST['name']);
    $unique_imagep = $appName . '_' . 'P' . '_' . substr(md5(time()), 0, 5) . '.' . $file_ext;
    //$uploaded_pic = "PDF/web_pdf/LAW_EXAM/pic/" . $unique_imagep;
    $uploaded_pic = "/images/pic/" . $unique_imagep;
    move_uploaded_file($tempname, $uploaded_pic);*/

    $sign = $_FILES['sign']['name'];
    /*$tempname = $_FILES['sign']['tmp_name'];
    $div = explode('.', $sign);
    $file_ext = strtolower(end($div));
    $unique_image = $appName . '_' . 'S' . '_' . substr(md5(time()), 11, 15) . '.' . $file_ext;
    //$uploaded_sign = "PDF/web_pdf/LAW_EXAM/sign/" . $unique_image;
    $uploaded_sign = "/images/sign/" . $unique_image;
    move_uploaded_file($tempname, $uploaded_sign);*/

    
    $sql_max_id = "select max(id) as max_id from app_details";
    $result_max = mysqli_query($link,$sql_max_id);
    $row_max = mysqli_fetch_assoc($result_max);

    $last_appid = str_pad($row_max['max_id']+1, 5, '0', STR_PAD_LEFT);
    
    $app_no = "MPLAW" .$last_appid ;
    $_SESSION['app_no']=$app_no;
    $full_name = $_REQUEST['name'];
    $father_name = $_REQUEST['father_name'];
    $mother_name = $_REQUEST['mother_name'];
    $gender = $_REQUEST['gender'];
    $dob = date("Y-m-d", strtotime($_REQUEST['dob']));
    $year = $_REQUEST['age_year'];
    $month = $_REQUEST['age_month'];
    $days = $_REQUEST['age_day'];
    $domicile = $_REQUEST['domicile'];
    $category = $_REQUEST['category'];
    $disability = $_REQUEST['disability'];
    $govt = $_REQUEST['govt'];
    $job_details = $_REQUEST['job_details'];
    $marital_status = $_REQUEST['marital_status'];
    $email = $_REQUEST['email'];
    $mobile = $_REQUEST['mobile_no'];
    $case_details = $_REQUEST['case_details'];
    $place_preference = $_REQUEST['ddlplace'];
    $current_address = $_REQUEST['current_address'];
    $permanent_address = $_REQUEST['permanent_address'];
    $que_1 = $_REQUEST['Q_Clerk_Cum_Research_Assist'];
    $que_2 = $_REQUEST['Q_JudicialService'];
    $que_3 = $_REQUEST['Q_Judge_Lawyer'];
    $check_dec = $_REQUEST['declaration'];
    $photo = $_REQUEST['pic'];
    $sign = $_REQUEST['sign'];
    $place = $_REQUEST['place'];
    $submit_date = date('Y-m-d h:i:s');
    $t10th_board = $_REQUEST['ten_board'];
    $t10th_year = $_REQUEST['ten_pass_year'];
    $t10th_per = $_REQUEST['ten_percentage'];
    $t12th_board = $_REQUEST['twelve_board'];
    $t12th_year = $_REQUEST['twelve_pass_year'];
    $t12th_per = $_REQUEST['twelve_percentage'];
    $Graduation_uni = $_REQUEST['grad_exam_unisity'];
    $Graduation_year = $_REQUEST['grad_pass_year'];
    $Graduation_per = $_REQUEST['grad_percentage'];
    $pg_uni = $_REQUEST['llb_exam_uni'];
    $pg_year = $_REQUEST['llb_pass_year'];
    $pg_per = $_REQUEST['llb_percentage'];
    $pg = $_REQUEST['ddlgraduation'];
    $I_secured = $_REQUEST['grad_pass_yearI'];
    $I_max = $_REQUEST['grad_percentageI'];
    $II_secured = $_REQUEST['grad_pass_yearII'];
    $II_max = $_REQUEST['grad_percentageII'];
    $III_secured = $_REQUEST['grad_pass_yearIII'];
    $III_max = $_REQUEST['grad_percentageIII'];
    $IV_secured = $_REQUEST['grad_pass_yearIV'];
    $IV_max = $_REQUEST['grad_percentageIV'];
    $V_secured = $_REQUEST['grad_pass_yearV'];
    $V_max = $_REQUEST['grad_percentageV'];
    $VI_secured = $_REQUEST['grad_pass_yearVI'];
    $VI_max = $_REQUEST['grad_percentageVI'];
    $VII_secured = $_REQUEST['grad_pass_yearVII'];
    $VII_max = $_REQUEST['grad_percentageVII'];
    $VIII_secured = $_REQUEST['grad_pass_yearVIII'];
    $VIII_max = $_REQUEST['grad_percentageVIII'];
    $IX_secured = $_REQUEST['grad_pass_yearIX'];
    $IX_max = $_REQUEST['grad_percentageIX'];
    $X_secured = $_REQUEST['grad_pass_yearX'];
    $X_max = $_REQUEST['grad_percentageX'];
    $additional_que = $_REQUEST['additional_qualification'];
    $achievement = $_REQUEST['achievement_llb'];
    $co_achievement = $_REQUEST['achievement_activities'];


     $sql = "INSERT INTO `law_exam`.`app_detail` (app_no,full_name,father_name,mother_name,gender,dob,year,month,days,mp_domicile,category,handicapped,marital_status,govt_employee,govt_employee_details,email,mobile,case_details,place_preference,current_address,permanent_address,que_1,que_2,que_3,check_dec,photo,sign,place,submit_date,10th_board,10th_year,10th_per,12th_board,12th_year,12th_per,Graduation_uni,Graduation_year,Graduation_per,pg_uni,pg_year,pg_per,pg,I_secured,I_max,II_secured,II_max,III_secured,III_max,IV_secured,IV_max,V_secured,V_max,VI_secured,VI_max,VII_secured,VII_max,VIII_secured,VIII_max,IX_secured,IX_max,X_secured,X_max,additional_que,achievement,co_achievement) VALUES "
    . "('$app_no','$full_name','$father_name','$mother_name','$gender','$dob','$year','$month','$days','$domicile','$category','$disability','$marital_status','$govt','$job_details',"
    . "'$email','$mobile','$case_details','$place_preference','$current_address','$permanent_address','$que_1','$que_2','$que_3','$check_dec','$unique_imagep','$unique_image','$place',"
    . "'$submit_date','$t10th_board','$t10th_year','$t10th_per','$t12th_board','$t12th_year','$t12th_per','$Graduation_uni','$Graduation_year','$Graduation_per','$pg_uni',"
    . "'$pg_year','$pg_per','$pg','$I_secured','$I_max','$II_secured','$II_max','$III_secured','$III_max','$IV_secured','$IV_max','$V_secured','$V_max','$VI_secured','$VI_max',"
    . "'$VII_secured','$VII_max','$VIII_secured','$VIII_max','$IX_secured','$IX_max','$X_secured','$X_max','$additional_que','$achievement','$co_achievement')";

    $result = mysqli_query($link, $sql);

    if ($result) {

        /*$conn_sms=mysql_connect("10.131.91.47:3307", "sms-web", "web**123") or die("unable to connect the server");
                  mysql_select_db("sms_from_bhopal") or die("unable to connect the database");

        $otp_msg = "Dear candidate, your application form for Legal Assistant/Law Clerk-cum-Research Test-2022 has been submitted successfully, and your registration number is $app_no and your password is DOB (DDMMYYYY). Regards MP High Court (Exam Cell)";
        $sql_msg = "INSERT INTO sms_from_bhopal.sms_pool (mobile,msg,table_name,ent_time) values ('" . trim($mobile) . "','$otp_msg', 'law_exam', NOW()) ";*/
        $rs = mysql_query($sql_msg) or die(mysql_errno());
        //header('Location:/law-clerk-preview');
        header('Location:preview.php');
    } else {
        //echo 'Error';
        echo("Error description: " . $mysqli -> error);
    }
}
?>