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

(-)a/C4/Biblio.pm (-2 / +4 lines)
Lines 2791-2806 sub GetNoZebraIndexes { Link Here
2791
2791
2792
=head2 EmbedItemsInMarcBiblio
2792
=head2 EmbedItemsInMarcBiblio
2793
2793
2794
    EmbedItemsInMarcBiblio($marc, $biblionumber);
2794
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2795
2795
2796
Given a MARC::Record object containing a bib record,
2796
Given a MARC::Record object containing a bib record,
2797
modify it to include the items attached to it as 9XX
2797
modify it to include the items attached to it as 9XX
2798
per the bib's MARC framework.
2798
per the bib's MARC framework.
2799
if $itemnumbers is defined, only specified itemnumbers are embedded
2799
2800
2800
=cut
2801
=cut
2801
2802
2802
sub EmbedItemsInMarcBiblio {
2803
sub EmbedItemsInMarcBiblio {
2803
    my ($marc, $biblionumber) = @_;
2804
    my ($marc, $biblionumber, $itemnumbers) = @_;
2804
    croak "No MARC record" unless $marc;
2805
    croak "No MARC record" unless $marc;
2805
2806
2806
    my $frameworkcode = GetFrameworkCode($biblionumber);
2807
    my $frameworkcode = GetFrameworkCode($biblionumber);
Lines 2813-2818 sub EmbedItemsInMarcBiblio { Link Here
2813
    my @item_fields;
2814
    my @item_fields;
2814
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2815
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2815
    while (my ($itemnumber) = $sth->fetchrow_array) {
2816
    while (my ($itemnumber) = $sth->fetchrow_array) {
2817
        next if $itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2816
        require C4::Items;
2818
        require C4::Items;
2817
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2819
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2818
        push @item_fields, $item_marc->field($itemtag);
2820
        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 358-364 sub marc2endnote { Link Here
358
358
359
=head2 marc2csv - Convert several records from UNIMARC to CSV
359
=head2 marc2csv - Convert several records from UNIMARC to CSV
360
360
361
  my ($csv) = marc2csv($biblios, $csvprofileid);
361
  my ($csv) = marc2csv($biblios, $csvprofileid, $itemnumbers);
362
362
363
Pre and postprocessing can be done through a YAML file
363
Pre and postprocessing can be done through a YAML file
364
364
Lines 368-377 C<$biblio> - a list of biblionumbers Link Here
368
368
369
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)
369
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)
370
370
371
C<$itemnumbers> - a list of itemnumbers to export
372
371
=cut
373
=cut
372
374
373
sub marc2csv {
375
sub marc2csv {
374
    my ($biblios, $id) = @_;
376
    my ($biblios, $id, $itemnumbers) = @_;
375
    my $output;
377
    my $output;
376
    my $csv = Text::CSV::Encoded->new();
378
    my $csv = Text::CSV::Encoded->new();
377
379
Lines 386-394 sub marc2csv { Link Here
386
    eval $preprocess if ($preprocess);
388
    eval $preprocess if ($preprocess);
387
389
388
    my $firstpass = 1;
390
    my $firstpass = 1;
389
    foreach my $biblio (@$biblios) {
391
    if ( $itemnumbers ) {
390
	$output .= marcrecord2csv($biblio, $id, $firstpass, $csv, $fieldprocessing) ;
392
        for my $itemnumber ( @$itemnumbers) {
391
	$firstpass = 0;
393
            my $biblionumber = GetBiblionumberFromItemnumber $itemnumber;
394
            $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] );
395
            $firstpass = 0;
396
        }
397
    } else {
398
        foreach my $biblio (@$biblios) {
399
            $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing );
400
            $firstpass = 0;
401
        }
392
    }
402
    }
393
403
394
    # Postprocessing
404
    # Postprocessing
Lines 411-426 C<$header> - true if the headers are to be printed (typically at first pass) Link Here
411
421
412
C<$csv> - an already initialised Text::CSV object
422
C<$csv> - an already initialised Text::CSV object
413
423
424
C<$fieldprocessing>
425
426
C<$itemnumbers> a list of itemnumbers to export
427
414
=cut
428
=cut
415
429
416
430
417
sub marcrecord2csv {
431
sub marcrecord2csv {
418
    my ($biblio, $id, $header, $csv, $fieldprocessing) = @_;
432
    my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_;
419
    my $output;
433
    my $output;
420
434
421
    # Getting the record
435
    # Getting the record
422
    my $record = GetMarcBiblio($biblio, 1);
436
    my $record = GetMarcBiblio($biblio);
423
    next unless $record;
437
    next unless $record;
438
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblio, $itemnumbers );
424
    # Getting the framework
439
    # Getting the framework
425
    my $frameworkcode = GetFrameworkCode($biblio);
440
    my $frameworkcode = GetFrameworkCode($biblio);
426
441
Lines 527-544 sub marcrecord2csv { Link Here
527
	    my @fields = ($record->field($marcfield));
542
	    my @fields = ($record->field($marcfield));
528
	    my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef);
543
	    my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef);
529
544
530
	    my @valuesarray;
545
        my @valuesarray;
531
	    foreach (@fields) {
546
        foreach (@fields) {
532
		my $value;
547
            my $value;
533
548
534
		# Getting authorised value
549
            # If it is a control field
535
		$value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string;
550
            if ($_->is_control_field) {
551
                $value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string;
552
            } else {
553
                # If it is a field, we gather all subfields, joined by the subfield separator
554
                my @subvaluesarray;
555
                my @subfields = $_->subfields;
556
                foreach my $subfield (@subfields) {
557
                    push (@subvaluesarray, defined $authvalues->{$subfield->[1]} ? $authvalues->{$subfield->[1]} : $subfield->[1]);
558
                }
559
                $value = join ($subfieldseparator, @subvaluesarray);
560
            }
536
561
537
		# Field processing
562
            # Field processing
538
		eval $fieldprocessing if ($fieldprocessing);
563
            eval $fieldprocessing if ($fieldprocessing);
539
564
540
		push @valuesarray, $value;
565
            push @valuesarray, $value;
541
	    }
566
        }
542
	    push (@fieldstab, join($fieldseparator, @valuesarray)); 
567
	    push (@fieldstab, join($fieldseparator, @valuesarray)); 
543
	 }
568
	 }
544
    };
569
    };
(-)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
<<<<<<< HEAD
5462
$DBversion = "3.09.00.023";
5463
$DBversion = "3.09.00.023";
5463
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5464
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5464
    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('SearchEngine','Zebra','Solr|Zebra','Search Engine','Choice')");
5465
    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('SearchEngine','Zebra','Solr|Zebra','Search Engine','Choice')");
Lines 5536-5541 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5536
    SetVersion($DBversion);
5537
    SetVersion($DBversion);
5537
}
5538
}
5538
5539
5540
$DBversion = "3.09.00.XXX";
5541
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5542
    $dbh->do(qq{
5543
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('DontExportFields','','List of fields for non export in circulation.pl (separated by a space)','','');
5544
    });
5545
    print "Upgrade to $DBversion done (Add system preference DontExportFields)\n";
5546
    SetVersion($DBversion);
5547
}
5548
5549
$DBversion = "3.09.00.XXX";
5550
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5551
    $dbh->do(qq{
5552
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('CsvProfileForExport','','Set a profile name for CSV export','','');
5553
    });
5554
    print "Upgrade to $DBversion done (Adds New System preference CsvProfileForExport)\n";
5555
    SetVersion($DBversion)
5556
}
5557
5539
=head1 FUNCTIONS
5558
=head1 FUNCTIONS
5540
5559
5541
=head2 TableExists($table)
5560
=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 108-114 $(document).ready(function() { Link Here
108
        </li>
108
        </li>
109
        <li>
109
        <li>
110
        <label for="dont_export_fields">Don't export fields</label>
110
        <label for="dont_export_fields">Don't export fields</label>
111
        <input id="dont_export_fields" type="text" name="dont_export_fields" />
111
        <input id="dont_export_fields" type="text" name="dont_export_fields" value="[% dont_export_fields %]" />
112
        separate by a blank. (e.g., 100a 200 606)
112
        separate by a blank. (e.g., 100a 200 606)
113
        </li></ol>
113
        </li></ol>
114
    </fieldset>
114
    </fieldset>
(-)a/tools/export.pl (-282 / +440 lines)
Lines 16-41 Link Here
16
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17
# Suite 330, Boston, MA  02111-1307 USA
17
# Suite 330, Boston, MA  02111-1307 USA
18
18
19
19
use Modern::Perl;
20
use strict;
20
use List::MoreUtils qw(uniq);
21
use warnings;
21
use Getopt::Long;
22
use CGI;
22
use C4::Auth;
23
use C4::Auth;
24
use C4::AuthoritiesMarc;    # GetAuthority
25
use C4::Biblio;             # GetMarcBiblio GetXmlBiblio
26
use C4::Branch;             # GetBranches
27
use C4::Csv;
28
use C4::Koha;               # GetItemTypes
23
use C4::Output;
29
use C4::Output;
24
use C4::Biblio;  # GetMarcBiblio GetXmlBiblio
25
use C4::AuthoritiesMarc; # GetAuthority
26
use CGI;
27
use C4::Koha;    # GetItemTypes
28
use C4::Branch;  # GetBranches
29
use C4::Record;
30
use C4::Record;
30
use Getopt::Long;
31
31
32
my $query = new CGI;
32
my $query = new CGI;
33
33
34
my $commandline = 0;
34
my $commandline = 0;
35
my $op;
36
my $filename;
37
my $dbh         = C4::Context->dbh;
38
my $marcflavour = C4::Context->preference("marcflavour");
39
my $clean;
35
my $clean;
40
my $output_format;
36
my $output_format;
41
my $dont_export_items;
37
my $dont_export_items;
Lines 43-48 my $deleted_barcodes; Link Here
43
my $timestamp;
39
my $timestamp;
44
my $record_type;
40
my $record_type;
45
my $help;
41
my $help;
42
my $op       = $query->param("op")       || '';
43
my $filename = $query->param("filename") || 'koha.mrc';
44
my $dbh      = C4::Context->dbh;
45
my $marcflavour = C4::Context->preference("marcflavour");
46
my $format = $query->param("format") || 'iso2709';
46
47
47
# Checks if the script is called from commandline
48
# Checks if the script is called from commandline
48
if ( scalar @ARGV > 0 ) {
49
if ( scalar @ARGV > 0 ) {
Lines 50-67 if ( scalar @ARGV > 0 ) { Link Here
50
    # Getting parameters
51
    # Getting parameters
51
    $op = 'export';
52
    $op = 'export';
52
    GetOptions(
53
    GetOptions(
53
        'format=s' => \$output_format,
54
        'format=s'          => \$output_format,
54
        'date=s' => \$timestamp,
55
        'date=s'            => \$timestamp,
55
        'dont_export_items' => \$dont_export_items,
56
        'dont_export_items' => \$dont_export_items,
56
        'deleted_barcodes' => \$deleted_barcodes,
57
        'deleted_barcodes'  => \$deleted_barcodes,
57
        'clean' => \$clean,
58
        'clean'             => \$clean,
58
        'filename=s' => \$filename,
59
        'filename=s'        => \$filename,
59
        'record-type=s' => \$record_type,
60
        'record-type=s'     => \$record_type,
60
        'help|?' => \$help
61
        'help|?'            => \$help
61
    );
62
    );
62
    $commandline = 1;
63
    $commandline = 1;
63
64
64
65
    if ($help) {
65
    if ($help) {
66
        print <<_USAGE_;
66
        print <<_USAGE_;
67
export.pl [--format=format] [--date=date] [--record-type=TYPE] [--dont_export_items] [--deleted_barcodes] [--clean] --filename=outputfile
67
export.pl [--format=format] [--date=date] [--record-type=TYPE] [--dont_export_items] [--deleted_barcodes] [--clean] --filename=outputfile
Lines 96-409 _USAGE_ Link Here
96
    # Redirect stdout
96
    # Redirect stdout
97
    open STDOUT, ">$filename" if $filename;
97
    open STDOUT, ">$filename" if $filename;
98
98
99
} else {
99
}
100
else {
100
101
101
    $op          = $query->param("op") || '';
102
    $op       = $query->param("op")       || '';
102
    $filename    = $query->param("filename") || 'koha.mrc';
103
    $filename = $query->param("filename") || 'koha.mrc';
103
    $filename =~ s/(\r|\n)//;
104
    $filename =~ s/(\r|\n)//;
104
105
105
}
106
}
106
107
107
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user(
108
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
108
    {
109
    {
109
        template_name => "tools/export.tmpl",
110
        template_name   => "tools/export.tmpl",
110
        query => $query,
111
        query           => $query,
111
        type => "intranet",
112
        type            => "intranet",
112
        authnotrequired => $commandline,
113
        authnotrequired => $commandline,
113
        flagsrequired => {tools => 'export_catalog'},
114
        flagsrequired   => { tools => 'export_catalog' },
114
        debug => 1,
115
        debug           => 1,
115
    }
116
    }
116
);
117
);
117
118
118
my $limit_ind_branch = (
119
my $limit_ind_branch =
119
    C4::Context->preference('IndependantBranches') &&
120
  (      C4::Context->preference('IndependantBranches')
120
    C4::Context->userenv &&
121
      && C4::Context->userenv
121
    !(C4::Context->userenv->{flags} & 1) &&
122
      && !( C4::Context->userenv->{flags} & 1 )
122
    C4::Context->userenv->{branch}
123
      && C4::Context->userenv->{branch} ) ? 1 : 0;
123
) ? 1 : 0;
124
124
125
my $branch = $query->param("branch") || '';
125
my $branch = $query->param("branch") || '';
126
if ( C4::Context->preference("IndependantBranches") &&
126
if (   C4::Context->preference("IndependantBranches")
127
     C4::Context->userenv &&
127
    && C4::Context->userenv
128
     !(C4::Context->userenv->{flags} & 1) ) {
128
    && !( C4::Context->userenv->{flags} & 1 ) )
129
{
129
    $branch = C4::Context->userenv->{'branch'};
130
    $branch = C4::Context->userenv->{'branch'};
130
}
131
}
131
132
132
my $backupdir = C4::Context->config('backupdir');
133
my $backupdir = C4::Context->config('backupdir');
133
warn $backupdir;
134
134
135
if ( $op eq "export" ) {
135
if ($op eq "export") {
136
    if ( $format eq "iso2709" or $format eq "xml" ) {
136
    my $charset  = 'utf-8';
137
        my $charset  = 'utf-8';
137
    my $mimetype = 'application/octet-stream';
138
        my $mimetype = 'application/octet-stream';
138
    binmode STDOUT, ':encoding(UTF-8)';
139
        binmode STDOUT, ':encoding(UTF-8)';
139
    if ( $filename =~ m/\.gz$/ ) {
140
        if ( $filename =~ m/\.gz$/ ) {
140
        $mimetype = 'application/x-gzip';
141
            $mimetype = 'application/x-gzip';
141
        $charset = '';
142
            $charset  = '';
142
        binmode STDOUT;
143
            binmode STDOUT;
143
    } elsif ( $filename =~ m/\.bz2$/ ) {
144
        }
144
        $mimetype = 'application/x-bzip2';
145
        elsif ( $filename =~ m/\.bz2$/ ) {
145
        binmode STDOUT;
146
            $mimetype = 'application/x-bzip2';
146
        $charset = '';
147
            binmode STDOUT;
147
    }
148
            $charset = '';
148
    print $query->header(
149
        }
149
        -type => $mimetype,
150
        print $query->header(
150
        -charset => $charset,
151
            -type       => $mimetype,
151
        -attachment => $filename
152
            -charset    => $charset,
152
    ) unless ($commandline);
153
            -attachment => $filename
153
154
        ) unless ($commandline);
154
    $record_type           = $query->param("record_type") unless ($commandline);
155
155
    $output_format         = $query->param("output_format") || 'marc' unless ($commandline);
156
        $record_type = $query->param("record_type") unless ($commandline);
156
    my $dont_export_fields = $query->param("dont_export_fields");
157
        $output_format = $query->param("output_format") || 'marc'
157
    my @sql_params;
158
          unless ($commandline);
158
    my $sql_query;
159
        my $dont_export_fields = $query->param("dont_export_fields");
159
160
        my @biblionumbers      = $query->param("biblionumbers");
160
    my $StartingBiblionumber = $query->param("StartingBiblionumber");
161
        my @itemnumbers        = $query->param("itemnumbers");
161
    my $EndingBiblionumber   = $query->param("EndingBiblionumber");
162
        my @sql_params;
162
    my $itemtype             = $query->param("itemtype");
163
        my $sql_query;
163
    my $start_callnumber     = $query->param("start_callnumber");
164
        my @recordids;
164
    my $end_callnumber       = $query->param("end_callnumber");
165
165
    $timestamp = ($timestamp) ? C4::Dates->new($timestamp) : '' if ($commandline);
166
        my $StartingBiblionumber = $query->param("StartingBiblionumber");
166
    my $start_accession =
167
        my $EndingBiblionumber   = $query->param("EndingBiblionumber");
167
      ( $query->param("start_accession") )
168
        my $itemtype             = $query->param("itemtype");
168
      ? C4::Dates->new( $query->param("start_accession") )
169
        my $start_callnumber     = $query->param("start_callnumber");
169
      : '';
170
        my $end_callnumber       = $query->param("end_callnumber");
170
    my $end_accession =
171
        $timestamp = ($timestamp) ? C4::Dates->new($timestamp) : ''
171
      ( $query->param("end_accession") )
172
          if ($commandline);
172
      ? C4::Dates->new( $query->param("end_accession") )
173
        my $start_accession =
173
      : '';
174
          ( $query->param("start_accession") )
174
    $dont_export_items    = $query->param("dont_export_item") unless ($commandline);
175
          ? C4::Dates->new( $query->param("start_accession") )
175
    my $strip_nonlocal_items = $query->param("strip_nonlocal_items");
176
          : '';
176
177
        my $end_accession =
177
    my $biblioitemstable = ($commandline and $deleted_barcodes)
178
          ( $query->param("end_accession") )
178
                                ? 'deletedbiblioitems'
179
          ? C4::Dates->new( $query->param("end_accession") )
179
                                : 'biblioitems';
180
          : '';
180
    my $itemstable = ($commandline and $deleted_barcodes)
181
        $dont_export_items = $query->param("dont_export_item")
181
                                ? 'deleteditems'
182
          unless ($commandline);
182
                                : 'items';
183
183
184
        my $strip_nonlocal_items = $query->param("strip_nonlocal_items");
184
    my $starting_authid = $query->param('starting_authid');
185
185
    my $ending_authid   = $query->param('ending_authid');
186
        my $biblioitemstable =
186
    my $authtype        = $query->param('authtype');
187
          ( $commandline and $deleted_barcodes )
187
188
          ? 'deletedbiblioitems'
188
    if ( $record_type eq 'bibs' ) {
189
          : 'biblioitems';
189
        if ($timestamp) {
190
        my $itemstable =
191
          ( $commandline and $deleted_barcodes )
192
          ? 'deleteditems'
193
          : 'items';
194
195
        my $starting_authid = $query->param('starting_authid');
196
        my $ending_authid   = $query->param('ending_authid');
197
        my $authtype        = $query->param('authtype');
198
199
        if ( $record_type eq 'bibs' and not @biblionumbers ) {
200
            if ($timestamp) {
201
190
            # Specific query when timestamp is used
202
            # Specific query when timestamp is used
191
            # Actually it's used only with CLI and so all previous filters
203
            # Actually it's used only with CLI and so all previous filters
192
            # are not used.
204
            # are not used.
193
            # If one day timestamp is used via the web interface, this part will
205
            # If one day timestamp is used via the web interface, this part will
194
            # certainly have to be rewrited
206
            # certainly have to be rewrited
195
            $sql_query = " (
207
                my ( $query, $params ) = construct_query(
196
                SELECT biblionumber
208
                    {
197
                FROM $biblioitemstable
209
                        recordtype       => $record_type,
198
                  LEFT JOIN items USING(biblionumber)
210
                        timestamp        => $timestamp,
199
                WHERE $biblioitemstable.timestamp >= ?
211
                        biblioitemstable => $biblioitemstable,
200
                  OR items.timestamp >= ?
212
                    }
201
            ) UNION (
213
                );
202
                SELECT biblionumber
214
                $sql_query  = $query;
203
                FROM $biblioitemstable
215
                @sql_params = @$params;
204
                  LEFT JOIN deleteditems USING(biblionumber)
205
                WHERE $biblioitemstable.timestamp >= ?
206
                  OR deleteditems.timestamp >= ?
207
            ) ";
208
            my $ts = $timestamp->output('iso');
209
            @sql_params = ($ts, $ts, $ts, $ts);
210
        } else {
211
            my $items_filter =
212
                $branch || $start_callnumber || $end_callnumber ||
213
                $start_accession || $timestamp || $end_accession ||
214
                ($itemtype && C4::Context->preference('item-level_itypes'));
215
            $sql_query = $items_filter ?
216
                "SELECT DISTINCT $biblioitemstable.biblionumber
217
                FROM $biblioitemstable JOIN $itemstable
218
                USING (biblionumber) WHERE 1"
219
                :
220
                "SELECT $biblioitemstable.biblionumber FROM $biblioitemstable WHERE biblionumber >0 ";
221
222
            if ( $StartingBiblionumber ) {
223
                $sql_query .= " AND $biblioitemstable.biblionumber >= ? ";
224
                push @sql_params, $StartingBiblionumber;
225
            }
226
227
            if ( $EndingBiblionumber ) {
228
                $sql_query .= " AND $biblioitemstable.biblionumber <= ? ";
229
                push @sql_params, $EndingBiblionumber;
230
            }
231
216
232
            if ($branch) {
233
                $sql_query .= " AND homebranch = ? ";
234
                push @sql_params, $branch;
235
            }
217
            }
236
218
            else {
237
            if ($start_callnumber) {
219
                my ( $query, $params ) = construct_query(
238
                $sql_query .= " AND itemcallnumber <= ? ";
220
                    {
239
                push @sql_params, $start_callnumber;
221
                        recordtype           => $record_type,
222
                        biblioitemstable     => $biblioitemstable,
223
                        itemstable           => $itemstable,
224
                        StartingBiblionumber => $StartingBiblionumber,
225
                        EndingBiblionumber   => $EndingBiblionumber,
226
                        branch               => $branch,
227
                        start_callnumber     => $start_callnumber,
228
                        end_callnumber       => $end_callnumber,
229
                        start_accession      => $start_accession,
230
                        end_accession        => $end_accession,
231
                        itemtype             => $itemtype,
232
                    }
233
                );
234
                $sql_query  = $query;
235
                @sql_params = @$params;
240
            }
236
            }
237
        }
238
        elsif ( $record_type eq 'auths' ) {
239
            my ( $query, $params ) = construct_query(
240
                {
241
                    recordtype      => $record_type,
242
                    starting_authid => $starting_authid,
243
                    ending_authid   => $ending_authid,
244
                    authtype        => $authtype,
245
                }
246
            );
247
            $sql_query  = $query;
248
            @sql_params = @$params;
241
249
242
            if ($end_callnumber) {
250
        }
243
                $sql_query .= " AND itemcallnumber >= ? ";
251
        elsif ( $record_type eq 'db' ) {
244
                push @sql_params, $end_callnumber;
252
            my $successful_export;
253
            if ( $flags->{superlibrarian}
254
                && C4::Context->config('backup_db_via_tools') )
255
            {
256
                $successful_export = download_backup(
257
                    {
258
                        directory => "$backupdir",
259
                        extension => 'sql',
260
                        filename  => "$filename"
261
                    }
262
                );
245
            }
263
            }
246
            if ($start_accession) {
264
            unless ($successful_export) {
247
                $sql_query .= " AND dateaccessioned >= ? ";
265
                my $remotehost = $query->remote_host();
248
                push @sql_params, $start_accession->output('iso');
266
                $remotehost =~ s/(\n|\r)//;
267
                warn
268
"A suspicious attempt was made to download the db at '$filename' by someone at "
269
                  . $remotehost . "\n";
249
            }
270
            }
250
271
            exit;
251
            if ($end_accession) {
272
        }
252
                $sql_query .= " AND dateaccessioned <= ? ";
273
        elsif ( $record_type eq 'conf' ) {
253
                push @sql_params, $end_accession->output('iso');
274
            my $successful_export;
275
            if ( $flags->{superlibrarian}
276
                && C4::Context->config('backup_conf_via_tools') )
277
            {
278
                $successful_export = download_backup(
279
                    {
280
                        directory => "$backupdir",
281
                        extension => 'tar',
282
                        filename  => "$filename"
283
                    }
284
                );
254
            }
285
            }
255
286
            unless ($successful_export) {
256
            if ( $itemtype ) {
287
                my $remotehost = $query->remote_host();
257
                $sql_query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?";
288
                $remotehost =~ s/(\n|\r)//;
258
                push @sql_params, $itemtype;
289
                warn
290
"A suspicious attempt was made to download the configuration at '$filename' by someone at "
291
                  . $remotehost . "\n";
259
            }
292
            }
293
            exit;
260
        }
294
        }
261
    }
295
        elsif (@biblionumbers) {
262
    elsif ( $record_type eq 'auths' ) {
296
            push @recordids, (@biblionumbers);
263
        $sql_query =
264
          "SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1";
265
266
        if ($starting_authid) {
267
            $sql_query .= " AND auth_header.authid >= ? ";
268
            push @sql_params, $starting_authid;
269
        }
297
        }
298
        else {
270
299
271
        if ($ending_authid) {
300
            # Someone is trying to mess us up
272
            $sql_query .= " AND auth_header.authid <= ? ";
301
            exit;
273
            push @sql_params, $ending_authid;
274
        }
302
        }
275
303
276
        if ($authtype) {
304
        unless (@biblionumbers) {
277
            $sql_query .= " AND auth_header.authtypecode = ? ";
305
            my $sth = $dbh->prepare($sql_query);
278
            push @sql_params, $authtype;
306
            $sth->execute(@sql_params);
279
        }
307
            push @recordids, map {
280
    }
308
                map { $$_[0] } $_
281
    elsif ( $record_type eq 'db' ) {
309
            } @{ $sth->fetchall_arrayref };
282
        my $successful_export;
283
        if ( $flags->{superlibrarian} && C4::Context->config('backup_db_via_tools') ) {
284
            $successful_export = download_backup( { directory => "$backupdir", extension => 'sql', filename => "$filename" } )
285
        }
286
        unless ( $successful_export ) {
287
            my $remotehost = $query->remote_host();
288
            $remotehost =~ s/(\n|\r)//;
289
            warn "A suspicious attempt was made to download the db at '$filename' by someone at " . $remotehost . "\n";
290
        }
291
        exit;
292
    }
293
    elsif ( $record_type eq 'conf' ) {
294
        my $successful_export;
295
        if ( $flags->{superlibrarian} && C4::Context->config('backup_conf_via_tools') ) {
296
            $successful_export = download_backup( { directory => "$backupdir", extension => 'tar', filename => "$filename" } )
297
        }
310
        }
298
        unless ( $successful_export ) {
299
            my $remotehost = $query->remote_host();
300
            $remotehost =~ s/(\n|\r)//;
301
            warn "A suspicious attempt was made to download the configuration at '$filename' by someone at " . $remotehost . "\n";
302
        }
303
        exit;
304
    }
305
    else {
306
        # Someone is trying to mess us up
307
        exit;
308
    }
309
311
310
    my $sth = $dbh->prepare($sql_query);
312
        for my $recordid ( uniq @recordids ) {
311
    $sth->execute(@sql_params);
313
            if ($deleted_barcodes) {
312
314
                my $q = "
313
    while ( my ($recordid) = $sth->fetchrow ) {
315
                    SELECT DISTINCT barcode
314
        if ( $deleted_barcodes ) {
316
                    FROM deleteditems
315
            my $q = "
317
                    WHERE deleteditems.biblionumber = ?
316
                SELECT DISTINCT barcode
318
                ";
317
                FROM deleteditems
319
                my $sth = $dbh->prepare($q);
318
                WHERE deleteditems.biblionumber = ?
320
                $sth->execute($recordid);
319
            ";
321
                while ( my $row = $sth->fetchrow_array ) {
320
            my $sth = $dbh->prepare($q);
322
                    print "$row\n";
321
            $sth->execute($recordid);
322
            while (my $row = $sth->fetchrow_array) {
323
                print "$row\n";
324
            }
325
        } else {
326
            my $record;
327
            if ( $record_type eq 'bibs' ) {
328
                $record = eval { GetMarcBiblio($recordid); };
329
330
                if ($@) {
331
                    next;
332
                }
323
                }
333
                next if not defined $record;
324
            }
334
                C4::Biblio::EmbedItemsInMarcBiblio( $record, $recordid )
325
            else {
335
                  unless $dont_export_items;
326
                my $record;
336
                if ( $strip_nonlocal_items || $limit_ind_branch ) {
327
                if ( $record_type eq 'bibs' ) {
337
                    my ( $homebranchfield, $homebranchsubfield ) =
328
                    $record = eval { GetMarcBiblio($recordid); };
338
                      GetMarcFromKohaField( 'items.homebranch', '' );
329
339
                    for my $itemfield ( $record->field($homebranchfield) ) {
330
                    next if $@;
340
331
                    next if not defined $record;
341
    # if stripping nonlocal items, use loggedinuser's branch if they didn't select one
332
                    C4::Biblio::EmbedItemsInMarcBiblio( $record, $recordid,
342
                        $branch = C4::Context->userenv->{'branch'} unless $branch;
333
                        \@itemnumbers )
343
                        $record->delete_field($itemfield)
334
                      unless $dont_export_items;
344
                          if (
335
                    if (   $strip_nonlocal_items
345
                            $itemfield->subfield($homebranchsubfield) ne $branch );
336
                        || $limit_ind_branch
337
                        || $dont_export_items )
338
                    {
339
                        my ( $homebranchfield, $homebranchsubfield ) =
340
                          GetMarcFromKohaField( 'items.homebranch', '' );
341
                        for my $itemfield ( $record->field($homebranchfield) ) {
342
343
# if stripping nonlocal items, use loggedinuser's branch if they didn't select one
344
                            $branch = C4::Context->userenv->{'branch'}
345
                              unless $branch;
346
                            $record->delete_field($itemfield)
347
                              if ( $dont_export_items
348
                                || $itemfield->subfield($homebranchsubfield) ne
349
                                $branch );
350
                        }
346
                    }
351
                    }
347
                }
352
                }
348
            }
353
                elsif ( $record_type eq 'auths' ) {
349
            elsif ( $record_type eq 'auths' ) {
354
                    $record = C4::AuthoritiesMarc::GetAuthority($recordid);
350
                $record = C4::AuthoritiesMarc::GetAuthority($recordid);
355
                    next if not defined $record;
351
                next if not defined $record;
356
                }
352
            }
353
357
354
            if ( $dont_export_fields ) {
358
                if ($dont_export_fields) {
355
                my @fields = split " ", $dont_export_fields;
359
                    my @fields = split " ", $dont_export_fields;
356
                foreach ( @fields ) {
360
                    foreach (@fields) {
357
                    /^(\d*)(\w)?$/;
361
                        /^(\d*)(\w)?$/;
358
                    my $field = $1;
362
                        my $field    = $1;
359
                    my $subfield = $2;
363
                        my $subfield = $2;
360
                    # skip if this record doesn't have this field
364
361
                    next if not defined $record->field($field);
365
                        # skip if this record doesn't have this field
362
                    if( $subfield ) {
366
                        next if not defined $record->field($field);
363
                        $record->field($field)->delete_subfields($subfield);
367
                        if ($subfield) {
368
                            $record->field($field)->delete_subfields($subfield);
369
                        }
370
                        else {
371
                            $record->delete_field( $record->field($field) );
372
                        }
373
                    }
374
                }
375
                RemoveAllNsb($record) if ($clean);
376
                if ( $output_format eq "xml" ) {
377
                    if ( $marcflavour eq 'UNIMARC' && $record_type eq 'auths' )
378
                    {
379
                        print $record->as_xml_record('UNIMARCAUTH');
364
                    }
380
                    }
365
                    else {
381
                    else {
366
                        $record->delete_field($record->field($field));
382
                        print $record->as_xml_record($marcflavour);
367
                    }
383
                    }
368
                }
384
                }
369
            }
385
                else {
370
            RemoveAllNsb($record) if ($clean);
386
                    print $record->as_usmarc();
371
            if ( $output_format eq "xml" ) {
372
                if ($marcflavour eq 'UNIMARC' && $record_type eq 'auths') {
373
                    print $record->as_xml_record('UNIMARCAUTH');
374
                } else {
375
                    print $record->as_xml_record($marcflavour);
376
                }
387
                }
377
            }
388
            }
378
            else {
379
                print $record->as_usmarc();
380
            }
381
        }
389
        }
390
        exit;
391
    }
392
    elsif ( $format eq "csv" ) {
393
        my @biblionumbers = uniq $query->param("biblionumbers");
394
        my @itemnumbers   = $query->param("itemnumbers");
395
        my $output =
396
          marc2csv( \@biblionumbers,
397
            GetCsvProfileId( C4::Context->preference('CsvProfileForExport') ),
398
            \@itemnumbers, );
399
        print $query->header(
400
            -type                        => 'application/octet-stream',
401
            -'Content-Transfer-Encoding' => 'binary',
402
            -attachment                  => "export.csv"
403
        );
404
        print $output;
405
        exit;
382
    }
406
    }
383
    exit;
384
385
}    # if export
407
}    # if export
386
408
387
else {
409
else {
388
410
389
    my $itemtypes = GetItemTypes;
411
    my $itemtypes = GetItemTypes;
390
    my @itemtypesloop;
412
    my @itemtypesloop;
391
    foreach my $thisitemtype (sort keys %$itemtypes) {
413
    foreach my $thisitemtype ( sort keys %$itemtypes ) {
392
        my %row =
414
        my %row = (
393
            (
415
            value       => $thisitemtype,
394
                value => $thisitemtype,
416
            description => $itemtypes->{$thisitemtype}->{'description'},
395
                description => $itemtypes->{$thisitemtype}->{'description'},
417
        );
396
            );
418
        push @itemtypesloop, \%row;
397
       push @itemtypesloop, \%row;
398
    }
419
    }
399
    my $branches = GetBranches($limit_ind_branch);
420
    my $branches = GetBranches($limit_ind_branch);
400
    my @branchloop;
421
    my @branchloop;
401
    for my $thisbranch (
422
    for my $thisbranch (
402
        sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} }
423
        sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} }
403
        keys %{$branches}
424
        keys %{$branches}
404
      ) {
425
      )
426
    {
405
        push @branchloop,
427
        push @branchloop,
406
          { value      => $thisbranch,
428
          {
429
            value      => $thisbranch,
407
            selected   => $thisbranch eq $branch,
430
            selected   => $thisbranch eq $branch,
408
            branchname => $branches->{$thisbranch}->{'branchname'},
431
            branchname => $branches->{$thisbranch}->{'branchname'},
409
          };
432
          };
Lines 420-433 else { Link Here
420
        push @authtypesloop, \%row;
443
        push @authtypesloop, \%row;
421
    }
444
    }
422
445
423
    if ( $flags->{superlibrarian} && C4::Context->config('backup_db_via_tools') && $backupdir && -d $backupdir ) {
446
    if (   $flags->{superlibrarian}
447
        && C4::Context->config('backup_db_via_tools')
448
        && $backupdir
449
        && -d $backupdir )
450
    {
424
        $template->{VARS}->{'allow_db_export'} = 1;
451
        $template->{VARS}->{'allow_db_export'} = 1;
425
        $template->{VARS}->{'dbfiles'} = getbackupfilelist( { directory => "$backupdir", extension => 'sql' } );
452
        $template->{VARS}->{'dbfiles'}         = getbackupfilelist(
453
            { directory => "$backupdir", extension => 'sql' } );
426
    }
454
    }
427
455
428
    if ( $flags->{superlibrarian} && C4::Context->config('backup_conf_via_tools') && $backupdir && -d $backupdir ) {
456
    if (   $flags->{superlibrarian}
457
        && C4::Context->config('backup_conf_via_tools')
458
        && $backupdir
459
        && -d $backupdir )
460
    {
429
        $template->{VARS}->{'allow_conf_export'} = 1;
461
        $template->{VARS}->{'allow_conf_export'} = 1;
430
        $template->{VARS}->{'conffiles'} = getbackupfilelist( { directory => "$backupdir", extension => 'tar' } );
462
        $template->{VARS}->{'conffiles'}         = getbackupfilelist(
463
            { directory => "$backupdir", extension => 'tar' } );
431
    }
464
    }
432
465
433
    $template->param(
466
    $template->param(
Lines 441-456 else { Link Here
441
    output_html_with_http_headers $query, $cookie, $template->output;
474
    output_html_with_http_headers $query, $cookie, $template->output;
442
}
475
}
443
476
477
sub construct_query {
478
    my ($params) = @_;
479
480
    my ( $sql_query, @sql_params );
481
482
    if ( $params->{recordtype} eq "bibs" ) {
483
        if ( $params->{timestamp} ) {
484
            my $biblioitemstable = $params->{biblioitemstable};
485
            $sql_query = " (
486
                SELECT biblionumber
487
                FROM $biblioitemstable
488
                  LEFT JOIN items USING(biblionumber)
489
                WHERE $biblioitemstable.timestamp >= ?
490
                  OR items.timestamp >= ?
491
            ) UNION (
492
                SELECT biblionumber
493
                FROM $biblioitemstable
494
                  LEFT JOIN deleteditems USING(biblionumber)
495
                WHERE $biblioitemstable.timestamp >= ?
496
                  OR deleteditems.timestamp >= ?
497
            ) ";
498
            my $ts = $timestamp->output('iso');
499
            @sql_params = ( $ts, $ts, $ts, $ts );
500
        }
501
        else {
502
            my $biblioitemstable     = $params->{biblioitemstable};
503
            my $itemstable           = $params->{itemstable};
504
            my $StartingBiblionumber = $params->{StartingBiblionumber};
505
            my $EndingBiblionumber   = $params->{EndingBiblionumber};
506
            my $branch               = $params->{branch};
507
            my $start_callnumber     = $params->{start_callnumber};
508
            my $end_callnumber       = $params->{end_callnumber};
509
            my $start_accession      = $params->{star_accession};
510
            my $end_accession        = $params->{end_accession};
511
            my $itemtype             = $params->{itemtype};
512
            my $items_filter =
513
                 $branch
514
              || $start_callnumber
515
              || $end_callnumber
516
              || $start_accession
517
              || $end_accession
518
              || ( $itemtype && C4::Context->preference('item-level_itypes') );
519
            $sql_query = $items_filter
520
              ? "SELECT DISTINCT $biblioitemstable.biblionumber
521
                FROM $biblioitemstable JOIN $itemstable
522
                USING (biblionumber) WHERE 1"
523
              : "SELECT $biblioitemstable.biblionumber FROM $biblioitemstable WHERE biblionumber >0 ";
524
525
            if ($StartingBiblionumber) {
526
                $sql_query .= " AND $biblioitemstable.biblionumber >= ? ";
527
                push @sql_params, $StartingBiblionumber;
528
            }
529
530
            if ($EndingBiblionumber) {
531
                $sql_query .= " AND $biblioitemstable.biblionumber <= ? ";
532
                push @sql_params, $EndingBiblionumber;
533
            }
534
535
            if ($branch) {
536
                $sql_query .= " AND homebranch = ? ";
537
                push @sql_params, $branch;
538
            }
539
540
            if ($start_callnumber) {
541
                $sql_query .= " AND itemcallnumber <= ? ";
542
                push @sql_params, $start_callnumber;
543
            }
544
545
            if ($end_callnumber) {
546
                $sql_query .= " AND itemcallnumber >= ? ";
547
                push @sql_params, $end_callnumber;
548
            }
549
            if ($start_accession) {
550
                $sql_query .= " AND dateaccessioned >= ? ";
551
                push @sql_params, $start_accession->output('iso');
552
            }
553
554
            if ($end_accession) {
555
                $sql_query .= " AND dateaccessioned <= ? ";
556
                push @sql_params, $end_accession->output('iso');
557
            }
558
559
            if ($itemtype) {
560
                $sql_query .=
561
                  ( C4::Context->preference('item-level_itypes') )
562
                  ? " AND items.itype = ? "
563
                  : " AND biblioitems.itemtype = ?";
564
                push @sql_params, $itemtype;
565
            }
566
        }
567
    }
568
    elsif ( $params->{recordtype} eq "auths" ) {
569
        if ( $params->{timestamp} ) {
570
571
            #TODO
572
        }
573
        else {
574
            my $starting_authid = $params->{starting_authid};
575
            my $ending_authid   = $params->{ending_authid};
576
            my $authtype        = $params->{authtype};
577
            $sql_query =
578
              "SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1";
579
580
            if ($starting_authid) {
581
                $sql_query .= " AND auth_header.authid >= ? ";
582
                push @sql_params, $starting_authid;
583
            }
584
585
            if ($ending_authid) {
586
                $sql_query .= " AND auth_header.authid <= ? ";
587
                push @sql_params, $ending_authid;
588
            }
589
590
            if ($authtype) {
591
                $sql_query .= " AND auth_header.authtypecode = ? ";
592
                push @sql_params, $authtype;
593
            }
594
        }
595
    }
596
    return ( $sql_query, \@sql_params );
597
}
598
444
sub getbackupfilelist {
599
sub getbackupfilelist {
445
    my $args = shift;
600
    my $args      = shift;
446
    my $directory = $args->{directory};
601
    my $directory = $args->{directory};
447
    my $extension = $args->{extension};
602
    my $extension = $args->{extension};
448
    my @files;
603
    my @files;
449
604
450
    if ( opendir(my $dir, $directory) ) {
605
    if ( opendir( my $dir, $directory ) ) {
451
        while (my $file = readdir($dir)) {
606
        while ( my $file = readdir($dir) ) {
452
            next unless ( $file =~ m/\.$extension(\.(gz|bz2|xz))?/ );
607
            next unless ( $file =~ m/\.$extension(\.(gz|bz2|xz))?/ );
453
            push @files, $file if ( -f "$backupdir/$file" && -r "$backupdir/$file" );
608
            push @files, $file
609
              if ( -f "$backupdir/$file" && -r "$backupdir/$file" );
454
        }
610
        }
455
        closedir($dir);
611
        closedir($dir);
456
    }
612
    }
Lines 458-477 sub getbackupfilelist { Link Here
458
}
614
}
459
615
460
sub download_backup {
616
sub download_backup {
461
    my $args = shift;
617
    my $args      = shift;
462
    my $directory = $args->{directory};
618
    my $directory = $args->{directory};
463
    my $extension = $args->{extension};
619
    my $extension = $args->{extension};
464
    my $filename  = $args->{filename};
620
    my $filename  = $args->{filename};
465
621
466
    return unless ( $directory && -d $directory );
622
    return unless ( $directory && -d $directory );
467
    return unless ( $filename =~ m/$extension(\.(gz|bz2|xz))?$/ && not $filename =~ m#|# );
623
    return
624
      unless ( $filename =~ m/$extension(\.(gz|bz2|xz))?$/
625
        && not $filename =~ m#|# );
468
    $filename = "$directory/$filename";
626
    $filename = "$directory/$filename";
469
    return unless ( -f $filename && -r $filename );
627
    return unless ( -f $filename && -r $filename );
470
    return unless ( open(my $dump, '<', $filename) );
628
    return unless ( open( my $dump, '<', $filename ) );
471
    binmode $dump;
629
    binmode $dump;
472
    while (read($dump, my $data, 64 * 1024)) {
630
631
    while ( read( $dump, my $data, 64 * 1024 ) ) {
473
        print $data;
632
        print $data;
474
    }
633
    }
475
    close ($dump);
634
    close($dump);
476
    return 1;
635
    return 1;
477
}
636
}
478
- 

Return to bug 7986