(UnRegistered) DLSuperC Insert and Delete Side-By-Side Report 6/23/2001 12:03:49 PM Panel 1 -- New Source Matches + Inserts Panel 2 -- New Source Matches + Deletes New File = c:\windows\desktop\display.cgi.new 6/22/2001 12:56:00 AM New File = c:\windows\desktop\display.cgi.new 6/22/2001 12:56:00 AM Old File = c:\windows\desktop\display.cgi.original 11/13/2000 2:57:00 AM Old File = c:\windows\desktop\display.cgi.original 11/13/2000 2:57:00 AM Ref# ID ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 Ref# ID ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 1 #!/usr/bin/perl 1 #!/usr/bin/perl 2 2 3 I - # last revised: # May 2001 for www.ghtRx.com # Roger Davies # www.ssdirect.com # 3 D - ############################################################## 4 I - # based on: # Display.cgi for Database_Doctor.cgi # Mike Carville # www.web-baza 4 D - # 5 I - $database = "_database/ghtrx.dat"; 5 D - # Display.cgi for Database_Doctor.cgi 6 I - @searchterms = ("Name","City","Condition","Product","Heading","Result"); 6 D - # Mike Carville 7 I - $debug=0; #1=yes,0=no debug print .. 7 D - # www.web-bazaar.com 8 8 D - # carville@web-bazaar.com 9 9 D - # 10 10 D - # This script is made available free of charge. 11 11 D - # Please leave my name in the header section. 12 12 D - # You may not sell this script for any reason. 13 13 D - # While not required, please leave the banner in the footer 14 14 D - # in the manager script to help fund further development. 15 15 D - # 16 16 D - # If you are really thrilled with this script, why not help 17 17 D - # us both out and buy a reference book from our scripts page. 18 18 D - # We get a commission, you get knowledge, and Amazon stockholders 19 19 D - # breathe easier for another day. <:-) 20 20 D - # 21 21 D - # I originally wrote the Database Doctor to manage inventory files for webstores 22 22 D - # specifically Selena Sols. But since everyone has an imagination and is general 23 23 D - # looking for the best fit of something existing to a custom project, people 24 24 D - # were constantly asking for a front end. 25 25 D - # 26 26 D - # Ok, so now you have it. 27 27 D - # 28 28 D - # Display.cgi will display your flat file database made in Database Doctor, 29 29 D - # or just about any I suppose. I believe I have given you a way to be really 30 30 D - # creative with the html as well. You be the judge, As always, to make something 31 31 D - # better, it gets more complicated. 32 32 D - # 33 33 D - # After we discuss the file setup here, read below, as there more comments place 34 34 D - # to help you use this to it's fullest. 35 35 D - # 36 36 D - # The working example of what I am using this for is at www.fsfprs.com 37 37 D - # A database of Facial Plastic Surgeons. 38 38 D - # 39 39 D - # Main CGI Directory 40 40 D - # -------------- 41 41 D - # display.cgi (permission 755) 42 42 D - # 43 43 D - # Data 44 44 D - # -------------- 45 45 D - # Set this line to the location of the data file you wish to search and display 46 46 D - # *This is a server path without a slash on the end.* 47 47 DM- 48 48 D - $datafile = "fsfprs.dat"; 49 49 D - 50 50 D - # HTML Files 51 51 D - # -------------- 52 52 D - # This script uses templates for the header of the page, 53 53 D - # the footer of the page, and a search form. Note the Usage of the 54 54 D - # example files provided. These are SECTIONS of a page... 55 55 D - # not the whole page...hint hint. 56 56 D - # 57 57 D - 58 58 D - 59 59 D - 60 60 D - # HTML Files Required 61 61 D - # ------------------- 62 62 D - # These files must exist, even if empty. They must be in the same directory as 63 63 D - # 64 64 D - # display_header.dat 65 65 D - # -html for the top of the web page created. Starts with and has a full h 66 66 D - # 67 67 D - # display_footer.dat 68 68 D - # -html for the bottom of the page. Ends with DOES NOT INCLUDE THE $search_form

180 D -
181 I -
181 D - 182 I - 182 D - 186 !; # end of print statement 186 !; # end of print statement 187 } 187 } 188 188 189 I - sub table_row { 189 D - # Not So Basic...the individual search result 190 I - $name="";$city="";$email="";$website="";$condition="";$product=""; 190 D - # ------------------------------------------- 191 I - if ($field[1] ne "") {$name="$field[1]";} else {$name="not given";} 191 D - # 192 I - if ($field[2] ne "") {$city="$field[2] $field[3]";} else {$city="$field[3]";} 192 D - # You have a lot of options here, and a little perl knowledge will help. However 193 I - if ($field[4] ne "") {$email="Email: $field[4] 193 D - # tell you everything you need to know. At the bottom is a specific example of a 194 I - if ($field[5] ne "") {$website="Website: $field[5] 194 D - # Don't be afraid to try! 195 I - if ($field[6] ne "") {$condition="Condition: $field[6]";} 195 D - # 196 I - if ($field[7] ne "") {$product="Product: $field[7]";} 196 D - # The program is taking the result and splitting it up into an array. You can th 197 197 D - # whatever parts of this individual line here by using a variable. 198 198 D - # 199 199 D - # We have split the line into the array @field. Individual parts of the array ar 200 200 D - # telling it what number you want. 201 201 D - # 202 202 D - # VERY IMPORTANT...arrays start counting from zero! 203 203 D - # 204 204 D - # So the first field in the line is $field[0], the fifth $field[4] etc... 205 205 D - # 206 206 D - # The variable name field is case sensitive! 207 207 D - # 208 208 D - # Include any html you want, and place your fields in any order. If you want to 209 209 D - # rows of color, set your table row to include , and set th 210 210 D - # The use of other variables is explained below. Otherwise $email and others hav 211 211 D - 212 212 D - sub table_row 213 213 D - { 214 214 D - $email="";$website="";$name=""; 215 215 D - 216 216 D - if ($field[2] ne "") 217 217 D - {$name="
$field[2]";} 218 218 D - 219 219 D - if ($field[4] ne "") 220 220 D - {$email="
Email:
$field[0] $field[1]";} 221 221 D - 222 222 D - if ($field[5] ne "") 223 223 D - {$website="
Website: $field[5]";} 224 224 D - 225 print qq! 225 print qq! 226 I - 226 D - 227 I - 237 I - 240 241 !; 241 !; 242 } 242 } 243 243 244 I - sub table_footer { 244 D - # Table Footer or Bottom of Display 245 245 D - # ------------------------------ 246 246 D - # 247 247 D - # really basic here...just html 248 248 D - # but I would caution you that Netscape will not show incomplete tables 249 249 D - # ...so make sure you close it out. 250 250 D - 251 251 D - sub table_footer 252 252 D - { 253 print qq! 253 print qq! 254 I - 254 D - 255 I -
Name< 183 I - Sou 183 D - 184 I - Tes 184 D - Comment 185 D -
227 D - 228 I - $field[0] $field[1] of $field[3] 229 I - 229 D - $name 230 I - 230 D - $email 231 I - 231 D - $website 232 I - 232 D - 233 I - 233 D - 234 I - 234 D - 235 D - $field[6]   236 I -
$name
$city
$email
$website
$condition
$product
235 I -
Date: $field[0]
236 D -
237 D - 238 I -
$field[8]
$field[10]
239 240 I -

 
255 D -    256 256 D - 257 257 D - 258 258 D - 259 259 D - 260 !; 260 !; 261 } 261 } 262 262 263 I - # End Of configure # 263 D - # Customization Example 264 264 D - # ------------------------------ 265 265 D - # 266 266 D - # In my original usage for the script I have email and website addresses. 267 267 D - # Some lines have them, and some don't. I only want to show them if they exist. 268 268 D - # You can do this for as many of the fields as you like. 269 269 D - # So we make a little if statement... 270 270 D - # 271 271 D - # if ($field[5] ne "") 272 272 D - # 273 273 D - # This is using a double negative...and reads if the 4th 274 274 D - # field is not equal to nothing, then it is something and do this... 275 275 D - # 276 276 D - # {$address2="
$field[5]";} 277 277 D - # 278 278 D - # What we do next is set the value of the field to a variable name. We then put 279 279 D - # in the the table row html where we would want it if it existed. If it exists, 280 280 D - # If it does have no value, nothing will appear. 281 281 D - # 282 282 D - # But Perl Programmers..this leaves us open to a lttle programming problem. 283 283 D - # ...if one line has a value, and the next does not, we need to clear 284 284 D - # out the value of our variable beforehand. We do this by setting the value of t 285 285 D - # we are using before we ask the if question and possible set a value. 286 286 D - # 287 287 D - # Below is the all of this put together. Remember to take out the comments (#) i 288 288 289 I - # Parse web form 289 D - 290 290 D - # $address2="";$email="";$website="";$name=""; 291 291 D - # 292 292 D - # 293 293 D - # if ($field[5] ne "") 294 294 D - # {$address2="
$field[5]";} 295 295 D - # 296 296 D - # if ($field[3] ne "") 297 297 D - # {$name="$field[3]";} 298 298 D - # 299 299 D - # if ($field[12] ne "") 300 300 D - # {$email="
Email: $field[12]";} 301 301 D - # 302 302 D - # if ($field[13] ne "") 303 303 D - # {$website="
Website: $field[13]";} 304 304 D - 305 305 D - 306 306 D - ############################################################## 307 307 D - ############################################################## 308 308 D - # End Of configure 309 309 D - ############################################################## 310 310 D - ############################################################## 311 311 D - 312 312 D - 313 313 D - ############################################################## 314 314 D - # Parse from the web form 315 315 D - ############################################################## 316 (!$ENV{'REQUEST_METHOD'}) && (die __FILE__.' line '.__LINE__." No Request method 316 (!$ENV{'REQUEST_METHOD'}) && (die __FILE__.' line '.__LINE__." No Request method 317 317 D - 318 318 D - ## If method is GET or HEAD, fetch the query from the environment. 319 319 D - 320 if ($ENV{'REQUEST_METHOD'} =~ /^(GET|HEAD)$/){ 320 if ($ENV{'REQUEST_METHOD'} =~ /^(GET|HEAD)$/){ 321 $query_string = $ENV{'QUERY_STRING'}; 321 $query_string = $ENV{'QUERY_STRING'}; 322 I - if(!$query_string) { # could just be a link into the script 322 D - 323 323 D - if(!$query_string) 324 324 D - { # could just be a link into the script 325 $form{1}=1; # so we have a defined value and the system will fire 325 $form{1}=1; # so we have a defined value and the system will fire 326 } 326 } 327 327 D - 328 } 328 } 329 329 D - 330 330 D - ## If the method is POST, fetch the query from standard input. 331 331 D - 332 if ($ENV{'REQUEST_METHOD'} eq 'POST'){ 332 if ($ENV{'REQUEST_METHOD'} eq 'POST'){ 333 333 D - 334 $length = $ENV{'CONTENT_LENGTH'} if $ENV{'CONTENT_LENGTH'}; 334 $length = $ENV{'CONTENT_LENGTH'} if $ENV{'CONTENT_LENGTH'}; 335 335 D - 336 336 D - ## no content length, and something is wrong, die to prevent further problems 337 (!$length) && (die __FILE__.' line '.__LINE__." No content length with with POS 337 (!$length) && (die __FILE__.' line '.__LINE__." No content length with with POS 338 I - # if length is to long, then someone is probably attempting to crack the system 338 D - 339 I - ($length > 16384) and (die __FILE__.' line '.__LINE__." Content Length exceede 339 D - ## if length is to long, then someone is probably attempting to crack the syste 340 I - # ok, this is probably ok 340 D - ($length > 163840) and (die __FILE__.' line '.__LINE__." Content Length exceed 341 341 D - 342 342 D - ## ok, this is probably ok 343 while($length){ 343 while($length){ 344 $query_string .= getc(*STDIN); 344 $query_string .= getc(*STDIN); 345 $length--; 345 $length--; 346 } 346 } 347 I - # we failed somehow 347 D - 348 348 D - ## we failed somehow 349 !$query_string && (die __FILE__.' line '.__LINE__." No standard input with POST 349 !$query_string && (die __FILE__.' line '.__LINE__." No standard input with POST 350 350 D - 351 } 351 } 352 I - # query string available, break down to key/value pairs 352 D - 353 353 D - 354 354 D - ## We've gotten this far, our query string is available, 355 355 D - ## break it down to key/value pairs 356 356 D - 357 my(@pairs) = split('&',$query_string); 357 my(@pairs) = split('&',$query_string); 358 my($key,$value); 358 my($key,$value); 359 359 D - 360 360 D - my(@pairs) = split('&',$query_string); 361 361 D - my($key,$value); 362 362 D - 363 foreach (@pairs){ 363 foreach (@pairs){ 364 ($key,$value) = split('='); 364 ($key,$value) = split('='); 365 $key = &unescape($key); # convert pairs to something usable 365 $key = &unescape($key); # convert pairs to something usable 366 !$key and next; 366 !$key and next; 367 !$value and next; 367 !$value and next; 368 $value = &unescape($value); 368 $value = &unescape($value); 369 $form{$key} = $value; # load our hash 369 $form{$key} = $value; # load our hash 370 } 370 } 371 371 372 372 D - 373 373 D - 374 374 D - 375 375 D - ##-------------------------------------Sub unescape -----------------------## 376 376 D - 377 sub unescape { 377 sub unescape { 378 my($string) = @_; 378 my($string) = @_; 379 $string =~ tr/+/ /; # pluses become spaces 379 $string =~ tr/+/ /; # pluses become spaces 380 $string =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; 380 $string =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; 381 return $string; 381 return $string; 382 } 382 } 383 383 384 I - # Read in html forms 384 D - 385 385 D - 386 print "Content-type: text/html\n\n"; 386 print "Content-type: text/html\n\n"; 387 I - $header=""; $search_form=""; $footer=""; 387 D - 388 I - open (FILE, "display_top.dat") || die print "display_top.dat"; 388 D - ############################################################## 389 I - while(){ 389 D - # Read in data and decide what to do 390 I - $row = $_;chop $row; 390 D - ############################################################## 391 I - $header .= "$row\n"; 391 D - 392 IM- } 392 D - 393 IM- close (FILE); 393 D - 394 I - open (FILE, "display_form.dat") || die print "display_form.dat"; 394 D - open (FILE, "display_header.dat") || die print "$html_path/display_header.dat"; 395 I - while(){ 395 D - while() 396 I - $row = $_;chop $row; 396 D - {$row = $_;chop $row; 397 I - $search_form .= "$row\n"; 397 D - $header .= "$row\n";} 398 IM- } 398 399 IM- close (FILE); 399 400 I - open (FILE, "display_add.dat") || die print "display_add.dat"; 400 401 I - while(){ 401 402 I - $row = $_;chop $row; 402 403 I - $add_form .= "$row\n"; 403 404 I - } 404 405 I - close (FILE); 405 406 I - open (FILE, "display_bot.dat") || die print "display_bot.dat"; 406 407 I - while(){ 407 408 I - $row = $_;chop $row; 408 409 I - $footer .= "$row\n"; 409 410 I - } 410 411 close (FILE); 411 close (FILE); 412 412 413 I - # Display Addition Form 413 D - open (FILE, "display_footer.dat") || die print "display_footer.dat"; 414 I - if ($form {'display'}){ 414 D - while() 415 I - print "$header"; 415 D - {$row = $_;chop $row; 416 I - print qq~
~; 416 D - $footer .= "$row\n";} 417 I - print "$add_form"; 417 DM- close (FILE); 418 I - print qq~

) 422 I - # Make the Addition 422 D - {$row = $_;chop $row; 423 I - if ($form {'add'}){ 423 D - $search_form .= "$row\n";} 424 I - $form{'Result'} =~ (s/\r\n/
/g); 424 DM- close (FILE); 425 I - foreach $table_fields (@table_fields) {push (@row, "$form{$table_fields}");} 425 D - 426 I - $new_row = join ("\|", @row); 426 D - 427 I - open (DATABASE, ">>$database"); 427 D - 428 I - print DATABASE "$new_row\n"; 428 D - open (DATABASE, "$datafile") || die print "$datafile"; 429 I - close (DATABASE); 429 430 I - print "

$form{$table_fields[1]} Item added to the Database

"; 430 431 I - } 431 432 I - # get data 432 433 I - open (DATABASE, "$database") || die print "$database"; 433 434 @data=; 434 @data=; 435 close (DATABASE); 435 close (DATABASE); 436 436 D - 437 $counter = 1; 437 $counter = 1; 438 I - foreach $data(@data) { 438 D - 439 I - $search_data{$counter} = $data; 439 D - foreach $data(@data) 440 I - $counter++; 440 D - {$search_data{$counter} = $data; $counter++;} 441 I - } 441 D - 442 $counter = 0; 442 $counter = 0; 443 I - foreach $table_fields(@table_fields) { 443 D - 444 I - $field_placement{$table_fields} = "$counter"; 444 D - foreach $table_fields(@table_fields) 445 I - $counter++; 445 D - {$field_placement{$table_fields} = "$counter"; $counter++;} 446 I - } 446 D - 447 I - # set up search keys 447 D - 448 448 D - ############################################################## 449 449 D - # Search if necessary 450 450 D - ############################################################## 451 $results_counter = 1; 451 $results_counter = 1; 452 I - if ($form{'search'}){ 452 D - 453 453 D - if ($form{'search'}) 454 454 D - { 455 455 D - 456 $search_terms_present = 0; 456 $search_terms_present = 0; 457 457 D - 458 # Split keywords 458 # Split keywords 459 I - @searchText = split(/\x20/,$form{'searchtext'}); # split at spaces 459 D - ######################################### 460 I - foreach $test (@searchText) {if ($test =~ /\S{2,}/) {push @searchKey, $test;}} 460 D - @searchText = split(/\x20/,$form{'searchtext'}); 461 461 D - 462 462 D - foreach $test (@searchText) 463 463 D - {if ($test =~ /\S{2,}/){ push @searchKey, $test;}} 464 464 D - 465 # Prepare Link 465 # Prepare Link 466 466 D - ######################################### 467 $search_query = "search=1"; 467 $search_query = "search=1"; 468 468 D - 469 $form{'searchtext'} and $search_query .= "&searchtext=$form{'searchtext'}" and 469 $form{'searchtext'} and $search_query .= "&searchtext=$form{'searchtext'}" and 470 I - foreach $searchterms(@searchterms) { 470 D - 471 I - if ($debug) {print "
1 searchterm=$searchterms \n";} 471 D - foreach $searchterms(@searchterms) 472 I - $form{$searchterms} ne "" and $search_query .= "&$searchterms=$form{$searchte 472 D - {$form{$searchterms} ne "" and $search_query .= "&$searchterms=$form{$searchter 473 I - } 473 D - 474 474 D - 475 # Loop Through Data 475 # Loop Through Data 476 I - foreach $key(keys %search_data){ 476 D - ######################################### 477 477 D - foreach $key(keys %search_data) 478 478 D - { 479 479 D - 480 $found = 0; 480 $found = 0; 481 481 D - 482 @line = split (/\|/, $search_data{$key}); 482 @line = split (/\|/, $search_data{$key}); 483 483 D - 484 # For those of you keeping score here...@line is the array we split, 484 # For those of you keeping score here...@line is the array we split, 485 # $key is a number which relates to the original data hash 485 # $key is a number which relates to the original data hash 486 # %field_placement relates to the position of the field we are searching for 486 # %field_placement relates to the position of the field we are searching for 487 487 D - 488 488 D - 489 489 D - 490 # Custom Searching 490 # Custom Searching 491 I - # foreach $searchterms(@searchterms) {$form{$searchterms} and $line[$field_pl 491 D - ######################################### 492 492 D - foreach $searchterms(@searchterms) 493 493 D - {$form{$searchterms} and $line[$field_placement{$searchterms}] =~ /\b$form{$sea 494 494 D - 495 # Text Searching 495 # Text Searching 496 I - if ($form{'searchtext'}){ 496 D - ######################################### 497 I - foreach $test(@searchKey) { 497 D - 498 I - $search_data{$key} =~ /\b$test\b/i and $found++; 498 D - if ($form{'searchtext'}) 499 I - if ($debug) {print "
2 found=$found test=$test vs search_data(key)=sear 499 D - { 500 I - } 500 D - 501 I - } 501 D - foreach $test(@searchKey) 502 I - # end if we have search text 502 D - {$search_data{$key} =~ /\b$test\b/i and $found++;} 503 I - # Check Results # if we find something we make a new hash relation ship calle 503 D - 504 I - if ($debug) {print "
3 found=$found search_terms_present=$search_terms_pr 504 D - } # end if we have search text 505 I - $found > 0 and $found >= $search_terms_present and do{ 505 D - 506 506 D - # Check Results 507 507 D - ######################################### 508 508 D - # if we find something we make a new hash relation ship called %search_results 509 509 D - 510 510 D - $found > 0 and $found == $search_terms_present and do{ 511 $search_results{$key} = $search_data{$key}; 511 $search_results{$key} = $search_data{$key}; 512 $result_map{$results_counter} = $key; 512 $result_map{$results_counter} = $key; 513 $results_counter++; 513 $results_counter++; 514 I - if ($debug) {print "
4 results_counter=$results_counter key=$key search_ 514 515 }; #end found do 515 }; #end found do 516 516 D - 517 } #end foreach search key 517 } #end foreach search key 518 518 D - 519 519 D - 520 520 D - 521 } # end search routines 521 } # end search routines 522 IM- 522 D - ############################################################## 523 # Begin the page of results 523 # Begin the page of results 524 524 D - ############################################################## 525 print "$header"; 525 print "$header"; 526 526 D - 527 $starting_point = $form{'starting_point'}; 527 $starting_point = $form{'starting_point'}; 528 !$starting_point and $starting_point = 1; 528 !$starting_point and $starting_point = 1; 529 529 D - 530 $current_page_number = int($form{'starting_point'}/$limit_of_search_results) +1 530 $current_page_number = int($form{'starting_point'}/$limit_of_search_results) +1 531 $end_point = ($current_page_number * $limit_of_search_results); 531 $end_point = ($current_page_number * $limit_of_search_results); 532 I - # Build next_results_link .. 532 D - 533 533 D - if (%search_results) 534 534 D - { 535 535 DM- &table_header; 536 536 DM- $result = $starting_point; 537 537 D - for $result($starting_point..$end_point) 538 538 D - { 539 539 D - 540 540 DM- !$search_results{$result_map{$result}} and next; 541 541 D - 542 542 DM- $last_displayed = $result; 543 543 D - 544 544 DM- @field = split (/\|/, $search_results{$result_map{$result}}); 545 545 D - 546 546 D - 547 547 D - if ($bgcount > 1) 548 548 D - {$bgcolor=$bgcolor2;$bgcount=1;} 549 549 D - else 550 550 D - {$bgcolor=$bgcolor1;$bgcount=2;} 551 551 D - 552 552 DM- &table_row; 553 553 DM- } 554 554 D - 555 555 DM- &table_footer; 556 556 DM- } 557 557 D - else 558 558 D - { 559 559 D - print "