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

if (isset($_GET['id'])) {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);

    // DELETE message
    $stmt = $pdo->prepare("DELETE FROM message WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);

    $delete = 1;
}

if (isset($_GET['func'])) {

    if ($_GET['func'] != "conf") {
        header("Location: " . $config_basedir . "../admin/outbox.php");
        exit();
    }

    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);

    // UPDATE message as verified
    $stmt = $pdo->prepare("UPDATE message SET verified = 2 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);

    header("Location: " . $config_basedir . "../admin/outbox.php");
    exit();
}
?>

     
    <div class="main-panel">
        <div class="content bg-light">
            <div class="page-inner">
                <div class="mt-2 mb-4">
                    <h1 class="title1 text-dark">OUTBOX</h1>
                </div>
                <div>
    </div>                <div>
    </div>                
               
               
               
               
                <div class="mb-5 row">
                    <div class="col-md-12 ">
                        <!--<div class="card shadow p-4 bg-light">-->
                           
                           
   
          

                           
           
           <div class="page-breadcrumb">
    <div class="row">
        <div class="col-12 d-flex no-block align-items-center">
            <h4 class="page-title">OUTBOX MAILS (
                <?php

                $stmt = $pdo->prepare("SELECT COUNT(id) as total FROM message WHERE status = 1");
                $stmt->execute();
                $result = $stmt->fetch(PDO::FETCH_ASSOC);
                echo $result['total'];
                ?>
            )</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">outbox</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>

        

  <div class='container-fluid'>
               
               
                <div class='row'>
                    <div class='col-md-10'>
                        <div class=''>
                           
                            <div class='card-body'>
                                <h4 class='card-title m-b-0'>Recent Posts</h4>
                            </div>
                           <div class='comment-widgets scrollable'>
                                 <!--Comment Row -->
                               
                               
                               
               <?php

try {
    $stmt = $pdo->prepare("SELECT * FROM message ORDER BY id DESC");
    $stmt->execute();
    $messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $numrows = count($messages);

    if (isset($delete)) {
        echo "<center>
                <span style='color:red'>Successfully deleted mail from outbox</span><br><br>
                <div class='loader'></div>
                <meta http-equiv='refresh' content='5;url=outbox.php'/>
              </center>";
    }

    foreach ($messages as $row) {
        if ($row['status'] == 1) {
            echo "<div class='d-flex flex-row comment-row m-t-0'>
                    <div class='p-2'>";

            if ($row['status'] > 0) {
                echo "<img src='../accounts/upload/photo/default.png' class='rounded-circle' alt='" . htmlspecialchars($row['username']) . "' style='width:50px;height:50px'>";
            } elseif ($row['status'] == 0) {
                echo "<img src='../" . htmlspecialchars($row['P_location']) . "' class='rounded-circle' alt='" . htmlspecialchars($row['username']) . "' style='width:50px;height:50px'>";
            }

            echo "</div>
                    <div class='comment-text w-100'>
                        <h6 class='font-medium'>" . htmlspecialchars($row['name']) . "</h6>
                        <span class='m-b-15 d-block'>" . htmlspecialchars($row['msg']) . "</span>
                        <div class='comment-footer'>
                            <span class='btn btn-success btn-sm float-right'>" . htmlspecialchars($row['date']) . "</span>
                            <a type='button' class='btn btn-info btn-sm' href='reply_outbox.php?id=" . $row['id'] . "'>View</a>
                            <a type='button' class='btn btn-success btn-sm' href='reply_msg.php?id=" . $row['id'] . "'>Reply</a>
                            <a type='button' class='btn btn-danger btn-sm' href='outbox.php?id=" . $row['id'] . "'>Delete</a>
                        </div>
                    </div>
                </div>";
        }
    }
} catch (PDOException $e) {
    echo "Error fetching messages: " . $e->getMessage();
}
?>

                                
                                
                                </div></div></div>
                            </div>
                        </div>
                          <!-- accoridan part -->
                          
                          
                          
                       
               </div></div></div></div></div>
               
            </div>
           
             <?php require ("footer.php")?>