コード例 #1
0
/**
 * Replace placeholders in a string with data for this case/operator
 * 
 * @param string $string The string 
 * @param int $operator_id The operator id
 * @param int $case_id The case id
 * @return string The string with replaced text
 *
 */
function template_replace($string, $operator_id, $case_id)
{
    $respondent_id = get_respondent_id(get_call_attempt($operator_id, false));
    while (stripos($string, "{Respondent:") !== false) {
        $answreplace = substr($string, stripos($string, "{Respondent:"), stripos($string, "}", stripos($string, "{Respondent:")) - stripos($string, "{Respondent:") + 1);
        $answreplace2 = substr($answreplace, 12, stripos($answreplace, "}", stripos($answreplace, "{Respondent:")) - 12);
        $answreplace3 = get_respondent_variable($answreplace2, $respondent_id);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    while (stripos($string, "{Operator:") !== false) {
        $answreplace = substr($string, stripos($string, "{Operator:"), stripos($string, "}", stripos($string, "{Operator:")) - stripos($string, "{Operator:") + 1);
        $answreplace2 = substr($answreplace, 10, stripos($answreplace, "}", stripos($answreplace, "{Operator:")) - 10);
        $answreplace3 = get_operator_variable($answreplace2, $operator_id);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    while (stripos($string, "{Sample:") !== false) {
        $answreplace = substr($string, stripos($string, "{Sample:"), stripos($string, "}", stripos($string, "{Sample:")) - stripos($string, "{Sample:") + 1);
        $answreplace2 = substr($answreplace, 8, stripos($answreplace, "}", stripos($answreplace, "{Sample:")) - 8);
        $answreplace3 = get_sample_variable($answreplace2, $case_id);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    while (stripos($string, "{PeriodOfDay") !== false) {
        $answreplace = substr($string, stripos($string, "{PeriodOfDay"), stripos($string, "}", stripos($string, "{PeriodOfDay")) - stripos($string, "{PeriodOfDay") + 1);
        $answreplace3 = get_period_of_day($respondent_id);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    return $string;
}
コード例 #2
0
ファイル: quexs.php プロジェクト: ddrmoscow/queXS
/**
 * Replace placeholders in a string with data for this case/operator
 * 
 * @param string $string The string 
 * @param int $operator_id The operator id
 * @param int $case_id The case id
 * @return string The string with replaced text
 *
 */
function quexs_template_replace($string)
{
    $operator_id = get_operator_id();
    $case_id = get_case_id($operator_id);
    $respondent_id = get_respondent_id($case_id, $operator_id);
    while (stripos($string, "{Respondent:") !== false) {
        $answreplace = substr($string, stripos($string, "{Respondent:"), stripos($string, "}", stripos($string, "{Respondent:")) - stripos($string, "{Respondent:") + 1);
        $answreplace2 = substr($answreplace, 12, stripos($answreplace, "}", stripos($answreplace, "{Respondent:")) - 12);
        $answreplace3 = get_respondent_variable($answreplace2, $respondent_id);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    while (stripos($string, "{Operator:") !== false) {
        $answreplace = substr($string, stripos($string, "{Operator:"), stripos($string, "}", stripos($string, "{Operator:")) - stripos($string, "{Operator:") + 1);
        $answreplace2 = substr($answreplace, 10, stripos($answreplace, "}", stripos($answreplace, "{Operator:")) - 10);
        $answreplace3 = get_operator_variable($answreplace2, $operator_id);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    while (stripos($string, "{Sample:") !== false) {
        $answreplace = substr($string, stripos($string, "{Sample:"), stripos($string, "}", stripos($string, "{Sample:")) - stripos($string, "{Sample:") + 1);
        $answreplace2 = substr($answreplace, 8, stripos($answreplace, "}", stripos($answreplace, "{Sample:")) - 8);
        $answreplace3 = get_sample_variable($answreplace2, $case_id);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    while (stripos($string, "{Outcome:") !== false) {
        $answreplace = substr($string, stripos($string, "{Outcome:"), stripos($string, "}", stripos($string, "{Outcome:")) - stripos($string, "{Outcome:") + 1);
        $answreplace2 = substr($answreplace, 9, stripos($answreplace, "}", stripos($answreplace, "{Outcome:")) - 9);
        $answreplace3 = get_outcome_variable($answreplace2);
        $string = str_replace($answreplace, $answreplace3, $string);
    }
    while (stripos($string, "{CALLATTEMPTS}") !== false) {
        $call_attempts = get_call_attempts($case_id);
        $string = str_ireplace("{CALLATTEMPTS}", $call_attempts, $string);
    }
    while (stripos($string, "{RESPONDENTSELECTIONURL}") !== false) {
        $url = get_respondent_selection_url();
        $string = str_ireplace("{RESPONDENTSELECTIONURL}", $url, $string);
    }
    while (stripos($string, "{ONAPPOINTMENT}") !== false) {
        $on_appointment = is_on_appointment($case_id, $operator_id);
        $str = T_("Not on an appointment");
        if ($on_appointment) {
            $str = T_("On an appointment");
        }
        $string = str_ireplace("{ONAPPOINTMENT}", $str, $string);
    }
    if (stripos($string, "{PERIODOFDAY}") !== false) {
        $string = str_ireplace("{PERIODOFDAY}", get_period_of_day($respondent_id), $string);
    }
    if (stripos($string, "{APPOINTMENTDATE}") !== false) {
        $string = str_ireplace("{APPOINTMENTDATE}", get_appointment_date($respondent_id), $string);
    }
    if (stripos($string, "{APPOINTMENTTIME}") !== false) {
        $string = str_ireplace("{APPOINTMENTTIME}", get_appointment_time($respondent_id), $string);
    }
    if (stripos($string, "{APPOINTMENTNUMBER}") !== false) {
        $string = str_ireplace("{APPOINTMENTNUMBER}", get_appointment_number($respondent_id), $string);
    }
    if (stripos($string, "{PERCCOMPLETE}") !== false) {
        $string = str_ireplace("{PERCCOMPLETE}", round(get_percent_complete($case_id), 0), $string);
    }
    return $string;
}
コード例 #3
0
ファイル: qanda.php プロジェクト: ddrmoscow/queXS
function do_multipleshorttext($ia)
{
    global $dbprefix, $clang, $thissurvey;
    $answer = '';
    $qidattributes = getQuestionAttributes($ia[0], $ia[4]);
    if ($qidattributes['numbers_only'] == 1) {
        $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']);
        $sSeperator = $sSeperator['seperator'];
        $checkconditionFunction = "fixnum_checkconditions";
    } else {
        $checkconditionFunction = "checkconditions";
    }
    if (intval(trim($qidattributes['maximum_chars'])) > 0) {
        // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
        $maximum_chars = intval(trim($qidattributes['maximum_chars']));
        $maxlength = "maxlength='{$maximum_chars}' ";
    } else {
        $maxlength = "";
    }
    if (trim($qidattributes['text_input_width']) != '') {
        $tiwidth = $qidattributes['text_input_width'];
    } else {
        $tiwidth = 20;
    }
    if (trim($qidattributes['prefix']) != '') {
        $prefix = $qidattributes['prefix'];
    } else {
        $prefix = '';
    }
    if (trim($qidattributes['suffix']) != '') {
        $suffix = $qidattributes['suffix'];
    } else {
        $suffix = '';
    }
    if ($thissurvey['nokeyboard'] == 'Y') {
        vIncludeKeypad();
        $kpclass = "text-keypad";
    } else {
        $kpclass = "";
    }
    if ($qidattributes['random_order'] == 1) {
        $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia['0']}  AND language='" . $_SESSION['s_lang'] . "' ORDER BY " . db_random();
    } else {
        $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia['0']}  AND language='" . $_SESSION['s_lang'] . "' ORDER BY question_order";
    }
    $ansresult = db_execute_assoc($ansquery);
    //Checked
    $anscount = $ansresult->RecordCount() * 2;
    //$answer .= "\t<input type='hidden' name='MULTI$ia[1]' value='$anscount'>\n";
    $fn = 1;
    $answer_main = '';
    $label_width = 0;
    if ($anscount == 0) {
        $inputnames = array();
        $answer_main .= '	<li>' . $clang->gT('Error: This question has no answers.') . "</li>\n";
    } else {
        if (trim($qidattributes['display_rows']) != '') {
            //question attribute "display_rows" is set -> we need a textarea to be able to show several rows
            $drows = $qidattributes['display_rows'];
            while ($ansrow = $ansresult->FetchRow()) {
                $myfname = $ia[1] . $ansrow['title'];
                if ($ansrow['question'] == "") {
                    $ansrow['question'] = "&nbsp;";
                }
                $quexs_answer = false;
                if (strncasecmp($ansrow['question'], "{SAMPLEUPDATE:", 14) == 0) {
                    $ansrow['question'] = substr($ansrow['question'], 14, -1);
                    //remove token text
                    include_once 'quexs.php';
                    $quexs_operator_id = get_operator_id();
                    $quexs_case_id = get_case_id($quexs_operator_id);
                    if ($quexs_case_id) {
                        $quexs_answer = get_sample_variable($ansrow['question'], $quexs_case_id);
                        $tiwidth = strlen($quexs_answer) + 5;
                        $maxsize = $tiwidth + 255;
                    }
                }
                list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, '', $myfname, "li");
                $answer_main .= "\t{$htmltbody2}\n" . "<label for=\"answer{$myfname}\">{$ansrow['question']}</label>\n" . "\t<span>\n" . $prefix . "\n" . '
				<textarea class="textarea ' . $kpclass . '" name="' . $myfname . '" id="answer' . $myfname . '"
				rows="' . $drows . '" cols="' . $tiwidth . '" ' . $maxlength . ' onkeyup="' . $checkconditionFunction . '(this.value, this.name, this.type);" >';
                if ($label_width < strlen(trim(strip_tags($ansrow['question'])))) {
                    $label_width = strlen(trim(strip_tags($ansrow['question'])));
                }
                if ($quexs_answer !== false) {
                    $answer_main .= $quexs_answer;
                } else {
                    if (isset($_SESSION[$myfname])) {
                        $dispVal = $_SESSION[$myfname];
                        if ($qidattributes['numbers_only'] == 1) {
                            $dispVal = str_replace('.', $sSeperator, $dispVal);
                        }
                        $answer_main .= htmlspecialchars(htmlspecialchars($dispVal));
                    }
                }
                $answer_main .= "</textarea>\n" . $suffix . "\n\t</span>\n" . "\t</li>\n";
                $fn++;
                $inputnames[] = $myfname;
            }
        } else {
            while ($ansrow = $ansresult->FetchRow()) {
                $myfname = $ia[1] . $ansrow['title'];
                if ($ansrow['question'] == "") {
                    $ansrow['question'] = "&nbsp;";
                }
                $quexs_answer = false;
                if (strncasecmp($ansrow['question'], "{SAMPLEUPDATE:", 14) == 0) {
                    $ansrow['question'] = substr($ansrow['question'], 14, -1);
                    //remove token text
                    include_once 'quexs.php';
                    $quexs_operator_id = get_operator_id();
                    $quexs_case_id = get_case_id($quexs_operator_id);
                    if ($quexs_case_id) {
                        $quexs_answer = get_sample_variable($ansrow['question'], $quexs_case_id);
                        $tiwidth = strlen($quexs_answer) + 5;
                        $maxsize = $tiwidth + 255;
                    }
                }
                list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, '', $myfname, "li");
                // color code missing mandatory questions red
                if ($ia[6] == 'Y' && ($_SESSION['step'] == $_SESSION['prevstep'] || $_SESSION['maxstep'] > $_SESSION['step']) && $_SESSION[$myfname] == '') {
                    $ansrow['question'] = "<span class='errormandatory'>{$ansrow['question']}</span>";
                }
                $answer_main .= "\t{$htmltbody2}\n" . "<label for=\"answer{$myfname}\">{$ansrow['question']}</label>\n" . "\t<span>\n" . $prefix . "\n" . '<input class="text ' . $kpclass . '" type="text" size="' . $tiwidth . '" name="' . $myfname . '" id="answer' . $myfname . '" value="';
                if ($label_width < strlen(trim(strip_tags($ansrow['question'])))) {
                    $label_width = strlen(trim(strip_tags($ansrow['question'])));
                }
                if ($quexs_answer !== false) {
                    $answer_main .= $quexs_answer;
                } else {
                    if (isset($_SESSION[$myfname])) {
                        $dispVal = $_SESSION[$myfname];
                        if ($qidattributes['numbers_only'] == 1) {
                            $dispVal = str_replace('.', $sSeperator, $dispVal);
                        }
                        $answer_main .= htmlspecialchars($dispVal, ENT_QUOTES, 'UTF-8');
                    }
                }
                $answer_main .= '" onkeyup="' . $checkconditionFunction . '(this.value, this.name, this.type);" ' . $maxlength . ' />' . "\n" . $suffix . "\n\t</span>\n" . "\t</li>\n";
                $fn++;
                $inputnames[] = $myfname;
            }
        }
    }
    $answer = "<ul>\n" . $answer_main . "</ul>\n";
    return array($answer, $inputnames);
}