$phparray = json_decode($idrow[$fnames[$i][0]], true); if (isset($phparray[$index])) { if ($metadata === "size") { $browseoutput .= rawurldecode((int) $phparray[$index][$metadata] . " KB"); } else { if ($metadata === "name") { $browseoutput .= "<a href='#' onclick=\" " . get2post($scriptname . '?action=browse&subaction=all&downloadindividualfile=' . $phparray[$index][$metadata] . '&fieldname=' . $fnames[$i][0] . '&id=' . $id . '&sid=' . $surveyid) . "\" >" . rawurldecode($phparray[$index][$metadata]) . "</a>"; } else { $browseoutput .= rawurldecode($phparray[$index][$metadata]); } } } else { $browseoutput .= ""; } } else { $browseoutput .= htmlspecialchars(strip_tags(strip_javascript(getextendedanswer($fnames[$i][0], $idrow[$fnames[$i][0]], '', $dateformatdetails['phpdate']))), ENT_QUOTES); } } $browseoutput .= "</td>\n\t</tr>\n"; $highlight = !$highlight; } } $browseoutput .= "</table>\n"; } elseif ($subaction == "all") { /** * fnames is used as informational array * it containts * $fnames[] = array(<dbfieldname>, <some strange title>, <questiontext>, <group_id>, <questiontype>); */ $browseoutput .= "\n<script type='text/javascript'>\n var strdeleteconfirm='" . $clang->gT('Do you really want to delete this response?', 'js') . "';\n var strDeleteAllConfirm='" . $clang->gT('Do you really want to delete all marked responses?', 'js') . "';\n var noFilesSelectedForDeletion = '" . $clang->gT('Please select at least one file for deletion', 'js') . "';\n var noFilesSelectedForDnld = '" . $clang->gT('Please select at least one file for download', 'js') . "';\n </script>\n"; if (!isset($_POST['sql'])) {
/** * Creates an array with details on a particular response for display purposes * Used in Print answers (done), Detailed response view (Todo:)and Detailed admin notification email (done) * * @param mixed $iSurveyID * @param mixed $iResponseID * @param mixed $sLanguageCode */ function aGetFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode) { global $connect; $aFieldMap = createFieldMap($iSurveyID, 'full', false, false, $sLanguageCode); //Get response data $idquery = "SELECT * FROM " . db_table_name('survey_' . $iSurveyID) . " WHERE id=" . $iResponseID; $idrow = $connect->GetRow($idquery) or safe_die("Couldn't get entry<br />\n{$idquery}<br />\n" . $connect->ErrorMsg()); //Checked $aResultTable = array(); $oldgid = 0; $oldqid = 0; foreach ($aFieldMap as $sKey => $fname) { if (!empty($fname['qid'])) { $attributes = getQuestionAttributes($fname['qid']); if (getQuestionAttributeValue($attributes, 'hidden') == 1) { continue; } } $question = $fname['question']; $subquestion = ''; if (isset($fname['gid']) && !empty($fname['gid'])) { //Check to see if gid is the same as before. if not show group name if ($oldgid !== $fname['gid']) { $oldgid = $fname['gid']; $aResultTable['gid_' . $fname['gid']] = array($fname['group_name']); } } if (isset($fname['qid']) && !empty($fname['qid'])) { if ($oldqid !== $fname['qid']) { $oldqid = $fname['qid']; if (isset($fname['subquestion']) || isset($fname['subquestion1']) || isset($fname['subquestion2'])) { $aResultTable['qid_' . $fname['sid'] . 'X' . $fname['gid'] . 'X' . $fname['qid']] = array($fname['question'], '', ''); } else { $answer = getextendedanswer($fname['fieldname'], $idrow[$fname['fieldname']]); $aResultTable[$fname['fieldname']] = array($question, '', $answer); continue; } } } else { $answer = getextendedanswer($fname['fieldname'], $idrow[$fname['fieldname']]); $aResultTable[$fname['fieldname']] = array($question, '', $answer); continue; } if (isset($fname['subquestion'])) { $subquestion = "{$fname['subquestion']}"; } if (isset($fname['subquestion1'])) { $subquestion = "{$fname['subquestion1']}"; } if (isset($fname['subquestion2'])) { $subquestion .= "[{$fname['subquestion2']}]"; } $answer = getextendedanswer($fname['fieldname'], $idrow[$fname['fieldname']]); $aResultTable[$fname['fieldname']] = array('', $subquestion, $answer); } return $aResultTable; }
if (isset($fname['subquestion2'])) { $question .= "[{$fname['subquestion2']}]"; } $printoutput .= "\t<tr>\n" . "<td class='printanswersquestiontext'>{$question}</td>\n" . "<td class='printanswersanswertext'>" . getextendedanswer($fname['fieldname'], $idrow[$fname['fieldname']]) . "</td>\n" . "\t</tr>\n"; if (isset($_POST['printableexport'])) { if (isset($fname['subquestion'])) { $question .= " [{$fname['subquestion']}]"; } if (isset($fname['subquestion1'])) { $question .= " [{$fname['subquestion1']}]"; } if (isset($fname['subquestion2'])) { $question .= " [{$fname['subquestion2']}]"; } if (isset($_POST['printableexport'])) { $pdf->intopdf(FlattenText($question, true) . ": " . FlattenText(getextendedanswer($fname['fieldname'], $idrow[$fname['fieldname']]), true), '', false); $pdf->ln(2); } } } else { if ($oldqid !== $fname['qid']) { $oldqid = $fname['qid']; } } } } $printoutput .= "</table>\n"; if (isset($_POST['printableexport'])) { // IE6 Header-Cache fix // Wenn der IE 6 das pdf file nicht erkennt, liegts am IE6 Nutzer //(zu doof, der Browser kennt keine pdf's oder kein reader ist installiert)
function sendsubmitnotification($sendnotification) { global $thissurvey, $debug; global $dbprefix, $clang, $emailcharset; global $sitename, $homeurl, $surveyid, $publicurl, $maildebug, $tokensexist; $subject = sprintf($clang->gT("Response submission for survey %s", "unescaped"), $thissurvey['name']); $message = $clang->gT("Hello!", "unescaped") . "\n" . $clang->gT("A new response was submitted for your survey.", "unescaped") . "\n\n"; if ($thissurvey['allowsave'] == "Y" && isset($_SESSION['scid'])) { $message .= $clang->gT("Click the following link to reload the survey:", "unescaped") . "\n"; $message .= " {$publicurl}/index.php?sid={$surveyid}&loadall=reload&scid=" . $_SESSION['scid'] . "&loadname=" . urlencode($_SESSION['holdname']) . "&loadpass="******"\n\n"; } $message .= $clang->gT("Click the following link to see the individual response:", "unescaped") . "\n" . " {$homeurl}/admin.php?action=browse&sid={$surveyid}&subaction=id&id=" . $_SESSION['srid'] . "\n\n" . $clang->gT("Click the following link to edit the individual response:", "unescaped") . "\n" . " {$homeurl}/admin.php?action=dataentry&sid={$surveyid}&subaction=edit&surveytable=survey_{$surveyid}&id=" . $_SESSION['srid'] . "\n\n" . $clang->gT("View statistics by clicking here:", "unescaped") . "\n" . " {$homeurl}/admin.php?action=statistics&sid={$surveyid}\n\n"; $emailresponseto = null; if (!empty($thissurvey['emailresponseto'])) { if (isset($_SESSION['token']) && $_SESSION['token'] != '' && db_tables_exist($dbprefix . 'tokens_' . $surveyid)) { //Gather token data for tokenised surveys $_SESSION['thistoken'] = getTokenData($surveyid, $_SESSION['token']); } elseif ($_SESSION['insertarray'][0] == 'token') { unset($_SESSION['insertarray'][0]); } //Make an array of email addresses to send to if ($erts = explode(";", $thissurvey['emailresponseto'])) { foreach ($erts as $ert) { $ert = insertansReplace($ert); $ert = tokenReplace($ert); $emailresponsetos[] = $ert; } } else { $ert = $thissurvey['emailresponseto']; $ert = insertansReplace($ert); $ert = tokenReplace($ert); $emailresponsetos[] = $ert; } //Now check each of the email addresses that they are valid before creating/adding to the $emailresponseto array foreach ($emailresponsetos as $ert) { if (validate_email($ert)) { $emailresponseto[] = $ert; } } } $results = ""; if ($sendnotification > 1 || $emailresponseto) { // Send results $results = "----------------------------\n"; $prevquestion = ''; $ssubquestion = ''; $fieldmap = createFieldMap($surveyid, 'full'); foreach ($_SESSION['insertarray'] as $value) { $sQuestion = strip_tags($fieldmap[$value]['question']); if (isset($fieldmap[$value]['subquestion2'])) { $ssubquestion = "[" . strip_tags($fieldmap[$value]['subquestion1']) . "] [" . strip_tags($fieldmap[$value]['subquestion2']) . "]"; } elseif (isset($fieldmap[$value]['subquestion'])) { $ssubquestion = strip_tags($fieldmap[$value]['subquestion']); } else { $ssubquestion = ''; } if ($prevquestion != $sQuestion) { $prevquestion = $sQuestion; $questiontitle = FlattenText($sQuestion, true, $emailcharset); $results .= "\n{$questiontitle}: "; if ($ssubquestion != '') { $results .= "\n"; } } if ($ssubquestion != '') { $answeroption = FlattenText($ssubquestion, true, $emailcharset); $results .= "\t[{$answeroption}]: "; } if ($fieldmap[$value]['type'] == "T" || $fieldmap[$value]['type'] == "U") { $results .= "\r\n"; if (isset($_SESSION[$value])) { foreach (explode("\n", $_SESSION[$value]) as $line) { $results .= "\t" . FlattenText($line, true, $emailcharset); $results .= "\n"; } } } elseif (isset($_SESSION[$value])) { $results .= FlattenText(getextendedanswer($value, $_SESSION[$value]), true, $emailcharset); $results .= "\n"; } else { $results .= "\n"; } } $results .= "\n\n----------------------------\n\n"; } $message .= $results; $message .= "LimeSurvey"; if ($recips = explode(";", $thissurvey['adminemail'])) { $from = $thissurvey['adminname'] . ' <' . $recips[0] . '>'; foreach ($recips as $rc) { if (!SendEmailMessage($message, $subject, trim($rc), $from, $sitename, false, getBounceEmail($surveyid))) { if ($debug > 0) { echo '<br />Email could not be sent. Reason: ' . $maildebug . '<br/>'; } } } } else { $from = $thissurvey['adminname'] . ' <' . $thissurvey['adminemail'] . '>'; if (!SendEmailMessage($message, $subject, $thissurvey['adminemail'], $from, $sitename, false, getBounceEmail($surveyid))) { if ($debug > 0) { echo '<br />Email could not be sent. Reason: ' . $maildebug . '<br/>'; } } } if ($emailresponseto) { $ertmessage = $clang->gT("This email contains confirmation of the responses you made to the survey") . " " . $thissurvey['name'] . "\n"; $ertmessage .= $results; $ertsubject = $clang->gT("Survey submission confirmation"); foreach ($emailresponseto as $ert) { if (!SendEmailMessage($ertmessage, $ertsubject, $ert, $from, $sitename, false, getBounceEmail($surveyid))) { if ($debug > 0) { echo '<br />Email could not be sent to EmailReponseTo field. Reason: ' . $maildebug . '<br />'; } } } } }
/** This function checks to see if there is an answer saved in the survey session * data that matches the $code. If it does, it returns that data. * It is used when building a questions text to allow incorporating the answer * to an earlier question into the text of a later question. * IE: Q1: What is your name? [Jason] * Q2: Hi [Jason] how are you ? * This function is called from the retriveAnswers function. * * @param mixed $code * @param mixed $phpdateformat The date format in which any dates are shown * @return mixed returns the answerText from session variable corresponding to a question code */ function retrieve_Answer($code, $phpdateformat = null) { //This function checks to see if there is an answer saved in the survey session //data that matches the $code. If it does, it returns that data. //It is used when building a questions text to allow incorporating the answer //to an earlier question into the text of a later question. //IE: Q1: What is your name? [Jason] // Q2: Hi [Jason] how are you ? //This function is called from the retriveAnswers function. global $dbprefix, $connect, $clang; //Find question details if (isset($_SESSION[$code])) { $questiondetails = getsidgidqidaidtype($code); //the getsidgidqidaidtype function is in common.php and returns //a SurveyID, GroupID, QuestionID and an Answer code //extracted from a "fieldname" - ie: 1X2X3a // also returns question type if ($questiondetails['type'] == "M" || $questiondetails['type'] == "P") { $query = "SELECT * FROM {$dbprefix}questions WHERE parent_qid='" . $questiondetails['qid'] . "' AND language='" . $_SESSION['s_lang'] . "'"; $result = db_execute_assoc($query) or safe_die("Error getting answer<br />{$query}<br />" . $connect->ErrorMsg()); //Checked while ($row = $result->FetchRow()) { if (isset($_SESSION[$code . $row['title']]) && $_SESSION[$code . $row['title']] == "Y") { $returns[] = $row['question']; } elseif (isset($_SESSION[$code]) && $_SESSION[$code] == "Y" && $questiondetails['aid'] == $row['title']) { return $row['question']; } } if (isset($_SESSION[$code . "other"]) && $_SESSION[$code . "other"]) { $returns[] = $_SESSION[$code . "other"]; } if (isset($returns)) { $return = implode(", ", $returns); if (strpos($return, ",")) { $return = substr_replace($return, " &", strrpos($return, ","), 1); } } else { $return = $clang->gT("No answer"); } } elseif (!$_SESSION[$code] && $_SESSION[$code] != 0) { $return = $clang->gT("No answer"); } else { $return = getextendedanswer($code, $_SESSION[$code], 'INSERTANS', $phpdateformat); } } else { $return = $clang->gT("Error") . "({$code})"; } return html_escape($return); }