[followup](bug #4062) marc21 item support
[koha.git] / opac / opac-recentacquisitions.pl
1 #!/usr/bin/perl
2
3 #attention fichier pour notices MARC21
4
5 use strict;
6 use warnings;
7
8 use C4::Context;
9 use C4::Search;
10 use MARC::File::XML;
11 #use XML::LibXML;
12 #use XML::LibXSLT;
13 use CGI;
14 use C4::Dates;
15 use Date::Calc;
16 use C4::Auth;
17 use C4::Output;
18 use C4::Koha;
19
20 my $query= new CGI;
21 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
22     {
23         template_name   => "opac-recentacquisitions.tmpl",
24         query           => $query,
25         type            => "opac",
26         authnotrequired => 1,
27         flagsrequired   => {},
28         debug           => 1,
29     }
30 );
31
32 die() unless C4::Context->preference("OpacRecentAcquisitions");
33
34 my $op = $query->param('op') || '';
35 if ($op eq "show_list"){
36
37     my $datebegin           = C4::Dates->new($query->param('datebegin'));
38     my $dateend             = C4::Dates->new($query->param('dateend')) if ($query->param('dateend'));
39
40     my $orderby             = $query->param('orderby') if ($query->param('orderby'));
41     my $criteria            = $query->param('criteria');
42     my @itemtypes           = $query->param('itemtypes');
43     
44     
45     my $loopacquisitions = SearchAcquisitions($datebegin, $dateend, \@itemtypes,
46                                                 $criteria, $orderby);
47     
48     $template->param(loopacquisitions=>$loopacquisitions,
49                      show_list=>1);
50 } else {
51     my $period      = C4::Context->preference("recentacquisitionregularPeriod")||30;
52     my $dateend     = C4::Dates->new();
53     #warn " dateend :".$dateend->output("syspref");
54     my @dateend     = Date::Calc::Today;
55     my @datebegin   = Date::Calc::Add_Delta_Days(@dateend,-$period) if ($period);
56     my $datebegin   = C4::Dates->new(sprintf("%04d-%02d-%02d",@datebegin[0..2]),'iso');
57     #warn 'datebegin :'.$datebegin->output("syspref")." dateend :".$dateend->output("syspref");
58     my $itemtypes   = GetItemTypes;
59     
60     my @itemtypesloop;
61     my $selected=1;
62     my $cnt;
63     my $imgdir = getitemtypeimagesrc();
64     
65     foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
66         my %row =(  number=>$cnt++,
67                     imageurl=> $itemtypes->{$thisitemtype}->{'imageurl'}?($imgdir."/".$itemtypes->{$thisitemtype}->{'imageurl'}):"",
68                     code => $thisitemtype,
69                     selected => $selected,
70                     description => $itemtypes->{$thisitemtype}->{'description'},
71                     count5 => $cnt % 4,
72                 );
73         $selected = 0 if ($selected) ;
74         push @itemtypesloop, \%row;
75     }
76     
77     $template->param(datebegin  => $datebegin->output("syspref"),
78                      dateend    => $dateend->output("syspref"),);
79     $template->param(period                   => $period,
80                      itemtypeloop             => \@itemtypesloop,
81                      DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),        
82                     );
83           
84 }
85 output_html_with_http_headers $query, $cookie, $template->output;
86