| |
53 |
53 |
# strings and all multiword values with one level of curly braces {} |
| |
54 |
54 |
# we need to get rid of them for almost any abstract_data_type |
| |
55 |
55 |
# except 'choice', where this is intended behaviour. Why bother |
| |
56 |
56 |
# with :multiple flag at all? Because otherwise we would lost all |
| |
57 |
57 |
# but first value for 'choice' abstract_data_type - see ad_page_contract |
| |
58 |
58 |
# doc and code for more info. |
| |
59 |
59 |
# |
| |
60 |
60 |
if { [exists_and_not_null response_to_question($question_id)] } { |
| |
61 |
61 |
if {$abstract_data_type != "choice"} { |
| |
62 |
62 |
set response_to_question($question_id) [join $response_to_question($question_id)] |
| |
63 |
63 |
} |
| |
64 |
64 |
} |
| |
65 |
65 |
|
| |
66 |
66 |
|
| |
67 |
67 |
if { $abstract_data_type == "date" } { |
| |
68 |
68 |
if [catch { set response_to_question($question_id) [validate_ad_dateentrywidget "" response_to_question.$question_id [ns_getform]]} errmsg] { |
| |
69 |
69 |
ad_complain "$errmsg: Please make sure your dates are valid." |
| |
70 |
70 |
} |
| |
71 |
71 |
} |
| |
72 |
72 |
|
| |
73 |
|
if { [exists_and_not_null response_to_question($question_id)] || ($abstract_data_type=="choice" && ![empty_string_p [lindex $response_to_question($question_id) 0]])} { |
| |
|
73 |
if { [exists_and_not_null response_to_question($question_id)] } { |
| |
74 |
74 |
set response_value [string trim $response_to_question($question_id)] |
| |
75 |
75 |
} elseif {$required_p == "t"} { |
| |
76 |
76 |
lappend questions_with_missing_responses $question_text |
| |
77 |
77 |
continue |
| |
78 |
78 |
} else { |
| |
79 |
79 |
set response_to_question($question_id) "" |
| |
80 |
80 |
set response_value "" |
| |
81 |
81 |
} |
| |
82 |
82 |
|
| |
83 |
83 |
if {![empty_string_p $response_value]} { |
| |
84 |
84 |
if { $abstract_data_type == "number" } { |
| |
85 |
85 |
if { ![regexp {^(-?[0-9]+\.)?[0-9]+$} $response_value] } { |
| |
86 |
86 |
|
| |
87 |
87 |
ad_complain "The response to \"$question_text\" must be a number. Your answer was \"$response_value\"." |
| |
88 |
88 |
continue |
| |
89 |
89 |
} |
| |
90 |
90 |
} elseif { $abstract_data_type == "integer" } { |
| |
91 |
91 |
if { ![regexp {^[0-9]+$} $response_value] } { |
| |
92 |
92 |
|
| |
93 |
93 |
ad_complain "The response to \"$question_text\" must be an integer. Your answer was \"$response_value\"." |
|
| |
152 |
152 |
set question_text [lindex $question 1] |
| |
153 |
153 |
set abstract_data_type [lindex $question 2] |
| |
154 |
154 |
set presentation_type [lindex $question 3] |
| |
155 |
155 |
|
| |
156 |
156 |
set response_value [string trim $response_to_question($question_id)] |
| |
157 |
157 |
|
| |
158 |
158 |
switch -- $abstract_data_type { |
| |
159 |
159 |
"choice" { |
| |
160 |
160 |
if { $presentation_type == "checkbox" } { |
| |
161 |
161 |
# Deal with multiple responses. |
| |
162 |
162 |
set checked_responses $response_to_question($question_id) |
| |
163 |
163 |
foreach response_value $checked_responses { |
| |
164 |
164 |
if { [empty_string_p $response_value] } { |
| |
165 |
165 |
set response_value [db_null] |
| |
166 |
166 |
} |
| |
167 |
167 |
|
| |
168 |
168 |
db_dml survey_question_response_checkbox_insert "insert into survey_question_responses (response_id, question_id, choice_id) |
| |
169 |
169 |
values (:response_id, :question_id, :response_value)" |
| |
170 |
170 |
} |
| |
171 |
171 |
} else { |
| |
172 |
|
if { [empty_string_p $response_value] } { |
| |
|
172 |
if { [empty_string_p $response_value] || [empty_string_p [lindex $response_value 0]] } { |
| |
173 |
173 |
set response_value [db_null] |
| |
174 |
174 |
} |
| |
175 |
175 |
|
| |
176 |
176 |
db_dml survey_question_response_choice_insert "insert into survey_question_responses (response_id, question_id, choice_id) |
| |
177 |
177 |
values (:response_id, :question_id, :response_value)" |
| |
178 |
178 |
} |
| |
179 |
179 |
} |
| |
180 |
180 |
"shorttext" { |
| |
181 |
181 |
db_dml survey_question_choice_shorttext_insert "insert into survey_question_responses (response_id, question_id, varchar_answer) |
| |
182 |
182 |
values (:response_id, :question_id, :response_value)" |
| |
183 |
183 |
} |
| |
184 |
184 |
"boolean" { |
| |
185 |
185 |
if { [empty_string_p $response_value] } { |
| |
186 |
186 |
set response_value [db_null] |
| |
187 |
187 |
} |
| |
188 |
188 |
|
| |
189 |
189 |
db_dml survey_question_response_boolean_insert "insert into survey_question_responses (response_id, question_id, boolean_answer) |
| |
190 |
190 |
values (:response_id, :question_id, :response_value)" |
| |
191 |
191 |
} |
| |
192 |
192 |
"integer" - |