<?php
if (!defined('BLOCK_FILE')) {
	Header("Location: ../index.php");
	exit;
}
#*******************************************
#
# ©2007 Serg_pnz. E-mail: print58@yandex.ru
#
#*******************************************

global $prefix, $db, $datetime;

# --------- настройки
$kol_news = 6; # количество новостей в блоке
$kol_stolb = 3; # количество колонок (столбцов) в блоке
$width_tablbloc = 97; # ширина таблицы блока в процентах

$width_stolb = $width_tablbloc/$kol_stolb."%"; # не править!!!
$width_tablbloc = $width_tablbloc."%"; # не править!!!
$kol_strok = $kol_news / $kol_stolb; # не править!!!

$kol_znakov = 450; #количество знаков в новости
$filtr = " AND s.topic<>'19' AND s.topic<>'20' ";# фильтр на категорию новостей, которую отображать не надо. если фильтр не нужен - закоментируйте эту строку.
$top_main = "s.time"; # порядок сортировки
$figdwidth = 120; # ширина превьюшки
$fidirectory = "";
# --------- конец настроек


$zap_stories=" SELECT s.sid, s.hometext, s.bodytext,  s.topic, s.time, s.title, t.topicid, t.topicname, t.topicimage, t.topictext FROM  ".$prefix."_stories AS s LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) WHERE time <= NOW() AND status='1' $filtr ORDER BY $top_main DESC  LIMIT  $kol_news ";

$content .="<table align=\"center\" width=\"$width_tablbloc\" border=\"1\" cellpadding=\"15\" cellspacing=\"1\" class=\"bgcolor1\">";

$i = 1;
$result = $db->sql_query($zap_stories);
while (list( $sid, $hometext, $bodytext,  $topic, $time, $title, $topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($result)){
	if ($i==1) {$content .= "<tr>";}

	$big_content = bb_decode (" $hometext  $bodytext ");
	preg_match('/<img(.*)>/sUi',$big_content,$match);
	$match1 = str_replace(">", " >", $match[0]);
	preg_match('/src=(.*) /sUi',$match1,$match2);
	$match3 = str_replace("src=", "", $match2[0]);
	$f_img = trim(str_replace("\"", "", $match3));
	
#	echo "<br><br><br>1111111 $i ".htmlspecialchars($match[0])."<br>5555555555555555 **".htmlspecialchars($match3)."**".htmlspecialchars($f_img)."***";
#	prem($match);
	$text = preg_replace("#<img(.*?)>#si","",bb_decode($hometext));
#	echo "<br> 222222 $i $text <br>";

$path_parts = pathinfo($f_img);

/*echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";*/
#PATHINFO_DIRNAME, PATHINFO_BASENAME и PATHINFO_EXTENSION

$name_tumb = "uploads/LastNewsImg/sid".$sid.".".$path_parts['extension']."";
if ( !file_exists($name_tumb) AND $f_img!="") {
	create_img_gd($f_img, $name_tumb, 103 );
}

//$big_content=" $hometext<br>$bodytext ";
//$big_content = bb_decode ($big_content);
//$big_content=cutstr(strip_tags($big_content, "<a><i><b><br>"),$kol_znakov);

formatTimestamp($time);

$content .= "<td align=\"left\" valign=\"top\" width=\"$width_stolb\">";

if (file_exists($name_tumb)) {
	$content .= "<table class=\"bgcolor3\"  style=\"padding-right: 15px; padding-bottom: 15px; padding-left: 15px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"left\"><tr><td>"
	."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/CaricaFoto.js\"></script>"
	."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowPic.js\"></script>"
	

	#."<img src=\"$name_tumb\" style=\"cursor: pointer;\" OnMouseOver=\"PicDivShow('".$f_img."');\" OnMouseOut=\"PicDivHide();\"  border=\"0\">"
	."<a href=\"javascript:CaricaFoto('".$f_img."')\" OnMouseOver=\"PicDivShow('".$f_img."');\" OnMouseOut=\"PicDivHide();\" border=\"0\" title=\"".$title."\"><img  border=\"0\" src=\"".$name_tumb."\" alt=\"".$title."\"></a>"

	."</td></tr></table>";
}

$content .= "<b><div class=\"bgcolor4\">$datetime<br>$title<br>Тема: $topicname</div></b><br>$text <a title=\"Подробнее\" href=\"index.php?name=News&op=article&sid=$sid\"><b><i>Подробнее&gt;&gt;&gt;</i></b></a></td>";
if ($i==$kol_stolb) {$content .= "</tr>"; $i=1;} else {$i++;}
}

$content .= "</table>";

$content .="<div align=\"right\"><a title=\"Смотреть все новости\" href=\"index.php?name=News\">Все новости&nbsp;&nbsp;</a></div>";

global $name;
if ($name!="Files") {$content .= "<div id=\"picDiv\" style=\"position: absolute; left: 525px; top: 180px; width: 200px; height: 200px; z-index: 1; display: none;\"><table class=\"bodyline\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"200\" width=\"200\"><tr class=\"bgcolor1\"><td align=\"center\" valign=\"middle\"><img src=\"images/load.gif\" id=\"picDivImg\"></td></tr></table></div>";}
?>