[dw-free] Updates to FAQ backend
[commit: http://hg.dwscoalition.org/dw-free/rev/6228d9286ad0]
http://bugs.dwscoalition.org/show_bug.cgi?id=113
More update to the FAQ system - combine faqedit_do.bml into faqedit.bml.
Patch by
pauamma.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=113
More update to the FAQ system - combine faqedit_do.bml into faqedit.bml.
Patch by
Files modified:
- htdocs/admin/faq/faqedit.bml
- htdocs/admin/faq/faqedit_do.bml
--------------------------------------------------------------------------------
diff -r d14ca95d95b0 -r 6228d9286ad0 htdocs/admin/faq/faqedit.bml
--- a/htdocs/admin/faq/faqedit.bml Sat Mar 21 23:25:10 2009 +0000
+++ b/htdocs/admin/faq/faqedit.bml Sat Mar 21 23:52:54 2009 +0000
@@ -7,10 +7,11 @@ body<=
<a href="./"><b>(Back to FAQ Index)</b></a>
</center>
-<form action="faqedit_do.bml" method="post">
<?_code
{
use strict;
+
+ # FIXME: add crumb
my $id = $FORM{id} + 0;
my $ret = "";
@@ -21,13 +22,13 @@ body<=
my %ac_edit;
my %ac_add;
LJ::remote_has_priv( $remote, "faqadd", \%ac_add );
+ LJ::remote_has_priv( $remote, "faqedit", \%ac_edit );
my $faqd = LJ::Lang::get_dom( "faq" );
+ my $rlang = LJ::Lang::get_root_lang( $faqd );
my ( $faqcat, $sortorder, $question, $summary, $answer );
if ( $id != 0 ) {
- my $lang = LJ::Lang::get_root_lang( $faqd );
- LJ::remote_has_priv( $remote, "faqedit", \%ac_edit );
- my $faq = LJ::Faq->load( $id, lang => $lang->{lncode} )
+ my $faq = LJ::Faq->load( $id, lang => $rlang->{lncode} )
or return "<b>Error:</b> FAQ #$id does not exist.";
$faqcat = $faq->faqcat;
@@ -50,6 +51,65 @@ body<=
$sortorder += 0;
$sortorder ||= 50;
+ if ( LJ::did_post() ) {
+ if ( $POST{'action:save'} ) { # Save FAQ
+ return "<b>$ML{'Error'}</b> $ML{'error.invalidform'}"
+ unless LJ::check_form_auth();
+
+ my $opts_question = { changeseverity => $FORM{sev_question}+0 };
+ my $opts_summary = { changeseverity => $FORM{sev_summary}+0 };
+ my $opts_answer = { changeseverity => $FORM{sev_answer}+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_question);
+ LJ::Lang::set_text($dbh, $faqd->{dmid}, $rlang->{lncode},
+ "$id.3summary", $FORM{s}, $opts_summary);
+ LJ::Lang::set_text($dbh, $faqd->{dmid}, $rlang->{lncode},
+ "$id.2answer", $FORM{a}, $opts_answer);
+ };
+
+ if ( $id == 0 ) {
+ return "<b>Error:</b> You did not select a FAQ category."
+ unless $FORM{faqcat};
+
+ $dbh->do( qq{ INSERT INTO faq
+ ( faqid, question, summary, answer, faqcat,
+ sortorder, lastmoduserid, lastmodtime)
+ VALUES (NULL, ?, ?, ?, ?, ?, ?, NOW()) },
+ undef, @FORM{qw( q s a faqcat )},
+ $FORM{sortorder}+0 || 50, $remote->{userid} );
+ $id = $dbh->{mysql_insertid};
+ $ret .= $dbh->errstr || "Added FAQ item. All good. FAQ id is <b><a href='$LJ::SITEROOT/support/faqbrowse.bml?faqid=$id'>$id</a></b>";
+
+ $opts_question->{childrenlatest} = 1;
+ $opts_summary->{childrenlatest} = 1;
+ $opts_answer->{childrenlatest} = 1;
+ $do_trans->( $id ) if $id;
+ } elsif ( $FORM{q} =~ /\S/ ) {
+ my $sortorder = $FORM{sortorder}+0 || 50;
+ $dbh->do( qq{ UPDATE faq SET question=?, summary=?, answer=?,
+ faqcat=?, lastmoduserid=?,
+ lastmodtime=NOW(), sortorder=?
+ WHERE faqid=? },
+ undef, @FORM{qw( q s a faqcat )}, $remote->{userid},
+ $FORM{sortorder}+0 || 50, $id );
+ $ret .= "Updated FAQ item. All good. FAQ id 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=?", undef, $id );
+ $ret .= "FAQ item deleted.";
+
+ # FIXME: delete translation from ml_* ?
+ }
+
+ return $ret;
+ }
+ }
+
+ $ret .= "<form action='faqedit.bml' method='post'>";
$ret .= LJ::form_auth();
$ret .= LJ::html_hidden( 'id', $id );
$ret .= "<p>Category: ";
@@ -62,7 +122,7 @@ body<=
while ( my ($fc, $fcname) = $sth->fetchrow_array ) {
# $fc can't be NULL/undef
push @cats, $fc, $fcname
- if $ac_add{'*'} || $ac_add{$fc} || ($fc eq $faqcat);
+ if $ac_add{'*'} || $ac_add{$fc} || $fc eq $faqcat;
}
$ret .= LJ::html_select( { name => 'faqcat', selected => $faqcat }, @cats );
@@ -118,12 +178,11 @@ body<=
$ret .= "</p>";
}
- $ret .= "<p>" . LJ::html_submit( '', 'Add/Edit FAQ Item' ) . "</p>";
+ $ret .= "<p>" . LJ::html_submit( 'action:save', 'Add/Edit FAQ Item' )
+ . "</p></form>";
return $ret;
}
_code?>
-
-</form>
<=body
page?><?_c <LJDEP>
diff -r d14ca95d95b0 -r 6228d9286ad0 htdocs/admin/faq/faqedit_do.bml
--- a/htdocs/admin/faq/faqedit_do.bml Sat Mar 21 23:25:10 2009 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,121 +0,0 @@
-<?_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'});
- $qs = $dbh->quote($FORM{'s'});
- $qa = $dbh->quote($FORM{'a'});
- $qfaqcat = $dbh->quote($FORM{'faqcat'});
-
- $sortorder = $FORM{'sortorder'}+0 || 50;
-
- return "<?requirepost?>" unless LJ::did_post();
- return "<b>$ML{'Error'}</b> $ML{'error.invalidform'}" unless LJ::check_form_auth();
-
- 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_question = {
- 'changeseverity' => $FORM{'sev_question'}+0,
- };
- my $opts_summary = {
- 'changeseverity' => $FORM{'sev_summary'}+0,
- };
- my $opts_answer = {
- 'changeseverity' => $FORM{'sev_answer'}+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_question);
- LJ::Lang::set_text($dbh, $faqd->{'dmid'}, $rlang->{'lncode'},
- "$id.3summary", $FORM{'s'}, $opts_summary);
- LJ::Lang::set_text($dbh, $faqd->{'dmid'}, $rlang->{'lncode'},
- "$id.2answer", $FORM{'a'}, $opts_answer);
- };
-
- unless ($id)
- {
- unless ($FORM{'faqcat'})
- {
- return "<B>Error: </B> You did not select a FAQ category.";
- }
- $dbh->do("INSERT INTO faq (faqid, question, summary, answer, faqcat, sortorder, lastmoduserid, lastmodtime) VALUES (NULL, $qq, $qs, $qa, $qfaqcat, $sortorder, $remote->{'userid'}, NOW())");
- $id = $dbh->{'mysql_insertid'};
- $ret .= $dbh->errstr || "Added FAQ item. All good. faqid is <b><a href='$LJ::SITEROOT/support/faqbrowse.bml?faqid=$id'>$id</a></b>";
-
- $opts_question->{'childrenlatest'} = 1;
- $opts_summary->{'childrenlatest'} = 1;
- $opts_answer->{'childrenlatest'} = 1;
- $do_trans->($id) if $id;
- }
- else
- {
-
- if ($FORM{'q'} =~ /\S/)
- {
- $dbh->do("UPDATE faq SET question=$qq, summary=$qs, 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?>
--------------------------------------------------------------------------------
