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