<?php
class Comment
{
	function Overview($where='',$object='')
	{
		if(isset($_POST['save']) && $_POST['save']==1)
		{
			foreach($_POST['CId'] as $cid => $pid)
			{
				if(!empty($_POST['Autor'][$cid]))
				{
					$GLOBALS['db']->Query("UPDATE " . PREFIX . "_kommentare
					 SET 
						Autor = '" . @$_POST['Autor'][$cid] . "',
						Eintrag = '" . @$_POST['Eintrag'][$cid] . "',
						Aktiv = '" . @$_POST['Aktiv'][$cid] . "',
						Autor_Web = '" . @$_POST['Autor_Web'][$cid] . "',
						Autor_Herkunft = '" . @$_POST['Autor_Herkunft'][$cid] . "' 
					 WHERE 
						Id = '{$cid}'");
					
					if(isset($_POST['del'][$cid]) && $_POST['del'][$cid]==1)
					{
						$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_kommentare WHERE Id = '{$cid}'");
					}
				}
			}
			Logger('User ' . $_SESSION['user_name'] . ' edit ' . strtoupper($where) . '-Comment', '3', $_SESSION['benutzer_id']);
			echo '<script>window.opener.location.reload();</script>';
		}
		
		
		$comments = array();
		
		$sql = $GLOBALS['db']->Query("SELECT Id FROM " . PREFIX . "_kommentare WHERE Bereich='{$where}' AND Objekt_Id='{$object}' ORDER BY Id DESC");
		$limit = 15;
		$num = $sql->numrows();
		$seiten = ceil($num / $limit);
		$a = prepage() * $limit - $limit;
		
		$sql = $GLOBALS['db']->Query("SELECT * FROM " . PREFIX . "_kommentare WHERE Bereich='{$where}' AND Objekt_Id='{$object}' ORDER BY Id DESC LIMIT $a,$limit");
		while($row = $sql->fetchrow())
		{
			array_push($comments, $row);
		}
		
		if($num>$limit)$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, '', "<a class=\"page_navigation\" href=\"index.php?do=comments&amp;where={$where}&amp;object={$object}&noframes=1&amp;page={s}\">{t}</a> "));
		$GLOBALS['tmpl']->assign('comments', $comments);
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/comments/comments.tpl'));
	}
}
?>