From 2e0e56a016f4829b479ec260435e185400b72a57 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Tue, 4 Dec 2007 17:40:46 -0600 Subject: [PATCH] tools subdir - Dates.pm integration and warnings fixes. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- tools/cleanborrowers.pl | 8 ++- tools/import_borrowers.pl | 19 +++---- tools/inventory.pl | 24 +++------ tools/letter.pl | 106 ++++++++++++++++---------------------- tools/pdfViewer.pl | 7 +-- tools/picture-upload.pl | 56 +++++++++----------- 6 files changed, 90 insertions(+), 130 deletions(-) diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl index e24f647a1d..c6ecac549f 100755 --- a/tools/cleanborrowers.pl +++ b/tools/cleanborrowers.pl @@ -36,10 +36,8 @@ use strict; use CGI; use C4::Auth; use C4::Output; -use C4::Date; - - -use C4::Members; # GetBorrowersWhoHavexxxBorrowed. +use C4::Dates; +use C4::Members; # GetBorrowersWhoHavexxxBorrowed. use C4::Circulation; # AnonymiseIssueHistory. use Date::Calc qw/Date_to_Days Today/; @@ -158,7 +156,7 @@ $template->param( step1 => '1', filterdate1 => $filterdate1, filterdate2 => $filterdate2, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); #writing the template diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index 14993d6b18..ae03c5202c 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -36,7 +36,7 @@ use strict; use C4::Auth; use C4::Output; -use C4::Date; +use C4::Dates; use C4::Context; use C4::Members; @@ -83,38 +83,31 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { my $overwritten = 0; my $invalid = 0; while ( my $borrowerline = <$uploadborrowers> ) { - my $status = $csv->parse($borrowerline); my @columns = $csv->fields(); my %borrower; if ( @columns == @columnkeys ) { - @borrower{@columnkeys} = @columns; if ( my $member = GetMember( $borrower{'cardnumber'}, 'cardnumber' ) ) { - # borrower exists if ($overwrite_cardnumber) { $borrower{'borrowernumber'} = $member->{'borrowernumber'}; ModMember(%borrower); $overwritten++; - } - else { + } else { $alreadyindb++; } } else { - my $borrowernumber = AddMember(%borrower); - if ($borrowernumber) { + if (AddMember(%borrower)) { $imported++; - } - else { - $invalid; + } else { + $invalid++; # was just "$invalid", I assume incrementing was the point --atz } } - } - else { + } else { $invalid++; } } diff --git a/tools/inventory.pl b/tools/inventory.pl index b8206a3119..a66d63d91a 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -23,7 +23,7 @@ use C4::Auth; use C4::Context; use C4::Output; use C4::Biblio; -use C4::Date; +use C4::Dates; use C4::Koha; use C4::Branch; # GetBranches @@ -86,7 +86,7 @@ while (my ($fwkcode)=$rq->fetchrow){ $template->param(branchloop => \@branch_loop, authorised_values=>\@authorised_value_list, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), minlocation => $minlocation, maxlocation => $maxlocation, location=>$location, @@ -97,14 +97,13 @@ $template->param(branchloop => \@branch_loop, ); if ($uploadbarcodes && length($uploadbarcodes)>0){ my $dbh=C4::Context->dbh; - my $date=format_date_in_iso($input->param('setdate')); - $date = format_date_in_iso("today") unless $date; + my $date = format_date_in_iso($input->param('setdate')) || C4::Dates->today('iso'); # warn "$date"; my $strsth="update items set (datelastseen = $date) where items.barcode =?"; my $qupdate = $dbh->prepare($strsth); - my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null"; + $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null"; my $qonloan = $dbh->prepare($strsth); - my $strsth="select * from items where items.barcode =? and issues.wthdrawn=1"; + $strsth="select * from items where items.barcode =? and issues.wthdrawn=1"; my $qwthdrawn = $dbh->prepare($strsth); my @errorloop; my $count=0; @@ -138,18 +137,11 @@ if ($uploadbarcodes && length($uploadbarcodes)>0){ $template->param(errorloop=>\@errorloop) if (@errorloop); }else{ if ($markseen) { - foreach my $field ($input->param) { - if ($field =~ /SEEN-(.*)/) { - &ModDateLastSeen($1); - } + foreach ($input->param) { + /SEEN-(.+)/ and &ModDateLastSeen($1); } - my $res = GetItemsForInventory($minlocation,$maxlocation,$location,$datelastseen,$branchcode,$offset,$pagesize); - $template->param(loop =>$res, - nextoffset => ($offset+$pagesize), - prevoffset => ($offset?$offset-$pagesize:0), - ); } - if ($op) { + if ($markseen or $op) { my $res = GetItemsForInventory($minlocation,$maxlocation,$location,$datelastseen,$branchcode,$offset,$pagesize); $template->param(loop =>$res, nextoffset => ($offset+$pagesize), diff --git a/tools/letter.pl b/tools/letter.pl index 78bf099a6b..ecc763439b 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -38,7 +38,7 @@ use strict; use CGI; -use C4::Date; +use C4::Dates; use C4::Auth; use C4::Context; use C4::Output; @@ -60,8 +60,6 @@ sub StringSearch { push( @results, $data ); $cnt++; } - - # $sth->execute; $sth->finish; return ( $cnt, \@results ); } @@ -110,8 +108,7 @@ if ( $op eq 'add_form' ) { #---- if primkey exists, it's a modify action, so read values to modify... my $letter; if ($code) { - my $sth = - $dbh->prepare("select * from letter where module=? and code=?"); + my $sth = $dbh->prepare("select * from letter where module=? and code=?"); $sth->execute( $module, $code ); $letter = $sth->fetchrow_hashref; $sth->finish; @@ -121,39 +118,39 @@ if ( $op eq 'add_form' ) { my @SQLfieldname; my %line = ( 'value' => "LibrarianFirstname", 'text' => 'LibrarianFirstname' ); push @SQLfieldname, \%line; - my %line = ( 'value' => "LibrarianSurname", 'text' => 'LibrarianSurname' ); + %line = ( 'value' => "LibrarianSurname", 'text' => 'LibrarianSurname' ); push @SQLfieldname, \%line; - my %line = ( 'value' => "LibrarianEmailaddress", 'text' => 'LibrarianEmailaddress' ); + %line = ( 'value' => "LibrarianEmailaddress", 'text' => 'LibrarianEmailaddress' ); push @SQLfieldname, \%line; my $sth2 = $dbh->prepare("SHOW COLUMNS from branches"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---BRANCHES---' ); + %line = ( 'value' => "", 'text' => '---BRANCHES---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( 'value' => "branches." . $field, 'text' => "branches." . $field ); + %line = ( 'value' => "branches." . $field, 'text' => "branches." . $field ); push @SQLfieldname, \%line; } # add acquisition specific tables if ( index( $module, "acquisition" ) > 0 ) { - my $sth2 = $dbh->prepare("SHOW COLUMNS from aqbooksellers"); + $sth2 = $dbh->prepare("SHOW COLUMNS from aqbooksellers"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---BOOKSELLERS---' ); + %line = ( 'value' => "", 'text' => '---BOOKSELLERS---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( + %line = ( 'value' => "aqbooksellers." . $field, 'text' => "aqbooksellers." . $field ); push @SQLfieldname, \%line; } - my $sth2 = $dbh->prepare("SHOW COLUMNS from aqorders"); + $sth2 = $dbh->prepare("SHOW COLUMNS from aqorders"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---ORDERS---' ); + %line = ( 'value' => "", 'text' => '---ORDERS---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( + %line = ( 'value' => "aqorders." . $field, 'text' => "aqorders." . $field ); @@ -163,49 +160,47 @@ if ( $op eq 'add_form' ) { # add issues specific tables } elsif ( index( $module, "issues" ) > 0 ) { - my $sth2 = $dbh->prepare("SHOW COLUMNS from aqbooksellers"); + $sth2 = $dbh->prepare("SHOW COLUMNS from aqbooksellers"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---BOOKSELLERS---' ); + %line = ( 'value' => "", 'text' => '---BOOKSELLERS---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( + %line = ( 'value' => "aqbooksellers." . $field, 'text' => "aqbooksellers." . $field ); push @SQLfieldname, \%line; } - my $sth2 = $dbh->prepare("SHOW COLUMNS from serial"); + $sth2 = $dbh->prepare("SHOW COLUMNS from serial"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---SERIALS---' ); + %line = ( 'value' => "", 'text' => '---SERIALS---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( 'value' => "serial." . $field, 'text' => "serial." . $field ); + %line = ( 'value' => "serial." . $field, 'text' => "serial." . $field ); push @SQLfieldname, \%line; } - my $sth2 = $dbh->prepare("SHOW COLUMNS from subscription"); + $sth2 = $dbh->prepare("SHOW COLUMNS from subscription"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---SUBSCRIPTION---' ); + %line = ( 'value' => "", 'text' => '---SUBSCRIPTION---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( + %line = ( 'value' => "subscription." . $field, 'text' => "subscription." . $field ); push @SQLfieldname, \%line; } - my %line = ( 'value' => "", 'text' => '---Biblio---' ); - push @SQLfieldname, \%line; - my %line = ('value' => "biblio.title",'text' => "Title"); - push @SQLfieldname, \%line; - my %line = ('value' => "biblio.author",'text' => "Author"); - push @SQLfieldname, \%line; - my %line = ('value' => "biblio.serial",'text' => "Serial"); + %line = ('value' => "", 'text' => '---Biblio---' ); push @SQLfieldname, \%line; + foreach(qw(title author serial)) { + %line = ('value' => "biblio.$_", 'text' => ucfirst($_)); + push @SQLfieldname, \%line; + } } else { - my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio"); + $sth2 = $dbh->prepare("SHOW COLUMNS from biblio"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---BIBLIO---' ); + %line = ( 'value' => "", 'text' => '---BIBLIO---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { @@ -214,28 +209,28 @@ if ( $op eq 'add_form' ) { my %line = ( 'value' => "biblio." . $field, 'text' => "biblio." . $field ); push @SQLfieldname, \%line; } - my $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems"); + $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---BIBLIOITEMS---' ); + %line = ( 'value' => "", 'text' => '---BIBLIOITEMS---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( + %line = ( 'value' => "biblioitems." . $field, 'text' => "biblioitems." . $field ); push @SQLfieldname, \%line; } - my %line = ( 'value' => "", 'text' => '---ITEMS---' ); + %line = ( 'value' => "", 'text' => '---ITEMS---' ); push @SQLfieldname, \%line; - my %line = ( 'value' => "items.content", 'text' => 'items.content' ); + %line = ( 'value' => "items.content", 'text' => 'items.content' ); push @SQLfieldname, \%line; - my $sth2 = $dbh->prepare("SHOW COLUMNS from borrowers"); + $sth2 = $dbh->prepare("SHOW COLUMNS from borrowers"); $sth2->execute; - my %line = ( 'value' => "", 'text' => '---BORROWERS---' ); + %line = ( 'value' => "", 'text' => '---BORROWERS---' ); push @SQLfieldname, \%line; while ( ( my $field ) = $sth2->fetchrow_array ) { - my %line = ( + %line = ( 'value' => "borrowers." . $field, 'text' => "borrowers." . $field ); @@ -256,8 +251,6 @@ if ( $op eq 'add_form' ) { ( $module ? $module : $letter->{module} ) => 1, SQLfieldname => \@SQLfieldname, ); - - # END $OP eq ADD_FORM ################## ADD_VALIDATE ################################## # called by add_form, used to insert/modify data in DB } @@ -274,8 +267,6 @@ elsif ( $op eq 'add_validate' ) { $sth->finish; print $input->redirect("letter.pl"); exit; - - # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } @@ -285,12 +276,10 @@ elsif ( $op eq 'delete_confirm' ) { $sth->execute($code); my $data = $sth->fetchrow_hashref; $sth->finish; - $template->param( module => $data->{module} ); - $template->param( code => $code ); - $template->param( name => $data->{'name'} ); - $template->param( content => $data->{'content'} ); - - # END $OP eq DELETE_CONFIRM + $template->param( code => $code ); + foreach (qw(module name content)) { + $template->param( $_ => $data->{$_} ); + } ################## DELETE_CONFIRMED ################################## # called by delete_confirm, used to effectively confirm deletion of data in DB } @@ -303,8 +292,6 @@ elsif ( $op eq 'delete_confirmed' ) { $sth->finish; print $input->redirect("/cgi-bin/koha/tools/letter.pl"); return; - - # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT @@ -321,17 +308,12 @@ else { # DEFAULT $i++ ) { - if ( $toggle ) { - $toggle = 0; - } - else { - $toggle = 1; - } + $toggle = ($toggle) ? 0 : 1; my %row_data; $row_data{toggle} = $toggle; - $row_data{module} = $results->[$i]{'module'}; - $row_data{code} = $results->[$i]{'code'}; - $row_data{name} = $results->[$i]{'name'}; + foreach (qw(module code name)) { + $row_data{$_} = $results->[$i]{$_}; + } push( @loop_data, \%row_data ); } $template->param( letter => \@loop_data ); diff --git a/tools/pdfViewer.pl b/tools/pdfViewer.pl index d6ec298a5b..aefedce33b 100755 --- a/tools/pdfViewer.pl +++ b/tools/pdfViewer.pl @@ -33,8 +33,9 @@ my $tmpFileName = $cgi->param('tmpFileName'); print "Content-Disposition: attachment; filename = $filename\n\n"; print $cgi->header(-type => 'application/pdf'), $cgi->start_html(-title=>"Codify to PDF"); -open fh, "<$tmpFileName"; -while () { - print; +open FH, "<$tmpFileName"; +while () { + print; } +close FH; print $cgi->end_html(); diff --git a/tools/picture-upload.pl b/tools/picture-upload.pl index 445b071db3..c5b5aec86a 100755 --- a/tools/picture-upload.pl +++ b/tools/picture-upload.pl @@ -39,8 +39,8 @@ if ( $uploadfile ) { my ( @directories, %errors ); $errors{'NOTZIP'} = 1 unless ( $uploadfilename =~ /\.zip$/i ); - $errors{'NOWRITETEMP'} = 1 unless ( -w "$dirname" ); - $errors{'NOWRITEDEST'} = 1 unless ( -w "$destdir" ); + $errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); + $errors{'NOWRITEDEST'} = 1 unless ( -w $destdir ); $errors{'EMPTYUPLOAD'} = 1 unless ( length( $uploadfile ) > 0 ); if ( %errors ) { @@ -52,13 +52,13 @@ if ( $uploadfile ) { close $tfh; - `unzip $tempfile -d $dirname`; + system("unzip $tempfile -d $dirname"); push @directories, "$dirname"; foreach $recursive_dir ( @directories ) { opendir $dir, $recursive_dir; while ( my $entry = readdir $dir ) { - push @directories, "$recursive_dir/$entry" if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ ); + push @directories, "$recursive_dir/$entry" if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ ); } closedir $dir; } @@ -79,42 +79,36 @@ if ( $uploadfile ) { output_html_with_http_headers $input, $cookie, $template->output; - sub handle_dir { my ( $dir ) = @_; my ( %count ); $count{filenames} = (); - return 0 unless ( -r "$dir/IDLINK.TXT" or -r "$dir/DATALINK.TXT" ); - my $file = ( -r "$dir/IDLINK.TXT" ) ? "$dir/IDLINK.TXT" : "$dir/DATALINK.TXT"; - - open $fh, $file or { print "Openning $dir/$filename failed!\n" and return 0 }; - - while (my $line = <$fh>) { - chomp $line; - - my ( $filename, $cardnumber ); - - my $delim = ($line =~ /\t/) ? "\t" : ","; - - ($cardnumber, $filename) = split $delim, $line; - $cardnumber =~ s/[\"\r\n]//g; # remove offensive characters - $filename =~ s/[\"\r\n]//g; - - if ($cardnumber && $filename) { - my $result = move ( "$dir/$filename", "$destdir/$cardnumber.jpg" ); - if ( $result ) { - $count{count}++; - push @{ $count{filenames} }, { source => $filename, dest => $cardnumber .".jpg" }; - } - } + unless (open (FILE, $file)) { + print "Openning $dir/$file failed!\n"; + return 0; + }; + + while (my $line = ) { + chomp $line; + my ( $filename, $cardnumber ); + my $delim = ($line =~ /\t/) ? "\t" : ","; + ($cardnumber, $filename) = split $delim, $line; + $cardnumber =~ s/[\"\r\n]//g; # remove offensive characters + $filename =~ s/[\"\r\n]//g; + + if ($cardnumber && $filename) { + my $result = move ( "$dir/$filename", "$destdir/$cardnumber.jpg" ); + if ( $result ) { + $count{count}++; + push @{ $count{filenames} }, { source => $filename, dest => $cardnumber .".jpg" }; + } + } } $count{source} = $dir; $count{dest} = $destdir; push @counts, \%count; - - close $fh; - + close FILE; return 1; } -- 2.39.5