<?php
session_start();
if(isset($_SESSION['admin']))
{
    $admin_id=$_SESSION['admin']['id'];
    include '../classes/session_class.php';
    include "../manage/function.php";

    $session=new Session("../manage/connection.php");
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Sessions - Malika International Academy </title>
    <!-- HTML5 Shim and Respond.js IE9 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
      <![endif]-->
    <!-- Meta -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="description" content="CodedThemes">
    <meta name="keywords"
        content=" Admin , Responsive, Landing, Bootstrap, App, Template, Mobile, iOS, Android, apple, creative app">
    <meta name="author" content="CodedThemes">
    <!-- Favicon icon -->
    <link rel="icon" href="assets/images/favicon.ico" type="image/x-icon">
    <!-- Google font-->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">
    <!-- Required Fremwork -->
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap/css/bootstrap.min.css">
    <!-- themify-icons line icon -->
    <link rel="stylesheet" type="text/css" href="assets/icon/themify-icons/themify-icons.css">
    <!-- ico font -->
    <link rel="stylesheet" type="text/css" href="assets/icon/icofont/css/icofont.css">
    <!-- Style.css -->
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <link rel="stylesheet" type="text/css" href="assets/css/jquery.mCustomScrollbar.css">
    <link rel="stylesheet" href="assets/vendors/simple-datatables/style.css">
</head>

<body>
    <!-- Pre-loader start -->
    <div class="theme-loader">
        <div class="ball-scale">
            <div class='contain'>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">

                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
            </div>
        </div>
    </div>
    <!-- Pre-loader end -->
    <div id="pcoded" class="pcoded">
        <div class="pcoded-overlay-box"></div>
        <div class="pcoded-container navbar-wrapper">

            <?php
                include 'topnav.php';
            ?>
            <div class="pcoded-main-container">
                <div class="pcoded-wrapper">
                    <?php
                        include 'sidenav.php';
                    ?>
                    <div class="pcoded-content">
                        <div class="pcoded-inner-content">
                            <div class="main-body">
                                <div class="page-wrapper">

                                    <div class="page-body">
                                    <section class="people">
                    <section class="w3l-team-block">
                        <!-- //people cards style 1 -->
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="card card_border mb-5">
                                    <div class="cards__heading">
                                        <div align="center">
                                        <?php
                                            if(isset($_POST['submit']))
                                            {
                                                if(isset($_POST['year']) && isset($_POST['end_year']) && isset($_POST['term']) && !empty($_POST['term']) && isset($_POST['begin']) && isset($_POST['end']))
                                                {
                                                   $s_year=$_POST['year'];
                                                   $e_year=$_POST['end_year'];
                                                    $term=$_POST['term'];
                                                    $begin=$_POST['begin'];
                                                    $end=$_POST['end'];
                                                    $time=time();
                                                    
                                                    if(!$session->findSession($s_year, $term))
                                                    {
                                                        if($session->addSession($term, $s_year, $e_year, $begin, $end, $admin_id, $time))
                                                        {
                                                            echo 'Session Added';
                                                        }
                                                        else
                                                        {
                                                            echo 'Could not add new Session';
                                                        }
                                                    }
                                                    else
                                                    {
                                                        echo 'Session already exist';
                                                    }
                                                }
                                                else
                                                {
                                                    echo 'Fields Cannot be empty';
                                                }
                                            }
                                        ?>
                                        </div>
                                        <div class="container-fluid">
                                            <div class="row">
                                                <div class="col-sm-10">
                                                    <h3>Session <span> </span></h3>
                                                    <!-- <div>Current Session <b>First term 2021</b></div> -->
                                                </div>
                                                <div class="col-sm-2" align="right">
                                                    <button type="button" class="btn btn-primary" data-toggle="modal"
                                                        data-target="#exampleModalCenter">
                                                        Add New
                                                    </button>
                                                    <!-- Modal -->
                                                    <div class="modal fade" id="exampleModalCenter" tabindex="-1"
                                                        role="dialog" aria-labelledby="exampleModalCenterTitle"
                                                        aria-hidden="true">
                                                        <div class="modal-dialog modal-dialog-centered" role="document">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h5 class="modal-title" id="exampleModalLongTitle">
                                                                        Add New Session</h5>
                                                                    <button type="button" class="close"
                                                                        data-dismiss="modal" aria-label="Close">
                                                                        <span aria-hidden="true">&times;</span>
                                                                    </button>
                                                                </div>
                                                                <div class="modal-body">
                                                                    <form method="post">
                                                                        <div class="row">
                                                                            <div class="form-group col-sm-6 col-sm-6">
                                                                                <label for="inputEmail4"
                                                                                    class="input__label">Session Year Begin</label>
                                                                                <input type="number" name="year"
                                                                                    class="form-control input-style"
                                                                                    id="inputEmail4"
                                                                                    placeholder="Type year"
                                                                                    value="<?php echo date('Y');?>">
                                                                            </div>
                                                                            <div class="form-group col-sm-6 col-sm-6">
                                                                                <label for="inputEmail4"
                                                                                    class="input__label">Session Year End</label>
                                                                                <input type="number" name="end_year"
                                                                                    class="form-control input-style"
                                                                                    id="inputEmail4"
                                                                                    placeholder="Type year"
                                                                                    value="<?php echo (date('Y')+1);?>">
                                                                            </div>
                                                                            <div class="form-group col-sm-12">
                                                                                <div align="center"><label for="inputEmail4"
                                                                                    class="input__label">Select
                                                                                    Term</label></div>
                                                                                <select id="inputState" name="term"
                                                                                    class="form-control input-style">
                                                                                    <option value="" selected>-- Choose --
                                                                                    </option>
                                                                                    <option value="1">First Term</option>
                                                                                    <option value="2">Second Term</option>
                                                                                    <option value="3">Third Term</option>
                                                                                </select>
                                                                            </div>
                                                                            <div class="form-group col-sm-6">
                                                                                <label for="inputEmail4"
                                                                                    class="input__label">Term
                                                                                    Begins</label>
                                                                                <input type="date"
                                                                                    class="form-control input-style"
                                                                                    id="inputEmail4" name="begin"
                                                                                    value="<?php echo date('Y-m-d');?>">
                                                                            </div>
                                                                            <div class="form-group col-sm-6">
                                                                                <label for="inputEmail4"
                                                                                    class="input__label">Term
                                                                                    Ends</label>
                                                                                <input type="date"
                                                                                    class="form-control input-style"
                                                                                    id="inputEmail4" name="end"
                                                                                    placeholder="Teype year"
                                                                                    value="<?php echo date('Y-m-d');?>">
                                                                            </div>
                                                                            <div class="form-group col-sm-4"></div>
                                                                            <div class="form-group col-sm-4">
                                                                                <button
                                                                                    class="btn btn-primary btn-block" name="submit">Add Session</button>
                                                                            </div>
                                                                        </div>
                                                                    </form>
                                                                </div>
                                                                <!-- <div class="modal-footer">
                                                                    <button type="button" class="btn btn-danger"
                                                                        data-dismiss="modal">Close</button>
                                                                    <button type="button" class="btn btn-success">Save
                                                                        changes</button>
                                                                </div> -->
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <!-- end modal -->
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="card-body">
                                        <table class='table table-striped' id="table1">
                                            <thead>
                                                <tr>
                                                    <th>S/N</th>
                                                    <th>Session</th>
                                                    <th>Term</th>
                                                    <th>Duration</th>
                                                    <th>From</th>
                                                    <th>To</th>
                                                    <th>Action</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $n=1;
                                                foreach($session->getAllSession() as $sessionInfo)
                                                {
                                                    echo '<tr>
                                                        <td>'.$n.'</td>
                                                        <td>'.$sessionInfo['year'].'/'.$sessionInfo['end_year'].'</td>';
                                                        // <td>'.$sessionInfo['term'].'</td>
                                                        switch($sessionInfo['term'])
                                                        {
                                                            case 1:
                                                                echo '<td>'.$sessionInfo['term'].'<sup>st</sup> Term</td>';
                                                                break;
                                                            case 2:
                                                                echo '<td>'.$sessionInfo['term'].'<sup>nd</sup> Term</td>';
                                                                break;
                                                            case 3:
                                                                echo '<td>'.$sessionInfo['term'].'<sup>rd</sup> Term</td>';
                                                                break;
                                                        }
                                                        echo '<td>'.intval(dates_range($sessionInfo['begin'],$sessionInfo['end'])/7).' week(s)</td>
                                                        <td>'.$sessionInfo['begin'].'</td>
                                                        <td>'.$sessionInfo['end'].'</td>
                                                        <td>
                                                            <a href="edit_session.php?id='.$sessionInfo['id'].'"><button class="btn btn-success">Edit</button></a>
                                                        </td>
                                                    </tr>';
                                                    $n++;
                                                }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <!-- <div class="col-sm-3">
                                <div class="card card_border mb-5">
                                    <div class="cards__heading">
                                        Pop-up dialog
                                    </div>
                                    <div class="card-body">
                                        <form method="post">
                                            <div class="form-group">
                                                <label for="inputEmail4" class="input__label">Year</label>
                                                <input type="number" class="form-control input-style" id="inputEmail4"
                                                    placeholder="Teype year" value="<?php echo date('Y');?>">
                                            </div>
                                            <div class="form-group">
                                                <label for="inputEmail4" class="input__label">Select Term</label>
                                                <select id="inputState" class="form-control input-style">
                                                    <option selected>-- Choose --</option>
                                                    <option>First Term</option>
                                                    <option>Second Term</option>
                                                    <option>Third Term</option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label for="inputEmail4" class="input__label">Term Begins</label>
                                                <input type="date" class="form-control input-style" id="inputEmail4"
                                                    value="<?php echo date('Y-m-d');?>">
                                            </div>
                                            <div class="form-group">
                                                <label for="inputEmail4" class="input__label">Term Ends</label>
                                                <input type="date" class="form-control input-style" id="inputEmail4"
                                                    placeholder="Teype year" value="<?php echo date('Y-m-d');?>">
                                            </div>
                                            <div class="form-group">
                                                <button class="btn btn-primary btn-block">Add</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div> -->
                        </div>
                    </section>
                                    </div>

                                    <div id="styleSelector">

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="fixed-button">
                    <a href="https://codedthemes.com/item/guru-able-admin-template/" target="_blank"
                        class="btn btn-md btn-primary">
                        <i class="fa fa-shopping-cart" aria-hidden="true"></i> Upgrade To Pro
                    </a>
                </div>
            </div>
        </div>

        <!-- Warning Section Starts -->
        <!-- Older IE warning message -->
        <!--[if lt IE 9]>
<div class="ie-warning">
    <h1>Warning!!</h1>
    <p>You are using an outdated version of Internet Explorer, please upgrade <br/>to any of the following web browsers to access this website.</p>
    <div class="iew-container">
        <ul class="iew-download">
            <li>
                <a href="http://www.google.com/chrome/">
                    <img src="assets/images/browser/chrome.png" alt="Chrome">
                    <div>Chrome</div>
                </a>
            </li>
            <li>
                <a href="https://www.mozilla.org/en-US/firefox/new/">
                    <img src="assets/images/browser/firefox.png" alt="Firefox">
                    <div>Firefox</div>
                </a>
            </li>
            <li>
                <a href="http://www.opera.com">
                    <img src="assets/images/browser/opera.png" alt="Opera">
                    <div>Opera</div>
                </a>
            </li>
            <li>
                <a href="https://www.apple.com/safari/">
                    <img src="assets/images/browser/safari.png" alt="Safari">
                    <div>Safari</div>
                </a>
            </li>
            <li>
                <a href="http://windows.microsoft.com/en-us/internet-explorer/download-ie">
                    <img src="assets/images/browser/ie.png" alt="">
                    <div>IE (9 & above)</div>
                </a>
            </li>
        </ul>
    </div>
    <p>Sorry for the inconvenience!</p>
</div>
<![endif]-->
        <!-- Warning Section Ends -->
        <!-- Required Jquery -->
        <script type="text/javascript" src="assets/js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="assets/js/jquery-ui/jquery-ui.min.js"></script>
        <script type="text/javascript" src="assets/js/popper.js/popper.min.js"></script>
        <script type="text/javascript" src="assets/js/bootstrap/js/bootstrap.min.js"></script>
        <!-- jquery slimscroll js -->
        <script type="text/javascript" src="assets/js/jquery-slimscroll/jquery.slimscroll.js"></script>
        <!-- modernizr js -->
        <script type="text/javascript" src="assets/js/modernizr/modernizr.js"></script>
        <!-- am chart -->
        <script src="assets/pages/widget/amchart/amcharts.min.js"></script>
        <script src="assets/pages/widget/amchart/serial.min.js"></script>
        <!-- Todo js -->
        <script type="text/javascript " src="assets/pages/todo/todo.js "></script>
        <!-- Custom js -->
        <script type="text/javascript" src="assets/pages/dashboard/custom-dashboard.js"></script>
        <script type="text/javascript" src="assets/js/script.js"></script>
        <script type="text/javascript " src="assets/js/SmoothScroll.js"></script>
        <script src="assets/js/pcoded.min.js"></script>
        <script src="assets/js/demo-12.js"></script>
        <script src="assets/js/jquery.mCustomScrollbar.concat.min.js"></script>

        <script src="assets/js/jquery.nicescroll.js"></script>
        <script src="assets/js/scripts.js"></script>
        <script src="assets/vendors/perfect-scrollbar/perfect-scrollbar.min.js"></script>
        <script src="assets/vendors/simple-datatables/simple-datatables.js"></script>
        <script src="assets/js/vendors.js"></script>
        <script>
        var $window = $(window);
        var nav = $('.fixed-button');
        $window.scroll(function() {
            if ($window.scrollTop() >= 200) {
                nav.addClass('active');
            } else {
                nav.removeClass('active');
            }
        });
        </script>
         

</body>

</html>
<?php
}
else
{
    header("location:../index.php");
}
?>