<?php
    session_start();
    include "../../db.php";
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('jS  F Y');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {
        header("Location: logout.php");
        exit();
    }
    if ( $_SESSION['utype'] != 'master_admin' && $_SESSION['uref'] != 'fssdf4543frts' ) {
        header("Location: logout.php");
        exit();
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Admin Panel</title>

    <link href="css/all.min.css" rel="stylesheet" type="text/css">
    <link href="css/sb-admin-2.min.css" rel="stylesheet">
    <link href="css/alltable.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
</head>

<?php
                                if ( isset($_GET["visit_id"]) ) {
                                    $visit_run = mysqli_query($con, "SELECT * FROM users WHERE uid = '$_GET[visit_id]'");
                                    $visit_row = mysqli_fetch_assoc($visit_run);
								}
                                    ?>
<body id="page-top" class="mt-55">

<div class="overlay"></div>

    <div id="wrapper">

        <div id="content-wrapper" class="d-flex flex-column">

            <div id="content">

                                        
<nav class="navbar colgreen navbar-expand navbar-light bg-h topbar mb-2 static-top shadow fixed-top ">

<div class="col-md-6">
<span class="mr-2 colgreen d-n one d-lg-inl ine  ">   <font color="" size="5px">    <i class="fas fa-user fa-sm fa-fw  "></i> <?php echo $_SESSION["uname"] ?> </font></span>
</div>



                            
    <ul class="navbar-nav ml-auto">

        <li class="nav-item dropdown no-arrow">
            <a class="nav-link dropdown-toggle " href="#" id="userDropdown" role="button" data-toggle="dropdown"
                aria-haspopup="true" aria-expanded="false">
                 <font color="black" size="5px">  
             <i class="fas fa-bars fa-lg"></i> </font>
            </a>
            <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">
 <font color="red" >               
			  <a class="dropdown-item colgreen" href="index.php">
                    <i class="fas fa-tachometer-alt fa-sm fa-fw mr-2 colred "></i> 
                    Dashboard
                </a>
                <a class="dropdown-item colgreen" href="members.php?see_id=$rows[uid]">
                    <i class="fas fa-globe-asia fa-sm fa-fw mr-2 colred"></i>
                    Members
                </a>
                <a class="dropdown-item colgreen" href="category.php?see_id=$rows[uid]">
                    <i class="fas fa-shopping-bag  fa-sm fa-fw mr-2 colred"></i>
                    Category
                </a>
                <a class="dropdown-item colgreen" href="blog1.php?visit_id=<?php echo $visit_row["uid"]; ?>">
                    <i class="fas fa-user fa-sm fa-fw mr-2 colred"></i>
                    Blog
                </a>
                <a class="dropdown-item colgreen" href="profile.php">
                    <i class="fas fa-lock fa-sm fa-fw mr-2 colred"></i>
                    Profile
                </a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item colgreen" href="#logoutModal" data-toggle="modal">
                    <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 colred"></i>
                    Logout
                </a>
				
				</font>
            </div>
        </li>

    </ul>

</nav>





<a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
</a>





<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                <a class="btn btn-primary" href="logout.php">Logout</a>
            </div>
        </div>
    </div>
</div>

                <div class="container-fluid px-0">

                    <div class="card shadow mb-4">
                        <div class="card-body">

                        
                            <h1 class="h3 mb-2 text-gray-800 text-center text-sm-left">Organization Profile</h1>
                            <hr>

                            <?php
                                if ( isset($_GET["edit_id"]) ) {
                                    $edit_run = mysqli_query($con, "SELECT * FROM users WHERE uid = '$_GET[edit_id]'");
                                    $edit_row = mysqli_fetch_assoc($edit_run);
                                    ?>
                                    <form class="user" method="post" enctype="multipart/form-data">
                                        <h4 class="mb-3 badge badge-secondary">Edit Organization Profile</h4>
                                        <div class="form-group row">
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uname" placeholder="Name of Level 2 Admin *" name="uname" value="<?php echo $edit_row["uname"]; ?>" required>
                                            </div>
                                     
                                       
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uphone" placeholder="Mobile Number *" name="uphone" value="<?php echo $edit_row["uphone"]; ?>" required>
                                            </div>
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="password" class="form-control form-control-sm mb-2" id="upass" placeholder="Password *" name="upass" value="<?php echo $edit_row["upass"]; ?>" required>
                                            </div>
                                        </div>
										
										
										
                                       <div class="form-group row">
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="utypeorg" value="<?php echo $edit_row["utypeorg"]; ?>" placeholder="Type of Organization  " name="utypeorg" >
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uwhatsapp" value="<?php echo $edit_row["uwhatsapp"]; ?>" placeholder="WhatsApp No" name="uwhatsapp" >
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="umail" value="<?php echo $edit_row["umail"]; ?>" placeholder="Email Id" name="umail" >
                                            </div>
                                        </div>
										 <div class="form-group row">
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="weburl" value="<?php echo $edit_row["uweburl"]; ?>" placeholder="website url " name="uweburl" >
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="ufburl" value="<?php echo $edit_row["ufburl"]; ?>" placeholder="FB Page url" name="ufburl" >
                                            </div>
											<div class="col-sm-2 mb-1 mb-sm-0">
                                                <label>logo</label>
                        <input type="file" accept="image/*" class="form-control" name="ulogo" >    </div>
											<div class="col-sm-2 mb-1 mb-sm-0">
                                                 <label>Agreement</label>
                        <input type="file" accept="application/pdf,image/*" class="form-control" name="uagreement" >    </div>
                                        </div>
										 <div class="form-group row">
                                            <div class="col-sm-6 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uaddress1" value="<?php echo $edit_row["uaddress1"]; ?>" placeholder="Address 1 " name="uaddress1" >
                                            </div>
											<div class="col-sm-6 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uaddress2" value="<?php echo $edit_row["uaddress2"]; ?>" placeholder="Address 2" name="uaddress2" >
                                            </div>
											
											
                                        </div>
										
										
                                        <div class="form-group row">
                                            <div class="col-sm-12 mb-1 mb-sm-0">
	<textarea style="resize:vertical;min-height:100px;max-height:200px;" class="form-control" placeholder="Details " name="uabout" maxlength="20000">
						<?php echo $edit_row["uabout"]; ?></textarea>
   
  
	
                                            </div>
                                        </div>
                                        <button type="submit" class="btn btn-success btn-user m-2" name="edit_users">
                                            <i class="far fa-image"></i> Update Organization Profile
                                        </button>
                                        <a href="admin_lvl2.php" class="btn btn-warning btn-user m-2"> <i class="fas fa-ban"></i> Cancel </a>
                                    </form>
									 	
                                    <?php
                                } else {
                                    ?>
									
									  <?php
                                if ( isset($_GET["see_id"]) ) {
                                    $see_run = mysqli_query($con, "SELECT * FROM users WHERE uid = '$_GET[see_id]'");
                                    $see_row = mysqli_fetch_assoc($see_run);
                                    ?>
                                   
                                        <h4 class="mb-3 badge badge-secondary">see Organization Profile</h4>
                                        <div class="form-group row">
										<div class="col-sm-3 mb-1 mb-sm-0">
										</div>
                                            <div class="col-sm-6 mb-1 mb-sm-0">
											<img src="<?php echo $see_row["ulogo"]; ?>" alt="Smiley face" height="auto" width="100">
                                            <br> Name - <?php echo $see_row["uname"]; ?>
											 <br>
											 Main Mobile - <a href="tel:+91<?php echo $see_row["uphone"]; ?>"> <?php echo $see_row["uphone"]; ?></a>

											 <br>
											   Creat Date - <?php echo $see_row["ucreated"]; ?> <br>
											  About - <?php echo $see_row["uabout"]; ?> <br>
											Password-   <?php echo $see_row["upass"]; ?> <br>
											Type of Org -   <?php echo $see_row["utypeorg"]; ?> <br>
											WhatsApp  -   <a href="https://wa.me/91<?php echo $see_row["uwhatsapp"]; ?>" target="_blank" > <?php echo $see_row["uwhatsapp"]; ?></a>
											 <br>
											Email -  <?php echo $see_row["umail"]; ?> <br>
											Website -  <a  href="<?php echo $see_row["uweburl"]; ?>"  target="_blank"> <?php echo $see_row["uweburl"]; ?> </a><br>
											Fb URL  - <a  href="<?php echo $see_row["ufburl"]; ?>"  target="_blank">  <?php echo $see_row["ufburl"]; ?> </a><br>
											 Address - <?php echo $see_row["uaddress1"]; ?> <br>
											 Address-  <?php echo $see_row["uaddress2"]; ?> <br>
                                          <a  href="<?php echo $see_row["uagreement"]; ?>"  target="_blank"> Aggrement Copy</a><br>
                                     
                                       
                                        <a href="admin_lvl2.php" class="btn btn-warning btn-user m-2"> <i class="fas fa-ban"></i> Back </a>
                        
									
									  </div>
									</div>
									
									
                                    <?php
                                } else {
                                    ?>
                                    <form class="user" method="post" enctype="multipart/form-data">
                                        <h4 class="mb-3 badge badge-secondary">Add New Organization Profile</h4>
                                        <div class="form-group row">
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uname" placeholder="Name of Organization  *" name="uname" required>
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uphone" placeholder="Main Mobile Number*" name="uphone" required>
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="upass" placeholder="Password*" name="upass" required>
                                            </div>
                                        </div>
                                       <div class="form-group row">
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="utypeorg" placeholder="Type of Organization  " name="utypeorg" >
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uwhatsapp" placeholder="WhatsApp No" name="uwhatsapp" >
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="umail" placeholder="Email Id" name="umail" >
                                            </div>
                                        </div>
										 <div class="form-group row">
                                            <div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="weburl" placeholder="website url " name="uweburl" >
                                            </div>
											<div class="col-sm-4 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="ufburl" placeholder="FB Page url" name="ufburl" >
                                            </div>
											<div class="col-sm-2 mb-1 mb-sm-0">
                                                <label>logo</label>
                        <input type="file" accept="image/*" class="form-control" name="ulogo" >    </div>
											<div class="col-sm-2 mb-1 mb-sm-0">
                                                 <label>Agreement</label>
                        <input type="file" accept="application/pdf,image/*" class="form-control" name="uagreement" >    </div>
                                        </div>
										 <div class="form-group row">
                                            <div class="col-sm-6 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uaddress1" placeholder="Address 1 " name="uaddress1" >
                                            </div>
											<div class="col-sm-6 mb-1 mb-sm-0">
                                                <input type="text" class="form-control form-control-sm mb-2" id="uaddress2" placeholder="Address 2" name="uaddress2" >
                                            </div>
											
											
                                        </div>
										
                                        <div class="form-group row">
                                            <div class="col-sm-12 mb-1 mb-sm-0">
                 <textarea class="form-control form-control-sm mb-2 " id="uabout" placeholder="Basic Details about Organization  (optional)"
				 name="uabout" style="min-height:100px;"></textarea>
                                        
										 </div>
                                        </div>
                                        <button type="submit" class="btn btn-primary btn-user m-2" name="new_admin">
                                            <i class="far fa-image"></i> Add New Organization Profile
                                        </button>
                                    </form>
                                    <?php
                                }
								}
                            ?>

                            <hr>

                            <div class="row m-0">
                                <h4 class="mb-3 badge badge-secondary">Users</h4>

                                <div class="col-md-12 p-0">
                                    <div class="table-responsive">
                                        <table class="table table-hover table-bordered table-sm" id="thisismytable">
                                            <thead>
                                                <tr>
                                                    <th>No.</th>
                                                    <th>Name</th>
                                                 
                                                    <th>User</th>
                                            
                                                    <th>Action</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                    $sql = "SELECT * FROM users WHERE utype = 'basic_lvl_admin' ORDER BY uid DESC";
                                                    $run = mysqli_query($con, $sql);

                                                    $c = 1;
                                                    while ( $rows = mysqli_fetch_assoc($run) ) {
                                                        echo "
                                                        <tr>
                                                            <td>
                                                                <span class='badge badge-info badge-pill'>$rows[uid]</span>
                                                            </td>
                                                            <td>
                                                             <a href='admin_lvl21.php?visit_id=$rows[uid]' cla ss='m-2 btn btn-success btn-sm  title='Click to Edit'>     $rows[uname]  </a>
                                                            </td>
                                                          
                                                            <td class='align-middle'>
                                                                 <a href='tel:$rows[uphone]' class='small text-dark' title='Click here to Call'> <i class='fas fa-phone fa-rotate-90'></i> $rows[uphone] </a>
                                                                <p class='small text-dark mb-0'> <i class='fas fa-lock'></i> $rows[upass] </p>  </td>
                                                           
                                                            <td class='text-center align-middle'>
                                                                <a href='admin_lvl2.php?edit_id=$rows[uid]' class='m-2 btn btn-success btn-sm rounded-circle' title='Click to Edit'> <i class='fas fa-pencil-alt'></i> </a>

                                                                <a href='admin_lvl2.php?del_id=$rows[uid]' class='delete m-2 btn btn-danger btn-sm rounded-circle' title='Click to Delete'> <i class='fas fa-trash'></i> </a>
                                                            </td>
                                                        </tr>
                                                        ";
                                                        $c++;
                                                    }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

            <?php include "includes/footer.php"; ?>

        </div>

    </div>




   



    <script>
        function checkFileDetails() {
            var fi = document.getElementById('file');
            if (fi.files.length > 0) {
                for (var i = 0; i <= fi.files.length - 1; i++) {
                    var fileName, fileExtension, fileSize, fileType, dateModified;
                    fileName = fi.files.item(i).name;
                    fileExtension = fileName.replace(/^.*\./, '');
                    if (fileExtension == 'png' || fileExtension == 'jpg' || fileExtension == 'jpeg') {
                        readImageFile(fi.files.item(i));
                    }
                }
                function readImageFile(file) {
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        var img = new Image();
                        img.src = e.target.result;
                        img.onload = function () {
                            var imgWidth = this.width;
                            var imgHeight = this.height;

                            if ( imgWidth == 1200 && imgHeight == 512 || imgWidth == 1500 && imgHeight == 640 ) {
                                var imgCheck = "<i class='fas fa-check-circle text-success'></i>";
                            } else {
                                var imgCheck = "<i class='fas fa-times-circle text-danger'></i>";
                            }
                            document.getElementById('fileInfo').innerHTML =
                                document.getElementById('fileInfo').innerHTML + '<br> ' +
                                'Name: <b>' + file.name + '</b> <br>' +
                                'Size: <b>' + Math.round((file.size / 1024)) + '</b> KB <br>' +
                                'Dimension: <b>' + imgWidth + '</b> x <b>' + imgHeight + '</b> ' + imgCheck + ' <br>';
                        }
                    };
                    reader.readAsDataURL(file);
                }
            }
        }
    </script>




    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.easing.min.js"></script>
    <script src="js/sb-admin-2.min.js"></script>
    <script src="js/sweetalert2.min.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap4.min.js"></script>
    <script src="js/datatables.mark.min.js"></script>
    <script src="js/jquery-ui-custom.min.js"></script>
    <script src="js/custom.js"></script>
 <script src="vendor/ckeditor.js"></script>
    <script>
		$(document).ready(function(){
            $('#thisismytable').DataTable();
            $('#show-img').on('show.bs.modal', function (e) {
                var src = $(e.relatedTarget).attr('src');
                $(this).find('.modal-body > img').attr('src', src);
            });
		});

        var $sortable = $("#thisismytable > tbody");

        $sortable.sortable({
            stop: function ( event, ui ) {
                var parameters = $sortable.sortable( "toArray" );
                $.post("slider_position.php",{value:parameters},function(result){
                    $(document).ready(function() {
                        const Toast = Swal.mixin({
                            toast: true,
                            position: 'bottom',
                            showConfirmButton: false,
                            timer: 2000
                        });
                        Toast.fire({
                            type: 'success',
                            title: result
                        });
                    });
                });
            }
        });
	</script>
	

</body>
</html>


<?php

    if(isset($_POST['new_admin'])){
        $uname = mysqli_real_escape_string($con, strip_tags($_POST['uname']));
        $uphone = mysqli_real_escape_string($con, strip_tags($_POST['uphone']));
        $upass = mysqli_real_escape_string($con, strip_tags($_POST['upass']));
        $uabout = mysqli_real_escape_string($con, strip_tags($_POST['uabout']));
		 $utypeorg = mysqli_real_escape_string($con, strip_tags($_POST['utypeorg']));
		 $uwhatsapp = mysqli_real_escape_string($con, strip_tags($_POST['uwhatsapp']));
		 $umail = mysqli_real_escape_string($con, strip_tags($_POST['umail']));
		 $uweburl = mysqli_real_escape_string($con, strip_tags($_POST['uweburl']));
if( !empty($_FILES["ulogo"]["name"]) && isset($_FILES) ){

            $filetmp = $_FILES["ulogo"]["tmp_name"];
            $filename = $_FILES["ulogo"]["name"];
            $filetype = $_FILES["ulogo"]["type"];
            $fileerror = $_FILES["ulogo"]["error"];

            $filesize = $_FILES["ulogo"]["size"];

            $fileExt = explode('.', $filename);
            $fileActualExt = strtolower(end($fileExt));

            $fileNewName = time().".".$fileActualExt;

            $allowed = array('jpg', 'jpeg', 'pdf', 'png');

            if ( $filesize == 0 || $filesize > 1000000 ) {
                // echo "<pre>";print_r($filesize);exit();
                ?>
                <script>
                    alert("Max File Size 1 mb");
                    window.location = "admin_lvl2.php??edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                </script>
                <?php
            } else {
                if ( in_array($fileActualExt, $allowed) ) {

                    $ulogo_upl_path = "../upload/logo/".$fileNewName;

                    move_uploaded_file($filetmp, $ulogo_upl_path);
                }
                else {
                    ?>
                    <script>
                        alert("Upload PDF / JPG / JPEG / PNG Image");
                    window.location = "admin_lvl2.php?edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                    </script>
                    <?php
                }
            }
        }

  

  

   if( !empty($_FILES["uagreement"]["name"]) && isset($_FILES) ){

            $filetmp = $_FILES["uagreement"]["tmp_name"];
            $filename = $_FILES["uagreement"]["name"];
            $filetype = $_FILES["uagreement"]["type"];
            $fileerror = $_FILES["uagreement"]["error"];

            $filesize = $_FILES["uagreement"]["size"];

            $fileExt = explode('.', $filename);
            $fileActualExt = strtolower(end($fileExt));

            $fileNewName = time().".".$fileActualExt;

            $allowed = array('jpg', 'jpeg', 'pdf', 'png');

            if ( $filesize == 0 || $filesize > 1000000 ) {
                // echo "<pre>";print_r($filesize);exit();
                ?>
                <script>
                    alert("Max File Size 1 mb");
                    window.location = "admin_lvl2.php??edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                </script>
                <?php
            } else {
                if ( in_array($fileActualExt, $allowed) ) {

                    $uagreement_upl_path = "../upload/agreemenyt/".$fileNewName;

                    move_uploaded_file($filetmp, $uagreement_upl_path);
                }
                else {
                    ?>
                    <script>
                        alert("Upload PDF / JPG / JPEG / PNG Image");
                    window.location = "admin_lvl2.php?edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                    </script>
                    <?php
                }
            }
        }

  

		
		 $uaddress1 = mysqli_real_escape_string($con, strip_tags($_POST['uaddress1']));
		 $uaddress2 = mysqli_real_escape_string($con, strip_tags($_POST['uaddress2']));

        $chk_ph = mysqli_query($con, "SELECT uphone FROM users WHERE uphone = '$uphone'");
        $chk_ph_count = mysqli_num_rows($chk_ph);
        if ( $chk_ph_count < 1 ) {
            $uref = rand().'_'.time();

            $ins_sql = "INSERT INTO users (uname, uphone, upass, uref, utype, uabout,utypeorg,uwhatsapp,umail,uweburl,ufburl,ulogo,uagreement,uaddress1,uaddress2, ucreated) VALUES ('$uname', '$uphone', '$upass', '$uref', 'basic_lvl_admin', '$uabout','$utypeorg','$uwhatsapp','$umail','$uweburl','$ufburl','$ulogo_upl_path','$uagreement_upl_path','$uaddress1','$uaddress2', '$currentTime')";

            if(mysqli_query($con, $ins_sql)){
                ?>
                <script>window.location = 'admin_lvl2.php';</script>
                <?php
            }
            else{
                ?>
                <script>
                    alert('OOPS !!!!');
                    setTimeout(() => {
                        window.location = 'admin_lvl2.php';
                    }, 1200);
                </script>
                <?php
            }
        } else {
            ?>
            <script>
                alert('Mobile Number Exists');
                setTimeout(() => {
                    window.location = 'admin_lvl2.php';
                }, 500);
            </script>
            <?php
        }
    }




    if ( isset($_GET["del_id"]) ) {

        $del_sql = "DELETE FROM users WHERE uid = '$_GET[del_id]'";

        if ( mysqli_query($con, $del_sql) ) {
            ?>
            <script>window.location = "admin_lvl2.php";</script>
            <?php
        } else {
            ?>
            <script>
                alert('OOPS !!!!');
                setTimeout(() => {
                    window.location = 'admin_lvl2.php';
                }, 1200);
            </script>
            <?php
        }
        
    }





    if(isset($_POST['edit_users'])){
        $uname = mysqli_real_escape_string($con, strip_tags($_POST['uname']));
        $uphone = mysqli_real_escape_string($con, strip_tags($_POST['uphone']));
        $upass = mysqli_real_escape_string($con, strip_tags($_POST['upass']));
        $uabout = mysqli_real_escape_string($con, strip_tags($_POST['uabout']));
		$utypeorg = mysqli_real_escape_string($con, strip_tags($_POST['utypeorg']));
		 $uwhatsapp = mysqli_real_escape_string($con, strip_tags($_POST['uwhatsapp']));
		 $umail = mysqli_real_escape_string($con, strip_tags($_POST['umail']));
		 $uweburl = mysqli_real_escape_string($con, strip_tags($_POST['uweburl']));
		 $ufburl = mysqli_real_escape_string($con, strip_tags($_POST['ufburl']));
  if( !empty($_FILES["ulogo"]["name"]) && isset($_FILES) ){

            $filetmp = $_FILES["ulogo"]["tmp_name"];
            $filename = $_FILES["ulogo"]["name"];
            $filetype = $_FILES["ulogo"]["type"];
            $fileerror = $_FILES["ulogo"]["error"];

            $filesize = $_FILES["ulogo"]["size"];

            $fileExt = explode('.', $filename);
            $fileActualExt = strtolower(end($fileExt));

            $fileNewName = time().".".$fileActualExt;

            $allowed = array('jpg', 'jpeg', 'pdf', 'png');

            if ( $filesize == 0 || $filesize > 1000000 ) {
                ?>
                <script>
                    alert("Max File Size 1 mb");
                    window.location = "admin_lvl2.php?edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                </script>
                <?php
            } else {
                if ( in_array($fileActualExt, $allowed) ) {

                    $ulogo_upl_path = "../upload/logo/".$fileNewName;

                    move_uploaded_file($filetmp, $ulogo_upl_path);

                    // $edit_sql = "UPDATE notice SET ulogo = '$ulogo_upl_path', nupdatedon = '$nupdatedon'";
                }
                else {
                    ?>
                    <script>
                        alert("Upload PDF / JPG / JPEG / PNG Image");
                        window.location = "admin_lvl2.php?edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                    </script>
                    <?php
                }
            }
        }



  if( !empty($_FILES["uagreement"]["name"]) && isset($_FILES) ){

            $filetmp = $_FILES["uagreement"]["tmp_name"];
            $filename = $_FILES["uagreement"]["name"];
            $filetype = $_FILES["uagreement"]["type"];
            $fileerror = $_FILES["uagreement"]["error"];

            $filesize = $_FILES["uagreement"]["size"];

            $fileExt = explode('.', $filename);
            $fileActualExt = strtolower(end($fileExt));

            $fileNewName = time().".".$fileActualExt;

            $allowed = array('jpg', 'jpeg', 'pdf', 'png');

            if ( $filesize == 0 || $filesize > 1000000 ) {
                ?>
                <script>
                    alert("Max File Size 1 mb");
                    window.location = "admin_lvl2.php?edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                </script>
                <?php
            } else {
                if ( in_array($fileActualExt, $allowed) ) {

                    $uagreement_upl_path = "../upload/agreemenyt/".$fileNewName;

                    move_uploaded_file($filetmp, $uagreement_upl_path);

                    // $edit_sql = "UPDATE notice SET ulogo = '$ulogo_upl_path', nupdatedon = '$nupdatedon'";
                }
                else {
                    ?>
                    <script>
                        alert("Upload PDF / JPG / JPEG / PNG Image");
                        window.location = "admin_lvl2.php?edit_id=<?php echo $idd; ?>&userref=<?php echo $refref; ?>";
                    </script>
                    <?php
                }
            }
        }
		 $uaddress1 = mysqli_real_escape_string($con, strip_tags($_POST['uaddress1']));
		 $uaddress2 = mysqli_real_escape_string($con, strip_tags($_POST['uaddress2']));
        $chk_ph = mysqli_query($con, "SELECT uphone FROM users WHERE uname != '$uname' AND uphone = '$uphone'");
        $chk_ph_count = mysqli_num_rows($chk_ph);
        if ( $chk_ph_count < 1 ) {
            $up_sql = "UPDATE users SET uname = '$uname', uphone = '$uphone', upass = '$upass',utypeorg = '$utypeorg',uwhatsapp = '$uwhatsapp',umail = '$umail',uweburl = '$uweburl',ufburl = '$ufburl',uaddress1 = '$uaddress1',uaddress2 = '$uaddress2', uabout = '$uabout' ";
   
  if(!empty($_FILES["ulogo"]["name"])){
            $up_sql .=", ulogo='$ulogo_upl_path'";
        }
if(!empty($_FILES["uagreement"]["name"])){
            $up_sql .=", uagreement='$uagreement_upl_path'";
        }
        $up_sql .= " WHERE uid = '$_GET[edit_id]'";
		 if(mysqli_query($con, $up_sql)){

       
            ?>
            <script>
                alert("Data Updated Successfully");
                window.location = 'admin_lvl2.php';
            </script>

        
               
                <?php
            }
            else{
                ?>
                <script>
                    alert('OOPS !!!!');
                    setTimeout(() => {
                        window.location = 'admin_lvl2.php';
                    }, 1200);
                </script>
                <?php
            }
        } else {
            ?>
            <script>
                alert('Mobile Number Exists');
                setTimeout(() => {
                    window.location = 'admin_lvl2.php?edit_id=<?php echo $_GET["edit_id"]; ?>';
                }, 500);
            </script>
			
			
            <?php
        }
    }

?>