############################################################
#
# pooclub_pages.pl
#
# Functions which are responsible for drawing an entire poopage
#
############################################################

require "pooclub_html.pl";


############################################################

sub pooclub_lobby  # pooclub home page
{
    my $yyyymmdd = shift(@_);

    # Table and left hand column
    print qq(
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
    );
    pooclub_menus();
    print ("<br>");


    # Main column (middle)
    print qq(
      </td>
      <td align="left" valign="top" width="450">
    );

    pooclub_banner();

    # Page Title
    print qq(
      <table border="0" align="left" width="100%">
       <tr>
        <td align="left" valign="top">
    );
#    poopage_title("Welcome");
    print qq(
        </td>
        <td align="center" valign="top">
         &nbsp;
        </td>
        <td align="right" valign="top" width="150">
    );
    pooclub_daysold();
    print qq(
        </td>
       </tr>
      </table><br clear="all">
    );

    print qq(
      <br clear="all">
      <table border="0" align="left" width="100%">
      <tr>
    );

    td_the_cull();  # 2x2 cell
    td_topic();

    print qq(</tr><tr>);
#    td_roll_of_honour();
    td_link("Daily Drivel", "drivel.jpg", "drivel",
            "Don't just read it. Write it!");


    print qq(</tr><tr>);
    td_the_shed();
    td_link("Lumps", "lumps1.jpg", "lumps",
            "Find out about your pooclub accounts.");
    td_forum();

    print qq(</tr><tr>);

    td_link("Who's poo?", "forum.gif", "who",
            "Who <i>are</i> these weirdos?");
    td_link("Poochoonz", "guitar1.jpg", "http://pooclub.pbwiki.com/Poochoonz",
            "Can you chooz this month's winning choon?");
    td_vote();

    print qq(</tr><tr>);
    td_caption_competition();  # 2x2 cell
    td_wiki();

    print qq(</tr><tr>);
#    td_poochoonz();

    print qq(
       </tr>
      </table>
      <br clear="all">
    );

    div_other_places();

    # Right hand column
    print qq(
      </td>
      <td align="left" valign="top" width="150">
    );
    pooclub_todays_date();
    print "<p>";
    pooclub_event();
    div_ten_years();
#    div_ians_party();
    print "<p>";

    pooclub_todays_poem();
    div_voty();
    print "<p>";
    div_roll_of_honour();

    print qq(
      </td>
     </tr>
    </table>
    );
} # pooclub_lobby()

############################################################

sub pooclub_shed
{
#    my $yyyymmdd = shift(@_);

    # Table and left hand column
    print qq(
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
    );
    pooclub_menus();
    print ("<br>");

    # Main column (middle)
    print qq(
      </td>
      <td align="left" valign="top" width="450">
    );

    pooclub_banner();
#    poopage_title("Pooclub Home");

    # Page Title
    print qq(
      <table border="0" align="left" width="100%">
       <tr>
        <td align="left" valign="top">
    );
    poopage_title("The Shed");
    print qq(
        </td>
        <td align="center" valign="top">
         &nbsp;
        </td>
        <td align="right" valign="top" width="150">
    );
    pooclub_daysold();
    print qq(
        </td>
       </tr>
      </table><br clear="all">
    );

#    my $poem_record = todays_poem($u_yyyymmdd);
#    my ($shiteId, $poemTitle, $poemAuthor, $poemType, $imageCode) = split /;/, $poem_record;

    # Inner table (middle column) starts here
    print qq(
      <br clear="all">
      <table border="0" align="left" width="100%">
      <tr>
    );
    td_shed_welcome();  # 2x2 cell
    td_cement();

    print qq(</tr><tr>);
    td_shedlight();

    print qq(</tr><tr>);
    td_topic();
    td_nominate_veg();
    td_sheddery();

    print qq(</tr><tr>);
    td_business();
    td_celsius();
    td_toolbox();

    print qq(</tr><tr>);
    td_prospects();
    td_luckyday();
    td_fat_cock();

    print qq(</tr><tr>);
    td_more_stuff();  # 3x1 cell

    print qq(
       </tr>
      </table>
      <br clear="all"><br>
    );
    div_other_places();

    # Right hand column
    print qq(
      </td>
      <td align="left" valign="top" width="150">
    );
    pooclub_todays_date();
    print qq(<p>);
    pooclub_event();
    print qq(<p>);

    pooclub_todays_poem();
    print qq(<br>);

    div_quorn_fed_chicken();
    print qq(<p>);
#    div_fat_cock();
    div_appropriate_content();
    print qq(<p>);
#    div_obey_conform_consume();
    print qq(<p>);
    print qq(
      </td>
     </tr>
    </table>
    );
} # pooclub_shed()

############################################################

sub td_link
{
    my ($title, $image, $link, $text) = @_;
    if ($link =~ /http/)
    {
    }
    else
    {
        $link = qq(${THIS_CGI}?p=$link) ;
    }

    print qq(
        <td align="center" valign="top" width="150">
         <div>
          <font face="verdana,arial" size="3">
           <b>$title</b>
          </font>
         </div>
         <a href="$link">
           <img src="${IMGPOODIR}/$image" alt="$title" width="100" border="0"></a>
         <div class="itemText">
          <a href="$link">$text</a>
         </div>
        </td>
    );
}

############################################################

sub td_vote
{
    print qq(
        <td align="center" valign="top" width="150">
         <div><font face="verdana,arial" size="3"><b>Vote!</b></font></div>
         <a href="${THIS_CGI}?page=polls">
           <img src="${IMGPOODIR}/voting_cross.jpg" alt="Vote" width="50" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?page=polls">to kill someone in the forum...</a>
         </div>
        </td>
    );
}

############################################################

sub td_cement
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b></b></font>
         <a href="${THIS_CGI}?p=shed">
           <img src="${IMGPOODIR}/cement1.jpg" alt="Solid Cement" width="100" border="0"></a>
        </td>
    );
}

############################################################

sub td_the_shed
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>The Shed</b></font>
         <a href="${THIS_CGI}?p=shed">
           <img src="${IMGPOODIR}/shed1.jpg" alt="The Shed" width="100" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?p=shed">What's in the pooclub shed?</a>
         </div>
        </td>
    );
}

############################################################

sub td_nominate_veg
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Nominate A Vegetable</b></font>
         <a href="${THIS_CGI}?page=voty_my_noms">
           <img src="${IMGPOODIR}/vegetables.jpg" alt="Vegetables" width="100" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?page=voty_my_noms">for the Vegetable Of the Year</a>
         </div>
        </td>
    );
}

############################################################

sub td_the_cull  # 2x2 cell
{
    print qq(
        <td rowspan="2" colspan="2" align="center" valign="top" width="300">
         <a href="${THIS_CGI}?p=cull">
           <img src="${IMGPOODIR}/cvpresents4.jpg" alt="The Cull" width="250" border="0"></a>
        </td>       
    );
}

############################################################

sub td_toolbox
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Toolbox</b></font>
         <div class="itemText" align="left">
          <li><a href="${THIS_CGI}?p=thesaurus">Thesaurus</a></li>
          <li><a href="${THIS_CGI}?p=chat&c=phrases">Phrases &amp; Their Origins</a></li>
          <li><a href="${THIS_CGI}?p=problems">Problems Pages</a></li>
          <li><a href="${THIS_CGI}?p=chat&c=mike">Mike's Spot</a></li>
          <li><a href="${THIS_CGI}?p=events">Events</a></li>
          <li><a href="${THIS_CGI}?p=celebritystiffs">Celebrity Stiffs</a></li>
          <li><a href="${THIS_CGI}?p=postas"><i>Be</i> a celebrity</a></li>
          <li><a href="${THIS_CGI}?p=pope">Be <i>a pope!</i></a></li>
          </a>
         </div>
        </td>
    );
}

############################################################

sub td_forum
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Forum</b></font>
         <a href="http://groups.google.com/group/pooclub">
           <img src="${IMGPOODIR}/forum.jpg" alt="Forum" width="100" border="0"></a>
         <div class="itemText">
          <a href="http://groups.google.com/group/pooclub">
           This is where they all hang out.
           Meet them, insult them, cull them.
          </a>
         </div>
        </td>
    );
}

############################################################

sub td_topic
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Today's Topic</b></font>
         <a href="${THIS_CGI}?p=topic">
           <img src="${IMGPOODIR}/topic.jpg" alt="Topic" width="100" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?p=topic">
           Post a topic to the pooclub forum.
          </a>
         </div>
        </td>
    );
}

############################################################

sub td_poochoonz
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Play&nbsp;Poochoonz</b></font>
         <a href="http://pooclub.pbwiki.com/Poochoonz">
           <img src="${IMGPOODIR}/guitar1.jpg" alt="Poochoonz" width="100" border="0"></a>
         <div class="itemText">
          <a href="http://pooclub.pbwiki.com/Poochoonz">
           Can you chooz this month's winning choon?
          </a>
         </div>
        </td>
    );
}

############################################################

sub div_ten_years
{
    print qq(
         <div>
         <a href="http://www.quornfedchicken.com">
          <center>
           <img src="${IMGPOODIR}/10_truly_horrible_years.jpg" alt="QFC" width="100" border="0"></a>
          </center>
          It's pooclub's 10th anniversary!
         </div>
    );
}

############################################################

sub div_ians_party
{
    print qq(
         <div><center>
         <b>Come to Ian's party!</b>
         <a href="http://www.halliday.co.nz/50.html">
           <img src="${IMGPOODIR}/ian.jpg" alt="50" width="100" border="0">
          Please... he's desperate
</a>
         </div>
          </center>
    );
}

############################################################

sub div_quorn_fed_chicken
{
    print qq(
         <div>
         <a href="http://www.quornfedchicken.com">
          <center>
           <img src="${IMGPOODIR}/tasty.jpg" alt="QFC" width="100" border="0"></a>
          </center>
Find out more about
<b><a href="http://www.quornfedchicken.com">Quorn-fed Chicken</a></b>
new alternative for vegetarians.
         </div>
    );
}

############################################################

sub div_obey_conform_consume()
{
    print qq(
        <div>
         <a href="${IMGPOODIR}/obey_conform_consume_large.jpg">
          <img src="${IMGPOODIR}/obey_conform_consume.jpg" width="150"
           alt="Graffiti at the corner of Moorgate and London Wall" border="0"></a>
        </div>
    );
}

############################################################

sub div_appropriate_content()
{
    print qq(
         <div align="center"><b>Report Appropriate Content</b></div>
         <div class="itemMinor">
If you feel that any of the content you have read
here in pooclub is interesting, factual,
entertaining or in any way worthwhile,
please report it to our 
<a href="${THIS_CGI}?p=complaint">complaints manager</a>
who will attend to the matter in a casual and indifferent manner.
Pooclub takes very seriously its commitment to providing
its members and visitors with the most stupid and profane services
and endeavours to ensure that all of its content is
of the lowest possible standard.
         </div>
    );
}

############################################################

sub div_fat_cock()
{
    print qq(
         <div align="center"><font face="verdana,arial" size="3">Art</font></div>
         <a href="${IMGPOODIR}/brians_skip.jpg">
           <img src="${IMGPOODIR}/fat_cock.jpg" 
                alt="When pooclub artist Brian Cruickshank spotted a skip in Grimsby with Fat Cock graffited on it he felt inspired to produce this masterpiece.  Actually, I bet he wished he'd had a digital camera with him to save all the bother." 
                width="150" border="0"></a>
         <div class="itemText">
          <a href="${IMGPOODIR}/brians_skip.jpg">Can you tell what it is yet?</a>
         </div>
    );
}

############################################################

sub td_fat_cock
{
    print qq(
        <td align="center" valign="top" width="150">
         <div align="center"><font face="verdana,arial" size="3"><b>Art</b></font></div>
         <a href="${IMGPOODIR}/brians_skip.jpg">
           <img src="${IMGPOODIR}/fat_cock.jpg" alt="Art" width="100" border="0"></a>
         <div class="itemText">
          <a href="${IMGPOODIR}/brians_skip.jpg">Can you tell what it is yet?</a>
         </div>
        </td>
    );
}

############################################################

sub td_blank
{
    print qq(
        <td align="center" valign="top" width="150">
&nbsp;
        </td>
    );
}

############################################################

sub td_shed_welcome  # 2x2 cell
{
    print qq(
        <td rowspan="2" colspan="2" align="left" valign="top" width="300">
         <span class="zz_itemText" align="left">
          <img src="${IMGPOODIR}/shed1.jpg" alt="The Shed" width="100" align="left" border="0">
<b>Welcome to pooclub's shed.</b> <p />
If you're not a member of pooclub and have just wandered in, 
or come round to complain about the noise, allow us to make you welcome. 
Just plonk yourself down on the half-bag of solid cement with a nice cup 
of tea, and enjoy all the exciting gadgets and wotnots we have for you to 
play around with here in the shed.
         </span>
        </td>
    );
}

############################################################

sub td_caption_competition  # 2x2 cell
{
    my $seed = random_seed();
    my $captionData = random_line("$LISTDIR/caption_samples.dat", $seed);
    my ($captionFile, $caption) = split /;/, $captionData;
    print qq(
        <td rowspan="2" colspan="2" align="center" valign="top" width="300">
         <font face="verdana,arial" size="3"><b>Caption Competition</b></font>
         <a href="${THIS_CGI}?p=chat&c=captions">
           <img src="${IMGCAPTIONSDIR}/$captionFile" alt="Welcome To Pooclub" width="250" height="180" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?p=chat&c=captions"><i>$caption</i></a>
         </div>
         <br>
        </td>
    );
}

############################################################

sub td_welcome
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Welcome</b></font>
         <a href="${THIS_CGI}?p=welcome">
           <img src="${IMGPOODIR}/cvwelcome.jpg" alt="Welcome To Pooclub" width="100" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?p=welcome">What's this bollocks all about then?</a>
         </div>
         <div class="itemText" align="left">
          <ul>
           <li><a href="${THIS_CGI}?p=welcome">Welcome</a></li>
           <li><a href="${THIS_CGI}?p=features">Features</a></li>
           <li><a href="${THIS_CGI}?p=guide">Guide</a></li>
           <li><a href="${THIS_CGI}?p=faq">FAQ</a></li>
          </ul>
         </div>
        </td>
    );
}

############################################################

sub td_prospects
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Prospects</b></font>
         <a href="${THIS_CGI}?p=prospects">
           <img src="${IMGPOODIR}/panning1.jpg" alt="Pooclubbers' Prospects" width="100" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?p=prospects">What's in store for you today?</a>
         </div>
        </td>
    );
}

############################################################

sub td_voty
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3">
          <b>Vegetable Of <nobr>The Year 2009</nobr></b></font><br>
           <div class="itemText" align="center">         
           <a href="${THIS_CGI}?p=features#vegetable">
             Quorn-fed Chicken</a>
          </div>
          <a href="${THIS_CGI}?p=features#vegetable">
           <img src="${IMGPOODIR}/tasty.jpg" alt="What's this all about, then?" zwidth="100" border="0"></a>
         </font>
           <div class="itemText" align="center">
            <a href="${THIS_CGI}?page=voty">Your nominations for 2010</a>
           </div>
        </td>
    );
}

############################################################

sub div_voty
{
    my @winners = read_voty_winners();
    my $current_winner = $winners[0];
    my ($year, $veg) = split /;/,$current_winner;
    my $next_year = $year + 1;

    print qq(
        <div>
         <font face="verdana,arial" size="3">
          <b>Vegetable Of <nobr>The Year $year</nobr></b></font><br>
          <a href="${THIS_CGI}?p=features#vegetable">
           <img src="${IMGPOODIR}/voty.jpg" alt="What's this all about, then?" width="100" align="center" border="0"></a>
         </font>
           <div class="itemText" align="left">
            <b>$veg</b><br />
            <a href="${THIS_CGI}?page=voty">Nominations for $next_year</a><br />
            <a href="${THIS_CGI}?page=voty_my_noms">Nominate your vegetables</a><br />
            <a href="${THIS_CGI}?p=features#vegetable">What's this all about?</a><br />
           </div>
        </div>
    );
}


############################################################

sub div_roll_of_honour
{
    print qq(
           <div class="itemText" align="left">
            <b>Roll Of Honour</b><br />
    );
    for my $rec (read_voty_winners())
    {
        ($year, $veg) = split /;/,$rec;
        print qq(
            $year $veg<br />
        );
    }

    print qq(</div>);
}

############################################################

sub td_roll_of_honour
{
    print qq(
        <td align="center" valign="top" width="150">
          <table class="itemText" align="center"><tr><td>
           Roll Of Honour<br>
           <div class="itemText" align="left">
            <a href="${THIS_CGI}?p=features#vegetable">
             2009 Quorn-fed<br>&nbsp;&nbsp;&nbsp;Chicken<br>
             2008 Mushroom<br>
             2007 Kelp<br>
             2006 Carrot<br>
             2005 Beetroot<br>
             2004 Cucumber<br>
             2003 Yam<br>
             2002 Pea<br>
             2001 Potato<br>
             2000 Parsnip
            </a>
           </div>
          </td></tr></table>
        </td>
    );
}

############################################################

sub td_shedlight
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Shed</b>Light</font>
         <a href="${THIS_CGI}?p=shedlight">
           <img src="${IMGPOODIR}/shedlight5.jpg" alt="ShedLight" width="100" border="0"></a>
         <div class="itemText">
          <a href="${THIS_CGI}?p=shedlight">See your emails in a whole new light.</a>
         </div>
        </td>
    );
}

############################################################

sub td_celsius
{
    print qq(
        <td align="center" valign="top" width="150">

         <font face="verdana,arial" size="3">
          <b>Hot Or Not?</b>
         </font><br>
           <div class="itemText" align="left">         
           <a href="${THIS_CGI}?p=celsius">
            <img src="${IMGPOODIR}/thermometer_cropped.jpg" alt="Temperature Converter" align="left" border="0">
             Are you steaming or chilled?  Find out in our Celsius to Centigrade converter.</a>
         </div>
        </td>
    );
}


############################################################

sub td_business
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3"><b>Make Your Fortune</b></font>
         <a href="${THIS_CGI}?p=chat&c=business">
           <img src="${IMGPOODIR}/business.gif" alt="Don't Be Poor - Be Rich" width="100" border="0"></a>
         <div class="itemText" align="left">
          <a href="${THIS_CGI}?p=chat&c=business">Read Mike's guide to "Business Opportunities For The Entrepenre"</a>
         </div>
        </td>
    );
}


############################################################

sub td_wiki
{

    my $seed = (random_seed() % 7) +1;
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3">
          <b>Wiki</b></font>
          <div class="itemText" align="center">
          <a href="http://pooclub.pbwiki.com">
           <img src="${IMGPOODIR}/blackboard${seed}.jpg" alt="Wiki" width="100" border="0">
          </a>
          <a href="http://pooclub.pbwiki.com">
           <nobr>Build your own</nobr> pooclub wiki page.
           Or mock other members' pages.
          </a>
          </div><br>
        </td>
    );
}

############################################################

sub td_luckyday
{
    # Get details of next lucky day (Tuesday 22nd)
    my ($luckyday, $days_until) = split /;/, next_luckyday();
    my $ly = substr($luckyday, 0, 4);
    my $lm = substr($luckyday, 4, 2);
    my $lmon = $monthList[($lm - 1)%12];
    my $when = "in $days_until days.";
    if ($days_until == 0)
    {
        $when = "Today!";
    }
    elsif ($days_until == 1)
    {
       $when = "Tomorrow!";
    }
    print qq(
        <td align="left" valign="top">
         <font face="verdana,arial" size="3">
          <b>The Next<br>Lucky Day</b>
         </font>
         <font face="verdana,arial" size="2">
          <br><b>is $when</b></font><br>
          <i>Tuesday 22nd $lmon $ly</i></font><p>
         <div class="itemText">
          <a href="${THIS_CGI}?p=luckyday">What's a lucky day? Why is it important to you?</a>
         </div>

        </td>
    );
}

############################################################

sub td_sheddery
{
    print qq(
        <td align="center" valign="top" width="150">
         <font face="verdana,arial" size="3">
          <b>Got A Shed?</b></font>
          <div class="itemText" align="center">
          <a href="http://pooclub.pbwiki.com/Sheds">
           <img src="${IMGPOODIR}/sheddery.jpg" alt="Members Sheds" width="100" border="0"><br>
           Then add it to our Sheddery! <nobr>We'd love to see it!</nobr></a>
          </div>
        </td>
    );
}

############################################################

sub td_more_stuff  # 3x1 cell
{
    print qq(
        <td colspan="3" align="left" valign="top" width="300">
         <br>
         <div class="itemText" align="left">
          Want more stuff to play with?
          Why not get yourself a
          <a href="${THIS_CGI}?page=signup">poopages account</a>?
          And for sheer uncontrollable excitement and adventure, join our 
          <a href="http://groups.google.com/group/pooclub">forum</a> at
          <a href="http://groups.google.com/group/pooclub">Googlegroups</a>!
         </div>
        </td>
    );
}

############################################################

sub div_other_places()
{
    print qq(
        <div class="itemText" align="left">
         Other places:<br>
         <a href="http://www.facebook.com/group.php?gid=2582086775">Facebook</a> |
         <a href="http://www.twitter.com/pooclub">Twatter</a> |
         <a href="http://groups.yahoo.com/group/pooclub">
          Yahoogroups</a> |
         <a href="http://www.shite.org">Shitespace</a> |
         <a href="http://www.quornfedchicken.com">Quorn-fed Chicken</a>
        </div>
    );
}

############################################################

sub pooclub_prospects_page  # pooclub prospects (used to be our front page)
{
    my $yyyymmdd = shift(@_);
    my $ed_date = $yyyymmdd;
    my $news_yyyymmdd = $yyyymmdd;
    my $newsHeadline = "";
    my $edTitle = "";
    my $edAuthor = "";

    while (!open (EDFILE, "$EDITDIR/ed_${ed_date}.txt") && $ed_date > 20010101)
    {
        $ed_date = date_calc("-d-1 $ed_date");
    }
    while (<EDFILE>)
    {
        if (/^!/)  # It's the title line
        {
            chop;
            s/^!//;
            ($edTitle,$edAuthor,$signature) = split /;/, $_;
            $edAuthor =~ s/Mike Two-Sheds/Mike/;
            last;
        }
        else
        {
            next;
        }
    }
    close (EDFILE);

    while (!open (NEWSFILE, "$NEWSDIR/news_${news_yyyymmdd}.txt") && $news_yyyymmdd > 20010101)
    {
        $news_yyyymmdd = date_calc("-d-1 $news_yyyymmdd");
    }
    while (<NEWSFILE>)
    {
        if (/^!/)  # It's the title line
        {
            chop;
            s/^!//;
            $newsHeadline = $_;
            last;
        }
        else
        {
            next;
        }
    }
    close (NEWSFILE);

    if (!NEWSFILE) {$news_yyyymmdd = "ARSE"};

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();
    print ("<br>");
    show_knickknack();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    poopage_title("Pooclub Prospects");
    poopeople("pooclubbers");

#    print <<EOT;
#      <br clear="all">
#
#      <!--- Latest news headline --->
#      <table border="1" cellspacing="0" cellpadding="8" width="100%">
#       <tr><td align="center" bgcolor="#f0f0e0">
#        <table><tr><td align="left">
#
#        <font face="arial,verdana,times" size="2" color="black">
#        Latest <a href="$THIS_CGI?p=news">News</a> Headline<br></font>
#        <font face="times,verdana,arial" size="5" color="black">$newsHeadline</font><br>
#        <font face="arial,verdana,times" size="2" color="gray">
#EOT
#    if ($u_yyyymmdd == $news_yyyymmdd)
#    {
#        print "<i>New Today!</i>";
#    }
#    else
#    {
#        @parse = split /;/, parse_date($news_yyyymmdd);
#        $posted = sprintf "%s %2d %s", $parse[0],
#                                       $parse[1],
#                                       $parse[2];
#        print "Posted: $posted";
#    }
#
#    print <<EOT;
#        <br>For previous headlines, see
#        <a href="$THIS_CGI?p=oldnews">Old Club News</a>
#       </font>
#       </td></tr></table>
#     </td></tr></table>
#     <br clear="all">
#EOT

    print <<EOT;
      <font face="verdana,arial,times" size="2">
       Be sure to visit this page each day to see
       what sort of a day is in store for you and your fellow pooclubbers.
       And don't forget, if you want to find out why your prospects are as they
       are, just click on your name and "Stuff Today" will give you a more
       detailed breakdown on your prospects points.
      </font>
      <br clear="all"><br>
EOT

    my $shiteHash = {};
    my @shiteList = ();
    get_shitems(\$shiteHash, \@shiteList, "r");  # get "Recommended Reading" list
    random_sort(\@shiteList, $u_yyyymmdd);

    show_poo_prospects("pooclubbers", \$shiteHash, \@shiteList);

#    # Show latest editorial
#    print <<EOT;
#      <br clear="all">
#      <table border="1" width="100%" cellspacing="0" cellpadding="8"><tr><td align="center" bgcolor="#f0f0e0">
#       <table><tr><td align="left">
#
#        <font face="arial,verdana,times" size="2" color="black">
#        Have you read the latest <a href="$THIS_CGI?p=editorial">Editorial</a>
#        by ${edAuthor}?<br></font>
#        <font face="times,verdana,arial" size="5" color="black">$edTitle</font><br>
#        <font face="arial,verdana,times" size="2" color="gray">
#EOT
#    if ($u_yyyymmdd == $ed_date)
#    {
#        print "<i>New Today!</i>";
#    }
#    else
#    {
#        @parse = split /;/, parse_date($ed_date);
#        $posted = sprintf "%s %2d %s", $parse[0],
#                                       $parse[1],
#                                       $parse[2];
#        print "Posted: $posted";
#    }
#
#    print <<EOT;
#        <br><nobr>Feeling nostalgic? Browse the back catalogue of
#        <a href="$THIS_CGI?p=backcat">Old Editorials</a></nobr>
#       </font>
#       </td></tr></table>
#     </td></tr></table>
#     <br clear="all">
#EOT

    print <<EOT;
      <font face="verdana,arial,times" size="2">
       And be sure to check out your "Recommended Reading"!
       This is a Shitespace poem or story which will be most
       relevant to you today.  Heed its words.
      </font>
      <br clear="all"><br>
EOT


    show_poo_prospects("poopals", \$shiteHash, \@shiteList);
    print "<br clear=all>";
    show_poo_prospects("pookids", \$shiteHash, \@shiteList);
    show_poo_prospects("poosterity", \$shiteHash, \@shiteList);
    print "<br clear=all>";

    print <<EOT;
      </td>
      <td align="left" valign="top" width="150">
EOT
    pooclub_todays_date();
    print "<p>";
    pooclub_event();
    print "<p>";
    pooclub_goodday($u_yyyymmdd);
    print "<p>";
    pooclub_todays_poem();
    print "<p>";
    pooclub_daysold();
    print "<p>";
    pooclub_prospects();
    print "<br>";
    show_knickknack(10);
    print <<EOT;
      </td>
     </tr>
    </table>
EOT
}

############################################################

sub pooclub_leaguetable  # Latest positions in the prospects league
{
    my ($groupId, $days, $yyyymmdd) = @_;

    $groupId  = "pooclubbers" if ($groupId eq "");
    $days     = 14            if ($days eq "" || $days < 1);
    $yyyymmdd = $u_yyyymmdd   if ($yyyymmdd eq "");

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT

    pooclub_menus();
    print "<br>";
    show_knickknack();

    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    poopage_title("League Table");
    my $poowinners = show_poo_league($groupId, $days, $yyyymmdd);
    my ($poochamp, $poostar) = split /;/, $poowinners;
    my ($champMember, $champSex, $champName, $champFile) = split /;/, get_trooper_rec($poochamp);
    my ($starMember,  $starSex,  $starName,  $starFile)  = split /;/, get_trooper_rec($poostar);
    $champFile = "$IMGTROOPDIR/$champFile";
    $starFile  = "$IMGTROOPDIR/$starFile";

    print <<EOT;
      </td>
      <td align="left" valign="top" width="150">
EOT

    pooclub_todays_date();

    print <<EOT;
      <br clear="all"><br><br>
      <center>
      <font face="verdana,arial,times" size="2">
       Current<br>poochamp:
       <div class="inlineimage" align="center">
        <img src="$champFile" alt="$champName" border="0">
        <div class="caption" align="center"><medium>$poochamp</medium></div>
       </div>
      </font>
      </center>

      <br clear="all"><br><br>
      <center>
      <font face="verdana,arial,times" size="2">
       Today's<br>poostar:
       <div class="inlineimage" align="center">
        <img src="$starFile" alt="$starName" border="0">
        <div class="caption" align="center"><medium>$poostar</medium></div>
       </div>
      </font>
      </center>

      </td>
     </tr>
    </table>
EOT
}

############################################################

sub pooclub_clubnews
{
    my $yyyymmdd = shift(@_);
    my $ed_date = $yyyymmdd;
    my $headline = "";
    my $title = "";
    my $author = "";

    while (!open (EDFILE, "$EDITDIR/ed_${ed_date}.txt") && $ed_date > 20010101)
    {
        $ed_date = date_calc("-d-1 $ed_date");
    }
    while (<EDFILE>)
    {
        if (/^!/)  # It's the title line
        {
            chop;
            s/^!//;
            ($title,$author,$signature) = split /;/, $_;
            $author =~ s/Mike Two-Sheds/Mike/;
            last;
        }
        else
        {
            next;
        }
    }
    close (EDFILE);

    while (!open (NEWSFILE, "$NEWSDIR/news_${yyyymmdd}.txt") && $yyyymmdd > 20010101)
    {
        $yyyymmdd = date_calc("-d-1 $yyyymmdd");
    }

    if (!NEWSFILE) {$yyyymmdd = "ARSE"};

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    poopage_title("Club News");
    setfont("text");

    while (<NEWSFILE>)
    {
        s/^\s*$/<p>/;  # Paragraph breaks for blank lines

        if (/^!/)  # It's a headline, print it big
        {
            chop;
            s/^!//;
            print <<EOT;
              </font>
              <font face="times,verdana,arial" size="5" color="black">$_</font>
              <p>
              <font face="verdana,arial,times" size="2" color="black">
EOT
        }
        else
        {
#            s/\$HOST/$HOST/g;
#            s/\$IMGDIR/$IMGDIR/g;
#            s/\$SCRIPT/$SCRIPT/g;
            substitute_vars(\$_);
            print "$_";
        }
    }
    close (NEWSFILE);

    ### Weather Forecast

    my $forecast = random_line ("$LISTDIR/pooclubweather.list", $u_yyyymmdd);
    $forecast =~ s/\s+$//;
    $forecast = lc($forecast);

    print <<EOT;
       </font>
       <a name="events">
       <font face="verdana,arial,times" size="4" color="brown">
        <b>Weather</b>
       </font><p>
       <font face="verdana,arial,times" size="2" color="black">
        Today it will be ${forecast}.
        <br clear="all"><br>
        <table border="1" cellspacing="0" cellpadding="8"><tr><td align="left" bgcolor="#f0f0e0">

        Have you read the latest <a href="$THIS_CGI?p=editorial">Editorial</a> by $author<br>
        <font face="times,verdana,arial" size="5" color="black">$title</font><br>
        <font face="verdana,arial,times" size="2" color="gray">
EOT
    if ($u_yyyymmdd == $ed_date)
    {
        print "<i>New Today!</i>";
    }
    else
    {
        @parse = split /;/, parse_date($ed_date);
        $posted = sprintf "%s %2d %s", $parse[0],
                                       $parse[1],
                                       $parse[2];
        print "Posted: $posted";
    }

    print <<EOT;
        <br>Feeling nostalgic? Browse the Editorial
        <a href="$THIS_CGI?p=backcat">Back Catalogue</a>
       </font>
       </td></tr></table>
      </td>
      <td align="left" valign="top" width="150">
EOT
    pooclub_todays_date();
    print "<p>";
    pooclub_event();
    print "<p>";
    pooclub_goodday($u_yyyymmdd);
    print "<p>";
    pooclub_todays_poem();
    print "<p>";
    pooclub_daysold();
    print "<p>";
    pooclub_prospects();
    print <<EOT;
       <br clear="all"><br><hr><br>
       <font face="times,arial,verdana" size="4"><i>Bygone&nbsp;Headlines</i><br>
       </font>
       <font face="verdana,arial,times" size="2">
        <a href="$THIS_CGI?p=oldnews">Old Club News</a>
       </font>
      </td>
     </tr>
    </table>
EOT
}

############################################################

sub pooclub_editorial
{
    my $yyyymmdd = shift(@_);
    my $headline = "";
    my $author = "";
    my $signature = "";

    while (!open (EDFILE, "$EDITDIR/ed_${yyyymmdd}.txt") && $yyyymmdd > 20010101)
    {
        $yyyymmdd = date_calc("-d-1 $yyyymmdd");
    }

    if (!EDFILE) {$yyyymmdd = "ARSE"};

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    poopage_title("Editorial");
    setfont("text");

    while (<EDFILE>)
    {
        s/^\s*$/<p>/;  # Paragraph breaks for blank lines

        if (/^!/)  # It's the title, print it big
        {
            chop;
            s/^!//;
            ($headline,$author,$signature) = split /;/, $_;
            $author =~ s/Mike Two-Sheds/Mike/;
            $author = "<br>" . $author if ($author);
            $signature = "<br>" . $signature if ($signature);
            print <<EOT;
              </font>
              <font face="times,verdana,arial" size="5" color="black">$headline</font>
              <p>
              <font face="verdana,arial,times" size="2" color="black">
EOT
        }
        else
        {
#            s/\$HOST/$HOST/g;
#            s/\$IMGDIR/$IMGDIR/g;
#            s/\$SCRIPT/$SCRIPT/g;
            substitute_vars(\$_);
            print "$_";
        }
    }
    close (EDFILE);

    my ($dow, $mday, $month, $year) = split /;/, parse_date ($yyyymmdd);
    my $mon = substr ($month, 0, 3);
    print <<EOT;
        </font>
       <br clear="all">
       <table align="right">
        <tr><td align="left">
           <font face="arial,verdana,times" size="2" color="brown">
            $author
            $signature
            <br>$mday $mon $year
<!-----
            <p>Editorial <a href="$THIS_CGI?p=backcat">Back Catalogue</a>
----->
           </font>
        </td></tr>
       </table>
       <br clear="all"><br>
       <font face="times,arial,verdana" size="3" color="gray"><i>
        If you would like to comment on these fine words, please feel free to
       </i></font>
       <font face="arial,verdana,times" size="2" color="brown">
        <a href="http://groups.yahoo.com/group/pooclub/post">post</a>
       </font>
       <font face="times,arial,verdana" size="3" color="gray"><i>
        a message on the
       </i></font>
       <font face="arial,verdana,times" size="2" color="brown">
        <a href="http://groups.yahoo.com/group/pooclub">pooboard</a>.
       </font>
      </td>
      <td align="left" valign="top" width="150">
EOT
    pooclub_todays_date();
    print "<p>";
    pooclub_event();
    print "<p>";
    pooclub_goodday($u_yyyymmdd);
    print "<p>";
    pooclub_todays_poem();
    print "<p>";
    pooclub_daysold();
    print "<p>";
    pooclub_prospects();
    print <<EOT;
       <br clear="all"><br><hr><br>
       <font face="times,arial,verdana" size="4"><i>Back&nbsp;Catalogue</i><br>
       </font>
       <font face="verdana,arial,times" size="2">
        <a href="$THIS_CGI?p=backcat">Old&nbsp;Editorials</a>
       </font>
      </td>
     </tr>
    </table>
EOT
}

############################################################

sub pooclub_oldnews
{
    my $yyyymmdd = shift(@_);

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    print <<EOT;
       <font face="verdana,arial,times" size="4" color="brown">
        <b>Club News</b>
       </font> -
       <font face="times,arial,verdana" size="4" color="black">
         <i>Bygone Headlines</i>
       </font>
       <p>
       <font face="verdana,arial,times" size="2" color="black">
        OK, this stuff's not news anymore but it's here for those long dull
        Sunday afternoons when you've got nothing better to do than read
        a pile of old crap that was just as crap when you first read it.
       </font>
       <br clear="all"><br>

       <table align="center" border="0" cellspacing="2" cellpadding="0">
EOT
    while ($yyyymmdd > 20011001)
    {
        if (open EDFILE, "$NEWSDIR/news_${yyyymmdd}.txt")
        {
            while (<EDFILE>)
            {
                if (/^\!/)
                {
                    chop;
                    s/^\!//;
                    $headline = $_;
                    ($dow, $mday, $month, $year) = split /;/, parse_date ($yyyymmdd);
                    $mon = substr ($month, 0, 3);

                    print <<EOT;
                     <tr><td align="right" valign="bottom">
                      <font face="arial,verdana,times" size="2">
                       <a href="$THIS_CGI?p=clubnews&a=$yyyymmdd"><nobr>$mday $mon $year</nobr></a>
                      </font>
                     </td><td align="left" valign="bottom">
                       &nbsp;
                     </td><td align="left" valign="bottom">
                      <font face="times,verdana,arial" size="3">
                       $headline
                      </font>
                     </td><td align="left" valign="bottom">
                       &nbsp;
                     </td><td align="left" valign="bottom">
                      <font face="arial,verdana,times" size="2" color="brown">
                       &nbsp;
                      </font>
                     </td></tr>
EOT
                }
            }
        }
        $yyyymmdd = date_calc("-d-1 $yyyymmdd");
    }
    print <<EOT;
       </table>
       <br clear="all"><br>
       <font face="verdana,arial,times" size="2">
        Got any exciting poonews you'd like to share with the rest of the club?
        Sling it this way:
        <a href="mailto:clubnews\@shite.org">clubnews\@shite.org</a>.
       </font>
      </td>
      <td align="left" valign="top" width="150">
EOT
    pooclub_todays_date();
    print "<p>";
    print <<EOT;
      </td>
     </tr>
    </table>
EOT

}

############################################################

sub pooclub_backcat
{
    my $yyyymmdd = shift(@_);

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    print <<EOT;
       <font face="verdana,arial,times" size="4" color="brown">
        <b>Editorial</b>
       </font> -
       <font face="times,arial,verdana" size="4" color="black">
         <i>Back Catalogue</i>
       </font>
       <p>
       <font face="verdana,arial,times" size="2" color="black">
        They say nostalgia's not what it used to be, but that doesn't mean we
        can't take a stroll down Memory Lane for a reload of all your old
        favourite editorials.
       </font>
       <br clear="all"><br>

       <table align="center" border="0" cellspacing="2" cellpadding="0">
EOT
    while ($yyyymmdd > 20011001)
    {
        if (open EDFILE, "$EDITDIR/ed_${yyyymmdd}.txt")
        {
            while (<EDFILE>)
            {
                if (/^\!/)
                {
                    chop;
                    s/^\!//;
                    ($headline,$author,$signature) = split /;/,$_;
                    $author =~ s/Mike Two-Sheds/Mike/;
                    ($dow, $mday, $month, $year) = split /;/, parse_date ($yyyymmdd);
                    $mon = substr ($month, 0, 3);

                    print <<EOT;
                     <tr><td align="right" valign="bottom">
                      <font face="arial,verdana,times" size="2">
                       <a href="$THIS_CGI?p=editorial&a=$yyyymmdd"><nobr>$mday $mon $year</nobr></a>
                      </font>
                     </td><td align="left" valign="bottom">
                       &nbsp;
                     </td><td align="left" valign="bottom">
                      <font face="times,verdana,arial" size="3">
                       $headline
                      </font>
                     </td><td align="left" valign="bottom">
                       &nbsp;
                     </td><td align="left" valign="bottom">
                      <font face="arial,verdana,times" size="2" color="brown">
                       $author
                      </font>
                     </td></tr>
EOT
                }
            }
        }
        $yyyymmdd = date_calc("-d-1 $yyyymmdd");
    }
    print <<EOT;
       </table>
       <br clear="all"><br>
       <font face="verdana,arial,times" size="2">
        If you would like to contribute a future editorial, please email
        <a href="mailto:editorial\@shite.org">editorial\@shite.org</a>.
       </font>
      </td>
      <td align="left" valign="top" width="150">
EOT
    pooclub_todays_date();
    print "<p>";
    print <<EOT;
      </td>
     </tr>
    </table>
EOT

}

############################################################

sub pooclub_events
{
    my $yyyymmdd = shift(@_);

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();

    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();


    my $fday;
    my $forecast;

    print <<EOT;
        <br clear="all">
        <table border="0" width="450" bgcolor="white"
               cellspacing="5" cellpadding="5">
         <tr><td width="400" align="left" valign="top" bgcolor="white">
          <font face="verdana,arial,times" size="4" color="brown">
           <b>Forthcoming Events</b>
          </font>
         </td><td width="50" align="left" valign="bottom" bgcolor="white">
          <font face="arial" size="2" color="gray"> Weather </font>
         </td></tr>
EOT
    for ($i = 0; $i <= 7; $i++)
    {
        ($f, $fd, $fm, $fy, $fo) = split /;/, parse_date($yyyymmdd);
        $forecast = random_line ("$LISTDIR/pooclubweather.list", $yyyymmdd);
        $forecast =~ s/Snowing/Snow/;
        $forecast =~ s/Foggy/Fog/;
        $forecast =~ s/Drizzly/Drizzle/;

        print <<EOT;
            <tr>
             <td width="400" align="center" valign="top" bgcolor="$colour[3]">
              <font face="arial" size=2" color="$colour[0]">$f $fd $fm</font>
            <br>
EOT

        display_poo_event($yyyymmdd);
        print <<EOT;
            </td><td width="50" align="left" valign="top" bgcolor="#f0f0f0">
             <font face="arial" size=2" color="black">
              $forecast
             </font>
            </td></tr>
EOT
        $yyyymmdd = date_calc("-d1 $yyyymmdd");
    }

    print <<EOT;
        </table>
       </font>
      </td>
      <td align="left" valign="top" width="150">
EOT
    pooclub_todays_date();
    print <<EOT;
       <br clear="all"><br>
       <font face="arial,times,verdana" size="1" color="brown">
        So, what's it like right now in pooclub's outlying regions?
       </font>
<!---- London ---->
<a href="http://www.wunderground.com/global/stations/03772.html">
<img src="http://banners.wunderground.com/banner/infobox_both/global/stations/03772.gif" height=108 width=144></a>
<br clear="all">

<!---- Leeds ---->
<a href="http://www.wunderground.com/global/stations/03346.html">
<img src="http://banners.wunderground.com/banner/infobox_both/global/stations/03346.gif" height=108 width=144></a>
<br clear="all">

<!---- Humberside ---->
<a href="http://www.wunderground.com/global/stations/03373.html">
<img src="http://banners.wunderground.com/banner/infobox_both/global/stations/03373.gif" height=108 width=144></a>
<br clear="all">

<!---- New York ---->
<a href="http://www.wunderground.com/US/NY/New_York.html">
<img src="http://banners.wunderground.com/banner/infobox_both/language/www/US/NY/New_York.gif" 
alt="Click for New York, New York Forecast" height=108 width=144></a> 
<br clear="all">

<!---- Plymouth, Indiana ---->
<a href="http://www.wunderground.com/US/IN/Plymouth.html">
<img src="http://banners.wunderground.com/banner/infobox_both/language/www/US/IN/Plymouth.gif"
alt="Click for Plymouth, Indiana Forecast" height=108 width=144></a>
<br clear="all">

<!---- Bristol ---->
<a href="http://www.wunderground.com/global/stations/03724.html">
<img src="http://banners.wunderground.com/banner/infobox_both/language/www/global/stations/03724.gif"
alt="Click for Bristol Airport, United Kingdom Forecast" height=108 width=144></a>
<br clear="all">

<!---- Bournemouth ---->
<!-----
<a href="http://www.wunderground.com/global/stations/03862.html">
<img src="http://banners.wunderground.com/banner/infobox_both/global/stations/03862.gif" height=108 width=144></a>
<br clear="all">
---->

<!---- Wellington ---->
<a href="http://www.wunderground.com/global/stations/93436.html">
<img src="http://banners.wunderground.com/banner/infobox_both/global/stations/93436.gif" height=108 width=144></a>
<br clear="all">

<!---- Melbourne ---->
<a href="http://www.wunderground.com/global/stations/94868.html">
<img src="http://banners.wunderground.com/banner/infobox_both/global/stations/94868.gif" height=108 width=144></a>
<!-------
       <a href="http://www.wunderground.com/global/stations/03772.html">
        <img src="http://banners.wunderground.com/banner/gizmotemp/global/stations/03772.gif" height=41 width=127></a>
---->
       <br clear="all">

       <font face="arial,times,verdana" size="1" color="brown">
        <a href="$THIS_CGI?p=news&a=20020521">News</a>
        article about the weather.
       </font>
      </td>
     </tr>
    </table>
EOT

}


############################################################

sub pooclub_stortroopers
{
    my $yyyymmdd = shift(@_);

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();

    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    poopage_title("Who's Poo");

    my $columns = 4;
    my @currentList = ();
    my @formerList = ();
    my @fakeList = ();
    my $fileHash = {};
    my $locHash = {};

#    my $TROOP_FILE = "$METADIR/troop.dat";  # defined in pooclub_setup.pl
    open (FD, "$TROOP_FILE");
    while (<FD>)
    {
        chop;
        next if (/^#/);
        ($member, $sex, $name, $file, $location) = split /;/, $_;

        $fileHash->{$name} = $file;
        $locHash->{$name} = $location;
        push @currentList, $name if ($member eq "C");
        push @formerList, $name if ($member eq "P");
        push @fakeList, $name if ($member eq "N");
    }

 #   poopage_subtitle("Current Members");
    poopage_subtitle("");
    troop_table(\@currentList, \$fileHash, \$locHash);
    print "<br>";
#    poopage_subtitle("Former Members");
#    troop_table(\@formerList, \$fileHash, \$locHash);
#    print "<br>";
#    poopage_subtitle("Fake Members");
#    troop_table(\@fakeList, \$fileHash, \$locHash);

    print <<EOT;
If you'd like to be included in this page, go to
<a href="http://www.stortroopers.com">www.stortroopers.com</a>
and design your own personal trooper.
Then send it to us and we'll include it in Who's Poo.
       </font>
      </td>
      <td align="left" valign="top" width="150">
EOT

    pooclub_todays_date();

    print <<EOT;
       <br clear="all"><br>
       <font face="arial,times,verdana" size="1" color="brown">
       </font>
      </td>
     </tr>
    </table>
EOT

}

############################################################

sub pooclub_sparetroopers
{
    my $yyyymmdd = shift(@_);

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();

    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    poopage_title("Spare Troopers");

    my $columns = 4;
    my @spareList = ();
    my $fileHash = {};
    my $locHash = {};

    open (FD, "$TROOP_FILE");
    while (<FD>)
    {
        chop;
        next if (/^#/);
        ($member, $sex, $name, $file, $location) = split /;/, $_;

        $fileHash->{$name} = $file;
        $locHash->{$name} = $location;
        push @spareList, $name if ($member eq "S");
    }

    poopage_subtitle("Wanna join us?  Take your pick...");
    troop_table(\@spareList, \$fileHash, \$locHash);
    print "<br>";

    print <<EOT;
       <font face="verdana,arial,times" size="2">
        We'd be well impressed if one of these were to match your appearance!
       </font>
      </td>
      <td align="left" valign="top" width="150">
EOT

    pooclub_todays_date();

    print <<EOT;
       <br clear="all"><br>
       <font face="arial,times,verdana" size="1" color="brown">
       </font>
      </td>
     </tr>
    </table>
EOT

}

############################################################

sub shedlight
{
    my $action = $q->param('send');
    my $intext = $q->param('text');
    my $pattern = $q->param('pattern');
    my $caseflag = $q->param('caseflag');

    my $pattern = "SHED" if (!$pattern);

    my $yyyymmdd = shift(@_);

    print qq(
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
    );
    pooclub_menus();

    print qq(
      </td>
      <td align="left" valign="top" width="450">
    );

    pooclub_banner();
    poopage_title("ShedLight");

    print img({-src=>"${IMGPOODIR}/shedlight1.jpg", -alt=>"ShedLight"});
    print p();

    if (!$intext)
    {
        print b("Shed some light on your inbox"), p();
        print qq(Suspect someone's been slipping subliminal sheds into their messages?
            Let's face it, it happens more often than you'd think.  Just cut-n-paste
            any email that someone's sent you into the text window below and see just
            how many sheds are lurking in it.
        ), p();
    }
    else
    {
        print b("Your Shedlit message:"), p();
        shedlight_convert($intext, $pattern, $caseflag);
    }

    print $q->startform;
    print $q->hidden(-name=>'p',
                     -default=>'shedlight');

    print table({-border=>'0', -width=>'400'},
            Tr(
              td({-align=>'left', valign=>'bottom', -width=>'200'},
                  "Text to convert..."
              ),
              td({-align=>'right', valign=>'top', -width=>'200'},
                  "Pattern",
                  $q->textfield(
                      -name=>'pattern',
                      -default=>'SHED',
                      -value=>$pattern,
                      -size=>16,
                      -maxlength=>60
                  )
              ),
            ),
            Tr(
              td({-valign=>"top", -colspan=>'2'},
                  $q->textarea(
                      -name=>'text',
                      -default=>$intext,
                      -rows=>8,
                      -columns=>54
                  )
              )
            ),
            Tr(
              td({-valign=>"top", -align=>"left", -class=>'smallText', -width=>'200'},
                  checkbox(-name=>'caseflag',
                      -label=>'Leave original capitals unchanged',
                      -checked=>$q->param(caseflag)
                  )
              ),
              td({-valign=>"top", -align=>"right", -width=>'200'},
                  $q->submit('send','Convert'),
              ),
            ),
    );
    print $q->endform;

    print qq(
      </td>
      <td align="left" valign="top" width="150">
    );

    pooclub_todays_date();

    print qq(
       <br clear="all"><br>
       <font face="arial,times,verdana" size="1" color="brown">
       </font>
      </td>
     </tr>
    </table>
    );
}

############################################################

sub shedlight_convert
{
    my ($text, $pattern, $caseFlag) = @_;
    my $t = 0;
    my $p = 0;

    # For some reason $pattern and $caseFlag don't seem to get picked up
    # when passed in as params.
    $pattern = $q->param('pattern');
    $caseFlag = $q->param('caseflag');

    $pattern = "SHED" if (!$pattern);
    $pattern =~ s/\W//g;

    my @inTextList = split //, $text;
    my @patternList = split //, $pattern;
    my $textLen = scalar(@inTextList);
    my $patternLen = scalar(@patternList);
    my @outTextList;
    my $commit = 0; # commit all changes up to this point
    my $count = 0; # number of complete patterns found
    my %converted = {};

    for ($t = 0; $t < $textLen; $t++)
    {
        if (lc($patternList[$p]) eq lc($inTextList[$t]))
        {
            $found = 1;
            $outTextList[$t] = uc($inTextList[$t]);
            $p++;
            $converted{$t} = 1;

            if ($p == $patternLen)  # We've found the last letter of the pattern in the text
            {
                $commit = $t;  # Commit all conversions up to letter $t
                $count++;
                $p = 0;
            }
        }
        else
        {
            if ($caseFlag)  # If set, don't force conversion to lowercase
            {
                $outTextList[$t] = $inTextList[$t];
            }
            else
            {
                $outTextList[$t] = lc($inTextList[$t]);
            }
        }
    }

    my $instances = "instances";
    $instances = "instance" if ($count == 1);
    print p(), "Found $count $instances of $pattern.", p() if ($text);

    # Now output the converted text

    for ($t = 0; $t < $textLen; $t++)
    {
        if (ord($inTextList[$t]) == 10)  # line break
        {
            print br();
        }

        if ($t <= $commit)
        {
            if ($converted{$t})
            {
                print b($outTextList[$t]);
            }
            else
            {
                print "$outTextList[$t]";
            }
        }
        else  # After the commit point so print the unconverted text
        {
            if ($caseFlag)
            {
                print "$inTextList[$t]";
            }
            else
            {
                print lc($inTextList[$t]);
            }
        }
    }

    print p(), "\n";
}

############################################################

sub celsius
{
    my $action = $q->param('send');
    my $intext = $q->param('text');
    my $temp = $q->param('temp');
    my $yyyymmdd = shift(@_);

    print qq(
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
    );
    pooclub_menus();

    print qq(
      </td>
      <td align="left" valign="top" width="450">
    );

    pooclub_banner();
    print qq(<br>);
    poopage_title("Celsius To Centigrade Converter");

    print qq(
        <table border="0" align="left" cellspacing="5" cellpadding="5"><tr>
         <td align="left" valign="top">
          <img src="${IMGPOODIR}/thermometer.jpg" alt="Hot or Not?">
         </td>
         <td align="left" valign="top">
We'd only just nicely got the hang of Centigrade
when they went and changed the temperature scale
again.  Nowadays everything seems to be in
Celsius.
<p>
Now, when we switched from Fahrenheit to Centigrade
we had converters that told you what the temperature
was in old money, and even if you didn't have a
ready reckoner handy you could work it out with a
biro if you could remember that formula with the
5, 9 and 32 in it.
<p>
But there doesn't appear to be any means of converting
between Celsius and Centigrade, which means that those
of us who haven't yet adapted to the new scale are
a bit stuck.
<p>
So, as a service to pooclubbers we have provided
this simple to use Celsius/Centigrade converter.
Just enter the temperature you wish to convert
and choose which way you want to do the conversion
and this useful little application will work it
all out for you.
<p>
And if you find it's a bit too chilly, just type
in a bigger number!
         <p>
    );


    if ($temp)
    {
        print b(qq($temp degrees Celsius = $temp degrees Centigrade.));
    }

    print $q->startform;
    print $q->hidden(-name=>'p',
                     -default=>'celsius');

    print table({-border=>'0', -width=>'400'},
            Tr(
              td({-valign=>"top", -align=>"left", -class=>'smallText', -width=>'200'},
                  radio_group(-name=>'direction',
                      -value=>['Celsius to Centigrade','Centigrade to Celsius'],
                      -default=>'Celsius to Centigrade',
                      -rows=>2
                  )
              ),
              td({-align=>'right', valign=>'top', -width=>'200'},
                  "Degrees:",
                  $q->textfield(
                      -name=>'temp',
                      -default=>'0',
                      -value=>$temp,
                      -size=>6,
                      -maxlength=>12
                  ),p(),
                  $q->submit('send','Convert')
              )
            )
    );
    print $q->endform;

    print qq(
         </td>
        </tr></table>
        <br clear="all">
    );
    show_bookmarks();
    print qq(
      </td>
      <td align="left" valign="top" width="150">
    );

    pooclub_todays_date();

    print qq(
       <br clear="all"><br>
       <font face="arial,times,verdana" size="1" color="brown">
       </font>
      </td>
     </tr>
    </table>
    );
}


############################################################

sub pooclub_chat_categories
{
    my $index_file;

    open (CATS, "${METADIR}/chat_categories.dat");
    while(<CATS>)
    {
        chop;
        next if (/^#/);
        next if (/^\s*$/);
        $index_file = $_;

        open (INDEX, "${METADIR}/$index_file");
        while(<INDEX>)
        {
            chop;
            next if (/^#/);
            next if (/^\s*$/);
            ($flag, $category, $header) = split /;/, $_;
            if ($flag eq "I")
            {
                print qq(
                    <a href="${THIS_CGI}?p=chat&c=$category">$header</a><br>
                );
            }       
        }
        close(INDEX);
    }
    close(CATS);
}

############################################################

sub pooclub_chats
{
    my ($type, $id) = @_;
    my $dataFile    = "$METADIR/${type}.dat";
    my $chatType    = "";
    my $chatHeader  = "Chat Categories";
    my $chatId      = "";
    my $chatTitle   = "";
    my $author;

    # Build table of chats
    my $hash = {};
    my @chatIdList = ();

    open (DATAFILE, "$dataFile");
    while (<DATAFILE>)
    {
        chop;
        next if (/^#/);
        next if (/^\s*$/);
        ($flag, $name, $value, $who) = split /;/, $_;

        if ($flag eq "I")
        {
            $chatType = $name;
            $chatHeader = $value;
            $chatId = $name if ($chatId eq "");
            $author = $who;
        }
        elsif ($flag eq "C")
        {
            $hash->{$name} = $value;
            push @chatIdList, $name;

            if ($id eq $name)
            {
               $chatId = $name;
               $chatTitle = $value;
               $author = $who;
            }
        }
    }
    close (DATAFILE);

    $chatFile = "$DATADIR/$chatType/${chatId}.txt";
    pooclub_header("$chatHeader", "$chatTitle");

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    poopage_title($chatHeader);
    poopage_subtitle($chatTitle);

    print <<EOT;
        <font face="verdana,arial,times" size="2">
EOT

    if (($type eq "") && ($id eq ""))
    {
        pooclub_chat_categories();
        $chatHeader = "";
    }

    my $chatCount = 0;

    open (FD, "$chatFile");
    while (<FD>)
    {
        next if (/^#/);
#        s/\$HOST/$HOST/g;
#        s/\$CGI_BIN/$CGI_BIN/g;
#        s/\$SCRIPT/$SCRIPT/g;
#        s/\$IMGDIR/$IMGDIR/g;
        substitute_vars(\$_);

        s/^/<br>/ if (/^\s+\S/);  # indented lines start a new line
        s/^\s*$/<\/font><p \/><font face="arial,verdana" size="2">/;    # blank lines start a new paragraph

        if (/^:/)   # change of chatter
        {
            s/^://;

            if ($chatCount < 1)  # It's the first chatter
            {                    # so start the chat table
                print <<EOT;
                 <table width="100%" border="0" cellspacing="2" cellpadding="2">
                  <tr><td align="right" valign="top">
                   <font face="times,arial,verdana" size="2">
                    <i>$_</i>
                   </font>
                  </td><td align="left" valign="top">
                   <font face="arial,verdana,times" size="2">
EOT
                $chatCount++;
            }
            elsif (/^:/ || /^\s*$/)  # It's the end of a chat session so
            {                        # close chat table and return to narrative
                print <<EOT;
                 </font></td></tr></table><br clear="all">
                 <font face="verdana,arial,times" size="2">
EOT
                $chatCount = 0;
            }
            else                 # It's a new chatter
            {                    # so start new row
                print <<EOT;
                   </font>
                  </td></tr>
                  <tr><td align="right" valign="top">
                   <font face="times,arial,verdana" size="2">
                    <i>$_</i>
                   </font>
                  </td><td align="left" valign="top">
                   <font face="arial,verdana,times" size="2">
EOT
                $chatCount++;
            }
        }
        elsif (/^\\/) # It's a feature
        {
            if (/^\\img/) # Insert an image
            {
                s/\\img *//;
                ($src, $alt,$align, $width, $caption) = split /;/;
                print qq(
   <table cellspacing="0" align="$align" border="0" width="$width" cellpadding="6">
    <tr><td>
     <div>
      <img hspace="0" vspace="0" border="0" width="175" 
           alt="$alt" 
           src="${IMGPOODIR}/$src" />

      <div class="cap">
       <font face="arial,times" size="2" color="#808000">
        $caption
       </font>
      </div>
     </div>
    </td></tr>
   </table>
                );
            }
        }
        else
        {
            print "$_";
        }
    }
    close (FD);

    if ($chatCount > 0)  # need to close chat table
    {
        print "</font></td></tr></table>\n";
    }

    if ($author) # Author's sig.
    {
        print qq(
          <div align="right">
           <font face="verdana,arial,times" size="2"><i>$author</i></font>
          </div>
        );
    }

    # And now to display the index table

    print <<EOT;
        <br clear="all">
         <a href="$THIS_CGI?p=chat&c=$type">$chatHeader</a>
        <ul>
EOT
    for $i (@chatIdList)
    {
        print <<EOT;
          <li><a href="$THIS_CGI?p=chat&c=$type&i=$i">$hash->{$i}</a>
EOT
    }


    print <<EOT;
       </ul>
EOT

    show_bookmarks();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="150">
EOT

    # Right-hand column
    pooclub_todays_date();

    print <<EOT;
       <br clear=all><br>
      </td>
     </tr>
    </table>
EOT
}

############################################################

sub pooclub_readhtml  # Generate a poopage using an html file
                      # in the poo directory
{
    my $file = shift(@_);
    my $fname = "$POODIR/$file";
    my $metadataFile = "$POO_HTML_FILE";
    my $stupidSite = "";
    my $metaTitle = $file;
    my $metaDesc = "The poopages";
    my $kk_count = 0;
    my $right_knickknack = 0;  # Don't show knickknack in right hand column

    $metaTitle =~ s/^pooclub_//;
    $metaTitle =~ s/.html$//;

    if ($file eq "pooclub_fakeads.html")
    {
        my ($l_sec,$l_min,$l_hour,$l_mday,$l_mon,$l_year,$l_wday,$l_yday,$l_isdst)
            = localtime(time);
        $seed = $l_sec + $l_yday;
        $stupidSite = random_line ("$LISTDIR/stupidsites.list", $seed);
    }

    # Get metadata for html header
    open (META, "$metadataFile");
    while (<META>)
    {
        chop;
        next if (/^#/);
        ($filename, $title, $description) = split /;/, $_;

        if ($filename eq $file)
        {
            $metaTitle = $title;
            $metaDesc = $description;
            last;
        }
    }

    pooclub_header("$metaTitle", "$metaDesc");

    print <<EOT;
    <table border="0" width="750" cellspacing="0" cellpadding="8" align="center"
           style="background-color: white;" />
     <tr>
      <td align="left" valign="top" width="150">
EOT
    pooclub_menus();
    print "<br>";
    show_knickknack();
    print <<EOT;
      </td>
      <td align="left" valign="top" width="450">
EOT

    pooclub_banner();
    print "<p>";

    my $sub;
    my $func;
    my $args;
    my @arglist;

    open (FD, "$fname");
    while (<FD>)
    {
#        s/\$HOST/$HOST/g;
#        s/\$CGI_BIN/$CGI_BIN/g;
#        s/\$SCRIPT/$SCRIPT/g;
#        s/\$IMGDIR/$IMGDIR/g;
        substitute_vars(\$_);

        s/\$STUPID_SITE/$stupidSite/g if ($stupidSite ne "");

        if (/^\\knickknack/)
        {
            show_knickknack(++$kk_count);
        }
        elsif (/^\\right_knickknack/)
        {
            ++$right_knickknack;  # Show knickknack in right hand column
        }
        elsif (/^\\topic_dates/)
        {
            show_topic_dates();
        }
        elsif (/^\\sub\s+/) # call subroutine name
        {
            chop;
            @arglist = ();
            ($sub, $args) = split /\(/, $_;
            $sub =~ s/\s+/ /g;
            ($spare, $func) = split/ /, $sub;
            $func =~ s/ //g;
            $args =~ s/\).*$//;

            for $arg (split /,/, $args)
            {
                $arg =~ s/^\s+//;
                $arg =~ s/\s+$//;
                push @arglist, $arg;
            }
            $func->(@arglist);
        }
        else
        {
            print "$_";
        }
    }
    close (FD);

#    if ($file eq "pooclub_luckyday.html")
#    {
#        list_luckydays(); # display list of forthcoming Tuesday 22nd's
#    }
#    elsif ($file eq "pooclub_faq.html")  # Alternative endings to the FAQ file
#    {
#        if (random_seed() % 2 == 0)
#        {
#            print <<EOT;
#              <font face="times,verdana,arial" size="5" color="black"><i>
#               Can I go now?
#              </i></font><p>
#              <font face="verdana,arial,times" size="2" color="black">
#               Yes.  Thank you for showing interest in our organisation.
#               You may get on with your life now.
#              </font><p>
#EOT
#        }
#        else
#        {
#            print <<EOT;
#              <font face="times,verdana,arial" size="5" color="black"><i>
#               Where do you get all your ideas from?
#              </i></font><p>
#              <font face="verdana,arial,times" size="2" color="black">
#               Right.  That's it.
#               You can fuck right off now.
#              </font><p>
#EOT
#        }
#    }

    show_bookmarks();

    print <<EOT;
      </td>
      <td align="left" valign="top" width="150">
EOT

    # Right-hand column
    $fname =~ s/\.html$/_right\.html/;
    pooclub_todays_date();
    print "<br clear=all><br>\n";

    open (FD, "$fname");
    while (<FD>)
    {
#        s/\$HOST/$HOST/g;
#        s/\$CGI_BIN/$CGI_BIN/g;
#        s/\$SCRIPT/$SCRIPT/g;
#        s/\$IMGDIR/$IMGDIR/g;
        substitute_vars(\$_);
        print "$_";
    }
    close (FD);

    if ($right_knickknack > 0)
    {
        show_knickknack(++$kk_count);
    }

    print <<EOT;
      </td>
     </tr>
    </table>
EOT
}


############################################################

1;

############################################################
# END OF FILE
############################################################
