- Posts: 14
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php require_once 'jsonrpcphp/JsonRPCClient.php'; define( 'LS_BASEURL', 'https://www.example.com/survey'); // adjust this one to your actual LimeSurvey URL define( 'LS_USER', 'myUserName' ); define( 'LS_PASSWORD', 'myPassword' ); // the survey to process $survey_id=mySurvey_ID; // instantiate a new client $myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); // receive session key $sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); if(is_array($sessionKey)) { header("Content-type: application/json"); echo json_encode($sessionKey); die(); } /* Get the responses */ $response = $myJSONRPCClient->export_responses( $sessionKey, $survey_id, 'json', // Document type : pdf,csv,xls,doc,json null, // Language code : null : default from survey 'complete', // Stautus complete|incomplete|all NULL, // Heading : code|full|abbreviated : question text, default code 'short', // answer : short|long , default : long 2, // First exported SAVEDID or NULL 3 // Last exported SAVEDID or NULL ); $decodedString = base64_decode($response); $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 "Key: ".$key." Row: ".$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( $sessionKey ); ?>
The thread is about how to access LimeSurvey instances hosted by LimeSurvey GmbH.Joffm wrote: Or you do it with direct access in php.