#!/usr/bin/perl -w
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
require("cookie.lib");
my $cgi = new CGI;
my $PATH = "/cgi-bin";
my $FILENAME = "sok.cgi";
my $FILENAME2 = "jeje.cgi";
my $DBNAME = "jejeno";
my $DBHOST = "sql24.webhuset.no";
my $DBUSERNAME = "jejeno";
my $DBPASSWORD = "lBEvGCx9t";
&GetCookies('jeje_id', 'jeje_al');
print("Content-type: text/html\r\n\r\n");
# Data from user..
getTop();
if($cgi->param('navn') && $cgi->param('sok')) {
my $name = $cgi->param('navn');
my $search = $cgi->param('sok');
getSearch($name, $search);
setSearchHits($name);
} elsif($cgi->param('sok')) {
my $search = $cgi->param('sok');
getHtml();
getData($search);
getData2($search);
} else {
getHtml();
}
print("");
print("");
getCatBar();
print("");
getBottom();
# Function getHtml prints out the html code with a form..
sub getHtml {
setPageHits(2);
print("");
print("
");
print("");
print("
Søk!
");
print("
");
print("
\n");
}
# Function getData prints out the search data..
sub getData {
my ($sok) = @_;
my $query = "SELECT id, title, description, hits FROM link where title LIKE '%" . $sok. "%' OR description LIKE '%" . $sok. "%' OR url LIKE '%" . $sok. "%' OR search_words LIKE '%" . $sok. "%' order by title;";
$dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD);
$sth = $dbh->prepare($query);
$sth->execute();
$sth->bind_columns(\$id, \$title, \$description, \$hits);
print " Resultat nettsider:
\n";
my $count = 0;
while($sth->fetch()) {
$count = $count + 1;
if($count ne 1 and $count ne 2) {
print("\n");
}
&GetCookies('jeje_id', 'jeje_al');
if ($Cookies{'jeje_id'} ne "" && $Cookies{'jeje_al'} ne "") {
my $found = 0;
my $query = "SELECT user_id, link_id FROM favorite where user_id = $Cookies{'jeje_id'};";
$sth2 = $dbh->prepare($query);
$sth2->execute();
$sth2->bind_columns(\$user_id, \$link_id);
while($sth2->fetch()) {
if($user_id eq $Cookies{'jeje_id'} && $link_id eq $id) {
$found = 1;
}
}
$sth2->finish();
if($found ne 1) {
print("
\n";
}
$sth->finish();
$dbh->disconnect;
}
sub getData2 {
my ($sok) = @_;
my $query = "SELECT id, title FROM cat where title LIKE '%" . $sok. "%' OR search_words LIKE '%" . $sok. "%' ORDER BY title;";
$dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD);
$sth = $dbh->prepare($query);
$sth->execute();
$sth->bind_columns(\$id, \$title);
print " Resultat arkiv:
\n");
my $query = "SELECT name FROM users where id=$Cookies{'jeje_id'};";
$dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD);
$sth = $dbh->prepare($query);
$sth->execute();
$sth->bind_columns(\$name);
$sth->fetch();
print("Logget inn som: \n");
print("$name
\n");
$sth->finish();
$dbh->disconnect;
print("Logg ut \n");
}
print("
\n");
print("\n");
print("\n");
print("
\n");
print("
TOPP 10!
\n");
print("
\n");
getTopp10();
print("
\n");
print("\n");
print("
\n");
print("\n");
print("
\n");
print("
\n");
my $year = getYear();
my $datetime = getDateTime();
print(" \n");
print("
\n");
print("
\n");
print(" \n");
print("\n");
}
sub getTopp10 {
my $query = "SELECT id, title, description, hits FROM link order by hits desc;";
$dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD);
$sth = $dbh->prepare($query);
$sth->execute();
$sth->bind_columns(\$id, \$title, \$description, \$hits);
my $count = 1;
while($sth->fetch()) {
print "$count. $title \n";
$count = $count + 1;
if($count == 11) {
last;
$count = 1;
}
}
$sth->finish();
$dbh->disconnect;
}
sub getDateTime {
my ($tmp_second, $tmp_minute, $tmp_hour, $tmp_day, $tmp_month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
my $year = 1900 + $yearOffset;
my $tmp_month = $tmp_month + 1;
if($tmp_month < 10) {
$month = "0$tmp_month";
} else {
$month = "$tmp_month";
}
if($tmp_day < 10) {
$day = "0$tmp_day";
} else {
$day = "$tmp_day";
}
if($tmp_hour < 10) {
$hour = "0$tmp_hour";
} else {
$hour = "$tmp_hour";
}
if($tmp_minute < 10) {
$minute = "0$tmp_minute";
} else {
$minute = "$tmp_minute";
}
if($tmp_second < 10) {
$second = "0$tmp_second";
} else {
$second = "$tmp_second";
}
return "$day.$month.$year $hour:$minute:$second";
}
sub getYear {
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
my $year = 1900 + $yearOffset;
return $year;
}
sub getFavorites {
my $query = "SELECT link_id FROM favorite where user_id = $Cookies{'jeje_id'};";
$dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD);
$sth = $dbh->prepare($query);
$sth->execute();
$sth->bind_columns(\$link_id);
my $count = 0;
while($sth->fetch()) {
$count = $count + 1;
if($link_id) {
my $query2 = "SELECT title FROM link where id = $link_id;";
$sth2 = $dbh->prepare($query2);
$sth2->execute();
$sth2->bind_columns(\$title);
$sth2->fetch();
print("
\n");
print("For å legge til en favoritt: Gå til arkivet, søk eller topp 100. Der finnes det mange nettsider. Til høyre for en av nettsidene, er det en stjerne. Klikk på denne! \n");
}
}