I am mystified with my Recording code, it does not work anymore, it used to work but I was kind of switching from ANSI to utf-8 codification and when I call the submit method to save Responses it just says a bad fetch error has occurred and I can't see where the problem is; is it a codification issue? or a syntax problem, I'd really appreciate your help.
Thanks,
Tony
index.vxml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE vxml SYSTEM "http://plumvoiceportals.com/vxml-260.dtd">
<vxml xml:lang="es" version="2.0" >
<noinput>
<prompt>
<speak xml:lang="es">
Lo siento, no pude oírle.
</speak>
</prompt>
<reprompt/>
</noinput>
<nomatch>
<prompt>
<speak xml:lang="es">
Lo siento, no le entiendo.
</speak>
</prompt>
<reprompt/>
</nomatch>
<property name="sensitivity" value="0.1"/>
<property name="completetimeout" value="0.3s"/>
<property name="incompletetimeout" value="1s"/>
<property name="timeout" value="7s"/>
<property name="documentmaxage" value="0s"/>
<var name="qCustomerId" expr="'ID-GOES-HERE'"/>
<var name="date_of_call" expr="'DATE-GOES-HERE'"/>
<var name="time_of_call" expr="'TIME-GOES-HERE'"/>
<var name="save_Name" expr="'SAVE-NEW-NAME'"/>
<var name="firsttime" expr="0"/>
<var name="q1DolorCabeza" expr="0"/>
<var name="q1_level" expr="0"/>
<var name="q2DolorPiernas" expr="0"/>
<var name="q2_level" expr="0"/>
<var name="q3TrabajoConstruccion" expr="0"/>
<var name="q4" expr="0"/>
<var name="q5TypeOfWork" expr="0"/>
<var name="q5_audio" expr="0"/>
<var name="q5_a" expr="0"/>
<var name="q6" expr="0"/>
<var name="q6HowMuchHarder" expr="0"/>
<var name="q6HowMuchEasier" expr="0"/>
<var name="q7" expr="0"/>
<var name="q7HowFaster" expr="0"/>
<var name="q7HowSlower" expr="0"/>
<var name="q8" expr="0"/>
<var name="q8HowMore" expr="0"/>
<var name="q8HowLess" expr="0"/>
<var name="q9" expr="0"/>
<var name="q9_steeltoe" expr="0"/>
<var name="q9_electric" expr="0"/>
<var name="q9_waterproof" expr="0"/>
<var name="q9_concrete" expr="0"/>
<var name="q10" expr="0"/>
<var name="q10_a" expr="0"/>
<var name="q10_b" expr="0"/>
<var name="q10_c" expr="0"/>
<var name="q10_c1" expr="0"/>
<var name="q10_c2" expr="0"/>
<var name="q10_c3" expr="2"/>
<var name="fullname" expr="0"/>
<form id="wfvt_survey">
<property name="bargein" value="false"/>
<subdialog name="fullname_dlog" src="audio.vxml" cond="save_Name == true">
<param name="confirm_prompt"
expr="'Por favor diga su nombre y apellidos despues del tono'"/>
<filled>
<assign name="fullname" expr="fullname_dlog.response"/>
</filled>
</subdialog>
<block>
<prompt bargein="false">
Por favor responda las siguientes preguntas con veracidad.
</prompt>
</block>
<subdialog name="q1_dlog" src="yesno.vxml">
<param name="confirm_prompt" expr="'¿Túvo un accidente el día de hoy.?'"/>
<filled>
<assign name="q1DolorCabeza" expr="q1_dlog.response"/>
</filled>
</subdialog>
<subdialog name="q1_level_dlog" src="unoAcuatro.vxml" cond="q1DolorCabeza=='1'">
<param name="confirm_prompt"
expr="'¿En qué parte del cuerpo tuvo el accidente.?'"/>
<filled>
<assign name="q1_level" expr="q1_level_dlog.response"/>
</filled>
</subdialog>
<subdialog name="q3_dlog" src="yesno.vxml">
<param name="confirm_prompt" expr="'¿Trabajó usted en construcción esta semana.?'"/>
<filled>
<assign name="q3TrabajoConstruccion" expr="q3_dlog.response"/>
<if cond="q3TrabajoConstruccion=='2'">
<submit next="saveResponses.php" namelist="qCustomerId , fullname , date_of_call , time_of_call , firsttime , q1DolorCabeza , q1_level , q2DolorPiernas , q2_level , q3TrabajoConstruccion , q4 , q5TypeOfWork , q5_audio , q5_a q6 , q6HowMuchHarder , q6HowMuchEasier , q7 , q7HowFaster , q7HowSlower , q8 , q8HowMore , q8HowLess , q9 , q9_steeltoe , q9_electric , q9_waterproof , q9_concrete , q10 , q10_a , q10_b , q10_c , q10_c1 , q10_c2 , q10_c3" method="post" enctype="multipart/form-data"/>
<exit/>
</if>
</filled>
</subdialog>
</form>
</vxml>
Code: Select all
<?php
header('Cache-Control: no-cache');
date_default_timezone_set('America/New_York');
$headers = array(
"qCustomerId" , "date_of_call" , "time_of_call" , "end_date_of_call" , "end_time_of_call" , "firsttime" , "q1DolorCabeza" , "q1_level" , "q2DolorPiernas" , "q2_level" , "q3TrabajoConstruccion" , "q4" , "q5TypeOfWork" , "q5_audio" , "q5_a" , "q6" , "q6HowMuchHarder" , "q6HowMuchEasier" , "q7" , "q7HowFaster" , "q7HowSlower" , "q8" , "q8HowMore" , "q8HowLess" , "q9" , "q9_steeltoe" , "q9_electric" , "q9_waterproof" , "q9_concrete" , "q10" , "q10_a" , "q10_b" , "q10_c" , "q10_c1" , "q10_c2" , "q10_c3");
$mapping = array(
"q1DolorCabeza" => "q1DolorCabeza",
"q2PicanOjos" => "q2PicanOjos",
"q3RonquidoPecho" => "q3RonquidoPecho",
"q4DificultadRespirar" => "q4DificultadRespirar",
"q5RonchasManos" => "q5RonchasManos",
"q6RonchasPies" => "q6RonchasPies",
"q7EntumecimientoManos" => "q7EntumecimientoManos",
"q8DolorManos" => "q8DolorManos",
"q9HinchazonManos" => "q9HinchazonManos",
"q10RigidezCuello" => "q10RigidezCuello");
function write_headers($fp)
{
GLOBAL $headers, $mapping;
// used to be: fputcsv($fp, $headers);
$results = array();
foreach($headers as $v) // use headers as a way to order the results
$results[] = map($v); // map spanish to english, if there is a translation
fputcsv($fp, $results); // write them all out
}
function map($spanish)
{
GLOBAL $mapping;
if (isset($mapping[$spanish]))
return $mapping[$spanish];
else
return $spanish;
}
function saveFile($msg, $prefix)
{
global $_FILES;
// based on code from Save.php available at
// http://www.plumvoice.com/docs/dev/developer_reference:dataexchange
// if (isset($_FILES[$msg])) {
// //echo "found the audio attachment for $msg\n";
// }
if (isset($_FILES[$msg]) && is_uploaded_file($_FILES[$msg]['tmp_name'])) {
$filename = $prefix . time() . ".wav";
move_uploaded_file($_FILES[$msg]['tmp_name'], $filename);
return $filename;
}
else {
//echo "Audio not saved.\n";
return "Error";
}
}
// These one is audio file response which corresponds to the user's full name
// qCustomerId
# copy the audio responses to a local file, named with a unique identifier
if (isset($_FILES['fullname'])) {
$fn_fullname = saveFile('fullname', "fullname-");
$_POST['qCustomerId'] = $fn_fullname;
}
//else
//$_POST['qCustomerId'] = 'not set';
// old use: "m:d:Y G:i:s"
$_POST['end_date_of_call'] = date("Y/m/d");
$_POST['end_time_of_call'] = date("H:i:s");
$file = "./data.csv";
# if file is empty or doesn't exist, then write headers
if (!file_exists($file)) {
$fp = fopen($file, "w");
write_headers($fp);
}
else if (filesize($file) == 0){
$fp = fopen($file, "w");
write_headers($fp);
}
else # file is there, so open it in append mode and add more results at the end
$fp = fopen($file, "a+");
$results = array();
foreach($headers as $v) // use headers as a way to order the results
$results[] = $_POST[$v];
# write results
fputcsv($fp, $results);
# close the file
fclose ($fp);
# echo a VXML with the goodbye message
echo "<?xml version=\"1.0\"?>\n";
echo "<vxml xml:lang=\"es-MX\" version=\"2.0\" xmlns=\"http://www.w3.org/2001/vxml\<form id="form_main">
<block>
<prompt>
Gracias por su tiempo. Este es el final del cuestionario.
Por favor recuerde llamar mañana a la misma hora.
</prompt>
</block>
</form>
</vxml>
">\n";
?>