
<?Php

	include('config/config_DB.php');

	$sql = "SELECT * FROM appli_projects";
	//$return = mysqli_query($connexion , $query);
	$result = $connexion->query($sql);
	if ($result->num_rows > 0) 
	{
		// output data of each row
		while($row = $result->fetch_assoc()) 
		{
			//echo "id: " . $row["id"]. " - Name: " . $row["project"]. " " . $row["categorie"]. "<br>";
			
			$id = $row["id"];
			$categorie = $row["categorie"];
 			$project = $row["project"];
			$location = $row["location"];
			$description = $row["description"];
			$client = $row["client"];
			$project_manager = $row["project_manager"];
			$design_leader = $row["design_leader"];
			$start_date = $row["start_date"];
			$end_date = $row["end_date"];
		
		} 
		/*else 
		{
			echo "0 results";
		}*/
		
		$connexion->close();
	}
?>


	<!-- Include Bootstrap 5 Datepicker CSS -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
 
	<div id="update_project" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
		<div class="modal-dialog"> 
				<div class="modal-content modal-md">  
					<div class="modal-header"> 
						<h4 class="modal-title mx-auto" id='head'>
						<i class=""></i> Edition project
						</h4> 
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
					</div> 
				  
				  
					<form method="POST" id='update_form'> 
 
						<div class="modal-body">
   
							<div class="form-horizontal">
        
								<div class="form-group" id="form_element">
									<div class="col-sm-12">
									 <div id="retCode2">
									   <div class="alert alert-success" id="suc_msgAA">
									   <h4><i class="fa fa-check"></i> Data successfully added.</h4>
									 </div>
									 <div class="alert alert-danger" id="err_msgAA">
									   <h4><i class="fa fa-times"></i> Data failed to add.</h4>
									 </div>
									 </div>
									 </div>
								</div>
							
								<div class="form-group" id="form_element">
									<label class="col-sm-5 control-label">Catégorie du project:</label>
									<div class="col-sm-6">
									
<?php										
										$selected = $categorie ; //"Toulouse";
										$options = array('Médical', 'Automobile', 'Power management', 'Sécurité');
										echo "<select id='categorie' name='categorie'  class='form-select' aria-label='Default select example'>";
										foreach($options as $option)
										{
											if($selected == $option) 
											{
												echo "<option selected='selected' value='$option'>$option</option>";
											}
											else 
											{
												echo "<option value='$option'>$option</option>";
											}
										}
										echo "</select>";
?>

									
									<!--
										<select type="text" class="form-control form-select input-sm" style="text-transform:capitalize" autocomplete="off" name="categorie" id="categorie" required/>
											<option id="p_typ"></option>
											<!--
											<option selected>Open this select menu</option>
											-->
									<!--		<option value="1">Médical</option>
											<option value="2">Automobile</option>
											<option value="3">Power management</option>
											<option value="4">Sécurité</option>
										</select>
									-->	
									</div>
								</div>
      
								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">Project Name:</label>
									<div class="col-sm-6">
										<input class="form-control" style="text-transform:capitalize" id="pname" name="pname" type="text" 
										oninput="checkProjectName()" required 
										value="<?php echo isset($project) ? $project : '' ?>" >
										<span id="projet-availability-status"></span>
										<p class="erreur_nom_projet"></p>
									</div>
								</div>
							
								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">Site Location:</label>
									<div class="col-sm-6">
										<!--
										<input class="form-control" id="location" name="location" type="text" placeholder="">-->
<?php										
										$selected = $location ; //"Toulouse";
										$options = array('Meylan', 'Toulouse', 'Autre');
										echo "<select id='location' name='location'  class='form-select' aria-label='Default select example'>";
										foreach($options as $option)
										{
											if($selected == $option) 
											{
												echo "<option selected='selected' value='$option'>$option</option>";
											}
											else 
											{
												echo "<option value='$option'>$option</option>";
											}
										}
										echo "</select>";
?>
										<!--
										<select id = "location" name = "location" class="form-select" aria-label="Default select example">
										<option selected>Selection</option>
										<option value="1">Meylan</option>
										<option value="2">Toulouse</option>
										<option value="3">Autre</option>
										</select>
										-->
										
										<!--
										style="text-transform:capitalize"
										-->
									</div>
								</div>
   
								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">Description:</label>
									<div class="col-sm-8">
										<!--
										<textarea class="form-control"  id="description" name="description" 
										value="<?php echo isset($description) ? $description : '' ?>"
										type="text"  required></textarea>
										-->
										
										<!--
										<textarea class="form-control"  id="description" name="description" 
										value="<?php echo htmlspecialchars($description) ?>"
										type="text"  required></textarea>
										
										<!--
										<textarea class="form-control"  id="description" name="description" type="text"  required
										<?php echo htmlspecialchars($description); ?>
										</textarea>
										-->
										
										<textarea class="form-control" type="text"  required id="description" name="description" ><?php echo htmlspecialchars($description); ?></textarea>
										
									</div>
								</div> 
							
								<!--
								<div class="form-group">
								<label for="datepicker">Select a Date:</label>
								<input type="text" id="datepicker" class="form-control">
								</div>
								-->
				
								<!--
								<div class="row form-group">
								<label for="date" class="col-sm-1 col-form-label">Date</label>
									<div class="col-sm-4">
										<div class="input-group date" id="datepicker">
											<input type="text" class="form-control">
											<span class="input-group-append">
												<span class="input-group-text bg-white d-block">
													<i class="fa fa-calendar"></i>
												</span>
											</span>
										</div>
									</div>
								</div>
								-->
																
								<div class="form-group">
								<label class="col-sm-4 control-label">Date:</label>
									<div class="col-sm-6">
										<div class="input-group date" id="xxxdatepicker">
											<input type="text" class="form-control">
											<span class="input-group-append">
												<span class="input-group-text bg-white d-block">
													<i class="fa fa-calendar"></i>
												</span>
											</span>
										</div>
									</div>
								</div>
					
								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">Client:</label>
									<div class="col-sm-6">
										<input class="form-control" id="client" name="client" type="text" 
										value="<?php echo isset($client) ? $client : '' ?>" placeholder="">
									</div>
								</div>

								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">Project manager:</label>
									<div class="col-sm-6">
										<!--
										<input class="form-control" id="project_manager" name="project_manager" type="text" placeholder="">
										-->
<?php										
										$selected = $project_manager ; //"Toulouse";
										$options = array('Le patron', 'Lulu', 'Alphonse');
										echo "<select id='project_manager' name='project_manager'  class='form-select' aria-label='Default select example'>";
										foreach($options as $option)
										{
											if($selected == $option) 
											{
												echo "<option selected='selected' value='$option'>$option</option>";
											}
											else 
											{
												echo "<option value='$option'>$option</option>";
											}
										}
										echo "</select>";
?>
										
										<!--
										<option selected>Selection</option>
										<option value="1">Le patron</option>
										<option value="2">Lulu</option>
										<option value="3">Alphonse</option>
										</select>
										-->
									</div>
								</div>
							
								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">Design leader:</label>
									<div class="col-sm-6">
										<!--
										<input class="form-control" id="design_leader" name="design_leader" type="text" placeholder="">
										-->
										<!--
										<select id="design_leader" name="design_leader" class="form-select" aria-label="Default select example">
										-->
<?php										
										$selected = $design_leader ; //"Toulouse";
										$options = array('Pierre', 'Paul', 'Jacques');
										echo "<select id='design_leader' name='design_leader'  class='form-select' aria-label='Default select example'>";
										foreach($options as $option)
										{
											if($selected == $option) 
											{
												echo "<option selected='selected' value='$option'>$option</option>";
											}
											else 
											{
												echo "<option value='$option'>$option</option>";
											}
										}
										echo "</select>";
?>
										
										<!--
										<option selected>Selection</option>
										<option value="1">Pierre</option>
										<option value="2">Paul</option>
										<option value="3">Jacques</option>
										</select>
										-->
										
									</div>
								</div>
							
							
								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">xxxStarting Date:</label>
									<div class="col-sm-6">
										<input class="form-control"  id="start_date" name="start_date" type="date" value='2024-09-02' required>
									</div>
								</div>

								<div class="form-group" id="form_element">
									<label class="col-sm-4 control-label">Deadline:</label>
									<div class="col-sm-6">
										<input class="form-control"  id="end_date" name="end_date" type="date"  required>
									</div>
								</div>
						
								<div id="mem-field"></div>
								<div id="div-field"></div>
    
							</div>
							
						</div>
          
						<div class="modal-footer">
							<button type="submit" class="btn btn-info btn-sm" id="btn_sub"><i class="fa fa-save"></i> Save</button>
							<button data-dismiss="modal" class="btn btn-info btn-sm" id="btn_update_close" ><i class="fa fa-close"></i> Close</button>
						</div>

					</form>
					
                </div> 
        </div>
    </div>



<div id="retCode2"></div>

	<!-- Include Bootstrap 5 Datepicker JavaScript -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
	<script src=" https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/locales/bootstrap-datepicker.fr.min.js"></script>
		  


<script>



	jQuery(document).ready(function()
	{
			$('#suc_msgAA').hide();
			$('#err_msgAA').hide();
	  
			$("#btn_update_close").click(function() 
			{
				$("#update_project").modal("hide");
			});
			
			
			jQuery("#update_form").submit(function(e){
								e.preventDefault();
								var formData = jQuery(this).serialize();
								alert("Bravo");
								$.ajax({
									type: "POST",
									url: "add_forms.php?action=project",
									data: formData,
									success: function(html){
										
										console.log("lulu et moi dans modal" + html);
										
										//echo '<script>$("#suc_msg2").show("slidedown");
										
										
										
										/*if( html === "error")
											 $('#err_msg2').show();
										else
										{*/
											 $('#suc_msg2').show();
											  setTimeout(function() { $('#new_project').modal('toggle'); }, 3000);
										
									 
									}
								});
									return false;
						});
			
	});

	
	 $(function () {    
    $('#xxxdatepicker').datepicker({
      isRTL: true,
      autoclose: true, 
      todayHighlight: true,
      language: 'fr',
      format: 'dd-mm-yyyy'
    });
});

</script>