@@ -, +, @@ 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 @@ -1837,6 +1837,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 @@ -427,3 +427,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo'); INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo'); +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'); --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -7022,6 +7022,28 @@ CREATE TABLE IF NOT EXISTS borrower_files ( 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 @@ -70,6 +70,13 @@ Administration: yes: Prevent no: "Don't prevent" - staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries. + - + - 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 @@ -133,6 +133,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( --