<?php

$table_name = 'questions';
$redirection_page = "index.php?action=$page_name";
$action_name = "action=$page_name";
$type = $_REQUEST['type'];
$edit_id = $_REQUEST['edit_id'];
$delete_id = $_REQUEST['delete_id'];

// For Submitting The Form  



// For Displaying the table

if (isset($_GET['pageno'])) {
    $pageno = $_GET['pageno'];
} else {
    $pageno = 1;
}
$no_of_records_per_page = 7;
$offset = ($pageno - 1) * $no_of_records_per_page;


$select_enquiry = "SELECT * FROM $table_name where status = 'Active' order by id desc";
$sql = $dbconn->prepare($select_enquiry);
$sql->execute();


$total_rows = $sql->fetchColumn();
$total_pages = ceil($total_rows / $no_of_records_per_page);

$select_enquiry = "SELECT * FROM $table_name where status = 'Active' order by id desc LIMIT $offset, $no_of_records_per_page";
$sql = $dbconn->prepare($select_enquiry);
$sql->execute();
$wlvd = $sql->fetchAll(PDO::FETCH_OBJ);


?>


<div class="container-fluid">
    <div class="content-wrapper">
        <div class="container-fluid">
            <!-- Breadcrumb-->
            <div class="row pt-2 pb-2">
                <div class="col-sm-9">
                    <h4 class="page-title"><?php echo $page_name; ?></h4>
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="index.php?action=Welcome">Dashboard</a></li>

                        <li class="breadcrumb-item active" aria-current="page"><a href="index.php?action=<?php echo $page_name; ?>"><?php echo $page_name; ?></a></li>
                    </ol>
                </div>

                <div class="col-sm-3">
                    <?php include('plugins/alert.php'); ?>
                    <!-- Button trigger modal -->
                </div>

            </div>
            <!-- End Breadcrumb-->
            <?php if ($type == 'Delete') {

                $delete_statement = "UPDATE `$table_name` SET
                status   = 'Inactive'
                where id='" . $delete_id . "'";


                $sql_insert = $dbconn->prepare($delete_statement);
                $sql_insert->execute();


                $message = "Details successfully updated.";
                $status = "success";
                header("Location: $redirection_page&id=$delete_id");
            } else {
            ?>
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><i class="fa fa-user"></i> All Records</div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-hover" id="sample-table-1">
                                        <thead class="thead-dark">
                                            <tr>
                                                <th class="center"> ID</th>
                                                <th class="center"> Parent Name</th>
                                                <th class="center"> Children Name</th>
                                                <th class="center"> Age</th>
                                                <th class="center"> Photo</th>
                                                <th class="center"> Questions</th>
                                                <th class="center"> Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php

                                            //while($rows = mysql_fetch_array($aResult,MYSQL_ASSOC))
                                            //{

                                            $select_enquiry = "SELECT * FROM `questions` where status = 'Active' order by id desc LIMIT $offset, $no_of_records_per_page";
                                            $sql = $dbconn->prepare($select_enquiry);
                                            $sql->execute();
                                            $wlvd = $sql->fetchAll(PDO::FETCH_OBJ);
                                            if ($sql->rowCount() > 0) {

                                                foreach ($wlvd as $rows) {
                                                    $field1 = $rows->id;
                                                    $field2 = $rows->parent;
                                                    $field3 = $rows->child;
                                                    $field4 = $rows->age;
                                                    $field5 = $rows->photo;
                                                    $field6 = $rows->problem;
                                            ?>
                                                    <tr>
                                                        <td class="center"><?php echo $field1; ?></td>
                                                        <td class="center"><?php echo $field2; ?></td>
                                                        <td class="center"><?php echo $field3; ?></td>
                                                        <td class="center"><?php echo $field4; ?></td>
                                                        <td class="center"><img src="photo/$name1<?php echo $field5; ?>" alt=""></td>
                                                        <td class="center"><?php echo $field6; ?></td>
                                                        <td class="center">
                                                            <!-- <a href="<?php echo $redirection_page; ?>&edit_id=<?php echo $field1; ?>&type=Edit" target="_self"><i class="fa fa-edit"></i> </a> -->

                                                            <a href="index.php?action=reply&edit_id=<?php echo $field1; ?>" target="_self"><i class="fa fa-reply"></i> Reply</a>


                                                            <a href="<?php echo $redirection_page; ?>&delete_id=<?php echo $field1; ?>&type=Delete" target="_self"><i class="fa fa-trash"></i> </a>
                                                        </td>
                                                    </tr>

                                            <?php }
                                            } ?>
                                        </tbody>
                                    </table>

                                    <?php include('plugins/pagination.php'); ?>

                                </div>

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

            <?php
            };
            ?>


        </div>
        <!-- End Row-->


    </div><!--End content-wrapper-->
    <!--Start Back To Top Button-->
    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
    <!--End Back To Top Button-->



<!-- reply starts here  -->



    <!-- new  -->
    <?php

    $table_name = 'sidebar_menu';
    $redirection_page = "index.php?action=$page_name";
    $action_name = "action=$page_name";
    $type = $_REQUEST['type'];
    $edit_id = $_REQUEST['edit_id'];
    $delete_id = $_REQUEST['delete_id'];


    // For Submitting The Form

    if (isset($_POST['submit'])) {

        $field1    =  $_POST['field1'];
        $field2    =  $_POST['field2'];
        $field3    =  $_POST['field3'];
        $field4    =  $_POST['field4'];
        $field5    =  $_POST['field5'];
        $field6    =  $_POST['field6'];
        $field7    =  $_POST['field7'];
        $field8    =  $_POST['field8'];
        $field9    =  $_POST['field9'];
        $field10    =  $_POST['field10'];


        if ($type == 'Edit') {
            $insert_bookings = "UPDATE `$table_name` SET
  sidebar_menu_name   = '" . addslashes($field1) . "',   
  sidebar_menu_type   = '" . addslashes($field2) . "',
  sidebar_menu_master   = '" . addslashes($field3) . "'
  where id='" . $edit_id . "'";


            $sql_insert = $dbconn->prepare($insert_bookings);
            $sql_insert->execute();


            $message = "Details successfully updated.";
            $status = "success";
            header("Location: $redirection_page&id=$edit_id");
        } else {
            $insert_bookings = "INSERT `$table_name` SET
  sidebar_menu_name   = '" . addslashes($field1) . "',   
  sidebar_menu_type   = '" . addslashes($field2) . "',
  sidebar_menu_master   = '" . addslashes($field3) . "',
  status   = 'Active'";


            $sql_insert = $dbconn->prepare($insert_bookings);
            $sql_insert->execute();
            $myid = $dbconn->lastInsertId();

            $message = "Details successfully updated.";
            $status = "success";
            header("Location: $redirection_page&id=$myid");
        }
    }

    // For Displaying the table

    if (isset($_GET['pageno'])) {
        $pageno = $_GET['pageno'];
    } else {
        $pageno = 1;
    }
    $no_of_records_per_page = 7;
    $offset = ($pageno - 1) * $no_of_records_per_page;


    $select_enquiry = "SELECT * FROM $table_name where status = 'Active' order by id desc";
    $sql = $dbconn->prepare($select_enquiry);
    $sql->execute();


    $total_rows = $sql->fetchColumn();
    $total_pages = ceil($total_rows / $no_of_records_per_page);

    $select_enquiry = "SELECT * FROM $table_name where status = 'Active' order by id desc LIMIT $offset, $no_of_records_per_page";
    $sql = $dbconn->prepare($select_enquiry);
    $sql->execute();
    $wlvd = $sql->fetchAll(PDO::FETCH_OBJ);


    $select_bookings = "SELECT * FROM `$table_name` WHERE id = '$edit_id'";
    $sql1 = $dbconn->prepare($select_bookings);
    $sql1->execute();
    $wlvd1 = $sql1->fetchAll(PDO::FETCH_OBJ);
    foreach ($wlvd1 as $rows1);


    ?>


    <div class="container-fluid">

        <div class="content-wrapper">
            <div class="container-fluid">
                <!-- Breadcrumb-->
                <div class="row pt-2 pb-2">
                    <div class="col-sm-9">
                        <h4 class="page-title"><?php echo $page_name; ?></h4>
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index.php?action=Welcome">Dashboard</a></li>

                            <li class="breadcrumb-item active" aria-current="page"><a href="index.php?action=<?php echo $page_name; ?>"><?php echo $page_name; ?></a></li>
                        </ol>
                    </div>

                    <div class="col-sm-3">
                        <?php include('plugins/alert.php'); ?>
                        <!-- Button trigger modal -->
                    </div>

                </div>
                <!-- End Breadcrumb-->
                <?php if ($type == 'Delete') {

                    $delete_statement = "UPDATE `$table_name` SET
      status   = 'Inactive'
      where id='" . $delete_id . "'";


                    $sql_insert = $dbconn->prepare($delete_statement);
                    $sql_insert->execute();


                    $message = "Details successfully updated.";
                    $status = "success";
                    header("Location: $redirection_page&id=$delete_id");
                } else {
                ?>
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <div class="container-fluid">
                                            <div style="border-bottom: 5px solid black;" class="row justify-content-between">
                                                <div class="col-md-6 align-self-start">
                                                    <h3>MBBS (Guwahati Medical College)</h3>
                                                    <h4>M.D (Guwahati Medical College)</h4>
                                                </div>
                                                <div class="col-md-4 align-self-end">
                                                    <h4 style="text-align: right;" class="">Reg. No - 123</h4>
                                                    <h4 style="text-align: right;" class="">Ph. No - 6002130320</h4>
                                                </div>
                                            </div>
                                        </div>
                                        <form id="formID" class="m-t-30" method="POST" action="">
                                            <div class="col-md-12 mt-5">
                                                <div class="row d-flex justify-content-around">
                                                    <div class="col-md-5 form-group">
                                                        <label for="inv_phone"> Name</label>
                                                        <input name="field1" type="text" class="form-control" id="field1">
                                                        <small id="emailHelp" class="form-text text-muted"></small>
                                                    </div>
                                                    <div class="col-md-5 form-group">
                                                        <label for="inv_phone"> Date</label>
                                                        <input name="field2" type="date" class="form-control" id="field1">
                                                        <small id="emailHelp" class="form-text text-muted"></small>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="row d-flex justify-content-around">
                                                    <div class="col-md-5 form-group">
                                                        <label for="inv_phone"> Age,Gender</label>
                                                        <input name="field1" type="text" class="form-control" id="field1">
                                                        <small id="emailHelp" class="form-text text-muted"></small>
                                                    </div>
                                                    <div class="col-md-5 form-group">
                                                        <label for="inv_phone"> Weight</label>
                                                        <input name="field2" type="text" class="form-control" id="field1">
                                                        <small id="emailHelp" class="form-text text-muted"></small>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="row d-flex justify-content-around">
                                                    <div class="col-md-5 form-group">
                                                        <label for="inv_phone"> Clinical Description</label>
                                                        <input name="field1" type="text" class="form-control" id="field1">
                                                        <small id="emailHelp" class="form-text text-muted"></small>
                                                    </div>
                                                    <div class="col-md-5 form-group">
                                                        <label for="inv_phone"> Advice</label>
                                                        <input name="field1" type="text" class="form-control" id="field1">
                                                        <small id="emailHelp" class="form-text text-muted"></small>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <button type="submit" name="submit" value="Submit" class="btn btn-primary btn-lg btn-block waves-effect waves-light m-1">Submit</button>

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

                <?php
                };
                ?>


            </div><!-- End Row-->


        </div><!--End content-wrapper-->
        <!--Start Back To Top Button-->
        <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
        <!--End Back To Top Button-->