diff --git a/lib/WebGUI/Workflow/Activity/ExpireIncompleteSurveyResponses.pm b/lib/WebGUI/Workflow/Activity/ExpireIncompleteSurveyResponses.pm new file mode 100644 index 000000000..caea2c54d --- /dev/null +++ b/lib/WebGUI/Workflow/Activity/ExpireIncompleteSurveyResponses.pm @@ -0,0 +1,152 @@ +package WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses; + + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + 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 + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Workflow::Activity'; +use WebGUI::Asset; +use WebGUI::DateTime; +use DateTime::Duration; + +=head1 NAME + +Package WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses + +=head1 DESCRIPTION + +This activity deletes the survey responses for which the allowed time has expired and emails the survey user. + +=head1 SYNOPSIS + +See WebGUI::Workflow::Activity for details on how to use any activity. + +=head1 METHODS + +These methods are available from this class: + +=cut + + +#------------------------------------------------------------------- + +=head2 definition ( session, definition ) + +See WebGUI::Workflow::Activity::defintion() for details. + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift; + my $i18n = WebGUI::International->new($session, "Workflow_Activity_ExpireIncompleteSurveyResponses"); + push(@{$definition}, { + name => $i18n->get("name"), + properties => { + deleteExpired=>{ + fieldType=>"yesNo", + defaultValue=>0, + label=>$i18n->get("Delete expired survey responses"), + hoverHelp=>$i18n->get("delete expired") + }, + emailUsers=>{ + fieldType=>"yesNo", + defaultValue=>0, + label=>$i18n->get("Email users that responses were deleted"), + hoverHelp=>$i18n->get("email users") + }, + emailTemplateId => { + fieldType => "template", + defaultValue => 'ExpireIncResptmpl00001', + namespace => "ExpireIncompleteSurveyResponses", + label => $i18n->get('Email template sent to user'), + hoverHelp => $i18n->get('email template'), + }, + from => { + fieldType=>"text", + label=>$i18n->get("from"), + defaultValue=>$session->setting->get("companyEmail"), + hoverHelp=>$i18n->get("from mouse over"), + }, + subject => { + fieldType=>"text", + label=>$i18n->get("subject", 'WebGUI'), + defaultValue=>"Expired Survey", + hoverHelp=>$i18n->get("subject mouse over"), + }, + } + }); + return $class->SUPER::definition($session,$definition); +} + + +#------------------------------------------------------------------- + +=head2 execute ( [ object ] ) + +Finds all the expired Survey Responses on the system. If delete is selected, they are removed. Then if +email is selected, the users are emailed the template. + +=cut + +sub execute { + my $self = shift; + my $session = $self->session; + + my $sql = "select r.Survey_responseId, r.username, r.userId, upd.email,upd.firstName,upd.lastName, r.startDate, s.timeLimit, ad.title, ad.url + from Survey s, Survey_response r, assetData ad, userProfileData upd + where r.isComplete = 0 and s.timeLimit > 0 and (unix_timestamp() - r.startDate) > (s.timeLimit * 1) + and r.assetId = s.assetId and s.revisionDate = (select max(revisionDate) from Survey where assetId = s.assetId) + and ad.assetId = s.assetId and ad.revisionDate = s.revisionDate and upd.userId = r.userId"; + my $refs = $self->session->db->buildArrayRefOfHashRefs($sql); + for my $ref (@{$refs}) { + if($self->get("deleteExpired") == 1){ + $self->session->db->write("delete from Survey_response where Survey_responseId = ?",[$ref->{Survey_responseId}]); + }else{#else sent to expired but not deleted + $self->session->db->write("update Survey_response set isComplete = 99 where Survey_responseId = ?",[$ref->{Survey_responseId}]); + } + if($self->get("emailUsers") == 1 && $ref->{email} =~ /\@/){ + + my $var = { + to => $ref->{email}, + from => $self->get("from"), + firstName => $ref->{firstName}, + lastName => $ref->{lastName}, + surveyTitle => $ref->{title}, + surveyUrl => $ref->{url}, + responseId => $ref->{Survey_responseId}, + deleted => $self->get("deleteExpired"), + companyName => $self->session->setting->get("companyName"), + }; + my $template = WebGUI::Asset->newByDynamicClass($self->session,$self->get('emailTemplateId')); + my $message = $template->processTemplate($var, $self->get("emailTemplateId")); + WebGUI::Macro::process($self->session,\$message); + my $mail = WebGUI::Mail::Send->create($self->session,{ + to => $ref->{email}, + subject => $self->get("subject"), + from => $self->get('from'), + }); + $mail->addHtml($message); + $mail->addFooter; + $mail->queue; + } + } + return $self->COMPLETE; +} + +1; + + diff --git a/lib/WebGUI/i18n/English/Workflow_Activity_ExpireIncompleteSurveyResponses.pm b/lib/WebGUI/i18n/English/Workflow_Activity_ExpireIncompleteSurveyResponses.pm new file mode 100644 index 000000000..fc3bb8e85 --- /dev/null +++ b/lib/WebGUI/i18n/English/Workflow_Activity_ExpireIncompleteSurveyResponses.pm @@ -0,0 +1,67 @@ +package WebGUI::i18n::English::Workflow_Activity_ExpireIncompleteSurveyResponses; +use strict; + +our $I18N = { + 'name' => { + message => q|ExpireIncompleteSurveyResponses|, + lastUpdated => 0, + }, + 'Delete expired survey responses' => { + message => q|Delete expired survey responses|, + context => q|the hover help for the delete responses field|, + lastUpdated => 0, + }, + 'delete expired' => { + message => q|When ran, every survey response which is expired will be completely removed from the database.|, + context => q|the hover help for the delete responses field|, + lastUpdated => 0, + }, + 'Email users that responses were deleted' => { + message => q|Email users that responses were deleted|, + context => q|the hover help for the email users field|, + lastUpdated => 0, + }, + 'email users' => { + message => q|When a survey response is deleted, should the user be informed of this via email?|, + context => q|the hover help for the email users field|, + lastUpdated => 0, + }, + 'email template' => { + message => q|When an email is sent updating the user that their response has been deleted, this is the text that is sent to them.|, + context => q|the hover help for the email template field|, + lastUpdated => 0, + }, + 'from' => { + message => q|Email from field|, + context => q||, + lastUpdated => 0, + }, + 'from mouse over' => { + message => q|This is the from field that will show up in the sent email.|, + context => q||, + lastUpdated => 0, + }, + 'subject' => { + message => q|Email subject field|, + context => q||, + lastUpdated => 0, + }, + 'subject mouse over' => { + message => q|This is the subject field that will show up in the sent email.|, + context => q||, + lastUpdated => 0, + }, + 'Email template sent to user' => { + message => q|The template for the email|, + context => q||, + lastUpdated => 0, + }, + 'email template' => { + message => q|This is the email template that will be sent to the user|, + context => q||, + lastUpdated => 0, + }, + +}; + +1; diff --git a/root_import_prop-style.wgpkg b/root_import_prop-style.wgpkg new file mode 100644 index 000000000..fea9f43c0 Binary files /dev/null and b/root_import_prop-style.wgpkg differ