<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 11/21/2018	ELL
//
	include ("check_session.php");
	
	$table = $_REQUEST['table'];
	$id = $_REQUEST['id'];
	
	if (!isset($table) || !isset($id) || ($table == "") || ($id == ""))	{
		echo -1;
		exit;
	}
	
	$query = "SHOW COLUMNS FROM `" . $table . "` LIKE 'marked_read'";
	$result = $bwb_dbh->query($query);
	if ($result->rowCount() < 1)	{
		$sql = "ALTER TABLE `" . $table . "` ADD `marked_read` INT NOT NULL DEFAULT 0";
		$cnt = $bwb_dbh->exec($sql);
	}
		
	$query = "SELECT * FROM " . $table . " WHERE id = " . $id;
	$result = $bwb_dbh->query($query);
	if ($result->rowCount() > 0)	{
		$row = $result->fetch(PDO::FETCH_ASSOC);
		$marked_read = $row['marked_read'];
		if ($marked_read == 0)
			$sql = "UPDATE " . $table . " SET marked_read = 1 WHERE id = " . $id;
		else
			$sql = "UPDATE " . $table . " SET marked_read = 0 WHERE id = " . $id;
	}
	else	{
		echo -1;
		exit;
	}
	$cnt = $bwb_dbh->exec($sql);
	
	echo $cnt;
?>