<?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>

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

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

    <link href="css/all.min.css" rel="stylesheet" type="text/css">

    <link href="css/alltable.css" rel="stylesheet">

    <style>
    .colgreen {
        color: green;
        font-size: 15px;
    }

    .colred {
        color: #286090;
        font-size: 15px;
    }
    </style>

</head>

<body id="page-top" class="mt-55">
    <div class="overlay"></div>
    <?php include "includes/header2.php"; ?>
    <div class="container">
        <div class="row mx-0 just ify-content-center">
            <div class="col-12 col-sm-12 col-md-12">
                <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-3 col-md-3 col-lg-3">
                                Name <br>
                                <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-3 col-md-3  col-lg-3">
                                Mobile<br>
                                <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-3 col-md-3  col-lg-3">
                                Password<br>
                                <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 class="col-sm-3 col-md-3  col-lg-3">
                                Theme<br>
                                <select name="theme" id="theme" class="form-control mb-3" required>
                                    <option value="<?php echo $edit_row["theme"]; ?>"> Select Theme :
                                        <?php echo $edit_row["theme"]; ?></option>
                                    <option value="FFA500">FFA500</option>
                                    <option value="3887c7">3887c7</option>
                                    <option value="336600">336600</option>
                                    <option value="336699">336699</option>
                                    <option value="666633">666633</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">

                            <div class="col-sm-3 mb-1 mb-sm-0">

                                Org Name <br>

                                <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-3 mb-1 mb-sm-0">

                                WhatsApp <br>

                                <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-3 mb-1 mb-sm-0">

                                Others Mobile <br>

                                <input type="text" class="form-control form-control-sm mb-2" id="uothcontact"
                                    value="<?php echo $edit_row["uothcontact"]; ?>" placeholder="Oth Mobile"
                                    name="uothcontact">

                            </div>



                            <div class="col-sm-3 mb-1 mb-sm-0">

                                Email <br>

                                <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-3 mb-1 mb-sm-0">

                                Twitter <br>

                                <input type="text" class="form-control form-control-sm mb-2" id="utwitter"
                                    value="<?php echo $edit_row["utwitter"]; ?>" placeholder="Twittert "
                                    name="utwitter">

                            </div>

                            <div class="col-sm-3 mb-1 mb-sm-0">

                                Instragram <br>

                                <input type="text" class="form-control form-control-sm mb-2" id="uinsta"
                                    value="<?php echo $edit_row["uinsta"]; ?>" placeholder="Instragram " name="uinsta">

                            </div>

                            <div class="col-sm-3 mb-1 mb-sm-0">

                                You Tube <br>

                                <input type="text" class="form-control form-control-sm mb-2" id="uyoutube"
                                    value="<?php echo $edit_row["uyoutube"]; ?>" placeholder="You Tube" name="uyoutube">

                            </div>



                            <div class="col-sm-3 mb-1 mb-sm-0">

                                Linkdin <br>

                                <input type="text" class="form-control form-control-sm mb-2" id="linkdin"
                                    value="<?php echo $edit_row["linkdin"]; ?>" placeholder="Linkdin" name="linkdin">

                            </div>

                        </div>

                        <div class="form-group row">

                            <div class="col-sm-4 mb-1 mb-sm-0">

                                web Page url <br>

                                <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">

                                Fb Page Url

                                <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> <img src="<?php echo $edit_row['ulogo'] ?>" alt="image" height="20"
                                    class="">

                                <input type="file" accept="image/*" class="form-control" name="ulogo">
                            </div>

                            <div class="col-sm-2 mb-1 mb-sm-0">

                                <label>Agreement</label> <img src="<?php echo $edit_row['uagreement'] ?>" alt="image"
                                    height="20" class="">

                                <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">
                                address 1<br>
                                <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">
                                Address 2 <br>
                                <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">
                                About <br>
                                <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>

                            Others Mobile - <a href="tel:+91<?php echo $see_row["uothcontact"]; ?>">
                                <?php echo $see_row["uothcontact"]; ?></a>



                            <br>

                            Creat Date - <?php echo $see_row["ucreated"]; ?> <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>

                            Twitter URL - <a href="<?php echo $see_row["utwitter"]; ?>" target="_blank">
                                <?php echo $see_row["utwitter"]; ?> </a><br>

                            Instragram URL - <a href="<?php echo $see_row["uinsta"]; ?>" target="_blank">
                                <?php echo $see_row["uinsta"]; ?> </a><br>

                            YouTube URL - <a href="<?php echo $see_row["uyoutube"]; ?>" target="_blank">
                                <?php echo $see_row["uyoutube"]; ?> </a><br>

                            linkdin URL - <a href="<?php echo $see_row["linkdin"]; ?>" target="_blank">
                                <?php echo $see_row["linkdin"]; ?> </a><br>

                            Address - <?php echo $see_row["uaddress1"]; ?> <br>

                            Address- <?php echo $see_row["uaddress2"]; ?> <br>

                            About - <?php echo $see_row["uabout"]; ?> <br>

                            <a href="<?php echo $see_row["uagreement"]; ?>" target="_blank"> Aggrement Copy</a><br>





                            <a href="nav_lv2.php?nav_for=<?php echo $_GET['see_id']; ?>"
                                class="btn btn-success btn-user m-2"> Nav Bar </a>



                            <a href="extra_info.php?info_for=<?php echo $_GET['see_id']; ?>"
                                class="btn btn-primary btn-user m-2"> <i
                                    class="fas  fa-globe-asia fa-sm fa-fw mr-2 colred"></i> Extra Info </a>



                            <a href="category1.php?visit_id=<?php echo $see_row["uid"]; ?>"
                                class="btn btn-primary btn-user m-2"> <i
                                    class="fas  fa-globe-asia fa-sm fa-fw mr-2 colred"></i> Category </a>



                            <a href="contact1.php?visit_id=<?php echo $see_row["uid"]; ?>"
                                class="btn btn-primary btn-user m-2"> <i
                                    class="fas  fa-globe-asia fa-sm fa-fw mr-2 colred"></i> Contact </a>



                            <a href="ad.php?ad_id=<?php echo $see_row["uid"]; ?>" class="btn btn-primary btn-user m-2">
                                <i class="fas fa-user fa-sm fa-fw mr-2 colred"></i> Advertisement </a>



                            <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-3 col-md-3  col-lg-3">

                                <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-3 col-md-3  col-lg-3">

                                <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-3 col-md-3  col-lg-3">

                                <input type="text" class="form-control form-control-sm mb-2" id="upass"
                                    placeholder="Password*" name="upass" required>

                            </div>



                            <div class="col-sm-3 col-md-3  col-lg-3">



                                <select name="theme" id="theme" class="form-control mb-3" required>

                                    <option value="FFA500"> Select Theme : </option>

                                    <option value="FFA500">FFA500 </option>

                                    <option value="3887c7">3887c7 </option>

                                    <option value="336600">336600 </option>

                                    <option value="336699">336699 </option>

                                    <option value="666633">666633 </option>

                                </select>





                            </div>

                        </div>

                        <div class="form-group row">

                            <div class="col-sm-3 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-3 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-3 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 class="col-sm-3 mb-1 mb-sm-0">

                                <input type="text" class="form-control form-control-sm mb-2" id="uothcontact"
                                    placeholder="Oth Mobile " name="uothcontact">

                            </div>

                        </div>

                        <div class="form-group row">

                            <div class="col-sm-3 mb-1 mb-sm-0">

                                <input type="text" class="form-control form-control-sm mb-2" id="utwitter"
                                    placeholder="Twitter link " name="utwitter">

                            </div>

                            <div class="col-sm-3 mb-1 mb-sm-0">

                                <input type="text" class="form-control form-control-sm mb-2" id="uinsta"
                                    placeholder="Instragram link " name="uinsta">

                            </div>

                            <div class="col-sm-3 mb-1 mb-sm-0">

                                <input type="text" class="form-control form-control-sm mb-2" id="uyoutube"
                                    placeholder="YouTube link" name="uyoutube">

                            </div>

                            <div class="col-sm-3 mb-1 mb-sm-0">

                                <input type="text" class="form-control form-control-sm mb-2" id="linkdin"
                                    placeholder="Linkdin link " name="linkdin">

                            </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'>$c</span>

                                                                

                                                            </td>

                                                            <td><span class='badge badge-info badge-pill'>Uid-$rows[uid]</span><br>

                                                             <a href='admin_lvl2.php?see_id=$rows[uid]' cla ss='m-2 btn btn-success btn-sm  title='Click to Edit'>     $rows[uname]  </a>

<br>

                                                           <a href='$rows[uweburl]'     target='_blank' cla ss='m-2 btn btn-success btn-sm  title='Click to Edit'>    <i class='fa fa-globe' aria-hidden='true'></i> </a>

                                                           &nbsp; <a href='$rows[ufburl]'   target='_blank' cla ss='m-2 btn btn-success btn-sm  title='Click to Edit'>    <i class='fa fa-facebook' aria-hidden='true'></i> </a>

                                                           &nbsp; <a href='https://api.whatsapp.com/send?phone=91$rows[uwhatsapp]'  target='_blank' cla ss='m-2 btn btn-success btn-sm  title='Click to Edit'>    <i class='fa fa-whatsapp' aria-hidden='true'></i></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/ft.php"; ?>







    <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']));

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

        $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']));

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

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

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

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

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

         $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 ) {

                // 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,theme,uothcontact,utwitter,uinsta,uyoutube,linkdin, uref, utype, uabout,utypeorg,uwhatsapp,umail,uweburl,ufburl,ulogo,uagreement,uaddress1,uaddress2, ucreated) VALUES ('$uname', '$uphone', '$upass','$theme','$uothcontact','$utwitter','$uinsta','$uyoutube','$linkdin', '$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']));

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

        $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']));

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

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

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

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

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

         $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', theme = '$theme', uothcontact = '$uothcontact', utwitter = '$utwitter', uinsta = '$uinsta', uyoutube = '$uyoutube', linkdin = '$linkdin',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

        }

    }



?>