View | Details | Raw Unified | Return to bug 11091
Collapse All | Expand All

(-)a/serials/subscription-bib-search.pl (-83 / +92 lines)
Lines 19-25 Link Here
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
21
22
23
=head1 NAME
22
=head1 NAME
24
23
25
subscription-bib-search.pl
24
subscription-bib-search.pl
Lines 47-53 to multipage gestion. Link Here
47
46
48
=cut
47
=cut
49
48
50
51
use strict;
49
use strict;
52
use warnings;
50
use warnings;
53
51
Lines 60-122 use C4::Search; Link Here
60
use C4::Biblio;
58
use C4::Biblio;
61
use C4::Debug;
59
use C4::Debug;
62
60
63
my $input=new CGI;
61
my $input = new CGI;
64
# my $type=$query->param('type');
65
my $op = $input->param('op') || q{};
62
my $op = $input->param('op') || q{};
66
my $dbh = C4::Context->dbh;
63
my $dbh = C4::Context->dbh;
67
64
68
my $startfrom=$input->param('startfrom');
65
my $startfrom = $input->param('startfrom');
69
$startfrom=0 unless $startfrom;
66
$startfrom = 0 unless $startfrom;
70
my ($template, $loggedinuser, $cookie);
67
my ( $template, $loggedinuser, $cookie );
71
my $resultsperpage;
68
my $resultsperpage;
72
69
73
my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
70
my $itype_or_itemtype =
71
  ( C4::Context->preference("item-level_itypes") ) ? 'itype' : 'itemtype';
74
72
75
my $query = $input->param('q');
73
my $query = $input->param('q');
74
76
# don't run the search if no search term !
75
# don't run the search if no search term !
77
if ($op eq "do_search" && $query) {
76
if ( $op eq "do_search" && $query ) {
78
77
79
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
78
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
80
        {   template_name   => "serials/result.tmpl",
79
        {
80
            template_name   => "serials/result.tmpl",
81
            query           => $input,
81
            query           => $input,
82
            type            => "intranet",
82
            type            => "intranet",
83
            authnotrequired => 0,
83
            authnotrequired => 0,
84
            flagsrequired => {catalogue => 1, serials => '*'},
84
            flagsrequired   => { catalogue => 1, serials => '*' },
85
            debug           => 1,
85
            debug           => 1,
86
        }
86
        }
87
    );
87
    );
88
88
89
    # add the limits if applicable
89
    # add the limits if applicable
90
    my $itemtypelimit = $input->param('itemtypelimit');
90
    my $itemtypelimit = $input->param('itemtypelimit');
91
    my $ccodelimit = $input->param('ccodelimit');
91
    my $ccodelimit    = $input->param('ccodelimit');
92
    my $op = C4::Context->preference('UseQueryParser') ? '&&' : 'and';
92
    my $op = C4::Context->preference('UseQueryParser') ? '&&' : 'and';
93
    $query .= " $op $itype_or_itemtype:$itemtypelimit" if $itemtypelimit;
93
    $query .= " $op $itype_or_itemtype:$itemtypelimit" if $itemtypelimit;
94
    $query .= " $op ccode:$ccodelimit" if $ccodelimit;
94
    $query .= " $op ccode:$ccodelimit" if $ccodelimit;
95
    $debug && warn $query;
95
    $debug && warn $query;
96
    $resultsperpage= $input->param('resultsperpage');
96
    $resultsperpage = $input->param('resultsperpage');
97
    $resultsperpage = 20 if(!defined $resultsperpage);
97
    $resultsperpage = 20 if ( !defined $resultsperpage );
98
98
99
    my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
99
    my ( $error, $marcrecords, $total_hits ) =
100
      SimpleSearch( $query, $startfrom * $resultsperpage, $resultsperpage );
100
    my $total = 0;
101
    my $total = 0;
101
    if (defined $marcrecords ) {
102
    if ( defined $marcrecords ) {
102
        $total = scalar @{$marcrecords};
103
        $total = scalar @{$marcrecords};
103
    }
104
    }
104
105
105
    if (defined $error) {
106
    if ( defined $error ) {
106
        $template->param(query_error => $error);
107
        $template->param( query_error => $error );
107
        warn "error: ".$error;
108
        warn "error: " . $error;
108
        output_html_with_http_headers $input, $cookie, $template->output;
109
        output_html_with_http_headers $input, $cookie, $template->output;
109
        exit;
110
        exit;
110
    }
111
    }
111
    my @results;
112
    my @results;
112
113
113
    for(my $i=0;$i<$total;$i++) {
114
    for ( my $i = 0 ; $i < $total ; $i++ ) {
114
        my %resultsloop;
115
        my %resultsloop;
115
        my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
116
        my $marcrecord = MARC::File::USMARC::decode( $marcrecords->[$i] );
116
        my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
117
        my $biblio = TransformMarcToKoha( C4::Context->dbh, $marcrecord, '' );
117
118
118
        #build the hash for the template.
119
        #build the hash for the template.
119
        $resultsloop{highlight}       = ($i % 2)?(1):(0);
120
        $resultsloop{highlight}       = ( $i % 2 ) ? (1) : (0);
120
        $resultsloop{title}           = $biblio->{'title'};
121
        $resultsloop{title}           = $biblio->{'title'};
121
        $resultsloop{subtitle}        = $biblio->{'subtitle'};
122
        $resultsloop{subtitle}        = $biblio->{'subtitle'};
122
        $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
123
        $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
Lines 129-215 if ($op eq "do_search" && $query) { Link Here
129
    }
130
    }
130
131
131
    # multi page display gestion
132
    # multi page display gestion
132
    my $displaynext=0;
133
    my $displaynext = 0;
133
    my $displayprev=$startfrom;
134
    my $displayprev = $startfrom;
134
    if(($total_hits - (($startfrom+1)*($resultsperpage))) > 0 ){
135
    if ( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
135
        $displaynext = 1;
136
        $displaynext = 1;
136
    }
137
    }
137
138
138
139
    my @numbers = ();
139
    my @numbers = ();
140
140
141
    if ($total_hits>$resultsperpage)
141
    if ( $total_hits > $resultsperpage ) {
142
    {
142
        for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
143
        for (my $i=1; $i<$total/$resultsperpage+1; $i++)
143
            if ( $i < 16 ) {
144
        {
144
                my $highlight = 0;
145
            if ($i<16)
145
                ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
146
            {
146
                push @numbers,
147
                my $highlight=0;
147
                  {
148
                ($startfrom==($i-1)) && ($highlight=1);
148
                    number     => $i,
149
                push @numbers, { number => $i,
149
                    highlight  => $highlight,
150
                    highlight => $highlight ,
150
                    searchdata => \@results,
151
                    searchdata=> \@results,
151
                    startfrom  => ( $i - 1 )
152
                    startfrom => ($i-1)};
152
                  };
153
            }
153
            }
154
        }
154
        }
155
    }
155
    }
156
156
157
    my $from = 0;
157
    my $from = 0;
158
    $from = $startfrom*$resultsperpage+1 if($total_hits > 0);
158
    $from = $startfrom * $resultsperpage + 1 if ( $total_hits > 0 );
159
    my $to;
159
    my $to;
160
160
161
    if($total_hits < (($startfrom+1)*$resultsperpage))
161
    if ( $total_hits < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
162
    {
163
        $to = $total;
162
        $to = $total;
164
    } else {
163
    }
165
        $to = (($startfrom+1)*$resultsperpage);
164
    else {
165
        $to = ( ( $startfrom + 1 ) * $resultsperpage );
166
    }
166
    }
167
    $template->param(
167
    $template->param(
168
                            query => $query,
168
        query          => $query,
169
                            resultsloop => \@results,
169
        resultsloop    => \@results,
170
                            startfrom=> $startfrom,
170
        startfrom      => $startfrom,
171
                            displaynext=> $displaynext,
171
        displaynext    => $displaynext,
172
                            displayprev=> $displayprev,
172
        displayprev    => $displayprev,
173
                            resultsperpage => $resultsperpage,
173
        resultsperpage => $resultsperpage,
174
                            startfromnext => $startfrom+1,
174
        startfromnext  => $startfrom + 1,
175
                            startfromprev => $startfrom-1,
175
        startfromprev  => $startfrom - 1,
176
                            total=>$total_hits,
176
        total          => $total_hits,
177
                            from=>$from,
177
        from           => $from,
178
                            to=>$to,
178
        to             => $to,
179
                            numbers=>\@numbers,
179
        numbers        => \@numbers,
180
                            );
180
    );
181
} # end of if ($op eq "do_search" & $query)
181
}    # end of if ($op eq "do_search" & $query)
182
else {
182
else {
183
    ($template, $loggedinuser, $cookie)
183
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
184
        = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
184
        {
185
                query => $input,
185
            template_name   => "serials/subscription-bib-search.tmpl",
186
                type => "intranet",
186
            query           => $input,
187
                authnotrequired => 0,
187
            type            => "intranet",
188
                flagsrequired => {catalogue => 1, serials => '*'},
188
            authnotrequired => 0,
189
                debug => 1,
189
            flagsrequired   => { catalogue => 1, serials => '*' },
190
                });
190
            debug           => 1,
191
        }
192
    );
191
193
192
    # load the itemtypes
194
    # load the itemtypes
193
    my $itemtypes = GetItemTypes();
195
    my $itemtypes = GetItemTypes();
194
    my @itemtypesloop;
196
    my @itemtypesloop;
195
	foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
197
    foreach my $thisitemtype (
196
	    my %row =(
198
        sort {
197
			code => $thisitemtype,
199
            $itemtypes->{$a}->{'description'}
198
			description => $itemtypes->{$thisitemtype}->{'description'},
200
              cmp $itemtypes->{$b}->{'description'}
199
		    );
201
        } keys %$itemtypes
200
	    push @itemtypesloop, \%row;
202
      )
201
	}
203
    {
204
        my %row = (
205
            code        => $thisitemtype,
206
            description => $itemtypes->{$thisitemtype}->{'description'},
207
        );
208
        push @itemtypesloop, \%row;
209
    }
202
210
203
    # load Collection Codes
211
    # load Collection Codes
204
	my $authvalues = GetAuthorisedValues('CCODE');
212
    my $authvalues = GetAuthorisedValues('CCODE');
205
	my @ccodesloop;
213
    my @ccodesloop;
206
	for my $thisauthvalue (sort {$a->{'lib'} cmp $b->{'lib'}} @$authvalues) {
214
    for my $thisauthvalue ( sort { $a->{'lib'} cmp $b->{'lib'} } @$authvalues )
207
	    my %row =(
215
    {
208
		    code => $thisauthvalue->{'authorised_value'},
216
        my %row = (
209
		    description => $thisauthvalue->{'lib'},
217
            code        => $thisauthvalue->{'authorised_value'},
210
		);
218
            description => $thisauthvalue->{'lib'},
211
	    push @ccodesloop, \%row;
219
        );
212
	}
220
        push @ccodesloop, \%row;
221
    }
213
222
214
    $template->param(
223
    $template->param(
215
        itemtypeloop => \@itemtypesloop,
224
        itemtypeloop => \@itemtypesloop,
Lines 217-222 else { Link Here
217
        no_query     => $op eq "do_search" ? 1 : 0,
226
        no_query     => $op eq "do_search" ? 1 : 0,
218
    );
227
    );
219
}
228
}
229
220
# Print the page
230
# Print the page
221
output_html_with_http_headers $input, $cookie, $template->output;
231
output_html_with_http_headers $input, $cookie, $template->output;
222
232
223
- 

Return to bug 11091