function __construct($suid, $primkey, $phpid, $version, $seid, $doState = true, $doContext = true) { $this->primkey = $primkey; $this->phpid = $phpid; $this->setSuid($suid); if (isset($_SESSION['URID']) && $_SESSION['URID'] != '') { $user = new User($_SESSION['URID']); if (isTestmode() && inArray($user->getUserType(), array(USER_SYSADMIN, USER_TRANSLATOR, USER_TESTER))) { $this->display = new DisplayQuestionTest($this->primkey, $this); } else { if ($user->getUserType() == USER_NURSE) { $this->display = new DisplayQuestionNurse($this->primkey, $this); } else { $this->display = new DisplayQuestionSms($this->primkey, $this); } } } else { $this->display = new DisplayQuestion($this->primkey, $this); } global $survey; $this->survey = $survey; $this->version = $version; /* get context */ if ($doContext == true) { $this->loadContext(); } /* data record */ $this->datarecord = new DataRecord($suid, $primkey); $this->datarecord->loadRecord(); /* do state */ if ($doState == true) { /* get main section and current section */ $this->mainseid = getSurveyMainSection($suid, $primkey); $this->seid = getSurveySection($suid, $primkey); /* check for existing state */ $this->state = new State($this->primkey, $this->survey->getSuid()); if ($this->loadLastState() == true) { $this->previousrgid = $this->getRgid(); $this->previousloopaction = $this->getForLoopLastAction(); $this->previousloopstring = $this->getLoopString(); $this->previouslooprgid = $this->getLoopRgid(); $this->previouswhilergid = $this->getWhileRgid(); $this->previouswhileaction = $this->getWhileLastAction(); } else { $this->state->setSuid($suid); $this->setMainSeid($this->mainseid); $this->setSeid($this->seid); $this->setPrefix(""); $this->setParentPrefix(""); $this->setParentSeid(0); $this->setParentRgid(0); /* set loop string, loop rgid and loop left off to empty by default */ $this->setLoopString(""); $this->setLoopRgid(""); $this->setForLoopLastAction(""); $this->setWhileRgid(""); $this->setWhileLastAction(""); } } else { $this->seid = $seid; // set for loadSetFillClasses } $this->flooding = false; $this->stop = false; $this->startatbegin = false; $this->redofills = false; $this->forward = false; $this->firstform = false; $this->updateaction = false; $this->reset = array(); $this->dk = array(); $this->rf = array(); $this->na = array(); $this->processedfills = array(); $this->justassigned = array(); $this->currentaction = ACTION_DYNAMIC; /* load any set fill classes */ //$this->loadSetFillClasses(); }
function getSurveySection($suid = "", $primkey = "") { /* declare */ $seid = ""; global $currentseid; /* returning to survey or starting */ if (getFromSessionParams(SESSION_PARAM_RGID) == '') { /* check in session first (overrides last state) */ $seid = getFromSessionParams(SESSION_PARAM_SEID); if (isSurveySection($seid)) { $currentseid = $seid; return $seid; } /* check for last state */ global $db; $result = $db->selectQuery('select seid from ' . Config::dbSurveyData() . '_states where suid=' . prepareDatabaseString($suid) . ' and primkey = "' . prepareDatabaseString($primkey) . '" and mainseid=' . getSurveyMainSection($suid, $primkey) . ' order by stateid desc limit 0,1'); /* we are re-entering */ if ($db->getNumberOfRows($result) > 0) { $row = $db->getRow($result); $seid = $row["seid"]; if (isSurveySection($seid)) { $currentseid = $seid; return $seid; } } /* we are starting the survey and no session parameter, then assume root section */ $currentseid = getBaseSectionSeid($suid); return $currentseid; } else { /* button action */ if (isset($_POST['navigation'])) { /* back button */ if ($_POST['navigation'] == Language::buttonBack()) { /* check for last state to determine which section we are going to */ global $db; $result = $db->selectQuery('select seid from ' . Config::dbSurveyData() . '_states where suid=' . prepareDatabaseString($suid) . ' and primkey = "' . prepareDatabaseString($primkey) . '" and mainseid=' . getSurveyMainSection($suid, $primkey) . ' order by stateid desc limit 0,1'); //echo 'select * from ' . Config::dbSurveyData() . '_states where suid=' . prepareDatabaseString($suid) . ' and primkey = "' . prepareDatabaseString($primkey) . '" and mainseid=' . getSurveyMainSection($suid, $primkey) . ' order by stateid desc limit 0,1'; if ($db->getNumberOfRows($result) > 0) { $row = $db->getRow($result); $seid = $row["seid"]; if (isSurveySection($seid)) { $currentseid = $seid; return $seid; } } } else { if ($_POST['navigation'] == Language::buttonUpdate()) { /* section does not change, so return from session */ $seid = getFromSessionParams(SESSION_PARAM_SEID); if (isSurveySection($seid)) { $currentseid = $seid; return $seid; } } else { /* section may change, but this is handled by the current section engine * calling the nex section engine, so we keep the same section */ $seid = getFromSessionParams(SESSION_PARAM_SEID); if (isSurveySection($seid)) { $currentseid = $seid; return $seid; } } } } /* everything failed, then assume root section */ $currentseid = getBaseSectionSeid($suid); return $currentseid; } /* check last state */ $currentseid = getBaseSectionSeid($suid); return $currentseid; }