<?php
include('dbconnect.php');
include('header.php');
?>

        <!-- ==================================================== -->
        <!-- 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">Teams</h4>
                            <ol class="breadcrumb mb-0">
                                <li class="breadcrumb-item"><a href="javascript: void(0);">Teams</a></li>
                                <li class="breadcrumb-item active">List</li>
                            </ol>
                        </div>
                    </div>
                </div>
                <!-- ========== Page Title End ========== -->
				
				<div class="row">
                         <div class="col-lg-12">
                              <div class="card">
                                   <div class="card-header border-0">
                                        <div class="row justify-content-between">
                                             <div class="col-lg-6">
                                                  <div class="row align-items-center">
                                                       <!--div class="col-lg-6">
                                                            <form class="app-search d-none d-md-block me-auto">
                                                                 <div class="position-relative">
                                                                      <input type="search" class="form-control" placeholder="Search Agent" autocomplete="off" value="">
                                                                      <iconify-icon icon="solar:magnifer-broken" class="search-widget-icon"></iconify-icon>
                                                                 </div>
                                                            </form>
                                                       </div-->
                                                       <!--div class="col-lg-4">
                                                            <h5 class="text-dark fw-medium mb-0">311 <span class="text-muted"> Agent</span></h5>
                                                       </div-->
                                                  </div>
                                             </div>
                                             <div class="col-lg-6">
                                                  <div class="text-md-end mt-3 mt-md-0">
                                                       <!--button type="button" class="btn btn-outline-primary me-1"><i class="ri-settings-2-line me-1"></i>More Setting</button-->
                                                       <!--button type="button" class="btn btn-outline-primary me-1"><i class="ri-filter-line me-1"></i> Filters</button-->
                                                       <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 Team</button>
										
                                                  </div>
                                             </div><!-- end col-->
                                        </div>
                                   </div>
                              </div>
                         </div>
                    </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">Add Teams</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="userForm" action="#" method="POST" onsubmit="return validateForm()">
								<div class="col-md-12">
									<label for="validationDefault01" class="form-label">Team 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">Select Team Lead</label>
									<select class="form-control" id="choices-single-no-sorting" name="choices-single-no-sorting" data-choices data-choices-sorting-false>
									<option value="">Select Team Lead</option>
										 <option value="Madrid">Varun - varun@vistaarr.com</option>
									</select>
								</div>
								<div class="col-md-12">
									<label for="choices-multiple-groups" class="form-label text-muted">Select Users</label>
									<select class="form-control" id="choices-multiple-remove-button" data-choices data-choices-removeItem name="choices-multiple-remove-button" multiple>
										 <option value="">Select Users</option>
										 <option value="Madrid">VARUN - varun@vistaarr.com</option>
										 <option value="Madrid">SAURABH KARLA - saurabh@vistaarr.com</option>
									</select>

								</div>
								<div class="col-md-12">
									<label for="blog-detail" class="form-label">Team Description</label>
                                                            <textarea class="form-control" id="blog-detail" rows="3" placeholder="Add Description"></textarea>
								</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">Confirm</button>
								</div>
							</form>
						</div>
					</div>

                <div class="row d-none">
                    <div class="col-xl-12">
                        <div class="card">
						
                            <div class="card-body">
                                <div>
                                    <div class="py-3">
                                        <div id="table-gridjs"></div>
                                    </div>
                                     
                                </div>
                            </div>
                        </div>


                    </div> <!-- end card body -->

                   


                </div> <!-- end row -->

            </div>
            <!-- End Container Fluid -->
<script>

$(document).ready(function() {
    if (document.getElementById("table-gridjs")) {
        new gridjs.Grid({
            columns: [{
                name: "S.No.",
                formatter: function(e) {
                    return gridjs.html('<span class="fw-semibold">' + e + "</span>")
                }
            }, "Name", {
                name: "Email",
                formatter: function(e) {
                    return gridjs.html('<a href="">' + e + "</a>")
                }
            }, "Mobile No", "Role", "Modified Date",
            {
                name:"Status",
                formatter: function(e) {
                    return gridjs.html('<span class="badge bg-success-subtle text-success py-1 px-2 fs-13">' + e + "</span>")
                }
            },                
            {
                name: "Actions",
                width: "120px",
                formatter: function(e) {
                    return gridjs.html('<li class="list-inline-item fs-20 dropdown d-none d-md-flex"><a href="javascript: void(0);" class="dropdown-toggle arrow-none text-dark show" data-bs-toggle="dropdown" aria-expanded="true"><i class="ri-more-2-fill"></i></a><div class="dropdown-menu dropdown-menu-end"><a class="dropdown-item" href="javascript: void(0);" data-bs-toggle="offcanvas" data-bs-target="#rightOffcanvas" aria-controls="rightOffcanvas">Reset Password</a><a class="dropdown-item" href="javascript: void(0);" data-bs-toggle="offcanvas" data-bs-target="#rightOffcanvas" aria-controls="rightOffcanvas">Edit User</a></div></li>')
                }
            }],
            pagination: {
                limit: 5
            },
            sort: true,
            search: true,
            server: {
                url: 'http://localhost/realState/crm/lahomes/admin/user-fetch-data.php',  // The PHP script that fetches data
                then: data => data,     // Process the fetched data
                // You can handle any other server-side processing here if necessary
            }
        }).render(document.getElementById("table-gridjs"));
    }
});
</script>	
<script>
        // JavaScript Validation Function
        function validateForm() {
            var name = document.forms["userForm"]["user_name"].value;
			var email = document.forms["userForm"]["user_email"].value;
            var mobile = document.forms["userForm"]["user_mobile"].value;
			var role = document.forms["userForm"]["user_role"].value;
            var errorMessage = "";

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

            // Check if the email is empty or invalid
            var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
            if (email == "") {
                errorMessage += "Email is required.\n";
            } else if (!emailPattern.test(email)) {
                errorMessage += "Invalid email format.\n";
            }
			
			// Check if the name is empty
            if (mobile == "") {
                errorMessage += "Mobile No. is required.\n";
            }
			
			// Check if the name is empty
            if (role == "") {
                errorMessage += "Role is required.\n";
            }

            // 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") {
    // Retrieve form data
	$action="<a href='javascript: void(0);' class='dropdown-toggle arrow-none text-dark' data-bs-toggle='dropdown' aria-expanded='false'>
	<i class='ri-more-2-fill'></i>
	 </a>
	 <div class='dropdown-menu dropdown-menu-end'>
		  <a class='dropdown-item' href='javascript: void(0);'><i class='ri-user-6-line me-2'></i>View Profile</a>
		  <a class='dropdown-item' href='javascript: void(0);'><i class='ri-music-2-line me-2'></i>Media, Links and Docs</a>
		  <a class='dropdown-item' href='javascript: void(0);'><i class='ri-search-2-line me-2'></i>Search</a>
		  <a class='dropdown-item' href='javascript: void(0);'><i class='ri-image-line me-2'></i>Wallpaper</a>
		  <a class='dropdown-item' href='javascript: void(0);'><i class='ri-arrow-right-circle-line me-2'></i>More</a>
	 </div>";
    
	$sql="insert into tbl_invite_user set name='".$_POST['user_name']."',email='".$_POST['user_email']."',
	mobile_no='".$_POST['user_mobile']."',role='".$_POST['user_role']."',cdate='".date('y-m-d h:i:s')."',flag=0,cuser='ADMIN',deleted_flag=0,status='ACTIVE'
	";
	$result=mysqli_query($conn,$sql);
	
	if($result==1){
		print("<script language='javascript'>alert('Requested Completed...');window.location.href='users-list.php'");
		exit;
	}
	else{
		print("<script language='javascript'>alert('Requested Incomplete Please Try Again!...');window.location.href='users-list.php'");
		exit;
	}
    
    
}

?>