logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: event calendar code: msg#00035

lang.perl.modules.html-template

Subject: Re: event calendar code

Kapoor, Nishikant wrote:

Sorry if this post is off-topic but I have a feeling people in this list would
have definitely come across it.

I am looking to generate an event calendar using H::T. Can anyone help me with
some pointers? code snippets?

I did search the archives but could not find much info.

Thanks,
Nishi


here is a fragment of some code I wrote a long time ago. It has some dependencies unique to my situation, and is crufty and inelegant, but it should give you a place to start. I was using SQLite to store the events, grabbing the data from the database, and passing the recordset to different routines to create the monthly, yearly, daily or weekly views. Here is the monthly view. The getappts() gets the data from the database, and getappt() converts it to viewable code (I know, I know, I already said it is crufty and inelegant, but it works) --

sub month {
my @cal = ();

my $start = my $firstOfMonth = timelocal(0, 0, 0, 1, $mon, $year);
my $end = my $lastOfMonth = timelocal(59, 59, 23, $daysInMonth, $mon, $year);
my $appts_ref = &getappts($start, $end);

my @firstOfMonth = localtime($firstOfMonth);
my $wdayOfFirstOfMonth = $firstOfMonth[6];
my $date = 1;

# first week
my %week;
#my $thisweek = $week;
my $thisweek = int(($firstOfMonth[7] + 1) / 7) + 1;
$week{'week'} = $thisweek;
$week{'weekcd'} = timelocal(0, 0, 0, $date, $mon, $year);

my @week;
for (1..7) {
my %day;
my @appointments;
if ($_ <= $wdayOfFirstOfMonth) {
$day{'day'} = '';
$day{'daycd'} = '';
$day{'appointments'} = \@appointments;
} else {
$day{'day'} = ($date == $today) ? "<div id='today'>" . $date . '</div>' : $date;
$day{'daycd'} = timelocal(0, 0, 0, $date, $mon, $year);
$day{'appointments'} = &getappt($mon, $date, $hour, 'month', $appts_ref);
$date++;
}
push(@week, \%day);
}
$week{'days'} = \@week;
push(@cal, \%week);
# end first week

# rest of the weeks
while ($date <= $daysInMonth) {
my %week;
$thisweek++;
$week{'week'} = $thisweek;
$week{'weekcd'} = timelocal(0, 0, 0, $date, $mon, $year);

my @week;
for (1..7) {
my %day;
my @appointments;
if ($date <= $daysInMonth) {
$day{'day'} = ($date == $today) ? "<div id='today'>" . $date . '</div>' : $date;
$day{'daycd'} = timelocal(0, 0, 0, $date, $mon, $year);
$day{'appointments'} = &getappt($mon, $date, $hour, 'month', $appts_ref);
} else {
$day{'day'} = '';
$day{'daycd'} = '';
$day{'appointments'} = \@appointments;
}
$date++;
push(@week, \%day);
}
$week{'days'} = \@week;
push(@cal, \%week);
}
return \@cal;
}

sub getappts {
my ($start, $end) = @_;
my $dbh = &connecttoDB();
my $sql = "SELECT event_id, start, end, title FROM events WHERE start BETWEEN $start AND $end ORDER BY start";
my $sth = $dbh->prepare(qq{$sql});
$sth->execute;
return my $tbl_ary_ref = $sth->fetchall_arrayref({});
}

sub getappt {
my ($m, $d, $h, $doh, $ary_ref) = @_;
my @inres = @$ary_ref;
my @outres;
foreach (@inres) {
my %row = %$_;
my ($ssec, $smin, $shour, $smday, $smon, $syear, $swday, $syday, $sisdst) = localtime($row{'start'});

if ($doh eq 'day') {
if ($shour == $h) {
$row{'start'} = &timetobase12($shour, $smin);
my ($esec, $emin, $ehour, $emday, $emon, $eyear, $ewday, $eyday, $eisdst) = localtime($row{'end'});
$row{'end'} = &timetobase12($ehour, $emin);
push(@outres, \%row) ;
}
} elsif ($doh eq 'week') {
if ($smday == $d and $shour == $h) {
$row{'start'} = &timetobase12($shour, $smin);
my ($esec, $emin, $ehour, $emday, $emon, $eyear, $ewday, $eyday, $eisdst) = localtime($row{'end'});
$row{'end'} = &timetobase12($ehour, $emin);
push(@outres, \%row) ;
}
} elsif ($doh eq 'month') {
if ($smday == $d) {
$row{'start'} = &timetobase12($shour, $smin);
my ($esec, $emin, $ehour, $emday, $emon, $eyear, $ewday, $eyday, $eisdst) = localtime($row{'end'});
$row{'end'} = &timetobase12($ehour, $emin);
push(@outres, \%row) ;
}
} elsif ($doh eq 'year') {
if ($smon == $m and $smday == $d) {
$row{'start'} = &timetobase12($shour, $smin);
my ($esec, $emin, $ehour, $emday, $emon, $eyear, $ewday, $eyday, $eisdst) = localtime($row{'end'});
$row{'end'} = &timetobase12($ehour, $emin);
push(@outres, \%row) ;
}
}
}
return \@outres;
}

$template->param(
prev => $prev,
next => $next,
currentlink => $currentlink,
currentdesc => $currentdesc,
view => $view,
monthwidget => &monthwidget,
daywidget => &daywidget,
yearwidget => &yearwidget,
cal => &month(),
selecteddayvalue => $mday,
selecteddaydisplay => $mday,
selectedmonthvalue => $mon,
selectedmonthdisplay => $months[$mon],
selectedyearvalue => $year,
selectedyeardisplay => $year
);

=========

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Month</title>
<link rel="stylesheet" TYPE="text/css" href="../perlpim.css">
</head>
<body>

<tmpl_include navbar.html>
<table border="1" width="600" cellpadding="2" cellspacing="1" bgcolor="black">
<tr bgcolor="silver"><td colspan="8"><tmpl_var currentdesc></td></tr>
<tr bgcolor="#ccffff">
<td width="40" bgcolor="#cccc99">Week</td>
<td width="80" bgcolor="silver">Sun</td>
<td width="80">Mon</td>
<td width="80">Tue</td>
<td width="80">Wed</td>
<td width="80">Thu</td>
<td width="80">Fri</td>
<td width="80" bgcolor="silver">Sat</td>
</tr>

<!-- start month loop -->
<tmpl_loop cal>
<tr bgcolor="white" valign="top">
<td bgcolor="#cccc99" height="70">
<a href="index.cgi?view=week&cd=<tmpl_var weekcd>"><tmpl_var week></a></td>


<tmpl_loop days>
<td <tmpl_if __first__>bgcolor="silver"</tmpl_if><tmpl_if __last__>bgcolor="silver"</tmpl_if><tmpl_unless day>bgcolor="silver"</tmpl_unless>>
<tmpl_if day>
<a href="index.cgi?view=day&cd=<tmpl_var daycd>" title="Day view"><tmpl_var day></a><br>
</tmpl_if>

<tmpl_loop appointments>
<tmpl_if start>
<tmpl_var start> - <tmpl_var end>:
<a href="index.cgi?event_id=<tmpl_var event_id>" title="Details on this event">
<tmpl_var title></a><br>
</tmpl_if>
</tmpl_loop>

</td>
</tmpl_loop>

</tr>
</tmpl_loop>
<!-- end month loop -->

</table>

</body>
</html>


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
krysalis.sandbo...    web.zope.zwiki/...    gnome.apps.gnum...    xfree86.newbie/...    editors.vim/200...    mozilla.enigmai...    boot-loaders.gr...    network.vnc.ult...    redhat.release....    java.geronimo.u...    os.netbsd.devel...    horde.wicked/20...    linux.lsb.discu...    ietf.ips/2005-0...    alsa.devel/2002...    user-groups.lin...    package-managem...    debian.devel.da...    security.cyrus....    video.gstreamer...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation