- Posts: 173
- Thank you received: 27
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once '../application/libraries/jsonRPCClient.php'; define( 'LS_BASEURL', 'https://yourserver/index.php'); // adjust this one to your actual LimeSurvey URL define( 'LS_USER', 'yourname' ); define( 'LS_PASSWORD', 'yourpassword' ); $iSurveyID = yoursurveyID; $token = $_GET['pid']; ; $email = 'xxx@xxx.com'; $FirstNameAPI = 'xxx' ; $LastNameAPI = 'Panel' ; // 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"=>'en',"emailstatus"=>"OK","attribute_1"=>"2"); $aParticipantData=array($tokenParams); $bCreateToken = false; // Create the tokens $newToken = $myJSONRPCClient->add_participants( $sSessionKey, $iSurveyID, $aParticipantData, $bCreateToken); $newURL ="https://yourserver/index.php/survey/index/sid/yoursurveyID/token/".$token."/lang/en"; // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); header('Location: '.$newURL); ?>
<?php if(empy($_GET['pid'])) { die("You kill me"); } $attribute1 = $_GET['pid']; $aToken = $myJSONRPCClient->get_participant_properties($sSessionKey, $iSurveyID, array('attribute_1' => $attribute1)); $status = isset($aToken['status']) ? $aToken['status'] : null; $token = isset($aToken['token']) ? $aToken['token'] : null; if(empty($token)) { $tokenParams = array( array("email"=>"","lastname"=>$LastNameAPI,"firstname"=>$FirstNameAPI,"language"=>'en',"emailstatus"=>"OK","attribute_1"=>$attribute1,"attribute_2"=>"2") ); $aToken = $myJSONRPCClient->add_participants($sSessionKey, $iSurveyID,$tokenParams); // add_participants seems broken currently (looking at code) , then get it $aToken = $myJSONRPCClient->get_participant_properties($sSessionKey, $iSurveyID, array('attribute_1' => $attribute1)); $status = isset($aToken['status']) ? $aToken['status'] : null; $token = isset($aToken['token']) ? $aToken['token'] : null; if(empty($token) && !empty($status)) { die("I made an error in my code :".$status); } } $newURL ="https://example.org/index.php/survey/index/sid/".$iSurveyID."/token/".$token; $myJSONRPCClient->release_session_key( $sSessionKey ); header('Location: '.$newURL);