#!/usr/bin/perl
########################################################################
# COPYRIGHT NOTICE:
#
# Copyright 2008 FocalMedia.Net All Rights Reserved.
#
# Selling the code for this program without prior written consent
# from FocalMedia.Net is expressly forbidden. You may not
# redistribute this program in any shape or form.
#
# This program is distributed "as is" and without warranty of any
# kind, either express or implied. In no event shall the liability
# of FocalMedia.Net for any damages, losses and/or causes of action
# exceed the total amount paid by the user for this software.
#
########################################################################
#### EDIT HERE -- FOR WINDOWS/IIS BASED INSTALLATIONS ONLY #######
$config_cgi = "config.cgi"; ## <-- CHANGE THIS LINE TO THE FULL SERVER PATH TO config.cgi (Windows Hosts Only)
# THE PATH ON A WINDOWS INSTALLATION WILL LOOK SOMETHING LIKE THIS:
# $config_cgi = "c:/inetpub/webpub/cgi-bin/pseek/config.cgi";
$use_ppc_plugin = 1; ## <-- DON'T CHANGE THIS SETTING UNLESS YOU OWN THIS PLUGIN
#### DO NOT CHANGE ANYTHING BELOW THIS LINE #################
#use FindBin;
#use lib $FindBin::Bin;
use CGI qw(param);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use URI::Escape;
use fmspm;
use pseek;
$default_permissions = 0777;
$pages_prev = "3"; ### PAGES TO LIST ON PAGE (TO THE LEFT)
$pages_next = "3"; ### PAGES TO LIST ON PAGE (TO THE RIGHT)
&get_setup;
fmspm::check_spamb("spcsearch.cgi", "header", "$data_dir");
$q = CGI->new;
print "Content-type: text/html\n\n";
### GET SQL QUERY
$sid = $q->param('id');
if ($sid =~ /-s/)
{
($sid, $tmp) = split (/-s/, $sid);
($sql_query, $page_passon_vals, $display_keywords, $cust_template) = &get_query_sql($sid);
$sqlsearch = "true";
}
else
{
($sql_query, $page_passon_vals, $display_keywords, $cust_template) = &get_query($sid);
}
$sid = int($sid);
$display_keywords = &get_search_ready($display_keywords);
## TOETS IMAGES / UPLOAD IMAGES / EXTRA FIELDS / LINK_IMAGE LINK_FILES
#print "--!!> $page_passon_vals
";
#### GET SETTINGS
$gsettings = new_gsettings;
### GET TEMPLATES
if ($cust_template eq "")
{
$search_templat = pseek::get_file_contents("$data_dir/searchres.html");
$links_style = pseek::get_file_contents("$data_dir/lsearchres_loc.html");
$links_stylep = pseek::get_file_contents("$data_dir/lsearchres_loc_prem.html");
$links_nomatch = pseek::get_file_contents("$data_dir/nomatch.html");
}
else
{
$tmpl1 = "custom-searchres_" . $cust_template . ".html";
$search_templat = pseek::get_file_contents("$data_dir/$tmpl1");
$tmpl2 = "custom-lsearchres_" . $cust_template . ".html";
$links_style = pseek::get_file_contents("$data_dir/$tmpl2");
$tmpl3 = "custom-lsearchresp_" . $cust_template . ".html";
$links_stylep = pseek::get_file_contents("$data_dir/$tmpl3");
$tmpl4 = "custom-nomatch_" . $cust_template . ".html";
$links_nomatch = pseek::get_file_contents("$data_dir/$tmpl4");
}
### GET EXTRA KEY DATA
$keydata = &get_file_contents("$data_dir/keys.dat");
@akeys = split (/\n/, $keydata);
$key_upload_data = &get_file_contents("$data_dir/keysupl.dat");
@upl_items = split (/:-o_:/, $key_upload_data);
### EXECUTE SQL QUERY
$sql = "SELECT * FROM links WHERE $sql_query";
#print "
!-> $sql
";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $sql";}
$rows = $sth->rows();
$linkmatches = $rows;
if ($rows < 1) { &display_no_match; }
#print "-->MATCHES $rows
";
### GET TIME
$nowtime = time();
### PREPARE PAGES
$icnt = $rows;
$nr_searchres = $gsettings->{search_nrlinks_perpage};
$modp = ($icnt % $nr_searchres);
$pages = ($icnt - $modp) / $nr_searchres;
if ($modp != 0) {$pages++;}
$st = $q->param('st');
$nd = $q->param('nd');
if ($st eq ""){$st = 0;}
if ($nd eq ""){$nd = $nr_searchres;}
$main_nd = $nd;
$main_st = $st;
$ippc = 1;
while ( @row = $sth->fetchrow() )
{
if (($ippc > $st) and ($ippc <= $nd))
{
&construct_display_results;
}
### CATEGORIES
### MORE INFO URL
$ippc++;
}
#### GET DISPLAY CATEGORIES
$all_cat_cids = substr($all_cat_cids, 0, length($all_cat_cids) - 3);
$sql = "SELECT * FROM dirs WHERE $all_cat_cids";
#print "
CID!!!-> $sql
";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $sql";}
$rows = $sth->rows();
while ( @row = $sth->fetchrow() )
{
$cats = ""; $rdcat = ""; $ecat = ""; $lv = 0;
for ($ms = 2; $ms < 18; $ms++)
{
if ($row[$ms] ne "")
{
$cats = $cats . $row[$ms] . " / ";
$rdcat = $rdcat . &encode_dir($row[$ms]) . "/";
$ecat = $ecat . &encode_dir($row[$ms]) . "-";
$lastcat = $row[$ms];
$lv++;
}
}
chop($ecat);
$cats = substr($cats, 0, length($cats) -3);
if ($gsettings->{dyn_stat} eq "Static") ### STATIC
{
$repcat = qq[$cats];
$all_links =~ s/!!CAT-$row[0]-CAT!!/$repcat/gi;
$all_links =~ s/!!CAT2-$row[0]-CAT2!!/$rdcat/gi;
}
else ### DYNAMIC
{
$repcat = qq[$cats];
$all_links =~ s/!!CAT-$row[0]-CAT!!/$repcat/gi;
}
}
if ($sqlsearch eq "true")
{
$psid = $sid . "-s";
}
else
{
$psid = $sid;
}
#### PAGES NAVIGATION
$original_keywords =~ s/ /+/g;
for ($ms = 0; $ms < $pages; $ms++)
{
$pg = $ms + 1;
if ($nd == ($pg * $nr_searchres)){ $cnposition = $pg; }
}
if ($cnposition < $pages_next) { $pages_next = $pages_next + $pages_next - ($cnposition - 1); }
$hiddenstr = "";
$pgstring = "";
if ($main_nd eq "") {$main_nd = $nr_searchres;}
for ($ms = 0; $ms < $pages; $ms++)
{
$pg = $ms + 1;
if ($main_nd == ($pg * $nr_searchres))
{
$pgstring = $pgstring . " [$pg] ";
$currentpage = $pg;
}
elsif (($pg >= ($cnposition - $pages_prev)) and ($pg <= ($cnposition + $pages_next)))
{
$st = ($pg * $nr_searchres) - $nr_searchres;
$nd = ($pg * $nr_searchres);
$pgstring = $pgstring . "$pg ";
}
}
#### << PAGES NAVIGATION
if (($cnposition - $pages_prev) > 1)
{
$prev_ppos = $cnposition - $pages_prev;
$staticpos = $prev_ppos - 1;
$prev_ppos = $prev_ppos - 2;
$pvst = $prev_ppos * $nr_searchres;
$pvnd = ($prev_ppos * $nr_searchres) + $nr_searchres;
$pgstring = "<< " . $pgstring;
}
#### » PAGES NAVIGATION
if (($cnposition + $pages_next) < $pages)
{
$next_ppos = $cnposition + $pages_next;
$staticpos = $next_ppos + 1;
$pvst = $next_ppos * $nr_searchres;
$pvnd = ($next_ppos * $nr_searchres) + $nr_searchres;
$pgstring = $pgstring . ">> ";
}
if ($pgstring eq "0") { $pgstring = ""; }
if ($pgstring eq " [1] ") { $pgstring = ""; }
if ($pgstring ne "") {$pgstring = $gsettings->{pages} . $pgstring; }
$search_templat =~ s/%%pages%%/$pgstring/gi;
$search_templat =~ s/!!page!!/$currentpage/gi;
### PREV NEXT PAGES
$st = $q->param('st');
$nd = $q->param('nd');
if ($st eq ""){$st = 0;}
if ($nd eq ""){$nd = $nr_searchres;}
$spls = $modp;
if ($spls == 0){$spls++;}
if ($nd <= ($icnt - $spls))
{
$st1 = $st + $nr_searchres;
$nd1 = $nd + $nr_searchres;
$nextt = "$gsettings->{nextpage} ";
}
if ($st > 0)
{
$st1 = $st - $nr_searchres;
$nd1 = $nd - $nr_searchres;
$prev = "$gsettings->{prevpage} ";
}
if (($prev ne "") and ($nextt ne ""))
{
$spcer = " | ";
}
else
{
$spcer = " ";
}
$prevnext = $prev . "$spcer" . $nextt;
if (length($prevnext) > 5){$myspacer = " | ";}
$search_templat =~ s/%%prevnext%%/$prevnext/g;
### CONSTRUCT SEARCH PAGE
$search_templat =~ s/!!scripts_url!!/$script_url/g;
$search_templat =~ s/!!tseeksearch!!/$script_url\/spcsearch\.cgi/g;
$search_templat =~ s/!build_url!/$web_url/g;
$search_templat =~ s/!!build_url!!/$web_url/g;
$addurl = "$gsettings->{add_url_link}";
$search_templat =~ s/%%addurl%%/$addurl/g;
$search_templat =~ s/%%link_matches%%/$linkmatches/g;
$search_templat =~ s/!!link_matches!!/$linkmatches/g;
$search_templat =~ s/%%searchresults%%/$all_links/g;
$search_templat = pseek::ts_insert_template_includes($search_templat);
$search_templat = pseek::fill_vars($search_templat);
$search_templat =~ s/!!advanced!!/$script_url\/searchadv\.cgi/g;
$search_templat =~ s/%%keywords%%/$display_keywords/g;
$search_templat =~ s/!!keywords!!/$display_keywords/g;
print $search_templat;
sub construct_display_results
{
### SET CLEAN STANDARD/PREMIUM LINK STYLE TEMPLATE
if (($row[21] == 0) and ($row[13] > 0))
{ $row[21] = 99999999999999; }
if (($row[13] > 0) and ($row[21] > $nowtime))
{
$search_links_tmp = $links_stylep;
}
else
{
$search_links_tmp = $links_style;
}
### WHEN TITLE WITH LINK CLICKED OPEN NEW WINDOW
if ($gsettings->{search_res_newwin} eq "Yes"){ $new_win_crit = " target=\"_blank\""; }
### HIDE URLS OR NOT
if ($gsettings->{hideurls} eq "No")
{
$title_with_link = "$row[2]";
}
else
{
$title_with_link = "$row[2]";
}
### IF NO URL JUST DISPLAY TITLE
if (($row[5] eq "http://") or ($row[5] eq "")) { $title_with_link = "$row[2]"; }
### !!title_without_link!!
$search_links_tmp =~ s/!!title_without_link!!/$row[2]/g;
$search_links_tmp =~ s/!!nr!!/$ippc/g;
$search_links_tmp =~ s/%%title_with_link%%/$title_with_link/g;
$search_links_tmp =~ s/!!title_with_link!!/$title_with_link/g;
$search_links_tmp =~ s/!!cid!!/$row[1]/g;
$search_links_tmp =~ s/!!id!!/$row[0]/g;
### %%description%%
$search_links_tmp =~ s/%%description%%/$row[3]/g;
$search_links_tmp =~ s/!!description!!/$row[3]/g;
### !!listing_keywords!!
$search_links_tmp =~ s/!!listing_keywords!!/$row[4]/g;
### !!url!! or !!itemurl!!
$search_links_tmp =~ s/!!url!!/$row[5]/g;
$search_links_tmp =~ s/!!itemurl!!/$row[5]/g;
$search_links_tmp =~ s/!!hidden_url!!/$script_url\/go\.cgi?id=$row[0]/g;
$domaincrit = $row[5];
$domaincrit =~ s/http:\/\///gi;
if ($domaincrit =~ /\//){ @domainrtmp = split(/\//, $domaincrit); $domainr = $domainrtmp[0];} else {$domainr = $domaincrit; }
$search_links_tmp =~ s/!!domain!!/$domainr/gi;
### !!name!!
$search_links_tmp =~ s/!!name!!/$row[8]/g;
### !!email!!
$search_links_tmp =~ s/!!email!!/$row[9]/g;
### !!gethtml!!
$search_links_tmp =~ s/!!gethtml!!/$script_url\/gethtml\.cgi?id=$row[0]-$row[1]/g;
### %%date%%
$reald = $row[17];
$row[17] = &decode_date($row[17]);
$search_links_tmp =~ s/%%date%%/$row[17]/g;
$search_links_tmp =~ s/!!date!!/$row[17]/g;
### %%votes%%
if ($row[11] eq "") { $row[11] = 0; }
$search_links_tmp =~ s/%%votes%%/$row[11]/g;
$search_links_tmp =~ s/!!votes!!/$row[11]/g;
### %%reviews
my $nrc = "";
if ($row[23] > 0) { $nrc = "($row[23])"; }
$reviews = "$gsettings->{comments} $nrc";
$search_links_tmp =~ s/%%reviews%%/$reviews/g;
$search_links_tmp =~ s/!!rno!!/$nrc/gi;
$search_links_tmp =~ s/!!review_link_url!!/$script_url\/reviews\.cgi?id=$row[0]&cid=$row[1]/gi;
### %%modify%%
$modifyl = $gsettings->{modify_text};
$modifyl = "$modifyl";
$search_links_tmp =~ s/%%modify%%/$modifyl/gi;
$search_links_tmp =~ s/!!modify_link!!/$script_url\/modify\.cgi?id=$row[0]&cid=$row[1]/gi;
### %%report%%
$rptdl = $gsettings->{report_dead_link};
$rptdl = "$rptdl";
$search_links_tmp =~ s/%%report%%/$rptdl/gi;
$search_links_tmp =~ s/!!report_dead_link!!/$script_url\/rprtb\.cgi?id=$row[0]&cid=$row[1]/gi;
### %%rateit%% %%rating%%
$rateit = "$gsettings->{rateit}";
$search_links_tmp =~ s/%%rateit%%/$rateit/g;
$search_links_tmp =~ s/!!rate_link_url!!/$script_url\/rateit\.cgi?id=$row[0]&cid=$row[1]/g;
if ($row[10] eq "") { $row[10] = 0; }
$search_links_tmp =~ s/%%rating%%/$row[10]/g;
$search_links_tmp =~ s/!!rating!!/$row[10]/g;
$rating_image = "";
$rating_image = &get_rating_images($row[28]);
$search_links_tmp =~ s/%%rating_image%%/$rating_image/gi;
$search_links_tmp =~ s/!!rating_image!!/$rating_image/gi;
### %%hits%%
if ($row[12] eq "") { $row[12] = 0; }
$search_links_tmp =~ s/%%hits%%/$row[12]/g;
$search_links_tmp =~ s/!!hits!!/$row[12]/g;
### NEW GRAPHIC
if ($reald ne "")
{
$time1 = 86400 * $gsettings->{days1};
if ($reald >= ($today_time - $time1)){ $crit = ""; $search_links_tmp =~ s/!!new!!/$crit/g; }
$time2 = 86400 * $gsettings->{days2};
if ($reald >= ($today_time - $time2)){ $crit = ""; $search_links_tmp =~ s/!!new!!/$crit/g; }
$time3 = 86400 * $gsettings->{days3};
if ($reald >= ($today_time - $time3)){ $crit = ""; $search_links_tmp =~ s/!!new!!/$crit/g; }
}
$search_links_tmp =~ s/!!new!!//gi;
### POP
if ($row[12] > $gsettings->{pop_links_amount})
{
$crit = "";
$search_links_tmp =~ s/!!pop!!/$crit/gi;
}
else
{
$search_links_tmp =~ s/!!pop!!//gi;
}
### RELEVANCE
$search_links_tmp =~ s/%%relevance%%//g;
$search_links_tmp =~ s/!!relevance!!//g;
$search_links_tmp =~ s/%%rgraphic%%//g;
$search_links_tmp =~ s/!!rgraphic!!//g;
### EXTRA FIELDS
$rowcntr = 27;
foreach $keyitem(@akeys)
{
($keyname, $visible, $size, $searched, $description, $na, $imgk, $nmbr) = split (/\t/, $keyitem);
if ($nmbr eq "Upload")
{
if ($row[$rowcntr] eq "")
{
$search_links_tmp =~ s/!!$keyname!!/$na/g;
}
else
{
$apreapp = ""; $aapend = "";
foreach $upload_item (@upl_items)
{
($fieldname_t, $filetypes_t, $preappend_t, $append_t, $uploadsize_t) = split (/:o:-:o:/, $upload_item);
if ($keyname eq $fieldname_t) { $apreapp = $preappend_t; $aapend = $append_t; }
}
$upcrit = $apreapp . "$web_url/imagefiles/$row[0]/$keyname" . "." . $row[$rowcntr] . $aapend;
$search_links_tmp =~ s/!!$keyname!!/$upcrit/g;
}
}
elsif ($imgk eq "Yes")
{
if ($row[$rowcntr] ne ""){$imgcrit = "";} else { $imgcrit = $na; }
$search_links_tmp =~ s/%%$keyname%%/$imgcrit/gi;
$search_links_tmp =~ s/!!$keyname!!/$imgcrit/gi;
}
else
{
if ($row[$rowcntr] eq "") { $row[$rowcntr] = $na; }
$search_links_tmp =~ s/%%$keyname%%/$row[$rowcntr]/gi;
$search_links_tmp =~ s/!!$keyname!!/$row[$rowcntr]/gi;
}
$rowcntr++;
}
##### INSERT IMAGES
$search_links_tmp = &insert_images($search_links_tmp, "$script_url/go.cgi?id=$row[0]");
### INSERT UPLOAD IMAGE IF ANY
if ($search_links_tmp =~ /!!link_image!!/i)
{
$img_fname = "$web_dir/imagefiles/" . $row[0] . "." . $row[6];
$image_width = $gsettings->{image_width};
$image_height = $gsettings->{image_height};
if ($image_width > 0) { $imgw = qq[ width="$image_width" ]; }
if ($image_height > 0) { $imgh = qq[ height="$image_height" ]; }
if (-e "$img_fname")
{
$the_image_url = "$web_url/imagefiles/$row[0]" . "." . $row[6];
$the_link_image = qq[];
$search_links_tmp =~ s/!!link_image!!/$the_link_image/gi;
}
else
{
if ($gsettings->{default_image} =~ /http:/)
{
$the_image_url = $gsettings->{default_image};
$the_link_image = qq[];
$search_links_tmp =~ s/!!link_image!!/$the_link_image/gi;
}
else
{
$search_links_tmp =~ s/!!link_image!!//gi;
}
}
}
elsif ($search_links_tmp =~ /!!link_file!!/i)
{
if ($row[6] ne "") {$the_image_url = "$web_url/imagefiles/$row[0]" . "." . $row[6];}
elsif ($gsettings->{default_image} =~ /http:/) { $the_image_url = $gsettings->{default_image};}
$search_links_tmp =~ s/!!link_file!!/$the_image_url/gi;
}
$imgnm = "";
if ($row[6] ne ""){$imgnm = $row[0] . "." . $row[6];}
$search_links_tmp =~ s/!!image_name!!/$imgnm/gi;
### CATEGORIES & MORE INFO URL
### CATEGORIES
$catreplacement = "!!CAT-$row[1]-CAT!!";
$search_links_tmp =~ s/!!category!!/$catreplacement/gi;
$search_links_tmp =~ s/%%category%%/$catreplacement/gi;
$all_cat_cids = $all_cat_cids . "(cid = '$row[1]') OR ";
if ($gsettings->{dyn_stat} eq "Static")
{
### MORE INFO URL
if ($gsettings->{more_info_naming} eq "linktitles")
{
$fext = "$web_url/!!CAT2-$row[1]-CAT2!!" . pseek::get_more_info_file_name($row[2]) . "_" . $row[0];
}
else
{
$fext = "$web_url/!!CAT2-$row[1]-CAT2!!" . $row[0];
}
$fext = $fext . $gsettings->{gen_file_ext};
$search_links_tmp =~ s/!!more_info_url!!/$fext/gi;
$search_links_tmp =~ s/%%more_info_url%%/$fext/gi;
}
else
{
$mid = $row[0];
$search_links_tmp =~ s/!!more_info_url!!/$script_url\/linfo\.cgi?id=$mid/gi;
$search_links_tmp =~ s/%%more_info_url%%/$script_url\/linfo\.cgi?id=$mid/gi;
}
####################################################
$all_links = $all_links . $search_links_tmp;
}
sub display_no_match
{
$nomatch = $links_nomatch;
$nomatch = pseek::ts_insert_template_includes($nomatch);
$nomatch = pseek::fill_vars($nomatch);
$nomatch =~ s/!!keywords!!/$display_keywords/gi;
$nomatch =~ s/%%keywords%%/$display_keywords/gi;
$sth->finish;
$dbh->disconnect;
print $nomatch;
exit;
}
sub insert_images
{
my ($ihtml, $iurl) = @_;
my ($crit);
$crit = ""; $ihtml =~ s/\[\/img\]/$crit/gi;
$crit = ""; $ihtml =~ s/\[\/imglnk\]/$crit/gi;
return ($ihtml);
}
sub get_query_sql
{
my ($id) = @_;
if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
$sql = "SELECT sql_qq, template FROM advsearcht WHERE searchid = '$id'";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $sql";}
while ( @row = $sth->fetchrow() )
{
$sql_qq = $row[0];
$ttu_template = $row[1];
}
$sth->finish;
$dbh->disconnect;
while ($endex eq "")
{
if ($sql_qq =~ m/!!/g)
{
$r = pos($sql_qq);
push (@coordin, $r);
}
else
{
$endex = "true";
}
}
$posl = 1;
foreach $item (@coordin)
{
if ($posl == 1) { $start = $item; $posl++; }
elsif ($posl == 2)
{
$endpos = $item;
push (@boxitems, substr($sql_qq, $start, $item - $start - 2));
$posl = 1;
}
}
foreach $item (@boxitems)
{
$foundmatch = "false";
foreach $nitem (@cleanbnames)
{
if ($item eq $nitem) {$foundmatch = "true";}
}
if ($foundmatch eq "false")
{
push (@cleanbnames, $item);
}
}
foreach $item (@cleanbnames)
{
$replval = $q->param($item);
$replval = $dbh->quote($replval);
$replval = substr($replval, 1, length($replval) - 1);
$replval = substr($replval, 0, length($replval) - 1);
$sql_qq =~ s/!!$item!!/$replval/gi;
$pass_on_vars = $pass_on_vars . "$item" . "=" . $replval . "&";
$pkeywords = $pkeywords . "$replval ";
}
return ($sql_qq, $pass_on_vars, $pkeywords, $ttu_template);
}
sub get_query
{
my ($id) = @_;
if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
$sql = "SELECT * FROM advsearcht WHERE searchid = '$id'";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror - From: $sql";}
### CONSTRUCT SQL QUERY
while ( @row = $sth->fetchrow() )
{
$fieldnr = 2;
for ($ms = 2; $ms < 32; $ms++)
{
if ($row[$fieldnr] ne "")
{
$add_val = $row[$fieldnr] . ":::" . $row[$fieldnr+1] . ":::" . $row[$fieldnr+2] . ":::" . $row[$fieldnr+3];
push (@search_lines, "$add_val");
}
$fieldnr = $fieldnr + 4;
$fsortby = $row[122];
$ascdesc = $row[123];
$flimitby = $row[124];
$template_to_use = $row[125];
}
}
foreach $line (@search_lines)
{
($fieldname, $match, $field_box_name, $ano) = split (/:::/, $line);
$tmp_boxname = $q->param($field_box_name);
if ($tmp_boxname ne "")
{
if ($match eq "LIKE") { $tmp_boxname = "%" . $tmp_boxname . "%"; }
$search_item = $dbh->quote($tmp_boxname);
$sql_match = $sql_match . "($fieldname $match $search_item) :: $ano ";
$query_created = "true";
}
}
if ($query_created ne "true") { &display_no_match; }
$sql_match = substr($sql_match, 0, length($sql_match) - 8);
### OR's must be grouped together
#print "--> $sql_match
";
@ditems = split (/::/, $sql_match);
$toc = 0;
foreach $ti (@ditems)
{
#print "--> $ti
";
if ($toc == 0) { $ti = "(" . $ti; }
elsif ($ti =~ / AND /) {$ti =~ s/AND/\) AND \(/gi;}
$complq = $complq . $ti;
$toc++;
}
$complq = $complq . ")";
if ($fsortby ne ""){ $complq = $complq . " ORDER BY $fsortby $ascdesc "; }
if ($flimitby > 0){ $complq = $complq . " LIMIT 0, $flimitby "; }
### GET PAGE PASSON VALUES
foreach $line (@search_lines)
{
($fieldname, $match, $field_box_name, $ano) = split (/:::/, $line);
$foundval = "false";
foreach $pitem (@pboxes)
{
if ($field_box_name eq $pitem)
{
$foundval = "true";
}
}
if ($foundval eq "false")
{
$pass_on_vars = $pass_on_vars . $field_box_name . "=" . $q->param($field_box_name) . "&";
$pkeywords = $pkeywords . $q->param($field_box_name) . " ";
}
push(@pboxes, $field_box_name);
}
chop($pkeywords);
$sth->finish;
$dbh->disconnect;
return ($complq, $pass_on_vars, $pkeywords, $template_to_use);
}
sub get_rating_images
{
my ($rating) = @_;
my ($image_rate, $decm, $images);
if ($rating > 0)
{
($image_rate, $decm) = split (/\./, $rating);
if (length($decm) == 1)
{
if ($decm > 4) {$image_rate++;}
}
if (length($decm) == 2)
{
if ($decm > 49) {$image_rate++;}
}
$image_rate = "r" . $image_rate . ".gif";
$image_rate =~ s/ //g;
$images = "";
}
return ($images);
}
sub get_search_ready
{
my ($search_line, $reline) = @_;
$reline = $search_line;
#$reline =~ s/\+/c%2B/g;
$reline =~ s/\[//g;
$reline =~ s/\]//g;
$reline =~ s//g;
$reline =~ s/>//g;
$reline =~ s/|//g;
#$reline =~ s/\)//g;
#$reline =~ s/\(//g;
#$reline =~ s/\*//g;
#$reline =~ s/\^//g;
#$reline =~ s/\.//g;
#$reline =~ s/\$//g;
#$reline =~ s/\?//g;
#$reline =~ s/\\//g;
#$reline =~ s/\~//g;
#$reline =~ s/;//g;
return ($reline);
}
sub get_setup
{
my ($line, $r);
my $exists = (-e "$config_cgi");
if ($exists > 0)
{
open (STP, "$config_cgi");
while (defined($line=))
{
if ($line =~ m/#/g)
{
$r = pos($line);
$line = substr($line, 0, $r - 1);
}
$line =~ s/\n//g;
if ($line =~ /^DB_NAME/){$db_name = &get_setup_line($line, DB_NAME);}
if ($line =~ /^DB_USERNAME/){$db_username = &get_setup_line($line, DB_USERNAME);}
if ($line =~ /^DB_PASSWORD/){$db_password = &get_setup_line($line, DB_PASSWORD);}
if ($line =~ /^MYSQL_HOSTNAME/){$mysql_hostname = &get_setup_line($line, MYSQL_HOSTNAME);}
if ($line =~ /^MYSQL_PORT/){$mysql_port = &get_setup_line($line, MYSQL_PORT);}
if ($line =~ /^SCRIPT_URL/){$script_url = &get_setup_line($line, SCRIPT_URL);}
if ($line =~ /^ADMIN_URL/){$admin_url = &get_setup_line($line, ADMIN_URL);}
if ($line =~ /^WEB_URL/){$web_url = &get_setup_line($line, WEB_URL);}
if ($line =~ /^WEB_DIR/){$web_dir = &get_setup_line($line, WEB_DIR);}
if ($line =~ /^DATA_DIR/){$data_dir = &get_setup_line($line, DATA_DIR);}
if ($line =~ /^USERNAME/){$username = &get_setup_line($line, USERNAME);}
if ($line =~ /^PASSWORD/){$password = &get_setup_line($line, PASSWORD);}
}
close (STP);
}
}
sub get_setup_line
{
my ($setup_line, $setup_var, $crit1, $r1, $r2, $return_val) = @_;
$crit1 = "\"";
$setup_line =~ m/$crit1/g;
$r1 = pos($setup_line);
$setup_line =~ m/$crit1/g;
$r2 = pos($setup_line);
$setup_line = substr($setup_line, $r1, ($r2 - $r1 - 1));
$return_val = $setup_line;
return ($return_val);
}
#### END CONFIGURATION ########################################################