Файл: sources/subcat.php
Строк: 216
<?php
if (!defined('VAPHP'))
{
die("Этот файл недоступен.");
}
class subcat extends base
{
function subcat()
{
global $FORM, $TMPL, $LNG, $DB, $CONF;
if (isset($FORM['id']) and !empty($FORM['id']))
{
$id = intval($FORM['id']);
list($catid, $catname) = $DB->fetch("SELECT {$CONF['sql_prefix']}_cat.id, {$CONF['sql_prefix']}_cat.name FROM {$CONF['sql_prefix']}_cat, {$CONF['sql_prefix']}_subcat WHERE {$CONF['sql_prefix']}_cat.id={$CONF['sql_prefix']}_subcat.idcat and {$CONF['sql_prefix']}_subcat.id='$id'", __FILE__, __LINE__);
list($subcatname) = $DB->fetch("SELECT name FROM {$CONF['sql_prefix']}_subcat WHERE id = '$id'", __FILE__, __LINE__);
if (empty($subcatname))
{
$TMPL['header'] = $LNG['g_error'];
$base = new base;
$base->error($LNG['g_page_empty']);
}
$TMPL['header'] = "{$subcatname}";
$TMPL['navmenu'] = "<span class="PathMenu"><a href="{$CONF['site_url']}">{$LNG['main_menu_index']}</a> <img src="{$CONF['skins_image']}/bullet.gif"> <a href="{$CONF['site_url']}/cat/{$catid}">$catname</a> <img src="{$CONF['skins_image']}/bullet.gif"> $subcatname</span>";
list($num_sites) = $DB->fetch("SELECT COUNT(*) FROM {$CONF['sql_prefix']}_sites WHERE idsubcat='{$id}' and visib = '1'", __FILE__, __LINE__);
if ($FORM['pp'])
{
$pp = intval($FORM['pp']);
if ($pp < $CONF['sites_per_page'][0]) {$pp = $CONF['sites_per_page'][0];}
}
else {$pp = $CONF['sites_per_page'][0];}
foreach($CONF['sites_per_page'] as $value)
{
if ($pp == $value) {$per_page_menu.= "<b>$value</b> ";}
else{
$per_page_menu.=<<<EndHTML
<a href="{$CONF['site_url']}/subcat/{$id}/$value">{$value}</a>
EndHTML;
}
}
if (isset($FORM['p']))
{
$p = intval ($FORM['p']);
if ($p > ceil($num_sites/$pp) || $p < 1) {$p=1;} //если номер страницы больше максимально возможного - присваиваем ему значение 1
$start = intval($p - 1);
if ($start < 0) $start=0;
$start = $start * $pp;
}
else
{
$p = 1;
$start = 0;
}
if($num_sites > $pp) //проверка необходимости в постраничном выводе
{
$TMPL['page_menu'] = '';
$num_page = ceil($num_sites/$pp); //количество страниц
$PrevPage = $p-1;
$NextPage = $p+1;
//определение переменных для счетчика цикла
if($num_page > $CONF['lenght_pp_block']){
$left_pages = floor(($CONF['lenght_pp_block']-1)/2);
$number_start_page = $p-$left_pages;
if($number_start_page <= 0) {$number_start_page = 1;}
$number_end_page = $number_start_page + $CONF['lenght_pp_block']-1;
if($number_end_page > $num_page) {$number_end_page = $num_page; $number_start_page = $number_end_page-$CONF['lenght_pp_block']+1;}
}else
{
$number_start_page = 1;
$number_end_page = $num_page;
}
//само построение кода постраничного вывода
if($number_start_page > 1) {
$prev_page = $number_start_page-1;
$TMPL['page_menu'] .= "<a href="{$CONF['site_url']}/subcat/{$id}/1/$pp">1</a> "; //ссылка на самую первую страницу
$TMPL['page_menu'] .= "<a href="{$CONF['site_url']}/subcat/{$id}/{$prev_page}/$pp">...</a> "; //
}
for($i=$number_start_page; $i<=$number_end_page; $i++)
{
if($i == $p)
$TMPL['page_menu'] .= "<b>$i</b> ";
else
$TMPL['page_menu'] .= "<a href="{$CONF['site_url']}/subcat/{$id}/$i/$pp">$i</a> ";
}
if($number_end_page < $num_page) {
$next_page = $number_end_page+1;
$TMPL['page_menu'] .= "<a href="{$CONF['site_url']}/subcat/{$id}/{$next_page}/$pp">...</a> ";
$TMPL['page_menu'] .= "<a href="{$CONF['site_url']}/subcat/{$id}/{$num_page}/$pp">$num_page</a> ";
}
if($p <= 1) {$TMPL['AtStart'] = "<span class=AtStart><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_prev.gif"></span>";}
else {$TMPL['AtStart'] = "<a href="{$CONF['site_url']}/subcat/{$id}/{$PrevPage}/{$pp}" class=AtStart><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_prev_act.gif"></a>";}
if($p >= $num_page) {$TMPL['AtEnd']="<a class=AtEnd><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_next.gif"></a>";}
else {$TMPL['AtEnd']="<a href="{$CONF['site_url']}/subcat/{$id}/{$NextPage}/{$pp}" class=AtEnd><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_next_act.gif"></a>";}
$TMPL['page_menu'] = $TMPL['AtStart'].$TMPL['page_menu'].$TMPL['AtEnd'];
$TMPL['page_menu']="<div class="PagingStrip">".$TMPL['page_menu']."</div>";
//конец построение кода постраничного вывода
}
$num_first_site = $start + 1;
$num_final_site = $num_first_site + $pp - 1;
if ($num_final_site > $num_sites) {$num_final_site = $num_sites;}
$LNG['g_number_of_all'] = sprintf($LNG['g_number_of_all'], $num_first_site, $num_final_site, $num_sites);
if ($num_sites != 0) $TMPL['list_sites'] .= <<<EndHTML
<tr><td colspan="2">
<table width="100%" border=0>
<tr>
<td width="33%"></td>
<td width="33%" align="center"><span class="GreyTextNormal">{$LNG['g_number_of_all']}</span></td>
<td width="33%" align="right"><span class="GreyTextSmall">{$LNG['g_sites_per_page']} <img src="{$CONF['skins_image']}/arrow_right.gif"> $per_page_menu</span></td>
</tr>
</table>
</td></tr>
<tr><td colspan="2"><hr width=100% size="1" class="SeparatorHr2"></td></tr>
<tr><td colspan="2" align=center>{$TMPL['page_menu']}</td></tr>
<tr><td colspan="2"><hr width=100% size="1" class="SeparatorHr"></td></tr>
EndHTML;
$result = $DB->select_limit("SELECT id, banner_url, URL, name, description, num_views, add_admin FROM {$CONF['sql_prefix']}_sites WHERE idsubcat='{$id}' and visib = '1' order by {$CONF['site_sorting_field']} {$CONF['site_sorting']}", $pp, $start, __FILE__, __LINE__);
while($result_sites_fetch=mysql_fetch_array($result))
{
if ($result_sites_fetch['add_admin']){$html_cod = $result_sites_fetch['description']; $href_button = "{$CONF['site_url']}/site/{$result_sites_fetch['id']}";}
else
{
if(strlen($result_sites_fetch['description']) > $CONF['cut_descr'] and $CONF['cut_descr']!=0)
{
$TMPL['meta_description']=substr($result_sites_fetch['description'], 0, 160);
$TMPL['meta_description'] = substr($TMPL['meta_description'],0,strrpos($TMPL['meta_description']," "));
$TMPL['meta_keywords']="";
$description = substr($result_sites_fetch['description'], 0, $CONF['cut_descr']);
$description .= "...";
$description =$this->fnrepl($description);
$html_cod="<a href="{$CONF['site_url']}/site/{$result_sites_fetch['id']}"><b>{$result_sites_fetch['name']}</b></a><br>{$description}";
}else
{
$html_cod="<a href="{$CONF['site_url']}/site/{$result_sites_fetch['id']}"><b>{$result_sites_fetch['name']}</b></a><br>{$result_sites_fetch['description']}";
}
$href_button = "{$CONF['site_url']}/site/{$result_sites_fetch['id']}";
}
$TMPL['list_sites'] .= <<<EndHTML
<tr>
<td><a href="{$href_button}"><img src="{$result_sites_fetch['banner_url']}" width="{$CONF['max_banner_width']}" height="{$CONF['max_banner_height']}" border="0" title="{$result_sites_fetch['name']}"></a></td>
<td width=100%>
<table width=100%>
<tr><td colspan="2">$html_cod</td></tr>
<tr>
<td width=50%>{$LNG['g_views']}: {$result_sites_fetch['num_views']}</td>
<td><a href="{$CONF['site_url']}/site/{$result_sites_fetch['id']}">{$LNG['g_detail']} >></a></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2"><hr width=100% size="1" class="SeparatorHr"></td></tr>
EndHTML;
}
$TMPL['content'] = $this->do_skin('list_sites');
}
else
{
$TMPL['header'] = $LNG['g_error'];
$base = new base;
$base->error($LNG['g_page_empty']);
}
}
}
?>