#!c:/perl/bin/perl -w ###################################################################### # Thanks for trying out NotePod! # # What is NotePod? It's a small notepad used for notes and memos. # # It's a cheap little script I threw together in an hour. # # Under what license is this? None! Do *whatever* you want with it! # # Modify it, throw it out, call it names, sell it, whatever. # # I will not be held responsable for lost data, etc, etc. # # Non-copyright 2002 by Nathan B. (you're not getting my last name!) # ###################################################################### use strict; my $version = "1.0"; $|++; # output buffering # Load modules use CGI::Carp qw(fatalsToBrowser); use CGI; use IO::Scalar; use Data::Dumper; use Fcntl ':flock'; # Declare variables use vars qw( $q %input %db $stdout $OUT $id ); # Get data input $q = new CGI; $input{$_} = $q->param($_) for $q->param(); # Load DB open LOCK, ">>lock.lck" or die "Could not open the lock file: $!\n"; flock LOCK, LOCK_EX or die "Could not flock the lock file: $!\n"; %db = (); do "db.dat"; # Print everything to a variable instead of STDOUT $OUT = new IO::Scalar \$stdout; select $OUT; # Branch off depending on action &main if !$input{'action'}; # Main Page &main("Changes Discarded.") if $input{'action'} eq "Cancel"; # Cancel Save &new_note if $input{'action'} eq "new"; # New Note &save_note if $input{'action'} eq "Save Note"; # Save Note &edit_note if $input{'action'} eq "edit"; # Edit Note &del if $input{'action'} eq "Delete Note"; # Delete Note &del(1) if $input{'action'} eq "delall"; # Delete All # Print HTTP/HTML Headers sub print_it { select STDOUT; # Print it all to STDOUT # Save DB $Data::Dumper::Purity = 1; $Data::Dumper::Indent = 0; open DATA, ">db.dat" or die "COuld not open database: $!\n"; flock DATA, LOCK_EX or die "Could not flock databse: $!\n"; print DATA Data::Dumper->Dump([\%db], ['*db']); close DATA; close LOCK; print qq|Content-type: text/html\n NotePod: $_[0]
$_[1]
$stdout
|; exit; } # Main Screen sub main { $_[0] = "NotePod version $version" if !$_[0]; print qq| $_[0]New Note \| Delete All TitleLengthLast Modified |; foreach my $id (keys %db) { next if $id eq "num"; my $title = $db{$id}[0]; # Note Title my $len = length($db{$id}[1]); # Length of Note my $mod = $db{$id}[2]; # Last Modified Date print qq|$title$len characters$mod|; } &print_it('Displaying Notes', 'Current Notes'); } # New Note sub new_note { $_[0] = "* Creating New Note." if !$_[0]; print qq| $_[0] Title: Contents: |; &print_it('New Note', 'Create New Note'); } sub save_note { &new_note('* You need to enter a title and contents.') if (!$input{'title'} || !$input{'contents'}); if ($input{'id'}) { $db{$input{'id'}} = [$input{'title'}, $input{'contents'}, my $a=localtime]; } else { $db{int(++$db{'num'})} = [$input{'title'}, $input{'contents'}, my $a=localtime]; } &main("Note Saved"); } sub edit_note { print qq| * You are editting an existing note. Title: Contents: |; &print_it('New Note', 'Create New Note'); } # Delete Note(s) sub del { if ($_[0] == 1) { %db = (); &main("All Notes Deleted!"); } else { delete $db{$input{'id'}}; &main("Note Deleted."); } }