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

(-)a/C4/Biblio.pm (-2 / +4 lines)
Lines 2789-2804 sub GetNoZebraIndexes { Link Here
2789
2789
2790
=head2 EmbedItemsInMarcBiblio
2790
=head2 EmbedItemsInMarcBiblio
2791
2791
2792
    EmbedItemsInMarcBiblio($marc, $biblionumber);
2792
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2793
2793
2794
Given a MARC::Record object containing a bib record,
2794
Given a MARC::Record object containing a bib record,
2795
modify it to include the items attached to it as 9XX
2795
modify it to include the items attached to it as 9XX
2796
per the bib's MARC framework.
2796
per the bib's MARC framework.
2797
if $itemnumbers is defined, only specified itemnumbers are embedded
2797
2798
2798
=cut
2799
=cut
2799
2800
2800
sub EmbedItemsInMarcBiblio {
2801
sub EmbedItemsInMarcBiblio {
2801
    my ($marc, $biblionumber) = @_;
2802
    my ($marc, $biblionumber, $itemnumbers) = @_;
2802
    croak "No MARC record" unless $marc;
2803
    croak "No MARC record" unless $marc;
2803
2804
2804
    my $frameworkcode = GetFrameworkCode($biblionumber);
2805
    my $frameworkcode = GetFrameworkCode($biblionumber);
Lines 2811-2816 sub EmbedItemsInMarcBiblio { Link Here
2811
    my @item_fields;
2812
    my @item_fields;
2812
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2813
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2813
    while (my ($itemnumber) = $sth->fetchrow_array) {
2814
    while (my ($itemnumber) = $sth->fetchrow_array) {
2815
        next if $itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2814
        require C4::Items;
2816
        require C4::Items;
2815
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2817
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2816
        push @item_fields, $item_marc->field($itemtag);
2818
        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 730-735 $template->param( Link Here
730
	AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
730
	AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
731
    dateformat                => C4::Context->preference("dateformat"),
731
    dateformat                => C4::Context->preference("dateformat"),
732
    DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar(),
732
    DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar(),
733
    dont_export_fields        => C4::Context->preference("DontExportFields"),
734
    csv_profil_for_export     => C4::Context->preference("CsvProfilForExport"),
733
    canned_bor_notes_loop     => $canned_notes,
735
    canned_bor_notes_loop     => $canned_notes,
734
);
736
);
735
737
(-)a/installer/data/mysql/updatedatabase.pl (+22 lines)
Lines 5308-5313 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5308
    SetVersion ($DBversion);
5308
    SetVersion ($DBversion);
5309
}
5309
}
5310
5310
5311
5312
5313
5314
5315
$DBversion = "3.07.00.XXX";
5316
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5317
    $dbh->do(qq{
5318
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('DontExportFields','','List of fields for non export in circulation.pl (separated by a space)','','');
5319
    });
5320
    print "Upgrade to $DBversion done (Add system preference DontExportFields)\n";
5321
    SetVersion($DBversion);
5322
}
5323
5324
$DBversion = "3.07.00.XXX";
5325
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5326
    $dbh->do(qq{
5327
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('CsvProfileForExport','','Set a profile name for CSV export','','');
5328
    });
5329
    print "Upgrade to $DBversion done (Adds New System preference CsvProfileForExport)\n";
5330
    SetVersion($DBversion)
5331
}
5332
5311
=head1 FUNCTIONS
5333
=head1 FUNCTIONS
5312
5334
5313
=head2 TableExists($table)
5335
=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 75-80 var allcheckboxes = $(".checkboxed"); Link Here
75
		$(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]"); return false;
75
		$(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]"); return false;
76
	});
76
	});
77
77
78
    $("#CheckAllexports").click(function(){
79
        $(".checkboxed").checkCheckboxes(":input[name*=biblionumbers]");
80
        $(".checkboxed").unCheckCheckboxes(":input[name*=items]");
81
        return false;
82
    });
83
    $("#CheckNoexports").click(function(){
84
        $(".checkboxed").unCheckCheckboxes(":input[name*=biblionumbers]");
85
        return false;
86
    });
78
    $("#relrenew_all").click(function(){
87
    $("#relrenew_all").click(function(){
79
        $(allcheckboxes).checkCheckboxes(":input[name*=items]");
88
        $(allcheckboxes).checkCheckboxes(":input[name*=items]");
80
        $(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]");
89
        $(allcheckboxes).unCheckCheckboxes(":input[name*=barcodes]");
Lines 137-147 var allcheckboxes = $(".checkboxed"); Link Here
137
		$("#add_message_form").show();
146
		$("#add_message_form").show();
138
	 });
147
	 });
139
148
140
     $("input.radio").click(function(){
149
    $("input.radio").click(function(){
141
        radioCheckBox($(this));
150
        radioCheckBox($(this));
142
     });
151
    });
152
    $("#exportmenuc").empty();
153
    initExportButton();
154
155
    var optionsFilters = {
156
        additionalFilterTriggers: [$('#quickfind')],
157
        clearFiltersControls: [$('#cleanfilters')],
158
        selectOptionLabel: [_('...')],
159
    };
160
    $('#issuest').tableFilter(optionsFilters);
143
 });
161
 });
144
162
163
function initExportButton() {
164
    var exportmenu = [
165
        { text: _("ISO2709 with items"), onclick: {fn: function(){export_submit("iso2709_995")}} },
166
        { text: _("ISO2709 without items"), onclick: {fn: function(){export_submit("iso2709")}} },
167
        { text: _("CSV"), onclick: {fn: function(){export_submit("csv")}} },
168
    ];
169
    new YAHOO.widget.Button({
170
        type: "menu",
171
        label: _("Export"),
172
        name: "exportmenubutton",
173
        menu: exportmenu,
174
        container: "exportmenuc"
175
    });
176
}
177
178
function export_submit(format) {
179
    if ($("input:checkbox[name='biblionumbers'][checked]").length < 1){
180
        alert(_("You must select a checkout to export"));
181
        return;
182
    }
183
184
    $("input:checkbox[name='biblionumbers']").each( function(){
185
        var input_item = $(this).siblings("input:checkbox");
186
        if ( $(this).is(":checked") ) {
187
            $(input_item).attr("checked", "checked");
188
        } else {
189
            $(input_item).attr("checked", "");
190
        }
191
    } );
192
193
    if (format == 'iso2709_995') {
194
        format = 'iso2709';
195
        $("#dont_export_item").val(0);
196
    } else if (format == 'iso2709') {
197
        $("#dont_export_item").val(1);
198
    } else {
199
        [% IF NOT ( csv_profil_for_export ) %]
200
            alert(_("You must defined a csv profil for export (in tools>CSV export profiles)"));
201
            return false;
202
        [% END %]
203
    }
204
    document.issues.action="/cgi-bin/koha/tools/export.pl";
205
    document.getElementById("export_format").value = format;
206
    document.issues.submit();
207
208
    /* Reset form action to its initial value */
209
    document.issues.action="/cgi-bin/koha/reserve/renewscript.pl";
210
211
};
212
145
function validate1(date) {
213
function validate1(date) {
146
    var today = new Date();
214
    var today = new Date();
147
    if ( date < today ) {
215
    if ( date < today ) {
Lines 691-697 No patron matched <span class="ex">[% message %]</span> Link Here
691
<!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
759
<!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
692
<div id="checkouts">
760
<div id="checkouts">
693
[% IF ( issuecount ) %]
761
[% IF ( issuecount ) %]
694
    <form action="/cgi-bin/koha/reserve/renewscript.pl" method="post" class="checkboxed">
762
    <div class="search_filters" style="display: block; margin: 0.5em;">
763
        <label for="filter">Quick Find: </label>
764
        <input type="text" id="quickfind"/>
765
        <a id="cleanfilters" href="#">Clear Filters</a>
766
    </div>
767
    <form name="issues" action="/cgi-bin/koha/reserve/renewscript.pl" method="post" class="checkboxed">
695
    <input type="hidden" value="circ" name="destination" />
768
    <input type="hidden" value="circ" name="destination" />
696
    <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
769
    <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
697
    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
770
    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
Lines 708-713 No patron matched <span class="ex">[% message %]</span> Link Here
708
        <th scope="col">Price</th>
781
        <th scope="col">Price</th>
709
        <th scope="col">Renew <p class="column-tool"><a href="#" id="CheckAllitems">select all</a> | <a href="#" id="CheckNoitems">none</a></p></th>
782
        <th scope="col">Renew <p class="column-tool"><a href="#" id="CheckAllitems">select all</a> | <a href="#" id="CheckNoitems">none</a></p></th>
710
        <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">Check in <p class="column-tool"><a href="#" id="CheckAllreturns">select all</a> | <a href="#" id="CheckNoreturns">none</a></p></th>
784
        <th scope="col">Export <p class="column-tool"><a href="#" id="CheckAllexports">select all</a> | <a href="#" id="CheckNoexports">none</a></p></th>
711
    </tr>
785
    </tr>
712
[% IF ( todayissues ) %]</thead>
786
[% IF ( todayissues ) %]</thead>
713
[% INCLUDE 'checkouts-table-footer.inc' %]
787
[% INCLUDE 'checkouts-table-footer.inc' %]
Lines 781-788 No patron matched <span class="ex">[% message %]</span> Link Here
781
    [% END %] <!-- /loop todayissues -->
855
    [% END %] <!-- /loop todayissues -->
782
    <!-- /if todayissues -->[% END %]
856
    <!-- /if todayissues -->[% END %]
783
[% IF ( previssues ) %]
857
[% IF ( previssues ) %]
784
[% IF ( todayissues ) %]<tr><th colspan="10"><a name="previous" id="previous"></a>Previous checkouts</th></tr>[% ELSE %]
858
[% IF ( todayissues ) %]<tr><th colspan="11"><a name="previous" id="previous"></a>Previous checkouts</th></tr>[% ELSE %]
785
<tr><th class="{sorter: false}" colspan="10"><a name="previous" id="previous"></a>Previous checkouts</th></tr></thead>
859
<tr><th class="{sorter: false}" colspan="11"><a name="previous" id="previous"></a>Previous checkouts</th></tr></thead>
786
[% INCLUDE 'checkouts-table-footer.inc' %]
860
[% INCLUDE 'checkouts-table-footer.inc' %]
787
	<tbody>
861
	<tbody>
788
[% END %]
862
[% END %]
Lines 851-856 No patron matched <span class="ex">[% message %]</span> Link Here
851
                <input type="checkbox" name="all_barcodes[]" value="[% previssue.barcode %]" checked="checked" style="display: none;" />
925
                <input type="checkbox" name="all_barcodes[]" value="[% previssue.barcode %]" checked="checked" style="display: none;" />
852
            </td>
926
            </td>
853
            [% END %]
927
            [% END %]
928
            <td style="text-align:center;">
929
                <input type="checkbox" id="export_[% previssue.biblionumber %]" name="biblionumbers" value="[% previssue.biblionumber %]" />
930
                <input type="checkbox" name="itemnumbers" value="[% previssue.itemnumber %]" style="visibility:hidden;" />
931
            </td>
854
      [% END %]
932
      [% END %]
855
    </tr>
933
    </tr>
856
    <!-- /loop previssues -->[% END %]
934
    <!-- /loop previssues -->[% END %]
Lines 867-873 No patron matched <span class="ex">[% message %]</span> Link Here
867
        [% END %]
945
        [% END %]
868
        <input type="submit" name="renew_checked" value="Renew or Return checked items" />
946
        <input type="submit" name="renew_checked" value="Renew or Return checked items" />
869
        <input type="submit" id="renew_all" name="renew_all" value="Renew all" />
947
        <input type="submit" id="renew_all" name="renew_all" value="Renew all" />
870
        </fieldset>
948
        <br/><br/>
949
        Don't export fields : <input type="text" id="dont_export_fields" name="dont_export_fields" value="[% dont_export_fields %]" />
950
        <span id="exportmenuc">Export</span>
951
        <input type="hidden" name="op" value="export" />
952
        <input type="hidden" id="export_format" name="format" value="iso2709" />
953
        <input type="hidden" id="dont_export_item" name="dont_export_item" value="0" />
954
    </fieldset>
871
    [% END %]
955
    [% END %]
872
    </form>
956
    </form>
873
[% ELSE %]
957
[% ELSE %]
Lines 914-920 No patron matched <span class="ex">[% message %]</span> Link Here
914
    [% END %] <!-- /loop relissues -->
998
    [% END %] <!-- /loop relissues -->
915
    <!-- /if relissues -->[% END %]
999
    <!-- /if relissues -->[% END %]
916
[% IF ( relprevissues ) %]
1000
[% IF ( relprevissues ) %]
917
<tr><th class="{sorter: false}" colspan="10"><a name="relprevious" id="relprevious"></a>Previous checkouts</th></tr>
1001
<tr><th class="{sorter: false}" colspan="11"><a name="relprevious" id="relprevious"></a>Previous checkouts</th></tr>
918
    [% FOREACH relprevissue IN relprevissues %]
1002
    [% FOREACH relprevissue IN relprevissues %]
919
    [% IF ( loop.odd ) %]
1003
    [% IF ( loop.odd ) %]
920
        <tr>
1004
        <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