diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 5a0d6d7d5..08db9aaee 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -7,6 +7,8 @@ - fix: Survey Asset Copy Problems - fix: EMS Add Subevent - fix: HTTPproxy + - fix: i18n reserved section name in Surveys + - fix: typo in Asset_ProjectManager i18n 6.99.3 - Someone removed the status from the submission templates. That has been diff --git a/docs/upgrades/upgrade_6.99.3-6.99.4.pl b/docs/upgrades/upgrade_6.99.3-6.99.4.pl index 78da5b87e..719f35183 100644 --- a/docs/upgrades/upgrade_6.99.3-6.99.4.pl +++ b/docs/upgrades/upgrade_6.99.3-6.99.4.pl @@ -22,8 +22,28 @@ my $session = start(); # this line required # upgrade functions go here +fixSurvey($session); + finish($session); # this line required +#------------------------------------------------- +sub fixSurvey{ + my $session = shift; + print "\tFixing Surveys.\n" unless ($quiet); + + # Add a defaultSectionId column to Survey table + $session->db->write("alter table Survey add column (defaultSectionId varchar(22) binary not null)"); + + # Set defaultSectionId for existing Surveys by finding the sectionId for the section called 'none' and update the asset + my @surveyAssets = $session->db->buildArray("select assetId from asset where className='WebGUI::Asset::Wobject::Survey'"); + foreach my $assetId (@surveyAssets) { + my $survey = WebGUI::Asset->new($session, $assetId, 'WebGUI::Asset::Wobject::Survey'); + my $i18n = WebGUI::International->new($session, 'Asset_Survey'); + my $noneLabel = $i18n->get(107); + my ($defaultSectionId) = $session->db->quickArray("select Survey_sectionId from Survey_section where assetId=? and sectionName=?", [$assetId,$noneLabel]); + $survey->update({defaultSectionId => $defaultSectionId}); + } +} ##------------------------------------------------- #sub exampleFunction { diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index 61543687e..ef6b9febf 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -39,11 +39,13 @@ sub addAnswer { sub addSection { my $self = shift; my $sectionName = shift; - $self->setCollateral("Survey_section","Survey_sectionId",{ + my $sectionId = $self->setCollateral("Survey_section","Survey_sectionId",{ Survey_id=>$self->get("Survey_id"), Survey_sectionId=>"new", sectionName=>$sectionName },1,0,"Survey_id"); + + return $sectionId; } #------------------------------------------------------------------- @@ -122,6 +124,10 @@ sub definition { fieldType => 'template', defaultValue => 'PBtmpl0000000000000064' }, + defaultSectionId => { + fieldType => 'text', + defaultValue => 'undef' + }, } }); return $class->SUPER::definition($session, $definition); @@ -580,9 +586,11 @@ sub prepareView { sub processPropertiesFromFormPost { my $self = shift; $self->SUPER::processPropertiesFromFormPost; - my $i18n = WebGUI::International->new($self->session); + my $i18n = WebGUI::International->new($self->session,"Asset_Survey"); if ($self->session->form->process("assetId") eq "new") { - $self->addSection($i18n->get(107)); + my $defaultSectionId = $self->addSection($i18n->get(107)); + $self->update({'defaultSectionId' => $defaultSectionId}); + $self->session->errorHandler->warn($defaultSectionId); } } @@ -740,15 +748,13 @@ sub www_deleteSectionConfirm { my $self = shift; return $self->session->privilege->insufficient() unless ($self->canEdit); my $i18n = WebGUI::International->new($self->session,'Asset_Survey'); - my $none = $i18n->get(107); - my ($sectionName) = $self->session->db->quickArray("select sectionName from Survey_section where Survey_sectionId=" - .$self->session->db->quote($self->session->form->process("sid"))); - if ($sectionName =~ /$none/) { + my $section_id = $self->session->form->get("sid"); + if ($section_id eq $self->get("defaultSectionId")) { return $self->session->privilege->vitalComponent(); } - $self->session->db->write("delete from Survey_section where Survey_sectionId=".$self->session->db->quote($self->session->form->process("sid"))); - $self->deleteCollateral("Survey_section","Survey_sectionId",$self->session->form->process("sid")); + $self->session->db->write("delete from Survey_section where Survey_sectionId=?",[$section_id]); + $self->deleteCollateral("Survey_section","Survey_sectionId",$section_id); $self->reorderCollateral("Survey_section","Survey_sectionId","Survey_id"); return ""; } @@ -1077,11 +1083,10 @@ sub www_editSection { my $self = shift; my ($f, $section, $sectionName); my $i18n = WebGUI::International->new($self->session, 'Asset_Survey'); - my $none = $i18n->get(107); return $self->session->privilege->insufficient() unless ($self->canEdit); $section = $self->getCollateral("Survey_section","Survey_sectionId",$self->session->form->process("sid")); - if ($section->{sectionName} =~ /$none/) { + if ($section->{Survey_sectionId} eq $self->get("defaultSectionId") && $section->{Survey_sectionId} ne "") { return $self->session->privilege->vitalComponent; } diff --git a/lib/WebGUI/i18n/English/Asset_ProjectManager.pm b/lib/WebGUI/i18n/English/Asset_ProjectManager.pm index 7ad647f28..beecca97c 100644 --- a/lib/WebGUI/i18n/English/Asset_ProjectManager.pm +++ b/lib/WebGUI/i18n/English/Asset_ProjectManager.pm @@ -208,7 +208,7 @@ our $I18N = { 'hours label abbrev' => { message => q|hrs|, - lastUpdated => 0 + lastUpdated => 0, context => q|Abbreviation for hours|, },