Pisa.pm - YAPM - Yes, Another Perl Mongers group

Home :: News :: Biblioteca :: Meetings

Biblioteca
#!/usr/local/bin/perl use strict; use lib './','/home/groupleaders/pisa/perl-dir/lib/site_perl'; #/site_perl/5.6.0/i686-linux'; use LibConfig; use Library; use DBI; use Data::Dumper (); use Date::Calc qw (Add_Delta_Days); use POSIX (); use vars qw(%c $admin); use CGI qw(:cgi-lib); my %form = Vars; *c = \%LibConfig::conf; my $str = "Content-type: text/html\n\n"; my $location; my $dbh = DBI->connect($c{'RDBMS'}{'driver'}, "", ""); $dbh->{AutoCommit} = 1; my $lib = new Library ( dbh => $dbh ); # show book if ( $form{'cmd'} eq 'show' ) { # modify book if ( $form{'act'} eq 'mod_book' && $admin ) { $lib->updateBook( id => $form{'id'}, form => \%form ); } my $book = ($lib->getBooks( id => $form{'id'} ))[0]; $str .= <
$book->{'title'}
$book->{'authors'}
$book->{'publisher'}, $book->{'publish_date'}
$book->{'price'}

In biblioteca dal: $book->{'entry_date'} EOM if ( $book->{'start_date'} && ! $book->{'end_date'} ) { my ($y,$m,$d) = Add_Delta_Days(split(/-/,$book->{'start_date'}),$c{'loans'}{'duration'} + $c{'loans'}{'review'} * $book->{'on_review'}); $str .= <
DisponibilitÓ: $c{'icons'}{'unavailable'}
Fine prestito: $y-$m-$d EOM # } else { $str .= < DisponibilitÓ: $c{'icons'}{'available'} EOM } $str .= < EOM # show book form if ( $admin ) { QuoteHTML(\$book->{title},\$book->{publisher},\$book->{authors},\$book->{price},\$book->{notes}); $str .= < Modifica book
Title
Immagine
Editore
Data pubblicazione
Autori
Prezzo
Note
In review
Entry date
EOM $str .= <Prestiti
EOM my $new_loans = 1; foreach my $loans ( $lib->getLoans( books_id => $form{'id'}) ) { $str .= < EOM $new_loans = 0 if $loans->{end_date} eq ''; } $str .= "
User Start date End date On review Mod
$loans->{users_id} $loans->{start_date} $loans->{end_date} $loans->{on_review} mod
\n"; $str .= "Nuovo prestito
\n" if $new_loans; } $str .= '
Recensioni'; $str .= " {id}\">[Add]" if $admin; $str .= '
'; foreach my $review ( $lib->getReviews( books_id => $form{'id'}) ) { my $stars = '' x $review->{'stars'} . ( $review->{'stars'} =~ /(,|\.)5$/ ? '' :''); $str .= "\n{'id'}\">\n
Recensione del $review->{'review_date'} di $review->{'users_id'} "; if ( $admin ) { $str .= "
{'id'}\">[Mod] | [Del]"; } $str .= <$stars

$review->{'ita'}
EOM $str .= "
$review->{'eng'}
\n" if $review->{'eng'}; $str .= <[Top]
EOM } } # reviews management elsif ( $admin && ($form{'cmd'} =~ /review$/i) ) { if ( $form{'act'} eq 'apply' ) { if ( $form{'cmd'} eq 'add_review' ) { $lib->addReview( form => \%form ); } else { $lib->updateReview( id => $form{'id'}, form => \%form ); } $str .= "Done. Back to book or library home"; } else { my $review; if ( $form{'cmd'} eq 'add_review' ) { $review->{books_id} = $form{'books_id'}; } else { $review = ($lib->getReviews( id => $form{'id'} ))[0]; QuoteHTML(\$review->{users_id},\$review->{ita},\$review->{eng}); } $str .= <Add/mod reviews for '$review->{title}'
User
Data pubblicazione
Ita
Eng
Stars (formato: x(\.|,)y)
EOM } } # loans management elsif ( $admin && ($form{'cmd'} =~ /loan$/i) ) { if ( $form{'act'} eq 'apply' ) { if ( $form{'cmd'} eq 'add_loan' ) { $lib->addLoan( form => \%form ); } else { $lib->updateLoan( id => $form{'id'}, form => \%form ); } $str .= "Done. Back to book or library home"; } else { my $loan; if ( $form{'cmd'} eq 'add_loan' ) { $loan->{books_id} = $form{'books_id'}; } else { $loan = ($lib->getLoans( id => $form{'id'} ))[0]; QuoteHTML(\$loan->{users_id}); } $str .= <Add/mod loan for '$loan->{title}'
User
Loan start
Loan end
On review
EOM } } # show books list else { # Add book if ( $form{'act'} eq 'add_book' && $admin ) { $lib->addBook( form => \%form ); } $str .= <Attualmente ci sono i seguenti libri:

EOM my %book_chk; foreach my $book ($lib->getBooks( awhere => [{sql => '(loans.end_date IS NULL OR loans.end_date = \'\')'}], order_by => 'books.title ASC, loans.end_date ASC' ) ) { next if $book_chk{$book->{'id'}}; $str .= < EOM if ( $book->{'start_date'} && ! $book->{'end_date'} ) { my ($y,$m,$d) = Add_Delta_Days(split(/-/,$book->{'start_date'}),$c{'loans'}{'duration'} + $c{'loans'}{'review'} * $book->{'on_review'}); $str .= <$c{'icons'}{'unavailable'} EOM $book_chk{$book->{'id'}} = 1; } else { $str .= <$c{'icons'}{'available'} EOM } } $str .= '
Titolo Autore Editore Data pubbl. DisponibilitÓ Fine prestito
$$book{'title'} $book->{'authors'} $book->{'publisher'} $$book{'publish_date'}$y-$m-$d
'; # show new book form if ( $admin ) { $str .= < Add new book:
Title
Immagine
Editore
Data pubblicazione
Autori
Prezzo
Note
In review
Entry date
EOM } } $dbh->disconnect; if ( $location ) { print "Location: $location\n\n"; } else { print $str; #print '
' . Data::Dumper::Dumper(\%form) . '
'; } sub QuoteHTML { my @array_var_ref = @_; my $last_value; foreach (@array_var_ref) { $$_ =~ s/&/&/g; $$_ =~ s//>/g; $$_ =~ s/"/"/g; $$_ =~ s/'/\&\#39;/g; $last_value = $$_; } return $last_value; }

Leggi attentamente le regole per l'accesso alla biblioteca!


Per qualsiasi dubbio, chiarimento e/o informazione scrivi a <info at pisa.pm.org>
Tutto il materiale copyright 2003 Pisa.pm, ad eccezione ove indicato
The use of the camel image in association with the Perl language is a trademark of O'Reilly & Associates, Inc. Used with permission.