Solved

How to add?

Posted on 2002-03-19
8
182 Views
Last Modified: 2013-12-25
Hello:

I would like to add more picture in this ecard scripts, but I am not sure what I have to change? I understand that the change should be near or similar to line number 564.

Here is the code :

#!/usr/bin/perl

# Web browser URL to your script's directory with a slash on the end
$link = "http://www.domain.com/cgi-bin/postcards/kids/";

# title of your system
$title = "your greetings card.com";

# header containing <body> control for colours of your post card system
$html = "<html><title>$title - Send someone an electronic post card.</title><body bgcolor=#ffffff text=#000000 link=black vlink=white alink=yellow><style>a {text-decoration:none }</style>";

# table cell colours setup
$table1 = "#000000";
$table2 = "#F4e6bf";
$table3 = "#F4e6bf";
$table4 = "#F4e6bf";

# path to your mail sending program
$mailprog = "/usr/sbin/sendmail";

# Web browser URL to images with a slash on the end
$imgPathWeb = "http://www.domain.com/postcards/kids/images/";
# or $imgPathWeb = "http://www.domain.com/scripts/dpostlite/";



#------------- DO NOT EDIT BELOW THIS LINE ---------------#







($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) =
      localtime(time);
$longyr = $year + 1900;
$fixmo = $mon + 1;
if ($isdst == 1) {
      $tz = "CDT";
} else {
      $tz = "CST";
}
$yr2 = substr($longyr,2,2);

$date = "$mday/$fixmo/$longyr";

print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ tr/|//;
    $value =~ tr/<//;
    $value =~ tr/>//;
    $FORM{$name} = $value;
}

read(STDIN, $buffer, $ENV{'QUERY_STRING'});
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM2{$name} = $value;
}

$FORM{message} =~ s/</[/g;
$FORM{message} =~ s/>/]/g;
$FORM{message} =~ s/\n/<br>/g;
$FORM{message} =~ s/\r//g;

if ($FORM2{action} eq "") { $FORM2{type} ="images"; &build }
if ($FORM2{action} eq "preview") { &preview }
if ($FORM2{action} eq "send") { &send }
if ($FORM2{action} eq "pickup") { &pickup }
if ($FORM2{action} eq "build") { &build }
else { &types }

sub preview {

if ($FORM{shot} eq "") { $msg = "Make sure you choose one of the pictures to send."; &error }
if ($FORM{toemail} eq "") { $msg = "Make sure you specify an email address to send the post card to."; &error }
if ($FORM{sendemail} eq "") { $notify = "" }
if ($FORM{message} eq "") { $msg = "Make sure you type a message to send with the postcard."; &error }
if ($FORM{sendname} eq"") { $FORM{sendname} = "Anonymous"; }

$FORM{sendemail} =~ tr/"//;
$FORM{sendname} =~ tr/"//;
$FORM{toname} =~ tr/"//;
$FORM{toemail} =~ tr/"//;
$FORM{message} =~ tr/"/'/;

if ($FORM{toemail} > "") {
      if ($FORM{toemail} =~ "\@") { }
      else { $msg = "The 'To' email address is invalid."; &error }
}

if ($FORM{sendemail} > "") {
      if ($FORM{sendemail} =~ "\@") { }
      else { $msg = "The 'From' email address is invalid."; &error }
}

open(INF,"cards.txt");
      @typesx = <INF>;
close(INF);

foreach $yehy (@typesx) {
      ($code,$name,$types) = split(/\|/, $yehy);
      if ($code eq $FORM2{type}) { $yeh2y = $yehy }
}

if ($yeh2y eq "") { exit }

($code,$name,$types) = split(/\|/, $yeh2y);

(@types) = split(/\,/, $types);


print <<"EOF";

$html

<center>
<font face=Arial size=3>
<b>Preview Your Post Card</b><br>

<Br>

<table bgcolor=$table1 border=0 cellpadding=1 cellspacing=0><tr><Td>
<table width=500 cellpadding=4 cellspacing=1 border=0>
 <tr>
  <td colspan=2 bgcolor=black><center>
<img src="
EOF
print $imgPathWeb;

print <<"EOF";
post$FORM{shot}.jpg" border=1><br>
  </td>
 </tr>
 <tr>
  <td colspan=2 bgcolor=$table2><center><font size=2>
<b>@types[$FORM{shot} - 1]<Br><br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>From: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
$FORM{sendname}<br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$FORM{sendemail}>$FORM{sendemail}<br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>To: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
$FORM{toname}<br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$FORM{toemail}>$FORM{toemail}<br>
  </td>
 </tr>


 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Date: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
$date<br>
  </td>
 </tr>

 <tr valign=top>
  <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>Message<br>
  </td>
 </tr>
 <tr valign=top>
  <td width=400 bgcolor=$table4 colspan=2><font face=Arial size=2>
$FORM{message}<br>
  </td>
 </tr>
 <tr valign=top>
  <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>---<br>
  </td>
 </tr>

</table>
</td></tr></table>
<br>
<font face=Arial size=2>
<center>If you wish to use this service to send a postcard, please click <a href=kids.pl><font color=red>here</a></font>.<br>
<br>
<hr width=80%>
End of preview.
<form method=post action=kids.pl?action=send&type=$FORM2{type}>

<input type=hidden name=shot value="$FORM{shot}">
<input type=hidden name=sendname value="$FORM{sendname}">
<input type=hidden name=sendemail value="$FORM{sendemail}">
<input type=hidden name=toname value="$FORM{toname}">
<input type=hidden name=toemail value="$FORM{toemail}">
<input type=hidden name=message value="$FORM{message}">
<input type=hidden name=notify value="$FORM{notify}">

<input type=Submit value="Send Postcard"><br>

</form>

<SCRIPT="JavaScript">
<FORM>
<INPUT TYPE="button" VALUE="Edit Card" onClick="history.go(-1)">
</FORM>
</SCRIPT>


</body>
</html>

EOF

exit;

}


sub send {

opening1:
open(INF,"cardinfo.txt") or retryfile1;
      @count = <INF>;
close(INF);

$x = 1;

foreach $yeh (@count) {
      $x = $x + 1;
}

@count = ();

$pass = random_password();

opening2:
open(OUTF,">>cardinfo.txt") or retryfile2;
      flock(OUTF,2);
      print OUTF "$FORM2{type}|$x|$FORM{shot}|$FORM{sendname}|$FORM{sendemail}|$FORM{toname}|$FORM{toemail}|$FORM{message}|$FORM{notify}|$FORM{music}|$date|$pass\n";
close(OUTF);

open (MAIL, "|$mailprog -t") or emailfail();
      print MAIL "To: $FORM{toname} <$FORM{toemail}>\n";
      print MAIL "From: webmaster\@domain.com\n";
      print MAIL "Subject: You have a $title\n\n";

      print MAIL "Hello $FORM{toname},\n\n";

      print MAIL "You have been sent a $title from $FORM{sendname}.\n\n";

      print MAIL "To pick up your electronic postcard, please go to the following URL:\n\n";

$link2 = "kids.pl?action=pickup&xrs=$x&imf=$pass\n\n";

      print MAIL "$link$link2";

      print MAIL "Thank you.\n\n";
close(MAIL);

print "$html";

print "<center><font face=Arial size=3><br><br>";
print "Your post card has been sent to <b>$FORM{toname}</b> at <b>$FORM{toemail}</b>.<br><br>";
print "Thank you for using $title.  To send another post card, please click <a href=http://www.domain.com/postcard.html><font color=red>here</a>.<br>";

exit;
}


sub pickup {

opening3:
open(INF,"cardinfo.txt") or retryfile3;
      @count = <INF>;
close(INF);

foreach $yeh (@count) {
      $x1 = $x1 + 1;
      chomp($yeh);
      if ($x1 == int($FORM2{xrs})) { ($type,$x2,$shot,$sendname,$sendemail,$toname,$toemail,$message,$notify,$track,$sdate,$pass) = split(/\|/,$yeh);
            if ($FORM2{imf} eq $pass) { @count = (); &pickup2 }
      }
}

print "$html<br>Invalid ID/password combination in URL.  Aborting!"; exit;
}


sub pickup2 {

$message =~ s/\[/\</g;
$message =~ s/\]/\>/g;


open(INF,"cards.txt");
      @typesx = <INF>;
close(INF);

foreach $yehy (@typesx) {
      ($code,$name,$types) = split(/\|/, $yehy);
      if ($code eq $type) { $yeh2y = $yehy }
}

if ($yeh2y eq "") { exit }

($code,$name,$types) = split(/\|/, $yeh2y);

(@types) = split(/\,/, $types);



print <<"EOF";

$html

<center>
<font face=Arial size=3>
<b>To $toname:</b><br>

<Br>

<table bgcolor=$table1 border=0 cellpadding=1 cellspacing=0><tr><Td>
<table width=500 cellpadding=4 cellspacing=1 border=0>
 <tr>
  <td colspan=2 bgcolor=black><center>
<img src="
EOF
print $imgPathWeb;
print <<"EOF";
post$shot.jpg" border=1><br>
  </td>
 </tr>
 <tr>
  <td colspan=2 bgcolor=$table2><center><font size=2>
<b>@types[$shot - 1]<Br><br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>From: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
$sendname<br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$sendemail>$sendemail<br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>To: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
$toname<br>
  </td>
 </tr>

 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$toemail>$toemail<br>
  </td>
 </tr>


 <tr valign=top>
  <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Date: <br>
  </td>
  <td width=400 bgcolor=$table4><font face=Arial size=2>
$sdate<br>
  </td>
 </tr>

 <tr valign=top>
  <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>Message<br>
  </td>
 </tr>
 <tr valign=top>
  <td width=400 colspan=2 bgcolor=$table4><font face=Arial size=2>
$message<br>
  </td>
 </tr>
 <tr valign=top>
  <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>---<br>
  </td>
 </tr>

</table>
</td></tr></table>
<br>
<font face=Arial size=2>
<center>If you wish to use this service to send a postcard, please click <a href=http://www.domain.com/postcard.html><font color=blue>here</a>.<br>
<br>


</body>
</html>

EOF

opening4:
open(INF,"cardinfo.txt") or retryfile4;
      @count = <INF>;
close(INF);

$x1 = 0;
foreach $yeh (@count) {
      chomp($yeh);
      $x1 = $x1 + 1;
      if ($x1 == int($FORM2{xrs})) { ($type,$x2,$shot,$sendname,$sendemail,$toname,$toemail,$message,$notify,$track,$sdate,$pass) = split(/\|/,$yeh);
            @count[$x1 - 1] = "$type|$x2|$shot|$sendname|$sendemail|$toname|$toemail|$message|off|$track|$sdate|$pass";
            if ($notify eq "on") { $notifynow = 1 };
      }
}

opening5:
open(OUTF,">cardinfo.txt") or retryfile5;
      flock(OUTF,2);
      foreach $yeh (@count) {
            print OUTF "$yeh\n";
      }
close(OUTF);


if ($notifynow == 1) {
open (MAIL, "|$mailprog -t") or emailfail();
      print MAIL "To: $sendname <$sendemail>\n";
      print MAIL "From: webmaster\@domain.com\n";
      print MAIL "Subject: $toname has received your post card\n\n";

      print MAIL "This email is just to let you know that $toname ($toemail) has received your $title postcard on $date.\n\n";

      print MAIL "Thank you for using our service.\n\n";
close(MAIL);
}

exit;
}


exit;

sub types {

print "$html<font face=Arial size=3>";
print "<br><center><img src=\"" . $imgPathWeb . "welcome.gif\"><br>";
print "<b>Welcome to the $title post card system.</b><br><br></center>";
print "<font size=2>Please select the type of post card you wish to send:<br><br>";

open

open(INF,"cards.txt");
      @types = <INF>;
close(INF);

foreach $yeh (@types) {
      ($code,$name,$types) = split(/\|/, $yeh);
      print "<li><a href=\"kids.pl?action=build&type=$code\">$name</a>";
}

print "<br><Br>";

exit;
}






sub build {


open(INF,"cards.txt");
      @typesx = <INF>;
close(INF);


foreach $yeh (@typesx) {
      ($code,$name,$types) = split(/\|/, $yeh);
      if ($code eq $FORM2{type}) { $yeh2 = $yeh }
}

if ($yeh2 eq "") { exit }

($code,$name,$types) = split(/\|/, $yeh2);

(@types) = split(/\,/, $types);

print $html;

print <<"EOF";
<center>
<font face=Arial size=3>
<b>$title Electronic Post Card Service</b><br>

<Br>

<form method=post action=kids.pl?action=preview&type=$FORM2{type}>

<table bgcolor=$table1 border=0 cellpadding=1 cellspacing=0><tr><Td>
<table width=700 cellpadding=4 cellspacing=1 border=0>
 <tr valign=top>
  <td bgcolor=$table3 colspan=5><font face=Arial size=2><center>
Please select which picture to send (click to enlarge):<br><br>
  </td>
 </tr>
 <tr valign=top>
EOF

for ($i=1; $i!=6; $i++) {
  print "  <td bgcolor=$table3 width=140><center><a href=\"" . $imgPathWeb . "post$i.jpg\" target=_blank><img src=\"" . $imgPathWeb . "post$i.gif\"><br>  </td>\n";
}

print <<"EOF";

 </tr> <tr valign=top>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=1>@types[0]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=2>@types[1]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=3>@types[2]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=4>@types[3]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=5>@types[4]<br><br>
  </td>
 </tr>
 <tr valign=top>
EOF

for ($i=6; $i!=11; $i++) {
  $i2 = $i;
  if ($i2 == 10) { $i2 = "0" }
  print "  <td bgcolor=$table3 width=140><center><a href=\"" . $imgPathWeb . "post$i2.jpg\" target=_blank><img src=\"" . $imgPathWeb . "post$i2.gif\"><br>  </td>\n";
}


print <<"EOF";
 </tr>
 <tr valign=top>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=6>@types[5]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=7>@types[6]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=8>@types[7]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=9>@types[8]<br>
  </td>
  <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=0>@types[9]<br><br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<br><br><b><u>From<br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
From name: <br>
  </td>
  <td bgcolor=$table3 colspan=4>
<input type=text name="sendname" maxlength=200 size=40><br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
From email: <br>
  </td>
  <td bgcolor=$table3 colspan=4>
<input type=text name="sendemail" maxlength=200 size=40><br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<b><u><br><br>To<br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
To name: <br>
  </td>
  <td bgcolor=$table3 colspan=4>
<input type=text name="toname" maxlength=200 size=40><br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
To email: <br>
  </td>
  <td bgcolor=$table3 colspan=4>
<input type=text name="toemail" maxlength=200 size=40><br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<b><u><br><br>Text message<br>
  </td>
 </tr>

 <tr valign=top>
  <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
Message: <br>
  </td>
  <td bgcolor=$table3 colspan=4>
<textarea name="message" rows=15 cols=60 wrap=soft></textarea><br>
  </td>
 </tr>

 <tr>
  <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<b><u><br><br>Option<br>
  </td>
 </tr>

 <tr valign=top>
  <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
&nbsp;<br>
  </td>
  <td bgcolor=$table3 colspan=4><font face=Arial size=2>
<input type=checkbox name=notify>&nbsp;&nbsp;Notify me via email when user has received my postcard.<br>
  </td>
 </tr>


</table>
 </td></tr></table>
<br>
</center>
</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=Submit value="Preview Postcard">&nbsp;&nbsp;&nbsp;<input type=Reset value="Reset Form"><br>

</form>


</body>
</html>







EOF
exit;

}









sub emailfail { print "Can not access mail program on this server."; exit; }

sub retryfile1 { goto opening1 }
sub retryfile2 { goto opening2 }
sub retryfile3 { goto opening3 }
sub retryfile4 { goto opening4 }
sub retryfile5 { goto opening5 }

sub random_password {
        ($length) = @_;
        if ($length eq "" or $length < 3) {
                $length = 6;            # make it at least 6 chars long.
        }
        $vowels = "aeiouyAEUY";
        $consonants = "bdghjmnpqrstvwxzBDGHJLMNPQRSTVWXZ12345678";
        srand(time() ^ ($$ + ($$ << 15)) );
        $alt = int(rand(2)) - 1;
        $s = "";
        $newchar = "";
        foreach $i (0..$length-1) {
                if ($alt == 1) {
                        $newchar =
substr($vowels,rand(length($vowels)),1);
                } else {
                        $newchar = substr($consonants,
                                rand(length($consonants)),1);
                }
                $s .= $newchar;
                $alt = !$alt;
        }
        return $s;
}

sub error {

print <<"EOF";

$html
<font face=arial size=2>
There is an error in your form!<br>
$msg<br><br>
<SCRIPT="JavaScript">
<FORM>
<INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)">
</FORM>
</SCRIPT>

EOF

exit;
}
-----------------------------------------------------
Thanks in advance for your help.

Rana
0
Comment
Question by:Sohel Rana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 5

Expert Comment

by:Peewee
ID: 6882213
rsdn,
i have looked at your script. It looks like line 564 reads in six postcards, all which have a suffix number.  Therefore if this is the case copy your new postards in a give them an identical naming convention with an ammended suffix.  Then ammend the following statement to the new number of cards:

current:
for ($i=1; $i!=6; $i++)

for ten cards:
for ($i=1; $i!=10; $i++)

let me knwo if you need naymore help
regards
peewee
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6882219
rsdn,
in the event of any further problems can you paste the conents of your image directory here, ie all the image files, this will help greatly if we have limited success first time around..

regards
peewee
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 6882275
first of all change the directories.

and then i guess this prog. shows all images in the directory you mentioned.
i didn't see what Peewee changed but it looked like it was the number of images to be displayed per page. i guess.

waititng for re feedback

lhn
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 16

Author Comment

by:Sohel Rana
ID: 6884455
Hello Peewee:

About image directory there are ten pictures but it has two of images. To show thumbnail first picture is 0.gif which represent the card number 1 actually. For postcard image it shows the full image name 0.jpg

Though there are 10 postcard, but it has number 9 because the place of number 1 takes 0.I think you understand what I mean. You told that there are six picture but there are five picture in each column. So I just want to add more column. Now there are two column contains 10 picture.

Please notice that there is one .txt file which contains the picture title or name. Inside this file it contains these lines :

images|General|Kids 1,Kids 2,Kids 3,Kids 4,Kids 5,Kids 6,Kids 7,Kids 8,Kids 9,Kids 10

If you need any other information, please let me know.

Rana
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6885068
rsdn,
did you try my ammendment?

what result did it vhange?

peewee
0
 
LVL 5

Accepted Solution

by:
Peewee earned 100 total points
ID: 6888234
rsdn,
this will increase your cards from 10 - 15.  Make sure you edit the relevant .txt files to get your captions etc, ie cards.txt  & cardinfo.txt.
In addittion yo will need to add your new postacrd pics in the relevant directory namely http://www.domain.com/postcards/kids/images/ and use the standard naming convention which i believe is post*.jpg.

let me know how it goes.

regards
peewee

#!/usr/bin/perl

# Web browser URL to your script's directory with a slash on the end
$link = "http://www.domain.com/cgi-bin/postcards/kids/";

# title of your system
$title = "your greetings card.com";

# header containing <body> control for colours of your post card system
$html = "<html><title>$title - Send someone an electronic post card.</title><body bgcolor=#ffffff text=#000000
link=black vlink=white alink=yellow><style>a {text-decoration:none }</style>";

# table cell colours setup
$table1 = "#000000";
$table2 = "#F4e6bf";
$table3 = "#F4e6bf";
$table4 = "#F4e6bf";

# path to your mail sending program
$mailprog = "/usr/sbin/sendmail";

# Web browser URL to images with a slash on the end
$imgPathWeb = "http://www.domain.com/postcards/kids/images/";
# or $imgPathWeb = "http://www.domain.com/scripts/dpostlite/";



#------------- DO NOT EDIT BELOW THIS LINE ---------------#







($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) =
     localtime(time);
$longyr = $year + 1900;
$fixmo = $mon + 1;
if ($isdst == 1) {
     $tz = "CDT";
} else {
     $tz = "CST";
}
$yr2 = substr($longyr,2,2);

$date = "$mday/$fixmo/$longyr";

print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ tr/|//;
   $value =~ tr/<//;
   $value =~ tr/>//;
   $FORM{$name} = $value;
}

read(STDIN, $buffer, $ENV{'QUERY_STRING'});
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $FORM2{$name} = $value;
}

$FORM{message} =~ s/</[/g;
$FORM{message} =~ s/>/]/g;
$FORM{message} =~ s/\n/<br>/g;
$FORM{message} =~ s/\r//g;

if ($FORM2{action} eq "") { $FORM2{type} ="images"; &build }
if ($FORM2{action} eq "preview") { &preview }
if ($FORM2{action} eq "send") { &send }
if ($FORM2{action} eq "pickup") { &pickup }
if ($FORM2{action} eq "build") { &build }
else { &types }

sub preview {

if ($FORM{shot} eq "") { $msg = "Make sure you choose one of the pictures to send."; &error }
if ($FORM{toemail} eq "") { $msg = "Make sure you specify an email address to send the post card to.";
&error }
if ($FORM{sendemail} eq "") { $notify = "" }
if ($FORM{message} eq "") { $msg = "Make sure you type a message to send with the postcard."; &error
}
if ($FORM{sendname} eq"") { $FORM{sendname} = "Anonymous"; }

$FORM{sendemail} =~ tr/"//;
$FORM{sendname} =~ tr/"//;
$FORM{toname} =~ tr/"//;
$FORM{toemail} =~ tr/"//;
$FORM{message} =~ tr/"/'/;

if ($FORM{toemail} > "") {
     if ($FORM{toemail} =~ "\@") { }
     else { $msg = "The 'To' email address is invalid."; &error }
}

if ($FORM{sendemail} > "") {
     if ($FORM{sendemail} =~ "\@") { }
     else { $msg = "The 'From' email address is invalid."; &error }
}

open(INF,"cards.txt");
     @typesx = <INF>;
close(INF);

foreach $yehy (@typesx) {
     ($code,$name,$types) = split(/\|/, $yehy);
     if ($code eq $FORM2{type}) { $yeh2y = $yehy }
}

if ($yeh2y eq "") { exit }

($code,$name,$types) = split(/\|/, $yeh2y);

(@types) = split(/\,/, $types);


print <<"EOF";

$html

<center>
<font face=Arial size=3>
<b>Preview Your Post Card</b><br>

<Br>

<table bgcolor=$table1 border=0 cellpadding=1 cellspacing=0><tr><Td>
<table width=500 cellpadding=4 cellspacing=1 border=0>
<tr>
 <td colspan=2 bgcolor=black><center>
<img src="
EOF
print $imgPathWeb;

print <<"EOF";
post$FORM{shot}.jpg" border=1><br>
 </td>
</tr>
<tr>
 <td colspan=2 bgcolor=$table2><center><font size=2>
<b>@types[$FORM{shot} - 1]<Br><br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>From: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
$FORM{sendname}<br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$FORM{sendemail}>$FORM{sendemail}<br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>To: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
$FORM{toname}<br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$FORM{toemail}>$FORM{toemail}<br>
 </td>
</tr>


<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Date: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
$date<br>
 </td>
</tr>

<tr valign=top>
 <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>Message<br>
 </td>
</tr>
<tr valign=top>
 <td width=400 bgcolor=$table4 colspan=2><font face=Arial size=2>
$FORM{message}<br>
 </td>
</tr>
<tr valign=top>
 <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>---<br>
 </td>
</tr>

</table>
</td></tr></table>
<br>
<font face=Arial size=2>
<center>If you wish to use this service to send a postcard, please click <a href=kids.pl><font color=red>here</a></font>.<br>
<br>
<hr width=80%>
End of preview.
<form method=post action=kids.pl?action=send&type=$FORM2{type}>

<input type=hidden name=shot value="$FORM{shot}">
<input type=hidden name=sendname value="$FORM{sendname}">
<input type=hidden name=sendemail value="$FORM{sendemail}">
<input type=hidden name=toname value="$FORM{toname}">
<input type=hidden name=toemail value="$FORM{toemail}">
<input type=hidden name=message value="$FORM{message}">
<input type=hidden name=notify value="$FORM{notify}">

<input type=Submit value="Send Postcard"><br>

</form>

<SCRIPT="JavaScript">
<FORM>
<INPUT TYPE="button" VALUE="Edit Card" onClick="history.go(-1)">
</FORM>
</SCRIPT>


</body>
</html>

EOF

exit;

}


sub send {

opening1:
open(INF,"cardinfo.txt") or retryfile1;
     @count = <INF>;
close(INF);

$x = 1;

foreach $yeh (@count) {
     $x = $x + 1;
}

@count = ();

$pass = random_password();

opening2:
open(OUTF,">>cardinfo.txt") or retryfile2;
     flock(OUTF,2);
     print OUTF "$FORM2{type}|$x|$FORM{shot}|$FORM{sendname}|$FORM{sendemail}|$FORM{toname}|$FORM{toemail}|$FORM{message}|$FORM{notify}|$FORM{music}|$date|$pass\n";
close(OUTF);

open (MAIL, "|$mailprog -t") or emailfail();
     print MAIL "To: $FORM{toname} <$FORM{toemail}>\n";
     print MAIL "From: webmaster\@domain.com\n";
     print MAIL "Subject: You have a $title\n\n";

     print MAIL "Hello $FORM{toname},\n\n";

     print MAIL "You have been sent a $title from $FORM{sendname}.\n\n";

     print MAIL "To pick up your electronic postcard, please go to the following URL:\n\n";

$link2 = "kids.pl?action=pickup&xrs=$x&imf=$pass\n\n";

     print MAIL "$link$link2";

     print MAIL "Thank you.\n\n";
close(MAIL);

print "$html";

print "<center><font face=Arial size=3><br><br>";
print "Your post card has been sent to <b>$FORM{toname}</b> at <b>$FORM{toemail}</b>.<br><br>";
print "Thank you for using $title.  To send another post card, please click <a href=http://www.domain.com/postcard.html><font color=red>here</a>.<br>";

exit;
}


sub pickup {

opening3:
open(INF,"cardinfo.txt") or retryfile3;
     @count = <INF>;
close(INF);

foreach $yeh (@count) {
     $x1 = $x1 + 1;
     chomp($yeh);
     if ($x1 == int($FORM2{xrs})) { ($type,$x2,$shot,$sendname,$sendemail,$toname,$toemail,$message,$notify,$track,$sdate,$pass)
= split(/\|/,$yeh);
          if ($FORM2{imf} eq $pass) { @count = (); &pickup2 }
     }
}

print "$html<br>Invalid ID/password combination in URL.  Aborting!"; exit;
}


sub pickup2 {

$message =~ s/\[/\</g;
$message =~ s/\]/\>/g;


open(INF,"cards.txt");
     @typesx = <INF>;
close(INF);

foreach $yehy (@typesx) {
     ($code,$name,$types) = split(/\|/, $yehy);
     if ($code eq $type) { $yeh2y = $yehy }
}

if ($yeh2y eq "") { exit }

($code,$name,$types) = split(/\|/, $yeh2y);

(@types) = split(/\,/, $types);



print <<"EOF";

$html

<center>
<font face=Arial size=3>
<b>To $toname:</b><br>

<Br>

<table bgcolor=$table1 border=0 cellpadding=1 cellspacing=0><tr><Td>
<table width=500 cellpadding=4 cellspacing=1 border=0>
<tr>
 <td colspan=2 bgcolor=black><center>
<img src="
EOF
print $imgPathWeb;
print <<"EOF";
post$shot.jpg" border=1><br>
 </td>
</tr>
<tr>
 <td colspan=2 bgcolor=$table2><center><font size=2>
<b>@types[$shot - 1]<Br><br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>From: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
$sendname<br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$sendemail>$sendemail<br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>To: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
$toname<br>
 </td>
</tr>

<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Email: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
<a href=mailto:$toemail>$toemail<br>
 </td>
</tr>


<tr valign=top>
 <td align=right width=100 bgcolor=$table3><font face=Arial size=2>
<b>Date: <br>
 </td>
 <td width=400 bgcolor=$table4><font face=Arial size=2>
$sdate<br>
 </td>
</tr>

<tr valign=top>
 <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>Message<br>
 </td>
</tr>
<tr valign=top>
 <td width=400 colspan=2 bgcolor=$table4><font face=Arial size=2>
$message<br>
 </td>
</tr>
<tr valign=top>
 <td colspan=2 width=100 bgcolor=$table3><font face=Arial size=2>
<center><b>---<br>
 </td>
</tr>

</table>
</td></tr></table>
<br>
<font face=Arial size=2>
<center>If you wish to use this service to send a postcard, please click <a href=http://www.domain.com/postcard.html><font color=blue>here</a>.<br>
<br>


</body>
</html>

EOF

opening4:
open(INF,"cardinfo.txt") or retryfile4;
     @count = <INF>;
close(INF);

$x1 = 0;
foreach $yeh (@count) {
     chomp($yeh);
     $x1 = $x1 + 1;
     if ($x1 == int($FORM2{xrs})) { ($type,$x2,$shot,$sendname,$sendemail,$toname,$toemail,$message,$notify,$track,$sdate,$pass)
= split(/\|/,$yeh);
          @count[$x1 - 1] = "$type|$x2|$shot|$sendname|$sendemail|$toname|$toemail|$message|off|$track|$sdate|$pass";
          if ($notify eq "on") { $notifynow = 1 };
     }
}

opening5:
open(OUTF,">cardinfo.txt") or retryfile5;
     flock(OUTF,2);
     foreach $yeh (@count) {
          print OUTF "$yeh\n";
     }
close(OUTF);


if ($notifynow == 1) {
open (MAIL, "|$mailprog -t") or emailfail();
     print MAIL "To: $sendname <$sendemail>\n";
     print MAIL "From: webmaster\@domain.com\n";
     print MAIL "Subject: $toname has received your post card\n\n";

     print MAIL "This email is just to let you know that $toname ($toemail) has received your $title postcard
on $date.\n\n";

     print MAIL "Thank you for using our service.\n\n";
close(MAIL);
}

exit;
}


exit;

sub types {

print "$html<font face=Arial size=3>";
print "<br><center><img src=\"" . $imgPathWeb . "welcome.gif\"><br>";
print "<b>Welcome to the $title post card system.</b><br><br></center>";
print "<font size=2>Please select the type of post card you wish to send:<br><br>";

open

open(INF,"cards.txt");
     @types = <INF>;
close(INF);

foreach $yeh (@types) {
     ($code,$name,$types) = split(/\|/, $yeh);
     print "<li><a href=\"kids.pl?action=build&type=$code\">$name</a>";
}

print "<br><Br>";

exit;
}






sub build {


open(INF,"cards.txt");
     @typesx = <INF>;
close(INF);


foreach $yeh (@typesx) {
     ($code,$name,$types) = split(/\|/, $yeh);
     if ($code eq $FORM2{type}) { $yeh2 = $yeh }
}

if ($yeh2 eq "") { exit }

($code,$name,$types) = split(/\|/, $yeh2);

(@types) = split(/\,/, $types);

print $html;

print <<"EOF";
<center>
<font face=Arial size=3>
<b>$title Electronic Post Card Service</b><br>

<Br>

<form method=post action=kids.pl?action=preview&type=$FORM2{type}>

<table bgcolor=$table1 border=0 cellpadding=1 cellspacing=0><tr><Td>
<table width=700 cellpadding=4 cellspacing=1 border=0>
<tr valign=top>
 <td bgcolor=$table3 colspan=5><font face=Arial size=2><center>
Please select which picture to send (click to enlarge):<br><br>
 </td>
</tr>
<tr valign=top>
EOF

for ($i=1; $i!=6; $i++) {
 print "  <td bgcolor=$table3 width=140><center><a href=\"" . $imgPathWeb . "post$i.jpg\" target=_blank><img
src=\"" . $imgPathWeb . "post$i.gif\"><br>  </td>\n";
}

print <<"EOF";

</tr> <tr valign=top>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=1>@types[0]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=2>@types[1]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=3>@types[2]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=4>@types[3]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=5>@types[4]<br><br>
 </td>
</tr>
<tr valign=top>
EOF

for ($i=6; $i!=11; $i++) {
 $i2 = $i;
 if ($i2 == 10) { $i2 = "0" }
 print "  <td bgcolor=$table3 width=140><center><a href=\"" . $imgPathWeb . "post$i2.jpg\" target=_blank><img
src=\"" . $imgPathWeb . "post$i2.gif\"><br>  </td>\n";
}


print <<"EOF";
</tr>
<tr valign=top>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=6>@types[5]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=7>@types[6]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=8>@types[7]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=9>@types[8]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=0>@types[9]<br><br>
 </td>
</tr>
EOF


for ($i=11; $i!=16; $i++) {
 $i2 = $i;
 if ($i2 == 15) { $i2 = "0" }
 print "  <td bgcolor=$table3 width=140><center><a href=\"" . $imgPathWeb . "post$i2.jpg\" target=_blank><img
src=\"" . $imgPathWeb . "post$i2.gif\"><br>  </td>\n";
}


print <<"EOF";
</tr>
<tr valign=top>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=11>@types[10]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=12>@types[11]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=13>@types[12]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=14>@types[13]<br>
 </td>
 <td bgcolor=$table3 width=140><font face=Arial size=1><center>
<input type=radio name=shot value=15>@types[14]<br><br>
 </td>
</tr>
                         
<tr>
 <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<br><br><b><u>From<br>
 </td>
</tr>

<tr>
 <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
From name: <br>
 </td>
 <td bgcolor=$table3 colspan=4>
<input type=text name="sendname" maxlength=200 size=40><br>
 </td>
</tr>

<tr>
 <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
From email: <br>
 </td>
 <td bgcolor=$table3 colspan=4>
<input type=text name="sendemail" maxlength=200 size=40><br>
 </td>
</tr>

<tr>
 <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<b><u><br><br>To<br>
 </td>
</tr>

<tr>
 <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
To name: <br>
 </td>
 <td bgcolor=$table3 colspan=4>
<input type=text name="toname" maxlength=200 size=40><br>
 </td>
</tr>

<tr>
 <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
To email: <br>
 </td>
 <td bgcolor=$table3 colspan=4>
<input type=text name="toemail" maxlength=200 size=40><br>
 </td>
</tr>

<tr>
 <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<b><u><br><br>Text message<br>
 </td>
</tr>

<tr valign=top>
 <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
Message: <br>
 </td>
 <td bgcolor=$table3 colspan=4>
<textarea name="message" rows=15 cols=60 wrap=soft></textarea><br>
 </td>
</tr>

<tr>
 <td bgcolor=$table3 colspan=5><font face=Arial size=2>
<b><u><br><br>Option<br>
 </td>
</tr>

<tr valign=top>
 <td bgcolor=$table3 colspan=1 align=right><font face=Arial size=2>
&nbsp;<br>
 </td>
 <td bgcolor=$table3 colspan=4><font face=Arial size=2>
<input type=checkbox name=notify>&nbsp;&nbsp;Notify me via email when user has received my postcard.<br>
 </td>
</tr>


</table>
</td></tr></table>
<br>
</center>
</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=Submit value="Preview Postcard">&nbsp;&nbsp;&nbsp;<input
type=Reset value="Reset Form"><br>

</form>


</body>
</html>







EOF
exit;

}









sub emailfail { print "Can not access mail program on this server."; exit; }

sub retryfile1 { goto opening1 }
sub retryfile2 { goto opening2 }
sub retryfile3 { goto opening3 }
sub retryfile4 { goto opening4 }
sub retryfile5 { goto opening5 }

sub random_password {
       ($length) = @_;
       if ($length eq "" or $length < 3) {
               $length = 6;            # make it at least 6 chars long.
       }
       $vowels = "aeiouyAEUY";
       $consonants = "bdghjmnpqrstvwxzBDGHJLMNPQRSTVWXZ12345678";
       srand(time() ^ ($$ + ($$ << 15)) );
       $alt = int(rand(2)) - 1;
       $s = "";
       $newchar = "";
       foreach $i (0..$length-1) {
               if ($alt == 1) {
                       $newchar =
substr($vowels,rand(length($vowels)),1);
               } else {
                       $newchar = substr($consonants,
                               rand(length($consonants)),1);
               }
               $s .= $newchar;
               $alt = !$alt;
       }
       return $s;
}

sub error {

print <<"EOF";

$html
<font face=arial size=2>
There is an error in your form!<br>
$msg<br><br>
<SCRIPT="JavaScript">
<FORM>
<INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)">
</FORM>
</SCRIPT>

EOF

exit;
}
0
 
LVL 16

Author Comment

by:Sohel Rana
ID: 6888331
Hello Peewee:

Thanks for your solution. It works nice.

Rana
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6888403
rsdn,
glad to help...

regards Peewee
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question