--- trunk/Portal.pm 2004/03/07 18:22:26 1 +++ trunk/Portal.pm 2004/03/07 18:48:13 3 @@ -5,6 +5,7 @@ use Config::IniFiles; use DBI; +use Carp; use Data::Dumper; @@ -13,7 +14,7 @@ my $dsn = 'Pg:dbname=libdata'; my ($user,$passwd) = ('dpavlin',''); -my @persistent_vars = qw(p); +my @persistent_vars = qw(p ms); # read global.conf configuration my $cfg_global = new Config::IniFiles( -file => '../global.conf' ) || die "can't open 'global.conf'"; @@ -35,7 +36,7 @@ 'home' => 'show_home', 'ms' => 'show_ms', 'it' => 'show_home', - 's' => 'show_home', + 's' => 'show_s', ); $self->start_mode('home'); $self->mode_param('p'); @@ -44,6 +45,7 @@ } +# home page sub show_home { my $self = shift; @@ -64,6 +66,8 @@ } + +# MasterSubject sub show_ms { my $self = shift; @@ -76,7 +80,7 @@ my $ms = $self->get_mastersubjects_by_id($q->param('ms')); $tmpl->param('title' => uc($ms->{'mastersubject'}) ); - $tmpl->param('mastersubject_lc' => lc($ms->{'mastersubject'}) ); + $tmpl->param('search_field' => lc($ms->{'mastersubject'}) ); $tmpl->param('InfoTypes' => $self->get_infotypes() ); @@ -86,7 +90,32 @@ } + +# Subject +sub show_s { + my $self = shift; + + my $q = $self->query(); + + my $tmpl = $self->use_template('s.html'); + + $tmpl->param('MasterSubjects' => $self->get_mastersubjects() ); + + my $s = $self->get_subjects_by_id($q->param('s')); + + $tmpl->param('title' => uc($s->{'subject'}) ); + $tmpl->param('search_field' => lc($s->{'subject'}) ); + + $tmpl->param('InfoTypes' => $self->get_infotypes() ); + + return $tmpl->output; + +} + + +# # load template and generate permanent valirables in template +# sub use_template { my $self = shift; @@ -105,8 +134,12 @@ return $tmpl; } + +# # get data from database +# +# get all MasterSubjects sub get_mastersubjects { my $self = shift; @@ -125,6 +158,7 @@ return $sth->fetchall_arrayref({}); } +# get one MasterSubject by it's ID sub get_mastersubjects_by_id { my $self = shift; @@ -142,6 +176,7 @@ return $sth->fetchrow_hashref(); } +# get all InfoTypes sub get_infotypes { my $self = shift; @@ -156,7 +191,15 @@ where res_sub_infotype.infotype_id=infotype.infotype_id and infotype.infotype_id > 1 }; - if ($q->param('ms')) { + + # first check if subject is defined and limit by that, and only if it's not + # fallback to mastersubject + if ($q->param('s')) { + $sql .= qq{ + and res_sub_infotype.subject_id = ? + }; + push @args, $q->param('s'); + } elsif ($q->param('ms')) { $sql .= qq{ and res_sub_infotype.subject_id in (select subject_id from sub_mastersubject where mastersubject_id = ?) @@ -179,6 +222,7 @@ return $arr; } +# get first letters for all Subjects sub get_subjects_letters { my $self = shift; @@ -195,6 +239,7 @@ return $sth->fetchall_arrayref({}); } +# get all Subjects sub get_subjects { my $self = shift; @@ -232,4 +277,22 @@ return $sth->fetchall_arrayref({}); } +# get one Subject by it's ID +sub get_subjects_by_id { + my $self = shift; + + my $id = shift || croak("need subject id"); + + my $sql = qq{ + select subject + from subject + where subject_id = ? + }; + + my $sth = $dbh->prepare($sql); + $sth->execute($id); + + return $sth->fetchrow_hashref(); +} + 1;