Index: openacs-4/contrib/packages/survey/www/process-response.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/process-response.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/contrib/packages/survey/www/process-response.tcl 11 Mar 2004 15:24:17 -0000 1.5 +++ openacs-4/contrib/packages/survey/www/process-response.tcl 12 Mar 2004 07:07:03 -0000 1.6 @@ -71,7 +71,12 @@ if { $abstract_data_type == "date" } { if [catch { set response_to_question($question_id) [validate_ad_dateentrywidget "" response_to_question.$question_id [ns_getform]]} errmsg] { - ad_complain "[_ survey.lt_errmsg_Please_make_su]" + # If the date is not valid, but required, we want to through an error. Otherwise silently insert db_null. + if { $required_p == "t" } { + ad_complain "$errmsg: Please make sure your dates are valid." + } else { + set invalid_date_p($question_id) 1 + } } } @@ -185,7 +190,9 @@ if {[info exists response_to_question($question_id)]} { if {$abstract_data_type=="date"} { - set response_value "$response_to_question($question_id.year)-$response_to_question($question_id.month)-$response_to_question($question_id.day)" + if {[exists_and_not_null invalid_date_p($question_id)]} { + set response_value [db_null] + } } else { set response_value [string trim $response_to_question($question_id)] } @@ -196,16 +203,20 @@ # If this is a predefined question, handle it accordingly if {$predefined_question_id != [db_null]} { db_1row predefined "" + + # Predefined DB questions are inserted both in the DB and in the response. if {$action_type=="db"} { + # Make sure we deal with dates correctly + # If we have an invalid date, insert a NULL value + if {[exists_and_not_null invalid_date_p($question_id)]} { + set response_value [db_null] + } + # insert value into db db_dml ignore "update $table_name set $column_name=:response_value where $key_name=:user_id" if {![db_resultrows]} { - db_dml insert "insert into $table_name ($key_name,$column_name) values (:user_id,:response_value)" + db_dml insert "insert into $table_name ($key_name,$column_name) values (:user_id,_response_value)" } - } else { - if {$action_type=="tcl"} { - # execute tcl code - need more specs on that - Kolja - } } } @@ -261,7 +272,11 @@ if { [empty_string_p $response_value] } { set response_value [db_null] } - + # Make sure we deal with dates correctly + # If we have an invalid date, insert a NULL value + if {[exists_and_not_null invalid_date_p($question_id)]} { + set response_value [db_null] + } db_dml survey_question_response_date_insert {} } "blob" { @@ -320,14 +335,14 @@ db_dml finish_response {} } -survey_do_notifications -response_id $response_id +# survey_do_notifications -response_id $response_id if {[exists_and_not_null return_url]} { ad_returnredirect "$return_url" ad_script_abort } else { - set context_bar [ad_context_bar "[_ survey.lt_Response_Submitted_fo]"] - ad_return_template + set context_bar [ad_context_bar "[_ survey.lt_Response_Submitted_fo]"] + ad_return_template }