<?php
session_start();
$crudpath = $_SESSION['crudpath'];
require_once 'Database2.php';
require_once 'Post.php';
include_once 'logging.php';

	if(ISSET($_POST['update'])){
		_log('Update_Event POST Update set for: '.$_POST['id']);
		$id = $_POST['id'];
		$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
 // Instantiate DB & connect
  $database = new Database2();
  $db = $database->connect();
  // Instantiate blog post object
  $post = new Post($db);
		$query = "UPDATE `events2` SET `title` = :title, `event_url` = :event_url, `allDay` = :allDay,`ev_start` = :ev_start, `ev_end` = :ev_end, `details` = :details, `venue` = :venue, `venue_add` = :venue_add, `social_url` = :social_url, `sponsors` = :sponsors, `textColor` = :textColor, `borderColor` = :borderColor, `backgroundColor` = :backgroundColor WHERE `id` = :id";
		$stmt = $db->prepare($query);
		$stmt->bindParam(':id', $id, PDO::PARAM_INT);
		$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, PDO::PARAM_STR);
		$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);
		$stmt->execute();
		// add filter field here
		$conn = null;
_log('Record: '.$_POST['id']. ' Updated.');
_log('----------------------------------------');
 echo "<script>alert('Your Table Has Been Successfully Updated!');</script>";
    echo "<script>window.location.href='$crudpath';</script>";
    exit;
		}
?>
