<?php
session_start();
if(isset($_SESSION['teacher']))
{
        $t_id=htmlentities($_SESSION['teacher']['id']);
    include '../classes/teachers.php';

    $getTeacher=new Teachers("../manage/connection.php");
    $teacher=$getTeacher->getTeacher($t_id);
?>
<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <title>Edit Teacher</title>

    <!-- Template CSS -->
    <link rel="stylesheet" href="assets/css/style-starter.css">

    <!-- google fonts -->
    <link href="//fonts.googleapis.com/css?family=Nunito:300,400,600,700,800,900&display=swap" rel="stylesheet">
</head>

<body class="sidebar-menu-collapsed">
    <!-- <div class="se-pre-con"></div> -->
    <section>
        <!-- sidebar menu start -->
        <?php
  include 'navigation.php';
  ?>
        <!-- //sidebar menu end -->
        <!-- header-starts -->
        <?php
  include 'header.php';
  ?>
        <!-- //header-ends -->
        <!-- main content start -->
        <div class="main-content">

            <!-- content -->
            <div class="container-fluid content-top-gap">

                <!-- breadcrumbs -->
                <nav aria-label="breadcrumb" class="mb-4">
                    <ol class="breadcrumb my-breadcrumb">
                        <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                        <li class="breadcrumb-item active" aria-current="page">Forms</li>
                    </ol>
                </nav>
                <!-- //breadcrumbs -->
                <!-- forms -->
                <section class="forms">

                    <!-- forms 2 -->
                    <div class="card card_border py-2 mb-4">
                        <div class="card-body">
                            <div align="center" style="min-height:50px;" id="status"> </div>
                            <form action="#" method="post" id="update_teacher">
                                <div class="form-row">
                                    <div class="col-sm-3">
                                        <div>
                                            <img src="../images/<?php echo $teacher['image'];?>" width="100%" height="300px" id="coverImage"/>
                                        </div>
                                        <div style="margin:10px;">
                                            <input type="file" name="image" onchange="readURL(this, '#coverImage');"/>
                                        </div>
                                    </div>

                                    <div class="col-sm-1"></div>
                                    <div class="col-sm-8">
                                        <div class="row">
                                            <div class="form-group col-md-6">
                                                <label for="inputEmail4" class="input__label">Full Name</label>
                                                <input type="text" class="form-control input-style" id="inputEmail4"
                                                    placeholder="Name" name="fullname" value="<?php echo $teacher['fullname'];?>" required>
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label for="inputPphone" class="input__label">Phone</label>
                                                <input type="text" class="form-control input-style" id="inputphone"
                                                    placeholder="" name="phone" value="<?php echo $teacher['phone'];?>" required>
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label for="inputAddress" class="input__label">Address</label>
                                                <input type="text" class="form-control input-style" id="inputAddress" name="address"
                                                    value="<?php echo $teacher['address'];?>" placeholder="Resident address">
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label for="inputPassword4" class="input__label">Password</label>
                                                <input type="password" class="form-control input-style"
                                                    id="inputPassword4" name="password" placeholder="Password">
                                            </div>
                                            <!-- <div class="form-group col-md-6">
                                                <label for="inputEmail4" class="input__label">Assign Class</label>
                                                <input type="email" class="form-control input-style" id="inputEmail4"
                                                    placeholder="Email">
                                            </div> -->
                                            <!-- <div class="form-group col-md-6">
                                                <label for="inputState" class="input__label">Assign Class</label>
                                                <select id="inputState" class="form-control input-style">
                                                    <option selected>Choose...</option>
                                                    <option>Primary One</option> 
                                                    <option>Primary Two</option> 
                                                </select>
                                            </div> -->
                                            <div class="form-group col-md-3 "></div>
                                            <div class="form-group col-md-6">
                                                <label for="inputState" class="input__label">Gender</label>
                                                <select id="inputState" name="gender" class="form-control input-style">
                                                    <option>Choose...</option>
                                                    <?php
                                                        if(strtolower($teacher['gender'])=='male')
                                                        {
                                                            echo '
                                                            <option value="male" selected>Male</option>
                                                            <option value="female">Female</option>';
                                                        }
                                                        else
                                                        {
                                                            echo '
                                                            <option value="male">Male</option>
                                                            <option value="female" selected>Female</option>';
                                                        }
                                                    ?>
                                                </select>
                                                <input type="radio" name="teacher_id" value="<?php echo $t_id; ?>" style="display: none;" checked/>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12" align="center">
                                    <button type="submit" class="btn btn-primary btn-style mt-4">Edit Teacher </button>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- //forms 2 -->
                    <!-- supported elements -->

                </section>
                <!-- //forms -->
    </section>
    <!-- //forms  -->

    </div>
    <!-- //content -->

    </div>
    <!-- main content end-->
    </section>
    <!--footer section start-->
    <?php
  include 'footer.php';
  ?>
    <!--footer section end-->
    <!-- move top -->
    <button onclick="topFunction()" id="movetop" class="bg-primary" title="Go to top">
        <span class="fa fa-angle-up"></span>
    </button>
    <script>
    // When the user scrolls down 20px from the top of the document, show the button
    window.onscroll = function() {
        scrollFunction()
    };

    function scrollFunction() {
        if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
            document.getElementById("movetop").style.display = "block";
        } else {
            document.getElementById("movetop").style.display = "none";
        }
    }

    // When the user clicks on the button, scroll to the top of the document
    function topFunction() {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }
    </script>
    <!-- /move top -->


    <script src="assets/js/jquery-3.3.1.min.js"></script>
    <script src="assets/js/jquery-1.10.2.min.js"></script>

    <!-- chart js -->
    <script src="assets/js/Chart.min.js"></script>
    <script src="assets/js/utils.js"></script>
    <!-- //chart js -->

    <!-- Different scripts of charts.  Ex.Barchart, Linechart -->
    <script src="assets/js/bar.js"></script>
    <script src="assets/js/linechart.js"></script>
    <!-- //Different scripts of charts.  Ex.Barchart, Linechart -->


    <script src="assets/js/jquery.nicescroll.js"></script>
    <script src="assets/js/scripts.js"></script>

    <!-- close script -->
    <script>
    var closebtns = document.getElementsByClassName("close-grid");
    var i;

    for (i = 0; i < closebtns.length; i++) {
        closebtns[i].addEventListener("click", function() {
            this.parentElement.style.display = 'none';
        });
    }
    </script>
    <!-- //close script -->

    <!-- disable body scroll when navbar is in active -->
    <script>
    $(function() {
        $('.sidebar-menu-collapsed').click(function() {
            $('body').toggleClass('noscroll');
        })
    });
    </script>
    <!-- disable body scroll when navbar is in active -->

    <!-- loading-gif Js -->
    <script src="assets/js/modernizr.js"></script>
    <script>
    $(window).load(function() {
        // Animate loader off screen
        $(".se-pre-con").fadeOut("slow");;
    });
    </script>
    <!--// loading-gif Js -->

    <!-- Bootstrap Core JavaScript -->
    <script src="assets/js/bootstrap.min.js"></script>
    <script>
    $(document).on('submit', '#update_teacher', function(e) {
        e.preventDefault(); 
        //    alert("WORKIN");
        var formData = new FormData(this);
        $('#status').html('<h4 class="card-title">Adding</h4>');
        $.ajax({
            url: "../control/update_teacher.php", // Url to which the request is send
            type: "POST", // Type of request to be send, called as method
            data: formData, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
            contentType: false, // The content type used when sending data to the server.
            cache: false, // To unable request pages to be cached
            processData: false, // To send DOMDocument or non processed data file it is set to false
            success: function(data) // A function to be called if request succeeds
            {
                $('#status').html('<h4 class="card-title">' + data + '</h4>');
                //    alert(data);
            }
        });
    });

    
function readURL(input, id) { 
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $(id)

                .attr('src', e.target.result)
                .width('100%')
                .height(300);
        };

        reader.readAsDataURL(input.files[0]);
    }
}
    </script>

</body>

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