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

(-)a/C4/UsageStats.pm (+1 lines)
Lines 314-319 sub _shared_preferences { Link Here
314
        autoMemberNum
314
        autoMemberNum
315
        BorrowerRenewalPeriodBase
315
        BorrowerRenewalPeriodBase
316
        EnableBorrowerFiles
316
        EnableBorrowerFiles
317
        EnableFilteringReports
317
        EnhancedMessagingPreferences
318
        EnhancedMessagingPreferences
318
        ExtendedPatronAttributes
319
        ExtendedPatronAttributes
319
        intranetreadinghistory
320
        intranetreadinghistory
(-)a/Koha/Manual.pm (+1 lines)
Lines 117-122 our $mapping = { Link Here
117
    'admin/preferences#logs'                   => '/logspreferences.html',
117
    'admin/preferences#logs'                   => '/logspreferences.html',
118
    'admin/preferences#opac'                   => '/opacpreferences.html',
118
    'admin/preferences#opac'                   => '/opacpreferences.html',
119
    'admin/preferences#patrons'                => '/patronspreferences.html',
119
    'admin/preferences#patrons'                => '/patronspreferences.html',
120
    'admin/preferences#reports'                => '/reportspreferences.html',
120
    'admin/preferences#searching'              => '/searchingpreferences.html',
121
    'admin/preferences#searching'              => '/searchingpreferences.html',
121
    'admin/preferences#serials'                => '/serialspreferences.html',
122
    'admin/preferences#serials'                => '/serialspreferences.html',
122
    'admin/preferences#staff_interface'        => '/staffclientpreferences.html',
123
    'admin/preferences#staff_interface'        => '/staffclientpreferences.html',
(-)a/Koha/Report.pm (-1 / +19 lines)
Lines 20-28 use Modern::Perl; Link Here
20
use Koha::Database;
20
use Koha::Database;
21
use Koha::Reports;
21
use Koha::Reports;
22
22
23
use Koha::Object;
24
use Koha::Object::Limit::Library;
25
26
use base qw(Koha::Object Koha::Object::Limit::Library);
27
23
#use Koha::DateUtils qw( dt_from_string output_pref );
28
#use Koha::DateUtils qw( dt_from_string output_pref );
24
29
25
use base qw(Koha::Object);
26
#
30
#
27
# FIXME We could only return an error code instead of the arrayref
31
# FIXME We could only return an error code instead of the arrayref
28
# Only 1 error is returned
32
# Only 1 error is returned
Lines 268-271 sub _type { Link Here
268
    return 'SavedSql';
272
    return 'SavedSql';
269
}
273
}
270
274
275
=head3 _library_limits
276
277
Configurable library limits
278
279
=cut
280
281
sub _library_limits {
282
    return {
283
        class   => "ReportsBranch",
284
        id      => "report_id",
285
        library => "branchcode",
286
    };
287
}
288
271
1;
289
1;
(-)a/Koha/Reports.pm (-1 / +26 lines)
Lines 21-27 use Koha::Database; Link Here
21
21
22
use Koha::Report;
22
use Koha::Report;
23
23
24
use base qw(Koha::Objects);
24
use base qw(Koha::Objects Koha::Objects::Limit::Library);
25
25
26
=head1 NAME
26
=head1 NAME
27
27
Lines 33-38 Koha::Reports - Koha Report Object set class Link Here
33
33
34
=cut
34
=cut
35
35
36
=head3 search_with_localization
37
38
=cut
39
40
sub search_with_localization {
41
    my ( $self, $params, $attributes ) = @_;
42
43
    my $language = C4::Languages::getlanguage();
44
    $Koha::Schema::Result::Itemtype::LANGUAGE = $language;
45
    $attributes->{order_by}                   = 'translated_description' unless exists $attributes->{order_by};
46
    $attributes->{join}                       = 'localization';
47
    $attributes->{'+select'}                  = [
48
        {
49
            coalesce => [qw( localization.translation me.description )],
50
            -as      => 'translated_description'
51
        }
52
    ];
53
    if ( defined $params->{branchcode} ) {
54
        my $branchcode = delete $params->{branchcode};
55
        $self->search_with_library_limits( $params, $attributes, $branchcode );
56
    } else {
57
        $self->SUPER::search( $params, $attributes );
58
    }
59
}
60
36
=head3 _type
61
=head3 _type
37
62
38
Returns name of corresponding DBIC resultset
63
Returns name of corresponding DBIC resultset
(-)a/installer/data/mysql/atomicupdate/bug_16631.pl (+39 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "16631",
6
    description => "Add library limits to reports",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        $dbh->do(
12
            q{CREATE TABLE IF NOT EXISTS `reports_branches` (
13
            `report_id` int(11) NOT NULL,
14
            `branchcode` varchar(10) NOT NULL,
15
            KEY `report_id` (`report_id`),
16
            KEY `branchcode` (`branchcode`),
17
            CONSTRAINT `reports_branches_ibfk_1` FOREIGN KEY (`report_id`) REFERENCES `saved_sql` (`id`) ON DELETE CASCADE,
18
            CONSTRAINT `reports_branches_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
19
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci}
20
        );
21
22
        say $out "Added new table 'reports_branches'";
23
24
        $dbh->do(
25
            q{INSERT IGNORE INTO systempreferences
26
            (variable,value,options,explanation,type) VALUES ('LimitReportsByBranch', '0', NULL, 'Enable ability for staff to limit report access based on home library.', 'YesNo')}
27
        );
28
29
        say $out "Added new system preference 'LimitReportsByBranch'";
30
31
        $dbh->do(
32
            q{INSERT IGNORE INTO permissions 
33
            (module_bit, code, description) VALUES (16, 'manage_report_limits', 'Manage report limits')}
34
        );
35
36
        say $out "Added new permission 'manage_report_limits'";
37
38
    },
39
};
(-)a/installer/data/mysql/kohastructure.sql (+13 lines)
Lines 5772-5777 CREATE TABLE `saved_reports` ( Link Here
5772
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5772
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5773
/*!40101 SET character_set_client = @saved_cs_client */;
5773
/*!40101 SET character_set_client = @saved_cs_client */;
5774
5774
5775
DROP TABLE IF EXISTS `reports_branches`;
5776
/*!40101 SET @saved_cs_client     = @@character_set_client */;
5777
/*!40101 SET character_set_client = utf8mb4 */;
5778
CREATE TABLE `reports_branches` (
5779
  `report_id` int(11) NOT NULL,
5780
  `branchcode` varchar(10) NOT NULL,
5781
  KEY `report_id` (`report_id`),
5782
  KEY `branchcode` (`branchcode`),
5783
  CONSTRAINT `reports_branches_ibfk_1` FOREIGN KEY (`report_id`) REFERENCES `saved_sql` (`id`) ON DELETE CASCADE,
5784
  CONSTRAINT `reports_branches_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
5785
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5786
/*!40101 SET character_set_client = @saved_cs_client */;
5787
5775
--
5788
--
5776
-- Table structure for table `saved_sql`
5789
-- Table structure for table `saved_sql`
5777
--
5790
--
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 385-390 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
385
('LibraryThingForLibrariesTabbedView','0','','Put LibraryThingForLibraries Content in Tabs.','YesNo'),
385
('LibraryThingForLibrariesTabbedView','0','','Put LibraryThingForLibraries Content in Tabs.','YesNo'),
386
('LibrisKey', '', 'This key must be obtained at http://api.libris.kb.se/. It is unique for the IP of the server.', NULL, 'Free'),
386
('LibrisKey', '', 'This key must be obtained at http://api.libris.kb.se/. It is unique for the IP of the server.', NULL, 'Free'),
387
('LibrisURL', 'http://api.libris.kb.se/bibspell/', 'This it the base URL for the Libris spellchecking API.',NULL,'Free'),
387
('LibrisURL', 'http://api.libris.kb.se/bibspell/', 'This it the base URL for the Libris spellchecking API.',NULL,'Free'),
388
('LimitReportsByBranch', '0', NULL, 'Enable ability for staff to limit report access based on home library.', 'YesNo'),
388
('LinkerConsiderDiacritics', '0', NULL, 'Linker should consider diacritics', 'YesNo'),
389
('LinkerConsiderDiacritics', '0', NULL, 'Linker should consider diacritics', 'YesNo'),
389
('LinkerConsiderThesaurus','0',NULL,'If ON the authority linker will only search for 6XX authorities from the same source as the heading','YesNo'),
390
('LinkerConsiderThesaurus','0',NULL,'If ON the authority linker will only search for 6XX authorities from the same source as the heading','YesNo'),
390
('LinkerKeepStale','0',NULL,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.','YesNo'),
391
('LinkerKeepStale','0',NULL,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.','YesNo'),
(-)a/installer/data/mysql/mandatory/userpermissions.sql (+1 lines)
Lines 141-146 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
141
   (16, 'execute_reports', 'Execute SQL reports'),
141
   (16, 'execute_reports', 'Execute SQL reports'),
142
   (16, 'create_reports', 'Create SQL reports'),
142
   (16, 'create_reports', 'Create SQL reports'),
143
   (16, 'delete_reports', 'Delete SQL reports'),
143
   (16, 'delete_reports', 'Delete SQL reports'),
144
   (16, 'manage_report_limits', 'Manage report limits'),
144
   (18, 'manage_courses', 'Add, edit and delete courses'),
145
   (18, 'manage_courses', 'Add, edit and delete courses'),
145
   (18, 'add_reserves', 'Add course reserves'),
146
   (18, 'add_reserves', 'Add course reserves'),
146
   (18, 'delete_reserves', 'Remove course reserves'),
147
   (18, 'delete_reserves', 'Remove course reserves'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc (+3 lines)
Lines 487-492 Link Here
487
    [%- CASE 'execute_reports' -%]
487
    [%- CASE 'execute_reports' -%]
488
        <span class="sub_permission execute_reports_subpermission"> Execute SQL reports </span>
488
        <span class="sub_permission execute_reports_subpermission"> Execute SQL reports </span>
489
        <span class="permissioncode">([% name | html %])</span>
489
        <span class="permissioncode">([% name | html %])</span>
490
    [%- CASE 'manage_report_limits' -%]
491
        <span class="sub_permission manage_report_limits_subpermission"> Manage Report Limits </span>
492
        <span class="permissioncode">([% name | html %])</span>
490
    [%- CASE 'add_reserves' -%]
493
    [%- CASE 'add_reserves' -%]
491
        <span class="sub_permission add_reserves_subpermission"> Add course reserves </span>
494
        <span class="sub_permission add_reserves_subpermission"> Add course reserves </span>
492
        <span class="permissioncode">([% name | html %])</span>
495
        <span class="permissioncode">([% name | html %])</span>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-menu.inc (+11 lines)
Lines 165-170 Link Here
165
            </li>
165
            </li>
166
        [% END %]
166
        [% END %]
167
167
168
        [% IF ( reports ) %]
169
            <li class="active">
170
                <a title="Reports" href="/cgi-bin/koha/admin/preferences.pl?tab=reports">Reports</a>
171
                [% PROCESS subtabs %]
172
            </li>
173
        [% ELSE %]
174
            <li>
175
                <a title="Reports" href="/cgi-bin/koha/admin/preferences.pl?tab=reports">Reports</a>
176
            </li>
177
        [% END %]
178
        
168
        [% IF ( searching ) %]
179
        [% IF ( searching ) %]
169
            <li class="active">
180
            <li class="active">
170
                <a title="Searching" href="/cgi-bin/koha/admin/preferences.pl?tab=searching">Searching</a>
181
                <a title="Searching" href="/cgi-bin/koha/admin/preferences.pl?tab=searching">Searching</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc (+16 lines)
Lines 11-16 Link Here
11
            </ul>
11
            </ul>
12
        </div>
12
        </div>
13
    [% END %]
13
    [% END %]
14
    [% IF (op == "list") && Koha.Preference('LimitReportsByBranch') %]
15
        [% IF ( CAN_user_superlibrarian || CAN_user_reports_manage_report_limits ) %]
16
            <div class="btn-group">
17
                <form method="get" action="">
18
                    <input type="hidden" name="op" value="list" />
19
                    [% IF show_all %]
20
                        <input type="hidden" name="show_all" value="0" />
21
                        <button type="submit" class="btn btn-default"><i class="fa fa-eye-slash"></i> Show my branch reports only</button>
22
                    [% ELSE %]
23
                        <input type="hidden" name="show_all" value="1" />
24
                        <button type="submit" class="btn btn-default"><i class="fa fa-eye"></i> Show all reports</button>
25
                    [% END %]
26
                </form>
27
            </div>
28
        [% END %]
29
    [% END %]
14
30
15
    [% IF ( showsql || execute || editsql || save_successful ) %]
31
    [% IF ( showsql || execute || editsql || save_successful ) %]
16
        [% IF ( CAN_user_reports_delete_reports && !CAN_user_reports_create_reports ) %]
32
        [% IF ( CAN_user_reports_delete_reports && !CAN_user_reports_create_reports ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/reports.pref (+8 lines)
Line 0 Link Here
1
Reports:
2
    Reports Access:
3
     -
4
         - pref: LimitReportsByBranch
5
           choices:
6
               1: Enable
7
               0: Disable
8
         - "limiting report access based on staff home library."
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-3 / +27 lines)
Lines 3-8 Link Here
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE KohaDates %]
4
[% USE KohaDates %]
5
[% USE Koha %]
5
[% USE Koha %]
6
[% USE Branches %]
6
[% USE TablesSettings %]
7
[% USE TablesSettings %]
7
[% USE HtmlScrubber %]
8
[% USE HtmlScrubber %]
8
[% USE JSON.Escape %]
9
[% USE JSON.Escape %]
Lines 199-205 Link Here
199
            <main>
200
            <main>
200
                [% INCLUDE 'messages.inc' %]
201
                [% INCLUDE 'messages.inc' %]
201
202
202
                [% INCLUDE "reports-toolbar.inc" %]
203
                [% INCLUDE 'reports-toolbar.inc' %]
203
204
204
                [% IF ( start ) %]
205
                [% IF ( start ) %]
205
                    <h1>Guided reports</h1>
206
                    <h1>Guided reports</h1>
Lines 850-855 Link Here
850
                            <input type="hidden" name="reportname" value="[% reportname | html %]" />
851
                            <input type="hidden" name="reportname" value="[% reportname | html %]" />
851
                            <input type="hidden" name="group" value="[% group | html %]" />
852
                            <input type="hidden" name="group" value="[% group | html %]" />
852
                            <input type="hidden" name="subgroup" value="[% subgroup | html %]" />
853
                            <input type="hidden" name="subgroup" value="[% subgroup | html %]" />
854
                            <input type="hidden" name="branches" value="[% branches | html %]" />
853
                            <input type="hidden" name="notes" value="[% notes | scrub_html type => 'note' | $raw %]" />
855
                            <input type="hidden" name="notes" value="[% notes | scrub_html type => 'note' | $raw %]" />
854
                            <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
856
                            <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
855
                            <input type="hidden" name="cache_expiry_units" value="[% cache_expiry_units | html %]" />
857
                            <input type="hidden" name="cache_expiry_units" value="[% cache_expiry_units | html %]" />
Lines 1434-1440 Link Here
1434
                                <span class="required">Required</span>
1436
                                <span class="required">Required</span>
1435
                            </div>
1437
                            </div>
1436
                        </fieldset>
1438
                        </fieldset>
1437
1439
                        [% IF ( Koha.Preference('LimitReportsByBranch') && ( CAN_user_superlibrarian || CAN_user_reports_manage_report_limits ) ) %]
1440
                            <fieldset class="rows">
1441
                                <legend>Library limitation:</legend>
1442
                                <div
1443
                                    ><label for="library_limitation">Library limitation: </label>
1444
                                    <select id="library_limitation" name="branches" multiple size="10">
1445
                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => report.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
1446
                                    </select>
1447
                                    <div class="hint">Limits the use of this report to the selected libraries.</div>
1448
                                </div>
1449
                            </fieldset>
1450
                        [% END %]
1438
                        <fieldset class="action">
1451
                        <fieldset class="action">
1439
                            <input type="hidden" name="op" value="cud-save" />
1452
                            <input type="hidden" name="op" value="cud-save" />
1440
                            <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
1453
                            <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
Lines 1548-1554 Link Here
1548
                            <br />
1561
                            <br />
1549
                            <span class="required" style="margin-left:30px;">Required</span>
1562
                            <span class="required" style="margin-left:30px;">Required</span>
1550
                        </fieldset>
1563
                        </fieldset>
1551
1564
                        [% IF ( Koha.Preference('LimitReportsByBranch') && ( CAN_user_superlibrarian || CAN_user_reports_manage_report_limits ) ) %]
1565
                            <fieldset class="rows">
1566
                                <legend>Library limitation:</legend>
1567
                                <div
1568
                                    ><label for="library_limitation">Library limitation: </label>
1569
                                    <select id="library_limitation" name="branches" multiple size="10">
1570
                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => report.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
1571
                                    </select>
1572
                                    <div class="hint">Limits the use of this report to the selected libraries.</div>
1573
                                </div>
1574
                            </fieldset>
1575
                        [% END %]
1552
                        <fieldset class="action">
1576
                        <fieldset class="action">
1553
                            <button class="btn btn-primary" type="submit" name="op" value="cud-update_sql">Update SQL</button>
1577
                            <button class="btn btn-primary" type="submit" name="op" value="cud-update_sql">Update SQL</button>
1554
                            <button class="btn btn-default" type="submit" name="op" value="cud-update_and_run_sql">Update and run SQL</button>
1578
                            <button class="btn btn-default" type="submit" name="op" value="cud-update_and_run_sql">Update and run SQL</button>
(-)a/reports/guided_reports.pl (-25 / +102 lines)
Lines 83-89 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
83
my $session_id = $input->cookie('CGISESSID');
83
my $session_id = $input->cookie('CGISESSID');
84
my $session    = $session_id ? get_session($session_id) : undef;
84
my $session    = $session_id ? get_session($session_id) : undef;
85
85
86
$template->param( templates => Koha::Notice::Templates->search( { module => 'report' } ) );
86
my $show_all = 0;
87
if ( defined $input->param('show_all') ) {
88
    my $param = $input->param('show_all');
89
    if ( defined $param && $param eq '1' ) {
90
        $show_all = 1;
91
        $session->param( 'show_all', 1 ) if $session;
92
    } else {
93
        $show_all = 0;
94
        $session->clear('show_all') if $session;
95
    }
96
} elsif ( $session && defined $session->param('show_all') ) {
97
    $show_all = $session->param('show_all') ? 1 : 0;
98
}
99
$template->param( 'show_all' => $show_all );
100
101
$template->param( templates => Koha::Notice::Templates->search( { module => 'report' } ), op => $op );
87
102
88
my $filter;
103
my $filter;
89
if ( $input->param("filter_set") or $input->param('clear_filters') ) {
104
if ( $input->param("filter_set") or $input->param('clear_filters') ) {
Lines 127-133 if ( !$op ) { Link Here
127
        'showsql'       => 1,
142
        'showsql'       => 1,
128
        'mana_success'  => scalar $input->param('mana_success'),
143
        'mana_success'  => scalar $input->param('mana_success'),
129
        'mana_id'       => $report->{mana_id},
144
        'mana_id'       => $report->{mana_id},
130
        'mana_comments' => $report->{comments}
145
        'mana_comments' => $report->{comments},
131
    );
146
    );
132
147
133
} elsif ( $op eq 'edit_form' ) {
148
} elsif ( $op eq 'edit_form' ) {
Lines 148-158 if ( !$op ) { Link Here
148
        'editsql'               => 1,
163
        'editsql'               => 1,
149
        'mana_id'               => $report->{mana_id},
164
        'mana_id'               => $report->{mana_id},
150
        'mana_comments'         => $report->{comments},
165
        'mana_comments'         => $report->{comments},
151
        'tables'                => $tables
166
        'tables'                => $tables,
167
        'report'                => $report,
152
    );
168
    );
153
169
154
} elsif ( $op eq 'cud-update_sql' || $op eq 'cud-update_and_run_sql' ) {
170
} elsif ( $op eq 'cud-update_sql' || $op eq 'cud-update_and_run_sql' ) {
155
    my $id                 = $input->param('id');
171
    my $id                 = $input->param('id');
172
    my $report             = Koha::Reports->find($id);
156
    my $sql                = $input->param('sql');
173
    my $sql                = $input->param('sql');
157
    my $reportname         = $input->param('reportname');
174
    my $reportname         = $input->param('reportname');
158
    my $group              = $input->param('group');
175
    my $group              = $input->param('group');
Lines 163-169 if ( !$op ) { Link Here
163
    my $public             = $input->param('public');
180
    my $public             = $input->param('public');
164
    my $save_anyway        = $input->param('save_anyway');
181
    my $save_anyway        = $input->param('save_anyway');
165
    my @errors;
182
    my @errors;
166
    my $tables = get_tables();
183
    my $tables   = get_tables();
184
    my @branches = grep { $_ ne q{} } $input->multi_param('branches');
167
185
168
    # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
186
    # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
169
    if ($cache_expiry_units) {
187
    if ($cache_expiry_units) {
Lines 211-216 if ( !$op ) { Link Here
211
                'problematic_authvals' => $problematic_authvals,
229
                'problematic_authvals' => $problematic_authvals,
212
                'warn_authval_problem' => 1,
230
                'warn_authval_problem' => 1,
213
                'phase_update'         => 1,
231
                'phase_update'         => 1,
232
                'branches'             => @branches,
233
                'report'               => $report,
214
            );
234
            );
215
235
216
        } else {
236
        } else {
Lines 225-234 if ( !$op ) { Link Here
225
                    subgroup     => $subgroup,
245
                    subgroup     => $subgroup,
226
                    notes        => $notes,
246
                    notes        => $notes,
227
                    public       => $public,
247
                    public       => $public,
228
                    cache_expiry => $cache_expiry,
248
                    cache_expiry => $cache_expiry
229
                }
249
                }
230
            );
250
            );
231
251
252
            $report->store;
253
            $report->replace_library_limits( \@branches );
254
232
            my $editsql = 1;
255
            my $editsql = 1;
233
            if ( $op eq 'cud-update_and_run_sql' ) {
256
            if ( $op eq 'cud-update_and_run_sql' ) {
234
                $editsql = 0;
257
                $editsql = 0;
Lines 245-251 if ( !$op ) { Link Here
245
                'cache_expiry'          => $cache_expiry,
268
                'cache_expiry'          => $cache_expiry,
246
                'public'                => $public,
269
                'public'                => $public,
247
                'usecache'              => $usecache,
270
                'usecache'              => $usecache,
248
                'tables'                => $tables
271
                'tables'                => $tables,
272
                'report'                => $report
249
            );
273
            );
250
            logaction( "REPORTS", "MODIFY", $id, "$reportname | $sql" ) if C4::Context->preference("ReportsLog");
274
            logaction( "REPORTS", "MODIFY", $id, "$reportname | $sql" ) if C4::Context->preference("ReportsLog");
251
        }
275
        }
Lines 514-519 if ( !$op ) { Link Here
514
    my $public             = $input->param('public');
538
    my $public             = $input->param('public');
515
    my $save_anyway        = $input->param('save_anyway');
539
    my $save_anyway        = $input->param('save_anyway');
516
    my $tables             = get_tables();
540
    my $tables             = get_tables();
541
    my @branches           = grep { $_ ne q{} } $input->multi_param('branches');
517
542
518
    # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
543
    # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
519
    if ($cache_expiry_units) {
544
    if ($cache_expiry_units) {
Lines 591-596 if ( !$op ) { Link Here
591
                    public         => $public,
616
                    public         => $public,
592
                }
617
                }
593
            );
618
            );
619
            my $report = Koha::Reports->find($id);
620
            $report->replace_library_limits( \@branches );
621
594
            logaction( "REPORTS", "ADD", $id, "$name | $sql" ) if C4::Context->preference("ReportsLog");
622
            logaction( "REPORTS", "ADD", $id, "$name | $sql" ) if C4::Context->preference("ReportsLog");
595
            $template->param(
623
            $template->param(
596
                'save_successful'       => 1,
624
                'save_successful'       => 1,
Lines 603-609 if ( !$op ) { Link Here
603
                'cache_expiry'          => $cache_expiry,
631
                'cache_expiry'          => $cache_expiry,
604
                'public'                => $public,
632
                'public'                => $public,
605
                'usecache'              => $usecache,
633
                'usecache'              => $usecache,
606
                'tables'                => $tables
634
                'tables'                => $tables,
635
                'report'                => $report,
607
            );
636
            );
608
        }
637
        }
609
    }
638
    }
Lines 746-765 if ( !$op ) { Link Here
746
775
747
} elsif ( $op eq 'add_form_sql' || $op eq 'duplicate' ) {
776
} elsif ( $op eq 'add_form_sql' || $op eq 'duplicate' ) {
748
777
749
    my ( $group, $subgroup, $sql, $reportname, $notes );
778
    my ( $group, $subgroup, $sql, $reportname, $notes, @branches, $report );
750
    if ( $input->param('sql') ) {
779
    if ( $input->param('sql') ) {
751
        $group      = $input->param('report_group');
780
        $group      = $input->param('report_group');
752
        $subgroup   = $input->param('report_subgroup');
781
        $subgroup   = $input->param('report_subgroup');
753
        $sql        = $input->param('sql')        // '';
782
        $sql        = $input->param('sql')        // '';
754
        $reportname = $input->param('reportname') // '';
783
        $reportname = $input->param('reportname') // '';
755
        $notes      = $input->param('notes')      // '';
784
        $notes      = $input->param('notes')      // '';
785
        @branches   = grep { $_ ne q{} } $input->multi_param('branches');
786
756
    } elsif ( my $report_id = $input->param('id') ) {
787
    } elsif ( my $report_id = $input->param('id') ) {
757
        my $report = Koha::Reports->find($report_id);
788
        $report     = Koha::Reports->find($report_id);
758
        $group      = $report->report_group;
789
        $group      = $report->report_group;
759
        $subgroup   = $report->report_subgroup;
790
        $subgroup   = $report->report_subgroup;
760
        $sql        = $report->savedsql    // '';
791
        $sql        = $report->savedsql    // '';
761
        $reportname = $report->report_name // '';
792
        $reportname = $report->report_name // '';
762
        $notes      = $report->notes       // '';
793
        $notes      = $report->notes       // '';
794
        @branches   = grep { $_ ne q{} } $input->multi_param('branches');
795
763
    }
796
    }
764
797
765
    my $tables = get_tables();
798
    my $tables = get_tables();
Lines 774-779 if ( !$op ) { Link Here
774
        'cache_expiry'          => 300,
807
        'cache_expiry'          => 300,
775
        'usecache'              => $usecache,
808
        'usecache'              => $usecache,
776
        'tables'                => $tables,
809
        'tables'                => $tables,
810
        'report'                => $report,
777
811
778
    );
812
    );
779
}
813
}
Lines 1081-1104 if ( $op eq 'list' || $op eq 'convert' ) { Link Here
1081
    my $subgroup = $input->param('subgroup');
1115
    my $subgroup = $input->param('subgroup');
1082
    $filter->{group}    = $group;
1116
    $filter->{group}    = $group;
1083
    $filter->{subgroup} = $subgroup;
1117
    $filter->{subgroup} = $subgroup;
1084
    my $reports = get_saved_reports($filter);
1118
1085
    my $has_obsolete_reports;
1119
    my $pref_limit_reports_by_branch = C4::Context->preference("LimitReportsByBranch");
1086
    for my $report (@$reports) {
1120
    if ( $show_all == 0 && $pref_limit_reports_by_branch == "1" ) {
1087
        $report->{results} = C4::Reports::Guided::get_results( $report->{id} );
1121
        my $reports_with_library_limits_results =
1088
        if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
1122
            Koha::Reports->search_with_library_limits( {}, {}, C4::Context::mybranch() );
1089
            $report->{seems_obsolete} = 1;
1123
        my $reports_list     = $reports_with_library_limits_results->unblessed;
1090
            $has_obsolete_reports++;
1124
        my $filtered_reports = get_saved_reports($filter);
1125
1126
        # Remove all reports in $reports_list that are not also in $filtered_reports
1127
1128
        my %seen;
1129
        my @filtered_reports_by_library_limits;
1130
        foreach my $element (@$filtered_reports) {
1131
            $seen{ $element->{id} } = 1;
1091
        }
1132
        }
1133
1134
        foreach my $element (@$reports_list) {
1135
            if ( $seen{ $element->{id} } ) {
1136
                push @filtered_reports_by_library_limits, $element;
1137
            }
1138
        }
1139
1140
        my $has_obsolete_reports;
1141
        for my $report (@filtered_reports_by_library_limits) {
1142
            $report->{results} = C4::Reports::Guided::get_results( $report->{id} );
1143
            if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
1144
                $report->{seems_obsolete} = 1;
1145
                $has_obsolete_reports++;
1146
            }
1147
            $template->param(
1148
                'manamsg'               => $input->param('manamsg') || '',
1149
                'saved1'                => 1,
1150
                'savedreports'          => \@filtered_reports_by_library_limits,
1151
                'usecache'              => $usecache,
1152
                'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
1153
                filters                 => $filter,
1154
                has_obsolete_reports    => $has_obsolete_reports,
1155
            );
1156
        }
1157
    } else {
1158
1159
        my $reports = get_saved_reports($filter);
1160
        my $has_obsolete_reports;
1161
1162
        for my $report (@$reports) {
1163
            $report->{results} = C4::Reports::Guided::get_results( $report->{id} );
1164
            if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
1165
                $report->{seems_obsolete} = 1;
1166
                $has_obsolete_reports++;
1167
            }
1168
        }
1169
        $template->param(
1170
            'manamsg'               => $input->param('manamsg') || '',
1171
            'saved1'                => 1,
1172
            'savedreports'          => $reports,
1173
            'usecache'              => $usecache,
1174
            'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
1175
            filters                 => $filter,
1176
            has_obsolete_reports    => $has_obsolete_reports,
1177
        );
1092
    }
1178
    }
1093
    $template->param(
1094
        'manamsg'               => $input->param('manamsg') || '',
1095
        'saved1'                => 1,
1096
        'savedreports'          => $reports,
1097
        'usecache'              => $usecache,
1098
        'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
1099
        filters                 => $filter,
1100
        has_obsolete_reports    => $has_obsolete_reports,
1101
    );
1102
}
1179
}
1103
1180
1104
# pass $sth, get back an array of names for the column headers
1181
# pass $sth, get back an array of names for the column headers
(-)a/t/Koha/Auth/Permissions.t (+2 lines)
Lines 63-68 subtest 'normal staff user test' => sub { Link Here
63
        'CAN_user_reports_create_reports'                    => 1,
63
        'CAN_user_reports_create_reports'                    => 1,
64
        'CAN_user_reports_delete_reports'                    => 1,
64
        'CAN_user_reports_delete_reports'                    => 1,
65
        'CAN_user_reports_execute_reports'                   => 1,
65
        'CAN_user_reports_execute_reports'                   => 1,
66
        'CAN_user_reports_manage_report_limits'              => 1,
66
    };
67
    };
67
    is_deeply( $authz, $expected, 'Expected permissions generated for normal staff user' );
68
    is_deeply( $authz, $expected, 'Expected permissions generated for normal staff user' );
68
};
69
};
Lines 228-233 subtest 'superlibrarian tests' => sub { Link Here
228
        'CAN_user_reports_create_reports'                           => 1,
229
        'CAN_user_reports_create_reports'                           => 1,
229
        'CAN_user_reports_delete_reports'                           => 1,
230
        'CAN_user_reports_delete_reports'                           => 1,
230
        'CAN_user_reports_execute_reports'                          => 1,
231
        'CAN_user_reports_execute_reports'                          => 1,
232
        'CAN_user_reports_manage_report_limits'                     => 1,
231
        'CAN_user_reports'                                          => 1,
233
        'CAN_user_reports'                                          => 1,
232
        'CAN_user_reserveforothers_modify_holds_priority'           => 1,
234
        'CAN_user_reserveforothers_modify_holds_priority'           => 1,
233
        'CAN_user_reserveforothers_place_holds'                     => 1,
235
        'CAN_user_reserveforothers_place_holds'                     => 1,
(-)a/t/db_dependent/Koha/Reports.t (-2 / +37 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 9;
21
use Test::More tests => 10;
22
22
23
use Koha::Report;
23
use Koha::Report;
24
use Koha::Reports;
24
use Koha::Reports;
Lines 185-188 subtest '_might_add_limit' => sub { Link Here
185
    );
185
    );
186
};
186
};
187
187
188
subtest 'reports_branches are added and removed from report_branches table' => sub {
189
    plan tests => 4;
190
191
    my $updated_nb_of_reports = Koha::Reports->search->count;
192
    my $report                = Koha::Report->new(
193
        {
194
            report_name => 'report_name_for_test_1',
195
            savedsql    => 'SELECT * FROM items WHERE itemnumber IN <<Test|list>>',
196
        }
197
    )->store;
198
199
    my $id       = $report->id;
200
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
201
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
202
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
203
    my @branches = ( $library1->branchcode, $library2->branchcode, $library3->branchcode );
204
205
    $report->replace_library_limits( \@branches );
206
207
    my @branches_loop = $report->get_library_limits->as_list;
208
    is( scalar @branches_loop, 3, '3 branches added to report_branches table' );
209
210
    $report->replace_library_limits( [ $library1->branchcode, $library2->branchcode ] );
211
212
    @branches_loop = $report->get_library_limits->as_list;
213
    is( scalar @branches_loop, 2, '1 branch removed from report_branches table' );
214
215
    $report->delete;
216
    is( Koha::Reports->search->count, $updated_nb_of_reports, 'Report deleted, count is back to original' );
217
    is(
218
        $schema->resultset('ReportsBranch')->search( { report_id => $id } )->count,
219
        0,
220
        'No branches left in reports_branches table after report deletion'
221
    );
222
};
223
188
$schema->storage->txn_rollback;
224
$schema->storage->txn_rollback;
189
- 

Return to bug 16631