Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Created 02-2017 by Marcel Minke (marcel.minke@limesurvey.org)
  4.  *
  5.  * This script creates a dummy token to directly start a survey with an empty data set
  6.  */
  7.  
  8. /*
  9.  * ------------ START SETTINGS --------------
  10.  */
  11.  
  12. //to be used dummy details for token first name, last name and email
  13. $firstname = "John";
  14. $lastname = "Doe";
  15. //use invalid email address to not accidentally send emails to a real account
  16. $email = "john.doe@gmail.comm";
  17.  
  18. //to create unique tokens we just use the current timestamp including seconds
  19. $token = date("YmdHis");
  20.  
  21. //set the URL of the current system
  22.  
  23. /*
  24.  * ------------ START CONFIG --------------
  25.  */
  26.  
  27.  
  28. //error reporting
  29. ini_set('display_errors',1);
  30. error_reporting(E_ALL  & ~E_NOTICE);
  31.  
  32. //check if SURVEYID was passed
  33. if(isset($_GET['sid']) && $_GET['sid'] != "")
  34. {
  35.     $sid = intval($_GET['sid']);
  36.  
  37.     //basepath needs to be defined in order to include config file (there is a check for this!)
  38.     define("BASEPATH", dirname(dirname(__FILE__)));
  39.  
  40.     //push all config details (config.details returns them as array) into this array
  41.     $config = require_once("application/config/config.php");
  42.  
  43.     // DB CONNECTION DETAILS
  44.     $username = $config['components']['db']['username'];
  45.     $password = $config['components']['db']['password'];
  46.     $dbprefix = $config['components']['db']['tablePrefix'];
  47.     //the DB connection string looks like this:
  48.     //'mysql:host=localhost;port=3306;dbname=etcvps88_devm;'
  49.     //so we need to check for the last "=", add 1 and get the string without the ending ";" character:
  50.     $database = substr($config['components']['db']['connectionString'],strrpos($config['components']['db']['connectionString'],"=")+1,-1);
  51.  
  52.     //connect to DB
  53.     $connect = mysqli_connect("localhost",$username,$password,$database) or die( "Unable connect to database '$database'");
  54.  
  55.     //set charset to deal with special characters
  56.     mysqli_set_charset($connect,'utf8');
  57.  
  58.     $tokentable = $dbprefix."tokens_$sid";
  59.  
  60.     //set the survey language to default (usually "en")
  61.     $lang = "en";
  62.    
  63.     /*
  64.      * ------------ START WORKFLOW --------------
  65.      */
  66.     $insertquery = "INSERT INTO $tokentable (firstname, lastname, email, token, language)
  67.                     VALUES('$firstname', '$lastname', '$email', '$token', '$lang')";
  68.    
  69.     //for debugging only
  70.     /*
  71.     echo "$insertquery<br /><pre>";
  72.     print_r($_SERVER);
  73.     echo "</pre>";
  74.     */
  75.    
  76.     //execute INSERT statement
  77.     mysqli_query($connect, $insertquery);
  78.    
  79.     //URL of current script
  80.     $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
  81.    
  82.     //remove "start.php"
  83.     $url = str_replace("start.php", "", $url);
  84.    
  85.     //add URL details to load survey
  86.     $url .= "index.php/survey/index/sid/$sid/token/$token/lang/$lang/newtest/Y";   
  87.    
  88.     //redirect
  89.     header("Location: $url");
  90.     exit;
  91. }
  92.  
  93. //no IDs passed
  94. else
  95. {
  96.     echo "No survey ID was passed.";
  97. }
  98.  
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement