Esempio n. 1
0
 function generateCases()
 {
     $suid = loadvar("suid");
     if ($suid == "") {
         $suid = 1;
     }
     $seid = loadvar("seid");
     if ($seid == "") {
         $seid = 1;
     }
     $version = 1;
     setSurvey($suid);
     setSurveyLanguage(loadvar(POST_PARAM_LANGUAGE), true);
     setSurveyMode(loadvar(POST_PARAM_MODE), true);
     setSurveyVersion($version);
     /* generate cases */
     $number = loadvar("number");
     for ($i = 0; $i < $number; $i++) {
         //set_time_limit(0);
         $primkey = generateRandomPrimkey();
         $this->generateCase($suid, $primkey, session_id(), $version, $seid);
         //exit;
     }
 }
Esempio n. 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();
                 }
             }
         }
     }
 }
Esempio n. 3
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();
         }
     }
 }