line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::OptimalQuery::LoadSearchTool; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
3
|
use JSON::XS(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
5
|
1
|
|
|
1
|
|
2
|
use CGI qw(escapeHTML); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub load_saved_search { |
9
|
0
|
|
|
0
|
0
|
|
my ($o, $id) = @_; |
10
|
0
|
|
|
|
|
|
local $$o{dbh}{LongReadLen}; |
11
|
0
|
0
|
|
|
|
|
if ($$o{dbh}{Driver}{Name} eq 'Oracle') { |
12
|
0
|
|
|
|
|
|
$$o{dbh}{LongReadLen} = 900000; |
13
|
0
|
|
|
|
|
|
my ($readLen) = $$o{dbh}->selectrow_array("SELECT dbms_lob.getlength(params) FROM oq_saved_search WHERE id = ?", undef, $id); |
14
|
0
|
0
|
|
|
|
|
$$o{dbh}{LongReadLen} = $readLen if $readLen > $$o{dbh}{LongReadLen}; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
my ($params) = $$o{dbh}->selectrow_array( |
17
|
0
|
|
|
|
|
|
"SELECT params FROM oq_saved_search WHERE id=?", undef, $id); |
18
|
0
|
0
|
|
|
|
|
if ($params) { |
19
|
0
|
|
|
|
|
|
$params = eval '{'.$params.'}'; |
20
|
0
|
0
|
|
|
|
|
if (ref($params) eq 'HASH') { |
21
|
0
|
|
|
|
|
|
delete $$params{module}; |
22
|
0
|
|
|
|
|
|
while (my ($k,$v) = each %$params) { |
23
|
0
|
|
|
|
|
|
$$o{q}->param( -name => $k, -values => $v ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
# remember saved search ID |
27
|
0
|
|
|
|
|
|
$$o{q}->param('OQss', $id); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
return undef; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub on_init { |
33
|
0
|
|
|
0
|
0
|
|
my ($o) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# request to delete a saved search |
36
|
0
|
0
|
0
|
|
|
|
if ($$o{q}->param('OQdeleteSavedSearch') =~ /^\d+$/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $id = $$o{q}->param('OQdeleteSavedSearch'); |
38
|
0
|
|
|
|
|
|
$$o{dbh}->do("DELETE FROM oq_saved_search WHERE user_id=? AND id=?", undef, $$o{schema}{savedSearchUserID}, $id); |
39
|
0
|
|
|
|
|
|
$$o{output_handler}->(CGI::header('text/html')."report deleted"); |
40
|
0
|
|
|
|
|
|
return undef; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# request to load a saved search? |
44
|
|
|
|
|
|
|
elsif ($$o{q}->param('OQLoadSavedSearch') =~ /^\d+$/) { |
45
|
0
|
|
|
|
|
|
load_saved_search($o, $$o{q}->param('OQLoadSavedSearch')); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# else if default saved searches are enabled and this isn't intial load, load default saved search if it exists |
49
|
|
|
|
|
|
|
elsif (exists $$o{schema}{canSaveDefaultSearches} && ! defined $$o{q}->param('filter')) { |
50
|
|
|
|
|
|
|
my ($id) = $$o{dbh}->selectrow_array(" |
51
|
|
|
|
|
|
|
SELECT id |
52
|
|
|
|
|
|
|
FROM oq_saved_search |
53
|
|
|
|
|
|
|
WHERE is_default=1 |
54
|
|
|
|
|
|
|
AND uri=? |
55
|
0
|
|
|
|
|
|
LIMIT 1", undef, $$o{schema}{URI}); |
56
|
0
|
0
|
|
|
|
|
load_saved_search($o, $id) if $id; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub on_open { |
61
|
0
|
|
|
0
|
0
|
|
my ($o) = @_; |
62
|
|
|
|
|
|
|
my $ar = $$o{dbh}->selectall_arrayref(" |
63
|
|
|
|
|
|
|
SELECT id, uri, user_title |
64
|
|
|
|
|
|
|
FROM oq_saved_search |
65
|
|
|
|
|
|
|
WHERE user_id = ? |
66
|
|
|
|
|
|
|
AND upper(uri) = upper(?) |
67
|
|
|
|
|
|
|
AND oq_title = ? |
68
|
|
|
|
|
|
|
ORDER BY 2", undef, $$o{schema}{savedSearchUserID}, |
69
|
0
|
|
|
|
|
|
$$o{schema}{URI}, $$o{schema}{title}); |
70
|
0
|
|
|
|
|
|
my $buf; |
71
|
|
|
|
|
|
|
# must include state params because server code may not run without them defined |
72
|
|
|
|
|
|
|
my $args; |
73
|
0
|
0
|
|
|
|
|
if ($$o{schema}{state_params}) { |
74
|
0
|
|
|
|
|
|
my @args; |
75
|
0
|
|
|
|
|
|
foreach my $p (@{ $$o{schema}{state_params} }) { |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $v = $$o{q}->param($p); |
77
|
0
|
0
|
|
|
|
|
push @args, "$p=".$o->escape_uri($v) if $v; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
0
|
|
|
|
|
$args = '&'.join('&', @args) if $#args > -1; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
foreach my $x (@$ar) { |
82
|
0
|
|
|
|
|
|
my ($id, $uri, $user_title) = @$x; |
83
|
0
|
|
|
|
|
|
$buf .= " |
".escapeHTML($user_title)." | |
";
84
|
|
|
|
|
|
|
} |
85
|
0
|
0
|
|
|
|
|
if (! $buf) { |
86
|
0
|
|
|
|
|
|
$buf = "none"; |
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
|
$buf = ""; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
return $buf; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub activate { |
94
|
0
|
|
|
0
|
0
|
|
my ($o) = @_; |
95
|
|
|
|
|
|
|
$$o{schema}{tools}{loadreport} ||= { |
96
|
0
|
|
0
|
|
|
|
title => "Load Report", |
97
|
|
|
|
|
|
|
on_init => \&on_init, |
98
|
|
|
|
|
|
|
on_open => \&on_open |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |