<?php
if (!defined('BLOCK_FILE')) {
	Header("Location: ../index.php");
	exit;
}

##  © Serg_pnz 
##  e-mail: print58@yandex.ru

/*-------------- настраиваемые параметры --------------*/

$strip = 50; #обрезка текста комментария
$limit = 10; #количество комментариев (тем)
$raz_tag = "<b><i><u>"; #разрешенные теги в комментарии. Набирать БЕЗ ПРОБЕЛОВ между тегами!

/*-------------- конец настраиваемые параметры --------------*/



global $prefix, $db;

$result = $db->sql_query("SELECT MAX(id) AS maxid, modul, cid  FROM ".$prefix."_comment GROUP BY modul, cid ORDER BY maxid DESC LIMIT $limit ");
while (list($maxid, $modul, $cid) = $db->sql_fetchrow($result)) {
	$mmaxid[] = $maxid;

	switch($modul) {
		case "voting":
	    $mVoting[] = "$cid";
		break;

		case "news":
		$mNews[] = "$cid";
	    break;
	
		case "files":
	    $mFiles[] = "$cid";
		break;

		case "pages":
		$mPages[] = "$cid";
		break;
	}
}

//--------- News
$const = sizeof ($mNews); 
if ($const>0) {
	$sql = " SELECT sid, title FROM ".$prefix."_stories WHERE ";
	for ($i=0; $i<($const-1); $i++) {
		$sql .= " sid='".$mNews[$i]."' OR ";
	}
	$sql .= " sid='".$mNews[$const-1]."' ";
	$result = $db->sql_query($sql);
	while(list($sid, $title) = $db->sql_fetchrow($result)) $mtNews[$sid] = $title;
}

//--------- Voting
$const = sizeof ($mVoting);
if ($const>0) {
	$sql = " SELECT poll_id, poll_title FROM ".$prefix."_survey WHERE ";
	for ($i=0; $i<($const-1); $i++) {
		$sql .= " poll_id='".$mVoting[$i]."' OR ";
	}
	$sql .= " poll_id='".$mVoting[$const-1]."' ";
	$result = $db->sql_query($sql);
	while(list($sid, $title) = $db->sql_fetchrow($result)) $mtVoting[$sid] = $title;
}

//--------- Files
$const = sizeof ($mFiles);
if ($const>0) {
	$sql = " SELECT lid, title FROM ".$prefix."_files WHERE ";
	for ($i=0; $i<($const-1); $i++) {
		$sql .= " lid='".$mFiles[$i]."' OR ";
	}
	$sql .= " lid='".$mFiles[$const-1]."' ";
	$result = $db->sql_query($sql);
	while(list($sid, $title) = $db->sql_fetchrow($result)) $mtFiles[$sid] = $title;
}

//--------- Pages
$const = sizeof ($mPages);
if ($const>0) {
	$sql = " SELECT pid, title FROM ".$prefix."_pages WHERE ";
	for ($i=0; $i<($const-1); $i++) {
		$sql .= " pid='".$mPages[$i]."' OR ";
	}
	$sql .= " pid='".$mPages[$const-1]."' ";
	$result = $db->sql_query($sql);
	while(list($sid, $title) = $db->sql_fetchrow($result)) $mtPages[$sid] = $title;
}

//---------- Сам блок
$sql = " SELECT cid, modul, date, name, comment FROM ".$prefix."_comment WHERE ";
for ($i=0; $i<($limit-1); $i++) {
	$sql .= " id='".$mmaxid[$i]."' OR ";
}
	$sql .= " id='".$mmaxid[$limit-1]."' ORDER BY id DESC ";

$i=0;
$result = $db->sql_query($sql);
while(list($cid, $modul, $date, $name, $comment) = $db->sql_fetchrow($result)) {
$i++;
$comment = preg_replace("#\[quote\](.*?)\[/quote\]#si","",$comment);
$comment = preg_replace("#\[php\](.*?)\[/php\]#si","",$comment);
$comment = preg_replace("#\[code\](.*?)\[/code\]#si","",$comment);
$comment = preg_replace("#\[hide\](.*?)\[/hide\]#si","",$comment);
$comment = cutstr(strip_tags(bb_decode($comment, ''), $raz_tag), $strip);

$date = format_time($date);

switch($modul) {
	case "voting":
    $link = "<a href=\"index.php?name=Voting&op=poll_result&poll_id=$cid#$cid\" title=\"".$mtVoting[$cid]."\">";
    break;

	case "news":
    $link = "<a href=\"index.php?name=news&op=view&id=$cid#$cid\" title=\"".$mtNews[$cid]."\">";
    break;
	
	case "files":
    $link = "<a href=\"index.php?name=Files&op=view_file&lid=$cid#$cid\" title=\"".$mtFiles[$cid]."\">";
	break;

	case "pages":
    $link = "<a href=\"index.php?name=Pages&op=page&pid=$cid#$cid\" title=\"".$mtPages[$cid]."\">";
	break;
}

$content .= "
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
	<tr style=\"padding-top: 7px;\">
		<td style=\"padding-right: 5px;\">"."$link"."<img src=\"images/blocks/$modul.gif\" border=\"0\"></a></td>
		<td width=\"100%\">$date <b>$name</b></td>
	</tr>
	<tr>
		<td colspan=\"2\">"."$link"."$comment</a></td>
	</tr>";
if ($i!=$limit) {$content .= "<tr><td colspan=\"2\"><hr width=\"90%\"></td></tr>";}
$content .= "</table>";
}

?>