Added anonymous response option to survey

This commit is contained in:
Andy Grundman 2003-07-24 18:17:35 +00:00
parent 1ee90115c6
commit 4c002c36db
3 changed files with 35 additions and 22 deletions

View file

@ -2,8 +2,7 @@
- Rewrote the discussion system and added many new features in the process.
- Fixed a bug in the collateralImport.pl script.
- Added external database group privileges. (Thanks to Andy Grundman.)
- Added anonymous response option to Survey. (Thanks to Andy Grundman.)

View file

@ -87,7 +87,9 @@ alter table groups add column databaseLinkId int not null default 0;
alter table groups add column dbCacheTimeout int not null default 3600;
alter table groups add column dbQuery text;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (81,1,'Survey','Anonymous responses?',1059069492);
delete from international where languageId=1 and namespace='Survey' and internationalId=4;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (4,1,'Survey','Surveys allow you to gather information from your users. In the case of WebGUI surveys, you can also use them to test your user\'s knowledge.\r\n<p/>\r\n\r\n<b>Question Order</b><br/>\r\nThe order the questions will be asked. Sequential displays the questions in the order you create them. Random displays the questions randomly. Response driven displays the questions in order based on the responses of the users.\r\n<p/>\r\n\r\n<b>Mode</b><br/>\r\nBy default the Survey is in survey mode. This allows it to ask questions of your users. However, if you switch to Quiz mode, you can have a self-correcting test of your user\'s knowledge.\r\n<p/>\r\n\r\n<b>Anonymous responses?</b><br/>\r\nSelect whether or not the survey will record and display information that can identify a user and their responses. If left at the default value of "No", the survey will record the user\'s IP address as well as their WebGUI User ID and Username if logged in. This info will then be available in the survey\'s reports. If set to "Yes", these three fields will contain scrambled data that can not be traced to a particular user.\r\n<p/>\r\n\r\n<b>Who can take the survey?</b><br/>\r\nWhich users can participate in the survey?\r\n<p/>\r\n\r\n\r\n<b>Who can view reports?</b><br/>\r\nWho can view the results of the survey?\r\n<p/>\r\n\r\n\r\n<b>What next?</b><br/>\r\nIf you leave this set at its default, then you will add a question directly after adding the survey.\r\n<p/>\r\n',1059069492);
alter table Survey add column anonymous char(1) not null default 0;
alter table Survey_response change userId userId varchar(11);

View file

@ -22,6 +22,7 @@ use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Utility;
use WebGUI::Wobject;
use Digest::MD5 qw(md5_hex);
our @ISA = qw(WebGUI::Wobject);
@ -126,7 +127,10 @@ sub new {
},
mode=>{
defaultValue=>"survey"
}
},
anonymous=>{
defaultValue=>0
},
}
);
bless $self, $class;
@ -194,7 +198,7 @@ sub www_deleteResponses {
#-------------------------------------------------------------------
sub www_deleteResponsesConfirm {
return "" unless (WebGUI::Privilege::isInGroup($_[0]->get("groupToViewReports")));
WebGUI::SQL->write("delete from Survey_response where ((userId=$session{form}{uid}
WebGUI::SQL->write("delete from Survey_response where ((userId='$session{form}{uid}'
and userId<>1) or (userId=1 and ipAddress='$session{form}{ip}')) and Survey_id=".$_[0]->get("Survey_id"));
return $_[0]->www_viewGradebook;
}
@ -240,6 +244,11 @@ sub www_edit {
-label=>WebGUI::International::get(11,$_[0]->get("namespace")),
-value=>[$_[0]->getValue("mode")]
);
$properties->yesNo(
-name=>"anonymous",
-value=>$_[0]->getValue("anonymous"),
-label=>WebGUI::International::get(81,$_[0]->get("namespace"))
);
$privileges->group(
-name=>"groupToTakeSurvey",
-value=>[$_[0]->getValue("groupToTakeSurvey")],
@ -550,8 +559,9 @@ sub www_moveQuestionUp {
sub www_respond {
return "" unless (WebGUI::Privilege::isInGroup($_[0]->get("groupToTakeSurvey")));
return "" unless ($session{form}{Survey_answerId} ne "");
my $userId = ($_[0]->get("anonymous")) ? substr(md5_hex($session{user}{userId}),0,8) : $session{user}{userId};
my ($previousResponse) = WebGUI::SQL->quickArray("select count(*) from Survey_response
where Survey_answerId=$session{form}{Survey_answerId} and ((userId=".$session{user}{userId}." and userId<>1)
where Survey_answerId=$session{form}{Survey_answerId} and ((userId='".$userId."' and userId<>1)
or (userId=1 and ipAddress='".$session{form}{ip}."'))");
return "" if ($previousResponse);
my $answer = $_[0]->getCollateral("Survey_answer","Survey_answerId",$session{form}{Survey_answerId});
@ -563,17 +573,19 @@ sub www_respond {
Survey_id=>$answer->{Survey_id},
comment=>$session{form}{comment},
response=>$response,
userId=>$session{user}{userId},
username=>$session{user}{username},
userId=>($_[0]->get("anonymous")) ? substr(md5_hex($session{user}{userId}),0,8) : $session{user}{userId},
username=>($_[0]->get("anonymous")) ? substr(md5_hex($session{user}{username}),0,8) : $session{user}{username},
dateOfResponse=>time(),
ipAddress=>$session{env}{REMOTE_ADDR}
ipAddress=>($_[0]->get("anonymous")) ? substr(md5_hex($session{env}{REMOTE_ADDR}),0,8) : $session{env}{REMOTE_ADDR}
},0,0);
return "";
}
#-------------------------------------------------------------------
sub www_view {
my ($output, $f, $previous, $questionOrder, $previousResponse, $question);
my ($output, $f, $previous, $questionOrder, $previousResponse, $question, $ipAddress, $userId);
$ipAddress = ($_[0]->get("anonymous")) ? substr(md5_hex($session{env}{REMOTE_ADDR}),0,8) : $session{env}{REMOTE_ADDR};
$userId = ($_[0]->get("anonymous")) ? substr(md5_hex($session{user}{userId}),0,8) : $session{user}{userId};
$output = $_[0]->displayTitle;
$output .= $_[0]->description;
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToViewReports"))) {
@ -583,14 +595,14 @@ sub www_view {
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToTakeSurvey"))) {
$previousResponse = WebGUI::SQL->quickHashRef("select Survey_questionId, Survey_answerId from Survey_response
where Survey_id=".$_[0]->get("Survey_id")
." and ((userId=$session{user}{userId} and userId<>1) or (userId=1 and
ipAddress='$session{env}{REMOTE_ADDR}')) order by dateOfResponse desc");
." and ((userId='$userId' and userId<>1) or (userId=1 and
ipAddress='$ipAddress')) order by dateOfResponse desc");
$questionOrder = $_[0]->get("questionOrder");
if ($previousResponse->{Survey_questionId}) {
if ($questionOrder eq "random") {
my @questions = WebGUI::SQL->buildArray("select Survey_questionId from Survey_response
where Survey_id=".$_[0]->get("Survey_id")." and ((userId=$session{user}{userId}
and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))");
where Survey_id=".$_[0]->get("Survey_id")." and ((userId='$userId'
and userId<>1) or (userId=1 and ipAddress='$ipAddress'))");
if ($#questions >= 0) {
@questions = WebGUI::SQL->buildArray("select Survey_questionId from Survey_question
where Survey_id=".$_[0]->get("Survey_id")
@ -673,8 +685,8 @@ sub www_view {
where Survey_id=".$_[0]->get("Survey_id"));
my ($correctCount) = WebGUI::SQL->quickArray("select count(*) from Survey_response a,
Survey_answer b where a.Survey_id=".$_[0]->get("Survey_id")."
and ((userId=$session{user}{userId} and userId<>1) or
(userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))
and ((userId='$userId' and userId<>1) or
(userId=1 and ipAddress='$ipAddress'))
and a.Survey_answerId=b.Survey_answerId and b.isCorrect=1");
if ($questionCount > 0) {
$output .= "<h1>".WebGUI::International::get(52,$_[0]->get("namespace")).": "
@ -734,7 +746,7 @@ sub www_viewGradebook {
$output .= '</a></td>';
my ($correctCount) = WebGUI::SQL->quickArray("select count(*) from Survey_response a,
Survey_answer b where a.Survey_id=".$_[0]->get("Survey_id")."
and ((userId=".$user->{userId}." and userId<>1) or
and ((userId='".$user->{userId}."' and userId<>1) or
(userId=1 and ipAddress='".$user->{ipAddress}."'))
and a.Survey_answerId=b.Survey_answerId and b.isCorrect=1");
$output .= '<td>'.$correctCount.'/'.$questionCount.'</td>';
@ -755,10 +767,10 @@ sub www_viewIndividualSurvey {
$output .= '<a href="'.WebGUI::URL::page('func=deleteResponses&wid='.$_[0]->get("wobjectId")
.'&uid='.$session{form}{uid}.'&ip='.$session{form}{ip}).'">'.WebGUI::International::get(69,$_[0]->get("namespace")).'</a><p/>';
my ($start) = WebGUI::SQL->quickArray("select min(dateOfResponse) from Survey_response
where Survey_id=".$_[0]->get("Survey_id")." and ((userId=".$session{form}{uid}." and userId<>1)
where Survey_id=".$_[0]->get("Survey_id")." and ((userId='".$session{form}{uid}."' and userId<>1)
or (userId=1 and ipAddress='".$session{form}{ip}."'))");
my ($end) = WebGUI::SQL->quickArray("select max(dateOfResponse) from Survey_response
where Survey_id=".$_[0]->get("Survey_id")." and ((userId=".$session{form}{uid}." and userId<>1)
where Survey_id=".$_[0]->get("Survey_id")." and ((userId='".$session{form}{uid}."' and userId<>1)
or (userId=1 and ipAddress='".$session{form}{ip}."'))");
$output .= '<b>'.WebGUI::International::get(76,$_[0]->get("namespace")).':</b> '.epochToHuman($start).'<br/>';
$output .= '<b>'.WebGUI::International::get(77,$_[0]->get("namespace")).':</b> '.epochToHuman($end).'<br/>';
@ -788,7 +800,7 @@ sub www_viewIndividualSurvey {
.WebGUI::International::get(66,$_[0]->get("namespace")).'</td>';
$rdata = WebGUI::SQL->quickHashRef("select Survey_answerId,response,comment from Survey_response
where Survey_questionId=".$qdata->{Survey_questionId}."
and ((userId=".$session{form}{uid}." and userId<>1)
and ((userId='".$session{form}{uid}."' and userId<>1)
or (userId=1 and ipAddress='".$session{form}{ip}."'))");
$output .= '<td width="75%">'.$rdata->{response}.'</td></tr>';
if ($rdata->{comment} ne "") {