<?php
include('header.php');
include('dbconnect.php');
?>
<style>
/* Make the main dropdown open on hover */
.dropdown:hover .dropdown-menu {
    display: block;
}

/* Ensure sub-dropdown opens on hover */
.dropdown-menu .dropdown-submenu:hover .dropdown-menu {
    display: block;
}

/* Hide dropdown menus initially */
.dropdown-menu {
    display: none;
    position: absolute;
    z-index: 1000;
}

/* Positioning for the sub-dropdown */
.dropdown-submenu .dropdown-menu {
    left: 100%;
    top: 0;
}

/* Make sub-menu hidden by default */
.dropdown-menu .dropdown-menu {
    display: none;
    position: absolute;
    left: 100%; /* Position the sub-menu to the right of the parent item */
    top: 0;
}

/* Display the sub-menu when hovering over the "Residential" item */
.dropdown-item:hover > .dropdown-menu {
    display: block;
}

/* Optional: Style adjustments for sub-menu */
.dropdown-item .dropdown-menu .dropdown-item {
    padding: 10px;
    background-color: #f8f9fa;
}


</style>
          <!-- ==================================================== -->
          <!-- Start right Content here -->
          <!-- ==================================================== -->
          <div class="page-content">

               <!-- Start Container Fluid -->
               <div class="container-fluid">

                    <!-- ========== Page Title Start ========== -->
                    <div class="row">
                        <div class="col-12">
                            <div class="page-title-box">
                                <h4 class="mb-0 fw-semibold">Project Add</h4>
								<div class="dropdown d-none">
									<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
										Select Project Type
									</button>
									<div class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
										<a class="dropdown-item" href="#">Residential
											<div class="dropdown-menu">
												<a class="dropdown-item" href="#">Sale</a>
												<a class="dropdown-item" href="#">Rent</a>
											</div>
										</a>
										<a class="dropdown-item" href="#">Commercial</a>
									</div>
								</div>
                                <ol class="breadcrumb mb-0">
                                    <li class="breadcrumb-item"><a href="javascript: void(0);">Projects</a></li>
                                    <li class="breadcrumb-item active">Project Add</li>
                                </ol>
                            </div>
							
							
                        </div>
                    </div>
                    <!-- ========== Page Title End ========== -->

                    <div class="row">
                        <ul class="nav nav-tabs">
							<li class="nav-item">
								<a href="#home" data-bs-toggle="tab" aria-expanded="false" class="nav-link active">
									<span class="d-block d-sm-none"><i class="bx bx-home"></i></span>
									<span class="d-none d-sm-block">Basic Details</span>
								</a>
							</li>
							<li class="nav-item">
								<a href="#profile" data-bs-toggle="tab" aria-expanded="true" class="nav-link ">
									<span class="d-block d-sm-none"><i class="bx bx-user"></i></span>
									<span class="d-none d-sm-block">Media Upload</span>
								</a>
							</li>
							<li class="nav-item">
								<a href="#messages" data-bs-toggle="tab" aria-expanded="false" class="nav-link">
									<span class="d-block d-sm-none"><i class="ri-mail-line"></i></span>
									<span class="d-none d-sm-block">Additional Info</span>
								</a>
							</li>
						</ul>
<form name="projectForm" action="#" method="POST" onsubmit="return validateForm()" enctype="multipart/form-data">
<div class="tab-content text-muted">
    <div class="tab-pane show active" id="home">
        <div class="col-xl-12 col-lg-12 ">
                            
                              <div class="card">
                                   <div class="card-header d-flex justify-content-between align-items-center">
                                        <h4 class="card-title">Project Details</h4>
										<button class="btn btn-primary" type="submit">Create Project</button>
                                   </div>
                                   <div class="card-body">
                                        <div class="row">
                                             <div class="col-lg-4">
                                                 
                                                       <div class="mb-3">
                                                            <label for="customer-name" class="form-label">Project/Property Name</label>
                                                            <input type="text" id="project-name" name="project-name" class="form-control" placeholder="e.g. DLF Property">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">Developer Name</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="V-Buzz Infra">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                                  <div class="mb-3">
                                                      
                                                            <label for="choices-country" class="form-label">Inventory Type</label>
                                                            <select class="form-control" id="choices-country" data-choices data-choices-groups data-placeholder="Select Country" name="choices-country">
                                                                 <option value="">Select Inventory Type</option>
                                                                 <optgroup label="">
                                                                      <option value="">New Launch</option>
                                                                      <option value="Fran">Sustenance</option>
                                                                      <option value="Netherlands">Resale</option>
                                                                 </optgroup>
                                                            </select>
                                                     
                                                  </div>
                                             </div>
                                             <div class="col-lg-4">
                                                  <div class="mb-3">
                                                   
                                                            <label for="choices-country" class="form-label">Possession Type</label>
                                                            <select class="form-control" id="choices-country" data-choices data-choices-groups data-placeholder="Select Country" name="choices-country">
                                                                 <option value="">Select Possession Type</option>
                                                                 <optgroup label="">
                                                                      <option value="">Under Construction</option>
                                                                      <option value="Fran">Ready to move in</option>
                                                                 </optgroup>
                                                            </select>
                                                       
                                                  </div>
                                             </div>
                                             
                                <div class="col-md-12">
								<label for="project_user" class="form-label">Responsible Person</label>
									<select class="form-control" id="choices-multiple-remove-button" data-choices data-choices-removeItem name="project_user[]" multiple>
										 <option value="" >Select Person</option>
										 <?php
										 $sql=mysqli_query($conn,"Select id,name from tbl_invite_user where 1 and flag=0");
										 while($row = mysqli_fetch_array($sql)){
										 ?>
										 <option value="<?=$row['id'];?>"><?=$row['name'];?></option>
										 <?php 
										 }
										 ?>
									</select>
								</div>
                                            
                                        </div>
                                   </div>
								   <div class="card-header">
                                        <h4 class="card-title">Location</h4>
                                   </div>
								   <div class="card-body">
                                        <div class="row">
                                             <div class="col-lg-4">
                                                 
                                                       <div class="mb-3">
                                                            <label for="customer-name" class="form-label">Full Address</label>
                                                            <input type="text" id="project-address" name="project-address" class="form-control" placeholder="e.g. Orchid Island">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                                  <div class="mb-3">
                                                      
                                                            <label for="choices-city" class="form-label">City</label>
                                                            <select class="form-control" id="project-city" name="project-city" data-choices data-choices-groups data-placeholder="Select City" name="choices-city">
                                                                 <option value="">Select City</option>
										 <?php
										 $sql=mysqli_query($conn,"Select tbl_city_id,tbl_city_name from tbl_city where 1 and tbl_city_flag=0");
										 while($row = mysqli_fetch_array($sql)){
										 ?>
										 <option value="<?=$row['tbl_city_id'];?>"><?=$row['tbl_city_name'];?></option>
										 <?php 
										 }
										 ?>
									</select>
                                                              
                                                                 
                                                            </select>

                                                  </div>
                                             </div>
											 <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">Nearby Landmark</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="Enter Landmark">
                                                       </div>

                                             </div>
											 <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">Enter Display Address</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="Enter Display Address">
                                                       </div>

                                             </div>
											 <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">Enter RERA Number</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="Enter RERA Number">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                                  <div class="mb-3">
                                                      
                                                            <label for="choices-country" class="form-label">Project Size</label>
															<input type="text" id="customer-email" class="form-control" placeholder="e.g. 1500">
                                                            <select class="form-control" id="choices-country" data-choices data-choices-groups data-placeholder="e.g. 1500" name="choices-country">
                                                                 <option value="">Select Size</option>
                                                                 <optgroup label="">
                                                                      <option value="">Acres</option>
                                                                      <option value="Fran">Sq. Feet</option>
                                                                      <option value="Netherlands">Sq. Yard</option>
                                                                 </optgroup>
                                                            </select>
                                                     
                                                  </div>
                                             </div>
                                            
											<div class="col-lg-12">
                                                  <div class="mb-3">
                                                       
                                                       <button type="button" class="btn btn-success me-1" data-bs-toggle="offcanvas" data-bs-target="#rightOffcanvas" aria-controls="rightOffcanvas"><i class="ri-add-line"></i> Add Amenities</button>
										
                                                  </div>
                                             </div><!-- end col-->
                                            
                                        </div>
                                   </div>
								   <div class="card-header">
                                        <h4 class="card-title">Other Project Info</h4>
                                   </div>
								   <div class="card-body">
                                        <div class="row">
                                              <div class="col-lg-12">
                                                  
                                                       <div class="mb-3">
                                                            <label for="customer-address" class="form-label">Project Description</label>
                                                            <textarea class="form-control" id="customer-address" rows="3" placeholder="Add Short Description"></textarea>
                                                       </div>
                                                  
                                             </div>
                                              <div class="col-lg-12">
                                                  
                                                       <div class="mb-3">
                                                            <label for="customer-address" class="form-label">Comments</label>
                                                            <textarea class="form-control" id="customer-address" rows="3" placeholder="Add Remarks"></textarea>
                                                       </div>
                                                  
                                             </div>
                                             
                                        </div>
                                   </div>
                              </div>

                              <!--div class="mb-3 rounded">
                                   <div class="row justify-content-end g-2">
                                        <div class="col-lg-2">
                                             <a href="#!" class="btn btn-outline-primary w-100">Create Customer</a>
                                        </div>
                                        <div class="col-lg-2">
                                             <a href="#!" class="btn btn-danger w-100">Cancel</a>
                                        </div>
                                   </div>
                              </div-->
                         </div>
    </div>
    <div class="tab-pane" id="profile">
        <div class="card">
                                   <!-- <div class="card-header">
                                        <h4 class="card-title">Add Property Photo</h4>
                                   </div> -->
                                   <div class="card-body">
                                        <div class="dropzone bg-light-subtle py-5" id="myAwesomeDropzone" data-plugin="dropzone" data-previews-container="#file-previews" data-upload-preview-template="#uploadPreviewTemplate">
                                             <div class="fallback">
                                                  <input name="project-file" id="project-file" type="file" multiple="multiple">
                                             </div>
                                             <div class="dz-message needsclick">
                                                  <i class="ri-upload-cloud-2-line fs-48 text-primary"></i>
                                                  <h3 class="mt-4">Drop your projects media here, or <span class="text-primary">click to browse</span></h3>
                                                  <span class="text-muted fs-13">
                                                       1600 x 1200 (4:3) recommended. PNG, JPG and GIF files are allowed
                                                  </span>
                                             </div>
                                        </div>


                                        <ul class="list-unstyled mb-0" id="dropzone-preview">
                                             <li class="mt-2" id="dropzone-preview-list">
                                                  <!-- This is used as the file preview template -->
                                                  <div class="border rounded">
                                                       <div class="d-flex p-2">
                                                            <div class="flex-shrink-0 me-3">
                                                                 <div class="avatar-sm bg-light rounded">
                                                                      <img data-dz-thumbnail class="img-fluid rounded d-block" src="#" alt="Dropzone-Image" />
                                                                 </div>
                                                            </div>
                                                            <div class="flex-grow-1">
                                                                 <div class="pt-1">
                                                                      <h5 class="fs-14 mb-1" data-dz-name>&</h5>
                                                                      <p class="fs-13 text-muted mb-0" data-dz-size></p>
                                                                      <strong class="error text-danger" data-dz-errormessage></strong>
                                                                 </div>
                                                            </div>
                                                            <div class="flex-shrink-0 ms-3">
                                                                 <button data-dz-remove class="btn btn-sm btn-danger">Delete</button>
                                                            </div>
                                                       </div>
                                                  </div>
                                             </li>
                                        </ul>
                                        <!-- end dropzon-preview -->
                                   </div>
                              </div>
    </div>
    <div class="tab-pane" id="messages">
        <div class="col-xl-12 col-lg-12 ">
                            
                              <div class="card">
                                   <div class="card-header d-flex justify-content-between align-items-center">
                                        <h4 class="card-title">Project Details</h4>
										<!--button class="btn btn-primary" type="submit">Create Project</button-->
                                   </div>
								   
                                   <div class="card-body">
                                        <div class="row">
                                             <div class="col-lg-4">
                                                 
                                                       <div class="mb-3">
                                                            <label for="customer-name" class="form-label">Allotment date</label>
                                                            <input type="text" id="basic-datepicker-start" class="form-control" placeholder="Select Allotment Date">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">No. Of Towers</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="e.g. 10">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                                  <div class="mb-3">
                                                      
                                                            <label for="choices-country" class="form-label">Tower Height</label>
															<input type="text" id="customer-email" class="form-control" placeholder="e.g. 100">
                                                            <select class="form-control" id="choices-country" data-choices data-choices-groups data-placeholder="Select Country" name="choices-country">
                                                                 <option value="">Choose Value</option>
                                                                 <optgroup label="">
                                                                      <option value="">Feet</option>
                                                                      <option value="Fran">Meters</option>
                                                                      <option value="Netherlands">Floors</option>
                                                                 </optgroup>
                                                            </select>
                                                     
                                                  </div>
                                             </div>
                                             
                                        </div>
                                   </div>
								   
								   <div class="card-body">
								   <div class="d-grid gap-2">
										<button type="button" class="btn btn-light btn-sm"><i class="ri-add-line"></i>Add Payment Plan</button>
									</div>
								   </div>
								   <div class="card-body">
								   <div class="d-grid gap-2">
										<button type="button" class="btn btn-light btn-sm"><i class="ri-add-line"></i>Add Bank Details</button>
									</div>
								   </div>
								   <div class="card-body">
								   <div class="d-grid gap-2">
										<button type="button" class="btn btn-light btn-sm"><i class="ri-add-line"></i>Add Nearby Landmark</button>
									</div>
								   </div>
								   
								   <div class="card-header">
                                        <h4 class="card-title">Location</h4>
                                   </div>
								   <div class="card-body">
                                        <div class="row">
                                             <div class="col-lg-4">
                                                 
                                                       <div class="mb-3">
                                                            <label for="customer-name" class="form-label">Full Address</label>
                                                            <input type="text" id="customer-name" class="form-control" placeholder="e.g. Orchid Island">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                                  <div class="mb-3">
                                                       
                                                            <label for="choices-city" class="form-label">City</label>
                                                            <select class="form-control" id="choices-city" data-choices data-choices-groups data-placeholder="Select City" name="choices-city">
                                                                 <option value="">Select city</option>
                                                                 <optgroup label="NCR">
                                                                      <option value="London">Delhi</option>
                                                                      <option value="Manchester">Gurgaon</option>
                                                                      <option value="Liverpool">Noida</option>
																	  <option value="Liverpool">Greater Noida</option>
                                                                 </optgroup>
                                                                 
                                                            </select>

                                                  </div>
                                             </div>
											 <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">Nearby Landmark</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="Enter Landmark">
                                                       </div>

                                             </div>
											 <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">Enter Display Address</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="Enter Display Address">
                                                       </div>

                                             </div>
											 <div class="col-lg-4">
                                               
                                                       <div class="mb-3">
                                                            <label for="customer-email" class="form-label">Enter RERA Number</label>
                                                            <input type="text" id="customer-email" class="form-control" placeholder="Enter RERA Number">
                                                       </div>

                                             </div>
                                             <div class="col-lg-4">
                                                  <div class="mb-3">
                                                      
                                                            <label for="choices-country" class="form-label">Project Size</label>
															<input type="text" id="customer-email" class="form-control" placeholder="e.g. 1500">
                                                            <select class="form-control" id="choices-country" data-choices data-choices-groups data-placeholder="e.g. 1500" name="choices-country">
                                                                 <option value="">Select Size</option>
                                                                 <optgroup label="">
                                                                      <option value="">Acres</option>
                                                                      <option value="Fran">Sq. Feet</option>
                                                                      <option value="Netherlands">Sq. Yard</option>
                                                                 </optgroup>
                                                            </select>
                                                     
                                                  </div>
                                             </div>
                                            
											<div class="col-lg-12">
                                                  <div class="mb-3">
                                                       
                                                       <button type="button" class="btn btn-success me-1" data-bs-toggle="offcanvas" data-bs-target="#rightOffcanvas" aria-controls="rightOffcanvas"><i class="ri-add-line"></i> Add Amenities</button>
										
                                                  </div>
                                             </div><!-- end col-->
                                            
                                        </div>
                                   </div>
								   <div class="card-header">
                                        <h4 class="card-title">Other Project Info</h4>
                                   </div>
								   <div class="card-body">
                                        <div class="row">
                                              <div class="col-lg-12">
                                                 
                                                       <div class="mb-3">
                                                            <label for="customer-address" class="form-label">Project Description</label>
                                                            <textarea class="form-control" id="customer-address" rows="3" placeholder="Add Short Description"></textarea>
                                                       </div>

                                             </div>
                                              <div class="col-lg-12">

                                                       <div class="mb-3">
                                                            <label for="customer-address" class="form-label">Comments</label>
                                                            <textarea class="form-control" id="customer-address" rows="3" placeholder="Add Remarks"></textarea>
                                                       </div>
                                                 
                                             </div>
                                             
                                        </div>
                                   </div>
								   <div class="mb-3 rounded">
                                   <div class="row justify-content-end g-2">
                                        <!--div class="col-lg-2">
                                             <a href="#!" class="btn btn-outline-primary w-100">Create Project</a>
                                        </div-->
                                        <!--div class="col-lg-2">
                                             <a href="#!" class="btn btn-danger w-100">Cancel</a>
                                        </div-->
                                   </div>
                              </div>
                              </div>

                              
                         </div>
    </div>
</div> 
</form>
                         
                    </div>
					
					<!-- right offcanvas -->
					<div class="offcanvas offcanvas-end" tabindex="-1" id="rightOffcanvas" aria-labelledby="rightOffcanvasLabel">
						<div class="offcanvas-header">
							<h4 class="offcanvas-title mt-0" id="rightOffcanvasLabel">Invite User</h4>
							<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
						</div>
						<div class="offcanvas-body">
							<form class="row g-3" name="" action="#" method="POST">
								<div class="col-md-12">
									<label for="validationDefault01" class="form-label">User name</label>
									<input type="text" class="form-control" name="user_name" id="validationDefault01" value="Enter User Name">
								</div>
								<div class="col-md-12">
									<label for="validationDefault02" class="form-label">Mobile No.</label>
									<input type="text" class="form-control" name="user_mobile" id="validationDefault02" value="" >
								</div>
								<div class="col-md-12">
									<label for="validationDefault02" class="form-label">Email</label>
									<input type="text" class="form-control" name="user_email" id="validationDefault02" value="" >
								</div>
								<div class="col-md-12">
									<label for="validationDefault04" class="form-label">Role</label>
									<select class="form-select" name="user_role" id="validationDefault04">
										<option selected disabled value="">Choose...</option>
										<option value="ADMIN">ADMIN</option>
										<option value="STANDARD">STANDARD</option>
									</select>
								</div><br><br><br><br><br>
								<div class="col-md-6">
									<button type="button" class="btn btn-primary" data-bs-dismiss="offcanvas" >Cancel</button>
								</div>
								<div class="col-md-6">
									<button class="btn btn-primary" type="submit">Invite User</button>
								</div>
							</form>
						</div>
					</div>
					

               </div>
<script>
        // JavaScript Validation Function
        function validateForm() {
			
            var pname = document.forms["projectForm"]["project-name"].value;
            var rPerson = document.forms["projectForm"]["project_user[]"].value;
			var padd = document.forms["projectForm"]["project-address"].value;
            var pcity = document.forms["projectForm"]["project-city"].value;
            //var rPerson 
            
            var errorMessage = "";

            // Check if the name is empty
            if (pname == "") {
                errorMessage += "Project Name is required.\n";
            }

            if (padd == "") {
                errorMessage += "Project Address is required.\n";
            }
			
            if (pcity == "") {
                errorMessage += "Project City is required.\n";
            }
            if (rPerson == "") {
                errorMessage += "Responsible Person is required.\n";
            }
			/*var files = $('#project-file')[0].files;
			 if(files.length > 0){
				errorMessage += "Project Image is required.\n";
			}
			if ($('#project-file').val() != "") {
				var fi = document.getElementById('project-file');
				var fsize = fi.files.item(0).size;
				if (fsize > 1048576) {
					errorMessage += "System allow Certificate scan copy file size maximum 1 MB only.";
				}
			} */

            // If there is any error, display it and prevent form submission
            if (errorMessage != "") {
                alert(errorMessage);
                return false; // prevent form submission
            }
            return true; // form is valid
        }
    </script>
<?php
include('footer.php');
?>

 <?php
 
 
// Check if the form is submitted

if ($_SERVER["REQUEST_METHOD"] == "POST") {
	$project_count=mysqli_num_rows(mysqli_query($conn,"Select tbl_project_id from tbl_project"));
	if($project_count> 0 ){
		$project_code='PRJ000'.$project_count+1;
	}else{
		$project_code='PRJ0001';
	}
	
	$api_url="https://crm.vistaarr.com/admin/api.php?pcode=".$project_code;
	$sql="insert into tbl_project set tbl_project_name='".$_POST['project-name']."',tbl_project_code='".$project_code."',
	tbl_project_location='".$_POST['project-city']."',tbl_project_address='".$_POST['project-address']."',tbl_project_api_url='".$api_url."',tbl_project_cdate='".date('y-m-d h:i:s')."',tbl_project_cuser='ADMIN'";
	
	$result=mysqli_query($conn,$sql);
	$project_id=$conn->insert_id;
	if($result==1){
	    if (isset($_POST['project_user']) && is_array($_POST['project_user'])) {
            $user_ids = $_POST['project_user'];
            // Insert selected projects into database
            foreach ($user_ids as $user_id) {
                $sql = "INSERT INTO tbl_lead_user_access_projects (tbl_lead_user_access_projects_user_id, tbl_lead_user_access_projects_project_id) VALUES ('$user_id', '$project_id')";
                mysqli_query($conn, $sql);
            }
            
	    }
		  echo "<script language='javascript'>
            Swal.fire({
				title: 'Success!',
				text: 'Your request has been completed.',
				icon: 'success',
				confirmButtonClass: 'btn btn-primary w-xs mt-2',
				buttonsStyling: false,
				showCloseButton: false
			}).then(function() {
				window.location.href = 'projects-list.php';
			});
          </script>";
		  exit;   
	}
	else{
		  echo "<script language='javascript'>
            Swal.fire({
				title: 'Oops...!',
				text: 'Requested Incomplete Please Try Again!...',
				icon: 'error',
				confirmButtonClass: 'btn btn-primary w-xs mt-2',
				buttonsStyling: false,
				showCloseButton: false
			}).then(function() {
				window.location.href = 'projects-list.php';
			});
          </script>";
		  exit; 
	} 
    
    
}
?>