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

  1. #!/usr/bin/perl
  2.  
  3. # $rcs = ' $Id: categories.cgi,v 1.2 1998/06/20 03:58:58 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. # If they're submitting this form, write and exit
  16. &write_files_and_exit() if %in;
  17.  
  18. &bib::load("CATEGORY", "KEYWORDS");
  19.  
  20. # Determine if we are running as an administrator
  21. &error("Cannot run this CGI except from the admin subdir!")
  22.   unless $ENV{SCRIPT_NAME} =~ m!/admin/!;
  23.  
  24.  
  25. # Get the categories and descriptions
  26. @categories = &bib::get_categories();
  27. &error($bib::error) unless defined @categories;
  28. %categories = &bib::read_category_desc();
  29.  
  30. # Get the keywords
  31. @keywords = &bib::get_keywords();
  32. &error($bib::error) unless defined @keywords;
  33. %keywords = &bib::read_keyword_desc();
  34.  
  35. # Get the keyword modifiers
  36. @modifiers = &bib::get_modifiers();
  37. &error($bib::error) unless defined @modifiers;
  38. %modifiers = &bib::read_modifier_desc();
  39.  
  40. # Tables for the categories, keywords, and modifiers
  41. foreach $category (@categories)
  42. {
  43.     #$category =~ s/\W//g;
  44.     $t =
  45.       sprintf("<TR><TD>%s</TD><TD><INPUT SIZE=50 NAME=%s VALUE=\"%s\"></TD></TR>\n",
  46.               $category, "c_$category", &untaint($categories{$category}));
  47.     $categories{$category} ? ($categories .= $t) : ($categories = "$t$categories");
  48. }
  49. foreach $keyword (@keywords)
  50. {
  51.     #$keyword =~ s/\W//g;
  52.     $t =
  53.       sprintf("<TR><TD>%s</TD><TD><INPUT SIZE=50 NAME=%s VALUE=\"%s\"></TD></TR>\n",
  54.               $keyword, "k_$keyword", &untaint($keywords{$keyword}));
  55.     $keywords{$keyword} ? ($keywords .= $t) : ($keywords = "$t$keywords");
  56. }
  57. foreach $modifier (@modifiers)
  58. {
  59.     #$modifier =~ s/\W//g;
  60.     $t =
  61.       sprintf("<TR><TD>%s</TD><TD><INPUT SIZE=50 NAME=%s VALUE=\"%s\"></TD></TR>\n",
  62.               $modifier, "m_$modifier", &untaint($modifiers{$modifier}));
  63.     $modifiers{$modifier} ? ($modifiers .= $t) : ($modifiers = "$t$modifiers");
  64. }
  65.  
  66. $data = &bib::template("categories.html",
  67.                        "CATEGORIES", $categories,
  68.                        "KEYWORDS", $keywords,
  69.                        "MODIFIERS", $modifiers,);
  70.  
  71. $data = &bib::template("categories-form.html",
  72.                        "DATA", $data);
  73.  
  74. print "\n", &bib::template("basic.html",
  75.                            "TITLE", "Edit Keyword Descriptions",
  76.                            "DATA", $data);
  77.  
  78. exit 0;
  79.  
  80.  
  81. sub write_files_and_exit
  82. {
  83.     my($k,$name,$c,%category_desc,%keyword_desc,%modifier_desc);
  84.  
  85.     foreach $k (keys %in)
  86.     {
  87.         if ($k =~ /^c_(.*)/)
  88.         {
  89.             $name = $1;
  90.             $category_desc{$name} = $in{$k};
  91.             $c++;
  92.             next;
  93.         }
  94.         elsif ($k =~ /^k_(.*)/)
  95.         {
  96.             $name = $1;
  97.             $keyword_desc{$name} = $in{$k};
  98.             $c++;
  99.             next;
  100.         }
  101.         elsif ($k =~ /^m_(.*)/)
  102.         {
  103.             $name = $1;
  104.             $modifier_desc{$name} = $in{$k};
  105.             $c++;
  106.             next;
  107.         }
  108.     }
  109.  
  110.     &error("Received no input!") unless $c;
  111.  
  112.     &bib::write_category_desc(%category_desc) ||
  113.       &error("Cannot write category description file: $bib::error");
  114.     &bib::write_keyword_desc(%keyword_desc) ||
  115.       &error("Cannot write keyword description file: $bib::error");
  116.     &bib::write_modifier_desc(%modifier_desc) ||
  117.       &error("Cannot write modifier description file: $bib::error");
  118.  
  119.     &success("Updated all description files.");
  120. }
  121.