#-------------------------------------------------------
+=head2 delete_buch( )
+
+Löscht ein vorhandenes Buch.
+
+=cut
+
+sub delete_buch : Path('delete') {
+
+ my ( $self, $c ) = @_;
+ my $K = ( caller(0) )[3] . "(): ";
+
+ $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+ $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
+ $self->add_booklist_menu($c) if $c->session->{'from_book_list'};
+ push @{ $c->stash->{'menu_path'} }, {
+ 'path' => $c->web_path("/books/delete"),
+ 'name' => "Löschen"
+ };
+
+ $c->stash->{'error_message'} = '';
+
+ my $buch_id = to_int( $c->request->params->{'delete_book_id'} || $c->session->{'delete_book_id'} || 0 );
+ unless ( $buch_id ) {
+ $c->stash->{'template'} = 'error.tt2';
+ $c->stash->{'error'} = 'Keine oder ungültige Buch-Id übergeben.';
+ return 1;
+ }
+ $c->session->{'delete_book_id'} = $buch_id;
+
+ my $buchliste = get_booklist( $c, 'buch_id' => $buch_id );
+ $c->log->debug( get_output_string( $K, "Erhaltene Buchliste: ", $buchliste ) ) if $c->stash->{'debug_level'} >= 2;
+
+ unless ( $buchliste and scalar( @$buchliste ) ) {
+ $c->stash->{'template'} = 'error.tt2';
+ $c->stash->{'error'} = 'Zur übergebenen Buch-Id wurde kein Buch gefunden.';
+ return 1;
+ }
+
+ $c->stash->{'return_target'} = $c->session->{'return_target_del'} or $c->web_path("/books/list");
+
+ $c->stash->{'book'} = $buchliste->[0];
+ $buchliste = undef;
+
+ $c->stash->{'template'} = 'books/delete.tt2';
+ push @{$c->stash->{'cssfiles'}}, 'books/view.css';
+
+ if ( $c->request->params->{'really_delete_book'} and $c->request->params->{'really_delete_book'} eq 'yes' and $c->request->params->{'do_delete'} ) {
+ eval {
+ delete_book( $c, $buch_id );
+ };
+ if ( $@ ) {
+ $c->stash->{'error_message'} = $@;
+ $c->log->warn( "Fehler beim Löschen des Buches: " . $@ );
+ return undef;
+ }
+ $c->stash->{'template'} = 'books/delete_success.tt2';
+ delete $c->session->{'delete_book_id'} if exists $c->session->{'delete_book_id'};
+ delete $c->session->{'book_data_edit'} if exists $c->session->{'book_data_edit'};
+ }
+
+}
+
+#-------------------------------------------------------
+
=head2 form_edit( )
Aendern eines vorhandenen Buches.
delete $buch->{'serien_ids'} if exists $buch->{'serien_ids'};
$buch->{'original_title'} = $buch->{'title_original'};
+ $buch->{'book_nr'} = $buch->{'buch_nr'};
$c->log->debug( get_output_string( $K, "Buch nach Bereinigung: ", $buch ) ) if $c->stash->{'debug_level'} >= 2;
$book->{'seiten'} = $seiten;
}
+ # Bindungsart-Id trimmen
+ if ( defined $book->{'bindungsart_id'} ) {
+ my ( $id ) = $book->{'bindungsart_id'} =~ /(\d+)/;
+ $book->{'bindungsart_id'} = $id;
+ }
+
+ # Orts-Id trimmen
+ if ( defined $book->{'orts_id'} ) {
+ my ( $id ) = $book->{'orts_id'} =~ /(\d+)/;
+ $book->{'orts_id'} = $id;
+ }
+
+ # Verlags-Id trimmen
+ if ( defined $book->{'verlags_id'} ) {
+ my ( $id ) = $book->{'verlags_id'} =~ /(\d+)/;
+ $book->{'verlags_id'} = $id;
+ }
+
+ # Waehrungs-Id trimmen
+ if ( defined $book->{'waehrungs_id'} ) {
+ my ( $id ) = $book->{'waehrungs_id'} =~ /(\d+)/;
+ $book->{'waehrungs_id'} = $id;
+ }
+
# Preis trimmen
if ( defined $book->{'preis'} ) {
$book->{'preis'} =~ s/^\s+//;
@EXPORT = qw(
&get_booklist
&save_book
+ &delete_book
);
#%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
#-----------------------------------------------------------------------------------
+=head2 delete_book( $c, $book_id )
+
+Loescht das Buch mit der uebergebenen Buch-Id
+
+=cut
+
+sub delete_book {
+
+ my $c = shift;
+ my $book_id = shift;
+ my $K = ( caller(0) )[3] . "(): ";
+
+ $c->log->debug( $K . "aufgerufen fuer Buch-Id " . ( defined $book_id ? $book_id : '<undef>' ) . "." ) if $c->stash->{'debug_level'} > 2;
+
+ return undef unless $book_id and to_int($book_id);
+ $book_id = to_int($book_id);
+
+ my $schema = $c->model('Schema')->{'schema'};
+ #$c->log->debug( get_output_string( $K . "Schema: ", $schema ) ) if $c->stash->{'debug_level'} > 4;
+ my $search_params = {
+ 'buch_id' => $book_id,
+ };
+
+ my $coderef = sub {
+ $c->model('Schema::Autor2buch')->search( $search_params )->delete();
+ $c->model('Schema::Buch2kategorie')->search( $search_params )->delete();
+ $c->model('Schema::Buch2serie')->search( $search_params )->delete();
+ $c->model('Schema::Buecher')->search( { 'id' => $book_id } )->delete();
+ };
+
+ my $rs;
+ eval {
+ $rs = $schema->txn_do($coderef);
+ };
+
+ if ($@) { # Transaction failed
+ die "Rollback nicht erfolgreich!" if ($@ =~ /Rollback failed/i ); # Rollback failed
+ die $@;
+ }
+
+}
+
+#-----------------------------------------------------------------------------------
+
=head2 save_book( $c, $book )
$book = {
color: [% site.col.error %];
}
+DIV.error {
+ white-space: pre;
+}
+
TABLE.menu {
font-size: 14pt;
margin-left: auto;
--- /dev/null
+<!-- [%#
+
+ Template zum Löschen eines Buches
+
+ vim: noai : ts=4 fenc=utf-8 filetype=html expandtab :
+
+ $Id$
+ $URL$
+
+ Übergebene Struktur in [book]:
+
+ $buch = {
+ 'ausgabejahr' => '2003',
+ 'autoren' => [
+ 'Bill Napier'
+ ],
+ 'bindungsart' => 'Softcover (Taschenbuch)',
+ 'bindungsart_id' => '4',
+ 'buch_nr' => '093314',
+ 'druckjahr' => '2007',
+ 'id' => '5',
+ 'isbn' => undef,
+ 'kategorien' => [
+ 'Mystery-Thriller'
+ ],
+ 'ort_beschreibung' => undef,
+ 'ort_ist_statisch' => undef,
+ 'orts_id' => undef,
+ 'ortsname' => undef,
+ 'preis' => '7.45',
+ 'seiten' => '416',
+ 'serien' => [],
+ 'title' => 'Der 77. Grad',
+ 'title_original' => 'Shattered Icon',
+ 'umrechnung_in_euro' => '1',
+ 'untertitel' => undef,
+ 'verlags_id' => '3',
+ 'verlagsname_long' => 'Bertelsmann Club GmbH - Taschenbuch',
+ 'verlagsname_short' => 'Club Taschenbuch',
+ 'waehrungs_id' => '1',
+ 'waehrungs_kuerzel' => '€',
+ 'waehrungs_name' => 'Euro'
+ }
+-%]
+
+Buch löschen -->
+
+<form method="post" name="book_form" action="[% self_url %]">
+<input type="hidden" name="really_delete_book" value="yes" />
+<input type="hidden" name="book_id" value="[% book.id | html %]" />
+
+<table class="ftable" cellspacing="0">
+ <tr>
+ <th colspan="2" class="title">Möchten Sie das Buch '[%- book.title | html -%]' wirklich löschen?</th>
+ </tr><tr>
+ <td colspan="2" class="empty"></td>
+ </tr><tr>
+ <th>Autor (-en):</th>
+ <td>[% IF book.autoren.size > 1 %]<ul>[% FOR autor IN book.autoren %]<li>[% autor %]</li>[% END %]</ul>[% ELSE %][% book.autoren.0 %][% END %]</td>
+ </tr><tr>
+ <th>Buchtitel:</th>
+ <td>[% book.title | html %]</td>
+ </tr><tr>
+ <th>Untertitel:</th>
+ <td>[% book.untertitel | html %]</td>
+ </tr><tr>
+ <th>Original-Titel:</th>
+ <td>[% book.title_original | html %]</td>
+ </tr><tr>
+ <th>Verlag:</th>
+ <td>[% book.verlagsname_long | html %]</td>
+ </tr><tr>
+ <th>Aufbewahrungsort:</th>
+ <td>[% book.ortsname | html %]</td>
+ </tr><tr>
+ <th>Bindungsart:</th>
+ <td>[% book.bindungsart | html %]</td>
+ </tr><tr>
+ <th>Kategorie(n):</th>
+ <td>[% IF book.kategorien.size > 1 %]<ul>[% FOR kat IN book.kategorien %]<li>[% kat %]</li>[% END %]</ul>[% ELSE %][% book.kategorien.0 %][% END %]</td>
+ </tr><tr>
+ <th>Buchserien:</th>
+ <td>[% IF book.serien.size > 1 %]<ul>[% FOR serie IN book.serien %]<li>[% serie %]</li>[% END %]</ul>[% ELSE %][% book.serien.0 %][% END %]</td>
+ </tr><tr>
+ <th>ISBN:</th>
+ <td>[% book.isbn | html %]</td>
+ </tr><tr>
+ <th>Buch-Nummer (verlagseigen):</th>
+ <td>[% book.buch_nr | html %]</td>
+ </tr><tr>
+ <th>Ausgabejahr:</th>
+ <td>[% book.ausgabejahr | html %]</td>
+ </tr><tr>
+ <th>Druckjahr:</th>
+ <td>[% book.druckjahr | html %]</td>
+ </tr><tr>
+ <th>Seiten:</th>
+ <td>[% book.seiten | html %]</td>
+ </tr><tr>
+ <th>Preis:</th>
+ <td>[% book.preis | format('%.2f') | replace('\.', ',') %] [% book.waehrungs_kuerzel | html %]</td>
+ </tr><tr>
+ <td colspan="2" class="empty"></td>
+ </tr><tr>
+ <th colspan="2" class="button"><input type="submit" name="do_delete" value=" Löschen " /></th>
+</table>
+
+[%- IF error_message %]
+<div class="error">
+<span class="bold">Fehler:</span> [% error_message %]
+</div>
+[% END -%]
+
+<div class="back">
+<h2><a href="[% return_target %]">[% 'Zurück' %]</a></h2>
+</div>
+
--- /dev/null
+<!-- [%#
+
+ Template zum Melden des erfolgreichen Löschen eines Buches
+
+ vim: noai : ts=4 fenc=utf-8 filetype=html expandtab :
+
+ $Id$
+ $URL$
+
+ Übergebene Struktur in [book]:
+
+ $buch = {
+ 'ausgabejahr' => '2003',
+ 'autoren' => [
+ 'Bill Napier'
+ ],
+ 'bindungsart' => 'Softcover (Taschenbuch)',
+ 'bindungsart_id' => '4',
+ 'buch_nr' => '093314',
+ 'druckjahr' => '2007',
+ 'id' => '5',
+ 'isbn' => undef,
+ 'kategorien' => [
+ 'Mystery-Thriller'
+ ],
+ 'ort_beschreibung' => undef,
+ 'ort_ist_statisch' => undef,
+ 'orts_id' => undef,
+ 'ortsname' => undef,
+ 'preis' => '7.45',
+ 'seiten' => '416',
+ 'serien' => [],
+ 'title' => 'Der 77. Grad',
+ 'title_original' => 'Shattered Icon',
+ 'umrechnung_in_euro' => '1',
+ 'untertitel' => undef,
+ 'verlags_id' => '3',
+ 'verlagsname_long' => 'Bertelsmann Club GmbH - Taschenbuch',
+ 'verlagsname_short' => 'Club Taschenbuch',
+ 'waehrungs_id' => '1',
+ 'waehrungs_kuerzel' => '€',
+ 'waehrungs_name' => 'Euro'
+ }
+-%]
+
+Buch wurde gelöscht -->
+
+<div style="text-align: center">
+
+Das Buch <b>"[% book.title | html %]"</b>
+von <b>[% tt_authors = [ ]; tt_authors.push(autor) FOREACH autor = book.autoren %][% tt_authors.join(', ') | html %]</b> wurde erfolgreich gelöscht.
+
+</div>
+
+<div class="back">
+<h2><a href="[% return_target %]">[% 'OK' %]</a></h2>
+</div>
+
<tr>
<th colspan="2" class="title">[% book_form_title %]</th>
</tr><tr>
- <td colspan="2"> </td>
+ <td colspan="2" class="empty"></td>
</tr><tr>
<th>Autor (-en):</th>
<td>
<option value="[% waehrungsid %]"[% IF book_edit.waehrungs_id == waehrungsid %] selected[% END %]>[% waehrungsliste.$waehrungsid.kuerzel %]</option>[% END %]
</select> <input type="button" name="neue_waehrung" value="*" class="shift_button" title="Neue Währung" /></td>
</tr><tr>
- <td colspan="2"> </td>
+ <td colspan="2" class="empty"></td>
</tr><tr>
<th colspan="2" class="button"><input type="submit" name="do_save" value=" OK " /></th>
</tr>
background-color: [% site.col.list_row_bold %];
}
+TABLE.ftable TD.empty {
+ height: 0.5em;
+}
+
TABLE.ftable TH.button {
font-weight: bolder;
text-align: center;
padding-right: 1em;
}
+TABLE.ftable TH.button INPUT {
+ font-weight: bolder;
+ text-align: center;
+ font-size: 1em;
+ padding-left: 1em;
+ padding-right: 1em;
+}
+
TABLE.buchliste {
text-align: left;
border-width: 2px;
-[%#
+<!-- [%#
Template fuer Buchanzeige
vim: noai : ts=4 fenc=utf-8 filetype=html expandtab :
-%]
-<!-- Buchanzeige -->
+Buchanzeige -->
<table class="ftable" cellspacing="0">
<tr>
<th colspan="2" class="title">Buchangaben '[%- book.title | html -%]'</th>
</tr><tr>
- <td colspan="2"> </td>
+ <td colspan="2" class="empty"></td>
</tr><tr>
<th>Autor (-en):</th>
<td>[% IF book.autoren.size > 1 %]<ul>[% FOR autor IN book.autoren %]<li>[% autor %]</li>[% END %]</ul>[% ELSE %][% book.autoren.0 %][% END %]</td>
<td>[% book.isbn | html %]</td>
</tr><tr>
<th>Buch-Nummer (verlagseigen):</th>
- <td>[% book.book_nr | html %]</td>
+ <td>[% book.buch_nr | html %]</td>
</tr><tr>
<th>Ausgabejahr:</th>
<td>[% book.ausgabejahr | html %]</td>