Solved

Cut'n'paste guestbook w. umlauts & linebreaks

Posted on 1998-10-02
15
517 Views
Last Modified: 2010-03-05
I need a guesbook script that uses three textareas, each that can be preformatted to give an output as follows:
First field: Headline in size 5 and bold
Second field: Text, size 3
Third field: Byline, size 2 and bold.
Another area should allow the submission of an URL, subsequently presenting an image (Could be omitted.)
The script should write over the previous file, creating a new file with the same name, thus replacing the old one everytime one uses the script.
There should be a password protected submission area only. No public access, except for the output.
The tricky part, i suppose, is to allow the textareas to maintain the line breaks and umlauts from the cut'n'pasted text, presenting them in a sort of "edited" form in the guestbook.
I have looked everywhere for a script like this, and have also been told that it can't be done. I thought i'd give it a shot here. X-perts here have helped me before
Algabatz
0
Comment
Question by:algabatz
  • 7
  • 7
15 Comments
 
LVL 4

Expert Comment

by:binkzz
ID: 1205080
It is by far not impossible; i've got a script like this at home
which I will post here as soon as I get there ;)

I can slight
0
 
LVL 1

Author Comment

by:algabatz
ID: 1205081
Eagerly awaiting!
Al Gabatz
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1205082
You can send me an example html of what you want it to look like;
for those 400 points I'm very willing to adjust it to your
personal needs.

Binkzz(@powernet.com)
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1205083
You can send me an example html of what you want it to look like;
for those 400 points I'm very willing to adjust it to your
personal needs.

Binkzz(@powernet.com)
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1205084
You can send me an example html of what you want it to look like;
for those 400 points I'm very willing to adjust it to your
personal needs.

Binkzz(@powernet.com)
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1205085
Never ever press refresh after posting a comment though..
0
 
LVL 1

Author Comment

by:algabatz
ID: 1205086
OK, i've posted a form and an output document. Please take a look at:

http://www.gp.se/nyheter/varldens_gang/kaseriform.html

and

http://www.gp.se/nyheter/varldens_gang/output.html

That should give you an idea of what i want.

Best,
Algabatz
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:binkzz
ID: 1205087
Cool, I should have them finished somewhere saturday afteroonish.

Sorry for the delay, had something to celebrate tonight ;)

Binkzz
0
 
LVL 1

Author Comment

by:algabatz
ID: 1205088
You still in the race?
/Al
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1205089
Yep, I'm getting there though you could do me a big favour
translating the data page for me..

Just so I know what the options stand for?

Binkzz
0
 
LVL 1

Author Comment

by:algabatz
ID: 1205090
OK, "Datum" is the date, found at the top of the output page. "Rubrik" is the headline, "Ingress" is the introduction (bold), "Bild" means image, with the options "Ja/Nej" : Yes/No
"Brödtext" is the text, "Byline" is of course the byline, "Publisera" means publish, ie Submit, and finally "Radera" means erase the form.
/Al  
0
 
LVL 1

Author Comment

by:algabatz
ID: 1205091
Hi there binkzz. If it turned out to be too difficult, please let me know so that i can concentrate on other options.
b w
Al
0
 
LVL 1

Author Comment

by:algabatz
ID: 1205092
It's now been a week since i posted this question. I am reopening it since i've not yet gotten an answer from binkzz.
/Algabatz
0
 
LVL 5

Accepted Solution

by:
aioudine earned 400 total points
ID: 1205093
#!/usr/local/bin/perl
require "cgi-lib2.pl";
######################################################################


# Configuration

# The full path to your directory containing the script (not an url)
$path= "data:/inw_web/shared/docs/lcgi/perl5/test";

#$path="e:/FOLKWEB/cgi-bin";

# Funny password
$password="password";

# The name of the text file where message stored
$page= "/data.txt";

# The full URL to the script
#This don't work??
#$scripturl=&MyURL;
$scripturl="http://techware.prometeus.nsc.ru/perl/test/Pb.pl";

# header of each page
#$header= <<EOT;
#      <div align=center>
#      <img height="86" width="351" src="/vg_logga.gif" ALT="Vg_Logga">
#      </div>
#EOT

# footer of each page
$footer = <<EOT;
 <div align=center><small>script by <a href=\"http://techware.prometeus.nsc.ru\">aioudine<\/a><\/small></div>
EOT

# succeful post
$good = <<EOT;
      <h2 align=center>Thank you for adding to our Profile<\/h2>
      <h3 align=center><a href=$scripturl>You may view your entry here<\/a><\/h3>
EOT

$script_name="ProfileBook";


# Colors placed in BODY tag
$bgcolor= "white";            # Background Color
$textcolor= "black";            # Text Color
$linkcolor= "blue";            # Link Color
$vlinkcolor= "darkblue";      # Visited Link Color
$alinkcolor= "red";            # Active Link Color

# Set this to a background image, or leave blank if you prefer

$bgimage= "";            # Full URL to your background image.

# End Configuration DO NOT MODIFY BELOW THIS LINE!
######################################################################



#######################
# Main
&ReadParse(*input);
{
  if ($input{'Cmd'} eq "ViewOnly"){
    &ViewProfile;
  }
 elsif ($input{'Cmd'} ne "")
  {
    &ProcessForm;
  }
 else
  {
    &ViewProfile;
  }
}



########################
# sub ViewProfile
sub ViewProfile{
      print &PrintHeader;

      print &Top ($script_name);
#      print $header;

print <<EOT;
      <table border="0" cellpadding="0" cellspacing="2" frame width="387">
      <tr>
            <td><img height="86" width="351" src="/vg_logga.gif"></td>
      </tr>
EOT

      open (DB, "$path$page") || print "<br><h1><font COLOR=red>ERROR:Can't open message file ".$path.$page."<\/h1><\/font>";
      @Data = <DB>;
      close DB;

      foreach $Match (@Data) {
            @TempData = split (/&&/, $Match);

#Date
print '      <TR><td><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">'.$TempData[0];
print '      <hr noshade width="100%" align="left">'."</font><BR></td></TR>\n";

# HeadLine
print '<TR><td><h1><FONT size="6" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">'.$TempData[1]."</FONT></h1></td></TR>\n";


# Subheader
print '<TR><td><FONT face="Arial, Helvetica, sans-serif" size="3"><B>'.$TempData[2] ."</B>\n";

# text1
            $text=$TempData[3];
            @textarray=split(/ /,$text);
##            $dd=10;
$dd=(@textarray-@textarray%2)/2;


$i=0;
$text1=$textarray[$i];


while ($i < $dd) {
   ++$i;
   $text1=$text1." ".@textarray[$i];
   };

print "$text1\n";

              
       
# Image
            if ($TempData[5] eq "Yes"){
                    $image = $TempData[4];
             $image =~ s/\&lt\;/\</g;
             $image =~ s/\&gt\;/\>/g;
             print "$image\n";
            }
# text2

#$text2=$textarray[$i];

while ($i <= @textarray) {
   ++$i;
   $text2=$text2." ".@textarray[$i];
   };
      

            print "$text2<BR></FONT><BR><BR></td></TR>\n";
              }

# Byline
      print '<tr><Td><hr noshade width="100%"  align="left">';
      print '      <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="5"><tt><b>'.$TempData[7]."</b></tt></font>\n";
      print '      <p><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2"><A HREF="mailto:'.$TempData[6].'">'.$TempData[6].'</a></font>';
      print "</td></TR></TABLE><P>\n<BR><BR><BR><hr>\n";


if ($input{'Cmd'} ne "ViewOnly")
{            print <<EOT;

            Would you like to add somthing?<br>
            <p>
            <FORM ACTION=\"$scripturl\" METHOD=\"POST\">
            Date (lates changes are  effective):<br>
            <input type=text name="date" size=20><br>

            The Title of Your Profile(lates changes are  effective):<br>
            <input type=text name="title" size=60><br>

            Subtitle:<br>
            <input type=text name="subtitle" size=60><br>
            
                Youre Story:<br>
                   <TEXTAREA NAME="Profile" ROWS=10 COLS=58 wrap=virtual>
            <\/TEXTAREA><br>
            Image parameters:<br>
            <TEXTAREA NAME="image" ROWS=2 COLS=58 wrap=virtual><IMG src="/vinci.jpg" align="left"><\/TEXTAREA><br>

            Add Image?:<br>
            <input name="yesno" type="radio" value="Yes">Yes<br>
            <input name="yesno" type="radio" value="No" checked>No<BR>

            Byline(lates changes are  effective):<BR>
            <input type=text name="byline" size=60><br><BR>
            Youre email(lates changes are  effective):<br>
            <input type=text name="email" size=60><br>

<BR>
            <input name="Cmd" type="radio" value="AddTop" checked>Add to top
            <input name="Cmd" type="radio" value="AddBootom">Add to bootom
            <input name="Cmd" type="radio" value="Over">Overwrite<br>
            Password:<br>
            <input type=password name="pasw" size=10><br>
            <input type=hidden name="user"value="test">
            <INPUT TYPE=submit VALUE=Submit><INPUT TYPE=Reset VALUE=Reset>
            <\/FORM>
            <br>

EOT
};                  
            print $footer;
            print &HtmlBot;

}

########################
# sub ProcessForm

sub ProcessForm{


        $Cmd = $input{'Cmd'};
        $email = $input{'email'};
      $date= $input{'date'};

      $title= $input{'title'};
      $title =~ s/\</\&lt\;/g;
      $title =~ s/\>/\&gt\;/g;


      $subtitle= $input{'subtitle'};
      $pass= $input{'pasw'};

      $Profile= $input{'Profile'};
      $Profile =~ s/\</\&lt\;/g;
      $Profile =~ s/\>/\&gt\;/g;
      $Profile =~ s/\n/<br>/g;
#      $Profile =~ s/\015/<br>/g;

##      $Profile2= $input{'Profile2'};
##      $Profile2 =~ s/\</\&lt\;/g;
##      $Profile2 =~ s/\>/\&gt\;/g;
##      $Profile2 =~ s/\n/<br>/g;
#      $Profile2 =~ s/\015/<br>/g;


      $image= $input{'image'};
      $image =~ s/\</\&lt\;/g;
      $image =~ s/\>/\&gt\;/g;
      $image =~ s/\n//g;
      $Profile =~ s/\015//g;


      $yesno= $input{'yesno'};

      $byline= $input{'byline'};
      $byline= $input{'byline'};
      $byline =~ s/\</\&lt\;/g;
      $byline =~ s/\>/\&gt\;/g;



       if ($Profile eq ""){
            print &PrintHeader;
            print &Top('Error -- No Profile');
            print <<EOT;
            <h2 align=center>You need to enter your Profile!<\/h2><br>
            <center>Please press your browser's back button and try again</center>
EOT
            print $footer;
            print &HtmlBot;
            }

        elsif ($pass ne $password){
            print &PrintHeader;
            print &Top('Error -- Wrong passwor use "password" $pass $password');
            print <<EOT;
            <h2 align=center>Wrong passwor use "password"!<\/h2><br>
            <center>Please press your browser's back button and try again</center>
EOT
            print $footer;
            print &HtmlBot;
            }

        elsif ($title eq""){
            print &PrintHeader;
            print &Top('Error -- No Title');
            print <<EOT;
            <h2 align=center>You need to enter your Title!<\/h2><br>
            <center>Please press your browser's back button and try again</center>
EOT

            print $footer;
            print &HtmlBot;
            }

        else{
            &AddProfile;
            }      

}


#######################
# sub AddProfile

sub AddProfile{

      open(DATA,"$path$page") || print "ERROR: Can't read".$path.$page;
      @oldentries = <DATA>;
      close(DATA);


      open(DATA,">$path$page") || print "ERROR: Can't write".$path.$page;
#      flock(DATA,2);

      $P =  $date."&&".$title."&&".$subtitle."&&".$Profile."&&".$image."&&".$yesno."&&".$email."&&".$byline."&&";
      $P =~ s/\n/<br>/g;
      $P =~ s/\015//g;
   


  if ($Cmd eq "Over"){
          print DATA $P."\n";
   }
   elsif ($Cmd eq "AddTop"){
      print DATA $P."\n";
      print DATA @oldentries;
       }
    else{
        print DATA @oldentries;
      print DATA $P."\n";
      };

      close(DATA);      
#      }

      print &PrintHeader;
      print &Top ('Thank you');
      print $good;
      print $footer;
      print &HtmlBot

}
########################
# sub Top

sub Top{

  local ($title) = @_;

  return <<EOT;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>$title</title>
</head>
<body background=\"$bgimage\" bgcolor=\"$bgcolor\" text=\"$textcolor\" link=\"$linkcolor\" vlink=\"$vlinkcolor\" alink=\"$alinkcolor\">
EOT
}
----------end--------
0
 
LVL 1

Author Comment

by:algabatz
ID: 1205094
Brilliant!
/Al
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now