This commit is contained in:
2019-02-06 00:49:12 +03:00
commit 8dbb1bb605
4796 changed files with 506072 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
<?_info
nocache=>1
_info?><?page
title=><?_code return $FORM{'id'} ? "Edit FAQ Item #$FORM{'id'}" : "Add to FAQ"; _code?>
body<=
<CENTER>
<A HREF="./"><B>(Back to FAQ Index)</B></A>
</CENTER>
<FORM ACTION="faqedit_do.bml" METHOD=POST>
<?_code
$id = $FORM{'id'} + 0;
$ret = "";
my $dbh = LJ::get_db_writer();
my $remote = LJ::get_remote();
my %ac_edit;
my %ac_add;
LJ::remote_has_priv($remote, "faqadd", \%ac_add);
if ($id)
{
LJ::remote_has_priv($remote, "faqedit", \%ac_edit);
my $sth = $dbh->prepare("SELECT question, answer, faqcat, sortorder FROM faq WHERE faqid=$id");
$sth->execute;
($question, $answer, $faqcat, $sortorder) = $sth->fetchrow_array or
return "<b>Error:</b> FAQ #$id does not exist.";
$q = LJ::ehtml($question);
$a = LJ::ehtml($answer);
unless ($ac_edit{'*'} || $ac_edit{$faqcat}) {
if (%ac_edit) {
return "<B>Error: </B> You do not have access to edit a FAQ question in the \"$faqcat\" category.";
} else {
return "<B>Error: </B> You do not have access to edit the FAQ.";
}
}
}
else
{
unless (%ac_add) {
return "<B>Error: </B> You do not have access to add to the FAQ.";
}
}
$sortorder += 0;
$sortorder ||= 50;
$ret .= "<INPUT TYPE=HIDDEN NAME=id VALUE=$id>\n";
$ret .= "<P>Category: <SELECT NAME=\"faqcat\"><OPTION VALUE=\"\">\n";
my $sth = $dbh->prepare("SELECT faqcat, faqcatname FROM faqcat ORDER BY catorder");
$sth->execute;
while (($fc, $fcname) = $sth->fetchrow_array)
{
if ($id) {
next unless ($ac_add{'*'} || $ac_add{$fc} || ($fc eq $faqcat));
} else {
next unless ($ac_add{'*'} || $ac_add{$fc});
}
$selected = ($fc eq $faqcat) ? " SELECTED" : "";
$ret .= "<OPTION VALUE=\"$fc\"$selected>" . LJ::ehtml($fcname) . "\n";
}
$ret .= "</SELECT>";
$ret .= "SortOrder (1-100): <INPUT NAME=sortorder SIZE=5 MAXLENGTH=4 VALUE=$sortorder>";
$ret .= "<BR><FONT SIZE=-1>(sort order is how to sort within the category. categories themselves are also sorted.)</FONT>";
$ret .= "<P><B>Question:</B> (as brief as possible, do not span multiple lines)<BR><TEXTAREA NAME=\"q\" ROWS=3 COLS=70 WRAP=SOFT>$q</TEXTAREA><BR><FONT SIZE=-1>(erase question to delete FAQ entry)</FONT>\n";
$ret .= "<P><B>Answer:</B> (long as you want, give URLs to links, not HTML)<BR><TEXTAREA NAME=\"a\" ROWS=15 COLS=70 WRAP=SOFT>$a</TEXTAREA>\n";
my $faqd = LJ::Lang::get_dom("faq");
if ($faqd) {
$ret .= "<p><b>Select modification level:</b> ";
$ret .= LJ::html_select({ 'name' => "sev", "selected" => 1 },
0 => "Typo/etc (no notify)",
1 => "Minor (notify translators)",
2 => "Major (require translation updates)");
$ret .= "</p>";
}
$ret .= "<P><INPUT TYPE=SUBMIT VALUE=\"Add/Edit FAQ Item\">";
return $ret;
_code?>
</FORM>
<=body
page?><?_c <LJDEP>
lib: cgi-bin/ljlib.pl
post: htdocs/admin/faq/faqedit_do.bml
</LJDEP> _c?>

View File

@@ -0,0 +1,109 @@
<?_info
nocache=>1
_info?><?page
title=><?_code return $FORM{'id'} ? "Edit FAQ Item #$FORM{'id'}" : "Add to FAQ"; _code?>
body<=
<CENTER>
<A HREF="./"><B>(Back to FAQ Index)</B></A>
</CENTER>
<P>
<?_code
my $dbh = LJ::get_db_writer();
my $remote = LJ::get_remote();
my %ac_edit;
my %ac_add;
$id = $FORM{'id'} + 0;
$ret = "";
$qq = $dbh->quote($FORM{'q'});
$qa = $dbh->quote($FORM{'a'});
$qfaqcat = $dbh->quote($FORM{'faqcat'});
$sortorder = $FORM{'sortorder'}+0 || 50;
return "<?requirepost?>" unless LJ::did_post();
if ($id)
{
LJ::remote_has_priv($remote, "faqedit", \%ac_edit);
my $sth = $dbh->prepare("SELECT faqcat FROM faq WHERE faqid=$id");
$sth->execute;
my ($faqcat) = $sth->fetchrow_array;
unless ($ac_edit{'*'} || $ac_edit{$faqcat}) {
if (%ac_edit) {
return "<B>Error: </B> You do not have access to edit a FAQ question in the \"$faqcat\" category.";
} else {
return "<B>Error: </B> You do not have access to edit the FAQ.";
}
}
}
else
{
LJ::remote_has_priv($remote, "faqadd", \%ac_add);
unless ($ac_add{'*'} || $ac_add{$FORM{'faqcat'}}) {
return "<B>Error: </B> You do not have access to add FAQ questions in this category";
}
}
my $faqd = LJ::Lang::get_dom("faq");
my $rlang = LJ::Lang::get_root_lang($faqd);
unless ($rlang) { undef $faqd; }
my $opts = {
'changeseverity' => $FORM{'sev'}+0,
};
my $do_trans = sub {
my $id = shift;
return unless $faqd;
LJ::Lang::set_text($dbh, $faqd->{'dmid'}, $rlang->{'lncode'},
"$id.1question", $FORM{'q'}, $opts);
LJ::Lang::set_text($dbh, $faqd->{'dmid'}, $rlang->{'lncode'},
"$id.2answer", $FORM{'a'}, $opts);
};
unless ($id)
{
unless ($FORM{'faqcat'})
{
return "<B>Error: </B> You did not select a FAQ category.";
}
$dbh->do("INSERT INTO faq (faqid, question, answer, faqcat, sortorder, lastmoduserid, lastmodtime) VALUES (NULL, $qq, $qa, $qfaqcat, $sortorder, $remote->{'userid'}, NOW())");
$id = $dbh->{'mysql_insertid'};
$ret .= $dbh->errstr || "Added FAQ item. All good.";
$opts->{'childrenlatest'} = 1;
$do_trans->($id) if $id;
}
else
{
if ($FORM{'q'} =~ /\S/)
{
$dbh->do("UPDATE faq SET question=$qq, answer=$qa, faqcat=$qfaqcat, lastmoduserid=$remote->{'userid'}, lastmodtime=NOW(), sortorder=$sortorder WHERE faqid=$id");
$ret .= "Updated FAQ item. All good. faqid is <b><a href='$LJ::SITEROOT/support/faqbrowse.bml?faqid=$id'>$id</a></b>";
$do_trans->($id);
}
else
{
$dbh->do("DELETE FROM faq WHERE faqid=$id");
$ret .= "FAQ item deleted.";
# TODO: delete translation from ml_* ?
}
}
return $ret;
_code?>
<=body
page?><?_c <LJDEP>
lib: cgi-bin/ljlib.pl
link: htdocs/admin/faq/index.bml
</LJDEP> _c?>

View File

@@ -0,0 +1,67 @@
<?_info
nocache=>1
_info?><?page
title=>FAQ
body<=
<?_code
my $dbh = LJ::get_db_writer();
my $remote = LJ::get_remote();
my %ac_add;
my %ac_edit;
LJ::remote_has_priv($remote, "faqadd", \%ac_add);
LJ::remote_has_priv($remote, "faqedit", \%ac_edit);
$ret = "";
if (%ac_add)
{
$ret .= "<A HREF=\"faqedit.bml\">[Add to FAQ]</A>\n";
}
my %faqcat;
my %faqq;
$sth = $dbh->prepare("SELECT faqcat, faqcatname, catorder FROM faqcat");
$sth->execute;
while ($_ = $sth->fetchrow_hashref)
{
$faqcat{$_->{'faqcat'}} = $_;
}
$sth = $dbh->prepare("SELECT faqid, question, sortorder, faqcat, lastmodtime FROM faq");
$sth->execute;
while ($_ = $sth->fetchrow_hashref)
{
$faqq{$_->{'faqcat'}}->{$_->{'faqid'}} = $_;
}
foreach my $faqcat (sort { $faqcat{$a}->{'catorder'} <=> $faqcat{$b}->{'catorder'} } keys %faqcat)
{
$ret .= "<H2><A HREF=\"readcat.bml?faqcat=$faqcat\">" . LJ::ehtml($faqcat{$faqcat}->{'faqcatname'}) . "</A></H2>\n";
$ret .= "<UL>\n";
foreach my $faqid (sort { $faqq{$faqcat}->{$a}->{'sortorder'} <=> $faqq{$faqcat}->{$b}->{'sortorder'} } keys %{$faqq{$faqcat}})
{
my $fe = $faqq{$faqcat}->{$faqid};
next unless ($fe->{'question'});
my $q = LJ::ehtml($fe->{'question'});
$q =~ s/^\s+//; $q =~ s/\s+$//;
$q =~ s/\n/<BR>/g;
$ret .= "<LI>";
if ($ac_edit{'*'} || $ac_edit{$faqcat}) {
$ret .= "<A HREF=\"faqedit.bml?id=$faqid\">[edit]</A> ($fe->{'sortorder'}) ";
}
$ret .= "<B>{$faqid}</B> $q\n";
}
$ret .= "</UL>\n";
}
return $ret;
_code?>
<=body
page?><?_c <LJDEP>
lib: cgi-bin/ljlib.pl
link: htdocs/admin/faq/readcat.bml, htdocs/admin/faq/faqedit.bml
</LJDEP> _c?>

View File

@@ -0,0 +1,63 @@
<?_info
nocache=>1
_info?><?page
title=>Read FAQ
body<=
<CENTER>
<A HREF="./"><B>(Back to FAQ Index)</B></A>
</CENTER>
<?_code
my $dbh = LJ::get_db_writer();
$ret = "";
my $qfaqcat = $dbh->quote($FORM{'faqcat'});
my %faqcat;
my %faqq;
$sth = $dbh->prepare("SELECT faqcat, faqcatname, catorder FROM faqcat WHERE faqcat=$qfaqcat");
$sth->execute;
while ($_ = $sth->fetchrow_hashref)
{
$faqcat{$_->{'faqcat'}} = $_;
}
$sth = $dbh->prepare("SELECT faqid, question, sortorder, faqcat, answer, lastmodtime FROM faq WHERE faqcat=$qfaqcat");
$sth->execute;
while ($_ = $sth->fetchrow_hashref)
{
$faqq{$_->{'faqid'}} = $_;
}
foreach my $faqcat (sort { $faqcat{$a}->{'catorder'} <=> $faqcat{$b}->{'catorder'} } keys %faqcat)
{
$ret .= "<h2>" . LJ::ehtml($faqcat{$faqcat}->{'faqcatname'}) . "</h2>\n";
$ret .= "<ul>\n";
foreach my $faqid (sort { $faqq{$a}->{'sortorder'} <=> $faqq{$b}->{'sortorder'} } grep { $faqq{$_}->{'faqcat'} eq $faqcat } keys %faqq)
{
next unless ($faqq{$faqid}->{'question'});
BML::note_mod_time($faqq{$faqid}->{'lastmodtime'});
my $q = LJ::ehtml($faqq{$faqid}->{'question'});
$q =~ s/^\s+//; $q =~ s/\s+$//;
$q =~ s!\n!<br />!g;
my $a = LJ::ehtml($faqq{$faqid}->{'answer'});
$a =~ s/^\s+//; $a =~ s/\s+$//;
$a =~ s/\n( +)/"\n" . "&nbsp;&nbsp;"x length($1)/eg;
$a =~ s!\n!<br />!g;
$ret .= "<p><table bgcolor='#c0c0c0'><tr><td><b>$q</b></td></tr></table>" . LJ::auto_linkify($a);
}
$ret .= "</ul>\n";
}
return $ret;
_code?>
<=body
page?><?_c <LJDEP>
lib: cgi-bin/ljlib.pl
link: htdocs/admin/faq/index.bml
</LJDEP> _c?>