<?php
    session_start();
    include "../../../db.php";
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('M j, Y g:i a');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {
        header("Location: index.php");
        exit();
    }
    $imgUrl="http://ins.net.in/admission/upload";
?>
<!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">
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body id="page-top">


    <div style="background-color: #116496; padding: 30px;margin-bottom: 15px;"></div>

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

                <div class="container-fluid">

                    <div cla ss="card shadow mb-4">
                        <div cla ss="card-body">

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

                          
                            <div class="row m-0">

                                <div class="col-md-12 p-0">
                                    <div class="table-responsive">
                                        <table class="table text-center align-middle table-hover table-bordered table-sm" id="thisismytable">
                                            <thead>
                                                <tr>
                                                    <th style='max-width:100px'>No.</th>
                                                    <th>Name</th>
                                                    <th>Document...</th>
                                                   
                                                    <th >Act.</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                    $sql = "SELECT * FROM intranjob2 WHERE cid = '$_SESSION[uid]'  ORDER BY id DESC";
                                                    $run = mysqli_query($con, $sql);

                                                    $c = 1;
                                                    while ( $rows = mysqli_fetch_assoc($run) )
												{
													 $fbId = $rows['id']; 	
                                                        echo "
                                                        <tr>
                                                            <td>
                                                                <span class='badge badge-info badge-pill'>$c</span>
                                                            </td>
                                                            <td class='text-center align-middle small'>
															    <a target='_blank' href='pdf/applicationpdf.php?id=$fbId'  ><i class='fa fa-print' style='font-size:28px;color:red' aria-hidden='true'></i></a><br>
                                                                
																<a target='_blank' href='pdf/applicationpdf.php?id=$fbId' cl ass='btn btn-primary btn-sm'><font size='3'> $rows[fname]</font></a>
																	  <br>
																$rows[mobileno]
																<br>
																Apply for :<b> $rows[dept]</b>
																<br>
																      
															$rows[dtsubmitted]
														
																
                                                            </td>
                                                            "; ?>


                <td class='text-center align-middle small'>

                <?php 
                if (!empty($rows['photo'])) {

                    echo "<a href='$imgUrl/photo/$rows[photo]' target='_blank' >   photo  </a>&nbsp;&nbsp;";
                }
                if (!empty($rows['photo9'])) {

                    echo "<a href='$imgUrl/photo9/$rows[photo9]' target='_blank' >   signature  </a> &nbsp;&nbsp;";
                } 
                if (!empty($rows['photo2'])) {

                    echo "<a href='$imgUrl/photo2/$rows[photo2]' target='_blank' >   Adhar Card  </a> &nbsp;&nbsp;";
                } 
                if (!empty($rows['photo3'])) {

                    echo "<a href='$imgUrl/photo3/$rows[photo3]' target='_blank' >   Madhyamik Admit Card  </a> &nbsp;&nbsp;";
                } 
                if (!empty($rows['photo4'])) {

                    echo " <a href='$imgUrl/photo4/$rows[photo4]' target='_blank' >   Madhyamik Result  </a> &nbsp;&nbsp;";
                } 
                if (!empty($rows['photo5'])) {

                    echo "<a href='$imgUrl/photo5/$rows[photo5]' target='_blank' >   Certificate   </a> &nbsp;&nbsp;";
                } 
                if (!empty($rows['photo6'])) {

                    echo "<a href='$imgUrl/photo6/$rows[photo6]' target='_blank' >   H.S. Result  </a> &nbsp;&nbsp;";
                } 
                if (!empty($rows['photo7'])) {

                    echo " <a href='$imgUrl/photo7/$rows[photo7]' target='_blank' >   H.S. Certificate </a> &nbsp;&nbsp;";
                } 
                if (!empty($rows['photo8'])) {

                    echo "<a href='$imgUrl/photo8/$rows[photo8]' target='_blank' > School leaving Certificate</a> &nbsp;&nbsp;";
                }  
                ?>

			  </td>

                                                         <?php
                                                           
                                                           echo " 
                                                            <td class='text-center align-middle'>
                                                                ."//<a href='admissionedit.php?edit_id=$rows[id]' class='m-2 btn btn-success btn-sm rounded-circle' title='Click to Edit'> <i class='fas fa-pencil-alt'></i> </a>
                                                                ."
                                                                <a href='admission.php?del_id=$rows[id]' 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 style="background-color: #116496; padding: 15px; margin-top: 30px;"></div>





    <div class="modal fade" id="show-img" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body">
                    <img src="" alt="sliderImage" id="image_modal" class="w-100">
                    <p class="small mt-3 mb-2" id="dimension"> <span class="font-weight-bold"> Name </span> : </p>
                    <p class="small mb-2" id="dimension"> <span class="font-weight-bold"> Dimension </span> : </p>
                    <p class="small mb-2" id="dimension"> <span class="font-weight-bold"> Size </span> : </p>
                </div>
                <div class="modal-footer">
                    <button type="close" class="btn btn-secondary" data-dismiss="modal"> Close </button>
                </div>
            </div>
        </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>
		$(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($_GET["del_id"]) ) {

        $del_sql = "DELETE FROM intranjob2 WHERE id = '$_GET[del_id]'";
        // echo '<pre>';print_r($del_sql);exit();
        if ( mysqli_query($con, $del_sql) ) {
            ?>
            <script>window.location = "admission.php";</script>
            <?php
        } else {
            ?>
            <script>
                alert('OOPS !!!!');
                setTimeout(() => {
                    window.location = 'admission.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']));
        $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', uabout = '$uabout' WHERE uid = '$_GET[edit_id]'";
    
            if(mysqli_query($con, $up_sql)){
                ?>
                <script>window.location = 'review-blog.php';</script>
                <?php
            }
            else{
                ?>
                <script>
                    alert('OOPS !!!!');
                    setTimeout(() => {
                        window.location = 'review-blog.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
        }
    }

?>