X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=course_reserves%2Fadd_items.pl;h=10b74a40cced2e7bcd5b3a10c423d14d173a8662;hb=9d6d641d1f8b77271800f43bc027b651f9aea52b;hp=7c16a143f59bffbd6661e109f7342dba877d9266;hpb=96cc447045f3f1d3702a3c69b36f596d88f38eda;p=srvgit diff --git a/course_reserves/add_items.pl b/course_reserves/add_items.pl index 7c16a143f5..10b74a40cc 100755 --- a/course_reserves/add_items.pl +++ b/course_reserves/add_items.pl @@ -22,13 +22,12 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use C4::Auth; -use C4::Output; -use C4::Koha; -use C4::Biblio; +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_html_with_http_headers ); +use C4::Koha qw( GetAuthorisedValues ); use Koha::Items; -use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve); +use C4::CourseReserves qw( GetCourse GetCourseReserve ModCourse ModCourseItem ModCourseReserve ); use Koha::Items; use Koha::ItemTypes; @@ -41,15 +40,26 @@ my $barcode = $cgi->param('barcode') || ''; my $return = $cgi->param('return') || ''; my $itemnumber = $cgi->param('itemnumber') || ''; my $is_edit = $cgi->param('is_edit') || ''; +my $biblionumber = $cgi->param('biblionumber') || ''; $barcode =~ s/^\s*|\s*$//g; #remove leading/trailing whitespace +$biblionumber =~ s/^\s*|\s*$//g; #remove leading/trailing whitespace -my $item = Koha::Items->find( { ( $itemnumber ? ( itemnumber => $itemnumber ) : ( barcode => $barcode ) ) } ); -$itemnumber = $item->id if $item; +my ( $item, $biblio ); -my $title = ($item) ? $item->biblio->title : undef; +if ( $barcode || $itemnumber ) { + # adding an item to course items + $item = $itemnumber ? Koha::Items->find( $itemnumber ) : Koha::Items->find({ barcode => $barcode }); + if ( $item ) { + $itemnumber = $item->id; + $biblio = $item->biblio; + } +} else { + # adding a biblio to course items + $biblio = Koha::Biblios->find( $biblionumber ); +} -my $step = ( $action eq 'lookup' && $item ) ? '2' : '1'; +my $step = ( $action eq 'lookup' && ( $item or $biblio ) ) ? '2' : '1'; my $tmpl = ($course_id) ? "add_items-step$step.tt" : "invalid-course.tt"; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -60,9 +70,10 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -if ( !$item && $action eq 'lookup' ){ +if ( !$item && !$biblio && $action eq 'lookup' ){ $template->param( ERROR_ITEM_NOT_FOUND => 1 ); $template->param( UNKNOWN_BARCODE => $barcode ) if $barcode; + $template->param( UNKNOWN_BIBLIONUMBER => $biblionumber ) if $biblionumber; } $template->param( course => GetCourse($course_id) ); @@ -80,7 +91,7 @@ if ( $action eq 'lookup' and $item ) { my $itemtypes = Koha::ItemTypes->search; $template->param( item => $item, - biblio => $item->biblio, + biblio => $biblio, course_item => $course_item, course_reserve => $course_reserve, is_edit => $is_edit, @@ -91,6 +102,26 @@ if ( $action eq 'lookup' and $item ) { return => $return, ); +} elsif ( $action eq 'lookup' and $biblio ) { + my $course_item = Koha::Course::Items->find({ biblionumber => $biblio->biblionumber }); + my $course_reserve = + ($course_item) + ? GetCourseReserve( + course_id => $course_id, + ci_id => $course_item->ci_id, + ) + : undef; + + my $itemtypes = Koha::ItemTypes->search; + $template->param( + biblio => $biblio, + course_item => $course_item, + course_reserve => $course_reserve, + is_edit => $is_edit, + + return => $return, + ); + } elsif ( $action eq 'add' ) { my $itype = scalar $cgi->param('itype'); my $ccode = scalar $cgi->param('ccode'); @@ -106,6 +137,7 @@ if ( $action eq 'lookup' and $item ) { my $ci_id = ModCourseItem( itemnumber => $itemnumber, + biblionumber => $biblionumber, itype => $itype, ccode => $ccode, homebranch => $homebranch,