View Issue Details

IDProjectCategoryView StatusLast Update
04419User patchesAdmin Toolspublic2010-12-14 13:02
ReporterorvilAssigned Toc_schmitz 
PrioritynormalSeveritytweak 
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version1.91 
Summary04419: Variable {PASSTHRU:arg}
Description

Often it is not possible to manipulate the incoming link for a survey. So if one has to build an exit link wth a passthru argument from the incoming link, there is a problem to solve.

e.g. if your participants are sent via links like
http://www.mydomain.org/limesurvey/index.php?sid=12345?=de&user=ABCDEF
but the "passthru=user&user=ABCDEF" part can't be done, you need to get the passthru argument on a different way.

The easyer way is to say in the exit link
http://www.myexit.org/thanks.php?{PASSTHRU:user}
where the user-value "ABCDEF" from the incoming link is sent, e.g. like
http://www.myexit.org/thanks.php?user=ABCDEF

Here is a patch I used recently (for LS 1.90RC1)

Steps To Reproduce

Uploaded file: passthru-patch.txt
Contains two code snips.
1) From index.php where 5 lines are to add.
2) From common.php where a few more lines are to add.

The patch is for LS1.90RC1 - was not selectable in the bug tracker

Additional Information

Tested it with LS 1.86 too, is working fine
Don't know if the key naming for $_SESSION['ls_initialquerystr']
is ok

TagsNo tags attached.
Complete LimeSurvey version number (& build)8819

Activities

orvil

orvil

2010-06-14 22:28

reporter  

passthru-patch.txt (2,368 bytes)
This is from index.php (V1.90RC1 lines 2512ff)
---------------------------------------------------- 

    // 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']];
        }
		
    }
	// NEW orvil: if no passthru variable is explicitely set, save the whole query_string
	else
	{
		$_SESSION['ls_initialquerystr']=$_SERVER['QUERY_STRING'];
	}
    // END NEW
	
	return $totalquestions;
	
	
This is from common.php (V1.90RC1 lines 3326ff) 
---------------------------------------------------- 

function passthruReplace($line, $thissurvey)
{	
	$line=str_replace("{PASSTHRULABEL}", $thissurvey['passthrulabel'], $line);
    $line=str_replace("{PASSTHRUVALUE}", $thissurvey['passthruvalue'], $line);
	
	// NEW orvil: replacement for variable passthru argument like {PASSTHRU:myarg}
	while (strpos($line,"{PASSTHRU:") !== false)
	{
		$p1 = strpos($line,"{PASSTHRU:");				// startposition
		$p2 = $p1 + 10;									// position of the first arg char
		$p3 = strpos($line,"}",10);						// position of the last arg char
		
		$cmd=substr($line,$p1,$p3-$p1+1);				// extract the complete passthru like "{PASSTHRU:myarg}"
		$arg=substr($line,$p2,$p3-$p2);					// extract the arg to passthru (like "myarg")
		
		// lookup for the fitting arg
		$qstring = $_SESSION['ls_initialquerystr'];		// get initial query_string

		parse_str($qstring, $keyvalue);					// split into key and value
		$match = 0;										// prevent an endless loop if there is no arg in url
		foreach ($keyvalue as $key=>$value)				// lookup loop
		{
			if ($key == $arg)          					// if match
			{
				$line=str_replace($cmd, $arg . "=" . $value, $line);		// replace
				$match = 1;
				break;
			}
			if ($match == 0)
			{
				$line=str_replace($cmd, $arg . "=", $line);					// clears "{PASSTHRU:myarg} to "myarg=" if there was no myarg in calling url
			}
		}		

	}
	// END NEW
	
    return $line;
}
passthru-patch.txt (2,368 bytes)
orvil

orvil

2010-06-14 23:16

reporter   ~12220

Uups, sorry copied some false lines into the passthru-patch.txt

Here is the correct version of the passthruReplace function:

function passthruReplace($line, $thissurvey)
{
$line=str_replace("{PASSTHRULABEL}", $thissurvey['passthrulabel'], $line);
$line=str_replace("{PASSTHRUVALUE}", $thissurvey['passthruvalue'], $line);

// ov: replacement for variable passthru argument like {PASSTHRU:myarg}
//if (strpos($line,"{PASSTHRU:"))                     // look weather there is a variable passthru
while (strpos($line,"{PASSTHRU:") !== false)
{
    $p1 = strpos($line,"{PASSTHRU:");             // startposition
    $p2 = $p1 + 10;                                 // position of the first arg char
    $p3 = strpos($line,"}",10);                       // position of the last arg char

    $cmd=substr($line,$p1,$p3-$p1+1);               // extract the complete passthru like "{PASSTHRU:myarg}"
    $arg=substr($line,$p2,$p3-$p2);                 // extract the arg to passthru (like "myarg")

    // lookup for the fitting arg
    $qstring = $_SESSION['ls_initialquerystr'];     // get initial query_string

    parse_str($qstring, $keyvalue);                 // split into key and value
    $match = 0;                                     // prevent an endless loop if there is no arg in url
    foreach ($keyvalue as $key=>$value)             // lookup loop
    {
        if ($key == $arg)                           // if match
        {
            $line=str_replace($cmd, $arg . "=" . $value, $line);      // replace
            $match = 1;
            break;
        }

    }       

    if ($match == 0)
    {
        $line=str_replace($cmd, $arg . "=", $line);                   // clears "{PASSTHRU:myarg} to "myarg=" if there was no myarg in calling url
    }
}

return $line;

}

DenisChenu

DenisChenu

2010-06-22 09:26

developer   ~12274

Hello,

If you had a server you can manipulate incoming link and outcoming link like you want.

For example :
mysurvey/income.php : income.php get user value and send in xxxxXxxxXxx value for LS.
mysurvey/outcome.php : outcome.php get xxxxXxxxXxx value from ls and send in value user for your convenience.

orvil

orvil

2010-06-22 19:33

reporter   ~12277

Same situation like for {GATE}. Often you cannot deal with xxxxXxxxXxx in or out parameters.
An example: you are getting your participants with a link that looks like
http://www.your-domain.com/LimeSurvey/index.php?sid=84236&usr=A123456
where "usr=A123456" is an identification for e.g. a reward for the participants
and the requirement is to redirect the participants afterwards to
http://www.an-otherones-domain.com/validation.php?usr=A123456

If you don't have the possibility to manipulate the incoming link you have to pass the argument as it is given and required and easily possible with {PASSTHRU:usr} in this case

c_schmitz

c_schmitz

2010-08-11 01:07

administrator   ~12601

Orvil, I think this is a great idea and I would like to apply this patch for 1.91.
Unfortunately there is something missing in the patch.

There is the function passthruReplace but it is never used anywhere in your patch. Can you have a look and add the missing snippet?

c_schmitz

c_schmitz

2010-08-11 01:09

administrator   ~12602

Never mind, just ignore me ;) Found out ;)

c_schmitz

c_schmitz

2010-08-11 01:14

administrator   ~12603

Patch applied in rev. 9049

Issue History

Date Modified Username Field Change
2010-06-14 22:28 orvil New Issue
2010-06-14 22:28 orvil File Added: passthru-patch.txt
2010-06-14 23:16 orvil Note Added: 12220
2010-06-22 09:26 DenisChenu Note Added: 12274
2010-06-22 19:33 orvil Note Added: 12277
2010-08-11 00:55 c_schmitz Assigned To => c_schmitz
2010-08-11 00:55 c_schmitz Status new => assigned
2010-08-11 01:07 c_schmitz Note Added: 12601
2010-08-11 01:07 c_schmitz Status assigned => feedback
2010-08-11 01:09 c_schmitz Note Added: 12602
2010-08-11 01:09 c_schmitz Status feedback => assigned
2010-08-11 01:14 c_schmitz Note Added: 12603
2010-08-11 01:14 c_schmitz Status assigned => resolved
2010-08-11 01:14 c_schmitz Fixed in Version => 1.91
2010-08-11 01:14 c_schmitz Resolution open => fixed
2010-12-14 13:02 c_schmitz Status resolved => closed