<?php
require_once('../config/config.php');
require_once('../foo/functions.php');
session_start();

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

if ($_POST['alrt_subject'] == ""){ redirect('alerts.php?error=' . urlencode('Enter a subject for your alert'));}
elseif ($_POST['alrt_cnt'] == ""){ redirect('alerts.php?error=' . urlencode('Your message cannot be empty'));}
else{
$alrt_subject = $_POST['alrt_subject'];
$alrt_cnt = $_POST['alrt_cnt'];
$alrt_rcvr = $_POST['alrt_rcvr'];
$alrt_read = $_POST['alrt_read'];
$rcvr_name = $_POST['alrt_rcvr'];

dbconnect();
$stmt = $pdo->prepare('INSERT INTO '.ALERT_TABLE_NAME.' (alrt_subject, alrt_cnt, alrt_rcvr, alrt_read, alrt_date, rcvr_name) VALUES (:subject, :cnt, :rcvr, :read, NOW(), :name)');

$stmt->execute(array(':subject' => $alrt_subject, ':cnt' => $alrt_cnt, ':rcvr' => $alrt_rcvr, ':read' => $alrt_read, ':name' => $rcvr_name));
if ($pdo->lastInsertId())

log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $rcvr_name, 'Alert Created Successfully');
redirect('alerts.php?msg=' . urlencode('Alert Successfully Sent'));		
}
}

?>