";
}
}
if ($_REQUEST['embed'] != "true") { // hide the console bar for embedded (iframed) surveys - just for neatness
$html .= $consolebar;
}
$qid = "surveys/quest_" . $_REQUEST['sid'] . ".xml";
$loaded = loadQuest2($qid); // load questionnaire
$configpath = "surveys/config_" . $_REQUEST['sid'] . ".php";
include_once($configpath); // load survey settings
$templatepath = "templates/" . $loaded['meta']['template'];
//include_once($templatepath); // load survey template (for header)
$template = @file_get_contents($templatepath);
if (strlen($template)<1) { // no content in the template, so just show the raw output
$template = "\n\n";
}
if ($surveysettings['surveyStatus'] == "Closed") {
$errormsg = ("{$surveysettings['surveyClosedMessage']}");
}
if ($surveysettings['blockResubmission'] == "TRUE" && ($_COOKIE["$completedSurveyCookie"] == $_REQUEST['sid'])) {
$errormsg = ("{$surveysettings['blockResubmissionMessage']}");
$blockresubmissionflag = "TRUE";
}
// do stuff with the most recent batch of $_POSTed data - stick in a session, validate it, whatever
foreach((array)$_POST['answers'] as $k => $v) {
$_SESSION['submitted'][$k] = $v;
}
// validate submission from previous page, if any
if (strlen($_POST['validated_required'])>0) {
$validated['required'] = explode(",",$_POST['validated_required']);
$missingflag = null;
foreach((array)$validated['required'] as $v) {
if (strlen(@implode("",$_SESSION['submitted'][$v]))<1) { // no answer supplied for this required q
$missingflag = "TRUE";
}
}
if ($missingflag == "TRUE") {
$errormsg = ("{$surveysettings['missingRequiredMessage']}");
}
}//print_r($_SESSION['submitted']);
if ($_POST['direction'] == "Next" || $_POST['direction'] == $surveysettings['submitButtonLabel']) {
$startid = ($_POST['nextnode']) ? $_POST['nextnode'] : "0";
} elseif ($_POST['direction'] == "Previous") {
$startid = ($_POST['prevnode']) ? $_POST['prevnode'] : "0";
} else {
$startid = "0";
$_SESSION = null;
}
$startnode = findBreak($startid,'prev',$loaded[questions]);
$nextnode = findBreak($startid,'next',$loaded[questions]);
$html .= "
";
$html = str_replace("",$html,$template);
//$html = str_replace("","fromQ".$startid,$html); // make it easy to build CSS hooks into this page
echo ($html);
} else { // startid is beyond the end of the questionnaire, so have reached the end
// check validation of stuff from the previous screen
if ($errormsg || $missingflag) {
$html .= ($errormsg) ? "
\n{$errormsg}\n
" : null;
$html .= "
{$prevbtn} {$nextbtn} {$resetlink}
\n";
$html = str_replace("",$html,$template);
echo ($html);
} else {
$dodgy = array("\r","\n","\t");
for ($c=1;$c<=count($loaded['questions']);$c++) {
if (is_array($_SESSION['submitted'][$c])) { // there is data for this question
$outputcell = NULL;
switch ($loaded['questions'][$c]['type']) {
case "single" :
if (is_array($loaded['questions'][$c]['scale'])) { // grid
foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
$answers_array[data][$c][$k] = $v; // store the questionoption and its corresponding scale value
}
} else { // flat single
if (eregi("other_specify",@implode("",$loaded['questions'][$c]['options']))) { // there is an other option for this question
$answers_array[data][$c][code] = $_SESSION['submitted'][$c]['code'];
$answers_array[data][$c][other] = str_replace($dodgy," ",$_SESSION['submitted'][$c]['other']);
} else {
$answers_array[data][$c] = $_SESSION['submitted'][$c]['code'];
}
}
break;
case "dropdown" :
$answers_array[data][$c] = $_SESSION['submitted'][$c]['code'];
break;
case "multi" :
if (is_array($loaded['questions'][$c]['scale'])) { // grid
foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
foreach((array)$v as $scalepoint => $value) { // then look across at each scale point...
$answers_array[data][$c][$k][$scalepoint] = $value; // store the scalepoint within its questionoption, and whether checked or not
}
}
} else { // flat multi - but still need to store each questionoption individually
if (eregi("other_specify",@implode("",$loaded['questions'][$c]['options']))) { // there is an other option for this question
foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
$answers_array[data][$c][$k] = $v; // store the questionoption, and whether checked or not
}
$answers_array[data][$c][_other] = str_replace($dodgy," ",$_SESSION['submitted'][$c][_other]);
} else {
foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
$answers_array[data][$c][$k] = $v; // store the questionoption, and whether checked or not
}
}
}
break;
default : // bigbox/smallbox
$answers_array[data][$c] = str_replace($dodgy," ",$_SESSION['submitted'][$c]['other']);
break;
}
} else { // no data
$answers_array[data][$c] = null;
}
}
$answers_array['uid'] = (strlen($_POST['uid'])>0) ? urldecode($_POST['uid']) : "Anonymous"; // append user id to answers, or say survey was filled in anonymously
// save responses
$savestring = saveResponse2($_REQUEST['sid'],$answers_array);
if ($surveysettings['blockResubmission'] == "TRUE") { // set 30 day cookie to block resubmission
setcookie("$completedSurveyCookie","$_REQUEST[sid]",time()+30*60*60*24);
}
if (@eregi("@",$surveysettings['emailResults'])) { // send the submission to administrator email address as an HTML attachment
// construct HTML
$data_array = @explode("\t",$savestring);
$emailhtml = "
New response submitted
New response submitted: {$loaded['meta']['title']}
";
$emailhtml .= makeRespondentResultsTable($data_array,$_REQUEST['sid']);
$emailhtml .= "";
$dodgy = array(" ","'",",",".");
$now = date("d-M");
$nicefilename = substr(strtolower(str_replace($dodgy,"_",$loaded['meta']['title'])),0,8) . "_" . $answers_array['uid'] . "_data.html";
$protocol = ($_SERVER['HTTPS'] == "on") ? "https://" : "http://"; // if installed on https server
$directory = (substr(dirname($_SERVER['PHP_SELF']),-1) == "/") ? dirname($_SERVER['PHP_SELF']) : dirname($_SERVER['PHP_SELF']) . "/";
$reportlink = $protocol . $_SERVER['HTTP_HOST'] . $directory . "respondentreport.php?sid=".$_SESSION['admin_sid'];
$headers = "From: results@askpeople.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
//$headers .= "Content-Type: multipart/mixed; boundary=pentri12345\r\n";
$headers .= "Content-Type: multipart/alternative; boundary=pentri12345\r\n";
$message .= "--pentri12345\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "Dear AskPeople user,\r\n\r\nA new response to your survey \"{$loaded['meta']['title']}\" has been received.\r\n\r\nThe response is embedded in this HTML email, or can be viewed online at:\r\n<{$reportlink}>\r\n\r\nThanks again for using AskPeople.\r\n\r\nBest regards,\r\nThe AskPeople.co.uk Team\r\n";
$message .= "--pentri12345\r\n";
$message .= "Content-Type: text/html;\r\n";
//$message .= "Content-Disposition: attachment; filename=\"$nicefilename\"\r\n";
$message .= "Content-Transfer-Encoding: 7-bit\r\n";
$message .= "
Dear AskPeople user,
A new response to your survey \"{$loaded['meta']['title']}\" is enclosed.