function showLanguage()
 {
     global $survey;
     $allowed = explode("~", $survey->getAllowedLanguages(getSurveyMode()));
     if (sizeof($allowed) == 1) {
         return "";
     }
     $rgid = $this->engine->getRgid();
     $variablenames = $this->getRealVariables(explode("~", $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);
     $current = getSurveyLanguage();
     $langs = Language::getLanguagesArray();
     foreach ($langs as $key => $lang) {
         if (inArray($lang["value"], $allowed)) {
             $check = '';
             if ($lang["value"] == getSurveyLanguage()) {
                 //              $check = ' <span class="glyphicon glyphicon-ok"></span>';
             } else {
                 $returnStr .= '<button type="button" class="btn btn-sm btn-warning" 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 => getSurveyMode(), SESSION_PARAM_TEMPLATE => getSurveyTemplate(), SESSION_PARAM_VERSION => getSurveyVersion(), SESSION_PARAM_LANGUAGE => $current, 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="' . NAVIGATION_LANGUAGE_CHANGE . '"; ' . $click . ' document.getElementById("form").submit(); \'>' . $lang["name"] . $check . '</button>';
             }
         }
     }
     return $returnStr;
 }
Beispiel #2
0
 function getNextQuestion()
 {
     global $db;
     /* get language */
     $language = getSurveyLanguage();
     // include language
     if (file_exists("language/language" . getSurveyLanguagePostFix($language) . ".php")) {
         require_once 'language' . getSurveyLanguagePostFix($language) . '.php';
         // language
     } else {
         require_once 'language_en.php';
         // fall back on english language  file
     }
     // check if session request already in progress
     if (isset($_SESSION['PREVIOUS_REQUEST_IN_PROGRESS']) && $_SESSION['PREVIOUS_REQUEST_IN_PROGRESS'] == 1) {
         doCommit();
         echo $this->display->showInProgressSurvey();
         doExit();
     } else {
         if ($this->isLocked()) {
             doCommit();
             echo $this->display->showLockedSurvey();
             doExit();
         }
     }
     // lock (we unlock in showQuestion OR doEnd if end of survey
     $this->lock();
     // we are starting/returning to the survey/section OR submit of old form
     $oldform = $this->isOldFormSubmit();
     //echo 'rgid: ' . getFromSessionParams(SESSION_PARAM_RGID) . '----';
     if (getFromSessionParams(SESSION_PARAM_RGID) == '' || $oldform) {
         // returning to the survey
         if ($this->getDisplayed() != "") {
             // completed interview
             if ($this->getDataRecord()->isCompleted()) {
                 /* see what to do on reentry after completion
                  * based on settings of last displayed variable/group
                  */
                 $reentry = AFTER_COMPLETION_NO_REENTRY;
                 $reentry_preload = PRELOAD_REDO_NO;
                 $groupname = $this->getTemplate();
                 $rgid = $this->getRgid();
                 $variablenames = $this->getDisplayed();
                 if ($groupname != "") {
                     $group = $this->getGroup($groupname);
                     $reentry = $group->getAccessReturnAfterCompletionAction();
                     $reentry_preload = $group->getAccessReturnAfterCompletionRedoPreload();
                 } else {
                     $variables = explode("~", $variablenames);
                     $realvariables = explode("~", $this->display->getRealVariables($variables));
                     if (sizeof($realvariables) > 0) {
                         $var = $this->getVariableDescriptive($realvariables[0]);
                         //echo $var->getName();
                         $reentry = $var->getAccessReturnAfterCompletionAction();
                         $reentry_preload = $var->getAccessReturnAfterCompletionRedoPreload();
                     }
                 }
                 if ($reentry == AFTER_COMPLETION_NO_REENTRY) {
                     $this->unlock();
                     doCommit();
                     echo $this->display->showCompletedSurvey();
                     doExit();
                 } else {
                     // set current action to reentry
                     $this->currentaction = ACTION_SURVEY_REENTRY;
                     /* update language, mode and version */
                     $this->setAnswer(VARIABLE_LANGUAGE, $language);
                     $this->setAnswer(VARIABLE_VERSION, getSurveyVersion());
                     $this->setAnswer(VARIABLE_MODE, getSurveyMode());
                     $this->setAnswer(VARIABLE_PLATFORM, $_SERVER['HTTP_USER_AGENT']);
                     $this->setAnswer(VARIABLE_EXECUTION_MODE, getSurveyExecutionMode());
                     $this->setAnswer(VARIABLE_TEMPLATE, getSurveyTemplate());
                     $this->setAnswer(VARIABLE_END, null);
                     /* set interview data as incompleted */
                     $this->getDataRecord()->setToIncomplete();
                     // redoing preloads
                     if ($reentry_preload == PRELOAD_REDO_YES) {
                         //echo 'preloading again';
                         $pd = loadvarSurvey('pd');
                         if ($pd != '') {
                             getSessionParamsPost(loadvarSurvey('pd'), 'PD');
                             foreach ($_SESSION['PD'] as $field => $answer) {
                                 //echo $field . ' set with ' . $answer . '<br/>';
                                 $this->setAnswer($field, $answer);
                             }
                         }
                     }
                     // where are we entering
                     $where = $reentry;
                     //$this->survey->getAccessReturnAfterCompletionAction();
                     // show first question(s) of survey
                     if ($where == AFTER_COMPLETION_FIRST_SCREEN) {
                         /* save data record */
                         $this->getDataRecord()->saveRecord();
                         // get data of current state, which is the last one (with updated preloads if we re-did the preloads)
                         $data = $this->state->getAllData();
                         // remove all states except first one with displayed != "" and anything before that state
                         $this->removeAllStatesExceptFirst();
                         // load the first state
                         $this->loadLastState();
                         // set data from last state to first state
                         $this->state->setAllData($data);
                         //unset($data);
                         // save updated state
                         $this->saveState(false);
                         /* if (language different from state AND not using last known language) OR (mode different from state AND not using last known language) OR (version different from state), then wipe fill texts */
                         if ($this->state->getLanguage() != getSurveyLanguage() && $this->survey->getReentryLanguage() == LANGUAGE_REENTRY_NO || $this->state->getMode() != getSurveyMode() && $this->survey->getReentryMode() == MODE_REENTRY_NO || $this->state->getVersion() != getSurveyVersion()) {
                             $this->setFillTexts(array());
                             /* indicate to redo any fills */
                             $this->setRedoFills(true);
                         }
                         // show question(s)
                         $groupname = $this->getTemplate();
                         $rgid = $this->getRgid();
                         $variablenames = $this->getDisplayed();
                         $this->showQuestion($variablenames, $rgid, $groupname);
                         doExit();
                     } else {
                         if ($where == AFTER_COMPLETION_FROM_START) {
                             // get data of current state, which is the last one (with updated preloads if we re-did the preloads)
                             $data = $this->state->getAllData();
                             // remove all states
                             $this->removeAllStates();
                             // initialize new state
                             $this->reinitializeState();
                             // set data
                             $this->state->setAllData($data);
                             // start main section
                             $this->doSection("", 0, $this->getMainSeid(), true);
                             /* stop */
                             doExit();
                         } else {
                             if (inArray($where, array(AFTER_COMPLETION_LAST_SCREEN, AFTER_COMPLETION_LAST_SCREEN_REDO))) {
                                 /* if (language different from state AND not using last known language) OR (mode different from state AND not using last known language) OR (version different from state), then wipe fill texts */
                                 if ($this->state->getLanguage() != getSurveyLanguage() && $this->survey->getReentryLanguage() == LANGUAGE_REENTRY_NO || $this->state->getMode() != getSurveyMode() && $this->survey->getReentryMode() == MODE_REENTRY_NO || $this->state->getVersion() != getSurveyVersion()) {
                                     $this->setFillTexts(array());
                                     /* indicate to redo any fills */
                                     $this->setRedoFills(true);
                                 }
                                 $groupname = $this->getTemplate();
                                 $rgid = $this->getRgid();
                                 $variablenames = $this->getDisplayed();
                                 // not redoing anything
                                 if ($where == AFTER_COMPLETION_LAST_SCREEN) {
                                     $this->showQuestion($variablenames, $rgid, $groupname);
                                     doExit();
                                 } else {
                                     // in group, then we redo
                                     if ($groupname != "") {
                                         /* indicate update action */
                                         $this->updateaction = true;
                                         /* clear inline fields and sub displays */
                                         $this->setInlineFields(array());
                                         $this->setSubDisplays(array());
                                         /* remove assignments within action */
                                         $this->removeAssignmentsAfterRgid($rgid);
                                         /* re-do action */
                                         $this->doAction($rgid);
                                         /* save data record */
                                         $this->getDataRecord()->saveRecord();
                                         /* we finished everything and are showing a question if all went well 
                                          * so this is the moment to update the state
                                          */
                                         $this->saveState(false);
                                         /* stop */
                                         return;
                                     }
                                 }
                                 doExit();
                             }
                         }
                     }
                 }
             } else {
                 /* see what to do on reentry
                  * based on settings of last 
                  * displayed variable/group
                  */
                 $action = REENTRY_SAME_SCREEN;
                 $reentry_preload = PRELOAD_REDO_NO;
                 $groupname = $this->getTemplate();
                 $rgid = $this->getRgid();
                 $variablenames = $this->getDisplayed();
                 if ($groupname != "") {
                     $group = $this->getGroup($groupname);
                     $action = $group->getAccessReentryAction();
                     $reentry_preload = $group->getAccessReentryRedoPreload();
                 } else {
                     $variables = explode("~", $variablenames);
                     $realvariables = explode("~", $this->display->getRealVariables($variables));
                     if (sizeof($realvariables) > 0) {
                         $var = $this->getVariableDescriptive($realvariables[0]);
                         $action = $var->getAccessReentryAction();
                         $reentry_preload = $var->getAccessReentryRedoPreload();
                     }
                 }
                 /* no re-entry allowed */
                 if ($action == REENTRY_NO_REENTRY) {
                     $this->unlock();
                     doCommit();
                     echo $this->display->showCompletedSurvey();
                     doExit();
                 } else {
                     // set current action to reentry
                     $this->currentaction = ACTION_SURVEY_RETURN;
                     /* update language, mode and version */
                     $this->setAnswer(VARIABLE_LANGUAGE, $language);
                     $this->setAnswer(VARIABLE_VERSION, getSurveyVersion());
                     $this->setAnswer(VARIABLE_MODE, getSurveyMode());
                     $this->setAnswer(VARIABLE_PLATFORM, $_SERVER['HTTP_USER_AGENT']);
                     $this->setAnswer(VARIABLE_EXECUTION_MODE, getSurveyExecutionMode());
                     $this->setAnswer(VARIABLE_TEMPLATE, getSurveyTemplate());
                     // redoing preloads
                     if ($reentry_preload == PRELOAD_REDO_YES) {
                         //echo 'preloading again';
                         $pd = loadvarSurvey('pd');
                         if ($pd != '') {
                             getSessionParamsPost(loadvarSurvey('pd'), 'PD');
                             foreach ($_SESSION['PD'] as $field => $answer) {
                                 //echo $field . ' set with ' . $answer . '<br/>';
                                 $this->setAnswer($field, $answer);
                             }
                         }
                     }
                     // show first question(s) of survey
                     if ($action == REENTRY_FIRST_SCREEN) {
                         /* save data record */
                         $this->getDataRecord()->saveRecord();
                         // get data of current state, which is the last one (with updated preloads if we re-did the preloads)
                         $data = $this->state->getAllData();
                         // remove all states except first one with displayed != "" and anything before that state
                         $this->removeAllStatesExceptFirst();
                         // load the first state
                         $this->loadLastState();
                         // set data from last state to first state
                         $this->state->setAllData($data);
                         //unset($data);
                         // save updated state
                         $this->saveState(false);
                         /* if (language different from state AND not using last known language) OR (mode different from state AND not using last known language) OR (version different from state), then wipe fill texts */
                         if ($this->state->getLanguage() != getSurveyLanguage() && $this->survey->getReentryLanguage() == LANGUAGE_REENTRY_NO || $this->state->getMode() != getSurveyMode() && $this->survey->getReentryMode() == MODE_REENTRY_NO || $this->state->getVersion() != getSurveyVersion()) {
                             $this->setFillTexts(array());
                             /* indicate to redo any fills */
                             $this->setRedoFills(true);
                         }
                         // show question(s)
                         $groupname = $this->getTemplate();
                         $rgid = $this->getRgid();
                         $variablenames = $this->getDisplayed();
                         $this->showQuestion($variablenames, $rgid, $groupname);
                         doExit();
                     } else {
                         if ($action == REENTRY_FROM_START) {
                             // get data of current state, which is the last one (with updated preloads if we re-did the preloads)
                             $data = $this->state->getAllData();
                             // remove all states
                             $this->removeAllStates();
                             // initialize new state
                             $this->reinitializeState();
                             // set data
                             $this->state->setAllData($data);
                             // start main section
                             $this->doSection("", 0, $this->getMainSeid(), true);
                             /* stop */
                             doExit();
                         } else {
                             if (inArray($action, array(REENTRY_SAME_SCREEN, REENTRY_SAME_SCREEN_REDO_ACTION))) {
                                 /* if (language different from state AND not using last known language) OR (mode different from state AND not using last known language) OR (version different from state), then wipe fill texts */
                                 if ($this->state->getLanguage() != getSurveyLanguage() && $this->survey->getReentryLanguage() == LANGUAGE_REENTRY_NO || $this->state->getMode() != getSurveyMode() && $this->survey->getReentryMode() == MODE_REENTRY_NO || $this->state->getVersion() != getSurveyVersion()) {
                                     $this->setFillTexts(array());
                                     /* indicate to redo any fills */
                                     $this->setRedoFills(true);
                                 }
                                 // not redoing anything
                                 if ($action == REENTRY_SAME_SCREEN) {
                                     $this->showQuestion($variablenames, $rgid, $groupname);
                                     doExit();
                                 } else {
                                     // in group, then we redo
                                     if ($groupname != "") {
                                         /* indicate update action */
                                         $this->updateaction = true;
                                         /* clear inline fields and sub displays */
                                         $this->setInlineFields(array());
                                         $this->setSubDisplays(array());
                                         /* clear any assignments part of the action */
                                         $this->removeAssignmentsAfterRgid($rgid);
                                         /* re-do action */
                                         $this->doAction($rgid);
                                         /* save data record */
                                         $this->getDataRecord()->saveRecord();
                                         /* we finished everything and are showing a question if all went well 
                                          * so this is the moment to update the state
                                          */
                                         $this->saveState(false);
                                         /* stop */
                                         return;
                                     }
                                 }
                             } else {
                                 $torgid = 0;
                                 $result = $db->selectQuery('select torgid from ' . Config::dbSurvey() . '_next where suid=' . prepareDatabaseString($this->getSuid()) . ' and seid=' . prepareDatabaseString($this->seid) . ' and fromrgid = ' . prepareDatabaseString($rgid));
                                 if ($row = $db->getRow($result)) {
                                     $torgid = $row["torgid"];
                                 }
                                 /* indicate we are going forward */
                                 $this->setForward(true);
                                 /* log action */
                                 $this->currentaction = ACTION_EXIT_NEXT;
                                 $this->logAction($rgid, ACTION_EXIT_NEXT);
                                 // action to do
                                 if ($torgid > 0) {
                                     /* reset any assignments */
                                     $this->setAssignments(array());
                                     /* reset inline fields */
                                     $this->setInlineFields(array());
                                     /* reset sub displays */
                                     $this->setSubDisplays(array());
                                     /* reset fill texts */
                                     $this->setFillTexts(array());
                                     /* do action */
                                     $this->doAction($torgid);
                                     /* we finished everything and are showing a question if 
                                      * all went well so this is the moment to save the state
                                      */
                                     if ($this->endofsurvey == false) {
                                         /* save data record */
                                         $this->getDataRecord()->saveRecord();
                                         $this->saveState();
                                     }
                                 } else {
                                     /* do end */
                                     $this->doEnd(true);
                                 }
                             }
                         }
                     }
                 }
                 /* stop */
                 doExit();
             }
         } else {
             $this->currentaction = ACTION_SURVEY_ENTRY;
             /* store basic fields */
             $this->setAnswer(VARIABLE_PRIMKEY, $this->primkey);
             $this->setAnswer(VARIABLE_BEGIN, date("Y-m-d H:i:s", time()));
             $this->setAnswer(VARIABLE_LANGUAGE, $language);
             $this->setAnswer(VARIABLE_VERSION, getSurveyVersion());
             $this->setAnswer(VARIABLE_MODE, getSurveyMode());
             $this->setAnswer(VARIABLE_PLATFORM, $_SERVER['HTTP_USER_AGENT']);
             $this->setAnswer(VARIABLE_EXECUTION_MODE, getSurveyExecutionMode());
             $this->setAnswer(VARIABLE_TEMPLATE, getSurveyTemplate());
             /* preload */
             $pd = loadvarSurvey('pd');
             if ($pd != '') {
                 getSessionParamsPost(loadvarSurvey('pd'), 'PD');
                 foreach ($_SESSION['PD'] as $field => $answer) {
                     //echo $field . ' set with ' . $answer . '<br/>';
                     $this->setAnswer($field, $answer);
                 }
             }
             /* save data record */
             $this->getDataRecord()->saveRecord();
             /* do first action */
             $this->doAction($this->getFirstAction());
             /* we finished everything and are showing a question if 
              * went well so this is the moment to save the state
              */
             $this->saveState();
             if ($this->getFlooding()) {
                 if ($this->stop != true) {
                     $this->doFakeSubmit($this->getDisplayed(), $this->getRgid(), $this->getTemplate());
                     $this->getNextQuestion();
                 }
             }
             /* stop */
             $this->stop = true;
             return;
         }
     } else {
         /* get the rgid */
         $lastrgid = getFromSessionParams(SESSION_PARAM_RGID);
         //echo 'dsdsdsdsdsdsd' . $lastrgid . '----' . $this->getPreviousRgid();
         /* check if rgid matches the one from the state AND no posted navigation
          * if not, then this is a browser resubmit
          */
         if ($lastrgid != $this->getPreviousRgid() && !isset($_POST['navigation'])) {
             /* show last question(s) and stop */
             $this->showQuestion($this->getDisplayed(), $this->getRgid(), $this->getTemplate());
             doExit();
         }
         /* handle timings */
         $this->addTimings($lastrgid, $this->getStateId());
         /* get query display object for button labels */
         //echo getFromSessionParams(SESSION_PARAM_VARIABLES) . '====';
         $vars = splitString("/~/", getFromSessionParams(SESSION_PARAM_VARIABLES));
         $dkrfnacheck = false;
         $queryobject = null;
         $screendumps = false;
         $paradata = false;
         if (sizeof($vars) == 1) {
             $var = $this->getVariableDescriptive($vars[0]);
             $queryobject = $var;
             $backlabel = $var->getLabelBackButton();
             $updatelabel = $var->getLabelUpdateButton();
             $nextlabel = $var->getLabelNextButton();
             $dklabel = $var->getLabelDKButton();
             $rflabel = $var->getLabelRFButton();
             $nalabel = $var->getLabelNAButton();
             $remarks = $var->getShowRemarkButton();
             $dkrfnacheck = $var->isIndividualDKRFNA();
             $screendumps = $var->isScreendumpStorage();
             $paradata = $var->isParadata();
         } else {
             $group = $this->getGroup(getFromSessionParams(SESSION_PARAM_GROUP));
             $queryobject = $group;
             $backlabel = $group->getLabelBackButton();
             $updatelabel = $group->getLabelUpdateButton();
             $nextlabel = $group->getLabelNextButton();
             $dklabel = $group->getLabelDKButton();
             $rflabel = $group->getLabelRFButton();
             $nalabel = $group->getLabelNAButton();
             $remarks = $group->getShowRemarkButton();
             $dkrfnacheck = $group->isIndividualDKRFNA();
             $screendumps = $group->isScreendumpStorage();
             $paradata = $group->isParadata();
         }
         /* handle screenshot */
         if ($screendumps == true) {
             $this->addScreenshot();
         }
         /* handle paradata */
         if ($paradata == true) {
             $this->addParadata($lastrgid);
         }
         /* handle action */
         // back
         if (isset($_POST['navigation']) && $_POST['navigation'] == $backlabel) {
             $this->currentaction = ACTION_EXIT_BACK;
             /* update remark status from clean to dirty */
             if ($remarks == BUTTON_YES && loadvarSurvey(POST_PARAM_REMARK_INDICATOR) == 1) {
                 $this->updateRemarkStatus(DATA_DIRTY);
             }
             $this->doBackState($lastrgid, $dkrfnacheck);
             $cnt = 0;
             $currentseid = $this->getSeid();
             // this was a section call, so we need to go back one more state
             while ($this->getDisplayed() == "") {
                 $this->setSeid($this->getParentSeid());
                 $this->setPrefix($this->getParentPrefix());
                 $this->doBackState($this->getRgid(), $dkrfnacheck, false);
                 // dont save answers again!
                 $cnt++;
                 if ($cnt > 100) {
                     break;
                 }
             }
             /* if (language different from state AND update) OR (mode different from state AND update) OR (version different from state), then wipe fill texts */
             $redo = false;
             if ($this->state->getLanguage() != getSurveyLanguage() && $this->survey->getBackLanguage() == LANGUAGE_BACK_YES || $this->state->getMode() != getSurveyMode() && $this->survey->getBackMode() == MODE_BACK_YES || $this->state->getVersion() != getSurveyVersion()) {
                 $this->setFillTexts(array());
                 /* indicate to redo any fills */
                 $this->setRedoFills(true);
                 $redo = true;
             }
             /* if language different, but keeping from state, then update language */
             if ($this->state->getLanguage() != getSurveyLanguage() && $this->survey->getBackLanguage() != LANGUAGE_BACK_YES) {
                 setSurveyLanguage($this->state->getLanguage());
             }
             if ($this->state->getMode() != getSurveyMode() && $this->survey->getBackMode() != MODE_BACK_YES) {
                 setSurveyMode($this->state->getMode());
             }
             if ($this->state->getVersion() != getSurveyVersion()) {
                 setSurveyVersion($this->state->getVersion());
             }
             /* check for on submit function */
             $onsubmit = $queryobject->getOnBack();
             $tocall = $this->replaceFills($onsubmit);
             $parameters = array();
             if (stripos($tocall, '(') !== false) {
                 $parameters = rtrim(substr($tocall, stripos($tocall, '(') + 1), ')');
                 $parameters = preg_split("/[\\s,]+/", $parameters);
                 $tocall = substr($tocall, 0, stripos($tocall, '('));
             }
             if (function_exists($tocall)) {
                 try {
                     $f = new ReflectionFunction($tocall);
                     $returnStr .= $f->invoke($parameters);
                 } catch (Exception $e) {
                 }
             }
             /* no need to reset inline fields array in state --> they are based on the routing
              * if we went back after a language change, then any routing related change resulting from
              * that are not effectuated until after going forward again.
              */
             /* show previous question(s) from the stored state */
             if ($this->getRgid() != "") {
                 // no language/mode/version change, so no need to redo anything
                 if ($redo == false) {
                     $this->showQuestion($this->getDisplayed(), $this->getRgid(), $this->getTemplate());
                 } else {
                     /* we have a rgid */
                     if ($this->getRgid() > 0) {
                         //$this->updateaction = true;
                         // we are going back to different section, so we need to load another engine
                         if ($currentseid != $this->getSeid()) {
                             global $engine;
                             $engine = loadEngine($this->getSuid(), $this->primkey, $this->phpid, $this->version, $this->getSeid(), false, true);
                             /* set state as current state */
                             $engine->setState($this->state);
                             /* update state properties */
                             $engine->setSeid($this->getSeid());
                             $engine->setMainSeid($this->getMainSeid());
                             $engine->setPrefix($this->getPrefix());
                             $engine->setParentSeid($this->getParentSeid());
                             $engine->setParentRgid($this->getParentRgid());
                             $engine->setParentPrefix($this->getParentPrefix());
                             $engine->setForward($this->getForward());
                             $engine->setFlooding($this->getFlooding());
                             // do the action in the correct engine
                             $engine->doAction($this->getRgid());
                             // stop
                             return;
                         } else {
                             $this->doAction($this->getRgid());
                             /* we finished everything and are showing a question if all went well 
                              * so this is the moment to update the state
                              */
                             $this->saveState(false);
                         }
                     } else {
                         $this->showQuestion($this->getDisplayed(), $this->getRgid(), $this->getTemplate());
                     }
                 }
             } else {
                 // this should not happen
                 $this->showQuestion(VARIABLE_INTRODUCTION, "");
                 //echo Language::messageSurveyStart();
             }
             /* save data record */
             $this->getDataRecord()->saveRecord();
             /* stop */
             return;
         } else {
             if (isset($_POST['navigation']) && ($_POST['navigation'] == $updatelabel || $_POST['navigation'] == NAVIGATION_LANGUAGE_CHANGE || $_POST['navigation'] == NAVIGATION_MODE_CHANGE || $_POST['navigation'] == PROGRAMMATIC_UPDATE)) {
                 $torgid = getFromSessionParams(SESSION_PARAM_RGID);
                 /* log action */
                 if ($_POST['navigation'] == $updatelabel) {
                     $this->currentaction = ACTION_EXIT_UPDATE;
                     $this->logAction($lastrgid, ACTION_EXIT_UPDATE);
                 } else {
                     if ($_POST['navigation'] == NAVIGATION_LANGUAGE_CHANGE) {
                         $this->currentaction = ACTION_EXIT_LANGUAGE_CHANGE;
                         $this->logAction($lastrgid, ACTION_EXIT_LANGUAGE_CHANGE);
                         $this->setAnswer(VARIABLE_LANGUAGE, getSurveyLanguage());
                     } else {
                         if ($_POST['navigation'] == NAVIGATION_MODE_CHANGE) {
                             $this->currentaction = ACTION_EXIT_MODE_CHANGE;
                             $this->logAction($lastrgid, ACTION_EXIT_MODE_CHANGE);
                             $this->setAnswer(VARIABLE_MODE, getSurveyMode());
                         } else {
                             if ($_POST['navigation'] == NAVIGATION_VERSION_CHANGE) {
                                 $this->currentaction = ACTION_EXIT_VERSION_CHANGE;
                                 $this->logAction($lastrgid, ACTION_EXIT_VERSION_CHANGE);
                                 $this->setAnswer(VARIABLE_VERSION, getSurveyVersion());
                             } else {
                                 if ($_POST['navigation'] == PROGRAMMATIC_UPDATE) {
                                     $this->currentaction = ACTION_EXIT_PROGRAMMATIC_UPDATE;
                                     $this->logAction($lastrgid, ACTION_EXIT_PROGRAMMATIC_UPDATE);
                                 }
                             }
                         }
                     }
                 }
                 /* store answers in db and previous state */
                 $cnt = 1;
                 foreach ($vars as $var) {
                     $vd = $this->getVariableDescriptive($var);
                     if ($vd->getAnswerType() == ANSWER_TYPE_SETOFENUMERATED) {
                         $answer = "";
                         if ($dkrfnacheck == true) {
                             /* dk/rf/na */
                             $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt . "_dkrfna");
                             if (!inArray($answer, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) {
                                 $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                             }
                         } else {
                             $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                         }
                         if (is_array($answer)) {
                             $answer = implode(SEPARATOR_SETOFENUMERATED, $answer);
                         }
                         $this->setAnswer($var, $answer, DATA_DIRTY);
                     } else {
                         if ($vd->getAnswerType() != ANSWER_TYPE_NONE) {
                             $answer = "";
                             if ($dkrfnacheck == true) {
                                 /* dk/rf/na */
                                 $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt . "_dkrfna");
                                 if (!inArray($answer, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) {
                                     $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                                 }
                             } else {
                                 $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                             }
                             $this->setAnswer($var, $answer, DATA_DIRTY);
                         }
                     }
                     $cnt++;
                 }
                 /* if update button OR language OR mode OR version now different from state, then wipe fill texts */
                 if ($this->currentaction == ACTION_EXIT_UPDATE || $_POST['navigation'] == NAVIGATION_LANGUAGE_CHANGE && $this->state->getLanguage() != getSurveyLanguage() || $_POST['navigation'] == NAVIGATION_MODE_CHANGE && $this->state->getMode() != getSurveyMode() || $_POST['navigation'] == NAVIGATION_VERSION_CHANGE && $this->state->getVersion() != getSurveyVersion()) {
                     $this->setFillTexts(array());
                     /* indicate to redo any fills */
                     $this->setRedoFills(true);
                 }
                 /* indicate update action */
                 $this->updateaction = true;
                 /* clear inline fields and sub displays */
                 $this->setInlineFields(array());
                 $this->setSubDisplays(array());
                 /* update remark status to clean */
                 if ($remarks == BUTTON_YES && loadvarSurvey(POST_PARAM_REMARK_INDICATOR) == 1) {
                     $this->updateRemarkStatus(DATA_DIRTY);
                 }
                 /* check for on submit function */
                 $onsubmit = "";
                 if ($_POST['navigation'] == $updatelabel) {
                     $onsubmit = $queryobject->getOnUpdate();
                 } else {
                     if ($_POST['navigation'] == NAVIGATION_LANGUAGE_CHANGE) {
                         $onsubmit = $queryobject->getOnLanguageChange();
                     } else {
                         if ($_POST['navigation'] == NAVIGATION_MODE_CHANGE) {
                             $onsubmit = $queryobject->getOnModeChange();
                         } else {
                             if ($_POST['navigation'] == NAVIGATION_VERSION_CHANGE) {
                                 $onsubmit = $queryobject->getOnVersionChange();
                             }
                         }
                     }
                 }
                 $tocall = $this->replaceFills($onsubmit);
                 $parameters = array();
                 if (stripos($tocall, '(') !== false) {
                     $parameters = rtrim(substr($tocall, stripos($tocall, '(') + 1), ')');
                     $parameters = preg_split("/[\\s,]+/", $parameters);
                     $tocall = substr($tocall, 0, stripos($tocall, '('));
                 }
                 if (function_exists($tocall)) {
                     try {
                         $f = new ReflectionFunction($tocall);
                         $returnStr .= $f->invoke($parameters);
                     } catch (Exception $e) {
                     }
                 }
                 /* re-do action */
                 $this->doAction($this->getRgid());
                 /* save data record */
                 $this->getDataRecord()->saveRecord();
                 /* we finished everything and are showing a question if all went well 
                  * so this is the moment to update the state
                  */
                 $this->saveState(false);
                 /* stop */
                 return;
             } else {
                 if (isset($_POST['navigation']) && inArray($_POST['navigation'], array($nextlabel, $dklabel, $rflabel, $nalabel))) {
                     $torgid = 0;
                     $result = $db->selectQuery('select torgid from ' . Config::dbSurvey() . '_next where suid=' . prepareDatabaseString($this->getSuid()) . ' and seid=' . prepareDatabaseString($this->seid) . ' and fromrgid = ' . prepareDatabaseString($lastrgid));
                     //echo 'select * from ' . Config::dbSurvey() . '_next where suid=' . prepareDatabaseString($this->getSuid()) . ' and seid=' . prepareDatabaseString($this->seid) . ' and fromrgid = ' . prepareDatabaseString($lastrgid);
                     if ($row = $db->getRow($result)) {
                         $torgid = $row["torgid"];
                     }
                     /* indicate we are going forward */
                     $this->setForward(true);
                     /* log action */
                     if ($_POST['navigation'] == $nextlabel) {
                         $this->currentaction = ACTION_EXIT_NEXT;
                         $this->logAction($lastrgid, ACTION_EXIT_NEXT);
                     } else {
                         if ($_POST['navigation'] == $dklabel) {
                             $this->currentaction = ACTION_EXIT_DK;
                             $this->logAction($lastrgid, ACTION_EXIT_DK);
                         } else {
                             if ($_POST['navigation'] == $rflabel) {
                                 $this->currentaction = ACTION_EXIT_RF;
                                 $this->logAction($lastrgid, ACTION_EXIT_RF);
                             } else {
                                 if ($_POST['navigation'] == $nalabel) {
                                     $this->currentaction = ACTION_EXIT_NA;
                                     $this->logAction($lastrgid, ACTION_EXIT_NA);
                                 }
                             }
                         }
                     }
                     /* store answers in db and previous state */
                     $cnt = 1;
                     //echo $torgid . '---';
                     foreach ($vars as $var) {
                         //echo 'answer for ' . $var . ' at ' . $cnt . ' is: ' .  loadvar("answer" . $cnt) . '---<br/>';
                         // next button
                         if ($_POST['navigation'] == $nextlabel) {
                             $vd = $this->getVariableDescriptive($var);
                             if ($vd->getAnswerType() == ANSWER_TYPE_SETOFENUMERATED || $vd->getAnswerType() == ANSWER_TYPE_MULTIDROPDOWN) {
                                 $answer = "";
                                 if ($dkrfnacheck == true) {
                                     /* dk/rf/na */
                                     $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt . "_dkrfna");
                                     if (!inArray($answer, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) {
                                         $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                                     }
                                 } else {
                                     $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                                 }
                                 if (is_array($answer)) {
                                     $answer = implode(SEPARATOR_SETOFENUMERATED, $answer);
                                 }
                                 $this->setAnswer($var, $answer, DATA_CLEAN);
                             } else {
                                 if ($vd->getAnswerType() != ANSWER_TYPE_NONE) {
                                     $answer = "";
                                     if ($dkrfnacheck == true) {
                                         /* dk/rf/na */
                                         $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt . "_dkrfna");
                                         if (!inArray($answer, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) {
                                             $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                                         }
                                     } else {
                                         $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt);
                                     }
                                     $this->setAnswer($var, $answer, DATA_CLEAN);
                                 }
                             }
                         } else {
                             if ($_POST['navigation'] == $dklabel) {
                                 $vd = $this->getVariableDescriptive($var);
                                 if ($vd->getAnswerType() != ANSWER_TYPE_NONE) {
                                     $this->setAnswer($var, ANSWER_DK, DATA_CLEAN);
                                 }
                             } else {
                                 if ($_POST['navigation'] == $rflabel) {
                                     $vd = $this->getVariableDescriptive($var);
                                     if ($vd->getAnswerType() != ANSWER_TYPE_NONE) {
                                         $this->setAnswer($var, ANSWER_RF, DATA_CLEAN);
                                     }
                                 } else {
                                     if ($_POST['navigation'] == $nalabel) {
                                         $vd = $this->getVariableDescriptive($var);
                                         if ($vd->getAnswerType() != ANSWER_TYPE_NONE) {
                                             $this->setAnswer($var, ANSWER_NA, DATA_CLEAN);
                                         }
                                     }
                                 }
                             }
                         }
                         $cnt++;
                     }
                     /* update remark status to clean */
                     if ($remarks == BUTTON_YES && loadvarSurvey(POST_PARAM_REMARK_INDICATOR) == 1) {
                         $this->updateRemarkStatus(DATA_CLEAN);
                     }
                     $onsubmit = "";
                     if ($_POST['navigation'] == $nextlabel) {
                         $onsubmit = $queryobject->getOnNext();
                     } else {
                         if ($_POST['navigation'] == $dklabel) {
                             $onsubmit = $queryobject->getOnDK();
                         } else {
                             if ($_POST['navigation'] == $rflabel) {
                                 $onsubmit = $queryobject->getOnRF();
                             } else {
                                 if ($_POST['navigation'] == $nalabel) {
                                     $onsubmit = $queryobject->getOnNA();
                                 }
                             }
                         }
                     }
                     $tocall = $this->replaceFills($onsubmit);
                     $parameters = array();
                     if (stripos($tocall, '(') !== false) {
                         $parameters = rtrim(substr($tocall, stripos($tocall, '(') + 1), ')');
                         $parameters = preg_split("/[\\s,]+/", $parameters);
                         $tocall = substr($tocall, 0, stripos($tocall, '('));
                     }
                     if (function_exists($tocall)) {
                         try {
                             $f = new ReflectionFunction($tocall);
                             $returnStr .= $f->invoke($parameters);
                         } catch (Exception $e) {
                         }
                     }
                     // action to do
                     if ($torgid > 0) {
                         /* reset any assignments */
                         $this->setAssignments(array());
                         /* reset inline fields */
                         $this->setInlineFields(array());
                         /* reset sub displays */
                         $this->setSubDisplays(array());
                         /* reset fill texts */
                         $this->setFillTexts(array());
                         /* do action */
                         $this->doAction($torgid);
                         /* we finished everything and are showing a question if 
                          * went well so this is the moment to save the state
                          */
                         if ($this->endofsurvey == false) {
                             if ($this->getFlooding()) {
                                 if ($this->stop != true) {
                                     $this->getDataRecord()->saveRecord();
                                     $this->saveState();
                                 }
                             } else {
                                 /* save data record */
                                 $this->getDataRecord()->saveRecord();
                                 $this->saveState();
                             }
                         }
                     } else {
                         /* not end of survey, then clear any assignments and so on */
                         if ($this->isMainSection() == false) {
                             /* reset any assignments */
                             $this->setAssignments(array());
                             /* reset inline fields */
                             $this->setInlineFields(array());
                             /* reset sub displays */
                             $this->setSubDisplays(array());
                             /* reset fill texts */
                             $this->setFillTexts(array());
                         }
                         /* do end */
                         $this->doEnd(true);
                     }
                     /* stop */
                     if ($this->getFlooding()) {
                         if ($this->stop != true) {
                             $this->doFakeSubmit($this->getDisplayed(), $this->getRgid(), $this->getTemplate());
                             $this->getNextQuestion();
                         }
                         $this->stop = true;
                         return;
                     }
                     doExit();
                 }
             }
         }
     }
 }
    public function showNavBar()
    {
        $returnStr = $this->showCalculator();
        //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);
        // begin language
        global $survey;
        if (getSurveyLanguageAllowChange() == LANGUAGE_CHANGE_RESPONDENT_ALLOWED) {
            $allowed = explode("~", $survey->getAllowedLanguages(getSurveyMode()));
            if (sizeof($allowed) > 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"], $allowed)) {
                        $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->primkey . '</li>
                                                                                <li class="dropdown-header">' . $variablenamesfull . '</li>';
        //$returnStr .= '<li><a href=# data-toggle="modal" data-target="#calculator">Calculator</a></li>';
        $returnStr .= '<li><a href="#" data-toggle="modal" data-target="#calculator"><span class="glyphicon glyphicon-th"></span> ' . Language::linkCalculator() . '</a></li>';
        $windowopen = 'window.open(\'tester/' . setSessionParams(array('type' => "2", '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>';
        $windowopen = 'window.open(\'tester/' . setSessionParams(array('type' => "2", 'testpage' => 'update', '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=1200,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::linkUpdate() . '</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('type' => "2", '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' => 'interviewer.backfromsms', 'primkey' => $this->engine->primkey, 'suid' => $this->engine->getSuid())) . '&se=' . addslashes(USCIC_SMS) . '"><span class="glyphicon glyphicon-home"></span> ' . Language::linkBackToSMS() . '</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;
    }
    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;
    }
Beispiel #5
0
 function surveyEntry()
 {
     global $engine;
     if ($this->checkDateTime() == false) {
         /* get whatever the language is (either post or default) and use it */
         $l = getSurveyLanguage();
         if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) {
             require_once 'language' . getSurveyLanguagePostFix($l) . '.php';
             // language
         } else {
             require_once 'language_en.php';
             // fall back on english language file
         }
         $login = new Login(session_id());
         return $login->getClosedScreen();
     }
     $logactions = new LogActions();
     $nosessionactions = $logactions->getNumberOfSurveyActionsBySession($this->phpid, USCIC_SURVEY);
     /* no entry yet, then ask for prim_key in login screen */
     if ($nosessionactions == 0 || loadvarSurvey(POST_PARAM_NEW_PRIMKEY) == '1') {
         //no entry yet: ask for prim_key!
         if (loadvarSurvey(POST_PARAM_NEW_PRIMKEY) == '1') {
             $logactions->deleteLoggedInSurveySession($this->phpid);
         }
         /* get whatever the language is (either post or default) and use it */
         $l = getSurveyLanguage();
         if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) {
             require_once 'language' . getSurveyLanguagePostFix($l) . '.php';
             // language
         } else {
             require_once 'language_en.php';
             // fall back on english language file
         }
         $logactions->addAction('', '', "loginstart", USCIC_SURVEY, 1);
         $login = new Login($this->phpid);
         return $login->getLoginScreen();
     } else {
         //entry: is this person logged in?
         $loggedin = $logactions->getLoggedInSurveySession($this->phpid);
         // gets the last logged in action
         /* no prim_key assigned to this sessionid. Assign if given (and check for pwd etc??)! */
         if ($loggedin["count"] == 0) {
             /* we don't have active session, so take the template we can get */
             global $survey;
             require_once "display/templates/displayquestion_" . getSurveyTemplate() . ".php";
             // we don't have an active session, so fall back to whatever was passed along as language in post OR is the default language
             $l = getSurveyLanguage();
             if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) {
                 //echo 'well done';
                 require_once 'language' . getSurveyLanguagePostFix($l) . '.php';
                 // language
             } else {
                 require_once 'language_en.php';
                 // fall back on english language file
             }
             $primkey = loadvarSurvey(POST_PARAM_PRIMKEY);
             $_SESSION['PRIMKEY'] = $primkey;
             if ($primkey != '' && strlen($primkey) < 20) {
                 // make sure primkey is not encrypted!
                 //check!!!!!!
                 $login = new Login($this->phpid);
                 if ($login->checkAccess()) {
                     $primkey = $_SESSION['PRIMKEY'];
                     $logactions->addAction($primkey, '', "loggedin", USCIC_SURVEY, 1);
                     // pass along primkey to load correct engine!
                     $engine = loadEngine(getSurvey(), $primkey, $this->phpid, getSurveyVersion(), getSurveySection(getSurvey(), $primkey));
                     $engine->setFirstForm(true);
                     return $engine->getNextQuestion();
                 } else {
                     // incorrect login..start new session
                     endSession();
                     session_start();
                     session_regenerate_id(true);
                     $logactions->addAction('', '', "loginempty", USCIC_SURVEY, 1);
                     $login = new Login(session_id());
                     global $survey;
                     return $login->getLoginScreen($survey->getLoginError());
                 }
             } else {
                 $logactions->addAction('', '', "loginempty", USCIC_SURVEY, 1);
                 $login = new Login($this->phpid);
                 global $survey;
                 if ($survey->getAccessType() == LOGIN_ANONYMOUS) {
                     return $login->getLoginScreen(Language::messageEnterPrimKey());
                 } else {
                     if ($survey->getAccessType() == LOGIN_LOGINCODE) {
                         return $login->getLoginScreen($survey->getLoginError());
                     } else {
                         return $login->getLoginScreen(Language::messageEnterPrimKeyDirectAccess());
                     }
                 }
             }
         } else {
             //continue interview! EXTRA CHECK!!!
             /* update survey info with what we know from the last session action */
             setSurvey($loggedin["suid"]);
             /* include survey template now that we know which survey we are in */
             global $survey;
             require_once "display/templates/displayquestion_" . getSurveyTemplate() . ".php";
             /* update interview mode with what we know from the last session action
              * IF we are not changing the interview mode right now
              */
             if (isset($_POST['navigation']) && $_POST['navigation'] != NAVIGATION_MODE_CHANGE && $survey->getReentryMode() == MODE_REENTRY_YES) {
                 setSurveyMode($loggedin["mode"]);
             }
             /* update language with what we know from the last session action 
              * IF we are not changing the language right now
              */
             if (isset($_POST['navigation']) && $_POST['navigation'] != NAVIGATION_LANGUAGE_CHANGE && $survey->getReentryLanguage(getSurveyMode()) == LANGUAGE_REENTRY_YES) {
                 setSurveyLanguage($loggedin["language"]);
             }
             /* update version with what we know from the last session action */
             setSurveyVersion($loggedin["version"]);
             // include language file
             $l = getSurveyLanguage();
             //echo 'NOW: ' . $l;
             if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) {
                 //echo 'well done';
                 require_once 'language' . getSurveyLanguagePostFix($l) . '.php';
                 // language
             } else {
                 require_once 'language_en.php';
                 // fall back on english language file
             }
             // pass along primkey to load correct engine!
             $engine = loadEngine(getSurvey(), $loggedin["primkey"], $this->phpid, getSurveyVersion(), getSurveySection(getSurvey(), $loggedin["primkey"]));
             /* handle button click */
             return $engine->getNextQuestion();
         }
     }
 }
Beispiel #6
0
 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ------------------------------------------------------------------------
*/
require_once "../constants.php";
require_once "../functions.php";
require_once "../dbConfig.php";
$_SESSION['SYSTEM_ENTRY'] = USCIC_SMS;
$loaded = dbConfig::load("../conf.php");
require_once "../config.php";
require_once "../globals.php";
require_once "../user.php";
require_once 'reportissue.php';
require_once 'watchwindow.php';
require_once 'jumpback.php';
require_once 'updater.php';
require_once "../display/templates/displayquestion_" . getSurveyTemplate() . ".php";
if (loadvar('r') != '') {
    getSessionParamsPost(loadvar('r'));
}
// include language
$l = getSMSLanguage();
if (file_exists("language/language" . getSMSLanguagePostFix($l) . ".php")) {
    require_once 'language_' . getSMSLanguagePostFix($l) . '.php';
} else {
    require_once 'language_en.php';
    // fall back on english language  file
}
$_SESSION['SYSTEM_ENTRY'] = USCIC_SURVEY;
// switch back to survey
$page = getFromSessionParams('testpage');
if (getFromSessionParams('type') != "2") {
Beispiel #7
0
    function displayParadataScripts($paradata)
    {
        //only for surveys
        if ($_SESSION['SYSTEM_ENTRY'] != USCIC_SURVEY) {
            return;
        }
        // check config
        if ($paradata == false) {
            return;
        }
        // http://greensock.com/forums/topic/9059-cross-browser-to-detect-tab-or-window-is-active-so-animations-stay-in-sync-using-html5-visibility-api/
        if (!isRegisteredScript("js/TabWindowVisibilityManager.min.js")) {
            registerScript('js/TabWindowVisibilityManager.min.js');
            $returnStr = getScript('js/TabWindowVisibilityManager.min.js');
        }
        if (!isRegisteredScript("js/datetimepicker/moment-min.js")) {
            registerScript('js/datetimepicker/moment-min.js');
            $returnStr .= getScript("js/datetimepicker/moment-min.js");
        }
        //if (!isRegisteredScript("js/zip/lzstring.js")) {
        //    registerScript('js/zip/lzstring.js');
        //    $returnStr .= '<script type=text/javascript src="js/zip/lzstring.js"></script>';
        //}
        $params = array(POST_PARAM_DEFAULT_LANGUAGE => getDefaultSurveyLanguage(), POST_PARAM_DEFAULT_MODE => getDefaultSurveyMode(), POST_PARAM_RGID => $this->engine->getRgid(), POST_PARAM_LANGUAGE => getSurveyLanguage(), POST_PARAM_MODE => getSurveyMode(), SESSION_PARAM_TEMPLATE => getSurveyTemplate(), POST_PARAM_VERSION => getSurveyVersion(), POST_PARAM_STATEID => $this->engine->getStateId(), POST_PARAM_DISPLAYED => urlencode(serialize($this->engine->getDisplayNumbers())), POST_PARAM_PRIMKEY => $this->engine->getPrimaryKey(), POST_PARAM_SUID => $this->engine->getSuid());
        $r = setSessionsParamString($params);
        $returnStr .= '<script type="text/javascript">';
        $str = '
            // bind listeners
            $(document).ready(function(){  ';
        if (Config::logParadataMouseMovement()) {
            $str .= '$("html").mousemove(function(event) {
                    window.mousex = event.pageX;
                    window.mousey = event.pageY;
                });';
        }
        $str .= '
                $("html").click(function(event){
                    var name = "";
                    if (event.target.name) {
                        name = event.target.name;
                    }
                    logParadata("MC:"+event.pageX+":"+event.pageY+":"+event.which+":"+name);
                });
                $("html").keyup(function(event){
                    var name = "";
                    if (event.target.name) {
                        name = event.target.name;
                    }
                    logParadata("KE:"+event.keyCode+":"+name);
                });
            });';
        if (Config::logParadataMouseMovement()) {
            $str .= '
                window.mousex = 0;
                window.mousey = 0;
                window.lastx = window.mousex;
                window.lasty = window.mousey;
                function mousemov() {
                    if (window.lastx != window.mousex || window.lasty != window.mousey) {
                        logParadata("MM:"+window.mousex+":"+window.mousey);
                        window.lastx = window.mousex;
                        window.lasty = window.mousey;
                    }

                }
                window.onload=setInterval(mousemov, ' . Config::logParadataMouseMovementInterval() . '); // capture mouse movement every 5 seconds
                ';
        }
        $str .= '
            // compress function
            function compress(string) {
                return string;
                //return LZString.compressToUTF16(string);
            }
            
            // function to log paradata
            function logParadata(para) {
                $("#pid").val($("#pid").val() + "||" + compress(para + "=" + moment()));
                //alert($("#pid").val().length);
                // if length exceeds limit
                //if ($("#pid").val().length > 1024) {
                    //alert($("#pid").val().length);
                    //sendParadata($("#pid").val()); // send to server
                    //$("#pid").val(""); // reset
                //}
            }

            // function to send paradata to the server
            function sendParadata(paradata) {
                $.ajax({
                    type: "POST",
                    url: "ajax/index.php",
                    data: {ajaxr: "' . $r . '", p: "storeparadata", ' . POST_PARAM_PARADATA . ': paradata},
                    async: true
                });
            }
                 
            var firedin = false;                
            var firedout = false; 
            $(window).TabWindowVisibilityManager({
                onFocusCallback: function(){
                        if (firedin == false) {
                            //document.title="visible";
                            logParadata("FI:");	                
                        }
                        firedin = true;
                        firedout = false;
                },
                onBlurCallback: function(){
                    if (firedout == false) {
                        //document.title="invisible";
                        logParadata("FO:");
                    }
                    firedout = true;    
                    firedin = false;
                }
            });';
        $returnStr .= minifyScript($str);
        $returnStr .= '</script>';
        return $returnStr;
    }