1 _info?> body<=
(Back to FAQ Index)

quote($FORM{'q'}); $qa = $dbh->quote($FORM{'a'}); $qfaqcat = $dbh->quote($FORM{'faqcat'}); $sortorder = $FORM{'sortorder'}+0 || 50; return "" 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 "Error: You do not have access to edit a FAQ question in the \"$faqcat\" category."; } else { return "Error: 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 "Error: 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 "Error: 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 $id"; $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?> lib: cgi-bin/ljlib.pl link: htdocs/admin/faq/index.bml _c?>