<?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"];
			$project_leader = $row["project_leader"];
			$start_date = $row["start_date"];
			$end_date = $row["end_date"];
		
		} 
		/*else 
		{
			echo "0 results";
		}*/
		
		$connexion->close();

?>


<!-- Update Project Modal -->

		<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" id='head'>
						<i class=""></i> Edition Projet
						</h4> 
					</div> 
                   
					<form method="POST" id='proj_form'> 
 
						<div class="modal-body">
					
							<div class="form-horizontal">
        
								<input type="hidden" name="id" value="<?php echo $id ?>">
						
								<div class="form-group" id="form-login">
									<div class="col-sm-12">
									 <div id="retCode2">
									   <div class="alert alert-success" id="suc_msg2">
									   <h4><i class="fa fa-check"></i> Data successfully updated.</h4>
									 </div>
									 <div class="alert alert-danger" id="err_msg2">
									   <h4><i class="fa fa-times"></i> Data failed to update.</h4>
									 </div>
									 </div>
									 </div>
								</div>
						
								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Proposed Project:</label>
									<div class="col-sm-8">
										<select type="text" class="form-control input-sm" style="text-transform:capitalize" autocomplete="off" name="p_type" id="p_type" onchange="div_field()" required/>
										<option id="p_typ" value="<?php echo $prow['proposed_project'] ?>" >
										<?php if($prow['proposed_project'] == '1'){
										echo 'Building';
										}elseif ($prow['proposed_project'] == '2') {
										echo 'House';
										}elseif ($prow['proposed_project'] == '3') {
										echo 'Highways';
										} ?>
										</option>
										<option value="1">Building</option>
										<option value="2">House</option>
										<option value="3">Highways</option>
										</select>
									</div>
								</div>
		
								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Project Name:</label>
								<div class="col-sm-8">
								<input class="form-control" style="text-transform:capitalize" id="pname" name="pname" type="text" value="<?php echo $project ?>"  required>
								</div>
								</div>
		   
								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Location:</label>
								<div class="col-sm-8">
								<textarea class="form-control" style="text-transform:capitalize" id="location" name="location" type="text"   required><?php echo $location ?></textarea>
								</div>
								</div> 

								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Cost:</label>
								<div class="col-sm-6">
								<input class="form-control" style="text-align:right" id="cc" name="cost" type="text" placeholder="Php." value="<?php echo $prow['overall_cost'] ?>">
								</div>
								</div>

								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Starting date:</label>
								<div class="col-sm-8">
								<input class="form-control"  id="" name="sdate" type="date"  value="<?php echo $prow['start_date'] ?>" required>
								</div>
								</div>

								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Deadline:</label>
								<div class="col-sm-8">
								<input class="form-control"  id="" name="deadline" type="date"  value="<?php echo $prow['deadline'] ?>" required>
								</div>
								</div>

								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Foreman:</label>
								<div class="col-sm-8">
									<select class="form-control"  id="" name="tid" type="text"  required>
									<option value="<?php echo $prow['tid'] ?>"> <?php echo $prow['name'] ?></option>
								<?php
								include '../includes/db.php';
								$pos_query = mysqli_query($conn,"SELECT *,Concat(lastname,', ',firstname,' ',midname) as name FROM project_team left join employee on project_team.eid = employee.eid where project_team.eid != '".$prow['eid']."' order by name ASC");
								while($pos_row = mysqli_fetch_assoc($pos_query)){
								?>
								<option style="text-transform:capitalize" value="<?php echo $pos_row['tid'] ?>"><?php echo $pos_row['name'] ?></option>
								<?php } ?>
								</select>
								</div>
								</div>

								<div class="form-group" id="form-login">
								<label class="col-sm-4 control-label">Status:</label>
								<div class="col-sm-8">
									<select class="form-control"  id="" name="stats" type="date" required>
									<option value="<?php echo $prow['status'] ?>">
									<?php 
									if($prow['status'] == '1'){
									echo 'On Going';
									}elseif($prow['status'] == '2'){
									echo 'Finished';
									}elseif($prow['status'] == '3'){
									echo 'Canceled';
									} 
									?>
									</option>
									<?php if($prow['status'] != '1'){ ?><option value="1">On Going</option><?php } ?>
									<?php if($prow['status'] != '2'){ ?><option value="2">Finished</option><?php } ?>
									<?php if($prow['status'] != '3'){ ?><option value="3">Cancel</option><?php } ?>
									</select>
								</div>
								</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"><i class="glyphicon glyphicon-close"></i>Close</button>
						</div>
			
					</form>
                     
                </div> 
            </div>
        </div>
