Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Creating reports with HTML::Template and CGI::Application

by bar10der (Beadle)
on Mar 03, 2004 at 14:55 UTC ( #333548=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks

I am new to perl and just recently started working on a tool using Html Template & CGI Application. One of my requirements is extracting rows of data from Oracle table and display it in columns! Let me give an example of data-

Name Date From Date To Work Days RP 01/03/2004 02/03/2004 2 RP 16/03/2004 17/03/2004 2 RP 08/04/2004 13/04/2004 2 GC 18/03/2004 25/03/2004 6 GC 08/04/2004 13/04/2004 2 GC 08/03/2004 09/03/2004 2 ---- ---- ---

When user clicks on 'View Holiday Plan' Link, above details should be extracted, monthly total for each user is derived and displayed in following format-

Name Months Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec RP 4 2 1 10 GC 8 2 XX 2 3 1

Further when user clicks on a month name and if there are holidays booked in that month, it should display calander of the month with holiday dates highlighted. Each holiday dates are stored in a saperate table.

Any help/guidance will be greatly appreciated. Please remember I am cutting my teeth in CA & HT so some examples will really help me.


jdporter - retitled

Replies are listed 'Best First'.
Re: Can I do this???
by matija (Priest) on Mar 03, 2004 at 15:42 UTC
    I assume you can handle your own extraction of the data from the database, and are only looking for guidance on using HTML::Template for this kind of stuff.

    To answer your second question first, have someone who is a good HTML designer design a calendar page for you in HTML. It will have rows and columns.

    Now alter the design by reducing all the rows to one, but put that inside a TMPL_LOOP:

    <table> <TMPL_LOOP name="calendar"> <tr> <td><TMPL_VAR name="sideheader"></td> <td <TMPL_IF name="holiday_1">bgcolor="mauve" </TMPL_IF>> <TMPL_VAR name="day_1"> </td> <td <TMPL_IF name="holiday_2">bgcolor="mauve" </TMPL_IF>> <TMPL_VAR name="day_2"> </td> <!-- ETC for the rest of the row --> </tr> </TMPL_LOOP> </table>
    And then simply assign appropriate values to the positions in each row such that the days of the month align properly with days of the week (leaving empty spaces at the start or at the end, as appropriate).

    Come to think of it, the same method would work for the first table - in fact there it's easy to see that it's months going along the row, so you can give your columns more intuitive names.

    One last thing. When making links, I prefer to use a cleaned up self_url from, and have <TMPL_VAR>s in the HTML. That way, the script and template will work, even if they are moved into another directory, or to another server.

      Thanks Matija,

      Looks like you have shown me some light..though I have made a slight change in design, to me extracting data in the format I have mentioned for 1st screen will be bit difficult...any thoughts/suggestions are welcomed.

      So instead of displaying plan for entire year, I decided to display current month with next and prev month buttons at top. This will be much easier to implement. Then using the tmpl_loop, as suggested above I will have to create a monthly calander with each holiday dates highlighted against all names. Any suggestions?

Re: Creating reports with HTML::Template and CGI::Application
by Abigail-II (Bishop) on Mar 03, 2004 at 15:05 UTC
    Any help/guidance will be greatly appreciated.
    Drink lots of fluids.

    I'm not sure what kind of answer you expect. Except being new to perl, you give no indication of what you know, what modules you are familiar with, what environments you use. Nor do you give any indication what you've done so far. Any answer given can be way over the top of your head, to trivial for you to be useful, to general or to specific, or something you've already done. None of such answers is useful to you, and it would just waste peoples time.


      'I am new to perl' explains that I do not have much experiance but that does not mean I do not have capabilities to learn.
Re: Creating reports with HTML::Template and CGI::Application
by dragonchild (Archbishop) on Mar 03, 2004 at 18:45 UTC
    When dealing with HTML::Template, Template toolkit, or other such templating modules, you must separate what you're doing into two (mostly) unrelated things - the data structure you generate and the template that accepts that data structure.

    I would recommend doing the following:

    1. Examine what you're doing and figure out what items/groups of items are similar. Those are candidates for looping.
    2. Figure out what items/groups of items can change between invocations of your page. (Things like date, username, colors, etc.)
    3. Create a data structure that encapsulates how the programmer thinks of the output.
    4. Then, and only then, create a template that will take that data structure and display it appropriately.

    If you follow that method, you're aren't tied to a given templating module. :-)

    Now, C::A has nothing to do with H::T. Yeah, it uses it by default (and most C::A users also use H::T), but they are solving two completely unrelated problems. (I use H::T to templatize Apache config files that never see the WWW.) C::A is meant to simplify how pages in your application relate to each other. It sounds like you're understanding that (for the most part), but you're having issues with H::T and how to build with/for it.

    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://333548]
Approved by arden
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2021-09-22 21:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found