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

(-)a/catalogue/itemsearch.pl (-82 / +65 lines)
Lines 36-45 my $cgi = new CGI; Link Here
36
my %params = $cgi->Vars;
36
my %params = $cgi->Vars;
37
37
38
my $format = $cgi->param('format');
38
my $format = $cgi->param('format');
39
my ($template_name, $content_type);
39
my $template_name = 'catalogue/itemsearch.tt';
40
40
if (defined $format and $format eq 'json') {
41
if (defined $format and $format eq 'json') {
41
    $template_name = 'catalogue/itemsearch_json.tt';
42
    $template_name = 'catalogue/itemsearch_json.tt';
42
    $content_type = 'json';
43
43
44
    # Map DataTables parameters with 'regular' parameters
44
    # Map DataTables parameters with 'regular' parameters
45
    $cgi->param('rows', scalar $cgi->param('iDisplayLength'));
45
    $cgi->param('rows', scalar $cgi->param('iDisplayLength'));
Lines 75-84 if (defined $format and $format eq 'json') { Link Here
75
75
76
    # Retrieve all results
76
    # Retrieve all results
77
    $cgi->param('rows', 0);
77
    $cgi->param('rows', 0);
78
} else {
78
} elsif (defined $format) {
79
    $format = 'html';
79
    die "Unsupported format $format";
80
    $template_name = 'catalogue/itemsearch.tt';
81
    $content_type = 'html';
82
}
80
}
83
81
84
my ($template, $borrowernumber, $cookie) = get_template_and_user({
82
my ($template, $borrowernumber, $cookie) = get_template_and_user({
Lines 226-318 if (scalar keys %params > 0) { Link Here
226
        search_params => $search_params,
224
        search_params => $search_params,
227
        results => $results,
225
        results => $results,
228
        total_rows => $total_rows,
226
        total_rows => $total_rows,
229
        search_done => 1,
230
    );
227
    );
231
228
232
    if ($format eq 'html') {
229
    if ($format eq 'csv') {
233
        # Build pagination bar
230
        print $cgi->header({
234
        my $url = '/cgi-bin/koha/catalogue/itemsearch.pl';
231
            type => 'text/csv',
235
        my @params;
232
            attachment => 'items.csv',
236
        foreach my $p (keys %params) {
233
        });
237
            my @v = $cgi->multi_param($p);
238
            push @params, map { "$p=" . $_ } @v;
239
        }
240
        $url .= '?' . join ('&', @params);
241
        my $nb_pages = 1 + int($total_rows / $search_params->{rows});
242
        my $current_page = $search_params->{page};
243
        my $pagination_bar = pagination_bar($url, $nb_pages, $current_page, 'page');
244
234
245
        $template->param(pagination_bar => $pagination_bar);
235
        for my $line ( split '\n', $template->output ) {
236
            print "$line\n" unless $line =~ m|^\s*$|;
237
        }
238
    } elsif ($format eq 'json') {
239
        output_with_http_headers $cgi, $cookie, $template->output, 'json';
246
    }
240
    }
247
}
248
241
249
if ($format eq 'html') {
242
    exit;
250
    # Retrieve data required for the form.
243
}
251
252
    my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } );
253
    my @locations;
254
    foreach my $location (@$location_values) {
255
        push @locations, {
256
            value => $location->{authorised_value},
257
            label => $location->{lib} // $location->{authorised_value},
258
        };
259
    }
260
    my @itemtypes;
261
    foreach my $itemtype ( Koha::ItemTypes->search ) {
262
        push @itemtypes, {
263
            value => $itemtype->itemtype,
264
            label => $itemtype->translated_description,
265
        };
266
    }
267
244
268
    my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } });
245
# Display the search form
269
    my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
270
    my $ccodes = GetAuthorisedValues($ccode_avcode);
271
    my @ccodes;
272
    foreach my $ccode (@$ccodes) {
273
        push @ccodes, {
274
            value => $ccode->{authorised_value},
275
            label => $ccode->{lib},
276
        };
277
    }
278
246
279
    my @notforloans;
247
my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } );
280
    foreach my $value (@$notforloan_values) {
248
my @locations;
281
        push @notforloans, {
249
foreach my $location (@$location_values) {
282
            value => $value->{authorised_value},
250
    push @locations, {
283
            label => $value->{lib},
251
        value => $location->{authorised_value},
284
        };
252
        label => $location->{lib} // $location->{authorised_value},
285
    }
253
    };
286
254
}
287
    my @items_search_fields = GetItemSearchFields();
255
my @itemtypes;
256
foreach my $itemtype ( Koha::ItemTypes->search ) {
257
    push @itemtypes, {
258
        value => $itemtype->itemtype,
259
        label => $itemtype->translated_description,
260
    };
261
}
288
262
289
    my $authorised_values = {};
263
$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } });
290
    foreach my $field (@items_search_fields) {
264
my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
291
        if (my $category = ($field->{authorised_values_category})) {
265
my $ccodes = GetAuthorisedValues($ccode_avcode);
292
            $authorised_values->{$category} = GetAuthorisedValues($category);
266
my @ccodes;
293
        }
267
foreach my $ccode (@$ccodes) {
294
    }
268
    push @ccodes, {
269
        value => $ccode->{authorised_value},
270
        label => $ccode->{lib},
271
    };
272
}
295
273
296
    $template->param(
274
my @notforloans;
297
        branches => \@branches,
275
foreach my $value (@$notforloan_values) {
298
        locations => \@locations,
276
    push @notforloans, {
299
        itemtypes => \@itemtypes,
277
        value => $value->{authorised_value},
300
        ccodes => \@ccodes,
278
        label => $value->{lib},
301
        notforloans => \@notforloans,
279
    };
302
        items_search_fields => \@items_search_fields,
303
        authorised_values_json => to_json($authorised_values),
304
    );
305
}
280
}
306
281
307
if ($format eq 'csv') {
282
my @items_search_fields = GetItemSearchFields();
308
    print $cgi->header({
309
        type => 'text/csv',
310
        attachment => 'items.csv',
311
    });
312
283
313
    for my $line ( split '\n', $template->output ) {
284
my $authorised_values = {};
314
        print "$line\n" unless $line =~ m|^\s*$|;
285
foreach my $field (@items_search_fields) {
286
    if (my $category = ($field->{authorised_values_category})) {
287
        $authorised_values->{$category} = GetAuthorisedValues($category);
315
    }
288
    }
316
} else {
317
    output_with_http_headers $cgi, $cookie, $template->output, $content_type;
318
}
289
}
290
291
$template->param(
292
    branches => \@branches,
293
    locations => \@locations,
294
    itemtypes => \@itemtypes,
295
    ccodes => \@ccodes,
296
    notforloans => \@notforloans,
297
    items_search_fields => \@items_search_fields,
298
    authorised_values_json => to_json($authorised_values),
299
);
300
301
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc (-24 lines)
Lines 1-24 Link Here
1
[%- USE Branches -%]
2
[%- USE Koha -%]
3
[% biblio = item.biblio %]
4
[% biblioitem = item.biblioitem %]
5
<tr>
6
  <td>
7
    <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber %]" title="Go to record detail page">[% biblio.title %]</a>
8
    [% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %] by[% END %] [% biblio.author |html %]
9
  </td>
10
  <td>[% biblioitem.publicationyear || biblio.copyrightdate %]</td>
11
  <td>[% biblioitem.publishercode %]</td>
12
  <td>[% biblioitem.collectiontitle %]</td>
13
  <td>
14
    <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblio.biblionumber %]#item[% item.itemnumber %]" title="Go to item details">[% item.barcode %]</a>
15
  </td>
16
  <td>[% item.itemcallnumber %]</td>
17
  <td>[% Branches.GetName(item.homebranch) %]</td>
18
  <td>[% Branches.GetName(item.holdingbranch) %]</td>
19
  <td>[% item.location %]</td>
20
  <td>[% item.stocknumber %]</td>
21
  <td>[% item.status %]</td>
22
  <td>[% item.issues || 0 %]</td>
23
  <td><a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&amp;biblionumber=[% item.biblionumber %]&amp;itemnumber=[% item.itemnumber %]">Edit</a></td>
24
</tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc (-49 lines)
Lines 1-49 Link Here
1
[% names = CGI.param() %]
2
[% params = [] %]
3
[% FOREACH name IN names %]
4
  [% IF name != 'sortby' AND name != 'sortorder' %]
5
    [% params.push(name _ "=" _ CGI.param(name)) %]
6
  [% END %]
7
[% END %]
8
[% base_url = "/cgi-bin/koha/catalogue/itemsearch.pl?" _ params.join('&') %]
9
10
[% BLOCK itemsearch_header %]
11
  [% sortorder = 'asc' %]
12
  [% classes = [] %]
13
  [% IF CGI.param('sortby') == name %]
14
    [% classes.push('active') %]
15
    [% classes.push('sort-' _ CGI.param('sortorder')) %]
16
    [% IF CGI.param('sortorder') == 'asc' %]
17
      [% sortorder = 'desc' %]
18
    [% END %]
19
  [% END %]
20
  [% url = base_url _ '&sortby=' _ name _ '&sortorder=' _ sortorder %]
21
  <th class="[% classes.join(' ') %]">
22
    <a href="[% url %]" title="Sort on [% label %] ([% sortorder %])">[% text %]</a>
23
  </th>
24
[% END %]
25
26
<table>
27
  <thead>
28
    <tr>
29
      [% INCLUDE itemsearch_header name='title' label='title' text='Title' %]
30
      [% INCLUDE itemsearch_header name='publicationyear' label='publication date' text='Publication date' %]
31
      [% INCLUDE itemsearch_header name='publishercode' label='publisher' text='Publisher' %]
32
      [% INCLUDE itemsearch_header name='collectiontitle' label='collection' text='Collection' %]
33
      [% INCLUDE itemsearch_header name='barcode' label='barcode' text='Barcode' %]
34
      [% INCLUDE itemsearch_header name='itemcallnumber' label='callnumber' text='Call number' %]
35
      [% INCLUDE itemsearch_header name='homebranch' label='home branch' text='Home library' %]
36
      [% INCLUDE itemsearch_header name='holdingbranch' label='holding branch' text='Current location' %]
37
      [% INCLUDE itemsearch_header name='location' label='location' text='Shelving location' %]
38
      [% INCLUDE itemsearch_header name='stocknumber' label='inventory number' text='Inventory number' %]
39
      [% INCLUDE itemsearch_header name='notforloan' label='status' text='Status' %]
40
      [% INCLUDE itemsearch_header name='issues' label='issues' text='Checkouts' %]
41
      <th></th>
42
    </tr>
43
  </thead>
44
  <tbody>
45
    [% FOREACH item IN items %]
46
      [% INCLUDE 'catalogue/itemsearch_item.inc' item = item %]
47
    [% END %]
48
  </tbody>
49
</table>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt (-19 / +1 lines)
Lines 487-509 Link Here
487
    </div>
487
    </div>
488
  </div>
488
  </div>
489
  <div id="doc3" class="yui-t7">
489
  <div id="doc3" class="yui-t7">
490
      <div id="results-wrapper">
490
      <div id="results-wrapper"></div>
491
        [% IF search_done %]
492
          [% IF total_rows > 0 %]
493
            <p>Found [% total_rows %] results.</p>
494
          [% ELSE %]
495
            <p>No results found.</p>
496
          [% END %]
497
498
          [% IF results %]
499
            [% INCLUDE 'catalogue/itemsearch_items.inc' items = results %]
500
          [% END %]
501
502
          <div class="pages">
503
            [% pagination_bar %]
504
          </div>
505
506
        [% END %]
507
      </div>
508
491
509
    [% INCLUDE 'intranet-bottom.inc' %]
492
    [% INCLUDE 'intranet-bottom.inc' %]
510
- 

Return to bug 18394