- блок, где показаны N последних ссылок
- добавление "навигации" в обсуждения товара
- модуль вывода сообщений-обсуждений без привязки к товару, т.е. всех сообщений сразу.
Тоже с навигацией и возможностью удаления сообщений
1. файл core/includes/product_discussion.php
1.1 вставляем в него нижеследующую функцию
function disc_getNavigation( $list,$productID)
{
$lim = 3; // Messages limit on page
$count = mysql_query("SELECT count(*) FROM ".DISCUSSIONS_TABLE." WHERE productID=".$productID);
$count = mysql_result($count, 0, 0);
$total = intval(($count - 1) / $lim) + 1;
$list = intval($list);
if(empty($list) or $list < 0) $list = 1;
if($list > $total) $list = $total;
$start = $list * $lim - $lim;
if($total > 1)
{
$url = "product_".$productID.".html&discuss=yes";
if ($list != 1) $pervpage = '<a href="'.$url.'&list=1"><<<</a> <a href= "'.$url.'&list='.($list - 1).'"><</a>';
if ($list != $total) $nextpage = ' <a href="'.$url.'&list='.($list + 1).'">></a> <a href="'.$url.'&list='.$total. '">>>></a>';
if($list - 2 > 0) $page2left = ' <a href="'.$url.'&list='. ($list - 2).'">'. ($list - 2) .'</a> | ';
if($list - 1 > 0) $page1left = '<a href="'.$url.'&list='. ($list - 1) .'">'. ($list - 1) .'</a> | ';
if($list + 2 <= $total) $page2right = ' | <a href="'.$url.'&list='. ($list + 2) .'">'. ($list + 2) .'</a>';
if($list + 1 <= $total) $page1right = ' | <a href="'.$url.'&list='. ($list + 1) .'">'. ($list + 1) .'</a>';
$navstr = "<br /><center>";
$navstr .= $pervpage.' '.$page2left.$page1left.'<b>'.$list.'</b>'.$page1right.$page2right.' '.$nextpage;
$navstr .= "</center><br />";
}
$result[0] = $navstr;
$result[1] = $start;
$result[2] = $lim;
return $result;
}
1.2. изменяем нижеследующее.
Закомментированное это старый код, а не закомментрованное - новый.
#$q = db_query(
#"select Author, Body, add_time, DID, Topic FROM ".DISCUSSIONS_TABLE.
#" WHERE productID=".$productID." ORDER BY add_time DESC");
$nav = disc_getNavigation($_GET["list"], $productID);
$smarty->assign("nav", $nav[0]);
$q = db_query("select Author, Body, add_time, DID, Topic FROM ".DISCUSSIONS_TABLE.
" WHERE productID=".$productID." ORDER BY add_time DESC LIMIT ".$nav[1].",".$nav[2]);
2. файл product_discussion.tpl.html
вставляем {$nav} до и после секции с дискуссией.
{$nav}
{section name=i loop=$product_reviews}
..................
{/section}
{$nav}
3. блок, показывающий последние N сообщений в дискуссиях, откуда можно перейти на выбранную дисуссию
либо на общую таблицу всех дискуссий. его надо скопировать в /core/tpl/user/[шаблон]/block
и подключить в админке как "блок из файла".
{php}
$data = db_query("SELECT d.add_time, d.productID, d.body, d.topic, p.name FROM ".DISCUSSIONS_TABLE." AS d
LEFT JOIN ".PRODUCTS_TABLE." AS p USING (productID)
ORDER BY DID DESC LIMIT 5");
while( $row[] = db_fetch_assoc( $data ))
$this->assign("disc_array", $row);
{/php}
{if $disc_array}
{section name=u loop=$disc_array}
{if $smarty.section.u.index ne 0}<br>{/if}
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" valign="top" width="100%">
<a href="{if $smarty.const.CONF_MOD_REWRITE eq 1}product_{$disc_array[u].productID}.html{else}index.php?product={$disc_array[u].productID}{/if}" class="cl12">{$disc_array[u].name|truncate:30}</a>
</td>
</tr>
<tr>
<td align="left" valign="top" style="padding-top: 1px;">{$disc_array[u].add_time}</td>
</tr>
<tr>
<td align="left" valign="top" width="100%">
<a href="{if $smarty.const.CONF_MOD_REWRITE eq 1}product_{$disc_array[u].productID}.html?discuss=yes{else}index.php?product={$disc_array[u].productID}&discuss=yes{/if}" class="cl12">{$disc_array[u].topic|truncate:30}</a>
<div class="fil1"></div>
{$disc_array[u].body|truncate:100}
</td>
</tr>
</table>
{/section}
<br>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" valign="top" width="100%"><a href="index.php?alldisc=yes" class="cl12">Все обсуждения</a>
</tr>
</table>
{else}
<div align="center">No messages</div>
{/if}
4. Все обсуждения "в одну кучу", а не "потоварно". С навигацией. Ссылка - index.php?alldisc=yes.
В вышеописанном блоке она уже есть. Если текущий логин админский, то можно удалять сообщения.
4.1 файл /core/includes/all_discussion.php:
<?php
if (isset($_GET["alldisc"]))
{
if (isset($_GET["remove_topic"]) && in_array(100, checklogin()))
{
discDeleteDiscusion( $_GET["remove_topic"] );
Redirect("index.php?alldisc=yes".(isset($_GET['list'])?("&list=".$_GET['list']):""));
}
$smarty->assign("main_content_template", "all_discussion.tpl.html");
$smarty->assign("product_name", "Все товары");
$q = db_query("select count(*) from ".DISCUSSIONS_TABLE);
$cnt = db_fetch_row($q);
if ($cnt[0])
{
$nav = all_getNavigation($_GET["list"]);
$smarty->assign("nav", $nav[0]);
$q = db_query("SELECT d.Author, d.Body, d.add_time, d.Topic, d.DID, d.productID, p.name FROM ".DISCUSSIONS_TABLE. " AS d
LEFT JOIN ".PRODUCTS_TABLE." AS p USING (productID)
ORDER BY add_time DESC LIMIT ".$nav[1].",".$nav[2]);
$result = array();
while ($row = db_fetch_row($q))
{
$row["add_time"]= format_datetime( $row["add_time"] );
$result[] = $row;
}
$smarty->assign("product_reviews", $result);
$smarty->assign("list_num", (isset($_GET['list'])?("&list=".$_GET['list']):""));
}
else
{
$smarty->assign("product_reviews", NULL);
}
}
function all_getNavigation($list)
{
$lim = 3; // Messages limit on page
$count = mysql_query("SELECT count(*) FROM ".DISCUSSIONS_TABLE);
$count = mysql_result($count, 0, 0);
$total = intval(($count - 1) / $lim) + 1;
$list = intval($list);
if(empty($list) or $list < 0) $list = 1;
if($list > $total) $list = $total;
$start = $list * $lim - $lim;
if($total > 1)
{
$url = "index.php?alldisc=yes";
if ($list != 1) $pervpage = '<a href="'.$url.'&list=1"><<<</a> <a href= "'.$url.'&list='.($list - 1).'"><</a>';
if ($list != $total) $nextpage = ' <a href="'.$url.'&list='.($list + 1).'">></a> <a href="'.$url.'&list='.$total. '">>>></a>';
if($list - 2 > 0) $page2left = ' <a href="'.$url.'&list='. ($list - 2).'">'. ($list - 2) .'</a> | ';
if($list - 1 > 0) $page1left = '<a href="'.$url.'&list='. ($list - 1) .'">'. ($list - 1) .'</a> | ';
if($list + 2 <= $total) $page2right = ' | <a href="'.$url.'&list='. ($list + 2) .'">'. ($list + 2) .'</a>';
if($list + 1 <= $total) $page1right = ' | <a href="'.$url.'&list='. ($list + 1) .'">'. ($list + 1) .'</a>';
$navstr = "<br /><center>";
$navstr .= $pervpage.' '.$page2left.$page1left.'<b>'.$list.'</b>'.$page1right.$page2right.' '.$nextpage;
$navstr .= "</center><br />";
}
$result[0] = $navstr;
$result[1] = $start;
$result[2] = $lim;
return $result;
}
?>
4.2 файл /core/tpl/user/[шаблон]/all_discussion.tpl.html:
{include file="header.tpl.html" header="`$smarty.const.DISCUSSION_TITLE`: Все продукты"}
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td class="hmin" align="left">
{if $product_reviews ne NULL}
{$nav}
{section name=i loop=$product_reviews}
{if $smarty.section.i.index ne 0}
<div class="fil1 white"></div>
{/if}
<table cellspacing="1" cellpadding="0" width="100%" class="gre">
<tr>
<td class="lt padt" valign="middle" align="right" nowrap="nowrap">Товар:</td>
<td width="99%" class="padt" align="left"><a href="product_{$product_reviews[i].productID}.html"><b>{$product_reviews[i].name}</b></td>
</tr>
<tr>
<td class="lt padt" valign="middle" align="right" nowrap="nowrap">{$smarty.const.DISCUSSION_SUBJECT}:</td>
<td width="99%" class="padt" align="left"><b>{$product_reviews[i].Topic}</b></td>
</tr>
<tr>
<td class="lt padt" valign="middle" align="right" nowrap="nowrap">{$smarty.const.DISCUSSION_NICKNAME}:</td>
<td width="99%" class="padt" align="left">{$product_reviews[i].Author}</td>
</tr>
<tr>
<td class="lt padt" valign="middle" align="right" nowrap="nowrap">{$smarty.const.DISCUSSION_DATE}:</td>
<td width="99%" class="padt" align="left">{$product_reviews[i].add_time}</td>
</tr>
<tr>
<td class="lt padt" valign="middle" align="right" nowrap="nowrap">{$smarty.const.DISCUSSION_BODY}:</td>
<td width="99%" class="padt" align="left">{$product_reviews[i].Body}</td>
</tr>
{if $isadmin eq "yes"}
<tr>
<td class="padt" valign="middle" align="right" nowrap="nowrap"> </td>
<td width="99%" class="padt" align="left"><a href="index.php?alldisc=yes&remove_topic={$product_reviews[i].DID}{$list_num}">{$smarty.const.DISCUSSION_DELETE_POST_LINK}</a></td>
</tr>
{/if}
</table>
{/section}
{$nav}
{else}
<div align="center" class="padt">{$smarty.const.DISCUSSION_NO_POSTS_ON_ITEM_STRING}</div>
{/if} </td>
</tr>
</table>
4.3 если хотим привязывать показ (или непоказ) в админке каких-либо блоков к этому шаблону,
то в файл core/tpl/admin/conf_blocks_edit.tpl.html после строки
<option value="visit_history.tpl.html" {if in_array("visit_history.tpl.html", $blocks_edit.pages)}selected{/if}>{$smarty.const.BLOCK_EDIT_PAGE_35}</option>
добавляем строку
<option value="all_discussion.tpl.html" {if in_array("all_discussion.tpl.html", $blocks_edit.pages)}selected{/if}>Все дискуссии</option>
Посмотреть пример работы, как всегда, можно на http://cpu.badisoft.ru, справа внизу