<?php include "headerLink.php"?>
<!DOCTYPE html>
<html lang="en">


<body class="animsition">
    <div class="page-wrapper">
        <!-- HEADER MOBILE-->
        <?php include "menuSideBar_mobile.php" ;?>
        <!-- END HEADER MOBILE-->
		
        <!-- MENU SIDEBAR-->
        <?php include "menuSideBar.php" ;?>
        <!-- END MENU SIDEBAR-->

        <!-- PAGE CONTAINER-->
        <div class="page-container">
            <!-- HEADER DESKTOP-->
			<?php include "headerPage.php"?>
            <!-- END HEADER DESKTOP-->
			
			
			
			<!-- MAIN CONTENT-->
			 <!--main content upper start-->
			<?php include "main-content-upper.php"?>
            <!--main content upper end-->
			<!--main content middle start-->
						<div class="row" >
                            <div class="col-lg-12">
									<div class="card">
										<div class="card-header">
											<strong>Properties</strong> Form
										</div>
										<div class="card-body card-block">
											<?php 	
													if($_POST['projectName'] != ""){
														$_SESSION['projectName']=$_POST['projectName'];
														$_SESSION['locationName'] = "";
														$_SESSION['propertiesParentsUnit'] = "";
													 }
													else{
														//echo "project name 0";
													$_SESSION['projectName']= "";
													$_SESSION['locationName'] = "";
													$_SESSION['propertiesParentsUnit'] = "";
													}
												
													if($projectLocation != ""){
														$_SESSION['projectName']= $projectName;
														$_SESSION['locationName']= $locationName;
													}?>
											<form action="" method="post" class="form-horizontal">
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Project</label>
													</div>
													<div class="col-12 col-md-9">
														<input type="text" id="text-input" class="form-control" list="projectName" name="projectName" onChange="javascript: submit();" size="50" value="<?php echo $_SESSION['projectName']?>" readonly placeholder="Select Project"/>
														<datalist id="projectName">
														<?php
															if($_SESSION["username"] != "admin"){
																
																$sqlProject = "select EL.location_id, locations.location_name, locations.project_id, projects.project_name from extra_locations as EL 
																				inner join locations on locations.id = EL.location_id 
																				left join projects on locations.project_id = projects.id 
																				where staff_id = '".$_SESSION['staff_id']."' group by `projects`.`project_name` ORDER BY `projects`.`project_name` ASC  
																				";
															}
															else if($_SESSION["username"] == "admin"){
																
																 $sqlProject = "select * from projects where (project_code <> '000') order by project_name ASC ";
																
															}
															$runProject = mysqli_query($link, $sqlProject);
															if($runProject === FALSE){
																die(mysqli_error($link));
															}
															while($resultProject = mysqli_fetch_array($runProject)){
																
																$project_name = $resultProject["project_name"];
																if($_SESSION["username"] != "admin"){
																	$project_name = $resultProject["project_name"];
																}
																	?>
																	
																	<option value="<?php echo strtoupper($project_name); ?>">
																	<?php
															}
														?>
														</datalist>
														<?php if($_SESSION['projectName'] == ""){?>
														<span class="help-block">Please choose project</span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Location</label>
													</div>
													<div class="col-12 col-md-9">
														
														<input type="text" id="text-input" class="form-control" list="locationName" name="locationName" onChange="javascript: submit();" size="50" value="<?php echo $_SESSION['locationName']?>" placeholder="Select Location" readonly autocomplete="off"/>
														<datalist id="projectName">
														<?php
															if($_SESSION["username"] <> "admin"){
																$sqlLocations = "select EL.location_id, locations.location_name, projects.project_name from extra_locations as EL 
																		inner join locations on locations.id = EL.location_id 
																		left join projects on locations.project_id = projects.id 
																		where projects.project_name = '".$_SESSION["projectName"]."' and staff_id = '".$_SESSION['staff_id']."'";
															}
															else if($_SESSION["username"] == "admin"){
																//ECHO $sqlLocations = "SELECT * FROM `locations`  ";
																 $sqlLocations = "SELECT id, 
																						location_code , 
																						location_name FROM `locations`
																						where project_id = '".$_SESSION["project_id"]. "' 
																						ORDER BY `location_name` ASC ";

															}
															
															$runLocations = mysqli_query($link, $sqlLocations);
															if($runLocations === FALSE){
																die(mysqli_error($link));
															}
															while($resultLocations = mysqli_fetch_array($runLocations)){
																$location_id = $resultLocations["id"];
																$location_code = $resultLocations["location_code"];
																$location_name = $resultLocations["location_name"];
																
																	?>
																	
																<option value="<?php echo strtoupper($location_name); ?>">
																<?php
															}
														?>
														</datalist>
														<?php if($_SESSION['locationName'] == ""){?>
														<span class="help-block">Please choose location</span>
														<?php } ?>
													</div>
												</div>
											</form>
											<form action="properties_registerNew_save.php" method="post" enctype="multipart/form data" >
												<input type="hidden" name="projectLocation" value="<?php echo $_SESSION["projectLocation"]?>">
												<input type="hidden" name="menu" value="<?php echo $_SESSION["menu"]?>">
												<input type="hidden" name="submenu" value="<?php echo $_SESSION["submenu"]?>">
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Parent's Unit No.</label>
													</div>
													<div class="col-12 col-md-9">
														<input type="text" id="propertiesParentsUnit_input" class="form-control" list="propertiesParentsUnit" name="parentUnitNo"  size="50" value="<?php echo $_SESSION['propertiesParentsUnit']?>"  autocomplete="off"/>
														<?php if($_SESSION['propertiesParentsUnit'] == ""){?>
														<span class="help-block">Please choose parent's unit no. </span>
														<?php } ?>
														<br/>
														&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="skipParentsUnit"  onclick="alert();" name="skipParentsUnit" value="yes" class="form-check-input">Skip Parent's Unit No.
													</div>
												</div>
												<div id="input_unitNo">
													<div class="row form-group">
														<div class="col col-md-3">
															<label for="text-input" class=" form-control-label">Child's Unit No.</label>
														</div>
														<div class="col-12 col-md-6">
															<input type="text" name="child_unit_no[]"  id="child_unit_no" size="25" required="" class="form-control" placeholder="Please type child's unit no. " >
														</div>
														<div class="col col-md-3">
															<span class="help-block">
																<a href="#"  alt="Add More Unit No." onclick="addNewLinkAcc();" id="add"><i class="fas fa-plus-square" ></a></i>
															</span>
														</div>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Block</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="block"   class="form-control" placeholder="Please type block no. (optional)" value="<?php echo $_SESSION['block']?>" autocomplete="off" >
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Address Line 1</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="line1"  required="" class="form-control" placeholder=" P.O. Box/ Company Name/ Unit No" value="<?php echo $_SESSION['line1']?>" >
														<?php if($_SESSION['line1'] == ""){?>
														<span class="help-block">Please insert P.O. Box/ Company Name/ Unit No for Address Line 1. </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Address Line 2</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="line2"  required="" class="form-control" placeholder="Floor/Apartment/Building/Street Name" value="<?php echo $_SESSION['line2']?>" >
														<?php if($_SESSION['line2'] == ""){?>
														<span class="help-block">Please insert Floor/Apartment/Building/Street Name for Address Line 2. </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">City</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="city"  required="" class="form-control"  value="<?php echo $_SESSION['city']?>" >
														<?php if($_SESSION['city'] == ""){?>
														<span class="help-block">Please insert City name </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Postcode</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="postcode"  required="" class="form-control"  value="<?php echo $_SESSION['postcode']?>" >
														<?php if($_SESSION['postcode'] == ""){?>
														<span class="help-block">Please insert Postcode </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">State</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="state"  required="" class="form-control"  value="<?php echo $_SESSION['state']?>" >
														<?php if($_SESSION['state'] == ""){?>
														<span class="help-block">Please insert State </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Country</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="country"  required="" class="form-control"  value="<?php echo $_SESSION['country']?>" >
														<?php if($_SESSION['country'] == ""){?>
														<span class="help-block">Please insert Country </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Kedudukan Lot</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="kedudukan_lot"   class="form-control"  value="<?php echo $_SESSION['kedudukan_lot']?>" >
														<?php if($_SESSION['kedudukan_lot'] == ""){?>
														<span class="help-block">Please insert Kedudukan Lot </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Jenis Pemilikan</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="jenis_pemilikan"   class="form-control"  value="<?php echo $_SESSION['jenis_pemilikan']?>" >
														<?php if($_SESSION['jenis_pemilikan'] == ""){?>
														<span class="help-block">Please insert Jenis Pemilikan </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">No. Hak Milik</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="no_hakmilik"  class="form-control"  value="<?php echo $_SESSION['no_hakmilik']?>" >
														<?php if($_SESSION['no_hakmilik'] == ""){?>
														<span class="help-block">Please insert No. Hak Milik </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">No. Lot</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="no_lot"   class="form-control"  value="<?php echo $_SESSION['no_lot']?>" >
														<?php if($_SESSION['no_lot'] == ""){?>
														<span class="help-block">Please insert No. Lot </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Mukim</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="mukim"   class="form-control"  value="<?php echo $_SESSION['mukim']?>" >
														<?php if($_SESSION['mukim'] == ""){?>
														<span class="help-block">Please insert Mukim </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Daerah</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="text" name="daerah"   class="form-control"  value="<?php echo $_SESSION['daerah']?>" >
														<?php if($_SESSION['daerah'] == ""){?>
														<span class="help-block">Please insert Daerah </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Pegangan</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="radio" name="pegangan"   class="form-check-input" value="freehold" <?php echo $_SESSION['pegangan']== "freehold"?"checked":""?> onclick="freeholdClick()"  />Freehold (Pegangan Bebas)
														<br/>
														<input type="radio" name="pegangan"   class="form-check-input" value="leasehold" <?php echo $_SESSION['pegangan']== "leasehold"?"checked":""?> onclick="leaseholdClick()"  />Leasehold (Pajakan)
														
														<div id="leaseholdClick" style='display:none;font-size:12px'>
															<table style="border-collapse: collapse;border: 1px solid black;" id="dataLeasehold">
																<tr  style="border: 1px solid black;">
																	<th style="border: 1px solid black;">Tempoh Pajakan</th>
																	<th style="border: 1px solid black;">Tarikh Luput Pajakan</th>
																</tr>
																<tr>
																	<td><input type="text" class="form-control"  name="tempoh_pajakan"  size="10" value="<?php echo $_SESSION['tempoh_pajakan']?>"   placeholder="Jumlah Tahun" /> </td>
																	<td><input type="date"  class="form-control"  name="tarikh_luput_pajakan"  value="<?php echo $_SESSION['tarikh_luput_pajakan']?>"   /></td>
																</tr>
															</table>
														</div>
														<?php if($_SESSION['pegangan'] == ""){?>
														<br/><span class="help-block">Please insert Pegangan </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Tarikh Perjanjian Jual Beli</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="date" name="tarikh_perjanjian_jualbeli"   class="form-control"  value="<?php echo $_SESSION['tarikh_perjanjian_jualbeli']?>" >
														<?php if($_SESSION['tarikh_perjanjian_jualbeli'] == ""){?>
														<span class="help-block">Please insert Tarikh </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Luas Tanah (kp)</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="number" name="luas_tanah_kp"   class="form-control"  value="<?php echo $_SESSION['luas_tanah_kp']?>" >
														<?php if($_SESSION['luas_tanah_kp'] == ""){?>
														<span class="help-block">Please insert Tarikh </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Luas Lantai/Bangunan (kp)</label>
													</div>
													<div class="col-12 col-md-6">
														<input type="number" name="luas_lantai_kp"   class="form-control"  value="<?php echo $_SESSION['luas_lantai_kp']?>" >
														<?php if($_SESSION['luas_lantai_kp'] == ""){?>
														<span class="help-block">Please insert Luas Lantai/Bangunan (kp) </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Harga Belian (RM) </label>
													</div>
													<div class="col-12 col-md-6">
														<input type="number" name="harga_belian" step="0.01"  class="form-control"  value="<?php echo $_SESSION['harga_belian']?>" >
														<?php if($_SESSION['harga_belian'] == ""){?>
														<span class="help-block">Please insert Harga Belian (RM) </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="text-input" class=" form-control-label">Status Pindah Milik </label>
													</div>
													<div class="col-12 col-md-6">
														<input type="radio"  name="status_pindahmilik"  class="form-check-input" value="Selesai" <?php echo $_SESSION['status_pindahmilik']== "Selesai"?"checked":""?>  />Selesai
														<br/>
														<input type="radio"  name="status_pindahmilik"  class="form-check-input"  value="Belum dipindahmilik" <?php echo $_SESSION['status_pindahmilik']== "Belum dipindahmilik"?"checked":""?>  />Belum dipindahmilik
														<?php if($_SESSION['status_pindahmilik'] == ""){?>
														<br/><span class="help-block">Please insert Status Pindah Milik </span>
														<?php } ?>
													</div>
												</div>
												<div class="row form-group">
													<div class="col col-md-3">
														<label for="textarea-input" class=" form-control-label">Catatan</label>
													</div>
													<div class="col-12 col-md-9">
														<textarea name="catatan" id="textarea-input" rows="4" placeholder="Catatan..." class="form-control"></textarea>
														<span class="help-block"><i>(Optional) </i></span>
													</div>
												</div>
												<div class="row form-group" id="tambahCatatanClick" >
													<div class="col col-md-3">
														<label for="textarea-input" class=" form-control-label">Catatan Tambahan</label>
													</div>
													<div class="col-12 col-md-9">
														<textarea name="catatan_tambahan" id="textarea-input" rows="4" placeholder="Catatan Tambahan..." class="form-control"></textarea>
														<span class="help-block"><i>(Optional)</i> </span>
													</div>
												</div>
											
										</div>
										<div class="card-footer">
											<button type="submit" class="btn btn-primary btn-sm">
												<i class="fa fa-dot-circle-o"></i> Submit
											</button>
											<button type="reset" class="btn btn-danger btn-sm">
												<i class="fa fa-ban"></i> Reset
											</button>
										</div>
										</form>
									</div>
								</div>
                        </div>
            <!--main content middle end-->
			<!--main content bottom start-->
				<?PHP include "main-content-bottom.php";?>
			<!--main content bottom end-->
			
            <!-- END MAIN CONTENT-->
            <!-- END PAGE CONTAINER-->
        </div>
    </div>
    <?PHP include "footerLink.php";?>
</body>
</html>
<!-- end document-->
<script type="text/javascript">

function addNewLinkAcc(){
	//alert();
	var divWrap = document.createElement('div');
	var div1 = document.createElement('div');
	var div2 = document.createElement('div');
	var div3 = document.createElement('div');
    divWrap.className = 'row form-group';
    div1.className = 'col col-md-3';
    div2.className = 'col-12 col-md-6';
    div3.className = 'col col-md-3';
	divWrap.id = 'divRow';
	div3.id = 'deleteButton';
	
	var div1_html = "<label for='text-input' class='form-control-label'>&nbsp;</label>";
	var div2_html = "<input type='text' name='child_unit_no[]'  id='child_unit_no' size='25' required='Please type childs unit no.' class='form-control' placeholder='Please type childs unit no. '>";
	var div3_html = "<span class='help-block'><a href='#' id='del' onclick='deleteRow(this)'><i class='fas fa-minus-square' ></a></i></span>";
	
	div1.innerHTML = div1_html;
	div2.innerHTML = div2_html;
	div3.innerHTML = div3_html;
	
	divWrap.append(div1,div2,div3);
	document.getElementById("input_unitNo").appendChild(divWrap);	
	
}
function deleteRow(row){ 
	
	var x = document.querySelectorAll("#deleteButton");
	
	var remove = function(){
		this.parentNode.remove();
	};

	var button = document.querySelectorAll('#del');
	for (var i = 0, len = x.length; i < len; i++) {
		x[i].addEventListener('click', remove, false);
	}


}


document.getElementById("skipParentsUnit").onclick = function() {myFunction()};

function myFunction() {
	if(document.getElementById("propertiesParentsUnit_input").disabled === true){
		document.getElementById("propertiesParentsUnit_input").removeAttribute("disabled");
		document.getElementById("propertiesParentsUnit_input").setAttribute("required","required");
	}
	else{
		document.getElementById("propertiesParentsUnit_input").setAttribute("disabled","disabled");
		document.getElementById("propertiesParentsUnit_input").removeAttribute("required");
		
	}
		
}


function leaseholdClick(){
  document.getElementById('leaseholdClick').style.display ='block';
}
function freeholdClick(){
  document.getElementById('leaseholdClick').style.display ='none';
}
function tambahCatatanClick(){
  document.getElementById('tambahCatatanClick').style.display ='block';
}
</script>
<!-- end document-->
