<?php
    include "head.php" ;
    session_start();
    date_default_timezone_set("Asia/Kolkata");

    if(isset($_SESSION['user_id']) && isset($_SESSION['user_name']) && $_SESSION['user_cate'] === "user"){
        $user_id = $_SESSION['user_id'] ;
        $username = $_SESSION['user_name'] ;
        $email = $_SESSION['user_email'] ;
        $phone = $_SESSION['user_phone'] ;
        $user_image = $_SESSION['user_image'] ;
        echo $user_image;
        if(isset($_POST['action']) || isset($_GET['pid'])){
            if(isset($_GET['pid'])){
                $pid = $_GET['pid'];
            }else{
                $pid = $_POST['pid'];
            }
            $p_sql = $config->query("SELECT * FROM players WHERE id = '$pid' ");
            $p_row = $p_sql->fetch_assoc();
            $name = $p_row['name'];
            $name_initial = $p_row['name_initial'];
            $school_name = $p_row['school_name'];
            $fname = $p_row['f_name'];
            $dob = $p_row['dob'];
            $gender = $p_row['gender'];
            $country = $p_row['country'];
            $state = $p_row['state'];
            $city = $p_row['city'];
            $address = $p_row['address'];
            $email = $p_row['email'];
            $phone = $p_row['phone'];
            $fide_id = $p_row['fide_id'];
            $aicf_id = $p_row['aicf_id'];
            $tnsca_id = $p_row['tnsca_id'];
            $chess_id = $p_row['chess_id'];
            $lichess_id = $p_row['lichess_id'];
        }
    }else{
        header("Location:login.php") ;
    }
?>

	<body>

		<!-- Main Wrapper -->
		<div class="main-wrapper">
		
			<!-- Header -->
			<?php include "header.php" ; ?>
			<!-- /Header -->
			
			<!-- Breadcrumb -->
			<?php include "breadcrumbuser.php" ; ?>
			<!-- /Breadcrumb -->
			
			<!-- Page Content -->
			<div class="content">
				<div class="container-fluid">

					<div class="row">
						<div class="col-md-5 col-lg-4 col-xl-3 theiaStickySidebar">
						
							<!-- Profile Sidebar -->
							<?php include "sidebar.php" ; ?>
							<!-- /Profile Sidebar -->
							
						</div>
						<div class="col-md-7 col-lg-8 col-xl-9">
						    <div class="d-flex justify-content-between align-items-start">
							    <h4 class="card-title">Edit Players</h4>
							    <a href="players-list.php" class="btn btn-sm bg-info-light">Back</a>
							</div>
						    <?php
						        $pro_sql = "SELECT * FROM v_profile WHERE v_id = '$user_id' " ;
						        $pro_res = $config->query($pro_sql);
						        $pro = $pro_res->fetch_assoc();
						    ?>
						    <form method="post" enctype="multipart/form-data" action="edit.php">
    							<!-- Basic Information -->
    							<div class="card">
    								<div class="card-body">
    								    <h4 class="card-title">Personal Details</h4>
        								<div class="row form-row">
    										<div class="col-md-4">
    											<div class="form-group">
    												<label for="name">Player Name<span class="text-danger">*</span></label>
    												<input type="text" class="form-control" name="name" id="name" value="<?= $name ?>" >
    											</div>
    										</div>
                                              <div class="col-md-2">
                                                <div class="form-group">
                                                    <label for="name">Name Initial<span class="text-danger">*</span></label>
                                                    <input type="text" class="form-control" value="<?=$name_initial?>" name="name_initial" id="initial" value="<?= $name_initial ?>" >
                                                    <span class="text-danger py-2"><?= $inErr ?></span>
                                                </div>
                                            </div>
                                           <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="name">School Name<span class="text-danger"></span></label>
                                                    <input type="text"  value="<?=$school_name?>"  class="form-control" name="school_name" id="s_name" value="<?= $school_name ?>" >
                                                    <span class="text-danger py-2"><?= $schoolErr ?></span>
                                                </div>
                                            </div> 
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="fname">Father Name/ Guardian Name<span class="text-danger">*</span></label>
    												<input type="text" class="form-control" name="fname" id="fname" value="<?= $fname ?>" >
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="dob">Date Of Birth<span class="text-danger">*</span></label>
    												<input type="date" class="form-control" name="dob" id="dob" value="<?= $dob ?>" >
    											</div>
    										</div>
    										<div class="col-md-6"> 
    											<div class="form-group">
    												<label for="gender">Gender<span class="text-danger">*</span></label>
    												<select class="form-control" name="gender" id="gender" >
    												    <option value="">--SELECT--</option>
    												    <option value="Female" <?= $gender == 'Female' ? 'selected' : '' ; ?>>Female</option>
    												    <option value="Male" <?= $gender == 'Male' ? 'selected' : '' ; ?>>Male</option>
    												    <option value="Others" <?= $gender == 'Others' ? 'selected' : '' ; ?>>Others</option>
    												</select>
    											</div>
    										</div>
    									</div>
    								</div>
    							</div>
    							<div class="card">
    								<div class="card-body">
    								    <h4 class="card-title">Contact Details</h4>
        								<div class="row form-row">
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="country" class="control-label">Country<span class="text-danger">*</span></label>
    												<input type="text" class="form-control" name="country" id="country" value="<?= $country ?>">
    												<span class="text-danger py-2"><?= $countryErr ?></span>
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="state" class="control-label">State<span class="text-danger">*</span></label>
    												<input type="text" class="form-control" name="state" id="state" value="<?= $state ?>">
    												<span class="text-danger py-2"><?= $stateErr ?></span>
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="city" class="control-label">City<span class="text-danger">*</span></label>
    												<input type="text" class="form-control" name="city" id="city" value="<?= $city ?>">
    												<span class="text-danger py-2"><?= $cityErr ?></span>
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="address" >Address<span class="text-danger">*</span></label>
    												<input type="text" class="form-control" name="address" id="address" value="<?= $address ?>">
    												<span class="text-danger py-2"><?= $addressErr ?></span>
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="com_map">Contact Email <span class="text-danger">*</span></label>
    												<input type="email" class="form-control" name="email" id="email" value="<?= $email ?>" >
    												<span class="text-danger py-2"><?= $emailErr ?></span>
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label>Contact Number <span class="text-danger">*</span></label>
    												<input type="text" class="form-control" name="phone" id="phone" value="<?= $phone ?>" maxlength="10" onkeypress="if(this.value.length == 10) return false;">
    												<span class="text-danger py-2"><?= $phoneErr ?></span>
    											</div>
    										</div>
    									</div>
    						        </div>
        							<!-- /Basic Information -->
        						</div>	
    							<div class="card">
    								<div class="card-body">
    								    <h4 class="card-title">Professional Details</h4>
        								<div class="row form-row">
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="fide_id" class="control-label">FIDE ID</label>
    												<input type="text" class="form-control" name="fide_id" id="fide_id" value="<?= $fide_id ?>">
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="aicf_id" class="control-label">AICF ID</label>
    												<input type="text" class="form-control" name="aicf_id" id="aicf_id" value="<?= $aicf_id ?>">
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="tnsca_id" >TNSCA ID</label>
    												<input type="text" class="form-control" name="tnsca_id" id="tnsca_id" value="<?= $tnsca_id ?>">
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="chess_id">Chess.com Id</label>
    												<input type="text" class="form-control" name="chess_id" id="chess_id" value="<?= $chess_id ?>" >
    											</div>
    										</div>
    										<div class="col-md-6">
    											<div class="form-group">
    												<label for="lichess_id">Lichess ID</label>
    												<input type="text" class="form-control" name="lichess_id" id="lichess_id" value="<?= $lichess_id ?>" >
    											</div>
    										</div>
    									</div>
    						        </div>
        							<!-- /Basic Information -->
        						</div>	
    							<div class="submit-section submit-btn-bottom">
    							    <input type="hidden" name="id" value="<?= $pid ?>" >
    								<button type="submit" class="btn btn-primary submit-btn" name="submit">Update</button>
    							</div>
							</form>
						</div>
					</div>

				</div>

			</div>		
			<!-- /Page Content -->
   
			<!-- Footer -->
		    <?php include "footer.php" ; ?>
			<!-- /Footer -->
		   
		</div>
		<!-- /Main Wrapper -->
	  
		<!-- jQuery -->
		<script src="assets/js/jquery.min.js"></script>
		
		<!-- Bootstrap Core JS -->
		<script src="assets/js/popper.min.js"></script>
		<script src="assets/js/bootstrap.min.js"></script>
		
		<!-- Sticky Sidebar JS -->
        <script src="assets/plugins/theia-sticky-sidebar/ResizeSensor.js"></script>
        <script src="assets/plugins/theia-sticky-sidebar/theia-sticky-sidebar.js"></script>
		
		<!-- Select2 JS -->
		<script src="assets/plugins/select2/js/select2.min.js"></script>
		
		<!-- Dropzone JS -->
		<script src="assets/plugins/dropzone/dropzone.min.js"></script>
		
		<!-- Bootstrap Tagsinput JS -->
		<script src="assets/plugins/bootstrap-tagsinput/js/bootstrap-tagsinput.js"></script>
		
		<!-- Profile Settings JS -->
		<script src="assets/js/profile-settings.js"></script>
		
		<!-- Custom JS -->
		<script src="assets/js/script.js"></script>
		<script>
    		<?php if(isset($_SESSION['status']) && !empty($_SESSION['status'])) { ?>
    		    swal({
                  title: "<?= $_SESSION['status'] ?>",
                  text: "",
                  icon: "<?= $_SESSION['alert'] ?>",
                });
            <?php unset($_SESSION['status']) ; } ?>
        </script>
        <script>
    		<?php if(isset($_SESSION['check']) && !empty($_SESSION['check'])) { ?>
    		    swal({
                    title: "<?= $_SESSION['check'] ?>", 
                    text: "",
                    icon: "<?= $_SESSION['alert'] ?>",
                });
            <?php unset($_SESSION['check']) ; } ?>
        </script>
	</body>

<!-- doccure/doctor-profile-settings.html  30 Nov 2019 04:12:15 GMT -->
</html>