| 1 | #!/usr/local/bin/perl | ||
| 2 | # a perl CGI database table editor | ||
| 3 | # | ||
| 4 | |||
| 5 | $VERSION = "1.7"; | ||
| 6 | 0 | ▶ | sub Version { $VERSION; } |
|
Subroutine
Version: not called CC=1 SCAR=6.9
| |||
| 7 | |||
| 8 | 1 | ▶ | use strict; # Check for inadvertent global variables |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use vars qw($X $SchemaCache $CacheCount $PQ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use CGI; # Use CGI module for interaction |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 0 | ▶ | use RDBAL; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | use RDBAL::Schema; | ||
| 13 | |||
| 14 | |||
| 15 | # Create CGI object | ||
| 16 | my($query); | ||
| 17 | $query = new CGI(); | ||
| 18 | |||
| 19 | # | ||
| 20 | # Change editing table, if an 'Edit Table: $table' button was pushed | ||
| 21 | # | ||
| 22 | Change_Edit_Table($query); | ||
| 23 | |||
| 24 | # Output header | ||
| 25 | # if ($query->request_method() eq 'GET' || $query->user_agent() !~ /MSIE/ || | ||
| 26 | # $query->server_software =~ /IIS/) { | ||
| 27 | print $query->header(-type => 'text/html', | ||
| 28 | -status => '200 OK', | ||
| 29 | -expires => 'now'); | ||
| 30 | #} | ||
| 31 | # } | ||
| 32 | |||
| 33 | |||
| 34 | # | ||
| 35 | # Get cgi parameters as $cgi_param entries to pass on | ||
| 36 | # | ||
| 37 | my($cgi_param) = PQEntry($query); | ||
| 38 | |||
| 39 | # Do password-less login | ||
| 40 | if (defined($query->param('login'))) { | ||
| 41 | my($server) = $cgi_param->{'server'}; | ||
| 42 | my($database) = $cgi_param->{'database'}; | ||
| 43 | my($login) = $query->param('login'); | ||
| 44 | ($cgi_param->{'username'}, $cgi_param->{'password'}) = | ||
| 45 | eval "use lib '.'; use PQLOGIN; PQLOGIN\:\:Fetch(\$server,\$database,\$login);"; | ||
| 46 | } | ||
| 47 | |||
| 48 | # | ||
| 49 | # Display Login screen, if necessary | ||
| 50 | # | ||
| 51 | if (!PQLogin($query,$cgi_param)) { | ||
| 52 | exit; | ||
| 53 | } | ||
| 54 | |||
| 55 | # | ||
| 56 | # Setup error handlers | ||
| 57 | # The message handler is all that is currently necessary (or works). | ||
| 58 | # | ||
| 59 | |||
| 60 | my($error_string); | ||
| 61 | $error_string = ''; # clear it for global use | ||
| 62 | undef $error_string; # clear it for global use | ||
| 63 | # different handler to check callbacks | ||
| 64 | if ($RDBAL::Layer{'SybaseDBlib'} || $RDBAL::Layer{'ApacheSybaseDBlib'}) { | ||
| 65 | &Sybase::DBlib::dbmsghandle (\&msg_handler); | ||
| 66 | } | ||
| 67 | |||
| 68 | # | ||
| 69 | # Connect to database server | ||
| 70 | # | ||
| 71 | my($logged_in); | ||
| 72 | # Get connnection to database | ||
| 73 | if ( $X = RDBAL::Connect($cgi_param->{'username'}, | ||
| 74 | $cgi_param->{'password'}, | ||
| 75 | $cgi_param->{'server'}, | ||
| 76 | $cgi_param->{'server_type'}, | ||
| 77 | $cgi_param->{'database'}) | ||
| 78 | ) { | ||
| 79 | if (defined($X->{'connection'})) { | ||
| 80 | if ( $X->UseDatabase($cgi_param->{'database'})) { | ||
| 81 | $logged_in = 1; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | if (defined($query->param('login'))) { | ||
| 86 | delete $cgi_param->{'username'}; | ||
| 87 | delete $cgi_param->{'password'}; | ||
| 88 | } | ||
| 89 | if (!$logged_in) { | ||
| 90 | Login_Error($query,$cgi_param); | ||
| 91 | exit; | ||
| 92 | } | ||
| 93 | |||
| 94 | # | ||
| 95 | # Get database schema object | ||
| 96 | # | ||
| 97 | my($cache_item) = $cgi_param->{'server'} . ':' . $cgi_param->{'database'}; | ||
| 98 | if ($cgi_param->{'no_schemacache'}) { | ||
| 99 | $SchemaCache->{$cache_item} = | ||
| 100 | new RDBAL::Schema($X, | ||
| 101 | $cgi_param->{'database'}, | ||
| 102 | -server => $cgi_param->{'server'}, | ||
| 103 | -nocache => $cgi_param->{'no_schemacache'}, | ||
| 104 | -server_type => $cgi_param->{'server_type'}); | ||
| 105 | } else { | ||
| 106 | if($SchemaCache->{$cache_item}) { | ||
| 107 | } else { | ||
| 108 | $SchemaCache->{$cache_item} = | ||
| 109 | new RDBAL::Schema($X, | ||
| 110 | $cgi_param->{'database'}, | ||
| 111 | -server => $cgi_param->{'server'}, | ||
| 112 | -nocache => $cgi_param->{'no_schemacache'}, | ||
| 113 | -server_type => $cgi_param->{'server_type'}); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | # | ||
| 118 | # Dump out parameters if in debug mode | ||
| 119 | # | ||
| 120 | if (defined($query->param('pqdebug'))) { | ||
| 121 | map { | ||
| 122 | $error_string .= "DEBUG> $_ = $cgi_param->{$_}<P>\n"; | ||
| 123 | } (sort (keys %$cgi_param)); | ||
| 124 | map { | ||
| 125 | if (/pq_/ || /pqsearch_/ || /pqold_/) { | ||
| 126 | $error_string .= "DEBUG> $_ = ". $query->param($_) . "<P>\n"; | ||
| 127 | } | ||
| 128 | } $query->param; | ||
| 129 | } | ||
| 130 | |||
| 131 | if (defined($query->param('Overview')) || | ||
| 132 | defined($query->param('overview'))) { | ||
| 133 | # | ||
| 134 | # Show overview table | ||
| 135 | # | ||
| 136 | Overview($X,$query,$cgi_param,$SchemaCache->{$cache_item}); | ||
| 137 | } else { | ||
| 138 | # | ||
| 139 | # Edit table | ||
| 140 | # | ||
| 141 | Edit($X,$query,$cgi_param,$SchemaCache->{$cache_item}); | ||
| 142 | } | ||
| 143 | exit; | ||
| 144 | #========================================================================= | ||
| 145 | # | ||
| 146 | # End of script--beginning of subroutines | ||
| 147 | # | ||
| 148 | |||
| 149 | |||
| 150 | # Message Handler callback handler | ||
| 151 | # Called when there is a message from the server | ||
| 152 | |||
| 153 | sub msg_handler { | ||
| 154 | my ($db, $message, $state, $severity, $text, | ||
| 155 | $server, $procedure, $line) | ||
| 156 | = @_; | ||
| 157 | my($out_text); | ||
| 158 | |||
| 159 | if ($severity > 0) { | ||
| 160 | $out_text = $text; | ||
| 161 | $out_text =~ s/^Line\s*\d+\:\s*//; | ||
| 162 | ($message == 102) or | ||
| 163 | $error_string .= "$out_text ($message:$severity:$state)"; | ||
| 164 | } | ||
| 165 | 1; | ||
| 166 | } | ||
| 167 | |||
| 168 | # | ||
| 169 | # Change_Edit_Table($query); | ||
| 170 | # | ||
| 171 | sub Change_Edit_Table { | ||
| 172 | my($query) = shift; | ||
| 173 | my($table); | ||
| 174 | |||
| 175 | if (defined($query->param('edit_lookup'))) { | ||
| 176 | map { | ||
| 177 | if (/^pqold_/) { | ||
| 178 | $query->delete($_); | ||
| 179 | } | ||
| 180 | } $query->param; | ||
| 181 | ($table) = $query->param('edit_lookup') =~ /^Edit Table:\s+(.*)$/; | ||
| 182 | $table =~ s/^\s*//g; | ||
| 183 | $table =~ s/\s*$//g; | ||
| 184 | $query->param('table',$table); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | # | ||
| 189 | # $td_label = TD_Field_Label($field,$required,$rlabel,$helppage); | ||
| 190 | # | ||
| 191 | |||
| 192 | sub TD_Field_Label { | ||
| 193 | my($field) = shift; | ||
| 194 | my($required) = shift; | ||
| 195 | my($rlabel) = shift; | ||
| 196 | my($helppage) = shift; | ||
| 197 | my($label); | ||
| 198 | my($td_label); | ||
| 199 | |||
| 200 | $field =~ s/_____/ and_/g; | ||
| 201 | $label = (defined($rlabel->{$field})) ? | ||
| 202 | $rlabel->{$field} : uc_string($field); | ||
| 203 | $td_label = '<TD WIDTH="25%" VALIGN="TOP"><p align="right">'; | ||
| 204 | if ($helppage !~ /^\s*$/) { | ||
| 205 | $td_label .= '<A HREF="'. $helppage .'#'. $field .'">' . | ||
| 206 | $label . ' ' . $required . "</A></TD>"; | ||
| 207 | } else { | ||
| 208 | $td_label .= $label . ' ' . $required . "</TD>"; | ||
| 209 | } | ||
| 210 | return $td_label; | ||
| 211 | } | ||
| 212 | |||
| 213 | # | ||
| 214 | # Output CGI forms overview screen | ||
| 215 | # | ||
| 216 | # Overview($X,$query,$cgi_param,$schema); | ||
| 217 | # | ||
| 218 | |||
| 219 | sub Overview { | ||
| 220 | my($X) = shift; | ||
| 221 | my($query) = shift; | ||
| 222 | my($cgi_param) = shift; | ||
| 223 | my($schema) = shift; | ||
| 224 | my(%qbe_fields); | ||
| 225 | my(%values); | ||
| 226 | my($table) = $cgi_param->{'table'}; | ||
| 227 | my($html_page); | ||
| 228 | my($self_url); | ||
| 229 | my($server) = $cgi_param->{'server'}; | ||
| 230 | my($database) = $cgi_param->{'database'}; | ||
| 231 | my($fullname) = $server . '.' . $database . '.' . $table; | ||
| 232 | my($body_bgcolor) = (defined($cgi_param->{'web_body_bgcolor'})) ? | ||
| 233 | $cgi_param->{'web_body_bgcolor'} : 'white'; | ||
| 234 | my(%value_array); | ||
| 235 | my($array_ref); | ||
| 236 | my($field); | ||
| 237 | my(@primary_keys) = (($schema->Primary_Keys($table) > 0) ? | ||
| 238 | $schema->Primary_Keys($table) : | ||
| 239 | $schema->Table_Fields($table)); | ||
| 240 | my(%primary_keys); | ||
| 241 | my(@pk_value); | ||
| 242 | my($number_rows); | ||
| 243 | my($pk_value); | ||
| 244 | my($escaped_pk_value); | ||
| 245 | my($value); | ||
| 246 | my(@other_fields); | ||
| 247 | my($other_cells); | ||
| 248 | my($i); | ||
| 249 | my($rlabel); | ||
| 250 | my($rl_field); | ||
| 251 | my($rl_value); | ||
| 252 | my($label); | ||
| 253 | my($target); | ||
| 254 | |||
| 255 | map { | ||
| 256 | $primary_keys{$_} = 1; | ||
| 257 | } @primary_keys; | ||
| 258 | %qbe_fields = qbe_fields($schema,$table); | ||
| 259 | %values = get_values($X,$schema,$table,\%qbe_fields,$query); | ||
| 260 | |||
| 261 | # Delete unneccessary parameters | ||
| 262 | # and find search fields that are not primary keys | ||
| 263 | map { | ||
| 264 | if (/^pqold_/ || | ||
| 265 | /^pq_/ || | ||
| 266 | /^pqsearch_/) { | ||
| 267 | $query->delete($_); | ||
| 268 | } | ||
| 269 | } $query->param; | ||
| 270 | $query->delete('Overview'); | ||
| 271 | $query->delete('overview'); | ||
| 272 | |||
| 273 | map { | ||
| 274 | if (!defined($primary_keys{$_})) { | ||
| 275 | push @other_fields, ($_); | ||
| 276 | } | ||
| 277 | } $schema->Table_Fields($table); | ||
| 278 | $self_url = $query->self_url; | ||
| 279 | # rearrange into an associative array of references to values arrays | ||
| 280 | foreach $field ($schema->Table_Fields($table)) { | ||
| 281 | $value_array{$field} = []; | ||
| 282 | @pk_value = split("\t",$values{$field}); | ||
| 283 | push @{$value_array{$field}}, @pk_value; | ||
| 284 | } | ||
| 285 | |||
| 286 | if (defined($error_string)) { | ||
| 287 | $html_page .= "Database Error: $error_string<P>\n"; | ||
| 288 | } | ||
| 289 | |||
| 290 | $html_page .= '<B>To Refresh, </B>' . | ||
| 291 | $query->button(-name => 'refresh', | ||
| 292 | -value => 'Refresh Search Set View', | ||
| 293 | -onClick => 'location.reload(true)'); | ||
| 294 | $html_page .= "<B> Press the Web Browser's 'Reload' or 'Refresh' button.</B><P>\n"; | ||
| 295 | $html_page .= '<TABLE ALIGN="center" BORDER="2">'."\n"; | ||
| 296 | undef $i; | ||
| 297 | map { | ||
| 298 | ($rl_field, $rl_value) = split(';'); | ||
| 299 | $rlabel->{$rl_field} = $rl_value; | ||
| 300 | } split(',',$query->param('labels')); | ||
| 301 | map { | ||
| 302 | $label = (defined($rlabel->{$_})) ? $rlabel->{$_} : uc_string($_); | ||
| 303 | if (!defined($i)) { | ||
| 304 | $i .= '<TH>'. $label; | ||
| 305 | } else { | ||
| 306 | $i .= ' and<BR>'. $label; | ||
| 307 | } | ||
| 308 | } @primary_keys; | ||
| 309 | $i .= "</TH>\n"; | ||
| 310 | map { | ||
| 311 | $label = (defined($rlabel->{$_})) ? $rlabel->{$_} : uc_string($_); | ||
| 312 | $i .= "<TH>$label</TH>"; | ||
| 313 | } @other_fields; | ||
| 314 | $html_page .= "<tr>$i</tr>\n"; | ||
| 315 | $target = ($query->param('single_window') eq 'ON') ? | ||
| 316 | '' : " TARGET=\"pqedit$table\""; | ||
| 317 | @pk_value = (@{$value_array{$primary_keys[0]}}); | ||
| 318 | $number_rows = $#pk_value; | ||
| 319 | for ($i = 0; $i <= $number_rows;$i++) { | ||
| 320 | undef @pk_value; | ||
| 321 | map { | ||
| 322 | $array_ref = $value_array{$_}; | ||
| 323 | $value = $$array_ref[$i]; | ||
| 324 | push @pk_value, ($$array_ref[$i]); | ||
| 325 | } @primary_keys; | ||
| 326 | $pk_value = join("\t",@pk_value); | ||
| 327 | $escaped_pk_value = $query->escape($pk_value); | ||
| 328 | undef $other_cells; | ||
| 329 | map { | ||
| 330 | $array_ref = $value_array{$_}; | ||
| 331 | $value = $$array_ref[$i]; | ||
| 332 | if (!defined($value) || $value =~ /^\s*$/) { | ||
| 333 | $value = ' '; | ||
| 334 | } | ||
| 335 | $other_cells .= " <td align=\"center\">$value</td>\n"; | ||
| 336 | } @other_fields; | ||
| 337 | $html_page .= " | ||
| 338 | <tr> | ||
| 339 | <td align=\"center\"> | ||
| 340 | <A href=\"$self_url&pk_value=$escaped_pk_value\"$target>$pk_value | ||
| 341 | </a> | ||
| 342 | </td> | ||
| 343 | $other_cells | ||
| 344 | </tr>\n"; | ||
| 345 | } | ||
| 346 | $html_page .= "</TABLE>\n"; | ||
| 347 | |||
| 348 | print $query->start_html(-title => "PQ Edit Overview for $fullname", | ||
| 349 | -author => 'brian@ibc.wustl.edu', | ||
| 350 | -BGCOLOR => $body_bgcolor, | ||
| 351 | -onload => 'window.focus();'); # Focus this page | ||
| 352 | # -onload => 'window.setInterval("location.reload(true)", 1500000);'); # Reload page every fifteen minutes | ||
| 353 | print $html_page; | ||
| 354 | print PQHidden_Parameters($query,$cgi_param); | ||
| 355 | print "\n" . $query->end_html; | ||
| 356 | } | ||
| 357 | |||
| 358 | # | ||
| 359 | # Output CGI forms editing screen | ||
| 360 | # | ||
| 361 | # Edit($X,$query,$cgi_param,$schema); | ||
| 362 | # | ||
| 363 | |||
| 364 | sub Edit { | ||
| 365 | my($X) = shift; | ||
| 366 | my($query) = shift; | ||
| 367 | my($cgi_param) = shift; | ||
| 368 | my($schema) = shift; | ||
| 369 | my($rlabel); | ||
| 370 | my($self_url) = $query->self_url; | ||
| 371 | my($body_bgcolor) = (defined($cgi_param->{'web_body_bgcolor'})) ? | ||
| 372 | $cgi_param->{'web_body_bgcolor'} : 'silver'; | ||
| 373 | my($table) = $cgi_param->{'table'}; | ||
| 374 | my(%qbe_fields); | ||
| 375 | my($javascript); | ||
| 376 | my(%lookup_hash); | ||
| 377 | my($helppage) = $cgi_param->{'helppage'}; | ||
| 378 | my(%selects); | ||
| 379 | my($default); | ||
| 380 | my($required); | ||
| 381 | my(%replacement_field); | ||
| 382 | my(%readonly_field); | ||
| 383 | my(%nondisplay_field); | ||
| 384 | my($server) = $cgi_param->{'server'}; | ||
| 385 | my($database) = $cgi_param->{'database'}; | ||
| 386 | my($fullname) = $server . '.' . $database . '.' . $table; | ||
| 387 | my($td_label); | ||
| 388 | my(%values); | ||
| 389 | my(%lookup_fields); | ||
| 390 | my(%multi_lookup_fields); | ||
| 391 | my($multi_field); | ||
| 392 | my($field); | ||
| 393 | my($html_page); | ||
| 394 | my($ltable,$lkey,$ldescription); | ||
| 395 | my(%lookup_tables); | ||
| 396 | my($col_count); | ||
| 397 | my($html_changes); | ||
| 398 | my(@radio_edit); | ||
| 399 | my(%done_tuple); | ||
| 400 | my($rl_field); | ||
| 401 | my($rl_value); | ||
| 402 | my($table_onclick); | ||
| 403 | my($overview_onclick); | ||
| 404 | |||
| 405 | if (!$cgi_param->{'pqdebug'}) { | ||
| 406 | $self_url =~ s/\?.*$//; | ||
| 407 | } | ||
| 408 | undef %lookup_hash; | ||
| 409 | |||
| 410 | $html_changes .= execute_changes($X,$schema,$table,$query); | ||
| 411 | |||
| 412 | map { | ||
| 413 | ($rl_field, $rl_value) = split(';'); | ||
| 414 | $rlabel->{$rl_field} = $rl_value; | ||
| 415 | } split(',',$cgi_param->{'labels'}); | ||
| 416 | |||
| 417 | if (defined($query->param('radio_edit')) && | ||
| 418 | !defined($query->param('edit_lookup')) && | ||
| 419 | $query->param('radio_edit') ne $table) { | ||
| 420 | map { | ||
| 421 | if (/^pqold_/) { | ||
| 422 | $query->delete($_); | ||
| 423 | } | ||
| 424 | } $query->param; | ||
| 425 | $table = $query->param('radio_edit'); | ||
| 426 | $table =~ s/^\s*//g; | ||
| 427 | $table =~ s/\s*$//g; | ||
| 428 | $query->param('table',$table); | ||
| 429 | $fullname = $server . '.' . $database . '.' . $table; | ||
| 430 | } | ||
| 431 | |||
| 432 | |||
| 433 | %qbe_fields = qbe_fields($schema,$table); | ||
| 434 | |||
| 435 | # Output HTML | ||
| 436 | $html_page .= "\n"; | ||
| 437 | # $html_page .= '<H1 ALIGN="CENTER">Editing: ' . $fullname . "</H1>\n"; | ||
| 438 | %lookup_fields = find_lookups($schema,$table,$cgi_param); | ||
| 439 | map { | ||
| 440 | if (/\,/) { | ||
| 441 | $multi_field = $_; | ||
| 442 | map { | ||
| 443 | $multi_lookup_fields{$_} = $multi_field; | ||
| 444 | } split(','); | ||
| 445 | } | ||
| 446 | } (keys %lookup_fields); | ||
| 447 | |||
| 448 | $html_page .= $html_changes; | ||
| 449 | |||
| 450 | %values = get_values($X,$schema,$table,\%qbe_fields,$query); | ||
| 451 | |||
| 452 | if (defined($error_string)) { | ||
| 453 | $html_page .= "Database Error: $error_string<P>\n"; | ||
| 454 | } | ||
| 455 | |||
| 456 | if ($query->param('single_window') eq 'ON') { | ||
| 457 | $html_page .= $query->start_form(-method => 'POST', | ||
| 458 | -name => "PQEdit", | ||
| 459 | -onSubmit => "return check_keys()", | ||
| 460 | -action => $self_url); | ||
| 461 | } else { | ||
| 462 | $html_page .= $query->start_form(-method => 'POST', | ||
| 463 | -name => "PQEdit", | ||
| 464 | -onSubmit => "return check_keys()", | ||
| 465 | -action => $self_url, | ||
| 466 | -target => "pqedit$table"); | ||
| 467 | } | ||
| 468 | if (defined($query->param('begin_html_include'))) { | ||
| 469 | $html_page .= html_file_include($query->param('begin_html_include')); | ||
| 470 | } | ||
| 471 | if (defined($query->param('subedit_tables'))) { | ||
| 472 | if (defined($query->param('button_subedit'))) { | ||
| 473 | $html_page .= "<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLSPACING=\"0\">\n<TR>\n"; | ||
| 474 | $col_count = 1; | ||
| 475 | map { | ||
| 476 | if (!$lookup_tables{$_} && $_ ne $table) { | ||
| 477 | if ($query->param('single_window') eq 'ON') { | ||
| 478 | $html_page .= "<TD>" . | ||
| 479 | $query->submit(-name => 'edit_lookup', | ||
| 480 | -value => "Edit Table: $_") . | ||
| 481 | "</TD>\n"; | ||
| 482 | } else { | ||
| 483 | $html_page .= "<TD>" . | ||
| 484 | $query->submit(-name => 'edit_lookup', | ||
| 485 | -onClick => "this.form.target='pqedit$_'", | ||
| 486 | -value => "Edit Table: $_") . | ||
| 487 | "</TD>\n"; | ||
| 488 | } | ||
| 489 | if (++$col_count > 2) { | ||
| 490 | $col_count = 1; | ||
| 491 | $html_page .= "</TR>\n</TR>\n"; | ||
| 492 | } | ||
| 493 | } | ||
| 494 | } split(',',$query->param('subedit_tables')); | ||
| 495 | $html_page .= "</TR>\n</TABLE>\n<HR>"; | ||
| 496 | } else { | ||
| 497 | push @radio_edit, ($table); | ||
| 498 | map { | ||
| 499 | if ($_ ne $table) { | ||
| 500 | push @radio_edit, ($_); | ||
| 501 | } | ||
| 502 | } split(',',$query->param('subedit_tables')); | ||
| 503 | if (@radio_edit > 1) { | ||
| 504 | $html_page .= "<BIG><B>Next edit table:</B></BIG>\n"; | ||
| 505 | $html_page .= $query->radio_group(-name => 'radio_edit', | ||
| 506 | -values => \@radio_edit, | ||
| 507 | -default => $table, | ||
| 508 | -columns => 6); | ||
| 509 | $html_page .= "\n"; | ||
| 510 | } | ||
| 511 | } | ||
| 512 | } | ||
| 513 | $html_page .= '<HR><TABLE BORDER="0" WIDTH="100%" CELLSPACING="0">'."\n"; | ||
| 514 | |||
| 515 | # set up onClick string for single window or multi window modes | ||
| 516 | if ($query->param('single_window') eq 'ON') { | ||
| 517 | $table_onclick = ''; | ||
| 518 | $overview_onclick = ''; | ||
| 519 | } else { | ||
| 520 | $table_onclick = " | ||
| 521 | onClick=\"this.form.target='pqedit$table'\""; | ||
| 522 | $overview_onclick = " | ||
| 523 | onClick=\"this.form.target='overview$table'\""; | ||
| 524 | } | ||
| 525 | $html_page .= <<"EndHTML"; | ||
| 526 | <tr> | ||
| 527 | <td colspan="3" align="center"> | ||
| 528 | <input TYPE="submit" VALUE="First Entry"$table_onclick | ||
| 529 | NAME="First" tabindex="7" style="background-color: gray"> | ||
| 530 | <input TYPE="submit" VALUE="Search for Entry"$table_onclick | ||
| 531 | NAME="retrieve" tabindex="8" style="background-color: gray"> | ||
| 532 | <input TYPE="submit" VALUE="View Search Set"$overview_onclick | ||
| 533 | NAME="Overview" tabindex="8" style="background-color: gray"> | ||
| 534 | <input TYPE="submit" VALUE="Next Entry >"$table_onclick | ||
| 535 | NAME="Next" tabindex="9" style="background-color: gray"> | ||
| 536 | </td> | ||
| 537 | </tr> | ||
| 538 | EndHTML | ||
| 539 | $html_page .= '<TR><TD COLSPAN="3"><HR></TD></TR>'."\n"; | ||
| 540 | $html_page .= <<"EndHTML"; | ||
| 541 | <tr> | ||
| 542 | <th colspan=\"2\"> | ||
| 543 | <P ALIGN="LEFT"><BIG>Searchable and Editable Fields: </BIG> | ||
| 544 | <INPUT TYPE="button" NAME="search_help" VALUE="Help on Searching" | ||
| 545 | STYLE="background-color: gray" | ||
| 546 | ONCLICK="alert('Click on the check marks in front of searchable fields to have them not be used in the search. In a text search field, use a question mark, ?, to represent any single character. Use an asterik, *, to represent any string of zero or more characters. Use brackets, [ ], to enclose a range of characters to match as a single character, such as [a-f], or a set of characters such as [a2Br]. [0-z] matches 0-9, A-Z, and a-z (and several punctuation characters). The caret, ^, is used to match a single character that is not in a range of characters. For example, [^a-f] matches any character which is not the letters a through f. ')"> | ||
| 547 | </P> | ||
| 548 | </th> | ||
| 549 | <th><p align="right"><em>* Required field.</em><BR><em># Leave field blank to autoassign value.</em></p></th> | ||
| 550 | </tr> | ||
| 551 | EndHTML | ||
| 552 | undef %done_tuple; | ||
| 553 | %replacement_field = Replacement_Fields($table,$query); | ||
| 554 | %readonly_field = Readonly_Fields($table,$query); | ||
| 555 | %nondisplay_field = Nondisplay_Fields($table,$query,$schema); | ||
| 556 | map { | ||
| 557 | $field = $_; | ||
| 558 | if (defined($qbe_fields{$field}) && | ||
| 559 | !defined($done_tuple{$field})) { | ||
| 560 | $required = ($replacement_field{$field}) ? '#' : | ||
| 561 | ( ($schema->Field_Null($table,$field)) ? '' : '*'); | ||
| 562 | if (defined($multi_lookup_fields{$field})) { | ||
| 563 | ($ltable,$lkey,$ldescription) = | ||
| 564 | split("\t",$lookup_fields{$multi_lookup_fields{$field}}); | ||
| 565 | %lookup_hash = | ||
| 566 | get_multi_lookup($X,$cgi_param,$ltable,$lkey,$ldescription); | ||
| 567 | if (defined(%lookup_hash)) { | ||
| 568 | $multi_field = | ||
| 569 | join('_____',split(',',$multi_lookup_fields{$field})); | ||
| 570 | map { | ||
| 571 | $done_tuple{$_} = 1; | ||
| 572 | } split(',',$multi_lookup_fields{$field}); | ||
| 573 | $values{$multi_field} = | ||
| 574 | join("\t", | ||
| 575 | @values{split(',',$multi_lookup_fields{$field})}); | ||
| 576 | $field = $multi_field; | ||
| 577 | } | ||
| 578 | } else { | ||
| 579 | ($ltable,$lkey,$ldescription) = split("\t",$lookup_fields{$field}); | ||
| 580 | %lookup_hash = get_lookup($X,$cgi_param,$ltable,$lkey,$ldescription); | ||
| 581 | } | ||
| 582 | $td_label = TD_Field_Label($field,$required,$rlabel,$helppage); | ||
| 583 | $lookup_tables{$ltable} = 1; | ||
| 584 | if (defined(%lookup_hash) && $required ne '*') { | ||
| 585 | $lookup_hash{''} = '<Select A Value>'; | ||
| 586 | } | ||
| 587 | $html_page .= Edit_Row($field,$td_label,$values{$field},$table, | ||
| 588 | $schema,\%lookup_hash,$cgi_param,$ltable,1, | ||
| 589 | \%readonly_field, \%nondisplay_field); | ||
| 590 | if (defined(%lookup_hash)) { | ||
| 591 | $selects{$field} = 1; | ||
| 592 | } | ||
| 593 | undef %lookup_hash; | ||
| 594 | } | ||
| 595 | } $schema->Table_Fields($table), $schema->View_Fields($table); | ||
| 596 | |||
| 597 | $html_page .= '<TR><TD COLSPAN="3"><HR></TD></TR>'."\n"; | ||
| 598 | $html_page .= <<"EndHTML"; | ||
| 599 | <tr> | ||
| 600 | <th colspan=\"3\" align=\"center\"> | ||
| 601 | <P ALIGN=\"LEFT\"><BIG>Nonsearchable but Editable Fields:</BIG></P> | ||
| 602 | </th> | ||
| 603 | </tr> | ||
| 604 | EndHTML | ||
| 605 | map { | ||
| 606 | $field = $_; | ||
| 607 | if (!defined($qbe_fields{$field}) && | ||
| 608 | !defined($done_tuple{$field})) { | ||
| 609 | $required = ($replacement_field{$field}) ? '#' : | ||
| 610 | ( ($schema->Field_Null($table,$field)) ? '' : '*'); | ||
| 611 | if (defined($multi_lookup_fields{$field})) { | ||
| 612 | ($ltable,$lkey,$ldescription) = | ||
| 613 | split("\t",$lookup_fields{$multi_lookup_fields{$field}}); | ||
| 614 | %lookup_hash = | ||
| 615 | get_multi_lookup($X,$cgi_param,$ltable,$lkey,$ldescription); | ||
| 616 | if (defined(%lookup_hash)) { | ||
| 617 | $multi_field = | ||
| 618 | join('_____',split(',',$multi_lookup_fields{$field})); | ||
| 619 | map { | ||
| 620 | $done_tuple{$_} = 1; | ||
| 621 | } split(',',$multi_lookup_fields{$field}); | ||
| 622 | $values{$multi_field} = | ||
| 623 | join("\t", | ||
| 624 | @values{split(',',$multi_lookup_fields{$field})}); | ||
| 625 | $field = $multi_field; | ||
| 626 | } | ||
| 627 | } else { | ||
| 628 | ($ltable,$lkey,$ldescription) = split("\t",$lookup_fields{$field}); | ||
| 629 | %lookup_hash = get_lookup($X,$cgi_param,$ltable,$lkey,$ldescription); | ||
| 630 | } | ||
| 631 | $td_label = TD_Field_Label($field,$required,$rlabel,$helppage); | ||
| 632 | $lookup_tables{$ltable} = 1; | ||
| 633 | if (defined(%lookup_hash) && $required ne '*') { | ||
| 634 | $lookup_hash{''} = '<Select A Value>'; | ||
| 635 | } | ||
| 636 | $html_page .= Edit_Row($field,$td_label,$values{$field},$table, | ||
| 637 | $schema,\%lookup_hash,$cgi_param,$ltable, | ||
| 638 | undef,\%readonly_field, \%nondisplay_field); | ||
| 639 | if (defined(%lookup_hash)) { | ||
| 640 | $selects{$field} = 1; | ||
| 641 | } | ||
| 642 | undef %lookup_hash; | ||
| 643 | } | ||
| 644 | } $schema->Table_Fields($table), $schema->View_Fields($table); | ||
| 645 | |||
| 646 | $html_page .= "</TABLE>\n"; | ||
| 647 | |||
| 648 | $html_page .= '<HR><TABLE BORDER="0" WIDTH="100%" CELLSPACING="0">'."\n"; | ||
| 649 | $html_page .= <<"EndHTML"; | ||
| 650 | <tr> | ||
| 651 | <td align="center"> | ||
| 652 | <input TYPE="submit" VALUE="Add New (Insert)"$table_onclick | ||
| 653 | NAME="Insert" tabindex="10" style="background-color: gray"> | ||
| 654 | <input TYPE="submit" VALUE="Update"$table_onclick | ||
| 655 | NAME="Update" tabindex="11" style="background-color: gray"> | ||
| 656 | <input TYPE="submit" VALUE="Delete"$table_onclick | ||
| 657 | NAME="Delete" tabindex="12" style="background-color: gray"> | ||
| 658 | </td> | ||
| 659 | </tr> | ||
| 660 | <tr> | ||
| 661 | <td align="center"><p><input TYPE="reset" | ||
| 662 | VALUE="Reset Form Values" NAME="Reset Form" tabindex="13" style="background-color: gray"> | ||
| 663 | </td> | ||
| 664 | </tr> | ||
| 665 | <td align="center"> | ||
| 666 | <input TYPE="submit" VALUE="Clear Form"$table_onclick | ||
| 667 | NAME="clear" tabindex="14" style="background-color: gray"></p> | ||
| 668 | </td> | ||
| 669 | </tr> | ||
| 670 | EndHTML | ||
| 671 | |||
| 672 | |||
| 673 | $html_page .= "</TABLE><HR>\n"; | ||
| 674 | if (defined($query->param('middle_html_include'))) { | ||
| 675 | $html_page .= html_file_include($query->param('middle_html_include')); | ||
| 676 | } | ||
| 677 | $javascript = pqedit_javascript($schema,$table,{},\%qbe_fields,\%selects,\%multi_lookup_fields); | ||
| 678 | |||
| 679 | print "\n"; | ||
| 680 | print $query->start_html(-title => "PQ Edit: $fullname", | ||
| 681 | -author => 'brian@ibc.wustl.edu', | ||
| 682 | -script => $javascript, | ||
| 683 | -BGCOLOR => $body_bgcolor, | ||
| 684 | -onload => 'window.focus();'); # Focus this page | ||
| 685 | print $html_page; | ||
| 686 | print PQHidden_Parameters($query,$cgi_param); | ||
| 687 | # Pass old values of primary key fields or of all fields | ||
| 688 | # so that we can do updates | ||
| 689 | map { | ||
| 690 | $query->delete("pqold_$_"); | ||
| 691 | print $query->hidden("pqold_$_",$values{$_}) . "\n"; | ||
| 692 | } (($schema->Primary_Keys($table) > 0) ? | ||
| 693 | $schema->Primary_Keys($table) : (keys %values)); | ||
| 694 | if (defined($query->param('end_html_include'))) { | ||
| 695 | print html_file_include($query->param('end_html_include')); | ||
| 696 | } | ||
| 697 | print "\n" . $query->end_form; | ||
| 698 | print "\n" . $query->end_html; | ||
| 699 | } | ||
| 700 | |||
| 701 | # | ||
| 702 | # execute_changes($X,$schema,$table,$query); | ||
| 703 | # | ||
| 704 | |||
| 705 | sub execute_changes { | ||
| 706 | my($X) = shift; | ||
| 707 | my($schema) = shift; | ||
| 708 | my($table) = shift; | ||
| 709 | my($query) = shift; | ||
| 710 | my($field); | ||
| 711 | my(@fields); | ||
| 712 | my(@values); | ||
| 713 | my(@update); | ||
| 714 | my(@delete_where); | ||
| 715 | my(@update_where); | ||
| 716 | my($value); | ||
| 717 | my($command); | ||
| 718 | my($show); | ||
| 719 | my($html_page); | ||
| 720 | |||
| 721 | if (!defined($query->param('Insert')) && | ||
| 722 | !defined($query->param('Update')) && | ||
| 723 | !defined($query->param('Delete'))) { | ||
| 724 | return; | ||
| 725 | } | ||
| 726 | if (defined($query->param('Insert')) || | ||
| 727 | defined($query->param('Update'))) { | ||
| 728 | Replace_Fields($X,$table,$query,$schema); | ||
| 729 | } | ||
| 730 | map { | ||
| 731 | if (/pq_/) { | ||
| 732 | $field = $_; | ||
| 733 | $field =~ s/^pq_//; | ||
| 734 | $value = $query->param($_); | ||
| 735 | $value =~ s/\t/ /g; | ||
| 736 | if (!defined($value) || | ||
| 737 | $value eq '') { | ||
| 738 | $value = 'NULL'; | ||
| 739 | } else { | ||
| 740 | $value = $schema->Quote_Field($table,$field,$value); | ||
| 741 | } | ||
| 742 | if (! $schema->Field_Identity($table,$field)) { | ||
| 743 | push @fields, ($field); | ||
| 744 | push @values, ($value); | ||
| 745 | push @update, ("$field=$value"); | ||
| 746 | } | ||
| 747 | if (defined($query->param("pqold_$field"))) { | ||
| 748 | push @delete_where, ("$field=$value"); | ||
| 749 | } | ||
| 750 | } | ||
| 751 | } $query->param; | ||
| 752 | map { | ||
| 753 | if (/pqold_/) { | ||
| 754 | $field = $_; | ||
| 755 | $field =~ s/^pqold_//; | ||
| 756 | $value = $query->param($_); | ||
| 757 | if (!defined($value) || | ||
| 758 | $value eq '') { | ||
| 759 | $value = 'NULL'; | ||
| 760 | } else { | ||
| 761 | $value = $schema->Quote_Field($table,$field,$value); | ||
| 762 | } | ||
| 763 | push @update_where, ("$field=$value"); | ||
| 764 | } | ||
| 765 | } $query->param; | ||
| 766 | if (defined($query->param('Insert'))) { | ||
| 767 | $show = 'insert'; | ||
| 768 | $command = "insert into $table \n" . | ||
| 769 | ' ( ' . join(', ',@fields) . " ) \n" . | ||
| 770 | ' values( ' . join(', ',@values) . ' ) '; | ||
| 771 | } elsif (defined($query->param('Update'))) { | ||
| 772 | $show = 'update'; | ||
| 773 | $command = "update $table set " . join(', ',@update) . | ||
| 774 | ' where ' . join(' and ',@update_where); | ||
| 775 | } elsif (defined($query->param('Delete'))) { | ||
| 776 | $show = 'delete'; | ||
| 777 | $command = "delete from $table " . | ||
| 778 | ' where ' . join(' and ',@delete_where); | ||
| 779 | } | ||
| 780 | if ($query->param('pqdebug')) { | ||
| 781 | $html_page .= "<P>$command<P>\n"; | ||
| 782 | } | ||
| 783 | ( $X->Sql($command) ) | ||
| 784 | or ($html_page .= "<P>Unable to $show entry<P>\n"); | ||
| 785 | if ($X->RowCount() > 0) { | ||
| 786 | $html_page .= "<P>Successful $show of " . $X->RowCount() . " entry.<P>\n"; | ||
| 787 | } else { | ||
| 788 | $html_page .= "<P><BIG><BIG><B>Unsuccessful $show:</B></BIG></BIG><P> $error_string<P>\n"; | ||
| 789 | undef $error_string; | ||
| 790 | } | ||
| 791 | while ($X->More_Results()) {} | ||
| 792 | return $html_page; | ||
| 793 | } | ||
| 794 | |||
| 795 | |||
| 796 | # | ||
| 797 | # $where = Next_Where($connection,$schema,$table,$cgi_query); | ||
| 798 | # | ||
| 799 | |||
| 800 | sub Next_Where { | ||
| 801 | my($X) = shift; | ||
| 802 | my($schema) = shift; | ||
| 803 | my($table) = shift; | ||
| 804 | my($query) = shift; | ||
| 805 | my(@row); | ||
| 806 | my($command); | ||
| 807 | my($i); | ||
| 808 | my(%value); | ||
| 809 | my($where); | ||
| 810 | my($value); | ||
| 811 | my($qvalue); | ||
| 812 | my($percent) = '%'; | ||
| 813 | my($underscore) = '_'; | ||
| 814 | my(@primary_keys) = (($schema->Primary_Keys($table) > 0) ? | ||
| 815 | $schema->Primary_Keys($table) : | ||
| 816 | $schema->Table_Fields($table)); | ||
| 817 | my($last); | ||
| 818 | my($rowcount); | ||
| 819 | |||
| 820 | map { | ||
| 821 | $value = $query->param("pq_$_"); | ||
| 822 | if (defined($value) && | ||
| 823 | $value !~ /^\s*$/ && | ||
| 824 | $value ne '_NULL_') { | ||
| 825 | $value =~ s/\*/$percent/g; | ||
| 826 | $value =~ s/\?/$underscore/g; | ||
| 827 | $qvalue = $schema->Quote_Field($table,$_,$value); | ||
| 828 | $value{$_} = $qvalue; | ||
| 829 | } | ||
| 830 | } @primary_keys; | ||
| 831 | $last = $#primary_keys; | ||
| 832 | |||
| 833 | do { | ||
| 834 | $where = 'where '; | ||
| 835 | for ($i = 0; $i <= $last;$i++) { | ||
| 836 | $_ = $primary_keys[$i]; | ||
| 837 | if (defined($value{$_})) { | ||
| 838 | if ($i == $last) { | ||
| 839 | $where .= ' and '.$_. ' > ' .$value{$_}; | ||
| 840 | } else { | ||
| 841 | $where .= ' and '.$_. ' = ' .$value{$_}; | ||
| 842 | } | ||
| 843 | } | ||
| 844 | } | ||
| 845 | $last--; | ||
| 846 | $where =~ s/^where\s+and\s+/where /; | ||
| 847 | if ($where =~ /^\s*where\s*$/ ) { | ||
| 848 | undef $where; | ||
| 849 | } | ||
| 850 | |||
| 851 | if ($query->param('server_type') eq 'mSQL') { | ||
| 852 | $command = "select 1 from $table $where"; | ||
| 853 | } else { | ||
| 854 | $command = "select count(*) from $table $where"; | ||
| 855 | } | ||
| 856 | |||
| 857 | $X->Sql($command); | ||
| 858 | @row = $X->NextRow(); | ||
| 859 | while ($X->More_Results()) {} | ||
| 860 | } while(!defined($row[0]) || $row[0] == 0); | ||
| 861 | return $where; | ||
| 862 | } | ||
| 863 | |||
| 864 | |||
| 865 | # | ||
| 866 | # %values = get_values($connection,$schema,$table,$cgi_query); | ||
| 867 | # | ||
| 868 | |||
| 869 | sub get_values { | ||
| 870 | my($X) = shift; | ||
| 871 | my($schema) = shift; | ||
| 872 | my($table) = shift; | ||
| 873 | my($qbef) = shift; | ||
| 874 | my($query) = shift; | ||
| 875 | my(@field) = $schema->Table_Fields($table); | ||
| 876 | my(@row); | ||
| 877 | my($command); | ||
| 878 | my($i); | ||
| 879 | my(%value); | ||
| 880 | my($where); | ||
| 881 | my($value); | ||
| 882 | my($qvalue); | ||
| 883 | my($rowcount) = 1; | ||
| 884 | my($current_row) = 0; | ||
| 885 | my($direction) = ' = '; | ||
| 886 | my($col_value); | ||
| 887 | my($percent) = '%'; | ||
| 888 | my($underscore) = '_'; | ||
| 889 | my(@primary_keys) = (($schema->Primary_Keys($table) > 0) ? | ||
| 890 | $schema->Primary_Keys($table) : | ||
| 891 | $schema->Table_Fields($table)); | ||
| 892 | my(@pk_value); | ||
| 893 | my($field); | ||
| 894 | |||
| 895 | if (defined($query->param('clear')) || | ||
| 896 | defined($query->param('Delete')) ) { | ||
| 897 | map { | ||
| 898 | if (/pq_/) { | ||
| 899 | $query->delete($_); | ||
| 900 | } | ||
| 901 | } $query->param; | ||
| 902 | return %value; | ||
| 903 | } | ||
| 904 | if (!defined($query->param('First')) && | ||
| 905 | !defined($query->param('Next')) && | ||
| 906 | !defined($query->param('pk_value'))) { | ||
| 907 | $where = 'where '; | ||
| 908 | map { | ||
| 909 | $value = $query->param("pq_$_"); | ||
| 910 | if (defined($query->param("pqsearch_$_")) && | ||
| 911 | defined($value) && | ||
| 912 | $value !~ /^\s*$/ && | ||
| 913 | $value ne '_NULL_') { | ||
| 914 | $value =~ s/\*/$percent/g; | ||
| 915 | $value =~ s/\?/$underscore/g; | ||
| 916 | $qvalue = $schema->Quote_Field($table,$_,$value); | ||
| 917 | if ($direction eq ' = ' && | ||
| 918 | $qvalue ne $value && | ||
| 919 | $schema->Field_Type($table,$_) !~ /[Dd]ate/) { | ||
| 920 | $where .= ' and '.$_. ' LIKE ' .$qvalue; | ||
| 921 | } else { | ||
| 922 | $where .= ' and '.$_. $direction .$qvalue; | ||
| 923 | } | ||
| 924 | } | ||
| 925 | } (keys %{$qbef}); | ||
| 926 | $where =~ s/^where\s+and\s+/where /; | ||
| 927 | if ($where =~ /^\s*where\s*$/ ) { | ||
| 928 | undef $where; | ||
| 929 | } | ||
| 930 | } | ||
| 931 | if (defined($query->param('pk_value'))) { | ||
| 932 | @pk_value = split("\t",$query->param('pk_value')); | ||
| 933 | $qvalue = $schema->Quote_Field($table, | ||
| 934 | $primary_keys[0],$pk_value[0]); | ||
| 935 | $where = 'where ' . $primary_keys[0] . ' = ' . $qvalue; | ||
| 936 | for ($i = 1; $i <= $#primary_keys;$i++) { | ||
| 937 | $qvalue = $schema->Quote_Field($table, | ||
| 938 | $primary_keys[$i],$pk_value[$i]); | ||
| 939 | $where .= ' and ' . $primary_keys[$i] . ' = ' . $qvalue; | ||
| 940 | } | ||
| 941 | } | ||
| 942 | |||
| 943 | if (defined($query->param('Next'))) { | ||
| 944 | $rowcount = 1; | ||
| 945 | $where = Next_Where($X,$schema,$table,$query); | ||
| 946 | } | ||
| 947 | if (defined($query->param('Overview')) || | ||
| 948 | defined($query->param('overview'))) { | ||
| 949 | $rowcount = 1000; | ||
| 950 | } | ||
| 951 | |||
| 952 | if ($query->param('server_type') eq 'oracle') { | ||
| 953 | if (!defined($where)) { | ||
| 954 | $where = " where ROWNUM <= $rowcount "; | ||
| 955 | } else { | ||
| 956 | $where .= " and ROWNUM <= $rowcount "; | ||
| 957 | } | ||
| 958 | $command = <<"EndQuery"; | ||
| 959 | select * from $table $where | ||
| 960 | EndQuery | ||
| 961 | } elsif ($query->param('server_type') eq 'Pg') { | ||
| 962 | $command = <<"EndQuery"; | ||
| 963 | SELECT * FROM $table $where LIMIT $rowcount | ||
| 964 | EndQuery | ||
| 965 | } else { | ||
| 966 | $command = <<"EndQuery"; | ||
| 967 | set rowcount $rowcount | ||
| 968 | select * from $table $where | ||
| 969 | set rowcount 0 | ||
| 970 | EndQuery | ||
| 971 | } | ||
| 972 | if ($query->param('pqdebug')) { | ||
| 973 | $error_string .= "DEBUG> $command<P>\n"; | ||
| 974 | } | ||
| 975 | $X->Sql($command); | ||
| 976 | do { | ||
| 977 | while(@row = $X->NextRow()) { | ||
| 978 | if (++$current_row > $rowcount) { | ||
| 979 | last; | ||
| 980 | } | ||
| 981 | if ($X->Regular_Row()) { | ||
| 982 | foreach $col_value (@row) { | ||
| 983 | $col_value =~ s/\t/ /g; | ||
| 984 | } | ||
| 985 | for ($i = 0; $i <= $#field;$i++) { | ||
| 986 | $_ = $field[$i]; | ||
| 987 | $row[$i] =~ s/^\s*//g; | ||
| 988 | $row[$i] =~ s/\s*$//g; | ||
| 989 | if ($current_row <= 1) { | ||
| 990 | $value{$_} = $row[$i]; | ||
| 991 | } else { | ||
| 992 | $value{$_} .= "\t".$row[$i]; | ||
| 993 | } | ||
| 994 | } | ||
| 995 | } | ||
| 996 | } | ||
| 997 | } while ($X->More_Results()); | ||
| 998 | if (defined($query->param('retrieve')) ) { | ||
| 999 | if ($current_row < 1) { | ||
| 1000 | $error_string .= "<B>Search Matched No Entries</B><P>\n"; | ||
| 1001 | } | ||
| 1002 | map { | ||
| 1003 | if (/pq_/) { | ||
| 1004 | $query->delete($_); | ||
| 1005 | } | ||
| 1006 | } $query->param; | ||
| 1007 | } | ||
| 1008 | return %value; | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | |||
| 1012 | # | ||
| 1013 | # Edit_Row($_,$td_label,$default,$table,$schema,\%lookup_hash,$cgi_param,$ltable); | ||
| 1014 | # | ||
| 1015 | |||
| 1016 | sub Edit_Row { | ||
| 1017 | my($field) = shift; | ||
| 1018 | my($td_label) = shift; | ||
| 1019 | my($default) = shift; | ||
| 1020 | my($table) = shift; | ||
| 1021 | my($schema) = shift; | ||
| 1022 | my($lookup_hash) = shift; | ||
| 1023 | my($cgi_param) = shift; | ||
| 1024 | my($lookup_table) = shift; | ||
| 1025 | my($search) = shift; | ||
| 1026 | my($readonly) = shift; | ||
| 1027 | my($nondisplay) = shift; | ||
| 1028 | my($output); | ||
| 1029 | my($display_length); | ||
| 1030 | my(@keys); | ||
| 1031 | my($lookup_button); | ||
| 1032 | my($textarea_rows); | ||
| 1033 | my($search_click); | ||
| 1034 | my($display_text); | ||
| 1035 | my($break); | ||
| 1036 | |||
| 1037 | if (defined($query->param("pq_$field")) && | ||
| 1038 | !defined($query->param("retrieve"))) { | ||
| 1039 | $query->param("pq_$field",$default); | ||
| 1040 | } | ||
| 1041 | if ($schema->Field_Type($table,$field) =~ /bit/) { | ||
| 1042 | $lookup_hash = { 0 => 'False', 1 => 'True' }; | ||
| 1043 | } | ||
| 1044 | if ($search) { | ||
| 1045 | $search_click = $query->checkbox(-name => "pqsearch_$field", | ||
| 1046 | -checked => 'checked', | ||
| 1047 | -value => 'ON', | ||
| 1048 | -label => ''); | ||
| 1049 | } | ||
| 1050 | if ($nondisplay->{$field}) { | ||
| 1051 | # The field shouldn't be processed-- | ||
| 1052 | # it doesn't matter for an insert, update or delete | ||
| 1053 | # $output .= $query->hidden("pq_$field", $default); | ||
| 1054 | } elsif ($readonly->{$field}) { | ||
| 1055 | $display_length = $schema->Field_Width($table,$field); | ||
| 1056 | $output .= "<TR>$td_label"; | ||
| 1057 | if ($display_length > $cgi_param->{'web_textarea_columns'}) { | ||
| 1058 | $display_text = $default; | ||
| 1059 | $break = $cgi_param->{'web_textarea_columns'}; | ||
| 1060 | $display_text =~ s/(.{$break})/$1<BR>/g; | ||
| 1061 | $output .= "<TD>". | ||
| 1062 | $search_click . | ||
| 1063 | "<B>$display_text</B>" . | ||
| 1064 | $query->hidden("pq_$field", $default) . | ||
| 1065 | "</TD></TR>\n"; | ||
| 1066 | } else { | ||
| 1067 | $output .= "<TD>". | ||
| 1068 | $search_click . | ||
| 1069 | "<B>$default</B>" . | ||
| 1070 | $query->hidden("pq_$field", $default) . | ||
| 1071 | "</TD></TR>\n"; | ||
| 1072 | } | ||
| 1073 | } elsif (defined(%{$lookup_hash})) { | ||
| 1074 | @keys = (sort (keys %{$lookup_hash})); | ||
| 1075 | $output .= "<TR>$td_label"; | ||
| 1076 | if (defined($lookup_table) && $lookup_table ne '') { | ||
| 1077 | if ($query->param('single_window') eq 'ON') { | ||
| 1078 | $lookup_button = "</TD><TD ALIGN=\"RIGHT\">" . | ||
| 1079 | $query->submit(-name => 'edit_lookup', | ||
| 1080 | -value => "Edit Table: $lookup_table"); | ||
| 1081 | } else { | ||
| 1082 | $lookup_button = "</TD><TD ALIGN=\"RIGHT\">" . | ||
| 1083 | $query->submit(-name => 'edit_lookup', | ||
| 1084 | -onClick => "this.form.target='pqedit$lookup_table'", | ||
| 1085 | -value => "Edit Table: $lookup_table"); | ||
| 1086 | } | ||
| 1087 | } | ||
| 1088 | $output .= "<TD>". | ||
| 1089 | $search_click . | ||
| 1090 | $query->popup_menu(-name => "pq_$field", | ||
| 1091 | -values => \@keys, | ||
| 1092 | -default => $default, | ||
| 1093 | -labels => $lookup_hash) . | ||
| 1094 | "$lookup_button</TD></TR>\n"; | ||
| 1095 | undef $lookup_button; | ||
| 1096 | } else { | ||
| 1097 | $display_length = $schema->Field_Width($table,$field); | ||
| 1098 | $output .= "<TR>$td_label"; | ||
| 1099 | if ($display_length > $cgi_param->{'web_textarea_columns'}) { | ||
| 1100 | $textarea_rows = (int $display_length / | ||
| 1101 | $cgi_param->{'web_textarea_columns'} | ||
| 1102 | < $cgi_param->{'web_textarea_rows'}) ? | ||
| 1103 | int $display_length / $cgi_param->{'web_textarea_columns'} | ||
| 1104 | : $cgi_param->{'web_textarea_rows'}; | ||
| 1105 | $output .= "<TD>". | ||
| 1106 | $search_click . | ||
| 1107 | $query->textarea(-name => "pq_$field", | ||
| 1108 | -default => $default, | ||
| 1109 | -rows => $textarea_rows, | ||
| 1110 | -columns => $cgi_param->{'web_textarea_columns'}, | ||
| 1111 | -size => $display_length, | ||
| 1112 | -maxlength => $display_length, | ||
| 1113 | -LANGUAGE => "JavaScript", | ||
| 1114 | -OnFocus => 'PQEdit.pq_'.$field.'.select()') . | ||
| 1115 | "</TD></TR>\n"; | ||
| 1116 | } else { | ||
| 1117 | $output .= "<TD>". | ||
| 1118 | $search_click . | ||
| 1119 | $query->textfield(-name => "pq_$field", | ||
| 1120 | -default => $default, | ||
| 1121 | -size => $display_length+1, | ||
| 1122 | -maxlength => $display_length, | ||
| 1123 | -LANGUAGE => "JavaScript", | ||
| 1124 | -OnFocus => 'PQEdit.pq_'.$field.'.select()') . | ||
| 1125 | "</TD></TR>\n"; | ||
| 1126 | } | ||
| 1127 | } | ||
| 1128 | return $output; | ||
| 1129 | } | ||
| 1130 | |||
| 1131 | # | ||
| 1132 | # qbe_fields($schema,$table) | ||
| 1133 | # | ||
| 1134 | |||
| 1135 | sub qbe_fields { | ||
| 1136 | my($schema) = shift; | ||
| 1137 | my($table) = shift; | ||
| 1138 | my($lqbef); | ||
| 1139 | my($n); | ||
| 1140 | my(%qbef); | ||
| 1141 | my(%nqbef); | ||
| 1142 | |||
| 1143 | map { | ||
| 1144 | $lqbef = ' '; | ||
| 1145 | $n = 0; | ||
| 1146 | map { | ||
| 1147 | s/^\s//g; | ||
| 1148 | s/\s$//g; | ||
| 1149 | if (!defined($qbef{$_}) || $nqbef{$_} > $n) { | ||
| 1150 | $qbef{$_} = "$lqbef\t$n"; | ||
| 1151 | $nqbef{$_} = $n; | ||
| 1152 | } | ||
| 1153 | $lqbef = $_; | ||
| 1154 | $n++; | ||
| 1155 | } split(','); | ||
| 1156 | } $schema->Keys($table,'User Table'); | ||
| 1157 | return %qbef; | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | # | ||
| 1161 | # $javascript = pqedit_javascript($schema,$table,\%label,\%qbe_fields,\%selects,\%multi_lookup_fields); | ||
| 1162 | # | ||
| 1163 | |||
| 1164 | sub pqedit_javascript { | ||
| 1165 | my($schema) = shift; | ||
| 1166 | my($table) = shift; | ||
| 1167 | my($rlabel) = shift; | ||
| 1168 | my($qbef) = shift; | ||
| 1169 | my($selects) = shift; | ||
| 1170 | my($multi_lookup_fields) = shift; | ||
| 1171 | my(%done_multi); | ||
| 1172 | my($multi_field); | ||
| 1173 | my($javascript) = <<"EndQuery"; | ||
| 1174 | function check_keys() { | ||
| 1175 | var r; | ||
| 1176 | r = ""; | ||
| 1177 | formObj = document.PQEdit; | ||
| 1178 | EndQuery | ||
| 1179 | my($label,$depends,$indent); | ||
| 1180 | my($depend_label,$check_name,$depends_name); | ||
| 1181 | my(@form_fields); | ||
| 1182 | |||
| 1183 | map { | ||
| 1184 | if (defined($qbef->{$_}) && | ||
| 1185 | !defined($multi_lookup_fields->{$_})) { | ||
| 1186 | push @form_fields, ($_); | ||
| 1187 | } | ||
| 1188 | } $schema->Table_Fields($table), $schema->View_Fields($table); | ||
| 1189 | map { | ||
| 1190 | $label = (defined($rlabel->{$_})) ? $rlabel->{$_} : uc_string($_); | ||
| 1191 | ($depends, $indent) = split("\t",$qbef->{$_}); | ||
| 1192 | if ($depends ne ' ') { | ||
| 1193 | # if (defined($multi_lookup_fields->{$depends})) { | ||
| 1194 | # $multi_field = $multi_lookup_fields->{$depends}; | ||
| 1195 | # $multi_field =~ s/\,/\_____/g; | ||
| 1196 | # $depends = $multi_field; | ||
| 1197 | # } | ||
| 1198 | $depend_label = (defined($rlabel->{$depends})) ? | ||
| 1199 | $rlabel->{$depends} : uc_string($depends); | ||
| 1200 | $check_name = ($selects->{$_}) ? | ||
| 1201 | "formObj.pq_$_.".'options['."formObj.pq_$_.selectedIndex".'].value' | ||
| 1202 | : "formObj.pq_$_.value"; | ||
| 1203 | $depends_name = ($selects->{$depends}) ? | ||
| 1204 | "formObj.pq_$depends.".'options['."formObj.pq_$depends.selectedIndex".'].value' | ||
| 1205 | : "formObj.pq_$depends.value"; | ||
| 1206 | if (!defined($multi_lookup_fields->{$depends})) { | ||
| 1207 | $javascript .= <<"EndQuery"; | ||
| 1208 | if ( ($check_name != "" && | ||
| 1209 | $check_name != "_NULL_" ) && | ||
| 1210 | ($depends_name == "" || | ||
| 1211 | $depends_name == "_NULL_" ) ) { | ||
| 1212 | r += "In order to specify $label, a value needs to be selected for $depend_label. "; | ||
| 1213 | } | ||
| 1214 | EndQuery | ||
| 1215 | } | ||
| 1216 | if (!defined($multi_lookup_fields->{$depends})) { | ||
| 1217 | $check_name = "formObj.pqsearch_$_.checked"; | ||
| 1218 | $depends_name = "formObj.pqsearch_$depends.checked"; | ||
| 1219 | $javascript .= <<"EndQuery"; | ||
| 1220 | if ( $check_name && | ||
| 1221 | !$depends_name) { | ||
| 1222 | r += "In order to specify $label, a value needs to be selected for $depend_label. "; | ||
| 1223 | } | ||
| 1224 | EndQuery | ||
| 1225 | } | ||
| 1226 | } | ||
| 1227 | } @form_fields; | ||
| 1228 | $javascript .= <<"EndQuery"; | ||
| 1229 | if (r == "") { | ||
| 1230 | return true; | ||
| 1231 | } else { | ||
| 1232 | alert(r); | ||
| 1233 | return false; | ||
| 1234 | } | ||
| 1235 | } | ||
| 1236 | EndQuery | ||
| 1237 | return $javascript; | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | # | ||
| 1241 | # uc_string($instring); | ||
| 1242 | # | ||
| 1243 | sub uc_string { | ||
| 1244 | my($instring) = shift; | ||
| 1245 | my(@label); | ||
| 1246 | map { | ||
| 1247 | push @label, (ucfirst $_); | ||
| 1248 | } split('_',$instring); | ||
| 1249 | return join(' ',@label); | ||
| 1250 | } | ||
| 1251 | |||
| 1252 | # | ||
| 1253 | # %lookup_fields = find_lookups($schema,$table); | ||
| 1254 | # | ||
| 1255 | |||
| 1256 | sub find_lookups { | ||
| 1257 | my($schema) = shift; | ||
| 1258 | my($table) = shift; | ||
| 1259 | my($cgi_param) = shift; | ||
| 1260 | my($parent); | ||
| 1261 | my(@relation); | ||
| 1262 | my(%lookups); | ||
| 1263 | my($field); | ||
| 1264 | my($pfield); | ||
| 1265 | my($first_pfield); | ||
| 1266 | my($description); | ||
| 1267 | my(@description_match) = split(',',$cgi_param->{'label_match'}); | ||
| 1268 | my($description_match) = (defined($cgi_param->{'label_match'})) ? | ||
| 1269 | \@description_match : | ||
| 1270 | [ 'description', 'comment', '_name', 'label', 'desc' ]; | ||
| 1271 | my(@fields); | ||
| 1272 | my(@pfields); | ||
| 1273 | my($single_key) = 1; | ||
| 1274 | my($multi_key); | ||
| 1275 | my($number_tuples); | ||
| 1276 | my($array_ref); | ||
| 1277 | my($i); | ||
| 1278 | |||
| 1279 | map { | ||
| 1280 | $parent = $_; | ||
| 1281 | @relation = $schema->Relation($_,$table); | ||
| 1282 | ($first_pfield) = split("=",$relation[0]); | ||
| 1283 | undef @pfields; | ||
| 1284 | map { | ||
| 1285 | ($pfield, $field) = split("="); | ||
| 1286 | if ($pfield ne $first_pfield) { | ||
| 1287 | $single_key = 0; | ||
| 1288 | } | ||
| 1289 | if (!defined($multi_key->{$pfield})) { | ||
| 1290 | $multi_key->{$pfield} = []; | ||
| 1291 | push @pfields, ($pfield); | ||
| 1292 | } | ||
| 1293 | push @{$multi_key->{$pfield}}, ($field); | ||
| 1294 | } @relation; | ||
| 1295 | if (@relation <= 1) { | ||
| 1296 | ($pfield, $field) = split("=",$relation[0]); | ||
| 1297 | $description = Find_Description_Field( [ 'description', | ||
| 1298 | '_name', 'label', 'desc' ], | ||
| 1299 | $schema->Table_Fields($parent)); | ||
| 1300 | if ($description eq '') { | ||
| 1301 | $description = $pfield; | ||
| 1302 | } | ||
| 1303 | $lookups{$field} = "$parent\t$pfield\t$description"; | ||
| 1304 | } elsif ($single_key) { | ||
| 1305 | map { | ||
| 1306 | ($pfield, $field) = split("="); | ||
| 1307 | $description = Find_Description_Field( $description_match, | ||
| 1308 | $schema->Table_Fields($parent)); | ||
| 1309 | if ($description eq '') { | ||
| 1310 | $description = $pfield; | ||
| 1311 | } | ||
| 1312 | $lookups{$field} = "$parent\t$pfield\t$description"; | ||
| 1313 | } @relation; | ||
| 1314 | } else { | ||
| 1315 | $description = Find_Description_Field( $description_match, | ||
| 1316 | $schema->Table_Fields($parent)); | ||
| 1317 | if ($description eq '') { | ||
| 1318 | $description = join(',',@pfields); | ||
| 1319 | } | ||
| 1320 | $number_tuples = $#{$multi_key->{$pfields[0]}}; | ||
| 1321 | for ($i = 0; $i <= $number_tuples; $i++) { | ||
| 1322 | undef @fields; | ||
| 1323 | map { | ||
| 1324 | $array_ref = $multi_key->{$_}; | ||
| 1325 | push @fields, ($array_ref->[$i]); | ||
| 1326 | } @pfields; | ||
| 1327 | $lookups{join(',',@fields)} = "$parent\t". | ||
| 1328 | join(',',@pfields)."\t$description"; | ||
| 1329 | } | ||
| 1330 | map { | ||
| 1331 | ($pfield, $field) = split("="); | ||
| 1332 | push @fields, ($field); | ||
| 1333 | push @pfields, ($pfield); | ||
| 1334 | } @relation; | ||
| 1335 | } | ||
| 1336 | } $schema->Parents($table); | ||
| 1337 | return %lookups; | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | sub Find_Description_Field { | ||
| 1341 | my($match_ref) = shift; | ||
| 1342 | my(@fields) = @_; | ||
| 1343 | my($match); | ||
| 1344 | my($description); | ||
| 1345 | |||
| 1346 | foreach $match (@$match_ref) { | ||
| 1347 | if (!defined($description)) { | ||
| 1348 | map { | ||
| 1349 | if (/$match/ && !defined($description)) { | ||
| 1350 | $description = $_; | ||
| 1351 | } | ||
| 1352 | } @fields; | ||
| 1353 | } | ||
| 1354 | } | ||
| 1355 | return (defined($description) ? $description : ''); | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | # | ||
| 1359 | # %lookup_hash = get_lookup($X,$cgi_param,$ltable,$lkey,$ldescription); | ||
| 1360 | # | ||
| 1361 | |||
| 1362 | sub get_lookup { | ||
| 1363 | my($X) = shift; | ||
| 1364 | my($cgi_param) = shift; | ||
| 1365 | my($object) = shift; | ||
| 1366 | my($key_field) = shift; | ||
| 1367 | my($description_field) = shift; | ||
| 1368 | my($query) = "select distinct $key_field, $description_field from $object"; | ||
| 1369 | my(%lookup_hash); | ||
| 1370 | my(@row); | ||
| 1371 | my($value); | ||
| 1372 | |||
| 1373 | map { | ||
| 1374 | s/^\s*//g; | ||
| 1375 | s/\s*$//g; | ||
| 1376 | if ($object eq $_) { | ||
| 1377 | return undef; | ||
| 1378 | } | ||
| 1379 | } split(',',$cgi_param->{'disable_lookup'}); | ||
| 1380 | if (defined($key_field) && | ||
| 1381 | $key_field !~ /^\s*$/ && | ||
| 1382 | defined($description_field) && | ||
| 1383 | $description_field !~ /^\s*$/ && | ||
| 1384 | defined($object) && | ||
| 1385 | $object !~ /^\s*$/) { | ||
| 1386 | $X->Sql($query); | ||
| 1387 | while(@row = $X->NextRow()) { | ||
| 1388 | if ($X->Regular_Row()) { | ||
| 1389 | $row[0] =~ s/^\s*//g; | ||
| 1390 | $row[0] =~ s/\s*$//g; | ||
| 1391 | $row[1] =~ s/^\s*//g; | ||
| 1392 | $row[1] =~ s/\s*$//g; | ||
| 1393 | if ($row[0] !~ /^\s*$/ ) { | ||
| 1394 | if (defined($row[1])) { | ||
| 1395 | $lookup_hash{$row[0]} = $row[1]; | ||
| 1396 | } else { | ||
| 1397 | $lookup_hash{$row[0]} = $row[0]; | ||
| 1398 | } | ||
| 1399 | } | ||
| 1400 | } | ||
| 1401 | } | ||
| 1402 | while ($X->More_Results()) {} | ||
| 1403 | } | ||
| 1404 | return %lookup_hash; | ||
| 1405 | } | ||
| 1406 | |||
| 1407 | # | ||
| 1408 | # %lookup_hash = get_multi_lookup($X,$cgi_param,$ltable,$lkey,$ldescription); | ||
| 1409 | # | ||
| 1410 | |||
| 1411 | sub get_multi_lookup { | ||
| 1412 | my($X) = shift; | ||
| 1413 | my($cgi_param) = shift; | ||
| 1414 | my($object) = shift; | ||
| 1415 | my($key_field) = shift; | ||
| 1416 | my(@key_fields) = split(',',$key_field); | ||
| 1417 | my($num_key_field) = $#key_fields; | ||
| 1418 | my($description_field) = shift; | ||
| 1419 | my($query) = "select distinct $key_field, $description_field from $object"; | ||
| 1420 | my(%lookup_hash); | ||
| 1421 | my(@row); | ||
| 1422 | my($value); | ||
| 1423 | my($label); | ||
| 1424 | |||
| 1425 | map { | ||
| 1426 | s/^\s*//g; | ||
| 1427 | s/\s*$//g; | ||
| 1428 | if ($object eq $_) { | ||
| 1429 | return undef; | ||
| 1430 | } | ||
| 1431 | } split(',',$cgi_param->{'disable_lookup'}); | ||
| 1432 | if (defined($key_field) && | ||
| 1433 | $key_field !~ /^\s*$/ && | ||
| 1434 | defined($description_field) && | ||
| 1435 | $description_field !~ /^\s*$/ && | ||
| 1436 | defined($object) && | ||
| 1437 | $object !~ /^\s*$/) { | ||
| 1438 | $X->Sql($query); | ||
| 1439 | while(@row = $X->NextRow()) { | ||
| 1440 | if ($X->Regular_Row()) { | ||
| 1441 | foreach $value (@row) { | ||
| 1442 | $value =~ s/^\s*//g; | ||
| 1443 | $value =~ s/\s*$//g; | ||
| 1444 | } | ||
| 1445 | $value = join("\t",@row[0..$num_key_field]); | ||
| 1446 | $label = join("\t",@row[$num_key_field+1..$#row]); | ||
| 1447 | if ($value !~ /^\s*$/) { | ||
| 1448 | if ($label !~ /^\s*$/) { | ||
| 1449 | $lookup_hash{$value} = $label; | ||
| 1450 | } else { | ||
| 1451 | $lookup_hash{$value} = $value; | ||
| 1452 | } | ||
| 1453 | } | ||
| 1454 | } | ||
| 1455 | } | ||
| 1456 | while ($X->More_Results()) {} | ||
| 1457 | } | ||
| 1458 | return %lookup_hash; | ||
| 1459 | } | ||
| 1460 | |||
| 1461 | # | ||
| 1462 | # %lookup_hash = get_range($X,$cgi_param,$object,$field); | ||
| 1463 | # | ||
| 1464 | |||
| 1465 | sub get_range { | ||
| 1466 | my($X) = shift; | ||
| 1467 | my($cgi_param) = shift; | ||
| 1468 | my($object) = shift; | ||
| 1469 | my($field) = shift; | ||
| 1470 | my($type) = shift; | ||
| 1471 | my($quote) = 0; | ||
| 1472 | my($query) = "select distinct $field from $object"; | ||
| 1473 | my(%lookup_hash); | ||
| 1474 | my(@row); | ||
| 1475 | my($key); | ||
| 1476 | |||
| 1477 | map { | ||
| 1478 | s/^\s*//g; | ||
| 1479 | s/\s*$//g; | ||
| 1480 | if ($object eq $_) { | ||
| 1481 | return undef; | ||
| 1482 | } | ||
| 1483 | } split(',',$cgi_param->{'disable_lookup'}); | ||
| 1484 | if ($type =~ /char/ || | ||
| 1485 | $type =~ /text/ || | ||
| 1486 | $type =~ /datetime/ ) { | ||
| 1487 | $quote = 1; | ||
| 1488 | } | ||
| 1489 | if (defined($field) && | ||
| 1490 | $field !~ /^\s*$/ && | ||
| 1491 | defined($object) && | ||
| 1492 | $object !~ /^\s*$/) { | ||
| 1493 | $X->Sql($query); | ||
| 1494 | while(@row = $X->NextRow()) { | ||
| 1495 | if ($X->Regular_Row()) { | ||
| 1496 | $row[0] =~ s/^\s*//g; | ||
| 1497 | $row[0] =~ s/\s*$//g; | ||
| 1498 | $key = $row[0]; | ||
| 1499 | if ($quote) { | ||
| 1500 | $key =~ s/\'/\'\'/g; # Quote quotes | ||
| 1501 | $key = "'$key'"; | ||
| 1502 | } | ||
| 1503 | if ($row[0] !~ /^\s*$/ ) { | ||
| 1504 | $lookup_hash{$key} = $row[0]; | ||
| 1505 | } | ||
| 1506 | } | ||
| 1507 | } | ||
| 1508 | while ($X->More_Results()) {} | ||
| 1509 | } | ||
| 1510 | return %lookup_hash; | ||
| 1511 | } | ||
| 1512 | |||
| 1513 | sub html_file_include { | ||
| 1514 | my($filearg) = shift; | ||
| 1515 | my($rootdir) = $ENV{'DOCUMENT_ROOT'}; | ||
| 1516 | my($filename) = "$rootdir$filearg"; | ||
| 1517 | my($file); | ||
| 1518 | |||
| 1519 | if (-e $filename && -r $filename) { | ||
| 1520 | open(HTML_INCLUDE_FILE,$filename); | ||
| 1521 | while(<HTML_INCLUDE_FILE>) { | ||
| 1522 | $file .= $_; | ||
| 1523 | } | ||
| 1524 | close(HTML_INCLUDE_FILE); | ||
| 1525 | } | ||
| 1526 | return $file; | ||
| 1527 | } | ||
| 1528 | |||
| 1529 | # | ||
| 1530 | # $cgi_param = PQEntry($cgi_query); | ||
| 1531 | # | ||
| 1532 | |||
| 1533 | sub PQEntry { | ||
| 1534 | my($query) = shift; | ||
| 1535 | my($pqdebug) = $query->param('pqdebug'); | ||
| 1536 | # Get pq database parameters or set defaults | ||
| 1537 | my($pq_server) = $query->param('pqweb_server'); | ||
| 1538 | my($pq_database) = $query->param('pqweb_database') || 'pqweb'; | ||
| 1539 | my($pq_username) = $query->param('pqweb_username'); | ||
| 1540 | my($pq_password) = $query->param('pqweb_password'); | ||
| 1541 | my($pqweb_entry) = $query->param('pqweb_entry'); | ||
| 1542 | |||
| 1543 | if (defined($pqweb_entry)) { | ||
| 1544 | # Get (open) connection to pqweb database | ||
| 1545 | ( $PQ = RDBAL::Connect($pq_username, $pq_password, | ||
| 1546 | $pq_server, | ||
| 1547 | $query->param('server_type'), | ||
| 1548 | $query->param('database')) ) | ||
| 1549 | or return undef; | ||
| 1550 | ( $PQ->UseDatabase($pq_database) ) | ||
| 1551 | or return undef; | ||
| 1552 | } | ||
| 1553 | |||
| 1554 | # Get pq parameters | ||
| 1555 | return get_pq_parameters($PQ,$pqweb_entry,$query,$pqdebug); | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | sub get_pq_parameters { | ||
| 1559 | my($PQ) = shift; | ||
| 1560 | my($pqweb_entry) = shift; | ||
| 1561 | my($query) = shift; | ||
| 1562 | my($pqdebug) = $query->param('pqdebug'); | ||
| 1563 | #---------------------------------------------------- | ||
| 1564 | my(@passthru) = ( | ||
| 1565 | 'pqdebug', | ||
| 1566 | 'server', | ||
| 1567 | 'database', | ||
| 1568 | 'table', | ||
| 1569 | 'username', | ||
| 1570 | 'password', | ||
| 1571 | 'login', | ||
| 1572 | 'server_type', | ||
| 1573 | 'single_window', | ||
| 1574 | 'subedit_tables', | ||
| 1575 | 'button_subedit', | ||
| 1576 | 'begin_html_include', | ||
| 1577 | 'middle_html_include', | ||
| 1578 | 'end_html_include', | ||
| 1579 | 'disable_lookup', | ||
| 1580 | 'label_match', | ||
| 1581 | 'auto_field', | ||
| 1582 | 'replace_field', | ||
| 1583 | 'readonly', | ||
| 1584 | 'no_schemacache' ); | ||
| 1585 | |||
| 1586 | my($helppage) = $query->param('helppage'); | ||
| 1587 | my($nondisplay) = $query->param('nondisplay'); | ||
| 1588 | my($labels) = $query->param('labels'); | ||
| 1589 | my(%web_value); | ||
| 1590 | my(@field); | ||
| 1591 | my(@value); | ||
| 1592 | my($parameter); | ||
| 1593 | my($i); | ||
| 1594 | my($result_type, $accumulate); | ||
| 1595 | |||
| 1596 | if (defined($query->param('pqweb_entry'))) { | ||
| 1597 | my($command) = "select result_enum, helppage, accumulate_keys ". | ||
| 1598 | "from pqweb where pq='$pqweb_entry'"; | ||
| 1599 | my(@row); | ||
| 1600 | $PQ->Sql($command); | ||
| 1601 | ($result_type, $helppage, $accumulate) = $PQ->NextRow(); | ||
| 1602 | $helppage =~ s/^\s*//g; | ||
| 1603 | $helppage =~ s/\s*$//g; | ||
| 1604 | while ($PQ->More_Results()) {} | ||
| 1605 | $command = "select field_name, label from pq_labels ". | ||
| 1606 | "where pq='$pqweb_entry'"; | ||
| 1607 | $PQ->Sql($command); | ||
| 1608 | while(@row = $PQ->NextRow()) { | ||
| 1609 | if ($PQ->Regular_Row()) { | ||
| 1610 | $row[0] =~ s/^\s*//g; | ||
| 1611 | $row[0] =~ s/\s*$//g; | ||
| 1612 | $row[1] =~ s/^\s*//g; | ||
| 1613 | $row[1] =~ s/\s*$//g; | ||
| 1614 | if (defined($labels)) { | ||
| 1615 | $labels .= ','."$row[0];$row[1]"; | ||
| 1616 | } else { | ||
| 1617 | $labels = "$row[0];$row[1]"; | ||
| 1618 | } | ||
| 1619 | } | ||
| 1620 | } | ||
| 1621 | while ($PQ->More_Results()) {} | ||
| 1622 | $command = "select noshow_field from pq_noshow ". | ||
| 1623 | "where pq='$pqweb_entry'"; | ||
| 1624 | $PQ->Sql($command); | ||
| 1625 | while(@row = $PQ->NextRow()) { | ||
| 1626 | if ($PQ->Regular_Row()) { | ||
| 1627 | $row[0] =~ s/^\s*//g; | ||
| 1628 | $row[0] =~ s/\s*$//g; | ||
| 1629 | if (defined($nondisplay)) { | ||
| 1630 | $nondisplay .= ';'.$row[0]; | ||
| 1631 | } else { | ||
| 1632 | $nondisplay = $row[0]; | ||
| 1633 | } | ||
| 1634 | } | ||
| 1635 | } | ||
| 1636 | while ($PQ->More_Results()) {} | ||
| 1637 | $command = "select element_description, web_property, web_value ". | ||
| 1638 | "from pq_webvalues a, web_elements b ". | ||
| 1639 | "where pq='$pqweb_entry' and a.web_elements=b.web_elements"; | ||
| 1640 | $PQ->Sql($command); | ||
| 1641 | while(@row = $PQ->NextRow()) { | ||
| 1642 | if ($PQ->Regular_Row()) { | ||
| 1643 | $row[0] =~ s/^\s*//g; | ||
| 1644 | $row[0] =~ s/\s*$//g; | ||
| 1645 | $row[1] =~ s/^\s*//g; | ||
| 1646 | $row[1] =~ s/\s*$//g; | ||
| 1647 | $row[2] =~ s/^\s*//g; | ||
| 1648 | $row[2] =~ s/\s*$//g; | ||
| 1649 | $web_value{"$row[0]_$row[1]"} = $row[2]; | ||
| 1650 | } | ||
| 1651 | } | ||
| 1652 | while ($PQ->More_Results()) {} | ||
| 1653 | } | ||
| 1654 | my(%cgi_param) = ( | ||
| 1655 | 'helppage' => $helppage, | ||
| 1656 | 'labels' => $labels, | ||
| 1657 | 'nondisplay' => $nondisplay); | ||
| 1658 | |||
| 1659 | map { | ||
| 1660 | if (defined($query->param($_)) && $query->param($_) !~ /^\s*$/) { | ||
| 1661 | $cgi_param{$_} = $query->param($_); | ||
| 1662 | } | ||
| 1663 | } @passthru; | ||
| 1664 | my($web_property); | ||
| 1665 | foreach $web_property (keys %web_value) { | ||
| 1666 | $cgi_param{"web_$web_property"} = $web_value{$web_property}; | ||
| 1667 | } | ||
| 1668 | map { | ||
| 1669 | if (/^web_/) { | ||
| 1670 | $cgi_param{"$_"} = $query->param("$_"); | ||
| 1671 | } | ||
| 1672 | if (/^pq_.*_____/) { | ||
| 1673 | $parameter = $_; | ||
| 1674 | @value = split("\t",$query->param($_)); | ||
| 1675 | $parameter =~ s/^pq_//; | ||
| 1676 | @field = split('_____',$parameter); | ||
| 1677 | for ($i = 0; $i <= $#field;$i++) { | ||
| 1678 | $query->param("pq_".$field[$i],$value[$i]); | ||
| 1679 | } | ||
| 1680 | $query->delete("pq_$parameter"); | ||
| 1681 | } | ||
| 1682 | if (/^pqsearch_.*_____/) { | ||
| 1683 | $parameter = $_; | ||
| 1684 | $parameter =~ s/^pqsearch_//; | ||
| 1685 | map { | ||
| 1686 | $query->param("pqsearch_".$_,1); | ||
| 1687 | } @field = split('_____',$parameter); | ||
| 1688 | $query->delete("pqsearch_$parameter"); | ||
| 1689 | } | ||
| 1690 | } $query->param; | ||
| 1691 | if (!defined($cgi_param{'web_textarea_columns'})) { | ||
| 1692 | $cgi_param{'web_textarea_columns'} = 61; | ||
| 1693 | } | ||
| 1694 | if (!defined($cgi_param{'web_textarea_rows'})) { | ||
| 1695 | $cgi_param{'web_textarea_rows'} = 2; | ||
| 1696 | } | ||
| 1697 | return \%cgi_param; | ||
| 1698 | } | ||
| 1699 | |||
| 1700 | sub PQLogin { | ||
| 1701 | my($query) = shift; | ||
| 1702 | my($cgi_param) = shift; | ||
| 1703 | my($self_url) = $query->self_url; | ||
| 1704 | my($body_bgcolor) = (defined($cgi_param->{'web_body_bgcolor'})) ? | ||
| 1705 | $cgi_param->{'web_body_bgcolor'} : 'teal'; | ||
| 1706 | my($javascript) = <<"EndJavaScript"; | ||
| 1707 | function submit_login() { | ||
| 1708 | formObj = document.PQLogin; | ||
| 1709 | if ( formObj.server.value == "" || | ||
| 1710 | formObj.database.value == "" || | ||
| 1711 | formObj.table.value == "" || | ||
| 1712 | formObj.username.value == "" || | ||
| 1713 | formObj.password.value == "" ) { | ||
| 1714 | alert("Please enter all login information"); | ||
| 1715 | return false; | ||
| 1716 | } | ||
| 1717 | } | ||
| 1718 | EndJavaScript | ||
| 1719 | |||
| 1720 | if (!$cgi_param->{'pqdebug'}) { | ||
| 1721 | $self_url =~ s/\?.*$//; | ||
| 1722 | } | ||
| 1723 | if (defined($query->param('password'))) { | ||
| 1724 | $cgi_param->{'password'} = $query->param('password'); | ||
| 1725 | } | ||
| 1726 | if (defined($cgi_param->{'server'}) && | ||
| 1727 | defined($cgi_param->{'database'}) && | ||
| 1728 | defined($cgi_param->{'table'}) && | ||
| 1729 | defined($cgi_param->{'username'}) && | ||
| 1730 | defined($cgi_param->{'password'})) { | ||
| 1731 | return 1; | ||
| 1732 | } | ||
| 1733 | # Output HTML | ||
| 1734 | print "\n"; | ||
| 1735 | print $query->start_html(-title => 'PQ Login', | ||
| 1736 | -author => 'brian@ibc.wustl.edu', | ||
| 1737 | -script => $javascript, | ||
| 1738 | -text => 'white', | ||
| 1739 | -BGCOLOR => $body_bgcolor, | ||
| 1740 | -onload => 'window.focus();'); # Focus this page | ||
| 1741 | |||
| 1742 | print "\n"; | ||
| 1743 | print '<H1 ALIGN="CENTER">PQ Login</H1>'."\n"; | ||
| 1744 | print $query->start_form(-method => 'POST', | ||
| 1745 | -name => "PQLogin", | ||
| 1746 | -onSubmit => "return submit_login()", | ||
| 1747 | -action => $self_url); | ||
| 1748 | print "\n"; | ||
| 1749 | print '<TABLE BORDER="3" ALIGN="CENTER" bordercolordark="#000000" CELLSPACING="0">'."\n\t<TR>\n\t\t<TD>"; | ||
| 1750 | print "<BIG>Server: </BIG></TD>\n\t\t<TD>"; | ||
| 1751 | if (defined($cgi_param->{'server'})) { | ||
| 1752 | print "<B><I>$cgi_param->{'server'}</I></B>"; | ||
| 1753 | } else { | ||
| 1754 | print $query->textfield(-name => 'server', | ||
| 1755 | -default => 'ibc_sybase', | ||
| 1756 | -size => 50, | ||
| 1757 | -style => 'background-color: white', | ||
| 1758 | -BGCOLOR => 'white', | ||
| 1759 | -maxlength => 255); | ||
| 1760 | } | ||
| 1761 | print "</TD>\n\t</TR>\n\t<TR>\n\t\t<TD>"; | ||
| 1762 | print "<BIG>Database: </BIG></TD>\n\t\t<TD>"; | ||
| 1763 | if (defined($cgi_param->{'database'})) { | ||
| 1764 | print "<B><I>$cgi_param->{'database'}</I></B>"; | ||
| 1765 | } else { | ||
| 1766 | print $query->textfield(-name => 'database', | ||
| 1767 | -default => 'master', | ||
| 1768 | -size => 50, | ||
| 1769 | -style => 'background-color: white', | ||
| 1770 | -maxlength => 255); | ||
| 1771 | } | ||
| 1772 | print "</TD>\n\t</TR>\n\t<TR>\n\t\t<TD>"; | ||
| 1773 | print "<BIG>Table: </BIG></TD>\n\t\t<TD>"; | ||
| 1774 | if (defined($cgi_param->{'table'})) { | ||
| 1775 | print "<B><I>$cgi_param->{'table'}</I></B>"; | ||
| 1776 | } else { | ||
| 1777 | print $query->textfield(-name => 'table', | ||
| 1778 | -default => '', | ||
| 1779 | -size => 50, | ||
| 1780 | -style => 'background-color: white', | ||
| 1781 | -maxlength => 255); | ||
| 1782 | } | ||
| 1783 | print "</TD>\n\t</TR>\n\t<TR>\n\t\t<TD>"; | ||
| 1784 | print "<BIG>Username: </BIG></TD>\n\t\t<TD>"; | ||
| 1785 | if (defined($cgi_param->{'username'})) { | ||
| 1786 | print "<B><I>$cgi_param->{'username'}</I></B>"; | ||
| 1787 | } else { | ||
| 1788 | print $query->textfield(-name => 'username', | ||
| 1789 | -default => 'guest', | ||
| 1790 | -size => 50, | ||
| 1791 | -style => 'background-color: white', | ||
| 1792 | -maxlength => 255); | ||
| 1793 | } | ||
| 1794 | print "</TD>\n\t</TR>\n\t<TR>\n\t\t<TD>"; | ||
| 1795 | print "<BIG>Password: </BIG></TD>\n\t\t<TD>"; | ||
| 1796 | if (defined($cgi_param->{'password'})) { | ||
| 1797 | print "<B><I>$cgi_param->{'password'}</I></B>"; | ||
| 1798 | } else { | ||
| 1799 | print $query->password_field(-name => 'password', | ||
| 1800 | -default => '', | ||
| 1801 | -size => 50, | ||
| 1802 | -style => 'background-color: white', | ||
| 1803 | -maxlength => 255); | ||
| 1804 | } | ||
| 1805 | print "</TD>\n\t</TR>\n</TABLE>\n"; | ||
| 1806 | print '<TABLE BORDER="0" ALIGN="CENTER" CELLSPACING="0">'."\n\t<TR>\n\t\t<TD>"; | ||
| 1807 | |||
| 1808 | $query->submit(-name => 'Login ', | ||
| 1809 | -onClick => "if (!document.PQLogin.single_window.checked) { this.form.target='pqedit' + document.PQLogin.table.value; }", | ||
| 1810 | -style => 'background-color: gray') . | ||
| 1811 | " \n" . | ||
| 1812 | $query->reset(-name => 'Reset ', | ||
| 1813 | -style => 'background-color: gray'); | ||
| 1814 | print "</TD>\n\t</TR>\n\t<TR>\n\t\t<TD>"; | ||
| 1815 | print $query->checkbox(-name => "single_window", | ||
| 1816 | -value => 'ON', | ||
| 1817 | -label => 'Use a Single Window'); | ||
| 1818 | print "\t\t</TD>\n\t</TR>\n</TABLE>\n"; | ||
| 1819 | print PQHidden_Parameters($query,$cgi_param); | ||
| 1820 | # Pass pq_*, pqsearch_*, pk_value and [Oo]verview through the login screen | ||
| 1821 | map { | ||
| 1822 | if (/^pq_/ || | ||
| 1823 | /^[Oo]verview/ || | ||
| 1824 | /^pk_value/ || | ||
| 1825 | /^pqsearch_/) { | ||
| 1826 | print $query->hidden($_,$query->param($_)),"\n"; | ||
| 1827 | } | ||
| 1828 | } $query->param; | ||
| 1829 | print "\n" . $query->end_form; | ||
| 1830 | print "\n" . $query->end_html; | ||
| 1831 | return 0; | ||
| 1832 | } | ||
| 1833 | |||
| 1834 | sub Login_Error { | ||
| 1835 | my($query) = shift; | ||
| 1836 | my($cgi_param) = shift; | ||
| 1837 | |||
| 1838 | print "\n"; | ||
| 1839 | print $query->start_html(-title => "PQ Login", | ||
| 1840 | -author => 'brian@ibc.wustl.edu', | ||
| 1841 | -BGCOLOR => 'green', | ||
| 1842 | -onload => 'window.focus();'); # Focus this page | ||
| 1843 | |||
| 1844 | print "\n"; | ||
| 1845 | print '<H1 ALIGN="CENTER">Login Error</H1>'."\n"; | ||
| 1846 | print "<BIG><BIG>Unable to login to server: <B>", | ||
| 1847 | $cgi_param->{'server'},'</B>, database: <B>', | ||
| 1848 | $cgi_param->{'database'},'</B> as user: <B>', | ||
| 1849 | $cgi_param->{'username'},"</B></BIG></BIG>\n"; | ||
| 1850 | print $query->end_html; | ||
| 1851 | } | ||
| 1852 | |||
| 1853 | sub PQHidden_Parameters { | ||
| 1854 | my($cgi_query) = shift; | ||
| 1855 | my($cgi_param) = shift; | ||
| 1856 | my($output_form); | ||
| 1857 | my($param_name); | ||
| 1858 | |||
| 1859 | |||
| 1860 | foreach $param_name (keys %{$cgi_param}) { | ||
| 1861 | if (defined($param_name) && | ||
| 1862 | defined($cgi_param->{$param_name})) { | ||
| 1863 | $output_form .= $cgi_query->hidden($param_name, | ||
| 1864 | $cgi_param->{$param_name}); | ||
| 1865 | $output_form .= "\n"; | ||
| 1866 | } | ||
| 1867 | } | ||
| 1868 | $output_form .= "\n"; | ||
| 1869 | return $output_form; | ||
| 1870 | } | ||
| 1871 | |||
| 1872 | # pq_field replacements for a table | ||
| 1873 | # | ||
| 1874 | # Replacement_Fields($table,$query); | ||
| 1875 | # | ||
| 1876 | sub Replacement_Fields { | ||
| 1877 | my($table) = shift; | ||
| 1878 | my($query) = shift; | ||
| 1879 | my($done); | ||
| 1880 | my($replace_table, $replace_field, $replace_command); | ||
| 1881 | my(%replacement_field); | ||
| 1882 | |||
| 1883 | map { | ||
| 1884 | ($replace_table, $replace_field, $replace_command) = split(','); | ||
| 1885 | $replace_table =~ s/^\s*//g; | ||
| 1886 | $replace_table =~ s/\s*$//g; | ||
| 1887 | $replace_field =~ s/^\s*//g; | ||
| 1888 | $replace_field =~ s/\s*$//g; | ||
| 1889 | if ($replace_table eq $table) { | ||
| 1890 | $replacement_field{$replace_field} = 1; | ||
| 1891 | } | ||
| 1892 | } split(';',$query->param('auto_field')); | ||
| 1893 | return %replacement_field; | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | # pq_field nondisplay for a table | ||
| 1897 | # | ||
| 1898 | # Nondisplay_Fields($table,$query,$schema); | ||
| 1899 | # | ||
| 1900 | sub Nondisplay_Fields { | ||
| 1901 | my($match_table) = shift; | ||
| 1902 | my($query) = shift; | ||
| 1903 | my($schema) = shift; | ||
| 1904 | my($done); | ||
| 1905 | my($table, $field); | ||
| 1906 | my(%nondisplay_field); | ||
| 1907 | |||
| 1908 | map { | ||
| 1909 | ($table, $field) = split(','); | ||
| 1910 | $table =~ s/^\s*//g; | ||
| 1911 | $table =~ s/\s*$//g; | ||
| 1912 | $field =~ s/^\s*//g; | ||
| 1913 | $field =~ s/\s*$//g; | ||
| 1914 | if ($table eq $match_table) { | ||
| 1915 | $nondisplay_field{$field} = 1; | ||
| 1916 | } | ||
| 1917 | } split(';',$query->param('nondisplay')); | ||
| 1918 | # Don't display or process timestamp fields | ||
| 1919 | map { | ||
| 1920 | if ($schema->Field_Type($match_table,$_) =~ /timestamp/ || | ||
| 1921 | $schema->Field_Type($match_table,$_) =~ /binary/ ) { | ||
| 1922 | $nondisplay_field{$_} = 1; | ||
| 1923 | } | ||
| 1924 | } $schema->Table_Fields($match_table); | ||
| 1925 | return %nondisplay_field; | ||
| 1926 | } | ||
| 1927 | |||
| 1928 | # pq_field readonly for a table | ||
| 1929 | # | ||
| 1930 | # Readonly_Fields($table,$query); | ||
| 1931 | # | ||
| 1932 | sub Readonly_Fields { | ||
| 1933 | my($match_table) = shift; | ||
| 1934 | my($query) = shift; | ||
| 1935 | my($done); | ||
| 1936 | my($table, $field); | ||
| 1937 | my(%readonly_field); | ||
| 1938 | |||
| 1939 | map { | ||
| 1940 | ($table, $field) = split(','); | ||
| 1941 | $table =~ s/^\s*//g; | ||
| 1942 | $table =~ s/\s*$//g; | ||
| 1943 | $field =~ s/^\s*//g; | ||
| 1944 | $field =~ s/\s*$//g; | ||
| 1945 | if ($table eq $match_table) { | ||
| 1946 | $readonly_field{$field} = 1; | ||
| 1947 | } | ||
| 1948 | } split(';',$query->param('replace_field')), | ||
| 1949 | split(';',$query->param('readonly')); | ||
| 1950 | return %readonly_field; | ||
| 1951 | } | ||
| 1952 | |||
| 1953 | # | ||
| 1954 | # pq_field replacement (auto assignment) | ||
| 1955 | # | ||
| 1956 | # Replace_Fields($X,$table,$query,$schema); | ||
| 1957 | # | ||
| 1958 | sub Replace_Fields { | ||
| 1959 | my($X) = shift; | ||
| 1960 | my($table) = shift; | ||
| 1961 | my($query) = shift; | ||
| 1962 | my($schema) = shift; | ||
| 1963 | my($replace_table, $replace_field, $replace_command); | ||
| 1964 | my(@replace_field); | ||
| 1965 | my(@replace_command); | ||
| 1966 | my($command); | ||
| 1967 | my($sql_command); | ||
| 1968 | my($field); | ||
| 1969 | my($value); | ||
| 1970 | my($i); | ||
| 1971 | my(%force_field); | ||
| 1972 | # Get env values as $replace{'$env'} = $value; | ||
| 1973 | my($localtime); | ||
| 1974 | $localtime = localtime(time()); | ||
| 1975 | $localtime =~ s/^\S+\s*//; | ||
| 1976 | my(%replace) = ( | ||
| 1977 | '\$referer' => $query->referer(), | ||
| 1978 | '\$remote_address' => $query->remote_addr(), | ||
| 1979 | '\$remote_ident' => $query->remote_ident(), | ||
| 1980 | '\$remote_host' => $query->remote_host(), | ||
| 1981 | '\$remote_user' => $query->remote_user(), | ||
| 1982 | '\$script_name' => $query->script_name(), | ||
| 1983 | '\$server_admin' => $ENV{'SERVER_ADMIN'}, | ||
| 1984 | '\$server_name' => $query->server_name(), | ||
| 1985 | '\$server_software' => $query->server_software(), | ||
| 1986 | '\$virtual_host' => $query->virtual_host(), | ||
| 1987 | '\$server_port' => $query->server_port(), | ||
| 1988 | '\$user_agent' => $query->user_agent(), | ||
| 1989 | '\$user_name' => $query->user_name(), | ||
| 1990 | '\$datetime' => $localtime, | ||
| 1991 | '\$unique_id' => $ENV{'UNIQUE_ID'} | ||
| 1992 | ); | ||
| 1993 | |||
| 1994 | # Get pq_field as $replace{'$pq_field'} = $value; | ||
| 1995 | map { | ||
| 1996 | $replace{'\$pq_'.$_} = $query->param('pq_'.$_); | ||
| 1997 | } $schema->Table_Fields($table); | ||
| 1998 | map { | ||
| 1999 | ($replace_table, $replace_field, $replace_command) = split(','); | ||
| 2000 | $replace_table =~ s/^\s*//g; | ||
| 2001 | $replace_table =~ s/\s*$//g; | ||
| 2002 | $replace_field =~ s/^\s*//g; | ||
| 2003 | $replace_field =~ s/\s*$//g; | ||
| 2004 | if ($replace_table eq $table) { | ||
| 2005 | push @replace_field, ($replace_field); | ||
| 2006 | push @replace_command, ($replace_command); | ||
| 2007 | } | ||
| 2008 | } split(';',$query->param('auto_field')); | ||
| 2009 | map { | ||
| 2010 | ($replace_table, $replace_field, $replace_command) = split(','); | ||
| 2011 | $replace_table =~ s/^\s*//g; | ||
| 2012 | $replace_table =~ s/\s*$//g; | ||
| 2013 | $replace_field =~ s/^\s*//g; | ||
| 2014 | $replace_field =~ s/\s*$//g; | ||
| 2015 | $force_field{$replace_field} = 1; | ||
| 2016 | if ($replace_table eq $table) { | ||
| 2017 | push @replace_field, ($replace_field); | ||
| 2018 | push @replace_command, ($replace_command); | ||
| 2019 | } | ||
| 2020 | } split(';',$query->param('replace_field')); | ||
| 2021 | for ($i = 0;$i <= $#replace_field;$i++) { | ||
| 2022 | if (!defined($query->param('pq_'.$replace_field)) || | ||
| 2023 | $query->param('pq_'.$replace_field) eq '' || | ||
| 2024 | $query->param('pq_'.$replace_field) eq '_NULL_' || | ||
| 2025 | $force_field{$replace_field}) { | ||
| 2026 | $command = $replace_command[$i]; | ||
| 2027 | if ($command =~ /^[Ss][Qq][Ll]\:/) { | ||
| 2028 | $sql_command = 1; | ||
| 2029 | $command =~ s/^[Ss][Qq][Ll]\://; | ||
| 2030 | } else { | ||
| 2031 | $sql_command = 0; | ||
| 2032 | $command =~ s/^[Vv][Aa][Ll][Uu][Ee]\://; | ||
| 2033 | } | ||
| 2034 | foreach $field (sort (keys %replace)) { | ||
| 2035 | $value = $replace{$field}; | ||
| 2036 | $command =~ s/$field/$value/g; | ||
| 2037 | $error_string .= "DEBUG REPLACE> $command = $field / $value<P>\n"; | ||
| 2038 | } | ||
| 2039 | if (defined($query->param('login'))) { | ||
| 2040 | $value = $command; | ||
| 2041 | } elsif ($sql_command) { | ||
| 2042 | $X->Sql($command); | ||
| 2043 | ($value) = $X->NextRow(); | ||
| 2044 | while ($X->More_Results()) {} | ||
| 2045 | } else { | ||
| 2046 | $value = $command; | ||
| 2047 | } | ||
| 2048 | $query->param('pq_'.$replace_field,$value); | ||
| 2049 | } | ||
| 2050 | } | ||
| 2051 | } | ||
| 2052 | |||
| 2053 | |||
| 2054 | 1; | ||