<?php 
    ob_start();
    include('../include/db_conx.php');
    isset($_SESSION['admin_login']);
    if(!isset($_SESSION['admin_login'])){
        header("location: auth-login.php");
        exit();
    }else{
    include('../include/admin_head.php');

    $upload = $_GET['upload'];
    if($upload == 'true'){
        $msg = ' Testimony  Successfully Uploaded';
        $link = 'testimony_add.php';
        swal_success($msg,$link);
    }
?>



    <body>

    <!-- <body data-layout="horizontal"> -->

        <!-- Begin page -->
        <div id="layout-wrapper">

        <?php include('../include/admin_header.php');?>

            <!-- ========== Left Sidebar Start ========== -->
           
            <!-- Left Sidebar End -->
            <?php include('../include/admin_sidebar.php');?>

            

            <!-- ============================================================== -->
            <!-- Start right Content here -->
            <!-- ============================================================== -->
            <div class="main-content">

                <div class="page-content">
                    <div class="container-fluid">

                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                                    <h4 class="mb-sm-0 font-size-18">Testimony Details </h4>

                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="javascript: void(0);">Admin</a></li>
                                            <li class="breadcrumb-item active">Testimony Details</li>
                                        </ol>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <!-- end page title -->

                       

                        <div class="row">
                            <div class="col-lg-12">
                            <div class="card">
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col-sm order-2 order-sm-1">
                                                <div class="d-flex align-items-start mt-3 mt-sm-0">
                                                    <div class="flex-shrink-0">
                                                        <div class="avatar-xl me-3">
                                                        <img src="../images/logo-sm.png" alt="" class="img-fluid rounded-circle d-block">

                                                        </div>
                                                    </div>
                                                    <div class="flex-grow-1">
                                                        <div>
                                                            <h5 class="font-size-16 mb-1">Testimony</h5>
                                                            <p class="text-muted font-size-13">Testimony list</p>
                                                           
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-auto order-1 order-sm-2">
                                                <div class="d-flex align-items-start justify-content-end gap-2">
                                                    <a href = 'index.php'>
                                                        <button type="button" class="btn btn-primary"><i class="me-1"></i> <i class="fas fa-chevron-left "></i> Return to Home </button>
                                                    </a>

                                                </div>
                                            </div>
                                        </div>

                                
                                    </div>
                                    <!-- end card body -->
                                </div>
                                <!-- end card -->
                            </div>
                            <!-- end col -->
                        </div>
                        <!-- end row -->
                        <div class="row">
                            <div class="col-sm">
                                <div class="mb-4">
                                    <a href="testimony.php">
                                        <button type="button" class="btn btn-info waves-effect waves-light"><i class=" fas fa-address-book "></i> View Testimony</button>

                                    </a>
                                    
                                </div>
                            </div>
                            <div class="col-sm-auto">
                                <div class="d-flex align-items-center gap-1 mb-4">
                                    <div class="input-group datepicker-range" style="line-height:2;">
                                        <?php echo $today?>                                                     &nbsp;
                                        <button class="input-group-text" id="date1" data-toggle=""><i class="bx bx-calendar-event"></i></button>
                                    </div>
                                
                                </div>
                            </div>
                        </div>
                        <hr />

                        <div class="card">
                            
                            <div class="card-body p-4">

                                <div class="row">

                                    <div class="card-body">
    
                                        <div>
                                            <form   enctype="multipart/form-data" method = 'POST'>
                                                <div class="mb-3">
                                                <label for="example-search-input" class="form-label">Select Image</label>
                                                    <input name="file" type="file" multiple="multiple" >
                                                </div>

                                                <hr />
               

                                                <div class="mb-3">
                                                <label class="form-label">Select Title </label>
                                                <select class="form-select" name="t_title">
                                                    <option value="Mr">Mr</option>
                                                    <option value="Mrs"> Mrs</option>
                                                    <option value="Miss"> Miss</option>
                                                    <option value="Dr">Dr</option>
                                                    <option value="Others">Others</option>
                                                </select>
                                            </div>

                                            <div class="mb-3">
                                                <label for="example-search-input" class="form-label">Enter Full Name</label>
                                                <input class="form-control" type="text" placeholder="James Shaw"  name="t_name" >
                                            </div>
                                            <div class="mb-3">
                                                <label for="example-search-input" class="form-label">Enter Comment</label>
                                                <input class="form-control" type="text" placeholder="I Got returns"  name="t_comment" >
                                            </div>
                                            <div class="mb-3">
                                                <label for="example-search-input" class="form-label">Enter Location</label>
                                                <input class="form-control" type="text" placeholder="St Mary Uk"  name="t_location" Value = 'UK' >
                                            </div>

                                            <button type="submit" class="btn btn-primary" name="submit">Click Here to Upload <i class="fas fa-chart-line"></i></button>


                                            </form>
                                        </div>



                                    <?php
                                    if (isset($_POST['submit'])) {
                                        $files = $_FILES['file'];
                                        $t_name = $_POST['t_name'];
                                        $t_title = $_POST['t_title'];
                                        $t_comment = $_POST['t_comment'];
                                        $t_location = $_POST['t_location'];

                                        $val= 	rand(120,10223);

                                        $fileName = $files['name'];
                                        $fileTmpName = $files['tmp_name'];
                                        $fileSize = $files['size'];
                                        $fileError = $files['error'];
                                        $fileType = $files['type'];

                                        $fileExt = explode('.', $fileName);
								        $fileActualExt = strtolower(end ($fileExt));//the end get the last peice of data in an array 

                                        $allowed = array('jpg', 'jpeg', 'png', 'pdf');
                                        if(in_array($fileActualExt,$allowed)){
                                            if ($fileError === 0) {
                                                if($fileSize < 5000000000){
                                                // main upload file code 
                                                // we have to rename it so that it will not have same name for different images
                                                $fileNameNew =  $val.".".$fileActualExt ;
                                                $fileDestination = 'testimony-images/'.$fileNameNew;	
                                                //main upload code
                                                move_uploaded_file($fileTmpName, $fileDestination);
                                                }
                                            }
                                        }

                                        $image = $val.'.'.$fileActualExt;

                                        $sql_photo = "INSERT INTO testimony(comment,name,title,location,img) 
                                        VALUES('$t_comment','$t_name','$t_title','$t_location','$image')";
                                        $query_photo =  $db_conx->query($sql_photo);

                                        

                                        if ($query_photo) {
                                            header('location:testimony_add.php?upload=true');
                                        } else {
                                            echo 'An error has occurred please contact admin';
                                        }
                                    }

                                    ?>


                                </div>
                                <!-- end row -->
                            </div>
                        </div>



                                                    


                    </div> <!-- container-fluid -->
                </div>
                <!-- End Page-content -->

                
               <?php include('../include/admin_footer.php');?>
            </div>
            <!-- end main content-->

        </div>
        <!-- END layout-wrapper -->

        
       

        <!-- Right bar overlay-->
        <div class="rightbar-overlay"></div>

        <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="assets/libs/metismenu/metisMenu.min.js"></script>
        <script src="assets/libs/simplebar/simplebar.min.js"></script>
        <script src="assets/libs/node-waves/waves.min.js"></script>
        <script src="assets/libs/feather-icons/feather.min.js"></script>
        <!-- pace js -->
        <script src="assets/libs/pace-js/pace.min.js"></script>

        <!-- flatpickr js -->
        <script src="assets/libs/flatpickr/flatpickr.min.js"></script>

        <!-- Required datatable js -->
        <script src="assets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="assets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
        
        <!-- Responsive examples -->
        <script src="assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
        <script src="assets/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script>

        <!-- init js -->
        <script src="assets/js/pages/invoices-list.init.js"></script>

        <script src="assets/js/app.js"></script>

         <!-- dropzone js -->
         <script src="assets/libs/dropzone/min/dropzone.min.js"></script>


       
    </body>

</html>

<?php  } 
    ob_end_flush();

?>
