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

//=====================================
// LINKER Category Engine
//=====================================
// Filename : ext_search.php
// Path  : Main directory
// last update : 2002/07/13
// Desc : Extend search image
//=====================================


//=====================================
// 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"); 
include ("./function/emphasis_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);

$tpl->assign(array(
TEMPLATE	=> $Stemplate,
DOMAIN			=> $Sdomain,
CHARSET		=> $Scharset,
BGCOLOR		=> $Sbgcolor,
MWIDTH			=> $Smain_width,
ALIGN			=> $Salign,
L_SEARCH		=>$l_search,
L_EXT_SEARCH => $l_ext_search,
PAGE_HEADER  => implode("",file("$Stemplate/header.html")),
PAGE_FOOTER  => implode("",file("$Stemplate/footer.html"))
));

//==============================================
// Extend search input part
//==============================================

if (!$switch) {

// define file
$tpl->define(	array( ext_search => "ext_search.html" ));
$tpl->dyn_define ( "tdcol", "ext_search" );
$tpl->dyn_define ( "opcol", "ext_search" );

$path_op = view_category("sid");

// usre field
for ($k=1 ;$k<=5 ;$k++) {
$u_name = ${"u_user" . $k};
$u_fname = "user". $k;
$u_cname = "c_user". $k;

if($u_name) {
$tpl->assign( array(SE_NAME		=> $u_name,	SE_RNAME	=> $u_cname, SE_OPNAME	=> $u_fname));
$tpl->parse("TDCOL", ".tdcol");
$tpl->parse("OPCOL", ".opcol");
	}
}

//=====================================
// Print input form
//=====================================

show_menu(); 
show_here("","",$l_ext_search);

$tpl->assign(array(
PATH_OP		=> $path_op,
L_NOFIELD	=> $l_nofield,
L_TITLE			=> $l_title,
L_SOURCE		=> $l_source,
L_NAME		=> $l_name,
L_EMAIL		=> $l_email,
L_SCONT		=> $l_scont,
L_LCONT		=> $l_lcont,
L_CAT			=> $l_cat,
L_OUTPUT_NUM => $l_output_num,
L_NOLIMIT => $l_nolimit,
L_SORT_TYPE => $l_sort_type,
L_COUNT		=> $l_count,
L_UPTIME		=> $l_uptime,
L_ASC_ORDER => $l_asc_order,
L_DESC_ORDER => $l_desc_order,
L_SEARCH_TYPE => $l_search_type,
L_KWORD => $l_search_word,
L_SUBMIT	=> $l_search,
L_RESET	=> $l_reset,
L_NOKWORD =>$l_error_nokword,
L_NOFIELD	=> $l_nofield
));

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

}


//==============================================
// Output Search Result parts
//==============================================

if ($switch =="search") {

// error check
if (!$kword) errmsg($l_error_nokword);

// no search filed -> title 
if (!$c_title && !$c_url && !$name && !$c_email && !$c_scont && !$c_lcont && !$c_user1 
&& !$user2  && !$user3 && !$user4 && !$use5) $c_title = "on";

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


// insert top search keyword
$db->query("insert into LINKER_TWORD SET kword='$kword'");


//=====================================
// Make search sql
//=====================================

if (!$c_sep) $c_sep = "or";
$kword=trim($kword);


$kword_buffer = explode(" ",$kword);
for ($i=0; $i<count($kword_buffer) ;$i++) {
if ($kword_buffer[$i]) $kword_array[] = $kword_buffer[$i];
}


$kword_num = count($kword_array); // kword num


for ($i=0; $i <$kword_num ; $i++) {

	if ($c_title) $query_buffer =" title like '%$kword_array[$i]%'"; 
	if ($c_url) { 
		if ($query_buffer) 	$query_buffer .= " or ";
		$query_buffer .= " url like '%$kword_array[$i]%'";
	}
	
	if ($c_name) { 
		if ($query_buffer) 	$query_buffer .= " or ";
		$query_buffer .= " name like '%$kword_array[$i]%'";
	}
	if ($c_email) { 
		if ($query_buffer) 	$query_buffer .= " or ";
		$query_buffer .= " email like '%$kword_array[$i]%'";
	}
	if ($c_scont) { 
		if ($query_buffer) 	$query_buffer .= " or ";
		$query_buffer .= " scont like '%$kword_array[$i]%'";
	}

	if ($c_lcont) { 
		if ($query_buffer) 	$query_buffer .= " or ";
		$query_buffer .= " lcont like '%$kword_array[$i]%'";
	}

	for ($k=1 ;$k<=5 ;$k++) {
	$u_name = ${"u_user" . $k};
	$u_fname = "user". $k;

	if($u_name) {
	if ($query_buffer) 	$query_buffer .= " or ";
	$query_buffer .= " $u_fname like '%$kword_array[$i]%'";

		}
	}

if ($kword_num>1) $query_buffer = "(" . $query_buffer . ")";
if ($kword_array[$i+1]) $query_buffer .= " $c_sep ";
$add_query .= $query_buffer;
unset($query_buffer);
}


if ($search_sid) {
$db->query("select path from LINKER_LINK where sid='$search_sid'");
$prow = $db->nrecord();
$add_query = "(" . $add_query . ")" ;
$path_query = " and (path like '$prow[path]%' or sid='$search_sid') ";
}

//=====================================
// Get link data
//=====================================


// Get Total link num
$db->query("select count(*) as total from LINKER_LINK where $add_query $path_query");


$Trow = $db->nrecord();
$TotalLink = $Trow[total]; // Total link num
$page_num = ceil($TotalLink / $c_pagenum); // Total page
$page = ($page) ? $page : 1;
$vstart = $c_pagenum * ($page-1);

$db->query("select * from LINKER_LINK where $add_query $path_query order by $u_sort $u_order limit $vstart,$c_pagenum") ;


//=====================================
// Make direct bar
//=====================================

$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='ext_search.php?page=$p&kword=$kword&switch=search&c_title=$c_title&c_url=$c_url&c_name=$c_name&c_email=$c_email&c_scont=$c_scont&c_lcont=$c_lcont&c_user1=$c_user1&c_user2=$c_user2&c_user3=$c_user3&c_user4=$c_user4&c_user5=$c_user5$search_sid=$search_sid&c_pagenum=$c_pagenum&u_sort=$u_sort&u_order=$u_order&c_sep=$c_sep'>$p</a>]";
}

if ($TotalLink > $vstart+$c_pagenum ) {		// make next button
$next_p=$page+1;
$next_list = "<a href='ext_search.php?page=$next_p&kword=$kword&switch=search&c_title=$c_title&c_url=$c_url&c_name=$c_name&c_email=$c_email&c_scont=$c_scont&c_lcont=$c_lcont&c_user1=$c_user1&c_user2=$c_user2&c_user3=$c_user3&c_user4=$c_user4&c_user5=$c_user5$search_sid=$search_sid&c_pagenum=$c_pagenum&u_sort=$u_sort&u_order=$u_order&c_sep=$c_sep'><img src='$Stemplate/image/next.gif' border=0 valign=middle></a>";
}


if ($page>1) {	// make prev button
$prev_p=$page-1;
$prev_list="<a href='ext_search.php?page=$prev_p&kword=$kword&switch=search&c_title=$c_title&c_url=$c_url&c_name=$c_name&c_email=$c_email&c_scont=$c_scont&c_lcont=$c_lcont&c_user1=$c_user1&c_user2=$c_user2&c_user3=$c_user3&c_user4=$c_user4&c_user5=$c_user5$search_sid=$search_sid&c_pagenum=$c_pagenum&u_sort=$u_sort&u_order=$u_order&c_sep=$c_sep'><img src='$Stemplate/image/prev.gif' border=0 valign=middle></a>";
}


//============================
// 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,$kword,1);
}

while ($imgcount % $Snail_row) {

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


//====================================
// Output Main page
//====================================

if (!$TotalLink) $noresult = $l_noresult;

$tpl->assign(array(
SEARCH_FILE	=>"ext_search.php",
KWORD			=> $kword,
SNUM			=>	 $TotalLink,
LINK				=> $link,
NORESULT		=> $noresult,
PREV				=> $prev_list,
DIRECT			=> $direct_bar,
NEXT				=> $next_list,
));

//user filed
for ($k=1 ;$k<=5 ;$k++) {
$u_name = ${"u_user" . $k};
$u_fname = "user". $k;
$u_cname = "c_user". $k;

if($u_name) {
$tpl->assign( array(SE_NAME		=> $u_name,	SE_RNAME	=> $u_fname));
$tpl->parse("SEFORM", ".seform");
	}
}


show_menu(); 
show_here("","",htmlspecial(stripslashes($kword)). " $l_search");

$self_file = "ext_search.php";
$self_str = "extsearch";
$mode = "search";

show_sebar();


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

}

//====================================
// Establish time
//====================================

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

?>
Return current item: Linker IMG