Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
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.

pdfcontest.pl 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env perl
  2. use 5.008;
  3. =head1 DESCRIPTION
  4. PDFreaders campaign "Commercials on Public websites" form processing script.
  5. =head1 AUTHOR
  6. Alexander Kahl <e-user@fsfe.org>
  7. =cut
  8. use Cwd qw (abs_path);
  9. use File::Basename qw (dirname);
  10. my $root;
  11. BEGIN { $root = abs_path (dirname (__FILE__).'/..') };
  12. use lib "$root/tools";
  13. use CGI;
  14. use DateTime;
  15. use Template;
  16. use WebBuild::FormValidation;
  17. use WebBuild::DynamicContent;
  18. use strict;
  19. use warnings;
  20. use constant TEMPLATE => "$root/templates/pdfcontest.tt2.xml";
  21. use constant UPLOAD => "$root/upload/pdfreaders";
  22. # Start actual logic
  23. my $form = WebBuild::FormValidation->new;
  24. my $content = WebBuild::DynamicContent->new;
  25. my $query = CGI->new;
  26. $content->layout ("$root/campaigns/pdfreaders/bug-report-uk.en.html");
  27. $form->validates_presence_of ('institution-name');
  28. $form->validates_presence_of ('institution-country');
  29. $form->validate_format ('institution-url', type => 'url');
  30. $form->validates_presence_of ('institution-address');
  31. $form->validates_presence_of ('name');
  32. $form->validate_format ('email', type => 'email');
  33. # Group, Comment are optional
  34. if ($form->has_errors)
  35. {
  36. $content->content ($form->get_errors);
  37. $content->render;
  38. exit;
  39. }
  40. elsif ($query->param ('url')) # Bot!!
  41. {
  42. exit;
  43. }
  44. # Record data here
  45. my $template = Template->new ({ INCLUDE_PATH => "$root/templates" });
  46. my $mail;
  47. my $dt = DateTime->now;
  48. my $data = { institution_name => $query->param ('institution-name'),
  49. institution_country => $query->param ('institution-country'),
  50. institution_address => $query->param ('institution-address'),
  51. institution_email => $query->param ('institution-email'),
  52. institution_url => $query->param ('institution-url'),
  53. opened => sprintf ('%d-%.2d-%.2d', $dt->year, $dt->month, $dt->day),
  54. name => $query->param ('name'),
  55. email => $query->param ('email'),
  56. group => $query->param ('group') || '',
  57. petition => $query->param ('petition'),
  58. newsletter => $query->param ('newsletter'),
  59. contact => $query->param ('contact'),
  60. comment => $query->param ('comment') || '' };
  61. $template->process ('pdfreaders-mail.tt2', $data, \$mail);
  62. open MAIL, "|/usr/lib/sendmail -t -f web\@fsfeurope.org";
  63. print MAIL $mail;
  64. close MAIL;
  65. my $output = <<'EOF';
  66. <div id="flash">
  67. <p>All data recorded, we will get in touch with you very soon.</p>
  68. </div>
  69. EOF
  70. $content->content ($output);
  71. $content->render_utf8