<?php

ob_start();
session_start();





/*
 * required files
 */
require_once ('../models/PHP-MySQLi-Database-Class/MysqliDb.php');
require_once("../models/config.php");
require_once("../models/functions.php");





/*
 * if user is not logged in redirect to login
 */
if ((!isset($_SESSION['sess_user_id']) || (trim(isset($_SESSION['sess_user_id'])) == ''))) {
  header("location: index.php");
  exit();
} else {
  /*
   * set session variables
   */
  $user_id = $_SESSION['sess_user_id'];
  $username = $_SESSION['sess_username'];
  $user_email = $_SESSION['sess_user_email'];
}


$subject = $_POST['edit_name'];
$email = $_POST['edit_email'];
$body = $_POST['edit_body'];

$data = Array(
    'subject' => $subject,
    'email' => $email,
    'body' => $body,
    'is_sent' => 0,
);


if ($db->insert('emails', $data)) {
  echo '<hr style="margin:7px 0"/><div><b>Message at ' . date('h:i') . ':</b> <br>Subject : ' . $subject . '<br>Email : ' . $email . '<br>Status: Scheduled to sent</div>';
} else {
  echo '<hr style="margin:7px 0"/><div><b>Message at ' . date('h:i') . ':</b> <br>Subject : ' . $subject . '<br>Email : ' . $email . '<br>Status: Error in Sending</div>';
}
