#!/usr/bin/perl
################################################################################
# Project : Chinavista YellowPage search engine, Copyright Xindeco BIC #
# Author : walker.Chen (ChenChaoRen) #
# E-mail : walker@chinavista.com #
################################################################################
require "/u/web/chinav/cgi-local/cgi-lib.chen";
#require "/usr/people/walker/cgi-local/cgi-lib.walker";
use Msql;
# Read parameters
ReadParse(*input);
$Lan = &SplitParam($input{'Lan'});
$StartLine = &SplitParam($input{'StartLine'});
$Lines = &SplitParam($input{'Lines'});
$KeyWords = &SplitParam($input{'KeyWords'});
$Class = &SplitParam($input{'Class'});
$Match = &SplitParam($input{'Match'});
$IdArray = &SplitParam($input{'IdArray'});
$Array = &SplitParam($input{'Array'});
$KeyWords =~ s/'/ /g;
# Classes
$TcNum = 15;
@Tc=([1000,"All","全部","场"],
[2000,"Banking & Finance","银行、金融业","蝗︽磕穨"],
[3000,"Computers & Internet","计算机、国际互联网","璸衡诀瓣悔が羛呼"],
[4000,"Consulting & Legal","咨询、法律","玹高猭"],
[5000,"Entertainment & Recreation","娱乐、消遣","甌贾缓"],
[6000,"Government","政府","現┎"],
[7000,"Health & Fitness","卫生、健康","矫ネ胺眃"],
[8000,"Industry & Manufacturing","工业、制造业","穨硑穨"],
[9000,"Media & Publishing","媒体、出版业","碈砰穨"],
[10000,"Real Estate","房地产业","┬玻穨"],
[11000,"Science & Technology","科学、技术","厩мズ"],
[12000,"Shipping & Forwarding","交通、运输业","ユ硄笲块穨"],
[13000,"Trade","贸易","禩"],
[14000,"Travel","旅游","村"],
[15000,"Other","其它","ㄤウ"]
);
@info_navi=(
["Add your company into our yellowpage","加入《中国指南》黄页数据库","い瓣玭独计沮畐"],
["ChinaVista","中国指南","い瓣玭"],
["CityVistas","城市指南","カ玭"],
["Business","商业指南","坝穨玭"],
["Tech","科技指南","м玭"],
["Discover China","神州纵横","羇绢"],
["Search","检索","浪"],
["Services","服务","狝叭"],
["Xindeco Business Information Co., Ltd.","信达商情有限公司","獺笷坝薄Τそ"],
["All rights reserved.","版权所有","舦┮Τ"],
);
@info=(
["Chinavista Yellow Page Search Result","中国指南黄页检索结果","い瓣玭独浪挡狦"],
["Key words : ","关键字:","闽龄"],
["New search","重新检索","浪穝"],
["Search in : ","在下列范围内检索:","璖瞅ず浪"],
["Add your company","免费加入","禣"],
["Layout : ","版面:",""],
[" Display"," 每页显示"," –陪ボ"],
["lines per page.","行。","︽"],
["Any word","匹配任一词","で皌ヴ迭"],
["All words","匹配所有词","で皌┮Τ迭"],
["Options : ","选项:","匡兜"],
["Your search return ","您的查询返回了","眤琩高"],
["result(s).","个结果。","挡狦"],
["Concise description shows as follow : ","下面是查询返回的公司的简要信息:","琌琩高そ虏璶獺"],
["Visit their web site.","访问他们的网址","砐拜呼"],
["Cllck here to see more details of this company.","点击这里显示该公司的详细信息。","翴阑硂ń陪ボ赣そ冈灿獺"],
["Services they provides : ","他们提供的服务:","矗ㄑ狝叭"],
["Next Page","后一页",""],
["Previous Page","前一页","玡"],
["Page Number : ","页码:","絏"],
["Key words is required, thanks!","请输入查询关键字,谢谢。","叫块琩高闽龄谅谅"],
["Keys words : ","关键字:","闽龄"],
["","",""],
["","",""],
["","",""],
);
@tech_info=(
["Bugs reports can be mail to walker\@chinavista.com, thanks!",
"如有问题,欢迎您发邮件至walker\@chinavista.com。",
"Τ拜肈舧眤祇秎ンwalker\@chinavista.com"],
["","",""],
["","",""],
);
@info_en=(
["(If you see some garbage characters, that's because the description of the record is written in Chinese. To be able to view Chinese document, please install Chinese platform software first, such as RichWin.)","",""],
["","",""],
["","",""],
["","",""],
["","",""],
["","",""],
["","",""],
["","",""],
["","",""],
);
@Version=(
["English Version","英文版","璣ゅ"],
["Chinese GB Version","简体中文版","虏砰いゅ"],
["Chinese B5 Version","繁体中文版","羉砰いゅ"],
);
@Navi=(
["/home.html","/chhome.html","/b5home.html"],
["/cities/home.html","/cities/chhome.html","/cities/b5home.html"],
["/business/home.html","/business/chhome.html","/business/b5home.html"],
["/tech/home.html","/tech/chhome.html","/tech/b5home.html"],
["/discover.html","/chdiscover.html","/b5discover.html"],
["/search.html","/chsearch.html","/b5search.html"],
["/services.html","/chservices.html","/b5services.html"]
);
@ClassArray=(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
# Output result
print "Content-type: text/html\n\n";
# Define
$database = "chinav";
$table = "yellowpage";
$table_temp = "yellowpage_temp";
if( $IdArray == 0 )
{
# Process data and translate keywords into non case-sensetive string
$CheckedAny = "";
$CheckedAll = "";
@Words = split(/ /, $KeyWords); # Split words
$i = 0;
$TranWords = $Words[ $i ]; # Copy first word into merge string
$TranWords =~ s/(.)/\[\L$1\E\U$1\E\]/g;
$Statement = "Name LIKE \'%$TranWords%\' ";
$StateAny = "Name LIKE \'%$TranWords%\' ";
for( $i = 1; $Words[ $i ]; $i++ ) # Merge words according to options
{
$TranWords = $Words[ $i ]; # Copy next word into merge string
$TranWords =~ s/(.)/\[\L$1\E\U$1\E\]/g;
$StateAny = $StateAny . " OR Name LIKE \'%$TranWords%\'";
if( $Match == 1 ) # Any word
{
$Statement = $Statement . " OR Name LIKE \'%$TranWords%\'"; # OR should be AND
}
else # All words
{
$Statement = $Statement . " OR Name LIKE \'%$TranWords%\'";
}
}
}
###### Ken ask for classification to be included in.
if( $IdArray == 0 )
{
$ClassArrayNum = 0;
$ClassString = "";
for( $i = 0; $Words[ $i ]; $i++ )
{
for( $k=1; $k<$TcNum; $k++ )
{
$TcTemp = $Tc[$k][$Lan];
# print "$TcTemp
";
$TcTemp =~s/$Words[$i]/WalkerSoft/gi;
# print "$TcTemp
";
if ($TcTemp ne $Tc[$k][$Lan])
{
$ClassArray[$ClassArrayNum]=$k+1;
$ClassString .= " OR Classification=$ClassArray[$ClassArrayNum]";
# print "$ClassString
";
$ClassArrayNum++;
}
}
}
}
###### Ken ask for classification to be included in.
if( $Match == 1 ) # Any word
{
$CheckedAll = "Checked";
}
else # All words
{
$CheckedAny = "Checked";
}
if( $IdArray == 0 )
{
$Statement_FullName = $Statement;
$Statement_FullName =~s/Name/FullName/g;
$Statement_Area = $Statement;
$Statement_Area =~s/Name/Area/g;
$Statement_Services = $Statement;
$Statement_Services =~s/Name/Services/g;
$Statement_Introduction = $Statement;
$Statement_Introduction =~s/Name/Introduction/g;
$Statement_Area = $Statement;
$Statement_Area =~s/Name/Area/g;
$Statement_Address = $Statement;
$Statement_Address =~s/Name/Address/g;
$Statement_Keywords = $Statement;
$Statement_Keywords =~s/Name/Contact/g;
$Statement = $Statement . " OR " .
$Statement_FullName . " OR " .
$Statement_Area . " OR " .
$Statement_Services . " OR " .
$Statement_Area . " OR " .
$Statement_Address . " OR " .
$Statement_Keywords . " OR " .
$Statement_Introduction;
#### Ken's Classification
if( $ClassArrayNum != 0 )
{
$Statement = $Statement . $ClassString;
}
#### Ken's Classification
else
{
if( $Class != 1 )
{
$Statement = "Classification=" . "$Class AND " . $Statement;
}
}
}
@SelectLines = ("","","","","","","");
if( $Lines == 5 )
{
$SelectLines[0] = "selected";
}
if( $Lines == 10 )
{
$SelectLines[1] = "selected";
}
if( $Lines == 15 )
{
$SelectLines[2] = "selected";
}
if( $Lines == 20 )
{
$SelectLines[3] = "selected";
}
if( $Lines == 30 )
{
$SelectLines[4] = "selected";
}
if( $Lines == 50 )
{
$SelectLines[5] = "selected";
}
if( $Lines == 100 )
{
$SelectLines[6] = "selected";
}
# Connect to database
$dbh = Connect Msql;
SelectDB $dbh $database;
if( $IdArray == 0 )
{
# Execute SQL statements to select all fields needed and merge into a long string
#### Ken want chinese entries not to be listed in english version.
if( $Lan == 1 )
{
}
$sql = "SELECT * FROM $table WHERE $Statement";
# print $sql;
$sth = Query $dbh $sql;
$ResultNum = $sth->numrows;
}
print "
\n";
print "\n";
print "$info[0][$Lan-1]";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "| \n";
print "\n";
print " \n";
print "" if( $Lan == 1 );
print "$info_navi[1][$Lan-1] | \n";
print "$info_navi[2][$Lan-1] | \n";
print "$info_navi[3][$Lan-1] | \n";
print "$info_navi[4][$Lan-1] | \n";
print "$info_navi[5][$Lan-1] | \n";
print "$info_navi[6][$Lan-1] | \n";
print "$info_navi[7][$Lan-1]\n";
print "\n" if( $Lan == 1 );
print " \n";
print "\n";
print " \n";
$buf = `lynx -source http://www.chinavista.com/adserver/ad_gen.phtml`;
print $buf;
#print " \n";
#print "\n";
print " \n";
print "\n";
print "$info[0][$Lan-1]\n";
print "\n";
print " \n";
print "\n";
if( $Lan != 1 )
{
print "| ";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print "$Version[0][$Lan-1]\n";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print " | ";
}
if( $Lan != 2 )
{
print "";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print "$Version[1][$Lan-1]\n";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print " | ";
}
if( $Lan != 3 )
{
print "";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print "$Version[2][$Lan-1]\n";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print " | ";
}
print "";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print "$info[4][$Lan-1]\n";
print "" if( $Lan == 1 );
print "" if( $Lan == 1 );
print " | ";
print " \n";
print " \n";
print " | \n";
print "\n";
print "\n";
print "| \n";
$KeyWords1 = $KeyWords;
$KeyWords1 =~s/ /+/g;
if( $IdArray == 0 )
{
####################################
# print " Statement 1 : Get strings into temporary table. $sql ";
if( $ResultNum <= 0 )
{
print "$info[11][$Lan-1] 0 $info[12][$Lan-1]\n";
}
else
{
# Copy data into a temporary table
$sth_copy = $sth;
while (@rows_temp = FetchRow $sth_copy)
{
@fields = (0, 0, 0, "", "");
$fields[0] = $rows_temp[0]; # ID
next if $fields[0] == -9999;
$fields[1] = $rows_temp[6]; # Classification
$fields[2] = $rows_temp[11]; # Language
$fields[4] = $rows_temp[10]; # E-mail
$fields[3] .= $rows_temp[1]; # All string
$fields[3] .= " ";
$fields[3] .= $rows_temp[2];
$fields[3] .= " ";
$fields[3] .= $rows_temp[5];
$fields[3] .= " ";
$fields[3] .= $rows_temp[7];
$fields[3] .= " ";
$fields[3] .= $rows_temp[8];
$fields[3] .= " ";
$fields[3] .= $rows_temp[9];
$fields[3] .= " ";
$fields[3] .= $rows_temp[12];
$fields[3] .= " ";
$fields[3] .= $rows_temp[15];
$sql_temp = "INSERT INTO $table_temp VALUES
($fields[0],$fields[1],$fields[2],\'$fields[3]\',\'$fields[4]\')";
$sth_temp = Query $dbh $sql_temp;
# print " Statement 2 : Copy strings and insert into temporary table. $sql_temp ";
}
$Statement = $Statement_FullName;
$Statement =~s/FullName/AllString/g;
if( $Match == 1 ) # All word
{
$Statement =~s/OR/AND/g;
}
#### Ken's Classification
if( $ClassArrayNum != 0 )
{
$Statement = $Statement . $ClassString;
}
#### Ken's Classification
# Execute SQL statements to select all fields needed
$sql_temp = "SELECT * FROM $table_temp WHERE $Statement ORDER BY AllString";
# $sql_temp = "SELECT * FROM $table_temp WHERE AllString LIKE \'ssss\' AND AllString LIKE \'SSSS\' OR Classification=3";
$sth_temp = Query $dbh $sql_temp;
$ResultNum = $sth_temp->numrows;
# print " Statement 3 : Search in temporary table. $sql_temp ";
if( $ResultNum <= 0 )
{
print "$info[11][$Lan-1] 0 $info[12][$Lan-1]\n";
}
else
{
# Get all Ids into a array
$Counter = 0;
$Array = "";
while (@rows = FetchRow $sth_temp)
{
#### Ken's Classification
if( $ClassArrayNum != 0 )
{
for( $i=0; $i<$ClassArrayNum; $i++ )
{
$i=200 if( $ClassArray[$i] == $rows[1] );
}
next if $i<200;
}
#### Ken's Classification
else
{
next if( ($Class!=1) && ($Class!=$rows[1]) );
}
$SaveId[$Counter] = $rows[0];
$Array .= "$rows[0]+";
$Counter++;
}
if( $Counter <=0 )
{
print "" if( $Lan == 1 );
print "$info[11][$Lan-1] 0 $info[12][$Lan-1]\n";
print "" if( $Lan == 1 );
}
else
{
print "" if( $Lan == 1 );
print "$info[11][$Lan-1] $Counter $info[12][$Lan-1] ($info[21][$Lan-1] $KeyWords) \n";
print "$info[13][$Lan-1]\n";
print "$info_en[0][$Lan-1]\n";
print " " if( $Lan == 1 );
print " \n";
if( $Counter > $Lines )
{
$DispLines = $Lines;
}
else
{
$DispLines = $Counter;
}
for( $i=0; $i<$DispLines; $i++ )
{
$sql = "SELECT * FROM $table WHERE Id=$SaveId[$i]";
$sth = Query $dbh $sql;
# print "Statement 4 : Search in yellowpage table. $sql ";
@rows = FetchRow $sth;
$IndexNo = $i+1;
print " - $IndexNo.\n";
if( $rows[9] )
{
print "";
}
print "$rows[1]
";
if( $rows[9] )
{
print "\n";
}
print "$rows[2] \n";
print "" if( $Lan == 1 );
print "$info[15][$Lan-1] \n";
print "" if( $Lan == 1 );
print "\n";
}
print " \n";
}
}
}
$sql_temp = "DELETE from $table_temp";
$sth_temp = Query $dbh $sql_temp;
# print "Statement 5 : Purge temporary table. $sql_temp ";
$StartLine=2;
$Pages = $Counter/$Lines;
$Pages++ if $Pages != (int $Pages);
$Pages = int $Pages;
# print " ID Array : $Array \n";
if( $Counter > $Lines )
{
print "" if( $Lan == 1 );
print "$info[17][$Lan-1]\n";
print " ($info[19][$Lan-1]1/$Pages) \n";
print "" if( $Lan == 1 );
}
print " \n";
####################################
}
else
{
$Pages = $IdArray/$Lines;
$Pages++ if $Pages != (int $Pages);
$Pages = int $Pages;
print "" if( $Lan == 1 );
print "$info[11][$Lan-1] $IdArray $info[12][$Lan-1] ($info[21][$Lan-1] $KeyWords) \n";
print "$info[13][$Lan-1]\n";
print "$info_en[0][$Lan-1]\n";
print " " if( $Lan == 1 );
print " \n";
if( ($IdArray - ($StartLine-1)*$Lines) > $Lines )
{
$DispLines = $Lines;
}
else
{
$DispLines = $IdArray - ($StartLine-1)*$Lines;
}
@SaveId = split(/ /, $Array); # Split ids
$PageBegin = ($StartLine-1)*$Lines;
for( $i=$PageBegin; $i<$PageBegin+$DispLines; $i++ )
{
$sql = "SELECT * FROM $table WHERE Id=$SaveId[$i]";
# print "Statement 6 : Search in yellowpage table. $sql ";
$sth = Query $dbh $sql;
@rows = FetchRow $sth;
$IndexNo = $i+1;
print " - $IndexNo.\n";
if( $rows[9] )
{
print "";
}
print "$rows[1]
";
if( $rows[9] )
{
print "\n";
}
print "$rows[2] \n";
print "" if( $Lan == 1 );
print "$info[15][$Lan-1] \n";
print "" if( $Lan == 1 );
print "\n";
}
print " \n";
$Array =~s/ /+/g;
# print "ID Array : $Array \n";
print "";
if( $StartLine > 1 )
{
$PrevPage = $StartLine-1;
print "" if( $Lan == 1 );
print "$info[18][$Lan-1]\n";
print "" if( $Lan == 1 );
}
if( ($StartLine > 1) && ($StartLine < $Pages) )
{
print " || ";
}
if( $StartLine < $Pages )
{
$NextPage = $StartLine+1;
print "" if( $Lan == 1 );
print "$info[17][$Lan-1]\n";
print "" if( $Lan == 1 );
}
print "" if( $Lan == 1 );
print " ($info[19][$Lan-1]$StartLine/$Pages) \n";
print "" if( $Lan == 1 );
print "";
print " \n";
}
print " | \n";
print "\n";
print "\n";
print "\n";
print "\n";
print " \n";
print "\n";
print "" if( $Lan == 1 );
print "";
print "$tech_info[0][$Lan-1] \n";
print " \n";
print "\n" if( $Lan == 1 );
print "";
print "\n";
print "\n";
print "" if( $Lan == 1 );
print "$info_navi[1][$Lan-1] | \n";
print "$info_navi[2][$Lan-1] | \n";
print "$info_navi[3][$Lan-1] | \n";
print "$info_navi[4][$Lan-1] | \n";
print "$info_navi[5][$Lan-1] | \n";
print "$info_navi[6][$Lan-1] | \n";
print "$info_navi[7][$Lan-1]\n";
print "\n" if( $Lan == 1 );
print " \n";
print " \n";
print " \n";
print "\n";
print " | \n";
print "\n";
print " \n";
print " |
\n";
print "\n";
print "
\n";
print "\n";
print "";
exit(0);