<?php
session_start();
if(isset($_SESSION['username'])){
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">



    <?php include 'includes/styles.php'; ?>
    <title> Promote Students |    <?php echo $school_name; ?> </title>

    <?php
    $module_name = 'Promotion';
    include "check-admin-privilege.php";
    ?>

</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">

    <!-- Navbar -->
    <?php include 'includes/notifications.php'; ?>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <?php include "includes/sidebar.php";?>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0">Students' Promotion</h1>
                    </div><!-- /.col -->
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="<?php echo $conn->base_url();?>">Home</a></li>
                            <li class="breadcrumb-item active">Promote Students</li>
                        </ol>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->
        </div>
        <!-- /.content-header -->

        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">

                <div class="row">
                    <div class="col-md-12">
                        <div class="callout callout-info" style="margin-top: 30px;">
                            <p style='font-size: 18px;'> <i class='fa fa-info-circle' data-toggle='tooltip' title='Pls read and understand this before promoting.'></i> Few information to keep in mind before promoting: <br> <span class='text-info'>
                                   1. When Promoting, what changes is the student's class and the section(arms) names.
                                      <br>
                                   2. We advise that you start promoting from the highest class. For example, Promote
                                    SS3 to a different class(you need to create the class you are promoting to if it does not exist. E.g SS3 to SS3_2021_2022) before
                                    promoting SS2 to SS3, SS1 to SS2...etc. <br>
                                   3. Promotion does not affect students scores already uploaded. Scores remain intact, this is
                                      so that students who are no longer active in a class can still have access to their terminal
                                      report for the previous class but only through admin session. <br>
                                   4. It's advisable that you promote students at the beginning of the session. This is usually September of every year. <br>

                                </span>
                            </p>
                        </div>
                        <div class="card card-info">
                            <div class="card-header">
                                <h3 class="card-title"><i class="fa fa-flask"></i> Promote Students</h3>
                            </div>
                            <!-- /.card-header -->
                            <!-- form start -->
                            <form class="form-horizontal" method="post" id="promote_class">
                                <div class="card-body">
                                    <div class="form-row">
                                        <div class="col-md-3">
                                            <label for="class"> Current Class <span class="text-danger">*</span></label>
                                            <select name="current_class" id="classID" class="form-control select2 myclass" required data-parsley-trigger="keyup" style="width: 100%;">
                                                <option value="">Select Class</option>
                                                <?php
                                                //fetch all teachers information
                                                $sql = "SELECT * FROM classes";
                                                $conn->query($sql);
                                                $rowcount = $conn->rowCount();

                                                if($rowcount > 0){
                                                    $result = $conn->fetchMultiple();
                                                    foreach ($result as $class) {
                                                        ?>  <option value="<?php echo $class->id; ?>"><?php echo $class->name; ?></option><?php
                                                    }

                                                }

                                                ?>

                                            </select>
                                        </div>

                                        <div class="col-md-3">
                                            <label for="class"> Class to Promote To <span class="text-danger">*</span></label>
                                            <select name="new_class" id="new_classID" class="form-control select2 myclass" required data-parsley-trigger="keyup" style="width: 100%;">
                                                <option value="">Select New Class</option>
                                                <?php
                                                //fetch all teachers information
                                                $sql = "SELECT * FROM classes";
                                                $conn->query($sql);
                                                $rowcount = $conn->rowCount();
                                                if($rowcount > 0){
                                                    $result = $conn->fetchMultiple();
                                                    foreach ($result as $class) {
                                                        ?>  <option value="<?php echo $class->id; ?>"><?php echo $class->name; ?></option><?php
                                                    }

                                                }

                                                ?>

                                            </select>
                                        </div>


                                        <div class="col-md-3" style="margin-top: 50px !important;">
                                            <input type="submit" value="View Student Details" class="btn btn-success" id="promote">
                                        </div>

                                    </div>

                                </div>
                                <div id="success-msg">
                                </div>
                                <!-- /.card-body -->

                                <!-- /.card-footer -->
                            </form>
                        </div>
                        <!-- /.card -->
                    </div>

                    <div class="col-md-12">
                        <!-- display promotion details-->
                        <div class="card card-info" id="display-details">

                        </div>


                </div>


                <!-- /.row (main row) -->
            </div><!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <?php include "includes/footer.php";?>



    <script>
        $(document).ready(function(){
            $('.select2').select2();
        })
    </script>
    <script>
        $(document).ready(function(){
            $('#class').select2();
            $('[data-toggle="tooltip"]').tooltip();
        })

    </script>
    <script>
        $(function () {
            $("#teacher").DataTable({
                "responsive": true, "lengthChange": false, "autoWidth": false,
                "buttons": ["copy", "csv", "pdf", "print"]
            }).buttons().container().appendTo('#teacher_wrapper .col-md-6:eq(0)');
            $('#example2').DataTable({
                "paging": true,
                "lengthChange": false,
                "searching": true,
                "ordering": true,
                "info": true,
                "autoWidth": false,
                "responsive": true
            });
        });
    </script>

    <script>
        $('#promote_class').parsley();
        $('#promote_class').on('submit', function (event) {
            event.preventDefault();
            if($('#promote_class').parsley().isValid()){
                $.ajax({
                    url: 'fetch-students-promotion-details.php',
                    method: 'POST',
                    data: new FormData(this),
                    contentType: false,
                    cache: false,
                    processData: false,
                    beforeSend: function () {
                        $('#promote').attr('disabled', 'disabled');
                        $('#promote').val('fetching details, pls wait.....');
                    },
                    success: function (data) {
                        $('#promote_class').parsley().reset();
                        $('#promote').attr('disabled', false);
                        $('#promote').val('View Students Details');
                        $('#display-details').html(data);
                    }
                });
            }
        });
    </script>


    <script>
        if ( window.history.replaceState ) {
            window.history.replaceState( null, null, window.location.href );
        }
    </script>

    <?php
    }else{
    ?>
    <!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, maximum-scale=1, shrink-to-fit=no">

        <?php include 'includes/styles.php'; ?>
        <title>Login to continue |    <?php echo $school_name; ?></title>
        <?php
        $module_name = 'Promotion';
        include "check-admin-privilege.php";
        ?>

        <!-- END PAGE LEVEL PLUGINS/CUSTOM STYLES -->

    </head>
    <body>
    <div class="container" style="margin-top: 20%;">
        <div class="row">
            <div class="col-lg-12 col-md-12">
                <div class="section-title text-center">
                    <h6> You need to login to continue </h6>
                    <div class="spinner-border text-info" role="status">
                        <span class="sr-only">Loading...</span>
                        <meta http-equiv='refresh' content='3; <?php echo $link; ?>'>
                    </div>
                    <p>Redirecting to the login  page...</p>
                </div>
            </div>
        </div>
    </div>

    <?php
    }

    ?>
