]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Pb/Entry.pm
Use Redis and reindent code
[gruntmaster-page.git] / lib / Gruntmaster / Page / Pb / Entry.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page::Pb::Entry;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
10use Fcntl qw/:flock/;
11use HTML::Template::Compiled;
12use IO::File;
13use POSIX qw/strftime/;
42546e6c 14use File::Basename qw/fileparse/;
832cb45e 15use Gruntmaster::Page::Common qw/header footer/;
cd9af27e 16use Gruntmaster::Data qw/contest_start contest_end problem_name problem_statement/;
42546e6c
MG
17
18use constant FORMATS => [qw/CPP/];
19use constant TITLE => '<tmpl_var name>';
20
21my %templates = (
cd9af27e 22 en => <<'HTML',
42546e6c
MG
23<tmpl_var statement>
24
fe78f0c1 25<tmpl_if cansubmit>
42546e6c
MG
26<h1>Submit solution</h1>
27<form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data">
28<input type="hidden" name="problem" value="<tmpl_var id>">
fe78f0c1 29<tmpl_if_defined contest><input type="hidden" name="contest" value="<tmpl_var contest>"></tmpl_if_defined>
42546e6c
MG
30<label>File: <input name="prog" required type="file"></label>
31
32<label>File format: <select name="prog_format" required>
33<tmpl_loop formats><option value="<tmpl_var _>"><tmpl_var _></option>
34</tmpl_loop></select></label>
35
36<input type="submit" value="Submit job">
6d28cb38 37</form>
fe78f0c1 38</tmpl_if>
42546e6c
MG
39HTML
40);
41
42$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
43$templates{$_} .= footer $_ for keys %templates;
44
45sub generate{
cd9af27e 46 $_[0] =~ m,(?:ct/([^/])+/)?log/(\w+)\.html$,;
42546e6c 47
cd9af27e
MG
48 my ($contest, $id) = ($1, $2);
49 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
50
51 $htc->param(cansubmit => 1);
52 if (defined $contest) {
53 $htc->param(cansubmit => time >= contest_start $contest && time <= contest_end $contest);
54 $htc->param(contest => $contest);
55 }
56 $htc->param(formats => FORMATS);
57 $htc->param(id => $id);
58 local $Gruntmaster::Data::contest = ($_[0] =~ m,(?:ct/([^/])+/)?,)[0];
59 $htc->param(name => problem_name $id);
60 $htc->param(statement => problem_statement $id, $_[2]);
61 $htc->output
42546e6c
MG
62}
63
641
This page took 0.027813 seconds and 4 git commands to generate.