Please help us help you and fill where relevant:
LimeSurvey version: 5.6.68+240625
Own server or LimeSurvey Cloud: Own
Survey theme/template: N/A
==================
I have a PHP script for LS3 that uses the API to export results from a specific survey. The PHP script worked with LS 3, but doesn't seem to work with LS 5.
I'm wondering if someone might be able to identify where the error lies in the script for LS 5.
The script outputs the <tr></tr> elements, but no results are included. Also the <th></th> group is blank.
Here's the script:
Code:
<?php
// Call like https://LSDOMAIN.TLD/api/ExportResponses.php?sid=######&secret=ABCD
require_once 'jsonRPCClient.php';
define( 'LS_BASEURL', 'https://LSDOMAIN.TLD/');
define( 'LS_USER', 'admin' );
define( 'LS_PASSWORD', 'aPasswordBetterThanThis' );
$iSurveyID = $_GET["sid"];;
$secret = $_GET["secret"];
// echo $secret ;
if ($secret != 'ABCD') {
die;
}
// Instantiate a new RPC client
$myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/admin/remotecontrol' );
// Get a session key
$sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
if(is_array($sSessionKey)) { // Invalid session
echo $sSessionKey['status'];
}
else if($sSessionKey) { // Valid session
$surveyResponses = $myJSONRPCClient->export_responses($sSessionKey, $iSurveyID, 'json', null, 'all', 'full', 'long', null, null, null);
if(is_array($surveyResponses)) {
// Oops, print any errors
print_r($surveyResponses);
}
else {
// Decode the retuned base-64 string and convert to an array
$decodedString = base64_decode($surveyResponses);
$aResponses = json_decode($decodedString, True);
// Find the first response ID
$aFirstResponse = reset($aResponses['responses'][0]);
echo '<table style="border-collapse: collapse; text-align: left;">';
echo '<tr>';
// Insert column headers
foreach($aFirstResponse as $key => $value) {
echo '<th style="border: 1px solid #CCC; padding: 2px 7px;">'.$key .'</th>';
}
echo '</tr>';
foreach($aResponses['responses'] as $key => $row) {
echo '<tr>';
// Insert the data
foreach(reset($row) as $key => $item) {
echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">'.$item .'</td>';
}
echo '</tr>';
}
echo '</table>';
}
}
// Release the session key
$myJSONRPCClient->release_session_key( $sSessionKey );
?>