X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/8a0d8b82a160fd9803cab50d25ba1f587b0066d2..5e4c37b26db8009a1104b7784fe4520d228aa7ff:/writer.plp?ds=inline
diff --git a/writer.plp b/writer.plp
index fd2fc86..a5aa431 100644
--- a/writer.plp
+++ b/writer.plp
@@ -5,128 +5,76 @@ Html({
version => '1.0',
nocache => 1,
raw => <<'EOT',
-
-
+
EOT
});
use List::Util qw( pairs pairkeys );
+use Shiar_Sheet::FormRow;
my $db = eval {
- my @dbinfo = (
- 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse',
- ) or die "database not configured\n";
- require DBIx::Simple;
- DBIx::Simple->new(@dbinfo[0..2], {
- RaiseError => 1,
- pg_enable_utf8 => 1,
- });
+ require Shiar_Sheet::DB;
+ Shiar_Sheet::DB->connect;
} or Abort('Database error', 501, $@);
-$db->abstract->{array_datatypes}++;
my $user = eval {
+ my $rootpath = ($ENV{REQUEST_URI} // '/writer') =~ s{(?new(
+ -name => 'login',
+ -value => '',
+ -path => $rootpath,
+ -expires => 'now',
+ )->as_string)) {
+ delete $cookie{login};
+ die "Logged out as requested\n";
+ }
+ Alert("Failed to log out", "Login cookie could not be removed.");
+ }
+
my $cookiedata = $cookie{login} or return;
my ($name, $key) = split /[:\v]/, DecodeURI($cookiedata);
my %rowmatch = (username => $name, pass => $key);
- $db->select(login => '*', \%rowmatch)->hash;
-} or Abort('Login required', 403);
+ my $found = $db->select(login => '*', \%rowmatch)->hash
+ or die "Invalid user or password\n";
+
+ eval {
+ require CGI::Cookie;
+ my $httpcookie = CGI::Cookie->new(
+ -name => 'login',
+ -value => join(':', @{$found}{qw( username pass )}),
+ -path => $rootpath,
+ ) or die "prepared object is empty\n";
+ AddCookie($httpcookie->as_string);
+ } or Abort(["Unable to create login cookie", $@], 403);
+
+ return $found;
+} or do {
+ say '
Login to edit words
';
+ Alert('Access denied', $@) if $@;
+ say '';
+ exit;
+};
my %lang = (
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 => ['â ', 'esperanto'],
ru => ["\N{REGIONAL INDICATOR SYMBOL LETTER R}\N{REGIONAL INDICATOR SYMBOL LETTER U}", 'ÑÑÑÑкий'],
+ zh => ["\N{REGIONAL INDICATOR SYMBOL LETTER C}\N{REGIONAL INDICATOR SYMBOL LETTER N}", 'ä¸æ'],
+ la => ["\N{PUSHPIN}", 'latin'],
);
my @wordcols = pairkeys
my %wordcol = (
@@ -136,9 +84,14 @@ my %wordcol = (
cat => [{-label => 'Category'}, 'ref'],
ref => {-label => 'Reference'},
prio => [
- {-label => 'Level', -select => [qw(
- essential basic common distinctive rare invisible
- )]},
+ {-label => 'Level', -select => sub {
+ my ($row) = @_;
+ my @enum = qw[ essential basic common distinctive optional invisible ];
+ return {
+ ('' => 'parent') x (defined $row->{ref}),
+ map { $_ => $enum[$_] } 0 .. $#enum
+ };
+ }},
'cover', 'grade',
],
cover => {-label => 'Highlighted', type => 'checkbox'},
@@ -146,11 +99,28 @@ my %wordcol = (
form => {-label => 'Title'},
alt => {-label => 'Synonyms', -multiple => 1},
wptitle => {-label => 'Wikipedia'},
- source => {-label => 'Image'},
- thumb => {-label => 'Convert options', -multiple => 1},
+ source => {-label => 'Image', -src => sub {
+ return "data/word/org/$_[0]->{id}.jpg";
+ }},
+ thumb => {-label => 'Convert options', -multiple => 1, -src => sub {
+ return "data/word/en/$_[0]->{id}.jpg";
+ }},
+ story => {-label => 'Story', type => 'textarea'},
);
-my ($find) = map {{id => $_}} $fields{id} || $Request || ();
+if (my $search = $fields{q}) {
+ my %filter = (form => {ilike => '%'.$search.'%'});
+ my $results = $db->select(word => '*', \%filter);
+ say '
Search
';
+ printf("
%s %s %s
\n",
+ $_->{id}, showlink($_->{form}, "/writer/$_->{id}"),
+ sprintf('', $wordcol{thumb}->{-src}->($_)) x defined $_->{thumb}
+ ) for $results->hashes;
+ say "