From: Mischa POSLAWSKY Date: Tue, 9 Jun 2020 07:29:03 +0000 (+0200) Subject: word edit: sql array values in multiple input fields X-Git-Tag: v1.13~223 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/df43fa85051ebf955c1f42dab2d789b5d6a68aa6 word edit: sql array values in multiple input fields --- diff --git a/writer.plp b/writer.plp index 7280142..62d26d7 100644 --- a/writer.plp +++ b/writer.plp @@ -104,6 +104,7 @@ my $db = eval { pg_enable_utf8 => 1, }); } or Abort('Database error', 501, $@); +$db->abstract->{array_datatypes}++; my %lang = ( nl => ["\N{REGIONAL INDICATOR SYMBOL LETTER N}\N{REGIONAL INDICATOR SYMBOL LETTER L}", 'nederlands'], @@ -127,10 +128,10 @@ my %wordcol = ( cover => {-label => 'Highlighted', type => 'checkbox'}, grade => {-label => 'Order', type => 'number'}, form => {-label => 'Title'}, - alt => {-label => 'Synonyms'}, + alt => {-label => 'Synonyms', -multiple => 1}, wptitle => {-label => 'Wikipedia'}, source => {-label => 'Image'}, - thumb => {-label => 'Convert options'}, + thumb => {-label => 'Convert options', -multiple => 1}, ); my ($find) = map {{id => $_}} $fields{id} || $Request || (); @@ -146,6 +147,9 @@ if (exists $get{copy}) { elsif ($ENV{REQUEST_METHOD} eq 'POST') {{ my $replace = $row; $row = {%post{keys %wordcol}}; + $row->{$_} = [grep {length} @{ $post{"\@$_"} }] for grep { + ref $wordcol{$_} eq 'HASH' and $wordcol{$_}->{-multiple} + } keys %wordcol; $_ = length ? $_ : undef for values %{$row}; if (!$row->{form}) { @@ -255,10 +259,11 @@ else { my $title = $row->{id} ? "entry #$row->{id}" : 'new entry'; package Shiar_Sheet::FormRow { + use PLP::Functions 'EscapeHTML'; + sub input { my ($row, $col, $attr) = @_; my $val = $row->{$col} // ''; - $val = '{'.join(',', map {s/,/\\,/gr} @{$val}).'}' if ref $val eq 'ARRAY'; my $html = ''; $html .= qq( $_="$attr->{$_}") for sort grep {!/^-/} keys %{$attr // {}}; @@ -290,8 +295,11 @@ package Shiar_Sheet::FormRow { (map { sprintf('', $col, $_) } $attr->{-label} // ()), + (map { + sprintf('', $col, EscapeHTML($_)) + } ref $val eq 'ARRAY' ? @{$val} : ()), sprintf('', - $col, PLP::Functions::EscapeHTML($val), $html + $col, ref $val eq 'ARRAY' ? '' : EscapeHTML($val), $html ), (map { sprintf '%s',