<?php

$database = new MySQLDatabase();
$session = new Session();
$applicant_fullname = User::applicant_fullname($session->applicant_id);
$result_details = User::find_by_id($session->applicant_id);
$next_of_kin_details = NextOfKin::find_by_id($session->applicant_id);
?>
<h3 align="center">Personal Details</h3>
<hr>
<h6 align="center">All Fields are Required </h6>
<form action="" method="POST" class="personal_details form-horizontal" >
	<div class="row-fluid">
        <div class="span6">
        
        <!-- Form ID -->
                    <div class="control-group">
                        <label class="control-label" for="inputFormId">Application Number:</label> 
                        <div class="controls">
                            <div class="input-prepend">
                                <span class="add-on"><i class="icon-user"></i></span>
                                <input type="text" readonly class="input-xlarge" name="form_id" id="form_id" value="<?php 
echo $result_details->form_id;
?>
" />
                            </div>
                        </div>
                    </div>
                    
                    <!-- Title -->
                    <?php 
        echo '<hr>';
        exit;
    }
}
$user->db_fields = array('title_id', 'gender', 'marital_status', 'dob', 'address', 'lga_id', 'religion_id', 'country_id');
$user->title_id = $_POST['title_id'];
$user->gender = $_POST['gender_id'];
$user->marital_status = $_POST['marital_status_id'];
$user->dob = $_POST['dob'];
$user->country_id = $_POST['country_id'];
$user->lga_id = $_POST['lga_id'];
$user->religion_id = $_POST['religion_id'];
$user->address = $_POST['address'];
$user->applicant_id = $session->applicant_id;
if ($user->save()) {
    $next_of_kin = new NextOfKin();
    $next_of_kin_details = $next_of_kin->find_by_id($user->applicant_id);
    if (!empty($next_of_kin_details)) {
        $next_of_kin->next_kin_id = $next_of_kin_details->next_kin_id;
    }
    $next_of_kin->next_of_kin_name = $_POST['next_kin_name'];
    $next_of_kin->next_of_kin_relationship = $_POST['next_of_kin_relationship'];
    $next_of_kin->next_of_kin_number = $_POST['next_of_kin_number'];
    $next_of_kin->next_of_kin_address = $_POST['next_of_kin_address'];
    $next_of_kin->applicant_id = $user->applicant_id;
    if ($next_of_kin->save()) {
        $user->updateProgress('A');
        sleep(2);
        echo '<h4 class="alert alert-success"><i class="iconic-o-check" style="color: #51A351"></i> Success</h4>';
        echo '<hr>';
        echo 'You have successfully saved your <span style=" font-weight: bold; text-shadow: 1px 1px 4px #51A351;">Personal Details </span> tab, use the close button to continue.';