Assigning Reports to Analysts

I’ve said that the responsibility for a record in the ProductAnalysis docbase is shared between a manager who assigns a report and an analyst who writes it. Let’s explore how that can work. It makes sense to bring email into the loop, because the act of making an assignment is best expressed in a push medium. When you assign a report to me, you don’t want to wait for me to check the work schedule posted somewhere on the intranet; you want to notify me right away. That notification, expressed as a URL, can link me straight to a partly completed report form, as shown in Figure 6.2.

A plain ASCII message, as shown in Example 6.12, can transmit the URL that links to that form.

Example 6-12. Plain-text Message Assigning a Report to an Analyst

To: [email protected]
From: [email protected]
Subject: Collabra Server report due 1999-05-01

<http://udell.roninhouse.com/cgi-bin/Docbase/formgen.pl?
     app=ProductAnalysis&duedate=1999-05-01&analyst=Jon%20Udell&
     company=Netscape&product=Collabra%20Server%204.0>

Jon, I think the new groupware server is called
Collabra Server 4.0. Could you please verify
that and fill in the correct name on the report?

Here we’re relying on the ability of the recipient’s mailreader to autoactivate the URL—that is, render it as a clickable link. We’re also assuming that the recipient is, or can be, connected to the server that generates the form.

Do I really expect the research manager to compose a message like this? No. It’s better if she can use a simple application to help compose that message. Ideally, that application presents a dynamically generated form that manages controlled vocabularies. The form should list analysts, companies, and products and offer ways to extend those lists. In Chapter 15, we’ll explore ways to connect this kind of form to a conventional database, using namespace completion to scope database queries and limit the number of items included in the generated HTML <select> statements. Here let’s just assume a mechanism that enables the research manager to produce the form shown in Figure 6.4.

The manager’s report-assignment form

Figure 6-4. The manager’s report-assignment form

The handler for this form will interpolate values into a message template in order to construct the assignment message shown in Example 6.12, then transmit that email message. How? It could launch a command-line mailer—sendmail or an equivalent such as Software.com’s postmail. Or it could use a Perl module, such as Net::SMTP.

The URL contained in the message shown in Example 6.12 can get pretty long and complex. From the recipient’s point of view it looks awkward, and if it gets broken in transit into two or more lines, autoactivation will fail. As we saw in Chapter 4, it’s helpful to wrap angle brackets around URLs that you want mailreaders or newsreaders to make clickable. Better yet, you can send an HTML-formatted message that wraps the URL in a descriptive label: “Click here to submit your report.”

Let’s recap the whole scenario. To assign a report, the research manager clicks a link, which invokes a Web script, which—using database-integration techniques I’ll demonstrate in Chapter 15—generates the form shown in Figure 6.4. She specifies a duedate, an analyst, and a company but leaves the product field open. In the comments field, she describes the product to be assessed and asks the analyst to supply the correct product name when filing the report. The handler for this form interpolates form variables into a template to produce an assignment message.

The analyst, on receiving the message, moves it to a Reports Due folder for use on the due date. On that date, he clicks the URL to produce the form that will collect the completed report. Because the product field is not preassigned in this case, it appears as an open input field on the form rather than as a static value.

If it seems as if templates and form generators are multiplying like rabbits, well, they are. These things, connected in series, create the Web equivalent of the Unix pipeline—a flexible way to assemble simple parts into custom applications. Example 6.13 shows a script that handles the form shown in Figure 6.4, processes it using a template (which is included with the script, following the __DATA__ directive), and sends an HTML email message containing a link that, when clicked, will produce the form used to collect the assignment.

Example 6-13. Handler for the Manager’s Report-Assignment Form

use TinyCGI;                 
my $tc = TinyCGI->new;
my $vars = $tc->readParse();        # get form variables
print $tc->printHeader;             # emit HTTP header

use Group::SimpleGroup;             # load directory module (see Chapter 11)

my $g =                             # access analyst group
    Group::SimpleGroup->new('analysts','analysts'), 

                                    # look up email addresses 

my $analyst_email    = $g->getProperty($vars->{analyst},'email'), 
my $manager_email    = $g->getProperty($vars->{manager},'email'),

use Net::SMTP;                      # load SMTP module

my $smtp =                          # connect to mail server
    Net::SMTP->new('udell.roninhouse.com'), 

if (! defined $smtp)
  {
  print "cannot connect to mail server";
  return;
  }

$smtp->mail($analyst_email);        # address the message
$smtp->to($analyst_email);
$smtp->data();

while (<DATA>)                      # read assignment-form template
  {
  s/ANALYST_EMAIL/$analyst_email/;  # swap in analyst's email address
  s/MANAGER_EMAIL/$manager_email/;  # swap in manager's email address
  s/%(w+)%/$vars->{$1}/g;          # swap %markers% for matching CGI vars
  $smtp->datasend($_);              # send the line
  }

$smtp->dataend();
$smtp->quit();

print "OK, assignment sent";


__DATA__
To: %analyst% <ANALYST_EMAIL>
From: %manager% <MANAGER_EMAIL>
Subject: Report on %company% (%product%) due on 
%year%-%month%-%day%
Content-type: text/html
Content-transfer-encoding: 7bit

<html><body>
<p>Your report on Company: %company%, Product: %product% is due on
%year%-%month%-%day%.

<p>Click <a href="http://udell.roninhouse.com/cgi-bin/Docbase/form-gen.pl?
app=ProductAnalysis&duedate=%year%-%month%-%day%&analyst=%analyst%&company=%company%
&product=%product%">here</a> for the report submission form.

<p>Comments: %comments%
</body></html>

This script uses two Perl modules that we haven’t seen yet. Group::SimpleGroup looks up email addresses in a simple directory. It’s one of a family of three directory modules that we’ll build in Chapter 11. This one stores names and addresses in a Perl hashtable that’s externalized as an ASCII file. Another works with LDAP directories, and a third with the NT accounts database.

The other new module is Net::SMTP. As Example 6.13 shows, it makes quick work of connecting to a mail server and sending a message.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.149