+#!/usr/bin/perl
+
+# Converted to new plugin style (Bug 13437)
+
+# Copyright 2015 Koha Development Team
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
use Modern::Perl;
-no warnings 'redefine';
-use CGI;
-use C4::Auth;
-use C4::ClassSource;
-use C4::Output;
+use C4::Auth qw( get_template_and_user );
+use C4::ClassSource qw( GetClassSort );
+use C4::Output qw( output_html_with_http_headers );
+
+use Koha::ClassSources;
-sub plugin_javascript {
- my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
- my $function_name = "328" . ( int( rand(100000) ) + 1 );
+my $builder = sub {
+ my ( $params ) = @_;
+ my $function_name = $params->{id};
my $res = "
-<script type=\"text/javascript\">
-//<![CDATA[
+<script>
-function Clic$function_name(i) {
- q = document.getElementById('$field_number');
- window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=cn_browser.pl&popup&q=\"+q.value,\"cnbrowser\",\"width=500,height=400,toolbar=false,scrollbars=yes\");
+function Click$function_name(i) {
+ q = document.getElementById('$params->{id}');
+ window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=cn_browser.pl&popup&q=\"+encodeURIComponent(q.value),\"cnbrowser\",\"width=500,height=400,toolbar=false,scrollbars=yes\");
}
-//]]>
</script>
";
+ return $res;
+};
- return ( $function_name, $res );
-}
-
-sub plugin {
- my ($input) = @_;
- my $cgi = new CGI;
- my $params = $cgi->Vars;
+my $launcher = sub {
+ my ( $params ) = @_;
+ my $cgi = $params->{cgi};
my $results_per_page = 30;
my $current_page = $cgi->param('page') || 1;
{ template_name => "cataloguing/value_builder/cn_browser.tt",
query => $cgi,
type => "intranet",
- authnotrequired => 0,
flagsrequired => { catalogue => 1 },
}
);
- my $cn_sort;
-
my $dbh = C4::Context->dbh;
my $sth;
my @cn;
$search = $gt;
}
+ my $cn_source = $cgi->param('cn_source') || C4::Context->preference("DefaultClassificationSource");
+ my @class_sources = Koha::ClassSources->search({ used => 1});
+
#Don't show half the results of show lt or gt
$real_limit = $results_per_page if $search ne $q;
- $cn_sort = GetClassSort( undef, undef, $search );
- my $cn_sort_q = GetClassSort( undef, undef, $q );
+ my $cn_sort = GetClassSort( $cn_source, undef, $search );
my $red = 0;
if ( $search ne $gt ) {
my $green = 0;
#Results before the cn_sort
- $query = "SELECT b.title, itemcallnumber, biblionumber, barcode, cn_sort, branchname, author
+ $query = "SELECT b.title, b.subtitle, itemcallnumber, biblionumber, barcode, cn_sort, branchname, author
FROM items AS i
JOIN biblio AS b USING (biblionumber)
LEFT OUTER JOIN branches ON (branches.branchcode = homebranch)
if ( $data->{itemcallnumber} eq $q ) {
$data->{background} = 'red';
$red = 1;
- } elsif ( ( GetClassSort( undef, undef, $data->{itemcallnumber} ) lt $cn_sort_q ) && !$green && !$red ) {
+ } elsif ( $data->{cn_sort} lt $cn_sort && !$green && !$red ) {
if ( $#cn != -1 ) {
unshift @cn, { 'background' => 'green' };
$globalGreen = 1;
my $green = 0;
#Results after the cn_sort
- $query = "SELECT b.title, itemcallnumber, biblionumber, i.cn_sort, branchname, author
+ $query = "SELECT b.title, b.subtitle, itemcallnumber, biblionumber, barcode, cn_sort, branchname, author
FROM items AS i
JOIN biblio AS b USING (biblionumber)
LEFT OUTER JOIN branches ON (branches.branchcode = homebranch)
if ( $data->{itemcallnumber} eq $q ) {
$data->{background} = 'red';
$red = 1;
- } elsif ( ( GetClassSort( undef, undef, $data->{itemcallnumber} ) gt $cn_sort_q ) && !$green && !$red && !$globalGreen ) {
+ } elsif ( $data->{cn_sort} gt $cn_sort && !$green && !$red && !$globalGreen ) {
push @cn, { 'background' => 'green' };
$green = 1;
}
$template->param( 'q' => $q );
$template->param( 'cn_loop' => \@cn ) if $#cn != -1;
$template->param( 'popup' => defined( $cgi->param('popup') ) );
+ $template->param( 'cn_source' => $cn_source ) if $cn_source;
+ $template->param( 'class_sources' => \@class_sources );
+
output_html_with_http_headers $cgi, $cookie, $template->output;
-}
+};
-1;
+return { builder => $builder, launcher => $launcher };