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

filter: Statementstmt 0.0% 0 / 247 Branchbran 0.0% 0 / 138 Conditioncond 0.0% 0 / 78 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 477 CC 70 SCAR 80.4
CC
70
Cov
0%
output
3906.0
getPager
90.0
new
2.0
CRAP 3115.3
1 package CGI::OptimalQuery::InteractiveQuery;
2  
3 use strict;
4 use warnings;
5 no warnings qw( uninitialized );
6 use base 'CGI::OptimalQuery::Base';
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 = %{ $$o{schema}{options}{$current_pack} } if exists $$o{schema}{options}{$current_pack};
286  
287 $opts{httpHeader} = $$o{q}->header('text/html') if ! exists $opts{httpHeader};
288  
289  
290 my $inlineCSS = "\n<style type='text/css' id='OQstyle'>";
291 if (! exists $opts{htmlHeader}) {
292 my $title = $opts{title} || 'OptimalQuery Report';
293 $opts{htmlHeader} = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
294 <html>
295 <head>
296 <title>".$o->escape_html($title)."</title>
297 </head>
298 <body style=\"margin: 0; background-color: white;\">";
299 $inlineCSS .= ($opts{replaceCSS} || get_defaultCSS());
300 $inlineCSS .= $opts{appendCSS} if exists $opts{appendCSS};
301  
302 # replace default title bar color if color is defined
303 if (exists $opts{color}) {
304 my $color = $opts{color};
305 $inlineCSS =~ s/(\#OQhead \s* \{ (?# find OQhead selector)
306 [^}]*? (?# read past rules before background-color)
307 background\-color\:\s*) (?# find background-color rule)
308 .*\; (?# old defined color)
309 /$1$opts{color};/x;
310 }
311  
312 # replace url(/OptimalQuery/ with custom resourceURI if it exists
313 if (exists $$o{schema}{resourceURI}) {
314 $$o{schema}{resourceURI} =~ s/\/$//;
315 $inlineCSS =~ s/(?<=\burl\() (?# match before)
316 .*? (?# stuff to replace)
317 (?=\/\w+\.gif) (?# match after)
318 /$$o{schema}{resourceURI}/xg;
319 }
320 }
321 $inlineCSS .= "#OQfilter { display: none; }\n" if $$o{filter} eq '';
322 $inlineCSS .= "#OQsort { display: none; }\n" if $$o{sort} eq '';
323 $inlineCSS .= "#OQqueryDescr { display: none; }\n" if $$o{queryDescr} eq '';
324 $inlineCSS .= "\n</style>\n";
325 if (!($opts{htmlHeader} =~ s/(<\/head>)/$inlineCSS$1/i)) {
326 $opts{htmlHeader} .= $inlineCSS;
327 }
328  
329 $opts{htmlFooter} = "</body>\n</html>\n"
330 unless exists $opts{htmlFooter};
331  
332 # eval if code ref
333 foreach my $key (qw( OQdocTop OQdocBottom OQformTop OQformBottom )) {
334 $opts{$key} = $opts{$key}->() if ref($opts{$key}) eq 'CODE';
335 }
336  
337 $opts{OQdocTop} ||= '';
338 $opts{OQdocBottom} ||= '';
339 $opts{OQformTop} ||= '';
340 $opts{OQformBottom} ||= '';
341 $opts{editButtonLabel} ||= 'edit';
342 $opts{disable_sort} ||= 0;
343 $opts{disable_filter} ||= 0;
344 $opts{disable_select} ||= 0;
345 $opts{mutateRecord} ||= undef;
346 $opts{noEscapeCol} ||= [];
347 $opts{editLink} ||= undef;
348  
349 # carry hidden state params
350 my $state_params = '';
351 if (ref($$o{schema}{state_params}) eq 'ARRAY') {
352 foreach my $p (@{ $$o{schema}{state_params} }) {
353 $state_params .= ";$p=".$o->escape_uri($o->{q}->param($p));
354 }
355 }
356 $state_params .= ';' if $state_params;
357  
358  
359  
360 my $doc = $opts{httpHeader}.$opts{htmlHeader}."
361 <div id='OQdoc'>
362 <div id='OQdocTop'>$opts{OQdocTop}</div>
363  
364 <form id='OQform' name='OQform' action='".$$o{schema}{URI}."#OQtop' method='post'>
365 <input type='hidden' name='act' value='' />
366 <input type='hidden' name='view' value='' />
367  
368 <script type='text/javascript' id='OQscript'>
369  
370 // code to open debug mode when ALT-Q is typed
371 var last_key;
372 if (window.document.getElementById) document.onkeyup = KeyCheck;
373 function KeyCheck(e) {
374 var KeyID = (window.event) ? event.keyCode : e.keyCode;
375 if (last_key == 18 && KeyID == 81) {
376 if (window.document.getElementById &&
377 window.document.getElementById('OQstateVars') &&
378 window.document.getElementById('OQstateVars').style ) {
379 var d = window.document.getElementById('OQstateVars').style.display;
380 d = (d == 'none') ? '' : 'none';
381 window.document.getElementById('OQstateVars').style.display = d;
382 }
383 }
384 else { last_key = KeyID; }
385 return true;
386 }
387  
388  
389  
390 var OQdefaultModule = 'InteractiveQuery';
391 function OQval(name, newVal) {
392 if (document.OQform.elements[name]) {
393 var elem = document.OQform.elements[name];
394 if (newVal != null) elem.value = newVal;
395 return elem.value;
396 }
397 }
398 function OQvals(name, newVals) {
399 if (document.OQform.elements[name]) {
400 var elem = document.OQform.elements[name];
401 if (newVals != null) elem.value = newVals.join(',');
402 if (elem.value == '') return new Array();
403 else return elem.value.split(',');
404 }
405 }
406  
407 function OQrefresh(updated_uid) {
408 var f = document.OQform;
409 f.target = '';
410 f.module.value = OQdefaultModule;
411 f.act.value = '';
412 f.view.value = '';
413  
414 if (updated_uid && f.on_select.value != '') {
415 funct_ref = eval('window.opener.'+f.on_select.value);
416 if (funct_ref) {
417 funct_ref(updated_uid);
418 window.opener.focus();
419 }
420 window.close();
421 }
422 else {
423 if (updated_uid) f.updated_uid.value = updated_uid;
424 f.action = '$$o{schema}{URI}#OQtop';
425 f.submit();
426 }
427 }
428  
429  
430 // special open window code (auto centers based on parent)
431 function OQopwin (lnk,target,opts,w,h) {
432  
433 if (! target) target = '_blank';
434 if (! opts) opts = 'resizable,scrollbars';
435 if (! w) w = $$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowWidth};
436 if (! h) h = $$o{schema}{options}{'CGI::OptimalQuery::InteractiveQuery'}{WindowHeight};
437  
438 if (window.screen) {
439 var s = window.screen;
440 var max_width = s.availWidth - 10;
441 var max_height = s.availHeight - 30;
442 if (opts.indexOf('toolbar',0) != -1) max_height -= 40;
443 if (opts.indexOf('menubar',0) != -1) max_height -= 35;
444 if (opts.indexOf('location',0) != -1)max_height -= 35;
445 var width = (w > max_width)?max_width:w;
446 var height = (h > max_height)?max_height:h;
447 var par_left_offset = (window.screenX == null)?0:window.screenX;
448 var par_top_offset = (window.screenY == null)?0:window.screenY;
449 var par_width;
450 if (window.outerWidth != null) {
451 par_width = window.outerWidth;
452 if (par_width < width)
453 par_left_offset -= parseInt((width - par_width)/2);
454 } else
455 par_width = max_width;
456  
457 var par_height;
458 if (window.outerHeight != null) {
459 par_height = window.outerHeight;
460 if (par_height < height) {
461 par_top_offset -= parseInt((height - par_height)/2);
462 }
463 } else
464 par_height = max_height;
465  
466 var left = parseInt(par_width /2 - width /2) + par_left_offset;
467 var top = parseInt(par_height/2 - height/2) + par_top_offset;
468  
469 var newopts = 'width='+width+',height='+height+',left='+left+',top='+top;
470 opts = (opts && opts != '')?newopts+','+opts:newopts;
471 }
472 var wndw = window.open(lnk,target,opts);
473 if (wndw.focus) wndw.focus();
474 return wndw;
475 }
476  
477 function hideCmdOptions() {
478 OQval('OQsaveSearchTitle','');
479 document.getElementById('cmdOptions').style.display = 'none';
480 document.getElementById('exportOptions').style.display = 'none';
481 document.getElementById('savedSearchesOptions').style.display = 'none';
482  
483 // hack for z-layer form input bug in IE
484 if (/MSIE\ 6/.test(navigator.userAgent))
485 document.getElementById('OQdata').style.visibility = 'visible';
486 }
487  
488 function toogleCmdOptions(id) {
489 if (document.getElementById(id).style.display == 'block') {
490 hideCmdOptions();
491 } else {
492 document.getElementById('exportOptions').style.display = 'none';
493 document.getElementById('savedSearchesOptions').style.display = 'none';
494  
495 if (/MSIE\ 6/.test(navigator.userAgent))
496 document.getElementById('OQdata').style.visibility = 'hidden';
497  
498 document.getElementById(id).style.display = 'block';
499 document.getElementById('cmdOptions').style.display = 'block';
500 }
501 }
502  
503  
504 </script><noscript>Javascript is required when viewing this page.</noscript>
505  
506 <table id='OQstateVars' style=\"display: none;\">
507 <tr>
508 <td>show</td>
509 <td><input type='text' name='show' value=\"".$o->escape_html(join(',',@{$$o{show}}))."\" /></td>
510 </tr>
511 <tr>
512 <td>filter</td>
513 <td><input type='text' name='filter' value=\"".$o->escape_html($$o{filter})."\" /></td>
514 </tr>
515 <tr>
516 <td>hiddenFilter</td>
517 <td><input type='text' name='hiddenFilter' value=\"".$o->escape_html($$o{hiddenFilter})."\" /></td>
518 </tr>
519 <tr>
520 <td>queryDescr</td>
521 <td><input type='text' name='queryDescr' value=\"".$o->escape_html($$o{queryDescr})."\" /></td>
522 </tr>
523 <tr>
524 <td>sort</td>
525 <td><input type='text' name='sort' value=\"".$o->escape_html($$o{sort})."\" /></td>
526 </tr>
527 <tr>
528 <td>page</td>
529 <td><input type='text' name='page' value=\"".$o->escape_html($$o{page})."\" /></td>
530 </tr>
531 <tr>
532 <td>module</td>
533 <td><input type='text' name='module' value=\"".$o->escape_html($$o{module})."\" /></td>
534 </tr>
535 <tr>
536 <td>rows_page</td>
537 <td><input type='text' name='rows_page' value=\"".$o->escape_html($$o{rows_page})."\" /></td>
538 </tr>
539 <tr>
540 <td>updated_uid</td>
541 <td><input type='text' name='updated_uid' value='' /></td>
542 </tr>
543 <tr>
544 <td>on_select</td>
545 <td><input type='text' name='on_select' value=\"".$o->escape_html($$o{q}->param('on_select'))."\" /></td>
546 </tr>";
547  
548 if (ref($$o{schema}{state_params}) eq 'ARRAY') {
549 foreach my $p (@{ $$o{schema}{state_params} }) {
550 $doc .= "<tr><td>$p</td><td><input type='text' name='$p' value='".$o->escape_html($o->{q}->param($p))."'></td></tr>";
551 }
552 }
553  
554 $doc .= "
555 <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>
556  
557 <a name='OQtop'></a>
558  
559 <div id='OQupdatedUidInfo'>".
560 (($$o{q}->param('updated_uid') eq '')?"":
561 "UID: ".$o->escape_html($$o{q}->param('updated_uid'))." updated")."
562 </div>
563  
564  
565 <div id='OQformTop'>$opts{OQformTop}</div>
566  
567 <table id='OQhead'>
568 <tr>
569 <td id='OQtitle'>".$o->escape_html($o->get_title)."</td>
570 <td id='OQsummary'>Result(s) (".$o->commify($o->get_lo_rec)." - ".$o->commify($o->get_hi_rec).") of ".$o->commify($o->get_count)."</td>
571 <td id='OQcmds'>";
572  
573 if (ref($opts{buildNewLink}) eq 'CODE') {
574 my $link = $opts{buildNewLink}->($o, \%opts);
575 if ($link ne '') {
576 $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>";
577 }
578 }
579 elsif (exists $opts{buildNewLink} && $opts{buildNewLink} eq '') {}
580 elsif ($opts{editLink} ne '') {
581 my $link = $opts{editLink}.(($opts{editLink} =~ /\?/)?'&':'?')."on_update=OQrefresh&act=new";
582 if ($link ne '') {
583 $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>";
584 }
585 }
586  
587 $doc .= "<button type='button' class='OQrefreshButton' onclick=\"OQrefresh();\">refresh</button>";
588 $doc .= "<button type='button' onclick=\"toogleCmdOptions('savedSearchesOptions');
589 if (document.getElementById('savedSearchesOptions').style.display != 'none') this.form.OQsaveSearchTitle.focus();
590 \">saved searches</button>" if $$o{schema}{savedSearchUserID};
591 $doc .= "<button type='button' onclick=\"toogleCmdOptions('exportOptions');\">export</button>
592 </td>
593 </tr>
594 </table>
595  
596 <div id='cmdOptions'>
597 <button type='button' class='closeButton' onclick=\"hideCmdOptions();\" title='close'>&times;</button>
598  
599 <div id='exportOptions'>
600 <h1>select download file type</h1>
601 <input type='radio' name='exportModule' checked = 'checked'/>Printer Friendly
602 <br />
603 <input type='radio' name='exportModule' />CSV <span class='note'>comma separated values (use in Microsoft Excel)</span>
604 <br />
605 <input type='radio' name='exportModule' />XML ";
606  
607 if ($$o{rows_page} ne 'All') {
608 $doc .= " <br /> <input type='checkbox' name='exportAll' />export all results"
609 }
610 $doc .= "
611 <br />
612 <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>
613 </div>
614  
615 <div id='savedSearchesOptions'>
616 ";
617  
618
619 # if saved searches are enabled ..
620 if ($$o{schema}{savedSearchUserID}) {
621 local $$o{dbh}->{LongReadLen};
622 $doc .= "
623 <h1>save search</h1>
624 name <input type=text name='OQsaveSearchTitle' value='' /><button type='button' title='save search' onclick=\"OQrefresh();\">save</button><br /> <br />";
625  
626 if ($$o{dbh}{Driver}{Name} eq 'Oracle') {
627 my ($readLen) = $$o{dbh}->selectrow_array("SELECT max(dbms_lob.getlength(params)) FROM oq_saved_search WHERE user_id = ?", undef, $$o{schema}{savedSearchUserID});
628 $$o{dbh}->{LongReadLen} = $readLen if $readLen > $$o{dbh}->{LongReadLen};
629 }
630  
631 my $sth = $$o{dbh}->prepare("
632 SELECT id, user_title, params
633 FROM oq_saved_search
634 WHERE user_id = ?
635 AND upper(uri) = upper(?)
636 AND oq_title = ?");
637 $sth->execute($$o{schema}{savedSearchUserID}, $$o{schema}{URI},$$o{schema}{title});
638  
639 my $buffer = '';
640 while (my ($id, $title, $params) = $sth->fetchrow_array()) {
641  
642 my $stateArgs = '';
643 if ($params ne '') {
644 $params = eval '{'.$params.'}';
645 if (ref($params) eq 'HASH') {
646 delete $$params{show};
647 delete $$params{rows_page};
648 delete $$params{page};
649 delete $$params{hiddenFilter};
650 delete $$params{filter};
651 delete $$params{queryDescr};
652 delete $$params{sort};
653 while (my ($k,$v) = each %$params) {
654 $stateArgs .= "&amp;$k=";
655 $stateArgs .= (ref($v) eq 'ARRAY') ?
656 CGI::escape($$v[0]) : CGI::escape($v);
657 }
658 }
659 }
660  
661 $buffer .= "<a href=# onclick=\"window.location='$$o{schema}{URI}?OQLoadSavedSearch=$id".$stateArgs."#OQtop';\">".$o->escape_html($title)."</a><br />";
662 }
663 $doc .= "<h1>load search</h1>$buffer" if $buffer;
664 }
665  
666 $doc .= "
667 </div>
668 </div>
669 <table id='OQinfo' style=\"border-bottom: 1px solid #666666;\">";
670  
671 if (!( $opts{disable_select} && $opts{disable_sort} && $opts{disable_filter} )) {
672 $doc .= "
673 <tr id='OQkey'><td class='OQinfoName'>Key:</td>
674 <td class='OQinfoVal'>";
675  
676 $doc .= "<button class='OQaddColButton' type='button'>add column</button>add column"
677 unless $opts{disable_select};
678  
679 $doc .= "<button class='OQsortAscButton' type='button'>sort</button>sort
680 <button class='OQsortDescButton'>reverse sort</button>reverse sort"
681 unless $opts{disable_sort};
682  
683 $doc .= "<button class='OQfilterCol' type='button'>filter column</button>filter column"
684 unless $opts{disable_filter};
685  
686 $doc .= "<button class='OQcloseButton' type='button'>close column</button>close column"
687 unless $opts{disable_select};
688 $doc .= "</td></tr>";
689 }
690 $doc .= "
691 <tr id='OQqueryDescr'><td class='OQinfoName'>Query:</td><td class='OQinfoVal'>".$o->escape_html($$o{queryDescr})."</td></tr>
692 <tr id='OQfilter'><td class='OQinfoName'>Filter:</td><td class='OQinfoVal'>".$o->escape_html($o->get_filter());
693  
694 $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};
695  
696 $doc .=
697 "</td></tr>
698 <tr id='OQsort'><td class='OQinfoName'>Sort:</td><td class='OQinfoVal'>";
699  
700 my @sort = $o->sth->sort_descr();
701 if (@sort) {
702 # create new sort description
703 my @buffer;
704 for (my $i=0; $i < @sort; $i++) {
705 my $buf = '';
706 $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};
707 $buf .= $o->escape_html($sort[$i]);
708 $buf .= "</a>" unless $opts{disable_sort};
709 push @buffer, $buf;
710 }
711 $doc .= join(', ',@buffer);
712 }
713  
714 $doc .= "</td></tr>
715 </table>
716  
717 <table id='OQdata'>
718 <thead>
719 <tr>
720  
721 <td id='OQdataLHead'>
722 </td>";
723  
724  
725  
726  
727 foreach my $i (0 .. ($o->get_num_usersel_cols() - 1)) {
728 my $colAlias = $o->get_usersel_cols->[$i];
729 $doc .= "<td class='OQcolHeader'><div class='OQcolCmds'>
730 <!-- the following line is necessary for IE browsers otherwise buttons won't display -->
731 <span style='visibility: hidden;'>.</span>
732 ";
733  
734 if (! ($$o{schema}{select}{$colAlias}[3]{disable_select} || $opts{disable_select})) {
735 $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>";
736 }
737 if (! ($$o{schema}{select}{$colAlias}[3]{disable_sort} || $opts{disable_sort}) ) {
738 $doc .= "<button type='button' title='sort' class='OQsortAscButton' onclick=\"var sort=OQvals('sort');sort.push('[$colAlias]'); OQvals('sort',sort);OQrefresh();\">sort</button>
739 <button type='button' title='reverse sort' class='OQsortDescButton' onclick=\"var sort=OQvals('sort');sort.push('[$colAlias] DESC');OQvals('sort',sort);OQrefresh();\">reverse sort</button>";
740 }
741 if (! ($$o{schema}{select}{$colAlias}[3]{disable_filter} || $opts{disable_filter}) ) {
742 $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>";
743 }
744 if (! ($$o{schema}{select}{$colAlias}[3]{disable_select} || $opts{disable_select})) {
745 $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 />";
746 }
747  
748 if ($$o{schema}{select}{$colAlias}[3]{disable_select} || $opts{'disable_select'}) {
749 $doc .= "<div class='OQcolHeadTitle'>".$o->escape_html($$o{schema}{select}{$colAlias}[2])."</div>";
750 }
751  
752 else {
753 $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();\">";
754  
755 # create possible cols to select
756 my $s = $$o{schema}{select};
757  
758 foreach my $col (sort { uc($s->{$a}->[2]) cmp uc($s->{$b}->[2]) } keys %{$$o{schema}{select}}) {
759 my $col_opts = $s->{$col}->[3] || {};
760 next if $col_opts->{'is_hidden'} || ! $$s{$col}[2];
761 my $nice = $o->get_nice_name($col);
762  
763 $doc .= "<option value='".$o->escape_html($col)."'";
764 $doc .= " selected='selected'" if ($o->{'show'}->[$i] eq $col);
765 $doc .= ">".$o->escape_html($nice)."</option>";
766 }
767 $doc .= "</select>";
768 }
769  
770 $doc .= "</div></td>";
771 }
772  
773 $doc .= "
774 <td id='OQdataRHead'></td>
775 </tr>
776 </thead>
777  
778 <tfoot id='OQdataFoot'>
779 </tfoot>
780  
781 <tbody>";
782  
783 # print data
784 my $rowType = 'Odd';
785  
786 my %noEsc = map { $_ => 1 } @{ $opts{noEscapeCol} };
787  
788 my $recs_in_buffer = 0;
789 while (my $r = $o->sth->fetchrow_hashref()) {
790 $opts{mutateRecord}->($r) if ref($opts{mutateRecord}) eq 'CODE';
791 $$o{schema}{mutateRecord}->($r) if ref($$o{schema}{mutateRecord}) eq 'CODE';
792  
793 my $class = "OQdataRowType$rowType";
794 $class .= " OQupdatedRow"
795 if $$r{U_ID} ne '' && $$r{U_ID} eq $$o{q}->param('updated_uid');
796  
797 $doc .= "<tr class='$class'>\n<td class='OQdataLCol'>";
798 if (ref($opts{OQdataLCol}) eq 'CODE') { $doc .= $opts{OQdataLCol}->($r); }
799 elsif (ref($opts{buildEditLink}) eq 'CODE') {
800 my $link = $opts{buildEditLink}->($o, $r, \%opts);
801 if ($link ne '') {
802 $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>";
803 }
804 } elsif ($opts{editLink} ne '' && $$r{U_ID} ne '') {
805 my $link = $opts{editLink}.(($opts{editLink} =~ /\?/)?'&':'?')."on_update=OQrefresh&act=load&id=$$r{U_ID}";
806 $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>";
807 }
808 $doc .= "\n</td>";
809  
810 # print table cell with value
811 foreach my $col (@{ $o->get_usersel_cols }) {
812 my $val;
813 if (exists $noEsc{$col}) {
814 $val = $$r{$col};
815 } else {
816 if (ref($$r{$col}) eq 'ARRAY') {
817 $val = join(', ', map { $o->escape_html($_) } @{ $$r{$col} });
818 } else {
819 $val = $o->escape_html($$r{$col});
820 }
821 }
822 $doc .= "<td class='OQcolData OQselect-$col'>$val</td>\n";
823 }
824  
825 # still need to add code for on_select functionality
826 $doc .= "<td class='OQdataRCol'>\n";
827  
828 if (ref($opts{OQdataRCol}) eq 'CODE') { $doc .= $opts{OQdataRCol}->($r); }
829 elsif ($o->{q}->param('on_select') ne '' && $$r{U_ID} ne '') {
830 my $on_select = $o->{q}->param('on_select');
831 $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>";
832 }
833  
834 $doc .= "\n</td>\n</tr>\n\n";
835  
836 $rowType = ($rowType eq "Odd") ? "Even" : "Odd";
837  
838 $recs_in_buffer++;
839 if ($recs_in_buffer == 20) { $$o{output_handler}->($doc); $doc = ''; $recs_in_buffer = 0; }
840 }
841 $o->sth->finish();
842  
843 $doc .= "
844 </tbody>
845 </table>";
846  
847 $doc .= $o->getPager();
848  
849 $doc .= "
850 <div id='OQformBottom'>".$opts{OQformBottom}."</div>
851 </form>
852  
853 <script type='text/javascript'>
854 $opts{OQscript}
855 document.OQform.reset();
856 </script><noscript>Javascript is required when viewing this page.</noscript>
857  
858 <div id='OQdocBottom'></div>
859 </div>
860 $opts{htmlFooter}";
861  
862 $$o{output_handler}->($doc);
863 return undef;
864 }
865  
866 1;