- Posts: 30
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://path/to/LimeSurvey/'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'yourPassword' ); $iSurveyID = '123456'; // The ID of the second survey $token = $_GET["token"]; $email = $_GET["email"]; $FirstNameAPI = $_GET["firstname"]; $LastNameAPI = $_GET["lastname"]; $language = 'en'; // 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 ); // Define the token params $tokenParams = array("email"=>$email,"lastname"=>$LastNameAPI,"firstname"=>$FirstNameAPI,"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); // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); // If token successfully created, redirect to survey if(isset($newToken[0]['tid']) && isset($newToken[0]['token'])) { $newURL = LS_BASEURL.'index.php/'.$iSurveyID.'?lang='.$language.'&token='.$newToken[0]['token']; header('Location: '.$newURL); die(); } // Otherwise, display errors else if (isset($newToken['status'])) { echo $newToken['status']; } else { echo '<br />'; echo 'Error: '.$newToken[0]['errors']['token'][0]; } ?>
{TEMPLATEURL}api_redirect.php?token={TOKEN:TOKEN}&email={TOKEN:EMAIL}&firstname={TOKEN:FIRSTNAME}&lastname={TOKEN:LASTNAME}
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://path/to/LimeSurvey/'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'yourPassword' ); $iSurveyID = '123456'; // The ID of the second survey $token = $_GET["token"]; $email = $_GET["email"]; $FirstNameAPI = $_GET["firstname"]; $LastNameAPI = $_GET["lastname"]; $language = 'en'; // 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 ); // 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($value['token'] == $token) { $tokenExists = true; } } // Token already exists in survey 2, so redirect to survey if($tokenExists == true) { // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); // Redirect to survey $newURL = LS_BASEURL.'index.php/'.$iSurveyID.'?lang='.$language.'&token='.$token; header('Location: '.$newURL); die(); } // No existing token in survey 2, so we'll create one else { // Define the token params $tokenParams = array("email"=>$email,"lastname"=>$LastNameAPI,"firstname"=>$FirstNameAPI,"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); // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); // If token successfully created, redirect to survey if(isset($newToken[0]['tid']) && isset($newToken[0]['token'])) { $newURL = LS_BASEURL.'index.php/'.$iSurveyID.'?lang='.$language.'&token='.$newToken[0]['token']; header('Location: '.$newURL); die(); } // Otherwise, display errors else if (isset($newToken['status'])) { echo $newToken['status']; } else { echo '<br />'; echo 'Error: '.$newToken[0]['errors']['token'][0]; } } ?>
<?php include_once 'vendor/autoload.php'; // include_once '/alfred/vendor/weberhofer/jsonrpcphp/src/org/jsonrpcphp/jsonRPCClient.php'; define('LS_BASEURL', 'https://www.fnak.fr/limesurvey/index.php'); // adjust this one to your actual LimeSurvey URL define('LS_USER', 'user'); define('LS_PASSWORD', 'password'); $iSurveyID = 616685; echo '<pre>'; // Instantiate a new RPC client $myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient(LS_BASEURL . '/admin/remotecontrol'); var_dump($myJSONRPCClient); // Get a session key $sessionKey = $myJSONRPCClient->get_session_key(LS_USER, LS_PASSWORD); var_dump($sessionKey); // Release the session key $myJSONRPCClient->release_session_key($sessionKey); echo '</pre>';
object(org\jsonrpcphp\JsonRPCClient)#3 (6) { ["debug":"org\jsonrpcphp\JsonRPCClient":private]=> bool(false) ["url":"org\jsonrpcphp\JsonRPCClient":private]=> string(60) "https://www.fnak.fr/limesurvey/index.php/admin/remotecontrol" ["id":"org\jsonrpcphp\JsonRPCClient":private]=> int(1) ["notification":"org\jsonrpcphp\JsonRPCClient":private]=> bool(false) ["enableCurl":"org\jsonrpcphp\JsonRPCClient":private]=> bool(true) ["proxy"]=> string(0) "" }