lib/CGI/OptimalQuery/InteractiveQuery.pm

filter: Statementstmt 100% 12 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 16 / 16 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/CGI/OptimalQuery/InteractiveFilter2.pm ↑ Summary lib/CGI/OptimalQuery/InteractiveQuery2.pm »
1 package CGI::OptimalQuery::InteractiveQuery;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶no warnings qw( uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'CGI::OptimalQuery::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub new {
9 my $pack = shift;
10 my $o = $pack->SUPER::new(@_);
11  
12 $$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowWidth} ||= 800;
13 $$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowHeight} ||= 600;
14  
15 return $o;
16 }
17  
18  
19  
20  
21 sub get_defaultCSS {
22 return <<TILEND;
23  
24 #OQinfo tr td { border: 1px solid #efefef; }
25 #OQinfo tr td.OQinfoName { border: 1px solid #666666; }
26  
27 #OQdataLHead {
28 background-color: #efefef;
29 }
30  
31 td.OQinfoName {
32 width: 1%;
33 font-size: 13px;
34 }
35  
36 .OQinfoVal {
37 background-color: white !important;
38 font-size: 13px;
39 }
40  
41 #OQtitle {
42 width: 40%;
43 padding-left: 10px !important;
44 }
45  
46 #OQhead td {
47 padding: 4px !important;
48 }
49  
50 /* workaround: too bad 'text-align: center' does not work */
51 table.OQpager {
52 margin-left: auto;
53 margin-right: auto;
54 }
55  
56 .OQcolHeadTitle {
57 font-size: 1.1em;
58 color: black;
59 font-weight: bold;
60 }
61  
62 #OQdata tr td {
63 border-right: 1px solid #efefef;
64 }
65  
66 #OQhead, #OQinfo, #OQdata {
67 width: 100%;
68 }
69  
70  
71 #OQdoc td {
72 padding: 2px 5px 2px 5px;
73 }
74  
75  
76 #OQhead {
77 background-color: #666666;
78 }
79  
80 #OQhead td {
81 color: white;
82 padding: 0px;
83 }
84  
85 #OQdoc button {
86 cursor: pointer;
87 background-color: #dddddd;
88 border: 1px outset #333333;
89 font-size: .8em;
90 color: #111111;
91 padding: 0px;
92 }
93  
94 #OQsummary {
95 width: 30%
96 }
97  
98 #OQcmds button {
99 margin-right: 2px;
100 }
101  
102 div.OQcolCmds button {
103 font-size: 10px;
104 }
105 div.OQcolCmds button {
106 margin-right: 1px;
107 }
108 div.OQcolCmds select {
109 margin-top: 3px;
110 }
111  
112 #OQinfo {
113 background-color: #cccccc;
114 }
115  
116 tr.OQdataRowTypeEven {
117 background-color: white;
118 }
119  
120 tr.OQdataRowTypeOdd {
121 background-color: #cccccc;
122 }
123  
124 td.OQdataRCol {
125 width: 1%;
126 }
127  
128 #OQcmds {
129 text-align: right;
130 }
131  
132 td.OQdataLCol { width: 1%; }
133 tr.OQupdatedRow { background-color: #ffdddd }
134  
135 td.OQcolHeader { white-space: nowrap }
136  
137 .OQaddColButton, .OQsortAscButton, .OQsortDescButton, .OQfilterCol, .OQcloseButton{
138 width: 15px; height: 16px; margin: 0; margin-right: 8px !important; padding: 0;
139 border: 0 !important; text-indent: -1000em;
140 }
141  
142 .OQaddColButton { background: transparent url(/OptimalQuery/add.gif) no-repeat center top; }
143 .OQsortAscButton { background: transparent url(/OptimalQuery/sortDown.gif) no-repeat center top; }
144 .OQsortDescButton { background: transparent url(/OptimalQuery/sortUp.gif) no-repeat center top; }
145 .OQfilterCol { background: transparent url(/OptimalQuery/filter.gif) no-repeat center top; }
146 .OQcloseButton { background: transparent url(/OptimalQuery/close.gif) no-repeat center top; }
147  
148 #cmdOptions {
149 margin-top: 10px;
150 position: absolute;
151 width: 20em;
152 height: 16em;
153 right: 20px;
154 background-color: #efefef;
155 border: 4px groove #666666;
156 padding-right: 8px;
157 padding-left: 8px;
158 padding-bottom: 8px;
159 font-size: .8em;
160 color: #444444;
161 overflow: auto;
162 display: none;
163 }
164  
165 #cmdOptions button.closeButton {
166 position: absolute;
167 right: 0;
168 color: black;
169 font-weight: bold;
170 padding: 0px;
171 margin: 0px;
172 background-color: white;
173 border: 1px outset black;
174 text-align: center;
175 vertical-align: middle;
176 cursor: pointer;
177 font-size: .8em;
178 }
179  
180 #cmdOptions h1 {
181 color: #222222;
182 margin: 0px;
183 font-size: 1.2em;
184 padding: 0;
185 }
186  
187 #cmdOptions span.note {
188 font-size: .7em;
189 }
190  
191 #OQdata { border-bottom: 1px solid #666666; }
192  
193 #OQkey button { margin-left: 10px; }
194  
195 TILEND
196 }
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213 sub can_embed { 1 }
214  
215 sub getPager {
216 my $o = shift;
217  
218 my $doc = "
219 <center>
220 <table class='OQpager'>
221 <tr>
222 <td>";
223 # print previous page button if user is not on first page
224 $doc .= "<button type='button' class='OQprevPageButton' onclick=\"OQval('page', ".
225 ($o->get_current_page() - 1)."); OQrefresh();\">previous</button>"
226 if $o->get_current_page() > 1;
227  
228 $doc .= "</td>
229 <td>
230 <select class='OQrowsPagePicker' onchange=\"OQval('rows_page',this.options[this.selectedIndex].value); OQrefresh();\">";
231  
232 # print results per page picker
233 foreach my $p (@{ $$o{schema}{results_per_page_picker_nums} }) {
234 next if $p ne 'All' && $p > $o->get_count();
235 $doc .= "<option value='$p'";
236 $doc .= " selected='selected'" if $p eq $o->get_rows_page();
237 $doc .= ">View $p results";
238 $doc .= " per page" if $p !~ /all/i;
239 $doc .= "</option>";
240 }
241 $doc .= "</select></td>
242  
243 <td>Page (";
244 # print current page picker
245 if ($o->get_num_pages() <= 1) {
246 $doc .= $o->get_num_pages();
247 } else {
248 $doc .= "<select class='OQpagePicker' onchange=\"OQval('page',this.options[this.selectedIndex].value); OQrefresh();\">\n";
249  
250 # only show page markers for pages 1 - 10,
251 # 5 pages before current page, 5 pages after current page, and last 10 pages
252 my @page_markers_to_show = sort { $a <=> $b } (
253 (1 .. 10),
254 (($$o{page} - 5) .. ($$o{page} + 5)),
255 (($o->get_num_pages() - 10) .. $o->get_num_pages() ) );
256 my $lastP;
257 foreach my $p (@page_markers_to_show) {
258 next if $p < 1 || $p == $lastP || $p > $o->get_num_pages();
259 $doc .= "<option value='$p'";
260 $doc .= " selected='selected'" if $p == $$o{page};
261 $doc .= ">".$o->commify($p);
262 $doc .= "</option>";
263 $lastP = $p;
264 }
265 $doc .= "</select>\n";
266 }
267  
268 $doc .= " of ".$o->commify($o->get_num_pages).")</td><td>\n";
269  
270 # print previous page button if user is not on last page
271 $doc .= "<button type='button' class='OQnextPageButton' onclick=\"OQval('page', ".($$o{page} + 1).")
272 ; OQrefresh();\">next</button>" if $$o{page} < $o->get_num_pages();
273 $doc .= "</td>
274 </tr>
275 </table>
276 </center>";
277  
278 return $doc;
279 }
280  
281  
282 sub output {
283 my $o = shift;
284 my $current_pack = __PACKAGE__;
285 my %opts;
286 %opts = %{ $$o{schema}{options}{$current_pack} } if exists $$o{schema}{options}{$current_pack};
287  
288 if (! exists $opts{httpHeader}) {
289 $opts{httpHeader} = $$o{httpHeader}->('text/html');
290 }
291  
292 my $inlineCSS = "\n<style type='text/css' id='OQstyle'>";
293 if (! exists $opts{htmlHeader}) {
294 my $title = $opts{title} || 'OptimalQuery Report';
295 $opts{htmlHeader} = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
296 <html>
297 <head>
298 <title>".$o->escape_html($title)."</title>
299 </head>
300 <body style=\"margin: 0; background-color: white;\">";
301 $inlineCSS .= ($opts{replaceCSS} || get_defaultCSS());
302 $inlineCSS .= $opts{appendCSS} if exists $opts{appendCSS};
303  
304 # replace default title bar color if color is defined
305 if (exists $opts{color}) {
306 my $color = $opts{color};
307 $inlineCSS =~ s/(\#OQhead \s* \{ (?# find OQhead selector)
308 [^}]*? (?# read past rules before background-color)
309 background\-color\:\s*) (?# find background-color rule)
310 .*\; (?# old defined color)
311 /$1$opts{color};/x;
312 }
313  
314 # replace url(/OptimalQuery/ with custom resourceURI if it exists
315 if (exists $$o{schema}{resourceURI}) {
316 $$o{schema}{resourceURI} =~ s/\/$//;
317 $inlineCSS =~ s/(?<=\burl\() (?# match before)
318 .*? (?# stuff to replace)
319 (?=\/\w+\.gif) (?# match after)
320 /$$o{schema}{resourceURI}/xg;
321 }
322 }
323 $inlineCSS .= "#OQfilter { display: none; }\n" if $$o{filter} eq '';
324 $inlineCSS .= "#OQsort { display: none; }\n" if $$o{sort} eq '';
325 $inlineCSS .= "#OQqueryDescr { display: none; }\n" if $$o{queryDescr} eq '';
326 $inlineCSS .= "\n</style>\n";
327 if (!($opts{htmlHeader} =~ s/(<\/head>)/$inlineCSS$1/i)) {
328 $opts{htmlHeader} .= $inlineCSS;
329 }
330  
331 $opts{htmlFooter} = "</body>\n</html>\n"
332 unless exists $opts{htmlFooter};
333  
334 # eval if code ref
335 foreach my $key (qw( OQdocTop OQdocBottom OQformTop OQformBottom )) {
336 $opts{$key} = $opts{$key}->() if ref($opts{$key}) eq 'CODE';
337 }
338  
339 $opts{OQdocTop} ||= '';
340 $opts{OQdocBottom} ||= '';
341 $opts{OQformTop} ||= '';
342 $opts{OQformBottom} ||= '';
343 $opts{editButtonLabel} ||= 'edit';
344 $opts{disable_sort} ||= 0;
345 $opts{disable_filter} ||= 0;
346 $opts{disable_select} ||= 0;
347 $opts{mutateRecord} ||= undef;
348 $opts{noEscapeCol} ||= [];
349 $opts{editLink} ||= undef;
350  
351 # carry hidden state params
352 my $state_params = '';
353 if (ref($$o{schema}{state_params}) eq 'ARRAY') {
354 foreach my $p (@{ $$o{schema}{state_params} }) {
355 $state_params .= ";$p=".$o->escape_uri($o->{q}->param($p));
356 }
357 }
358 $state_params .= ';' if $state_params;
359  
360  
361  
362 my $doc = $opts{httpHeader}.$opts{htmlHeader}."
363 <div id='OQdoc'>
364 <div id='OQdocTop'>$opts{OQdocTop}</div>
365  
366 <form id='OQform' name='OQform' action='".$$o{schema}{URI}."#OQtop' method='post'>
367 <input type='hidden' name='act' value='' />
368 <input type='hidden' name='view' value='' />
369  
370 <script type='text/javascript' id='OQscript'>
371  
372 // code to open debug mode when ALT-Q is typed
373 var last_key;
374 if (window.document.getElementById) document.onkeyup = KeyCheck;
375 function KeyCheck(e) {
376 var KeyID = (window.event) ? event.keyCode : e.keyCode;
377 if (last_key == 18 && KeyID == 81) {
378 if (window.document.getElementById &&
379 window.document.getElementById('OQstateVars') &&
380 window.document.getElementById('OQstateVars').style ) {
381 var d = window.document.getElementById('OQstateVars').style.display;
382 d = (d == 'none') ? '' : 'none';
383 window.document.getElementById('OQstateVars').style.display = d;
384 }
385 }
386 else { last_key = KeyID; }
387 return true;
388 }
389  
390  
391  
392 var OQdefaultModule = 'InteractiveQuery';
393 function OQval(name, newVal) {
394 if (document.OQform.elements[name]) {
395 var elem = document.OQform.elements[name];
396 if (newVal != null) elem.value = newVal;
397 return elem.value;
398 }
399 }
400 function OQvals(name, newVals) {
401 if (document.OQform.elements[name]) {
402 var elem = document.OQform.elements[name];
403 if (newVals != null) elem.value = newVals.join(',');
404 if (elem.value == '') return new Array();
405 else return elem.value.split(',');
406 }
407 }
408  
409 function OQrefresh(updated_uid) {
410 var f = document.OQform;
411 f.target = '';
412 f.module.value = OQdefaultModule;
413 f.act.value = '';
414 f.view.value = '';
415  
416 if (updated_uid && f.on_select.value != '') {
417 funct_ref = eval('window.opener.'+f.on_select.value);
418 if (funct_ref) {
419 funct_ref(updated_uid);
420 window.opener.focus();
421 }
422 window.close();
423 }
424 else {
425 if (updated_uid) f.updated_uid.value = updated_uid;
426 f.action = '$$o{schema}{URI}#OQtop';
427 f.submit();
428 }
429 }
430  
431  
432 // special open window code (auto centers based on parent)
433 function OQopwin (lnk,target,opts,w,h) {
434  
435 if (! target) target = '_blank';
436 if (! opts) opts = 'resizable,scrollbars';
437 if (! w) w = $$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowWidth};
438 if (! h) h = $$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowHeight};
439  
440 if (window.screen) {
441 var s = window.screen;
442 var max_width = s.availWidth - 10;
443 var max_height = s.availHeight - 30;
444 if (opts.indexOf('toolbar',0) != -1) max_height -= 40;
445 if (opts.indexOf('menubar',0) != -1) max_height -= 35;
446 if (opts.indexOf('location',0) != -1)max_height -= 35;
447 var width = (w > max_width)?max_width:w;
448 var height = (h > max_height)?max_height:h;
449 var par_left_offset = (window.screenX == null)?0:window.screenX;
450 var par_top_offset = (window.screenY == null)?0:window.screenY;
451 var par_width;
452 if (window.outerWidth != null) {
453 par_width = window.outerWidth;
454 if (par_width < width)
455 par_left_offset -= parseInt((width - par_width)/2);
456 } else
457 par_width = max_width;
458  
459 var par_height;
460 if (window.outerHeight != null) {
461 par_height = window.outerHeight;
462 if (par_height < height) {
463 par_top_offset -= parseInt((height - par_height)/2);
464 }
465 } else
466 par_height = max_height;
467  
468 var left = parseInt(par_width /2 - width /2) + par_left_offset;
469 var top = parseInt(par_height/2 - height/2) + par_top_offset;
470  
471 var newopts = 'width='+width+',height='+height+',left='+left+',top='+top;
472 opts = (opts && opts != '')?newopts+','+opts:newopts;
473 }
474 var wndw = window.open(lnk,target,opts);
475 if (wndw.focus) wndw.focus();
476 return wndw;
477 }
478  
479 function hideCmdOptions() {
480 OQval('OQsaveSearchTitle','');
481 document.getElementById('cmdOptions').style.display = 'none';
482 document.getElementById('exportOptions').style.display = 'none';
483 document.getElementById('savedSearchesOptions').style.display = 'none';
484  
485 // hack for z-layer form input bug in IE
486 if (/MSIE\ 6/.test(navigator.userAgent))
487 document.getElementById('OQdata').style.visibility = 'visible';
488 }
489  
490 function toogleCmdOptions(id) {
491 if (document.getElementById(id).style.display == 'block') {
492 hideCmdOptions();
493 } else {
494 document.getElementById('exportOptions').style.display = 'none';
495 document.getElementById('savedSearchesOptions').style.display = 'none';
496  
497 if (/MSIE\ 6/.test(navigator.userAgent))
498 document.getElementById('OQdata').style.visibility = 'hidden';
499  
500 document.getElementById(id).style.display = 'block';
501 document.getElementById('cmdOptions').style.display = 'block';
502 }
503 }
504  
505  
506 </script><noscript>Javascript is required when viewing this page.</noscript>
507  
508 <table id='OQstateVars' style=\"display: none;\">
509 <tr>
510 <td>show</td>
511 <td><input type='text' name='show' value=\"".$o->escape_html(join(',',@{$$o{show}}))."\" /></td>
512 </tr>
513 <tr>
514 <td>filter</td>
515 <td><input type='text' name='filter' value=\"".$o->escape_html($$o{filter})."\" /></td>
516 </tr>
517 <tr>
518 <td>hiddenFilter</td>
519 <td><input type='text' name='hiddenFilter' value=\"".$o->escape_html($$o{hiddenFilter})."\" /></td>
520 </tr>
521 <tr>
522 <td>queryDescr</td>
523 <td><input type='text' name='queryDescr' value=\"".$o->escape_html($$o{queryDescr})."\" /></td>
524 </tr>
525 <tr>
526 <td>sort</td>
527 <td><input type='text' name='sort' value=\"".$o->escape_html($$o{sort})."\" /></td>
528 </tr>
529 <tr>
530 <td>page</td>
531 <td><input type='text' name='page' value=\"".$o->escape_html($$o{page})."\" /></td>
532 </tr>
533 <tr>
534 <td>module</td>
535 <td><input type='text' name='module' value=\"".$o->escape_html($$o{module})."\" /></td>
536 </tr>
537 <tr>
538 <td>rows_page</td>
539 <td><input type='text' name='rows_page' value=\"".$o->escape_html($$o{rows_page})."\" /></td>
540 </tr>
541 <tr>
542 <td>updated_uid</td>
543 <td><input type='text' name='updated_uid' value='' /></td>
544 </tr>
545 <tr>
546 <td>on_select</td>
547 <td><input type='text' name='on_select' value=\"".$o->escape_html($$o{q}->param('on_select'))."\" /></td>
548 </tr>";
549  
550 if (ref($$o{schema}{state_params}) eq 'ARRAY') {
551 foreach my $p (@{ $$o{schema}{state_params} }) {
552 $doc .= "<tr><td>$p</td><td><input type='text' name='$p' value='".$o->escape_html($o->{q}->param($p))."'></td></tr>";
553 }
554 }
555  
556 $doc .= "
557 <tr><td colspan=2><button type='reset'>reset</button> <button type=button onclick=\"this.form.method='GET';this.form.submit();\">submit</button></td></tr></table>
558  
559 <a name='OQtop'></a>
560  
561 <div id='OQupdatedUidInfo'>".
562 (($$o{q}->param('updated_uid') eq '')?"":
563 "UID: ".$o->escape_html($$o{q}->param('updated_uid'))." updated")."
564 </div>
565  
566  
567 <div id='OQformTop'>$opts{OQformTop}</div>
568  
569 <table id='OQhead'>
570 <tr>
571 <td id='OQtitle'>".$o->escape_html($o->get_title)."</td>
572 <td id='OQsummary'>Result(s) (".$o->commify($o->get_lo_rec)." - ".$o->commify($o->get_hi_rec).") of ".$o->commify($o->get_count)."</td>
573 <td id='OQcmds'>";
574  
575 if (ref($opts{buildNewLink}) eq 'CODE') {
576 my $link = $opts{buildNewLink}->($o, \%opts);
577 if ($link ne '') {
578 $doc .= "<button type='button' class='OQnewButton' onclick=\"OQopwin('$link','_blank','resizable,scrollbars',$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowWidth},$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowHeight});\">new</button>";
579 }
580 }
581 elsif (exists $opts{buildNewLink} && $opts{buildNewLink} eq '') {}
582 elsif ($opts{editLink} ne '') {
583 my $link = $opts{editLink}.(($opts{editLink} =~ /\?/)?'&':'?')."on_update=OQrefresh&act=new";
584 if ($link ne '') {
585 $doc .= "<button type='button' class='OQnewButton' onclick=\"OQopwin('$link','_blank','resizable,scrollbars',$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowWidth},$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowHeight});\">new</button>";
586 }
587 }
588  
589 $doc .= "<button type='button' class='OQrefreshButton' onclick=\"OQrefresh();\">refresh</button>";
590 $doc .= "<button type='button' onclick=\"toogleCmdOptions('savedSearchesOptions');
591 if (document.getElementById('savedSearchesOptions').style.display != 'none') this.form.OQsaveSearchTitle.focus();
592 \">saved searches</button>" if $$o{schema}{savedSearchUserID};
593 $doc .= "<button type='button' onclick=\"toogleCmdOptions('exportOptions');\">export</button>
594 </td>
595 </tr>
596 </table>
597  
598 <div id='cmdOptions'>
599 <button type='button' class='closeButton' onclick=\"hideCmdOptions();\" title='close'>&times;</button>
600  
601 <div id='exportOptions'>
602 <h1>select download file type</h1>
603 <input type='radio' name='exportModule' checked = 'checked'/>Printer Friendly
604 <br />
605 <input type='radio' name='exportModule' />CSV <span class='note'>comma separated values (use in Microsoft Excel)</span>
606 <br />
607 <input type='radio' name='exportModule' />XML ";
608  
609 if ($$o{rows_page} ne 'All') {
610 $doc .= " <br /> <input type='checkbox' name='exportAll' />export all results"
611 }
612 $doc .= "
613 <br />
614 <button type='button' onclick=\" hideCmdOptions(); var f = this.form; if (f.exportModule[0].checked) { f.module.value = 'PrinterFriendly'; f.target = '_blank'; } else if (f.exportModule[1].checked) f.module.value = 'CSV'; else if (f.exportModule[2].checked) f.module.value = 'XML'; if (f.exportAll &amp;&amp; f.exportAll.checked) { var tmp = f.rows_page.value; f.rows_page.value = 'All'; window.setTimeout('OQval(\\x27rows_page\\x27,\\x27' + tmp + '\\x27)', 1000); } f.action = '$$o{schema}{URI_standalone}'; f.submit(); \">download</button>
615 </div>
616  
617 <div id='savedSearchesOptions'>
618 ";
619  
620
621 # if saved searches are enabled ..
622 if ($$o{schema}{savedSearchUserID}) {
623 local $$o{dbh}->{LongReadLen};
624 $doc .= "
625 <h1>save search</h1>
626 name <input type=text name='OQsaveSearchTitle' value='' /><button type='button' title='save search' onclick=\"OQrefresh();\">save</button><br /> <br />";
627  
628 if ($$o{dbh}{Driver}{Name} eq 'Oracle') {
629 my ($readLen) = $$o{dbh}->selectrow_array("SELECT max(dbms_lob.getlength(params)) FROM oq_saved_search WHERE user_id = ?", undef, $$o{schema}{savedSearchUserID});
630 $$o{dbh}->{LongReadLen} = $readLen if $readLen > $$o{dbh}->{LongReadLen};
631 }
632  
633 my $sth = $$o{dbh}->prepare("
634 SELECT id, user_title, params
635 FROM oq_saved_search
636 WHERE user_id = ?
637 AND upper(uri) = upper(?)
638 AND oq_title = ?");
639 $sth->execute($$o{schema}{savedSearchUserID}, $$o{schema}{URI},$$o{schema}{title});
640  
641 my $buffer = '';
642 while (my ($id, $title, $params) = $sth->fetchrow_array()) {
643  
644 my $stateArgs = '';
645 if ($params ne '') {
646 $params = eval '{'.$params.'}';
647 if (ref($params) eq 'HASH') {
648 delete $$params{show};
649 delete $$params{rows_page};
650 delete $$params{page};
651 delete $$params{hiddenFilter};
652 delete $$params{filter};
653 delete $$params{queryDescr};
654 delete $$params{sort};
655 while (my ($k,$v) = each %$params) {
656 $stateArgs .= "&amp;$k=";
657 $stateArgs .= (ref($v) eq 'ARRAY') ?
658 CGI::escape($$v[0]) : CGI::escape($v);
659 }
660 }
661 }
662  
663 $buffer .= "<a href=# onclick=\"window.location='$$o{schema}{URI}?OQLoadSavedSearch=$id".$stateArgs."#OQtop';\">".$o->escape_html($title)."</a><br />";
664 }
665 $doc .= "<h1>load search</h1>$buffer" if $buffer;
666 }
667  
668 $doc .= "
669 </div>
670 </div>
671 <table id='OQinfo' style=\"border-bottom: 1px solid #666666;\">";
672  
673 if (!( $opts{disable_select} && $opts{disable_sort} && $opts{disable_filter} )) {
674 $doc .= "
675 <tr id='OQkey'><td class='OQinfoName'>Key:</td>
676 <td class='OQinfoVal'>";
677  
678 $doc .= "<button class='OQaddColButton' type='button'>add column</button>add column"
679 unless $opts{disable_select};
680  
681 $doc .= "<button class='OQsortAscButton' type='button'>sort</button>sort
682 <button class='OQsortDescButton'>reverse sort</button>reverse sort"
683 unless $opts{disable_sort};
684  
685 $doc .= "<button class='OQfilterCol' type='button'>filter column</button>filter column"
686 unless $opts{disable_filter};
687  
688 $doc .= "<button class='OQcloseButton' type='button'>close column</button>close column"
689 unless $opts{disable_select};
690 $doc .= "</td></tr>";
691 }
692 $doc .= "
693 <tr id='OQqueryDescr'><td class='OQinfoName'>Query:</td><td class='OQinfoVal'>".$o->escape_html($$o{queryDescr})."</td></tr>
694 <tr id='OQfilter'><td class='OQinfoName'>Filter:</td><td class='OQinfoVal'>".$o->escape_html($o->get_filter());
695  
696 $doc .= "<button class='OQfilterCol' title='filter query' type=\"button\" onclick=\"OQopwin('$$o{schema}{URI_standalone}?module=InteractiveFilter;".$state_params."filter='+escape(OQval('filter')),'filter','resizable,scrollbars',760,300);\">filter</button>" unless $opts{disable_filter};
697  
698 $doc .=
699 "</td></tr>
700 <tr id='OQsort'><td class='OQinfoName'>Sort:</td><td class='OQinfoVal'>";
701  
702 my @sort = $o->sth->sort_descr();
703 if (@sort) {
704 # create new sort description
705 my @buffer;
706 for (my $i=0; $i < @sort; $i++) {
707 my $buf = '';
708 $buf .= "<a href='#' title='remove sort' onclick=\"var sort=OQvals('sort');sort.splice($i,1);OQvals('sort',sort);OQrefresh(); return false;\">" unless $opts{disable_sort};
709 $buf .= $o->escape_html($sort[$i]);
710 $buf .= "</a>" unless $opts{disable_sort};
711 push @buffer, $buf;
712 }
713 $doc .= join(', ',@buffer);
714 }
715  
716 $doc .= "</td></tr>
717 </table>
718  
719 <table id='OQdata'>
720 <thead>
721 <tr>
722  
723 <td id='OQdataLHead'>
724 </td>";
725  
726  
727  
728  
729 foreach my $i (0 .. ($o->get_num_usersel_cols() - 1)) {
730 my $colAlias = $o->get_usersel_cols->[$i];
731 $doc .= "<td class='OQcolHeader'><div class='OQcolCmds'>
732 <!-- the following line is necessary for IE browsers otherwise buttons won't display -->
733 <span style='visibility: hidden;'>.</span>
734 ";
735  
736 if (! ($$o{schema}{select}{$colAlias}[3]{disable_select} || $opts{disable_select})) {
737 $doc .= "<button type='button' class='OQaddColButton' title='add column' onclick=\"var show=OQvals('show');show.splice($i,0,'$colAlias');OQvals('show',show);OQrefresh();\">add</button>";
738 }
739 if (! ($$o{schema}{select}{$colAlias}[3]{disable_sort} || $opts{disable_sort}) ) {
740 $doc .= "<button type='button' title='sort' class='OQsortAscButton' onclick=\"var sort=OQvals('sort');sort.push('[$colAlias]'); OQvals('sort',sort);OQrefresh();\">sort</button>
741 <button type='button' title='reverse sort' class='OQsortDescButton' onclick=\"var sort=OQvals('sort');sort.push('[$colAlias] DESC');OQvals('sort',sort);OQrefresh();\">reverse sort</button>";
742 }
743 if (! ($$o{schema}{select}{$colAlias}[3]{disable_filter} || $opts{disable_filter}) ) {
744 $doc .= "<button type='button' title='filter column' class='OQfilterCol' onclick=\"OQopwin('$$o{schema}{URI_standalone}?module=InteractiveFilter;".$state_params."filter='+escape(OQval('filter'))+';NEXT_EXPR='+escape('$colAlias'),'filter','resizable,scrollbars',760,300);\">filter</button>";
745 }
746 if (! ($$o{schema}{select}{$colAlias}[3]{disable_select} || $opts{disable_select})) {
747 $doc .= "<button type='button' title='close column' class='OQcloseButton' onclick=\"var show=OQvals('show');show.splice($i,1);OQvals('show',show);OQrefresh();\">close</button><br />";
748 }
749  
750 if ($$o{schema}{select}{$colAlias}[3]{disable_select} || $opts{'disable_select'}) {
751 $doc .= "<div class='OQcolHeadTitle'>".$o->escape_html($$o{schema}{select}{$colAlias}[2])."</div>";
752 }
753  
754 else {
755 $doc .= "<select class='OQcolSelect' title='select a different column to view' onchange=\"var show=OQvals('show');show.splice($i,1,this.options[this.selectedIndex].value);OQvals('show',show);OQrefresh();\">";
756  
757 # create possible cols to select
758 my $s = $$o{schema}{select};
759  
760 foreach my $col (sort { uc($s->{$a}->[2]) cmp uc($s->{$b}->[2]) } keys %{$$o{schema}{select}}) {
761 my $col_opts = $s->{$col}->[3] || {};
762 next if $col_opts->{'is_hidden'} || ! $$s{$col}[2];
763 my $nice = $o->get_nice_name($col);
764  
765 $doc .= "<option value='".$o->escape_html($col)."'";
766 $doc .= " selected='selected'" if ($o->{'show'}->[$i] eq $col);
767 $doc .= ">".$o->escape_html($nice)."</option>";
768 }
769 $doc .= "</select>";
770 }
771  
772 $doc .= "</div></td>";
773 }
774  
775 $doc .= "
776 <td id='OQdataRHead'></td>
777 </tr>
778 </thead>
779  
780 <tfoot id='OQdataFoot'>
781 </tfoot>
782  
783 <tbody>";
784  
785 # print data
786 my $rowType = 'Odd';
787  
788 my %noEsc = map { $_ => 1 } @{ $opts{noEscapeCol} };
789  
790 my $recs_in_buffer = 0;
791 while (my $r = $o->sth->fetchrow_hashref()) {
792 $opts{mutateRecord}->($r) if ref($opts{mutateRecord}) eq 'CODE';
793 $$o{schema}{mutateRecord}->($r) if ref($$o{schema}{mutateRecord}) eq 'CODE';
794  
795 my $class = "OQdataRowType$rowType";
796 $class .= " OQupdatedRow"
797 if $$r{U_ID} ne '' && $$r{U_ID} eq $$o{q}->param('updated_uid');
798  
799 $doc .= "<tr class='$class'>\n<td class='OQdataLCol'>";
800 if (ref($opts{OQdataLCol}) eq 'CODE') { $doc .= $opts{OQdataLCol}->($r); }
801 elsif (ref($opts{buildEditLink}) eq 'CODE') {
802 my $link = $opts{buildEditLink}->($o, $r, \%opts);
803 if ($link ne '') {
804 $doc .= "<button type='button' class='OQeditButton' onclick=\"OQopwin('$link','_blank','resizable,scrollbars',$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowWidth},$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowHeight});\">$opts{editButtonLabel}</button>";
805 }
806 } elsif ($opts{editLink} ne '' && $$r{U_ID} ne '') {
807 my $link = $opts{editLink}.(($opts{editLink} =~ /\?/)?'&':'?')."on_update=OQrefresh&act=load&id=$$r{U_ID}";
808 $doc .= "<button type='button' class='OQeditButton' onclick=\"OQopwin('$link','_blank','resizable,scrollbars',$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowWidth},$$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowHeight});\">$opts{editButtonLabel}</button>";
809 }
810 $doc .= "\n</td>";
811  
812 # print table cell with value
813 foreach my $col (@{ $o->get_usersel_cols }) {
814 my $val;
815 if (exists $noEsc{$col}) {
816 $val = $$r{$col};
817 } else {
818 if (ref($$r{$col}) eq 'ARRAY') {
819 $val = join(', ', map { $o->escape_html($_) } @{ $$r{$col} });
820 } else {
821 $val = $o->escape_html($$r{$col});
822 }
823 }
824 $doc .= "<td class='OQcolData OQselect-$col'>$val</td>\n";
825 }
826  
827 # still need to add code for on_select functionality
828 $doc .= "<td class='OQdataRCol'>\n";
829  
830 if (ref($opts{OQdataRCol}) eq 'CODE') { $doc .= $opts{OQdataRCol}->($r); }
831 elsif ($o->{q}->param('on_select') ne '' && $$r{U_ID} ne '') {
832 my $on_select = $o->{q}->param('on_select');
833 $doc .= "<button type='button' onclick=\"if (window.opener &amp;&amp; window.opener.$on_select) window.opener.$on_select('$$r{U_ID}'); window.close();\">select</button>";
834 }
835  
836 $doc .= "\n</td>\n</tr>\n\n";
837  
838 $rowType = ($rowType eq "Odd") ? "Even" : "Odd";
839  
840 $recs_in_buffer++;
841 if ($recs_in_buffer == 20) { $$o{output_handler}->($doc); $doc = ''; $recs_in_buffer = 0; }
842 }
843 $o->sth->finish();
844  
845 $doc .= "
846 </tbody>
847 </table>";
848  
849 $doc .= $o->getPager();
850  
851 $doc .= "
852 <div id='OQformBottom'>".$opts{OQformBottom}."</div>
853 </form>
854  
855 <script type='text/javascript'>
856 $opts{OQscript}
857 document.OQform.reset();
858 </script><noscript>Javascript is required when viewing this page.</noscript>
859  
860 <div id='OQdocBottom'></div>
861 </div>
862 $opts{htmlFooter}";
863  
864 $$o{output_handler}->($doc);
865 return undef;
866 }
867  
868 1;
« lib/CGI/OptimalQuery/InteractiveFilter2.pm ↑ Summary lib/CGI/OptimalQuery/InteractiveQuery2.pm »