From dcf25a5b443ef4546a08badc5627012b4fb1d4d8 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 10 Jun 2009 14:04:50 -0500 Subject: [PATCH] Cleanup authtypes and currency .pl and .tmpl Removed unused javascript. Enabled warnings. Use common $dbh. Removed sth->finish calls. Removed toggle code. Added row highlight where none had been implemented. Added some HTML escaping in TMPL. Signed-off-by: Galen Charlton --- admin/authtypes.pl | 140 +++++--------- admin/currency.pl | 85 +++----- .../prog/en/modules/admin/authtypes.tmpl | 108 ++++++----- .../prog/en/modules/admin/currency.tmpl | 183 +++++++----------- 4 files changed, 207 insertions(+), 309 deletions(-) diff --git a/admin/authtypes.pl b/admin/authtypes.pl index d36068031a..8789559378 100755 --- a/admin/authtypes.pl +++ b/admin/authtypes.pl @@ -1,7 +1,6 @@ #!/usr/bin/perl -# NOTE: 4-character tabs -#written 20/02/2002 by paul.poulain@free.fr +# 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 @@ -22,37 +21,25 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +use warnings; use CGI; use C4::Context; use C4::Auth; use C4::Output; - sub StringSearch { - my ($searchstring,$type)=@_; - my $dbh = C4::Context->dbh; - $searchstring=~ s/\'/\\\'/g; - my @data=split(' ',$searchstring); - my $count=@data; - my $sth=$dbh->prepare("SELECT * FROM auth_types WHERE (authtypecode like ?) ORDER BY authtypecode"); - $sth->execute("$data[0]%"); - my @results; - while (my $data=$sth->fetchrow_hashref){ - push(@results,$data); - } - # $sth->execute; - $sth->finish; - return (scalar(@results),\@results); + my $sth = C4::Context->dbh->prepare("SELECT * FROM auth_types WHERE (authtypecode like ?) ORDER BY authtypecode"); + $sth->execute((shift || '') . "%"); + return $sth->fetchall_arrayref({}); } my $input = new CGI; -my $searchfield=$input->param('authtypecode'); -my $offset=$input->param('offset'); -my $script_name="/cgi-bin/koha/admin/authtypes.pl"; -my $authtypecode=$input->param('authtypecode'); -my $pagesize=20; -my $op = $input->param('op'); -$searchfield=~ s/\,//g; +my $script_name = "/cgi-bin/koha/admin/authtypes.pl"; +my $searchfield = $input->param('authtypecode'); # FIXME: Auth Type search not really implemented +my $authtypecode = $input->param('authtypecode'); +my $offset = $input->param('offset') || 0; +my $op = $input->param('op') || ''; +my $pagesize = 20; my ($template, $borrowernumber, $cookie) = get_template_and_user({template_name => "admin/authtypes.tmpl", query => $input, @@ -62,101 +49,76 @@ my ($template, $borrowernumber, $cookie) debug => 1, }); -if ($op) { -$template->param(script_name => $script_name, - $op => 1); # we show only the TMPL_VAR names $op -} else { -$template->param(script_name => $script_name, - 'else' => 1); # we show only the TMPL_VAR names $op -} -################## ADD_FORM ################################## +$template->param( + script_name => $script_name, + ($op || 'else') => 1, +); + +my $dbh = C4::Context->dbh; + # 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 ($authtypecode) { - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?"); + my $sth = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?"); $sth->execute($authtypecode); - $data=$sth->fetchrow_hashref; - $sth->finish; - $template->param(authtypecode => $authtypecode, - authtypetext => $data->{'authtypetext'}, - auth_tag_to_report => $data->{'auth_tag_to_report'}, - summary => $data->{'summary'}, - ); + my $data = $sth->fetchrow_hashref(); + $template->param( + authtypecode => $authtypecode, + authtypetext => $data->{'authtypetext'}, + auth_tag_to_report => $data->{'auth_tag_to_report'}, + summary => $data->{'summary'}, + ); } # 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('modif')) { - my $sth=$dbh->prepare("UPDATE auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=? WHERE authtypecode=?"); - $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode')); - $sth->finish; - } else { - my $sth=$dbh->prepare("INSERT INTO auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=?, authtypecode=?"); - $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode')); - $sth->finish; - } - print "Content-Type: text/html\n\n"; + my $sth = $input->param('modif') ? + $dbh->prepare("UPDATE auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=? WHERE authtypecode=?") : + $dbh->prepare("INSERT INTO auth_types SET authtypetext=?, auth_tag_to_report=?, summary=?, authtypecode=?") ; + $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode')); + 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') { #start the page and read in includes - my $dbh = C4::Context->dbh; - - my $total = 0; - for my $table ('auth_tag_structure') { - my $sth=$dbh->prepare("SELECT count(*) AS total FROM $table WHERE authtypecode=?"); + my $sth=$dbh->prepare("SELECT count(*) AS total FROM auth_tag_structure WHERE authtypecode=?"); $sth->execute($authtypecode); - $total += $sth->fetchrow_hashref->{total}; - $sth->finish; - } + my $total = $sth->fetchrow_hashref->{total}; - my $sth=$dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?"); - $sth->execute($authtypecode); - my $data=$sth->fetchrow_hashref; - $sth->finish; + my $sth2 = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?"); + $sth2->execute($authtypecode); + my $data = $sth2->fetchrow_hashref; $template->param(authtypecode => $authtypecode, - authtypetext => $data->{'authtypetext'}, - summary => $data->{'summary'}, + authtypetext => $data->{'authtypetext'}, + summary => $data->{'summary'}, total => $total); # 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') { #start the page and read in includes - my $dbh = C4::Context->dbh; - my $authtypecode=uc($input->param('authtypecode')); my $sth=$dbh->prepare("DELETE FROM auth_types WHERE authtypecode=?"); - $sth->execute($authtypecode); - $sth->finish; - print "Content-Type: text/html\n\n"; + $sth->execute(uc $input->param('authtypecode')); + print $input->redirect($script_name); # FIXME: unnecessary redirect exit; # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT - my ($count,$results)=StringSearch($searchfield,'web'); - my $toggle="white"; + my $results = StringSearch($searchfield); + my $count = scalar @$results; my @loop_data; for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ - my %row_data; - if ($toggle eq 'white'){ - $row_data{toggle}="#ffffcc"; - } else { - $row_data{toggle}="white"; - } - $row_data{authtypecode} = $results->[$i]{'authtypecode'}; - $row_data{authtypetext} = $results->[$i]{'authtypetext'}; - $row_data{auth_tag_to_report} = $results->[$i]{'auth_tag_to_report'}; - $row_data{summary} = $results->[$i]{'summary'}; - push(@loop_data, \%row_data); + push @loop_data, { + authtypecode => $results->[$i]{'authtypecode'}, + authtypetext => $results->[$i]{'authtypetext'}, + auth_tag_to_report => $results->[$i]{'auth_tag_to_report'}, + summary => $results->[$i]{'summary'}, + }; } $template->param(loop => \@loop_data); if ($offset>0) { @@ -164,12 +126,8 @@ if ($op eq 'add_form') { $template->param(previous => "$script_name?offset=".$prevpage); } if ($offset+$pagesize<$count) { - my $nextpage =$offset+$pagesize; + my $nextpage = $offset+$pagesize; $template->param(next => "$script_name?offset=".$nextpage); } } #---- END $OP eq DEFAULT output_html_with_http_headers $input, $cookie, $template->output; - -# Local Variables: -# tab-width: 4 -# End: diff --git a/admin/currency.pl b/admin/currency.pl index 0a237bc908..6c74842a30 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -38,6 +38,7 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +# use warnings; # FIXME use CGI; use C4::Context; use C4::Auth; @@ -45,47 +46,33 @@ use C4::Dates qw(format_date); use C4::Output; sub StringSearch { - my ($searchstring,$type)=@_; - my $dbh = C4::Context->dbh; - $searchstring=~ s/\'/\\\'/g; - my @data=split(' ',$searchstring); - my $count=@data; - my $query="Select * from currency where (currency like \"$data[0]%\") order by currency"; - my $sth=$dbh->prepare($query); - $sth->execute; - my @results; - my $cnt=0; - while (my $data=$sth->fetchrow_hashref){ - push(@results,$data); - $cnt++; - } - # $sth->execute; - $sth->finish; - return ($cnt,\@results); + my $query = "SELECT * FROM currency WHERE (currency LIKE ?) ORDER BY currency"; + warn "$query :: @_[0]"; + my $sth = C4::Context->dbh->prepare($query); + $sth->execute((shift || '') . '%'); + return $sth->fetchall_arrayref({}); } my $input = new CGI; -my $searchfield=$input->param('searchfield'); -#my $branchcode=$input->param('branchcode'); -my $offset=$input->param('offset'); -my $script_name="/cgi-bin/koha/admin/currency.pl"; - -my $pagesize=20; -my $op = $input->param('op'); -$searchfield=~ s/\,//g; - -my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "admin/currency.tmpl", - query => $input, - type => "intranet", - flagsrequired => {parameters => 1}, - authnotrequired => 0, - debug => 1, - }); +my $searchfield = $input->param('searchfield') || $input->param('description') || ''; +my $offset = $input->param('offset') || 0; +my $op = $input->param('op') || ''; +my $script_name = "/cgi-bin/koha/admin/currency.pl"; +my $pagesize = 20; + +my ($template, $loggedinuser, $cookie) = get_template_and_user({ + template_name => "admin/currency.tmpl", + query => $input, + type => "intranet", + flagsrequired => {parameters => 1}, + authnotrequired => 0, + debug => 1, +}); $template->param(searchfield => $searchfield, script_name => $script_name); +my $dbh = C4::Context->dbh; ################## ADD_FORM ################################## # called by default. Used to create form to add or modify a record @@ -94,11 +81,9 @@ if ($op eq 'add_form') { #---- if primkey exists, it's a modify action, so read values to modify... my $data; if ($searchfield) { - my $dbh = C4::Context->dbh; my $sth=$dbh->prepare("select * from currency where currency=?"); $sth->execute($searchfield); $data=$sth->fetchrow_hashref; - $sth->finish; } foreach (keys %$data) { $template->param($_ => $data->{$_}); @@ -110,38 +95,26 @@ if ($op eq 'add_form') { # called by add_form, used to insert/modify data in DB } elsif ($op eq 'add_validate') { $template->param(add_validate => 1); - my $dbh = C4::Context->dbh; - my $check = $dbh->prepare("select * from currency where currency = ?"); $check->execute($input->param('currency')); - if ( $check->fetchrow ) - { + if ( $check->fetchrow ) { my $sth = $dbh->prepare("UPDATE currency SET rate = ?, symbol = ?, timestamp = ? WHERE currency = ?"); $sth->execute($input->param('rate'),$input->param('symbol'),C4::Dates->new->output('iso'),$input->param('currency')); - $sth->finish; - } - else - { + } else { my $sth = $dbh->prepare("INSERT INTO currency (currency, rate, symbol) VALUES (?,?,?)"); $sth->execute($input->param('currency'),$input->param('rate'),$input->param('symbol')); - $sth->finish; } - - $check->finish; # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { $template->param(delete_confirm => 1); - my $dbh = C4::Context->dbh; my $sth=$dbh->prepare("select count(*) as total from aqbooksellers where currency=?"); $sth->execute($searchfield); my $total = $sth->fetchrow_hashref; - $sth->finish; my $sth2=$dbh->prepare("select currency,rate from currency where currency=?"); $sth2->execute($searchfield); my $data=$sth2->fetchrow_hashref; - $sth2->finish; if ($total->{'total'} >0) { $template->param(totalgtzero => 1); @@ -154,25 +127,23 @@ if ($op eq 'add_form') { # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ($op eq 'delete_confirmed') { $template->param(delete_confirmed => 1); - my $dbh = C4::Context->dbh; my $sth=$dbh->prepare("delete from currency where currency=?"); $sth->execute($searchfield); - $sth->finish; # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT $template->param(else => 1); - my ($count,$results)=StringSearch($searchfield,'web'); + my $results = StringSearch($searchfield); + my $count = scalar(@$results); my @loop; for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ - my %row = ( + push @loop, { currency => $results->[$i]{'currency'}, rate => $results->[$i]{'rate'}, symbol => $results->[$i]{'symbol'}, timestamp => format_date($results->[$i]{'timestamp'}), - ); - push @loop, \%row; + }; } $template->param(loop => \@loop); @@ -181,7 +152,7 @@ if ($op eq 'add_form') { prevpage => $offset-$pagesize); } - if ($offset+$pagesize<$count) { + if ($offset+$pagesize < scalar @$results) { $template->param(ltcount => 1, nextpage => $offset+$pagesize); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tmpl index 774d947e92..1a214661b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tmpl @@ -1,5 +1,11 @@ -Koha › Administration › <!-- TMPL_IF NAME="add_form" --><!-- TMPL_IF NAME="authtypecode" --> Authority Types › Modify authority type<!-- TMPL_ELSE --> Authority Types › New authority type<!-- /TMPL_IF --><!-- TMPL_ELSE --><!-- TMPL_IF NAME="delete_confirm" -->Authority Types › Confirm Deletion of Authority Type<!-- TMPL_ELSE -->Authority Types<!-- /TMPL_IF --><!-- /TMPL_IF --> +Koha › Administration › Authority Types +<!-- TMPL_IF NAME="add_form" --> +› <!-- TMPL_IF NAME="authtypecode" -->Modify authority type<!-- TMPL_ELSE -->New authority type<!-- /TMPL_IF --> +<!-- TMPL_ELSIF NAME="delete_confirm" --> +› Confirm Deletion of Authority Type +<!-- /TMPL_IF --> + @@ -61,42 +52,60 @@ function Check(f) { - +
- -
+
-
+
-
" name="Aform" method="post"> -
- - Modify authority type + " name="Aform" method="post"> +
+ + + Modify authority type - New authority type + New authority type -
    - -
  1. Authority type - " />
  2. - -
  3. - + +
      +
    1. + + Authority type + + + " /> + + + + +
    2. " />
    3. Note: for 'Authority field to copy', enter the authority field that should be copied from the authority record to the bibliographic record. E.g., in MARC21, field 100 in the authority record should be copied to field 100 in the bibliographic record

      " /> - - - -
    + + + + +
-
Cancel
+
+ ">Cancel +
@@ -116,19 +125,8 @@ function Check(f) {
-

Authority Types

@@ -145,7 +143,11 @@ function Check(f) { + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl index 4dfdd04b8d..86248818e8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl @@ -6,76 +6,52 @@ Currency Deleted Currencies - - - -
@@ -85,27 +61,15 @@
-
" name="Aform" method="post"> - - +
Modify currency @@ -133,59 +97,62 @@
  • - -
    + +
    -
    Cancel
    - +
    + ">Cancel +
    +
    -

    Data Recorded

    -
    " method="post"> -
    +

    Data Recorded

    +
    " method="get"> + +
    - -

    Cannot Delete Currencey ''

    -

    This currency is used times. Deletion not possible -

    " method="post"> - -
    - -

    Confirm Deletion of Currency ''

    - - - - - - - - - -
    Currency
    Rate
    - - -
    " method="post"> - - " /> - -
    -
    " method="post"> - -
    - + +
    +

    Cannot Delete Currencey ''

    +

    This currency is used times. Deletion not possible

    +
    " method="post"> + +
    +
    + +
    +

    Confirm Deletion of Currency ''

    + + + + + + + +
    Currency
    Rate
    +
    " method="post"> + + " /> + +
    +
    " method="post"> + +
    +
    +

    Currency Deleted

    " method="post"> - -
    + +
    @@ -211,7 +178,7 @@ - + ?op=add_form&searchfield=">Edit ?op=delete_confirm&searchfield=">Delete -- 2.39.5