templatized the poll

This commit is contained in:
JT Smith 2003-04-13 02:44:19 +00:00
parent 8898dd3323
commit cdfdd07219
2 changed files with 52 additions and 45 deletions

View file

@ -45,6 +45,18 @@ delete from international where languageId=1 and namespace='WebGUI' and internat
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (634,1,'WebGUI','<b>Default Home Page</b><br>\r\nSome really small sites don\'t have a home page, but instead like to use one of their internal pages like "About Us" or "Company Information" as their home page. For that reason, you can set the default page of your site to any page in the site. That page will be the one people go to if they type in just your URL http://www.mywebguisite.com, or if they click on the Home link generated by the ^H; macro.\r\n<p>\r\n\r\n<b>Not Found Page</b><br>\r\nIf a page that a user requests is not found in the system, the user can be redirected to the home page or to an error page where they can attempt to find what they were looking for. You decide which is better for your users.\r\n<p>\r\n\r\n<b>Document Type Declaration</b><br>\r\nThese days it is very common to have a wide array of browsers accessing your site, including automated browsers like search engine spiders. Many of those browsers want to know what kind of content you are serving. The doctype tag allows you to specify that. By default WebGUI generates HTML 4.0 compliant content.\r\n<p>\r\n\r\n<b>Favicon</b><br>\r\nAn icon that appears on Internet Explorer short cuts such as your "Favorites". To learn more about Favicon <a href="http://msdn.microsoft.com/workshop/author/dhtml/howto/shortcuticon.asp">click here</a>.\r\n<p>\r\n\r\n<b>Site Icon</b><br>\r\nAn icon that appears in the URL bar of most modern browsers. It may also appear in the bookmarks of the browser. The image must be 16x16 pixels.\r\n<p>\r\n\r\n\r\n<b>Add edit stamp to posts?</b><br>\r\nTypically if a user edits a post on a discussion, a stamp is added to that post to identify who made the edit, and at what time. On some sites that information is not necessary, therefore you can turn it off here.\r\n<p>\r\n\r\n<b>Filter Contributed HTML</b><br>\r\nEspecially when running a public site where anybody can post to your message boards or user submission systems, it is often a good idea to filter their content for malicious code that can harm the viewing experience of your visitors; And in some circumstances, it can even cause security problems. Use this setting to select the level of filtering you wish to apply.\r\n<p>\r\n\r\n<b>Maximum Attachment Size</b><br>\r\nThe size (in kilobytes) of the maximum allowable attachment to be uploaded to your system.\r\n<p>\r\n\r\n<b>Max Image Size</b><br>\r\nIf images are uploaded to your system that are bigger than the max image size, then they will be resized to the max image size. The max image size is measured in pixels and will use the size of the longest side of the image to determine if the limit has been reached.\r\n<p>\r\n\r\n<b>Thumbnail Size</b><br>\r\nWhen images are uploaded to your system, they will automatically have thumbnails generated at the size specified here (unless overridden on a case-by-case basis). Thumbnail size is measured in pixels.\r\n<p>\r\n\r\n<b>Snippet Preview Length</b><br/>\r\nHow many characters of a snippet should be displayed in the collateral management system main listing.\r\n<p/>\r\n\r\n<b>Text Area Rows</b><br>\r\nSome sites wish to control the size of the forms that WebGUI generates. With this setting you can specify how many rows of characters will be displayed in textareas on the site.\r\n<p>\r\n\r\n<b>Text Area Columns</b><br>\r\nSome sites wish to control the size of the forms that WebGUI generates. With this setting you can specify how many columns of characters will be displayed in textareas on the site.\r\n<p>\r\n\r\n<b>Text Box Size</b><br>\r\nSome sites wish to control the size of the forms that WebGUI generates. With this setting you can specify how characters can be displayed at once in text boxes on the site.\r\n<p>\r\n\r\n<b>Page Cache Timeout</b><br>\r\nThe amount of time pages should remain cached for registered users.\r\n<p>\r\n\r\n<b>Page Cache Timeout (Visitors)</b><br>\r\nThe amount of time pages should remain cached for visitors.\r\n<p>\r\n\r\n<b>NOTE:</b> Page caching is only available if your administrator has installed the Cache::FileCache Perl module. Using page caching can improve site performance by as much as 1000%.', 1050172368);
delete from international where languageId=1 and namespace='WebGUI' and internationalId=897;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (897,1,'WebGUI','Favicon', 1050170767);
delete from international where languageId=1 and namespace='Poll' and internationalId=61;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (61,1,'Poll','Poll, Add/Edit', 1050183732);
delete from international where languageId=1 and namespace='Poll' and internationalId=71;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (71,1,'Poll','Polls can be used to get the impressions of your users on various topics.\r\n<br><br>\r\n<b>Active</b><br>\r\nIf this box is checked, then users will be able to vote. Otherwise they\'ll only be able to see the results of the poll.\r\n<br><br>\r\n\r\n<b>Who can vote?</b><br>\r\nChoose a group that can vote on this Poll.\r\n<br><br>\r\n\r\n<b>Karma Per Vote</b><br>\r\nHow much karma should be given to a user when they vote?\r\n<p>\r\n\r\n<b>Graph Width</b><br>\r\nThe width of the poll results graph. The width is measured in pixels.\r\n<br><br>\r\n\r\n<b>Question</b><br>\r\nWhat is the question you\'d like to ask your users?\r\n<br><br>\r\n\r\n<b>Answers</b><br>\r\nEnter the possible answers to your question. Enter only one answer per line. Polls are only capable of 20 possible answers.\r\n<br><br>\r\n\r\n<b>Randomize answers?</b><br>\r\nIn order to be sure that the ordering of the answers in the poll does not bias your users, it is often helpful to present the options in a random order each time they are shown. Select "yes" to randomize the answers on the poll.\r\n<p>\r\n\r\n<b>Reset votes.</b><br>\r\nReset the votes on this Poll.\r\n<br><br>\r\n', 1050183732);
delete from international where languageId=1 and namespace='Poll' and internationalId=73;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (73,1,'Poll','Poll Template', 1050183668);
delete from international where languageId=1 and namespace='Poll' and internationalId=74;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (74,1,'Poll','The following variables are available to the poll template:\r\n\r\n<b>canVote</b><br>\r\nA condition indicating whether the user has the right to vote on this poll.\r\n<p>\r\n\r\n<b>question</b><br>\r\nThe poll question.\r\n<p>\r\n\r\n<b>form.start</b><br>\r\nThe beginning of the vote form.\r\n<p>\r\n\r\n<b>answer_loop</b><br>\r\nA loop containing information about the answers in the poll.\r\n<p>\r\n\r\n<blockquote>\r\n\r\n<b>answer.form</b><br>\r\nThe radio button for this answer.\r\n<p>\r\n\r\n<b>answer.text</b><br>\r\nThe text of the answer.\r\n<p>\r\n\r\n<b>answer.number</b><br>\r\nThe number of this answer. As in 1, 2, 3, etc.\r\n<p>\r\n\r\n<b>answer.graphWidth</b><br>\r\nThe width that the graph should be rendered for this answer. Based upon a percentage of the total graph size.\r\n<p>\r\n\r\n\r\n<b>answer.percent</b><br>\r\nThe percentage of the vote that this answer has received.\r\n<p>\r\n\r\n<b>answer.total</b><br>\r\nThe total number of votes that this answer has received.\r\n<p>\r\n\r\n</blockquote>\r\n\r\n\r\n<b>form.submit</b><br>\r\nThe submit button for the poll form.\r\n<p>\r\n\r\n<b>form.end</b><br>\r\nThe end of the poll form.\r\n<p>\r\n\r\n<b>responses.label</b><br>\r\nThe label for the total responses. "Total Votes"\r\n<p>\r\n\r\n<b>responses.total</b><br>\r\nThe total number of votes that have been placed on this poll.\r\n<p>\r\n\r\n', 1050183668);
delete from international where languageId=1 and namespace='Poll' and internationalId=12;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (12,1,'Poll','Total Votes', 1050182699);
INSERT INTO template VALUES (1,'Default Poll','<tmpl_if displayTitle>\r\n <h1><tmpl_var title></h1>\r\n</tmpl_if>\r\n\r\n<tmpl_if description>\r\n <tmpl_var description><p />\r\n</tmpl_if>\r\n\r\n<span class=\"pollQuestion\"><tmpl_var question></span><br />\r\n\r\n<tmpl_if canVote>\r\n\r\n <tmpl_var form.start>\r\n <tmpl_loop answer_loop>\r\n <tmpl_var answer.form> <tmpl_var answer.text><br />\r\n </tmpl_loop>\r\n <p />\r\n <tmpl_var form.submit>\r\n <tmpl_var form.end>\r\n\r\n<tmpl_else>\r\n\r\n <tmpl_loop answer_loop>\r\n <span class=\"pollAnswer\"><hr size=\"1\"><tmpl_var answer.text><br></span>\r\n <table cellpadding=0 cellspacing=0 border=0><tr>\r\n <td width=\"<tmpl_var answer.graphWidth>\" class=\"pollColor\"><img src=\"^Extras;spacer.gif\" height=\"1\" width=\"1\"></td>\r\n <td class=\"pollAnswer\">&nbsp;&nbsp;<tmpl_var answer.percent>% (<tmpl_var answer.total>)</td>\r\n </tr></table>\r\n </tmpl_loop>\r\n <span class=\"pollAnswer\"><hr size=\"1\"><b><tmpl_var responses.label>:</b> <tmpl_var responses.total></span>\r\n\r\n</tmpl_if>\r\n\r\n','Poll');

View file

@ -13,6 +13,7 @@ package WebGUI::Wobject::Poll;
use strict;
use Tie::CPHash;
use WebGUI::Form;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
@ -26,6 +27,13 @@ use WebGUI::Wobject;
our @ISA = qw(WebGUI::Wobject);
#-------------------------------------------------------------------
sub _hasVoted {
my ($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer
where wobjectId=".$_[0]->get("wobjectId")." and ((userId=$session{user}{userId}
and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))");
return $hasVoted;
}
#-------------------------------------------------------------------
sub duplicate {
@ -182,15 +190,12 @@ sub www_resetVotes {
#-------------------------------------------------------------------
sub www_view {
my ($hasVoted, $answer, $output, @answers, $showPoll, $f, $i, $totalResponses, @data);
$output = $_[0]->displayTitle;
$output .= $_[0]->description;
my (%var, $answer, @answers, $showPoll, $f);
$var{question} = $_[0]->get("question");
if ($_[0]->get("active") eq "0") {
$showPoll = 0;
} elsif (WebGUI::Privilege::isInGroup($_[0]->get("voteGroup"),$session{user}{userId})) {
($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where wobjectId=".$_[0]->get("wobjectId")."
and ((userId=$session{user}{userId} and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))");
if ($hasVoted) {
if ($_[0]->_hasVoted()) {
$showPoll = 0;
} else {
$showPoll = 1;
@ -198,51 +203,41 @@ sub www_view {
} else {
$showPoll = 0;
}
$output .= '<span class="pollQuestion">'.$_[0]->get("question").'</span><br>';
if ($showPoll) {
$f = WebGUI::HTMLForm->new(1);
$f->hidden('wid',$_[0]->get("wobjectId"));
$f->hidden('func','vote');
for ($i=1; $i<=20; $i++) {
if ($_[0]->get('a'.$i) =~ /\C/) {
$answers[($i-1)] = '<input type="radio" name="answer" value="a'.$i.'"> <span class="pollAnswer">'.$_[0]->get('a'.$i).'</span><br>';
}
$var{canVote} = $showPoll;
my ($totalResponses) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where wobjectId="
.$_[0]->get("wobjectId"));
$var{"responses.label"} = WebGUI::International::get(12,$_[0]->get("namespace"));
$var{"responses.total"} = $totalResponses;
$var{"form.start"} = WebGUI::Form::formHeader();
$var{"form.start"} .= WebGUI::Form::hidden({name=>'wid',value=>$_[0]->get("wobjectId")});
$var{"form.start"} .= WebGUI::Form::hidden({name=>'func',value=>'vote'});
$var{"form.submit"} = WebGUI::Form::submit({value=>WebGUI::International::get(11,$_[0]->get("namespace"))});
$var{"form.end"} = "</form>";
$totalResponses = 1 if ($totalResponses < 1);
for (my $i=1; $i<=20; $i++) {
if ($_[0]->get('a'.$i) =~ /\C/) {
my ($tally) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where answer='a"
.$i."' and wobjectId=".$_[0]->get("wobjectId")." group by answer");
push(@answers,{
"answer.form"=>WebGUI::Form::radio({name=>"answer",value=>"a".$i}),
"answer.text"=>$_[0]->get('a'.$i),
"answer.graphWidth"=>round($_[0]->get("graphWidth")*$tally/$totalResponses),
"answer.number"=>$i,
"answer.percent"=>round(100*$tally/$totalResponses),
"answer.total"=>($tally+0)
});
}
if ($_[0]->get("randomizeAnswers")) {
randomizeArray(\@answers);
}
foreach $answer (@answers) {
$f->raw($answer);
}
$f->raw('<br>');
$f->submit(WebGUI::International::get(11,$_[0]->get("namespace")));
$output .= $f->print;
} else {
($totalResponses) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where wobjectId=".$_[0]->get("wobjectId"));
if ($totalResponses < 1) {
$totalResponses = 1;
}
for ($i=1; $i<=20; $i++) {
if ($_[0]->get('a'.$i) =~ /\C/) {
$output .= '<span class="pollAnswer"><hr size="1">'.$_[0]->get('a'.$i).'<br></span>';
@data = WebGUI::SQL->quickArray("select count(*), answer from Poll_answer where answer='a$i' and wobjectId="
.$_[0]->get("wobjectId")." group by answer");
$output .= '<table cellpadding=0 cellspacing=0 border=0><tr><td width="'.
round($_[0]->get("graphWidth")*$data[0]/$totalResponses).'" class="pollColor"><img src="'.
$session{config}{extrasURL}.'/spacer.gif" height="1" width="1"></td><td class="pollAnswer">&nbsp;&nbsp;'.
round(100*$data[0]/$totalResponses).'% ('.($data[0]+0).')</td></tr></table>';
}
}
$output .= '<span class="pollAnswer"><hr size="1"><b>'.WebGUI::International::get(12,$_[0]->get("namespace")).'</b> '.$totalResponses.'</span>';
}
return $output;
randomizeArray(\@answers) if ($_[0]->get("randomizeAnswers"));
$var{answer_loop} = \@answers;
return $_[0]->processTemplate($_[0]->get("templateId"),\%var);
}
#-------------------------------------------------------------------
sub www_vote {
my ($hasVoted, $u);
($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where wobjectId=".$_[0]->get("wobjectId")." and ((userId=$session{user}{userId} and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))");
if ($session{form}{answer} ne "" && WebGUI::Privilege::isInGroup($_[0]->get("voteGroup"),$session{user}{userId}) && !($hasVoted)) {
my $u;
if ($session{form}{answer} ne "" && WebGUI::Privilege::isInGroup($_[0]->get("voteGroup"),$session{user}{userId}) && !($_[0]->_hasVoted())) {
WebGUI::SQL->write("insert into Poll_answer values (".$_[0]->get("wobjectId").",
'$session{form}{answer}', $session{user}{userId}, '$session{env}{REMOTE_ADDR}')");
if ($session{setting}{useKarma}) {