Added the FAQ wobject and some new features to Wobject.pm.
This commit is contained in:
parent
295e1e3c16
commit
4c80c7a559
4 changed files with 288 additions and 350 deletions
|
|
@ -1136,7 +1136,7 @@ sub url {
|
|||
|
||||
=head2 yesNo ( name [ label, value, extras, subtext ] )
|
||||
|
||||
Adds a yes/no pull down menu to this form.
|
||||
Adds a yes/no radio menu to this form.
|
||||
|
||||
=item name
|
||||
|
||||
|
|
@ -1167,24 +1167,20 @@ sub url {
|
|||
=cut
|
||||
|
||||
sub yesNo {
|
||||
my (%hash, $subtext, $class, $key, $output, $name, $label, $extras, $value);
|
||||
my ($subtext, $class, $output, $name, $label, $extras, $value);
|
||||
$class = shift;
|
||||
$name = shift;
|
||||
$label = shift;
|
||||
$value = shift;
|
||||
$extras = shift;
|
||||
$subtext = shift;
|
||||
tie %hash, 'Tie::IxHash';
|
||||
%hash = ('1'=>WebGUI::International::get(138), '0'=>WebGUI::International::get(139));
|
||||
$output = '<select name="'.$name.'" '.$extras.'>';
|
||||
foreach $key (keys %hash) {
|
||||
$output .= '<option value="'.$key.'"';
|
||||
if ($value eq $key) {
|
||||
$output .= " selected";
|
||||
}
|
||||
$output .= '>'.$hash{$key};
|
||||
}
|
||||
$output .= '</select>';
|
||||
$output = '<input type="radio" name="'.$name.'" value="1"';
|
||||
$output .= ' checked="1"' if ($value == 1);
|
||||
$output .= $extras.'>'.WebGUI::International::get(138);
|
||||
$output .= ' ';
|
||||
$output .= '<input type="radio" name="'.$name.'" value="0"';
|
||||
$output .= ' checked="1"' if ($value == 0);
|
||||
$output .= $extras.'>'.WebGUI::International::get(139);
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$class->{_data} .= $output;
|
||||
|
|
|
|||
|
|
@ -1,336 +0,0 @@
|
|||
package WebGUI::Widget::FAQ;
|
||||
|
||||
our $namespace = "FAQ";
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2002 Plain Black Software.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Shortcut;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Widget;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _reorderQuestions {
|
||||
my ($sth, $i, $qid);
|
||||
$sth = WebGUI::SQL->read("select questionId from FAQ_question where widgetId=$_[0] order by sequenceNumber");
|
||||
while (($qid) = $sth->array) {
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber='$i' where questionId=$qid");
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my ($sth, %data, $newWidgetId, $pageId, @row, $newQuestionId);
|
||||
tie %data, 'Tie::CPHash';
|
||||
%data = getProperties($namespace,$_[0]);
|
||||
$pageId = $_[1] || $data{pageId};
|
||||
$newWidgetId = create($pageId,$namespace,$data{title},$data{displayTitle},$data{description},$data{processMacros},$data{templatePosition});
|
||||
WebGUI::SQL->write("insert into FAQ values ($newWidgetId)");
|
||||
$sth = WebGUI::SQL->read("select * from FAQ_question where widgetId=$_[0]");
|
||||
while (@row = $sth->array) {
|
||||
$newQuestionId = getNextId("questionId");
|
||||
WebGUI::SQL->write("insert into FAQ_question values ($newWidgetId, $newQuestionId, ".quote($row[2]).", ".quote($row[3]).", '$row[4]')");
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
WebGUI::SQL->write("delete from FAQ_question where widgetId=$_[0]",$_[1]);
|
||||
purgeWidget($_[0],$_[1],$namespace);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub widgetName {
|
||||
return WebGUI::International::get(2,$namespace);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_add {
|
||||
my ($output, %hash);
|
||||
tie %hash, 'Tie::IxHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = helpLink(1,$namespace);
|
||||
$output .= '<h1>'.WebGUI::International::get(3,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("widget",$namespace);
|
||||
$output .= WebGUI::Form::hidden("func","addSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(WebGUI::International::get(99),WebGUI::Form::text("title",20,128,'F.A.Q.'));
|
||||
$output .= tableFormRow(WebGUI::International::get(174),WebGUI::Form::checkbox("displayTitle",1,1));
|
||||
$output .= tableFormRow(WebGUI::International::get(175),WebGUI::Form::checkbox("processMacros",1));
|
||||
%hash = WebGUI::Widget::getPositions();
|
||||
$output .= tableFormRow(WebGUI::International::get(363),WebGUI::Form::selectList("templatePosition",\%hash));
|
||||
$output .= tableFormRow(WebGUI::International::get(85),WebGUI::Form::textArea("description",'','','',1));
|
||||
$output .= tableFormRow(WebGUI::International::get(1,$namespace),WebGUI::Form::checkbox("proceed",1,1));
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addSave {
|
||||
my ($widgetId);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$widgetId = create($session{page}{pageId},$session{form}{widget},$session{form}{title},$session{form}{displayTitle},$session{form}{description},$session{form}{processMacros},$session{form}{templatePosition});
|
||||
WebGUI::SQL->write("insert into FAQ values ($widgetId)");
|
||||
if ($session{form}{proceed} == 1) {
|
||||
$session{form}{wid} = $widgetId;
|
||||
return www_addQuestion();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addQuestion {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = '<h1>'.WebGUI::International::get(4,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
|
||||
$output .= WebGUI::Form::hidden("func","addQuestionSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(WebGUI::International::get(5,$namespace),WebGUI::Form::textArea("question",'',50,3));
|
||||
$output .= tableFormRow(WebGUI::International::get(6,$namespace),WebGUI::Form::textArea("answer",'',50,10,1));
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addQuestionSave {
|
||||
my ($questionId, $nextSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($nextSeq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from FAQ_question where widgetId=$session{form}{wid}");
|
||||
$nextSeq += 1;
|
||||
$questionId = getNextId("questionId");
|
||||
WebGUI::SQL->write("insert into FAQ_question values ($session{form}{wid}, $questionId, ".quote($session{form}{question}).", ".quote($session{form}{answer}).", '$nextSeq')");
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copy {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
duplicate($session{form}{wid});
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteQuestion {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
|
||||
$output .= WebGUI::International::get(7,$namespace).'<p>';
|
||||
$output .= '<div align="center"><a href="'.
|
||||
WebGUI::URL::page('func=deleteQuestionConfirm&wid='.$session{form}{wid}.
|
||||
'&qid='.$session{form}{qid}).'">'.WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.WebGUI::URL::page('func=edit&wid='.$session{form}{wid})
|
||||
.'">'.WebGUI::International::get(45).'</a></div>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteQuestionConfirm {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
WebGUI::SQL->write("delete from FAQ_question where questionId=$session{form}{qid}");
|
||||
_reorderQuestions($session{form}{wid});
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my ($output, %hash, @array, %data, @question, $sth);
|
||||
tie %data, 'Tie::CPHash';
|
||||
tie %hash, 'Tie::IxHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
%data = getProperties($namespace,$session{form}{wid});
|
||||
$output = helpLink(1,$namespace);
|
||||
$output = '<h1>'.WebGUI::International::get(8,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
|
||||
$output .= WebGUI::Form::hidden("func","editSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(WebGUI::International::get(99),WebGUI::Form::text("title",20,128,$data{title}));
|
||||
$output .= tableFormRow(WebGUI::International::get(174),
|
||||
WebGUI::Form::checkbox("displayTitle","1",$data{displayTitle}));
|
||||
$output .= tableFormRow(WebGUI::International::get(175),
|
||||
WebGUI::Form::checkbox("processMacros","1",$data{processMacros}));
|
||||
%hash = WebGUI::Widget::getPositions();
|
||||
$array[0] = $data{templatePosition};
|
||||
$output .= tableFormRow(WebGUI::International::get(363),
|
||||
WebGUI::Form::selectList("templatePosition",\%hash,\@array));
|
||||
$output .= tableFormRow(WebGUI::International::get(85),
|
||||
WebGUI::Form::textArea("description",$data{description},'','',1));
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
$output .= '<p><a href="'.WebGUI::URL::page('func=addQuestion&wid='.$session{form}{wid})
|
||||
.'">'.WebGUI::International::get(9,$namespace).'</a><p>';
|
||||
$output .= '<table border=1 cellpadding=3 cellspacing=0>';
|
||||
$sth = WebGUI::SQL->read("select questionId,question from FAQ_question where widgetId='$session{form}{wid}' order by sequenceNumber");
|
||||
while (@question = $sth->array) {
|
||||
$output .= '<tr><td><a href="'.WebGUI::URL::page('func=editQuestion&wid='.$session{form}{wid}.
|
||||
'&qid='.$question[0]).'"><img src="'.$session{setting}{lib}.
|
||||
'/edit.gif" border=0></a><a href="'.WebGUI::URL::page('func=deleteQuestion&wid='.
|
||||
$session{form}{wid}.'&qid='.$question[0]).'"><img src="'.$session{setting}{lib}.
|
||||
'/delete.gif" border=0></a><a href="'.WebGUI::URL::page('func=moveQuestionUp&wid='.
|
||||
$session{form}{wid}.'&qid='.$question[0]).'"><img src="'.$session{setting}{lib}.
|
||||
'/upArrow.gif" border=0></a><a href="'.WebGUI::URL::page('func=moveQuestionDown&wid='.
|
||||
$session{form}{wid}.'&qid='.$question[0]).'"><img src="'.$session{setting}{lib}.
|
||||
'/downArrow.gif" border=0></a></td><td>'.$question[1].'</td><tr>';
|
||||
}
|
||||
$sth->finish;
|
||||
$output .= '</table>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
update();
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editQuestion {
|
||||
my ($output, %question);
|
||||
tie %question, 'Tie::CPHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
%question = WebGUI::SQL->quickHash("select * from FAQ_question where questionId='$session{form}{qid}'");
|
||||
$output = '<h1>'.WebGUI::International::get(10,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
|
||||
$output .= WebGUI::Form::hidden("qid",$session{form}{qid});
|
||||
$output .= WebGUI::Form::hidden("func","editQuestionSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(WebGUI::International::get(5,$namespace),WebGUI::Form::textArea("question",$question{question},50,3));
|
||||
$output .= tableFormRow(WebGUI::International::get(6,$namespace),WebGUI::Form::textArea("answer",$question{answer},50,10,1));
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editQuestionSave {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
WebGUI::SQL->write("update FAQ_question set question=".quote($session{form}{question}).", answer=".quote($session{form}{answer})." where questionId=$session{form}{qid}");
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveQuestionDown {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from FAQ_question where questionId=$session{form}{qid}");
|
||||
@data = WebGUI::SQL->quickArray("select questionId from FAQ_question where widgetId=$session{form}{wid} and sequenceNumber=$thisSeq+1 group by widgetId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber+1 where questionId=$session{form}{qid}");
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber-1 where questionId=$data[0]");
|
||||
}
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveQuestionUp {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from FAQ_question where questionId=$session{form}{qid}");
|
||||
@data = WebGUI::SQL->quickArray("select questionId from FAQ_question where widgetId=$session{form}{wid} and sequenceNumber=$thisSeq-1 group by widgetId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber-1 where questionId=$session{form}{qid}");
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber+1 where questionId=$data[0]");
|
||||
}
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my (%data, @question, $output, $sth, $qNa);
|
||||
tie %data, 'Tie::CPHash';
|
||||
%data = getProperties($namespace,$_[0]);
|
||||
if (defined %data) {
|
||||
if ($data{displayTitle} == 1) {
|
||||
$output = "<h1>".$data{title}."</h1>";
|
||||
}
|
||||
if ($data{description} ne "") {
|
||||
$output .= $data{description};
|
||||
}
|
||||
$output .= '<ul>';
|
||||
$sth = WebGUI::SQL->read("select questionId,question,answer from FAQ_question where widgetId='$_[0]' order by sequenceNumber");
|
||||
while (@question = $sth->array) {
|
||||
$output .= '<li><a href="#'.$question[0].'">'.$question[1].'</a>';
|
||||
$qNa .= '<a name="'.$question[0].'"><span class="faqQuestion">'.$question[1].'</span></a><br>'.$question[2].'<p>';
|
||||
}
|
||||
$sth->finish;
|
||||
$output .= '</ul>'.$qNa;
|
||||
}
|
||||
if ($data{processMacros} == 1) {
|
||||
$output = WebGUI::Macro::process($output);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
|
@ -79,6 +79,34 @@ sub _getPositions {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 description ( )
|
||||
|
||||
Returns this instance's description if it exists.
|
||||
|
||||
=cut
|
||||
|
||||
sub description {
|
||||
if ($_[0]->get("description")) {
|
||||
return $_[0]->get("description").'<p>';
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 displayTitle ( )
|
||||
|
||||
Returns this instance's title if displayTitle is set to yes.
|
||||
|
||||
=cut
|
||||
|
||||
sub displayTitle {
|
||||
if ($_[0]->get("displayTitle")) {
|
||||
return "<h1>".$_[0]->get("title")."</h1>";
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 duplicate ( [ pageId ] )
|
||||
|
||||
Duplicates this wobject with a new wobject ID. Returns the new
|
||||
|
|
@ -107,7 +135,7 @@ sub duplicate {
|
|||
displayTitle => $_[0]->get("displayTitle"),
|
||||
processMacros => $_[0]->get("processMacros"),
|
||||
startDate => $_[0]->get("startDate"),
|
||||
endDate => $_[0]->get("startDate"),
|
||||
endDate => $_[0]->get("endDate"),
|
||||
templatePosition => $_[0]->get("templatePosition")
|
||||
});
|
||||
return $w->get("wobjectId");
|
||||
|
|
|
|||
250
lib/WebGUI/Wobject/FAQ.pm
Normal file
250
lib/WebGUI/Wobject/FAQ.pm
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
package WebGUI::Wobject::FAQ;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2002 Plain Black Software.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Wobject;
|
||||
|
||||
our @ISA = qw(WebGUI::Wobject);
|
||||
our $namespace = "FAQ";
|
||||
our $name = WebGUI::International::get(2,$namespace);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _reorderQuestions {
|
||||
my ($sth, $i, $qid);
|
||||
$sth = WebGUI::SQL->read("select questionId from FAQ_question where wobjectId=$_[0] order by sequenceNumber");
|
||||
while (($qid) = $sth->array) {
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber='$i' where questionId=$qid");
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my ($w, %data, $newQuestionId, $sth);
|
||||
tie %data, 'Tie::CPHash';
|
||||
$w = $_[0]->SUPER::duplicate($_[1]);
|
||||
$sth = WebGUI::SQL->read("select * from FAQ_question where wobjectId=".$_[0]->get("wobjectId"));
|
||||
while (%data = $sth->hash) {
|
||||
$newQuestionId = getNextId("questionId");
|
||||
WebGUI::SQL->write("insert into FAQ_question values ($w, $newQuestionId, "
|
||||
.quote($data{question}).", ".quote($data{answer}).", $data{sequenceNumber})");
|
||||
}
|
||||
$sth->finish;}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub new {
|
||||
my ($self, $class, $property);
|
||||
$class = shift;
|
||||
$property = shift;
|
||||
$self = WebGUI::Wobject->new($property);
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
WebGUI::SQL->write("delete from FAQ_question where wobjectId=".$_[0]->get("wobjectId"));
|
||||
$_[0]->SUPER::purge();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copy {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$_[0]->duplicate;
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteQuestion {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
|
||||
$output .= WebGUI::International::get(7,$namespace).'<p>';
|
||||
$output .= '<div align="center"><a href="'.
|
||||
WebGUI::URL::page('func=deleteQuestionConfirm&wid='.$_[0]->get("wobjectId").
|
||||
'&qid='.$session{form}{qid}).'">'.WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.WebGUI::URL::page('func=edit&wid='.$_[0]->get("wobjectId"))
|
||||
.'">'.WebGUI::International::get(45).'</a></div>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteQuestionConfirm {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
WebGUI::SQL->write("delete from FAQ_question where questionId=$session{form}{qid}");
|
||||
_reorderQuestions($_[0]->get("wobjectId"));
|
||||
return $_[0]->www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my ($f, $output, @question, $sth);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = helpIcon(1,$namespace);
|
||||
$output = '<h1>'.WebGUI::International::get(8,$namespace).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->yesNo("proceed",WebGUI::International::get(1,$namespace),1);
|
||||
$output = $_[0]->SUPER::www_edit($f->printRowsOnly);
|
||||
unless ($_[0]->get("wobjectId") eq "new") {
|
||||
$output .= '<p><a href="'.WebGUI::URL::page('func=editQuestion&wid='.$_[0]->get("wobjectId"))
|
||||
.'">'.WebGUI::International::get(9,$namespace).'</a><p>';
|
||||
$output .= '<table border=1 cellpadding=3 cellspacing=0>';
|
||||
$sth = WebGUI::SQL->read("select questionId,question from FAQ_question where wobjectId="
|
||||
.$_[0]->get("wobjectId")." order by sequenceNumber");
|
||||
while (@question = $sth->array) {
|
||||
$output .= '<tr><td>'
|
||||
.editIcon('func=editQuestion&wid='.$_[0]->get("wobjectId").'&qid='.$question[0])
|
||||
.deleteIcon('func=deleteQuestion&wid='.$_[0]->get("wobjectId").'&qid='.$question[0])
|
||||
.moveUpIcon('func=moveQuestionUp&wid='.$_[0]->get("wobjectId").'&qid='.$question[0])
|
||||
.moveDownIcon('func=moveQuestionDown&wid='.$_[0]->get("wobjectId").'&qid='.$question[0])
|
||||
.'</td><td>'.$question[1].'</td><tr>';
|
||||
}
|
||||
$sth->finish;
|
||||
$output .= '</table>';
|
||||
}
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$_[0]->SUPER::www_editSave();
|
||||
if ($session{form}{proceed}) {
|
||||
$_[0]->www_editQuestion();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editQuestion {
|
||||
my ($output, %question, $f);
|
||||
tie %question, 'Tie::CPHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
%question = WebGUI::SQL->quickHash("select * from FAQ_question where questionId='$session{form}{qid}'");
|
||||
$output = '<h1>'.WebGUI::International::get(10,$namespace).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->hidden("wid",$_[0]->get("wobjectId"));
|
||||
$session{form}{qid} = "new" if ($session{form}{qid} eq "");
|
||||
$f->hidden("qid",$session{form}{qid});
|
||||
$f->hidden("func","editQuestionSave");
|
||||
$f->textarea("question",WebGUI::International::get(5,$namespace),$question{question});
|
||||
$f->HTMLArea("answer",WebGUI::International::get(6,$namespace),$question{answer});
|
||||
$f->yesNo("proceed",WebGUI::International::get(1,$namespace),1);
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editQuestionSave {
|
||||
my ($seq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
if ($session{form}{qid} eq "new") {
|
||||
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from FAQ_question where wobjectId=".$_[0]->get("wobjectId"));
|
||||
$session{form}{qid} = getNextId("questionId");
|
||||
WebGUI::SQL->write("insert into FAQ_question (wobjectId,questionId,sequenceNumber) values
|
||||
(".$_[0]->get("wobjectId").",$session{form}{qid},".($seq+1).")");
|
||||
}
|
||||
WebGUI::SQL->write("update FAQ_question set question=".quote($session{form}{question}).",
|
||||
answer=".quote($session{form}{answer})." where questionId=$session{form}{qid}");
|
||||
if ($session{form}{proceed}) {
|
||||
$session{form}{qid} = "new";
|
||||
return $_[0]->www_editQuestion();
|
||||
} else {
|
||||
return $_[0]->www_edit();
|
||||
}
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveQuestionDown {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from FAQ_question where questionId=$session{form}{qid}");
|
||||
@data = WebGUI::SQL->quickArray("select questionId from FAQ_question where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$thisSeq+1 group by wobjectId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber+1 where questionId=$session{form}{qid}");
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber-1 where questionId=$data[0]");
|
||||
}
|
||||
return $_[0]->www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveQuestionUp {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from FAQ_question where questionId=$session{form}{qid}");
|
||||
@data = WebGUI::SQL->quickArray("select questionId from FAQ_question where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$thisSeq-1 group by wobjectId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber-1 where questionId=$session{form}{qid}");
|
||||
WebGUI::SQL->write("update FAQ_question set sequenceNumber=sequenceNumber+1 where questionId=$data[0]");
|
||||
}
|
||||
return $_[0]->www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my (@question, $output, $sth, $qNa);
|
||||
$output = $_[0]->displayTitle;
|
||||
$output .= $_[0]->description;
|
||||
$output .= '<ul>';
|
||||
$sth = WebGUI::SQL->read("select questionId,question,answer from FAQ_question where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
|
||||
while (@question = $sth->array) {
|
||||
$output .= '<li><a href="#'.$question[0].'"><span class="faqQuestion">'.$question[1].'</span></a>';
|
||||
$qNa .= '<a name="'.$question[0].'"><span class="faqQuestion">'.$question[1].'</span></a><br>'.$question[2].'<p>';
|
||||
}
|
||||
$sth->finish;
|
||||
$output .= '</ul>'.$qNa;
|
||||
return $_[0]->processMacros($output);
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue