+my $id = $input->param('id');
+my $op = $input->param('op') || 'list';
+my @messages;
+
+if ( $op eq 'add_form' ) {
+ $template->param( quote => Koha::Quotes->find($id), );
+}
+elsif ( $op eq 'add_validate' ) {
+ my @fields = qw(
+ source
+ text
+ );
+
+ if ($id) {
+ my $quote = Koha::Quotes->find($id);
+ for my $field (@fields) {
+ $quote->$field( scalar $input->param($field) );
+ }
+
+ try {
+ $quote->store;
+ push @messages, { type => 'message', code => 'success_on_update' };
+ }
+ catch {
+ push @messages, { type => 'alert', code => 'error_on_update' };
+ }
+ }
+ else {
+ my $quote = Koha::Quote->new(
+ {
+ id => $id,
+ ( map { $_ => scalar $input->param($_) || undef } @fields )
+ }
+ );
+
+ try {
+ $quote->store;
+ push @messages, { type => 'message', code => 'success_on_insert' };
+ }
+ catch {
+ push @messages, { type => 'alert', code => 'error_on_insert' };
+ };
+ }
+ $op = 'list';
+}
+else {
+ $op = 'list';
+}
+
+$template->param( quotes_count => Koha::Quotes->search->count )
+ if $op eq 'list';
+
+$template->param(
+ messages => \@messages,
+ op => $op,
+);
+
+output_html_with_http_headers $input, $cookie, $template->output;