(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 - 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~