From: Jonathan Druart <[email protected]>

Code written by Edgar Fuß <[email protected]>,
Mathematisches Institut der Uniersität Bonn

Signed-off-by: Katrin Fischer <[email protected]>
- rebased on current master, fixed a conflict in booksellers.pl
- reworked permission checks to account for general acq permissions and
  superlibrarian permission
- rephrased text of system preference (Thx to Jared Camins-Esakov)

Signed-off-by: Nicole C. Engard <[email protected]>
---
 acqui/booksellers.pl                               |   28 ++++++++++++++-----
 admin/systempreferences.pl                         |    1 +
 installer/data/mysql/sysprefs.sql                  |    1 +
 .../en/modules/admin/preferences/acquisitions.pref |    7 +++++
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl
index fb6b2f1..2b16fe4 100755
--- a/acqui/booksellers.pl
+++ b/acqui/booksellers.pl
@@ -59,6 +59,7 @@ use CGI;
 use C4::Dates qw/format_date/;
 use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
 use C4::Members qw/GetMember/;
+use C4::Context;
 
 my $query = CGI->new;
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -95,6 +96,11 @@ if ($loggedinuser) {
     $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
 }
 
+my $userenv = C4::Context::userenv;
+my $viewbaskets = C4::Context->preference('AcqViewBaskets');
+
+my $userbranch = $userenv->{branch};
+
 #build result page
 my $loop_suppliers = [];
 
@@ -102,19 +108,25 @@ for my $vendor (@suppliers) {
     my $baskets = get_vendors_baskets( $vendor->{id} );
 
     my $loop_basket = [];
+    
     for my $basket ( @{$baskets} ) {
-        if ((      $basket->{authorisedby}
-                && $basket->{authorisedby} eq $loggedinuser
-            )
-            || haspermission( $uid, { acquisition => q{*} } )
-          ) {
+        my $authorisedby = $basket->{authorisedby};
+        my $basketbranch = GetMember( borrowernumber => $authorisedby 
)->{branchcode};
+        
+        if ($userenv->{'flags'} & 1 || #user is superlibrarian
+               (haspermission( $uid, { acquisition => q{*} } ) && #user has 
acq permissions and
+                   ($viewbaskets eq 'all' || #user is allowed to see all 
baskets
+                   ($viewbaskets eq 'branch' && $authorisedby && $userbranch 
eq $basketbranch) || #basket belongs to user's branch
+                   ($basket->{authorisedby} &&  $viewbaskets == 'user' && 
$authorisedby == $loggedinuser) #user created this basket
+                   ) 
+                ) 
+           ) { 
             for my $date_field (qw( creationdate closedate)) {
                 if ( $basket->{$date_field} ) {
-                    $basket->{$date_field} =
-                      format_date( $basket->{$date_field} );
+                    $basket->{$date_field} = format_date( 
$basket->{$date_field} );
                 }
             }
-            push @{$loop_basket}, $basket;
+            push @{$loop_basket}, $basket; 
         }
     }
 
diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl
index 87ecac4..78d0768 100755
--- a/admin/systempreferences.pl
+++ b/admin/systempreferences.pl
@@ -76,6 +76,7 @@ my %tabsysprefs;
     $tabsysprefs{AcqCreateItem}="Acquisitions";
     $tabsysprefs{OrderPdfFormat}="Acquisitions";
     $tabsysprefs{CurrencyFormat}="Acquisitions";
+    $tabsysprefs{AcqViewBaskets}="Acquisitions";
 
 # Admin
 $tabsysprefs{singleBranchMode}      = "Admin";
diff --git a/installer/data/mysql/sysprefs.sql 
b/installer/data/mysql/sysprefs.sql
index 8cfd73f..7905d3f 100755
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -1,3 +1,4 @@
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) 
VALUES ('AcqViewBaskets','user','user|branch|all','Define which baskets a user 
is allowed to view: his own only, any within his branch or all','Choice');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) 
VALUES('advancedMARCeditor',0,"If ON, the MARC editor won't display 
field/subfield descriptions",'','YesNo');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) 
VALUES ('AllowHoldDateInFuture','0','If set a date field is displayed on the 
Hold screen of the Staff Interface, allowing the hold date to be set in the 
future.','','YesNo');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) 
VALUES ('OPACAllowHoldDateInFuture','0','If set, along with the 
AllowHoldDateInFuture system preference, OPAC users can set the date of a hold 
to be in the future.','','YesNo');
diff --git 
a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref 
b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref
index 43a7ad5..70e660d 100644
--- 
a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref
+++ 
b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref
@@ -16,6 +16,13 @@ Acquisitions:
               1: always ask for confirmation.
               2: do not ask for confirmation.
     -
+        - Show baskets
+        - pref: AcqViewBaskets
+          choices:
+              user: created by staff member.
+              branch: from staff member's branch.
+              all: in system, regardless of owner.
+    -
         - Display currencies using the following format 
         - pref: CurrencyFormat
           choices:
-- 
1.7.2.3

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to