moved FAQ's into USS

This commit is contained in:
JT Smith 2003-11-30 00:05:08 +00:00
parent 6e568979e6
commit 83f1188ea3
9 changed files with 352 additions and 88 deletions

View file

@ -7,6 +7,7 @@
- Migrated styles to templates and removed the styles system.
- Updated page templates to be more powerful.
- Converted items to articles and removed the item wobject.
- Converted FAQ's to USS submissions and removed the FAQ wobject.
- Created format and processReplacements subs in the WebGUI::HTML package.

View file

@ -7,6 +7,18 @@ upgrading from one version to the next, or even between multiple
versions. Be sure to heed the warnings contained herein as they will
save you many hours of grief.
6.0.0
--------------------------------------------------------------------
* As part of the upgrade process our scripts will attempt to
migrate your styles, page, FAQ, Item, Link List, and
SQL Report templates. However, the migration scripts are not
perfect due to the wide-variety of templates out there, so
you may need to update some portions of your templates
manually.
5.5.0
--------------------------------------------------------------------
* If you have any custom Message Board templates they will be

View file

@ -6,6 +6,7 @@ use Parse::PlainConfig;
use strict;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Forum;
my $configFile;
my $quiet;
@ -123,6 +124,95 @@ $sth->finish;
WebGUI::SQL->write("drop table Item");
#--------------------------------------------
print "\tSequencing user submissions.\n" unless ($quiet);
WebGUI::SQL->write("alter table USS_submission add column sequenceNumber int not null");
WebGUI::SQL->write("alter table USS add column USS_id int not null");
WebGUI::SQL->write("alter table USS_submission add column USS_id int not null");
my $ussId = 1000;
my $a = WebGUI::SQL->read("select wobjectId from USS");
while (my ($wobjectId) = $a->array) {
WebGUI::SQL->write("update USS set USS_id=$ussId where wobjectId=$wobjectId");
my $b = WebGUI::SQL->read("select USS_submissionId from USS_submission where wobjectId=$wobjectId order by dateSubmitted");
my $seq = 1;
while (my ($subId) = $b->array) {
WebGUI::SQL->write("update USS_submission set sequenceNumber=$seq, USS_id=$ussId where USS_submissionId=$subId");
$seq++;
}
$b->finsih;
$ussId++;
}
$a->finish;
WebGUI::SQL->write("alter table USS_submission drop column wobjectId");
WebGUI::SQL->write("alter table USS add column submissionFormTemplateId int not null default 1");
WebGUI::SQL->write("alter table USS_submission add column contentType varchar(35) not null default 'mixed'");
WebGUI::SQL->write("update USS_submission set contentType='html' where convertCarriageReturns=0");
WebGUI::SQL->write("alter table USS_submission drop column convertCarriageReturns");
WebGUI::SQL->write("insert into incrementer (incrementerId,nextValue) values ('USS_id',$ussId)");
#--------------------------------------------
print "\tConverting FAQs into USS Submissions.\n" unless ($quiet);
my $sth = WebGUI::SQL->read("select * from template where namespace='FAQ'");
while (my $template = $sth->hashRef) {
$template->{name} =~ s/Default (.*?)/$1/i;
if ($template->{templateId} < 1000) {
($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS' and templateId<1000");
$template->{templateId}++;
} else {
($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS'");
if ($template->{templateId} > 999) {
$template->{templateId}++;
} else {
$template->{templateId} = 1000;
}
}
$template->{template} =~ s/\<tmpl\_loop\s+qa\_loop\>/\<tmpl\_loop submissions\_loop\>/igs;
my $replacement = '
<tmpl_if submission.currentUser>
[<a href="<tmpl_var submission.edit.url>"><tmpl_var submission.edit.label></a>]
</tmpl_if>
<tmpl_if canModerate>
<tmpl_var submission.controls>
</tmpl_if>
';
$template->{template} =~ s/\<tmpl\_if\s+session\.var\.adminOn\>\s*\<tmpl\_var\s+qa\.controls\>\s*\<\/tmpl_if\>/$replacement/igs;
$replacement = ' <tmpl_if canPost>
<a href="<tmpl_var post.url>"> ';
$template->{template} =~ s/\<tmpl\_if\s+session\.var\.adminOn\>\s*\<a\s+href="\<tmpl\_var\s+addquestion\.url\>"\>/$replacement/igs;
$template->{template} =~ s/\<tmpl\_var\s+qa\.question\>/\<tmpl\_var submission\.title\>/igs;
$template->{template} =~ s/\<tmpl\_var\s+qa\.id\>/\<tmpl\_var submission\.id\>/igs;
$template->{template} =~ s/\<tmpl\_var\s+qa\.answer\>/\<tmpl\_var submission\.content\.full\>/igs;
WebGUI::SQL->write("insert into template (templateId,name,template,namespace) values (".$template->{templateId}.",
".quote($template->{name}).", ".quote($template->{template}).", 'USS')");
}
$sth->finish;
WebGUI::SQL->write("delete from template where namespace='FAQ'");
my $a = WebGUI::SQL->read("select a.wobjectId,a.groupIdEdit,a.ownerId,a.lastEdited,b.username,a.dateAdded from wobject a left join users b on
a.ownerId=b.userId where a.namespace='FAQ'");
while (my $data = $a->hashRef) {
$ussId = getNextId("USS_id");
WebGUI::SQL->write("insert into USS (wobjectId, USS_id, groupToContribute, submissionsPerPage, filterContent, sortBy, sortOrder,
submissionFormTemplateId) values (
".$data->{wobjectId}.", $ussId, ".$data->{groupIdEdit}.", 1000, 'none', 'sequenceNumber', 'asc', 2)");
my $b = WebGUI::SQL->read("select * from FAQ_question");
while (my $sub = $b->hashRef) {
my $subId = getNextId("USS_submissionId");
my $forum = WebGUI::Forum->create({});
WebGUI::SQL->write("insert into USS_submission (USS_submissionId, USS_id, title, username, userId, content,
dateUpdated, dateSubmited, forumId,contentType) values ( $subId, $ussId, ".quote($sub->{question}).",
".quote($data->{username}).", ".$data->{ownerId}.", ".quote($sub->{answer}).", ".$data->{lastEdited}.",
".$data->{dateAdded}.", ".$forum->get("forumId").", 'html')");
}
$b->finish;
}
$a->finish;
WebGUI::SQL->write("update wobject set namespace='USS' where namespace='FAQ'");
WebGUI::SQL->write("drop table FAQ");
WebGUI::SQL->write("drop table FAQ_question");
WebGUI::SQL->write("delete from incrementer where incrementerId='FAQ_questionId'");
#--------------------------------------------
print "\tUpdating config file.\n" unless ($quiet);
my $pathToConfig = '../../etc/'.$configFile;
@ -134,7 +224,7 @@ $conf->set("macros"=>$macros);
my $wobjects = $conf->get("wobjects");
my @newWobjects;
foreach my $wobject (@{$wobjects}) {
unless ($wobject eq "Item") {
unless ($wobject eq "Item" || $wobject eq "FAQ") {
push(@newWobjects,$wobject);
}
}
@ -148,7 +238,7 @@ print "\tRemoving unneeded files.\n" unless ($quiet);
unlink("../../lib/WebGUI/Operation/Style.pm");
unlink("../../lib/WebGUI/Wobject/Item.pm");
#unlink("../../lib/WebGUI/Wobject/LinkList.pm");
#unlink("../../lib/WebGUI/Wobject/FAQ.pm");
unlink("../../lib/WebGUI/Wobject/FAQ.pm");

View file

@ -52,16 +52,14 @@ insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (46, 'WebGUI',
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (22, 'WebGUI', 672, 627, '12,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'USS', 61, 71, '71,WebGUI;3,USS;2,USS;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (24, 'WebGUI', 674, 629, '12,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'FAQ', 61, 71, '3,FAQ;2,FAQ;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (13, 'WebGUI', 663, 618, '12,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'SyndicatedContent', 61, 71, '2,SyndicatedContent;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'EventsCalendar', 61, 71, '2,EventsCalendar;3,EventsCalendar;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'MessageBoard', 61, 71, '3,MessageBoard;2,MessageBoard;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'LinkList', 61, 71, '3,LinkList;2,LinkList;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (21, 'WebGUI', 671, 626, '19,WebGUI;18,WebGUI;27,WebGUI;14,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'Article', 61, 71, '2,Article;71,WebGUI;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'ExtraColumn', 61, 71, '21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (27, 'WebGUI', 677, 632, '1,Article;1,EventsCalendar;1,ExtraColumn;1,FAQ;1,FileManager;1,HttpProxy;1,LinkList;1,DataForm;1,MessageBoard;1,Poll;1,Product;1,SiteMap;1,SQLReport;1,Survey;1,SyndicatedContent;1,USS;1,WobjectProxy;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (27, 'WebGUI', 677, 632, '1,Article;1,EventsCalendar;1,ExtraColumn;1,FileManager;1,HttpProxy;1,DataForm;1,MessageBoard;1,Poll;1,Product;1,SiteMap;1,SQLReport;1,Survey;1,SyndicatedContent;1,USS;1,WobjectProxy;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'Poll', 61, 71, '2,Poll;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'SiteMap', 61, 71, '2,SiteMap;21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'SQLReport', 61, 71, '21,WebGUI;');
@ -88,8 +86,6 @@ insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (66, 'WebGUI',
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (65, 'WebGUI', 957, 958, '67,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'FileManager', 72, 73, '1,FileManager;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'EventsCalendar', 72, 73, '4,EventsCalendar;1,EventsCalendar;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'FAQ', 72, 73, '1,FAQ;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'LinkList', 72, 73, '1,LinkList;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (47, 'WebGUI', 697, 698, '1,Article;17,WebGUI;1,MessageBoard;1,Poll;2,WebGUI;1,USS;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'WobjectProxy', 5, 6, '21,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'Product', 38, 39, '5,Product;4,Product;6,Product;2,Product;3,Product;7,Product;21,WebGUI;');
@ -103,12 +99,10 @@ insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'Survey',
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (49, 'WebGUI', 785, 786, '53,WebGUI;54,WebGUI;56,WebGUI;20,WebGUI;61,WebGUI;55,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (50, 'WebGUI', 825, 826, '33,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'Article', 72, 73, '1,Article;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (51, 'WebGUI', 827, 828, '2,Article;3,DataForm;3,EventsCalendar;3,FAQ;3,FileManager;3,LinkList;2,MessageBoard;7,Product;2,SiteMap;2,SyndicatedContent;33,WebGUI;2,USS;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (51, 'WebGUI', 827, 828, '2,Article;3,DataForm;3,EventsCalendar;3,FileManager;2,MessageBoard;7,Product;2,SiteMap;2,SyndicatedContent;33,WebGUI;2,USS;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (3, 'EventsCalendar', 94, 95, '1,EventsCalendar;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (3, 'FAQ', 76, 77, '1,FAQ;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (3, 'FileManager', 75, 76, '1,FileManager;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (4, 'EventsCalendar', 96, 97, '2,EventsCalendar;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (3, 'LinkList', 75, 76, '1,LinkList;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'MessageBoard', 73, 74, '75,WebGUI;76,WebGUI;73,WebGUI;77,WebGUI;72,WebGUI;74,WebGUI;1,MessageBoard;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'SiteMap', 72, 73, '1,SiteMap;51,WebGUI;');
insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'USS', 74, 75, '1,USS;51,WebGUI;');
@ -148,5 +142,18 @@ insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (3, 'MessageBo
delete from international where namespace='Item';
update international set namespace='USS', internationalId='83' where namespace='FAQ' and internationalId=9;
update international set namespace='USS', internationalId='84' where namespace='FAQ' and internationalId=10;
update international set namespace='USS', internationalId='85' where namespace='FAQ' and internationalId=5;
update international set namespace='USS', internationalId='86' where namespace='FAQ' and internationalId=6;
delete from international where namespace='FAQ';
delete from international where namespace='USS' and internationalId=34;
delete from international where namespace='USS' and internationalId=38;
INSERT INTO template VALUES (1,'Default Submission Form','<h1><tmpl_var submission.header.label></h1>\n\n<tmpl_var form.header>\n <table>\n <tmpl_if user.isVisitor> <tmpl_if submission.isNew>\n <tr><td><tmpl_var visitorName.label></td><td><tmpl_var visitorName.form></td></tr>\n </tmpl_if> </tmpl_if>\n <tr><td><tmpl_var title.label></td><td><tmpl_var title.form></td></tr>\n <tr><td><tmpl_var body.label></td><td><tmpl_var body.form></td></tr>\n <tr><td><tmpl_var image.label></td><td><tmpl_var image.form></td></tr>\n <tr><td><tmpl_var attachment.label></td><td><tmpl_var attachment.form></td></tr>\n <tr><td><tmpl_var contentType.label></td><td><tmpl_var contentType.form></td></tr>\n <tr><td></td><td><tmpl_var form.submit></td></tr>\n </table>\n<tmpl_var form.footer>\n','USS/SubmissionForm');
INSERT INTO template VALUES (2,'FAQ Submission Form','<h1><tmpl_var question.header.label></h1>\n\n<tmpl_var form.header>\n <table>\n <tmpl_if user.isVisitor> <tmpl_if submission.isNew>\n <tr><td><tmpl_var visitorName.label></td><td><tmpl_var visitorName.form></td></tr>\n </tmpl_if> </tmpl_if>\n <tr><td><tmpl_var question.label></td><td><tmpl_var title.form.textarea></td></tr>\n <tr><td><tmpl_var answer.label></td><td><tmpl_var body.form></td></tr>\n <tr><td><tmpl_var contentType.label></td><td><tmpl_var contentType.form></td></tr>\n <tr><td></td><td><tmpl_var form.submit></td></tr>\n </table>\n<tmpl_var form.footer>\n','USS/SubmissionForm');
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (87,1,'USS','Submission Form Template', 1070027660,'Prompt the user to select a template for the USS submission form.');
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (88,1,'USS','Sequence', 1070027660,'A type of ordering in the USS that will allow the admin to specify (or sequence) the order of the results.');

View file

@ -60,7 +60,7 @@ sub _processAction {
#-------------------------------------------------------------------
sub _processFunctions {
my ($wobject, $extra, %hash, $output, $proxyWobjectId, $cmd, $w);
my ($wobject, $output, $proxyWobjectId, $cmd, $w);
if (exists $session{form}{func} && exists $session{form}{wid}) {
if ($session{form}{func} =~ /^[A-Za-z]+$/) {
if ($session{form}{wid} eq "new") {
@ -73,12 +73,6 @@ sub _processFunctions {
."corrupt, but was requested "
."by $session{user}{username} [$session{user}{userId}].");
$wobject = ();
} else {
$extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace}
where wobjectId=${$wobject}{wobjectId}");
tie %hash, 'Tie::CPHash';
%hash = (%{$wobject},%{$extra});
$wobject = \%hash;
}
}
if ($wobject) {

View file

@ -1184,29 +1184,9 @@ sub getPostTemplateVars {
$var->{'post.subject.label'} = WebGUI::International::get(229);
$var->{'post.subject'} = WebGUI::HTML::filter($post->get("subject"),"none");
$var->{'post.message'} = WebGUI::HTML::filter($post->get("message"),$forum->get("filterPosts"));
if ($post->get("contentType") eq "mixed") {
unless ($var->{'post.message'} =~ /\<div/ig || $var->{'post.message'} =~ /\<br/ig || $var->{'post.message'} =~ /\<p/ig) {
$var->{'post.message'} =~ s/\n/\<br \/\>/g;
}
} elsif ($post->get("contentType") eq "text") {
$var->{'post.message'} =~ s/\t/&nbsp;&nbsp;&nbsp;&nbsp;/g;
$var->{'post.message'} =~ s/ /&nbsp;/g;
$var->{'post.message'} =~ s/\n/\<br \/\>/g;
} elsif ($post->get("contentType") eq "code") {
$var->{'post.message'} =~ s/&/&amp;/g;
$var->{'post.message'} =~ s/\</&lt;/g;
$var->{'post.message'} =~ s/\>/&gt;/g;
$var->{'post.message'} =~ s/\n/\<br \/\>/g;
$var->{'post.message'} =~ s/\t/&nbsp;&nbsp;&nbsp;&nbsp;/g;
$var->{'post.message'} =~ s/ /&nbsp;/g;
$var->{'post.message'} = '<div style="font-family: fixed;">'.$var->{'post.message'}.'</div>';
}
$var->{'post.message'} = WebGUI::HTML::format($var->{'post.message'}, $post->get("contentType"));
if ($forum->get("allowReplacements")) {
my $sth = WebGUI::SQL->read("select searchFor,replaceWith from replacements");
while (my ($searchFor,$replaceWith) = $sth->array) {
$var->{'post.message'} =~ s/\Q$searchFor/$replaceWith/gs;
}
$sth->finish;
$var->{'post.message'} = WebGUI::HTML::processReplacements($var->{'post.message'});
}
$var->{'user.canPost'} = $forum->canPost;
$var->{'post.date.value'} = formatPostDate($post->get("dateOfPost"));

View file

@ -18,6 +18,7 @@ use HTML::TagFilter;
use strict;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::SQL;
=head1 NAME
@ -32,6 +33,8 @@ A package for manipulating and massaging HTML.
use WebGUI::HTML;
$html = WebGUI::HTML::cleanSegment($html);
$html = WebGUI::HTML::filter($html);
$html = WebGUI::HTML::format($content, $contentType);
$html = WebGUI::HTML::processReplacements($html);
=head1 METHODS
@ -127,6 +130,85 @@ sub filter {
}
}
#-------------------------------------------------------------------
=head2 format ( content [ , contentType ] )
Formats various text types into HTML.
=over
=item content
The text content to be formatted.
=item contentType
The content type to use as formatting. Valid types are 'html', 'text', 'code', and 'mixed'. Defaults to mixed. See also the contentType method in WebGUI::Form, WebGUI::HTMLForm, and WebGUI::FormProcessor.
=back
=cut
sub format {
my ($content, $contentType) = @_;
$contentType = 'mixed' unless ($contentType);
if ($contentType eq "mixed") {
unless ($content =~ /\<div/ig || $content =~ /\<br/ig || $content =~ /\<p/ig) {
$content =~ s/\n/\<br \/\>/g;
}
} elsif ($contentType eq "text") {
$content =~ s/\t/&nbsp;&nbsp;&nbsp;&nbsp;/g;
$content =~ s/ /&nbsp;/g;
$content =~ s/\n/\<br \/\>/g;
} elsif ($contentType eq "code") {
$content =~ s/&/&amp;/g;
$content =~ s/\</&lt;/g;
$content =~ s/\>/&gt;/g;
$content =~ s/\n/\<br \/\>/g;
$content =~ s/\t/&nbsp;&nbsp;&nbsp;&nbsp;/g;
$content =~ s/ /&nbsp;/g;
$content = '<div style="font-family: fixed;">'.$content.'</div>';
}
return $content;
}
#-------------------------------------------------------------------
=head2 processReplacements ( content )
Processes text using the WebGUI replacements system.
=over
=item content
The content to be processed through the replacements filter.
=back
=cut
sub processReplacements {
my ($content) = @_;
if (exists $session{replacements}) {
my $replacements = $session{replacements};
foreach my $searchFor (keys %{$replacements}) {
my $replaceWith = $replacements->{$searchFor};
$content =~ s/\Q$searchFor/$replaceWith/gs;
}
} else {
my $sth = WebGUI::SQL->read("select searchFor,replaceWith from replacements");
while (my ($searchFor,$replaceWith) = $sth->array) {
$session{replacements}{$searchFor} = $replaceWith;
$content =~ s/\Q$searchFor/$replaceWith/gs;
}
$sth->finish;
}
return $content;
}
1;

View file

@ -857,6 +857,11 @@ sub set {
)");
WebGUI::SQL->write("insert into ".$self->{_property}{namespace}." (wobjectId)
values (".$self->{_property}{wobjectId}.")");
foreach my $key (keys %{$self->{_extendedProperties}}) {
if ($self->{_extendedProperties}{$key}{autoIncrement}) {
$properties->{$key} = getNextId($key);
}
}
}
$self->{_property}{lastEdited} = time();
$self->{_property}{editedBy} = $session{user}{userId};

View file

@ -62,17 +62,20 @@ sub duplicate {
my ($sth, $file, %row, $newSubmissionId, $w);
tie %row, 'Tie::CPHash';
$w = $_[0]->SUPER::duplicate($_[1],1);
$sth = WebGUI::SQL->read("select * from USS_submission where wobjectId=".$_[0]->get("wobjectId"));
my $props = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=$w");
my $newWobject = WebGUI::Wobject::USS->new($props);
$sth = WebGUI::SQL->read("select * from USS_submission where USS_id=".$_[0]->get("USS_id"));
while (%row = $sth->hash) {
$newSubmissionId = getNextId("USS_submissionId");
$file = WebGUI::Attachment->new($row{image},$_[0]->get("wobjectId"),$row{USS_submissionId});
$file->copy($w,$newSubmissionId);
$file = WebGUI::Attachment->new($row{attachment},$_[0]->get("wobjectId"),$row{USS_submissionId});
$file->copy($w,$newSubmissionId);
WebGUI::SQL->write("insert into USS_submission values (".$w.", $newSubmissionId, ".
quote($row{title}).", $row{dateSubmitted}, ".quote($row{username}).", '$row{userId}', ".quote($row{content}).", ".
quote($row{image}).", ".quote($row{attachment}).", '$row{status}', '$row{convertCarriageReturns}',
'$row{views}')");
WebGUI::SQL->write("insert into USS_submission (USS_submissionId, title, dateSubmitted, username, userId, content,
image, attachment, status, views, forumId, dateUpdated, sequenceNumber, USS_id, contentType) values ($newSubmissionId, ".
quote($row{title}).", $row{dateSubmitted}, ".quote($row{username}).", $row{userId}, ".quote($row{content}).", ".
quote($row{image}).", ".quote($row{attachment}).", '$row{status}', $row{views}, $row{forumId}, $row{dateUpdated},
$row{sequenceNumber}, ".$newWobject->get("USS_id").", ".quote($row{contentType}).")");
}
$sth->finish;
}
@ -105,6 +108,9 @@ sub new {
submissionTemplateId=>{
defaultValue=>1
},
submissionFormTemplateId=>{
defaultValue=>1
},
karmaPerSubmission=>{
defaultValue=>0
},
@ -116,6 +122,12 @@ sub new {
},
sortOrder=>{
defaultValue=>"desc"
},
USS_id=>{
autoIncrement=>1
},
submissionFormTemplateId=>{
defaultValue=>1
}
},
-useTemplate=>1
@ -125,7 +137,7 @@ sub new {
#-------------------------------------------------------------------
sub purge {
my $sth = WebGUI::SQL->read("select forumId from USS_submission where wobjectId=".$_[0]->get("wobjectId"));
my $sth = WebGUI::SQL->read("select forumId from USS_submission where USS_id=".$_[0]->get("USS_id"));
while (my ($forumId) = $sth->array) {
my ($inUseElsewhere) = WebGUI::SQL->quickArray("select count(*) from USS_submission where forumId=".$forumId);
unless ($inUseElsewhere > 1) {
@ -134,7 +146,7 @@ sub purge {
}
}
$sth->finish;
WebGUI::SQL->write("delete from USS_submission where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("delete from USS_submission where USS_id=".$_[0]->get("USS_id"));
$_[0]->SUPER::purge();
}
@ -236,6 +248,13 @@ sub www_edit {
-label=>WebGUI::International::get(73,$_[0]->get("namespace")),
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
);
$layout->template(
-name=>"submissionFormTemplateId",
-value=>$_[0]->getValue("submissionFormTemplateId"),
-namespace=>$_[0]->get("namespace")."/SubmissionForm",
-label=>WebGUI::International::get(87,$_[0]->get("namespace")),
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
);
$privileges->group(
-name=>"groupToApprove",
-label=>WebGUI::International::get(1,$_[0]->get("namespace")),
@ -277,6 +296,7 @@ sub www_edit {
-name=>"sortBy",
-value=>[$_[0]->getValue("sortBy")],
-options=>{
sequenceNumber=>WebGUI::International::get(88,$_[0]->get("namespace")),
dateUpdated=>WebGUI::International::get(78,$_[0]->get("namespace")),
dateSubmitted=>WebGUI::International::get(13,$_[0]->get("namespace")),
title=>WebGUI::International::get(35,$_[0]->get("namespace"))
@ -306,42 +326,79 @@ sub www_edit {
sub www_editSubmission {
my ($output, $submission, $f, @submission, $sth);
$submission = $_[0]->getCollateral("USS_submission","USS_submissionId",$session{form}{sid});
my %var;
if ($submission->{USS_submissionId} eq "new") {
$submission->{userId} = $session{user}{userId};
$submission->{contentType} = "mixed";
$var{'submission.isNew'} = 1;
}
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToContribute")) || $submission->{userId} == $session{user}{userId} || WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove"))) {
$output = '<h1>'.WebGUI::International::get(19,$_[0]->get("namespace")).'</h1>';
$f = WebGUI::HTMLForm->new;
if ($session{user}{userId} == 1 && $submission->{USS_submissionId} eq "new") {
$f->text("visitorName",WebGUI::International::get(438));
}
$f->hidden("wid",$session{form}{wid});
$f->hidden("sid",$submission->{USS_submissionId});
$f->hidden("func","editSubmissionSave");
$f->text("title",WebGUI::International::get(35,$_[0]->get("namespace")),$submission->{title});
$f->HTMLArea("body",WebGUI::International::get(31,$_[0]->get("namespace")),$submission->{content});
if ($submission->{image} ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteFile&file=image&wid='.$session{form}{wid}.'&sid='.$submission->{USS_submissionId}).'">'
.WebGUI::International::get(391).'</a>',WebGUI::International::get(32,$_[0]->get("namespace")));
} else {
$f->file("image",WebGUI::International::get(32,$_[0]->get("namespace")));
}
if ($submission->{attachment} ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteFile&file=attachment&wid='.$session{form}{wid}
.'&sid='.$submission->{USS_submissionId}).'">'
.WebGUI::International::get(391).'</a>',WebGUI::International::get(33,$_[0]->get("namespace")));
} else {
$f->file("attachment",WebGUI::International::get(33,$_[0]->get("namespace")));
}
$f->yesNo("convertCarriageReturns",WebGUI::International::get(34,$_[0]->get("namespace")),$submission->{convertCarriageReturns},
'',' &nbsp; '.WebGUI::International::get(38,$_[0]->get("namespace")));
$f->submit;
$output .= $f->print;
return $output;
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::isInGroup($_[0]->get("groupToContribute"))
|| $submission->{userId} == $session{user}{userId}
|| WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove")));
$var{'question.header.label'} = WebGUI::International::get(84,$_[0]->get("namespace"));
$var{'question.label'} = WebGUI::International::get(85,$_[0]->get("namespace"));
$var{'answer.label'} = WebGUI::International::get(86,$_[0]->get("namespace"));
$var{'submission.header.label'} = WebGUI::International::get(19,$_[0]->get("namespace"));
$var{'user.isVisitor'} = ($session{user}{userId} == 1);
$var{'visitorName.label'} = WebGUI::International::get(438);
$var{'visitorName.form'} = WebGUI::Form::text({
name=>"visitorName"
});
$var{'form.header'} = WebGUI::Form::formHeader()
.WebGUI::Form::hidden({
name=>"wid",
value=>$session{form}{wid}
})
.WebGUI::Form::hidden({
name=>"sid",
value=>$submission->{USS_submissionId}
})
.WebGUI::Form::hidden({
name=>"func",
value=>"editSubmissionSave"
});
$var{'title.label'} = WebGUI::International::get(35,$_[0]->get("namespace"));
$var{'title.form'} = WebGUI::Form::text({
name=>"title",
value=>$submission->{title}
});
$var{'title.form.textarea'} = WebGUI::Form::textarea({
name=>"title",
value=>$submission->{title}
});
$var{'title.value'} = $submission->{title};
$var{'body.label'} = WebGUI::International::get(31,$_[0]->get("namespace"));
$var{'body.value'} = $submission->{content};
$var{'body.form'} = WebGUI::Form::HTMLArea({
name=>"body",
value=>$submission->{content}
});
$var{'image.label'} = WebGUI::International::get(32,$_[0]->get("namespace"));
if ($submission->{image} ne "") {
$var{'image.form'} = '<a href="'.WebGUI::URL::page('func=deleteFile&amp;file=image&amp;wid='.$session{form}{wid}
.'&amp;sid='.$submission->{USS_submissionId}).'">'.WebGUI::International::get(391).'</a>';
} else {
return WebGUI::Privilege::insufficient();
$var{'image.form'} = WebGUI::Form::file({
name=>"image"
});
}
return $output;
$var{'attachment.label'} = WebGUI::International::get(33,$_[0]->get("namespace"));
if ($submission->{attachment} ne "") {
$var{'attachment.form'} = '<a href="'.WebGUI::URL::page('func=deleteFile&amp;file=attachment&amp;wid='
.$session{form}{wid}.'&amp;sid='.$submission->{USS_submissionId}).'">'.WebGUI::International::get(391).'</a>';
} else {
$var{'attachment.form'} = WebGUI::Form::file({
name=>"attachment"
});
}
$var{'contentType.label'} = WebGUI::International::get(1007);
$var{'contentType.form'} = WebGUI::Form::contentType({
name=>'contentType',
value=>[$submission->{contentType}]
});
$var{'form.submit'} = WebGUI::Form::submit();
$var{'form.footer'} = '</form>';
return WebGUI::Template::process(WebGUI::Template::get($_[0]->get("submissionFormTemplateId"),"USS/SubmissionForm"), \%var);
}
#-------------------------------------------------------------------
@ -358,6 +415,7 @@ sub www_editSubmissionSave {
forumId=>"new"
});
$hash{forumId} = $forum->get("forumId");
$hash{USS_id} = $_[0]->get("USS_id");
$hash{username} = $session{form}{visitorName} || $session{user}{alias};
$hash{userId} = $session{user}{userId};
$hash{dateSubmitted} = WebGUI::DateTime::time();
@ -367,14 +425,14 @@ sub www_editSubmissionSave {
$u->karma($_[0]->get("karmaPerSubmission"),$_[0]->get("namespace")." (".$_[0]->get("wobjectId")
."/".$session{form}{sid}.")","User submission.");
}
$session{form}{sid} = $_[0]->setCollateral("USS_submission","USS_submissionId",\%hash,0);
$session{form}{sid} = $_[0]->setCollateral("USS_submission","USS_submissionId",\%hash,1,0,"USS_id",$_[0]->get("USS_id"));
%hash = ();
}
$hash{title} = WebGUI::HTML::filter($session{form}{title},'all') || WebGUI::International::get(16,$_[0]->get("namespace"));
$hash{USS_submissionId} = $session{form}{sid};
$hash{dateUpdated} = WebGUI::DateTime::time();
$hash{content} = $session{form}{body};
$hash{convertCarriageReturns} = $session{form}{convertCarriageReturns};
$hash{contentType} = $session{form}{contentType};
$file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{sid});
$file->save("image");
$hash{image} = $file->getFilename if ($file->getFilename ne "");
@ -391,13 +449,28 @@ sub www_editSubmissionSave {
$hash{status} = "Approved";
}
}
$_[0]->setCollateral("USS_submission", "USS_submissionId", \%hash, 0);
$_[0]->setCollateral("USS_submission", "USS_submissionId", \%hash, 1, 0, "USS_id", $_[0]->get("USS_id"));
return $_[0]->www_viewSubmission();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveSubmissionDown {
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId")));
$_[0]->moveCollateralDown("USS_submission","USS_submissionId",$session{form}{sid}, "USS_id", $_[0]->get("USS_id"));
return "";
}
#-------------------------------------------------------------------
sub www_moveSubmissionUp {
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId")));
$_[0]->moveCollateralUp("USS_submission","USS_submissionId",$session{form}{sid}, "USS_id", $_[0]->get("USS_id"));
return "";
}
#-------------------------------------------------------------------
sub www_view {
my (%var, $row, $page, $p, $constraints, @submission, @content, $image, $i, $numResults, $thumbnail, $responses);
@ -422,19 +495,24 @@ sub www_view {
} else {
$constraints = "(status='Approved' or (userId=$session{user}{userId} and userId<>1))";
}
$var{"addquestion.label"} = WebGUI::International::get(83,$_[0]->get("namespace"));
$var{canModerate} = WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove"),$session{user}{userId});
$var{"title.label"} = WebGUI::International::get(99);
$var{"thumbnail.label"} = WebGUI::International::get(52,$_[0]->get("namespace"));
$var{"date.label"} = WebGUI::International::get(13,$_[0]->get("namespace"));
$var{"date.updated.label"} = WebGUI::International::get(78,$_[0]->get("namespace"));
$var{"by.label"} = WebGUI::International::get(21,$_[0]->get("namespace"));
$var{"submission.edit.label"} = WebGUI::International::get(27,$_[0]->get("namespace"));
$p = WebGUI::Paginator->new(WebGUI::URL::page('func=view&wid='.$_[0]->get("wobjectId")),[],$numResults);
$p->setDataByQuery("select USS_submissionId, content, title, userId, status, image, dateSubmitted, username, forumId from USS_submission
where wobjectId=".$_[0]->get("wobjectId")." and $constraints order by ".$_[0]->getValue("sortBy")." ".$_[0]->getValue("sortOrder"));
$p->setDataByQuery("select USS_submissionId, content, title, userId, status, image, dateSubmitted, dateUpdated,
username, contentType, forumId from USS_submission
where USS_id=".$_[0]->get("USS_Id")." and $constraints order by ".$_[0]->getValue("sortBy")." ".$_[0]->getValue("sortOrder"));
$page = $p->getPageData;
$i = 0;
my $imageURL;
foreach $row (@$page) {
$page->[$i]->{content} = WebGUI::HTML::filter($page->[$i]->{content},$_[0]->get("filterContent"));
$page->[$i]->{content} = WebGUI::HTML::format($page->[$i]->{content},$page->[$i]->{contentType});
$page->[$i]->{content} =~ s/\n/\^\-\;/ unless ($page->[$i]->{content} =~ m/\^\-\;/);
@content = split(/\^\-\;/,$page->[$i]->{content});
if ($page->[$i]->{image} ne "") {
@ -447,10 +525,23 @@ sub www_view {
}
($responses) = WebGUI::SQL->quickArray("select count(*) from forumPost left join forumThread on
forumThread.forumThreadId=forumPost.forumThreadId where forumThread.forumId=".$row->{forumId});
my $quickurl = 'wid='.$_[0]->get("wobjectId").'&amp;sid='.$page->[$i]->{USS_submissionId}.'&amp;func=';
my $controls = deleteIcon($quickurl.'deleteSubmission')
.editIcon($quickurl.'editSubmission');
if ($_[0]->get("sortBy") eq "sequenceNumber") {
if ($_[0]->get("sortOrder") eq "desc") {
$controls .= moveUpIcon($quickurl.'moveSubmissionDown')
.moveDownIcon($quickurl.'moveSubmissionUp');
} else {
$controls .= moveUpIcon($quickurl.'moveSubmissionUp')
.moveDownIcon($quickurl.'moveSubmissionDown');
}
}
push (@submission,{
"submission.id"=>$page->[$i]->{USS_submissionId},
"submission.url"=>WebGUI::URL::page('wid='.$_[0]->get("wobjectId").'&func=viewSubmission&sid='.$page->[$i]->{USS_submissionId}),
"submission.url"=>WebGUI::URL::page($quickurl.'viewSubmission'),
"submission.content"=>$content[0],
"submission.content.full"=>join("\n",@content),
"submission.responses"=>$responses,
"submission.title"=>$page->[$i]->{title},
"submission.userId"=>$page->[$i]->{userId},
@ -462,10 +553,12 @@ sub www_view {
"submission.currentUser"=>($session{user}{userId} == $page->[$i]->{userId}),
"submission.username"=>$page->[$i]->{username},
"submission.userProfile"=>WebGUI::URL::page('op=viewProfile&uid='.$page->[$i]->{userId}),
"submission.edit.url"=>WebGUI::URL::page($quickurl.'editSubmission'),
"submission.secondColumn"=>(($i+1)%2==0),
"submission.thirdColumn"=>(($i+1)%3==0),
"submission.fourthColumn"=>(($i+1)%4==0),
"submission.fifthColumn"=>(($i+1)%5==0),
'submission.controls'=>$controls
});
$i++;
}
@ -501,7 +594,7 @@ sub www_viewRSS {
my $res = WebGUI::SQL->read
("select USS_submissionId, content, title, " .
"dateSubmitted, username from USS_submission " .
"where wobjectId = " .$session{dbh}->quote($wid) . " " .
"where USS_id = " .$session{dbh}->quote($_[0]->get("USS_id")) . " " .
"order by ".$_[0]->getValue("sortBy")." ".$_[0]->getValue("sortOrder")." limit " . $numResults);
while (my $row = $res->{_sth}->fetchrow_arrayref()) {
@ -555,7 +648,7 @@ sub www_viewSubmission {
$var{title} = $submission->{title};
$var{content} = WebGUI::HTML::filter($submission->{content},$_[0]->get("filterContent"));
$var{content} =~ s/\^\-\;//g;
$var{content} =~ s/\n/\<br\>/g if ($submission->{convertCarriageReturns});
$var{content} =~ WebGUI::HTML::format($submission->{content},$submission->{contentType});
$var{"user.label"} = WebGUI::International::get(21,$_[0]->get("namespace"));
$var{"user.Profile"} = WebGUI::URL::page('op=viewProfile&uid='.$submission->{userId});
$var{"user.Id"} = $submission->{userId};
@ -574,13 +667,13 @@ sub www_viewSubmission {
$var{"post.url"} = WebGUI::URL::page('func=editSubmission&sid=new&wid='.$_[0]->get("wobjectId"));
$var{"post.label"} = WebGUI::International::get(20,$_[0]->get("namespace"));
@data = WebGUI::SQL->quickArray("select max(USS_submissionId) from USS_submission
where wobjectId=".$_[0]->get("wobjectId")." and USS_submissionId<$submission->{USS_submissionId}
where USS_id=".$_[0]->get("USS_id")." and USS_submissionId<$submission->{USS_submissionId}
and (userId=$submission->{userId} or status='Approved')");
$var{"previous.more"} = ($data[0] ne "");
$var{"previous.url"} = WebGUI::URL::page('func=viewSubmission&sid='.$data[0].'&wid='.$session{form}{wid});
$var{"previous.label"} = WebGUI::International::get(58,$_[0]->get("namespace"));
@data = WebGUI::SQL->quickArray("select min(USS_submissionId) from USS_submission
where wobjectId=$submission->{wobjectId} and USS_submissionId>$submission->{USS_submissionId}
where USS_id=$submission->{USS_id} and USS_submissionId>$submission->{USS_submissionId}
and (userId=$submission->{userId} or status='Approved')");
$var{"next.more"} = ($data[0] ne "");
$var{"next.url"} = WebGUI::URL::page('func=viewSubmission&sid='.$data[0].'&wid='.$session{form}{wid});