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 132-137 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
132
('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'),
132
('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'),
133
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
133
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
134
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
134
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
135
('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'),
135
('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'),
136
('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'),
136
('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'),
137
('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'),
137
('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'),
138
('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 (+22 lines)
Lines 7067-7072 if ( CheckVersion($DBversion) ) { Link Here
7067
    SetVersion($DBversion);
7067
    SetVersion($DBversion);
7068
}
7068
}
7069
7069
7070
$DBversion = "3.13.00.XXX";
7071
if ( CheckVersion($DBversion) ) {
7072
    $dbh->do(q{
7073
        INSERT INTO systempreferences (
7074
            variable,
7075
            value,
7076
            explanation,
7077
            type
7078
        ) VALUES (
7079
            'IndependentBranchesReports',
7080
            '0',
7081
            'If enabled, custom reports will only be visible to librarians of the same library or library group as the report creator.',
7082
            'YesNo'
7083
        );
7084
    });
7085
    $dbh->do(q{
7086
        ALTER TABLE saved_sql ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER borrowernumber;
7087
    });
7088
    print "Upgrade to $DBversion done (Bug 10502 - Add independent branches option for sql reports)\n";
7089
    SetVersion($DBversion);
7090
}
7091
7070
=head1 FUNCTIONS
7092
=head1 FUNCTIONS
7071
7093
7072
=head2 TableExists($table)
7094
=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 140-145 elsif ( $phase eq 'Show SQL'){ Link Here
140
elsif ( $phase eq 'Edit SQL'){
140
elsif ( $phase eq 'Edit SQL'){
141
    my $id = $input->param('reports');
141
    my $id = $input->param('reports');
142
    my $report = get_saved_report($id);
142
    my $report = get_saved_report($id);
143
144
    if (   $report->{branchcode}
145
        && C4::Context->preference('IndependentBranchesReports')
146
        && !C4::Context->IsSuperLibrarian() )
147
    {
148
        unless (
149
            C4::Branch::GetIndependentGroupModificationRights(
150
                { for => $report->{branchcode} }
151
            )
152
          )
153
        {
154
            print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved");
155
        }
156
    }
157
143
    my $group = $report->{report_group};
158
    my $group = $report->{report_group};
144
    my $subgroup  = $report->{report_subgroup};
159
    my $subgroup  = $report->{report_subgroup};
145
    $template->param(
160
    $template->param(
146
- 

Return to bug 10502