Exemplo n.º 1
0
/**
 * This function builds all the required session variables when a survey is first started and
 * it loads any answer defaults from command line or from the table defaultvalues
 * It is called from the related format script (group.php, question.php, survey.php)
 * if the survey has just started.
 * @param int $surveyid
 * @param boolean $preview Defaults to false
 * @return void
 */
function buildsurveysession($surveyid, $preview = false)
{
    Yii::trace('start', 'survey.buildsurveysession');
    global $secerror, $clienttoken;
    global $tokensexist;
    global $move, $rooturl;
    $sLangCode = App()->language;
    $languagechanger = makeLanguageChangerSurvey($sLangCode);
    if (!$preview) {
        $preview = Yii::app()->getConfig('previewmode');
    }
    $thissurvey = getSurveyInfo($surveyid, $sLangCode);
    if ($thissurvey['nokeyboard'] == 'Y') {
        includeKeypad();
        $kpclass = "text-keypad";
    } else {
        $kpclass = '';
    }
    // $thissurvey['template'] already fixed by model : but why put this in session ?
    $_SESSION['survey_' . $surveyid]['templatename'] = $thissurvey['template'];
    $_SESSION['survey_' . $surveyid]['templatepath'] = getTemplatePath($thissurvey['template']) . DIRECTORY_SEPARATOR;
    $sTemplatePath = $_SESSION['survey_' . $surveyid]['templatepath'];
    $oTemplate = Template::model()->getInstance('', $surveyid);
    $sTemplatePath = $oTemplate->path;
    $sTemplateViewPath = $oTemplate->viewPath;
    /**
     * This method has multiple outcomes that virtually do the same thing
     * Possible scenarios/subscenarios are =>
     *   - No token required & no captcha required
     *   - No token required & captcha required
     *       > captcha may be wrong
     *   - token required & captcha required
     *       > token may be wrong/used
     *       > captcha may be wrong
     */
    $scenarios = array("tokenRequired" => $tokensexist == 1, "captchaRequired" => isCaptchaEnabled('surveyaccessscreen', $thissurvey['usecaptcha']) && !isset($_SESSION['survey_' . $surveyid]['captcha_surveyaccessscreen']));
    /**
     *   Set subscenarios depending on scenario outcome
     */
    $subscenarios = array("captchaCorrect" => false, "tokenValid" => false);
    //Check the scenario for token required
    if ($scenarios['tokenRequired']) {
        //Check for the token-validity
        if ($thissurvey['alloweditaftercompletion'] == 'Y') {
            $oTokenEntry = Token::model($surveyid)->findByAttributes(array('token' => $clienttoken));
        } else {
            $oTokenEntry = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $clienttoken));
        }
        $subscenarios['tokenValid'] = !empty($oTokenEntry) && $clienttoken != "";
    } else {
        $subscenarios['tokenValid'] = true;
    }
    //Check the scenario for captcha required
    if ($scenarios['captchaRequired']) {
        //Check if the Captcha was correct
        $loadsecurity = returnGlobal('loadsecurity', true);
        $captcha = Yii::app()->getController()->createAction('captcha');
        $subscenarios['captchaCorrect'] = $captcha->validate($loadsecurity, false);
    } else {
        $subscenarios['captchaCorrect'] = true;
        $loadsecurity = false;
    }
    //RenderWay defines which html gets rendered to the user_error
    // Possibilities are main,register,correct
    $renderCaptcha = "";
    $renderToken = "";
    //Define array to render the partials
    $aEnterTokenData = array();
    $aEnterTokenData['bNewTest'] = false;
    $aEnterTokenData['bDirectReload'] = false;
    $aEnterTokenData['error'] = $secerror;
    $aEnterTokenData['iSurveyId'] = $surveyid;
    $aEnterTokenData['sKpClass'] = $kpclass;
    // ???
    $aEnterTokenData['sLangCode'] = $sLangCode;
    if (isset($_GET['bNewTest']) && $_GET['newtest'] == "Y") {
        $aEnterTokenData['bNewTest'] = true;
    }
    // If this is a direct Reload previous answers URL, then add hidden fields
    if (isset($loadall) && isset($scid) && isset($loadname) && isset($loadpass)) {
        $aEnterTokenData['bDirectReload'] = true;
        $aEnterTokenData['sCid'] = $scid;
        $aEnterTokenData['sLoadname'] = htmlspecialchars($loadname);
        $aEnterTokenData['sLoadpass'] = htmlspecialchars($loadpass);
    }
    $FlashError = "";
    // Scenario => Captcha required
    if ($scenarios['captchaRequired'] && !$preview) {
        list($renderCaptcha, $FlashError) = testCaptcha($aEnterTokenData, $subscenarios, $surveyid, $loadsecurity);
    }
    // Scenario => Token required
    if ($scenarios['tokenRequired'] && !$preview) {
        //Test if token is valid
        list($renderToken, $FlashError) = testIfTokenIsValid($subscenarios, $thissurvey, $aEnterTokenData, $clienttoken);
    }
    //If there were errors, display through yii->FlashMessage
    if ($FlashError !== "") {
        $aEnterTokenData['errorMessage'] = $FlashError;
    }
    $renderWay = getRenderWay($renderToken, $renderCaptcha);
    $redata = compact(array_keys(get_defined_vars()));
    renderRenderWayForm($renderWay, $redata, $scenarios, $sTemplateViewPath, $aEnterTokenData, $surveyid);
    // Reset all the session variables and start again
    resetAllSessionVariables($surveyid);
    // Multi lingual support order : by REQUEST, if not by Token->language else by survey default language
    if (returnGlobal('lang', true)) {
        $language_to_set = returnGlobal('lang', true);
    } elseif (isset($oTokenEntry) && $oTokenEntry) {
        // If survey have token : we have a $oTokenEntry
        // Can use $oTokenEntry = Token::model($surveyid)->findByAttributes(array('token'=>$clienttoken)); if we move on another function : this par don't validate the token validity
        $language_to_set = $oTokenEntry->language;
    } else {
        $language_to_set = $thissurvey['language'];
    }
    // Always SetSurveyLanguage : surveys controller SetSurveyLanguage too, if different : broke survey (#09769)
    SetSurveyLanguage($surveyid, $language_to_set);
    UpdateGroupList($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
    $totalquestions = Question::model()->getTotalQuestions($surveyid);
    $iTotalGroupsWithoutQuestions = QuestionGroup::model()->getTotalGroupsWithoutQuestions($surveyid);
    // Fix totalquestions by substracting Test Display questions
    $iNumberofQuestions = Question::model()->getNumberOfQuestions($surveyid);
    $_SESSION['survey_' . $surveyid]['totalquestions'] = $totalquestions - (int) reset($iNumberofQuestions);
    // 2. SESSION VARIABLE: totalsteps
    setTotalSteps($surveyid, $thissurvey, $totalquestions);
    // Break out and crash if there are no questions!
    if ($totalquestions == 0 || $iTotalGroupsWithoutQuestions > 0) {
        $redata = compact(array_keys(get_defined_vars()));
        breakOutAndCrash($redata, $sTemplateViewPath, $totalquestions, $iTotalGroupsWithoutQuestions, $thissurvey);
    }
    //Perform a case insensitive natural sort on group name then question title of a multidimensional array
    //    usort($arows, 'groupOrderThenQuestionOrder');
    //3. SESSION VARIABLE - insertarray
    //An array containing information about used to insert the data into the db at the submit stage
    //4. SESSION VARIABLE - fieldarray
    //See rem at end..
    if ($tokensexist == 1 && $clienttoken) {
        $_SESSION['survey_' . $surveyid]['token'] = $clienttoken;
    }
    if ($thissurvey['anonymized'] == "N") {
        $_SESSION['survey_' . $surveyid]['insertarray'][] = "token";
    }
    $qtypes = getQuestionTypeList('', 'array');
    $fieldmap = createFieldMap($surveyid, 'full', true, false, $_SESSION['survey_' . $surveyid]['s_lang']);
    //$seed = ls\mersenne\getSeed($surveyid, $preview);
    // Randomization groups for groups
    list($fieldmap, $randomized1) = randomizationGroup($surveyid, $fieldmap, $preview);
    // Randomization groups for questions
    list($fieldmap, $randomized2) = randomizationQuestion($surveyid, $fieldmap, $preview);
    $randomized = $randomized1 || $randomized2;
    if ($randomized === true) {
        $fieldmap = finalizeRandomization($fieldmap);
        $_SESSION['survey_' . $surveyid]['fieldmap-' . $surveyid . $_SESSION['survey_' . $surveyid]['s_lang']] = $fieldmap;
        $_SESSION['survey_' . $surveyid]['fieldmap-' . $surveyid . '-randMaster'] = 'fieldmap-' . $surveyid . $_SESSION['survey_' . $surveyid]['s_lang'];
    }
    // TMSW Condition->Relevance:  don't need hasconditions, or usedinconditions
    $_SESSION['survey_' . $surveyid]['fieldmap'] = $fieldmap;
    initFieldArray($surveyid, $fieldmap);
    // Prefill questions/answers from command line params
    prefillFromCommandLine($surveyid);
    if (isset($_SESSION['survey_' . $surveyid]['fieldarray'])) {
        $_SESSION['survey_' . $surveyid]['fieldarray'] = array_values($_SESSION['survey_' . $surveyid]['fieldarray']);
    }
    //Check if a passthru label and value have been included in the query url
    checkPassthruLabel($surveyid, $preview, $fieldmap);
    Yii::trace('end', 'survey.buildsurveysession');
    //traceVar($_SESSION['survey_' . $surveyid]);
}
Exemplo n.º 2
0
/**
 * Output Conditional Submission/Update JavaScript validation.
 * @since 2.2.0
 * @version 2.2.0
 * @return void
 */
function submit_valid_output($sub_type)
{
    global $eID, $hc_cfg, $hc_lang_submit, $hc_lang_core, $hc_time;
    echo '
	<script src="' . CalRoot . '/inc/javascript/validation.js"></script>
	<script src="' . CalRoot . '/inc/lang/' . $_SESSION['LangSet'] . '/popCal.js"></script>
	<script src="' . CalRoot . '/inc/javascript/DateSelect.js"></script>
	<script>
	//<!--
	var calx = new CalendarPopup("dsCal");
	calx.showNavigationDropdowns();
	calx.setCssPrefix("hc_");
	calx.offsetX = 30;
	calx.offsetY = -5;

	function toggleMe(who){who.style.display == "none" ? who.style.display = "block":who.style.display = "none";return false;}
	function chngClock(obj,inc,max){if(obj.disabled == false){var val = (!isNaN(obj.value)) ? parseInt(obj.value,10):0;val += inc;if(max == 59){if(val > max) val = 0;if(val < 0) val = max + 1 - Math.abs(val);} else {if(val > max) val = ' . $hc_time['minHr'] . ';if(val < ' . $hc_time['minHr'] . ') val = max;}obj.value = (val < 10) ? "0" + val : val;}}
	function togOverride(){
		var inputs = (document.getElementById("overridetime").checked) ? true : false;
		document.getElementById("startTimeHour").disabled = inputs;
		document.getElementById("startTimeMins").disabled = inputs;
		document.getElementById("ignoreendtime").disabled = inputs;
		document.getElementById("specialtimeall").disabled = (inputs == true) ? false : true;
		if(' . $hc_time['input'] . ' == 12)
			document.getElementById("startTimeAMPM").disabled = inputs;
		if(document.getElementById("ignoreendtime").checked || inputs)
			togEndTime(true);
		else
			togEndTime(false);
	}
	function togEndTime(disable){
		document.getElementById("endTimeHour").disabled = disable;
		document.getElementById("endTimeMins").disabled = disable;
		if(' . $hc_time['input'] . ' == 12)
			document.getElementById("endTimeAMPM").disabled = disable;
	}
	function chkDate(){
		var err = "";
		err += reqField(document.getElementById("eventDate"),"' . $hc_lang_submit['Valid23'] . '\\n");
		err += validDate(document.getElementById("eventDate"),"' . $hc_cfg[51] . '","' . $hc_lang_submit['Valid24'] . ' ' . strtoupper($hc_cfg[51]) . '\\n");
		err += validDateBefore("' . strftime($hc_cfg[24], strtotime(SYSDATE)) . '",document.getElementById("eventDate").value,"' . $hc_cfg[51] . '","' . $hc_lang_submit['Valid20'] . '\\n");
		return err;
	}
	function togRegistration(){
		var regChk = document.getElementById("rsvp_type").value; 
		document.getElementById("rsvp_space").disabled = (regChk == 1) ? false : true;
		document.getElementById("openDate").disabled = (regChk == 1) ? false : true;
		document.getElementById("closeDate").disabled = (regChk == 1) ? false : true;
		document.getElementById("rsvpEmail").disabled = (regChk == 1) ? false : true;
		document.getElementById("rsvp").style.display = (regChk == 1) ? "block" : "none";
	}';
    if ($sub_type == 0) {
        submit_valid();
    } else {
        submit_update_valid();
    }
    testCaptcha();
    include_once HCPATH . '/inc/javascript/locations.php';
    echo '
	//-->
	</script>';
}