]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Pb/Entry.pm
Close form element in Pb::Entry
[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/;
14use YAML::Any qw/LoadFile/;
15use File::Basename qw/fileparse/;
16use File::Slurp qw/slurp/;
832cb45e 17use Gruntmaster::Page::Common qw/header footer/;
42546e6c
MG
18
19use constant FORMATS => [qw/CPP/];
20use constant TITLE => '<tmpl_var name>';
21
22my %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">
6d28cb38 38</form>
fe78f0c1 39</tmpl_if>
42546e6c
MG
40HTML
41);
42
43$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
44$templates{$_} .= footer $_ for keys %templates;
45
46sub generate{
47 my ($path, $lang) = @_;
fe78f0c1
MG
48 my $contest;
49 $contest = $1 if $path =~ m,ct/([^/]*)/,;
50 my $id = ($path =~ m,pb/([^/]*)/index,)[0];
51 $path =~ s,/index\.html$,,;
42546e6c
MG
52 my $template = $templates{$_[1]};
53 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
fe78f0c1
MG
54 flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
55 my $meta = LoadFile "$path/meta.yml";
42546e6c 56
fe78f0c1
MG
57 $htc->param(cansubmit => 1);
58 if (defined $contest) {
59 my $meta = LoadFile "ct/$contest/meta.yml";
60 $htc->param(cansubmit => time >= $meta->{start} && time <= $meta->{end});
61 $htc->param(contest => $contest);
62 }
42546e6c 63 $htc->param(formats => FORMATS);
fe78f0c1 64 $htc->param(id => $id);
42546e6c 65 $htc->param(name => $meta->{name});
fe78f0c1 66 $htc->param(statement => scalar slurp "$path/statement.$lang");
42546e6c
MG
67 $htc->output
68}
69
701
This page took 0.029139 seconds and 4 git commands to generate.