--- /dev/null
+
+-- $Id: $
+-- $URL: $
+
+drop view if exists `v_autoren`;
+
+create view `v_autoren` as
+select `id`,
+ concat( ifnull( `titel`, '' ), if( isnull(`titel`), '', ' ' ),
+ ifnull( `vorname`, '' ), if( isnull(`vorname`), '', ' ' ),
+ ifnull( `mittelname`, '' ), if( isnull(`mittelname`), '', ' ' ),
+ `nachname`,
+ if( isnull( `name_suffix` ), '', ' ' ), ifnull( `name_suffix`, '' )
+ ) as `name`,
+ `titel`,
+ `vorname`,
+ `mittelname`,
+ `nachname`,
+ `name_suffix`,
+ `autor_descr`
+ from `autoren`
+ order by `nachname`, `vorname`, `mittelname`, `name_suffix` ;
+
+SELECT * FROM (
+ SELECT ab.`id` AS `autor2buch_id`,
+ ab.`buch_id` AS `buch_id`,
+ ab.`autor_id` AS `autor_id`,
+ CONCAT( IFNULL( a.`titel`, '' ), IF( ISNULL(a.`titel`), '', ' ' ),
+ IFNULL( a.`vorname`, '' ), IF( ISNULL(a.`vorname`), '', ' ' ),
+ IFNULL( a.`mittelname`, '' ), IF( ISNULL(a.`mittelname`), '', ' ' ),
+ a.`nachname`,
+ IF( ISNULL( a.`name_suffix` ), '', ' ' ), IFNULL( a.`name_suffix`, '' )
+ ) AS `autor_name`,
+ ab.`ord_num` AS `autor_ord_num`,
+ a.`titel` AS `autor_titel`,
+ a.`vorname` AS `autor_vorname`,
+ a.`mittelname` AS `autor_mittelname`,
+ a.`nachname` AS `autor_nachname`,
+ a.`name_suffix` AS `autor_name_suffix`,
+ a.`autor_descr` AS `autor_descr`,
+ b.`title` AS `title`,
+ b.`title_original` AS `title_original`,
+ b.`untertitel` AS `untertitel`
+ FROM autor2buch AS ab
+ LEFT JOIN `autoren` a ON ab.`autor_id` = a.`id`
+ RIGHT JOIN `buecher` b ON ab.`buch_id` = b.`id`
+ GROUP BY b.`id` ) AS c
+ORDER BY c.`autor_nachname`, c.`autor_vorname`, c.`autor_mittelname`, c.`autor_name_suffix`, c.`title`;
+
+DROP VIEW IF EXISTS `v_autor_buecher`;
+
+CREATE VIEW `v_autor_buecher` AS
+SELECT ab.`id` AS `autor2buch_id`,
+ ab.`buch_id` AS `buch_id`,
+ b.`title` AS `title`,
+ b.`title_original` AS `title_original`,
+ b.`untertitel` AS `untertitel`,
+ ab.`autor_id` AS `autor_id`,
+ CONCAT( IFNULL( a.`titel`, '' ), IF( ISNULL(a.`titel`), '', ' ' ),
+ IFNULL( a.`vorname`, '' ), IF( ISNULL(a.`vorname`), '', ' ' ),
+ IFNULL( a.`mittelname`, '' ), IF( ISNULL(a.`mittelname`), '', ' ' ),
+ a.`nachname`,
+ IF( ISNULL( a.`name_suffix` ), '', ' ' ), IFNULL( a.`name_suffix`, '' )
+ ) AS `autor_name`,
+ ab.`ord_num` AS `autor_ord_num`,
+ a.`titel` AS `autor_titel`,
+ a.`vorname` AS `autor_vorname`,
+ a.`mittelname` AS `autor_mittelname`,
+ a.`nachname` AS `autor_nachname`,
+ a.`name_suffix` AS `autor_name_suffix`,
+ a.`autor_descr` AS `autor_descr`
+ FROM autor2buch AS ab
+ LEFT JOIN `autoren` a ON ab.`autor_id` = a.`id`
+ RIGHT JOIN `buecher` b ON ab.`buch_id` = b.`id`
+ ORDER BY b.`title`, ab.`buch_id`, ab.`ord_num`;
+
+-- vim: noai : ts=4 fenc=utf-8 filetype=sql expandtab :
$c->session->{'return_target_del'} = $c->web_path("/books") unless $c->session->{'return_target_del'};
$c->session->{'return_target_new'} = $c->web_path("/books") unless $c->session->{'return_target_new'};
+ $c->stash->{'return_target_action'} = $c->web_path("/books");
+
$c->stash->{'cssfiles'} = [] unless $c->stash->{'cssfiles'};
push @{$c->stash->{'cssfiles'}}, 'books/styles.css';
$c->session->{'return_target_del'} = $c->web_path("/books");
$c->session->{'return_target_new'} = $c->web_path("/books");
+ delete $c->session->{'from_book_list'} if exists $c->session->{'from_book_list'};
+
}
#-------------------------------------------------------
} ## end sub default :
+#-------------------------------------------------------
+
+sub add_booklist_menu : Private {
+
+ my ( $self, $c ) = @_;
+ my $K = ( caller(0) )[3] . "(): ";
+
+ push @{ $c->stash->{'menu_path'} }, {
+ 'path' => $c->web_path("/books/list"),
+ 'name' => "Liste"
+ };
+
+}
+
#-------------------------------------------------------
=head2 list
my $K = ( caller(0) )[3] . "(): ";
$c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
- push @{ $c->stash->{'menu_path'} }, {
- 'path' => $c->web_path("/books/list"),
- 'name' => "Liste"
- };
+ $self->add_booklist_menu($c);
my $buchliste = get_booklist( $c );
$c->log->debug( get_output_string( $K, "Erhaltene Buchliste: ", $buchliste ) ) if $c->stash->{'debug_level'} >= 2;
$c->session->{'return_target_edit'} = $c->web_path("/books/list");
$c->session->{'return_target_del'} = $c->web_path("/books/list");
$c->session->{'return_target_new'} = $c->web_path("/books/list");
-
+ $c->session->{'from_book_list'} = 1;
}
#-------------------------------------------------------
$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/new"),
'name' => "Neu"
$c->stash->{'error_message'} = '';
+ if ( $c->session->{'book_data_edit'} and $c->session->{'book_data_edit'}{'id'} ) {
+ delete $c->session->{'book_data_edit'};
+ }
+
$self->prepare_data_structures($c);
$self->bookdata_cgi2session($c);
return 1;
}
+ $c->stash->{'return_target_action'} = $c->session->{'return_target_new'};
return $self->do_save_book($c);
}
$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/view"),
'name' => "Betrachten"
$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/edit"),
'name' => "Ändern"
$c->stash->{'error_message'} = '';
+ # Zu bearbeitende Buch-Id ermitteln
my $buch_id = to_int( $c->request->params->{'edit_book_id'} || 0 );
+
+ unless ( $buch_id ) {
+ if ( $c->session->{'book_data_edit'} and $c->session->{'book_data_edit'}{'id'} ) {
+ $buch_id = $c->session->{'book_data_edit'}{'id'};
+ }
+ }
+
+ # Keine Buch-Id da?
unless ( $buch_id ) {
$c->stash->{'template'} = 'error.tt2';
$c->stash->{'error'} = 'Keine oder ungültige Buch-Id übergeben.';
return 1;
}
+ # Angaben zum Buch aus der Datenbank holen
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';
my $buch = $buchliste->[0];
+ $c->log->debug( get_output_string( $K, "Buch aus Datenbank: ", $buch ) ) if $c->stash->{'debug_level'} >= 2;
+
+ # Umbiegen der Datenstrukturen (keine Konsistenz - narf!)
$buch->{'autoren'} = $buch->{'autor_ids'};
delete $buch->{'autor_ids'} if exists $buch->{'autor_ids'};
$buch->{'serien'} = $buch->{'serien_ids'};
delete $buch->{'serien_ids'} if exists $buch->{'serien_ids'};
+ $buch->{'original_title'} = $buch->{'title_original'};
+
+ $c->log->debug( get_output_string( $K, "Buch nach Bereinigung: ", $buch ) ) if $c->stash->{'debug_level'} >= 2;
+
+ # Ruecksprung-URL bestimmen
$c->stash->{'return_target'} = $c->session->{'return_target_edit'} or $c->web_path("/books/list");
- $c->stash->{'book_edit'} = $buch;
- $c->session->{'book_data_edit'} = $buch;
+ # Sitzungsdaten vorbelegen, falls noch nicht geschehen
+ if ( $c->session->{'book_data_edit'} ) {
+ if ( ! $c->session->{'book_data_edit'}{'id'} or $c->session->{'book_data_edit'}{'id'} != $buch_id ) {
+ $c->session->{'book_data_edit'} = $buch;
+ }
+ }
+ else {
+ $c->session->{'book_data_edit'} = $buch;
+ }
$buchliste = undef;
$self->prepare_data_structures($c);
return 1;
}
+ $c->stash->{'return_target_action'} = $c->session->{'return_target_edit'};
return $self->do_save_book($c);
}
my $book = $c->stash->{'book_edit'};
+ # Felder vorbereiten
$book->{'autoren'} = $c->stash->{'autor_list_book'};
$book->{'kategorien'} = $c->stash->{'kategorie_list_book'};
$book->{'serien'} = $c->stash->{'serienliste_book'};
+
$c->log->debug( get_output_string( $K . "Buchangaben, die gesichert werden sollen: ", $book ) );
return 1 unless $self->check_formparams( $c, $book );
+ $c->log->debug( get_output_string( $K . "Buchangaben, die gesichert werden: ", $book ) );
my $book_id = undef;
}
$c->stash->{'template'} = 'books/save_success.tt2';
- delete $c->session->{'book_data_edit'} if exists $c->session->{'book_data_edit'};
+ if ( exists $c->session->{'book_data_edit'} ) {
+ $c->log->debug( $K . "Loesche Buchdaten in der Session ..." );
+ delete $c->session->{'book_data_edit'};
+ }
return 1;
my ( $self, $c, $book ) = @_;
my $K = ( caller(0) )[3] . "(): ";
+ # Titel trimmen
+ $book->{'title'} = '' unless defined $book->{'title'};
+ $book->{'title'} =~ s/^\s+//;
+ $book->{'title'} =~ s/\s+$//;
+
+ # Untertitel trimmen
+ if ( defined $book->{'untertitel'} ) {
+ $book->{'untertitel'} =~ s/^\s+//;
+ $book->{'untertitel'} =~ s/\s+$//;
+ $book->{'untertitel'} = undef if $book->{'untertitel'} eq "";
+ }
+
+ # Original-Titel trimmen
+ if ( defined $book->{'original_title'} ) {
+ $book->{'original_title'} =~ s/^\s+//;
+ $book->{'original_title'} =~ s/\s+$//;
+ $book->{'original_title'} = undef if $book->{'original_title'} eq "";
+ }
+
+ # ISBN trimmen
+ if ( defined $book->{'isbn'} ) {
+ $book->{'isbn'} =~ s/^\s+//;
+ $book->{'isbn'} =~ s/\s+$//;
+ $book->{'isbn'} = undef if $book->{'isbn'} eq "";
+ }
+
+ # Verlags-Buchnummer trimmen
+ if ( defined $book->{'book_nr'} ) {
+ $book->{'book_nr'} =~ s/^\s+//;
+ $book->{'book_nr'} =~ s/\s+$//;
+ $book->{'book_nr'} = undef if $book->{'book_nr'} eq "";
+ }
+
+ # Ausgabejahr trimmen
+ if ( defined $book->{'ausgabejahr'} ) {
+ my ( $jahr ) = $book->{'ausgabejahr'} =~ /(\d+)/;
+ $book->{'ausgabejahr'} = $jahr;
+ }
+
+ # Druckjahr trimmen
+ if ( defined $book->{'druckjahr'} ) {
+ my ( $jahr ) = $book->{'druckjahr'} =~ /(\d+)/;
+ $book->{'druckjahr'} = $jahr;
+ }
+
+ # Seitenzahl trimmen
+ if ( defined $book->{'seiten'} ) {
+ my ( $seiten ) = $book->{'seiten'} =~ /(\d+)/;
+ $book->{'seiten'} = $seiten;
+ }
+
+ # Preis trimmen
+ if ( defined $book->{'preis'} ) {
+ $book->{'preis'} =~ s/^\s+//;
+ $book->{'preis'} =~ s/\s+$//;
+ if ( $book->{'preis'} =~ /\d/ ) {
+ $book->{'preis'} = to_float( $book->{'preis'} ) + 0;
+ }
+ else {
+ $book->{'preis'} = undef;
+ }
+ }
+
unless ( $book->{'title'} ) {
$c->stash->{'error_message'} = "Kein Buchtitel angegeben.";
return undef;
$c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
my $storage = $c->stash->{'storage'};
- $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+ #$c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
my $save_func = sub {
push @params, $buch->{'title'};
push @params, $buch->{'original_title'};
- push @params, $buch->{'verlags_id'};
push @params, $buch->{'untertitel'};
+ push @params, $buch->{'verlags_id'};
push @params, $buch->{'orts_id'};
push @params, $buch->{'bindungsart_id'};
push @params, $buch->{'isbn'};
my $K = ( caller(0) )[3] . "(): ";
my $storage = $c->stash->{'storage'};
- $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+ # $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
my $dbh = $storage->dbh();
- $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
+ # $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
my $anzahl = 0;
$anzahl = scalar( @$autor_ids ) if $autor_ids and ref($autor_ids) and ref($autor_ids) eq 'ARRAY';
my $K = ( caller(0) )[3] . "(): ";
my $storage = $c->stash->{'storage'};
- $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+ # $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
my $dbh = $storage->dbh();
- $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
+ # $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
my $anzahl = 0;
$anzahl = scalar( @$serien_ids ) if $serien_ids and ref($serien_ids) and ref($serien_ids) eq 'ARRAY';
my $K = ( caller(0) )[3] . "(): ";
my $storage = $c->stash->{'storage'};
- $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+ # $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
my $dbh = $storage->dbh();
- $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
+ # $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
my $anzahl = 0;
$anzahl = scalar( @$kategorie_ids ) if $kategorie_ids and ref($kategorie_ids) and ref($kategorie_ids) eq 'ARRAY';