<?php require ("header.php")?>


     
     
 

   <?php
 
// Ensure $id is defined and is numeric
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die('Invalid ID');
}
$id = (int) $_GET['id'];

// Fetch message
$stmt = $pdo->prepare("SELECT * FROM message WHERE id = ?");
$stmt->execute([$id]);
$ordrow = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$ordrow) {
    die("Message not found.");
}

// Fetch settings
$settingsStmt = $pdo->query("SELECT * FROM settings ORDER BY id DESC LIMIT 1");
$settings = $settingsStmt->fetch(PDO::FETCH_ASSOC);

// Generate ticket ID
$ticket_id = rand(10000000000000, 100000000000000);
?>
 



<div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title">Resend Message</h4>
                        <div class="ml-auto text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                                    <li class="breadcrumb-item active" aria-current="page">Message Details</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>

            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
               
                <?php
                       if(isset($sucess)){
                            echo $sucess;
                        }
                        ?>
           <?php
// Assume $pdo is your active PDO connection
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

$stmt = $pdo->prepare("SELECT * FROM message WHERE id = ?");
$stmt->execute([$id]);
$ordrow = $stmt->fetch(PDO::FETCH_ASSOC);

if ($ordrow):
?>

<div class='card'>
    <div class='card-body wizard-content'>
        <h4 class='card-title'>Reply messages</h4>

        <form class='form-horizontal' action='' method='post'>
            <div class='card-body'>

                <input type='hidden' class='form-control' name='id' value="<?= htmlspecialchars($ordrow['log_id']) ?>" readonly>

                <div class='form-group row'>
                    <label class='col-sm-3 text-right control-label col-form-label'>Name</label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='name' value="<?= htmlspecialchars($ordrow['name']) ?>" readonly>
                    </div>
                </div>

                <div class='form-group row'>
                    <label class='col-sm-3 text-right control-label col-form-label'>Email</label>
                    <div class='col-sm-9'>
                        <input type='email' class='form-control' name='email' value="<?= htmlspecialchars($ordrow['email']) ?>" readonly>
                    </div>
                </div>

                <div class='form-group row'>
                    <label class='col-sm-3 text-right control-label col-form-label'>Mobile Number</label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='phone' value="<?= htmlspecialchars($ordrow['phone']) ?>">
                    </div>
                </div>

                <div class='form-group row'>
                    <label class='col-sm-3 text-right control-label col-form-label'>Title</label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='title' value="RE:<?= htmlspecialchars($ordrow['title']) ?>">
                    </div>
                </div>

                <div class='form-group row'>
                    <label class='col-sm-3 text-right control-label col-form-label'>Message</label>
                    <div class='col-sm-9'>
                        <textarea name='msg' id='editor1' class='form-control'><?= htmlspecialchars($ordrow['msg']) ?></textarea>
                    </div>
                </div>

                <input type="hidden" name="date" value="<?= date("jS F Y g.iA") ?>" readonly>

                <?php
                // Fetch settings
                $settings = $pdo->query("SELECT * FROM settings ORDER BY id DESC LIMIT 1")->fetch(PDO::FETCH_ASSOC);
                if ($settings):
                ?>
                    <input type='hidden' name='cname' value="<?= htmlspecialchars($settings['domain_name']) ?>">
                    <input type='hidden' name='cemail' value="<?= htmlspecialchars($settings['email2']) ?>">
                    <input type='hidden' name='cphone' value="<?= htmlspecialchars($settings['phone']) ?>">
                <?php endif; ?>

                <div class="col-md-12">
                    <div class="form-group app-label">
                        <label class="control-label">Ticket ID</label>
                        <input name="ticket_id" type="number" class="form-control" value="<?= rand(10000000000000, 100000000000000) ?>" readonly>
                    </div>
                </div>

            </div>

            <div class='border-top'>
                <div class='card-body'>
                    <button type='submit' name='action' class='btn btn-primary'>Submit</button>
                </div>
            </div>
        </form>
    </div>
</div>

<?php else: ?>
    <div class="alert alert-danger">Message not found.</div>
<?php endif; ?>




                    </div>
                </div>
             
             
            </div>
           
           
           <?php require ("footer.php")?>
           
           
           
           
               