return $self->load_myopac_bookbags if $path =~ m|opac/myopac/lists|;
return $self->load_myopac_bookbag_print if $path =~ m|opac/myopac/list/print|;
return $self->load_myopac_bookbag_update if $path =~ m|opac/myopac/list/update|;
+ return $self->load_myopac_circ_history_export if $path =~ m|opac/myopac/circ_history/export|;
return $self->load_myopac_circ_history if $path =~ m|opac/myopac/circ_history|;
return $self->load_myopac_hold_history if $path =~ m|opac/myopac/hold_history|;
return $self->load_myopac_prefs_notify if $path =~ m|opac/myopac/prefs_notify|;
sub load_myopac_bookbag_print {
my ($self) = @_;
- $self->apache->content_type("text/plain; encoding=utf8");
-
my $id = int($self->cgi->param("list"));
my ($sorter, $modifier) = $self->_get_bookbag_sort_params("sort");
# provoke browser download dialogs.
(my $filename = $bbag->id . $bbag->name) =~ s/[^a-z0-9_ -]//gi;
- $self->apache->headers_out->add(
- "Content-Disposition",
- "attachment;filename=$filename.csv"
+ return $self->set_file_download_headers("$filename.csv");
+}
+
+sub load_myopac_circ_history_export {
+ my $self = shift;
+ my $e = $self->editor;
+ my $filename = $self->cgi->param('filename') || 'circ_history.csv';
+
+ my $ids = $e->json_query({
+ select => {
+ au => [{
+ column => 'id',
+ transform => 'action.usr_visible_circs',
+ result_field => 'id'
+ }]
+ },
+ from => 'au',
+ where => {id => $e->requestor->id}
+ });
+
+ $self->ctx->{csv} = $U->fire_object_event(
+ undef,
+ 'circ.format.history.csv',
+ $e->search_action_circulation({id => [map {$_->{id}} @$ids]}, {substream =>1}),
+ $self->editor->requestor->home_ou
);
- return Apache2::Const::OK;
+ return $self->set_file_download_headers($filename);
}
sub load_password_reset {
$ctx->{copy_location_groups} = \%buckets;
}
+sub set_file_download_headers {
+ my $self = shift;
+ my $filename = shift;
+ my $ctype = shift || "text/plain; encoding=utf8";
+
+ $self->apache->content_type($ctype);
+ $self->apache->headers_out->add(
+ "Content-Disposition",
+ "attachment;filename=$filename"
+ );
+
+ return Apache2::Const::OK;
+}
1;
'gui',
'integer'
);
+-- circ export csv export --
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+VALUES (
+ 'circ.format.history.csv',
+ 'circ',
+ oils_i18n_gettext(
+ 'circ.format.history.csv',
+ 'Produce CSV of circulation history',
+ 'ath',
+ 'description'
+ ),
+ FALSE
+);
+
+INSERT INTO action_trigger.event_definition (
+ active, owner, name, hook, reactor, validator, group_field, template)
+VALUES (
+ TRUE, 1, 'Circ History CSV', 'circ.format.history.csv', 'ProcessTemplate', 'NOOP_True', 'usr',
+$$
+Title,Author,Call Number,Barcode,Format
+[%-
+FOR circ IN target;
+ bibxml = helpers.unapi_bre(circ.target_copy.call_number.record, {flesh => '{mra}'});
+ title = "";
+ FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
+ title = title _ part.textContent;
+ END;
+ author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
+ item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value') %]
+
+ [%- helpers.csv_datum(title) -%],
+ [%- helpers.csv_datum(author) -%],
+ [%- helpers.csv_datum(circ.target_copy.call_number.label) -%],
+ [%- helpers.csv_datum(circ.target_copy.barcode) -%],
+ [%- helpers.csv_datum(item_type) %]
+[%- END -%]
+$$
+);
+
+INSERT INTO action_trigger.environment (event_def, path)
+ VALUES (
+ currval('action_trigger.event_definition_id_seq'),
+ 'target_copy.call_number'
+ );
--- /dev/null
+
+BEGIN;
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+VALUES (
+ 'circ.format.history.csv',
+ 'circ',
+ oils_i18n_gettext(
+ 'circ.format.history.csv',
+ 'Produce CSV of circulation history',
+ 'ath',
+ 'description'
+ ),
+ FALSE
+);
+
+INSERT INTO action_trigger.event_definition (
+ active, owner, name, hook, reactor, validator, group_field, template)
+VALUES (
+ TRUE, 1, 'Circ History CSV', 'circ.format.history.csv', 'ProcessTemplate', 'NOOP_True', 'usr',
+$$
+Title,Author,Call Number,Barcode,Format
+[%-
+FOR circ IN target;
+ bibxml = helpers.unapi_bre(circ.target_copy.call_number.record, {flesh => '{mra}'});
+ title = "";
+ FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
+ title = title _ part.textContent;
+ END;
+ author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
+ item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value') %]
+
+ [%- helpers.csv_datum(title) -%],
+ [%- helpers.csv_datum(author) -%],
+ [%- helpers.csv_datum(circ.target_copy.call_number.label) -%],
+ [%- helpers.csv_datum(circ.target_copy.barcode) -%],
+ [%- helpers.csv_datum(item_type) %]
+[%- END -%]
+$$
+);
+
+INSERT INTO action_trigger.environment (event_def, path)
+ VALUES (
+ currval('action_trigger.event_definition_id_seq'),
+ 'target_copy.call_number'
+ );
+
+COMMIT;
+
+/* UNDO
+DELETE FROM action_trigger.event WHERE event_def = (
+ SELECT id FROM action_trigger.event_definition WHERE hook = 'circ.format.history.csv');
+DELETE FROM action_trigger.event_definition WHERE hook = 'circ.format.history.csv');
+DELETE FROM action_trigger.hook WHERE key = 'circ.format.history.csv';
+*/
<a href='[% mkurl('circ_history', {limit => limit, offset => (offset + limit)}) %]'
[% IF ctx.circs.size < limit %] class='invisible' [% END %] >[% l('Next') %]<span class="nav_arrow_fix">►</span></a>
</span>
- <span class="float-right">
- <a class="hide_me" href="#">[% l('Export List') %]</a>
+ <span class="float-left">
+ <form action="[% mkurl(ctx.opac_root _ '/myopac/circ_history/export') %]" method="POST">
+ <div>
+ [%- INCLUDE "opac/parts/preserve_params.tt2" %]
+ <input type="hidden" name="filename" value="[% l('circ_history.csv') %]"/>
+ <button type="submit">[% l('Download CSV') %]</button>
+ </div>
+ </form>
</span>
</div>
<div class="clear-both"></div>
--- /dev/null
+[%- ctx.csv.template_output.data -%]