Browse Source

Bug 14889: Use Koha::BiblioFramework[s] in admin/biblio_framework.pl

Test plan:
Add/edit/remove biblio frameworks from the administration module
(admin/biblio_framework.pl).
You should get message feedback after each action.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
No problems found. Tested add/edit/delete
No koha-qa errors

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
new_12478_elasticsearch
Jonathan Druart 9 years ago
committed by Brendan Gallagher
parent
commit
ba2f667c3c
  1. 202
      admin/biblio_framework.pl
  2. 183
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt

202
admin/biblio_framework.pl

@ -1,10 +1,7 @@
#!/usr/bin/perl
# NOTE: 4-character tabs
#written 20/02/2002 by paul.poulain@free.fr
# This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
# Copyright 2000-2002 Katipo Communications
# Copyright 2002 Paul Poulain
#
# This file is part of Koha.
#
@ -21,131 +18,108 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Context;
use C4::Auth;
use C4::Output;
use Koha::Biblios;
use Koha::BiblioFramework;
use Koha::BiblioFrameworks;
use Koha::Cache;
sub StringSearch {
my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("Select * from biblio_framework where (frameworkcode like ?) order by frameworktext");
$sth->execute((shift || '') . '%');
return $sth->fetchall_arrayref({});
}
my $input = new CGI;
my $script_name = "/cgi-bin/koha/admin/biblio_framework.pl";
my $frameworkcode = $input->param('frameworkcode') || '';
my $offset = $input->param('offset') || 0;
my $op = $input->param('op') || '';
my $pagesize = 20;
my $input = new CGI;
my $frameworkcode = $input->param('frameworkcode') || q||;
my $op = $input->param('op') || q|list|;
my $cache = Koha::Cache->get_instance();
my @messages;
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => "admin/biblio_framework.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 'parameters_remaining_permissions'},
debug => 1,
});
$template->param( script_name => $script_name);
$template->param(($op||'else') => 1);
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{ template_name => "admin/biblio_framework.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { parameters => 'parameters_remaining_permissions' },
debug => 1,
}
);
my $dbh = C4::Context->dbh;
################## ADD_FORM ##################################
# called by default. Used to create form to add or modify a record
if ($op eq 'add_form') {
#start the page and read in includes
#---- if primkey exists, it's a modify action, so read values to modify...
my $data;
if ($frameworkcode) {
my $sth=$dbh->prepare("select * from biblio_framework where frameworkcode=?");
$sth->execute($frameworkcode);
$data=$sth->fetchrow_hashref;
}
$template->param(
frameworkcode => $frameworkcode,
frameworktext => $data->{'frameworktext'},
);
# END $OP eq ADD_FORM
################## ADD_VALIDATE ##################################
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
my $dbh = C4::Context->dbh;
if ( $input->param('frameworktext') and $frameworkcode ) {
if ($input->param('modif')) {
my $sth=$dbh->prepare("UPDATE biblio_framework SET frameworktext=? WHERE frameworkcode=?");
$sth->execute( $input->param('frameworktext'), $frameworkcode );
if ( $op eq 'add_form' ) {
my $framework;
if ($frameworkcode) {
$framework = Koha::BiblioFrameworks->find($frameworkcode);
}
$template->param( framework => $framework );
} elsif ( $op eq 'add_validate' ) {
my $frameworkcode = $input->param('frameworkcode');
my $frameworktext = $input->param('frameworktext');
my $framework = Koha::BiblioFrameworks->find($frameworkcode);
if ($framework) {
$framework->frameworktext($frameworktext);
eval { $framework->store; };
if ($@) {
push @messages, { type => 'error', code => 'error_on_update' };
} else {
my $sth=$dbh->prepare("INSERT into biblio_framework (frameworkcode,frameworktext) values (?,?)");
$sth->execute( $frameworkcode, $input->param('frameworktext') );
push @messages, { type => 'message', code => 'success_on_update' };
}
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
}
print $input->redirect($script_name); # FIXME: unnecessary redirect
exit;
# END $OP eq ADD_VALIDATE
################## DELETE_CONFIRM ##################################
# called by default form, used to confirm deletion of data in DB
} elsif ($op eq 'delete_confirm') {
# Check both categoryitem and biblioitems, see Bug 199
my $sth = $dbh->prepare("select count(*) as total from biblio where frameworkcode=?");
$sth->execute($frameworkcode);
my $total = $sth->fetchrow_hashref->{total};
$sth = $dbh->prepare("select * from biblio_framework where frameworkcode=?");
$sth->execute($frameworkcode);
my $data = $sth->fetchrow_hashref;
} else {
$framework = Koha::BiblioFramework->new(
{ frameworkcode => $frameworkcode,
frameworktext => $frameworktext,
}
);
eval { $framework->store; };
if ($@) {
push @messages, { type => 'error', code => 'error_on_insert' };
} else {
push @messages, { type => 'message', code => 'success_on_insert' };
}
}
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
$op = 'list';
} elsif ( $op eq 'delete_confirm' ) {
my $framework = Koha::BiblioFrameworks->find($frameworkcode);
my $count = Koha::Biblios->search( { frameworkcode => $frameworkcode, } )->count;
$template->param(
frameworkcode => $frameworkcode,
frameworktext => $data->{'frameworktext'},
total => $total
$template->param(
framework => $framework,
biblios_use_this_framework => $count,
);
# END $OP eq DELETE_CONFIRM
################## DELETE_CONFIRMED ##################################
# called by delete_confirm, used to effectively confirm deletion of data in DB
} elsif ($op eq 'delete_confirmed') {
if ($frameworkcode) {
my $sth=$dbh->prepare("delete from marc_tag_structure where frameworkcode=?");
$sth->execute($frameworkcode);
$sth=$dbh->prepare("delete from marc_subfield_structure where frameworkcode=?");
$sth->execute($frameworkcode);
$sth=$dbh->prepare("delete from biblio_framework where frameworkcode=?");
$sth->execute($frameworkcode);
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
}
print $input->redirect($script_name); # FIXME: unnecessary redirect
exit;
# END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
my $results = StringSearch($frameworkcode);
my $count = scalar(@$results);
my @loop_data;
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
push @loop_data, {
frameworkcode => $results->[$i]{'frameworkcode'},
frameworktext => $results->[$i]{'frameworktext'},
} elsif ( $op eq 'delete_confirmed' ) {
my $framework = Koha::BiblioFrameworks->find($frameworkcode);
my $deleted = eval { $framework->delete; };
if ( $@ or not $deleted ) {
push @messages, { type => 'error', code => 'error_on_delete' };
} else {
eval {
my $dbh = C4::Context->dbh;
$dbh->do( q|DELETE FROM marc_tag_structure WHERE frameworkcode=?|, undef, $frameworkcode );
$dbh->do( q|DELETE FROM marc_subfield_structure WHERE frameworkcode=?|, undef, $frameworkcode );
};
}
$template->param(loop => \@loop_data);
if ($offset>0) {
my $prevpage = $offset-$pagesize;
$template->param(previous => "$script_name?offset=".$prevpage);
}
if ($offset+$pagesize<$count) {
my $nextpage =$offset+$pagesize;
$template->param(next => "$script_name?offset=".$nextpage);
}
} #---- END $OP eq DEFAULT
if ($@) {
push @messages, { type => 'error', code => 'error_on_delete_fk' };
} else {
push @messages, { type => 'message', code => 'success_on_delete' };
}
}
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
$op = 'list';
}
if ( $op eq 'list' ) {
my $frameworks = Koha::BiblioFrameworks->search( {}, { order_by => ['frameworktext'], } );
$template->param( frameworks => $frameworks, );
}
$template->param(
messages => \@messages,
op => $op,
);
output_html_with_http_headers $input, $cookie, $template->output;

183
koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt

@ -1,18 +1,29 @@
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Administration &rsaquo; MARC frameworks
[% IF ( add_form ) %]
&rsaquo; [% IF ( frameworkcode ) %]Modify framework text[% ELSE %]Add framework[% END %]
[% ELSIF ( delete_confirm ) %]
&rsaquo; Delete framework for [% frameworktext %] ([% frameworkcode %])?
[% IF op == 'add_form' %]
&rsaquo; [% IF framework %]Modify framework text[% ELSE %]Add framework[% END %]
[% ELSIF op == 'delete_confirm' %]
&rsaquo; Delete framework for [% framework.frameworktext %] ([% framework.frameworkcode %])?
[% END %]
</title>
[% INCLUDE 'doc-head-close.inc' %]
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
[% INCLUDE 'datatables.inc' %]
<script type="text/javascript">
/* Import/Export from/to spreadsheet */
var importing = false;
$(document).ready(function() {
$("#table_biblio_frameworks").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "aTargets": [ -1, -2, -3, -4, -5 ], "bSortable": false, "bSearchable": false },
{ "aTargets": [ 0, 1 ], "sType": "natural" },
],
"bSort": false,
"sPaginationType": "four_button"
}));
$("body").css("cursor", "auto");
$('.import_export_options').hide();
$('a.import_export_fw').click(function() {
@ -87,10 +98,10 @@
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
&rsaquo; <a href="/cgi-bin/koha/admin/biblio_framework.pl">MARC frameworks</a>
[% IF ( add_form ) %]
&rsaquo; [% IF ( frameworkcode ) %]Modify framework text[% ELSE %]Add framework[% END %]
[% ELSIF ( delete_confirm ) %]
&rsaquo; Delete framework for [% frameworktext %] ([% frameworkcode %])?
[% IF op == 'add_form' %]
&rsaquo; [% IF framework %]Modify framework text[% ELSE %]Add framework[% END %]
[% ELSIF op == 'delete_confirm' %]
&rsaquo; Delete framework for [% framework.frameworktext %] ([% framework.frameworkcode %])?
[% END %]
</div>
@ -99,56 +110,90 @@
<div id="yui-main">
<div class="yui-b">
[% IF ( else ) %]
<div id="toolbar" class="btn-toolbar">
<a class="btn btn-small" id="newframework" href="/cgi-bin/koha/admin/biblio_framework.pl?op=add_form"><i class="fa fa-plus"></i> New framework</a>
</div>
[% FOR m IN messages %]
<div class="dialog [% m.type %]">
[% SWITCH m.code %]
[% CASE 'error_on_update' %]
An error occurred when updating this framework. Perhaps it already exists.
[% CASE 'error_on_insert' %]
An error occurred when inserting this framework. The framework might already exist.
[% CASE 'error_on_delete' %]
An error occurred when deleting this framework. Check the logs.
[% CASE 'success_on_update' %]
Framework updated successfully.
[% CASE 'success_on_insert' %]
Framework inserted successfully.
[% CASE 'success_on_delete' %]
Framework deleted successfully.
[% CASE 'already_exists' %]
This framework code already exists.
[% CASE %]
[% m.code %]
[% END %]
</div>
[% END %]
[% IF op == 'list'%]
<div id="toolbar" class="btn-toolbar">
<a class="btn btn-small" id="newframework" href="/cgi-bin/koha/admin/biblio_framework.pl?op=add_form"><i class="fa fa-plus"></i> New framework</a>
</div>
[% END %]
[% IF ( add_form ) %]
<h1>[% IF ( frameworkcode ) %]Modify framework text[% ELSE %]Add framework[% END %]</h1>
<form action="[% script_name %]" name="Aform" method="post" class="validated">
[% IF op == 'add_form' %]
<h1>[% IF framework %]Modify framework text[% ELSE %]Add framework[% END %]</h1>
<form action="/cgi-bin/koha/admin/biblio_framework.pl" name="Aform" method="post" class="validated">
<input type="hidden" name="op" value="add_validate" />
<fieldset class="rows">
<ol>
[% IF ( frameworkcode ) %]
<li><span class="label">Framework code: </span><input type="hidden" id="frameworkcode" name="frameworkcode" value="[% frameworkcode %]" />[% frameworkcode %]
<input type="hidden" name="modif" value="1" />
</li>
[% ELSE %]
<li>
<label for="frameworkcode" class="required">Framework code: </label>
<input type="text" id="frameworkcode" name="frameworkcode" size="4" maxlength="4" onblur="toUC(this)" required="required" class="required" />
<span class="required">Required</span>
</li>
[% END %]
<li>
<label for="description" class="required">Description: </label>
<input type="text" name="frameworktext" id="description" size="40" maxlength="80" value="[% frameworktext |html %]" required="required" class="required" />
<span class="required">Required</span>
</li>
</ol>
</fieldset>
<fieldset class="action"><input type="submit" value="Submit" class="submit" /></fieldset>
<fieldset class="rows">
<ol>
[% IF framework %]
<li>
<span class="label">Framework code: </span>
<input type="hidden" id="frameworkcode" name="frameworkcode" value="[% framework.frameworkcode %]" />[% framework.frameworkcode %]
</li>
[% ELSE %]
<li>
<label for="frameworkcode" class="required">Framework code: </label>
<input type="text" id="frameworkcode" name="frameworkcode" size="4" maxlength="4" onblur="toUC(this)" required="required" class="required" />
<span class="required">Required</span>
</li>
[% END %]
<li>
<label for="description" class="required">Description: </label>
<input type="text" name="frameworktext" id="description" size="40" maxlength="80" value="[% framework.frameworktext |html %]" required="required" class="required" />
<span class="required">Required</span>
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="submit" value="Submit" class="submit" />
</fieldset>
</form>
[% END %]
[% IF ( delete_confirm ) %]
<div class="dialog alert">
<h3>Delete framework for [% frameworktext %] ([% frameworkcode %])?</h3>
[% IF ( total ) %]
<p><strong>This framework is used [% total %] times</strong>.</p>
[% END %]
<form class="inline" action="[% script_name %]" method="post"><input type="hidden" name="op" value="delete_confirmed" /><input type="hidden" name="frameworkcode" value="[% frameworkcode %]" /><input type="submit" class="approve" value="Yes, delete this framework!" />
</form>
<form class="inline" action="[% script_name %]" method="get"><input type="submit" class="deny" value="No, do not delete!" /></form>
</div>
[% IF op == 'delete_confirm' %]
<div class="dialog alert">
<h3>Delete framework for [% framework.frameworktext %] ([% framework.frameworkcode %])?</h3>
[% IF biblios_use_this_framework %]
<p><strong>This framework is used [% biblios_use_this_framework %] times</strong>.</p>
[% END %]
<form class="inline" action="/cgi-bin/koha/admin/biblio_framework.pl" method="post">
<input type="hidden" name="op" value="delete_confirmed" />
<input type="hidden" name="frameworkcode" value="[% framework.frameworkcode %]" />
<input type="submit" class="approve" value="Yes, delete this framework!" />
</form>
<form class="inline" action="/cgi-bin/koha/admin/biblio_framework.pl" method="get">
<input type="submit" class="deny" value="No, do not delete!" />
</form>
</div>
[% END %]
[% IF ( else ) %]
[% IF op == 'list' %]
<h1>MARC frameworks</h1>
<p>Framework name, then go to MARC biblio to set MARC editor parameters</p>
<table>
<table id="table_biblio_frameworks">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
@ -158,29 +203,31 @@
<th title="Export framework structure (fields, subfields) to a spreadsheet file (.csv, .xml, .ods)">Export</th>
<th title="Import framework structure (fields, subfields) from a spreadsheet file (.csv, .xml, .ods)">Import</th>
</tr>
</thead>
<tbody>
<tr>
<td>&nbsp;</td>
<td>Default framework</td>
<td><a href="marctagstructure.pl?frameworkcode=[% frameworkcode %]">MARC structure</a></td>
<td><a href="marctagstructure.pl?frameworkcode=">MARC structure</a></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>
<!-- Button to trigger modal -->
<a href="#" data-toggle="modal" data-target="#exportModal_[% frameworkcode %]">Export</a>
<a href="#" data-toggle="modal" data-target="#exportModal_default">Export</a>
<!-- Modal -->
<div class="modal hide" id="exportModal_[% frameworkcode %]" tabindex="-1" role="dialog" aria-labelledby="exportLabelexportModal_[% frameworkcode %]" aria-hidden="true">
<div class="modal hide" id="exportModal_default" tabindex="-1" role="dialog" aria-labelledby="exportLabelexportModal_default" aria-hidden="true">
<div class="modal-header">
<button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="exportLabelexportModal_[% frameworkcode %]">Export default framework</h3>
<h3 id="exportLabelexportModal_default">Export default framework</h3>
</div>
<form action="import_export_framework.pl" name="form_[% frameworkcode %]" method="get" target="_blank" class="form_export">
<form action="import_export_framework.pl" name="form_defaul" method="get" target="_blank" class="form_export">
<div class="modal-body">
<fieldset>
<input type="hidden" name="frameworkcode" value="[% frameworkcode %]" />
<p><label for="csv_type_export_[% frameworkcode %]"><input type="radio" name="type_export_[% frameworkcode %]" value="csv" id="csv_type_export_[% frameworkcode %]" checked="checked" /> Export to CSV spreadsheet</label></p>
<p><label for="xml_type_export_[% frameworkcode %]"><input type="radio" name="type_export_[% frameworkcode %]" value="excel" id="xml_type_export_[% frameworkcode %]" /> Export to Excel with XML format, compatible with OpenOffice/LibreOffice as well</label></p>
<p><label for="ods_type_export_[% frameworkcode %]"><input type="radio" name="type_export_[% frameworkcode %]" value="ods" id="ods_type_export_[% frameworkcode %]" /> Export to OpenDocument spreadsheet format</label></p>
<input type="hidden" name="frameworkcode" value="" />
<p><label for="csv_type_export_default"><input type="radio" name="type_export_defaul" value="csv" id="csv_type_export_default" checked="checked" /> Export to CSV spreadsheet</label></p>
<p><label for="xml_type_export_default"><input type="radio" name="type_export_default" value="excel" id="xml_type_export_default" /> Export to Excel with XML format, compatible with OpenOffice/LibreOffice as well</label></p>
<p><label for="ods_type_export_default"><input type="radio" name="type_export_default" value="ods" id="ods_type_export_default" /> Export to OpenDocument spreadsheet format</label></p>
</fieldset>
</div>
@ -195,19 +242,19 @@
<td>
<!-- Button to trigger modal -->
<a href="#" data-toggle="modal" data-target="#importModal_[% frameworkcode %][% loop.count %]">Import</a>
<a href="#" data-toggle="modal" data-target="#importModal_[% framework.frameworkcode %][% frameworks.count %]">Import</a>
<!-- Modal -->
<div class="modal hide" id="importModal_[% frameworkcode %][% loop.count %]" tabindex="-1" role="dialog" aria-labelledby="importLabelexportModal_[% frameworkcode %][% loop.count %]" aria-hidden="true">
<div class="modal hide" id="importModal_[% framework.frameworkcode %][% frameworks.count %]" tabindex="-1" role="dialog" aria-labelledby="importLabelexportModal_default[% frameworks.count %]" aria-hidden="true">
<div class="modal-header">
<button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="importLabelexportModal_[% frameworkcode %][% loop.count %]">Import default framework structure (fields and subfields) from a spreadsheet file (.csv, .xml, .ods)</h3>
<h3 id="importLabelexportModal_[% framework.frameworkcode %][% frameworks.count %]">Import default framework structure (fields and subfields) from a spreadsheet file (.csv, .xml, .ods)</h3>
</div>
<form action="/cgi-bin/koha/admin/import_export_framework.pl" name="form_i_[% frameworkcode %]" id="form_i_[% frameworkcode %]" method="post" enctype="multipart/form-data" class="form_import">
<form action="/cgi-bin/koha/admin/import_export_framework.pl" name="form_i_default" id="form_i_default" method="post" enctype="multipart/form-data" class="form_import">
<div class="modal-body">
<input type="hidden" name="frameworkcode" value="[% frameworkcode %]" />
<input type="hidden" name="frameworkcode" value="default" />
<input type="hidden" name="action" value="import" />
<p><label for="file_import_[% frameworkcode %]">Upload file:</label> <input type="file" name="file_import_[% frameworkcode %]" id="file_import_[% frameworkcode %]" class="input_import" /></p>
<div id="importing_[% frameworkcode %]" style="display:none" class="importing"><img src="[% interface %]/[% theme %]/img/loading-small.gif" alt="" /><span class="importing_msg"></span></div>
<p><label for="file_import_default">Upload file:</label> <input type="file" name="file_import_default" id="file_import_default" class="input_import" /></p>
<div id="importing_default" style="display:none" class="importing"><img src="[% interface %]/[% theme %]/img/loading-small.gif" alt="" /><span class="importing_msg"></span></div>
</div>
<div class="modal-footer">
<button type="submit" class="btn">Import</button>
@ -219,13 +266,13 @@
</td>
</tr>
<!-- note highlight assignment appears backwards because we already have a normal row for Default -->
[% FOREACH loo IN loop %]
[% FOREACH loo IN frameworks %]
<tr>
<td>[% loo.frameworkcode %]</td>
<td>[% loo.frameworktext %]</td>
<td><a href="marctagstructure.pl?frameworkcode=[% loo.frameworkcode %]" >MARC structure</a></td>
<td><a href="[% loo.script_name %]?op=add_form&amp;frameworkcode=[% loo.frameworkcode |html %]">Edit</a></td>
<td><a href="[% loo.script_name %]?op=delete_confirm&amp;frameworkcode=[% loo.frameworkcode |html %]">Delete</a></td>
<td><a href="/cgi-bin/koha/admin/biblio_framework.pl?op=add_form&amp;frameworkcode=[% loo.frameworkcode |html %]">Edit</a></td>
<td><a href="/cgi-bin/koha/admin/biblio_framework.pl?op=delete_confirm&amp;frameworkcode=[% loo.frameworkcode |html %]">Delete</a></td>
<td>
<!-- Button to trigger modal -->
@ -280,8 +327,6 @@
</tr>
[% END %]
</table>
[% IF ( previous ) %]<a href="[% previous %]">&lt;&lt; Previous</a>[% END %]
[% IF ( next ) %]<a href="[% next %]">Next &gt;&gt;</a>[% END %]
[% END %]
</div>

Loading…
Cancel
Save