- Posts: 16
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<html> <head> <title>HWA Bram Stoker Award Recommendations</title> <script language="JavaScript" type="text/JavaScript"> // THE FOLLOWING IS LIMESURVEY CODE function get_session_key(USERNAME $username, PASSWORD $password) </script> </head> <body> <!-- START OF CONTENT --> <table border=1><tr bgcolor="#bbbbbb"><td colspan=8><br><center><h1>HWA Bram Stoker Award&reg; Member Recommendations for Works Published in 2018</h1></td></tr> <?php require_once 'jsonrpcphp/JsonRPCClient.php'; define( 'LS_BASEURL', 'https://www.myServer.de/survey'); // adjust this one to your actual LimeSurvey URL define( 'LS_USER', 'user' ); define( 'LS_PASSWORD', 'password' ); // the survey to process $survey_id=977824; // 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); echo '<br />This is another test with sesssion key.<br />'; die(); } else if($sessionKey) // Is a valid session { /* Get the responses */ $rawResponses = $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 'code', // Heading : code|full|abbreviated : question text, default code 'short', // answer : short|long , default : long null, null ); $category= array ("","Novel","First Novel","Graphic Novel","Young adult novel","Long Fiction","Short Fiction","Screenplay","Anthology","Fiction Collection"); $columns = array("title", "author", "publisher", "venue", "month"); if(is_array($rawResponses)) { print_r($rawResponses); } else { $decodedString = base64_decode($rawResponses); // The decodedString variable turns the data into an array and contains the entire array of data for the survey in English $responseArr = json_decode($decodedString, True); // Creates the json-decoded array of data for use in PHP. for ($i=1;$i<9;$i++) { echo '<tr bgcolor="#bbbbbb"><td colspan="8" style="font-size:14pt;font-weight:bold;text-align:center">'.$category[$i].'</td></tr>'; foreach($responseArr['responses'] as $rownumber => $row) { foreach($row as $column => $item) { if ($item["category"]=="A".$i) { echo '<tr bgcolor="#bbbbbb">'; foreach($columns as $col) { echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">' . $item[$col] . '</td>'; } } echo '</tr>'; } } } echo '</table>'; } } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?> </table> <!-- END OF CONTENT --> </body> </html>
datto lib seems for jsonRPC spec 2, we are on spec 1 : www.limesurvey.org/manual/RemoteControl_2_API#How_to_use_LSRC2jelo wrote: Nice effort.
What external library did you use for JSON-RPC?
The one linked in the LimeSurvey manual?
github.com/weberhofer/jsonrpcphp
Since there many php libs around JSON-RPC, it's worth pointing out what external dependence we have.
Since PHP 7 is more and more the norm, this JSON PHP lib is worth a look.
github.com/datto/php-json-rpc