예제 #1
0
 function generateAnswer($var, $queryobject)
 {
     $variable = $var->getName();
     if ($variable == VARIABLE_LANGUAGE) {
         if (getSurveyLanguageAllowChange() == LANGUAGE_CHANGE_PROGRAMMATIC_ALLOWED) {
             $allowed = explode("~", $this->survey->getAllowedLanguages(getSurveyMode()));
             if (sizeof($allowed) > 1) {
                 $rand = mt_rand(0, sizeof($allowed));
                 return $allowed[$rand];
             }
         }
         return getSurveyLanguage();
     }
     if ($variable == VARIABLE_MODE) {
         if (getSurveyModeAllowChange() == MODE_CHANGE_PROGRAMMATIC_ALLOWED) {
             $allowed = explode("~", $this->survey->getAllowedModes());
             if (sizeof($allowed) > 1) {
                 $rand = mt_rand(0, sizeof($allowed));
                 return $allowed[$rand];
             }
         }
         return getSurveyMode();
     }
     if ($variable == VARIABLE_VERSION) {
         return getSurveyVersion();
     }
     // check for error options
     $noanswer = array();
     if ($var->getIfEmpty() != IF_EMPTY_NOTALLOW) {
         $noanswer[] = "";
     }
     $allowerror = $var->getIfError() != IF_ERROR_NOTALLOW;
     // check for dk/rf/na
     if ($queryobject->getShowDKButton() == BUTTON_YES) {
         $noanswer[] = ANSWER_DK;
     }
     if ($queryobject->getShowRFButton() == BUTTON_YES) {
         $noanswer[] = ANSWER_RF;
     }
     if ($queryobject->getShowNAButton() == BUTTON_YES) {
         $noanswer[] = ANSWER_NA;
     }
     // no answer is an option, then do a random probe
     if (sizeof($noanswer) > 0) {
         // 1/50 chance for an empty answer
         if (mt_rand(1, 50) == 25) {
             return $noanswer[mt_rand(0, sizeof($noanswer))];
             // return a no answer option
         }
     }
     // we return a non-empty answer
     $answertype = $var->getAnswerType();
     switch ($answertype) {
         case ANSWER_TYPE_INTEGER:
             return mt_rand(0, PHP_INT_MAX);
         case ANSWER_TYPE_DOUBLE:
             return mt_rand(0, PHP_INT_MAX);
         case ANSWER_TYPE_RANGE:
             $min = $this->getFill($variable, $var, SETTING_MINIMUM_RANGE);
             if ($min == "") {
                 $min = 0;
             }
             $max = $this->getFill($variable, $var, SETTING_MAXIMUM_RANGE);
             if ($max == "") {
                 $max = PHP_INT_MAX;
             }
             $others = explode(",", $this->getFill($variable, $var, SETTING_OTHER_RANGE));
             $r = mt_rand(1, 50);
             if (sizeof($others) > 0 && $r == 50) {
                 $opt = array();
                 foreach ($others as $o) {
                     if (is_numeric($o)) {
                         $opt[] = $o;
                     }
                 }
                 if (sizeof($opt) > 0) {
                     return $opt[mt_rand(0, sizeof($opt))];
                 } else {
                     return mt_rand($min, $max);
                 }
             } else {
                 return mt_rand($min, $max);
             }
         case ANSWER_TYPE_SLIDER:
             $min = $this->getFill($variable, $var, SETTING_MINIMUM_RANGE);
             if ($min == "") {
                 $min = 0;
             }
             $max = $this->getFill($variable, $var, SETTING_MAXIMUM_RANGE);
             if ($max == "") {
                 $max = PHP_INT_MAX;
             }
             return mt_rand($min, $max);
         case ANSWER_TYPE_STRING:
             $min = $this->getFill($variable, $var, SETTING_MINIMUM_LENGTH);
             if ($min == "") {
                 $min = 5;
             }
             $max = $this->getFill($variable, $var, SETTING_MAXIMUM_LENGTH);
             if ($max == "") {
                 $max = PHP_INT_MAX;
             }
             return $this->generateRandomText($min);
         case ANSWER_TYPE_OPEN:
             $min = $this->getFill($variable, $var, SETTING_MINIMUM_LENGTH);
             if ($min == "") {
                 $min = 5;
             }
             $max = $this->getFill($variable, $var, SETTING_MAXIMUM_LENGTH);
             if ($max == "") {
                 $max = PHP_INT_MAX;
             }
             return $this->generateRandomText($min);
         case ANSWER_TYPE_DROPDOWN:
             /* fall through */
         /* fall through */
         case ANSWER_TYPE_ENUMERATED:
             return $this->generateRandomEnumerated($variable, $var);
         case ANSWER_TYPE_MULTIDROPDOWN:
             /* fall through */
         /* fall through */
         case ANSWER_TYPE_SETOFENUMERATED:
             return $this->generateRandomSetOfEnumerated($variable, $var);
         case ANSWER_TYPE_DATE:
             return date("Y-m-d", $this->generateRandomDateTime($variable, $var));
         case ANSWER_TYPE_TIME:
             return $this->generateRandomDateTime($variable, $var);
         case ANSWER_TYPE_DATETIME:
             return date("Y-m-d H:i:s", $this->generateRandomDateTime($variable, $var));
         case ANSWER_TYPE_CUSTOM:
             return "1";
         case ANSWER_TYPE_SECTION:
             /* fall through */
         /* fall through */
         case ANSWER_TYPE_NONE:
             return "";
             // should not happen, but ok
         // should not happen, but ok
         default:
             return "";
     }
 }
예제 #2
0
    public function showNavBar()
    {
        $returnStr = $this->getHeader();
        //language
        $rgid = $this->engine->getRgid();
        $variablenames = $this->getRealVariables(explode("~", $this->engine->getDisplayed()));
        $variablenamesfull = $this->engine->getDisplayed();
        $template = $this->engine->getTemplate();
        $click = "";
        if ($template != "") {
            $group = $this->engine->getGroup($template);
            $click = $this->engine->replaceFills($group->getClickLanguageChange());
        } else {
            $vars = explode("~", $variablenames);
            $var = $this->engine->getVariableDescriptive($vars[0]);
            $click = $this->engine->replaceFills($var->getClickLanguageChange());
        }
        $click = str_replace("'", "", $click);
        $clickmode = "";
        if ($template != "") {
            $group = $this->engine->getGroup($template);
            $clickmode = $this->engine->replaceFills($group->getClickModeChange());
        } else {
            $vars = explode("~", $variablenames);
            $var = $this->engine->getVariableDescriptive($vars[0]);
            $clickmode = $this->engine->replaceFills($var->getClickModeChange());
        }
        $clickmode = str_replace("'", "", $clickmode);
        // begin language
        global $survey;
        $user = new User($_SESSION['URID']);
        $allowedmodes = $user->getModes();
        $allowedlanguages = explode("~", $user->getLanguages(getSurvey(), getSurveyMode()));
        $default = $survey->getDefaultLanguage();
        $ut = "sysadmin";
        if ($user->getUserType() == USER_TRANSLATOR) {
            $ut = "translator";
            if (!inArray($default, $allowedlanguages)) {
                $allowedlanguages[] = $default;
            }
        } else {
            if ($user->GetUserType() == USER_TESTER) {
                $ut = "tester";
            }
        }
        if (getSurveyModeAllowChange() == MODE_CHANGE_RESPONDENT_ALLOWED) {
            //$allowed = explode("~", $survey->getAllowedModes());
            if (sizeof($allowedmodes) > 1) {
                $template = $this->engine->getTemplate();
                $returnStr .= '<li class="dropdown">';
                $returnStr .= '   <a href="#" class="dropdown-toggle" data-toggle="dropdown">Mode <b class="caret"></b></a>';
                $returnStr .= '<ul class="dropdown-menu" role="menu">';
                $current = getSurveyMode();
                $modes = Common::surveyModes();
                foreach ($modes as $key => $mode) {
                    if (inArray($key, $allowedmodes)) {
                        $check = '';
                        if ($key == $current) {
                            $check = ' <span class="glyphicon glyphicon-ok"></span>';
                        }
                        //$returnStr .= '<li><a href=# onclick=\'document.getElementById("r").value="' . setSessionsParamString(array_merge(array(SESSION_PARAM_LASTACTION => $this->engine->getLastSurveyAction(), SESSION_PARAM_SURVEY => $survey->getSuid(), SESSION_PARAM_PRIMKEY => $this->primkey, SESSION_PARAM_RGID => $rgid, SESSION_PARAM_VARIABLES => $variablenames, SESSION_PARAM_GROUP => $template, SESSION_PARAM_MODE => $current, SESSION_PARAM_VERSION => getSurveyVersion(), SESSION_PARAM_LANGUAGE => getSurveyLanguage(), SESSION_PARAM_TIMESTAMP => time(), SESSION_PARAM_SEID => $this->engine->getSeid(), SESSION_PARAM_MAINSEID => $this->engine->getMainSeid()), array(SESSION_PARAM_NEWMODE => $key))) . '"; document.getElementById("navigation").value="' . NAVIGATION_MODE_CHANGE . '"; $("#form").submit(); \'>' . $mode . $check . '</a></li>';
                        $returnStr .= '<li><a href=# onclick=\'document.getElementById("r").value="' . setSessionsParamString(array_merge(array(SESSION_PARAM_SURVEY => $survey->getSuid(), SESSION_PARAM_PRIMKEY => $this->engine->getPrimaryKey(), SESSION_PARAM_RGID => $rgid, SESSION_PARAM_VARIABLES => $variablenames, SESSION_PARAM_GROUP => $template, SESSION_PARAM_MODE => getSurveyMode(), SESSION_PARAM_LANGUAGE => getSurveyLanguage(), SESSION_PARAM_TEMPLATE => getSurveyTemplate(), SESSION_PARAM_TIMESTAMP => time(), SESSION_PARAM_SEID => $this->engine->getSeid(), SESSION_PARAM_MAINSEID => $this->engine->getMainSeid()), array(SESSION_PARAM_NEWMODE => $key))) . '"; document.getElementById("navigation").value="' . addslashes(Language::buttonUpdate()) . '"; ' . $clickmode . ' document.getElementById("form").submit(); \'>' . $mode . $check . '</a></li>';
                    }
                }
                $returnStr .= '</ul></li>';
            }
        }
        if (getSurveyLanguageAllowChange() == LANGUAGE_CHANGE_RESPONDENT_ALLOWED) {
            //$allowed = explode("~", $survey->getAllowedLanguages(getSurveyMode()));
            if (sizeof($allowedlanguages) > 1) {
                $returnStr .= '<li class="dropdown">';
                $returnStr .= '   <a href="#" class="dropdown-toggle" data-toggle="dropdown">Language <b class="caret"></b></a><ul class="dropdown-menu">';
                $langs = Language::getLanguagesArray();
                //getSurveyLanguages($this->engine->survey);
                foreach ($langs as $lang) {
                    if (inArray($lang["value"], $allowedlanguages)) {
                        $check = '';
                        if ($lang["value"] == getSurveyLanguage()) {
                            $check = ' <span class="glyphicon glyphicon-ok"></span>';
                        }
                        $returnStr .= '<li><a href=# onclick=\'document.getElementById("r").value="' . setSessionsParamString(array_merge(array(SESSION_PARAM_SURVEY => $survey->getSuid(), SESSION_PARAM_PRIMKEY => $this->engine->getPrimaryKey(), SESSION_PARAM_RGID => $rgid, SESSION_PARAM_VARIABLES => $variablenames, SESSION_PARAM_GROUP => $template, SESSION_PARAM_MODE => getSurveyMode(), SESSION_PARAM_LANGUAGE => getSurveyLanguage(), SESSION_PARAM_TEMPLATE => getSurveyTemplate(), SESSION_PARAM_TIMESTAMP => time(), SESSION_PARAM_SEID => $this->engine->getSeid(), SESSION_PARAM_MAINSEID => $this->engine->getMainSeid()), array(SESSION_PARAM_NEWLANGUAGE => $lang["value"]))) . '"; document.getElementById("navigation").value="' . addslashes(Language::buttonUpdate()) . '"; ' . $click . ' document.getElementById("form").submit(); \'>' . $lang["name"] . $check . '</a></li>';
                    }
                }
                $returnStr .= '</ul></li>';
            }
            //end language
        }
        $user = new User($_SESSION['URID']);
        $returnStr .= '<li class="dropdown">
              <a href="#" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown">' . $user->getName() . ' <b class="caret"></b></a>
                 <ul class="dropdown-menu">
										<li class="dropdown-header">' . $this->engine->getPrimaryKey() . '</li>
                                                                                <li class="dropdown-header">' . $variablenamesfull . '</li>';
        $windowopen = 'window.open(\'tester/' . setSessionParams(array('reporturid' => $_SESSION['URID'], 'testpage' => 'report', 'reportsuid' => $this->engine->getSuid(), 'reportseid' => $this->engine->getSeid(), 'reportmainseid' => $this->engine->getMainSeid(), 'reportrgid' => $rgid, 'reportdisplayed' => $variablenames, 'reportlanguage' => getSurveyLanguage(), 'reportmode' => getSurveyMode(), 'reportversion' => getSurveyVersion(), 'reportprimkey' => $this->engine->getPrimarykey())) . '\', \'popupWindow\', \'width=770,height=500,scrollbars=yes,top=100,left=100\'); return false;';
        $javascript = ' onclick="' . $windowopen . '"';
        $returnStr .= '<li><a style="cursor: pointer;" ' . $javascript . '><span class="glyphicon glyphicon-remove-sign"></span> ' . Language::linkReportProblem() . '</a></li>';
        $windowopen = 'window.open(\'tester/' . setSessionParams(array('testpage' => 'watch', 'watchurid' => $_SESSION['URID'], 'watchsuid' => $this->engine->getSuid(), 'watchseid' => $this->engine->getSeid(), 'watchmainseid' => $this->engine->getMainSeid(), 'watchrgid' => $rgid, 'watchdisplayed' => $variablenames, 'watchlanguage' => getSurveyLanguage(), 'watchmode' => getSurveyMode(), 'watchversion' => getSurveyVersion(), 'watchprimkey' => $this->engine->getPrimarykey())) . '\', \'popupWindow\', \'width=770,height=650,scrollbars=yes,top=100,left=100\'); return false;';
        $javascript = ' onclick="' . $windowopen . '"';
        $returnStr .= '<li><a style="cursor: pointer;" ' . $javascript . '><span class="glyphicon glyphicon-zoom-in"></span> ' . Language::linkWatch() . '</a></li>';
        $first = $this->engine->isFirstState();
        if ($first == false || $first == true && $this->engine->getForward() == true) {
            if ($this->engine->getForward() == true) {
                $stateid = $this->engine->getStateId() + 1;
            } else {
                $stateid = $this->engine->getStateId();
            }
            $windowopen = 'window.open(\'tester/' . setSessionParams(array('testpage' => 'jumpback', 'jumpurid' => $_SESSION['URID'], 'jumpsuid' => $this->engine->getSuid(), 'jumpstateid' => $stateid, 'jumpprimkey' => $this->engine->getPrimaryKey())) . '\', \'popupWindow\', \'width=770,height=300,scrollbars=yes,top=100,left=100\'); return false;';
            $javascript = ' onclick="' . $windowopen . '"';
            $returnStr .= '<li><a style="cursor: pointer;" ' . $javascript . '><span class="glyphicon glyphicon-arrow-left"></span> ' . Language::linkJumpBack() . '</a></li>';
        }
        $returnStr .= '<li><a href="' . setSessionParams(array('page' => $ut . '.tools.test', 'suid' => $this->engine->getSuid())) . '&se=' . addslashes(USCIC_SMS) . '"><span class="glyphicon glyphicon-home"></span> ' . Language::linkBackToNubis() . '</a></li>                   
                    <li class="divider"></li>
                   <li><a href="index.php?rs=1&se=2"><span class="glyphicon glyphicon-log-out"></span> ' . Language::linkLogout() . '</a></li>
                 </ul>
             </li>
            </ul>
';
        $returnStr .= '</div><!--/.nav-collapse --> </div> </div>';
        return $returnStr;
    }
예제 #3
0
function getSurveyMode()
{
    /* SMS */
    if ($_SESSION['SYSTEM_ENTRY'] == USCIC_SMS) {
        if (loadvar(SMS_POST_MODE) != '') {
            $l = loadvar(SMS_POST_MODE);
            if (isSurveyMode($l)) {
                $_SESSION['SURVEY_MODE'] = $l;
                return $_SESSION['SURVEY_MODE'];
            }
        }
        if (isset($_SESSION['SURVEY_MODE'])) {
            if (isSurveyMode($_SESSION['SURVEY_MODE'])) {
                return $_SESSION['SURVEY_MODE'];
            }
        }
        $user = new User($_SESSION['URID']);
        $utype = $user->getUserType();
        switch ($utype) {
            case USER_SYSADMIN:
                $default = getDefaultSurveyMode();
                $_SESSION['SURVEY_MODE'] = $default;
                return $default;
            case USER_TRANSLATOR:
                $modes = $user->getModes(getSurvey());
                $default = getDefaultSurveyMode();
                if (inArray($default, $modes)) {
                    $_SESSION['SURVEY_MODE'] = $default;
                    return $default;
                }
                $_SESSION['SURVEY_MODE'] = $modes[0];
                return $modes[0];
            default:
                $default = getDefaultSurveyMode();
                $_SESSION['SURVEY_MODE'] = $default;
                return $default;
        }
    }
    /* SURVEY */
    // check for new mode
    global $engine, $mode;
    /* global mode has been set! (via one of the options below, so no need to repeat) */
    if (isSurveyMode($mode)) {
        return $mode;
    }
    /* get from loadvar (IF ALLOWED) */
    if (getSurveyModeAllowChange() != MODE_CHANGE_NOTALLOWED) {
        $l = loadvarSurvey(POST_PARAM_MODE);
        if (isSurveyMode($l)) {
            $mode = $l;
            $_SESSION["PARAMS"][SESSION_PARAM_MODE] = $l;
            return $mode;
        }
        $l = getFromSessionParams(SESSION_PARAM_NEWMODE);
        if (isSurveyMode($l)) {
            $_SESSION["PARAMS"][SESSION_PARAM_MODE] = $l;
            unset($_SESSION["PARAMS"][SESSION_PARAM_NEWMODE]);
            $mode = $l;
            return $l;
        }
    }
    // check for old mode
    $l = getFromSessionParams(SESSION_PARAM_MODE);
    if (isSurveyMode($l)) {
        $mode = $l;
        return $l;
    }
    // default mode
    $l = getDefaultSurveyMode();
    if (isSurveyMode($l)) {
        $mode = $l;
        return $mode;
    }
    /* everything failed */
    $mode = MODE_CASI;
    return $mode;
}
예제 #4
0
 function displayBody()
 {
     $returnStr = '';
     if (getSurveyModeAllowChange() == MODE_CHANGE_RESPONDENT_ALLOWED) {
         $returnStr .= $this->showMode();
     }
     if (getSurveyLanguageAllowChange() == LANGUAGE_CHANGE_RESPONDENT_ALLOWED) {
         $returnStr .= $this->showLanguage();
     }
     //$returnStr .= '<link href="css/uscic.css" type="text/css" rel="stylesheet">';
     $returnStr .= '<form id="form" role="form" method="post" autocapitalize="off" spellcheck="false" autocorrect="off" autocomplete="off">';
     if ($this->padding) {
         $returnStr .= '<div class="uscic-wrap-with-sms">';
     } else {
         $returnStr .= '<div class="uscic-wrap">';
     }
     //$returnStr .= $header;
     $returnStr .= '<div class="container"><p>';
     $returnStr .= "<input type=hidden id=navigation name=navigation>";
     $returnStr .= '<div id="uscic-mainpanel" class="panel panel-default uscic-mainpanel">';
     $returnStr .= '<div id="uscic-mainbody" class="panel-body">';
     return $returnStr;
 }