<?php
// modify below for filtering
session_start();
require 'Post.php';
include_once 'logging.php';
_log('In save event');
$crudpath = $_SESSION['crudpath'];
	include_once 'Database2.php';
	

  // Instantiate DB & connect
     
try {
  $database = new Database2();
} catch (Exception $e) {
  _log('Save_Event Says: Error new Database2: ' . $e->getMessage());
  die();
}
try {
  $db = $database->connect();
} catch (Exception $e) {
  _log('Save_Event Says: Error connecting to database: ' . $e->getMessage());
  die();
}
try {
  $post = new Post($db);
 // $post = new Post($database->getConnection());
} catch (Exception $e) {
  _log('Save_Event Says: Error instantiating post object: ' . $e->getMessage());
  die();
}




	if(ISSET($_POST['save'])){
		_log('POST save set. ');
		$title = $_POST['title'];
		$event_url = $_POST['event_url'];
		$allDay = $_POST['allDay'];
		_log('allDay: '.$allDay);
		$ev_start = $_POST['ev_start'];
		$ev_end = $_POST['ev_end'];
		$details = nl2br($_POST['details']);
		$venue = $_POST['venue'];
		$venue_add = nl2br($_POST['venue_add']);
		$social_url = $_POST['social_url'];
		$sponsors = nl2br($_POST['sponsors']);
		$textColor = $_POST['textColor'];
		$borderColor = $_POST['borderColor'];
		$backgroundColor = $_POST['backgroundColor'];
		// add filter field here
		$query = "INSERT INTO `events2` (title, event_url, allDay, ev_start, ev_end, details, venue, venue_add, social_url, sponsors, textColor, borderColor, backgroundColor) VALUES(:title, :event_url, :allDay, :ev_start, :ev_end, :details, :venue, :venue_add, :social_url, :sponsors, :textColor, :borderColor, :backgroundColor)";
		$stmt = $db->prepare($query);
		$stmt->bindParam(':title', $title, PDO::PARAM_STR);
		$stmt->bindParam(':event_url', $event_url, PDO::PARAM_STR);
		$stmt->bindParam(':allDay', $allDay, PDO::PARAM_STR);
		$stmt->bindParam(':ev_start', $ev_start, PDO::PARAM_STR);
		$stmt->bindParam(':ev_end', $ev_end, PDO::PARAM_STR);
		$stmt->bindParam(':details', $details, PDO::PARAM_STR);
		$stmt->bindParam(':venue', $venue);
		$stmt->bindParam(':venue_add', $venue_add, PDO::PARAM_STR);
		$stmt->bindParam(':social_url', $social_url, PDO::PARAM_STR);
		$stmt->bindParam(':sponsors', $sponsors, PDO::PARAM_STR);
		$stmt->bindParam(':textColor', $textColor, PDO::PARAM_STR);
		$stmt->bindParam(':borderColor', $borderColor, PDO::PARAM_STR);
		$stmt->bindParam(':backgroundColor', $backgroundColor, PDO::PARAM_STR);
		//add filter field here
		$stmt->execute();
		$conn = null;
_log('New Event Saved...');
_log('----------------------------------------');
 echo "<script>alert('Your New Record Has Been Successfully Added!');</script>";
    echo "<script>window.location.href='$crudpath';</script>";
    exit;
	
	}else{
		_log('Save event says: save not set in POST');
	}

?>
