]>
Commit | Line | Data |
---|---|---|
1 | package Gruntmaster::Page::Pb::Entry; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | use parent qw/Exporter/; | |
7 | our @EXPORT_OK = qw/generate/; | |
8 | our $VERSION = '0.001'; | |
9 | ||
10 | use Fcntl qw/:flock/; | |
11 | use HTML::Template::Compiled; | |
12 | use IO::File; | |
13 | use POSIX qw/strftime/; | |
14 | use File::Basename qw/fileparse/; | |
15 | use Gruntmaster::Page::Common qw/header footer/; | |
16 | use Gruntmaster::Data qw/contest_start contest_end problem_name problem_statement/; | |
17 | ||
18 | use constant FORMATS => [qw/CPP/]; | |
19 | use constant TITLE => '<tmpl_var name>'; | |
20 | ||
21 | my %templates = ( | |
22 | en => <<'HTML', | |
23 | <tmpl_var statement> | |
24 | ||
25 | <tmpl_if cansubmit> | |
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>"> | |
29 | <tmpl_if_defined contest><input type="hidden" name="contest" value="<tmpl_var contest>"></tmpl_if_defined> | |
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"> | |
37 | </form> | |
38 | </tmpl_if> | |
39 | HTML | |
40 | ); | |
41 | ||
42 | $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; | |
43 | $templates{$_} .= footer $_ for keys %templates; | |
44 | ||
45 | sub generate{ | |
46 | $_[0] =~ m,(?:ct/([^/])+/)?log/(\w+)\.html$,; | |
47 | ||
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 | |
62 | } | |
63 | ||
64 | 1 |