home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / skeptic / bibliography / admin / delete.cgi < prev    next >
Text File  |  2009-08-26  |  2KB  |  78 lines

  1. #!/usr/bin/perl
  2.  
  3. # $rcs = ' $Id: delete.cgi,v 1.2 1998/06/20 03:47:18 fitz Exp $ ' ;
  4.  
  5. unshift(@INC, "lib");
  6.  
  7. require 'web.pl';
  8. require 'cgi-lib.pl';
  9.  
  10.  
  11. &ReadParse; # Read the script input
  12. print "Content-type: text/html\n";
  13.  
  14. # Determine if we are running as an administrator
  15. $admin = ($ENV{SCRIPT_NAME} =~ m!/admin/! ? 1 : 0);
  16.  
  17. # If the ID is specified as part of the URL,
  18. # then we are editing an existing file
  19. ($id = $ENV{PATH_INFO}) =~ s!.*/!!;
  20. if ($id)
  21. {
  22.     &error("Invalid format for ID '$id'.")
  23.       unless $id =~ /^\d+$/;
  24.  
  25.     &error("Editing allowed only for administrators.")
  26.       unless $admin;
  27.  
  28.     %entry = &db::read_entry($id);
  29.     &error("Error reading bibliography entry for ID '$id': $db::error")
  30.       unless defined %entry;
  31. }
  32. else
  33. {
  34.     &error("There was no database ID specified as part of the URL.");
  35. }
  36.  
  37.  
  38. if (%in)
  39. {
  40.     $entry{META} = "delete";
  41.  
  42.     if ($in{delete_mark})
  43.     {
  44.         if (&bib::write_entry($id, %entry))
  45.         {
  46.             &success("Marked entry $id deleted.");
  47.         }
  48.     }
  49.     elsif ($in{delete_kill})
  50.     {
  51.         # Move to "killed" subdir
  52.         if (rename("$db::dir/$id$db::ext",
  53.                    "$db::dir/killed/$id$db::ext"))
  54.         {
  55.             &success("Killed entry $id.");
  56.         }
  57.     }
  58.     else
  59.     {
  60.         &error("Neither delete_mark nor delete_kill was specified - contact webmaster.");
  61.     }
  62.  
  63.     &error("Could not delete entry $id: $!");
  64. }
  65.  
  66. $entry = &bib::template("entry.html", %entry);
  67.  
  68. $data = &bib::template("delete.html",
  69.                        "ID", $id,
  70.                        "DATA", $entry,);
  71.  
  72.  
  73. print "\n", &bib::template("basic.html",
  74.                            "TITLE", "Delete Entry $id",
  75.                            "DATA", $data);
  76.  
  77. exit 0;
  78.