user12634
2011-03-25 22:57
~14541
|
This quick and dirty modyfications of insertansReplace() and retrieve_Answer() functions in common_functions.php let me use only QID instead of SGQ.
The loop through the $_SESSION keys is not a preaty sollution but the number of keys in $_SESSION table seems to be about 40+number_od_questions_given, so it is not a really big overhead to iterate through it.
function insertansReplace($line)
{
if (!isset($_SESSION['dateformats']['phpdate'])) $_SESSION['dateformats']['phpdate']='';
//<-- MATEUSZ 25.03.2011
// dirty patch implementing using only QID for retrieving answers that were already given, eg. {INSERTANS:1234} instead of {INSERTANS:1234X5678X9012}
while (($pos=strpos($line, "{INSERTANS:")) !== false)
{
$len=strpos($line, "}", $pos)-$pos+1;
$answreplace=substr($line, $pos, $len);
$answreplace2=substr($answreplace, 11, -1);
/
$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;
}
function retrieve_Answer($code, $phpdateformat=null)
{
//This function checks to see if there is an answer saved in the survey session
//data that matches the $code. If it does, it returns that data.
//It is used when building a questions text to allow incorporating the answer
//to an earlier question into the text of a later question.
//IE: Q1: What is your name? [Jason]
// Q2: Hi [Jason] how are you ?
//This function is called from the retriveAnswers function.
global $dbprefix, $connect, $clang;
//Find question details
//<-- MATEUSZ 25.03.2011
// dirty patch implementing using only QID for retrieving answers that were already given, eg. {INSERTANS:1234} instead of {INSERTANS:1234X5678X9012}
if (!isset($_SESSION[$code]))
{
foreach(array_keys($_SESSION) as $i)
{
$itmp=explode('X', $i);
if(count($itmp) < 3 ) continue;
$itmp=implode('X', array_slice($itmp, 2));
if($itmp == $code)
{
$code=$i;
break;
}
}
}
//-->
if (isset($_SESSION[$code]))
{
$questiondetails=getsidgidqidaidtype($code);
//the getsidgidqidaidtype function is in common.php and returns
//a SurveyID, GroupID, QuestionID and an Answer code
//extracted from a "fieldname" - ie: 1X2X3a
// also returns question type
if ($questiondetails['type'] == "M" ||
$questiondetails['type'] == "P")
{
$query="SELECT * FROM {$dbprefix}questions WHERE parent_qid='".$questiondetails['qid']."' AND language='".$_SESSION['s_lang']."'";
$result=db_execute_assoc($query) or safe_die("Error getting answer<br />$query<br />".$connect->ErrorMsg()); //Checked
while($row=$result->FetchRow())
{
if (isset($_SESSION[$code.$row['title']]) && $_SESSION[$code.$row['title']] == "Y")
{
$returns[] = $row['question'];
}
elseif (isset($_SESSION[$code]) && $_SESSION[$code] == "Y" && $questiondetails['aid']==$row['title'])
{
return $row['question'];
}
}
if (isset($_SESSION[$code."other"]) && $_SESSION[$code."other"])
{
$returns[]=$_SESSION[$code."other"];
}
if (isset($returns))
{
$return=implode(", ", $returns);
if (strpos($return, ","))
{
$return=substr_replace($return, " &", strrpos($return, ","), 1);
}
}
else
{
$return=$clang->gT("No answer");
}
}
elseif (!$_SESSION[$code] && $_SESSION[$code] !=0)
{
$return=$clang->gT("No answer");
}
else
{
$return=getextendedanswer($code, $_SESSION[$code], 'INSERTANS',$phpdateformat);
}
}
else
{
$return=$clang->gT("Error") . "($code)";
}
return html_escape($return);
} |