| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | DBedit - Class to handle database editing | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | This class takes an HTML form and fills it in with database material. | ||
| 10 | |||
| 11 | =head1 LICENSE | ||
| 12 | |||
| 13 | This class is copyright (C) 2002 Globewide Network Academy and released | ||
| 14 | under the terms of the Scheme License. | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | use DBstorage::RDB; | ||
| 19 | use strict; | ||
| 20 | use Carp; | ||
| 21 | use HTML::FillInForm; | ||
| 22 | use Data::Dumper; | ||
| 23 | package DBedit; | ||
| 24 | |||
| 25 | $DBedit::VERSION = '1.96'; | ||
| 26 | sub new { | ||
| 27 | my $proto = shift; | ||
| 28 | my $inref = shift; | ||
| 29 | my $class = ref($proto) || $proto; | ||
| 30 | my $self = {}; | ||
| 31 | bless ($self, $class); | ||
| 32 | my ($field); | ||
| 33 | my(%default_params) = ("scan_marker", "*", | ||
| 34 | "scan_header_marker", "Scan all records", | ||
| 35 | "append_marker", "Append record", | ||
| 36 | "search_marker", "Search record", | ||
| 37 | "submit_append_marker", "Do append", | ||
| 38 | "submit_search_marker", "Do search", | ||
| 39 | "submit_form_marker", "Do it", | ||
| 40 | "scan_page_size", 0); | ||
| 41 | |||
| 42 | foreach $field (keys %default_params) { | ||
| 43 | if ($inref->{$field} eq "") { | ||
| 44 | $self->{$field} = $default_params{$field}; | ||
| 45 | } else { | ||
| 46 | $self->{$field} = $inref->{$field}; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | if (!defined($self->{'storage'})) { | ||
| 50 | $self->{"storage"} = DBstorage::RDB->new(); | ||
| 51 | } | ||
| 52 | $self->{'handler'} = {}; | ||
| 53 | $self->{'status_out'} = ""; | ||
| 54 | $self->{'abort_transaction'} = 0; | ||
| 55 | $self->{'record'} = 0; | ||
| 56 | $self->{'last'} = 0; | ||
| 57 | $self->{'next'} = 0; | ||
| 58 | $self->{'script'} = ""; | ||
| 59 | $self->{'menu_hide'} = 0; | ||
| 60 | $self->{'permission'} = {}; | ||
| 61 | $self->{'keycols'} = []; | ||
| 62 | $self->{'form'} = ""; | ||
| 63 | $self->{'table'} = ""; | ||
| 64 | $self->{'fill_form'} = HTML::FillInForm->new(); | ||
| 65 | $self->{'permission'} = { | ||
| 66 | "read"=>1, | ||
| 67 | "write"=>1, | ||
| 68 | "append"=>1, | ||
| 69 | "delete"=>1 | ||
| 70 | }; | ||
| 71 | |||
| 72 | $self->set_handler("scan_menu", | ||
| 73 | sub { | ||
| 74 | my($self) = @_; | ||
| 75 | my($returnval) = | ||
| 76 | "<br><a href=\"$self->{'script'}RDBaction=scan\">$self->{'scan_header_marker'}</a>"; | ||
| 77 | $returnval .= "<br><a href=\"$self->{'script'}RDBaction=search\">$self->{'search_marker'}</a>"; | ||
| 78 | |||
| 79 | |||
| 80 | if ($self->permission("append")) { | ||
| 81 | $returnval .= "<br><A HREF=\"" . | ||
| 82 | $self->{'script'} . | ||
| 83 | "RDBaction=append\">$self->{'append_marker'}</A>"; | ||
| 84 | } | ||
| 85 | $returnval .= "<p>"; | ||
| 86 | return $returnval; | ||
| 87 | }); | ||
| 88 | $self->set_handler("scan_header", | ||
| 89 | sub { | ||
| 90 | my($self) = @_; | ||
| 91 | my($returnval) = <<EOP; | ||
| 92 | <hr> | ||
| 93 | <table border=1> | ||
| 94 | <tr> | ||
| 95 | <td> </td><td><b> | ||
| 96 | EOP | ||
| 97 | $returnval .= | ||
| 98 | join("</b></td> <td><b>", @{$self->{'keycols'}}) . | ||
| 99 | "</b></td></tr><h6></h6>"; | ||
| 100 | return $returnval; | ||
| 101 | }); | ||
| 102 | |||
| 103 | |||
| 104 | $self->set_handler("scan_line", | ||
| 105 | sub { | ||
| 106 | my($self, $name, $href, $fref) = @_; | ||
| 107 | my ($returnval); | ||
| 108 | $returnval .= "<tr><td><a name=\"$name\" href=\"$href\">(edit)</a></td> <td>"; | ||
| 109 | $returnval .= join("</td> <td>", @{$fref}{@{$self->{'keycols'}}}) . "</td></tr><h6></h6>"; | ||
| 110 | return $returnval; | ||
| 111 | }); | ||
| 112 | |||
| 113 | |||
| 114 | $self->set_handler("scan_footer", | ||
| 115 | sub { | ||
| 116 | return "</table><hr>\n"; | ||
| 117 | }); | ||
| 118 | return $self; | ||
| 119 | } | ||
| 120 | |||
| 121 | sub permission { | ||
| 122 | my ($self, $action, $set) = @_; | ||
| 123 | if (defined($set)) { | ||
| 124 | $self->{'permission'}->{$action} = | ||
| 125 | $set; | ||
| 126 | } | ||
| 127 | return $self->{'permission'}->{$action}; | ||
| 128 | } | ||
| 129 | |||
| 130 | sub form { | ||
| 131 | my($self, $formin) = @_; | ||
| 132 | $self->{'form'} = $formin; | ||
| 133 | } | ||
| 134 | |||
| 135 | sub keycols { | ||
| 136 | my($self, $keycolref) = @_; | ||
| 137 | $self->{'keycols'} = $keycolref; | ||
| 138 | } | ||
| 139 | |||
| 140 | sub table { | ||
| 141 | my($self, $tablein) = @_; | ||
| 142 | $self->{'table'} = $tablein; | ||
| 143 | } | ||
| 144 | |||
| 145 | sub param { | ||
| 146 | my($self, $param, $value) = @_; | ||
| 147 | $self->{$param} = $value; | ||
| 148 | } | ||
| 149 | |||
| 150 | sub scan_table { | ||
| 151 | my($self, $tablein) = @_; | ||
| 152 | $self->{'scan_table'} = $tablein; | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | sub storage { | ||
| 157 | my($self, $storage) = @_; | ||
| 158 | if (defined($self->{'storage'})) { | ||
| 159 | undef($self->{'storage'}); | ||
| 160 | } | ||
| 161 | $self->{'storage'} = $storage; | ||
| 162 | } | ||
| 163 | |||
| 164 | sub process { | ||
| 165 | my($self, $inref) = @_; | ||
| 166 | my(%in, %found); | ||
| 167 | my(@keycols) = @{$self->{'keycols'}}; | ||
| 168 | local ($_); | ||
| 169 | my ($returnval) = ""; | ||
| 170 | %in = %{$inref}; | ||
| 171 | |||
| 172 | my($scan_table); | ||
| 173 | if (defined($self->{'scan_table'}) && | ||
| 174 | $self->{'scan_table'} ne "") { | ||
| 175 | $scan_table = $self->{'scan_table'}; | ||
| 176 | } else { | ||
| 177 | $scan_table = $self->{'table'}; | ||
| 178 | } | ||
| 179 | |||
| 180 | my($dbh) = $self->{'storage'}; | ||
| 181 | |||
| 182 | if ($in{'RDBscan_page_size'} != 0) { | ||
| 183 | $self->{'scan_page_size'} = $in{'RDBscan_page_size'}; | ||
| 184 | } | ||
| 185 | |||
| 186 | $self->{'scan_page_start'} = $in{'RDBscan_page_start'}; | ||
| 187 | if ($self->{'scan_page_size'} != 0 && | ||
| 188 | $self->{'scan_page_start'} < 1) { | ||
| 189 | $self->{'scan_page_start'} = 1; | ||
| 190 | } | ||
| 191 | |||
| 192 | my ($action) = $in{'RDBaction'}; | ||
| 193 | $self->{'record'} = $in{'RDBrecord'}; | ||
| 194 | $self->{'last'} = $in{'RDBlast'}; | ||
| 195 | |||
| 196 | $self->{'script'} = $ENV{'SCRIPT_NAME'} . "?"; | ||
| 197 | $self->{'script'} .= "RDBdate="; | ||
| 198 | $self->{'script'} .= &get_time; | ||
| 199 | $self->{'script'} .= "&"; | ||
| 200 | |||
| 201 | foreach (keys %{$self->{'attrib'}}) { | ||
| 202 | $self->{'script'} .= "$_=" . $self->{'attrib'}->{$_} . "&"; | ||
| 203 | } | ||
| 204 | |||
| 205 | my ($field); | ||
| 206 | foreach $field (keys %in) { | ||
| 207 | if ($field =~ /^RDB/) { | ||
| 208 | delete $in{$field}; | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | my (%keys); | ||
| 213 | foreach (@keycols) { | ||
| 214 | $keys{$_} = $in{"$_.old"}; | ||
| 215 | delete $in{"$_.old"}; | ||
| 216 | } | ||
| 217 | |||
| 218 | # w is for write permission | ||
| 219 | # a is for append permission | ||
| 220 | # d is for delete permission | ||
| 221 | |||
| 222 | $returnval .= $self->{'page_header'}; | ||
| 223 | my($record) = $self->{'record'}; | ||
| 224 | my($last) = $self->{'last'}; | ||
| 225 | my($table) = $self->{'table'}; | ||
| 226 | $self->{'abort_transction'} = 0; | ||
| 227 | $self->{'status_out'} = ""; | ||
| 228 | |||
| 229 | if ($action eq "do_append" && $self->permission("append")) { | ||
| 230 | $self->run_handler("preprocess.append", \%in); | ||
| 231 | if (!$self->{'abort_transaction'}) { | ||
| 232 | $dbh->append($table, \%in); | ||
| 233 | $self->run_handler("postprocess.append", \%in); | ||
| 234 | } | ||
| 235 | |||
| 236 | $action="find_key_only"; | ||
| 237 | } elsif ($action eq "do_replace" && $self->permission("write")) { | ||
| 238 | $self->run_handler("preprocess.replace", \%in); | ||
| 239 | if (!$self->{'abort_transaction'}) { | ||
| 240 | $dbh->replace($table, \%keys, \%in, 0); | ||
| 241 | $self->run_handler("postprocess.replace", \%in); | ||
| 242 | } | ||
| 243 | $action = "find_key_only"; | ||
| 244 | } elsif ($action eq "do_delete" && $self->permission("delete")) { | ||
| 245 | $self->run_handler("preprocess.delete", \%in); | ||
| 246 | if (!$self->{'abort_transaction'}) { | ||
| 247 | $dbh->delete($table, \%keys); | ||
| 248 | $self->run_handler("postprocess.delete", \%in); | ||
| 249 | } | ||
| 250 | $action = "scan"; | ||
| 251 | } elsif ($action eq "do_search") { | ||
| 252 | $self->scan($scan_table, \%in); | ||
| 253 | } elsif (!$dbh->exists($table)) { | ||
| 254 | return $self->show_form(\%in, "append"); | ||
| 255 | }; | ||
| 256 | |||
| 257 | if ($action eq "append") { | ||
| 258 | return $self->show_form(\%in, "append"); | ||
| 259 | } elsif ($action eq "search") { | ||
| 260 | return $self->show_form(\%in, "search"); | ||
| 261 | } elsif ($action eq "scan" || ($record == 0 && $action eq "")) { | ||
| 262 | return $self->scan($scan_table, \%in); | ||
| 263 | } elsif ($action eq "find_key_only") { | ||
| 264 | my (%key); | ||
| 265 | (@key{@keycols}) = (@in{@keycols}); | ||
| 266 | $record = $dbh->find($self->{'table'}, \%key, \%found, \$last); | ||
| 267 | } elsif ($action eq "find") { | ||
| 268 | $record = $dbh->find($self->{'table'}, \%in, \%found, \$last); | ||
| 269 | } elsif ($action eq "last") { | ||
| 270 | $dbh->open($self->{'table'}) || die; | ||
| 271 | while ($dbh->read(\%found)) { | ||
| 272 | $last++; | ||
| 273 | } | ||
| 274 | $dbh->close(); | ||
| 275 | $record = $last; | ||
| 276 | } else { | ||
| 277 | $record = $dbh->get_nth($scan_table, $record, \%found, \$last); | ||
| 278 | } | ||
| 279 | |||
| 280 | $self->{'record'} = $record; | ||
| 281 | $self->{'last'} = $last; | ||
| 282 | |||
| 283 | $record ? | ||
| 284 | return $self->show_form(\%found, "replace") : | ||
| 285 | return "Cannot find record $record"; | ||
| 286 | } | ||
| 287 | |||
| 288 | |||
| 289 | sub show_form { | ||
| 290 | my($self, $fref, $action) = @_; | ||
| 291 | my($dbh) = $self->{'storage'}; | ||
| 292 | my ($returnval); | ||
| 293 | my (%insert); | ||
| 294 | my($field, $next, $prev); | ||
| 295 | my($noedit); | ||
| 296 | my($last) = $self->{'last'}; | ||
| 297 | my($record) = $self->{'record'}; | ||
| 298 | my($form) = $self->{'form'}; | ||
| 299 | |||
| 300 | $self->run_handler("preprocess.show_form", $fref, \$form); | ||
| 301 | $insert{'header'} = "<TITLE>Table: $self->{'table'}</TITLE>"; | ||
| 302 | |||
| 303 | |||
| 304 | if ($action eq "replace") { | ||
| 305 | $next=$record+1; | ||
| 306 | $prev=$record-1; # | ||
| 307 | |||
| 308 | ($record==$last) && ($next=1); | ||
| 309 | ($record==1) && ($prev=$last); | ||
| 310 | if ($dbh->{'nocursor'} == 0) { | ||
| 311 | $insert{'top'} = "Record $record of $last\n<hr>\n"; | ||
| 312 | } else { | ||
| 313 | $insert{'top'} = ""; | ||
| 314 | } | ||
| 315 | |||
| 316 | |||
| 317 | |||
| 318 | if (!$self->{"menu_hide"}) { | ||
| 319 | $insert{'top'} .= ' | ||
| 320 | <A HREF="' . $self->{'script'} . 'RDBaction=scan#record' . | ||
| 321 | $self->{'record'} . '">Scan</A> | ||
| 322 | '; | ||
| 323 | if ($dbh->{'nocursor'} == 0) { | ||
| 324 | $insert{'top'} .= " | ||
| 325 | <A HREF=\"$self->{'script'}RDBaction=search\">Search</a> | ||
| 326 | <A HREF=\"$self->{'script'}RDBrecord=1\">First</a> | ||
| 327 | <A HREF=\"$self->{'script'}RDBrecord=$prev\">Previous</a> | ||
| 328 | <A HREF=\"$self->{'script'}RDBrecord=$next\">Next</a> | ||
| 329 | <A HREF=\"$self->{'script'}RDBrecord=$last\">Last</a>"; | ||
| 330 | } | ||
| 331 | } | ||
| 332 | |||
| 333 | |||
| 334 | $self->permission("append") && | ||
| 335 | ($insert{'top'} .= " <A HREF=\"". $self->{'script'} . | ||
| 336 | "RDBaction=append\">Append</a>"); | ||
| 337 | |||
| 338 | $insert{'top'} .= "<HR>\n"; | ||
| 339 | |||
| 340 | if ($self->permission("write") || $self->permission("delete")) { | ||
| 341 | $insert{'top'} .= "<FORM METHOD=POST ACTION=$ENV{'SCRIPT_NAME'}> | ||
| 342 | <INPUT TYPE=hidden NAME=RDBrecord VALUE=$self->{'record'}> | ||
| 343 | <INPUT TYPE=hidden NAME=RDBlast VALUE=$self->{'last'}> | ||
| 344 | "; | ||
| 345 | |||
| 346 | foreach $field (keys %{$self->{'attrib'}}) { | ||
| 347 | $insert{'top'} .= | ||
| 348 | "<INPUT TYPE=\"hidden\" NAME=\"$field\" VALUE=\"$self->{'attrib'}->{$_}\">"; | ||
| 349 | } | ||
| 350 | |||
| 351 | foreach $field (@{$self->{'keycols'}}) { | ||
| 352 | $insert{'top'} .= '<input type="hidden" name="'. $field . '.old" value="'. $fref->{$field} . '">'. "\n"; | ||
| 353 | } | ||
| 354 | $insert{'bottom'} .= "<p>"; | ||
| 355 | $self->permission("write") && ($insert{'bottom'} .= | ||
| 356 | '<input type="radio" name="RDBaction" value="do_replace" CHECKED>Replace'); | ||
| 357 | $self->permission("delete") && ($insert{'bottom'} .= | ||
| 358 | '<input type="radio" name="RDBaction" value="do_delete">Delete'); | ||
| 359 | $insert{'bottom'} .= "<br>\n" | ||
| 360 | . '<input type="submit" name="RDBsubmit" value="'. | ||
| 361 | $self->{'submit_form_marker'} . '">'. '</FORM>'; | ||
| 362 | $noedit = 0; | ||
| 363 | |||
| 364 | } else { | ||
| 365 | $noedit=1; | ||
| 366 | } | ||
| 367 | |||
| 368 | } elsif ($action eq "append") { | ||
| 369 | (!$self->permission("append")) && return ""; | ||
| 370 | $insert{'top'} = "<hr>"; | ||
| 371 | if (!$self->{"menu_hide"}) { | ||
| 372 | $insert{'top'} .= "<A HREF=\"$self->{'script'}RDBaction=scan\">Scan</a> | ||
| 373 | <hr> | ||
| 374 | "; | ||
| 375 | } | ||
| 376 | |||
| 377 | |||
| 378 | if ($self->permission("append")) { | ||
| 379 | $insert{'top'} .= "Appending record<br> | ||
| 380 | <FORM METHOD=POST ACTION=$ENV{'SCRIPT_NAME'}> | ||
| 381 | <INPUT type=hidden name=RDBaction value=do_append>"; | ||
| 382 | foreach $field (keys %{$self->{'attrib'}}) { | ||
| 383 | $insert{'top'} .= '<INPUT TYPE="hidden" NAME="' . | ||
| 384 | $field . '" VALUE="' . | ||
| 385 | $self->{'attrib'}->{$field} . '">'; | ||
| 386 | } | ||
| 387 | |||
| 388 | $insert{'bottom'} = "<hr> | ||
| 389 | <input type=submit name=RDBsubmit value=\"$self->{'submit_append_marker'}\"> | ||
| 390 | </FORM> | ||
| 391 | "; | ||
| 392 | } | ||
| 393 | |||
| 394 | } elsif ($action eq "search") { | ||
| 395 | $insert{'top'} = "<hr>"; | ||
| 396 | |||
| 397 | if (!$self->{"menu_hide"}) { | ||
| 398 | $insert{'top'} .= '<A HREF="' . | ||
| 399 | $self->{'script'} . | ||
| 400 | 'RDBaction=scan">Scan</a> | ||
| 401 | <hr> | ||
| 402 | '; | ||
| 403 | } | ||
| 404 | $insert{'top'} .= "Search record<br> | ||
| 405 | <FORM METHOD=POST ACTION=$ENV{'SCRIPT_NAME'}> | ||
| 406 | <INPUT type=hidden name=RDBaction value=do_search>"; | ||
| 407 | foreach (keys %{$self->{'attrib'}}) { | ||
| 408 | $insert{'top'} .= '<INPUT TYPE=hidden NAME="' . | ||
| 409 | $_ . '" VALUE="' . | ||
| 410 | $self->{'attrib'}->{$_} . '">'; | ||
| 411 | } | ||
| 412 | |||
| 413 | $insert{'bottom'} = "<hr> | ||
| 414 | <input type=submit name=RDBsubmit value=\"$self->{'submit_search_marker'}\"> | ||
| 415 | </FORM> | ||
| 416 | "; | ||
| 417 | } | ||
| 418 | |||
| 419 | $returnval .= $insert{'header'}; | ||
| 420 | $returnval .= $insert{'top'}; | ||
| 421 | $returnval .= $self->{'status_out'}; | ||
| 422 | $returnval .= $self->fill_form($form, $fref, $noedit); | ||
| 423 | $returnval .= $insert{'bottom'}; | ||
| 424 | $self->run_handler("postprocess.show_form", $fref, \$returnval); | ||
| 425 | return $returnval; | ||
| 426 | } | ||
| 427 | |||
| 428 | |||
| 429 | sub scan { | ||
| 430 | my ($self, $scan_table, $keyref) = @_; | ||
| 431 | my ($returnval) = ""; | ||
| 432 | my (%f); | ||
| 433 | my ($dbh) = $self->{'storage'}; | ||
| 434 | $returnval .= $self->run_handler("scan_menu"); | ||
| 435 | $returnval .= $self->run_handler("scan_header"); | ||
| 436 | |||
| 437 | my ($j) = 1; | ||
| 438 | |||
| 439 | if (defined($scan_table) | ||
| 440 | && $scan_table ne "") { | ||
| 441 | $dbh->open($scan_table) || die; | ||
| 442 | loop: | ||
| 443 | while ($dbh->read(\%f)) { | ||
| 444 | if ($self->{'scan_page_size'} == 0 || | ||
| 445 | ($self->{'scan_page_start'} <= $j && | ||
| 446 | $j < $self->{'scan_page_start'} + | ||
| 447 | $self->{'scan_page_size'})) { | ||
| 448 | |||
| 449 | if ($keyref->{'RDBaction'} eq "do_search") { | ||
| 450 | my($key); | ||
| 451 | foreach $key (keys %{$keyref}) { | ||
| 452 | if ($key !~ /^RDB/ && $keyref->{$key} !~ /^\s*$/) { | ||
| 453 | if ($f{$key} !~ /$keyref->{$key}/i) { | ||
| 454 | next loop; | ||
| 455 | } | ||
| 456 | } | ||
| 457 | } | ||
| 458 | |||
| 459 | } | ||
| 460 | my ($href) = $self->{'script'}; | ||
| 461 | $href .= "RDBaction=find"; | ||
| 462 | foreach (@{$self->{'keycols'}}) { | ||
| 463 | $href .= "&$_=" . &cgi_quote($f{$_}); | ||
| 464 | } | ||
| 465 | $returnval .= $self->run_handler("scan_line", "record$j", | ||
| 466 | $href, \%f); | ||
| 467 | |||
| 468 | } | ||
| 469 | $j++; | ||
| 470 | } | ||
| 471 | |||
| 472 | $dbh->close(); | ||
| 473 | } | ||
| 474 | $returnval .= $self->run_handler("scan_footer"); | ||
| 475 | |||
| 476 | if ($self->{'scan_page_size'} > 0) { | ||
| 477 | my ($number_of_pages) = int(($j-1)/$self->{'scan_page_size'}) + 1; | ||
| 478 | my ($page_start) = $self->{'scan_page_start'}; | ||
| 479 | my ($page_size) = $self->{'scan_page_size'}; | ||
| 480 | my ($page_prev_start) = $page_start - $page_size; | ||
| 481 | my ($page_next_start) = $page_start + $page_size; | ||
| 482 | my ($page_cur_page) = int ($page_start / $page_size) + 1; | ||
| 483 | my ($i, $field); | ||
| 484 | my($script_root) = $self->{'script'}; | ||
| 485 | foreach $i (keys %{$keyref}) { | ||
| 486 | if ($i ne "RDBaction" && $i ne "RDBscan_page_size" && | ||
| 487 | $i ne "RDBscan_page_start") { | ||
| 488 | $script_root .= "${i}=" . &cgi_quote($keyref->{$i}) . "&"; | ||
| 489 | } | ||
| 490 | } | ||
| 491 | |||
| 492 | $returnval .= "<center>"; | ||
| 493 | |||
| 494 | if ($page_prev_start > 0) { | ||
| 495 | $returnval .= "<a href=${script_root}RDBaction=scan&RDBscan_page_size=${page_size}&RDBscan_page_start=${page_prev_start}>[Prev Page]</a>"; | ||
| 496 | } | ||
| 497 | foreach $i (1..$number_of_pages) { | ||
| 498 | my ($page_link_start) = | ||
| 499 | ($i-1) * $page_size + 1; | ||
| 500 | $returnval .= " "; | ||
| 501 | if ($i == $page_cur_page) { | ||
| 502 | $returnval .= "<b>"; | ||
| 503 | } else { | ||
| 504 | $returnval .= "<a href=${script_root}RDBaction=scan&RDBscan_page_size=${page_size}&RDBscan_page_start=${page_link_start}>"; | ||
| 505 | } | ||
| 506 | $returnval .= "[$i]"; | ||
| 507 | if ($i == $page_cur_page) { | ||
| 508 | $returnval .= "</b>"; | ||
| 509 | } else { | ||
| 510 | $returnval .= "</a>"; | ||
| 511 | } | ||
| 512 | $returnval .= " "; | ||
| 513 | |||
| 514 | } | ||
| 515 | |||
| 516 | if ($page_next_start <= $j) { | ||
| 517 | $returnval .= "<a href=${script_root}RDBaction=scan&RDBscan_page_size=${page_size}&RDBscan_page_start=${page_next_start}>[Next Page]</a>"; | ||
| 518 | } | ||
| 519 | $returnval .= "</center>"; | ||
| 520 | } | ||
| 521 | |||
| 522 | $returnval .= $self->{"page_footer"}; | ||
| 523 | return $returnval; | ||
| 524 | } | ||
| 525 | |||
| 526 | sub get_time { | ||
| 527 | my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time); | ||
| 528 | $year += 1900; | ||
| 529 | $mon++; | ||
| 530 | return sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, $hour, $min, $sec); | ||
| 531 | } | ||
| 532 | |||
| 533 | sub fill_form { | ||
| 534 | my($self, $input, $fref, $noedit) = @_; | ||
| 535 | |||
| 536 | |||
| 537 | return $self->{'fill_form'}->fill(scalarref=>\$input, | ||
| 538 | fdat=>$fref); | ||
| 539 | } | ||
| 540 | |||
| 541 | |||
| 542 | |||
| 543 | sub split_tag { | ||
| 544 | my($fulltag)=@_; | ||
| 545 | my($tagname,$etc,$var,$quote,$arg,$value,@tagargs); | ||
| 546 | undef $etc; | ||
| 547 | ($tagname,$etc)=$fulltag=~/\s*(\S+)\s*(.*)$/; | ||
| 548 | while ($etc!~/^\s*$/) { | ||
| 549 | ($arg,$var,$value,$etc)=$etc=~/\s*([^=\s]+)\s*(=)?\s*(\S+)?(.*)$/; | ||
| 550 | ($value,$etc)=((undef),$value.$etc) unless $var=~/^=$/; | ||
| 551 | ($quote)=$value=~/^([\"\'])/; | ||
| 552 | if ($quote) { | ||
| 553 | if ($value!~/.$quote$/) { | ||
| 554 | ($_,$etc)=$etc=~/^([^$quote]*)$quote?(.*)$/; | ||
| 555 | $value.=$_.$quote; | ||
| 556 | } | ||
| 557 | $value=~s/$quote\s*(.*)\s*$quote$/$1/; | ||
| 558 | $value=~s/\s*$//; | ||
| 559 | } | ||
| 560 | $arg="\U$arg\E"; | ||
| 561 | $arg =~ y/a-z/A-Z/; | ||
| 562 | push(@tagargs,$arg,$value); | ||
| 563 | } | ||
| 564 | |||
| 565 | $tagname="\U$tagname\E"; | ||
| 566 | $tagname =~ y/a-z/A-Z/; | ||
| 567 | ($tagname,@tagargs); | ||
| 568 | } | ||
| 569 | |||
| 570 | |||
| 571 | |||
| 572 | sub make_tag { | ||
| 573 | my($tag, %args) = @_; | ||
| 574 | local($_); | ||
| 575 | my ($output); | ||
| 576 | $output = "$tag "; | ||
| 577 | foreach (keys %args) { | ||
| 578 | $output .= "$_=\"$args{$_}\" "; | ||
| 579 | } | ||
| 580 | return $output; | ||
| 581 | } | ||
| 582 | |||
| 583 | sub cgi_quote { | ||
| 584 | my ($s) = @_; | ||
| 585 | $s =~ s/\%/%25/g; | ||
| 586 | $s =~ s/\+/%2b/g; | ||
| 587 | $s =~ s/ /%20/g; | ||
| 588 | $s =~ s/&/%26/g; | ||
| 589 | $s =~ s/</%3c/g; | ||
| 590 | $s =~ s/>/%3e/g; | ||
| 591 | $s =~ s/\;/%3b/g; | ||
| 592 | $s =~ s/!/%41/g; | ||
| 593 | $s =~ s/#/%23/g; | ||
| 594 | $s =~ s/\"/%22/g; | ||
| 595 | $s =~ s/\'/%27/g; | ||
| 596 | $s =~ s/\?/%3f/g; | ||
| 597 | $s =~ s/([\x00-\x1f]|[\x80-\xff])/"%" . sprintf("%x", ord($1)) /ge; | ||
| 598 | |||
| 599 | # Next line not strictly necessary but may break some browsers if not done | ||
| 600 | $s =~ s/\//%2f/g; | ||
| 601 | return $s; | ||
| 602 | } | ||
| 603 | |||
| 604 | sub set_handler { | ||
| 605 | my ($self, $value, $func) = @_; | ||
| 606 | $self->{'handler'}->{$value} = $func; | ||
| 607 | } | ||
| 608 | |||
| 609 | sub run_handler { | ||
| 610 | my ($self, $value, @args) = @_; | ||
| 611 | |||
| 612 | if (defined($self->{'handler'}->{$value})) { | ||
| 613 | return &{$self->{'handler'}->{$value}}($self, @args); | ||
| 614 | |||
| 615 | } | ||
| 616 | } | ||
| 617 | 1; |