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

(-)a/C4/VirtualShelves.pm (-56 lines)
Lines 42-48 BEGIN { Link Here
42
    @EXPORT = qw(
42
    @EXPORT = qw(
43
            &GetShelves &GetShelfContents
43
            &GetShelves &GetShelfContents
44
            &AddToShelf
44
            &AddToShelf
45
            &ModShelf
46
            &ShelfPossibleAction
45
            &ShelfPossibleAction
47
            &DelFromShelf
46
            &DelFromShelf
48
            &GetBibliosShelves
47
            &GetBibliosShelves
Lines 307-367 sub AddToShelf { Link Here
307
    $sth->execute( $shelfnumber );
306
    $sth->execute( $shelfnumber );
308
}
307
}
309
308
310
=head2 ModShelf
311
312
my $result= ModShelf($shelfnumber, $hashref)
313
314
Where $hashref->{column} = param
315
316
Modify the value into virtualshelves table with values given 
317
from hashref, which each key of the hashref should be
318
the name of a column of virtualshelves.
319
Fields like shelfnumber or owner cannot be changed.
320
321
Returns 1 if the action seemed to be successful.
322
323
=cut
324
325
sub ModShelf {
326
    my ($shelfnumber,$hashref) = @_;
327
    my $dbh = C4::Context->dbh;
328
329
    my $query= "SELECT * FROM virtualshelves WHERE shelfnumber=?";
330
    my $sth = $dbh->prepare($query);
331
    $sth->execute($shelfnumber);
332
    my $oldrecord= $sth->fetchrow_hashref;
333
    return 0 unless $oldrecord; #not found?
334
335
    #initialize missing hash values to silence warnings
336
    foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) {
337
        $hashref->{$_}= undef unless exists $hashref->{$_};
338
    }
339
340
    #if name or category changes, the name should be tested
341
    if($hashref->{shelfname} || $hashref->{category}) {
342
        unless(_CheckShelfName(
343
            $hashref->{shelfname}//$oldrecord->{shelfname},
344
            $hashref->{category}//$oldrecord->{category},
345
            $oldrecord->{owner},
346
            $shelfnumber )) {
347
                return 0; #name check failed
348
        }
349
    }
350
351
    #only the following fields from the hash may be changed
352
    $query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?";
353
    $sth = $dbh->prepare($query);
354
    $sth->execute(
355
        $hashref->{shelfname}//$oldrecord->{shelfname},
356
        $hashref->{category}//$oldrecord->{category},
357
        $hashref->{sortfield}//$oldrecord->{sortfield},
358
        $hashref->{allow_add}//$oldrecord->{allow_add},
359
        $hashref->{allow_delete_own}//$oldrecord->{allow_delete_own},
360
        $hashref->{allow_delete_other}//$oldrecord->{allow_delete_other},
361
        $shelfnumber );
362
    return $@? 0: 1;
363
}
364
365
=head2 ShelfPossibleAction
309
=head2 ShelfPossibleAction
366
310
367
ShelfPossibleAction($loggedinuser, $shelfnumber, $action);
311
ShelfPossibleAction($loggedinuser, $shelfnumber, $action);
(-)a/C4/VirtualShelves/Page.pm (-11 / +10 lines)
Lines 180-196 sub shelfpage { Link Here
180
                        push @paramsloop, { nopermission => $shelfnumber };
180
                        push @paramsloop, { nopermission => $shelfnumber };
181
                        last SWITCH;
181
                        last SWITCH;
182
                }
182
                }
183
                my $shelf = {
183
                my $shelf = Koha::Virtualshelves->find( $shelfnumber );
184
                    shelfname          => $query->param('shelfname'),
184
                $shelf->shelfname($query->param('shelfname'));
185
                    sortfield          => $query->param('sortfield'),
185
                $shelf->sortfield($query->param('sortfield'));
186
                    allow_add          => $query->param('allow_add'),
186
                $shelf->allow_add($query->param('allow_add'));
187
                    allow_delete_own   => $query->param('allow_delete_own'),
187
                $shelf->allow_delete_own($query->param('allow_delete_own'));
188
                    allow_delete_other => $query->param('allow_delete_other'),
188
                $shelf->allow_delete_other($query->param('allow_delete_other'));
189
                };
189
                if( my $category = $query->param('category')) { #optional
190
                if($query->param('category')) { #optional
190
                    $shelf->category($category);
191
                    $shelf->{category}= $query->param('category');
192
                }
191
                }
193
                unless(ModShelf($shelfnumber, $shelf )) {
192
                eval { $shelf->store };
193
                if ( $@ ) {
194
                  push @paramsloop, {modifyfailure => $shelf->{shelfname}};
194
                  push @paramsloop, {modifyfailure => $shelf->{shelfname}};
195
                  last SWITCH;
195
                  last SWITCH;
196
                }
196
                }
197
- 

Return to bug 14544