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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (-1 / +74 lines)
Lines 2-7 Link Here
2
<title>Koha &rsaquo; Tools &rsaquo; MARC export</title>
2
<title>Koha &rsaquo; Tools &rsaquo; MARC export</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'calendar.inc' %]
4
[% INCLUDE 'calendar.inc' %]
5
<script type="text/javascript">
6
//<![CDATA[
7
$(document).ready(function() {
8
    $('#exporttype').tabs();
9
});
10
//]]>
11
</script>
5
</head>
12
</head>
6
<body id="tools_export" class="tools">
13
<body id="tools_export" class="tools">
7
[% INCLUDE 'header.inc' %]
14
[% INCLUDE 'header.inc' %]
Lines 15-20 Link Here
15
	<div id="yui-main">
22
	<div id="yui-main">
16
	<div class="yui-b">
23
	<div class="yui-b">
17
24
25
<div id="exporttype" class="toptabs">
26
<ul>
27
<li><a href="#bibs">Export bibliographic records</a></li>
28
<li><a href="#auths">Export authority records</a></li>
29
</ul>
30
<div id="bibs">
18
<p>
31
<p>
19
    <b>Note : The items are exported by this tool unless specified.</b>
32
    <b>Note : The items are exported by this tool unless specified.</b>
20
</p>
33
</p>
Lines 110-118 Link Here
110
        </li></ol>
123
        </li></ol>
111
    </fieldset>
124
    </fieldset>
112
    <input type="hidden" name="op" value="export" />
125
    <input type="hidden" name="op" value="export" />
126
    <input type="hidden" name="record_type" value="bibs" />
113
127
114
    <fieldset class="action"><input type="submit" value="Export" class="button" /></fieldset>
128
    <fieldset class="action"><input type="submit" value="Export bibliographic records" class="button" /></fieldset>
115
</form>
129
</form>
130
</div>
131
132
<div id="auths">
133
<form method="post" action="/cgi-bin/koha/tools/export.pl">
134
    <fieldset class="rows">
135
    <legend> Select records to export </legend>
136
        <ol><li>
137
            <label for="start">From authid: </label>
138
            <input id="start" type="text" name="starting_authid" size="6" />
139
        </li>
140
        <li>
141
            <label for="end">To authid: </label>
142
            <input id="end" type="text" name="ending_authid" size="6" />
143
        </li>
144
        <li>
145
            <label for="authtype">Authority type: </label>
146
            <select name="authtype" id="authtype">
147
                <option value="">-- All --</option>
148
                [% FOREACH authtypeloo IN authtypeloop %]
149
                [% IF ( authtypeloo.selected ) %]
150
                <option value="[% authtypeloo.value %]" selected="selected">[% authtypeloo.description %]</option>
151
[% ELSE %]
152
                <option value="[% authtypeloo.value %]">[% authtypeloo.description %]</option>
153
[% END %]
154
                [% END %]
155
            </select>
156
        </li>
157
        </ol>
158
    </fieldset>
159
    <fieldset class="rows">
160
    <legend>Options</legend>
161
        <ol>
162
        <li>
163
            <label for="dont_export_fields">Don't export fields</label>
164
            <input id="dont_export_fields" type="text" name="dont_export_fields" />
165
            separate by a blank. (e.g., 100a 200 606)
166
        </li></ol>
167
    </fieldset>
168
    <fieldset class="rows">
169
    <legend>Output format</legend>
170
        <ol><li>
171
            <label for="output_format">File format: </label>
172
            <select id="output_format" name="output_format">
173
                <option value="marc">marc</option>
174
                <option value="xml">xml</option>
175
            </select>
176
        </li>
177
        <li>
178
        <label for="filename">File name:</label><input id="filename" type="text" name="filename" value="koha.mrc" />
179
        </li></ol>
180
    </fieldset>
181
    <input type="hidden" name="op" value="export" />
182
    <input type="hidden" name="record_type" value="auths" />
183
184
    <fieldset class="action"><input type="submit" value="Export authority records" class="button" /></fieldset>
185
</form>
186
</div>
187
188
</div>
116
189
117
</div>
190
</div>
118
</div>
191
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (-2 / +2 lines)
Lines 113-120 Link Here
113
    [% END %]
113
    [% END %]
114
    
114
    
115
    [% IF ( CAN_user_tools_export_catalog ) %]
115
    [% IF ( CAN_user_tools_export_catalog ) %]
116
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export bibliographic and holdings</a></dt>
116
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt>
117
    <dd>Export bibliographic and holdings data</dd>
117
    <dd>Export bibliographic, holdings, and authority records</dd>
118
    [% END %]
118
    [% END %]
119
119
120
    [% IF ( CAN_user_tools_inventory ) %]
120
    [% IF ( CAN_user_tools_inventory ) %]
(-)a/tools/export.pl (-81 / +140 lines)
Lines 22-27 use warnings; Link Here
22
use C4::Auth;
22
use C4::Auth;
23
use C4::Output;
23
use C4::Output;
24
use C4::Biblio;  # GetMarcBiblio GetXmlBiblio
24
use C4::Biblio;  # GetMarcBiblio GetXmlBiblio
25
use C4::AuthoritiesMarc; # GetAuthority
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
Lines 62-150 if ($op eq "export") { Link Here
62
                            -charset => 'utf-8',
63
                            -charset => 'utf-8',
63
                            -attachment=>$filename);
64
                            -attachment=>$filename);
64
     
65
     
65
    my $StartingBiblionumber  = $query->param("StartingBiblionumber");
66
    my $record_type        = $query->param("record_type");
66
    my $EndingBiblionumber    = $query->param("EndingBiblionumber");
67
    my $output_format      = $query->param("output_format");
67
    my $output_format         = $query->param("output_format");
68
    my $dont_export_fields = $query->param("dont_export_fields");
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;
69
    my @sql_params;
77
    
70
    my $sql_query;
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 $itemtype             = $query->param("itemtype");
102
    }
75
    my $start_callnumber     = $query->param("start_callnumber");
76
    my $end_callnumber       = $query->param("end_callnumber");
77
    my $start_accession =
78
      ( $query->param("start_accession") )
79
      ? C4::Dates->new( $query->param("start_accession") )
80
      : '';
81
    my $end_accession =
82
      ( $query->param("end_accession") )
83
      ? C4::Dates->new( $query->param("end_accession") )
84
      : '';
85
    my $dont_export_items    = $query->param("dont_export_item");
86
    my $strip_nonlocal_items = $query->param("strip_nonlocal_items");
103
87
104
    if ($start_callnumber) {
88
    my $starting_authid = $query->param('starting_authid');
105
        $query .= " AND itemcallnumber <= ? ";
89
    my $ending_authid   = $query->param('ending_authid');
106
        push @sql_params, $start_callnumber;
90
    my $authtype        = $query->param('authtype');
107
    }
108
91
109
    if ($end_callnumber) {
92
    if ( $record_type eq 'bibs' ) {
110
        $query .= " AND itemcallnumber >= ? ";
93
        my $items_filter =
111
        push @sql_params, $end_callnumber;
94
            $branch || $start_callnumber || $end_callnumber ||
112
    }
95
            $start_accession || $end_accession ||
113
    if ($start_accession) {
96
            ($itemtype && C4::Context->preference('item-level_itypes'));
114
        $query .= " AND dateaccessioned >= ? ";
97
        $sql_query = $items_filter ?
115
        push @sql_params, $start_accession->output('iso');
98
            "SELECT DISTINCT biblioitems.biblionumber
116
    }
99
            FROM biblioitems JOIN items
100
            USING (biblionumber) WHERE 1"
101
            :
102
            "SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 ";
103
104
        if ( $StartingBiblionumber ) {
105
            $sql_query .= " AND biblioitems.biblionumber >= ? ";
106
            push @sql_params, $StartingBiblionumber;
107
        }
108
109
        if ( $EndingBiblionumber ) {
110
            $sql_query .= " AND biblioitems.biblionumber <= ? ";
111
            push @sql_params, $EndingBiblionumber;
112
        }
113
114
        if ($branch) {
115
            $sql_query .= " AND homebranch = ? ";
116
            push @sql_params, $branch;
117
        }
118
119
        if ($start_callnumber) {
120
            $sql_query .= " AND itemcallnumber <= ? ";
121
            push @sql_params, $start_callnumber;
122
        }
123
124
        if ($end_callnumber) {
125
            $sql_query .= " AND itemcallnumber >= ? ";
126
            push @sql_params, $end_callnumber;
127
        }
128
        if ($start_accession) {
129
            $sql_query .= " AND dateaccessioned >= ? ";
130
            push @sql_params, $start_accession->output('iso');
131
        }
132
133
        if ($end_accession) {
134
            $sql_query .= " AND dateaccessioned <= ? ";
135
            push @sql_params, $end_accession->output('iso');
136
        }
117
137
118
    if ($end_accession) {
138
        if ( $itemtype ) {
119
        $query .= " AND dateaccessioned <= ? ";
139
            $sql_query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?";
120
        push @sql_params, $end_accession->output('iso');
140
            push @sql_params, $itemtype;
141
        }
121
    }
142
    }
122
    
143
    elsif ( $record_type eq 'auths' ) {
123
    if ( $itemtype ) {
144
        $sql_query =
124
        $query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?";
145
          "SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1";
125
        push @sql_params, $itemtype;
146
147
        if ($starting_authid) {
148
            $sql_query .= " AND auth_header.authid >= ? ";
149
            push @sql_params, $starting_authid;
150
        }
151
152
        if ($ending_authid) {
153
            $sql_query .= " AND auth_header.authid <= ? ";
154
            push @sql_params, $ending_authid;
155
        }
156
157
        if ($authtype) {
158
            $sql_query .= " AND auth_header.authtypecode = ? ";
159
            push @sql_params, $authtype;
160
        }
126
    }
161
    }
127
    my $sth = $dbh->prepare($query);
162
163
    my $sth = $dbh->prepare($sql_query);
128
    $sth->execute(@sql_params);
164
    $sth->execute(@sql_params);
129
    
165
130
    while (my ($biblionumber) = $sth->fetchrow) {
166
    while ( my ($recordid) = $sth->fetchrow ) {
131
        my $record = eval{ GetMarcBiblio($biblionumber); };
167
        my $record;
132
        # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve
168
        if ( $record_type eq 'bibs' ) {
133
        if ($@) {
169
            $record = eval { GetMarcBiblio($recordid); };
134
            next;
170
135
        }
171
     # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve
136
        next if not defined $record;
172
            if ($@) {
137
        C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) unless $dont_export_items;
173
                next;
138
        if ($strip_nonlocal_items || $limit_ind_branch) {
174
            }
139
            my ( $homebranchfield, $homebranchsubfield ) =
175
            next if not defined $record;
140
                GetMarcFromKohaField( 'items.homebranch', '' );
176
            C4::Biblio::EmbedItemsInMarcBiblio( $record, $recordid )
141
			for my $itemfield ($record->field($homebranchfield)){
177
              unless $dont_export_items;
142
				# if stripping nonlocal items, use loggedinuser's branch if they didn't select one
178
            if ( $strip_nonlocal_items || $limit_ind_branch ) {
143
				$branch = C4::Context->userenv->{'branch'} unless $branch;
179
                my ( $homebranchfield, $homebranchsubfield ) =
144
                $record->delete_field($itemfield) if($itemfield->subfield($homebranchsubfield) ne $branch) ;
180
                  GetMarcFromKohaField( 'items.homebranch', '' );
181
                for my $itemfield ( $record->field($homebranchfield) ) {
182
183
# if stripping nonlocal items, use loggedinuser's branch if they didn't select one
184
                    $branch = C4::Context->userenv->{'branch'} unless $branch;
185
                    $record->delete_field($itemfield)
186
                      if (
187
                        $itemfield->subfield($homebranchsubfield) ne $branch );
188
                }
145
            }
189
            }
146
        }
190
        }
147
        
191
        elsif ( $record_type eq 'auths' ) {
192
            $record = C4::AuthoritiesMarc::GetAuthority($recordid);
193
            next if not defined $record;
194
        }
195
148
        if ( $dont_export_fields ) {
196
        if ( $dont_export_fields ) {
149
            my @fields = split " ", $dont_export_fields;
197
            my @fields = split " ", $dont_export_fields;
150
            foreach ( @fields ) {
198
            foreach ( @fields ) {
Lines 165-176 if ($op eq "export") { Link Here
165
            print $record->as_xml_record($marcflavour);
213
            print $record->as_xml_record($marcflavour);
166
        }
214
        }
167
        else {
215
        else {
168
            print $record->as_usmarc(); 
216
            print $record->as_usmarc();
169
        }
217
        }
170
    }
218
    }
171
    exit;
219
    exit;
172
    
220
173
} # if export
221
}    # if export
174
222
175
else {
223
else {
176
224
Lines 196-206 else { Link Here
196
          };
244
          };
197
    }
245
    }
198
246
247
    my $authtypes = getauthtypes;
248
    my @authtypesloop;
249
    foreach my $thisauthtype ( sort keys %$authtypes ) {
250
        next unless $thisauthtype;
251
        my %row = (
252
            value       => $thisauthtype,
253
            description => $authtypes->{$thisauthtype}->{'authtypetext'},
254
        );
255
        push @authtypesloop, \%row;
256
    }
257
199
    $template->param(
258
    $template->param(
200
        branchloop   => \@branchloop,
259
        branchloop               => \@branchloop,
201
        itemtypeloop => \@itemtypesloop,
260
        itemtypeloop             => \@itemtypesloop,
202
		DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
261
        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
262
        authtypeloop             => \@authtypesloop,
203
    );
263
    );
204
    
264
205
    output_html_with_http_headers $query, $cookie, $template->output;
265
    output_html_with_http_headers $query, $cookie, $template->output;
206
}
266
}
207
- 

Return to bug 8202