- Posts: 7
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php require_once 'pathTo/jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limesurvey/'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = $_GET["sid"]; $token = $_GET["token"]; $email = $_GET["email"]; $firstName = $_GET["firstname"]; $lastName = $_GET["lastname"]; $language = $_GET["lang"]; // Instantiate a new RPC client $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); // Get a session key $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); // Check if token already exists $tokenExists = false; $aConditions = array("completed"=>"N"); $listParticipants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 100000, false, false, $aConditions); foreach ($listParticipants as $value) { if(is_array($value)) { if(array_key_exists('token', $value)) { if($value['token'] == $token) { $tokenExists = true; } } } } // Token does not exist so we'll create one if($tokenExists == false) { // Define the token params $tokenParams = array("email"=>$email,"lastname"=>$lastName,"firstname"=>$firstName,"token"=>$token,"language"=>$language,"emailstatus"=>"OK"); $aParticipantData=array($tokenParams); $bCreateToken = false; // Create the token in survey 2 $newToken = $myJSONRPCClient->add_participants( $sSessionKey, $iSurveyID, $aParticipantData, $bCreateToken); // If token successfully created, redirect to survey if(isset($newToken[0]['tid']) && isset($newToken[0]['token'])) { echo('New token '.$newToken[0]['token'].', ID '.$newToken[0]['tid']); } // Otherwise, display errors else if (isset($newToken['status'])) { echo $newToken['status']; } else { echo '<br />'; echo 'Error: '.$newToken[0]['errors']['token'][0]; } } // Token already exists else { echo 'The token already exists!'; } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?>