Lines 23-29
use Modern::Perl;
Link Here
|
23 |
use Data::Dumper; |
23 |
use Data::Dumper; |
24 |
use POSIX; |
24 |
use POSIX; |
25 |
use CGI qw ( -utf8 ); |
25 |
use CGI qw ( -utf8 ); |
26 |
use CGI::Cookie; # need to check cookies before having CGI parse the POST request |
26 |
use CGI::Cookie; # need to check cookies before having CGI parse the POST request |
27 |
use URI::Escape; |
27 |
use URI::Escape; |
28 |
use C4::Auth qw(:DEFAULT check_cookie_auth); |
28 |
use C4::Auth qw(:DEFAULT check_cookie_auth); |
29 |
use C4::Context; |
29 |
use C4::Context; |
Lines 34-77
use C4::Debug;
Link Here
|
34 |
use C4::Tags qw(get_tags get_approval_rows approval_counts whitelist blacklist is_approved); |
34 |
use C4::Tags qw(get_tags get_approval_rows approval_counts whitelist blacklist is_approved); |
35 |
|
35 |
|
36 |
my $script_name = "/cgi-bin/koha/tags/review.pl"; |
36 |
my $script_name = "/cgi-bin/koha/tags/review.pl"; |
37 |
my $needed_flags = { tools => 'moderate_tags' }; # FIXME: replace when more specific permission is created. |
37 |
my $needed_flags = { tools => 'moderate_tags' }; # FIXME: replace when more specific permission is created. |
38 |
|
38 |
|
39 |
sub ajax_auth_cgi ($) { # returns CGI object |
39 |
sub ajax_auth_cgi ($) { # returns CGI object |
40 |
my $needed_flags = shift; |
40 |
my $needed_flags = shift; |
41 |
my %cookies = CGI::Cookie->fetch; |
41 |
my %cookies = CGI::Cookie->fetch; |
42 |
my $input = CGI->new; |
42 |
my $input = CGI->new; |
43 |
my $sessid = $cookies{'CGISESSID'}->value; |
43 |
my $sessid = $cookies{'CGISESSID'}->value; |
44 |
my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); |
44 |
my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); |
45 |
$debug and |
45 |
$debug and |
46 |
print STDERR "($auth_status, $auth_sessid) = check_cookie_auth($sessid," . Dumper($needed_flags) . ")\n"; |
46 |
print STDERR "($auth_status, $auth_sessid) = check_cookie_auth($sessid," . Dumper($needed_flags) . ")\n"; |
47 |
if ($auth_status ne "ok") { |
47 |
if ($auth_status ne "ok") { |
48 |
output_with_http_headers $input, undef, |
48 |
output_with_http_headers $input, undef, |
49 |
"window.alert('Your CGI session cookie ($sessid) is not current. " . |
49 |
"window.alert('Your CGI session cookie ($sessid) is not current. " . |
50 |
"Please refresh the page and try again.');\n", 'js'; |
50 |
"Please refresh the page and try again.');\n", 'js'; |
51 |
exit 0; |
51 |
exit 0; |
52 |
} |
52 |
} |
53 |
$debug and print STDERR "AJAX request: " . Dumper($input), |
53 |
$debug and print STDERR "AJAX request: " . Dumper($input), |
54 |
"\n(\$auth_status,\$auth_sessid) = ($auth_status,$auth_sessid)\n"; |
54 |
"\n(\$auth_status,\$auth_sessid) = ($auth_status,$auth_sessid)\n"; |
55 |
return $input; |
55 |
return $input; |
56 |
} |
56 |
} |
57 |
|
57 |
|
58 |
if (is_ajax()) { |
58 |
if (is_ajax()) { |
59 |
my $input = &ajax_auth_cgi($needed_flags); |
59 |
my $input = &ajax_auth_cgi($needed_flags); |
60 |
my $operator = C4::Context->userenv->{'number'}; # must occur AFTER auth |
60 |
my $operator = C4::Context->userenv->{'number'}; # must occur AFTER auth |
61 |
$debug and print STDERR "op: " . Dumper($operator) . "\n"; |
61 |
$debug and print STDERR "op: " . Dumper($operator) . "\n"; |
62 |
my ($tag, $js_reply); |
62 |
my ($tag, $js_reply); |
63 |
if ($tag = $input->param('test')) { |
63 |
if ($tag = $input->param('test')) { |
64 |
my $check = is_approved($tag); |
64 |
my $check = is_approved($tag); |
65 |
$js_reply = ( $check >= 1 ? 'success' : $check <= -1 ? 'failure' : 'indeterminate' ) . "_test('".uri_escape_utf8($tag)."');\n"; |
65 |
$js_reply = ( $check >= 1 ? 'success' : $check <= -1 ? 'failure' : 'indeterminate' ) . "_test('".uri_escape_utf8($tag)."');\n"; |
66 |
} |
66 |
} |
67 |
if ($tag = $input->param('ok')) { |
67 |
if ($tag = $input->param('ok')) { |
68 |
$js_reply = ( whitelist($operator,$tag) ? 'success' : 'failure') . "_approve('".uri_escape_utf8($tag)."');\n"; |
68 |
$js_reply = ( whitelist($operator,$tag) ? 'success' : 'failure') . "_approve('".uri_escape_utf8($tag)."');\n"; |
69 |
} |
69 |
} |
70 |
if ($tag = $input->param('rej')) { |
70 |
if ($tag = $input->param('rej')) { |
71 |
$js_reply = ( blacklist($operator,$tag) ? 'success' : 'failure') . "_reject('".uri_escape_utf8($tag)."');\n"; |
71 |
$js_reply = ( blacklist($operator,$tag) ? 'success' : 'failure') . "_reject('".uri_escape_utf8($tag)."');\n"; |
72 |
} |
72 |
} |
73 |
output_with_http_headers $input, undef, $js_reply, 'js'; |
73 |
output_with_http_headers $input, undef, $js_reply, 'js'; |
74 |
exit; |
74 |
exit; |
75 |
} |
75 |
} |
76 |
|
76 |
|
77 |
### Below is the sad, boring, necessary non-AJAX HTML code. |
77 |
### Below is the sad, boring, necessary non-AJAX HTML code. |
Lines 98-226
$op ||= 'none';
Link Here
|
98 |
@tags = $input->multi_param('tags'); |
98 |
@tags = $input->multi_param('tags'); |
99 |
|
99 |
|
100 |
$borrowernumber == 0 and push @errors, {op_zero=>1}; |
100 |
$borrowernumber == 0 and push @errors, {op_zero=>1}; |
101 |
if ($op eq 'approve') { |
101 |
if ($op eq 'approve') { |
102 |
foreach (@tags) { |
102 |
foreach (@tags) { |
103 |
whitelist($borrowernumber,$_) or push @errors, {failed_ok=>$_}; |
103 |
whitelist($borrowernumber,$_) or push @errors, {failed_ok=>$_}; |
104 |
} |
104 |
} |
105 |
} elsif ($op eq 'reject' ) { |
105 |
} elsif ($op eq 'reject' ) { |
106 |
foreach (@tags) { |
106 |
foreach (@tags) { |
107 |
blacklist($borrowernumber,$_) or push @errors, {failed_rej=>$_}; |
107 |
blacklist($borrowernumber,$_) or push @errors, {failed_rej=>$_}; |
108 |
} |
108 |
} |
109 |
} elsif ($op eq 'test' ) { |
109 |
} elsif ($op eq 'test' ) { |
110 |
my $tag = $input->param('test'); |
110 |
my $tag = $input->param('test'); |
111 |
push @tags, $tag; |
111 |
push @tags, $tag; |
112 |
my $check = is_approved($tag); |
112 |
my $check = is_approved($tag); |
113 |
$template->param( |
113 |
$template->param( |
114 |
test_term => $tag, |
114 |
test_term => $tag, |
115 |
( $check >= 1 ? 'verdict_ok' : |
115 |
( $check >= 1 ? 'verdict_ok' : |
116 |
$check <= -1 ? 'verdict_rej' : 'verdict_indeterminate' ) => 1, |
116 |
$check <= -1 ? 'verdict_rej' : 'verdict_indeterminate' ) => 1, |
117 |
); |
117 |
); |
118 |
} |
118 |
} |
119 |
|
119 |
|
120 |
my $counts = &approval_counts; |
120 |
my $counts = &approval_counts; |
121 |
foreach (keys %$counts) { |
121 |
foreach (keys %$counts) { |
122 |
$template->param($_ => $counts->{$_}); |
122 |
$template->param($_ => $counts->{$_}); |
123 |
} |
123 |
} |
124 |
|
124 |
|
125 |
sub pagination_calc ($;$) { |
125 |
sub pagination_calc ($;$) { |
126 |
my $query = shift or return undef; |
126 |
my $query = shift or return undef; |
127 |
my $hardlimit = (@_) ? shift : 100; # hardcoded, could be another syspref |
127 |
my $hardlimit = (@_) ? shift : 100; # hardcoded, could be another syspref |
128 |
my $pagesize = $query->param('limit' ) || $hardlimit; |
128 |
my $pagesize = $query->param('limit' ) || $hardlimit; |
129 |
my $page = $query->param('page' ) || 1; |
129 |
my $page = $query->param('page' ) || 1; |
130 |
my $offset = $query->param('offset') || 0; |
130 |
my $offset = $query->param('offset') || 0; |
131 |
($pagesize <= $hardlimit) or $pagesize = $hardlimit; |
131 |
($pagesize <= $hardlimit) or $pagesize = $hardlimit; |
132 |
if ($page > 1) { |
132 |
if ($page > 1) { |
133 |
$offset = ($page-1)*$pagesize; |
133 |
$offset = ($page-1)*$pagesize; |
134 |
} else { |
134 |
} else { |
135 |
$page = 1; |
135 |
$page = 1; |
136 |
} |
136 |
} |
137 |
return ($pagesize,$page,$offset); |
137 |
return ($pagesize,$page,$offset); |
138 |
} |
138 |
} |
139 |
|
139 |
|
140 |
my ($pagesize,$page,$offset) = pagination_calc($input,100); |
140 |
my ($pagesize,$page,$offset) = pagination_calc($input,100); |
141 |
|
141 |
|
142 |
my %filters = ( |
142 |
my %filters = ( |
143 |
limit => $offset ? "$offset,$pagesize" : $pagesize, |
143 |
limit => $offset ? "$offset,$pagesize" : $pagesize, |
144 |
sort => 'approved,-weight_total,+term', |
144 |
sort => 'approved,-weight_total,+term', |
145 |
); |
145 |
); |
146 |
my ($filter,$date_from,$date_to); |
146 |
my ($filter,$date_from,$date_to); |
147 |
if (defined $input->param('approved')) { # 0 is valid value, must check defined |
147 |
if (defined $input->param('approved')) { # 0 is valid value, must check defined |
148 |
$filter = $input->param('approved'); |
148 |
$filter = $input->param('approved'); |
149 |
} else { |
149 |
} else { |
150 |
$filter = 0; |
150 |
$filter = 0; |
151 |
} |
151 |
} |
152 |
if ($filter eq 'all') { |
152 |
if ($filter eq 'all') { |
153 |
$template->param(filter_approved_all => 1); |
153 |
$template->param(filter_approved_all => 1); |
154 |
} elsif ($filter =~ /-?[01]/) { |
154 |
} elsif ($filter =~ /-?[01]/) { |
155 |
$filters{approved} = $filter; |
155 |
$filters{approved} = $filter; |
156 |
$template->param( |
156 |
$template->param( |
157 |
($filter == 1 ? 'filter_approved_ok' : |
157 |
($filter == 1 ? 'filter_approved_ok' : |
158 |
$filter == 0 ? 'filter_approved_pending' : |
158 |
$filter == 0 ? 'filter_approved_pending' : |
159 |
$filter == -1 ? 'filter_approved_rej' : |
159 |
$filter == -1 ? 'filter_approved_rej' : |
160 |
'filter_approved') => 1 |
160 |
'filter_approved') => 1 |
161 |
); |
161 |
); |
162 |
} |
162 |
} |
163 |
|
163 |
|
164 |
# my $q_count = get_approval_rows({limit=>$pagesize, sort=>'approved,-weight_total,+term', count=>1}); |
164 |
# my $q_count = get_approval_rows({limit=>$pagesize, sort=>'approved,-weight_total,+term', count=>1}); |
165 |
if ($filter = $input->param('tag')) { |
165 |
if ($filter = $input->param('tag')) { |
166 |
$template->param(filter_tag=>$filter); |
166 |
$template->param(filter_tag=>$filter); |
167 |
$filters{term} = $filter; |
167 |
$filters{term} = $filter; |
168 |
} |
168 |
} |
169 |
if ($filter = $input->param('from')) { |
169 |
if ($filter = $input->param('from')) { |
170 |
$date_from = eval { output_pref( { dt => dt_from_string( $filter ), dateonly => 1, dateformat => 'iso' } ); }; |
170 |
$date_from = eval { output_pref( { dt => dt_from_string( $filter ), dateonly => 1, dateformat => 'iso' } ); }; |
171 |
if ( $date_from ) { |
171 |
if ( $date_from ) { |
172 |
$template->param(filter_date_approved_from=>$filter); |
172 |
$template->param(filter_date_approved_from=>$filter); |
173 |
$filters{date_approved} = ">=$date_from"; |
173 |
$filters{date_approved} = ">=$date_from"; |
174 |
} else { |
174 |
} else { |
175 |
push @errors, {date_from=>$filter}; |
175 |
push @errors, {date_from=>$filter}; |
176 |
} |
176 |
} |
177 |
} |
177 |
} |
178 |
if ($filter = $input->param('to')) { |
178 |
if ($filter = $input->param('to')) { |
179 |
$date_to = eval { output_pref( { dt => dt_from_string( $filter ), dateonly => 1, dateformat => 'iso' } ); }; |
179 |
$date_to = eval { output_pref( { dt => dt_from_string( $filter ), dateonly => 1, dateformat => 'iso' } ); }; |
180 |
if ( $date_to ) { |
180 |
if ( $date_to ) { |
181 |
$template->param(filter_date_approved_to=>$filter); |
181 |
$template->param(filter_date_approved_to=>$filter); |
182 |
$filters{date_approved} = "<=$date_to"; |
182 |
$filters{date_approved} = "<=$date_to"; |
183 |
} else { |
183 |
} else { |
184 |
push @errors, {date_to=>$filter}; |
184 |
push @errors, {date_to=>$filter}; |
185 |
} |
185 |
} |
186 |
} |
186 |
} |
187 |
if ($filter = $input->param('approver')) { # name (or borrowernumber) from input box |
187 |
if ($filter = $input->param('approver')) { # name (or borrowernumber) from input box |
188 |
if ($filter =~ /^\d+$/ and $filter > 0) { |
188 |
if ($filter =~ /^\d+$/ and $filter > 0) { |
189 |
# $filter=get borrowernumber from name |
189 |
# $filter=get borrowernumber from name |
190 |
# FIXME: get borrowernumber from name not implemented. |
190 |
# FIXME: get borrowernumber from name not implemented. |
191 |
$template->param(filter_approver=>$filter); |
191 |
$template->param(filter_approver=>$filter); |
192 |
$filters{approved_by} = $filter; |
192 |
$filters{approved_by} = $filter; |
193 |
} else { |
193 |
} else { |
194 |
push @errors, {approver=>$filter}; |
194 |
push @errors, {approver=>$filter}; |
195 |
} |
195 |
} |
196 |
} |
196 |
} |
197 |
if ($filter = $input->param('approved_by')) { # borrowernumber from link |
197 |
if ($filter = $input->param('approved_by')) { # borrowernumber from link |
198 |
if ($filter =~ /^\d+$/ and $filter > 0) { |
198 |
if ($filter =~ /^\d+$/ and $filter > 0) { |
199 |
$template->param(filter_approver=>$filter); |
199 |
$template->param(filter_approver=>$filter); |
200 |
$filters{approved_by} = $filter; |
200 |
$filters{approved_by} = $filter; |
201 |
} else { |
201 |
} else { |
202 |
push @errors, {approved_by=>$filter}; |
202 |
push @errors, {approved_by=>$filter}; |
203 |
} |
203 |
} |
204 |
} |
204 |
} |
205 |
$debug and print STDERR "filters: " . Dumper(\%filters); |
205 |
$debug and print STDERR "filters: " . Dumper(\%filters); |
206 |
my $tagloop = get_approval_rows(\%filters); |
206 |
my $tagloop = get_approval_rows(\%filters); |
207 |
my $qstring = $input->query_string; |
207 |
my $qstring = $input->query_string; |
208 |
$qstring =~ s/([&;])*\blimit=\d+//; # remove pagination var |
208 |
$qstring =~ s/([&;])*\blimit=\d+//; # remove pagination var |
209 |
$qstring =~ s/^;+//; # remove leading delims |
209 |
$qstring =~ s/^;+//; # remove leading delims |
210 |
$qstring = "limit=$pagesize" . ($qstring ? '&' . $qstring : ''); |
210 |
$qstring = "limit=$pagesize" . ($qstring ? '&' . $qstring : ''); |
211 |
$debug and print STDERR "number of approval_rows: " . scalar(@$tagloop) . "rows\n"; |
211 |
$debug and print STDERR "number of approval_rows: " . scalar(@$tagloop) . "rows\n"; |
212 |
(scalar @errors) and $template->param(message_loop=>\@errors); |
212 |
(scalar @errors) and $template->param(message_loop=>\@errors); |
213 |
$template->param( |
213 |
$template->param( |
214 |
offset => $offset, # req'd for EXPR |
214 |
offset => $offset, # req'd for EXPR |
215 |
op => $op, |
215 |
op => $op, |
216 |
op_count => scalar(@tags), |
216 |
op_count => scalar(@tags), |
217 |
script_name => $script_name, |
217 |
script_name => $script_name, |
218 |
approved => 0, # dummy value (also EXPR) |
218 |
approved => 0, # dummy value (also EXPR) |
219 |
tagloop => $tagloop, |
219 |
tagloop => $tagloop, |
220 |
pagination_bar => pagination_bar( |
220 |
pagination_bar => pagination_bar( |
221 |
"$script_name?$qstring\&", |
221 |
"$script_name?$qstring\&", |
222 |
ceil($counts->{approved_total}/$pagesize), # $page, 'page' |
222 |
ceil($counts->{approved_total}/$pagesize), # $page, 'page' |
223 |
) |
223 |
) |
224 |
); |
224 |
); |
225 |
|
225 |
|
226 |
output_html_with_http_headers $input, $cookie, $template->output; |
226 |
output_html_with_http_headers $input, $cookie, $template->output; |
227 |
- |
|
|