View | Details | Raw Unified | Return to bug 18606
Collapse All | Expand All

(-)a/C4/RotatingCollections.pm (-34 lines)
Lines 50-56 BEGIN { Link Here
50
    @EXPORT = qw(
50
    @EXPORT = qw(
51
      CreateCollection
51
      CreateCollection
52
      UpdateCollection
52
      UpdateCollection
53
      DeleteCollection
54
53
55
      GetItemsInCollection
54
      GetItemsInCollection
56
55
Lines 163-201 sub UpdateCollection { Link Here
163
162
164
}
163
}
165
164
166
=head2 DeleteCollection
167
168
 ( $success, $errorcode, $errormessage ) = DeleteCollection( $colId );
169
 Deletes a collection of the given id
170
171
 Input:
172
   $colId : id of the Archetype to be deleted
173
174
 Output:
175
   $success: 1 if all database operations were successful, 0 otherwise
176
   $errorCode: Code for reason of failure, good for translating errors in templates
177
   $errorMessage: English description of error
178
179
=cut
180
181
sub DeleteCollection {
182
    my ($colId) = @_;
183
184
    ## Parameter check
185
    if ( !$colId ) {
186
        return ( 0, 1, "NO_ID" );
187
    }
188
189
    my $dbh = C4::Context->dbh;
190
191
    my $sth;
192
193
    $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?");
194
    $sth->execute($colId) or return ( 0, 4, $sth->errstr() );
195
196
    return 1;
197
}
198
199
=head2 GetCollections
165
=head2 GetCollections
200
166
201
 $collections = GetCollections();
167
 $collections = GetCollections();
(-)a/rotating_collections/editCollections.pl (-17 / +17 lines)
Lines 23-32 use CGI qw ( -utf8 ); Link Here
23
use C4::Output;
23
use C4::Output;
24
use C4::Auth;
24
use C4::Auth;
25
use C4::Context;
25
use C4::Context;
26
27
use C4::RotatingCollections;
26
use C4::RotatingCollections;
28
27
28
use Koha::RotatingCollections;
29
29
my $query = new CGI;
30
my $query = new CGI;
31
my $action = $query->param('action');
32
my @messages;
30
33
31
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32
    {
35
    {
Lines 39-47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
39
    }
42
    }
40
);
43
);
41
44
42
my $action = $query->param('action');
43
$template->param( action => $action );
44
45
# Create new Collection
45
# Create new Collection
46
if ( $action eq 'create' ) {
46
if ( $action eq 'create' ) {
47
    my $title       = $query->param('title');
47
    my $title       = $query->param('title');
Lines 62-82 if ( $action eq 'create' ) { Link Here
62
        $template->param( createFailure  => 1 );
62
        $template->param( createFailure  => 1 );
63
        $template->param( failureMessage => $errorMessage );
63
        $template->param( failureMessage => $errorMessage );
64
    }
64
    }
65
}
65
} elsif ( $action eq 'delete' ) { # Delete collection
66
67
## Delete a club or service
68
elsif ( $action eq 'delete' ) {
69
    my $colId = $query->param('colId');
66
    my $colId = $query->param('colId');
70
    my ( $success, $errorCode, $errorMessage ) = DeleteCollection($colId);
67
    my $collection = Koha::RotatingCollections->find($colId);
68
    my $deleted = eval { $collection->delete; };
71
69
72
    $template->param( previousActionDelete => 1 );
70
    if ( $@ or not $deleted ) {
73
    if ($success) {
71
        push @messages, { type => 'error', code => 'error_on_delete' };
74
        $template->param( deleteSuccess => 1 );
72
    } else {
75
    }
73
        push @messages, { type => 'message', code => 'success_on_delete' };
76
    else {
77
        $template->param( deleteFailure  => 1 );
78
        $template->param( failureMessage => $errorMessage );
79
    }
74
    }
75
    $action = "list";
80
}
76
}
81
77
82
## Edit a club or service: grab data, put in form.
78
## Edit a club or service: grab data, put in form.
Lines 114-117 elsif ( $action eq 'update' ) { Link Here
114
    }
110
    }
115
}
111
}
116
112
113
$template->param(
114
    action   => $action,
115
    messages => \@messages,
116
);
117
117
output_html_with_http_headers $query, $cookie, $template->output;
118
output_html_with_http_headers $query, $cookie, $template->output;
118
- 

Return to bug 18606