Skip to content

Commit

Permalink
New Feature: #3055: Passing email address from survey to external php…
Browse files Browse the repository at this point in the history
… script

Dev: End URL may now contain {INSERTANS:1234X56X78} SGQA codes replaced by relevant answer
Dev: End URL may now contain {PASSTHRULABEL} and {PASSTHRUVALUE} codes which will be replaced
Dev: By values passed in the initial survey query url as ?passthru=AWORD&AWORD=1234

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@6721 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
jcleeland committed Apr 26, 2009
1 parent 0d97c4d commit 250635c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 30 deletions.
1 change: 1 addition & 0 deletions admin/templates.php
Expand Up @@ -293,6 +293,7 @@
$thissurvey['templatedir']=$templatename;
$thissurvey['format']="G";
$thissurvey['url']="http://www.limesurvey.org/";
$thissurvey['surveyls_url']=$thissurvey['url'];
$thissurvey['urldescrip']=$clang->gT("Some URL description");
$thissurvey['usecaptcha']="A";
$percentcomplete=makegraph(6, 10);
Expand Down
57 changes: 49 additions & 8 deletions common.php
Expand Up @@ -1565,6 +1565,8 @@ function getSurveyInfo($surveyid, $languagecode='')
if (!isset($thissurvey['adminemail'])) {$thissurvey['adminemail']=$siteadminemail;}
if (!isset($thissurvey['urldescrip']) ||
$thissurvey['urldescrip'] == '' ) {$thissurvey['urldescrip']=$thissurvey['surveyls_url'];}
$thissurvey['passthrulabel']=isset($_SESSION['passthrulabel']) ? $_SESSION['passthrulabel'] : "";
$thissurvey['passthruvalue']=isset($_SESSION['passthruvalue']) ? $_SESSION['passthruvalue'] : "";
}

//not sure this should be here... ToDo: Find a better place
Expand Down Expand Up @@ -2932,14 +2934,9 @@ function templatereplace($line)
{
if (strpos($line, "{QUESTIONHELP}") !== false) $line=str_replace("{QUESTIONHELP}", $help, $line);
if (strpos($line, "{QUESTIONHELPPLAINTEXT}") !== false) $line=str_replace("{QUESTIONHELPPLAINTEXT}", strip_tags(addslashes($help)), $line);
}
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));
$line=str_replace($answreplace, $answreplace3, $line);
}
}

$line=insertansReplace($line);

if (strpos($line, "{SUBMITCOMPLETE}") !== false) $line=str_replace("{SUBMITCOMPLETE}", "<strong>".$clang->gT("Thank You!")."<br /><br />".$clang->gT("You have completed answering the questions in this survey.")."</strong><br /><br />".$clang->gT("Click on 'Submit' now to complete the process and save your answers."), $line);
if (strpos($line, "{SUBMITREVIEW}") !== false) {
Expand Down Expand Up @@ -3130,6 +3127,50 @@ function templatereplace($line)
return $line;
}

/**
* 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)
{
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));
$line=str_replace($answreplace, $answreplace3, $line);
}
return $line;
}

/**
* passthruReplace() takes a string and looks for {PASSTHRULABEL} and {PASSTHRUVALUE} variables
* which it then substitutes for passthru data sent in the initial URL and stored
* in the session array containing responses
*
* @param mixed $line string - the string to iterate, and then return
* @param mixed $thissurvey string - the string containing the surveyinformation
* @return string This string is returned containing the substituted responses
*
*/
function passthruReplace($line, $thissurvey)
{
$line=str_replace("{PASSTHRULABEL}", $thissurvey['passthrulabel'], $line);
$line=str_replace("{PASSTHRUVALUE}", $thissurvey['passthruvalue'], $line);

return $line;
}

function getSavedCount($surveyid)
{
//This function returns a count of the number of saved responses to a survey
Expand Down
16 changes: 11 additions & 5 deletions group.php
Expand Up @@ -89,7 +89,7 @@
}

//COMMIT CHANGES TO DATABASE
if ($thissurvey['active'] != "Y")
if ($thissurvey['active'] != "Y") //If survey is not active, don't really commit
{
if ($thissurvey['assessments']== "Y")
{
Expand Down Expand Up @@ -122,14 +122,19 @@
$completed .= "<a href='{$_SERVER['PHP_SELF']}?sid=$surveyid&amp;move=clearall'>".$clang->gT("Clear Responses")."</a><br /><br />\n";
}
}
else
else //THE FOLLOWING DEALS WITH SUBMITTING ANSWERS AND COMPLETING AN ACTIVE SURVEY
{
if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1)
if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1) //don't use cookies if tokens are being used
{
$cookiename="PHPSID".returnglobal('sid')."STATUS";
setcookie("$cookiename", "COMPLETE", time() + 31536000);
setcookie("$cookiename", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days
}

//Before doing the "templatereplace()" function, check the $thissurvey['url']
//field for limereplace stuff, and do transformations!
$thissurvey['surveyls_url']=insertansReplace($thissurvey['surveyls_url']);
$thissurvey['surveyls_url']=passthruReplace($thissurvey['surveyls_url'], $thissurvey);

$content='';
$content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl"));

Expand Down Expand Up @@ -238,7 +243,8 @@
}
header("Location: {$redir}"); */

$url = $thissurvey['url'];
$url = insertansReplace($thissurvey['url']);
$url = passthruReplace($url, $thissurvey);
$url=str_replace("{SAVEDID}",$saved_id, $url); // to activate the SAVEDID in the END URL
$url=str_replace("{TOKEN}",$clienttoken, $url); // to activate the TOKEN in the END URL
$url=str_replace("{SID}", $surveyid, $url); // to activate the SID in the END URL
Expand Down
12 changes: 11 additions & 1 deletion index.php
Expand Up @@ -145,7 +145,7 @@
@session_destroy(); // make it silent because for
// some strange reasons it fails sometimes
// which is not a problem
// but if it throughs an error then future
// but if it throws an error then future
// session functions won't work because
// headers are already sent.
$usquery = "SELECT stg_value FROM ".db_table_name("settings_global")." where stg_name='SessionName'";
Expand Down Expand Up @@ -2314,6 +2314,16 @@ function buildsurveysession()
}
// Check if the current survey language is set - if not set it
// this way it can be changed later (for example by a special question type)

//Check if a passthru label and value have been included in the query url
if(isset($_GET['passthru']) && $_GET['passthru'] != "")
{
if(isset($_GET[$_GET['passthru']]) && $_GET[$_GET['passthru']] != "")
{
$_SESSION['passthrulabel']=$_GET['passthru'];
$_SESSION['passthruvalue']=$_GET[$_GET['passthru']];
}
}

return $totalquestions;
}
Expand Down
15 changes: 9 additions & 6 deletions question.php
Expand Up @@ -213,17 +213,19 @@
}

}
else
else //THE FOLLOWING DEALS WITH SUBMITTING ANSWERS AND COMPLETING AN ACTIVE SURVEY
{


if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1) //don't use cookies if tokens are being used
{
$cookiename="PHPSID".returnglobal('sid')."STATUS";
setcookie("$cookiename", "COMPLETE", time() + 31536000);
setcookie("$cookiename", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days
}


//Before doing the "templatereplace()" function, check the $thissurvey['url']
//field for limereplace stuff, and do transformations!
$thissurvey['surveyls_url']=insertansReplace($thissurvey['surveyls_url']);
$thissurvey['surveyls_url']=passthruReplace($thissurvey['surveyls_url'], $thissurvey);

$content='';
$content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl"));

Expand Down Expand Up @@ -289,7 +291,8 @@
if (isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['url'])
{
//Automatically redirect the page to the "url" setting for the survey
$url = $thissurvey['url'];
$url = insertansReplace($thissurvey['url']);
$url = passthruReplace($url, $thissurvey);
$url=str_replace("{SAVEDID}",$saved_id, $url); // to activate the SAVEDID in the END URL
$url=str_replace("{TOKEN}",$clienttoken, $url); // to activate the TOKEN in the END URL
$url=str_replace("{SID}", $surveyid, $url); // to activate the SID in the END URL
Expand Down
27 changes: 17 additions & 10 deletions survey.php
Expand Up @@ -65,6 +65,10 @@
{
$assessments = doAssessment($surveyid); // assessments are using session data so this has to be placed before killSession
}

//Before doing the "templatereplace()" function, check the $thissurvey['url']
//field for limereplace stuff, and do transformations!

killSession();
sendcacheheaders();
doHeader();
Expand All @@ -87,19 +91,21 @@
$completed .= "<a href='{$_SERVER['PHP_SELF']}?sid=$surveyid&amp;move=clearall'>".$clang->gT("Clear Responses")."</a><br /><br />\n";
}
}
else
else //THE FOLLOWING DEALS WITH SUBMITTING ANSWERS AND COMPLETING AN ACTIVE SURVEY
{

if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1)
if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1) //don't use cookies if tokens are being used
{
$cookiename="PHPSID".returnglobal('sid')."STATUS";
setcookie("$cookiename", "COMPLETE", time() + 31536000); //365 days
setcookie("$cookiename", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days
}

$content='';
//Before doing the "templatereplace()" function, check the $thissurvey['url']
//field for limereplace stuff, and do transformations!
$thissurvey['surveyls_url']=insertansReplace($thissurvey['surveyls_url']);
$thissurvey['surveyls_url']=passthruReplace($thissurvey['surveyls_url'], $thissurvey);

//Start to print the final page
$content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
$content='';
$content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl"));

//Check for assessments
$assessments = doAssessment($surveyid);
Expand Down Expand Up @@ -170,14 +176,15 @@
sendcacheheaders();
if (!$embedded && isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['url'])
{
//Automatically redirect the page to the "url" setting for the survey
session_write_close();

$url = $thissurvey['url'];
$url = insertansReplace($thissurvey['url']);
$url = passthruReplace($url, $thissurvey);
$url=str_replace("{SAVEDID}",$saved_id, $url); // to activate the SAVEDID in the END URL
$url=str_replace("{TOKEN}",$clienttoken, $url); // to activate the TOKEN in the END URL
$url=str_replace("{SID}", $surveyid, $url); // to activate the SID in the END URL
$url=str_replace("{LANG}", $clang->getlangcode(), $url); // to activate the LANG in the END URL
//Automatically redirect the page to the "url" setting for the survey
session_write_close();

header("Location: {$url}");
}
Expand Down

0 comments on commit 250635c

Please sign in to comment.