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