Cgi.pm and CSS

N

Nikos

ok html::template its out of the question for me even iwth the help of
Dreamweaver. Iam done with it:
i will continue using cgi.pm ans style sheets: I can do the same things
as with the tamplate but unfortunately i cant seperate the code
entirely, but a little with a file called style.css

Here is one style.css i wrote to help me reduce the formatting tags
inside index.pl

/* style.css */

body {
background-image : url(../data/images/night.gif);
position : relative;
margin : 0px;
padding : 0px;
width : 100%;
}


table {
background-image : url(../data/images/swirl.jpg);
margin-left : auto;
margin-right : auto;
width : 55%;
font : 18px Times;
text-align : center;
color : lime;
border : 5px ridge magenta;
border-collapse : collapse;
}


tr {
text-align : center;
border : 1px solid lime;
}


td.tip {
font-style : bold;
color : white;
}


td.host {
font-style : bold;
color : yellow;
}


td.xronos {
font-style : bold;
color : lime;
}


td.counter {
font-style : bold;
color : white;
}

problem is that i have 4 different tables in my index.pl and they all
use the same style of the table i specify.

How can i define more table inside style.css so to pick one that i like
when i want to print in index.pl?
 
N

Nikos

Nikos wrote:
For example i have this in my show.pl

while( $row = $st->fetchrow_hashref )
{
print table( {border=>1, -width=>'80%', -align=>'center',
-style=>'border: thick groove Orange',
-background=>'../data/images/swirl.jpg'},

Tr( {-align=>'center'},
td( {-width=>'25%'}, font( {-size=>4, -color=>'Cyan'},
$row->{onoma} ) ),
td( {-width=>'50%'}, font( {-size=>4,
-color=>'Orange'}, $row->{email} ) ),
td( {-width=>'25%'}, font( {-size=>4,
-color=>'AquaMarine'}, $row->{xronos} ) ) ),

Tr(
td( {-align=>'center'}, font( {-size=>4,
-color=>'Lavender'}, "Åõ÷Þ ôïõ Éçóïý" ) ),
td( {colspan=>2}, font( {-size=>4,
-color=>'Yellow'}, $row->{euxoula} ) ) ),

Tr(
td( {-align=>'center'}, font( {-size=>4,
-color=>'Lavender'}, "ÃñïóùðéêÞ ÃñèïäïîïðíåõìáôéêÞ Åìðåéñßá" ) ),
td( {colspan=>2}, font( {-size=>4, -color=>'Lime'},
$row->{sxolio} ) ) ),

Tr( {-align=>'center'},
td( {colspan=>3}, font( {-size=>4,
-color=>'LightSkyBlue'}, $row->{host} ) ) ) ),

br(), br();
}

But i want to write it more clear with the use of CSS.
How can i write it?
 
S

Scott Bryce

Nikos said:
ok html::template its out of the question for me even with the help of
Dreamweaver. I am done with it:

Sorry to hear that. It really is a good solution to your problem.

How can i define more table inside style.css so to pick one that i like
when i want to print in index.pl?

Now you are asking an HTML question. Perhaps you can ask in an HTML
newsgroup.
 
N

Nikos

Scott said:
Nikos wrote:
Sorry to hear that. It really is a good solution to your problem.

Well yes but that would involve handcoding pure html without the use of
cgi.pm which
i dont want to mess with. But as an idea it would help me to keep cleat
the perl file butnow with the css help its really the same since i ahve
all the formatting rules applied in style.css and i just use print table
Tr( td( $data ) ) to output it. Its not so bad really.

Is there is something even better and easier please let me know.
Again thanks for your willingness time and effort you spent to help me
Scott.

Now you are asking an HTML question. Perhaps you can ask in an HTML
newsgroup.

Yes you are right. i just though it was concering perl and css that why
i mistaken asked it hear sorry.
 
J

J. Gleixner

Nikos wrote:
[...]
Tr( {-align=>'center'},
td( {colspan=>3}, font( {-size=>4,
-color=>'LightSkyBlue'}, $row->{host} ) ) ) ),

br(), br();
}

But i want to write it more clear with the use of CSS.
How can i write it?

Your CSS has the classes, however you're not using them. Read up on CSS
and post questions to the various HTML or CSS newsgroups.

Maybe a site like the following may help:
http://stopdesign.com/present/2005/wdw-sf/

When using CSS correctly, your final HTML will not contain any font or
align elements or attributes, and if done really well, you won't have
any table elements at all.
 
N

Nikos

When using CSS correctly, your final HTML will not contain any font or
align elements or attributes, and if done really well, you won't have
any table elements at all.

Thank you, it sounds very promising! :)
Also is a way of actually seperating perl with html since all the
formatting attributes are in just one file called style.css :)
 
J

J. Gleixner

Nikos said:
Thank you, it sounds very promising! :)
Also is a way of actually seperating perl with html since all the
formatting attributes are in just one file called style.css :)

Using CSS separates the content from the presentation (layout, color,
font, etc.), nothing at all to do with perl. :)
 
J

John W. Kennedy

J. Gleixner said:
When using CSS correctly, your final HTML will not contain any font or
align elements or attributes, and if done really well, you won't have
any table elements at all.

Whoa! CSS can replace abusive use of <TABLE>, but there are still such
things in this world as tables.

--
John W. Kennedy
"Those in the seat of power oft forget their failings and seek only the
obeisance of others! Thus is bad government born! Hold in your heart
that you and the people are one, human beings all, and good government
shall arise of its own accord! Such is the path of virtue!"
-- Kazuo Koike. "Lone Wolf and Cub: Thirteen Strings" (tr. Dana Lewis)
 
J

johnh

Nikos, you seem like a nice guy, but you keep asking questions which
make us think you don't understand what's really going on.

I want to tell you what everyone else has told you: if you want to
display web pages with Perl, use a templating system, and
HTML::Template is recommended.

If I was working with you, I'd tell you this:

* get your HTML and CSS right first;
* don't produce your HTML via CGI.pm and Perl;
* produce them as an HTML file;

That's stage one. And, you know what? Get someone else to do it if you
want. They don't have to understand Perl at all. Just get a friend
who's good at HTML/CSS to do you a good-looking page.

* when that file is the way you want it, come back to the Perl
newsgroups;
* then we will transform your HTML file into an HTML::Template file;
* then we will write a Perl script to display the Template with the
information in it;

This is the whole point of a Templating system. The HTML and the CSS
are in one place, and the script is in another. Different people can
work on different parts.
 
N

Nikos

johnh said:
Nikos, you seem like a nice guy, but you keep asking questions which
make us think you don't understand what's really going on.

I want to tell you what everyone else has told you: if you want to
display web pages with Perl, use a templating system, and
HTML::Template is recommended.

If I was working with you, I'd tell you this:

* get your HTML and CSS right first;
* don't produce your HTML via CGI.pm and Perl;
* produce them as an HTML file;

That's stage one. And, you know what? Get someone else to do it if you
want. They don't have to understand Perl at all. Just get a friend
who's good at HTML/CSS to do you a good-looking page.

* when that file is the way you want it, come back to the Perl
newsgroups;
* then we will transform your HTML file into an HTML::Template file;
* then we will write a Perl script to display the Template with the
information in it;

This is the whole point of a Templating system. The HTML and the CSS
are in one place, and the script is in another. Different people can
work on different parts.

Thank you John for persistant will to help, i appreciate that.
Yes i confess that i was confused about the HTML::Templating system.

What i wanted to tell you is that from the very moment i decided to use
Perl not only as a high-level language but as a way to design web pages
and especially mine i needed a way of not getting my hands dirty with
html. I really dont like html but in order to make a webpage this is
unavoidable since i have to produce it somehow.
Thats why i choosed to use Perl's cgi.pm module functions to produce
html output.
All went good but then i noticed that my webpage although it did not
contained any pure html code it was still filled with stuff like:

print table( {border=>1, -width=>'80%', -align=>'center',
-style=>'border: thick groove Orange',
-background=>'../data/images/swirl.jpg'},

Tr( {-align=>'center'},
td( {-width=>'25%'}, font( {-size=>4, -color=>'Cyan'},
$row->{onoma} ) ),
td( {-width=>'50%'}, font( {-size=>4,
-color=>'Orange'}, $row->{email} ) ),
td( {-width=>'25%'}, font( {-size=>4,
-color=>'AquaMarine'}, $row->{xronos} ) ) ),

so it was messy with formating directives.
I though of a moment why not seperate the Perl code from the actual html
code.
Problem is that to do that i must create a html file with the design of
the webpage and then another perl file that would fill values to it by
replacing 'tmlp_var names=value' with the appropriate vaules.

Thats good but i dont want to create an html file but since i have the
index.pl by running it on the browser i then get the html output.

I try to convert it but i couldn manage it but since you are willing to
help convert it ic an paste it to you.
Man iam scared enouph just by looking at it :)
here is is btw as cgi.pm produced it:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><title>Ψυχωφελή Πνευματικά Κείμενα!</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
</head><body><form method="post" action="index.pl"
enctype="application/x-www-form-urlencoded">
<p align="center"><font color="Lime" size="5">Λόγος Ψυχωφελής και
Θαυμάσιος => </font> <select name="select">
<option value="Ένα μήνυμα σε όλους τους άπιστους">Ένα μήνυμα σε όλους
τους άπιστους</option>
<option value="Αγιος Ιωάννης ο Δαμασκηνός -- ΠεÏί Παθών">Αγιος Ιωάννης ο
Δαμασκηνός -- ΠεÏί Παθών</option>
<option value="Αγιος Îείλος ο Ασκητής -- ΠεÏί ΑντιχÏίστου">Αγιος Îείλος
ο Ασκητής -- ΠεÏί ΑντιχÏίστου</option>
<option value="Ευφυολογήματα -- Κάποιοι Κάπου Κάποτε">Ευφυολογήματα --
Κάποιοι Κάπου Κάποτε</option>

<option value="ΕφÏαίμ Κατουνακιώτης -- ΠεÏί Ευχής">ΕφÏαίμ Κατουνακιώτης
-- ΠεÏί Ευχής</option>
<option value="Η ΘÏησκεία στο Δωδεκάθεο">Η ΘÏησκεία στο Δωδεκάθεο</option>
<option value="Η αλήθεια για τις ψυχές των κεκοιμημένων">Η αλήθεια για
τις ψυχές των κεκοιμημένων</option>
<option value="Θανάσιμα αμαÏτήματα">Θανάσιμα αμαÏτήματα</option>
<option value="Θεόκλητος Διονυσιάτης -- ΠεÏί Δαιμόνων">Θεόκλητος
Διονυσιάτης -- ΠεÏί Δαιμόνων</option>
<option value="Ιωσήφ Ησυχαστής -- ΠεÏί Ευχής Îο1">Ιωσήφ Ησυχαστής --
ΠεÏί Ευχής Îο1</option>
<option value="Ιωσήφ Ησυχαστής -- ΠεÏί Ευχής Îο2">Ιωσήφ Ησυχαστής --
ΠεÏί Ευχής Îο2</option>
<option value="ΛατÏευτικό ΕγχειÏίδιο -- ΠεÏί Ευχής">ΛατÏευτικό
ΕγχειÏίδιο -- ΠεÏί Ευχής</option>
<option value="ΛατÏευτικό ΕγχειÏίδιο -- ΠεÏί ΣκανδαλισμοÏ">ΛατÏευτικό
ΕγχειÏίδιο -- ΠεÏί ΣκανδαλισμοÏ</option>

<option value="ΜετεμψÏχωση">ΜετεμψÏχωση</option>
<option value="Οι πάπυÏοι της ÎεκÏάς Θάλασσας">Οι πάπυÏοι της ÎεκÏάς
Θάλασσας</option>
<option value="Πίστευε και μη εÏεÏνα">Πίστευε και μη εÏεÏνα</option>
<option value="ΠεÏιπέτεις ενός ΠÏοσκυνητή -- ΠεÏί ΠÏοσευχής">ΠεÏιπέτεις
ενός ΠÏοσκυνητή -- ΠεÏί ΠÏοσευχής</option>
<option value="Î Î¿Ï Ï€Î¬Î¼Îµ μετά θάνατο;">Î Î¿Ï Ï€Î¬Î¼Îµ μετά θάνατο;</option>
<option value="ΠÏόσεχε την ψυχή σου">ΠÏόσεχε την ψυχή σου</option>
<option value="Σχέση ΧÏÎ¹ÏƒÏ„Î¹Î±Î½Î¿Ï Î¼Îµ κοσμικότητα">Σχέση ΧÏÎ¹ÏƒÏ„Î¹Î±Î½Î¿Ï Î¼Îµ
κοσμικότητα</option>
</select> <input type="submit" name="ok" value="ok"
/></p><div></div></form><br /><html><head><title></title>
<script type='text/javascript'>

var textToShow = "Καλώς ήÏθες dell.lan! ΧαίÏομαι Ï€Î¿Î»Ï Ï€Î¿Ï… σε
ξαναβλέπω!\nΤελευταία φοÏα ήÏθες εδώ ως dell.lan στις 18 Apr, 16:6
!!\nΑυτή είναι η 325 φοÏά που επισκέφτεσαι την σελίδα μου και χαίÏομαι
Ï€Î¿Î»Ï Ï€Î¿Ï… την βÏίσκεις ενδιαφέÏουσα !!!\nΤην τελευταία φοÏά διάβασες το
κείμενο [ ΛατÏευτικό ΕγχειÏίδιο -- ΠεÏί Î£ÎºÎ±Î½Î´Î±Î»Î¹ÏƒÎ¼Î¿Ï ]\nΠοιo λόγο θα
ήθελες να μελετήσεις αυτήν τη φοÏά ?!?";
var tm;
var pos = 0;
var counter = 0;

function init()
{ tm = setInterval("type()", 45) }

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>

<body onload=init()>
<center>
<div id="DivText" align="Left" style="
background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px;
width: 850px;
height: 500px;
color: LightSkyBlue;
font-family: Times;
font-size: 18px;">
</div
<br /><br /><br /><form method="post" action="show.pl"
enctype="application/x-www-form-urlencoded">
<table class="user"><tr><td>Πώς σε λένε αδελφέ?</td> <td><input
type="text" name="onoma" /></td></tr> <tr><td>Ποιά είναι η γνώμη σου
για την ευχοÏλα
*ΚÏÏιε Î™Î·ÏƒÎ¿Ï Î§Ïιστέ Ελέησον Με* ?</td> <td><textarea
name="euxoula" rows="4" cols="25"></textarea></td></tr> <tr><td>ΜοιÏάσου
μαζί μας μία κατά τη γνώμη σου
θαυμαστή Ï€Ïοσωπική πνευματική εμπειÏία από
κάποιον γέÏοντα Ï€Ïος ώφελος των υπολοίπων
αδελφών (αν φυσικά έχεις :)</td> <td><textarea
name="sxolio" rows="6" cols="25"></textarea></td></tr> <tr><td>Ποιό
είναι το e-mail σου?</td> <td><input type="text" name="email"
/></td></tr> <tr><td><input type="submit" name="Εμφάνιση όλων των
απόψεων" value="Εμφάνιση όλων των απόψεων" /></td> <td><input
type="submit" name="Αποστολή" value="Αποστολή"
/></td></tr></table><div></div></form><br /><br /><table
class="quote"><tr><td># Μην αισθάνεσαι ποτέ Ï„Ïψεις για αυτά που έχεις
σκεφτεί για την γυναίκα σου. Αυτή έχει σκεφτεί Ï€Î¿Î»Ï Ï‡ÎµÎ¹ÏότεÏα για σένα.
(Jean Rostand)

</td></tr></table><br /><table class="info"><tr><td>dell.lan</td></tr>
<tr><td>21 Apr, 13:38</td></tr> <tr><td>1327</td></tr></table><br /><a
href="games.pl"><img src="../data/images/games.gif" /></a><p
align="right"><a href="show.pl?onoma=showlog"><font color="Lime"
size="2"><b>Last Update: 18/4/2005</b></font></a></p>

If you still want to help me please do and if you actually decide to,
please if you see something you dont like or can be written better make
changes at your wish.

After all its my personal webpage where you can see also see it runnign
at my host http://www.nikolas.tk/

Here is also the index.pl that produced the above html output:

#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI::Cookie;
use CGI qw:)standard);
use DBI;
use DBD::mysql;

@months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
$xronos = "$mday $months[$mon], $hour:$min";

$ip = $ENV{'REMOTE_ADDR'};
@numbers = split (/\./,$ip);
$address = pack ("C4", @numbers);
$host = gethostbyaddr ($address, 2) || $ip;
$host = "ÃÖÅÃÔÉÊÃ" if ( ($host eq "localhost") or ($host eq
"dslcustomer-221-228.vivodi.gr" or $host eq "dell") );

print header( -charset=>'iso-8859-7' );
print start_html( -style=>'../style.css', -title=>'Øõ÷ùöåëÞ ÃíåõìáôéêÜ
Êåßìåíá!' );


$db = ($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 print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;

#*******************************************************************************
@files = <../data/text/*.txt>;
@display_files = map( /([^\/]+)\.txt/, @files );

print start_form(-action=>'index.pl');
print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'},
'Ëüãïò Øõ÷ùöåëÞò êáé ÈáõìÜóéïò => ' ),
popup_menu( -name=>'select',
-values=>\@display_files ),
submit('ok'));
print end_form(), br();

$keimeno = param('select') or "Ãñ÷éêÞ Óåëßäá";

$st = $db->prepare( "SELECT host FROM logs" );
$st->execute();
while( $row = $st->fetchrow_hashref ) {
if( $host eq $row->{host} ) {
$hostmatch = 1;
}
}

if( param('select') and param('select') !~ /\.\./ )
{
open(FILE, "<../data/text/$keimeno.txt") or die $!;
@data = <FILE>;
close(FILE);

$data = join('', @data);

$db->do( "UPDATE logs SET keimeno='$keimeno' WHERE host='$host'" )
or die $db->errstr;
}
elsif( $hostmatch == 1 )
{
$db->do( "UPDATE logs SET visits = visits + 1 WHERE host='$host'" )
or die $db->errstr;
$st = $db->prepare( "SELECT * FROM logs WHERE host='$host'" );
$st->execute();
$row = $st->fetchrow_hashref;

$data = "Êáëþò Þñèåò " .$host. "! ×áßñïìáé ðïëý ðïõ óå îáíáâëÃðù!\n" .
"Ôåëåõôáßá öïñá Þñèåò åäþ ùò " .$row->{host}. " óôéò "
..$row->{xronos}. " !!\n" .
"ÃõôÞ åßíáé ç " .$row->{visits}. " öïñÜ ðïõ åðéóêÃöôåóáé ôçí
óåëßäá ìïõ êáé ÷áßñïìáé ðïëý ðïõ ôçí âñßóêåéò åíäéáöÃñïõóá !!!\n" .
"Ôçí ôåëåõôáßá öïñÜ äéÜâáóåò ôï êåßìåíï [ "
..$row->{keimeno}. " ]\n" .
"Ãïéo ëüãï èá Þèåëåò íá ìåëåôÞóåéò áõôÞí ôç öïñÜ ?!?";
}
elsif( $hostmatch != 1 )
{
if ( $host ne "ÃÖÅÃÔÉÊÃ" )
{
$data = "Êáëþò üñéóåò " .$host. "!\n" .
"ÃõôÞ åéíáé ç 1ç óïõ åðßóêåøç åäþ ðÃñá! Åëðßæù íá óïõ
áñÃóåé!\n" .
"Ãíïßãïíôáò ôï ðáñáðÜíù drop-down menu åðÃëåîå ôï êåßìåíï
ðïõ èá Þèåëåò íá äéáâÜóåéò...";

$db->do( "INSERT INTO logs VALUES (null, '$host', '$xronos',
'$text', 1)" ) or die $db->errstr;
}
else
{
$data = "Ôé ÷áìðÜñéá $host :) ÈõìÞèçêåò íá ìå ðåñéðïéçèåßò êáé
åìÃíá ëéãÜêé !?!";
}
}

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;

#*******************************************************************************
print <<ENDOFILETML;
<html><head><title></title>
<script type='text/javascript'>

var textToShow = "$data";
var tm;
var pos = 0;
var counter = 0;

function init()
{ tm = setInterval("type()", 45) }

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>

<body onload=init()>
<center>
<div id="DivText" align="Left" style="
background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px;
width: 850px;
height: 500px;
color: LightSkyBlue;
font-family: Times;
font-size: 18px;">
</div
ENDOFILETML
#*******************************************************************************

print br(), br(), br();
print start_form(-action=>'show.pl');
print table( {class=>'user'},
Tr( td( 'Ãþò óå ëÃíå áäåëöÃ?' ),
td( textfield( 'onoma' ))),
Tr( td( 'ÃïéÜ åßíáé ç ãíþìç óïõ ãéá ôçí åõ÷ïýëá
*Êýñéå Éçóïý ×ñéóôà ÅëÃçóïí Ìå* ?' ),
td( textarea( -name=>'euxoula', -rows=>4, -columns=>25 ))),
Tr( td( 'ÌïéñÜóïõ ìáæß ìáò ìßá êáôÜ ôç ãíþìç óïõ
èáõìáóôÞ ðñïóùðéêÞ ðíåõìáôéêÞ åìðåéñßá áðü
êÜðïéïí ãÃñïíôá ðñïò þöåëïò ôùí õðïëïßðùí
áäåëöþí (áí öõóéêÜ Ã÷åéò :)' ),
td( textarea( -name=>'sxolio', -rows=>6, -columns=>25 ))),
Tr( td( 'Ãïéü åßíáé ôï e-mail óïõ?' ),
td( textfield( 'email' ))),
Tr( td( submit( 'ÅìöÜíéóç üëùí ôùí áðüøåùí' )),
td( submit( 'ÃðïóôïëÞ' ))),
);
print end_form(), br(), br();

open(FILE, "<../data/text/tips") or die $!;
@tips = <FILE>;
close(FILE);

@tips = grep { !/^\s*\z/s } @tips;
$tip = $tips[int(rand(@tips))];

print table( {class=>'quote'},
Tr( td( $tip ))
);

$db->do( "UPDATE counter SET counter = counter + 1" ) if ($host ne
"ÃÖÅÃÔÉÊÃ");

$st = $db->prepare( "SELECT counter FROM counter" );
$st->execute();
$row = $st->fetchrow_hashref;

print br();
print table( {class=>'info'},
Tr( td( $host )),
Tr( td( $xronos )),
Tr( td( $row->{counter} ))
);

print br(), a( {href=>'games.pl'},
img{src=>'../data/images/games.gif'} );
print p( {-align=>'right'}, a( {href=>'show.pl?onoma=showlog'}, font(
{-size=>2, -color=>'Lime'}, b( 'Last Update: 18/4/2005' ))));

You can see that in my index.pl i dont any more have the long-lines
prints with width,height afont stuff since i created the style.css

here it is also btw:

/* style.css */

body {
background-image : url(../data/images/night.gif);
position : relative;
margin : 0px;
padding : 0px;
width : 100%;
}

table.user {
background-image : url(../data/images/swirl.jpg);
width : 55%;
color : lime;

text-align : center;
font : 18px times;

border : 5px ridge magenta;
border-collapse: : collapse;
}

table.quote {
background-image : url(../data/images/nebula.jpg);
width : 80%;
color : yellow;

text-align : center;
font : 18px comic;

border : 3px ridge lime;
border-collapse: : collapse;
}

table.info {
background-image : url(../data/images/nebula.jpg);
width : 25%;
color : cyan;

text-align : center;
font : 18px comic;

border : 3px ridge orange;
border-collapse: : collapse;

td {
border : 2px inset yellow;
}



td.tip {
font-style : bold;
color : white;
}

td.host {
font-style : bold;
color : yellow;
}

td.xronos {
font-style : bold;
color : lime;
}

td.counter {
font-style : bold;
color : white;
}

Its up to you now if you want to make the covertion.

ps. Sorry for the long copy/pastes but i dont know how to attach files
in usenet.
 
J

J. Gleixner

John said:
Whoa! CSS can replace abusive use of <TABLE>, but there are still such
things in this world as tables.

There are still such things in the world as <font> and <blink> too, it
doesn't mean they should be used. :)
 
N

Nikos

J. Gleixner said:
John W. Kennedy wrote:

There are still such things in the world as <font> and <blink> too, it
doesn't mean they should be used. :)

By what have they been replaced? In my script i have an extensive use of
<table> and <font> and i want o get rid of them :)
 
A

Alan J. Flavell

There are still such things in the world as <font> and <blink> too,
it doesn't mean they should be used. :)

The trouble with off-topic answers is that they're so often
fundamentally misleading. Anyone who happens by this thread should be
advised that it could be injurious to their WWW health, and to please
seek answers in a more-appropriate place.
 
F

Fabian Pilkowski

* Nikos said:
I try to convert it but i couldn manage it but since you are willing to
help convert it ic an paste it to you.
Man iam scared enouph just by looking at it :)
here is is btw as cgi.pm produced it:
[...]

</td></tr></table><br /><table class="info"><tr><td>dell.lan</td></tr>
<tr><td>21 Apr, 13:38</td></tr> <tr><td>1327</td></tr></table><br /><a
href="games.pl"><img src="../data/images/games.gif" /></a><p
align="right"><a href="show.pl?onoma=showlog"><font color="Lime"
size="2"><b>Last Update: 18/4/2005</b></font></a></p>

Haven't I told you to use »CGI::pretty« instead of »CGI«? Then, you'll
get a well-formatted HTML output from your script. Anyway, I've looked
through your HTML code (I have requested the current one from your own
website). But, I'm disappointed: There are only six TMPL_VARs (and one
TMPL_LOOP, to be correct). Since you have already seen an example with
three TMPL_VARs, I don't see why extending it to six vars could be a
real problem ...

Sorry about the long lines, but because it's nothing important in those
lines, I've not choosen to break them. Here is your template I would
using for a first test (but, I haven't tested it yet):

##########
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">

<head>
<title>Ψυχωφελή Πνευματικά Κείμενα!</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
<script language="JavaScript" tape="text/javascript">
var textToShow = "<TMPL_VAR name=data>";
<!-- here you have to insert the rest of your javascript code -->
</script>
</head>

<body onload="init()">

<form method="post" action="index.pl" enctype="application/x-www-form-urlencoded">
<p align="center">
<font color="Lime" size="5">Λόγος Ψυχωφελής και Θαυμάσιος => </font>
<select name="select">
<TMPL_LOOP name=options>
<option value="<TMPL_VAR name=option>"><TMPL_VAR name=option></option>
</TMPL_LOOP>
</select>
<input type="submit" name="ok" value="ok" />
</p>
<div></div> <!-- I don't think you need this empty div -->
</form>

<br />

<center>
<div id="DivText" align="Left" style="background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px; width: 850px; height: 500px; color: LightSkyBlue;
font-family: Times; font-size: 18px;"></div>

<br /><br /><br />

<form method="post" action="show.pl" enctype="application/x-www-form-urlencoded">
<table class="user">
<tr><td>Πώς σε λένε αδελφέ?</td> <td><input type="text" name="onoma" /></td></tr>
<tr><td>Ποιά είναι η γνώμη σου για την ευχοÏλα *ΚÏÏιε Î™Î·ÏƒÎ¿Ï Î§Ïιστέ Ελέησον Με* ?</td> <td><textarea name="euxoula" rows="4" cols="25"></textarea></td></tr>
<tr><td>ΜοιÏάσου μαζί μας μία κατά τη γνώμη σου θαυμαστή Ï€Ïοσωπική πνευματική εμπειÏία από κάποιον γέÏοντα Ï€Ïος ώφελος των υπολοίπων αδελφών (αν φυσικά έχεις :)</td> <td><textarea name="sxolio" rows="6" cols="25"></textarea></td></tr>
<tr><td>Ποιό είναι το e-mail σου?</td> <td><input type="text" name="email" /></td></tr>
<tr><td><input type="submit" name="Εμφάνιση όλων των απόψεων" value="Εμφάνιση όλων των απόψεων" /></td> <td><input type="submit" name="Αποστολή" value="Αποστολή" /></td></tr>
</table>
<div></div>
</form>

<br /><br />

<!-- table: tip -->
<table class="quote">
<tr><td><TMPL_VAR name=tip></td></tr>
</table>

<br />

<!-- table: host, date and counter -->
<table class="info">
<tr><td><TMPL_VAR name=host></td></tr>
<tr><td><TMPL_VAR name=date></td></tr>
<tr><td><TMPL_VAR name=counter></td></tr>
</table>

<br />

<a href="games.pl"><img src="../data/images/games.gif" /></a>
<p class="first"><a href="show.pl?onoma=showlog"><b>Last Update: 21/4/2005</b></a></p>

</body>

</html>
##########

Within this template I have used the following TMPL_* tags.

data
options (loop) => option
tip
host
date
counter

Now, it's your part to fill in their values. I've shown you already (as
many others here), how this works. Untested:

my $data = '...'; # do something to determine $data
$tmpl->param( data => $data );

# To fill TMPL_LOOPs you have to pass a reference to an array with
# references to hashes inside. And the inner hashes contain the data
# for the TMPL_VARs inside the TMPL_LOOP. Well, it's a bit tricky.
my @display_files = map /([^\/]+)\.txt/, glob '../data/text/*.txt';
my @array_of_hashes = map { option => $_ }, @display_files;
$tmpl->param( options => \@array_of_hashes );

my $tip = $tips[ int rand @tips ];
$tmpl->param( tip => $tip );
# etc.

Last but not least, a few comment to the HTML template above. In the
first lines, "iso-8859-1" is defined as encoding. Additionally, the
predicted language of this HTML file is "en-US". Are these settings
typically for Greek sites resp sites containing Greek characters (I'm
not up to date in this)?

It's not very intelligent to put all the *information* of the page into
one javascript variable. Then, a user without javascript enabled will
see nothing -- is that what you want? When using such nice (?) effects,
try to change existing HTML code. Just an idea: Put the text into its
own tags, eg. like

<div id="DivText">The text you want to present.</div>

Then cut out this text with javascript while loading the page and write
it back with your effect (as you're doing this moment).

regards,
fabian

postscript. It's not really pleasant to post 500+ lines into a newsgroup
read by hundreds of humans. The posting guidelines for this group you've
already read, I hope, suggest to post a "short (less than 30 lines) and
complete program". Yes, your code is exceeding this limit, isn't it?
 
J

John W. Kennedy

Nikos said:
By what have they been replaced? In my script i have an extensive use of
<table> and <font> and i want o get rid of them :)

Intelligent use of <div> with CSS can and should replace the use of
<table> to force layouts. For things that are actual semantic tables,
such as:

* | 0 1 2 3 4 5 6 7 8 9 Sing. Plur.
----------------------------------- --------------------
0 | 0 0 0 0 0 0 0 0 0 0 1st | amo amamus
1 | 0 1 2 3 4 5 6 7 8 9 2nd | amas amatis
2 | 0 2 4 6 8 10 12 14 16 18 3rd | amat amant
3 | 0 3 6 9 12 15 18 21 24 27
4 | 0 4 8 12 16 20 24 28 32 36 or
5 | 0 5 10 15 20 25 30 35 40 45
6 | 0 6 12 18 24 30 36 42 48 54
7 | 0 7 14 21 28 35 42 49 56 63
8 | 0 8 16 24 32 40 48 56 64 72
9 | 0 9 18 27 36 45 54 63 72 81

<table> should continue to be used. That's what it's for.

Use of CSS can and should always replace <font>.

<h1><font color="red" size="7">Big headline</h1>

should become

<style type="text/css">
h1.big {color: red; text-size: 400%;}
....
</style>
....
<h1 class="big">Big headline</h1>
 
N

Nikos

Fabian Pilkowski wrote:

Sorry man, but i still cant make the damn thinbg work:
I try to run it and still it aint running showing no values inside index.pl
Iam really pieced of...and my head hurts.

I hate html::tamplate. its trouble and nothign more since one has to
create first the html by himself with all the damn anooying eye
confusing tags.

The way i had it so far with cgi.pm i didnt have to mess with all those
tags and in my opinion the webpage was much more strighforward.
Please agree with me. You saw my index.pl
Even if you add the lines of your index.pl + index.tmpl agianst my
index.pl the way i have it used less code.

I was also wondering if there is a way to insert all my havascript code
i have indide index.pl to the style.css file so my perl file is more pure.
 
N

Nikos

Nikos wrote:

Guys i accidentaly lost the original index.pl i posted with the greek
chats and i have no backup.

please can someone post it back correctly?
I eman i can see it now on usenet form my post but the chars are not
greek, they are showing very weird and if i copy paste then i have a lot
more errors come up cause of the chars.

Damn i am complete messed up.
Please someone post my inde.xpl back correctly
 
T

Tad McClellan

Nikos said:
Fabian Pilkowski wrote:


Nikos:

PLEASE QUOTE SOME CONTEXT WHEN COMPOSING FOLLOWUPS!

Please do this very soon if you want the maximum readership
for your posts in the future.

Have you seen the Posting Guidelines that are posted here frequently?

Iam really pieced of...


Me too.
 
S

Scott Bryce

Nikos said:
I hate html::tamplate. its trouble and nothign more since one has to
create first the html by himself with all the damn anooying eye
confusing tags.

If you can't understand HTML, you won't be able to write CGI in Perl.

I was also wondering if there is a way to insert all my havascript
code i have indide index.pl to the style.css file so my perl file is
more pure.

No. If you put the Javascript inside the CSS file, it won't run.

You have been advised to learn HTML before you go much farther with this
project. If you won't do that, there isn't much we can do for you. You
have been given good answers to your Perl questions. You have been given
with examples. That is about as much as we can do in this newsgroup.

Your options are either 1) Go back to using CGI.pm to produce your HTML
or 2) Learn enough HTML to understand that side of the project before
proceeding any farther.

Please be advised that this newsgroup does not exist to help you with
HTML, or to listen to your rants about how much you hate perfectly good
Perl modules.
 
N

Nikos

Scott Bryce wrote:

ok iam still trying with this template thing:

here what i manage to do but still it has some erros i think which i
cant see:

#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI::Cookie;
use CGI qw:)standard);
use DBI;
use DBD::mysql;
use HTML::Template;

$tmpl = HTML::Template->new(filename => 'index.html');

@months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
$xronos = "$mday $months[$mon], $hour:$min";

$ip = $ENV{'REMOTE_ADDR'};
@numbers = split (/\./,$ip);
$address = pack ("C4", @numbers);
$host = gethostbyaddr ($address, 2) || $ip;
$host = "Íßêïò" if ( ($host eq "localhost") or ($host eq
"dslcustomer-221-228.vivodi.gr" or $host eq "dell") );

print header( -charset=>'iso-8859-7' );

$db = ($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 print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;

#*******************************************************************************
@files = <../data/text/*.txt>;
@display_files = map( /([^\/]+)\.txt/, @files );

$keimeno = param('select') or "Áñ÷éêÞ Óåëßäá";

$st = $db->prepare( "SELECT host FROM logs" );
$st->execute();
while( $row = $st->fetchrow_hashref ) {
if( $host eq $row->{host} ) {
$hostmatch = 1;
}
}

if( param('select') and param('select') !~ /\.\./ )
{
open(FILE, "<../data/text/$keimeno.txt") or die $!;
@data = <FILE>;
close(FILE);

$data = join('', @data);

$db->do( "UPDATE logs SET keimeno='$keimeno' WHERE host='$host'" )
or die $db->errstr;
}
elsif( $hostmatch == 1 )
{
$db->do( "UPDATE logs SET visits = visits + 1 WHERE host='$host'" )
or die $db->errstr;
$st = $db->prepare( "SELECT * FROM logs WHERE host='$host'" );
$st->execute();
$row = $st->fetchrow_hashref;

$data = "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçí óåëßäá
åíäéáöÝñïõóá!\n" .
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
..$row->{xronos}. " !!\n" .
"ÓýíïëéêÝò Þñèåò åäþ " .$row->{visits}. " öïñÝò!!!\n" .
"Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{keimeno}. " }\n" .
"Ðïéü êåßìåíï èá ìåëåôÞóåòé áõôÞí ôç öïñÜ !?";
}
elsif( $hostmatch != 1 )
{
if ( $host ne "6" )
{
$data = "1" .$host. "!\n" .
"2\n" .
"3...";

$db->do( "INSERT INTO logs VALUES (null, '$host', '$xronos',
'$text', 1)" ) or die $db->errstr;
}
else
{
$data = "4 $host :) 5 !?!";
}
}

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
$tmpl->param( data => $data );

# To fill TMPL_LOOPs you have to pass a reference to an array with
# references to hashes inside. And the inner hashes contain the data
# for the TMPL_VARs inside the TMPL_LOOP. Well, it's a bit tricky.

@display_files = map ( /([^\/]+)\.txt/, glob '../data/text/*.txt' );
@array_of_hashes = map { option => $_ }, @display_files;
$tmpl->param( options => \@array_of_hashes );

open(FILE, "<../data/text/tips") or die $!;
@tips = <FILE>;
close(FILE);

@tips = grep { !/^\s*\z/s } @tips;
$tip = $tips[int(rand(@tips))];

$db->do( "UPDATE counter SET counter = counter + 1" ) if ($host ne "Íßêïò");

$st = $db->prepare( "SELECT counter FROM counter" );
$st->execute();
$row = $st->fetchrow_hashref;

$tip = $tips[ int rand @tips ];
$tmpl->param( tip => $tip );

$tmpl->param(host => $host);
$tmpl->param(xronos => $xronos);
$tmpl->param(counter => $counter);

# Appropriate headers go here
print $tmpl->output;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top