]>
Commit | Line | Data |
---|---|---|
42546e6c MG |
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 YAML::Any qw/LoadFile/; | |
15 | use File::Basename qw/fileparse/; | |
16 | use File::Slurp qw/slurp/; | |
832cb45e | 17 | use Gruntmaster::Page::Common qw/header footer/; |
42546e6c MG |
18 | |
19 | use constant FORMATS => [qw/CPP/]; | |
20 | use constant TITLE => '<tmpl_var name>'; | |
21 | ||
22 | my %templates = ( | |
23 | en => <<'HTML', | |
24 | <tmpl_var statement> | |
25 | ||
fe78f0c1 | 26 | <tmpl_if cansubmit> |
42546e6c MG |
27 | <h1>Submit solution</h1> |
28 | <form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data"> | |
29 | <input type="hidden" name="problem" value="<tmpl_var id>"> | |
fe78f0c1 | 30 | <tmpl_if_defined contest><input type="hidden" name="contest" value="<tmpl_var contest>"></tmpl_if_defined> |
42546e6c MG |
31 | <label>File: <input name="prog" required type="file"></label> |
32 | ||
33 | <label>File format: <select name="prog_format" required> | |
34 | <tmpl_loop formats><option value="<tmpl_var _>"><tmpl_var _></option> | |
35 | </tmpl_loop></select></label> | |
36 | ||
37 | <input type="submit" value="Submit job"> | |
fe78f0c1 | 38 | </tmpl_if> |
42546e6c MG |
39 | HTML |
40 | ); | |
41 | ||
42 | $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; | |
43 | $templates{$_} .= footer $_ for keys %templates; | |
44 | ||
45 | sub generate{ | |
46 | my ($path, $lang) = @_; | |
fe78f0c1 MG |
47 | my $contest; |
48 | $contest = $1 if $path =~ m,ct/([^/]*)/,; | |
49 | my $id = ($path =~ m,pb/([^/]*)/index,)[0]; | |
50 | $path =~ s,/index\.html$,,; | |
42546e6c MG |
51 | my $template = $templates{$_[1]}; |
52 | my $htc = HTML::Template::Compiled->new(scalarref => \$template); | |
fe78f0c1 MG |
53 | flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH; |
54 | my $meta = LoadFile "$path/meta.yml"; | |
42546e6c | 55 | |
fe78f0c1 MG |
56 | $htc->param(cansubmit => 1); |
57 | if (defined $contest) { | |
58 | my $meta = LoadFile "ct/$contest/meta.yml"; | |
59 | $htc->param(cansubmit => time >= $meta->{start} && time <= $meta->{end}); | |
60 | $htc->param(contest => $contest); | |
61 | } | |
42546e6c | 62 | $htc->param(formats => FORMATS); |
fe78f0c1 | 63 | $htc->param(id => $id); |
42546e6c | 64 | $htc->param(name => $meta->{name}); |
fe78f0c1 | 65 | $htc->param(statement => scalar slurp "$path/statement.$lang"); |
42546e6c MG |
66 | $htc->output |
67 | } | |
68 | ||
69 | 1 |