Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

  1. #!/usr/local/bin/perl
  2. use CGI qw(:standard);
  3. @ANIMALS=sort qw/lion tiger bear pig porcupine ferret zebra gnu ostrich
  4. emu moa goat weasel yak chicken sheep hyena dodo lounge-lizard
  5. squirrel rat mouse hedgehog racoon baboon kangaroo hippopotamus
  6. giraffe/;
  7. # Recover the previous animals from the magic cookie.
  8. # The cookie has been formatted as an associative array
  9. # mapping animal name to the number of animals.
  10. %zoo = cookie('animals');
  11. # Recover the new animal(s) from the parameter 'new_animal'
  12. @new = param('new_animals');
  13. # If the action is 'add', then add new animals to the zoo. Otherwise
  14. # delete them.
  15. foreach (@new) {
  16. if (param('action') eq 'Add') {
  17. $zoo{$_}++;
  18. } elsif (param('action') eq 'Delete') {
  19. $zoo{$_}-- if $zoo{$_};
  20. delete $zoo{$_} unless $zoo{$_};
  21. }
  22. }
  23. # Add new animals to old, and put them in a cookie
  24. $the_cookie = cookie(-name=>'animals',
  25. -value=>\%zoo,
  26. -expires=>'+1h');
  27. # Print the header, incorporating the cookie and the expiration date...
  28. print header(-cookie=>$the_cookie);
  29. # Now we're ready to create our HTML page.
  30. print start_html('Animal crackers');
  31. print <<EOF;
  32. <h1>Animal Crackers</h1>
  33. Choose the animals you want to add to the zoo, and click "add".
  34. Come back to this page any time within the next hour and the list of
  35. animals in the zoo will be resurrected. You can even quit Netscape
  36. completely!
  37. <p>
  38. Try adding the same animal several times to the list. Does this
  39. remind you vaguely of a shopping cart?
  40. <p>
  41. <em>This script only works with Netscape browsers</em>
  42. <p>
  43. <center>
  44. <table border>
  45. <tr><th>Add/Delete<th>Current Contents
  46. EOF
  47. ;
  48. print "<tr><td>",start_form;
  49. print scrolling_list(-name=>'new_animals',
  50. -values=>[@ANIMALS],
  51. -multiple=>1,
  52. -override=>1,
  53. -size=>10),"<br>";
  54. print submit(-name=>'action',-value=>'Delete'),
  55. submit(-name=>'action',-value=>'Add');
  56. print end_form;
  57. print "<td>";
  58. if (%zoo) { # make a table
  59. print "<ul>\n";
  60. foreach (sort keys %zoo) {
  61. print "<li>$zoo{$_} $_\n";
  62. }
  63. print "</ul>\n";
  64. } else {
  65. print "<strong>The zoo is empty.</strong>\n";
  66. }
  67. print "</table></center>";
  68. print <<EOF;
  69. <hr>
  70. <ADDRESS>Lincoln D. Stein</ADDRESS><BR>
  71. <A HREF="./">More Examples</A>
  72. EOF
  73. ;
  74. print end_html;