blib/lib/CGI/OptimalQuery/SavedSearches.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 101 CC 13 SCAR 39.8
CC
13
Cov
0%
process_request
90.0
get_html
30.0
BEGIN
2.0
CRAP 53.8
1 package CGI::OptimalQuery::SavedSearches;
2  
3 use strict;
4 use warnings;
5 no warnings qw( uninitialized );
6 use CGI qw( escapeHTML );
7  
8 sub process_request {
9 my ($q,$dbh,$userid,$selfurl) = @_;
10  
11 if ($q->param('load') =~ /^(\d+)$/) {
12 my $id = $1;
13 my $oracleReadLen;
14 if ($$dbh{Driver}{Name} eq 'Oracle') {
15 ($oracleReadLen) = $dbh->selectrow_array("SELECT max(dbms_lob.getlength(params)) FROM oq_saved_search WHERE user_id = ?", undef, $userid);
16 }
17 local $dbh->{LongReadLen} = $oracleReadLen
18 if $oracleReadLen && $oracleReadLen > $dbh->{LongReadLen};
19  
20 my $sth = $dbh->prepare("SELECT uri, params FROM oq_saved_search WHERE id=? AND user_id = ?");
21 $sth->execute($id, $userid);
22 my ($uri, $params) = $sth->fetchrow_array();
23  
24 if (! $uri) {
25 print CGI::header("text/plain"), "saved search not found";
26 return undef;
27 } else {
28 my $stateArgs = '';
29 if ($params ne '') {
30 $params = eval '{'.$params.'}';
31 $$params{module} = 'InteractiveQuery2';
32 if (ref($params) eq 'HASH') {
33 delete $$params{show};
34 delete $$params{rows_page};
35 delete $$params{page};
36 delete $$params{hiddenFilter};
37 delete $$params{filter};
38 delete $$params{queryDescr};
39 delete $$params{sort};
40 while (my ($k,$v) = each %$params) {
41 $stateArgs .= "&$k=";
42 $stateArgs .= (ref($v) eq 'ARRAY') ? CGI::escape($$v[0]) : CGI::escape($v);
43 }
44 }
45 }
46 print CGI::redirect("$uri?OQLoadSavedSearch=".$id.$stateArgs);
47 return undef;
48 }
49 }
50  
51 elsif ($q->param('delete') =~ /^(\d+)$/) {
52 my $id = $1;
53 $dbh->do("DELETE FROM oq_saved_search WHERE id=? AND user_id=?", undef, $id, $userid);
54 print CGI::header('text/plain'), "OK";
55 return undef;
56 }
57  
58 else {
59 print CGI::header('text/plain'), get_html($q,$dbh,$userid,$selfurl);
60 return undef;
61 }
62  
63 return undef;
64 }
65  
66 sub get_html {
67 my ($q,$dbh,$userid,$selfurl) = @_;
68 my $sth = $dbh->prepare(
69 "SELECT id, oq_title, user_title
70 FROM oq_saved_search
71 WHERE user_id=?
72 ORDER BY oq_title, user_title");
73 $sth->execute($userid);
74 my $last_oq_title = '';
75 my $buf = '';
76 while (my ($id, $oq_title, $user_title) = $sth->fetchrow_array()) {
77 if ($last_oq_title ne $oq_title) {
78 $buf .= '</ul>' if $last_oq_title;
79 $last_oq_title = $oq_title;
80 $buf .= "<h4>".escapeHTML($oq_title)."</h4><ul>";
81 }
82 $buf .= "<li>
83 <a href=$selfurl?load=$id title='load saved search' class=oqssload>".escapeHTML($user_title)."</a>
84 <a href=# title='delete saved search' class=oqssdelete data-id='$id'>delete</a>
85 </li>";
86 }
87 $buf .= '</ul>' if $last_oq_title;
88  
89 if ($buf) {
90 $buf = '<div id=loadsavedsearches>'.$buf.'</div>
91 <script>
92 $("#loadsavedsearches").delegate("a.oqssdelete","click",function(){
93 var $t = $(this);
94 var $li = $t.closest("li");
95 $.ajax({
96 type: "post",
97 url: "'.$selfurl.'",
98 data: { "delete": $t.attr("data-id") },
99 success: function() {
100 if ($li.siblings().length==0) {
101 var $ul = $li.parent();
102 $ul.add($ul.prev("h4")).remove();
103 }
104 else {
105 $li.remove();
106 }
107 }
108 });
109 return false;
110 });
111 </script><noscript>Javascript is required when viewing this page. For more information see the <a href=accessibility.html>UNHCEMS&reg; Accessibility</a> page.</noscript>
112 ';
113 }
114 return $buf;
115 }
116 1;