Bug 29897: Rename get_marc_authors with get_marc_contributors
[srvgit] / virtualshelves / sendshelf.pl
index dfd4be1..e870928 100755 (executable)
@@ -26,20 +26,22 @@ use Try::Tiny qw( catch try );
 
 use C4::Auth qw( get_template_and_user );
 use C4::Biblio qw(
-    GetBiblioData
-    GetMarcAuthors
-    GetMarcBiblio
     GetMarcISBN
     GetMarcSubjects
 );
 use C4::Items qw( GetItemsInfo );
-use C4::Output qw( output_html_with_http_headers );
+use C4::Output qw(
+    output_html_with_http_headers
+    output_and_exit
+);
+
+use Koha::Biblios;
 use Koha::Email;
 use Koha::Virtualshelves;
 
 my $query = CGI->new;
 
-my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
         template_name   => "virtualshelves/sendshelfform.tt",
         query           => $query,
@@ -51,7 +53,10 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
 my $shelfid    = $query->param('shelfid');
 my $to_address = $query->param('email');
 
-my $dbh = C4::Context->dbh;
+my $shelf = Koha::Virtualshelves->find( $shelfid );
+
+output_and_exit( $query, $cookie, $template, 'insufficient_permission' )
+    if $shelf && !$shelf->can_be_viewed( $loggedinuser );
 
 if ($to_address) {
     my $comment = $query->param('comment');
@@ -65,7 +70,6 @@ if ($to_address) {
         }
     );
 
-    my $shelf = Koha::Virtualshelves->find( $shelfid );
     my $contents = $shelf->get_contents;
     my $marcflavour = C4::Context->preference('marcflavour');
     my $iso2709;
@@ -73,12 +77,10 @@ if ($to_address) {
 
     while ( my $content = $contents->next ) {
         my $biblionumber     = $content->biblionumber;
-        my $biblio           = Koha::Biblios->find( $biblionumber );
-        my $dat              = GetBiblioData($biblionumber);
-        my $record           = GetMarcBiblio({
-            biblionumber => $biblionumber,
-            embed_items  => 1 });
-        my $marcauthorsarray = $biblio->get_marc_authors;
+        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
+        my $dat              = $biblio->unblessed;
+        my $record           = $biblio->metadata->record({ embed_items => 1 });
+        my $marcauthorsarray = $biblio->get_marc_contributors;
         my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
 
         my @items = GetItemsInfo($biblionumber);