Managing IndependantBranches when creating a new Biblio
authorHenri-Damien LAURENT <henridamien@koha-fr.org>
Mon, 22 Oct 2007 19:43:16 +0000 (14:43 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 23 Oct 2007 00:44:29 +0000 (19:44 -0500)
librarians can only add/edit/delete items on their own branches.

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
cataloguing/addbiblio.pl
cataloguing/additem.pl
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl

index 234b3e6..5e6a224 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Context;
 use MARC::Record;
 use C4::Log;
 use C4::Koha;    # XXX subfield_is_koha_internal_p
+use C4::Branch;    # XXX subfield_is_koha_internal_p
 use Date::Calc qw(Today);
 use MARC::File::USMARC;
 use MARC::File::XML;
@@ -163,16 +164,16 @@ sub build_authorized_values_list ($$$$$$$) {
 
     #---- branch
     if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-        my $sth =
-          $dbh->prepare(
-            "select branchcode,branchname from branches order by branchname");
-        $sth->execute;
-        push @authorised_values, ""
-          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
-
-        while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
-            push @authorised_values, $branchcode;
-            $authorised_lib{$branchcode} = $branchname;
+        #Use GetBranches($onlymine)
+        my $onlymine=C4::Context->preference('IndependantBranches') && 
+                C4::Context->userenv && 
+                C4::Context->userenv->{flags}!=1 && 
+                C4::Context->userenv->{branch};
+        my $branches = GetBranches($onlymine);
+        my @branchloop;
+        foreach my $thisbranch ( sort keys %$branches ) {
+            push @authorised_values, $thisbranch;
+            $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
         }
 
         #----- itemtypes
index 32c17f2..81b904d 100755 (executable)
@@ -25,6 +25,7 @@ use C4::Output;
 use C4::Biblio;
 use C4::Context;
 use C4::Koha; # XXX subfield_is_koha_internal_p
+use C4::Branch; # XXX subfield_is_koha_internal_p
 use Date::Calc qw(Today);
 
 use MARC::File::XML;
@@ -256,7 +257,7 @@ foreach my $tag (sort keys %{$tagslib}) {
  
     my $index_subfield= int(rand(1000000)); 
     if($subfield eq '@'){
-        $subfield_data{id} = "tag_".$tag."_subfield_0_".$index_subfield;
+        $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
     } else {
          $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
     }
@@ -308,18 +309,18 @@ foreach my $tag (sort keys %{$tagslib}) {
   
       #---- branch
       if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-          my $sth =
-            $dbh->prepare(
-              "select branchcode,branchname from branches order by branchname");
-          $sth->execute;
-          push @authorised_values, ""
-            unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
-  
-          while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
-              push @authorised_values, $branchcode;
-              $authorised_lib{$branchcode} = $branchname;
+          #Use GetBranches($onlymine)
+          my $onlymine=C4::Context->preference('IndependantBranches') && 
+                  C4::Context->userenv && 
+                  C4::Context->userenv->{flags}!=1 && 
+                  C4::Context->userenv->{branch};
+          my $branches = GetBranches($onlymine);
+          my @branchloop;
+          foreach my $thisbranch ( sort keys %$branches ) {
+              push @authorised_values, $thisbranch;
+              $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
           }
-  
+          
           #----- itemtypes
       }
       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
index 221353d..e51ddd2 100644 (file)
@@ -155,8 +155,8 @@ function CreateKey(){
                 <!-- TMPL_LOOP NAME="item_loop" -->
                 <tr>
                     <!-- TMPL_VAR NAME="item_value" -->
-                    <td><a href="additem.pl?op=edititem&amp;biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->">Edit</a></td>
-                    <td><a href="javascript:confirm_deletion(<!-- TMPL_VAR NAME="biblionumber" -->,<!-- TMPL_VAR NAME="itemnumber" -->)">Delete</a></td>
+                    <!-- TMPL_IF Name="nomod"--> <td colspan="2">&nbsp;</td><!--TMPL_ELSE--><td><a href="additem.pl?op=edititem&amp;biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->">Edit</a></td>
+                    <td><a href="javascript:confirm_deletion(<!-- TMPL_VAR NAME="biblionumber" -->,<!-- TMPL_VAR NAME="itemnumber" -->)">Delete</a></td><!--/TMPL_IF-->
                 </tr>
                 <!-- /TMPL_LOOP -->
         </table>