Skip to content

Commit

Permalink
NEW: Script can now gather data from token entry and use that data in…
Browse files Browse the repository at this point in the history
… presenting questions. New function "getTokenData" which returns an array containing the token info. New "str_replace" lines in templatereplace function to replace {TOKEN:FIRSTNAME} etc.. with that data if it exists. Modified buildsurveysession() function to add $_SESSION['thistoken'] variable if the survey uses tokens and is NOT anonymous.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@1067 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
jcleeland committed Jun 14, 2004
1 parent f2db2d4 commit f867f83
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions index.php
Expand Up @@ -256,6 +256,22 @@
require_once("question.php");
}

function getTokenData($sid, $token)
{
global $dbprefix;
$query = "SELECT * FROM {$dbprefix}tokens_$sid WHERE token=$token";
$result = mysql_query($query) or die("Couldn't get token info in getTemplateData()<br />".$query."<br />".mysql_error());
while($row=mysql_fetch_array($result))
{
$thistoken=array("firstname"=>$row['firstname'],
"lastname"=>$row['lastname'],
"email"=>$row['email'],
"attribute_1"=>$row['attribute_1'],
"attribute_2"=>$row['attribute_2']);
} // while
return $thistoken;
}

function templatereplace($line)
{
global $thissurvey;
Expand Down Expand Up @@ -330,6 +346,16 @@ function templatereplace($line)
$line=str_replace("{PRIVACYMESSAGE}", _PRIVACY_MESSAGE, $line);
$line=str_replace("{CLEARALL}", $clearall, $line);
$line=str_replace("{TEMPLATEURL}", $templateurl, $line);

if (isset($_SESSION['thistoken']))
{
$line=str_replace("{TOKEN:FIRSTNAME}", $_SESSION['thistoken']['firstname'], $line);
$line=str_replace("{TOKEN:LASTNAME}", $_SESSION['thistoken']['lastname'], $line);
$line=str_replace("{TOKEN:EMAIL}", $_SESSION['thistoken']['email'], $line);
$line=str_replace("{TOKEN:ATTRIBUTE_1}", $_SESSION['thistoken']['attribute_1'], $line);
$line=str_replace("{TOKEN:ATTRIBUTE_2}", $_SESSION['thistoken']['attribute_2'], $line);
}

return $line;
}

Expand Down Expand Up @@ -1004,7 +1030,7 @@ function buildsurveysession()
unset($_SESSION['grouplist']);
unset($_SESSION['fieldarray']);
unset($_SESSION['insertarray']);

unset($_SESSION['thistoken']);
//1. SESSION VARIABLE: grouplist
//A list of groups in this survey, ordered by group name.

Expand Down Expand Up @@ -1080,7 +1106,13 @@ function buildsurveysession()
$_SESSION['token'] = returnglobal('token');
$_SESSION['insertarray'][]= "token";
}


if ($tokensexist == 1 && $thissurvey['private'] == "N")
{
//Gather survey data for "non anonymous" surveys, for use in presenting questions
$_SESSION['thistoken']=getTokenData($sid, returnglobal('token'));
}

foreach ($arows as $arow)
{
//WE ARE CREATING A SESSION VARIABLE FOR EVERY FIELD IN THE SURVEY
Expand Down

0 comments on commit f867f83

Please sign in to comment.