#!/usr/local/bin/perl # # Copyright 1999 InfoDesign Communications - All rights reserved. # # Site: The Lutheran World Federation (lutheranworld.org) # Component: Publishing # # Class: main # Version: $Revision: 1.5 $ ($Date: 2002/01/22 07:30:00 $) by $Author: jp $ # Usage: # # Comments: # PATHINFO format : /Language/Section/Slice ################################################################# package main; ################################################################# # Do not remove this line -- IDClassPath use lib qw( e:/inetpub/lwf_mainsite/scripts/classes e:/inetpub/lwf_mainsite/scripts/classes/Foundation e:/inetpub/lwf_mainsite/scripts/classes/File e:/inetpub/lwf_mainsite/scripts/classes/Web); # Perl libraries use Carp; use strict 'vars'; use vars qw( $VERSION ); # InfoDesign libraries require IDPublisher; require IDPublisherFactoryFlatSQL; require IDPublisherFactoryODBC; require IDHTTPPage; require IDPropertyList; require IDConfig; require IDCGI; require IDDate; $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/); # Instanciate CGI adapter my $cgi = IDCGI->New; # Read configuration my $config = IDPropertyList->NewFromFile(' e:/inetpub/lwf_mainsite/scripts/Data/Publisher/PublisherConfig.plist'); croak '[error] '.IDPropertyList->_Error if not $config or $config->_Error; my $templatesDir = $config->plist->{'TemplatesDirectory'}; # Site config file my $genLocations = IDConfig->New(' e:/inetpub/lwf_mainsite/scripts/lwf.cfg'); $genLocations->load or croak '[error] Cannot load lwf.cfg file '; my $publishAction = $genLocations->publisherBrowserAction; # Turn Path info into classical CGI parameters (easiest way to # access path info value) my $pathInfoFields = ['Language', 'Section', 'Slice']; $cgi->pathInfoToParameters($pathInfoFields); # Prepare page contents which are common to all templates my $pageContents = {}; $pageContents->{'PublishAction'} = $publishAction; $pageContents->{'BaseURL'} = $genLocations->baseURL; $pageContents->{'ActionSearch'} = $genLocations->searchAction; $pageContents->{'ConditionError'} = 0; $pageContents->{'ConditionEmpty'} = 0; # If the page is not accessed for the first time, retrieve CGI parameters my $docType = $cgi->param('Section'); my $language = $cgi->param('Language'); #include here database query to retrieve first and last year my @years = ( {'Year' => 2010}, {'Year' => 2009}, {'Year' => 2008}, {'Year' => 2007}, {'Year' => 2006}, {'Year' => 2005}, {'Year' => 2004}, {'Year' => 2003}, {'Year' => 2002}, {'Year' => 2001}, {'Year' => 2000}, {'Year' => 1999}); my $currentYear = $cgi->param('CurrentYear'); my $isMostRecent = $cgi->param('MostRecentArticles'); unless ($docType) { $docType = 'LWI'; $cgi->param('Section', 'LWI'); } unless ($language) { $language = 'EN'; $cgi->param('Language', 'EN'); } unless ($currentYear) { $currentYear = '2010'; $cgi->param('CurrentYear', $currentYear); } # determine current year foreach my $index (@years) { if ($index->{'Year'} == $currentYear) { $index->{'ConditionYearCurrent'} = 1; } else { $index->{'ConditionYearCurrent'} = 0; } } $pageContents->{'Language'} = $language; my $currentSlice = $cgi->param('Slice'); unless ($currentSlice) { # January selected by default unless this is current year if ($isMostRecent) { $currentSlice = 12; } else { if ($currentYear eq $years[0]->{'Year'}) { $currentSlice = 0; } else { $currentSlice = 0; } } $cgi->param('Slice', $currentSlice); } my $section = $cgi->param('Section'); unless ($section) { $section = $config->plist->{'DefaultFlow'}; $cgi->param('Slice', $section); } $pageContents->{'Section'} = $section; # Create the publisher, according to the database to be used. ## For testing purpose #$IDPublisher::DefaultSliceLimit = 16; #$IDPublisher::DefaultSliceBalance = 0.5; my $publisher; if ($config->plist->{'Database'} =~ /FlatSQL/i ) { # Read FlatSQL specific configuration my $configFSQL = IDPropertyList->NewFromFile(join('/',$config->plist->{'ResourcesPath'} , 'Publisher' ,'PublisherConfigFlatSQL.plist')); croak '[error] '.IDPropertyList->_Error if not $configFSQL or $configFSQL->_Error; $publisher = IDPublisher->New($section, $language, IDPublisherFactoryFlatSQL->New($configFSQL), $config ); } elsif ($config->plist->{'Database'} =~ /ODBC/i ) { # Read FlatSQL specific configuration my $configFSQL = IDPropertyList->NewFromFile(join('/',$config->plist->{'ResourcesPath'}, 'Publisher' , 'PublisherConfigODBC.plist')); croak '[error] '.IDPropertyList->_Error if not $configFSQL or $configFSQL->_Error; $publisher = IDPublisher->New($docType, $language, IDPublisherFactoryODBC->New($configFSQL), $config ); } #print "Current Year : $currentYear\n"; my $slices = $publisher->slicesOfArticles($currentYear); my $articles; if ($isMostRecent) { $articles = $publisher->mostRecentArticles($config->plist->{'NbOfArticlesOnDisplay'}); } else { $articles = $publisher->articlesForSlice($currentSlice); } if ($articles) { my $articlesRepetition = $articles->asArrayOfDictionaries; # Slices additions for repetition in template foreach my $index (0..$#{$slices}) { my $startDate = IDDate->New('', $slices->[$index]->{'SliceStartDate'}, '%Y%m%d'); $slices->[$index]->{'SliceStartMonth'} = $startDate->toString(substr($language,0,1), '%b'); if ($slices->[$index]->{'SliceEndDate'} ne $slices->[$index]->{'SliceStartDate'} ) { my $endDate = IDDate->New('', $slices->[$index]->{'SliceEndDate'}, '%Y%m%d'); $slices->[$index]->{'SliceEndDate'} = $endDate->toString(substr($language,0,1), '%d %b %y'); } else { $slices->[$index]->{'SliceEndDate'} = undef; } $slices->[$index]->{'SliceStartDate'} = $startDate->toString(substr($language,0,1), '%d %b %y'); $slices->[$index]->{'ConditionCurrent'} = ($index == $currentSlice); $slices->[$index]->{'SliceNumber'} = $index; } # Articles modifications for display foreach my $index (0 .. $#{$articlesRepetition}) { my $date = IDDate->New('', $articlesRepetition->[$index]->{'LWIDate'}, '%Y%m%d'); $articlesRepetition->[$index]->{'LWIDate'} = $date->toString(substr($language,0,1), '%d %b %y'); $articlesRepetition->[$index]->{'ArticleURL'} = $publisher->URLForArticle($articles->objectAtIndex($index)); } $pageContents->{'ListYears'} = \@years; $pageContents->{'ListSlices'} = $slices; $pageContents->{'ListArticles'} = $articlesRepetition; } else { if ($publisher->_Error =~ /no slices found/) { $pageContents->{'ConditionEmpty'} = 1; } else { $pageContents->{'ConditionError'} = 1; $pageContents->{'Error'} = $publisher->_Error; } } my $page = IDHTTPPage->New('html', '', $cgi, $templatesDir."/BrowserWelcome.$language.htmlt", 1); $page->send($pageContents); exit 0;