public function run($args) { global $connect; $field = $args[0]; if (isset($_SESSION['srid'])) { $srid = $_SESSION['srid']; } $sid = returnglobal('sid'); return retrieve_Answer($field, $_SESSION['dateformats']['phpdate']); }
/** * Create the arrays of answer and token replacement fields * This function should only be called once per page display (e.g. only if $fieldMap changes) * * @param <type> $forceRefresh * @return boolean - true if $fieldmap had been re-created, so ExpressionManager variables need to be re-set */ function getAnswerAndTokenMappings($forceRefresh=false,$anonymized=false) { global $globalfieldmap, $clang, $surveyid; //checks to see if fieldmap has already been built for this page. if (isset($globalfieldmap[$surveyid]['full'][$clang->langcode])) { if (isset($globalfieldmap[$surveyid]['full-VarMap'][$clang->langcode]) && !$forceRefresh) { return $globalfieldmap[$surveyid]['full-VarMap'][$clang->langcode]; // means the mappings have already been set and don't need to be re-created } } if (!isset($surveyid)) { return array(); // will happen on public root view } $fieldmap=createFieldMap($surveyid,$style='full',$forceRefresh); if (!isset($fieldmap)) { return array(); // implies an error occurred } $sgqaMap = array(); // mapping of SGQA to Value foreach($fieldmap as $fielddata) { $code = $fielddata['fieldname']; if (!preg_match('#^\d+X\d+X\d+#',$code)) { continue; // not an SGQA value } if (isset($_SESSION[$code])) { $displayValue= retrieve_Answer($code, $_SESSION['dateformats']['phpdate']); $sgqaMap['INSERTANS:' . $code] = $displayValue; } else { $sgqaMap['INSERTANS:' . $code] = ""; // so if know value has been set, replace with blank - is that the desired behavior? } } // Now set tokens $tokenMap = array(); // mapping of TOKENS to values if (isset($_SESSION['token']) && $_SESSION['token'] != '') { //Gather survey data for tokenised surveys, for use in presenting questions $_SESSION['thistoken']=getTokenData($surveyid, $_SESSION['token']); } if (isset($_SESSION['thistoken'])) { foreach (array_keys($_SESSION['thistoken']) as $tokenkey) { if ($anonymized) { $val = ""; } else { $val = $_SESSION['thistoken'][$tokenkey]; } $key = "TOKEN:" . strtoupper($tokenkey); $tokenMap[$key] = $val; } } else { // Explicitly set all tokens to blank $tokenMap['TOKEN:FIRSTNAME'] = ""; $tokenMap['TOKEN:LASTNAME'] = ""; $tokenMap['TOKEN:EMAIL'] = ""; $tokenMap['TOKEN:USESLEFT'] = ""; for ($i=1;$i<=100;++$i) // TODO - is there a way to know how many attributes are set? Looks like max is 100 { $tokenMap['TOKEN:ATTRIBUTE_' . $i] = ""; } } $fullMap = array_merge($sgqaMap, $tokenMap); $globalfieldmap[$surveyid]['full-VarMap'][$clang->langcode] = $fullMap; return $fullMap; }
function answer_replace($text) { while (strpos($text, "{INSERTANS:") !== false) { $replace=substr($text, strpos($text, "{INSERTANS:"), strpos($text, "}", strpos($text, "{INSERTANS:"))-strpos($text, "{INSERTANS:")+1); $replace2=substr($replace, 11, strpos($replace, "}", strpos($replace, "{INSERTANS:"))-11); $replace3=retrieve_Answer($replace2, $_SESSION['dateformats']['phpdate']); $text=str_replace($replace, $replace3, $text); } //while return $text; }
/** * insertAnsReplace() takes a string and looks for any {INSERTANS:xxxx} variables * which it then, one by one, substitutes the SGQA code with the relevant answer * from the session array containing responses * * The operations of this function were previously in the templatereplace function * but have been moved to a function of their own to make it available * to other areas of the script. * * @param mixed $line string - the string to iterate, and then return * * @return string This string is returned containing the substituted responses * */ function insertansReplace($line) { if (!isset($_SESSION['dateformats']['phpdate'])) { $_SESSION['dateformats']['phpdate'] = ''; } while (strpos($line, "{INSERTANS:") !== false) { $answreplace = substr($line, strpos($line, "{INSERTANS:"), strpos($line, "}", strpos($line, "{INSERTANS:")) - strpos($line, "{INSERTANS:") + 1); $answreplace2 = substr($answreplace, 11, strpos($answreplace, "}", strpos($answreplace, "{INSERTANS:")) - 11); $answreplace3 = strip_tags(retrieve_Answer($answreplace2, $_SESSION['dateformats']['phpdate'])); $line = str_replace($answreplace, $answreplace3, $line); } return $line; }