Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Someone get the coffee

by hagus (Monk)
on Aug 21, 2002 at 03:54 UTC ( #191650=sourcecode: print w/ replies, xml ) Need Help??

Category: fun stuff
Author/Contact Info hagus
Description: A self contained CGI script to manage your daily coffee runs. Everyone adds their name + email to the web page, and when it reaches a certain amount of entries (3 by default), the coffee order list is then mailed to everyone. It's up to you to decide who actually goes to get them though ;)

Note: in practise, name usually ends up being 'hagus - flat white', combining name and coffee type.


use strict;
use warnings;
use CGI qw/:all *table/;
use Cache::FileCache;

my $cache = new Cache::FileCache({namespace => 'coffee'});

my $cgi = new CGI;

print $cgi->header;
print $cgi->start_html({bgcolor=>'white', title=>'Someone get the coff
+ee'});

print h1({align=>'center'}, "Someone get the coffee");

if ($cgi->param("action"))
{
    my $action = $cgi->param("action");

    if ($action eq "add")
    {
        my $name = $cgi->param("name");
        my $email = $cgi->param("email");
        
        unless ($name and $email)
        {
            print "Get lost.\n";
            print hr();
            exit;
        }
        else
        {
            $cache->set($name, $email, "1 day");
        }

        my @keys = $cache->get_keys();
        if (@keys > 2)
        {
            foreach my $key (@keys)
            {
                my $email = $cache->get($key);
                open(FOO, "|mail $email");
                print FOO "Subject: someone get the coffee\n\n";
                foreach my $keyagain (@keys)
                {
                    print FOO "$keyagain - " . $cache->get($keyagain) 
+. "\n";
                }
                print FOO $cgi->url() . "\n\n.\n";
                close(FOO);
            }
            
        }
    }
    elsif ($action eq "deleteall")
    {
        $cache->clear();
    }
    else
    {
        print "Get lost.\n";
        print hr();
        exit;
    }
}

my @keys = $cache->get_keys();

unless (@keys > 0)
{
    print p({align=>'center'}, "No orders right now.");
}
else
{
    print start_table({cellpadding=>3,cellspacing=>3, align=>'center'}
+);
    print Tr({bgcolor=>'blue'},
             td( span({style=>'color: white'}, "Name")),
             td( span({style=>'color: white'}, "E-mail"))
             );
    foreach my $key (@keys)
    {
        my $email = $cache->get($key);
        print Tr(
           td($key),
           td($email)
           );
    }
    print end_table(), p();
}
  
print start_form({url=>$cgi->self_url, method=>'get'}),
    start_table(),
    Tr(
       td( "Name" ),
       td( textfield({name=>'name'}) ),
       ),
    Tr(
       td( "Email" ),
       td( textfield({name=>'email'}) )
       ),
    end_table();

print start_table(),
    Tr(
       td(submit({name=>'action', value=>'add'}, "add")),
       td(submit({name=>'action', value=>'deleteall'}, "deleteall")),
       td(button({name=>'refreshpage',
              value=>'refreshpage',
              onClick=>"document.location.href=\"" . $cgi->url() . "\"
+; return;"}))
       ),
    end_table();

print end_form();

Comment on Someone get the coffee
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://191650]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-12-21 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls