Пример #1
0
if ($thissurvey['anonymized'] == "Y")
{
    echo templatereplace(file_get_contents("$thistpl/privacy.pstpl"))."\n";
}

print <<<END

<!-- JAVASCRIPT FOR CONDITIONAL QUESTIONS -->
<script type='text/javascript'>
<!--

END;
// Find out if there are any array_filter questions in this group
$array_filterqs = getArrayFiltersForGroup($surveyid, "");
$array_filterXqs = getArrayFilterExcludesForGroup($surveyid, "");
$array_filterXqs_cascades = getArrayFilterExcludesCascadesForGroup($surveyid, "");
// Put in the radio button reset javascript for the array filter unselect
if (isset($array_filterqs) && is_array($array_filterqs)) {
    print <<<END

		function radio_unselect(radioObj)
		{
			var radioLength = radioObj.length;
			for(var i = 0; i < radioLength; i++)
			{
				radioObj[i].checked = false;
			}
		}

END;
Пример #2
0
/**
* getArrayFilterExcludesForQuestion($qid) finds out if a question has an array_filter_exclude attribute and what codes where selected on target question
* @return returns an array of codes that were selected else returns false
*/
function getArrayFilterExcludesForQuestion($qid)
{
    static $cascadesCache = array();
    static $cache = array();
    // TODO: Check list_filter values to make sure questions are previous?
    //    $surveyid = Yii::app()->getConfig('sid');
    $surveyid = returnGlobal('sid');
    $qid = sanitize_int($qid);
    if (isset($cache[$qid])) {
        return $cache[$qid];
    }
    $attributes = getQuestionAttributeValues($qid);
    $excludevals = array();
    if (isset($attributes['array_filter_exclude'])) {
        $selected = array();
        $excludevals[] = $attributes['array_filter_exclude'];
        // Get the Value of the Attribute ( should be a previous question's title in same group )
        /* Find any cascades and place them in the $excludevals array*/
        if (!isset($cascadesCache[$surveyid])) {
            $cascadesCache[$surveyid] = getArrayFilterExcludesCascadesForGroup($surveyid, "", "title");
        }
        $array_filterXqs_cascades = $cascadesCache[$surveyid];
        if (isset($array_filterXqs_cascades[$qid])) {
            foreach ($array_filterXqs_cascades[$qid] as $afc) {
                $excludevals[] = array("value" => $afc);
            }
        }
        /* For each $val (question title) that applies to this, check what values exist and add them to the $selected array */
        foreach ($excludevals as $val) {
            foreach (Yii::app()->session['fieldarray'] as $fields) {
                if ($fields[2] == $val) {
                    // we found the target question, now we need to know what the answers were!
                    $fields[0] = sanitize_int($fields[0]);
                    $query = "SELECT title FROM {{questions}} where parent_qid='{$fields[0]}' AND language='" . Yii::app()->session[$surveyid]['s_lang'] . "' order by question_order";
                    $qresult = dbExecuteAssoc($query);
                    //Checked
                    foreach ($qresult->readAll() as $code) {
                        if (isset(Yii::app()->session[$fields[1]])) {
                            if (isset(Yii::app()->session[$fields[1] . $code['title']]) && Yii::app()->session[$fields[1] . $code['title']] == "Y" || Yii::app()->session[$fields[1]] == $code['title']) {
                                array_push($selected, $code['title']);
                            }
                        }
                    }
                    //Now we also need to find out if (a) the question had "other" enabled, and (b) if that was selected
                    $query = "SELECT other FROM {{questions}} where qid='{$fields[0]}'";
                    $qresult = dbExecuteAssoc($query);
                    foreach ($qresult->readAll() as $row) {
                        $other = $row['other'];
                    }
                    if ($other == "Y") {
                        if (Yii::app()->session[$fields[1] . 'other'] != "") {
                            array_push($selected, "other");
                        }
                    }
                }
            }
        }
        if (count($selected) > 0) {
            $cache[$qid] = $selected;
            return $cache[$qid];
        } else {
            $cache[$qid] = false;
            return $cache[$qid];
        }
    }
    $cache[$qid] = false;
    return $cache[$qid];
}
Пример #3
0
/**
 * getArrayFilterExcludesForQuestion($qid) finds out if a question has an array_filter_exclude attribute and what codes where selected on target question
 * @global string $surveyid
 * @global string $gid
 * @global string $dbprefix
 * @return returns an array of codes that were selected else returns false
 */
function getArrayFilterExcludesForQuestion($qid)
{
    static $cascadesCache = array();
    static $cache = array();

    // TODO: Check list_filter values to make sure questions are previous?
    global $surveyid, $dbprefix;
    $qid=sanitize_int($qid);

    if (isset($cache[$qid])) return $cache[$qid];

    $attributes = getQuestionAttributes($qid);
    $excludevals=array();
    if (isset($attributes['array_filter_exclude'])) // We Found a array_filter_exclude attribute
    {
        $selected=array();
        $excludevals[] = $attributes['array_filter_exclude']; // Get the Value of the Attribute ( should be a previous question's title in same group )
        /* Find any cascades and place them in the $excludevals array*/
        if (!isset($cascadesCache[$surveyid])) {
            $cascadesCache[$surveyid] = getArrayFilterExcludesCascadesForGroup($surveyid, "", "title");
        }
        $array_filterXqs_cascades = $cascadesCache[$surveyid];

        if(isset($array_filterXqs_cascades[$qid]))
        {
            foreach($array_filterXqs_cascades[$qid] as $afc)
            {
                $excludevals[]=array("value"=>$afc);

            }
        }
        /* For each $val (question title) that applies to this, check what values exist and add them to the $selected array */
        foreach ($excludevals as $val)
        {
            foreach ($_SESSION['fieldarray'] as $fields) //iterate through every question in the survey
            {
                if ($fields[2] == $val)
                {
                    // we found the target question, now we need to know what the answers were!
                    $fields[0]=sanitize_int($fields[0]);
                    $query = "SELECT title FROM ".db_table_name('questions')." where parent_qid='{$fields[0]}' AND language='".$_SESSION['s_lang']."' order by question_order";
                    $qresult = db_execute_assoc($query);  //Checked
                    while ($code = $qresult->fetchRow())
                    {
                        if (isset($_SESSION[$fields[1]]))
                            if ((isset($_SESSION[$fields[1].$code['title']]) && $_SESSION[$fields[1].$code['title']] == "Y")
                            || $_SESSION[$fields[1]] == $code['title'])
                                array_push($selected,$code['title']);
                    }
                    //Now we also need to find out if (a) the question had "other" enabled, and (b) if that was selected
                    $query = "SELECT other FROM ".db_table_name('questions')." where qid='{$fields[0]}'";
                    $qresult = db_execute_assoc($query);
                    while ($row=$qresult->fetchRow()) {$other=$row['other'];}
                    if($other == "Y")
                    {
                        if($_SESSION[$fields[1].'other'] != "") {array_push($selected, "other");}
                    }
                }
            }
        }
        if(count($selected) > 0)
        {
            $cache[$qid] = $selected;
            return $cache[$qid];
        } else {
            $cache[$qid] = false;
            return $cache[$qid];
        }
    }
    $cache[$qid] = false;
    return $cache[$qid];
}