<?php
//adjust the following.
define( 'LS_BASEURL', 'http://yourserver/index.php/');  // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'youruser' );
define( 'LS_PASSWORD', 'yourpassword' );
$survey_id = '73983';



require_once 'includes/jsonRPCClient.php';

/** turn limesurvey csv export answers into an array of format 

	[0]{code=>answer}
	[1]{code=>answer} (only if second answer set was included),...

 inspired by http://stackoverflow.com/questions/2276626/is-there-a-way-to-access-a-string-as-a-filehandle-in-php 
 and https://gist.github.com/385876 
*/
function str_getcsvarray($input, $delimiter = ",", $enclosure = '"', $escape = "\\")  {
	$header = NULL;
	$data = array();
	$fp = fopen("php://memory", 'r+');
	fputs($fp, $input);
	rewind($fp);

	while (($row = fgetcsv($fp, 0, $delimiter, $enclosure, $escape)) !== FALSE)	{
		if(!$header)
			$header = $row;
		else
			$data[] = array_combine($header, $row);
	}
	fclose($fp);
	return $data;
}

$myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'admin/remotecontrol', DEBUG);	
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );				

$lang = 'fr';
$textscsv = base64_decode($myJSONRPCClient->export_responses( 
	$sessionKey, $survey_id, 'csv', $lang, 'all', 'full', 'long', 0, 1)); 
$texts_ =  str_getcsvarray($textscsv); 
$textsFR =  array_keys($texts_[0]); 

$lang = 'en';
$textscsv = base64_decode($myJSONRPCClient->export_responses( 
	$sessionKey, $survey_id, 'csv', $lang, 'all', 'full', 'long', 0, 1)); 
$texts_ =  str_getcsvarray($textscsv); 
$textsEN =  array_keys($texts_[0]); 

print("the 2 next arrays should contain translations of questions texts\nFR(default language):\n");
print_r($textsFR);
print("EN:\n");
print_r($textsEN);

?>