Hey guys (and gals too),
   I'm having problems with this here script.  It seems that I can save new articles, 
but
when I go to save changes to an old article, it doesn't save them.  If you need it, I 
can
provide the source to admin_news.cgi also.  Thanks for your help in advance. (I'm not
sure if this wil be formatted right.  Yahoo's text area isn't as wide as my text 
editor).

#!/usr/bin/perl -wT
# edit_article.cgi

use strict;
use lib "..."; /* this contains my mod dir...but I */
               /* wasn't going to give that to you guys */

use CGI;
use Ntdw10Error;
use Fcntl qw/ :flock /;

my $NEWS_DIR = "$ENV{DOCUMENT_ROOT}/news";
my $q = new CGI;

if ( $q->param( 'story' ) ) {
        my( $headline, $article ) = get_story( $q->param( 'story' ) );
        $q->param( -name => 'headline', -value => $headline );
        $q->param( -name => 'article', -value => $article );
}
elsif ( $q->param( 'save' ) ) {
        save_story( $q->param( 'story' ), $q->param( 'headline' ), $q->param( 
'article' ) );
        print $q->redirect( "/admin/admin_news.cgi" );
        exit;
}

print   $q->header,
                $q->start_html( -title  => "Edit Article",
                                                -style  => { -src       => 
"/admin.css" },
                                                -script => { -src       => 
"/ntdw10.js" } ),
                $q->h2( "Edit Article" ),
                $q->hr,
                $q->start_form,
                $q->p(  
                                $q->span( { -class      => "bold" }, "Headline: " ), 
                                $q->textfield( -name    => "headline",
                                                           -size        => 50 )
                          ),
                $q->p(
                                $q->span( { -class      => "bold" }, "Article: " ),
                                "(HTML formatted)",
                                $q->br,
                                $q->textarea( -name             => "article",
                                                          -rows         => 20,
                                                          -cols         => 60,
                                                          -wrap         => "physical" )
                          ),
                $q->hidden( -name       => "story",
                                        -value  => $q->param( 'story' ) ),
                $q->reset( "Reset Form" ),
                $q->submit( -name       => "save",
                                        -value  => "Save Article" ),
                $q->span( { -class => "italic" }, "Note: clicking Save Article on an 
article 

which you are editing (is not new) will not return you to the News Administration 
page!! 
Use the 

Return to News Administration link at the bottom of the page." ),
                $q->end_form,
                $q->hr,
                $q->p( "Return to ", $q->a( { -href => "/admin/admin_news.cgi" }, 
"News 

Administration" ), ".", $q->span( { -class => "italic" }, "Warning! If you have not
saved, your 

changes will be lost!!!" ) ),
                $q->end_html;


sub get_story {
        my( $filename ) = shift() =~ /^(\d+)$/;
        my( $headline, $article );
        
        local( *STORY );
        open STORY, "$NEWS_DIR/$filename" or die "Cannot open $NEWS_DIR/$filename: $!";
        flock STORY, LOCK_SH;
        $headline = <STORY>;
        chomp $headline;
        local $/ = undef;
        $article = <STORY>;
        
        return $headline, $article, get_date( $filename );
}

sub get_date {
        my $filename = shift;
        ( my $date = localtime $filename ) =~ s/ +\d+:\d+:\d+/,/;
        return $date;
}

sub save_story {
        my( $story, $headline, $article ) = @_;
        local *STORY;
        
        $story ||= time;
        $article =~ s/\015\012|\015|\012/\n/g;
        $headline =~ tr/\015\012//d;
        
        my( $file ) = $story =~ /^(\d+)$/ or die "Illegal filename: '$story'";
        my( $st )       = "$NEWS_DIR/$file" =~ /^(.+)$/;
        
        open STORY, "> $st";
        flock STORY, LOCK_EX;
        seek STORY, 0, 0;
        print STORY $headline, "\n", $article;
        close STORY;
}

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to