#!/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"); print("\n"); print("
\n"); 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"); } } print "
\n"; if($description ne "") { print "
$description
\n"; } print("
\n"); if($count eq 1) { print("
\n"); } } if($count == 0) { print "
Dessverre, ingen treff!

\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 $count = 0; while($sth->fetch()) { $count = $count + 1; print "\n"; } if($count == 0) { print "
Dessverre, ingen treff!

\n"; } $sth->finish(); $dbh->disconnect; } sub getSearch { my ($name, $search) = @_; if($name ne "jejeno") { print(""); print("
"); print(""); print("
Søking pågår.. Vennligst vent..
"); print("
"); print("Søking pågår.. Vennligst vent..\n"); my $query = "SELECT url1, url2 FROM top_search WHERE search_word LIKE '$name';"; $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth = $dbh->prepare($query); $sth->execute(); $sth->bind_columns(\$url1, \$url2); $sth->fetch(); print "\n"; $sth->finish(); $dbh->disconnect; } else { getHtml(); getData($search); getData2($search); } } sub setSearchHits { my ($name) = @_; my $query = "UPDATE top_search SET hits = hits + 1 WHERE search_word='$name';"; $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth = $dbh->prepare($query); $sth->execute(); $dbh->disconnect; } sub setPageHits { my ($id) = @_; my $query = "UPDATE page_hits SET hits = hits + 1 WHERE id=$id;"; $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth = $dbh->prepare($query); $sth->execute(); $dbh->disconnect; } sub getPosition { my ($cat_id) = @_; if($cat_id == -1) { print("\n"); } else { my $query = "SELECT title, parent_id FROM cat WHERE id=$cat_id"; my $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); my $sth = $dbh->prepare($query); $sth->execute(); $sth->bind_columns(\$title, \$parent_id); $sth->fetch(); my $this_title = $title; my $query2 = "SELECT id, title FROM cat WHERE id=$parent_id"; my $sth2 = $dbh->prepare($query2); $sth2->execute(); $sth2->bind_columns(\$id, \$title); $sth2->fetch(); print "\n"; print "
\n"; print "
$this_title

\n"; $sth->finish(); $sth2->finish(); $dbh->disconnect; } } sub getCat { my ($cat_id) = @_; my $query = "SELECT id, title FROM cat WHERE parent_id=" . $cat_id . " order by title;"; $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth = $dbh->prepare($query); $sth->execute(); $sth->bind_columns(\$id, \$title); my $query2 = "SELECT count(id) as total_cat FROM cat WHERE parent_id=" . $cat_id . ";"; $sth2 = $dbh->prepare($query2); $sth2->execute(); $sth2->bind_columns(\$total_cat); $sth2->fetch(); my $height = 124; my $count = 0; if($total_cat < 9) { $height = ($total_cat * 18); print("$height - $total_cat"); } while($sth->fetch()) { $count = $count + 1; if($count == 1) { print "
\n"; } if($count == 9) { print "
\n"; print "
\n"; } if($count == 17) { print "
\n"; print "
\n"; } print "
\n"; print "
\n"; print "
$title
\n"; } if($count >= 1) { print "
\n"; } if($count == 0 and $cat_id != -1) { print "
Ingen underkategorier...

\n"; } $sth->finish(); $sth2->finish(); $dbh->disconnect; } sub getCatBar { my $cat_id = -1; print("
\n"); print("\n"); print("
Arkiv
\n"); print("
\n"); getPosition($cat_id); getCat($cat_id); print("
\n"); print("\n"); } sub getTop { 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(" JEJE.no - Lett på nett!\n"); print(" \n"); print(" \n"); #print("
\"\"
\n"); print("
\n"); print("
\n"); print("
\n"); print("
\n"); if ($Cookies{'jeje_id'} ne "" && $Cookies{'jeje_al'} ne "") { my $query = "SELECT top_color 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(\$top_color); $sth->fetch(); my $color_id = $top_color; $sth->finish(); $dbh->disconnect; if($color_id ne 0) { my $query2 = "SELECT top_url, header_url FROM top_color where id = $color_id;"; $dbh2 = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth2 = $dbh2->prepare($query2); $sth2->execute(); $sth2->bind_columns(\$top_url, \$header_url); $sth2->fetch(); print(" \"JEJE.no\n"); print("\n"); $sth2->finish(); $dbh2->disconnect; } else { my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); my $color_id = 1; if($dayOfWeek eq 0) { $color_id = 1; } elsif($dayOfWeek eq 1) { $color_id = 1; } elsif($dayOfWeek eq 2) { $color_id = 2; } elsif($dayOfWeek eq 3) { $color_id = 3; } elsif($dayOfWeek eq 4) { $color_id = 4; } elsif($dayOfWeek eq 5) { $color_id = 5; } elsif($dayOfWeek eq 6) { $color_id = 1; } my $query = "SELECT top_url, header_url FROM top_color where id = $color_id;"; $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth = $dbh->prepare($query); $sth->execute(); $sth->bind_columns(\$top_url, \$header_url); $sth->fetch(); print(" \"JEJE.no\n"); print("\n"); $sth->finish(); $dbh->disconnect; } } else { my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); my $color_id = 1; if($dayOfWeek eq 0) { $color_id = 1; } elsif($dayOfWeek eq 1) { $color_id = 1; } elsif($dayOfWeek eq 2) { $color_id = 2; } elsif($dayOfWeek eq 3) { $color_id = 3; } elsif($dayOfWeek eq 4) { $color_id = 4; } elsif($dayOfWeek eq 5) { $color_id = 5; } elsif($dayOfWeek eq 6) { $color_id = 1; } my $query = "SELECT top_url, header_url FROM top_color where id = $color_id;"; $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth = $dbh->prepare($query); $sth->execute(); $sth->bind_columns(\$top_url, \$header_url); $sth->fetch(); print(" \"JEJE.no\n"); print("\n"); $sth->finish(); $dbh->disconnect; } print("
\n"); print("
\n"); print(" \n"); my $query = "SELECT title, search_word FROM top_search ORDER BY search_index;"; $dbh = DBI->connect("dbi:mysql:$DBNAME;$DBHOST",$DBUSERNAME,$DBPASSWORD); $sth = $dbh->prepare($query); $sth->execute(); $sth->bind_columns(\$title, \$search_word); 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("
Meny\n"); if ($Cookies{'jeje_id'} ne "" && $Cookies{'jeje_al'} ne "" && $cgi->param('action') ne "11") { print("
\n"); } else { print("
\n"); } print(" \n"); &GetCookies('jeje_id', 'jeje_al'); if ($Cookies{'jeje_id'} ne "" && $Cookies{'jeje_al'} ne "") { print("
Favoritter\n"); 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; } $sth->finish(); $dbh->disconnect; if($count == 0) { print("
\n"); } else { print(" rediger
\n"); } print("
    \n"); getFavorites(); print("
\n"); } print("
\n"); print(" \n"); print("
\n"); print("
\n"); } sub getBottom { print("\n"); print("
\n"); if ($Cookies{'jeje_id'} eq "" && $Cookies{'jeje_al'} eq "") { print("\n"); print("
\n"); print("
Login
\n"); print("
\n"); $email = $cgi->param('email'); $password = $cgi->param('password'); print("\n"); print("\n"); print("\n"); print("\n"); print("
E-post:
Passord:
Registrer deg!
\n"); if($error) { print("$error
\n"); } } else { print("\n"); print("
\n"); print("
Bruker
\n"); print("
\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("
Copyright $year JEJE.no.. Lett på nett! - support\@jeje.no$datetime\n"); 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"); $sth2->finish(); } } $sth->finish(); $dbh->disconnect; if($count == 0) { print("Ingen favoritter!

    \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"); } }