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

(-)a/C4/Biblio.pm (-2 / +4 lines)
Lines 2790-2805 sub GetNoZebraIndexes { Link Here
2790
2790
2791
=head2 EmbedItemsInMarcBiblio
2791
=head2 EmbedItemsInMarcBiblio
2792
2792
2793
    EmbedItemsInMarcBiblio($marc, $biblionumber);
2793
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2794
2794
2795
Given a MARC::Record object containing a bib record,
2795
Given a MARC::Record object containing a bib record,
2796
modify it to include the items attached to it as 9XX
2796
modify it to include the items attached to it as 9XX
2797
per the bib's MARC framework.
2797
per the bib's MARC framework.
2798
if $itemnumbers is defined, only specified itemnumbers are embedded
2798
2799
2799
=cut
2800
=cut
2800
2801
2801
sub EmbedItemsInMarcBiblio {
2802
sub EmbedItemsInMarcBiblio {
2802
    my ($marc, $biblionumber) = @_;
2803
    my ($marc, $biblionumber, $itemnumbers) = @_;
2803
    croak "No MARC record" unless $marc;
2804
    croak "No MARC record" unless $marc;
2804
2805
2805
    my $frameworkcode = GetFrameworkCode($biblionumber);
2806
    my $frameworkcode = GetFrameworkCode($biblionumber);
Lines 2812-2817 sub EmbedItemsInMarcBiblio { Link Here
2812
    my @item_fields;
2813
    my @item_fields;
2813
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2814
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2814
    while (my ($itemnumber) = $sth->fetchrow_array) {
2815
    while (my ($itemnumber) = $sth->fetchrow_array) {
2816
        next if $itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2815
        require C4::Items;
2817
        require C4::Items;
2816
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2818
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2817
        push @item_fields, $item_marc->field($itemtag);
2819
        push @item_fields, $item_marc->field($itemtag);
(-)a/C4/Csv.pm (+13 lines)
Lines 35-40 $VERSION = 3.07.00.049; Link Here
35
@EXPORT = qw(
35
@EXPORT = qw(
36
  &GetCsvProfiles
36
  &GetCsvProfiles
37
  &GetCsvProfile
37
  &GetCsvProfile
38
  &GetCsvProfileId
38
  &GetCsvProfilesLoop
39
  &GetCsvProfilesLoop
39
  &GetMarcFieldsForCsv
40
  &GetMarcFieldsForCsv
40
);
41
);
Lines 64-69 sub GetCsvProfile { Link Here
64
    return ($sth->fetchrow_hashref);
65
    return ($sth->fetchrow_hashref);
65
}
66
}
66
67
68
# Returns id of csv profile about a given csv profile name
69
sub GetCsvProfileId {
70
    my ($name)  = @_;
71
    my $dbh   = C4::Context->dbh;
72
    my $query = "SELECT export_format_id FROM export_format WHERE profile=?";
73
74
    $sth = $dbh->prepare($query);
75
    $sth->execute($name);
76
77
    return ( $sth->fetchrow );
78
}
79
67
# Returns fields to extract for the given csv profile
80
# Returns fields to extract for the given csv profile
68
sub GetMarcFieldsForCsv {
81
sub GetMarcFieldsForCsv {
69
82
(-)a/C4/Record.pm (-17 / +42 lines)
Lines 330-336 sub marc2endnote { Link Here
330
330
331
=head2 marc2csv - Convert several records from UNIMARC to CSV
331
=head2 marc2csv - Convert several records from UNIMARC to CSV
332
332
333
  my ($csv) = marc2csv($biblios, $csvprofileid);
333
  my ($csv) = marc2csv($biblios, $csvprofileid, $itemnumbers);
334
334
335
Pre and postprocessing can be done through a YAML file
335
Pre and postprocessing can be done through a YAML file
336
336
Lines 340-349 C<$biblio> - a list of biblionumbers Link Here
340
340
341
C<$csvprofileid> - the id of the CSV profile to use for the export (see export_format.export_format_id and the GetCsvProfiles function in C4::Csv)
341
C<$csvprofileid> - the id of the CSV profile to use for the export (see export_format.export_format_id and the GetCsvProfiles function in C4::Csv)
342
342
343
C<$itemnumbers> - a list of itemnumbers to export
344
343
=cut
345
=cut
344
346
345
sub marc2csv {
347
sub marc2csv {
346
    my ($biblios, $id) = @_;
348
    my ($biblios, $id, $itemnumbers) = @_;
347
    my $output;
349
    my $output;
348
    my $csv = Text::CSV::Encoded->new();
350
    my $csv = Text::CSV::Encoded->new();
349
351
Lines 358-366 sub marc2csv { Link Here
358
    eval $preprocess if ($preprocess);
360
    eval $preprocess if ($preprocess);
359
361
360
    my $firstpass = 1;
362
    my $firstpass = 1;
361
    foreach my $biblio (@$biblios) {
363
    if ( $itemnumbers ) {
362
	$output .= marcrecord2csv($biblio, $id, $firstpass, $csv, $fieldprocessing) ;
364
        for my $itemnumber ( @$itemnumbers) {
363
	$firstpass = 0;
365
            my $biblionumber = GetBiblionumberFromItemnumber $itemnumber;
366
            $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] );
367
            $firstpass = 0;
368
        }
369
    } else {
370
        foreach my $biblio (@$biblios) {
371
            $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing );
372
            $firstpass = 0;
373
        }
364
    }
374
    }
365
375
366
    # Postprocessing
376
    # Postprocessing
Lines 383-398 C<$header> - true if the headers are to be printed (typically at first pass) Link Here
383
393
384
C<$csv> - an already initialised Text::CSV object
394
C<$csv> - an already initialised Text::CSV object
385
395
396
C<$fieldprocessing>
397
398
C<$itemnumbers> a list of itemnumbers to export
399
386
=cut
400
=cut
387
401
388
402
389
sub marcrecord2csv {
403
sub marcrecord2csv {
390
    my ($biblio, $id, $header, $csv, $fieldprocessing) = @_;
404
    my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_;
391
    my $output;
405
    my $output;
392
406
393
    # Getting the record
407
    # Getting the record
394
    my $record = GetMarcBiblio($biblio, 1);
408
    my $record = GetMarcBiblio($biblio);
395
    next unless $record;
409
    next unless $record;
410
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblio, $itemnumbers );
396
    # Getting the framework
411
    # Getting the framework
397
    my $frameworkcode = GetFrameworkCode($biblio);
412
    my $frameworkcode = GetFrameworkCode($biblio);
398
413
Lines 499-516 sub marcrecord2csv { Link Here
499
	    my @fields = ($record->field($marcfield));
514
	    my @fields = ($record->field($marcfield));
500
	    my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef);
515
	    my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef);
501
516
502
	    my @valuesarray;
517
        my @valuesarray;
503
	    foreach (@fields) {
518
        foreach (@fields) {
504
		my $value;
519
            my $value;
505
520
506
		# Getting authorised value
521
            # If it is a control field
507
		$value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string;
522
            if ($_->is_control_field) {
523
                $value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string;
524
            } else {
525
                # If it is a field, we gather all subfields, joined by the subfield separator
526
                my @subvaluesarray;
527
                my @subfields = $_->subfields;
528
                foreach my $subfield (@subfields) {
529
                    push (@subvaluesarray, defined $authvalues->{$subfield->[1]} ? $authvalues->{$subfield->[1]} : $subfield->[1]);
530
                }
531
                $value = join ($subfieldseparator, @subvaluesarray);
532
            }
508
533
509
		# Field processing
534
            # Field processing
510
		eval $fieldprocessing if ($fieldprocessing);
535
            eval $fieldprocessing if ($fieldprocessing);
511
536
512
		push @valuesarray, $value;
537
            push @valuesarray, $value;
513
	    }
538
        }
514
	    push (@fieldstab, join($fieldseparator, @valuesarray)); 
539
	    push (@fieldstab, join($fieldseparator, @valuesarray)); 
515
	 }
540
	 }
516
    };
541
    };
(-)a/circ/circulation.pl (+2 lines)
Lines 734-739 $template->param( Link Here
734
	AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
734
	AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
735
    dateformat                => C4::Context->preference("dateformat"),
735
    dateformat                => C4::Context->preference("dateformat"),
736
    DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar(),
736
    DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar(),
737
    dont_export_fields        => C4::Context->preference("DontExportFields"),
738
    csv_profile_for_export    => C4::Context->preference("CsvProfileForExport"),
737
    canned_bor_notes_loop     => $canned_notes,
739
    canned_bor_notes_loop     => $canned_notes,
738
);
740
);
739
741
(-)a/installer/data/mysql/updatedatabase.pl (+19 lines)
Lines 5459-5464 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5459
    SetVersion($DBversion);
5459
    SetVersion($DBversion);
5460
}
5460
}
5461
5461
5462
5463
$DBversion = "3.09.00.XXX";
5464
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5465
    $dbh->do(qq{
5466
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('DontExportFields','','List of fields for non export in circulation.pl (separated by a space)','','');
5467
    });
5468
    print "Upgrade to $DBversion done (Add system preference DontExportFields)\n";
5469
    SetVersion($DBversion);
5470
}
5471
5472
$DBversion = "3.09.00.XXX";
5473
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5474
    $dbh->do(qq{
5475
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('CsvProfileForExport','','Set a profile name for CSV export','','');
5476
    });
5477
    print "Upgrade to $DBversion done (Adds New System preference CsvProfileForExport)\n";
5478
    SetVersion($DBversion)
5479
}
5480
5462
=head1 FUNCTIONS
5481
=head1 FUNCTIONS
5463
5482
5464
=head2 TableExists($table)
5483
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc (-1 / +1 lines)
Lines 3-9 Link Here
3
        <td colspan="6" style="text-align: right; font-weight:bold;">Totals:</td>
3
        <td colspan="6" style="text-align: right; font-weight:bold;">Totals:</td>
4
		<td>[% totaldue %]</td>
4
		<td>[% totaldue %]</td>
5
		<td>[% totalprice %]</td>
5
		<td>[% totalprice %]</td>
6
		<td colspan="2">
6
                <td colspan="3">
7
            <p>Renewal due date: <input type="text" size="8" id="newduedate" name="newduedate" value="[% newduedate %]" />
7
            <p>Renewal due date: <input type="text" size="8" id="newduedate" name="newduedate" value="[% newduedate %]" />
8
</p>
8
</p>
9
			<p><label>Forgive fines on return: <input type="checkbox" name="exemptfine" value="1" /></label></p>
9
			<p><label>Forgive fines on return: <input type="checkbox" name="exemptfine" value="1" /></label></p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-menu.inc (+1 lines)
Lines 15-20 Link Here
15
[% IF ( searching ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Searching" href="/cgi-bin/koha/admin/preferences.pl?tab=searching">Searching</a></li>
15
[% IF ( searching ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Searching" href="/cgi-bin/koha/admin/preferences.pl?tab=searching">Searching</a></li>
16
[% IF ( serials ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Serials" href="/cgi-bin/koha/admin/preferences.pl?tab=serials">Serials</a></li>
16
[% IF ( serials ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Serials" href="/cgi-bin/koha/admin/preferences.pl?tab=serials">Serials</a></li>
17
[% IF ( staff_client ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Staff client" href="/cgi-bin/koha/admin/preferences.pl?tab=staff_client">Staff client</a></li>
17
[% IF ( staff_client ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Staff client" href="/cgi-bin/koha/admin/preferences.pl?tab=staff_client">Staff client</a></li>
18
[% IF ( tools ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Tools" href="/cgi-bin/koha/admin/preferences.pl?tab=tools">Tools</a></li>
18
[% IF ( web_services ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Web services" href="/cgi-bin/koha/admin/preferences.pl?tab=web_services">Web services</a></li>
19
[% IF ( web_services ) %]<li class="active">[% ELSE %]<li>[% END %]<a title="Web services" href="/cgi-bin/koha/admin/preferences.pl?tab=web_services">Web services</a></li>
19
</ul>
20
</ul>
20
</div>
21
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+6 lines)
Lines 109-114 Circulation: Link Here
109
                  yes: Do
109
                  yes: Do
110
                  no: "Do not"
110
                  no: "Do not"
111
            - update a bibliographic record's total issues count whenever an item is issued (WARNING! This increases server load significantly; if performance is a concern, use the update_totalissues.pl cron job to update the total issues count).
111
            - update a bibliographic record's total issues count whenever an item is issued (WARNING! This increases server load significantly; if performance is a concern, use the update_totalissues.pl cron job to update the total issues count).
112
        -
113
            - pref: DontExportFields
114
            - choices:
115
                yes: Export
116
                no: "Don't export"
117
            - fields for csv or iso2709 export
112
    Checkout Policy:
118
    Checkout Policy:
113
        -
119
        -
114
            - pref: AllowNotForLoanOverride
120
            - pref: AllowNotForLoanOverride
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref (+4 lines)
Line 0 Link Here
1
Tools:
2
    -
3
        - pref: CsvProfileForExport
4
        - CSV profile for export
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-7 / +82 lines)
Lines 76-81 var allcheckboxes = $(".checkboxed"); Link Here
76
		$(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]"); return false;
76
		$(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]"); return false;
77
	});
77
	});
78
78
79
    $("#CheckAllexports").click(function(){
80
        $(".checkboxed").checkCheckboxes(":input[name*=biblionumbers]");
81
        $(".checkboxed").unCheckCheckboxes(":input[name*=items]");
82
        return false;
83
    });
84
    $("#CheckNoexports").click(function(){
85
        $(".checkboxed").unCheckCheckboxes(":input[name*=biblionumbers]");
86
        return false;
87
    });
88
79
    $("#relrenew_all").click(function(){
89
    $("#relrenew_all").click(function(){
80
        $(allcheckboxes).checkCheckboxes(":input[name*=items]");
90
        $(allcheckboxes).checkCheckboxes(":input[name*=items]");
81
        $(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]");
91
        $(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]");
Lines 138-146 var allcheckboxes = $(".checkboxed"); Link Here
138
		$("#add_message_form").show();
148
		$("#add_message_form").show();
139
	 });
149
	 });
140
150
141
     $("input.radio").click(function(){
151
    $("input.radio").click(function(){
142
        radioCheckBox($(this));
152
        radioCheckBox($(this));
143
     });
153
    });
154
    $("#exportmenuc").empty();
155
    initExportButton();
156
144
    $("#newduedate").datepicker({ minDate: 1 }); // require that renewal date is after today
157
    $("#newduedate").datepicker({ minDate: 1 }); // require that renewal date is after today
145
    $("#duedatespec").datepicker({
158
    $("#duedatespec").datepicker({
146
        onSelect: function(dateText, inst) { $("#barcode").focus(); }
159
        onSelect: function(dateText, inst) { $("#barcode").focus(); }
Lines 148-153 var allcheckboxes = $(".checkboxed"); Link Here
148
161
149
 });
162
 });
150
163
164
function initExportButton() {
165
    var exportmenu = [
166
        { text: _("ISO2709 with items"), onclick: {fn: function(){export_submit("iso2709_995")}} },
167
        { text: _("ISO2709 without items"), onclick: {fn: function(){export_submit("iso2709")}} },
168
        { text: _("CSV"), onclick: {fn: function(){export_submit("csv")}} },
169
    ];
170
    new YAHOO.widget.Button({
171
        type: "menu",
172
        label: _("Export"),
173
        name: "exportmenubutton",
174
        menu: exportmenu,
175
        container: "exportmenuc"
176
    });
177
}
178
179
function export_submit(format) {
180
    if ($("input:checkbox[name='biblionumbers'][checked]").length < 1){
181
        alert(_("You must select a checkout to export"));
182
        return;
183
    }
184
185
    $("input:checkbox[name='biblionumbers']").each( function(){
186
        var input_item = $(this).siblings("input:checkbox");
187
        if ( $(this).is(":checked") ) {
188
            $(input_item).attr("checked", "checked");
189
        } else {
190
            $(input_item).attr("checked", "");
191
        }
192
    } );
193
194
    if (format == 'iso2709_995') {
195
        format = 'iso2709';
196
        $("#dont_export_item").val(0);
197
    } else if (format == 'iso2709') {
198
        $("#dont_export_item").val(1);
199
    } else {
200
        [% UNLESS ( csv_profile_for_export ) %]
201
            alert(_("You must defined a csv profile for export (in tools>CSV export profiles) and filled the CsvProfileForExport system preference"));
202
            return false;
203
        [% END %]
204
    }
205
    document.issues.action="/cgi-bin/koha/tools/export.pl";
206
    document.getElementById("export_format").value = format;
207
    document.issues.submit();
208
209
    /* Reset form action to its initial value */
210
    document.issues.action="/cgi-bin/koha/reserve/renewscript.pl";
211
212
};
213
151
function validate1(date) {
214
function validate1(date) {
152
    var today = new Date();
215
    var today = new Date();
153
    if ( date < today ) {
216
    if ( date < today ) {
Lines 667-673 No patron matched <span class="ex">[% message %]</span> Link Here
667
<!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
730
<!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
668
<div id="checkouts">
731
<div id="checkouts">
669
[% IF ( issuecount ) %]
732
[% IF ( issuecount ) %]
670
    <form action="/cgi-bin/koha/reserve/renewscript.pl" method="post" class="checkboxed">
733
    <form name="issues" action="/cgi-bin/koha/reserve/renewscript.pl" method="post" class="checkboxed">
671
    <input type="hidden" value="circ" name="destination" />
734
    <input type="hidden" value="circ" name="destination" />
672
    <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
735
    <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
673
    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
736
    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
Lines 684-689 No patron matched <span class="ex">[% message %]</span> Link Here
684
        <th scope="col">Price</th>
747
        <th scope="col">Price</th>
685
        <th scope="col">Renew <p class="column-tool"><a href="#" id="CheckAllitems">select all</a> | <a href="#" id="CheckNoitems">none</a></p></th>
748
        <th scope="col">Renew <p class="column-tool"><a href="#" id="CheckAllitems">select all</a> | <a href="#" id="CheckNoitems">none</a></p></th>
686
        <th scope="col">Check in <p class="column-tool"><a href="#" id="CheckAllreturns">select all</a> | <a href="#" id="CheckNoreturns">none</a></p></th>
749
        <th scope="col">Check in <p class="column-tool"><a href="#" id="CheckAllreturns">select all</a> | <a href="#" id="CheckNoreturns">none</a></p></th>
750
        <th scope="col">Export <p class="column-tool"><a href="#" id="CheckAllexports">select all</a> | <a href="#" id="CheckNoexports">none</a></p></th>
687
    </tr>
751
    </tr>
688
[% IF ( todayissues ) %]</thead>
752
[% IF ( todayissues ) %]</thead>
689
[% INCLUDE 'checkouts-table-footer.inc' %]
753
[% INCLUDE 'checkouts-table-footer.inc' %]
Lines 757-764 No patron matched <span class="ex">[% message %]</span> Link Here
757
    [% END %] <!-- /loop todayissues -->
821
    [% END %] <!-- /loop todayissues -->
758
    <!-- /if todayissues -->[% END %]
822
    <!-- /if todayissues -->[% END %]
759
[% IF ( previssues ) %]
823
[% IF ( previssues ) %]
760
[% IF ( todayissues ) %]<tr><th colspan="10"><a name="previous" id="previous"></a>Previous checkouts</th></tr>[% ELSE %]
824
[% IF ( todayissues ) %]<tr><th colspan="11"><a name="previous" id="previous"></a>Previous checkouts</th></tr>[% ELSE %]
761
<tr><th class="{sorter: false}" colspan="10"><a name="previous" id="previous"></a>Previous checkouts</th></tr></thead>
825
<tr><th class="{sorter: false}" colspan="11"><a name="previous" id="previous"></a>Previous checkouts</th></tr></thead>
762
[% INCLUDE 'checkouts-table-footer.inc' %]
826
[% INCLUDE 'checkouts-table-footer.inc' %]
763
	<tbody>
827
	<tbody>
764
[% END %]
828
[% END %]
Lines 827-832 No patron matched <span class="ex">[% message %]</span> Link Here
827
                <input type="checkbox" name="all_barcodes[]" value="[% previssue.barcode %]" checked="checked" style="display: none;" />
891
                <input type="checkbox" name="all_barcodes[]" value="[% previssue.barcode %]" checked="checked" style="display: none;" />
828
            </td>
892
            </td>
829
            [% END %]
893
            [% END %]
894
            <td style="text-align:center;">
895
                <input type="checkbox" id="export_[% previssue.biblionumber %]" name="biblionumbers" value="[% previssue.biblionumber %]" />
896
                <input type="checkbox" name="itemnumbers" value="[% previssue.itemnumber %]" style="visibility:hidden;" />
897
            </td>
830
      [% END %]
898
      [% END %]
831
    </tr>
899
    </tr>
832
    <!-- /loop previssues -->[% END %]
900
    <!-- /loop previssues -->[% END %]
Lines 843-849 No patron matched <span class="ex">[% message %]</span> Link Here
843
        [% END %]
911
        [% END %]
844
        <input type="submit" name="renew_checked" value="Renew or Return checked items" />
912
        <input type="submit" name="renew_checked" value="Renew or Return checked items" />
845
        <input type="submit" id="renew_all" name="renew_all" value="Renew all" />
913
        <input type="submit" id="renew_all" name="renew_all" value="Renew all" />
846
        </fieldset>
914
        <br/><br/>
915
        Don't export fields : <input type="text" id="dont_export_fields" name="dont_export_fields" value="[% dont_export_fields %]" title="Use for iso2709 exports" />
916
        <span id="exportmenuc">Export</span>
917
        <input type="hidden" name="op" value="export" />
918
        <input type="hidden" id="export_format" name="format" value="iso2709" />
919
        <input type="hidden" id="dont_export_item" name="dont_export_item" value="0" />
920
        <input type="hidden" id="record_type" name="record_type" value="bibs" />
921
    </fieldset>
847
    [% END %]
922
    [% END %]
848
    </form>
923
    </form>
849
[% ELSE %]
924
[% ELSE %]
Lines 890-896 No patron matched <span class="ex">[% message %]</span> Link Here
890
    [% END %] <!-- /loop relissues -->
965
    [% END %] <!-- /loop relissues -->
891
    <!-- /if relissues -->[% END %]
966
    <!-- /if relissues -->[% END %]
892
[% IF ( relprevissues ) %]
967
[% IF ( relprevissues ) %]
893
<tr><th class="{sorter: false}" colspan="10"><a name="relprevious" id="relprevious"></a>Previous checkouts</th></tr>
968
<tr><th class="{sorter: false}" colspan="11"><a name="relprevious" id="relprevious"></a>Previous checkouts</th></tr>
894
    [% FOREACH relprevissue IN relprevissues %]
969
    [% FOREACH relprevissue IN relprevissues %]
895
    [% IF ( loop.odd ) %]
970
    [% IF ( loop.odd ) %]
896
        <tr>
971
        <tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (-1 / +1 lines)
Lines 102-108 $(document).ready(function() { Link Here
102
        </li>
102
        </li>
103
        <li>
103
        <li>
104
        <label for="dont_export_fields">Don't export fields</label>
104
        <label for="dont_export_fields">Don't export fields</label>
105
        <input id="dont_export_fields" type="text" name="dont_export_fields" />
105
        <input id="dont_export_fields" type="text" name="dont_export_fields" value="[% dont_export_fields %]" />
106
        separate by a blank. (e.g., 100a 200 606)
106
        separate by a blank. (e.g., 100a 200 606)
107
        </li></ol>
107
        </li></ol>
108
    </fieldset>
108
    </fieldset>
(-)a/tools/export.pl (-139 / +169 lines)
Lines 19-24 Link Here
19
19
20
use strict;
20
use strict;
21
use warnings;
21
use warnings;
22
use List::MoreUtils qw(uniq);
22
use C4::Auth;
23
use C4::Auth;
23
use C4::Output;
24
use C4::Output;
24
use C4::Biblio;  # GetMarcBiblio GetXmlBiblio
25
use C4::Biblio;  # GetMarcBiblio GetXmlBiblio
Lines 26-37 use C4::AuthoritiesMarc; # GetAuthority Link Here
26
use CGI;
27
use CGI;
27
use C4::Koha;    # GetItemTypes
28
use C4::Koha;    # GetItemTypes
28
use C4::Branch;  # GetBranches
29
use C4::Branch;  # GetBranches
30
use C4::Record;
31
use C4::Csv;
29
32
30
my $query = new CGI;
33
my $query = new CGI;
31
my $op=$query->param("op") || '';
34
my $op=$query->param("op") || '';
32
my $filename=$query->param("filename");
35
my $filename=$query->param("filename") || 'koha.mrc';
33
my $dbh=C4::Context->dbh;
36
my $dbh=C4::Context->dbh;
34
my $marcflavour = C4::Context->preference("marcflavour");
37
my $marcflavour = C4::Context->preference("marcflavour");
38
my $format      = $query->param("format") || 'iso2709';
35
39
36
my ($template, $loggedinuser, $cookie)
40
my ($template, $loggedinuser, $cookie)
37
    = get_template_and_user
41
    = get_template_and_user
Lines 58-227 my ($template, $loggedinuser, $cookie) Link Here
58
	}
62
	}
59
63
60
if ($op eq "export") {
64
if ($op eq "export") {
61
    binmode STDOUT, ':encoding(UTF-8)';
65
    if ( $format eq "iso2709" ) {
62
	print $query->header(   -type => 'application/octet-stream', 
66
        binmode STDOUT, ':encoding(UTF-8)';
63
                            -charset => 'utf-8',
67
        print $query->header(
64
                            -attachment=>$filename);
68
            -type => 'application/octet-stream',
65
     
69
            -charset => 'utf-8',
66
    my $record_type        = $query->param("record_type");
70
            -attachment=>$filename
67
    my $output_format      = $query->param("output_format");
71
        );
68
    my $dont_export_fields = $query->param("dont_export_fields");
69
    my @sql_params;
70
    my $sql_query;
71
72
72
    my $StartingBiblionumber = $query->param("StartingBiblionumber");
73
        my $record_type        = $query->param("record_type");
73
    my $EndingBiblionumber   = $query->param("EndingBiblionumber");
74
        my $output_format      = $query->param("output_format") || 'marc';
74
    my $itemtype             = $query->param("itemtype");
75
        my $dont_export_fields = $query->param("dont_export_fields");
75
    my $start_callnumber     = $query->param("start_callnumber");
76
        my @biblionumbers      = $query->param("biblionumbers");
76
    my $end_callnumber       = $query->param("end_callnumber");
77
        my @itemnumbers        = $query->param("itemnumbers");
77
    my $start_accession =
78
        my @sql_params;
78
      ( $query->param("start_accession") )
79
        my $sql_query;
79
      ? C4::Dates->new( $query->param("start_accession") )
80
        my @recordids;
80
      : '';
81
    my $end_accession =
82
      ( $query->param("end_accession") )
83
      ? C4::Dates->new( $query->param("end_accession") )
84
      : '';
85
    my $dont_export_items    = $query->param("dont_export_item");
86
    my $strip_nonlocal_items = $query->param("strip_nonlocal_items");
87
81
88
    my $starting_authid = $query->param('starting_authid');
82
        my $StartingBiblionumber = $query->param("StartingBiblionumber");
89
    my $ending_authid   = $query->param('ending_authid');
83
        my $EndingBiblionumber   = $query->param("EndingBiblionumber");
90
    my $authtype        = $query->param('authtype');
84
        my $itemtype             = $query->param("itemtype");
85
        my $start_callnumber     = $query->param("start_callnumber");
86
        my $end_callnumber       = $query->param("end_callnumber");
87
        my $start_accession =
88
          ( $query->param("start_accession") )
89
          ? C4::Dates->new( $query->param("start_accession") )
90
          : '';
91
        my $end_accession =
92
          ( $query->param("end_accession") )
93
          ? C4::Dates->new( $query->param("end_accession") )
94
          : '';
95
        my $dont_export_items    = $query->param("dont_export_item");
96
        my $strip_nonlocal_items = $query->param("strip_nonlocal_items");
91
97
92
    if ( $record_type eq 'bibs' ) {
98
        my $starting_authid = $query->param('starting_authid');
93
        my $items_filter =
99
        my $ending_authid   = $query->param('ending_authid');
94
            $branch || $start_callnumber || $end_callnumber ||
100
        my $authtype        = $query->param('authtype');
95
            $start_accession || $end_accession ||
96
            ($itemtype && C4::Context->preference('item-level_itypes'));
97
        $sql_query = $items_filter ?
98
            "SELECT DISTINCT biblioitems.biblionumber
99
            FROM biblioitems JOIN items
100
            USING (biblionumber) WHERE 1"
101
            :
102
            "SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 ";
103
101
104
        if ( $StartingBiblionumber ) {
102
        if ( $record_type eq 'bibs' and not @biblionumbers ) {
105
            $sql_query .= " AND biblioitems.biblionumber >= ? ";
103
            my $items_filter =
106
            push @sql_params, $StartingBiblionumber;
104
                   $branch
107
        }
105
                || $start_callnumber
106
                || $end_callnumber
107
                || $start_accession
108
                || $end_accession
109
                || ($itemtype && C4::Context->preference('item-level_itypes'));
110
            $sql_query = $items_filter ?
111
                "SELECT DISTINCT biblioitems.biblionumber
112
                FROM biblioitems JOIN items
113
                USING (biblionumber) WHERE 1"
114
                :
115
                "SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 ";
108
116
109
        if ( $EndingBiblionumber ) {
117
            if ( $StartingBiblionumber ) {
110
            $sql_query .= " AND biblioitems.biblionumber <= ? ";
118
                $sql_query .= " AND biblioitems.biblionumber >= ? ";
111
            push @sql_params, $EndingBiblionumber;
119
                push @sql_params, $StartingBiblionumber;
112
        }
120
            }
113
121
114
        if ($branch) {
122
            if ( $EndingBiblionumber ) {
115
            $sql_query .= " AND homebranch = ? ";
123
                $sql_query .= " AND biblioitems.biblionumber <= ? ";
116
            push @sql_params, $branch;
124
                push @sql_params, $EndingBiblionumber;
117
        }
125
            }
118
126
119
        if ($start_callnumber) {
127
            if ($branch) {
120
            $sql_query .= " AND itemcallnumber <= ? ";
128
                $sql_query .= " AND homebranch = ? ";
121
            push @sql_params, $start_callnumber;
129
                push @sql_params, $branch;
122
        }
130
            }
123
131
124
        if ($end_callnumber) {
132
            if ($start_callnumber) {
125
            $sql_query .= " AND itemcallnumber >= ? ";
133
                $sql_query .= " AND itemcallnumber <= ? ";
126
            push @sql_params, $end_callnumber;
134
                push @sql_params, $start_callnumber;
127
        }
135
            }
128
        if ($start_accession) {
129
            $sql_query .= " AND dateaccessioned >= ? ";
130
            push @sql_params, $start_accession->output('iso');
131
        }
132
136
133
        if ($end_accession) {
137
            if ($end_callnumber) {
134
            $sql_query .= " AND dateaccessioned <= ? ";
138
                $sql_query .= " AND itemcallnumber >= ? ";
135
            push @sql_params, $end_accession->output('iso');
139
                push @sql_params, $end_callnumber;
136
        }
140
            }
141
            if ($start_accession) {
142
                $sql_query .= " AND dateaccessioned >= ? ";
143
                push @sql_params, $start_accession->output('iso');
144
            }
137
145
138
        if ( $itemtype ) {
146
            if ($end_accession) {
139
            $sql_query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?";
147
                $sql_query .= " AND dateaccessioned <= ? ";
140
            push @sql_params, $itemtype;
148
                push @sql_params, $end_accession->output('iso');
141
        }
149
            }
142
    }
143
    elsif ( $record_type eq 'auths' ) {
144
        $sql_query =
145
          "SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1";
146
150
147
        if ($starting_authid) {
151
            if ( $itemtype ) {
148
            $sql_query .= " AND auth_header.authid >= ? ";
152
                $sql_query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?";
149
            push @sql_params, $starting_authid;
153
                push @sql_params, $itemtype;
154
            }
150
        }
155
        }
156
        elsif ( $record_type eq 'auths' ) {
157
            $sql_query =
158
              "SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1";
151
159
152
        if ($ending_authid) {
160
            if ($starting_authid) {
153
            $sql_query .= " AND auth_header.authid <= ? ";
161
                $sql_query .= " AND auth_header.authid >= ? ";
154
            push @sql_params, $ending_authid;
162
                push @sql_params, $starting_authid;
155
        }
163
            }
156
164
157
        if ($authtype) {
165
            if ($ending_authid) {
158
            $sql_query .= " AND auth_header.authtypecode = ? ";
166
                $sql_query .= " AND auth_header.authid <= ? ";
159
            push @sql_params, $authtype;
167
                push @sql_params, $ending_authid;
160
        }
168
            }
161
    }
162
169
163
    my $sth = $dbh->prepare($sql_query);
170
            if ($authtype) {
164
    $sth->execute(@sql_params);
171
                $sql_query .= " AND auth_header.authtypecode = ? ";
172
                push @sql_params, $authtype;
173
            }
174
        } elsif ( @biblionumbers ) {
175
            push @recordids, (@biblionumbers);
176
        }
165
177
166
    while ( my ($recordid) = $sth->fetchrow ) {
178
        unless ( @biblionumbers ) {
167
        my $record;
179
            my $sth = $dbh->prepare($sql_query);
168
        if ( $record_type eq 'bibs' ) {
180
            $sth->execute(@sql_params);
169
            $record = eval { GetMarcBiblio($recordid); };
181
            push @recordids, map { map { $$_[0] } $_ } @{$sth->fetchall_arrayref};
182
        }
170
183
171
     # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve
184
        for my $recordid ( uniq @recordids ) {
172
            if ($@) {
185
            my $record;
173
                next;
186
            if ( $record_type eq 'bibs' ) {
174
            }
187
                $record = eval { GetMarcBiblio($recordid); };
175
            next if not defined $record;
188
                # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve
176
            C4::Biblio::EmbedItemsInMarcBiblio( $record, $recordid )
189
                next if $@;
177
              unless $dont_export_items;
190
                next if not defined $record;
178
            if ( $strip_nonlocal_items || $limit_ind_branch ) {
191
                C4::Biblio::EmbedItemsInMarcBiblio( $record, $recordid, \@itemnumbers )
179
                my ( $homebranchfield, $homebranchsubfield ) =
192
                  unless $dont_export_items;
180
                  GetMarcFromKohaField( 'items.homebranch', '' );
193
                if ( $strip_nonlocal_items || $limit_ind_branch || $dont_export_items  ) {
181
                for my $itemfield ( $record->field($homebranchfield) ) {
194
                    my ( $homebranchfield, $homebranchsubfield ) =
195
                      GetMarcFromKohaField( 'items.homebranch', '' );
196
                    for my $itemfield ( $record->field($homebranchfield) ) {
182
197
183
# if stripping nonlocal items, use loggedinuser's branch if they didn't select one
198
    # if stripping nonlocal items, use loggedinuser's branch if they didn't select one
184
                    $branch = C4::Context->userenv->{'branch'} unless $branch;
199
                        $branch = C4::Context->userenv->{'branch'} unless $branch;
185
                    $record->delete_field($itemfield)
200
                        $record->delete_field($itemfield)
186
                      if (
201
                          if ( $dont_export_items || $itemfield->subfield($homebranchsubfield) ne $branch );
187
                        $itemfield->subfield($homebranchsubfield) ne $branch );
202
                    }
188
                }
203
                }
189
            }
204
            }
190
        }
205
            elsif ( $record_type eq 'auths' ) {
191
        elsif ( $record_type eq 'auths' ) {
206
                $record = C4::AuthoritiesMarc::GetAuthority($recordid);
192
            $record = C4::AuthoritiesMarc::GetAuthority($recordid);
207
                next if not defined $record;
193
            next if not defined $record;
208
            }
194
        }
195
209
196
        if ( $dont_export_fields ) {
210
            if ( $dont_export_fields ) {
197
            my @fields = split " ", $dont_export_fields;
211
                my @fields = split " ", $dont_export_fields;
198
            foreach ( @fields ) {
212
                foreach ( @fields ) {
199
                /^(\d*)(\w)?$/;
213
                    /^(\d*)(\w)?$/;
200
                my $field = $1;
214
                    my $field = $1;
201
                my $subfield = $2;
215
                    my $subfield = $2;
202
                # skip if this record doesn't have this field
216
                    # skip if this record doesn't have this field
203
                next if not defined $record->field($field);
217
                    next if not defined $record->field($field);
204
                if( $subfield ) {
218
                    if( $subfield ) {
205
                    $record->field($field)->delete_subfields($subfield);
219
                        $record->field($field)->delete_subfields($subfield);
220
                    }
221
                    else {
222
                        $record->delete_field($record->field($field));
223
                    }
206
                }
224
                }
207
                else {
225
            }
208
                    $record->delete_field($record->field($field));
226
            if ( $output_format eq "xml" ) {
227
                if ($marcflavour eq 'UNIMARC' && $record_type eq 'auths') {
228
                    print $record->as_xml_record('UNIMARCAUTH');
229
                } else {
230
                    print $record->as_xml_record($marcflavour);
209
                }
231
                }
210
            }
232
            }
211
        }
233
            else {
212
        if ( $output_format eq "xml" ) {
234
                print $record->as_usmarc();
213
            if ($marcflavour eq 'UNIMARC' && $record_type eq 'auths') {
214
                print $record->as_xml_record('UNIMARCAUTH');
215
            } else {
216
                print $record->as_xml_record($marcflavour);
217
            }
235
            }
218
        }
236
        }
219
        else {
237
        exit;
220
            print $record->as_usmarc();
238
    }
221
        }
239
    elsif ( $format eq "csv" ) {
240
        my @biblionumbers = uniq $query->param("biblionumbers");
241
        my @itemnumbers   = $query->param("itemnumbers");
242
        my $output = marc2csv(
243
            \@biblionumbers,
244
            GetCsvProfileId(C4::Context->preference('CsvProfileForExport')),
245
            \@itemnumbers,
246
        );
247
        print $query->header(
248
            -type                        => 'application/octet-stream',
249
            -'Content-Transfer-Encoding' => 'binary',
250
            -attachment                  => "export.csv"
251
        );
252
        print $output;
253
        exit;
222
    }
254
    }
223
    exit;
224
225
}    # if export
255
}    # if export
226
256
227
else {
257
else {
Lines 264-269 else { Link Here
264
        itemtypeloop             => \@itemtypesloop,
294
        itemtypeloop             => \@itemtypesloop,
265
        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
295
        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
266
        authtypeloop             => \@authtypesloop,
296
        authtypeloop             => \@authtypesloop,
297
        dont_export_fields       => C4::Context->preference("DontExportFields"),
267
    );
298
    );
268
299
269
    output_html_with_http_headers $query, $cookie, $template->output;
300
    output_html_with_http_headers $query, $cookie, $template->output;
270
- 

Return to bug 7986