#!/usr/bin/perl # # shiva.pl -- Shiva scheduling program # # (c) Copyright 2007 Software Garden, Inc. # All Rights Reserved. # Subject to Software License at the end of this file # # # Access with: # # http://www.domain.com/cgi-bin/shiva.pl # # This program may create the following files: # # shivadata.txt - Non-default string settings. See save_shivadata for format. # Note: Includes admin password in clear text. # # *.set directories, each with: # # event.txt - Contains event set data for event set "setname" in dir setname.set. # See load_set routine below for data format. # # person.n.txt - Name and event sign up data for person number "n". # See load_people routine below for data format. # # All files are in text format, so their operation should be easy to discover, # and problems fixable. # # # Do uses # use strict; use CGI qw(:standard); # # Define some variables # # # Here are the program name strings for display when executing. # our $programversion = "0.9"; # The version information string our $programmark = "Shiva"; # This is the main trademark for the product. Change if required by trademark law. our $programname = "$programmark $programversion"; # Change name if required by trademark usage. This is where the version is indicated. our $SGIfootertext = <<"EOF"; Shiva Program (c) Copyright 2007 Software Garden, Inc.
All Rights Reserved.
The original version of this program is from Software Garden. EOF # Strings # # For each string add to @stringinfo: # [$snum][$stringname] = short name for lookup # [$snum][$stringfullname] = full name # [$snum][$stringtype] = type: $stringtypesingleline, $stringtypemultiline # [$snum][$stringdesc] = description (HTML) # [$snum][$stringdefault] = default value # # The order here is the order listed in edit lists # Access using String Name Lookup ($snl): $stringinfo[$snl{stringname}][valuetype] # Stringnames starting with "admin" are only settable on the main admin page, not for each event set my $stringname = 0; my $stringfullname = 1; my $stringtype = 2; my $stringdesc = 3; my $stringdefault = 4; my $stringtypesingleline = 1; my $stringtypemultiline = 2; my @stringinfo = ( ["adminpassword", "Administrator Password", $stringtypesingleline, "This is the password for logging into the Administration part of the program. If you change it here you will have to login again with the new password. If you forget the password, the person who set up this system may be able to reset it for you. The default value is no password, so you should set it to something not easy for people to guess.", "" ], ["adminpageheading", "Heading at the top of all pages", $stringtypesingleline, "This is the text that appears at the top of each page in large type and as the page title for the browser.", 'Shiva Signup Program' ], ["admininitialpageinstructions", "Initial page instructions", $stringtypemultiline, "Instructions above the list of sets of events that a normal user may choose from when no set has been chosen. May include special markup commands.", 'Select the set of events for which you wish to sign up:' ], ["adminchoosebutton", "Choose buttons on initial page", $stringtypesingleline, "The text on the Choose buttons on the page with the list of sets of events visible to a normal user.", 'Choose' ], ["adminloginbutton", "Admin Login button on initial page", $stringtypesingleline, "The text on the Admin Login button on the page with the list of sets of events visible to a normal user.", 'Admin Login' ], ["admininitialpagefooting", "Initial page footer", $stringtypemultiline, "Text at the bottom of the list of sets of events visible to a normal user. This may include information about the organization running this website. May include special markup commands.", '' ], ["adminnosets", "No Sets To List Message", $stringtypesingleline, "The text displayed when there are no sets listed on the page with the list of sets of events visible to a normal user.", '*** No events available for signup at this time ***' ], ["adminlogininstructions", "Login page instructions", $stringtypemultiline, "Instructions on the administration login page. May include special markup commands.", 'Login here to create new events, etc.' ], ["adminmaptext", "Map link text", $stringtypesingleline, 'The text that appears as a link to a map when using the "[map:...]" special markup command.', 'Map' ], ["admintimeoffset", "Time offset", $stringtypesingleline, 'The number of hours to add to the time displayed at the bottom of each page and on backup listings to adjust for differences in time settings between the web server and local time for users. (For example, the server is in Eastern Time Zone Atlanta, and users are in Central Time Zone Chicago.) This is for cosmetic purposes only, and just affects what is displayed. It must be just a number with an optional plus or minus sign. (Note: It does not change the time display on the first screen after it is changed, just ones after that.)', '0' ], ["topinstructionsnew", "Signup top instructions (new signup)", $stringtypemultiline, "Instructions above the Events section on the normal signup sheet when normally showing the signup page. May include special markup commands.", 'Select the events you plan to attend below, enter your name and party size in the space below them, and then press the "Save" button below:' ], ["topinstructionsold", "Signup top instructions (editing person)", $stringtypemultiline, "Instructions above the Events section on the normal signup sheet when editing an existing person's information. May include special markup commands.", 'Make any changes to the events you plan to attend below, make any changes to your name and party size in the space below them, and then press the "Save" button:' ], ["eventsectiontitle", "Signup Event section title", $stringtypesingleline, "The main title of the section listing the events.", "Events" ], ["eventheaderdescattendee", "Signup Event heading: Description/Attendee", $stringtypesingleline, "The heading on the event description/attendee column.", "Description / Attendees" ], ["eventheadercount", "Signup Event heading: Counts", $stringtypesingleline, "The heading on the event column listing the counts of attendees signed up.", "Counts" ], ["signupattending", "Signup checkbox text", $stringtypesingleline, "The text that goes next to the checkbox indicating that the person is attending the event.", "Attending" ], ["signupactiontitlenew", "Signup action title (new signup)", $stringtypesingleline, "The title below the events on the signup page above the name and count.", "Attendee to Add:" ], ["signupactiontitleold", "Signup action title (editing person)", $stringtypesingleline, "The title below the events on the signup page above the name and count.", "Editing Attendee:" ], ["signupname", "Signup: name", $stringtypesingleline, "The text to the left of the textbox in which to type the person's name.", "Name:" ], ["signupnumpeople", "Signup: number of people", $stringtypesingleline, "The text to the left of the radio buttons for selecting the number of people attending an event.", "Number of People:" ], ["signupsavemsg", "Signup save message", $stringtypemultiline, "This is the text above the signup Save button. May include special markup commands.", "Make sure you have selected the events you are planning to attend before saving!" ], ["signupsavingbuttonnew", "Signup Save button (new signup)", $stringtypesingleline, "The text on the signup Save button when normally showing the signup page.", "Save" ], ["signupsavingbuttonold", "Signup Save button (editing person)", $stringtypesingleline, "The text on the signup Save button for saving an update to an existing person being edited.", "Save" ], ["signupcancelbutton", "Signup Cancel button", $stringtypesingleline, "The text on the signup Cancel button.", "Cancel" ], ["signupbottominstructions", "Signup bottom instructions", $stringtypemultiline, "Instructions before the People section on the signup page. May include special markup commands.", "Click on the Edit button next to the entry for which you wish to make changes:" ], ["peoplesectiontitle", "Signup People section title", $stringtypesingleline, "The title of the section listing people by name with edit buttons.", "People" ], ["peoplenamecolumn", "Signup People heading: Name", $stringtypesingleline, "The heading on the column of names of people who have signed up, sorted by name.", "Name" ], ["peoplepeoplecolumn", "Signup People heading: People", $stringtypesingleline, "The heading on the column of showing the numbers of persons represented by each name.", "People" ], ["peopleattendingcolumn", "Signup People heading: Attending", $stringtypesingleline, "The heading on the column listing the short names of the events for which each person has signed up.", "Attending" ], ["peopleeditbutton", "Signup People Edit button", $stringtypesingleline, "The text on the Edit button on each line in the people list.", "Edit" ], ["adminpagetemplate", "Page HTML template", $stringtypemultiline, 'This advanced feature is the template used to create the HTML that makes up the web page. It includes all of the text that is static on the page. The string "{pagecontents}" in this text is replaced by the contents of the page created dynamically by this program and {pagetitle} is replaced by the "Heading at the top of all pages" value. The default value includes the CSS classes that may be customized to change the look of the output. Only change this value if you are familiar with HTML and using templates of this type. ', <<"EOF" {pagetitle}
{pagecontents}
EOF ], ); my %snl; # String Name Lookup -- filled in automatically from @strings my $maxcountbuttons = 10; # Program common values my (@personname, %personnumber, @personevents, @personcount, @personssorted, @eventcount); my $eventdir; # # *** Local serving: For development and debugging only *** # # To use this standalone on a computer, not served by a web server on the web, # uncomment the following lines and make sure shivaserver.pm is in the # same directory as this program. # # use shivaserver; # shivaserver::local_server(\&process_request); # exit; # *** End of local serving *** # # * * * * * # # Main entry - processes CGI request # # Get query parameters my $query; if ($ENV{REQUEST_METHOD} eq 'POST') { read(STDIN, $query, $ENV{CONTENT_LENGTH}); } else { $query = $ENV{QUERY_STRING}; } # Process the request and output the results my %responsedata = (); # holds results of processing request process_request($query, \%responsedata); my $content = $responsedata{content}; my $type = $responsedata{contenttype}; # Output header $type ||= "text/html; charset=UTF-8"; # default type my $header = "Content-type: $type\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\n"; print "$header\n"; # print header plus extra line # Output content print $content; # # * * * * * # # process_request($querystring, \%responsedata) # # Process the HTTP request # # Responds to browser request and does all the work # Returns data in %responsedata: # $responsedata{content} - a string with the HTML response # $responsedata{contenttype} - the HTTP response header content MIME type or null for default text/html UTF-8 # $responsedata{contentexpires} - expire string or null for default (-1d) # # The $querystring is the raw query from the browser. # sub process_request { my ($querystring, $responsedata) = @_; my $response; # Get CGI object to get parameters: $querystring ||= ""; # make sure has something my $q = new CGI($querystring); my %params = $q->Vars; # # # # # # # # # # # # Load %strings # # # # # # # # # # # my %shivadata; load_shivadata(\%shivadata); my %strings; for (my $snum=0; $snum <= $#stringinfo; $snum++) { # fill in %strings values my $sname = $stringinfo[$snum][$stringname]; $strings{$sname} = $shivadata{$sname} || $stringinfo[$snum][$stringdefault]; $snl{$sname} = $snum; } for (my $snum=0; $snum <= $#stringinfo; $snum++) { # after adminmaptext is copied, expand special chars my $sname = $stringinfo[$snum][$stringname]; if ($stringinfo[$snum][$stringtype] == $stringtypemultiline) { $strings{$sname} = wikitext_encode($strings{$sname}, $strings{adminmaptext}); } else { $strings{$sname} = special_chars($strings{$sname}) unless $sname eq "adminmaptext"; # map all but the "Map" text (which will get it on encode) } } # Get current time string my $start_clock_time = scalar localtime(time()+3600*($strings{admintimeoffset} || 0)); # # # # # # # # # # # # Check arguments # # # # # # # # # # # my ($newattend, $editnum); $params{set} = check_setname($params{set}); $params{editset} = check_setname($params{editset}); foreach my $p (keys %params) { # go through all the parameters if ($p =~ /^showset:(.*)/) { # get set to show $params{set} = check_setname($1); last; } elsif ($p eq "backtolist") { if ($params{person}) { # treat as a "Save" if person set $params{dosave} = "Save"; last; } %params = (); # reset back to top next; } elsif ($p =~ /^attend:(\d*)/) { # set attendence $newattend .= ":" if $newattend; $newattend .= $1; } elsif ($p =~ /^edit:(\d*)/) { # edit existing person $editnum = $1; } elsif ($p =~ /^editset:(.*)/) { # edit existing set last unless check_adminpassword(\%params, \%strings); $params{editset} = check_setname($1); last; } elsif ($p =~ /^ssave:([^\:]*):(.*?)$/) { # save string value last unless check_adminpassword(\%params, \%strings); $shivadata{$1} = $2 eq "c" ? $params{"snew:$1"} : ""; $strings{$1} = $shivadata{$1} || $stringinfo[$snl{$1}][$stringdefault]; if ($stringinfo[$snl{$1}][$stringtype] == $stringtypemultiline) { $strings{$1} = wikitext_encode($strings{$1}, $strings{adminmaptext}); } else { $strings{$1} = special_chars($strings{$1}); } save_shivadata(\%shivadata); $params{admintop} = 1; last; } elsif ($p =~ /^deleteset:(.*)/) { # delete existing set last unless check_adminpassword(\%params, \%strings); my $sname = check_setname($1); my @peoplefiles = my $pcount = unlink glob("$sname.set/person.*.txt"); # Delete all people unlink "$sname.set/event.txt"; # Delete event file rmdir "$sname.set"; # Delete directory $params{admintop} = 1; $params{statusmessage} = qq!Deleted "$sname" which included $pcount people signup record(s)!; last; } elsif ($p eq "admincreate") { # create a new set merging text set and info set last unless check_adminpassword(\%params, \%strings); my $newname = check_setname($params{createname}); # make legal if (length($newname)<1) { $params{admintop} = 1; $params{statusmessage} = "Name missing or invalid - nothing created"; last; } my %setdata1; if ($params{createtext} ne "[none]") { load_set(check_setname($params{createtext}) . ".set", \%setdata1); } my %setdata2; if ($params{createinfo} ne "[none]") { load_set(check_setname($params{createinfo}) . ".set", \%setdata2); } my %newsetdata; $newsetdata{event} = []; $newsetdata{eventorder} = []; $newsetdata{strings} = {}; $newsetdata{set} = $newname; $newsetdata{setname} = $setdata1{setname}; $newsetdata{setdescription} = $setdata1{setdescription}; $newsetdata{countbuttons} = $setdata2{countbuttons} || 1; if ($setdata2{event}) { # copy events from setdata2 for (my $eline=1; $eline < scalar @{$setdata2{eventorder}}; $eline++) { my $enum = $setdata2{eventorder}->[$eline]; $newsetdata{event}->[$enum] = {name => $setdata2{event}->[$enum]->{name}, desc => $setdata2{event}->[$enum]->{desc}}; $newsetdata{eventorder}->[$eline] = $enum; } $newsetdata{maxevent} = $setdata2{maxevent}; } if ($setdata1{strings}) { # copy strings from setdata1 foreach my $sname (sort keys %{$setdata1{strings}}) { $newsetdata{strings}->{$sname} = $setdata1{strings}->{$sname}; } } $newsetdata{visible} = "N"; # start out not listed in public list my $ok = mkdir("$newname.set"); # create the set directory if ($ok) { save_set_from_setdata(\%newsetdata); # save the new data file $params{statusmessage} = "Created $newname from $setdata2{set} (events) and $setdata1{set} (text)"; } else { $params{statusmessage} = qq!Unable to create "$newname".!; } $params{admintop} = 1; last; } elsif ($p eq "adminbackup") { # display all variable data as text $response .= <<"EOF"; Shiva Program Backup of data from: $start_clock_time



= = = = = = = = = = = = = = = = =
 ADMINISTRATION TEXT DATA
= = = = = = = = = = = = = = = = =

(Non-default settings only)

EOF my $somenondefault; for (my $snum=0; $snum <= $#stringinfo; $snum++) { my $sname = $stringinfo[$snum][$stringname]; if ($shivadata{$sname}) { $somenondefault++; my $stringtext = for_listing($shivadata{$sname}, ($stringinfo[$snum][$stringtype]==$stringtypemultiline)); $response .= <<"EOF"; - - -
$stringinfo[$snum][$stringfullname]:
$stringtext
EOF } } $response .= "- No non-default administration text data -
\n" unless $somenondefault; $response .= <<"EOF";
= = = = = = = = = = = = = = = = =
 DATA FOR EACH EVENT SET
= = = = = = = = = = = = = = = = =
EOF my @sets = glob("*.set"); for (my $snum=0; $snum <= $#sets; $snum++) { my %setdata; my $maxeline = load_set($sets[$snum], \%setdata); $maxeline += 0; my $setname = for_listing($setdata{setname},0); my $setdesc = for_listing($setdata{setdescription}, 1); $response .= <<"EOF";
****************

$setdata{set}: $setname

****************

Short Name: $setdata{set}
Set Display Name: $setname
Maximum number of people: $setdata{countbuttons}
Visible in public list: $setdata{visible}
- - - - - - -
Set Description:
$setdesc
- - - - - - -
$maxeline event(s):

EOF for (my $eline=1; $eline <= $maxeline; $eline++) { my $enum = $setdata{eventorder}->[$eline]; my $ename = special_chars($setdata{event}->[$enum]->{name}); my $edesc = special_chars($setdata{event}->[$enum]->{desc}); $response .= "($enum) $ename: $edesc
\n"; } my $maxpnum = load_people($sets[$snum]); # get people information my $npeople = 0; for (my $unsortedpnum=1; $unsortedpnum <= $#personname; $unsortedpnum++) { $npeople ++ if $personname[$personssorted[$unsortedpnum-1]]; } $response .= <<"EOF"; - - - - - - -
People records: $npeople

EOF for (my $unsortedpnum=1; $unsortedpnum <= $#personname; $unsortedpnum++) { my $pnum = $personssorted[$unsortedpnum-1]; next unless $personname[$pnum]; my @pevents = split(/\:/, $personevents[$pnum]); $response .= "($pnum) " . special_chars($personname[$pnum]) . ", attendees: "; $response .= "$personcount[$pnum] " . ", events: "; my $elist; foreach my $enum (@pevents) { $elist .= ", " if $elist; $elist .= special_chars($setdata{event}->[$enum]->{name}) . " ($enum)"; } $response .= "$elist
\n"; } $response .= <<"EOF"; - - - - - - -
Set specific text data (non-default settings only):
EOF $response .= "- No set specific text data -
\n" unless scalar(keys %{$setdata{strings}}); for (my $snum=0; $snum <= $#stringinfo; $snum++) { my $sname = $stringinfo[$snum][$stringname]; if (exists $setdata{strings}->{$sname}) { my $stringtext = for_listing($setdata{strings}->{$sname}, ($stringinfo[$snum][$stringtype]==$stringtypemultiline)); $response .= <<"EOF"; - - -
$stringinfo[$snum][$stringfullname]:
$stringtext
EOF } } } $response .= <<"EOF";
= = = = = = = = = = = = = = = = =
 END OF BACKUP DATA
= = = = = = = = = = = = = = = = =
EOF $responsedata->{content} = $response; $responsedata->{contenttype} = "text/HTML; charset=UTF-8"; return; } elsif ($p =~ /^editsetsave/) { # save new values for set last unless check_adminpassword(\%params, \%strings); my %setdata; my $maxevent = load_set("$params{editset}.set", \%setdata); load_set_from_params(\%params, \%setdata); save_set_from_setdata(\%setdata); last; } elsif ($p =~ /^editsetssave:([^\:]*):(.*?)$/) { # save set specific string value last unless check_adminpassword(\%params, \%strings); my %setdata; my $maxevent = load_set("$params{editset}.set", \%setdata); $setdata{strings}->{$1} = $2 eq "c" ? $params{"editsetsnew:$1"} : ""; # "c" is change, "d" is default $setdata{strings}->{$1} =~ s/\n$//; # remove trailing new line so it doesn't keep adding load_set_from_params(\%params, \%setdata); save_set_from_setdata(\%setdata); last; } elsif ($p =~ /^editsetreorder:([a-z]*):(\d*)$/) { # reorder set events: up/down/insert/delete last unless check_adminpassword(\%params, \%strings); my $cmd = $1; my $eline = $2; my %setdata; my $maxeventline = load_set("$params{editset}.set", \%setdata); $maxeventline = load_set_from_params(\%params, \%setdata); # get set data, including any new changes here if ($cmd eq "up") { if ($eline > 1) { my $enum = splice(@{$setdata{eventorder}}, $eline, 1); splice(@{$setdata{eventorder}}, $eline-1, 0, $enum); } } elsif ($cmd eq "down") { if ($eline < $maxeventline) { my $enum = splice(@{$setdata{eventorder}}, $eline, 1); splice(@{$setdata{eventorder}}, $eline+1, 0, $enum); } } elsif ($cmd eq "insert") { my $newenum; for ($newenum=1; $newenum <= $maxeventline; $newenum++) { last unless $setdata{event}->[$newenum]; # find first unused number } $params{insertnewevent} = [$eline, $newenum]; # remember to show it in listing } elsif ($cmd eq "delete") { my $delnum = $setdata{eventorder}->[$eline]; splice(@{$setdata{eventorder}}, $eline, 1); # remove event my $enamesc = special_chars($setdata{event}->[$delnum]->{name}); $params{statusmessage} = qq!Deleted "$enamesc" ($delnum)!; load_people("$params{editset}.set"); # get people information my $pnum; my $pplupdatelist; for (my $unsortedpnum=1; $unsortedpnum <= $#personname; $unsortedpnum++) { $pnum = $personssorted[$unsortedpnum-1]; next unless $personname[$pnum]; my %pevents; @pevents{split(/\:/, $personevents[$pnum])} = 1; if (exists $pevents{$delnum}) { # this person is signed up for the deleted event delete $pevents{$delnum}; $personevents[$pnum] = join(":", sort keys %pevents); $pplupdatelist .= ", " if $pplupdatelist; $pplupdatelist .= special_chars($personname[$pnum]); if ($personevents[$pnum]) { # other events left - update file open (PERSONFILEOUT, ">$params{editset}.set/person.$pnum.txt"); print PERSONFILEOUT "version:1.0\n"; print PERSONFILEOUT "name:$personname[$pnum]\n"; print PERSONFILEOUT "count:$personcount[$pnum]\n"; foreach my $penum (sort {$a <=> $b} split(/\:/, $personevents[$pnum])) { print PERSONFILEOUT "event:$penum\n"; } close PERSONFILEOUT; } else { # no events left - delete person file unlink "$params{editset}.set/person.$pnum.txt"; $pplupdatelist .= " (no remaining events)"; } } } $params{statusmessage} .= "
Removed from the following people: $pplupdatelist" if $pplupdatelist; } save_set_from_setdata(\%setdata); last; } elsif ($p =~ /^editsetcancel/) { # just redisplay last; } elsif ($p =~ /^editsetadmin/) { # go back to admin last unless check_adminpassword(\%params, \%strings); $params{editset} = ""; $params{admintop} = 1; last; } } $response .= <<"EOF";
$strings{adminpageheading}
EOF if ($params{statusmessage}) { # display status message if necessary $response .= <<"EOF";
$params{statusmessage}
EOF $params{statusmessage} = ""; # only show this one once } # # # # # # # # # # # # See which type of invocation # # # # # # # # # # # # # ADMIN command # if ($params{doinglogin} && !$params{adminlogincancel}) { # IE submits without using button name $params{admintop} = "Login"; } if ($params{admintop} || $params{editset}) { check_adminpassword(\%params, \%strings); } if ($params{admintop}) { my $passwordwarning; $passwordwarning = <<"EOF" unless $strings{adminpassword};

The administrator password is currently not set. This allows any user to access this page. If this is not what you want, you can set the password below. EOF $response .= <<"EOF";
Administration Page
This page is for use by the people who are administering the use of this program. It has facilities for creating, modifying, and deleting event sets. It is the means for setting the administrator password that controls access to this page and for setting the default values for the text that is displayed to normal users on other pages. Finally, it can list all of the data stored by this program for backup or historical purposes. Pressing "Done" exits this page, logs out, and returns to the normal list of event sets page. $passwordwarning
EOF my @sets = glob("*.set"); for (my $snum=0; $snum <= $#sets; $snum++) { my %setdata; my $maxevent = load_set($sets[$snum], \%setdata); my $sname = $setdata{set}; my $snamesc = special_chars($setdata{setname}); my $sevents; for (my $eline=1; $eline <= $maxevent; $eline++) { my $enum = $setdata{eventorder}->[$eline]; $sevents .= ", " if $sevents; $sevents .= special_chars($setdata{event}->[$enum]->{name}); } my @peoplefiles = glob("$sets[$snum]/person.*.txt"); # See how many people my $npeople = scalar @peoplefiles; $response .= <<"EOF"; EOF } $response .= <<"EOF";
Edit Event Sets
This first section lets you edit or delete existing event sets. Editing lets you create and/or modify the list of events that make up the set. Deleting an event set is permanent and cannot be undone. Doing so deletes the event definitions as well as all of the signup information. Alternatively, event sets may be hidden from normal users by setting their "Visible In Public List" setting to "No" using the Edit page.
Event Set Visible Attendee
Names
Delete
Set
$sname $snamesc
$sevents
$setdata{visible} $npeople
EOF for (my $snum=0; $snum <= $#sets; $snum++) { my %setdata; my $maxevent = load_set($sets[$snum], \%setdata); my $sname = $setdata{set}; my $snamesc = special_chars($setdata{set}); $response .= <<"EOF"; EOF } $response .= <<"EOF";
Create New Event Set
This is where you can create a new event set. You may select an existing event set from which to copy initial values for text and another one from which to copy initial event information (they may both be the same existing event set). The "Text" includes the Set Name, Set Description, instructions, text on buttons, etc. The "Event Info" includes all of the event names and descriptions, and the number of "Number of People" radio buttons. All of the initial values may be changed by subsequently editing the new event set. You can create "template" event sets whose sole purpose is for copying. Keep them out of the public listing by setting their "Visible In Public List" value to "No".
Text From: Event Info From:
Default Empty
$snamesc $snamesc
The new event set needs its own short name, made up of up to 8 letters and/or numbers with no spaces. Case is ignored. Specify the short name for the new event set here:
EOF $response .= <<"EOF";
Edit Text
Much of the text that is displayed by this program may be replaced with custom values. Each of these text strings may be set separately. You set custom values by typing them here or typing them when editing an event set and then pressing the corresponding "Change" button. You can reset a text string to its default value by pressing the "Use Default" button.

Text values shown here on the main administration page are used on the main public event set list page and on the admin login page. They are also used on specific event set pages for text strings that are set to default for that event set.

Many of the multi-line text strings may optionally include special markup commands that help you make the text more useful. These commands are as follows:
[http://a.url text to show] - "text to show" as a web link. For example, [http://www.nytimes.com New York Times] will result in New York Times, which, when clicked, pops up a new browser window showing the requested page.

[map:address] - The word "map" linked to Google Maps. For example, [map:77 Massachusetts Ave, Cambridge, MA] will result in Map.

[addr:address] - The address followed by the word "map" in parenthesis linked to Google Maps. For example, [addr:77 Massachusetts Ave, Cambridge, MA] will result in "77 Massachusetts Ave, Cambridge, MA (Map)".

Explicit line breaks (from pressing Enter/Return) are preserved making it easy to have paragraphs.

[b:text in bold:b] - "text in bold" will appear as bold text. For example, "This is [b:bold type:b]." becomes "This is bold type."

[i:italic text:i] - "italic text" will appear in italics. For example, "This is [i:italic text:i]." becomes "This is italic text."

[quote:indented text:quote] - "indented text" will appear indented (like this text) and may be multiple paragraphs in length by including line breaks.

{{amp}}, {{lt}}, {{gt}}, {{quot}} - for advanced users who know HTML, this is a way to insert raw &, <, >, and " characters.
Here is the full list of text strings, with an explanation of how they are used by the program:
EOF for (my $snum=0; $snum <= $#stringinfo; $snum++) { my $sname = $stringinfo[$snum][$stringname]; my $stringval = special_chars($shivadata{$sname} || $stringinfo[$snum][$stringdefault]); $response .= <<"EOF";
$stringinfo[$snum][$stringfullname]
$stringinfo[$snum][$stringdesc]
EOF if ($stringinfo[$snum][$stringtype]==$stringtypesingleline) { $response .= <<"EOF";
EOF } elsif ($stringinfo[$snum][$stringtype]==$stringtypemultiline) { $response .= <<"EOF";
EOF } $response .= <<"EOF";
EOF if ($shivadata{$sname}) { $response .= <<"EOF"; EOF } else { $response .= <<"EOF"; (Showing default value) EOF } $response .= <<"EOF";
EOF } $response .= <<"EOF";
List Everything For Backup
Pressing this button will display a page with all of the entered data. This page may then be printed out or saved so that in the event of a problem with the website that loses data (including text settings and signups) there will be backup information that may be used to re-enter any data that was lost.
Legal Notices
This is the $programmark program version $programversion
(c) Copyright 2007 Software Garden, Inc.
All Rights Reserved.

This program comes with ABSOLUTELY NO WARRANTY; see the program source code for a complete copy of the license. This is "free" software, released under the GPL 2.0 license, and you are welcome to redistribute it under certain conditions; see the license for details.
EOF } # # EDIT SET command # elsif ($params{editset}) { my %setdata; my $maxevent = load_set("$params{editset}.set", \%setdata); my ($insertedeline, $insertedenum); if ($params{insertnewevent}) { $maxevent++; # add a blank one in the middle ($insertedeline, $insertedenum) = @{$params{insertnewevent}}; splice(@{$setdata{eventorder}}, $insertedeline, 0, $insertedenum); $setdata{event}->[$insertedenum] = {name => "", desc => ""}; } my $maxblank = 3; my $mindisplayed = 10; my $setnamesc = special_chars($setdata{setname}); my $descsc = special_chars($setdata{setdescription}); $descsc =~ s/\\n/\n/g; my %visiblechecked; $visiblechecked{$setdata{visible}} = " CHECKED"; $response .= <<"EOF";
Editing Event Set:$setdata{set}
This page lets you set up, and then later edit, an event set. Make sure that the event set has a Set Display Name, a Set Description, and at least one event defined. Changes take effect immediately. There is no undo. Before making changes you can save or print out backup information by using the "List Everything For Backup" facility available on the administration page.

When finished, press the Admin button to return to the admininstration page.
Event Set Main Values
Enter and/or make changes to the following values and then save them all by clicking the "Save" button below.
Set Display Name
This is the name that is displayed at the top of the user signup page and used to refer to this event set in most lists of event sets. Unlike the short name, it may be the same for more than one event set.
Set Description
This is the text that appears under the Set Display Name on the user signup page. It describes the particular set of events in greater detail. This text may include special markup commands. Those commands are more fully described on the main administration page under "Edit Text". For reference, they include: Explicit line breaks (Enter/Return), [http://a.url text to show], [map:address], [addr:address], [b:bold:b], [i:italic:i], [quote:indent:quote], and HTML-enabling escapes {{amp}}, {{lt}}, {{gt}}, and {{quot}}.
Events
This is where you set and modify the list of events for this event set. There is a short name used to refer to this event in some lists and a longer description displayed in the main listing. Changes to the Name and Description are saved by clicking the "Save" button below this list. Once events are set, the display order may be changed using the Up and Down buttons. New events may be added to an existing set by either entering them in blank entries at the bottom of the list (additional ones are added automatically if necessary) or by using an Insert button to open up a blank entry above an existing event. Existing events may be deleted from the list by pressing the corresponding Delete button. This deletes the event and removes the signups from all people who signed up for it. (People with no remaining signed up events are deleted from the list.) The event name, description, and display order may be changed even after people have signed up without affecting those signups.
EOF my $maxeventnum; my $rowtype = 0; for (my $eline=1; $eline <= $maxevent; $eline++) { my $enum = $setdata{eventorder}->[$eline]; $maxeventnum = $maxeventnum > $enum ? $maxeventnum : $enum; my $updisabled = $eline == 1 ? " disabled" : ""; my $downdisabled = $eline == $maxevent ? " disabled" : ""; my $ename = special_chars($setdata{event}->[$enum]->{name}); my $edesc = special_chars($setdata{event}->[$enum]->{desc}); $response .= <<"EOF"; EOF $ename = $setdata{event}->[$enum]->{name}; $ename =~ s/\\/\\x2F/g; $ename =~ s/"/\\x22/g; if ($enum == $insertedenum) { $response .= <<"EOF"; EOF } else { $response .= <<"EOF"; EOF } $response .= <<"EOF"; EOF $rowtype = 1 - $rowtype; } for (my $eline=$maxevent+1; $eline <= $maxevent+$maxblank || $eline <= $mindisplayed; $eline++) { $maxeventnum++; $response .= <<"EOF"; EOF $rowtype = 1 - $rowtype; } $response .= <<"EOF";
Name Description
 
 
 
Maximum Number of People
This specifies the number of "Number of people" buttons displayed on the signup page for this event set.
EOF my %countchecked; $countchecked{$setdata{countbuttons}} = " CHECKED" if $setdata{countbuttons}; for (my $i=1; $i <= $maxcountbuttons; $i++) { $response .= <<"EOF"; $i EOF } $response .= <<"EOF";
Visible In Public List
If this value is set to "No" this event set will not be listed on the public list of event sets. The event set will still be listed on the main administration page and available for copying when creating new event sets. It may be reset back to "Yes" to return the event set to the listing.
Yes No
Event Set Custom Text
Much of the text that is displayed by this program may be replaced with custom values. Each of these text strings may be set separately. You set custom values specific to this event set by typing them here and then pressing the corresponding "Change" button. You can reset a text string to its default value by pressing the "Use Default" button. If set to "Use Default", the actual value used is either the value set on the main administration page, or, if that is set to "Use Default", to the built-in default value shown here.

Many of the multi-line text strings may optionally include special markup commands that help you make the text more useful. Those commands are more fully described on the main administration page under "Edit Text". For reference, they include: Explicit line breaks (Enter/Return), [http://a.url text to show], [map:address], [addr:address], [b:bold:b], [i:italic:i], [quote:indent:quote], and HTML-enabling escapes {{amp}}, {{lt}}, {{gt}}, and {{quot}}.
EOF for (my $snum=0; $snum <= $#stringinfo; $snum++) { my $sname = $stringinfo[$snum][$stringname]; my $stringvalue = special_chars($setdata{strings}->{$sname}) || $strings{$sname}; next if $sname =~ m/^admin/; # don't edit admin ones here $response .= <<"EOF";
$stringinfo[$snum][$stringfullname]
$stringinfo[$snum][$stringdesc]
EOF if ($stringinfo[$snum][$stringtype]==$stringtypesingleline) { $response .= <<"EOF";
EOF } elsif ($stringinfo[$snum][$stringtype]==$stringtypemultiline) { $response .= <<"EOF";
EOF } $response .= <<"EOF";
EOF if ($setdata{strings}->{$sname}) { $response .= <<"EOF"; EOF } else { $response .= <<"EOF"; (Showing default value) EOF } $response .= <<"EOF";
EOF } $response .= <<"EOF";
EOF } # # SHOW ADMIN LOGIN SCREEN # elsif ($params{adminlogin}) { if ($params{statusmessage}) { # display status message if present $response .= <<"EOF";
$params{statusmessage}
EOF } $response .= <<"EOF";
Administration Login
$strings{adminlogininstructions}
Password
EOF } # # EVENT SET NOT SET # elsif (!$params{set}) { $response .= <<"EOF";
$strings{admininitialpageinstructions}
EOF my @sets = glob("*.set"); my $setdisplayed; for (my $snum=0; $snum <= $#sets; $snum++) { my %setdata; load_set($sets[$snum], \%setdata); next if $setdata{visible} eq "N"; $setdisplayed = 1; # remember we displayed at least one my $sname = $setdata{set}; my $snamesc = special_chars($setdata{setname}); $response .= <<"EOF"; EOF } $response .= <<"EOF" unless $setdisplayed; EOF $response .= <<"EOF";
$sname $snamesc
$strings{adminnosets}
$strings{admininitialpagefooting}
EOF } # # # # # # # # # # # # Have set, list events, etc. -- main display # # # # # # # # # # # else { my ($command, $rest, $enum, $eline, $maxevent, $ename, $edesc, $pnum, $ecount, $rowtype, $maxpnum); my ($changednum, $setname, $setdescription, $countbuttons); my (%setdata, %countchecked); $eventdir = "$params{set}.set"; $maxevent = load_set($eventdir, \%setdata); if (!$setdata{exists} || $setdata{visible} && $setdata{visible} ne "Y") { $responsedata->{content} = <<"EOF"; # should not get here unless URL with "set" param was given out Page not found The page you are looking for might have been removed, had its name changed, or is temporarily unavailable. EOF $responsedata->{contenttype} = "text/plain; charset=UTF-8"; return; } foreach my $sname (keys %{$setdata{strings}}) { # override non-default text strings with setdata if ($stringinfo[$snl{$sname}][$stringtype] == $stringtypemultiline) { $strings{$sname} = wikitext_encode($setdata{strings}->{$sname}, $strings{adminmaptext}); } else { $strings{$sname} = special_chars($setdata{strings}->{$sname}); } } my $maxpnum = load_people($eventdir); if ($params{dosave} && $params{person}) { # update or create person info if ($newattend) { # attending at least one thing if ($params{editnum}) { # updating an existing person (will even update their name) $pnum = $params{editnum}; } else { # new one - still look up just in case person didn't remember they were coming $pnum = $personnumber{$params{person}}; # see if already exists if ($pnum) { # already exists -- add this to their existing events my %setevents; @setevents{split(/\:/, $newattend)} = 1; @setevents{split(/\:/, $personevents[$pnum])} = 1; $newattend = join(":", sort keys %setevents); } else { $pnum ||= $maxpnum + 1; # add a new one } } my $pname = $params{person}; $pname = substr($pname, 0, 40) if length($pname) > 40; # spam protection of a sort my $pcount = $params{pcount}; $pcount = $pcount > 10 ? 10 : $pcount; # spam protection of a sort open (PERSONFILEOUT, ">$eventdir/person.$pnum.txt"); print PERSONFILEOUT "version:1.0\n"; print PERSONFILEOUT "name:$pname\n"; print PERSONFILEOUT "count:$pcount\n"; foreach $enum (sort {$a <=> $b} split(/\:/, $newattend)) { print PERSONFILEOUT "event:$enum\n"; } close PERSONFILEOUT; $changednum = $pnum; # remember to highlight } else { # not attending anything - delete if existed if($personnumber{$params{person}}) { unlink "$eventdir/person.$personnumber{$params{person}}.txt"; } } load_people($eventdir); # reload people information $editnum = 0; # not editing anymore if were } my ($topinstructions, $savingtitle, $namevalue, $savingbutton, $donedisabled); if ($editnum) { $topinstructions = $strings{topinstructionsold}; $countchecked{$personcount[$editnum]} = " CHECKED"; $namevalue = special_chars($personname[$editnum]); $savingtitle = $strings{signupactiontitleold}; $savingbutton = $strings{signupsavingbuttonold}; $donedisabled = " disabled"; } else { $topinstructions = $strings{topinstructionsnew}; $countchecked{1} = " CHECKED"; $savingtitle = $strings{signupactiontitlenew}; $savingbutton = $strings{signupsavingbuttonnew}; $donedisabled = ""; } # # # # # # # # # # # # List Events # # # # # # # # # # # $setname = special_chars($setdata{setname}); $setdescription = wikitext_encode($setdata{setdescription}, $strings{adminmaptext}); $response .= <<"EOF";
$setname
$setdescription
$topinstructions
EOF $rowtype = 0; for ($eline=1; $eline <= $maxevent; $eline++) { $enum = $setdata{eventorder}->[$eline]; $ename = special_chars($setdata{event}->[$enum]->{name}); $edesc = special_chars($setdata{event}->[$enum]->{desc}); $response .= <<"EOF"; EOF $rowtype = 1 - $rowtype; } $response .= <<"EOF"; EOF $response .= <<"EOF";
$strings{eventsectiontitle}
$strings{eventheaderdescattendee} $strings{eventheadercount}
$ename $edesc EOF $ecount = 0; my $enamelist; my $eventchecked; for (my $unsortedpnum=1; $unsortedpnum <= $#personname; $unsortedpnum++) { $pnum = $personssorted[$unsortedpnum-1]; if ($personevents[$pnum] =~ m/(^|\:)$enum($|\:)/) { $ecount += $personcount[$pnum]; $enamelist .= ", " if $enamelist; $enamelist .= "" if $pnum == $changednum; $enamelist .= special_chars($personname[$pnum]); $enamelist .= "" if $pnum == $changednum; if ($pnum == $editnum) { # editing this person $eventchecked = " CHECKED"; } } } $response .= <<"EOF";
$enamelist
$ecount $strings{signupattending}
$savingtitle
$strings{signupname}
$strings{signupnumpeople} EOF $countbuttons = $setdata{countbuttons} || 1; for (my $i=1; $i <= $countbuttons; $i++) { # output the specified number of attendee buttons $response .= <<"EOF"; $i EOF } $response .= <<"EOF";
$strings{signupsavemsg}
EOF # # # # # # # # # # # # List People # # # # # # # # # # # $response .= <<"EOF";

$strings{signupbottominstructions}
EOF $rowtype = 0; for (my $unsortedpnum=1; $unsortedpnum <= $#personname; $unsortedpnum++) { $pnum = $personssorted[$unsortedpnum-1]; next unless $personname[$pnum]; $response .= <<"EOF"; EOF $rowtype = 1 - $rowtype; } $response .= "
$strings{peoplesectiontitle}
  $strings{peoplenamecolumn} $strings{peoplepeoplecolumn} $strings{peopleattendingcolumn}
$personname[$pnum] $personcount[$pnum] EOF my $evlist; foreach my $ev (split(/\:/, $personevents[$pnum])) { $evlist .= ", " if $evlist; if ($setdata{event}->[$ev]) { # event exists $evlist .= $setdata{event}->[$ev]->{name}; } else { $evlist .= "(deleted event)"; } } $response .= <<"EOF"; $evlist
\n"; # # # # # # # # # # # # Output footer # # # # # # # # # # # } my $end_time = times(); my $time_string = $start_clock_time; $response .= <<"EOF";

EOF # Get template and fill in variable response text my $template = $shivadata{adminpagetemplate} || $stringinfo[$snl{adminpagetemplate}][$stringdefault]; $template =~ s/{pagetitle}/$strings{adminpageheading}/e; $template =~ s/{pagecontents}/$response/e; $responsedata->{content} = $template; $responsedata->{contenttype} = "text/html; charset=UTF-8"; return; } # # # # # # # # # # # # load_shivadata(\%shivadata) # # Loads the string overrides and fills out %shivadata. # # Format is: stringname:value (encoding for NL, ":", and "\": \n, \c, \b) # # %shivadata{stringname} = value for stringname # sub load_shivadata { my $shivadata = shift @_; my ($stringname, $value); open (SHIVAFILEIN, "shivadata.txt"); while (my $line = ) { chomp $line; $line =~ s/\r//g; ($stringname, $value) = split(/\:/, $line, 2); next if $stringname eq "version"; $value =~ s/\\n/\n/g; $value =~ s/\\c/:/g; $value =~ s/\\b/\\/g; $shivadata->{$stringname} = $value; } close SHIVAFILEIN; } # # # # # # # # # # # # save_shivadata(\%shivadata) # # Saves the string overrides from %shivadata. # # Format is: stringname:value (encoding for NL, ":", and "\": \n, \c, \b) # # %shivadata{stringname} = value for stringname # # Blank overrides are not output # # String "version" should be "1.0" # sub save_shivadata { my $shivadata = shift @_; my $value; open (SHIVAFILEOUT, "> shivadata.txt"); print SHIVAFILEOUT "version:1.0\n"; foreach my $stringname (sort keys %$shivadata) { $value = $shivadata->{$stringname}; next unless $value; # don't output blank ones $value =~ s/\r//g; $value =~ s/\\/\\b/g; $value =~ s/\n/\\n/g; $value =~ s/\:/\\c/g; print SHIVAFILEOUT "$stringname:$value\n"; } close SHIVAFILEOUT; } # # # # # # # # # # # # $maxeventline = load_set($eventdir, \%setdata) # # Loads the information about the set from $eventdir and fills out %setdata, returning number of event lines. # # %setdata # {event} - reference to array of hashes # {event}->[n]->{name} = event n's name (always non-blank) # {event}->[n]->{desc} = event n's description # {maxevent} - highest event number # {eventorder} - reference to array # {eventorder}->[n] = event number in this line position ([1] is what's on first line, etc.) # only events listed here are saved # {set} - set really short name # {setname} - set name, short form # {setdescription} - set name, long form # {countbuttons} - max number of "Number of People" # {visible} - whether to show in public list ("Y" or "N"). Hidden is good for templates. # {strings} - reference to hash with string overrides # {strings}->{string-name} - value for "string-name" # {exists} - true if this set exists, false if $eventdir does not exist or have an event.txt file with data # # Format in file: # # version:version-number (1.0 now) # name:short-form-name # desc:long-form-name in wiki-text format # countbuttons:number # event:event-num:event-name:event-description (name has \ and : encoded) # Multiple events appear here in the order in which they will be listed. # Events are identified by their event number which stays constant # even when events are reordered or renamed. # People are signed up to event numbers, not event names. # visible:Y or N (default is Y) # string:stringname:string-value (\n, \, and : encoded) # sub load_set { my ($eventdir, $setdata) = @_; my ($command, $rest, $enum, $maxevent, $ename, $edesc); $setdata->{event} = []; # initialize set data $setdata->{eventorder} = []; $setdata->{strings} = {}; $eventdir =~ m/^([^\.]+)\./; $setdata->{set} = $1; $setdata->{strings} = {}; my ($enum, $pnum, $rest, $command, $sname, $eventline); open (EVENTFILEIN, "$eventdir/event.txt"); # Get list of all events while (my $line = ) { chomp $line; $line =~ s/\r//g; ($command, $rest) = split(/\:/, $line, 2); if ($command eq "event") { ($enum, $ename, $edesc) = split(/\:/, $rest, 3); $ename =~ s/\\c/:/g; $ename =~ s/\\b/\\/g; $setdata->{event}->[$enum] = {name => $ename, desc => $edesc}; $maxevent = $enum > $maxevent ? $enum : $maxevent; $setdata->{eventorder}->[++$eventline] = $enum; # remember order } elsif ($command eq "name") { $setdata->{setname} = $rest; } elsif ($command eq "desc") { $setdata->{setdescription} = $rest; } elsif ($command eq "countbuttons") { $setdata->{countbuttons} = $rest; } elsif ($command eq "visible") { $setdata->{visible} = $rest; } elsif ($command eq "string") { ($sname, $rest) = split(/\:/, $rest, 2); $rest =~ s/\\n/\n/g; $rest =~ s/\\c/:/g; $rest =~ s/\\b/\\/g; $setdata->{strings}->{$sname} = $rest; } $setdata->{exists} = 1; # remember we found something } close EVENTFILEIN; $setdata->{maxevent} = $maxevent; $setdata->{visible} = $setdata->{visible} eq "N" ? "N" : "Y"; return $eventline; } # # # # # # # # # # # # $maxeventline = load_set_from_params(\%params, \%setdata) # # Replaces %setdata name, desc, countbuttons, and events with data in params, leaving strings alone. # sub load_set_from_params { my ($params, $setdata) = @_; my $value; my $setdesc = $params->{editsetsetdesc}; $setdesc =~ s/\r//g; $setdesc =~ s/\n$//; # remove last new line $setdesc =~ s/\n/\\n/g; # only newlines are escaped $setdata->{setname} = $params->{editsetsetname}; $setdata->{setdescription} = $setdesc; $setdata->{countbuttons} = $params->{editsetcountbuttons}; $setdata->{visible} = $params->{editsetvisible} || "Y"; $setdata->{event} = []; # reset event data $setdata->{eventorder} = []; my $maxeventline = 0; foreach my $paramname (sort keys %$params) { # find last line with data next unless $paramname =~ m/^editsetevent\:(.+)$/; $maxeventline = $1 > $maxeventline ? $1 : $maxeventline; } my $maxevent = 0; my $neweline = 0; for (my $eline=1; $eline <= $maxeventline; $eline++) { my $enum = $params->{"editseteventnum:$eline"}; my $ename = $params->{"editsetevent:$eline"}; my $edesc = $params->{"editseteventdesc:$eline"}; next unless $ename; # don't process blank ones # NOTE: This means you can delete event without knowing to delete people info $setdata->{event}->[$enum] = {name => $ename, desc => $edesc}; $maxevent = $enum > $maxevent ? $enum : $maxevent; $setdata->{eventorder}->[++$neweline] = $enum; # remember order } $setdata->{maxevent} = $maxevent; return $neweline; } # # # # # # # # # # # # save_set_from_setdata(\%setdata) # # sub save_set_from_setdata { my $setdata = shift @_; open (SETFILEOUT, "> $setdata->{set}.set/event.txt"); # save to file: setname.set/event.txt print SETFILEOUT "version:1.0\n"; print SETFILEOUT <<"EOF"; name:$setdata->{setname} desc:$setdata->{setdescription} countbuttons:$setdata->{countbuttons} visible:$setdata->{visible} EOF for (my $eline=1; $eline < scalar @{$setdata->{eventorder}}; $eline++) { my $enum = $setdata->{eventorder}->[$eline]; my $ename = $setdata->{event}->[$enum]->{name}; my $edesc = $setdata->{event}->[$enum]->{desc}; $ename =~ s/\\/\\b/g; $ename =~ s/\:/\\c/g; print SETFILEOUT "event:$enum:$ename:$edesc\n"; } foreach my $sname (sort keys %{$setdata->{strings}}) { my $sstring = $setdata->{strings}->{$sname}; $sstring =~ s/\r//g; $sstring =~ s/\\/\\b/g; $sstring =~ s/\n/\\n/g; $sstring =~ s/\:/\\c/g; next unless $sstring; print SETFILEOUT "string:$sname:$sstring\n"; } close SETFILEOUT; } # # # # # # # # # # # # $maxpnum = load_people($eventdir) # # Gets a list of all people and fills out @personevents, @personname, %personnumber, @personcount, and @eventcount # It also sets @personsorted. # # Format in file: # # version:version-number (1.0 now) # name:attendee-name # count:number-of-people # event:event-number # sub load_people { my $eventdir = shift @_; my ($enum, $pnum, $rest, $command); @personevents = (); @personname = (); %personnumber = (); @personcount = (); @eventcount = (); my @peoplefiles = glob("$eventdir/person.*.txt"); # Get list of all people my $maxpnum = 0; for (my $pfnum=1; $pfnum <= $#peoplefiles+1; $pfnum++) { open (PERSONFILEIN, $peoplefiles[$pfnum-1]); $peoplefiles[$pfnum-1] =~ m/.*\.(.+?)\.txt$/; # get person number $pnum = $1; $maxpnum = $pnum > $maxpnum ? $pnum : $maxpnum; # remember last while (my $line = ) { chomp $line; $line =~ s/\r//g; ($command, $rest) = split(/\:/, $line, 2); if ($command eq "name") { $personname[$pnum] = $rest; $personnumber{$rest} = $pnum; # hash to find number } elsif ($command eq "count") { $personcount[$pnum] = $rest; } elsif ($command eq "event") { $enum = $rest; if ($enum) { $personevents[$pnum] .= ":" if $personevents[$pnum]; $personevents[$pnum] .= $enum; $eventcount[$enum] += $personcount[$pnum]; } } elsif ($command eq "version") { # ignored for now } } close PERSONFILEIN; } @personssorted = sort {lc($personname[$a]) cmp lc($personname[$b])} (1 .. $#personname); return $maxpnum; } # # # # # # # # # # # # $setname = check_setname($string) # # Returns a legal setname, check for size and characters # sub check_setname { my $string = shift @_; $string =~ s/[^0-9a-zA-Z\-\_]//g; $string = substr($string, 0, 8) if length($string) > 8; $string = lc $string; return $string; } # # # # # # # # # # # # $ok = check_adminpassword(\%params, \%strings) # # Returns true if admin password is correct, otherwise false, and removes all params, adds adminlogin # sub check_adminpassword { my ($params, $strings) = @_; if ($params->{password} eq $strings->{adminpassword}) { # Password OK return 1; } %$params = (); # delete all parameters $params->{adminlogin} = "Admin"; # set to login $params->{statusmessage} = "Incorrect administrator password."; sleep 2; # wait a bit, to make guessing harder return 0; } # # # # # # # # # # # # special_chars($string) # # Returns $string where &, <, >, " are HTML escaped # sub special_chars { my $string = shift @_; $string =~ s/&/&/g; $string =~ s//>/g; $string =~ s/"/"/g; return $string; } # # # # # # # # # # # # for_listing($string, $nl) # # If $nl is true, the characters "\n" are converted into newlines (\n). # Returns $string where &, <, >, " are HTML escaped, and \n is
. # sub for_listing { my ($string, $nl) = @_; $string =~ s/&/&/g; $string =~ s//>/g; $string =~ s/"/"/g; $string =~ s/\\n/\n/g if $nl; $string =~ s/\n/
/g; return $string; } # # # # # # # # # # # # url_encode($string) # # Returns $estring with special chars URL encoded # # Based on Mastering Regular Expressions, Jeffrey E. F. Friedl, additional legal characters added # sub url_encode { my $string = shift @_; $string =~ s!([^a-zA-Z0-9_\-;/?:@=#.+])!sprintf('%%%02X', ord($1))!ge; $string =~ s/%26/{{amp}}/gs; # let ampersands in URLs through -- convert to {{amp}} return $string; } # # # # # # # # # # # # addr_encode($string) # # Returns $estring with chars encoded as Google Maps wants it in the URL # # Based on Mastering Regular Expressions, Jeffrey E. F. Friedl, additional legal characters added # sub addr_encode { my $string = shift @_; $string =~ s!([^a-zA-Z0-9_\-;/?:@=#.])!sprintf('%%%02X', ord($1))!ge; $string =~ s/%20/+/gs; # convert spaces to "+" return $string; } # # # # # # # # # # # # wikitext_encode($string, $mapword) # # Turns a description string into HTML, including: # # [http://url text to show] -> text to show # [map:address string] -> the $mapword linked to Google maps # [addr:address string] -> "address string ($mapword)" with $mapword linked to Google maps # Line breaks preserved as
# [b:text in bold:b] # [i:text in italic:i] # [quote:text to treat as a block quote:quote] # {{amp}}, {{lt}}, {{gt}}, {{quot}} - raw &, <, >, " # sub wikitext_encode { my ($string, $mapword) = @_; $string =~ s!\[(http:.+?)\s+(.+?)\]!'{{lt}}a href={{quot}}' . url_encode("$1") . "{{quot}} target={{quot}}_blank{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!egs; # Wiki-style links $string =~ s!\[map:(.+?)\]!'{{lt}}a href={{quot}}http://maps.google.com/maps?q=' . addr_encode("$1") . "{{quot}} target={{quot}}_blank{{quot}}{{gt}}$mapword\{{lt}}/a{{gt}}"!egs; # Google map links $string =~ s!\[addr:(.+?)\]!"$1" . ' ({{lt}}a href={{quot}}http://maps.google.com/maps?q=' . addr_encode("$1") . "{{quot}} target={{quot}}_blank{{quot}}{{gt}}$mapword\{{lt}}/a{{gt}})"!egs; # Other Google map links $string = special_chars($string); $string =~ s/\n/\\n/g; $string =~ s/\\n/
/g; # Line breaks are preserved $string =~ s/\[b:(.+?)\:b]/$1<\/b>/gs; # [b:text:b] for bold $string =~ s/\[i:(.+?)\:i]/$1<\/i>/gs; # [i:text:i] for italic $string =~ s/\[quote:(.+?)\:quote]/
$1<\/blockquote>/gs; # [quote:text:quote] to indent $string =~ s/\{\{amp}}/&/gs; # {{amp}} for ampersand $string =~ s/\{\{lt}}//gs; # {{gt}} for greater than $string =~ s/\{\{quot}}/"/gs; # {{quot}} for quote return $string; } =begin license SOFTWARE LICENSE This software and documentation is: Copyright (c) 2007 Software Garden, Inc. All rights reserved. 1. The source code of this program is made available as free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 3. If the GNU General Public License is restrictive in a way that does not meet your needs, contact the copyright holder (Software Garden, Inc.) to inquire about the availability of other licenses, such as traditional commercial licenses. 4. The right to distribute this software or to use it for any purpose does not give you the right to use Servicemarks or Trademarks of Software Garden, Inc., including Garden, Software Garden, ListGarden, and wikiCalc. 5. An appropriate copyright notice will include the Software Garden, Inc., copyright, and a prominent change notice will include a reference to Software Garden, Inc., as the originator of the code to which the changes were made. Disclaimer THIS SOFTWARE IS PROVIDED BY SOFTWARE GARDEN, INC., "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWARE GARDEN, INC. NOR ITS EMPLOYEES AND OFFICERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE DISTRIBUTION OR USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Software Garden, Inc. PO Box 610369 Newton Highlands, MA 02461 USA www.softwaregarden.com License version: 1.4/2007-03-19 = = = = = GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. =end =cut