5 |
|
|
6 |
use Config::IniFiles; |
use Config::IniFiles; |
7 |
use DBI; |
use DBI; |
8 |
|
use Carp; |
9 |
|
|
10 |
use Data::Dumper; |
use Data::Dumper; |
11 |
|
|
14 |
my $dsn = 'Pg:dbname=libdata'; |
my $dsn = 'Pg:dbname=libdata'; |
15 |
my ($user,$passwd) = ('dpavlin',''); |
my ($user,$passwd) = ('dpavlin',''); |
16 |
|
|
17 |
my @persistent_vars = qw(p); |
my @persistent_vars = qw(p ms); |
18 |
|
|
19 |
# read global.conf configuration |
# read global.conf configuration |
20 |
my $cfg_global = new Config::IniFiles( -file => '../global.conf' ) || die "can't open 'global.conf'"; |
my $cfg_global = new Config::IniFiles( -file => '../global.conf' ) || die "can't open 'global.conf'"; |
36 |
'home' => 'show_home', |
'home' => 'show_home', |
37 |
'ms' => 'show_ms', |
'ms' => 'show_ms', |
38 |
'it' => 'show_home', |
'it' => 'show_home', |
39 |
's' => 'show_home', |
's' => 'show_s', |
40 |
); |
); |
41 |
$self->start_mode('home'); |
$self->start_mode('home'); |
42 |
$self->mode_param('p'); |
$self->mode_param('p'); |
45 |
} |
} |
46 |
|
|
47 |
|
|
48 |
|
# home page |
49 |
sub show_home { |
sub show_home { |
50 |
my $self = shift; |
my $self = shift; |
51 |
|
|
66 |
|
|
67 |
} |
} |
68 |
|
|
69 |
|
|
70 |
|
# MasterSubject |
71 |
sub show_ms { |
sub show_ms { |
72 |
my $self = shift; |
my $self = shift; |
73 |
|
|
80 |
my $ms = $self->get_mastersubjects_by_id($q->param('ms')); |
my $ms = $self->get_mastersubjects_by_id($q->param('ms')); |
81 |
|
|
82 |
$tmpl->param('title' => uc($ms->{'mastersubject'}) ); |
$tmpl->param('title' => uc($ms->{'mastersubject'}) ); |
83 |
$tmpl->param('mastersubject_lc' => lc($ms->{'mastersubject'}) ); |
$tmpl->param('search_field' => lc($ms->{'mastersubject'}) ); |
84 |
|
|
85 |
$tmpl->param('InfoTypes' => $self->get_infotypes() ); |
$tmpl->param('InfoTypes' => $self->get_infotypes() ); |
86 |
|
|
90 |
|
|
91 |
} |
} |
92 |
|
|
93 |
|
|
94 |
|
# Subject |
95 |
|
sub show_s { |
96 |
|
my $self = shift; |
97 |
|
|
98 |
|
my $q = $self->query(); |
99 |
|
|
100 |
|
my $tmpl = $self->use_template('s.html'); |
101 |
|
|
102 |
|
$tmpl->param('MasterSubjects' => $self->get_mastersubjects() ); |
103 |
|
|
104 |
|
my $s = $self->get_subjects_by_id($q->param('s')); |
105 |
|
|
106 |
|
$tmpl->param('title' => uc($s->{'subject'}) ); |
107 |
|
$tmpl->param('search_field' => lc($s->{'subject'}) ); |
108 |
|
|
109 |
|
$tmpl->param('InfoTypes' => $self->get_infotypes() ); |
110 |
|
|
111 |
|
return $tmpl->output; |
112 |
|
|
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
# |
117 |
# load template and generate permanent valirables in template |
# load template and generate permanent valirables in template |
118 |
|
# |
119 |
|
|
120 |
sub use_template { |
sub use_template { |
121 |
my $self = shift; |
my $self = shift; |
134 |
return $tmpl; |
return $tmpl; |
135 |
} |
} |
136 |
|
|
137 |
|
|
138 |
|
# |
139 |
# get data from database |
# get data from database |
140 |
|
# |
141 |
|
|
142 |
|
# get all MasterSubjects |
143 |
sub get_mastersubjects { |
sub get_mastersubjects { |
144 |
my $self = shift; |
my $self = shift; |
145 |
|
|
158 |
return $sth->fetchall_arrayref({}); |
return $sth->fetchall_arrayref({}); |
159 |
} |
} |
160 |
|
|
161 |
|
# get one MasterSubject by it's ID |
162 |
sub get_mastersubjects_by_id { |
sub get_mastersubjects_by_id { |
163 |
my $self = shift; |
my $self = shift; |
164 |
|
|
176 |
return $sth->fetchrow_hashref(); |
return $sth->fetchrow_hashref(); |
177 |
} |
} |
178 |
|
|
179 |
|
# get all InfoTypes |
180 |
sub get_infotypes { |
sub get_infotypes { |
181 |
my $self = shift; |
my $self = shift; |
182 |
|
|
191 |
where res_sub_infotype.infotype_id=infotype.infotype_id and infotype.infotype_id > 1 |
where res_sub_infotype.infotype_id=infotype.infotype_id and infotype.infotype_id > 1 |
192 |
}; |
}; |
193 |
|
|
194 |
if ($q->param('ms')) { |
|
195 |
|
# first check if subject is defined and limit by that, and only if it's not |
196 |
|
# fallback to mastersubject |
197 |
|
if ($q->param('s')) { |
198 |
|
$sql .= qq{ |
199 |
|
and res_sub_infotype.subject_id = ? |
200 |
|
}; |
201 |
|
push @args, $q->param('s'); |
202 |
|
} elsif ($q->param('ms')) { |
203 |
$sql .= qq{ |
$sql .= qq{ |
204 |
and res_sub_infotype.subject_id in |
and res_sub_infotype.subject_id in |
205 |
(select subject_id from sub_mastersubject where mastersubject_id = ?) |
(select subject_id from sub_mastersubject where mastersubject_id = ?) |
222 |
return $arr; |
return $arr; |
223 |
} |
} |
224 |
|
|
225 |
|
# get first letters for all Subjects |
226 |
sub get_subjects_letters { |
sub get_subjects_letters { |
227 |
my $self = shift; |
my $self = shift; |
228 |
|
|
239 |
return $sth->fetchall_arrayref({}); |
return $sth->fetchall_arrayref({}); |
240 |
} |
} |
241 |
|
|
242 |
|
# get all Subjects |
243 |
sub get_subjects { |
sub get_subjects { |
244 |
my $self = shift; |
my $self = shift; |
245 |
|
|
277 |
return $sth->fetchall_arrayref({}); |
return $sth->fetchall_arrayref({}); |
278 |
} |
} |
279 |
|
|
280 |
|
# get one Subject by it's ID |
281 |
|
sub get_subjects_by_id { |
282 |
|
my $self = shift; |
283 |
|
|
284 |
|
my $id = shift || croak("need subject id"); |
285 |
|
|
286 |
|
my $sql = qq{ |
287 |
|
select subject |
288 |
|
from subject |
289 |
|
where subject_id = ? |
290 |
|
}; |
291 |
|
|
292 |
|
my $sth = $dbh->prepare($sql); |
293 |
|
$sth->execute($id); |
294 |
|
|
295 |
|
return $sth->fetchrow_hashref(); |
296 |
|
} |
297 |
|
|
298 |
1; |
1; |