Lines 219-237
sub GetSomeShelfNames {
Link Here
|
219 |
|
219 |
|
220 |
=head2 GetShelf |
220 |
=head2 GetShelf |
221 |
|
221 |
|
222 |
(shelfnumber,shelfname,owner,category,sortfield) = &GetShelf($shelfnumber); |
222 |
(shelfnumber,shelfname,owner,category,sortfield,allow_add,allow_delete_own,allow_delete_other) = &GetShelf($shelfnumber); |
223 |
|
223 |
|
224 |
Looks up information about the contents of virtual virtualshelves number |
224 |
Returns the above-mentioned fields for passed virtual shelf number. |
225 |
C<$shelfnumber> |
|
|
226 |
|
227 |
Returns the database's information on 'virtualshelves' table. |
228 |
|
225 |
|
229 |
=cut |
226 |
=cut |
230 |
|
227 |
|
231 |
sub GetShelf ($) { |
228 |
sub GetShelf ($) { |
232 |
my ($shelfnumber) = @_; |
229 |
my ($shelfnumber) = @_; |
233 |
my $query = qq( |
230 |
my $query = qq( |
234 |
SELECT shelfnumber, shelfname, owner, category, sortfield |
231 |
SELECT shelfnumber, shelfname, owner, category, sortfield, |
|
|
232 |
allow_add, allow_delete_own, allow_delete_other |
235 |
FROM virtualshelves |
233 |
FROM virtualshelves |
236 |
WHERE shelfnumber=? |
234 |
WHERE shelfnumber=? |
237 |
); |
235 |
); |
Lines 315-321
sub AddShelf {
Link Here
|
315 |
|
313 |
|
316 |
#initialize missing hash values to silence warnings |
314 |
#initialize missing hash values to silence warnings |
317 |
foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) { |
315 |
foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) { |
318 |
$hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': ''; |
316 |
$hashref->{$_}= undef unless exists $hashref->{$_}; |
319 |
} |
317 |
} |
320 |
|
318 |
|
321 |
return -1 unless _CheckShelfName($hashref->{shelfname}, $hashref->{category}, $owner, 0); |
319 |
return -1 unless _CheckShelfName($hashref->{shelfname}, $hashref->{category}, $owner, 0); |
Lines 330-338
sub AddShelf {
Link Here
|
330 |
$owner, |
328 |
$owner, |
331 |
$hashref->{category}, |
329 |
$hashref->{category}, |
332 |
$hashref->{sortfield}, |
330 |
$hashref->{sortfield}, |
333 |
$hashref->{allow_add}||0, |
331 |
$hashref->{allow_add}//0, |
334 |
$hashref->{allow_delete_own}||1, |
332 |
$hashref->{allow_delete_own}//1, |
335 |
$hashref->{allow_delete_other}||0 ); |
333 |
$hashref->{allow_delete_other}//0 ); |
336 |
my $shelfnumber = $dbh->{'mysql_insertid'}; |
334 |
my $shelfnumber = $dbh->{'mysql_insertid'}; |
337 |
return $shelfnumber; |
335 |
return $shelfnumber; |
338 |
} |
336 |
} |
Lines 397-412
sub ModShelf {
Link Here
|
397 |
|
395 |
|
398 |
#initialize missing hash values to silence warnings |
396 |
#initialize missing hash values to silence warnings |
399 |
foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) { |
397 |
foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) { |
400 |
$hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': ''; |
398 |
$hashref->{$_}= undef unless exists $hashref->{$_}; |
401 |
} |
399 |
} |
402 |
|
400 |
|
403 |
#if name or category changes, the name should be tested |
401 |
#if name or category changes, the name should be tested |
404 |
if($hashref->{shelfname} || $hashref->{category}) { |
402 |
if($hashref->{shelfname} || $hashref->{category}) { |
405 |
unless(_CheckShelfName( |
403 |
unless(_CheckShelfName( |
406 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
404 |
$hashref->{shelfname}//$oldrecord->{shelfname}, |
407 |
$hashref->{category}||$oldrecord->{category}, |
405 |
$hashref->{category}//$oldrecord->{category}, |
408 |
$oldrecord->{owner}, $shelfnumber )) { |
406 |
$oldrecord->{owner}, |
409 |
return 0; #name check failed |
407 |
$shelfnumber )) { |
|
|
408 |
return 0; #name check failed |
410 |
} |
409 |
} |
411 |
} |
410 |
} |
412 |
|
411 |
|
Lines 414-426
sub ModShelf {
Link Here
|
414 |
$query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?"; |
413 |
$query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?"; |
415 |
$sth = $dbh->prepare($query); |
414 |
$sth = $dbh->prepare($query); |
416 |
$sth->execute( |
415 |
$sth->execute( |
417 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
416 |
$hashref->{shelfname}//$oldrecord->{shelfname}, |
418 |
$hashref->{category}||$oldrecord->{category}, |
417 |
$hashref->{category}//$oldrecord->{category}, |
419 |
$hashref->{sortfield}||$oldrecord->{sortfield}, |
418 |
$hashref->{sortfield}//$oldrecord->{sortfield}, |
420 |
$hashref->{allow_add}||$oldrecord->{allow_add}, |
419 |
$hashref->{allow_add}//$oldrecord->{allow_add}, |
421 |
$hashref->{allow_delete_own}||$oldrecord->{allow_delete_own}, |
420 |
$hashref->{allow_delete_own}//$oldrecord->{allow_delete_own}, |
422 |
$hashref->{allow_delete_other}||$oldrecord->{allow_delete_other}, |
421 |
$hashref->{allow_delete_other}//$oldrecord->{allow_delete_other}, |
423 |
$shelfnumber ); |
422 |
$shelfnumber ); |
424 |
return $@? 0: 1; |
423 |
return $@? 0: 1; |
425 |
} |
424 |
} |
426 |
|
425 |
|