$value) { if(in_array($key,$response_table_fields_to_export_all)) { //store response table fieldnames (without encryption function) for the purpose of writing a header to the output file $response_table_fieldnames_to_export[] = $key; if( ($_SESSION['encrypted_response_table']) && ((strcmp($key,"response_text") == 0) || (strcmp($key,"response_enum") == 0)) ) { $key = sprintf("aes_encrypt(`%s`,'%s') as `%s`",$key,$enc_key,$key); } $response_table_fields_to_export[] = $key; } if(in_array($key,$question_table_fields_to_export_all)) $question_table_fields_to_export[] = $key; if(in_array($key,$question_x_data_format_fields_to_export_all)) $question_x_data_format_fields_to_export[] = $key; if(in_array($key,$subject_fields_to_export_all)) $subject_fields_to_export[] = $key; } $data_format_fields_to_export = array("type","enum_values"); //this function is called for prepending the table name string to each element in the field arrays defined above function prepend_string2array($prepend_string,$string_array) { for($idx = 0; $idx < sizeof($string_array); $idx++) $string_array[$idx] = $prepend_string.$string_array[$idx]; return($string_array); } function decextbin($decimalnumber,$bit) { /* decextbin function by James Preece (j.preece@gmail.com) http://www.lovingit.co.uk First we find that maximum value represented by the leftmost binary digit. For error checking purposes we also calulate the maximum number we can display using the number of bits requested: */ $maxval = 1; $sumval = 1; for($i=1;$i<$bit;$i++) { $maxval = $maxval * 2; $sumval = $sumval + $maxval; } /* Using our sumval we now check if it is possible to display the decimal number our function received: */ if ($sumval < $decimalnumber) return 'ERROR - Not enough bits to display this figure in binary.'; /* Then we work down through the figures, to get a better idea of how this works remove the commenting from the echo lines */ for($bitvalue=$maxval;$bitvalue>=1;$bitvalue=$bitvalue/2) { //echo 'Bit Value: '.$bitvalue.'
'; //echo 'Decimal Number: '.$decimalnumber.'
'; if (($decimalnumber/$bitvalue) >= 1) $thisbit = 1; else $thisbit = 0; //echo 'This Bit: '.$thisbit.'

'; if ($thisbit == 1) $decimalnumber = $decimalnumber - $bitvalue; $binarynumber .= $thisbit; } /* Finally we return the output... */ return $binarynumber; } function resolve_enum_values($mask_int) { // convert from ^2 to bin # for each enum mask $mask_bin = strrev(decextbin($mask_int,64)); for($mask_idx = 0; $mask_idx < strlen($mask_bin); $mask_idx++) { $bit = substr($mask_bin,$mask_idx,1); if($bit == 1) { if($return_enum == NULL) $return_enum = $mask_idx+1; else { $return_enum .= ",".$mask_idx+1; } } } return $return_enum; } function resolve_enum_text($mask_int,$enum_values) { // resolve the enum text that goes along with an enum mask $enum_array = enumstr2array($enum_values); $mask_bin = strrev(decextbin($mask_int,64)); for($mask_idx = 0; $mask_idx < strlen($mask_bin); $mask_idx++) { $bit = substr($mask_bin,$mask_idx,1); if($bit == 1) { if($return_enum == NULL) $return_enum = $enum_array[$mask_idx]; else { $return_enum .= ",".$enum_array[$mask_idx]; } } } return $return_enum; } //unless "Export" button was pressed, send the HTTP headers if(!isset($_POST['action']) || ($_POST['action'] != "Export")) { ?> Export Responses

Ensemble Response Export Utility

Main Menu
Log Out

 

 

\"%s,\" Ticket(s) \"%s,\", Subject(s) \"%s,\" and Session(s) %s
",$descript_expid,$descript_tickid,$descript_subid,$descript_sessid); printf("
\n",$_SERVER['PHP_SELF']); printf("

 

"); printf("

Select Fields to Export:

\n"); printf("\n"); $col = 1; print "\n"; foreach($response_table_fields_to_export_all as $value) { if($col > 6) { $col = 1; print ""; } print "\n"; printf("
response table:
$value "; $col++; } print "
"); printf("

 

"); printf("\n"); $col = 1; print "\n"; foreach($question_table_fields_to_export_all as $value) { if($col > 6) { $col = 1; print ""; } print "\n"; printf("
question table:
$value "; $col++; } print "
"); printf("

 

"); printf("\n"); $col = 1; print "\n"; foreach($question_x_data_format_fields_to_export_all as $value) { if($col > 6) { $col = 1; print ""; } print "\n"; printf("
question_x_data_format table:
$value "; $col++; } print "
"); printf("

 

"); printf("\n"); $col = 1; print "\n"; foreach($subject_fields_to_export_all as $value) { if($col > 6) { $col = 1; print ""; } print "\n"; printf("
subject table:
$value "; $col++; } print "
"); printf("

 

"); printf("",$export_experiment_id); printf("",$export_session_id); printf("",$export_subject_id); printf("Please type in a filename: "); printf("\n"); printf("\n"); printf("
"); } else { $sql_get_experiments = sprintf("select * from experiment"); $experiment_name = mysql_query($sql_get_experiments) or die(mysql_error()); //Obtain the ticket IDs used for this experiment $sql_tickets = sprintf("select ticket_id from session where experiment_id like '%s' and ticket_id is not null",$export_experiment_id); $tickets = mysql_query($sql_tickets) or die(mysql_error()); //Obtain the subject IDs for the experiment(s) and ticket(s) selected $sql_subjects = sprintf("select subject_id from session where experiment_id like '%s' and (ticket_id like '%s' or ticket_id is null) group by subject_id",$export_experiment_id,$export_ticket_id); $subjects = mysql_query($sql_subjects) or die(mysql_error()); //find all the sessions for a given experiment, subject, and ticket $sql_session_id = sprintf("select session_id from `session` where experiment_id like '%s' and subject_id like '%s' and (ticket_id like '%s' or ticket_id is null)",$export_experiment_id,$export_subject_id,$export_ticket_id); $session_ids = mysql_query($sql_session_id) or die(mysql_error()); printf("
\n",$_SERVER['PHP_SELF']); printf("

Select Experiment\n"); printf("

\n"); printf("

Select Tickets\n"); printf("

\n"); printf("

Select Subjects\n"); printf("

\n"); printf("

Select Session\n"); printf("

\n"); printf(""); printf("
\n"); } ?>