Location: PHPKode > scripts > Linker IMG > linker-img/index.php
<?php

//=====================================
// LINKER Category Engine
//=====================================
// Filename : index.php
// Path  : Main directory
// last update : 2002/07/13
// Desc : View Main Page
//=====================================


//=====================================
// File include part
//=====================================

$time1 = microtime();
include ("./function/base_info.php");
include ("./function/main_func.php");
include ("./function/$Sdb_type.php");
include ("./function/template.php");
include ("./function/userfield_info.php"); 

$lan_dir = $HTTP_COOKIE_VARS[cook_lan];
if ($lan_dir && file_exists("./$lan_dir/u_common.php")) 
include ("./$lan_dir/u_common.php"); 
else include ("./$Slang/u_common.php"); 

//=====================================
// DB_LAYER / TEMPLATE
//=====================================

$db = new DB_Sql($Sdb_host,$Sdb_user,$Sdb_pass,$Sselect_db);
$tpl = new Stemplate($Stemplate);


if (!$cat) {
$tpl->define(array( mpage	=>	 "main.html", mcol	 => "main_col.html" ));
$cat = 0;
$cols = $Smain_col;
}
else {
$tpl->define(array( mpage	=>	 "submain.html",  mcol => "sub_col.html" ));
$cols = $Ssub_col;
}

$tpl->dyn_define ( "tdcol", "mpage" );


//=====================================
// Get this Category config Data
//=====================================

$db->query("update LINKER_CAT set count = count+1 where sid = '$cat'");
$db->query("select * from LINKER_CAT where sid = '$cat'");

if (!$db->numrow) errmsg($l_error_nocat);
$cat_row = $db->nrecord();

//=====================================
// Main page head
//=====================================

$col_width = ceil(100 / $cols) . "%";

$tpl->assign(array(
DOMAIN			=> $Sdomain,
TEMPLATE	=> $Stemplate,
CHARSET		=> $Scharset,
BGCOLOR		=> $Sbgcolor,
MWIDTH	 		=> $Smain_width,
ALIGN			=> $Salign,
SID				=> $cat,
CWIDTH			=> $col_width,
PAGE				=> $page,
U_SORT			=> $u_sort,
U_ORDER		=> $u_order,
VIEW_TYPE		=> $viewtype
));

//====================================
// Sub category data
//====================================

// parent = $cat
$db->query("select * from  LINKER_CAT where parent = '$cat' order by title");
$total_row = $db->numrow;

for ($i = 0; $i <$total_row ;$i++) {
$row[$i] = $db->nrecord();
$temp_ar[$row[$i][sid]] = $i;
}

// pparent = $cat 
if ($cat_row[c_sub] == 2) 
{
	$db->query("select sid,parent,title from LINKER_CAT where pparent='$cat' order by parent,title");
	while ($prow = $db->nrecord()) 
	{
		$tsid = $temp_ar[$prow[parent]];
		if ($row[$tsid][subnum] < $Smain_sub_num) 
		{
		$row[$tsid][subnum]++;
		$subsm[$tsid][] = "<a href='index.php?cat=$prow[sid]' ><font color=blue class=smallfont>$prow[title]</font></a>";
		}
	}
}

//=====================================
// Category Loop
//=====================================

$now_time = time(); // now timestamp for directory new mark

for ($col=0; $col<$cols ; $col++) 
{

$prev_col = ceil(count($row) * ($col / $cols ));
$next_col = ceil(count($row) * (($col+1) / $cols ));

	for ($i = $prev_col; $i < $next_col; $i++ ) 
	{
		
		// for directory new mark
		
		unset($dmark,$interval);
		if ($row[$i][bingo1]) 
		{
		    $interval = ceil( ($now_time - $row[$i][bingo1])/86400 );
		
		if ($interval <=1) $dmark="<img src='$Sdomain/$Stemplate/image/new_1.gif'>";	
		elseif ($interval<=3) $dmark="<img src='$Sdomain/$Stemplate/image/new_3.gif'>";
		elseif ($interval<=7) $dmark="<img src='$Sdomain/$Stemplate/image/new_7.gif'>";
		else $dmark = "";
		}

		// end directory new makr

		switch ($cat_row[c_sub]) 
		{
			case 2 : $sm = @implode(",&nbsp;" ,$subsm[$i]);break;
			case 1 : $sm = $row[$i][descript];	break;
			default: $sm = "";
		}
		
		if ($Smain_sub_num < $row[$i][sub_cat] && $cat_row[c_sub]==2) 
		$sm .="...";
		
		if ($row[$i][relate]>0 ) {
		$row[$i][title] = "@".stripslashes($row[$i][title]);
		$row[$i][sid] = $row[$i][relate];
		}

	
		$tpl->assign( array(
		CAT			=> $row[$i][sid],
		TITLE			=> stripslashes($row[$i][title]),
		DNEW		=> $dmark,
		SUBCAT		=> $row[$i][sub_cat],
		SUBLINK		=> $row[$i][sub_link],
		SM			=> $sm
		));
		
		$tpl->parse("DROW",".mcol");
	}


	$tpl->parse("TDCOL", ".tdcol");
	$tpl->clear("DROW");
}

//====================================
// LINK output part 
//====================================

if ($cat) {

if ($viewtype == "list") 
{
	$tpl->define( array( link_row => "link.html"));
}
else 
{
	$tpl->define( array( link_row => "link_list.html"));
}


$db->query("select count(*) as TotalLink from LINKER_LINK where parent='$cat'");
if ($db->numrow) $Trow = $db->nrecord();

$TotalLink = $Trow[TotalLink];
$page_num = ceil($TotalLink / $Spagecut);


$page = ($page) ? $page : 1;
$vstart = $Spagecut * ($page-1);

if ($Sorderpick) $tem_pick = "c_pick desc,";
if (!$u_sort) $u_sort = $Ssort;
if (!$u_order) $u_order = $Sorder;

$db->query("select * from LINKER_LINK where parent = '$cat' order by $tem_pick $u_sort $u_order limit $vstart,$Spagecut") ;


//============================
// Make Directbar button
//============================

$page_start = floor(($page-1)/ $Sdirectcut ) * $Sdirectcut ; 
$page_end = $page_start + $Sdirectcut; 

for ($p=$page_start+1 ; ($p <= $page_end) && ($p <= $page_num)  ; $p++ ) 
{	

	if ($page == $p) 	$direct_bar .= "[<b>$p</b>]";
	else 	$direct_bar .= "[<a href='index.php?page=$p&cat=$cat&viewtype=$viewtype&u_sort=$u_sort&u_order=$u_order'><font class=midsmall>$p</font></a>]";
}


if ($TotalLink > $vstart+$Spagecut ) {		// Next button
$next_p=$page+1;
$next_list = "<a href='index.php?page=$next_p&cat=$cat&viewtype=$viewtype&u_sort=$u_sort&u_order=$u_order'><img src='$Stemplate/image/next.gif' border=0 valign=middle></a>&nbsp;\n";
}


if ($page>1) {	// Prev button
$prev_p=$page-1;
$prev_list="<a href='index.php?page=$prev_p&cat=$cat&viewtype=$viewtype&u_sort=$u_sort&u_order=$u_order'><img src='$Stemplate/image/prev.gif' border=0 valign=middle></a>&nbsp;\n";
}

//============================
// Link assign and make
//============================

	link_assign();

	$row_width = intval($Smain_width / $Snail_row);

	while ($row = $db->nrecord()) 
	{
		$imgcount++;
		if (!($imgcount % $Snail_row))	$tpl->assign("TRROW", "</tr><tr>");
		else	$tpl->assign("TRROW", "");

		$link .= view_link($row);
	}
	
	while ($imgcount % $Snail_row) {

		$link .= "<td width=$row_width>&nbsp;</td>\n";
		$imgcount++;
	}

} // if ($cat)

//============================
// end if ($cat)
//============================

else 
{
    $db->query("select count(*) as total from LINKER_CAT");
    $t_catrow = $db->nrecord();
    $db->query("select count(*) as total from LINKER_LINK");
    $t_linkrow = $db->nrecord();
}
//====================================
// Output Main page
//====================================


show_menu($cat);
show_here($cat_row[path],$cat_row[pathtxt]);

// search bar
$cat_count = $cat_row[count];
$cat_path = $cat_row[path];


if ($cat) {
	$total_cat = $total_row;
	$total_link = $TotalLink;
	show_search(1,1);
	show_linkbar();

	
	$tpl->assign(array (
	LINK					=> $link,
	PREV					=> $prev_list,
	DIRECT				=> $direct_bar,
	NEXT					=> $next_list ));
	$pagetitle = $cat_row[title];
	
}

else 
{
	$total_cat = $t_catrow[total];
	$total_link = $t_linkrow[total];
	show_search(1);
	if ($Stkword) show_tkword(5);
	if ($Sfmaillist) show_mailling();
	if ($Snewimg)  
	{
		$tpl->assign( array( 
			IMG_CWIDTH	=> intval(100 / $Snail_row),
			T_WIDTH		=> $Snail_width,
			T_HEIGHT		=> $Snail_height
			));
	show_newimg();
	}

	$pagetitle = $Ssite_name;
}

if (!$cat_row[meta_key]) $cat_row[meta_key] = $cat_row[title] ;

$tpl->assign(array(
SNAME				=> $pagetitle,
CAT_HEADER		=> $cat_row[header],
CAT_FOOTER		=> $cat_row[footer],
META					=> $cat_row[meta_key],
PAGE_HEADER  => implode("",file("$Stemplate/header.html")),
PAGE_FOOTER  => implode("",file("$Stemplate/footer.html"))
));


// index Language 
$tpl->assign(array( 
L_NOKWORD	=> $l_error_nokword,
L_NOADDR		=> $l_noaddr
));

$tpl->parse("MAIN","mpage");
$tpl->simprint("MAIN");

//====================================
// Eastablish Time
//====================================

if ($Stime == "Y") check_time($time1);

?>
Return current item: Linker IMG