N
Nikos
Is there a way to put those 2 javascript snippets that are currently
embedded inside index.pl into 1 or 2 separate files because index.pl
now has gone very huge, but also index.pl to remain functional?
#===============================================================================
my $js = <<EOH;
function addFromList() {
var popup = document.getElementById('title');
var olist = document.getElementById('ordered_items');
for (var i = 0; i<popup.options.length;i++) {
if(popup.options.selected) {
var item = popup.options.value;
// if you want to allow multiple instances
// of the same item in your list, remove the
// next three lines.
for(var j = 0; j<olist.options.length; j++) {
if (olist.options[j].value == item) return;
}
var opt = new Option(item,item,false,false);
olist.options[olist.options.length] = opt;
}
}
}
function addFromEntry () {
var olist = document.getElementById('ordered_items');
var entry = document.getElementById('requesttext');
if(entry.value != '') {
var opt = new Option(entry.value,entry.value, false,false);
olist.options[olist.options.length] = opt;
}
}
function removeFromList () {
var olist = document.getElementById('ordered_items');
for (var i = olist.options.length - 1; i>=0; i--) {
if (olist.options.selected) {
olist.options = null;
}
}
olist.selectedIndex = -1;
}
function selectAll() {
var olist = document.getElementById('ordered_items');
for (var i = 0; i<olist.options.length; i++) {
olist.options.selected = true;
}
}
EOH
#===============================================================================
print header( -charset=>'utf-8' );
print start_html( -script => $js,
-style=>'/data/css/style.css',
-title=>'Order Project!' );
print a( {href=>'/cgi-bin/register.pl'}, img{src=>'/data/images/
reg.jpg'} );
my @userlist = @{ $db->selectcol_arrayref("SELECT username FROM
users") };
print start_form( action=>'/cgi-bin/index.pl' );
print h1( {class=>'lime'}, "ÊÜíå LOGIN ãéá íá äåéò ôéò
ðáñáããåëßåò óïõ ìÝ÷ñé óôéãìÞò => ",
popup_menu( -name => 'userlogin', -
values => \@userlist ),
submit('Óýíäåóç!'));
print end_form;
my $userlogin = param('userlogin');
if ( param('Óýíäåóç!') )
{
unless( grep { $_ eq $userlogin }
@userlist ) #Check if userlogin name exists in
the drop down menu
{
print br() x 2, h1( {class=>'big'}, "Äåí õðÜñ÷åé ÷ñÞóôçò ìå
üíïìá: $userlogin" );
exit;
}
$select = $db->prepare( "SELECT host FROM guestlog WHERE
host=?" );
$select->execute( $host );
if ($select->rows)
{
$select = $db->prepare( "SELECT host, DATE_FORMAT(date, '%a %d
%b, %h:%i') AS date, counter FROM guestlog WHERE host=?" );
$select->execute( $host );
$row = $select->fetchrow_hashref;
$data = "Êáëþò Þëèåò $userlogin! ×áßñïìáé ðïõ âñßóêåéò ôçí
óåëßäá åíäéáöÝñïõóá.
Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò $row->{host} óôéò $row-
Ôß èá ðÜñåéò óÞìåñá !?";
$select = $db->prepare( "UPDATE guestlog SET date=?,
counter=counter+1 WHERE host=?" );
$select->execute( $date, $host );
}
}
else
{
if ($host eq "Íßêïò") {
$data = "ÃåéÜ óïõ Íéêüëá! Ðþò ðÜíå ôá êÝöéá? ;-)";
}
else {
$data = "ÃåéÜ óïõ $host!
¸ñ÷åóáé ãéá 1ç öïñÜ åäþ!!
Åëðßæù íá âñåßò üëï ôï ëïãéóìéêü ðïõ åðéèõìåßò ";
}
unless ($host eq "Íßêïò") {
$select = $db->prepare( "INSERT INTO guestlog (host, date,
counter) VALUES (?, ?, ?)" );
$select->execute( $host, $date, 1 );
}
}
for ($data) {
s/\n/\\n/g;
s/"/\\"/g;
tr/\cM//d;
}
#===============================================================================
print <<ENDOFHTML;
<script type='text/javascript'>
var textToShow = "$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 >= 3000 && (c.charCodeAt(0) == 10 || c == "."))
{
d.appendChild(document.createElement("br"));
d.appendChild(document.createTextNode("Press a key to
continue..."));
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="
overflow: auto;
background-image: url(/data/images/vortex.jpg);
border: Ridge Magenta 5px;
width: 1100px;
height: 100px;
color: Cyan;
font-family: Bookman;
font-size: 16px;">
</div>
ENDOFHTML
#===============================================================================
embedded inside index.pl into 1 or 2 separate files because index.pl
now has gone very huge, but also index.pl to remain functional?
#===============================================================================
my $js = <<EOH;
function addFromList() {
var popup = document.getElementById('title');
var olist = document.getElementById('ordered_items');
for (var i = 0; i<popup.options.length;i++) {
if(popup.options.selected) {
var item = popup.options.value;
// if you want to allow multiple instances
// of the same item in your list, remove the
// next three lines.
for(var j = 0; j<olist.options.length; j++) {
if (olist.options[j].value == item) return;
}
var opt = new Option(item,item,false,false);
olist.options[olist.options.length] = opt;
}
}
}
function addFromEntry () {
var olist = document.getElementById('ordered_items');
var entry = document.getElementById('requesttext');
if(entry.value != '') {
var opt = new Option(entry.value,entry.value, false,false);
olist.options[olist.options.length] = opt;
}
}
function removeFromList () {
var olist = document.getElementById('ordered_items');
for (var i = olist.options.length - 1; i>=0; i--) {
if (olist.options.selected) {
olist.options = null;
}
}
olist.selectedIndex = -1;
}
function selectAll() {
var olist = document.getElementById('ordered_items');
for (var i = 0; i<olist.options.length; i++) {
olist.options.selected = true;
}
}
EOH
#===============================================================================
print header( -charset=>'utf-8' );
print start_html( -script => $js,
-style=>'/data/css/style.css',
-title=>'Order Project!' );
print a( {href=>'/cgi-bin/register.pl'}, img{src=>'/data/images/
reg.jpg'} );
my @userlist = @{ $db->selectcol_arrayref("SELECT username FROM
users") };
print start_form( action=>'/cgi-bin/index.pl' );
print h1( {class=>'lime'}, "ÊÜíå LOGIN ãéá íá äåéò ôéò
ðáñáããåëßåò óïõ ìÝ÷ñé óôéãìÞò => ",
popup_menu( -name => 'userlogin', -
values => \@userlist ),
submit('Óýíäåóç!'));
print end_form;
my $userlogin = param('userlogin');
if ( param('Óýíäåóç!') )
{
unless( grep { $_ eq $userlogin }
@userlist ) #Check if userlogin name exists in
the drop down menu
{
print br() x 2, h1( {class=>'big'}, "Äåí õðÜñ÷åé ÷ñÞóôçò ìå
üíïìá: $userlogin" );
exit;
}
$select = $db->prepare( "SELECT host FROM guestlog WHERE
host=?" );
$select->execute( $host );
if ($select->rows)
{
$select = $db->prepare( "SELECT host, DATE_FORMAT(date, '%a %d
%b, %h:%i') AS date, counter FROM guestlog WHERE host=?" );
$select->execute( $host );
$row = $select->fetchrow_hashref;
$data = "Êáëþò Þëèåò $userlogin! ×áßñïìáé ðïõ âñßóêåéò ôçí
óåëßäá åíäéáöÝñïõóá.
Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò $row->{host} óôéò $row-
Ðñïçãïýìåíïò áñéèìþíåðéóêÝøåùí => $row->{counter}{date} !
Ôß èá ðÜñåéò óÞìåñá !?";
$select = $db->prepare( "UPDATE guestlog SET date=?,
counter=counter+1 WHERE host=?" );
$select->execute( $date, $host );
}
}
else
{
if ($host eq "Íßêïò") {
$data = "ÃåéÜ óïõ Íéêüëá! Ðþò ðÜíå ôá êÝöéá? ;-)";
}
else {
$data = "ÃåéÜ óïõ $host!
¸ñ÷åóáé ãéá 1ç öïñÜ åäþ!!
Åëðßæù íá âñåßò üëï ôï ëïãéóìéêü ðïõ åðéèõìåßò ";
}
unless ($host eq "Íßêïò") {
$select = $db->prepare( "INSERT INTO guestlog (host, date,
counter) VALUES (?, ?, ?)" );
$select->execute( $host, $date, 1 );
}
}
for ($data) {
s/\n/\\n/g;
s/"/\\"/g;
tr/\cM//d;
}
#===============================================================================
print <<ENDOFHTML;
<script type='text/javascript'>
var textToShow = "$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 >= 3000 && (c.charCodeAt(0) == 10 || c == "."))
{
d.appendChild(document.createElement("br"));
d.appendChild(document.createTextNode("Press a key to
continue..."));
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="
overflow: auto;
background-image: url(/data/images/vortex.jpg);
border: Ridge Magenta 5px;
width: 1100px;
height: 100px;
color: Cyan;
font-family: Bookman;
font-size: 16px;">
</div>
ENDOFHTML
#===============================================================================