Lines 241-247
sub EnableOrDisableCourseItems {
Link Here
|
241 |
warn identify_myself(%params) if $DEBUG; |
241 |
warn identify_myself(%params) if $DEBUG; |
242 |
|
242 |
|
243 |
my $course_id = $params{'course_id'}; |
243 |
my $course_id = $params{'course_id'}; |
244 |
my $enabled = $params{'enabled'} || 0; |
244 |
my $enabled = $params{'enabled'} || 0; |
245 |
|
245 |
|
246 |
my $lookfor = ( $enabled eq 'yes' ) ? 'no' : 'yes'; |
246 |
my $lookfor = ( $enabled eq 'yes' ) ? 'no' : 'yes'; |
247 |
|
247 |
|
Lines 252-264
sub EnableOrDisableCourseItems {
Link Here
|
252 |
|
252 |
|
253 |
if ( $enabled eq 'yes' ) { |
253 |
if ( $enabled eq 'yes' ) { |
254 |
foreach my $course_reserve (@$course_reserves) { |
254 |
foreach my $course_reserve (@$course_reserves) { |
255 |
if ( |
255 |
if (CountCourseReservesForItem( |
256 |
CountCourseReservesForItem( |
|
|
257 |
ci_id => $course_reserve->{'ci_id'}, |
256 |
ci_id => $course_reserve->{'ci_id'}, |
258 |
enabled => 'yes' |
257 |
enabled => 'yes' |
259 |
) |
258 |
) |
260 |
) |
259 |
) { |
261 |
{ |
|
|
262 |
EnableOrDisableCourseItem( |
260 |
EnableOrDisableCourseItem( |
263 |
ci_id => $course_reserve->{'ci_id'}, |
261 |
ci_id => $course_reserve->{'ci_id'}, |
264 |
enabled => 'yes', |
262 |
enabled => 'yes', |
Lines 273-280
sub EnableOrDisableCourseItems {
Link Here
|
273 |
ci_id => $course_reserve->{'ci_id'}, |
271 |
ci_id => $course_reserve->{'ci_id'}, |
274 |
enabled => 'yes' |
272 |
enabled => 'yes' |
275 |
) |
273 |
) |
276 |
) |
274 |
) { |
277 |
{ |
|
|
278 |
EnableOrDisableCourseItem( |
275 |
EnableOrDisableCourseItem( |
279 |
ci_id => $course_reserve->{'ci_id'}, |
276 |
ci_id => $course_reserve->{'ci_id'}, |
280 |
enabled => 'no', |
277 |
enabled => 'no', |
Lines 376-382
sub ModCourseInstructors {
Link Here
|
376 |
return unless ( $cardnumbers || $borrowernumbers ); |
373 |
return unless ( $cardnumbers || $borrowernumbers ); |
377 |
return if ( $cardnumbers && $borrowernumbers ); |
374 |
return if ( $cardnumbers && $borrowernumbers ); |
378 |
|
375 |
|
379 |
my (@cardnumbers, @borrowernumbers); |
376 |
my ( @cardnumbers, @borrowernumbers ); |
380 |
@cardnumbers = @$cardnumbers if ( ref($cardnumbers) eq 'ARRAY' ); |
377 |
@cardnumbers = @$cardnumbers if ( ref($cardnumbers) eq 'ARRAY' ); |
381 |
@borrowernumbers = @$borrowernumbers |
378 |
@borrowernumbers = @$borrowernumbers |
382 |
if ( ref($borrowernumbers) eq 'ARRAY' ); |
379 |
if ( ref($borrowernumbers) eq 'ARRAY' ); |
Lines 387-394
sub ModCourseInstructors {
Link Here
|
387 |
|
384 |
|
388 |
my $dbh = C4::Context->dbh; |
385 |
my $dbh = C4::Context->dbh; |
389 |
|
386 |
|
390 |
$dbh->do( "DELETE FROM course_instructors WHERE course_id = ?", |
387 |
$dbh->do( "DELETE FROM course_instructors WHERE course_id = ?", undef, $course_id ) |
391 |
undef, $course_id ) |
|
|
392 |
if ( $mode eq 'replace' ); |
388 |
if ( $mode eq 'replace' ); |
393 |
|
389 |
|
394 |
my $query; |
390 |
my $query; |
Lines 400-407
sub ModCourseInstructors {
Link Here
|
400 |
FROM borrowers |
396 |
FROM borrowers |
401 |
WHERE $field IN ( $placeholders ) |
397 |
WHERE $field IN ( $placeholders ) |
402 |
"; |
398 |
"; |
403 |
} |
399 |
} else { |
404 |
else { |
|
|
405 |
$query = " |
400 |
$query = " |
406 |
DELETE FROM course_instructors |
401 |
DELETE FROM course_instructors |
407 |
WHERE course_id = ? |
402 |
WHERE course_id = ? |
Lines 485-492
sub ModCourseItem {
Link Here
|
485 |
course_item => $course_item, |
480 |
course_item => $course_item, |
486 |
%params |
481 |
%params |
487 |
); |
482 |
); |
488 |
} |
483 |
} else { |
489 |
else { |
|
|
490 |
$ci_id = _AddCourseItem(%params); |
484 |
$ci_id = _AddCourseItem(%params); |
491 |
} |
485 |
} |
492 |
|
486 |
|
Lines 570-577
sub _UpdateCourseItem {
Link Here
|
570 |
foreach (@FIELDS) { |
564 |
foreach (@FIELDS) { |
571 |
if ( $params{$_} |
565 |
if ( $params{$_} |
572 |
&& $course_item->{$_} |
566 |
&& $course_item->{$_} |
573 |
&& $params{$_} ne $course_item->{$_} ) |
567 |
&& $params{$_} ne $course_item->{$_} ) { |
574 |
{ |
|
|
575 |
$mod_params{$_} = $params{$_}; |
568 |
$mod_params{$_} = $params{$_}; |
576 |
} |
569 |
} |
577 |
} |
570 |
} |
Lines 618-627
sub _ModStoredFields {
Link Here
|
618 |
} |
611 |
} |
619 |
} |
612 |
} |
620 |
|
613 |
|
621 |
my $query = |
614 |
my $query = "UPDATE course_items SET " . join( ',', map { "$_=?" } @fields_to_update ) . " WHERE ci_id = ?"; |
622 |
"UPDATE course_items SET " |
|
|
623 |
. join( ',', map { "$_=?" } @fields_to_update ) |
624 |
. " WHERE ci_id = ?"; |
625 |
|
615 |
|
626 |
C4::Context->dbh->do( $query, undef, @values_to_update, $params{'ci_id'} ) |
616 |
C4::Context->dbh->do( $query, undef, @values_to_update, $params{'ci_id'} ) |
627 |
if (@values_to_update); |
617 |
if (@values_to_update); |
Lines 660-669
sub _RevertFields {
Link Here
|
660 |
} |
650 |
} |
661 |
ModItem( $mod_item_params, undef, $course_item->{'itemnumber'} ); |
651 |
ModItem( $mod_item_params, undef, $course_item->{'itemnumber'} ); |
662 |
|
652 |
|
663 |
my $query = |
653 |
my $query = "UPDATE course_items SET " . join( ',', map { "$_=NULL" } @fields_to_null ) . " WHERE ci_id = ?"; |
664 |
"UPDATE course_items SET " |
|
|
665 |
. join( ',', map { "$_=NULL" } @fields_to_null ) |
666 |
. " WHERE ci_id = ?"; |
667 |
|
654 |
|
668 |
C4::Context->dbh->do( $query, undef, $ci_id ) if (@fields_to_null); |
655 |
C4::Context->dbh->do( $query, undef, $ci_id ) if (@fields_to_null); |
669 |
} |
656 |
} |
Lines 785-792
sub GetCourseReserve {
Link Here
|
785 |
"; |
772 |
"; |
786 |
$sth = $dbh->prepare($query); |
773 |
$sth = $dbh->prepare($query); |
787 |
$sth->execute($cr_id); |
774 |
$sth->execute($cr_id); |
788 |
} |
775 |
} else { |
789 |
else { |
|
|
790 |
my $query = " |
776 |
my $query = " |
791 |
SELECT * FROM course_reserves |
777 |
SELECT * FROM course_reserves |
792 |
WHERE course_id = ? AND ci_id = ? |
778 |
WHERE course_id = ? AND ci_id = ? |
Lines 816-823
sub ModCourseReserve {
Link Here
|
816 |
|
802 |
|
817 |
return unless ( $course_id && $ci_id ); |
803 |
return unless ( $course_id && $ci_id ); |
818 |
|
804 |
|
819 |
my $course_reserve = |
805 |
my $course_reserve = GetCourseReserve( course_id => $course_id, ci_id => $ci_id ); |
820 |
GetCourseReserve( course_id => $course_id, ci_id => $ci_id ); |
|
|
821 |
my $cr_id; |
806 |
my $cr_id; |
822 |
|
807 |
|
823 |
my $dbh = C4::Context->dbh; |
808 |
my $dbh = C4::Context->dbh; |
Lines 831-838
sub ModCourseReserve {
Link Here
|
831 |
WHERE cr_id = ? |
816 |
WHERE cr_id = ? |
832 |
"; |
817 |
"; |
833 |
$dbh->do( $query, undef, $staff_note, $public_note, $cr_id ); |
818 |
$dbh->do( $query, undef, $staff_note, $public_note, $cr_id ); |
834 |
} |
819 |
} else { |
835 |
else { |
|
|
836 |
my $query = " |
820 |
my $query = " |
837 |
INSERT INTO course_reserves SET |
821 |
INSERT INTO course_reserves SET |
838 |
course_id = ?, |
822 |
course_id = ?, |
Lines 840-849
sub ModCourseReserve {
Link Here
|
840 |
staff_note = ?, |
824 |
staff_note = ?, |
841 |
public_note = ? |
825 |
public_note = ? |
842 |
"; |
826 |
"; |
843 |
$dbh->do( $query, undef, $course_id, $ci_id, $staff_note, |
827 |
$dbh->do( $query, undef, $course_id, $ci_id, $staff_note, $public_note ); |
844 |
$public_note ); |
828 |
$cr_id = $dbh->last_insert_id( undef, undef, 'course_reserves', 'cr_id' ); |
845 |
$cr_id = |
|
|
846 |
$dbh->last_insert_id( undef, undef, 'course_reserves', 'cr_id' ); |
847 |
} |
829 |
} |
848 |
|
830 |
|
849 |
my $course = GetCourse($course_id); |
831 |
my $course = GetCourse($course_id); |
Lines 872-881
sub GetCourseReserves {
Link Here
|
872 |
my (%params) = @_; |
854 |
my (%params) = @_; |
873 |
warn identify_myself(%params) if $DEBUG; |
855 |
warn identify_myself(%params) if $DEBUG; |
874 |
|
856 |
|
875 |
my $course_id = $params{'course_id'}; |
857 |
my $course_id = $params{'course_id'}; |
876 |
my $ci_id = $params{'ci_id'}; |
858 |
my $ci_id = $params{'ci_id'}; |
877 |
my $include_items = $params{'include_items'}; |
859 |
my $include_items = $params{'include_items'}; |
878 |
my $include_count = $params{'include_count'}; |
860 |
my $include_count = $params{'include_count'}; |
879 |
my $include_courses = $params{'include_courses'}; |
861 |
my $include_courses = $params{'include_courses'}; |
880 |
|
862 |
|
881 |
return unless ( $course_id || $ci_id ); |
863 |
return unless ( $course_id || $ci_id ); |
Lines 898-919
sub GetCourseReserves {
Link Here
|
898 |
if ($include_items) { |
880 |
if ($include_items) { |
899 |
foreach my $cr (@$course_reserves) { |
881 |
foreach my $cr (@$course_reserves) { |
900 |
$cr->{'course_item'} = GetCourseItem( ci_id => $cr->{'ci_id'} ); |
882 |
$cr->{'course_item'} = GetCourseItem( ci_id => $cr->{'ci_id'} ); |
901 |
$cr->{'item'} = GetBiblioFromItemNumber( $cr->{'itemnumber'} ); |
883 |
$cr->{'item'} = GetBiblioFromItemNumber( $cr->{'itemnumber'} ); |
902 |
$cr->{'issue'} = GetOpenIssue( $cr->{'itemnumber'} ); |
884 |
$cr->{'issue'} = GetOpenIssue( $cr->{'itemnumber'} ); |
903 |
} |
885 |
} |
904 |
} |
886 |
} |
905 |
|
887 |
|
906 |
if ($include_count) { |
888 |
if ($include_count) { |
907 |
foreach my $cr (@$course_reserves) { |
889 |
foreach my $cr (@$course_reserves) { |
908 |
$cr->{'reserves_count'} = |
890 |
$cr->{'reserves_count'} = CountCourseReservesForItem( ci_id => $cr->{'ci_id'} ); |
909 |
CountCourseReservesForItem( ci_id => $cr->{'ci_id'} ); |
|
|
910 |
} |
891 |
} |
911 |
} |
892 |
} |
912 |
|
893 |
|
913 |
if ($include_courses) { |
894 |
if ($include_courses) { |
914 |
foreach my $cr (@$course_reserves) { |
895 |
foreach my $cr (@$course_reserves) { |
915 |
$cr->{'courses'} = |
896 |
$cr->{'courses'} = GetCourses( itemnumber => $cr->{'itemnumber'} ); |
916 |
GetCourses( itemnumber => $cr->{'itemnumber'} ); |
|
|
917 |
} |
897 |
} |
918 |
} |
898 |
} |
919 |
|
899 |
|
Lines 946-953
sub DelCourseReserve {
Link Here
|
946 |
|
926 |
|
947 |
## If there are no other course reserves for this item |
927 |
## If there are no other course reserves for this item |
948 |
## delete the course_item as well |
928 |
## delete the course_item as well |
949 |
unless ( CountCourseReservesForItem( ci_id => $course_reserve->{'ci_id'} ) ) |
929 |
unless ( CountCourseReservesForItem( ci_id => $course_reserve->{'ci_id'} ) ) { |
950 |
{ |
|
|
951 |
DelCourseItem( ci_id => $course_reserve->{'ci_id'} ); |
930 |
DelCourseItem( ci_id => $course_reserve->{'ci_id'} ); |
952 |
} |
931 |
} |
953 |
|
932 |
|
Lines 1007-1014
sub CountCourseReservesForItem {
Link Here
|
1007 |
|
986 |
|
1008 |
return unless ( $ci_id || $itemnumber ); |
987 |
return unless ( $ci_id || $itemnumber ); |
1009 |
|
988 |
|
1010 |
my $course_item = |
989 |
my $course_item = GetCourseItem( ci_id => $ci_id, itemnumber => $itemnumber ); |
1011 |
GetCourseItem( ci_id => $ci_id, itemnumber => $itemnumber ); |
|
|
1012 |
|
990 |
|
1013 |
my @params = ( $course_item->{'ci_id'} ); |
991 |
my @params = ( $course_item->{'ci_id'} ); |
1014 |
push( @params, $enabled ) if ($enabled); |
992 |
push( @params, $enabled ) if ($enabled); |
Lines 1082-1088
sub SearchCourses {
Link Here
|
1082 |
my $dbh = C4::Context->dbh; |
1060 |
my $dbh = C4::Context->dbh; |
1083 |
my $sth = $dbh->prepare($query); |
1061 |
my $sth = $dbh->prepare($query); |
1084 |
|
1062 |
|
1085 |
$sth->execute(@params, $enabled); |
1063 |
$sth->execute( @params, $enabled ); |
1086 |
|
1064 |
|
1087 |
my $courses = $sth->fetchall_arrayref( {} ); |
1065 |
my $courses = $sth->fetchall_arrayref( {} ); |
1088 |
|
1066 |
|