function tag($module, $template, $sql, $page = 0, $number = 10, $setting = array(), $ccatid = 0)
{
global $db, $CATEGORY, $MODULE, $URLRULE, $PHPCMS, $MODEL,$catid;
if($sql)
{
@include_once PHPCMS_ROOT.$MODULE[$module]['path'].'include/output.func.php';
$offset = 0;
if($page !== 0)
{
$page = max(intval($page), 1);
$offset = $number*($page-1);
$sql_count = preg_replace("/^SELECT([^(]+)\s*FROM(.+)(ORDER BY.+)$/i", "SELECT COUNT(*) AS `count` FROM\\2", $sql);
$count = cache_count($sql_count);
$urlruleid = isset($setting['urlruleid']) ? intval($setting['urlruleid']) : 0;
$urlrule = $urlruleid > 0 ? $URLRULE[$urlruleid] : '';
$ccatid=($ccatid===0)?$catid:$ccatid;
$pages = pages($count, $page, $number, $urlrule, $setting, $ccatid);
}
$i = 0;
$data = array();
$result = $db->query("$sql LIMIT $offset, $number");
while($r = $db->fetch_array($result))
{
$data[++$i] = $r;
}
$rows = $db->num_rows($result);
$db->free_result($result);
}
else
{
$data = array();
$number = $rows = $count = $page = 0;
$pages = '';
}
require_once template($module, $template, 1);
$func = '_tag_'.$module.'_'.$template;
$func($data, $number, $rows, $count, $page, $pages, $setting);
}
|