- Posts: 417
- Thank you received: 34
Ask the community, share ideas, and connect with other LimeSurvey users!
<?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 ); ?>
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.