Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
/data/
OUTPUT/*
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ HtmlQ introduces a few new settings that were not available in FlashQ:
<item id="leaveSiteWarning">Your answers will be lost.</item>
```

### CSV Export

If your webspace supports [PHP](https://www.php.net/) then you can config HtmlQ to write all results into a CSV file. You will find the CSV file in the folder with the name `OUTPUT`. Delete the file to start a new survey.

`settings/config.xml`:

```xml
<!-- URL for data transmission via POST/GET (leave blank if not required) -->
<item id="submitUrl">src/save_as_csv.php</item>
<!-- request mode (post|get) -->
<item id="submitUrlMethod">get</item>
```

## Creating unique participation links (UID)

If you want to send out unique links to a HtmlQ survey that will automatically fill in the UID/user code, you can create links in the following format: [https://www.yourdomain.com/htmlq/#/?userCode=USERCODE](). In the resulting CSV file, the user code will show up in the UID field. This allows you to identify participants without requiring them to log in.
Expand Down
90 changes: 90 additions & 0 deletions src/save_as_csv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* This PHP script takes the results of the survey and writes it into a CSV file.
*
* Change in settings/config.xml the following:
*
* <!-- URL for data transmission via POST/GET (leave blank if not required) -->
* <item id="submitUrl">src/save_as_csv.php</item>
* <!-- request mode (post|get) -->
* <item id="submitUrlMethod">get</item>
*
* You will find the generate CSV file in the folder OUTPUT. Simply move or delete the file if you
* would like to start a new survey.
*
* @author Paul Spiesberger - no warrenty for any dataloss or other harm.
*/

$filePath = "../OUTPUT/survey_results.csv";

createDir("../OUTPUT/"); // create directory if it doesn't exist yet

$csvFile = fopen($filePath, "a") or die("Unable to open file!");

// Extract comments
$comments = array();
$commentHeaders = array();

for ($x = 0; $x <= 10000; $x++) {
$key = "comment" . $x;

if(isset($_GET[$key])) {
$comments[] = htmlspecialchars($_GET[$key]);
$commentHeaders[] = "comment" . sizeof($commentHeaders);
}
}

// Extract Forms
$forms = array();
$formHeaders = array();

for ($x = 0; $x <= 10000; $x++) {
$key = "form" . $x;

if(isset($_GET[$key])) {
$forms[] = htmlspecialchars($_GET[$key]);
$formHeaders[] = $key;
}
}

// Extract Durations
$durations = array();
$durationHeaders = array();

for ($x = 0; $x <= 10000; $x++) {
$key = "dur" . $x;

if(isset($_GET[$key])) {
$durations[] = htmlspecialchars($_GET[$key]);
$durationHeaders[] = $key;
}
}

// Adding headers
if (filesize($filePath) == 0) {

$headers = array("uuid", "name", "datetime", "nneg", "nneu", "npos", "sort");
$headers = array_merge($headers, $commentHeaders, $formHeaders, $durationHeaders);
fputcsv($csvFile, $headers);
}

// Create Data Arrays
$data = array_merge(array(
uniqid(), // generate random UUID
htmlspecialchars($_GET["name"]),
htmlspecialchars($_GET["datetime"]),
htmlspecialchars($_GET["nneg"]),
htmlspecialchars($_GET["nneu"]),
htmlspecialchars($_GET["npos"]),
htmlspecialchars($_GET["sort"])
), $comments, $forms, $durations);

fputcsv($csvFile, $data); // Write data

fclose($csvFile); // Closing file

function createDir($path, $mode = 0777, $recursive = true) {
if(file_exists($path)) return true;
return mkdir($path, $mode, $recursive);
}
?>