diff options
author | Yorhel <git@yorhel.nl> | 2020-07-25 14:03:37 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-07-25 14:03:37 +0200 |
commit | 025ab84a962f3c61fd4217f1518ef4928bf72bf3 (patch) | |
tree | 3c553ead5033006e51736922720af2f41568d8c7 /lib/VNWeb/Misc | |
parent | 40ea78ddfa265daea03f9904784bc0c35980b894 (diff) |
Reports: Allow reporting DB entries
Diffstat (limited to 'lib/VNWeb/Misc')
-rw-r--r-- | lib/VNWeb/Misc/History.pm | 14 | ||||
-rw-r--r-- | lib/VNWeb/Misc/Reports.pm | 29 |
2 files changed, 19 insertions, 24 deletions
diff --git a/lib/VNWeb/Misc/History.pm b/lib/VNWeb/Misc/History.pm index 26ef5f48..7ce5584f 100644 --- a/lib/VNWeb/Misc/History.pm +++ b/lib/VNWeb/Misc/History.pm @@ -170,19 +170,7 @@ sub filters_ { TUWF::get qr{/(?:([upvrcsd])([1-9]\d*)/)?hist} => sub { my($type, $id) = (tuwf->capture(1)||'', tuwf->capture(2)); - my sub dbitem { - my($table, $title) = @_; - tuwf->dbRowi('SELECT id,', $title, ' AS title, hidden AS entry_hidden, locked AS entry_locked FROM', $table, 'WHERE id =', \$id); - }; - - my $obj = !$type ? undef : - $type eq 'u' ? tuwf->dbRowi('SELECT id, ', sql_user(), 'FROM users u WHERE id =', \$id) : - $type eq 'p' ? dbitem producers => 'name' : - $type eq 'v' ? dbitem vn => 'title' : - $type eq 'r' ? dbitem releases => 'title' : - $type eq 'c' ? dbitem chars => 'name' : - $type eq 's' ? dbitem staff => '(SELECT name FROM staff_alias WHERE aid = staff.aid)' : - $type eq 'd' ? dbitem docs => 'title' : die; + my $obj = dbobj $type, $id; return tuwf->resNotFound if $type && !$obj->{id}; $obj->{title} = user_displayname $obj if $type eq 'u'; diff --git a/lib/VNWeb/Misc/Reports.pm b/lib/VNWeb/Misc/Reports.pm index d229d434..fa1cbb44 100644 --- a/lib/VNWeb/Misc/Reports.pm +++ b/lib/VNWeb/Misc/Reports.pm @@ -16,16 +16,23 @@ sub enrich_object { FROM threads t JOIN threads_posts tp ON tp.tid = t.id LEFT JOIN users u ON u.id = tp.uid WHERE NOT t.hidden AND NOT t.private AND t.id =', \"$+{id}", 'AND tp.num =', \"$+{num}" ); - if($post->{num}) { - $o->{title} = xml_string sub { - txt_ 'Post '; - a_ href => "/$o->{object}", "#$post->{num}"; - txt_ ' on '; - a_ href => "/$o->{object}", $post->{title}; - txt_ ' by '; - user_ $post; - }; - } + $o->{title} = xml_string sub { + txt_ 'Post '; + a_ href => "/$o->{object}", "#$post->{num}"; + txt_ ' on '; + a_ href => "/$o->{object}", $post->{title}; + txt_ ' by '; + user_ $post; + } if $post->{num}; + + } elsif($o->{rtype} eq 'db' && $o->{object} =~ /^([vrpcsd])$RE{num}$/) { + my($t,$id) = ($1, $+{num}); + my $obj = dbobj $t, $id; + $o->{title} = xml_string sub { + txt_ {qw/v VN r Release p Producer c Character s Staff d Doc/}->{$t}; + txt_ ': '; + a_ href => "/$t$id", $obj->{title}; + } if $obj->{id}; } } } @@ -63,7 +70,7 @@ elm_api Report => undef, $FORM, sub { }; -TUWF::get qr{/report/(?<rtype>t)/(?<object>.+)}, sub { +TUWF::get qr{/report/(?<rtype>t|db)/(?<object>.+)}, sub { my $obj = { rtype => tuwf->capture('rtype'), object => tuwf->capture('object') }; enrich_object $obj; return tuwf->resNotFound if !$obj->{title}; |