OfficeLinebacker has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, esteemed monks!

In my organization it's common for there to be a whiteboard in the hall near a workgroup that lists each person's name and whether they are in or out that day. One other group developed a web page for the same thing, only each member is responsible for editing it to reflect exactly where they are at any given time (like "lunch" or "errand"). My boss wanted the same thing, only really just to report exceptional circumstances.

So anyway the gist of it is that there's an HTML page with a table in it, with a link to the edit script at the bottom of the page. The edit script displays a drop down list of workgroup members and a large text box for the note. Works fine, except that when I wrote it I decided I was going to use XML as the underlying data as a learning experience. Talk about a cannon to swat a fly. Anyway the order of the entries is important, and I thought I got the order tied, but then someone left our group and we hired a new guy. So when I edited the xml, the order got shifted and I can't get it back. So anyway, if you were going to start from scratch to write an application like this, how would you keep track of the underlying data? Having gained some experience since I first wrote the thing, I am thinking just a CSV with two columns would suffice.

I'll put code in a reply to this node so it doesn't take up lots of space if it shows up on a front page.

_________________________________________________________________________________

I like computer programming because it's like Legos for the mind.

Replies are listed 'Best First'.
Re: An Office In/Out Whiteboard Web Page
by Fletch (Bishop) on Jun 15, 2006 at 17:33 UTC

    Use a database, that's what they're for. It'll hide the locking and concurrency issues for you (most likely :) and you don't have to worry about the details of how your data's stored. If you don't want to go whole hog for something like My or Postgres there's sqlite. You can even use DBD::File to work with your CSV during development and then switch to something else for production (or just go with sqlite to start with and be done with it).

      You're right, why dodge the inevitable? Pretty sure the other whiteboard uses Postgres. I was just too busy or lazy to implement that (I had some experience with XML already).

      For now, I figured out that the hash gets sorted by the length of the key (the new guy has a really short name), so I hacked something to make it work for now.

      Thanks,

      T.

      _________________________________________________________________________________

      I like computer programming because it's like Legos for the mind.

Re: An Office In/Out Whiteboard Web Page
by OfficeLinebacker (Chaplain) on Jun 15, 2006 at 17:43 UTC
    Here's the code--I edited out information that isn't relevant so don't expect it to work:
    BEGIN { use CGI ':all'; use XML::Simple; use XML::LibXML; use Data::Dumper; use File::Copy; use Tie::IxHash; my $htmlfile = "whiteboard.html"; my $xmlfile = "whiteboard.xml"; tie %$xml, "Tie::IxHash", %{XMLin($xmlfile, SuppressEmpty => undef +, )}; #no forcearray needed here because we know the elements don't doub +le. if ( (!(param("Apply Edit"))) && (!(param("Cancel"))) ) #so if the page is a first load, or a change in selection, or the +"Clear" button was pressed { print header(); print start_html( -title => "Edit Whiteboard", -bgcolor => 'pu +rple' ) ; print font( { -color => 'yellow' } ), h1("Whiteboard Editor"); print h5("Type <br&gt to create a new line in the webpage displ +ay."); print start_form(); @keys = keys( %{ $xml->{name} } ); print popup_menu( -name => 'selname', -values => \@keys, -align => 'top', -onChange => "submit();" ); if ( param('selname') ) { if ( param("Clear") ) { param( 'thenote', "" ); } else { param( 'thenote', "" ); #we need this to clear the not +e if it's already blank, otherwise the #text from the defined note will persist param( 'thenote', $xml->{name}->{ param('selname') }-> +{note} ); } print textarea( -name => 'thenote', -rows => 10, -columns +=> 55 ); } else { param( 'thenote', $xml->{name}->{ $keys[0] }->{note} ); print textarea( -name => 'thenote', -rows => 10, -columns +=> 55 ); } print br(), br(), submit("Apply Edit"), "\t ", submit("Cancel" +), "\t ", submit("Clear"); print end_form(); my $mtime = localtime( ( stat "edit.pl" )[9] ); print hr(), font( { -size => '-1' }, "Modified $mtime", br(), "Created and maintained by Terry Tate, Office Lineba +cker" ); print end_html(); } #end if !param else { #this is a repost
    The thing with keeping track with a counter in the table creation is because there is also a "General Note" that should come first and get different formatting than entries from individual people.

    _________________________________________________________________________________

    I like computer programming because it's like Legos for the mind.

Re: An Office In/Out Whiteboard Web Page
by planetscape (Chancellor) on Jun 16, 2006 at 00:55 UTC

    Instead of splitting code and explanatory text across multiple writeups, I suggest you try using readmore tags. (Unless, of course, you plan on crossing the 64K boundary...)

    HTH,

    planetscape
      Hey, do readmore tags work within a <code> block? I can't seem to just show the first portion of my code.

      _________________________________________________________________________________

      I like computer programming because it's like Legos for the mind.

        "Proper nesting works wonders" (Copyright, 2006)
        and PNWW (TM, 2006) are registered by ww. Infringement will result in litigation or maybe just boredom.

        Try this sequence:

        narrative exposition...
        blah, blah, blah....


        <c>
        code starts here...
        002: ...
        003: ...
        </c>
        code tag has been closed
        <readmore>
        <c>
        code tag reopened
        more code... hidden inside the readmore...
        </c>
        </readmore>

        code and readmore closed; blah, blah, blah is again visible