X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/86a6750572ee3fa30d006a4edce6d5c188726a17..9ddf2e9a6173fcb1649ab9dd72ded3896195c83f:/writer.plp
diff --git a/writer.plp b/writer.plp
index ba81e8a..256a074 100644
--- a/writer.plp
+++ b/writer.plp
@@ -5,89 +5,7 @@ Html({
version => '1.0',
nocache => 1,
raw => <<'EOT',
-
-
+
EOT
});
@@ -95,21 +13,65 @@ EOT
use List::Util qw( pairs pairkeys );
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, $@);
+my $user = eval {
+ if (defined $post{username}) {
+ $cookie{login} = EncodeURI(join ':', @post{qw( username pass )});
+ }
+ elsif (exists $fields{logout}) {
+ require CGI::Cookie;
+ if (AddCookie(CGI::Cookie->new(
+ -name => 'login',
+ -value => '',
+ -path => '/writer',
+ -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);
+ 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 => '/writer',
+ ) 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}", 'ÑÑÑÑкий'],
+ la => ["\N{PUSHPIN}", 'latin'],
);
my @wordcols = pairkeys
my %wordcol = (
@@ -119,21 +81,38 @@ 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'},
grade => {-label => 'Order', type => 'number'},
- form => 'Title',
- alt => 'Synonyms',
- wptitle => 'Wikipedia',
- source => 'Image',
- thumb => 'Convert options',
+ form => {-label => 'Title'},
+ alt => {-label => 'Synonyms', -multiple => 1},
+ wptitle => {-label => 'Wikipedia'},
+ source => {-label => 'Image'},
+ thumb => {-label => 'Convert options', -multiple => 1},
);
-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('', Shiar_Sheet::FormRow::imagepath($_ => 'thumb')) x defined $_->{thumb}
+ ) for $results->hashes;
+ say "