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

(-)a/C4/Biblio.pm (-2 / +4 lines)
Lines 2743-2758 sub GetNoZebraIndexes { Link Here
2743
2743
2744
=head2 EmbedItemsInMarcBiblio
2744
=head2 EmbedItemsInMarcBiblio
2745
2745
2746
    EmbedItemsInMarcBiblio($marc, $biblionumber);
2746
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2747
2747
2748
Given a MARC::Record object containing a bib record,
2748
Given a MARC::Record object containing a bib record,
2749
modify it to include the items attached to it as 9XX
2749
modify it to include the items attached to it as 9XX
2750
per the bib's MARC framework.
2750
per the bib's MARC framework.
2751
if $itemnumbers is defined, only specified itemnumbers are embedded
2751
2752
2752
=cut
2753
=cut
2753
2754
2754
sub EmbedItemsInMarcBiblio {
2755
sub EmbedItemsInMarcBiblio {
2755
    my ($marc, $biblionumber) = @_;
2756
    my ($marc, $biblionumber, $itemnumbers) = @_;
2756
    croak "No MARC record" unless $marc;
2757
    croak "No MARC record" unless $marc;
2757
2758
2758
    my $frameworkcode = GetFrameworkCode($biblionumber);
2759
    my $frameworkcode = GetFrameworkCode($biblionumber);
Lines 2765-2770 sub EmbedItemsInMarcBiblio { Link Here
2765
    my @item_fields;
2766
    my @item_fields;
2766
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2767
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2767
    while (my ($itemnumber) = $sth->fetchrow_array) {
2768
    while (my ($itemnumber) = $sth->fetchrow_array) {
2769
        next if $itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2768
        require C4::Items;
2770
        require C4::Items;
2769
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2771
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2770
        push @item_fields, $item_marc->field($itemtag);
2772
        push @item_fields, $item_marc->field($itemtag);
(-)a/C4/Csv.pm (+13 lines)
Lines 35-40 $VERSION = 3.00; 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 (-9 / +34 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
343
=cut
344
=cut
344
345
345
sub marc2csv {
346
sub marc2csv {
346
    my ($biblios, $id) = @_;
347
    my ( $biblios, $id, $itemnumbers ) = @_;
347
    my $output;
348
    my $output;
348
    my $csv = Text::CSV::Encoded->new();
349
    my $csv = Text::CSV::Encoded->new();
349
350
Lines 358-366 sub marc2csv { Link Here
358
    eval $preprocess if ($preprocess);
359
    eval $preprocess if ($preprocess);
359
360
360
    my $firstpass = 1;
361
    my $firstpass = 1;
361
    foreach my $biblio (@$biblios) {
362
362
	$output .= marcrecord2csv($biblio, $id, $firstpass, $csv, $fieldprocessing) ;
363
    if ( $itemnumbers ) {
363
	$firstpass = 0;
364
        for my $itemnumber ( @$itemnumbers) {
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 503-510 sub marcrecord2csv { Link Here
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);
(-)a/circ/circulation.pl (+2 lines)
Lines 726-731 $template->param( Link Here
726
	AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
726
	AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
727
    dateformat                => C4::Context->preference("dateformat"),
727
    dateformat                => C4::Context->preference("dateformat"),
728
    DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar(),
728
    DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar(),
729
    dont_export_fields        => C4::Context->preference("DontExportFields"),
730
    csv_profil_for_export     => C4::Context->preference("CsvProfilForExport"),
729
    canned_bor_notes_loop     => $canned_notes,
731
    canned_bor_notes_loop     => $canned_notes,
730
);
732
);
731
733
(-)a/installer/data/mysql/updatedatabase.pl (+22 lines)
Lines 5199-5204 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5199
}
5199
}
5200
5200
5201
5201
5202
5203
5204
5205
5206
$DBversion = "3.07.00.XXX";
5207
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5208
    $dbh->do(qq{
5209
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('DontExportFields','','List of fields for non export in circulation.pl (separated by a space)','','');
5210
    });
5211
    print "Upgrade to $DBversion done (Add system preference DontExportFields)\n";
5212
    SetVersion($DBversion);
5213
}
5214
5215
$DBversion = "3.07.00.XXX";
5216
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5217
    $dbh->do(qq{
5218
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('CsvProfileForExport','','Set a profile name for CSV export','','');
5219
    });
5220
    print "Upgrade to $DBversion done (Adds New System preference CsvProfileForExport)\n";
5221
    SetVersion($DBversion)
5222
}
5223
5202
=head1 FUNCTIONS
5224
=head1 FUNCTIONS
5203
5225
5204
=head2 TableExists($table)
5226
=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
			<img src="[% themelang %]/lib/calendar/cal.gif" id="newduedate_button" alt="Show Calendar" />
8
			<img src="[% themelang %]/lib/calendar/cal.gif" id="newduedate_button" alt="Show Calendar" />
9
			<script type="text/javascript"> //<![CDATA[
9
			<script type="text/javascript"> //<![CDATA[
(-)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 103-108 Circulation: Link Here
103
            - pref: NoticeCSS
103
            - pref: NoticeCSS
104
              class: url
104
              class: url
105
            - on Notices. (This should be a complete URL, starting with <code>http://</code>)
105
            - on Notices. (This should be a complete URL, starting with <code>http://</code>)
106
        -
107
            - pref: DontExportFields
108
            - choices:
109
                yes: Export
110
                no: "Don't export"
111
            - fields for csv or iso2709 export
106
    Checkout Policy:
112
    Checkout Policy:
107
        -
113
        -
108
            - pref: AllowNotForLoanOverride
114
            - 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 / +91 lines)
Lines 74-79 var allcheckboxes = $(".checkboxed"); Link Here
74
		$(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]"); return false;
74
		$(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]"); return false;
75
	});
75
	});
76
76
77
    $("#CheckAllexports").click(function(){
78
        $(".checkboxed").checkCheckboxes(":input[name*=biblionumbers]");
79
        $(".checkboxed").unCheckCheckboxes(":input[name*=items]");
80
        return false;
81
    });
82
    $("#CheckNoexports").click(function(){
83
        $(".checkboxed").unCheckCheckboxes(":input[name*=biblionumbers]");
84
        return false;
85
    });
77
    $("#relrenew_all").click(function(){
86
    $("#relrenew_all").click(function(){
78
        $(allcheckboxes).checkCheckboxes(":input[name*=items]");
87
        $(allcheckboxes).checkCheckboxes(":input[name*=items]");
79
        $(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]");
88
        $(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]");
Lines 136-146 var allcheckboxes = $(".checkboxed"); Link Here
136
		$("#add_message_form").show();
145
		$("#add_message_form").show();
137
	 });
146
	 });
138
147
139
     $("input.radio").click(function(){
148
    $("input.radio").click(function(){
140
        radioCheckBox($(this));
149
        radioCheckBox($(this));
141
     });
150
    });
151
    $("#exportmenuc").empty();
152
    initExportButton();
153
154
    var optionsFilters = {
155
        additionalFilterTriggers: [$('#quickfind')],
156
        clearFiltersControls: [$('#cleanfilters')],
157
        selectOptionLabel: [_('...')],
158
    };
159
    $('#issuest').tableFilter(optionsFilters);
142
 });
160
 });
143
161
162
function initExportButton() {
163
    var exportmenu = [
164
        { text: _("ISO2709 with items"), onclick: {fn: function(){export_submit("iso2709_995")}} },
165
        { text: _("ISO2709 without items"), onclick: {fn: function(){export_submit("iso2709")}} },
166
        { text: _("CSV"), onclick: {fn: function(){export_submit("csv")}} },
167
    ];
168
    new YAHOO.widget.Button({
169
        type: "menu",
170
        label: _("Export"),
171
        name: "exportmenubutton",
172
        menu: exportmenu,
173
        container: "exportmenuc"
174
    });
175
}
176
177
function export_submit(format) {
178
    if ($("input:checkbox[name='biblionumbers'][checked]").length < 1){
179
        alert(_("You must select a checkout to export"));
180
        return;
181
    }
182
183
    $("input:checkbox[name='biblionumbers']").each( function(){
184
        var input_item = $(this).siblings("input:checkbox");
185
        if ( $(this).is(":checked") ) {
186
            $(input_item).attr("checked", "checked");
187
        } else {
188
            $(input_item).attr("checked", "");
189
        }
190
    } );
191
192
    if (format == 'iso2709_995') {
193
        format = 'iso2709';
194
        $("#dont_export_item").val(0);
195
    } else if (format == 'iso2709') {
196
        $("#dont_export_item").val(1);
197
    } else {
198
        [% IF NOT ( csv_profil_for_export ) %]
199
            alert(_("You must defined a csv profil for export (in tools>CSV export profiles)"));
200
            return false;
201
        [% END %]
202
    }
203
    document.issues.action="/cgi-bin/koha/tools/export.pl";
204
    document.getElementById("export_format").value = format;
205
    document.issues.submit();
206
207
    /* Reset form action to its initial value */
208
    document.issues.action="/cgi-bin/koha/reserve/renewscript.pl";
209
210
};
211
144
function validate1(date) {
212
function validate1(date) {
145
    var today = new Date();
213
    var today = new Date();
146
    if ( date < today ) {
214
    if ( date < today ) {
Lines 690-696 No patron matched <span class="ex">[% message %]</span> Link Here
690
<!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
758
<!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
691
<div id="checkouts">
759
<div id="checkouts">
692
[% IF ( issuecount ) %]
760
[% IF ( issuecount ) %]
693
    <form action="/cgi-bin/koha/reserve/renewscript.pl" method="post" class="checkboxed">
761
    <div class="search_filters" style="display: block; margin: 0.5em;">
762
        <label for="filter">Quick Find: </label>
763
        <input type="text" id="quickfind"/>
764
        <a id="cleanfilters" href="#">Clear Filters</a>
765
    </div>
766
    <form name="issues" action="/cgi-bin/koha/reserve/renewscript.pl" method="post" class="checkboxed">
694
    <input type="hidden" value="circ" name="destination" />
767
    <input type="hidden" value="circ" name="destination" />
695
    <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
768
    <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
696
    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
769
    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
Lines 707-712 No patron matched <span class="ex">[% message %]</span> Link Here
707
        <th scope="col">Price</th>
780
        <th scope="col">Price</th>
708
        <th scope="col">Renew <p class="column-tool"><a href="#" id="CheckAllitems">select all</a> | <a href="#" id="CheckNoitems">none</a></p></th>
781
        <th scope="col">Renew <p class="column-tool"><a href="#" id="CheckAllitems">select all</a> | <a href="#" id="CheckNoitems">none</a></p></th>
709
        <th scope="col">Check in <p class="column-tool"><a href="#" id="CheckAllreturns">select all</a> | <a href="#" id="CheckNoreturns">none</a></p></th>
782
        <th scope="col">Check in <p class="column-tool"><a href="#" id="CheckAllreturns">select all</a> | <a href="#" id="CheckNoreturns">none</a></p></th>
783
        <th scope="col">Export <p class="column-tool"><a href="#" id="CheckAllexports">select all</a> | <a href="#" id="CheckNoexports">none</a></p></th>
710
    </tr>
784
    </tr>
711
[% IF ( todayissues ) %]</thead>
785
[% IF ( todayissues ) %]</thead>
712
[% INCLUDE 'checkouts-table-footer.inc' %]
786
[% INCLUDE 'checkouts-table-footer.inc' %]
Lines 780-787 No patron matched <span class="ex">[% message %]</span> Link Here
780
    [% END %] <!-- /loop todayissues -->
854
    [% END %] <!-- /loop todayissues -->
781
    <!-- /if todayissues -->[% END %]
855
    <!-- /if todayissues -->[% END %]
782
[% IF ( previssues ) %]
856
[% IF ( previssues ) %]
783
[% IF ( todayissues ) %]<tr><th colspan="10"><a name="previous" id="previous"></a>Previous checkouts</th></tr>[% ELSE %]
857
[% IF ( todayissues ) %]<tr><th colspan="11"><a name="previous" id="previous"></a>Previous checkouts</th></tr>[% ELSE %]
784
<tr><th class="{sorter: false}" colspan="10"><a name="previous" id="previous"></a>Previous checkouts</th></tr></thead>
858
<tr><th class="{sorter: false}" colspan="11"><a name="previous" id="previous"></a>Previous checkouts</th></tr></thead>
785
[% INCLUDE 'checkouts-table-footer.inc' %]
859
[% INCLUDE 'checkouts-table-footer.inc' %]
786
	<tbody>
860
	<tbody>
787
[% END %]
861
[% END %]
Lines 850-855 No patron matched <span class="ex">[% message %]</span> Link Here
850
                <input type="checkbox" name="all_barcodes[]" value="[% previssue.barcode %]" checked="checked" style="display: none;" />
924
                <input type="checkbox" name="all_barcodes[]" value="[% previssue.barcode %]" checked="checked" style="display: none;" />
851
            </td>
925
            </td>
852
            [% END %]
926
            [% END %]
927
            <td style="text-align:center;">
928
                <input type="checkbox" id="export_[% previssue.biblionumber %]" name="biblionumbers" value="[% previssue.biblionumber %]" />
929
                <input type="checkbox" name="itemnumbers" value="[% previssue.itemnumber %]" style="visibility:hidden;" />
930
            </td>
853
      [% END %]
931
      [% END %]
854
    </tr>
932
    </tr>
855
    <!-- /loop previssues -->[% END %]
933
    <!-- /loop previssues -->[% END %]
Lines 866-872 No patron matched <span class="ex">[% message %]</span> Link Here
866
        [% END %]
944
        [% END %]
867
        <input type="submit" name="renew_checked" value="Renew or Return checked items" />
945
        <input type="submit" name="renew_checked" value="Renew or Return checked items" />
868
        <input type="submit" id="renew_all" name="renew_all" value="Renew all" />
946
        <input type="submit" id="renew_all" name="renew_all" value="Renew all" />
869
        </fieldset>
947
        <br/><br/>
948
        Don't export fields : <input type="text" id="dont_export_fields" name="dont_export_fields" value="[% dont_export_fields %]" />
949
        <span id="exportmenuc">Export</span>
950
        <input type="hidden" name="op" value="export" />
951
        <input type="hidden" id="export_format" name="format" value="iso2709" />
952
        <input type="hidden" id="dont_export_item" name="dont_export_item" value="0" />
953
    </fieldset>
870
    [% END %]
954
    [% END %]
871
    </form>
955
    </form>
872
[% ELSE %]
956
[% ELSE %]
Lines 913-919 No patron matched <span class="ex">[% message %]</span> Link Here
913
    [% END %] <!-- /loop relissues -->
997
    [% END %] <!-- /loop relissues -->
914
    <!-- /if relissues -->[% END %]
998
    <!-- /if relissues -->[% END %]
915
[% IF ( relprevissues ) %]
999
[% IF ( relprevissues ) %]
916
<tr><th class="{sorter: false}" colspan="10"><a name="relprevious" id="relprevious"></a>Previous checkouts</th></tr>
1000
<tr><th class="{sorter: false}" colspan="11"><a name="relprevious" id="relprevious"></a>Previous checkouts</th></tr>
917
    [% FOREACH relprevissue IN relprevissues %]
1001
    [% FOREACH relprevissue IN relprevissues %]
918
    [% IF ( loop.odd ) %]
1002
    [% IF ( loop.odd ) %]
919
        <tr>
1003
        <tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (-1 / +1 lines)
Lines 111-117 Calendar.setup( Link Here
111
        </li>
111
        </li>
112
        <li>
112
        <li>
113
        <label for="dont_export_fields">Don't export fields</label>
113
        <label for="dont_export_fields">Don't export fields</label>
114
        <input id="dont_export_fields" type="text" name="dont_export_fields" />
114
        <input id="dont_export_fields" type="text" name="dont_export_fields" value="[% dont_export_fields %]" />
115
        separate by a blank. (e.g., 100a 200 606)
115
        separate by a blank. (e.g., 100a 200 606)
116
        </li></ol>
116
        </li></ol>
117
    </fieldset>
117
    </fieldset>
(-)a/tools/export.pl (-109 / +139 lines)
Lines 19-36 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
25
use CGI;
26
use CGI;
26
use C4::Koha;    # GetItemTypes
27
use C4::Koha;    # GetItemTypes
27
use C4::Branch;  # GetBranches
28
use C4::Branch;  # GetBranches
29
use C4::Record;
30
use C4::Csv;
28
31
29
my $query = new CGI;
32
my $query       = new CGI;
30
my $op=$query->param("op") || '';
33
my $op          = $query->param("op") || '';
31
my $filename=$query->param("filename");
34
my $filename    = $query->param("filename") || 'koha.mrc';
32
my $dbh=C4::Context->dbh;
35
my $dbh         = C4::Context->dbh;
33
my $marcflavour = C4::Context->preference("marcflavour");
36
my $marcflavour = C4::Context->preference("marcflavour");
37
my $format      = $query->param("format") || 'iso2709';
34
38
35
my ($template, $loggedinuser, $cookie)
39
my ($template, $loggedinuser, $cookie)
36
    = get_template_and_user
40
    = get_template_and_user
Lines 57-175 my ($template, $loggedinuser, $cookie) Link Here
57
	}
61
	}
58
62
59
if ($op eq "export") {
63
if ($op eq "export") {
60
    binmode STDOUT, ':encoding(UTF-8)';
64
    if ( $format eq "iso2709" ) {
61
	print $query->header(   -type => 'application/octet-stream', 
65
        binmode STDOUT, ':encoding(UTF-8)';
62
                            -charset => 'utf-8',
66
        print $query->header(
63
                            -attachment=>$filename);
67
            -type => 'application/octet-stream', 
64
     
68
            -charset => 'utf-8',
65
    my $StartingBiblionumber  = $query->param("StartingBiblionumber");
69
            -attachment=>$filename
66
    my $EndingBiblionumber    = $query->param("EndingBiblionumber");
70
        );
67
    my $output_format         = $query->param("output_format");
68
    my $itemtype              = $query->param("itemtype");
69
    my $start_callnumber      = $query->param("start_callnumber");
70
    my $end_callnumber        = $query->param("end_callnumber");
71
    my $start_accession      = ($query->param("start_accession")) ? C4::Dates->new($query->param("start_accession")) : '' ;
72
    my $end_accession        = ($query->param("end_accession")) ? C4::Dates->new($query->param("end_accession")) : '' ;
73
    my $dont_export_items     = $query->param("dont_export_item");
74
    my $strip_nonlocal_items   = $query->param("strip_nonlocal_items");
75
    my $dont_export_fields    = $query->param("dont_export_fields");
76
    my @sql_params;
77
    
78
    my $items_filter =
79
        $branch || $start_callnumber || $end_callnumber ||  
80
        $start_accession || $end_accession || 
81
        ($itemtype && C4::Context->preference('item-level_itypes'));
82
    my $query = $items_filter ?
83
        "SELECT DISTINCT biblioitems.biblionumber
84
         FROM biblioitems JOIN items
85
         USING (biblionumber) WHERE 1"
86
        :
87
        "SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 ";
88
                  
89
    if ( $StartingBiblionumber ) {
90
        $query .= " AND biblioitems.biblionumber >= ? ";
91
        push @sql_params, $StartingBiblionumber;
92
    }
93
    
94
    if ( $EndingBiblionumber ) {
95
        $query .= " AND biblioitems.biblionumber <= ? ";
96
        push @sql_params, $EndingBiblionumber;    
97
    }
98
71
99
    if ($branch) {
72
        my $StartingBiblionumber  = $query->param("StartingBiblionumber");
100
        $query .= " AND homebranch = ? ";
73
        my $EndingBiblionumber    = $query->param("EndingBiblionumber");
101
        push @sql_params, $branch;
74
        my $output_format         = $query->param("output_format") || 'marc';
102
    }
75
        my $itemtype              = $query->param("itemtype");
76
        my $start_callnumber      = $query->param("start_callnumber");
77
        my $end_callnumber        = $query->param("end_callnumber");
78
        my $start_accession       = ($query->param("start_accession")) ? C4::Dates->new($query->param("start_accession")) : '' ;
79
        my $end_accession         = ($query->param("end_accession")) ? C4::Dates->new($query->param("end_accession")) : '' ;
80
        my $dont_export_items     = $query->param("dont_export_item");
81
        my $strip_nonlocal_items  = $query->param("strip_nonlocal_items");
82
        my $dont_export_fields    = $query->param("dont_export_fields");
83
        my @biblionumbers         = $query->param("biblionumbers");
84
        my @itemnumbers           = $query->param("itemnumbers");
85
        my @sql_params;
103
86
104
    if ($start_callnumber) {
87
        if ( not @biblionumbers ) {
105
        $query .= " AND itemcallnumber <= ? ";
88
            my $items_filter =
106
        push @sql_params, $start_callnumber;
89
                   $branch
107
    }
90
                || $start_callnumber
91
                || $end_callnumber
92
                || $start_accession
93
                || $end_accession
94
                || ($itemtype && C4::Context->preference('item-level_itypes'));
95
            my $query = $items_filter
96
                ? "SELECT DISTINCT biblioitems.biblionumber
97
                   FROM biblioitems JOIN items
98
                   USING (biblionumber) WHERE 1"
99
                : "SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 ";
108
100
109
    if ($end_callnumber) {
101
            if ( $StartingBiblionumber ) {
110
        $query .= " AND itemcallnumber >= ? ";
102
                $query .= " AND biblioitems.biblionumber >= ? ";
111
        push @sql_params, $end_callnumber;
103
                push @sql_params, $StartingBiblionumber;
112
    }
104
            }
113
    if ($start_accession) {
114
        $query .= " AND dateaccessioned >= ? ";
115
        push @sql_params, $start_accession->output('iso');
116
    }
117
105
118
    if ($end_accession) {
106
            if ( $EndingBiblionumber ) {
119
        $query .= " AND dateaccessioned <= ? ";
107
                $query .= " AND biblioitems.biblionumber <= ? ";
120
        push @sql_params, $end_accession->output('iso');
108
                push @sql_params, $EndingBiblionumber;    
121
    }
109
            }
122
    
110
123
    if ( $itemtype ) {
111
            if ($branch) {
124
        $query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?";
112
                $query .= " AND homebranch = ? ";
125
        push @sql_params, $itemtype;
113
                push @sql_params, $branch;
126
    }
114
            }
127
    my $sth = $dbh->prepare($query);
115
128
    $sth->execute(@sql_params);
116
            if ($start_callnumber) {
129
    
117
                $query .= " AND itemcallnumber <= ? ";
130
    while (my ($biblionumber) = $sth->fetchrow) {
118
                push @sql_params, $start_callnumber;
131
        my $record = eval{ GetMarcBiblio($biblionumber); };
119
            }
132
        # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve
120
133
        if ($@) {
121
            if ($end_callnumber) {
134
            next;
122
                $query .= " AND itemcallnumber >= ? ";
135
        }
123
                push @sql_params, $end_callnumber;
136
        next if not defined $record;
137
        C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) unless $dont_export_items;
138
        if ($strip_nonlocal_items || $limit_ind_branch) {
139
            my ( $homebranchfield, $homebranchsubfield ) =
140
                GetMarcFromKohaField( 'items.homebranch', '' );
141
			for my $itemfield ($record->field($homebranchfield)){
142
				# if stripping nonlocal items, use loggedinuser's branch if they didn't select one
143
				$branch = C4::Context->userenv->{'branch'} unless $branch;
144
                $record->delete_field($itemfield) if($itemfield->subfield($homebranchsubfield) ne $branch) ;
145
            }
124
            }
125
            if ($start_accession) {
126
                $query .= " AND dateaccessioned >= ? ";
127
                push @sql_params, $start_accession->output('iso');
128
            }
129
130
            if ($end_accession) {
131
                $query .= " AND dateaccessioned <= ? ";
132
                push @sql_params, $end_accession->output('iso');
133
            }
134
135
            if ( $itemtype ) {
136
                $query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?";
137
                push @sql_params, $itemtype;
138
            }
139
            my $sth = $dbh->prepare($query);
140
            $sth->execute(@sql_params);
141
            push @biblionumbers, map { map { $$_[0] } $_ } @{$sth->fetchall_arrayref};
146
        }
142
        }
147
        
143
148
        if ( $dont_export_fields ) {
144
        for my $biblionumber (uniq @biblionumbers) {
149
            my @fields = split " ", $dont_export_fields;
145
            my $record = eval{ GetMarcBiblio($biblionumber); };
150
            foreach ( @fields ) {
146
            # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve
151
                /^(\d*)(\w)?$/;
147
            if ($@) {
152
                my $field = $1;
148
                next;
153
                my $subfield = $2;
149
            }
154
                # skip if this record doesn't have this field
150
            next if not defined $record;
155
                next if not defined $record->field($field);
151
            C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber, \@itemnumbers) unless $dont_export_items;
156
                if( $subfield ) {
152
            if ( $strip_nonlocal_items || $limit_ind_branch || $dont_export_items ) {
157
                    $record->field($field)->delete_subfields($subfield);
153
                my ( $homebranchfield, $homebranchsubfield ) =
154
                    GetMarcFromKohaField( 'items.homebranch', '' );
155
                for my $itemfield ($record->field($homebranchfield)){
156
                    # if stripping nonlocal items, use loggedinuser's branch if they didn't select one
157
                    $branch = C4::Context->userenv->{'branch'} unless $branch;
158
                    $record->delete_field($itemfield) if( $dont_export_items || $itemfield->subfield($homebranchsubfield) ne $branch) ;
158
                }
159
                }
159
                else {
160
            }
160
                    $record->delete_field($record->field($field));
161
162
            if ( $dont_export_fields ) {
163
                my @fields = split " ", $dont_export_fields;
164
                foreach ( @fields ) {
165
                    /^(\d*)(\w)?$/;
166
                    my $field = $1;
167
                    my $subfield = $2;
168
                    # skip if this record doesn't have this field
169
                    next if not defined $record->field($field);
170
                    if( $subfield ) {
171
                        $record->field($field)->delete_subfields($subfield);
172
                    }
173
                    else {
174
                        $record->delete_field($record->field($field));
175
                    }
161
                }
176
                }
162
            }
177
            }
178
            if ( $output_format eq "xml" ) {
179
                print $record->as_xml_record($marcflavour);
180
            }
181
            else {
182
                print $record->as_usmarc(); 
183
            }
163
        }
184
        }
164
        if ( $output_format eq "xml" ) {
185
        exit;
165
            print $record->as_xml_record($marcflavour);
186
    }
166
        }
187
    elsif ( $format eq "csv" ) {
167
        else {
188
        my @biblionumbers = uniq $query->param("biblionumbers");
168
            print $record->as_usmarc(); 
189
        my @itemnumbers          = $query->param("itemnumbers");
169
        }
190
        my $output = marc2csv(
191
            \@biblionumbers,
192
            GetCsvProfileId(C4::Context->preference('CsvProfileForExport')),
193
            \@itemnumbers,
194
        );
195
        print $query->header(
196
            -type                        => 'application/octet-stream',
197
            -'Content-Transfer-Encoding' => 'binary',
198
            -attachment                  => "export.csv"
199
        );
200
        print $output;
201
        exit;
170
    }
202
    }
171
    exit;
172
    
173
} # if export
203
} # if export
174
204
175
else {
205
else {
Lines 199-206 else { Link Here
199
    $template->param(
229
    $template->param(
200
        branchloop   => \@branchloop,
230
        branchloop   => \@branchloop,
201
        itemtypeloop => \@itemtypesloop,
231
        itemtypeloop => \@itemtypesloop,
202
		DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
232
        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
233
        dont_export_fields        => C4::Context->preference("DontExportFields"),
203
    );
234
    );
204
    
235
205
    output_html_with_http_headers $query, $cookie, $template->output;
236
    output_html_with_http_headers $query, $cookie, $template->output;
206
}
237
}
207
- 

Return to bug 7986