/[libdata-portal]/trunk/Portal.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Portal.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Sun Mar 7 18:22:26 2004 UTC revision 3 by dpavlin, Sun Mar 7 18:48:13 2004 UTC
# Line 5  use strict; Line 5  use strict;
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    
# Line 13  use lib '..'; Line 14  use lib '..';
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'";
# Line 35  sub setup { Line 36  sub setup {
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');
# Line 44  sub setup { Line 45  sub setup {
45  }  }
46    
47    
48    # home page
49  sub show_home {  sub show_home {
50          my $self = shift;          my $self = shift;
51    
# Line 64  sub show_home { Line 66  sub show_home {
66    
67  }  }
68    
69    
70    # MasterSubject
71  sub show_ms {  sub show_ms {
72          my $self = shift;          my $self = shift;
73    
# Line 76  sub show_ms { Line 80  sub show_ms {
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    
# Line 86  sub show_ms { Line 90  sub show_ms {
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;
# Line 105  sub use_template { Line 134  sub use_template {
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    
# Line 125  sub get_mastersubjects { Line 158  sub get_mastersubjects {
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    
# Line 142  sub get_mastersubjects_by_id { Line 176  sub get_mastersubjects_by_id {
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    
# Line 156  sub get_infotypes { Line 191  sub get_infotypes {
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 = ?)
# Line 179  sub get_infotypes { Line 222  sub get_infotypes {
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    
# Line 195  sub get_subjects_letters { Line 239  sub get_subjects_letters {
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    
# Line 232  sub get_subjects { Line 277  sub get_subjects {
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;

Legend:
Removed from v.1  
changed lines
  Added in v.3

  ViewVC Help
Powered by ViewVC 1.1.26