<?php  session_start(); error_reporting(0); ?>
<?php if(!isset($_SESSION['j_admin']) && !isset($_SESSION['j_admin'])){ 
    $url = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); header('location:../login/?url='.$url.'');  
} ?>
<!doctype html>
<html lang="en"> 
<head>
	<?php
    require_once("../j_conn/url.php");
    require_once("../j_conn/dbc.php");
    require_once("../j_incs/functions.php");
    $page_name="Edit Profile";
    $page_desc="$page_name";
    $page_img="".$dir."j_files/j_img/logo/logo-meta.png";
    $page_author="$company";
    $page_keywords="".$company.", $page_name, $page_desc, ".$company_motto.", $company_desc";
    $page_url="".$dir."profile-edit/";
    require_once("../j_incs/metas.php");
    require_once("../j_incs/scripts-top.php");
    ?>
</head>
<body>
    
    <div class="app">
        <div class="layout">
            <?php 
            require_once("../j_incs/header.php");
            require_once("../j_incs/nav.php");
            ?>
            <!-- Page Container START -->
            <div class="page-container">
                

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="page-header">
                        <?php /*<h2 class="header-title"><?php echo $page_name; ?></h2>*/ ?>
                        <div class="header-sub-title">
                            <nav class="breadcrumb breadcrumb-dash">
                                <a href="<?php echo $dir; ?>" class="breadcrumb-item"><i class="anticon anticon-dashboard m-r-5"></i>Dashboard</a>
                                <!--<a class="breadcrumb-item" href="#"> </a>-->
                                <span class="breadcrumb-item active"><?php echo $page_name; ?></span>
                            </nav>
                        </div>
                    </div>
                     
                    <div class="container">
                        <div class="tab-content m-t-15">
                            <div class="tab-pane fade show active" id="tab-account">
                                
                                
                                <div class="card">
                                    <div class="card-header">
                                        <h4>
											Profile Update 
										</h4>
                                    </div>
                                    <div class="card-body">
                                        <form method="POST" action="" id="form" enctype="multipart/form-data">
                                            <div class="form-row">
                                               
                                                <div class="form-group col-md-4">
                                                    <label class="font-weight-semibold">Username</label>
                                                     <div class="input-affix m-b-10">
                                                         <input maxlength="25" type="text" value="<?php echo $username; ?>" class="form-control rMe" name="username" placeholder="Username"/>
                                                     </div>
                                                </div>
                                                
												
                                                <div class="form-group col-md-4">
                                                    <label class="font-weight-semibold">Gender</label>
												   <select type="text" class="form-control rMe" name="gender">
													<?php if(empty($gender)){ ?>
													<option value="">*Choose*</option>
													<?php }else{ ?>
													<option><?php echo $gender; ?></option>
													<?php }?>
													<?php 
													foreach ($gender_array as $gen){ ?>
													<option><?php echo $gen; ?></option>
													<?php } ?>
													</select>
                                                 </div>
                                                
                                                
                                                
                                                
                                                
                                                
                                                <div class="form-group col-md-4">
                                                    <label class="font-weight-semibold lc"><?php if($gender=="Company"){ echo "Company's Name"; }else{ echo "First Name";} ?></label>
                                                     <div class="input-affix m-b-10">
                                                         <input maxlength="50" type="text" value="<?php echo $firstname; ?>"  class="form-control rMe" name="firstname" placeholder="First Name"/>
                                                     </div>
                                                </div>
                                                
                                                
                                                
                                                <div class="form-group col-md-4 lastname" <?php if($gender=="Company"){ ?> style="display:none;" <?php } ?> >
                                                    <label class="font-weight-semibold">Last Name</label>
                                                     <div class="input-affix m-b-10">
                                                         <input maxlength="25" type="text" value="<?php echo $lastname; ?>" class="form-control rMe" name="lastname" placeholder="Last Name"/>
                                                     </div>
                                                </div>
                                                
                                                
                                                <div class="form-group col-md-4">
                                                    <label class="font-weight-semibold">Country</label>
                                                   <select type="text" class="form-control rMe" name="country">
                                                        <?php if(empty($country)){ ?>
                                                            <?php 
                                                            $main_country = get_country();
                                                            if(empty($main_country)){ ?>
                                                            <option value="">*Choose*</option>
                                                            <?php }else{ ?>
                                                            <option><?php echo $main_country; ?></option>
                                                            <?php }?>
                                                        <?php }else{ ?>
                                                        <option><?php echo $country; ?></option>
                                                        <?php }?>

                                                        <?php 
                                                        $sql ="SELECT * from j_countries";
                                                        $result = runSQL($sql);
                                                        while($row=mysqli_fetch_array($result)){
                                                        ?>
                                                        <option><?php echo $row['j_country']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                
                                                <?php 
												/*
                                                <div class="form-group col-md-4">
                                                    <label class="font-weight-semibold">State of Origin</label>
                                                   <select type="text" class="form-control rMe" name="state">
                                                        <?php if(empty($state)){ ?>
                                                        <option value="">*Choose*</option>
                                                        <?php }else{ ?>
                                                        <option><?php echo $state; ?></option>
                                                        <?php }?>
                                                        <?php 
                                                        $sql ="SELECT * from j_states where j_country_id='160'";
                                                        $result = runSQL($sql);
                                                        while($row=mysqli_fetch_array($result)){
                                                        ?>
                                                        <option><?php echo $row['j_name']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
												*/
												?>
												
												<div class="form-group col-md-4" style="display:none;">
                                                    <label class="font-weight-semibold">Home / Office Address</label>
                                                     <input maxlength="50" type="text" value="<?php echo $address; ?>" class="form-control rMe" name="address" placeholder="Home/Office"/>
                                                 </div>
                                                
                                                
                                                
                                                
                                                <div class="form-group col-md-4" style="display:none;">
                                                    <label class="font-weight-semibold">Date of Birth (DD-MM-YYYY)</label>
                                                     <div class="input-affix m-b-10">
                                                         <input maxlength="50" type="date" value="<?php echo $dob; ?>" class="form-control rMe" name="dob" placeholder="DD-MM-YYYY"/>
                                                     </div>
                                                </div>
                                                
                                                
                                                
                                                
                                                
                                                
                                                <div class="form-group col-md-4">
                                                    <label class="font-weight-semibold">E-mail Address</label>
                                                     <div class="input-affix m-b-10">
                                                         <input maxlength="50" type="email" value="<?php echo $email; ?>" class="form-control rMe" name="email" placeholder="E-mail"/>
                                                     </div>
                                                </div>
                                                
                                                
                                                
                                                
                                                <div class="form-group col-md-4" style="display:none;">
                                                    <label class="font-weight-semibold">Mobile Number</label>
                                                     <div class="input-affix m-b-10">
                                                         <input maxlength="20" type="text" value="<?php echo $phone; ?>" class="form-control rMe" name="phone" placeholder="Mobile Number"/>
                                                     </div>
                                                </div>
                                                
                                                
                                                
                                                
                                                
    
                                                
                                                <div class="form-group col-md-4">
                                                    <label class="font-weight-semibold">Current Password</label>
                                                     <div class="input-affix m-b-10">
                                                         <input type="password" class="form-control passw rMe" name="old_password" placeholder="Password"/>
                                                        <span class="prefix-icon" id="sPass" style="cursor: pointer; margin-left: 87%;">
                                                            <i class="anticon anticon-eye"></i>
                                                        </span>
                                                        <span id="sStatus" style="display:none;">0</span>
                                                    </div>
                                                </div>
                                                
                                         
                                                
                               
                                                <div class="form-group col-md-3">
                                                     <button id="submit"  name="submit" class="btn btn-primary btn-block m-t-30">Update</button>
                                                </div>
                                            </div>
                                        </form>
                                        <div id="formresult"></div>
                                    </div>
                                </div>
                             
                            </div>
                            
                        </div>
                    </div>
                </div>
                <!-- Content Wrapper END -->

                <?php
                require_once("../j_incs/footer.php");
                ?>

            </div>
            <!-- Page Container END -->
        </div>
    </div>
    
    
    <?php
    require_once("../j_incs/scripts-bottom.php");
    ?>
    <script>
		/*
        $("[name=country]").change(function () {
            var value=$("[name=country]").val();
            if(value!=""){
                $("[name=state]").html('<option value="">*Loading States...*</option>');	
                $.post("states.php",
                {
                country:value,	
                },function(data){
                    if(data){
                    $("[name=state]").html(data);	
                    }else{
                        $("[name=state]").html('<option value="">*No State*</option>');	
                    }
                });
            }
        });
		*/
        
        $("[name=gender]").on('change',(function() {
        if($("[name=gender]").val() =="Company"){
            $(".lastname").hide();
            $(".lc").text("Company's Name");
        }else{
            $(".lastname").show();
            $(".lc").text("First Name");
        }
        }));
        var form = "#form";
        var button = "#submit";
        var button_val = $(button).html();
        var result = "#formresult";
        $(form).on('submit',(function(e) {
        e.preventDefault();
        $(button).attr('disabled', '');
        $(button).html("<i class='anticon anticon-loading'></i> Processing");
        $(result).html("<div class='alert alert-warning'> Taking too long? <a href=''>Reload </a></div>");
         $.ajax({
        url: "save.php",
        type: "POST",
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
        success: function(data)
        {
        if(data){
         $(button).removeAttr('disabled');
        $(button).html(button_val);
        $(result).html(data);
        }else{
        $(result).html("Error occurred.");
        $(button).removeAttr('disabled');
        $(button).html(button_val);
        }
        }
        });
        }));
        </script>
   
</body>
</html>