<(../common.inc.plp)><:
+my $editorurl = '/word/edit';
s{\Aedit(/|\z)}{} for $Request // ();
+
Html({
title => 'words cheat sheet admin',
version => '1.0',
} or Abort('Database error', 501, $@);
my $user = eval {
- my $rootpath = '/word/edit';
if (defined $post{username}) {
$cookie{login} = EncodeURI(join ':', @post{qw( username pass )});
}
if (AddCookie(CGI::Cookie->new(
-name => 'login',
-value => '',
- -path => $rootpath,
+ -path => $editorurl,
-expires => 'now',
)->as_string)) {
delete $cookie{login};
my $httpcookie = CGI::Cookie->new(
-name => 'login',
-value => join(':', @{$found}{qw( username pass )}),
- -path => $rootpath,
+ -path => $editorurl,
) or die "prepared object is empty\n";
AddCookie($httpcookie->as_string);
} or Abort(["Unable to create login cookie", $@], 403);
};
my %lang = (
+ '' => ['(reference)'],
nl => ["\N{REGIONAL INDICATOR SYMBOL LETTER N}\N{REGIONAL INDICATOR SYMBOL LETTER L}", 'nederlands'],
en => ["\N{REGIONAL INDICATOR SYMBOL LETTER G}\N{REGIONAL INDICATOR SYMBOL LETTER B}", 'english'],
eo => [qq'<span style="color:green">\N{BLACK STAR}</span>', 'esperanto'],
);
if (my $search = $fields{q}) {
- my %filter = (form => {ilike => '%'.$search.'%'});
+ my %filter = $search eq '^' ? (cat => undef, ref => undef) :
+ (form => {ilike => '%'.parseinput($search).'%'});
my $results = $db->select(word => '*', \%filter);
say '<h1>Search</h1><ul>';
printf("<li><small>%s</small> %s %s</li>\n",
- $_->{id}, showlink($_->{form}, "/writer/$_->{id}"),
+ $_->{id}, showlink($_->{form}, "$editorurl/$_->{id}"),
sprintf('<img src="/%s" style="height:3ex; width:auto" />', $wordcol{convert}->{-src}->($_)) x defined $_->{image}
) for $results->hashes;
say "</ul>\n";
my $imagecol = $row->{image}; # backup image subcolumns
ref $_ eq 'HASH' and $_ = encode_json($_) for values %{$row};
- if (!$row->{form}) {
+ if (!$row->{form} and $row->{lang}) {
if ($row->{ref} ne 'delete') {
Alert("Empty title",
"Confirm removal by setting <em>Reference</em> to <q>delete</q>."
}
}}
else {
- $row->{lang} //= $user->{editlang}->[0];
+ $row->{lang} //= $user->{editlang}->[0] unless exists $row->{lang};
$row->{$_} = $get{$_} for keys %get;
$row->{prio} = defined $row->{ref} ? undef : 1 unless exists $row->{prio};
}
eval {
- my $imagerow = $row->{image} && decode_json(delete $row->{image}) || {};
+ my $imagerow = $row->{image} && JSON->new->decode(delete $row->{image}) || {};
while (my ($col, $val) = each %{$imagerow}) {
$row->{$col} = $val;
}
}
if (not $row->{ref}) {
- printf '<li><label for="%s">%s</label><div><ul class="inline" id="%1$s">',
+ printf '<li><label for="%s">%s</label><div><ul class="inline multiinput" id="%1$s">',
'trans', 'Translations';
my @children = !$row->{id} ? () :
$db->select(word => '*', {ref => $row->{id}}, 'lang, id')->hashes;
printf(
$ref->{id} ? '<a id="%s" href="%s">%s</a></li>' :
'<input id="%s" name="%1$s" value="%3$s" />',
- "trans-$ref->{lang}", "/writer/$ref->{id}", Entity($ref->{form} // ''),
+ "trans-$ref->{lang}", "$editorurl/$ref->{id}", Entity($ref->{form} // ''),
);
}
say '</ul></div></li>';
</ul>
<p>
<input type="submit" value="Save" />
- <input type="submit" value="New" formaction="/writer?copy=cat" />
+ <input type="submit" value="New" formaction="<:= $editorurl :>?copy=cat" />
</p>
</form>
say '<ul>';
my $parents = $db->select(word => '*', [{id => $row->{cat}}, {id => $row->{ref}}]);
while (my $ref = $parents->hash) {
- printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
+ printf '<li><a href="%s/%d">%s</a></li>', $editorurl, $ref->{id}, Entity($ref->{form});
}
say "<li><strong>$_</strong></li>" for Entity($row->{form});
my $children = $db->select(word => '*', {cat => $row->{id}, ref => undef}, 'grade, id');
while (my $ref = $children->hash) {
- printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
+ printf '<li><a href="%s/%d">%s</a></li>', $editorurl, $ref->{id}, Entity($ref->{form});
}
:>
-<li><form action="/writer">
+<li><form action="<:= $editorurl :>">
<input type="hidden" name="cat" value="<:= $row->{id} :>" />
<input type="hidden" name="lang" value="<:= $row->{lang} :>" />
<input type="submit" value="Add" />