\n"); printf("
\n\n",$submit_to,preg_replace('/\s+/', "_", $form_name)); //required questions that were missed. HTML fieldnames are passed back as $_GET variables $missed_required = (isset($_GET['missed_required']))? explode(",",$_GET['missed_required']) : array(); //if certain questions were declined, but we are going back to the form because of other missed questions //or out of range questions, these need to be passed back into "declined" list. $declined_checked = (isset($_GET['declined_checked']))? explode(",",$_GET['declined_checked']) : array(); //start writing the form fields for($ind=0;$ind < $totalRows_form_questions;$ind++) { //missedMultTitle tracks whether any part of the multi-title was missed //if any column of a "required" multi-title is skipped, the whole //multi-title is regarded as skipped $missedMultiTitle = FALSE; if($trial_form) { $sql_num_subquestions = sprintf("select max(question_x_data_format.subquestion) as total_subquestions "). sprintf("from question_x_data_format where question_id = %d ",$row_form_questions['question_id']). sprintf("group by question_id"); $result_num_subquestions = mysql_select($sql_num_subquestions); $current_iteration = 1; $num_iterations = 1; $num_subquestions = $result_num_subquestions['total_subquestions']; } else { $current_iteration = $row_form_questions['question_iteration']; //find the total iterations for this question $query_total_iterations = sprintf("SELECT MAX(form_x_question.question_iteration) as total_iterations,MAX(question_x_data_format.subquestion) as total_subquestions "). sprintf("FROM form_x_question,question_x_data_format WHERE form_x_question.form_id = %d AND ",$form_id). sprintf("form_x_question.form_question_num = %d AND question_x_data_format.question_id = form_x_question.question_id ",$row_form_questions['form_question_num']). sprintf("GROUP BY form_x_question.form_question_num"); $total_iterations = mysql_query($query_total_iterations) or report_error_form(mysql_error()); $row_total_iterations = mysql_fetch_assoc($total_iterations); $num_iterations = $row_total_iterations['total_iterations']; $num_subquestions = $row_total_iterations['total_subquestions']; } //the heading format (i.e. single question, multi-title, or multi-question) //single question involves no special formatting. multi-title will place a column heading for each subquestion. multi-question will issue another question as part of that same question (basically //instead of printing a new question number and paragraph spacing, a break will be used). $heading_format = $row_form_questions['heading_format']; //the field name for the form field. the format determines which formquest_num, iteration, and subquestion that the //field belongs to. When the form is submitted, these are referenced and the response is submitted with this information. //trial_forms are now using identical html field formats. The only difference is that the formquestnum is set to 0 - S.T. 4/19/2010 if($trial_form) $html_fieldname = sprintf("questid_%d_formquest_0_iter_%d_subquest_%d_type_%d",$row_form_questions['question_id'],$current_iteration,$row_form_questions['subquestion'],$row_form_questions['data_format_id']); else $html_fieldname = sprintf("questid_%d_formquest_%d_iter_%d_subquest_%d_type_%d",$row_form_questions['question_id'],$row_form_questions['form_question_num'],$current_iteration,$row_form_questions['subquestion'],$row_form_questions['data_format_id']); //if this is a required fieldname, add it to an array of required fields (to be submitted to submit_response.php) if( ($row_form_questions['required'] == 'T') && (($row_form_questions['question_iteration'] == 1) || $trial_form) && ($row_form_questions['type'] != "null") ) $required_fields[] = $html_fieldname; //if this is the first iteration and first subquestion, print the question number and the question text //additionally, if this is a multi-title question, create a table and print the heading for each subquestion if(($current_iteration == 1) && ($row_form_questions['subquestion'] == 1)) { print "\n"; if($_SESSION['play_question_audio'] && !empty($row_form_questions['audio_path'])) { print "\n"; } print "
\n"; //display in red only if they missed a required field but did not previously check "decline" if(in_array($html_fieldname,$missed_required) && !in_array($html_fieldname,$declined_checked)) print ""; elseif($heading_format == "multi-title") { //for multi-title questions, we are going to check if any one subquestion (column) was skipped //if so, display text in red. We need to check all $missed_required for the subquestions foreach($missed_required as $missedQ) { $subqPattern = sprintf("/^questid_%d_formquest_%d_iter_%d_subquest_.*$/",$row_form_questions['question_id'],$row_form_questions['form_question_num'],$row_form_questions['question_iteration']); if(preg_match($subqPattern,$missedQ)) { $missedMultiTitle = TRUE; break; } } if($missedMultiTitle) print ""; else print ""; } else print ""; //replace use of $trial_form and $consent_form with $form_type if(!$trial_form && !$consent_form && !in_array($form_type,array('subinfo','consent','trial','security_questions'))) { switch($_SESSION['exp_params']['question_numbering']) { case "by_form": default: $questNumDisplay = sprintf("%d) ",$row_form_questions['form_question_num']); break; case "by_experiment": $numQuestionsDisplayed += 1; $questNumDisplay = sprintf("%d) ",$numQuestionsDisplayed); break; } } else { //do not include these questions in consecutive numbering over the experiment (if question_numbering=by_experiment) $include_consecutive_nums = 0; $questNumDisplay = ""; } printf("%s%s\n",$questNumDisplay,$row_form_questions['question_text']); //display the declined checkbox if they missed a required question OR they previously checked "decline" //the participant may have previously checked "decline" if they declined this response but failed to answer //another required question if(in_array($html_fieldname,$missed_required) || in_array($html_fieldname,$declined_checked) || $missedMultiTitle) { $this_decline_checked = (in_array($html_fieldname,$declined_checked)) ? "checked" : ""; $html_fieldname_decline = $html_fieldname . "_decline"; printf("",$html_fieldname_decline,$html_fieldname_decline,$this_decline_checked,$html_fieldname_decline,LANGUAGE_TEXT_QUOTE_DECLINE); } print "\n"; $flashOptions['urls'][0] = $question_audio_url_dir . "/" . $row_form_questions['audio_path']; play_audio_stimuli_flash($flashOptions); print "
\n"; if($heading_format == "multi-title") { $query_headings = sprintf("SELECT question_x_data_format.heading FROM question_x_data_format WHERE question_id = %d",$row_form_questions['question_id']); $headings = mysql_query($query_headings) or report_error_form(mysql_error()); $row_headings = mysql_fetch_assoc($headings); printf(sprintf("\n")); printf(sprintf("\n")); do { printf(sprintf("\n",$row_headings['heading'])); } while($row_headings = mysql_fetch_assoc($headings)); printf(sprintf("\n")); } } //if this is a multi-question and we are on the second or higher subquestion, print a break and the heading for the subquestion if($heading_format == "multi-question" && ($row_form_questions['subquestion'] > 1)) { print "
%s
\n"; if($_SESSION['play_question_audio'] && !empty($row_form_questions['audio_path'])) { print "\n"; } print "
\n"; if(in_array($html_fieldname,$missed_required) && !in_array($html_fieldname,$declined_checked)) print ""; else print ""; printf(sprintf("%s\n",$row_form_questions['heading'])); if(in_array($html_fieldname,$missed_required) || in_array($html_fieldname,$declined_checked)) { $this_decline_checked = (in_array($html_fieldname,$declined_checked)) ? "checked" : ""; $html_fieldname_decline = $html_fieldname . "_decline"; printf("",$html_fieldname_decline,$html_fieldname_decline,$this_decline_checked,$html_fieldname_decline); } print "\n"; $flashOptions['urls'][0] = $question_audio_url_dir . "/" . $row_form_questions['audio_path']; play_audio_stimuli_flash($flashOptions); print "
\n"; } //if this is a multi-title, start a new row for each new iteration //always create a new column for each field if($heading_format == "multi-title") { if(($current_iteration >= 1) && ($row_form_questions['subquestion'] == 1)) printf(sprintf("\n")); printf(sprintf("\n")); } //output a line break if this field is a multiple iteration, single question format if(($heading_format == "single_quest") && ($num_iterations > 1)) printf(sprintf("\n
\n")); //if revisiting this form because of an error, the previously entered fields are re-entered via GET (!is_null($_GET[$html_fieldname])) ? $selected_answer = htmlspecialchars(stripslashes(urldecode($_GET[$html_fieldname]))) : $selected_answer = $row_form_questions['default']; //now create the form fields! The form field type will vary based on the data type of the response. switch($row_form_questions['type']) { case "text": if($heading_format == "multi-question" && ($row_form_questions['subquestion'] > 1)) printf("
\n"); //use a table to further indent the responses to subquestions if($row_form_questions['html_field_type'] == "text") printf(sprintf("\n",$html_fieldname,$html_fieldname,$selected_answer)); else //default type is textarea so any other value results in this printf(sprintf("\n",$html_fieldname,$html_fieldname,$selected_answer)); //close the table tags for indenting answers to subquestions if($heading_format == "multi-question" && ($row_form_questions['subquestion'] > 1)) printf("
\n"); break; case "varchar": $maxlength = (integer) $row_form_questions['range']; if(is_null($maxlength) || ($maxlength < 1)) { //if there is a maxlength (range), then limit the field entry $fieldsize=30; printf(sprintf("\n",$html_fieldname,$html_fieldname,$fieldsize,$selected_answer)); } else { $fieldsize=$maxlength; printf(sprintf("\n",$html_fieldname,$html_fieldname,$fieldsize,$maxlength,$selected_answer)); } break; case "enum": unset($options); $options = enumstr2array($row_form_questions['enum_values']); $num_options = sizeof($options); $html_field_type = ($row_form_questions['html_field_type'] != NULL || $row_form_questions['html_field_type'] != "")? $row_form_questions['html_field_type'] : "radiogroup"; //check the html_field_type to determine the type of form field to use switch($html_field_type) { case "checkbox": //this is a "check all that apply" html field type printf("\n\n"); $mask = strrev(decbin($selected_answer)); $pos = 0; $idx = 0; unset($mask_array); while(($idx < strlen($mask)) && ($pos !== false)) { $pos = strpos($mask,'1',$idx); if($pos !== false) { $mask_array[] = $pos; $idx = $pos + 1; } } $num_row_cells = 1; for($enum_ind = 0;$enum_ind < sizeof($options);$enum_ind++) { if($num_row_cells / $checkbox_cells_in_row > 1.0) { //start a new row after every 8 cells printf("\n"); printf("\n"); $num_row_cells = 1; } $enum_fieldname = $html_fieldname."_enum_".$enum_ind; if(strlen($options[$enum_ind]) > 25) $checkbox_text_align = "left"; else $checkbox_text_align = "right"; if($options[$enum_ind] != "") { if(!is_null($mask_array) && (in_array(strval($enum_ind),$mask_array))) printf(sprintf("\n",$enum_fieldname,$enum_fieldname,$enum_ind,$enum_fieldname,$options[$enum_ind])); else printf(sprintf("\n",$enum_fieldname,$enum_fieldname,$enum_ind,$enum_fieldname,$options[$enum_ind])); } $num_row_cells++; } printf("\n
\n"); break; case "menu": $enum_fieldname = $html_fieldname."_enum_0"; //this enum type only allows one selection at a time, so just append "_enum_0" to enable type conversion printf("
\n"); printf(sprintf("\n")); printf("\n
\n"); break; case "radiogroup": default: printf("\n"); printf("\t\n"); $enum_fieldname = $html_fieldname."_enum_0"; //this enum type only allows one selection at a time, so just append "_enum_0" to enable type conversion $enum_ind = 0; while($enum_ind < sizeof($options)) { $row_count = $enum_ind % $num_cell_width + 1; $row_enum_ind = $enum_ind; while(($row_count <= $num_cell_width) && ($row_enum_ind < sizeof($options)) ) { $radiobutton_id = $enum_fieldname . "_" . $row_enum_ind; printf(sprintf("\n\t\n",$radiobutton_id,$options[$row_enum_ind])); $row_enum_ind++; $row_count++; } printf("\n\n"); $row_enum_ind = $enum_ind; $row_count = $enum_ind % $num_cell_width + 1; while( ($row_count <= $num_cell_width) && ($row_enum_ind < sizeof($options)) ) { $radiobutton_id = $enum_fieldname . "_" . $row_enum_ind; if(pow(2,$row_enum_ind) != $selected_answer) printf(sprintf("\n\t\n",$enum_fieldname,$radiobutton_id,$row_enum_ind)); else printf(sprintf("\n\t\n",$enum_fieldname,$radiobutton_id,$row_enum_ind)); $row_enum_ind++; $row_count++; } //start a new row if we have exceeded the row width if($row_count > $num_cell_width) printf("\n\n\n"); $enum_ind = $row_enum_ind; } printf("\n"); printf("\n
"); break; } //end switch html_field_type break; case "int16": case "int32": case "int64": //set the low and high limits for a range //and assign numbers to an array unset($options); if(!is_null($row_form_questions['range'])) { $low = ((integer) strtok($row_form_questions['range'],"-")); $high = ((integer) strtok("-")); for($range = $low;$range <= $high;$range++) { $options[] = $range; } //for } //if we have a range else { //we don't have a range $low = NULL; $high = NULL; } if($row_form_questions['type'] = "int16") $fieldsize = 6; elseif($row_form_questions['type'] = "int32") $fieldsize = 11; elseif($row_form_questions['type'] = "int64") $fieldsize = 20; //if radiogroup html field type was selected, use it only if the range of numbers <= 30 //otherwise the default field type (text) is used. switch($row_form_questions['html_field_type']) { case "radiogroup": if(is_int($low) && is_int($high) && (abs($high - $low) <= 30)) { printf("\n"); printf("\t\n"); for($enum_ind = 0;$enum_ind < sizeof($options);$enum_ind++) { if($options[$enum_ind] != $selected_answer) printf(sprintf("\n\n\n",$options[$enum_ind],$html_fieldname,$options[$enum_ind])); else printf(sprintf("\n\n",$options[$enum_ind],$html_fieldname,$options[$enum_ind])); } printf("\n
\n%s \n%s
\n"); } else { //use default text type since range is too large printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize,$fieldsize)); } break; case "menu": if(is_int($low) && is_int($high) && (abs($high - $low) <= 30)) { printf(sprintf("\n")); } else { //use default text type since range is too large printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize,$fieldsize)); } break; case "text": default: printf("
\n"); printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize,$fieldsize)); printf("
"); break; } //inner switch break; case "double": $fieldsize = 30; printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize)); break; case "date": if($heading_format == "multi-question" && ($row_form_questions['subquestion'] > 1)) printf("
\n"); //use a table to further indent the responses to subquestions $fieldsize = 10; printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize,$fieldsize)); if($heading_format == "multi-question" && ($row_form_questions['subquestion'] > 1)) printf("
\n"); break; case "time": $fieldsize = 10; printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize,$fieldsize)); break; case "year": $fieldsize = 4; printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize,$fieldsize)); break; case "null": //null response printf(sprintf("\n",$html_fieldname)); break; default: //an unsupported or not yet defined data type $fieldsize = 30; printf(sprintf("\n", $html_fieldname,$html_fieldname,$selected_answer,$fieldsize,$fieldsize)); break; } //switch data type //if format is multi-title, write a end of column tag after the field //additionally, if that field was the last subquestion, write an end of row tag // and if this was the last subqestion of the last iteration, write an end of table tag if($heading_format == "multi-title") { printf(sprintf("\n")); if($trial_form || $row_form_questions['subquestion'] == $num_subquestions) { printf(sprintf("\n\n")); if($current_iteration == $num_iterations) printf(sprintf("\n")); }//if }//if // if($heading_format == "multi-question" || $heading_format == "single_quest") // printf(sprintf("

\n")); //get the next form question in the query $row_form_questions = mysql_fetch_assoc($form_questions); } //for $totalRows print "

 

"; //write the footer of the form if($_SESSION['play_question_audio'] && !empty($footer_audio_path)) { print "
\n"; $headerFlashOptions['audio_player'] = "play_audio_button.swf"; $headerFlashOptions['width'] = 35; $headerFlashOptions['height'] = 35; $headerFlashOptions['urls'][0] = $form_head_foot_url_dir . "/" . $footer_audio_path; play_audio_stimuli_flash($headerFlashOptions); print "
\n"; } print $row_form_info['footer']; if(isset($required_fields) && sizeof($required_fields) > 0) $required_field_string = implode(",",$required_fields); else $required_field_string = ""; printf("

\n",$required_field_string); printf("\n",date("Y-m-d H:i:s")); //if the form handler manages security questions, $security_questions should be set to "true" //the "true" value will be reset to 1 for POST submission. //Otherwise, $security_questions defaults to "0" (false) $security_questions = (isset($security_questions) && $security_questions)? 1 : 0 ; printf("\n",$security_questions); //this variable handles whether or not to include these questions when for numbering them consecutively over the session //Consent forms, for example, should probably not be included in such numbering. if(!isset($include_consecutive_nums)) $include_consecutive_nums = 1; printf("\n",$include_consecutive_nums); if($row_form_info['break_loop_button'] == 'T') { if (is_null($row_form_info['break_loop_button_text']) || $row_form_info['break_loop_button_text'] == "") { $button_matches[0] = ""; //dummy placeholder $button_matches[1] = LANGUAGE_TEXT_BREAK_LOOP_DEFAULT_SUBMIT_ANOTHER; $button_matches[2] = LANGUAGE_TEXT_BREAK_LOOP_DEFAULT_GOTO_NEXT; } else { $button_text = $row_form_info['break_loop_button_text']; $found_matches = preg_match('|\"([^\"]*)\",\"([^\"]*)\"|',$button_text,$button_matches); } printf("

",$button_matches[1],$form_name); printf("",$button_matches[2],$form_name); } else { printf("

\n

\n",LANGUAGE_TEXT_QPI_NEXT_BUTTON,$form_name); } printf("\n
\n"); include('disp_progress_report.php'); ?>