View | Details | Raw Unified | Return to bug 10502
Collapse All | Expand All

(-)a/C4/Reports/Guided.pm (-2 / +12 lines)
Lines 534-543 sub save_report { Link Here
534
    my $cache_expiry = $fields->{cache_expiry} || 300;
534
    my $cache_expiry = $fields->{cache_expiry} || 300;
535
    my $public = $fields->{public};
535
    my $public = $fields->{public};
536
536
537
    my $branchcode = ( C4::Context->userenv && C4::Context->userenv->{branch} ne 'NO_LIBRARY_SET' ) ? C4::Context->userenv->{branch} : undef;
538
537
    my $dbh = C4::Context->dbh();
539
    my $dbh = C4::Context->dbh();
538
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
540
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
539
    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(),?,?,?,?,?,?,?,?,?)";
541
    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(),?,?,?,?,?,?,?,?,?)";
540
    $dbh->do($query, undef, $borrowernumber, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public);
542
    $dbh->do($query, undef, $borrowernumber, $branchcode, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public);
541
543
542
    my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef,
544
    my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef,
543
                                   $borrowernumber, $name);
545
                                   $borrowernumber, $name);
Lines 669-674 sub get_saved_reports { Link Here
669
            push @args, $filter->{subgroup};
671
            push @args, $filter->{subgroup};
670
        }
672
        }
671
    }
673
    }
674
675
    if ( C4::Context->preference('IndependentBranchesReports') && !C4::Context->IsSuperLibrarian() ) {
676
        my $branches =
677
          C4::Branch::GetIndependentGroupModificationRights( { stringify => 1 } );
678
679
        push( @cond, "( s.branchcode IN ( $branches ) OR s.branchcode IS NULL )" );
680
    }
681
672
    $query .= " WHERE ".join( " AND ", map "($_)", @cond ) if @cond;
682
    $query .= " WHERE ".join( " AND ", map "($_)", @cond ) if @cond;
673
    $query .= " ORDER by date_created";
683
    $query .= " ORDER by date_created";
674
    
684
    
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1837-1842 DROP TABLE IF EXISTS `saved_sql`; Link Here
1837
CREATE TABLE saved_sql ( -- saved sql reports
1837
CREATE TABLE saved_sql ( -- saved sql reports
1838
   `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha
1838
   `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha
1839
   `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber)
1839
   `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber)
1840
   `branchcode` VARCHAR(10) NULL DEFAULT NULL, -- the branchcode of the staff member who created this report
1840
   `date_created` datetime default NULL, -- the date this report was created
1841
   `date_created` datetime default NULL, -- the date this report was created
1841
   `last_modified` datetime default NULL, -- the date this report was last edited
1842
   `last_modified` datetime default NULL, -- the date this report was last edited
1842
   `savedsql` text, -- the SQL for this report
1843
   `savedsql` text, -- the SQL for this report
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 427-429 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' Link Here
427
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo');
427
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo');
428
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo');
428
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo');
429
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo');
429
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo');
430
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 (+22 lines)
Lines 7022-7027 CREATE TABLE IF NOT EXISTS borrower_files ( Link Here
7022
    SetVersion($DBversion);
7022
    SetVersion($DBversion);
7023
}
7023
}
7024
7024
7025
$DBversion = "3.13.00.XXX";
7026
if ( CheckVersion($DBversion) ) {
7027
    $dbh->do(q{
7028
        INSERT INTO systempreferences (
7029
            variable,
7030
            value,
7031
            explanation,
7032
            type
7033
        ) VALUES (
7034
            'IndependentBranchesReports',
7035
            '0',
7036
            'If enabled, custom reports will only be visible to librarians of the same library or library group as the report creator.',
7037
            'YesNo'
7038
        );
7039
    });
7040
    $dbh->do(q{
7041
        ALTER TABLE saved_sql ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER borrowernumber;
7042
    });
7043
    print "Upgrade to $DBversion done (Bug 10502 - Add independent branches option for sql reports)\n";
7044
    SetVersion($DBversion);
7045
}
7046
7025
=head1 FUNCTIONS
7047
=head1 FUNCTIONS
7026
7048
7027
=head2 TableExists($table)
7049
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+7 lines)
Lines 70-75 Administration: Link Here
70
                  yes: Prevent
70
                  yes: Prevent
71
                  no: "Don't prevent"
71
                  no: "Don't prevent"
72
            - staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries.
72
            - staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries.
73
        -
74
            - pref: IndependentBranchesReports
75
              default: 0
76
              choices:
77
                  yes: Prevent
78
                  no: "Don't prevent"
79
            - staff (but not superlibrarians) from accessing reports created by other libraries.
73
    CAS Authentication:
80
    CAS Authentication:
74
        -
81
        -
75
            - pref: casAuthentication
82
            - pref: casAuthentication
(-)a/reports/guided_reports.pl (-1 / +15 lines)
Lines 133-138 elsif ( $phase eq 'Show SQL'){ Link Here
133
elsif ( $phase eq 'Edit SQL'){
133
elsif ( $phase eq 'Edit SQL'){
134
    my $id = $input->param('reports');
134
    my $id = $input->param('reports');
135
    my $report = get_saved_report($id);
135
    my $report = get_saved_report($id);
136
137
    if (   $report->{branchcode}
138
        && C4::Context->preference('IndependentBranchesReports')
139
        && !C4::Context->IsSuperLibrarian() )
140
    {
141
        unless (
142
            C4::Branch::GetIndependentGroupModificationRights(
143
                { for => $report->{branchcode} }
144
            )
145
          )
146
        {
147
            print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved");
148
        }
149
    }
150
136
    my $group = $report->{report_group};
151
    my $group = $report->{report_group};
137
    my $subgroup  = $report->{report_subgroup};
152
    my $subgroup  = $report->{report_subgroup};
138
    $template->param(
153
    $template->param(
139
- 

Return to bug 10502