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 1865-1870 DROP TABLE IF EXISTS `saved_sql`; Link Here
1865
CREATE TABLE saved_sql ( -- saved sql reports
1865
CREATE TABLE saved_sql ( -- saved sql reports
1866
   `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha
1866
   `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha
1867
   `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber)
1867
   `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber)
1868
   `branchcode` VARCHAR(10) NULL DEFAULT NULL, -- the branchcode of the staff member who created this report
1868
   `date_created` datetime default NULL, -- the date this report was created
1869
   `date_created` datetime default NULL, -- the date this report was created
1869
   `last_modified` datetime default NULL, -- the date this report was last edited
1870
   `last_modified` datetime default NULL, -- the date this report was last edited
1870
   `savedsql` text, -- the SQL for this report
1871
   `savedsql` text, -- the SQL for this report
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 136-141 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
136
('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'),
136
('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'),
137
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
137
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
138
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
138
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
139
('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'),
139
('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'),
140
('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'),
140
('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'),
141
('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'),
141
('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'),
142
('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 7888-7893 if ( CheckVersion($DBversion) ) { Link Here
7888
    SetVersion ($DBversion);
7888
    SetVersion ($DBversion);
7889
}
7889
}
7890
7890
7891
$DBversion = "3.13.00.XXX";
7892
if ( CheckVersion($DBversion) ) {
7893
    $dbh->do(q{
7894
        INSERT INTO systempreferences (
7895
            variable,
7896
            value,
7897
            explanation,
7898
            type
7899
        ) VALUES (
7900
            'IndependentBranchesReports',
7901
            '0',
7902
            'If enabled, custom reports will only be visible to librarians of the same library or library group as the report creator.',
7903
            'YesNo'
7904
        );
7905
    });
7906
    $dbh->do(q{
7907
        ALTER TABLE saved_sql ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER borrowernumber;
7908
    });
7909
    print "Upgrade to $DBversion done (Bug 10502 - Add independent branches option for sql reports)\n";
7910
    SetVersion($DBversion);
7911
}
7912
7891
=head1 FUNCTIONS
7913
=head1 FUNCTIONS
7892
7914
7893
=head2 TableExists($table)
7915
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+7 lines)
Lines 84-89 Administration: Link Here
84
                  yes: Prevent
84
                  yes: Prevent
85
                  no: "Don't prevent"
85
                  no: "Don't prevent"
86
            - 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 ).
86
            - 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 ).
87
        -
88
            - pref: IndependentBranchesReports
89
              default: 0
90
              choices:
91
                  yes: Prevent
92
                  no: "Don't prevent"
93
            - staff (but not superlibrarians) from accessing reports created by other libraries.
87
    CAS Authentication:
94
    CAS Authentication:
88
        -
95
        -
89
            - pref: casAuthentication
96
            - 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