Location: PHPKode > scripts > Kemana Directory > module/portal/cat.php
<?php
//
$cat_id = get_param ('cid');
$p = get_param ('p');
if (empty ($cat_id)) redir ($config['site_url']);

// content
$sub_content = TRUE;
$tpl = load_tpl ('mod', 'module_portal_cat.tpl');

// create portal pages (cached with smartcache or radicalcache)
$txt['block_content'] = $txt['block_new'] = '';

// determine cat_image
$cat_img = '';
$rowi = sql_qquery ("SELECT cat_img, cat_struct_id FROM ".$db_prefix."pcategory WHERE cat_id='$cat_id' LIMIT 1");
if (empty ($rowi[0]))
{
	// no image for current cat, try top cat
	$f = explode (',', $rowi[1]);
	$top = $f[0];
	$rowii = sql_qquery ("SELECT cat_img FROM ".$db_prefix."pcategory WHERE cat_id='$top' LIMIT 1");
	if (!empty ($rowii[0])) $cat_img = $rowii[0]; else $cat_img = 'portal.jpg';
}
else
	$cat_img = $rowi[0];

// -- get latest entries
$foo = sql_multipage ($db_prefix.'ppage', 'page_id, page_image, page_title, page_summary', "cat_id='$cat_id'", 'page_id DESC', $p);
foreach ($foo as $row)
{
	// image
	$image = empty ($row['page_image']) ? $cat_img : $row['page_image'];
	$row['image'] = "<img src=\"public/thumb/$image\" alt=\"thumb\" align=\"left\" height=\"50\" />";
	$txt['block_new'] .= quick_tpl ($tpl_block['new'], $row);
}


// -- get sub content
$res = sql_query ("SELECT cat_id, cat_name, cat_img, cat_struct_id FROM ".$db_prefix."pcategory WHERE parent='$cat_id' ORDER BY cat_order");
while ($row = sql_fetch_array ($res))
{
	// -- get sub cat
	$c = $row['cat_id'].',';
	$foo_cat = array ($row['cat_id'] => $row['cat_name']);
	$foo_img = array ($row['cat_id'] => $row['cat_img']);

	$res2 = sql_query ("SELECT cat_id, cat_name, cat_img FROM ".$db_prefix."pcategory WHERE cat_struct_id LIKE '$row[cat_struct_id],%'");
	while ($row2 = sql_fetch_array ($res2))
	{
		$c .= $row2['cat_id'].',';
		$foo_cat[$row2['cat_id']] = $row2['cat_name'];
		$foo_img[$row2['cat_id']] = $row2['cat_img'];
	}
	$c = substr ($c, 0, -1);
	
	// -- get latest content
	$first = TRUE; $rest = FALSE;
	$res1 = sql_query ("SELECT page_id, cat_id, page_title, page_summary, page_image FROM ".$db_prefix."ppage WHERE cat_id IN ($c) ORDER BY page_id DESC LIMIT 1");
	$row1 = sql_fetch_array ($res1);
	if (!empty ($row1))
	{
		// -- get single liners
		$row1['more'] = '<ul class="portal_more">';
		$res3 = sql_query ("SELECT page_id, cat_id, page_title, page_summary, page_image FROM ".$db_prefix."ppage WHERE cat_id IN ($c) ORDER BY page_id DESC LIMIT 5");
		while ($row3 = sql_fetch_array ($res3)) $row1['more'] .= "<li><a href=\"task.php?mod=portal&amp;cmd=read&amp;pid=$row3[page_id]\">$row3[page_title]</a></li>";
		$row1['more'] .= "<li><a href=\"task.php?mod=portal&amp;cmd=cat&amp;cid=$row[cat_id]\">More Articles...</li></ul>";
		
		// image
		if (empty ($row1['page_image']))
		{
			// if no image -> use cat image
			$image = empty ($foo_img[$row1['cat_id']]) ? $foo_img[$row['cat_id']] : $foo_img[$row1['cat_id']];
			if (empty ($image)) // if still empty, use top cat image, still empty? use general image
				$row1['image'] = "<img src=\"public/thumb/$cat_img\" alt=\"thumb\" align=\"left\" />";
			else
				$row1['image'] = "<img src=\"public/thumb/$image\" alt=\"thumb\" align=\"left\" />";
		}
		else
			$row1['image'] = "<img src=\"public/thumb/$row1[page_image]\" alt=\"thumb\" align=\"left\" />";
		
		// output
		$row1['cat_name'] = $foo_cat[$row['cat_id']];
		$row1['cat_id'] = $row['cat_id'];
		// $row1['more'] = '';
		$txt['block_content'] .= quick_tpl ($tpl_block['content'], $row1);
	}
}
if (empty ($txt['block_content'])) $sub_content = FALSE;

$txt['cat_name'] = pcat_name ($cat_id, FALSE, FALSE);
$txt['cat_img'] = $cat_img;
$txt['fcat_name'] = pcat_name ($cat_id, TRUE, TRUE);
$txt['main_body'] = quick_tpl (load_tpl ('mod', 'module_portal_cat.tpl'), $txt);	// reload page.tpl
?>
Return current item: Kemana Directory