Example #1
0
 /**
  * This metod translates the given text and returns it
  * @param $text
  * @return String
  */
 public static function run($text)
 {
     $text = insertansReplace($text);
     $text = tokenReplace($text);
     // ISSUE - how should anonymized be passed to this function?
     return $text;
 }
Example #2
0
     $completed .= "<br /><br />" . "<a class='publicstatisticslink' href='statistics_user.php?sid={$surveyid}' target='_blank'>" . $clang->gT("View the statistics for this survey.") . "</a><br />\n";
 }
 //*****************************************
 //Update the token if needed and send a confirmation email
 if (isset($clienttoken) && $clienttoken) {
     submittokens();
 }
 //Send notification to survey administrator //Thanks to Jeff Clement http://jclement.ca
 if ($thissurvey['sendnotification'] > 0 && $thissurvey['adminemail']) {
     sendsubmitnotification($thissurvey['sendnotification']);
 }
 $_SESSION['finished'] = true;
 $_SESSION['sid'] = $surveyid;
 sendcacheheaders();
 if (!$embedded && isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['surveyls_url']) {
     $url = insertansReplace($thissurvey['surveyls_url']);
     $url = passthruReplace($url, $thissurvey);
     $url = str_replace("{SAVEDID}", $saved_id, $url);
     // to activate the SAVEDID in the END URL
     $url = str_replace("{TOKEN}", $clienttoken, $url);
     // to activate the TOKEN in the END URL
     $url = str_replace("{SID}", $surveyid, $url);
     // to activate the SID in the END URL
     $url = str_replace("{LANG}", $clang->getlangcode(), $url);
     // to activate the LANG in the END URL
     //Automatically redirect the page to the "url" setting for the survey
     session_write_close();
     header("Location: {$url}");
 }
 //if($thissurvey['printanswers'] != 'Y' && $thissurvey['usecookie'] != 'Y' && $tokensexist !=1)
 if ($thissurvey['printanswers'] != 'Y') {
/**
 * getQuotaInformation() returns quota information for the current survey
 * @param string $surveyid - Survey identification number
 * @param string $quotaid - Optional quotaid that restricts the result to a given quota
 * @return array - nested array, Quotas->Members->Fields
 */
function getQuotaInformation($surveyid, $language, $quotaid = 'all')
{
    global $clang, $clienttoken;
    $baselang = GetBaseLanguageFromSurveyID($surveyid);
    $query = "SELECT * FROM " . db_table_name('quota') . ", " . db_table_name('quota_languagesettings') . "\n\t\t   \t  WHERE " . db_table_name('quota') . ".id = " . db_table_name('quota_languagesettings') . ".quotals_quota_id\n\t\t\t  AND sid='{$surveyid}'\n              AND quotals_language='" . $language . "'";
    if ($quotaid != 'all') {
        $query .= " AND id={$quotaid}";
    }
    $result = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
    //Checked
    $quota_info = array();
    $x = 0;
    $surveyinfo = getSurveyInfo($surveyid);
    // Check all quotas for the current survey
    if ($result->RecordCount() > 0) {
        while ($survey_quotas = $result->FetchRow()) {
            //Modify the URL - thanks janokary
            $survey_quotas['quotals_url'] = str_replace("{SAVEDID}", isset($_SESSION['srid']) ? $_SESSION['srid'] : '', $survey_quotas['quotals_url']);
            $survey_quotas['quotals_url'] = str_replace("{SID}", $surveyid, $survey_quotas['quotals_url']);
            $survey_quotas['quotals_url'] = str_replace("{LANG}", $clang->getlangcode(), $survey_quotas['quotals_url']);
            $survey_quotas['quotals_url'] = str_replace("{TOKEN}", $clienttoken, $survey_quotas['quotals_url']);
            array_push($quota_info, array('Name' => $survey_quotas['name'], 'Limit' => $survey_quotas['qlimit'], 'Action' => $survey_quotas['action'], 'Message' => $survey_quotas['quotals_message'], 'Url' => passthruReplace(insertansReplace($survey_quotas['quotals_url']), $surveyinfo), 'UrlDescrip' => $survey_quotas['quotals_urldescrip'], 'AutoloadUrl' => $survey_quotas['autoload_url']));
            $query = "SELECT * FROM " . db_table_name('quota_members') . " WHERE quota_id='{$survey_quotas['id']}'";
            $result_qe = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
            //Checked
            $quota_info[$x]['members'] = array();
            if ($result_qe->RecordCount() > 0) {
                while ($quota_entry = $result_qe->FetchRow()) {
                    $query = "SELECT type, title,gid FROM " . db_table_name('questions') . " WHERE qid='{$quota_entry['qid']}' AND language='{$baselang}'";
                    $result_quest = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
                    //Checked
                    $qtype = $result_quest->FetchRow();
                    $fieldnames = "0";
                    if ($qtype['type'] == "I" || $qtype['type'] == "G" || $qtype['type'] == "Y") {
                        $fieldnames = array(0 => $surveyid . 'X' . $qtype['gid'] . 'X' . $quota_entry['qid']);
                        $value = $quota_entry['code'];
                    }
                    if ($qtype['type'] == "L" || $qtype['type'] == "O" || $qtype['type'] == "!") {
                        $fieldnames = array(0 => $surveyid . 'X' . $qtype['gid'] . 'X' . $quota_entry['qid']);
                        $value = $quota_entry['code'];
                    }
                    if ($qtype['type'] == "M") {
                        $fieldnames = array(0 => $surveyid . 'X' . $qtype['gid'] . 'X' . $quota_entry['qid'] . $quota_entry['code']);
                        $value = "Y";
                    }
                    if ($qtype['type'] == "A" || $qtype['type'] == "B") {
                        $temp = explode('-', $quota_entry['code']);
                        $fieldnames = array(0 => $surveyid . 'X' . $qtype['gid'] . 'X' . $quota_entry['qid'] . $temp[0]);
                        $value = $temp[1];
                    }
                    array_push($quota_info[$x]['members'], array('Title' => $qtype['title'], 'type' => $qtype['type'], 'code' => $quota_entry['code'], 'value' => $value, 'qid' => $quota_entry['qid'], 'fieldnames' => $fieldnames));
                }
            }
            $x++;
        }
    }
    return $quota_info;
}
Example #4
0
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 />';
                }
            }
        }
    }
}