@@ -, +, @@ reports are 'grandfathered' in, assuming that existing reports may be used by multiple libraries or library groups. --- C4/Reports/Guided.pm | 14 ++++++++++- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 22 ++++++++++++++++++++ .../prog/en/modules/admin/preferences/admin.pref | 7 ++++++ reports/guided_reports.pl | 15 +++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) --- a/C4/Reports/Guided.pm +++ a/C4/Reports/Guided.pm @@ -534,10 +534,12 @@ sub save_report { my $cache_expiry = $fields->{cache_expiry} || 300; my $public = $fields->{public}; + my $branchcode = ( C4::Context->userenv && C4::Context->userenv->{branch} ne 'NO_LIBRARY_SET' ) ? C4::Context->userenv->{branch} : undef; + my $dbh = C4::Context->dbh(); $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/ - my $query = "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public) VALUES (?,now(),now(),?,?,?,?,?,?,?,?,?)"; - $dbh->do($query, undef, $borrowernumber, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public); + my $query = "INSERT INTO saved_sql (borrowernumber,branchcode,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public) VALUES (?,?,now(),now(),?,?,?,?,?,?,?,?,?)"; + $dbh->do($query, undef, $borrowernumber, $branchcode, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public); my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef, $borrowernumber, $name); @@ -669,6 +671,14 @@ sub get_saved_reports { push @args, $filter->{subgroup}; } } + + if ( C4::Context->preference('IndependentBranchesReports') && !C4::Context->IsSuperLibrarian() ) { + my $branches = + C4::Branch::GetIndependentGroupModificationRights( { stringify => 1 } ); + + push( @cond, "( s.branchcode IN ( $branches ) OR s.branchcode IS NULL )" ); + } + $query .= " WHERE ".join( " AND ", map "($_)", @cond ) if @cond; $query .= " ORDER by date_created"; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1865,6 +1865,7 @@ DROP TABLE IF EXISTS `saved_sql`; CREATE TABLE saved_sql ( -- saved sql reports `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber) + `branchcode` VARCHAR(10) NULL DEFAULT NULL, -- the branchcode of the staff member who created this report `date_created` datetime default NULL, -- the date this report was created `last_modified` datetime default NULL, -- the date this report was last edited `savedsql` text, -- the SQL for this report --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -136,6 +136,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'), ('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'), ('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'), +('IndependentBranchesReports','0', NULL, 'If enabled, custom reports will only be visible to librarians of the same library or library group as the report creator.','YesNo'), ('InProcessingToShelvingCart','0','','If set, when any item with a location code of PROC is \'checked in\', it\'s location code will be changed to CART.','YesNo'), ('INTRAdidyoumean',NULL,NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'), ('IntranetBiblioDefaultView','normal','normal|marc|isbd|labeled_marc','Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd','Choice'), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -7888,6 +7888,28 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + INSERT INTO systempreferences ( + variable, + value, + explanation, + type + ) VALUES ( + 'IndependentBranchesReports', + '0', + 'If enabled, custom reports will only be visible to librarians of the same library or library group as the report creator.', + 'YesNo' + ); + }); + $dbh->do(q{ + ALTER TABLE saved_sql ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER borrowernumber; + }); + print "Upgrade to $DBversion done (Bug 10502 - Add independent branches option for sql reports)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -84,6 +84,13 @@ Administration: yes: Prevent no: "Don't prevent" - the logged in library from editing bibliographic records of other libraries. The owning library is defined by the branchcode in biblio.branchcode which should be mapped to a MARC field ( e.g. 951$o ). + - + - pref: IndependentBranchesReports + default: 0 + choices: + yes: Prevent + no: "Don't prevent" + - staff (but not superlibrarians) from accessing reports created by other libraries. CAS Authentication: - - pref: casAuthentication --- a/reports/guided_reports.pl +++ a/reports/guided_reports.pl @@ -140,6 +140,21 @@ elsif ( $phase eq 'Show SQL'){ elsif ( $phase eq 'Edit SQL'){ my $id = $input->param('reports'); my $report = get_saved_report($id); + + if ( $report->{branchcode} + && C4::Context->preference('IndependentBranchesReports') + && !C4::Context->IsSuperLibrarian() ) + { + unless ( + C4::Branch::GetIndependentGroupModificationRights( + { for => $report->{branchcode} } + ) + ) + { + print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved"); + } + } + my $group = $report->{report_group}; my $subgroup = $report->{report_subgroup}; $template->param( --