(back to the source index) midday

commented source





#!/usr/bin/perl # This script is part of the NoonQuilt project: # # <insert URL> # # © Ali Graham, 1998 <mailto:agraham@hal9000.net.au> # # (See makeQuilt.pl for the version history.) # # # Start of editPatch.pl () # ################################################################ # make sure this is syntactically clear... use strict; use English; # ...and running under Perl5... require 5.001; # uses a module available from # CPAN ( http://www.perl.com/CPAN/ ), # CGI_Lite # set the include path to recognise it use lib 'perllib'; # include the external files... my $path = ""; if ( $OSNAME =~ /^mswin/i ) { $path = "d:\\Inetpub\\wwwroot\\quilt\\scripts\\"; chdir($path); }

(I needed to add the above lines to the start of every script, otherwise the Perl interpreter on Windows NT would not change to the directory the scripts were running in -- this is inconsistent with the behaviour on Unix, Amiga & Macintosh Perl, which did.)



(require $path."nq_config.pl") or (die "Can't open \"nq_config.pl\": $!\n"); (require $path."nq_dirstuff.pl") or (die "Can't open \"nq_dirstuff.pl\": $!\n"); # ################################################################ # Start of main() # check CGI - if pending, do edit for accept/reject, otherwise # edit and save back. :) use CGI_Lite; my $cgi = new CGI_Lite (); my %cgi_data = $cgi->parse_form_data(); my $params; my $patch_file; my $page_title; my $source_dir; my $defaults = &nqco_getScriptDefaults; if ( $cgi_data{'subm_type'} eq "pending" ) { $source_dir = $defaults->{'S_PatchInDir'}; $page_title = "processing a submitted patch"; } elsif ( $cgi_data{'subm_type'} eq "accepted" ) { $source_dir = $defaults->{'S_PatchDir'}; $page_title = "editing an accepted patch"; } else { $source_dir = $defaults->{'S_PatchRejectDir'}; $page_title = "editing a rejected patch"; }

The code above checks the location of the patch data file to be edited: this is passed in by the HTML page that call this script, which is generated by editList.pl.

The rest of the code below reads the data from the file and generates the form and its contents as HTML which is passed to the web server. The HTML is actually a trimmed-down version of submit.htm.



$patch_file = $cgi_data{'subm_file'}; $params = &nqco_readParameters("$source_dir$patch_file"); print STDOUT <<End_Header; Content-type: text/html <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <HTML> <HEAD> <TITLE>$page_title</TITLE> <SCRIPT LANGUAGE="JavaScript"><!-- var p_width = 330, p_height = 440 var p_screenx = 80, p_screeny = 40 var win_str function open_patch(url) { if ( (!patchWin) || patchWin.closed ) { win_str = '' win_str = "width="+p_width+","+"height="+p_height win_str += ","+"screenX="+p_screenx win_str += ","+"screenY="+p_screeny win_str += ",toolbar=yes,location=no,status=yes" win_str += ",menubar=no,scrollbars=yes,resizable=yes" patchWin = window.open('', 'patch', win_str) } else { patchWin.focus() } }

This JavaScript is required so that the 'Preview' button can work - this window is then the target for the HTML file that submitPatch.pl returns.



// --> </SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFCE" TEXT="#313131"> <BR> <BR> <DIV ALIGN=CENTER> <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH="95%"> <TR> <TD> </TD> <TD ALIGN=RIGHT WIDTH=219> <IMG SRC="grf/noonsun.gif" WIDTH="219" HEIGHT="44" BORDER=0 ALT="midday"> <BR> <BR> <DIV ALIGN=CENTER> <FONT FACE="helvetica,arial,verdana,times" COLOR="#313131" SIZE="+2"> <I>$page_title</I> </FONT> </TD> </TR> </TABLE> <BR> <BR> <HR WIDTH="75%" ALIGN=RIGHT> </DIV> <BR> <BR> End_Header if ($patch_file) { my $status = "file&nbsp;name:&nbsp;<B>$patch_file</B><BR>\n"; $status .= "current&nbsp;status:&nbsp;<B>$cgi_data{'subm_type'}</B>\n"; my $temp = ($params->{'F_AddressPublic'}{'Value'} eq "on"); my $check_address = $temp?" CHECKED":""; print STDOUT <<End_EditPage; <DIV ALIGN=CENTER> <FORM ACTION="../scripts/submitPatch.pl" METHOD="POST"> <INPUT TYPE="hidden" NAME="subm_type" VALUE="$cgi_data{'subm_type'}"> <INPUT TYPE="hidden" NAME="subm_file" VALUE="$patch_file"> <TABLE WIDTH="90%" BORDER=0> <TR> <TD WIDTH="12%" ALIGN=CENTER VALIGN=TOP> <INPUT TYPE="submit" NAME="subm_action" VALUE="Accept" onClick="this.form.target='_self'"> </TD> <TD WIDTH="12%" ALIGN=CENTER VALIGN=TOP> <INPUT TYPE="submit" NAME="subm_action" VALUE="Hold" onClick="this.form.target='_self'"> </TD> <TD WIDTH="12%" ALIGN=CENTER VALIGN=TOP> <INPUT TYPE="submit" NAME="subm_action" VALUE="Reject" onClick="this.form.target='_self'"> </TD> <TD WIDTH="50%" ALIGN=CENTER VALIGN=TOP> $status </TD> <TD WIDTH="14%" ALIGN=CENTER VALIGN=TOP> <INPUT TYPE="submit" NAME="subm_action" VALUE="Preview" onClick="open_patch(); this.form.target='patch'"> </TD> </TR> </TABLE> <BR><BR> <TABLE WIDTH="90%" BORDER=0> <TR> <TD WIDTH="45%" ALIGN=CENTER VALIGN=TOP> <B>Name:</B><BR><BR><INPUT TYPE="text" NAME="F_UserName" SIZE=32 VALUE="$params->{'F_UserName'}{'Value'}"> </TD> <TD WIDTH="10%" COLSPAN=2> </TD> <TD WIDTH="45%" ALIGN=CENTER VALIGN=TOP> <B>\@ddress:</B><BR><BR><INPUT TYPE="text" NAME="F_UserAddress" SIZE=32 VALUE="$params->{'F_UserAddress'}{'Value'}"> <DIV ALIGN=LEFT> <BR> <BR> Publically visible? <INPUT TYPE="checkbox" NAME="F_AddressPublic"$check_address> </DIV> <BR> <BR> </TD> </TR> <TR> <TD COLSPAN=4 WIDTH="100%" ALIGN=CENTER VALIGN=TOP> <DIV ALIGN=CENTER> <B>Location:</B><BR><BR> <TEXTAREA NAME="F_UserLocation" COLS=35 ROWS=5 WRAP="virtual"> $params->{'F_UserLocation'}{'Value'}</TEXTAREA> </DIV> <BR><BR> </TD> </TR> <TR> <TD COLSPAN=4 WIDTH="100%"> <DIV ALIGN=CENTER> <B>Submission:</B> <BR><BR> <TEXTAREA NAME="F_UserSubmission" COLS=60 ROWS=10 WRAP="virtual"> $params->{'F_UserSubmission'}{'Value'}</TEXTAREA> <BR><BR> <BR><BR><BR> <DIV ALIGN=CENTER> <B>Bio:</B> <BR><BR> <TEXTAREA NAME="F_UserBiography" COLS=60 ROWS=8 WRAP="virtual"> $params->{'F_UserBiography'}{'Value'}</TEXTAREA> <BR> <BR> </TD> </TR> </TABLE> </FORM> </DIV> </BODY> </HTML> End_EditPage } # End of editPatch.pl