%s

",$message)); } //returns an sql timestamp value from a formatted date/time string // 14 Feb 2005 - currently not used in questionnaire function dt2timestamp($date_time) { $year = strtok($date_time," -:"); $month = strtok(" -:"); $day = strtok(" -:"); $hour = strtok(" -:"); $min = strtok(" -:"); $sec = strtok(" -:"); $timestamp = mktime($hour,$min,$sec,$month,$day,$year); return $timestamp; } function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "blob": $theValue = "COMPRESS('" . $theValue . "')"; case "file": //if $theType == "file", replace the hostname in addition to regular text processing $theValue = substr($theValue,56); case "text": $theValue = ($theValue != "") ? "'" . preg_replace("|%20|"," ",$theValue) . "'" : "NULL"; //replacing urlencoded spaces in addition to regular sql processing break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "time": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } //performs a select query (given as $sql_string) and returns the first record of the query //useful when a select is needed to get just one record. function mysql_select($sql_string) { $query = mysql_query($sql_string) or report_error_form("mysql_select error ($sql_string): " . mysql_error()); $result_query = mysql_fetch_assoc($query); return ($result_query); } //performs an insert query. If query unsuccessful, returns 0, otherwise, returns id inserted. function mysql_insert($sql_string) { $query = mysql_query($sql_string) or report_error_form("mysql_insert error ($sql_string): " . mysql_error()); if (!query) return($query); else return(mysql_insert_id()); } function mysql_update($sql_string) { mysql_query($sql_string) or report_error_form("mysql_update error ($sql_string): " . mysql_error()); } //parses a comma-delimited enum string with enum fields in double-quotes //returns the string array of enum fields with double-quotes removed function enumstr2array($enum_str) { $enum_vals = array(); $str_rem = $enum_str; while(preg_match("|\"([^\"]*)\",?|",$str_rem,$matches)) { $enum_vals[] = $matches[1]; $str_rem_start = strpos($str_rem,$matches[0])+strlen($matches[0]); $str_rem_len = strlen($str_rem) - $str_rem_start; $str_rem = substr($str_rem,$str_rem_start,$str_rem_len); } return $enum_vals; } // // I think this one is self-explanatory. // it checks against the subject table, not the response // table for this specific experiment. // Return value is the string containing the subject_id // which is constructed in the form_subject_id or // form_subject_id_with_validation form handlers. // Or, returns NULL if subject_id for this name and DOB // combination doesn't exist in the subject table. - JG // // 29 Sept. 2009 - Added code to decrypt subject Info - S.T. // function get_subject_id_if_it_exists( $name_first, $name_last, $dob,$find_inc_session = FALSE ) { // these are created in /var/www/private/conn_XXXX.php // the "$subject" variable is actually the mysql connection global $database_subject; global $subject; if( !$name_first || !$name_last || !$dob ) return( NULL ); $enc_key = subinfo_encryption_key(); $sql_query = sprintf( "SELECT *,session.end_datetime as edt, session.date_time as sdt, session.end_datetime is not null as session_is_finished ". " FROM subject left join session using (subject_id) ". "WHERE aes_decrypt(`name_last`,'%s')=%s ". "AND aes_decrypt(`name_first`,'%s')=%s AND aes_decrypt(`dob`,'%s')=%s ". "order by ". (($find_inc_session)? "session_is_finished asc, ": ""). "session.date_time desc", $enc_key, GetSQLValueString($name_last,"text"), $enc_key, GetSQLValueString($name_first,"text"), $enc_key, GetSQLValueString($dob,"date")); $query_result = mysql_query( $sql_query, $subject) or report_error_form("get_subject_id_if_it_exists error ($sql_query): " . mysql_error()); // if there's anything in the result, it will be the // record corresponding to this subject's id, so return the value // of the subject_id field in the first row in the result set. // there should never be 2 rows in the result set because // subject_id is a unique field in the subject table if( mysql_num_rows( $query_result ) ) { $record_array = mysql_fetch_assoc( $query_result ); return( $record_array[ 'subject_id' ] ); } return( NULL ); } // // play_video_with_quicktime( $player, $videoURL, $height, $width, $bAutoPlay, $bAllowControl, $numPlays ) // // player not used here. artifact of the design of present_stimuli() // // url full path to video file // // height, width required // // bAutoPlay true-> movie plays automatically right after loading // optional: default = true // bAllowControl true-> basic QT controls are visible to the user which allow pausing, // repeating, etc. but the movie will still auto play on page load if // bAutoPlay is true, regardless of bAllowControl's value. // optional: default = false // numPlays only applies if bAutoPlay is set to true. can repeat the same movie // any number of times. after that, if the user clicks the play button // again (if bAllowControl is true), the original movie is only played once. // QT actually allows any number of different movies to be auto-played in // sequence on page load using the QTnext tag. We will assume that the // numPlays applies only to the original movie, but we could easily modify // to support multiple movies if necessary. // optional: default = 1 // function play_video_with_quicktime() { $numArgs = func_num_args(); $argList = func_get_args(); if( $numArgs < 4 || $argList[1] == NULL ) report_error_form( "NULL or missing video URL, height, or width parameter(s) passed to include/functions.php: play_video_with_quicktime()." ); if( $argList[2] < 1 || $argList[3] < 1 ) report_error_form( "invalid height or width values passed to include/functions.php: play_video_with_quicktime()." ); // Check for optional arguments and assign defaults $videoURL = $argList[1]; if( $videoURL == NULL ) report_error_form( "NULL video URL passed to play_video_with_quicktime() in include/functions.php" ); $height = $argList[2]; $width = $argList[3]; if( $numArgs > 4 ) $autoPlayStr = ( $argList[4] == true )? "true" : "false"; else $autoPlayStr = "true"; // default if( $numArgs > 5 ) $allowControlStr = ( $argList[5] == true )? "true" : "false"; else $allowControlStr = "false"; // default if( $numArgs > 6 ) $numReps = $argList[6]; else $numReps = 1; // default if( $numReps < 1 ) $numReps = 1; // Note: for movies with controll=true, displaying the // movie controls to the user, you need to add 16 to the movie's actual // height to account for the controls. for audio only movies, set height to 16. if( $allowControlStr == "true" ) $height = $height + 16; // -- Output HTML object tag for QT player -------------------------------------- // this clsid is always the same for anyone using QT plugin // This should be compatible with most browsers and gracefully degrade for others printf( "
\n"); printf( "\n" ); printf( "\n", $videoURL ); printf( "\n", $autoPlayStr ); printf( "\n", $allowControlStr ); printf( "\n" ); // prevent reloading movie on every play printf( "\n" ); // don't sacrifice quality for speed // QTnext tags enumerate a list of videos (may all be the same or different) to play in sequence // the T part says to use the same browser window to play each movie in the QTnext list. // If numReps == 1, then no QTnext tag will be included at all. for( $x = 1; $x < $numReps; $x++ ) { printf( "T\">\n", $x, $videoURL ); } // safari and firefox seem to follow the tag printf( "\n", $videoURL, $width, $height ); printf( "\n", $allowControlStr ); printf( "\n", $autoPlayStr ); printf( "\n" ); // prevent reloading movie on every play printf( "\n" ); // don't sacrifice quality for speed printf( "Download video: sign.mov\n", $videoURL ); for( $x = 1; $x < $numReps; $x++ ) { printf( "T\">\n", $x, $videoURL ); } printf( "\n" ); printf( "\n" ); printf( "
\n" ); // ------------------------------------------------------------------------- $_SESSION[ 'stimulus_completed' ] = true; } function play_video_with_html5() { $numArgs = func_num_args(); $argList = func_get_args(); if( $numArgs < 4 || $argList[1] == NULL ) report_error_form( "NULL or missing video URL, height, or width parameter(s) passed to include/functions.php: play_video_with_quicktime()." ); if( $argList[2] < 1 || $argList[3] < 1 ) report_error_form( "invalid height or width values passed to include/functions.php: play_video_with_quicktime()." ); // Check for optional arguments and assign defaults $videoURL = $argList[1]; if( $videoURL == NULL ) report_error_form( "NULL video URL passed to play_video_with_quicktime() in include/functions.php" ); $height = $argList[2]; $width = $argList[3]; if( $numArgs > 4 ) $autoPlayStr = ( $argList[4] == true )? "autoplay" : ""; else $autoPlayStr = "autoplay"; // default if( $numArgs > 5 ) $controlStr = ( $argList[5] == true )? "controls" : ""; else $controlStr = ""; // default if( $numArgs > 6 ) $numReps = $argList[6]; else $numReps = 1; // default if( $numReps < 1 ) $numReps = 1; printf( "
\n"); printf("", $videoURL, $controlStr, $autoPlayStr, $height, $width); printf( "
\n" ); // ------------------------------------------------------------------------- $_SESSION[ 'stimulus_completed' ] = true; } // play_video_with_html5() // java applet audio player that supports wav, aiff, au // can play any number of audio stimuli in succession // Should never be called directly by a form handler (use present_stimuli or present_trial_stimuli) // Expects play_audio_stimuli_applet($player,$audioURL1,$playLength1,$pause1,$audioURL2,$playLength2,$pause2,$audioURL3,...) // Expects a single argument ($options), which is an associative array with the following possible values: // $options['urls'] - an array of urls of audio files. At least one url should be set. // $options['playLengths'] an array of play lengths corresponding to the 'urls' in order. A value of 0 indicates to play the entire stim. // $options['pauses'] - an array of pause values (pause before stim) corresponding to the 'urls' in order. Uses $default_pause if ommitted. // $options['loadWhenDone'] - URL to load when finished playing. // where $audioURL# is the url of the audio file, $playLength# is the duration of the audio file to play, and // $pause# is the number of seconds to pause before playing the audio file. function play_audio_stimuli_applet($options) { global $questionnaire_location; global $stimuli_location; global $stimuli_dir; $default_audio_player="JavaSamplePlayer.class"; $this_file = "include/functions.php"; $this_fn = "play_audio_stimuli_applet"; $loadWhenDone=$options['loadWhenDone']; $default_pause = 1; //default pause value to use between stims if pause isn't specified. $applet_player_loc = $stimuli_location."/applet/classes/"; $audioURLs_list = (isset($options['urls']))? $options['urls'] : array(); $playLengths_list = (isset($options['playLengths']))? $options['playLengths'] : array(); $pauses_list = (isset($options['pauses']))? $options['pauses'] : array(); $audio_player = $flash_player_loc . (isset($options['audio_player']))? $options['audio_player'] : $default_audio_player; $nAudio = count($audioURLs_list); $nPL = count($playLengths_list); $nPauses = count($pauses_list); if($nAudio < 1) report_error_form("No Audio URLs specified.",$this_file,$this_fn); //applet player expects playLengths to be set for each audio file //also, we need to take care of NULLs that are propogated down to this function. //when playLength = 0, the entire audio file is played. for ($iAudio = 0; $iAudio < $nAudio; $iAudio++) { if( ($iAudio > $nPauses - 1) || ($pauses_list[$iAudio] == NULL) ) $pauses_list[$iAudio] = $default_pause; if ( ($iAudio > $nPL - 1) || ($playLengths_list[$iAudio] == NULL) ) $playLengths_list[$iAudio] = 0; } //if the stim is greater than a certain file size, preloading will fail //This threshold was empirically found at approximately 4Mb by trying different file sizes //Investigation into the Java player code will be necessary to find the //real limitation. Currently setting the threshold to 3500000 bytes. //This is essentially a temporary fix. S.T. $soundFileSize = 0; foreach($options['urls'] as $audPath) { //remove $stimuli_location from the url and use local dir path $audPath = substr($audPath,(strlen($stimuli_location)-1)); $audPath = $stimuli_dir . $audPath; $soundFileSize = $soundFileSize + filesize($audPath); } if($soundFileSize < 3500000) $preloadVal = "true"; else $preloadVal = "false"; printf("\n"); printf("\n",$audio_player); printf("\n",$applet_player_loc); printf("\n"); printf("\n",$loadWhenDone); if($nAudio == 1) printf("\n",$preloadVal); for($audioIdx = 0; $audioIdx < $nAudio; $audioIdx++) printf("\n",$audioIdx+1, $audioURLs_list[$audioIdx]); for($plIdx= 0; $plIdx < $nPL; $plIdx++) printf("\n",$playLengthIdx+1, $playLengths_list[$plIdx]); for($pauseIdx = 0; $pauseIdx < $nPauses; $pauseIdx++) printf("\n",$pauseIdx+1, $pauses_list[$pauseIdx]); printf("\n"); printf("\n"); printf("\n"); printf("No Java 2 SDK, Standard Edition v 1.5 support for APPLET!!\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); $_SESSION['stimulus_completed'] = true; } // Flash player that supports 1 or 2 mp3 stims. // Should never be called directly by a form handler (use present_stimuli or present_trial_stimuli) // This function is currently used for trials which present // play_audio_stimuli_flash($player,$audioURL1,$playLength1,$pause1,$audioURL2,$playLength2,$pause2) //edited 3/19/2010 to accept param, value pairs //this will allow for unlimited numbers of audioURLs, playLengths, and pauses. Also allows easy exclusion of unneeded parameters. function play_audio_stimuli_flash($options) { global $questionnaire_location; global $stimuli_location; $this_file = "include/functions.php"; $this_fn = "play_audio_stimuli_flash"; $flash_player_loc = $stimuli_location."flash/"; $default_audio_player = "present_audio_stimuli.swf"; $getvars = ""; $audioURLs_list = (isset($options['urls']))? $options['urls'] : array(); $playLengths_list = (isset($options['playLengths']))? $options['playLengths'] : array(); $pauses_list = (isset($options['pauses']))? $options['pauses'] : array(); $audio_player = $flash_player_loc . ((isset($options['audio_player']))? $options['audio_player'] : $default_audio_player); $nAudio = count($audioURLs_list); if($nAudio < 1) report_error_form("No Audio URLs specified.",$this_file,$this_fn); for($idx = 0; $idx < $nAudio; $idx++) { $getvars = $getvars . (($idx == 0)? "":"&") . "audioURL" . ($idx+1) . "=" . urlencode($audioURLs_list[$idx]); } $nPL = count($playLengths_list); for($idx = 0; $idx < $nPL ; $idx++) { if(!is_null($playLengths_list[$idx])) $getvars = $getvars . ( ($playLengths_list[$idx] != NULL)? ("&playLength" . ($idx+1) . "=" . $playLengths_list[$idx]) : "" ); } $nPauses = count($pauses_list); for($idx = 0; $idx < $nPauses ; $idx++) { if(!is_null($pauses_list[$idx])) $getvars = $getvars . "&pause" . ($idx+1) . "=" . $pauses_list[$idx]; } if(isset($options['loadWhenDone'])) $getvars = sprintf("loadWhenDone=%s",urlencode($options['loadWhenDone']))."&".$getvars; printf("\n"); printf("\n"); printf("\n",$audio_player,$getvars); printf("\n"); printf("\n"); printf("\n\n"); } //Uses HTML5