N
Nikos
!!! Finally i made it !!!
I accept congratulations
Here is th html template version of my index.pl which troubled me many
ma days! After reading and reading what you told me i finally get
succeeded!
Here it is:
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-7" />
<title>Ψυχωφελή Πνευματικά Κείμενα!</title>
<link rel="stylesheet" type="text/css"
href="../data/css/style.css" />
<script type="text/javascript" language="javascript">
// <![CDATA[
var textToShow = "<TMPL_VAR name=data>";
var tm;
var pos = 0;
var counter = 0;
function init()
{ tm = setInterval("type()", 50) }
function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("DivText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 10)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
counter++;
if (counter >= 1800 && (c.charCodeAt(0) == 10 || c == "."))
{
d.appendChild(document.createElement("br"));
d.appendChild(document.createTextNode("Press any key..."));
counter = 0;
clearInterval(tm);
document.body.onkeypress = function ()
{
document.getElementById("DivText").innerHTML = '';
tm = setInterval("type()", 50);
document.body.onkeypress = null;
};
}
}
else
clearInterval(tm);
}
// ]]>
</script>
</head>
<body onload=init()>
<div id=page>
<br>
<div id=select_form>
<form action="index.pl">Διάλεξε Îνα από τα κείμενα για να διαβάσεις =>
<select name="select">
<TMPL_LOOP name=files>
<option value="<TMPL_VAR name=file>"><TMPL_VAR name=file></option>
</TMPL_LOOP>
</select>
<input type="submit" name="select" value="Επιλογή" />
</form>
</div>
<div id="DivText"></div>
<div id=user_form>
<form action="show.pl">
<table class="user">
<tr><td>Î ÏŽÏ‚ σε λÎνε αδελφÎ?</td><td class="two"><input name="onoma"
type="text" /></td></tr>
<tr><td>Ποιά είναι η γνώμη σου για την ευχοÏλα »ΚÏÏιε Î™Î·ÏƒÎ¿Ï Î§ÏιστÎ,
ΕλÎησον Με« ?</td><td class="two"><textarea name="euxoula" rows="4"
cols="25"></textarea></td></tr>
<tr><td>ΠεÏιÎγÏαψε μας, μία Ï€Ïοσωπική σου πνευματική εμπειÏία από
κάποιον γÎÏοντα, Ï€Ïος ώφελος των υπολοίπων αδελφών ( αν φυσικά Îχεις
</td><td class="two"><textarea name="sxolio" rows="6"
cols="25"></textarea></td></tr>
<tr><td>Ποιό είναι το email σου?</td><td class="two"><input name="email"
type="text" /></td></tr>
<tr><td><input type="submit" name="show" value="Εμφάνιση όλων των
απόψεων" /></td><td class="two"><input type="submit" name="send"
value="Αποστολή" /></td></tr>
</table>
</form>
</div>
<div id=tip><TMPL_VAR NAME=tip></div>
<div id=info><table>
<tr><td class="host"><TMPL_VAR NAME=host></td></tr>
<tr><td class="xronos"><TMPL_VAR NAME=xronos></td></tr>
<tr><td class="counter"><TMPL_VAR NAME=counter></td></tr>
</table>
</div>
<div id=links>
<a href="games.pl"><img src="../data/images/games.gif" /></a>
<p><a href="show.pl?onoma=showlog" name="showlog">Last Update:
25/4/2005</a></p>
</div>
</div>
</body>
</html>
and here is the index.pl file now in a pure format written since its
only code and with subs this time
#!/usr/bin/perl
use strict;
use warnings;
use CGI qwstandard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use HTML::Template;
use vars qw ($sec $min $hour $mday $mon $year $wday $yday $isdst);
print header;
my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
my $xronos = "$mday $months[$mon], $hour:$min";
my $dbh = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', '')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db',
'********')
or die $DBI::errstr;
my ($match, $host) = get_host( $ENV{'REMOTE_ADDR'} );
my $data;
if( param('select') ) {
$data = open_keimeno( $host, param('select') );
} elsif( $match ) {
$data = welcome_old( $host );
} else {
$data = welcome_new( $host );
}
$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
my $sth;
my $row;
$dbh->do( "UPDATE logs SET page = page + 1" ) if ($host ne "Ãßêïò");
$sth = $dbh->prepare( "SELECT page FROM logs" );
$sth->execute();
$row = $sth->fetchrow_hashref;
my $tmpl = HTML::Template->new(filename=>'./index.html');
$tmpl->param(
files => &select_form(),
tip => &tips(),
data => $data,
host => $host,
xronos => $xronos,
counter => $row->{'counter'}
);
print $tmpl->output;
sub get_host {
my ($url) = @_;
my @numbers = split (/\./,$url);
my $address = pack ("C4", @numbers);
my $host = gethostbyaddr ($address, 2) || $url;
$host = "Ãßêïò" if ( ($host eq "localhost") or ($host eq
"dslcustomer-221-228.vivodi.gr") or ($host eq "dell") );
my $ref = $dbh->selectall_hashref( "SELECT host FROM logs",
'host');
if (exists $ref->{$host}) {
return (1, $host);
} else {
return (0, $host);
}
}
sub open_keimeno {
my ($host, $file) = @_;
my $keimeno = $file;
open(FILE, "<../data/text/$keimeno.txt") or die $!;
my @data = <FILE>;
close(FILE);
my $data = join('', @data);
$dbh->do( "UPDATE logs SET keimeno='$keimeno' WHERE
host='$host'" );
$data;
}
sub welcome_old {
my ($host) = @_;
$dbh->do( "UPDATE logs SET visits = visits + 1 WHERE
host='$host'" );
my $sth = $dbh->prepare( "SELECT * FROM logs WHERE host='$host'" );
$sth->execute();
my $row = $sth->fetchrow_hashref;
return "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçÃ
óåëßäá Ã¥ÃäéáöÃñïõóá!\n".
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
..$row->{xronos}. " !!\n".
"ÓýÃïëéêÃò Þñèåò åäþ " .$row->{visits}. " öïñÃò !!!\n".
"Ôåëåõôáßá åßäåò ôï êåßìåÃï { " .$row->{keimeno}. " }\n".
"Ãïéü êåßìåÃï èá ìåëåôÞóåéò áõôÞà ôçà öïñÜ !?";
}
sub welcome_new {
my ($host) = @_;
my $data;
if ( $host ne "Ãßêïò" ) {
$data = "Ãåéá óïõ " .$host. "!\n" .
"¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
"Åëðßæù Ãá âñåéò ôá êåßìåÃá Ã¥ÃäéáöÃñïÃôá !!!";
my $text;
$dbh->do( "INSERT INTO logs VALUES (null, '$host',
'$xronos', '$text', 1)" );
} else {
$data = "Ãåéá óïõ Ãéêüëá, ôé ÷áìðÜñéá !?! ";
}
$data;
}
sub select_form {
my @files = </data/text/*.txt>;
my @display_files = map {file=>/([^\/]+)\.txt/}, @files;
\@display_files;
}
sub tips {
open(FILE, '<../data/text/tips') or die $!;
my @tips = <FILE>;
close(FILE);
@tips = grep { !/^\s*\z/s } @tips;
$tips[int(rand(@tips))];
};
It works ok! Teh only problem is that if i change the relative path from
this open(FILE, '<../data/text/tips') or die $!;
to this absolute one
open(FILE, '</data/text/tips') or die $!;
then the interpreter gives an error opening the file.... thats funyn
because other absolute parts work!
Gee, i am so happy i finalyl made it work!
I accept congratulations
Here is th html template version of my index.pl which troubled me many
ma days! After reading and reading what you told me i finally get
succeeded!
Here it is:
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-7" />
<title>Ψυχωφελή Πνευματικά Κείμενα!</title>
<link rel="stylesheet" type="text/css"
href="../data/css/style.css" />
<script type="text/javascript" language="javascript">
// <![CDATA[
var textToShow = "<TMPL_VAR name=data>";
var tm;
var pos = 0;
var counter = 0;
function init()
{ tm = setInterval("type()", 50) }
function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("DivText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 10)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
counter++;
if (counter >= 1800 && (c.charCodeAt(0) == 10 || c == "."))
{
d.appendChild(document.createElement("br"));
d.appendChild(document.createTextNode("Press any key..."));
counter = 0;
clearInterval(tm);
document.body.onkeypress = function ()
{
document.getElementById("DivText").innerHTML = '';
tm = setInterval("type()", 50);
document.body.onkeypress = null;
};
}
}
else
clearInterval(tm);
}
// ]]>
</script>
</head>
<body onload=init()>
<div id=page>
<br>
<div id=select_form>
<form action="index.pl">Διάλεξε Îνα από τα κείμενα για να διαβάσεις =>
<select name="select">
<TMPL_LOOP name=files>
<option value="<TMPL_VAR name=file>"><TMPL_VAR name=file></option>
</TMPL_LOOP>
</select>
<input type="submit" name="select" value="Επιλογή" />
</form>
</div>
<div id="DivText"></div>
<div id=user_form>
<form action="show.pl">
<table class="user">
<tr><td>Î ÏŽÏ‚ σε λÎνε αδελφÎ?</td><td class="two"><input name="onoma"
type="text" /></td></tr>
<tr><td>Ποιά είναι η γνώμη σου για την ευχοÏλα »ΚÏÏιε Î™Î·ÏƒÎ¿Ï Î§ÏιστÎ,
ΕλÎησον Με« ?</td><td class="two"><textarea name="euxoula" rows="4"
cols="25"></textarea></td></tr>
<tr><td>ΠεÏιÎγÏαψε μας, μία Ï€Ïοσωπική σου πνευματική εμπειÏία από
κάποιον γÎÏοντα, Ï€Ïος ώφελος των υπολοίπων αδελφών ( αν φυσικά Îχεις
</td><td class="two"><textarea name="sxolio" rows="6"
cols="25"></textarea></td></tr>
<tr><td>Ποιό είναι το email σου?</td><td class="two"><input name="email"
type="text" /></td></tr>
<tr><td><input type="submit" name="show" value="Εμφάνιση όλων των
απόψεων" /></td><td class="two"><input type="submit" name="send"
value="Αποστολή" /></td></tr>
</table>
</form>
</div>
<div id=tip><TMPL_VAR NAME=tip></div>
<div id=info><table>
<tr><td class="host"><TMPL_VAR NAME=host></td></tr>
<tr><td class="xronos"><TMPL_VAR NAME=xronos></td></tr>
<tr><td class="counter"><TMPL_VAR NAME=counter></td></tr>
</table>
</div>
<div id=links>
<a href="games.pl"><img src="../data/images/games.gif" /></a>
<p><a href="show.pl?onoma=showlog" name="showlog">Last Update:
25/4/2005</a></p>
</div>
</div>
</body>
</html>
and here is the index.pl file now in a pure format written since its
only code and with subs this time
#!/usr/bin/perl
use strict;
use warnings;
use CGI qwstandard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use HTML::Template;
use vars qw ($sec $min $hour $mday $mon $year $wday $yday $isdst);
print header;
my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
my $xronos = "$mday $months[$mon], $hour:$min";
my $dbh = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', '')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db',
'********')
or die $DBI::errstr;
my ($match, $host) = get_host( $ENV{'REMOTE_ADDR'} );
my $data;
if( param('select') ) {
$data = open_keimeno( $host, param('select') );
} elsif( $match ) {
$data = welcome_old( $host );
} else {
$data = welcome_new( $host );
}
$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
my $sth;
my $row;
$dbh->do( "UPDATE logs SET page = page + 1" ) if ($host ne "Ãßêïò");
$sth = $dbh->prepare( "SELECT page FROM logs" );
$sth->execute();
$row = $sth->fetchrow_hashref;
my $tmpl = HTML::Template->new(filename=>'./index.html');
$tmpl->param(
files => &select_form(),
tip => &tips(),
data => $data,
host => $host,
xronos => $xronos,
counter => $row->{'counter'}
);
print $tmpl->output;
sub get_host {
my ($url) = @_;
my @numbers = split (/\./,$url);
my $address = pack ("C4", @numbers);
my $host = gethostbyaddr ($address, 2) || $url;
$host = "Ãßêïò" if ( ($host eq "localhost") or ($host eq
"dslcustomer-221-228.vivodi.gr") or ($host eq "dell") );
my $ref = $dbh->selectall_hashref( "SELECT host FROM logs",
'host');
if (exists $ref->{$host}) {
return (1, $host);
} else {
return (0, $host);
}
}
sub open_keimeno {
my ($host, $file) = @_;
my $keimeno = $file;
open(FILE, "<../data/text/$keimeno.txt") or die $!;
my @data = <FILE>;
close(FILE);
my $data = join('', @data);
$dbh->do( "UPDATE logs SET keimeno='$keimeno' WHERE
host='$host'" );
$data;
}
sub welcome_old {
my ($host) = @_;
$dbh->do( "UPDATE logs SET visits = visits + 1 WHERE
host='$host'" );
my $sth = $dbh->prepare( "SELECT * FROM logs WHERE host='$host'" );
$sth->execute();
my $row = $sth->fetchrow_hashref;
return "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçÃ
óåëßäá Ã¥ÃäéáöÃñïõóá!\n".
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
..$row->{xronos}. " !!\n".
"ÓýÃïëéêÃò Þñèåò åäþ " .$row->{visits}. " öïñÃò !!!\n".
"Ôåëåõôáßá åßäåò ôï êåßìåÃï { " .$row->{keimeno}. " }\n".
"Ãïéü êåßìåÃï èá ìåëåôÞóåéò áõôÞà ôçà öïñÜ !?";
}
sub welcome_new {
my ($host) = @_;
my $data;
if ( $host ne "Ãßêïò" ) {
$data = "Ãåéá óïõ " .$host. "!\n" .
"¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
"Åëðßæù Ãá âñåéò ôá êåßìåÃá Ã¥ÃäéáöÃñïÃôá !!!";
my $text;
$dbh->do( "INSERT INTO logs VALUES (null, '$host',
'$xronos', '$text', 1)" );
} else {
$data = "Ãåéá óïõ Ãéêüëá, ôé ÷áìðÜñéá !?! ";
}
$data;
}
sub select_form {
my @files = </data/text/*.txt>;
my @display_files = map {file=>/([^\/]+)\.txt/}, @files;
\@display_files;
}
sub tips {
open(FILE, '<../data/text/tips') or die $!;
my @tips = <FILE>;
close(FILE);
@tips = grep { !/^\s*\z/s } @tips;
$tips[int(rand(@tips))];
};
It works ok! Teh only problem is that if i change the relative path from
this open(FILE, '<../data/text/tips') or die $!;
to this absolute one
open(FILE, '</data/text/tips') or die $!;
then the interpreter gives an error opening the file.... thats funyn
because other absolute parts work!
Gee, i am so happy i finalyl made it work!