--- /dev/null
+package FrBr::Books::Controller::Autor;
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+use FrBr::Common;
+use FrBr::Books::Util::Author;
+
+=head1 NAME
+
+FrBr::Books::Controller::Autor - Catalyst Controller fuer alle Autorensachen
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+#-------------------------------------------------------
+
+=head2 auto
+
+=cut
+
+sub auto : Private {
+
+ my ( $self, $c ) = @_;
+ my $K = __PACKAGE__ . "::auto(): ";
+
+ $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+ $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
+ push @{ $c->stash->{'menu_path'} }, {
+ 'path' => $c->web_path("/autor"),
+ 'name' => "Autoren"
+ };
+
+ $c->stash->{'cssfiles'} = [] unless $c->stash->{'cssfiles'};
+ push @{$c->stash->{'cssfiles'}}, 'autor/styles.css';
+
+ 1;
+
+} ## end sub auto :
+
+#-------------------------------------------------------
+
+=head2 index
+
+=cut
+
+sub index : Private {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{'template'} = 'autor/index.tt2';
+
+}
+
+#-------------------------------------------------------
+
+=head2 default
+
+=cut
+
+sub default : Private {
+
+ my ( $self, $c ) = @_;
+ my $K = __PACKAGE__ . "::default(): ";
+
+ $c->stash->{'template'} = 'not_implemented.tt2';
+
+ push @{ $c->stash->{'menu_path'} }, {
+ 'path' => $c->web_path("/autor/default"),
+ 'name' => "Nicht Implementiert"
+ };
+
+} ## end sub default :
+
+#-------------------------------------------------------
+
+=head2 form_new( )
+
+Erstellen eines neuen Autors.
+
+=cut
+
+sub form_new : Path('new') {
+
+ my ( $self, $c ) = @_;
+ my $K = __PACKAGE__ . "::form_new(): ";
+
+ $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+ $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
+ push @{ $c->stash->{'menu_path'} }, {
+ 'path' => $c->web_path("/autor/new"),
+ 'name' => "Neu"
+ };
+
+ $c->stash->{'template'} = 'autor/new.tt2';
+ push @{$c->stash->{'cssfiles'}}, 'autor/form.css';
+
+ $c->stash->{'error_message'} = '';
+
+# $self->prepare_data_structures($c);
+
+ $self->autor_cgi2session($c);
+
+ $c->stash->{'autor_edit'} = {} unless $c->stash->{'autor_edit'};
+ $self->autor_session2stash($c);
+ $c->stash->{'autor_edit'}{'name'} = "Neuer Autor" unless $c->stash->{'autor_edit'}{'name'};
+
+ return 1 unless $c->request->params->{'autor_form_sent'} and $c->request->params->{'do_save'};
+ return 1 unless $self->check_formparams($c);
+
+ return 1;
+
+}
+
+#-------------------------------------------------------
+
+sub save_author : Private {
+
+ my ( $self, $c ) = @_;
+ my $K = __PACKAGE__ . "::save_author(): ";
+
+
+
+}
+
+#-------------------------------------------------------
+
+sub check_formparams : Private {
+
+ my ( $self, $c ) = @_;
+ my $K = __PACKAGE__ . "::check_formparams(): ";
+
+ unless ( $c->stash->{'autor_edit'} ) {
+ $c->stash->{'error_message'} = "Interner Fehler";
+ return undef;
+ }
+
+ unless ( $c->stash->{'autor_edit'} ) {
+ $c->stash->{'error_message'} = "Kein Name des Autors angegeben.";
+ return undef;
+ }
+
+ return 1;
+
+}
+
+#-------------------------------------------------------
+
+sub autor_session2stash : Private {
+
+ my ( $self, $c ) = @_;
+ my $K = __PACKAGE__ . "::autor_session2stash(): ";
+
+ $c->stash->{'autor_edit'} = {} unless $c->stash->{'autor_edit'};
+ $c->stash->{'autor_edit'}{'id'} = $c->session->{'autor_data_edit'}{'id'} if $c->session->{'autor_data_edit'}{'id'};
+ $c->stash->{'autor_edit'}{'name'} = $c->session->{'autor_data_edit'}{'name'} if $c->session->{'autor_data_edit'}{'name'};
+ $c->stash->{'autor_edit'}{'desc'} = $c->session->{'autor_data_edit'}{'desc'} if $c->session->{'autor_data_edit'}{'desc'};
+
+ return 1;
+
+}
+
+#-------------------------------------------------------
+
+sub autor_cgi2session : Private {
+
+ my ( $self, $c ) = @_;
+ my $K = __PACKAGE__ . "::autor_cgi2session(): ";
+
+ return 1 unless $c->request->params->{'autor_form_sent'};
+
+ # Basis anlegen, wenn notwendig
+ $c->session->{'autor_data_edit'} = {} unless $c->session->{'autor_data_edit'};
+
+ # Autor-Id eintragen, wenn notwendig
+ $c->session->{'autor_data_edit'}{'id'} = $c->request->params->{'autor_id'} if $c->request->params->{'autor_id'};
+
+ # Name des Autors
+ if ( defined $c->request->params->{'autor_name'} ) {
+ my $name = $c->request->params->{'autor_name'};
+ $name =~ s/^\s+//;
+ $name =~ s/\s+$//;
+ $c->session->{'autor_data_edit'}{'name'} = $name;
+ }
+
+ # Untertitel
+ $c->session->{'autor_data_edit'}{'desc'} = $c->request->params->{'autor_desc'} if defined $c->request->params->{'autor_desc'};
+
+ return 1;
+
+}
+
+#-------------------------------------------------------
+
+
+=head1 AUTHOR
+
+Frank Brehm
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
@ISA = qw(Exporter);
@EXPORT = qw(
&get_author_list
+ &save_autor
);
#%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
#-----------------------------------------------------------------------------------
+=head2 save_autor( $c, $autor )
+
+=cut
+
+sub save_autor {
+
+ my $c = shift;
+ my $autor = shift;
+ my $K = __PACKAGE__ . "::save_autor(): ";
+
+ $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+ my $storage = $c->stash->{'storage'};
+
+ my $save_func = sub {
+ my ( $storage, $dbh, $autor_id, $name, $desc ) = @_;
+ my $sql = <<ENDE;
+INSERT INTO `autoren` (
+ `id`, `autor_name`, `autor_descr` )
+ VALUES (
+ ?, ?, ? )
+ ON DUPLICATE KEY UPDATE
+ `autor_name` = ?, `autor_descr` = ?
+ENDE
+
+ if ( $storage->debug() ) {
+ my $text = $sql;
+ $text =~ s/\s+$//;
+ $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $uid, $ptype_id, $value, $value ) ) . "\n";
+ warn $text;
+ }
+
+ my $sth = $dbh->prepare($sql);
+ $sth->execute( $autor_id, $name, $desc, $name, $desc );
+ };
+
+ $storage->dbh_do( $save_func, $autor->{'id'}, $autor->{'name'}, $autor->{'desc'} );
+
+ return $storage->last_insert_id();
+
+}
+
+#-----------------------------------------------------------------------------------
+
=head1 AUTHOR
Frank Brehm
--- /dev/null
+[%#
+ Template fuer Autorenangaben
+
+ $Id$
+ $URL$
+
+-%]
+
+<!-- Autoren-Formular -->
+
+<form method="post" name="autor_form" action="[% self_url %]">
+<input type="hidden" name="autor_form_sent" value="sent" />
+[%- IF autor_edit.id %]<input type="hidden" name="autor_id" value="[% autor_edit.id | html %]" />[% END %]
+ <table class="ftable" cellspacing="0">
+ <tr>
+ <th colspan="2" class="title">[% autor_form_title %]</th>
+ </tr><tr>
+ <td colspan="2"> </td>
+ </tr><tr>
+ <th>Name des Autors:</th>
+ <td><input type="text" name="autor_name" size="50" maxlength="250" value="[% autor_edit.name | html %]" /></td>
+ </tr><tr>
+ <th>Zusätzliche Angaben:</th>
+ <td><textarea name="autor_desc" cols="50" rows="5">[% autor_edit.desc | html %]</textarea></td>
+ </tr><tr>
+ <td colspan="2"> </td>
+ </tr><tr>
+ <th colspan="2" class="button"><input type="submit" name="do_save" value=" OK " /></th>
+ </tr>
+ </table>
+</form>
+[%- IF error_message %]
+<div class="error">
+<span class="bold">Fehler:</span> [% error_message %]
+</div>
+[% END -%]