Chapter 13: Sending Automatic E-mail Reports

Overview

Although a Web-based reporting interface can be a helpful tool, an e-mail-based system is much more so. E-mail can be downloaded and moved off-line; it may be archived more readily than a Web page, and it may serve as the basis for reports to be sent to others who do not necessarily have administrative access to the system.

Perl is very well-suited to the construction of this type of report. This chapter demonstrates some of the flexibility Perl offers in this regard—from simple text-based notes to complex reports incorporating graphics.

The examples in this chapter deal with the reporting of user sessions. The relevant tables are the session table, which can be created as follows:

CREATE TABLE session (   user_id integer unsigned,   first_used datetime,   last_used datetime,   valid tinyint unsigned,   ip varchar(20) );

and the user table:

CREATE TABLE user (   id integer unsigned primary key auto_increment,   username varchar(20) ); 

Obviously, in a real-world application, the tables would contain other fields (a password for the user table and an authentication token for the session table), but those are not relevant here. The operation of this session system is simple: when a user logs on, he or she is presented by a randomly generated authentication token (which might be stored in a cookie or encoded in the URL of the page), which is valid for the current session. This creates a new entry in the session table, setting user_id, first_used, valid, and ip. Each page the user accesses updates the last_used field. When the user logs out, or attempts to access a page after the session has expired due to inactivity, valid is set to 0 to indicate that the session is no longer active.



Perl Database Programming
Perl Database Programming
ISBN: 0764549561
EAN: 2147483647
Year: 2001
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net