Example #1
0
 function generate($seid, $nestingcounter = 1)
 {
     $_SESSION['PARAMETER_RETRIEVAL'] = PARAMETER_SURVEY_RETRIEVAL;
     global $db;
     set_time_limit(0);
     ini_set('memory_limit', '128M');
     $this->seid = $seid;
     $q = "select * from " . Config::dbSurvey() . "_routing where suid=" . $this->suid . " and seid=" . $this->seid . " order by rgid asc";
     if ($rules = $db->selectQuery($q)) {
         if ($db->getNumberOfRows($rules) > 0) {
             /* set uscic-paperversion-nesting counter */
             $this->nesting = $nestingcounter;
             while ($row = $db->getRow($rules)) {
                 //echo $row["rule"] . "<br/>";
                 $this->instructions[$row["rgid"]] = new RoutingInstruction($row["suid"], $row["seid"], $row["rgid"], $row["rule"]);
             }
             //echo'yytyyy';
             /* process rules */
             for ($this->cnt = 1; $this->cnt <= sizeof($this->instructions); $this->cnt++) {
                 if (isset($this->instructions[$this->cnt])) {
                     //echo $this->instructions[$this->cnt]->getRule() . "<br/>";
                     $this->addRule($rootnode, $this->instructions[$this->cnt]);
                 }
             }
         }
     }
     $_SESSION['PARAMETER_RETRIEVAL'] = PARAMETER_ADMIN_RETRIEVAL;
 }
Example #2
0
 function checkAccess()
 {
     global $db, $survey;
     switch ($survey->getAccessType()) {
         case LOGIN_ANONYMOUS:
             return true;
             break;
         case LOGIN_DIRECT:
             return true;
             break;
         case LOGIN_LOGINCODE:
             $logincode = loadvarSurvey('primkey');
             $result = $db->selectQuery('select count(*), primkey from ' . Config::dbSurvey() . '_respondents where aes_decrypt(logincode, \'' . Config::loginCodeKey() . '\') = \'' . prepareDatabaseString($logincode) . '\'');
             //echo 'select count(*), primkey from ' . Config::dbSurvey() . '_respondents where aes_decrypt(logincode, "' . Config::loginCodeKey() . '") = "' . prepareDatabaseString($logincode) . '"';
             $row = $db->getRow($result);
             if ($row[0] == 1) {
                 $_SESSION['PRIMKEY'] = $row['primkey'];
                 return true;
             } else {
                 $logactions = new LogActions();
                 $logactions->addAction('', '', "loginwrong", USCIC_SURVEY);
             }
             break;
     }
     return false;
 }
Example #3
0
 function checkProxyCode($startcode, $permissioncode)
 {
     global $db;
     $query = 'select count(*) as cnt from ' . Config::dbSurvey() . '_proxypermission where startcode=\'' . prepareDatabaseString($startcode) . '\' and permissioncode = \'' . prepareDatabaseString($permissioncode) . '\'';
     //echo '<br/><br/><br/>' . $query;
     $result = $db->selectQuery($query);
     $row = $db->getRow($result);
     return $row['cnt'] > 0;
 }
Example #4
0
 function Psu($rowOrPuid)
 {
     global $db;
     if (is_array($rowOrPuid)) {
         $this->psu = $rowOrPuid;
     } else {
         $query = 'select * from ' . Config::dbSurvey() . '_psus where puid = ' . prepareDatabaseString($rowOrPuid);
         $result = $db->selectQuery($query);
         $this->psu = $db->getRow($result);
     }
 }
Example #5
0
 function getPsusByCodeAsArray()
 {
     //used in assign new sample to map between code and index
     global $db;
     $psus = array();
     $result = $db->selectQuery('select * from ' . Config::dbSurvey() . '_psus');
     while ($row = $db->getRow($result)) {
         $psus[$row['code']] = $row['puid'];
     }
     return $psus;
 }
Example #6
0
 function GPS($village, $dwellingid)
 {
     global $db;
     $query = 'select *,';
     $query .= 'aes_decrypt(latitude, "' . Config::smsPersonalInfoKey() . '") as latitude, ';
     $query .= 'aes_decrypt(longitude, "' . Config::smsPersonalInfoKey() . '") as longitude ';
     $query .= ' from ' . Config::dbSurvey() . '_gps where dwellingid = "' . prepareDatabaseString($dwellingid) . '" and code = "' . prepareDatabaseString($village) . '"';
     //echo '<br/><br/><br/>' . $query;
     $result = $db->selectQuery($query);
     $this->gps = $db->getRow($result);
 }
Example #7
0
 function Version($rowOrVnid = "")
 {
     if (is_array($rowOrVnid)) {
         $this->version = $rowOrVnid;
     } else {
         if ($rowOrVnid != "") {
             global $db;
             $result = $db->selectQuery('select * from ' . Config::dbSurvey() . '_versions where suid=' . prepareDatabaseString(getSurvey()) . ' and vnid = ' . prepareDatabaseString($rowOrVnid));
             $this->version = $db->getRow($result);
         }
     }
 }
Example #8
0
 function addRemark($primkey, $remark, $urid)
 {
     global $db;
     $query = 'replace into ' . Config::dbSurvey() . '_remarks (primkey, remark, urid, ts) values (\'' . prepareDatabaseString($primkey) . '\', aes_encrypt(\'' . prepareDatabaseString($remark) . '\',\'' . Config::smsRemarkKey() . '\'), ' . $urid . ', \'' . date('Y-m-d H:i:s') . '\')';
     //      echo '<br/><br/><br/>' . $query;
     $db->executeQuery($query);
     if (isset($this->remarksArray[$primkey])) {
         unset($this->remarksArray[primkey]);
         //remove from array so getremarks re-reads it.
     }
     return $query;
 }
Example #9
0
 function getEntry($trid)
 {
     global $db;
     $query = "select * from " . Config::dbSurvey() . "_tracks where trid=" . prepareDatabaseString($trid);
     $res = $db->selectQuery($query);
     $arr = array();
     if ($res) {
         if ($db->getNumberOfRows($res) > 0) {
             $arr = $db->getRow($res);
         }
     }
     return $arr;
 }
Example #10
0
 {
     return dbConfig::dbServer();
 }
 static function dbType()
 {
     return dbConfig::dbType();
 }
 static function dbSurveyData()
 {
     if (isset($_SESSION[SURVEY_EXECUTION_MODE])) {
         switch ($_SESSION[SURVEY_EXECUTION_MODE]) {
             case SURVEY_EXECUTION_MODE_NORMAL:
                 return Config::dbSurvey();
             case SURVEY_EXECUTION_MODE_TEST:
                 return Config::dbSurvey() . "_test";
Example #11
0
 function getUsers()
 {
     global $db;
     if (isset($this->userArray[$_SESSION['URID']])) {
         $users = $this->userArray[$_SESSION['URID']];
     } else {
         $users = array();
         $result = $db->selectQuery('SELECT ' . $this->getSelectQuery() . ' FROM ' . Config::dbSurvey() . '_users');
         while ($row = $db->getRow($result)) {
             $users[] = new User($row);
         }
         $this->userArray[$_SESSION['URID']] = $users;
     }
     return $users;
 }
Example #12
0
 function DataExport($suid)
 {
     global $db, $survey;
     $this->db = $db;
     $this->suid = $suid;
     $this->survey = new Survey($this->suid);
     $survey = $this->survey;
     $this->variabledescriptives = array();
     $this->setProperty(DATA_OUTPUT_MAINTABLE, Config::dbSurvey());
     $this->setProperty(DATA_OUTPUT_MAINDATATABLE, Config::dbSurveyData());
     /* set file names */
     $this->setProperty(DATA_OUTPUT_FILENAME, $this->getProperty(DATA_OUTPUT_MAINTABLE));
     /* set defaults */
     $this->setProperty(DATA_OUTPUT_FILETYPE, FILETYPE_STATA);
     $this->setProperty(DATA_OUTPUT_SURVEY, "");
     $this->setProperty(DATA_OUTPUT_MODES, "");
     $this->setProperty(DATA_OUTPUT_LANGUAGES, "");
     $this->setProperty(DATA_OUTPUT_VERSIONS, "");
     $this->setProperty(DATA_OUTPUT_PRIMARY_KEY_IN_DATA, PRIMARYKEY_YES);
     $this->setProperty(DATA_OUTPUT_HIDDEN, DATA_NOTHIDDEN);
     $this->setProperty(DATA_OUTPUT_CLEAN, DATA_DIRTY);
     $this->setProperty(DATA_OUTPUT_INCLUDE_VALUE_LABEL_NUMBERS, VALUELABELNUMBERS_YES);
     $this->setProperty(DATA_OUTPUT_FIELDNAME_CASE, FIELDNAME_LOWERCASE);
     $this->setProperty(DATA_OUTPUT_INCLUDE_VALUE_LABELS, VALUELABEL_YES);
     $this->setProperty(DATA_OUTPUT_VARIABLES_WITHOUT_DATA, VARIABLES_WITHOUT_DATA_YES);
     $this->setProperty(DATA_OUTPUT_VALUELABEL_PREFIX, $this->getProperty(DATA_OUTPUT_MAINTABLE) . "_vl");
     $this->setProperty(DATA_OUTPUT_VALUELABEL_WIDTH, VALUELABEL_WIDTH_FULL);
     $this->setProperty(DATA_OUTPUT_ENCODING, "UTF-8");
     $this->setProperty(DATA_OUTPUT_COMPLETED, INTERVIEW_NOTCOMPLETED);
     $this->setProperty(DATA_OUTPUT_MARK_EMPTY, MARKEMPTY_IN_VARIABLE);
     $this->setProperty(DATA_OUTPUT_KEEP_ONLY, DATA_KEEP_NO);
     $this->setProperty(DATA_OUTPUT_CLEAN, DATA_CLEAN);
     $this->setProperty(DATA_OUTPUT_TYPEDATA, DATA_REAL);
     $this->setProperty(DATA_OUTPUT_VARLIST, "");
     $this->setProperty(DATA_OUTPUT_TYPE, DATA_OUTPUT_TYPE_DATA_TABLE);
     $this->setProperty(DATA_OUTPUT_PRIMARY_KEY_ENCRYPTION, "");
     $this->setProperty(DATA_OUTPUT_FROM, "");
     $this->setProperty(DATA_OUTPUT_TO, "");
     $this->minprimkeylength = Config::getMinimumPrimaryKeyLength();
     $this->maxprimkeylength = Config::getMaximumPrimaryKeyLength();
 }
Example #13
0
 function getBarcode()
 {
     $barcode = $this->lab['barcode_dec'];
     if ($barcode != '') {
         return $this->lab['barcode_dec'];
     } else {
         //lookup barcode!!! in haalsi_data -> stored at BS021
         global $survey, $db;
         $query = 'select *, aes_decrypt(answer, "' . $survey->getDataEncryptionKey() . '") as answer from ' . Config::dbSurvey() . '_data where primkey = "' . prepareDatabaseString($this->getPrimkey()) . '" and variablename="bs021"';
         $result = $db->selectQuery($query);
         //            print_r($result);
         if ($result != null && $db->getNumberOfRows($result) > 0) {
             $row = $db->getRow($result);
             $barcode = $row['answer'];
             $this->lab['barcode_dec'] = $barcode;
             $this->saveChanges();
             return $barcode;
         } else {
             //no barcode....
             //echo "no code";
             return '';
         }
     }
 }
 function save()
 {
     global $db;
     if (!isset($this->variabledescriptive['vsid'])) {
         $query = "select max(vsid) as max from " . Config::dbSurvey() . "_variables";
         $r = $db->selectQuery($query);
         $row = $db->getRow($r);
         $vsid = $row["max"] + 1;
         $this->setObjectName($vsid);
         $this->setVsid($vsid);
         /* set position */
         $query = "select max(position) as max from " . Config::dbSurvey() . "_variables where suid=" . $this->getSuid() . " and seid=" . $this->getSeid();
         $r = $db->selectQuery($query);
         $row = $db->getRow($r);
         $pos = $row["max"] + 1;
         $this->setPosition($pos);
     }
     $query = "replace into " . Config::dbSurvey() . "_variables (suid, vsid, seid, variablename, position, tyd) values(";
     $query .= prepareDatabaseString($this->getSuid()) . ",";
     $query .= prepareDatabaseString($this->getVsid()) . ",";
     $query .= prepareDatabaseString($this->getSeid()) . ",";
     $query .= "'" . prepareDatabaseString($this->getName()) . "',";
     $order = $this->getPosition();
     if ($order == "") {
         $order = 1;
     }
     $query .= prepareDatabaseString($order) . ",";
     $tyd = $this->getTyd();
     if ($tyd == "") {
         $tyd = -1;
     }
     $query .= prepareDatabaseString($tyd) . "";
     $query .= ")";
     $db->executeQuery($query);
     /* save settings */
     $settings = $this->getSettingsArray();
     foreach ($settings as $key => $setting) {
         $setting->setObject($this->getVsid());
         $setting->setSuid($this->getSuid());
         $setting->save();
     }
 }
Example #15
0
 function getRespondentsByUrid($urid)
 {
     global $db;
     $respondents = array();
     $query = 'select primkey from ' . Config::dbSurvey() . '_lab where urid = \'' . prepareDatabaseString($urid) . '\'';
     $result = $db->selectQuery($query);
     while ($row = $db->getRow($result)) {
         $respondents[] = new Respondent($row['primkey']);
     }
     return $respondents;
 }
Example #16
0
 function save()
 {
     global $db;
     if (!isset($this->group['gid'])) {
         $query = "select max(gid) as max from " . Config::dbSurvey() . "_groups";
         $r = $db->selectQuery($query);
         $row = $db->getRow($r);
         $gid = $row["max"] + 1;
         $this->setObjectName($gid);
         $this->setGid($gid);
     }
     $query = "replace into " . Config::dbSurvey() . "_groups (suid, gid, name) values(";
     $query .= prepareDatabaseString($this->getSuid()) . ",";
     $query .= prepareDatabaseString($this->getGid()) . ",";
     $query .= "'" . prepareDatabaseString($this->getName()) . "'";
     $query .= ")";
     //echo $query;
     $db->executeQuery($query);
     /* save settings */
     $settings = $this->getSettingsArray();
     foreach ($settings as $key => $setting) {
         $setting->setObject($this->getGid());
         $setting->setSuid($this->getSuid());
         $setting->save();
     }
 }
Example #17
0
 function reportRes()
 {
     global $db;
     $query = "insert into " . Config::dbSurvey() . "_issues (urid,suid,primkey,mainseid,seid,rgid,displayed,category,comment,status,language,mode,version) values (";
     $query .= getFromSessionParams('reporturid') . ",";
     $query .= getFromSessionParams('reportsuid') . ",";
     $query .= "'" . getFromSessionParams('reportprimkey') . "',";
     $query .= "'" . getFromSessionParams('reportmainseid') . "',";
     $query .= "'" . getFromSessionParams('reportseid') . "',";
     $query .= "'" . getFromSessionParams('reportrgid') . "',";
     $query .= "'" . getFromSessionParams('reportdisplayed') . "',";
     $query .= "'" . loadvar('reportcategory') . "',";
     $query .= "'" . loadvar('reportcomment') . "',";
     $query .= ISSUE_REPORTED . ", ";
     $query .= "'" . getFromSessionParams('reportlanguage') . "',";
     $query .= "'" . getFromSessionParams('reportmode') . "',";
     $query .= "'" . getFromSessionParams('reportversion') . "'";
     $query .= ")";
     //echo $query;
     $db->executeQuery($query);
     $returnStr = $this->showHeader(Language::messageSMSTitle());
     $returnStr .= '<div id="wrap">';
     $returnStr .= '<div class="container"><p>';
     $returnStr .= $this->reportSub('<div class="alert alert-success">' . Language::reportProblemConfirmation() . '</div>');
     //'<button onclick="window.close();" type="cancel" class="btn btn-default" style="min-width:100px">' . Language::buttonClose() . '</button>';
     $returnStr .= '                </div></div>';
     $returnStr .= '</p></div>    </div>';
     //container and wrap
     $returnStr .= $this->showFooter();
     echo $returnStr;
 }
Example #18
0
 //echo $query;
 if ($res) {
     $row4 = $db->getRow($res);
     $loopmin = $row4["loopmin"];
     $loopmax = $row4["loopmax"];
     $loopcounters = $row4["loopcounter"];
 }
 // go through outer/inner loops
 $counters = explode("~", $loopcounters);
 $current = "";
 foreach ($counters as $count) {
     if ($current == "") {
         $current = $engine->getAnswer($count);
     } else {
         $current = $current * $engine->getAnswer($count);
     }
Example #19
0
 function exportNubis()
 {
     global $db;
     $exporttables = Common::surveyExportTables();
     $returnStr = "";
     /* based off https://davidwalsh.name/backup-mysql-database-php */
     foreach ($exporttables as $export) {
         if (strtoupper($export) == strtoupper("_tracks")) {
             continue;
         }
         $query = 'select * from ' . Config::dbSurvey() . $export . ' where suid=' . $this->suid;
         $result = $db->selectQuery($query);
         $num_fields = $db->getNumberOfFields($result);
         $fields = $db->getFields($result);
         $num_fields = sizeof($fields);
         $fieldstr = "";
         // `
         for ($i = 0; $i < $num_fields; $i++) {
             if ($fieldstr != "") {
                 $fieldstr .= ",";
             }
             $fi = $fields[$i];
             $fieldstr .= $fi->name;
         }
         // add content (table name and suid are added as placeholders)
         while ($row = $db->getRow($result)) {
             $returnStr .= $export . EXPORT_DELIMITER . $fieldstr . EXPORT_DELIMITER;
             for ($j = 0; $j < $num_fields; $j++) {
                 $fi = $fields[$j];
                 if (strtoupper($fi->name) == strtoupper(EXPORT_COLUMN_SUID)) {
                     $returnStr .= '"' . EXPORT_PLACEHOLDER_SUID . '"';
                 } else {
                     if (strtoupper($fi->name) == strtoupper(EXPORT_COLUMN_URID)) {
                         $returnStr .= '"' . EXPORT_PLACEHOLDER_URID . '"';
                     } else {
                         if (isset($row[$j])) {
                             $returnStr .= '"' . prepareExportString($row[$j]) . '"';
                         } else {
                             $returnStr .= prepareExportString('""');
                         }
                     }
                 }
                 if ($j < $num_fields - 1) {
                     $returnStr .= ',';
                 }
             }
             $returnStr .= "\r\n";
         }
     }
     // output as SQL file
     /* allow for time */
     set_time_limit(0);
     // http://www.richnetapps.com/the-right-way-to-handle-file-downloads-in-php/
     /* declare headers */
     header("Content-Description: File Transfer");
     header("Content-Type: application/force-download");
     header("Content-Type: application/download");
     header('Content-Type: application/octet-stream');
     header("Content-Disposition: attachment; filename=" . Config::dbSurvey() . EXPORT_FILE_NUBIS . '; modification-date="' . date('r', time()) . '";');
     header("Content-Type: application/sql");
     /* prevent caching (http://stackoverflow.com/questions/13640109/how-to-prevent-browser-cache-for-php-site) */
     header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     // http://stackoverflow.com/questions/15299325/x-download-options-noopen-equivalent
     header("X-Content-Type-Options: nosniff");
     // http://stackoverflow.com/questions/21723436/firefox-downloads-text-plain-instead-of-showing-it
     /* clean buffer before outputting file */
     ob_end_clean();
     // echo output
     echo $returnStr;
     // stop
     exit;
 }
Example #20
0
 function getRefusalsByUrid($urid)
 {
     global $db;
     if (isset($this->refusalsByUridArray[$urid])) {
         $contacts = $this->refusalsByUridArray[$urid];
     } else {
         $contacts = array();
         //$csidQuery = ' AND code = 103 ';
         //   $result = $db->selectQuery('select *, aes_decrypt(remark, "' . Config::smsContactRemarkKey() . '") as remark_dec, aes_decrypt(proxyname, "' . Config::smsContactNameKey() . '") as proxyname_dec from ' . Config::dbSurvey() . '_contacts as t1 left join ' . Config::dbSurvey() . '_users as t2 on t1.urid = t2.urid where t1.urid = ' . prepareDatabaseString($urid) . $csidQuery . ' order by t1.contactts desc');
         //echo '<br/><br/><br/>'. 'select *, aes_decrypt(remark, "' . Config::smsContactRemarkKey() . '") as remark_dec, aes_decrypt(proxyname, "' . Config::smsContactNameKey() . '") as proxyname_dec from ' . Config::dbSurvey() . '_contacts as t1 left join ' . Config::dbSurvey() . '_users as t2 on t1.urid = t2.urid where t1.urid = ' . prepareDatabaseString($urid) . ' order by t1.contactts desc';
         $query = 'select *, aes_decrypt(remark, "' . Config::smsContactRemarkKey() . '") as remark_dec, aes_decrypt(proxyname, "' . Config::smsContactNameKey() . '") as proxyname_dec from ' . Config::dbSurvey() . '_contacts as t1 ';
         $query .= 'left join ' . Config::dbSurvey() . '_users as t2 on t1.urid = t2.urid ';
         $query .= 'left join ' . Config::dbSurvey() . '_respondents as t3 on t1.primkey = t3.primkey ';
         $query .= 'where t3.primkey is not null AND ' . getTextmodeStr() . ' t1.urid = ' . prepareDatabaseString($urid) . ' order by t1.contactts desc';
         $result = $db->selectQuery($query);
         while ($row = $db->getRow($result)) {
             $contact = new Contact($row);
             if ($contact->isRefusal()) {
                 $contacts[] = $contact;
             }
         }
         $this->refusalsByUridArray[$urid] = $contacts;
     }
     return $contacts;
 }
Example #21
0
 function getReportedIssues()
 {
     global $db;
     $query = "select * from " . Config::dbSurvey() . "_issues where suid=" . $this->getSuid();
     $res = $db->selectQuery($query);
     $arr = array();
     if ($res) {
         if ($db->getNumberOfRows($res) > 0) {
             while ($row = $db->getRow($res)) {
                 $arr[] = $row;
             }
         }
     }
     return $arr;
 }
Example #22
0
 function showCleanRes()
 {
     /* update last page */
     $_SESSION['LASTPAGE'] = substr($_SESSION['LASTPAGE'], 0, strripos($_SESSION['LASTPAGE'], "res"));
     $clean = loadvar("clean");
     $from = loadvar("from");
     $to = loadvar("to");
     $datatypes = loadvar("datatype");
     global $db;
     $content = "";
     $displaySysAdmin = new DisplaySysAdmin();
     if ($clean != "" && $datatypes != "") {
         foreach ($clean as $cl) {
             $tsquery = "";
             if ($from != "") {
                 $tsquery .= " and ts > '" . $from . "'";
             }
             if ($to != "") {
                 $tsquery .= " and ts < '" . $to . "'";
             }
             $tables = array();
             if (inArray(SURVEY_EXECUTION_MODE_NORMAL, $datatypes)) {
                 $tables[] = Config::dbSurvey();
             }
             if (inArray(SURVEY_EXECUTION_MODE_TEST, $datatypes)) {
                 $tables[] = Config::dbSurvey() . "_test";
             }
             foreach ($tables as $table) {
                 $query = "delete from " . $table . "_actions where suid=" . $cl . " and systemtype=" . USCIC_SURVEY . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_data where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_datarecords where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_screendumps where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_logs where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_observations where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_states where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_times where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_paradata where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_loopdata where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_consolidated_times where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
                 $query = "delete from " . $table . "_processed_paradata where suid=" . $cl . $tsquery;
                 $db->executeQuery($query);
             }
         }
         $content = $displaySysAdmin->displaySuccess(Language::messageToolsCleanOk());
     } else {
         if ($clean == "") {
             $content = $displaySysAdmin->displayWarning(Language::messageToolsCleanSelectSurvey());
         } else {
             if ($datatypes == "") {
                 $content = $displaySysAdmin->displayWarning(Language::messageToolsCleanSelectDataType());
             }
         }
     }
     return $displaySysAdmin->showClean($content);
 }
Example #23
0
 function getLastUploaded($urid)
 {
     global $db;
     $query = 'select max(ts) as lastupdated from ' . Config::dbSurvey() . '_communication where direction = 2 and urid = ' . $urid;
     $result = $db->selectQuery($query);
     $row = $db->getRow($result);
     return $row['lastupdated'];
 }
Example #24
0
 function getContactCodeData($code)
 {
     global $db;
     $dataStr = '';
     $actions = array();
     $query = 'select DATE(ts) as dateobs, count(*) as cntobs, primkey from ' . Config::dbSurvey() . '_contacts where code = ' . $code . ' group by DATE(ts) order by ts asc';
     $total = 0;
     $dataStr .= "[Date.UTC(2014,  6, 20), 0   ],";
     $result = $db->selectQuery($query);
     while ($row = $db->getRow($result)) {
         $key = $row['dateobs'];
         $total += $row['cntobs'];
         $dataStr .= "[Date.UTC(" . substr($key, 0, 4) . ", " . (substr($key, 5, 2) - 1) . ", " . substr($key, 8, 2) . "), " . $total . "],";
     }
     $returnStr = rtrim($dataStr, ',');
     return $returnStr;
 }
Example #25
0
 function generateProgressbarSection($progressbar, $mainseid, $sectionseid, $sectionrgid, $outerlooptimes = "", $loopstring = "", $loopcount = "")
 {
     global $db;
     $q1 = "select * from " . Config::dbSurvey() . "_screens where suid=" . $this->suid . " and seid=" . $sectionseid . " order by number asc, rgid asc, dummy asc";
     $res1 = $db->selectQuery($q1);
     if ($res1) {
         if ($db->getNumberOfRows($res1) > 0) {
             while ($row1 = $db->getRow($res1)) {
                 // no section or loop stuff
                 if ($row1["section"] == -1 && $row1["outerlooptimes"] == -1 && $row1["dummy"] == 0) {
                     //echo 'Adding entry in section ' . $sectionseid . " with loopstring " . $loopstring . "<br/>";
                     $progressbar->addEntry($sectionseid, $sectionrgid, $row1["rgid"], $loopstring, $row1["ifrgid"], $loopcount);
                 } else {
                     if ($row1["outerlooptimes"] != -1) {
                         $actions = array();
                         // TODO: WILL THIS WORK WITH NESTED LOOPS???
                         $actions[] = array("ifrgid" => $row1["ifrgid"], "rgid" => $row1["rgid"], "looptimes" => $row1["looptimes"], "outerlooptimes" => $row1["outerlooptimes"], "section" => $row1["section"], "dummy" => $row1["dummy"]);
                         /* find actions until end of loop */
                         while ($row2 = $db->getRow($res1)) {
                             if ($row2["outerlooptimes"] == -1) {
                                 $toadd = $row2["rgid"];
                                 break;
                             }
                             $actions[] = array("ifrgid" => $row2["ifrgid"], "rgid" => $row2["rgid"], "looptimes" => $row2["looptimes"], "outerlooptimes" => $row2["outerlooptimes"], "section" => $row2["section"], "dummy" => $row2["dummy"]);
                         }
                         //echo 'Processing loop in ' . $sectionseid . " at " . $row1["rgid"] . "<br/>";
                         $this->generateProgressBarLoop($progressbar, $sectionseid, $sectionrgid, $row1["rgid"], $row1["looptimes"], $row1["looptimes"], $row1["outerlooptimes"], $actions, $loopstring);
                         //echo 'fniished with loop in ' . $sectionseid . " at " . $row1["rgid"] . "<br/>";
                         // add the action right after end of loop
                         // next one is a question screen
                         if ($row2["section"] == -1 && $row2["outerlooptimes"] == -1 && $row2["dummy"] == 0) {
                             $progressbar->addEntry($sectionseid, $sectionrgid, $toadd, $loopstring, $row2["ifrgid"]);
                         } else {
                             if ($row2["outerlooptimes"] != -1) {
                                 $actions = array();
                                 // TODO: WILL THIS WORK WITH NESTED LOOPS???
                                 $actions[] = array("ifrgid" => $row2["ifrgid"], "rgid" => $row2["rgid"], "looptimes" => $row2["looptimes"], "outerlooptimes" => $row2["outerlooptimes"], "section" => $row2["section"], "dummy" => $row2["dummy"]);
                                 /* find actions until end of loop */
                                 while ($row3 = $db->getRow($res1)) {
                                     if ($row3["outerlooptimes"] == -1) {
                                         $toadd = $row3["rgid"];
                                         break;
                                     }
                                     $actions[] = array("ifrgid" => $row3["ifrgid"], "rgid" => $row3["rgid"], "looptimes" => $row3["looptimes"], "outerlooptimes" => $row3["outerlooptimes"], "section" => $row3["section"], "dummy" => $row3["dummy"]);
                                 }
                                 //echo 'Processing loop in ' . $sectionseid . " at " . $row1["rgid"] . "<br/>";
                                 //$this->generateProgressBarLoop($progressbar, $sectionseid, $sectionrgid, $row2["rgid"], $row2["looptimes"], $row2["looptimes"], $row2["outerlooptimes"], $actions, $loopstring);
                             } else {
                                 if ($row2["section"] > -1 && $row2["dummy"] == 0) {
                                     $this->generateProgressbarSection($progressbar, $sectionseid, $row2["section"], $row2["rgid"], $outerlooptimes, $loopstring);
                                 }
                             }
                         }
                     } else {
                         if ($row1["section"] > -1 && $row1["dummy"] == 0) {
                             //echo 'Processing section in ' . $sectionseid . " at " . $row1["section"] . "<br/>";
                             //if ($row1["ifrgid"] > 0) {
                             //    echo 'HEHEHE WE SHOULD RESET HERE';
                             //}
                             //echo 'section!!!';
                             $this->generateProgressbarSection($progressbar, $sectionseid, $row1["section"], $row1["rgid"], $outerlooptimes, $loopstring);
                         }
                     }
                 }
             }
         }
     }
 }
Example #26
0
                     $user->setLanguages($this->suid, $m, $survey->getAllowedLanguages($m));
                 }
                 $user->saveChanges();
             }
         }
     }
 }
 function convertSurveySettings($row)
 {
     $query = "replace into " . Config::dbSurvey() . "_surveys (suid, name, description) values (";
     $query .= prepareDatabaseString($this->suid) . ",";
     $query .= "'" . prepareDatabaseString($row["header"]) . "',";
     $query .= "'')";
     $this->db->executeQuery($query);
     $query = "replace into " . Config::dbSurvey() . "_versions (suid, vnid, name, description) values (";
     $query .= prepareDatabaseString($this->suid) . ",";
     $query .= prepareDatabaseString(1) . ",";
     $query .= "'Current',";
     $query .= "'Current version')";
     $this->db->executeQuery($query);
     /* add default survey */
     $setting = new Setting();
     $setting->setSuid($this->suid);
     $setting->setObject(USCIC_SURVEY);
     $setting->setObjectType(OBJECT_SURVEY);
     $setting->setName(SETTING_DEFAULT_SURVEY);
     $setting->setValue($this->suid);
     $setting->setMode(MODE_CASI);
     // dummy
     $setting->setLanguage(1);
     // dummy
     $setting->save();
     /* add default mode */
     $setting = new Setting();
     $setting->setSuid($this->suid);
     $setting->setObject(USCIC_SURVEY);
     $setting->setObjectType(OBJECT_SURVEY);
     $setting->setName(SETTING_DEFAULT_MODE);
     $setting->setMode(MODE_CASI);
     $setting->setLanguage(1);
     // dummy
     $setting->setValue(MODE_CASI);
     $setting->save();
     /* add default language */
     $setting = new Setting();
     $setting->setSuid($this->suid);
     $setting->setObject(USCIC_SURVEY);
     $setting->setObjectType(OBJECT_SURVEY);
     $setting->setName(SETTING_DEFAULT_LANGUAGE);
Example #27
0
    function showSearchSysadmin($searchparameters)
    {
        $returnStr = '<a id="closelink" class="close pull-right">&times;</a>';
        $returnStr .= "<script type='text/javascript'>\n                        \$ ('#closelink').click(function(event) {\n                                \$.sidr('close', 'optionssidebar');\n                                \$.get('" . setSessionParams(array("page" => "sysadmin.search.hide")) . "&updatesessionpage=2" . "',{},function(response){});\n                            });\n                        ";
        $returnStr .= "</script>";
        if (trim($searchparameters) == "") {
            $returnStr .= $this->displayWarning(Language::messageSearchNoTerm());
        } else {
            global $db, $survey;
            $query = "select * from " . Config::dbSurvey() . "_settings where suid=" . $_SESSION['SUID'] . " and CONVERT(value using utf8) COLLATE utf8_general_ci like '%" . prepareDatabaseString($searchparameters) . "%' group by objecttype,object order by objecttype, object";
            $res = $db->selectQuery($query);
            $query1 = "select * from " . Config::dbSurvey() . "_routing where suid=" . $_SESSION['SUID'] . " and CONVERT(rule using utf8) COLLATE utf8_general_ci like '%" . prepareDatabaseString($searchparameters) . "%' order by seid asc, rgid asc";
            $res1 = $db->selectQuery($query1);
            if ($res || $res1) {
                if ($db->getNumberOfRows($res) == 0 && $db->getNumberOfRows($res1) == 0) {
                    $returnStr .= $this->displayWarning(Language::labelNoSearched($searchparameters));
                } else {
                    /*
                     * 
                     */
                    $returnStr .= $this->displayCookieScripts();
                    $returnStr .= "<script type='text/javascript'>\n                        \$(document).ready(function(){\n                            \$('#search a').bind('click',function(event){\n                                  event.preventDefault();\n                                  var url=this.href + \"&" . POST_PARAM_AJAX_LOAD . "=" . AJAX_LOAD . "\";\n                                  \$.get(url,{},function(response){ \n                                     \$('#content').html(\$(response).children().first())\n                              })\t\n                           })\n                          });\n                        ";
                    $returnStr .= "</script>";
                    $_SESSION['SEARCH'] = SEARCH_OPEN_YES;
                    $_SESSION['SEARCHTERM'] = $searchparameters;
                    $returnStr .= $this->displaySuccess(Language::labelSearched($searchparameters));
                    $var_results = array();
                    $type_results = array();
                    $survey_results = array();
                    $group_results = array();
                    $section_results = array();
                    // TODO: HOW TO GROUP HERE: VARIABLE YES, SURVEY NO, SHOW NUMBER OF PLACES FOUND IN CASE OF MULTIPLE LOCATIONS? OR SHOW ALL ENTRIES?
                    if ($db->getNumberOfRows($res) > 0) {
                        while ($row = $db->getRow($res)) {
                            /* process */
                            switch ($row["objecttype"]) {
                                case OBJECT_VARIABLEDESCRIPTIVE:
                                    $variable = $survey->getVariableDescriptive($row["object"]);
                                    $tagclass = "";
                                    //'class="btn btn-default"';
                                    if (isset($_COOKIE['uscicvariablecookie'])) {
                                        $cookievalue = $_COOKIE['uscicvariablecookie'];
                                        if (inArray($variable->getSuid() . "~" . $variable->getVsid(), explode("-", $cookievalue))) {
                                            $tagclass = 'class="uscic-cookie-tag-active"';
                                        }
                                    }
                                    $var_results[$row["name"] . $row["object"] . $row["objecttype"]] = "<tr>\n                                            <td><a " . $tagclass . ' onclick="var res = updateCookie(\'uscicvariablecookie\',\'' . $variable->getSuid() . "~" . $variable->getVsid() . '\'); if (res == 1) { $(this).addClass(\'uscic-cookie-tag-active\'); } else { $(this).removeClass(\'uscic-cookie-tag-active\'); } return false;" title="' . Language::linkTagTooltip() . '" href="" role="button"><span class="glyphicon glyphicon-tag"></span></a></td>' . "<td><a class='searchlink' href='" . setSessionParams(array("page" => "sysadmin.survey.editvariable", "suid" => $_SESSION['SUID'], "vsid" => $row["object"])) . "'>" . $variable->getName() . "</a></td>                                                      \n                                                          </tr>";
                                    break;
                                case OBJECT_TYPE:
                                    $type = $survey->getType($row["object"]);
                                    $tagclass = "";
                                    //'class="btn btn-default"';
                                    if (isset($_COOKIE['uscictypeecookie'])) {
                                        $cookievalue = $_COOKIE['uscictypecookie'];
                                        if (inArray($type->getSuid() . "~" . $type->getTyd(), explode("-", $cookievalue))) {
                                            $tagclass = 'class="uscic-cookie-tag-active"';
                                        }
                                    }
                                    $type_results[] = "<tr>\n                                        <td><a " . $tagclass . ' onclick="var res = updateCookie(\'uscictypecookie\',\'' . $type->getSuid() . "~" . $type->getTyd() . '\'); if (res == 1) { $(this).addClass(\'uscic-cookie-tag-active\'); } else { $(this).removeClass(\'uscic-cookie-tag-active\'); } return false;" title="' . Language::linkTagTooltip() . '" href="" role="button"><span class="glyphicon glyphicon-tag"></span></a></td>' . "<td><a class='searchlink' href='" . setSessionParams(array("page" => "sysadmin.survey.edittype", "suid" => $_SESSION['SUID'], "tyd" => $row["object"])) . "'>" . $type->getName() . "</a></td>\n\n                                                          </tr>";
                                    break;
                                case OBJECT_SECTION:
                                    $section = $survey->getSection($row["object"]);
                                    $tagclass = "";
                                    //'class="btn btn-default"';
                                    if (isset($_COOKIE['uscicsectioncookie'])) {
                                        $cookievalue = $_COOKIE['uscicsectioncookie'];
                                        if (inArray($section->getSuid() . "~" . $section->getSeid(), explode("-", $cookievalue))) {
                                            $tagclass = 'class="uscic-cookie-tag-active"';
                                        }
                                    }
                                    $section_results[] = "<tr>\n                                        <td><a " . $tagclass . ' onclick="var res = updateCookie(\'uscicsectioncookie\',\'' . $section->getSuid() . "~" . $section->getSeid() . '\'); if (res == 1) { $(this).addClass(\'uscic-cookie-tag-active\'); } else { $(this).removeClass(\'uscic-cookie-tag-active\'); } return false;" title="' . Language::linkTagTooltip() . '" href="" role="button"><span class="glyphicon glyphicon-tag"></span></a></td>' . "<td><a class='searchlink' href='" . setSessionParams(array("page" => "sysadmin.survey.editsection", "suid" => $_SESSION['SUID'], "seid" => $row["object"])) . "'>" . $section->getName() . "</a></td>\n\n                                                          </tr>";
                                    break;
                                case OBJECT_GROUP:
                                    $group = $survey->getGroup($row["object"]);
                                    $tagclass = "";
                                    //'class="btn btn-default"';
                                    if (isset($_COOKIE['uscicgroupcookie'])) {
                                        $cookievalue = $_COOKIE['uscicgroupcookie'];
                                        if (inArray($group->getSuid() . "~" . $group->getGid(), explode("-", $cookievalue))) {
                                            $tagclass = 'class="uscic-cookie-tag-active"';
                                        }
                                    }
                                    $group_results[] = "<tr>\n                                        <td><a " . $tagclass . ' onclick="var res = updateCookie(\'uscicgroupcookie\',\'' . $group->getSuid() . "~" . $group->getGid() . '\'); if (res == 1) { $(this).addClass(\'uscic-cookie-tag-active\'); } else { $(this).removeClass(\'uscic-cookie-tag-active\'); } return false;" title="' . Language::linkTagTooltip() . '" href="" role="button"><span class="glyphicon glyphicon-tag"></span></a></td>' . "<td><a class='searchlink' href='" . setSessionParams(array("page" => "sysadmin.survey.editgroup", "suid" => $_SESSION['SUID'], "gid" => $row["object"])) . "'>" . $group->getName() . "</a></td>\n\n                                                          </tr>";
                                    break;
                                case OBJECT_SURVEY:
                                    $survey_results[] = "<tr>\n                                                            <td>" . $survey->getName() . "</td>                                                      \n                                                          </tr>";
                                    break;
                            }
                        }
                    }
                    $var_header .= '<div id="collapseVariables" class="panel-collapse collapse">
                                            <div class="panel-body">';
                    if (sizeof($var_results) > 0) {
                        $var_header .= '<table class="table table-striped table-bordered">
                                        <thead>
                                        <th></th><th align=middle>' . Language::labelSearchName() . '</th>' . '</thead>
                                        <tbody data-link="row" class="rowlink">';
                        $var_footer .= "</tbody></table></div></div>";
                    } else {
                        $var_footer .= "</div></div>";
                    }
                    $type_header .= '<div id="collapseTypes" class="panel-collapse collapse">
                                            <div class="panel-body">';
                    if (sizeof($type_results) > 0) {
                        $type_header .= '<table class="table table-striped table-bordered">
                                        <thead>
                                        <th align=middle>' . Language::labelSearchName() . '</th>' . '</thead>
                                        <tbody data-link="row" class="rowlink">';
                        $type_footer .= "</tbody></table></div></div>";
                    } else {
                        $type_footer .= "</div></div>";
                    }
                    $survey_header .= '<div id="collapseSurvey" class="panel-collapse collapse">
                                            <div class="panel-body">';
                    if (sizeof($survey_results) > 0) {
                        $survey_header .= '<table class="table table-striped table-bordered">
                                        <thead>
                                        <th align=middle>' . Language::labelSearchName() . '</th>' . '</thead>
                                        <tbody data-link="row" class="rowlink">';
                        $survey_footer .= "</tbody></table></div></div>";
                    } else {
                        $survey_footer .= "</div></div>";
                    }
                    $group_header .= '<div id="collapseGroups" class="panel-collapse collapse">
                                            <div class="panel-body">';
                    if (sizeof($group_results) > 0) {
                        $group_header .= '<table class="table table-striped table-bordered">
                                        <thead>
                                        <th align=middle>' . Language::labelSearchName() . '</th>' . '</thead>
                                        <tbody data-link="row" class="rowlink">';
                        $group_footer .= "</tbody></table></div></div>";
                    } else {
                        $group_footer .= "</div></div>";
                    }
                    $section_header .= '<div id="collapseSections" class="panel-collapse collapse">
                                            <div class="panel-body">';
                    if (sizeof($section_results) > 0) {
                        $section_header .= '<table class="table table-striped table-bordered">
                                        <thead>
                                        <th align=middle>' . Language::labelSearchName() . '</th>' . '</thead>
                                        <tbody data-link="row" class="rowlink">';
                        $section_footer .= "</tbody></table></div></div>";
                    } else {
                        $section_footer .= "</div></div>";
                    }
                    /* search in routing */
                    $routing_results = array();
                    $routing_header .= '<div id="collapseRouting" class="panel-collapse collapse">
                                            <div class="panel-body">';
                    if ($db->getNumberOfRows($res1) > 0) {
                        while ($row = $db->getRow($res1)) {
                            $section = $survey->getSection($row["seid"]);
                            $routing_results[] = "<tr>\n                                                    <td><a class='searchlink' href='" . setSessionParams(array("page" => "sysadmin.survey.section", "suid" => $_SESSION['SUID'], "seid" => $row["seid"], "routingline" => $row["rgid"])) . "'>" . $section->getName() . " at " . Language::labelSearchLine() . " " . $row["rgid"] . "</a></td>\n                                                  </tr>";
                        }
                    }
                    if (sizeof($routing_results) > 0) {
                        $routing_header .= '<table class="table table-striped table-bordered">
                                        <thead>
                                        <th align=middle>' . Language::labelSearchSection() . ' at ' . Language::labelSearchLine() . '</th> 
                                        </thead>
                                        <tbody data-link="row" class="rowlink">';
                        $routing_footer .= "</tbody></table></div></div>";
                    } else {
                        $routing_footer .= "</div></div>";
                    }
                    if (sizeof($var_results) > 0) {
                        $varstring = $var_header . implode("", $var_results) . $var_footer;
                    } else {
                        $varstring = $var_header . $this->displayWarning(Language::messageSearchNoResults()) . $var_footer;
                    }
                    if (sizeof($type_results) > 0) {
                        $typestring = $type_header . implode("", $type_results) . $type_footer;
                    } else {
                        $typestring = $type_header . $this->displayWarning(Language::messageSearchNoResults()) . $type_footer;
                    }
                    if (sizeof($group_results) > 0) {
                        $groupstring = $group_header . implode("", $group_results) . $group_footer;
                    } else {
                        $groupstring = $group_header . $this->displayWarning(Language::messageSearchNoResults()) . $group_footer;
                    }
                    if (sizeof($section_results) > 0) {
                        $sectionstring = $section_header . implode("", $section_results) . $section_footer;
                    } else {
                        $sectionstring = $section_header . $this->displayWarning(Language::messageSearchNoResults()) . $section_footer;
                    }
                    if (sizeof($survey_results) > 0) {
                        $surveystring = $survey_header . implode("", $survey_results) . $survey_footer;
                    } else {
                        $surveystring = $survey_header . $this->displayWarning(Language::messageSearchNoResults()) . $survey_footer;
                    }
                    if (sizeof($routing_results) > 0) {
                        $routingstring = $routing_header . implode("", $routing_results) . $routing_footer;
                    } else {
                        $routingstring = $routing_header . $this->displayWarning(Language::messageSearchNoResults()) . $routing_footer;
                    }
                    $returnStr .= '<div id="search">
                                    <div class="panel-group" id="accordion">
                                       <div class="panel panel-default">
                                          <div class="panel-heading">
                                            <h4 class="panel-title">
                                              <a data-toggle="collapse" data-target="#collapseVariables">
                                                ' . Language::labelSearchVariables() . '(' . sizeof($var_results) . ')
                                              </a>
                                            </h4>
                                          </div> ' . $varstring . '</div>

                                       <div class="panel panel-default">
                                          <div class="panel-heading">
                                            <h4 class="panel-title">
                                              <a data-toggle="collapse" data-target="#collapseSurvey">
                                                ' . Language::labelSearchSurvey() . '(' . sizeof($survey_results) . ')
                                              </a>
                                            </h4>
                                          </div> ' . $surveystring . '</div>
                                              
                                        <div class="panel panel-default">
                                          <div class="panel-heading">
                                            <h4 class="panel-title">
                                              <a data-toggle="collapse" data-target="#collapseRouting">
                                                ' . Language::labelSearchRouting() . '(' . sizeof($routing_results) . ')
                                              </a>
                                            </h4>
                                          </div> ' . $routingstring . '</div>  

                                      <div class="panel panel-default">
                                          <div class="panel-heading">
                                            <h4 class="panel-title">
                                              <a data-toggle="collapse" data-target="#collapseTypes">
                                                ' . Language::labelSearchTypes() . '(' . sizeof($type_results) . ')
                                              </a>
                                            </h4>
                                          </div> ' . $typestring . '</div>

                                      <div class="panel panel-default">
                                          <div class="panel-heading">
                                            <h4 class="panel-title">
                                              <a data-toggle="collapse" data-target="#collapseGroups">
                                                ' . Language::labelSearchGroups() . '(' . sizeof($group_results) . ')
                                              </a>
                                            </h4>
                                          </div> ' . $groupstring . '</div>

                                      <div class="panel panel-default">
                                          <div class="panel-heading">
                                            <h4 class="panel-title">
                                              <a data-toggle="collapse" data-target="#collapseSections">
                                                ' . Language::labelSearchSections() . '(' . sizeof($section_results) . ')
                                              </a>
                                            </h4>
                                          </div> ' . $sectionstring . '</div>';
                    /* accordion end div */
                    $returnStr .= '</div>';
                    /* end search div */
                    $returnStr .= "</div>";
                }
            } else {
                $returnStr .= $this->displayWarning(Language::messageSearchNoResults());
            }
        }
        return $returnStr;
    }
Example #28
0
function getBaseSectionSeid($suid)
{
    global $baseseid;
    if ($baseseid != "") {
        return $baseseid;
    }
    // check in _sections table
    global $db;
    $query = "select seid from " . Config::dbSurvey() . "_sections where suid=" . $suid . " and name='Base'";
    $res = $db->selectQuery($query);
    if ($res) {
        if ($db->getNumberOfRows($res) > 0) {
            $row = $db->getRow($res);
            return $row["seid"];
        }
    }
    // all failed, then assume 1
    return 1;
}
Example #29
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();
                 }
             }
         }
     }
 }
Example #30
0
 function getFirstSurvey($all = false)
 {
     global $db;
     $surveys = array();
     $result = $db->selectQuery('select suid from ' . Config::dbSurvey() . '_surveys order by suid asc');
     if ($result && $db->getNumberOfRows($result) > 0) {
         if ($_SESSION['SYSTEM_ENTRY'] == USCIC_SMS) {
             $user = new User($_SESSION['URID']);
             $avsurveys = $user->getSurveysAccess();
             while ($row = $db->getRow($result)) {
                 if (inArray($row["suid"], $avsurveys) || $all) {
                     return $row["suid"];
                 }
             }
         } else {
             $row = $db->getRow($result);
             return $row["suid"];
         }
     }
     return "";
 }