Location: PHPKode > scripts > Kemana Directory > module/portal/window.php
<?php
// get param
$mode = strtolower (mod_param ('mode'));
$cat_id = mod_param ('cat_id');
$img = mod_param ('img');
$summary = mod_param ('summary');
$num = mod_param ('num');

switch ($mode)
{
	case 'list':
		if (empty ($num)) $num = 20;

		$output = "<ul class=\"list_1\">";
		// 1. get 20 last entries
		if ($cat_id)
			$res = sql_query ("SELECT page_id, page_image, page_title, page_summary FROM ".$db_prefix."ppage WHERE cat_id='$cat_id' ORDER BY page_id DESC LIMIT $num");
		else
			$res = sql_query ("SELECT page_id, page_image, page_title, page_summary FROM ".$db_prefix."ppage ORDER BY page_id DESC LIMIT $num");
		while ($row = sql_fetch_array ($res))
		{
			// image?
			$image = '';
			if ($img) $image = $row['page_image'] ? "<img src=\"public/thumb/$row[page_image]\" alt=\"row[page_title]\" align=\"left\" width=\"50\" hspace=\"5\" />" : '';
			if ($summary) $summary = $row['page_summary'] ? '<br />'.$row['page_summary'] : '';
			$output .= "<li><a href=\"task.php?mod=portal&amp;cmd=read&amp;pid=$row[page_id]\">{$image} {$row['page_title']}</a>{$summary}</li>\n";
		}
		$output .= "</ul>\n";
	break;


	default:
		if (empty ($num)) $num = 5;

		// 1. create portal pages (cached for better perfomance)
		$output = qcache_get ('portal');
		if (!$output)
		{
			load_tpl ('mod', 'module_portal_window.tpl');

			// 1.1 get top cat
			$res = sql_query ("SELECT cat_id, cat_name, cat_img FROM ".$db_prefix."pcategory WHERE parent = 0 ORDER BY cat_order");
			while ($row = sql_fetch_array ($res))
			{
				// -- 1.1.1 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_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);
				
				// -- 1.1.2 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 1, $num");
					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>More in <a href="task.php?mod=portal&amp;cmd=cat&amp;cid='.$row['cat_id'].'">'.$foo_cat[$row['cat_id']].'</a></li>';
					$row1['more'] .= '</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))
							$row1['image'] = '';
						else
							$row1['image'] = "<img src=\"public/thumb/$image\" alt=\"thumb\" />";
					}
					else
						$row1['image'] = "<img src=\"public/thumb/$row1[page_image]\" alt=\"thumb\" />";
					
					// -- 1.1.3 output
					$row1['cat_name'] = $foo_cat[$row['cat_id']];
					$row1['cat_id'] = $row['cat_id'];
					$output .= quick_tpl ($tpl_block['content'], $row1);
				}
			}
			
			// save to cache
			qcache_update ('portal', $output);
		}
	break;
}
?>
Return current item: Kemana Directory