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

  1. #!/usr/bin/perl
  2.  
  3. # $rcs = ' $Id: edit.cgi,v 1.2 1998/06/20 04:00:04 fitz Exp $ ' ;
  4.  
  5. unshift(@INC, "lib");
  6.  
  7. require 'bib.pl';
  8. require 'web.pl';
  9. require 'cgi-lib.pl';
  10.  
  11.  
  12. &ReadParse; # Read the script input
  13. print "Content-type: text/html\n";
  14.  
  15. &bib::load("CATEGORY", "KEYWORDS");
  16.  
  17. # Determine if we are running as an administrator
  18. $admin = ($ENV{SCRIPT_NAME} =~ m!/admin/! ? 1 : 0);
  19.  
  20. # If the ID is specified as part of the URL,
  21. # then we are editing an existing file
  22. #($id = $ENV{PATH_INFO}) =~ s!.*/!!;
  23. if ($ENV{PATH_INFO} =~ /.*\/(\d+)/)
  24. {
  25.     $id = $1;
  26. }
  27. if ($id)
  28. {
  29.     $heading = "Edit Bibliography Entry";
  30.  
  31.     &error("Invalid format for ID '$id'.")
  32.       unless $id =~ /^\d+$/;
  33.  
  34.     &error("Editing allowed only for administrators.")
  35.       unless $admin;
  36.  
  37.     %entry = &db::read_entry($id);
  38.     &error("Error reading bibliography entry for ID '$id': $db::error")
  39.       unless defined %entry;
  40. }
  41. else
  42. {
  43.     $heading = ($admin ?
  44.                 "Create Bibliography Entry" :
  45.                 "Submit Bibliography Entry");
  46.     %entry = ();
  47. }
  48.  
  49. # Get the categories
  50. @categories = &bib::get_categories();
  51. &error($bib::error) unless defined @categories;
  52.  
  53. # Get the keywords
  54. @keywords = &bib::get_keywords(1);
  55. &error($bib::error) unless defined @keywords;
  56.  
  57. # If they clicked the "Erase Changes",
  58. # revert to the last saved
  59. undef %in if $in{REVERT};
  60.  
  61. if (%in)
  62. {
  63.     # If the Delete button was pressed, redirect to another CGI
  64.     if ($in{delete})
  65.     {
  66.         $url = "$bib::admin_cgi/delete.cgi/$id";
  67.         print "Location: $url\n\n",
  68.         "This page has been redirected to<P><a href=\"$url\">$url</a>\n";
  69.         exit 0;
  70.     }
  71.  
  72.     # If they entered a new category,
  73.     # override the category selected in the list
  74.     $in{CATEGORY} = $in{NEW_CATEGORY} if $in{NEW_CATEGORY};
  75.  
  76.  
  77.     # If they selected multiple keywords,
  78.     # convert it into a single string,
  79.     # and include any additional keywords
  80.     if ($in{KEYWORDS})
  81.     {
  82.         my(@k) = &splitMultiple($in{KEYWORDS});
  83.         $in{KEYWORDS} = "@k";
  84.     }
  85.     $in{KEYWORDS} .= " $in{NEW_KEYWORDS}";
  86.  
  87.     # If the user is not an administrator, list the entry as
  88.     # preliminary 
  89.     unless ($admin)
  90.     {
  91.         $in{META} = "submit";
  92.  
  93.         &error("You must enter a submitter name and email address.")
  94.           unless ($in{SUBMITNAME} && $in{SUBMITADDR});
  95.     }
  96.  
  97.     if ($id2 = &bib::write_entry($id, %in))
  98.     {
  99.         if ($id)
  100.         {
  101.             &success("Wrote entry ID=$id<P>\n",
  102.                      "<A HREF=$bib::cgi/display.cgi/$id>Display Entry</A>\n");
  103.         }
  104.         elsif ($admin)
  105.         {
  106.             &success("Added new entry ID=$id2<P>\n",
  107.                      "<A HREF=$bib::cgi/display.cgi/$id2>Display Entry</A>\n");
  108.         }
  109.         else
  110.         {
  111.             $link = "http://$ENV{SERVER_NAME}$bib::cgi/display.cgi/$id2";
  112.  
  113.             &bib::sendmail("The following entry was submitted:" .
  114.                            "\n$link\n$in{TITLE}\n",
  115.                            "To: $bib::email{admin}",
  116.                            "Bcc: $bib::email{webmaster}",
  117.                            "From: $in{SUBMITADDR} ($in{SUBMITNAME})",
  118.                            "Subject: submission to SKEPTIC bibliography",)
  119.               || ($mail_error = "<P>Mail error: $bib::error");
  120.  
  121.             &success("Submitted new entry: it will not appear ",
  122.                      "in the bibliography until an administrator verifies it.<P>\n",
  123.                      "<A HREF=$bib::cgi/display.cgi/$id2>Display Entry</A>\n",
  124.                      $mail_error,
  125.                     );
  126.         }
  127.     }
  128.     else
  129.     {
  130.         # Validation or write error.
  131.         # Display the error, and redisplay the entry form
  132.         $vars = "<FONT COLOR=red SIZE=4><STRONG>Errors:</STRONG>"
  133.           . "<UL>$bib::error</UL></FONT>";
  134.         %entry = %in;
  135.  
  136.         $revert = "<INPUT TYPE=submit NAME=REVERT VALUE=\"Revert Entry to Last Saved\">" if $id;
  137.     }
  138. }
  139.  
  140.  
  141. # Construct a list of all current categories
  142. # and make sure the correct one is selected
  143. # if we are editing an existing entry
  144. foreach $category (@categories)
  145. {
  146.     $select = ($category eq $entry{CATEGORY}) ? "SELECTED" : "";
  147.     $categories .= "<OPTION $select>$category";
  148. }
  149.  
  150. # Construct a list of all current keywords
  151. # and make sure the correct ones are selected
  152. # if we are editing an existing entry
  153. foreach $keyword (@keywords)
  154. {
  155.     $select = "";
  156.     $select = "SELECTED"
  157.       if ($entry{KEYWORDS} =~ /\b$keyword\b/ &&
  158.           $entry{KEYWORDS} !~ /\b$keyword:/);
  159.     $keywords .= "<OPTION $select>$keyword";
  160. }
  161.  
  162.  
  163. # Make a copy of the entry, but untaint the values
  164. # so the special HTML characters are escaped
  165. %entry_untaint = &untaint_assoc(%entry);
  166. $entry_untaint{CATEGORY} = $categories;
  167. $entry_untaint{KEYWORDS} = $keywords;
  168.  
  169. $delete = "<INPUT TYPE=submit NAME=delete VALUE=\"Delete Entry...\">"
  170.   if $admin && $id;
  171. $newcat = "<INPUT NAME=NEW_CATEGORY VALUE=\"$entry_untaint{NEW_CATEGORY}\">"
  172.   if $admin;
  173. $revert = "<INPUT TYPE=reset VALUE=\"Erase Changes\">" unless $revert;
  174.  
  175. $data = &bib::template("edit.html",
  176.                        %entry_untaint,
  177.                        "HEADING", $heading,
  178.                        "VARS", $vars,
  179.                        "DELETE", $delete,
  180.                        "NEW_CATEGORY", $newcat,
  181.                        "REVERT", $revert,);
  182.  
  183. print "\n", &bib::template("basic.html",
  184.                            "TITLE", "Edit Entry $id",
  185.                            "DATA", $data);
  186.  
  187. exit 0;
  188.