예제 #1
0
                        $java .= "$JSsourceElt != null && document.getElementById('".$idname2."') !=null && parseFloat($JSsourceVal) $cd[6] parseFloat(document.getElementById('".$idname2."').value)";
                    }
                    elseif (preg_match("/^a(.*)b$/",$cd[6],$matchmethods))
                    { // String comparizons
                        $java .= "$JSsourceElt != null && document.getElementById('".$idname2."') !=null && parseFloat($JSsourceVal) ".$matchmethods[1]." parseFloat(document.getElementById('".$idname2."').value)";
                    }
                    else
                    {
                        $java .= "$JSsourceElt != null && document.getElementById('".$idname2."') !=null && parseFloat($JSsourceVal) ".$cd[6]." parseFloat(document.getElementById('".$idname2."').value)";
                    }

                }
                elseif ($thissurvey['anonymized'] == "N" && preg_match('/^{TOKEN:([^}]*)}$/', $cd[3], $comparedtokenattr))
                {
                    if ( isset($_SESSION['token']) &&
                    in_array(strtolower($comparedtokenattr[1]),GetTokenConditionsFieldNames($surveyid)))
                    {
                        $comparedtokenattrValue = GetAttributeValue($surveyid,strtolower($comparedtokenattr[1]),$_SESSION['token']);
                        //if (in_array($cd[4],array("A","B","K","N","5",":")) || (in_array($cd[4],array("Q",";")) && $cqidattributes['other_numbers_only']==1 ))
                        if (in_array($cd[6],array("<","<=",">",">=")))
                        { // // Numerical comparizons
                            $java .= "$JSsourceElt != null && parseFloat($JSsourceVal) $cd[6] parseFloat('".javascript_escape($comparedtokenattrValue)."')";
                        }
                        elseif(preg_match("/^a(.*)b$/",$cd[6],$matchmethods))
                        { // Strings comparizon
                            $java .= "$JSsourceElt != null && $JSsourceVal ".$matchmethods[1]." '".javascript_escape($comparedtokenattrValue)."'";
                        }
                        else
                        {
                            $java .= "$JSsourceElt != null && $JSsourceVal $cd[6] '".javascript_escape($comparedtokenattrValue)."'";
                        }
예제 #2
0
 if (preg_match('/^@([0-9]+X[0-9]+X[^@]+)@/', $cd[3], $comparedfieldname)) {
     // when the right operand is the answer of a previous question
     $sgq_from_sgqa = $_SESSION['fieldnamesInfo'][$comparedfieldname[1]];
     preg_match('/^([0-9]+)X([0-9]+)X([0-9]+)$/', $sgq_from_sgqa, $qidMatched);
     $qid_from_sgq = $qidMatched[3];
     $q2type = $qtypesarray[$sgq_from_sgqa];
     $idname2 = retrieveJSidname(array('', $qid_from_sgq, $comparedfieldname[1], 'Y', $q2type, $sgq_from_sgqa));
     $cqidattributes = getQuestionAttributes($cd[1]);
     if (in_array($cd[4], array("A", "B", "K", "N", "5", ":")) || in_array($cd[4], array("Q", ";")) && $cqidattributes['other_numbers_only'] == 1) {
         // Numerical questions
         $java .= "{$JSsourceElt} != null && document.getElementById('" . $idname2 . "') !=null && parseFloat({$JSsourceVal}) {$cd['6']} parseFloat(document.getElementById('" . $idname2 . "').value)";
     } else {
         $java .= "{$JSsourceElt} != null && document.getElementById('" . $idname2 . "') !=null && {$JSsourceVal} {$cd['6']} document.getElementById('" . $idname2 . "').value";
     }
 } elseif ($thissurvey['private'] == "N" && preg_match('/^{TOKEN:([^}]*)}$/', $cd[3], $comparedtokenattr)) {
     if (isset($_SESSION['token']) && in_array(strtolower($comparedtokenattr[1]), GetTokenConditionsFieldNames($surveyid))) {
         $comparedtokenattrValue = GetAttributeValue($surveyid, strtolower($comparedtokenattr[1]), $_SESSION['token']);
         if (in_array($cd[4], array("A", "B", "K", "N", "5", ":")) || in_array($cd[4], array("Q", ";")) && $cqidattributes['other_numbers_only'] == 1) {
             // Numerical questions
             $java .= "{$JSsourceElt} != null && parseFloat({$JSsourceVal}) {$cd['6']} parseFloat('" . javascript_escape($comparedtokenattrValue) . "')";
         } else {
             $java .= "{$JSsourceElt} != null && {$JSsourceVal} {$cd['6']} '" . javascript_escape($comparedtokenattrValue) . "'";
         }
     } else {
         $java .= " 'impossible to evaluate tokenAttr' == 'tokenAttr'";
     }
 } else {
     if ($cd[6] == 'RX') {
         $java .= "{$JSsourceElt} != null  && match_regex({$JSsourceVal},'{$cd['3']}')";
     } else {
         $cqidattributes = getQuestionAttributes($cd[1]);
/**
 * Retrieves the token attribute value from the related token table
 *
 * @param mixed $surveyid  The survey ID
 * @param mixed $attrName  The token-attribute field name
 * @param mixed $token  The token code
 * @return string The token attribute value (or null on error)
 */
function GetAttributeValue($surveyid, $attrName, $token)
{
    global $dbprefix, $connect;
    $attrName = strtolower($attrName);
    if (!tableExists('tokens_' . $surveyid) || !in_array($attrName, GetTokenConditionsFieldNames($surveyid))) {
        return null;
    }
    $sanitized_token = $connect->qstr($token, get_magic_quotes_gpc());
    $surveyid = sanitize_int($surveyid);
    $query = "SELECT {$attrName} FROM {$dbprefix}tokens_{$surveyid} WHERE token={$sanitized_token}";
    $result = db_execute_num($query);
    $count = $result->RecordCount();
    if ($count != 1) {
        return null;
    } else {
        $row = $result->FetchRow();
        return $row[0];
    }
}
예제 #4
0
function checkconfield($value)
{
    global $dbprefix, $connect, $surveyid, $thissurvey, $qattributes;
    $fieldisdisplayed = true;
    if (!is_array($thissurvey)) {
        $local_thissurvey = getSurveyInfo($surveyid);
    } else {
        $local_thissurvey = $thissurvey;
    }
    // we know the true fieldname $value (for instance SGQA for each checkboxes)
    // and we want to compare it to the values stored in $_SESSION['fieldarray'] which are simple fieldnames
    // ==> We first translate $value to the simple fieldname (let's call it the masterFieldName) from
    //     the $_SESSION['fieldnamesInfo'] translation table
    if (isset($_SESSION['fieldnamesInfo'][$value])) {
        $masterFieldName = $_SESSION['fieldnamesInfo'][$value];
    } else {
        // for token refurl, ipaddr...
        $masterFieldName = 'token';
    }
    $value_qid = 0;
    $value_type = '';
    //$value is the fieldname for the field we are checking for conditions
    foreach ($_SESSION['fieldarray'] as $sfa) {
        // record the qid and question type for future use
        if ($sfa[1] == $masterFieldName) {
            $value_qid = $sfa[0];
            $value_type = $sfa[4];
        }
        // this fieldname '$value' is inside a question identified by the SGQ code '$masterFieldName'
        // we are looping on fieldnames $sfa
        // if $sfa[1] == $masterFieldName, we are processing a fieldname inside the same question as $value
        // check if this question is conditionnal ($sfa[7]): if yes eval conditions
        if ($sfa[1] == $masterFieldName && $sfa[7] == "Y" && isset($_SESSION[$value])) {
            $scenarioquery = "SELECT DISTINCT scenario FROM " . db_table_name("conditions") . " WHERE " . db_table_name("conditions") . ".qid={$sfa['0']} ORDER BY scenario";
            $scenarioresult = db_execute_assoc($scenarioquery);
            $matchfound = 0;
            //$scenario=1;
            //while ($scenario > 0)
            $evalNextScenario = true;
            while ($evalNextScenario === true && ($scenariorow = $scenarioresult->FetchRow())) {
                $aAllCondrows = array();
                $cqval = array();
                $container = array();
                $scenario = $scenariorow['scenario'];
                $currentcfield = "";
                $query = "SELECT " . db_table_name('conditions') . ".*, " . db_table_name('questions') . ".type " . "FROM " . db_table_name('conditions') . ", " . db_table_name('questions') . " " . "WHERE " . db_table_name('conditions') . ".cqid=" . db_table_name('questions') . ".qid " . "AND " . db_table_name('conditions') . ".qid={$sfa['0']} " . "AND " . db_table_name('conditions') . ".scenario={$scenario} " . "AND " . db_table_name('conditions') . ".cfieldname NOT LIKE '{%' " . "ORDER BY " . db_table_name('conditions') . ".qid," . db_table_name('conditions') . ".cfieldname";
                $result = db_execute_assoc($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
                //Checked
                $conditionsfound = $result->RecordCount();
                $querytoken = "SELECT " . db_table_name('conditions') . ".*, '' as type " . "FROM " . db_table_name('conditions') . " " . "WHERE " . " " . db_table_name('conditions') . ".qid={$sfa['0']} " . "AND " . db_table_name('conditions') . ".scenario={$scenario} " . "AND " . db_table_name('conditions') . ".cfieldname LIKE '{%' " . "ORDER BY " . db_table_name('conditions') . ".qid," . db_table_name('conditions') . ".cfieldname";
                $resulttoken = db_execute_assoc($querytoken) or safe_die($querytoken . "<br />" . $connect->ErrorMsg());
                //Checked
                $conditionsfoundtoken = $resulttoken->RecordCount();
                $conditionsfound = $conditionsfound + $conditionsfoundtoken;
                while ($Condrow = $resulttoken->FetchRow()) {
                    $aAllCondrows[] = $Condrow;
                }
                while ($Condrow = $result->FetchRow()) {
                    $aAllCondrows[] = $Condrow;
                }
                foreach ($aAllCondrows as $rows) {
                    if (preg_match("/^\\+(.*)\$/", $rows['cfieldname'], $cfieldnamematch)) {
                        // this condition uses a single checkbox as source
                        $rows['type'] = "+" . $rows['type'];
                        $rows['cfieldname'] = $cfieldnamematch[1];
                    }
                    if ($rows['type'] == "M" || $rows['type'] == "P") {
                        $matchfield = $rows['cfieldname'] . $rows['value'];
                        $matchmethod = $rows['method'];
                        $matchvalue = "Y";
                    } else {
                        $matchfield = $rows['cfieldname'];
                        $matchmethod = $rows['method'];
                        $matchvalue = $rows['value'];
                    }
                    $cqval[] = array("cfieldname" => $rows['cfieldname'], "value" => $rows['value'], "type" => $rows['type'], "matchfield" => $matchfield, "matchvalue" => $matchvalue, "matchmethod" => $matchmethod);
                    if ($rows['cfieldname'] != $currentcfield) {
                        $container[] = $rows['cfieldname'];
                    }
                    $currentcfield = $rows['cfieldname'];
                }
                if ($conditionsfound > 0) {
                    //At least one match must be found for each "$container"
                    $total = 0;
                    foreach ($container as $con) {
                        $conditionCanBeEvaluated = true;
                        $addon = 0;
                        foreach ($cqval as $cqv) {
                            //Go through each condition
                            // Replace @SGQA@ condition values
                            // By corresponding value
                            if (preg_match('/^@([0-9]+X[0-9]+X[^@]+)@/', $cqv["matchvalue"], $targetconditionfieldname)) {
                                if (isset($_SESSION[$targetconditionfieldname[1]])) {
                                    $cqv["matchvalue"] = $_SESSION[$targetconditionfieldname[1]];
                                } else {
                                    $conditionCanBeEvaluated = false;
                                }
                            }
                            // Replace {TOKEN:XXX} condition values
                            // By corresponding value
                            if ($local_thissurvey['private'] == 'N' && preg_match('/^{TOKEN:([^}]*)}$/', $cqv["matchvalue"], $targetconditiontokenattr)) {
                                if (isset($_SESSION['token']) && in_array(strtolower($targetconditiontokenattr[1]), GetTokenConditionsFieldNames($surveyid))) {
                                    $cqv["matchvalue"] = GetAttributeValue($surveyid, strtolower($targetconditiontokenattr[1]), $_SESSION['token']);
                                } else {
                                    $conditionCanBeEvaluated = false;
                                }
                            }
                            // Use == as default operator
                            if (trim($cqv['matchmethod']) == '') {
                                $cqv['matchmethod'] = '==';
                            }
                            if ($cqv['cfieldname'] == $con && $conditionCanBeEvaluated === true) {
                                if (!preg_match("/^{/", $cqv['cfieldname'])) {
                                    if (isset($_SESSION[$cqv['matchfield']])) {
                                        $comparisonLeftOperand = $_SESSION[$cqv['matchfield']];
                                    } else {
                                        $comparisonLeftOperand = null;
                                    }
                                } elseif ($local_thissurvey['private'] == "N" && preg_match('/^{TOKEN:([^}]*)}$/', $cqv['cfieldname'], $sourceconditiontokenattr)) {
                                    if (isset($_SESSION['token']) && in_array(strtolower($sourceconditiontokenattr[1]), GetTokenConditionsFieldNames($surveyid))) {
                                        $comparisonLeftOperand = GetAttributeValue($surveyid, strtolower($sourceconditiontokenattr[1]), $_SESSION['token']);
                                    } else {
                                        $comparisonLeftOperand = null;
                                    }
                                } else {
                                    $comparisonLeftOperand = null;
                                }
                                if ($cqv['matchmethod'] != "RX") {
                                    if (isset($comparisonLeftOperand) && !is_null($comparisonLeftOperand) && eval('if (trim($comparisonLeftOperand) ' . $cqv['matchmethod'] . ' trim($cqv["matchvalue"]) ) {return true;} else {return false;}')) {
                                        //plug successful matches into appropriate container
                                        $addon = 1;
                                    }
                                } elseif (isset($comparisonLeftOperand) && !is_null($comparisonLeftOperand) && preg_match('/' . $cqv["matchvalue"] . '/', $comparisonLeftOperand)) {
                                    $addon = 1;
                                }
                            }
                        }
                        if ($addon == 1) {
                            $total++;
                        }
                    }
                    if ($total == count($container)) {
                        $matchfound = 1;
                        $evalNextScenario = false;
                        // Don't look for other scenario's.
                    }
                    unset($cqval);
                    unset($container);
                } else {
                    //Curious there is no condition for this question in this scenario
                    // this is not a normal behaviour, but I propose to defaults to a
                    // condition-matched state in this case
                    $matchfound = 1;
                    $evalNextScenario = false;
                }
            }
            // while ($scenario)
            if ($matchfound == 0) {
                //If this is not a "moveprev" then
                // Reset the value in SESSION
                //if(isset($move) && $move != "moveprev")
                //{
                $_SESSION[$value] = "";
                $fieldisdisplayed = false;
                //}
            }
        }
    }
    if ($value_qid != 0) {
        // not token masterFieldname
        $value_qa = getQuestionAttributes($value_qid, $value_type);
    }
    if ($fieldisdisplayed === true && isset($value_qa) && (isset($value_qa['array_filter']) && trim($value_qa['array_filter']) != '' || isset($value_qa['array_filter_exclude']) && trim($value_qa['array_filter_exclude']) != '')) {
        // check if array_filter//array_filter_exclude have hidden the field
        $value_code = preg_replace("/{$masterFieldName}(.*)/", "\$1", $value);
        //If this question is a multi-flexible, the value_code will be both the array_filter value
        // (at the beginning) and then a labelset value after an underscore
        // ie: 2_1 for answer code=2 and labelset code=1 then 2_2 for answer_code=2 and
        // labelset code=2. So for these question types we need to split it again at the underscore!
        // 1. Find out if this is question type ":" or ";"
        if ($value_type == ";" || $value_type == ":") {
            list($value_code, $value_label) = explode("_", $value_code);
        }
        if (isset($value_qa['array_filter_exclude'])) {
            $arrayfilterXcludes_selected_codes = getArrayFilterExcludesForQuestion($value_qid);
            if ($arrayfilterXcludes_selected_codes !== false && in_array($value_code, $arrayfilterXcludes_selected_codes)) {
                $fieldisdisplayed = false;
            }
        } elseif (isset($value_qa['array_filter'])) {
            $arrayfilter_selected_codes = getArrayFiltersForQuestion($value_qid);
            if ($arrayfilter_selected_codes !== false && !in_array($value_code, $arrayfilter_selected_codes)) {
                $fieldisdisplayed = false;
            }
        }
    }
    return $fieldisdisplayed;
}
예제 #5
0
/**
* Retrieves the token attribute value from the related token table
*
* @param mixed $surveyid  The survey ID
* @param mixed $attrName  The token-attribute field name
* @param mixed $token  The token code
* @return string The token attribute value (or null on error)
*/
function GetAttributeValue($surveyid, $attrName, $token)
{
    global $dbprefix, $connect;
    $attrName = strtolower($attrName);
    if ($attrName == 'callattempts' || $attrName == 'onappointment' || $attrName == 'perccomplete' || $attrName == 'messagesleft') {
        include_once "quexs.php";
        $quexs_operator_id = get_operator_id();
        $quexs_case_id = get_case_id($quexs_operator_id);
        if ($quexs_case_id) {
            if ($attrName == 'callattempts') {
                return get_call_attempts($quexs_case_id);
            } else {
                if ($attrName == 'onappointment') {
                    return is_on_appointment($quexs_case_id, $quexs_operator_id);
                } else {
                    if ($attrName == 'perccomplete') {
                        return get_percent_complete($quexs_case_id);
                    } else {
                        if ($attrName == 'messagesleft') {
                            return get_messages_left($quexs_case_id);
                        }
                    }
                }
            }
        } else {
            return 0;
        }
    } else {
        if (!tableExists('tokens_' . $surveyid) || !in_array($attrName, GetTokenConditionsFieldNames($surveyid))) {
            return null;
        }
    }
    $sanitized_token = $connect->qstr($token, get_magic_quotes_gpc());
    $surveyid = sanitize_int($surveyid);
    $query = "SELECT {$attrName} FROM {$dbprefix}tokens_{$surveyid} WHERE token={$sanitized_token}";
    $result = db_execute_num($query);
    $count = $result->RecordCount();
    if ($count != 1) {
        return null;
    } else {
        $row = $result->FetchRow();
        return $row[0];
    }
}
예제 #6
0
                        $newjava .= "(parseFloat($JSsourceVal) $cd[6] parseFloat(document.getElementById('$idname2').value))";
                    }
                    elseif(preg_match("/^a(.*)b$/",$cd[6],$matchmethods))
                    { // String comparizons
                        $newjava .= "($JSsourceVal ".$matchmethods[1]." document.getElementById('$idname2').value)";
                    }
                    else
                    {
                        $newjava .= "($JSsourceVal $cd[6] document.getElementById('$idname2').value)";
                    }

                } // end target @SGQA@
                elseif ($thissurvey['anonymized'] == "N" && preg_match('/^{TOKEN:([^}]*)}$/', $cd[3], $targetconditiontokenattr))
                {
                    if ( isset($_SESSION['token']) &&
                    in_array(strtolower($targetconditiontokenattr[1]),GetTokenConditionsFieldNames($surveyid)))
                    {
                        $cvalue=GetAttributeValue($surveyid,strtolower($targetconditiontokenattr[1]),$_SESSION['token']);
                        if ($conditionSourceOnPreviousPage === false)
                        {
                            if (in_array($cd[4],array("A","B","K","N","5",":"))  || (in_array($cd[4],array("Q",";")) && $cqidattributes['numbers_only']==1))
                            {
                                $newjava .= "parseFloat($JSsourceVal) $cd[6] parseFloat('".javascript_escape($cvalue)."')";
                            }
                            else
                            {
                                //$newjava .= "document.getElementById('$idname').value $cd[6] '".javascript_escape($cvalue)."'";
                                $newjava .= "$JSsourceVal $cd[6] '".javascript_escape($cvalue)."'";
                            }
                        }
                        else