diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index 2e3257394..b49148932 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -1348,6 +1348,7 @@ sub prepareShowSurveyTemplate { my %slider = ( 'Slider', 1, 'Dual Slider - Range', 1, 'Multi Slider - Allocate', 1 ); my %dateType = ( 'Date', 1, 'Date Range', 1 ); my %dateShort = ( 'Year Month', 1 ); + my %country = ( 'Country', 1 ); my %fileUpload = ( 'File Upload', 1 ); my %hidden = ( 'Hidden', 1 ); @@ -1385,6 +1386,14 @@ sub prepareShowSurveyTemplate { ]; } } + elsif ( $country{ $q->{questionType} } ) { + $q->{country} = 1; + use WebGUI::Form::Country; + my @countries = map +{ 'country' => $_ }, WebGUI::Form::Country::getCountries(); + foreach my $a(@{$q->{answers}}){ + $a->{countries} = [ {'country' => ''}, @countries ]; + } + } elsif ( $slider{ $q->{questionType} } ) { $q->{slider} = 1; if ( $q->{questionType} eq 'Dual Slider - Range' ) { diff --git a/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm index 3a768f0ad..a6bf06a30 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm @@ -527,48 +527,54 @@ sub recordResponses { my $submittedAnswerComment = $submittedResponses->{ $answer->{id} . 'comment' }; my $submittedAnswerVerbatim = $submittedResponses->{ $answer->{id} . 'verbatim' }; - # Proceed if we're satisfied that the submitted answer response is valid.. - if ( defined $submittedAnswerResponse && $submittedAnswerResponse =~ /\S/ ) { - - #Validate answers met question criteria - if($question->{questionType} eq 'Number'){ - if($answer->{max} =~ /\d/ and $submittedAnswerResponse > $answer->{max}){ - next; - }elsif($answer->{min} =~ /\d/ and $submittedAnswerResponse < $answer->{min}){ - next; - }elsif($answer->{step} =~ /\d/ and $submittedAnswerResponse % $answer->{step} != 0){ - next; - } - } + # Server-side Validation and storing of extra data for special q types goes here - $aAnswered = 1; - - # Now, decide what to record. For multi-choice questions, use recordedAnswer. - # Otherwise, we use the (raw) submitted response (e.g. text input, date input etc..) - $self->responses->{ $answer->{id} }->{value} - = $knownTypes{ $question->{questionType} } - ? $submittedAnswerResponse - : $answer->{recordedAnswer}; - - $self->responses->{ $answer->{id} }->{verbatim} = $answer->{verbatim} ? $submittedAnswerVerbatim : undef; - $self->responses->{ $answer->{id} }->{time} = time; - $self->responses->{ $answer->{id} }->{comment} = $submittedAnswerComment; - - # Handle terminal Answers.. - if ( $answer->{terminal} ) { - $terminal = 1; - $terminalUrl = $answer->{terminalUrl}; + if($question->{questionType} eq 'Number'){ + if($answer->{max} =~ /\d/ and $submittedAnswerResponse > $answer->{max}){ + next; + }elsif($answer->{min} =~ /\d/ and $submittedAnswerResponse < $answer->{min}){ + next; + }elsif($answer->{step} =~ /\d/ and $submittedAnswerResponse % $answer->{step} != 0){ + next; } - - # ..and also gotos.. - elsif ( $answer->{goto} =~ /\w/ ) { - $goto = $answer->{goto}; + } elsif ($question->{questionType} eq 'Year Month'){ + # store year and month as "YYYY Month" + $submittedAnswerResponse = $submittedResponses->{ $answer->{id} . '-year' } . " " . $submittedResponses->{ $answer->{id} . '-month' }; + } else { + if ( !defined $submittedAnswerResponse || $submittedAnswerResponse !~ /\S/ ) { + $self->session->log->debug("Skipping invalid submitted answer response: $submittedAnswerResponse"); + next; } + } + + # If we reach here, answer validated ok + $aAnswered = 1; - # .. and also gotoExpressions.. - elsif ( $answer->{gotoExpression} =~ /\w/ ) { - $answerExpression = $answer->{gotoExpression}; - } + # Now, decide what to record. For multi-choice questions, use recordedAnswer. + # Otherwise, we use the (raw) submitted response (e.g. text input, date input etc..) + $self->responses->{ $answer->{id} }->{value} + = $knownTypes{ $question->{questionType} } + ? $submittedAnswerResponse + : $answer->{recordedAnswer}; + + $self->responses->{ $answer->{id} }->{verbatim} = $answer->{verbatim} ? $submittedAnswerVerbatim : undef; + $self->responses->{ $answer->{id} }->{time} = time; + $self->responses->{ $answer->{id} }->{comment} = $submittedAnswerComment; + + # Handle terminal Answers.. + if ( $answer->{terminal} ) { + $terminal = 1; + $terminalUrl = $answer->{terminalUrl}; + } + + # ..and also gotos.. + elsif ( $answer->{goto} =~ /\w/ ) { + $goto = $answer->{goto}; + } + + # .. and also gotoExpressions.. + elsif ( $answer->{gotoExpression} =~ /\w/ ) { + $answerExpression = $answer->{gotoExpression}; } } diff --git a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm index e9e999df3..a5d446763 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm @@ -57,10 +57,6 @@ use Clone qw/clone/; # The maximum value of questionsPerPage is currently hardcoded here my $MAX_QUESTIONS_PER_PAGE = 20; -#sub specialQuestionTypes { -# return @SPECIAL_QUESTION_TYPES; -#} - =head2 new ( $session, json ) Object constructor. @@ -126,6 +122,7 @@ sub loadTypes { 'Date', 'Date Range', 'Year Month', + 'Country', 'Hidden', ) if(! defined $self->{specialQuestionTypes}); if(! defined $self->{multipleChoiceTypes}){ diff --git a/lib/WebGUI/Form/Country.pm b/lib/WebGUI/Form/Country.pm index 8e1761d7e..420f2c604 100644 --- a/lib/WebGUI/Form/Country.pm +++ b/lib/WebGUI/Form/Country.pm @@ -86,6 +86,140 @@ sub definition { #------------------------------------------------------------------- +=head2 getCountries + +Returns the list of Countries + +=cut + +sub getCountries { + return ( + 'Afghanistan', 'Albania', + 'Algeria', 'American Samoa', + 'Andorra', 'Anguilla', + 'Antarctica', 'Antigua And Barbuda', + 'Argentina', 'Armenia', + 'Aruba', 'Australia', + 'Austria', 'Azerbaijan', + 'Bahamas', 'Bahrain', + 'Bangladesh', 'Barbados', + 'Belarus', 'Belgium', + 'Belize', 'Benin', + 'Bermuda', 'Bhutan', + 'Bolivia', 'Bosnia and Herzegovina', + 'Botswana', 'Bouvet Island', + 'Brazil', 'British Indian Ocean Territory', + 'Brunei Darussalam', 'Bulgaria', + 'Burkina Faso', 'Burundi', + 'Cambodia', 'Cameroon', + 'Canada', 'Cape Verde', + 'Cayman Islands', 'Central African Republic', + 'Chad', 'Chile', + 'China', 'Christmas Island', + 'Cocos (Keeling) Islands', 'Colombia', + 'Comoros', 'Congo', + 'Congo, the Democratic Republic of the', 'Cook Islands', + 'Costa Rica', 'Cote d\'Ivoire', + 'Croatia', 'Cyprus', + 'Czech Republic', 'Denmark', + 'Djibouti', 'Dominica', + 'Dominican Republic', 'East Timor', + 'Ecuador', 'Egypt', + 'El Salvador', 'England', + 'Equatorial Guinea', 'Eritrea', + 'Espana', 'Estonia', + 'Ethiopia', 'Falkland Islands', + 'Faroe Islands', 'Fiji', + 'Finland', 'France', + 'French Guiana', 'French Polynesia', + 'French Southern Territories', 'Gabon', + 'Gambia', 'Georgia', + 'Germany', 'Ghana', + 'Gibraltar', 'Great Britain', + 'Greece', 'Greenland', + 'Grenada', 'Guadeloupe', + 'Guam', 'Guatemala', + 'Guinea', 'Guinea-Bissau', + 'Guyana', 'Haiti', + 'Heard and Mc Donald Islands', 'Honduras', + 'Hong Kong', 'Hungary', + 'Iceland', 'India', + 'Indonesia', 'Ireland', + 'Israel', 'Italy', + 'Jamaica', 'Japan', + 'Jordan', 'Kazakhstan', + 'Kenya', 'Kiribati', + 'Korea (South)', 'Korea, Republic of', + 'Kuwait', 'Kyrgyzstan', + 'Lao People\'s Democratic Republic', 'Latvia', + 'Lebanon', 'Lesotho', + 'Liberia', 'Libya', + 'Liechtenstein', 'Lithuania', + 'Luxembourg', 'Macau', + 'Macedonia', 'Madagascar', + 'Malawi', 'Malaysia', + 'Maldives', 'Mali', + 'Malta', 'Marshall Islands', + 'Martinique', 'Mauritania', + 'Mauritius', 'Mayotte', + 'Mexico', 'Micronesia, Federated States of', + 'Moldova, Republic of', 'Monaco', + 'Mongolia', 'Montenegro', + 'Montserrat', 'Morocco', + 'Mozambique', 'Myanmar', + 'Namibia', 'Nauru', + 'Nepal', 'Netherlands', + 'Netherlands Antilles', 'New Caledonia', + 'New Zealand', 'Nicaragua', + 'Niger', 'Nigeria', + 'Niue', 'Norfolk Island', + 'Northern Ireland', 'Northern Mariana Islands', + 'Norway', 'Oman', + 'Pakistan', 'Palau', + 'Panama', 'Papua New Guinea', + 'Paraguay', 'Peru', + 'Philippines', 'Pitcairn', + 'Poland', 'Portugal', + 'Puerto Rico', 'Qatar', + 'Reunion', 'Romania', + 'Russia', 'Russian Federation', + 'Rwanda', 'Saint Kitts and Nevis', + 'Saint Lucia', 'Saint Vincent and the Grenadines', + 'Samoa (Independent)', 'San Marino', + 'Sao Tome and Principe', 'Saudi Arabia', + 'Scotland', 'Senegal', + 'Serbia', 'Seychelles', + 'Sierra Leone', 'Singapore', + 'Slovakia', 'Slovenia', + 'Solomon Islands', 'Somalia', + 'South Africa', 'South Georgia and the South Sandwich Islands', + 'South Korea', 'Spain', + 'Sri Lanka', 'St. Helena', + 'St. Pierre and Miquelon', 'Suriname', + 'Svalbard and Jan Mayen Islands', 'Swaziland', + 'Sweden', 'Switzerland', + 'Taiwan', 'Tajikistan', + 'Tanzania', 'Thailand', + 'Togo', 'Tokelau', + 'Tonga', 'Trinidad', + 'Trinidad and Tobago', 'Tunisia', + 'Turkey', 'Turkmenistan', + 'Turks and Caicos Islands', 'Tuvalu', + 'Uganda', 'Ukraine', + 'United Arab Emirates', 'United Kingdom', + 'United States', 'United States Minor Outlying Islands', + 'Uruguay', 'Uzbekistan', + 'Vanuatu', 'Vatican City State (Holy See)', + 'Venezuela', 'Viet Nam', + 'Virgin Islands (British)', 'Virgin Islands (U.S.)', + 'Wales', 'Wallis and Futuna Islands', + 'Western Sahara', 'Yemen', + 'Zambia', 'Zimbabwe' + ); +} + +#------------------------------------------------------------------- + =head2 getName ( session ) Returns the human readable name of this control. @@ -119,253 +253,10 @@ Renders a country picker control. sub toHtml { my $self = shift; -my %countries; -tie %countries, 'Tie::IxHash'; -%countries = ( -'Afghanistan' => 'Afghanistan', -'Albania' => 'Albania', -'Algeria' => 'Algeria', -'American Samoa' => 'American Samoa', -'Andorra' => 'Andorra', -'Anguilla' => 'Anguilla', -'Antarctica' => 'Antarctica', -'Antigua And Barbuda' => 'Antigua And Barbuda', -'Argentina' => 'Argentina', -'Armenia' => 'Armenia', -'Aruba' => 'Aruba', -'Australia' => 'Australia', -'Austria' => 'Austria', -'Azerbaijan' => 'Azerbaijan', -'Bahamas' => 'Bahamas', -'Bahrain' => 'Bahrain', -'Bangladesh' => 'Bangladesh', -'Barbados' => 'Barbados', -'Belarus' => 'Belarus', -'Belgium' => 'Belgium', -'Belize' => 'Belize', -'Benin' => 'Benin', -'Bermuda' => 'Bermuda', -'Bhutan' => 'Bhutan', -'Bolivia' => 'Bolivia', -'Bosnia and Herzegovina' => 'Bosnia and Herzegovina', -'Botswana' => 'Botswana', -'Bouvet Island' => 'Bouvet Island', -'Brazil' => 'Brazil', -'British Indian Ocean Territory' => 'British Indian Ocean Territory', -'Brunei Darussalam' => 'Brunei Darussalam', -'Bulgaria' => 'Bulgaria', -'Burkina Faso' => 'Burkina Faso', -'Burundi' => 'Burundi', -'Cambodia' => 'Cambodia', -'Cameroon' => 'Cameroon', -'Canada' => 'Canada', -'Cape Verde' => 'Cape Verde', -'Cayman Islands' => 'Cayman Islands', -'Central African Republic' => 'Central African Republic', -'Chad' => 'Chad', -'Chile' => 'Chile', -'China' => 'China', -'Christmas Island' => 'Christmas Island', -'Cocos (Keeling) Islands' => 'Cocos (Keeling) Islands', -'Colombia' => 'Colombia', -'Comoros' => 'Comoros', -'Congo' => 'Congo', -'Congo, the Democratic Republic of the' => 'Congo, the Democratic Republic of the', -'Cook Islands' => 'Cook Islands', -'Costa Rica' => 'Costa Rica', -'Cote d\'Ivoire' => 'Cote d\'Ivoire', -'Croatia' => 'Croatia', -'Cyprus' => 'Cyprus', -'Czech Republic' => 'Czech Republic', -'Denmark' => 'Denmark', -'Djibouti' => 'Djibouti', -'Dominica' => 'Dominica', -'Dominican Republic' => 'Dominican Republic', -'East Timor' => 'East Timor', -'Ecuador' => 'Ecuador', -'Egypt' => 'Egypt', -'El Salvador' => 'El Salvador', -'England' => 'England', -'Equatorial Guinea' => 'Equatorial Guinea', -'Eritrea' => 'Eritrea', -'Espana' => 'Espana', -'Estonia' => 'Estonia', -'Ethiopia' => 'Ethiopia', -'Falkland Islands' => 'Falkland Islands', -'Faroe Islands' => 'Faroe Islands', -'Fiji' => 'Fiji', -'Finland' => 'Finland', -'France' => 'France', -'French Guiana' => 'French Guiana', -'French Polynesia' => 'French Polynesia', -'French Southern Territories' => 'French Southern Territories', -'Gabon' => 'Gabon', -'Gambia' => 'Gambia', -'Georgia' => 'Georgia', -'Germany' => 'Germany', -'Ghana' => 'Ghana', -'Gibraltar' => 'Gibraltar', -'Great Britain' => 'Great Britain', -'Greece' => 'Greece', -'Greenland' => 'Greenland', -'Grenada' => 'Grenada', -'Guadeloupe' => 'Guadeloupe', -'Guam' => 'Guam', -'Guatemala' => 'Guatemala', -'Guinea' => 'Guinea', -'Guinea-Bissau' => 'Guinea-Bissau', -'Guyana' => 'Guyana', -'Haiti' => 'Haiti', -'Heard and Mc Donald Islands' => 'Heard and Mc Donald Islands', -'Honduras' => 'Honduras', -'Hong Kong' => 'Hong Kong', -'Hungary' => 'Hungary', -'Iceland' => 'Iceland', -'India' => 'India', -'Indonesia' => 'Indonesia', -'Ireland' => 'Ireland', -'Israel' => 'Israel', -'Italy' => 'Italy', -'Jamaica' => 'Jamaica', -'Japan' => 'Japan', -'Jordan' => 'Jordan', -'Kazakhstan' => 'Kazakhstan', -'Kenya' => 'Kenya', -'Kiribati' => 'Kiribati', -'Korea, Republic of' => 'Korea, Republic of', -'Korea (South)' => 'Korea (South)', -'Kuwait' => 'Kuwait', -'Kyrgyzstan' => 'Kyrgyzstan', -"Lao People's Democratic Republic" => "Lao People's Democratic Republic", -'Latvia' => 'Latvia', -'Lebanon' => 'Lebanon', -'Lesotho' => 'Lesotho', -'Liberia' => 'Liberia', -'Libya' => 'Libya', -'Liechtenstein' => 'Liechtenstein', -'Lithuania' => 'Lithuania', -'Luxembourg' => 'Luxembourg', -'Macau' => 'Macau', -'Macedonia' => 'Macedonia', -'Madagascar' => 'Madagascar', -'Malawi' => 'Malawi', -'Malaysia' => 'Malaysia', -'Maldives' => 'Maldives', -'Mali' => 'Mali', -'Malta' => 'Malta', -'Marshall Islands' => 'Marshall Islands', -'Martinique' => 'Martinique', -'Mauritania' => 'Mauritania', -'Mauritius' => 'Mauritius', -'Mayotte' => 'Mayotte', -'Mexico' => 'Mexico', -'Micronesia, Federated States of' => 'Micronesia, Federated States of', -'Moldova, Republic of' => 'Moldova, Republic of', -'Monaco' => 'Monaco', -'Mongolia' => 'Mongolia', -'Montenegro' => 'Montenegro', -'Montserrat' => 'Montserrat', -'Morocco' => 'Morocco', -'Mozambique' => 'Mozambique', -'Myanmar' => 'Myanmar', -'Namibia' => 'Namibia', -'Nauru' => 'Nauru', -'Nepal' => 'Nepal', -'Netherlands' => 'Netherlands', -'Netherlands Antilles' => 'Netherlands Antilles', -'New Caledonia' => 'New Caledonia', -'New Zealand' => 'New Zealand', -'Nicaragua' => 'Nicaragua', -'Niger' => 'Niger', -'Nigeria' => 'Nigeria', -'Niue' => 'Niue', -'Norfolk Island' => 'Norfolk Island', -'Northern Ireland' => 'Northern Ireland', -'Northern Mariana Islands' => 'Northern Mariana Islands', -'Norway' => 'Norway', -'Oman' => 'Oman', -'Pakistan' => 'Pakistan', -'Palau' => 'Palau', -'Panama' => 'Panama', -'Papua New Guinea' => 'Papua New Guinea', -'Paraguay' => 'Paraguay', -'Peru' => 'Peru', -'Philippines' => 'Philippines', -'Pitcairn' => 'Pitcairn', -'Poland' => 'Poland', -'Portugal' => 'Portugal', -'Puerto Rico' => 'Puerto Rico', -'Qatar' => 'Qatar', -'Reunion' => 'Reunion', -'Romania' => 'Romania', -'Russia' => 'Russia', -'Russian Federation' => 'Russian Federation', -'Rwanda' => 'Rwanda', -'Saint Kitts and Nevis' => 'Saint Kitts and Nevis', -'Saint Lucia' => 'Saint Lucia', -'Saint Vincent and the Grenadines' => 'Saint Vincent and the Grenadines', -'Samoa (Independent)' => 'Samoa (Independent)', -'San Marino' => 'San Marino', -'Sao Tome and Principe' => 'Sao Tome and Principe', -'Saudi Arabia' => 'Saudi Arabia', -'Scotland' => 'Scotland', -'Senegal' => 'Senegal', -'Serbia' => 'Serbia', -'Seychelles' => 'Seychelles', -'Sierra Leone' => 'Sierra Leone', -'Singapore' => 'Singapore', -'Slovakia' => 'Slovakia', -'Slovenia' => 'Slovenia', -'Solomon Islands' => 'Solomon Islands', -'Somalia' => 'Somalia', -'South Africa' => 'South Africa', -'South Georgia and the South Sandwich Islands' => 'South Georgia and the South Sandwich Islands', -'South Korea' => 'South Korea', -'Spain' => 'Spain', -'Sri Lanka' => 'Sri Lanka', -'St. Helena' => 'St. Helena', -'St. Pierre and Miquelon' => 'St. Pierre and Miquelon', -'Suriname' => 'Suriname', -'Svalbard and Jan Mayen Islands' => 'Svalbard and Jan Mayen Islands', -'Swaziland' => 'Swaziland', -'Sweden' => 'Sweden', -'Switzerland' => 'Switzerland', -'Taiwan' => 'Taiwan', -'Tajikistan' => 'Tajikistan', -'Tanzania' => 'Tanzania', -'Thailand' => 'Thailand', -'Togo' => 'Togo', -'Tokelau' => 'Tokelau', -'Tonga' => 'Tonga', -'Trinidad' => 'Trinidad', -'Trinidad and Tobago' => 'Trinidad and Tobago', -'Tunisia' => 'Tunisia', -'Turkey' => 'Turkey', -'Turkmenistan' => 'Turkmenistan', -'Turks and Caicos Islands' => 'Turks and Caicos Islands', -'Tuvalu' => 'Tuvalu', -'Uganda' => 'Uganda', -'Ukraine' => 'Ukraine', -'United Arab Emirates' => 'United Arab Emirates', -'United Kingdom' => 'United Kingdom', -'United States' => 'United States', -'United States Minor Outlying Islands' => 'United States Minor Outlying Islands', -'Uruguay' => 'Uruguay', -'Uzbekistan' => 'Uzbekistan', -'Vanuatu' => 'Vanuatu', -'Vatican City State (Holy See)' => 'Vatican City State (Holy See)', -'Venezuela' => 'Venezuela', -'Viet Nam' => 'Viet Nam', -'Virgin Islands (British)' => 'Virgin Islands (British)', -'Virgin Islands (U.S.)' => 'Virgin Islands (U.S.)', -'Wales' => 'Wales', -'Wallis and Futuna Islands' => 'Wallis and Futuna Islands', -'Western Sahara' => 'Western Sahara', -'Yemen' => 'Yemen', -'Zambia' => 'Zambia', -'Zimbabwe' => 'Zimbabwe' - ); + my %countries; + tie %countries, 'Tie::IxHash'; + %countries = map {$_ => $_} getCountries(); $self->set("options", \%countries); return $self->SUPER::toHtml(); } diff --git a/www/extras/wobject/Survey/administersurvey.js b/www/extras/wobject/Survey/administersurvey.js index 8475d7c2d..07225e7f7 100644 --- a/www/extras/wobject/Survey/administersurvey.js +++ b/www/extras/wobject/Survey/administersurvey.js @@ -30,6 +30,9 @@ if (typeof Survey === "undefined") { var DATE_SHORT = { 'Year Month': 1 }; + var COUNTRY = { + 'Country': 1 + }; var DATE_TYPES = { 'Date': 1, 'Date Range': 1 @@ -643,6 +646,17 @@ if (typeof Survey === "undefined") { continue; } + if (COUNTRY[q.questionType]) { + for (var k = 0; k < q.answers.length; k++) { + var ans = q.answers[k]; + if (toValidate[q.id]) { + toValidate[q.id].type = q.questionType; + toValidate[q.id].answers[ans.id] = 1; + } + } + continue; + } + if (DATE_TYPES[q.questionType]) { for (var k = 0; k < q.answers.length; k++) { var ans = q.answers[k];