<?php
//=====================================
// LINKER Category Engine
//=====================================
// Filename : toprank.php
// Path : Main directory
// last update : 2002/07/13
// Desc : View hits, visit, rating top site view
//=====================================
//=====================================
// Info File include
//=====================================
$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);
$tpl->define( array( top_page => "topsite.html"));
$tpl->dyn_define ( "hitcol", "top_page" );
$tpl->dyn_define ( "numcol", "top_page" );
$tpl->dyn_define ( "avgcol", "top_page" );
$tpl->assign(array(
TEMPLATE => $Stemplate,
DOMAIN => $Sdomain,
CHARSET => $Scharset,
BGCOLOR => $Sbgcolor,
MWIDTH => $Smain_width,
ALIGN => $Salign
));
//=====================================
// Make link
//=====================================
$default_top_num = 10;
$query_hits = "select * from LINKER_LINK order by count desc limit $default_top_num";
$query_votenum = "select sid,title,url,visit,upfile,count,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n1+n2+n3+n4+n5+n6+n7+n8+n9+n10 as tsum from LINKER_LINK order by tsum desc limit $default_top_num";
$query_avg = "select sid,title,url,visit,upfile,count,(n1*1+n2*2+n3*3+n4*4+n5*5+n6*6+n7*7+n8*8+n9*9+n10*10) / (n1+n2+n3+n4+n5+n6+n7+n8+n9+n10) as average, n1+n2+n3+n4+n5+n6+n7+n8+n9+n10 as tsum from LINKER_LINK where (n1+n2+n3+n4+n5+n6+n7+n8+n9+n10) !=0 order by average desc limit $default_top_num";
//====================================
// HITS
//====================================
$db->query("$query_hits");
while ($row = $db->nrecord()) {
for ($i=1; $i<=10 ;$i++) {
$vnum = "n".$i;
$vote +=$row[$vnum];
$total_sum += $i * $row[$vnum];
}
$temp_evere = ($vote) ? $total_sum / $vote : 0 ;
$evere = number_format($temp_evere , 2);
$top_hit++;
$upfile = @unserialize(stripslashes($row[upfile]));
$tpl->assign( array(
TNUMBER => $top_hit,
TSID => $row[sid],
TTITLE => $row[title],
RECAT => $row[parent],
TCOUNT => $row[count],
TVISIT => $row[visit],
TSUM => $vote,
TAVG => $evere,
FIMGNAME => $upfile[1]
));
$tpl->parse("CROW",".hitcol");
$tpl->clear(array("FIMGNAME"));
unset($total_sum,$vote);
}
//====================================
// Vote_num
//====================================
$db->query("$query_votenum");
while ($row = $db->nrecord()) {
for ($i=1; $i<=10 ;$i++) {
$vnum = "n".$i;
$vote +=$row[$vnum];
$total_sum += $i * $row[$vnum];
}
$temp_evere = ($vote) ? $total_sum / $vote : 0 ;
$evere = number_format($temp_evere , 2);
$top_num++;
$upfile = @unserialize(stripslashes($row[upfile]));
$tpl->assign( array(
TNUMBER => $top_num,
TSID => $row[sid],
TTITLE => $row[title],
RECAT => $row[parent],
TCOUNT => $row[count],
TVISIT => $row[visit],
TSUM => $row[tsum],
TAVG => $evere,
FIMGNAME => $upfile[1]
));
$tpl->parse("NROW",".numcol");
unset($total_sum,$vote);
$tpl->clear(array("FIMGNAME"));
}
//====================================
// Poll average
//====================================
$db->query("$query_avg");
while ($row = $db->nrecord()) {
$evere = number_format($row[average] , 2);
$top_avg++;
$upfile = @unserialize(stripslashes($row[upfile]));
$tpl->assign( array(
TNUMBER => $top_avg,
TSID => $row[sid],
TTITLE => $row[title],
RECAT => $row[parent],
TCOUNT => $row[count],
TVISIT => $row[visit],
TSUM => $row[tsum],
TAVG => $evere,
FIMGNAME => $upfile[1]
));
$tpl->parse("AROW",".avgcol");
$tpl->clear(array("FIMGNAME"));
}
//====================================
// Result print
//====================================
show_menu();
show_here("","","TOP 10");
show_search();
$tpl->assign(array(
L_COUNT => $l_count,
L_LINK => $l_link,
L_TITLE => $l_title,
L_VISIT => $l_visit,
L_VOTE_NUM => $l_vote_num,
L_VOTE_AVE => $l_vote_ave,
PAGE_HEADER => implode("",file("$Stemplate/header.html")),
PAGE_FOOTER => implode("",file("$Stemplate/footer.html")),
));
$tpl->parse("MAIN","top_page");
$tpl->simprint("MAIN");
//====================================
// Eatablish Time
//====================================
if ($Stime == "Y") check_time($time1);
?>