Added code to get comments from database

This commit is contained in:
PeterEdmond committed 2025-06-02 17:24:32 +01:00
1 parent 827924bd26
commit 5dc5d0c728
4 files changed
+165 -1509

No files matched your search

-1507
View File
File diff suppressed because it is too large. Load diff
-2
View File
@@ -1,2 +0,0 @@
{"meta":{"httpStatus":"200 - OK","requestId":"20317bbf-d7d7-4ae2-b041-6796991c0eab"},
"result":{"elements":[{"QuestionText":"<span style=\"font-size:19px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;\"><strong>2. EO Approach</strong></span></span><br />\n<font face=\"Arial, Helvetica, sans-serif\"><span style=\"font-size: 16px;\"><b><span style=\"font-family:Arial,Helvetica,sans-serif;\">Develop shared values and practices that empower employee owners to contribute to success.&nbsp;</span></b></span></font><br />\n<br />\n<span style=\"font-size:16px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;\"><span style=\"line-height:90%\"><span style=\"unicode-bidi:embed\"><span style=\"word-break:normal\">A true sense of ownership drives behaviour change and unlocks the potential of individuals.<br />\nInvolving employee owners in developing shared values and practices that supports them to have a voice, unlocks enhanced levels of personal, team and organisational performance &ndash; including attracting and retaining the right talent to excel in your marketplace.<span style=\"color:black\"> </span></span></span></span></span></span><br />\n<br />\n<br />\n<strong><span style=\"font-size:16px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;\"><span style=\"line-height:90%\"><span style=\"unicode-bidi:embed\"><span style=\"word-break:normal\">To what extent are you leveraging the full potential of your ownership mindset and behaviours?</span></span></span></span></span></strong><br />\n&nbsp;","DefaultChoices":false,"DataExportTag":"Q20","QuestionType":"DB","Selector":"TB","Configuration":{"QuestionDescriptionOption":"UseText"},"QuestionDescription":"2. EO Approach Develop shared values and practices that empower employee owners to contribute to...","ChoiceOrder":[],"Validation":{"Settings":{"Type":"None"}},"GradingData":[],"Language":[],"QuestionID":"QID1","DataVisibility":{"Private":false,"Hidden":false},"NextChoiceId":1,"NextAnswerId":1,"QuestionText_Unsafe":"<span style=\"font-size:19px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;\"><strong>2. EO Approach</strong></span></span><br />\n<font face=\"Arial, Helvetica, sans-serif\"><span style=\"font-size: 16px;\"><b><span style=\"font-family:Arial,Helvetica,sans-serif;\">Develop shared values and practices that empower employee owners to contribute to success.&nbsp;</span></b></span></font><br />\n<br />\n<span style=\"font-size:16px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;\"><span style=\"line-height:90%\"><span style=\"unicode-bidi:embed\"><span style=\"word-break:normal\">A true sense of ownership drives behaviour change and unlocks the potential of individuals.<br />\nInvolving employee owners in developing shared values and practices that supports them to have a voice, unlocks enhanced levels of personal, team and organisational performance &ndash; including attracting and retaining the right talent to excel in your marketplace.<span style=\"color:black\"> </span></span></span></span></span></span><br />\n<br />\n<br />\n<strong><span style=\"font-size:16px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;\"><span style=\"line-height:90%\"><span style=\"unicode-bidi:embed\"><span style=\"word-break:normal\">To what extent are you leveraging the full potential of your ownership mindset and behaviours?</span></span></span></span></span></strong><br />\n&nbsp;"},{"QuestionText":"<span style=\"font-family: arial, helvetica, sans-serif; font-size: 19px;\">Name</span>","DefaultChoices":false,"DataExportTag":"Q2","QuestionType":"TE","Selector":"SL","Configuration":{"QuestionDescriptionOption":"UseText","AllowFreeResponse":"false"},"QuestionDescription":"Name","Validation":{"Settings":{"ForceResponse":"OFF","ForceResponseType":"ON","Type":"None"}},"GradingData":[],"Language":[],"QuestionID":"QID19","DataVisibility":{"Private":false,"Hidden":false},"NextChoiceId":1,"NextAnswerId":1,"SearchSource":{"AllowFreeResponse":"false"},"QuestionText_Unsafe":"<span style=\"font-family: arial, helvetica, sans-serif; font-size: 19px;\">Name</span>"},{"QuestionText":"<span style=\"font-size:16px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;\"><strong>Great EO Culture</strong></span></span>","DefaultChoices":false,"DataExportTag":"Q21","QuestionID":"QID2","QuestionType":"Matrix","Selector":"Likert","SubSelector":"SingleAnswer","Configuration":{"QuestionDescriptionOption":"SpecifyLabel","TextPosition":"inline","ChoiceColumnWidth":25,"RepeatHeaders":"none","WhiteSpace":"OFF","MobileFirst":true,"ChoiceColumnWidthPixels":353},"QuestionDescription":"To what extent are you realising the full potential of your EO approach?Great EO Culture","Choices":{"2":{"Display":"Our people processes (recruitment, development, appraisal and reward) encourage and reward our desired owner behaviours"},"4":{"Display":"Our culture and people proposition retains the right talent in the business"},"7":{"Display":"Our people role model our desired owner behaviours"},"8":{"Display":"Our culture enables a safe environment Line truncated
+58
View File
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Form Submit Example</title>
<style>
textarea {
width: 100%;
height: 200px;
margin-top: 1em;
}
</style>
</head>
<body>
<form id="qidForm">
<label for="qidInput">Enter QID:</label>
<input type="text" id="qidInput" name="qid" required /><br />
<label for="survey">Survey: (SV_cwKjMqAqGxImjMG)</label>
<input type="text" id="survey" name="survey" required /><br />
<label for="Q1">Enter Q1:</label>
<input type="text" id="Q1" name="Q1" /><br />
<label for="Q2">Enter Q2:</label>
<input type="text" id="Q2" name="Q2" /><br />
<label for="Q3">Enter Q3:</label>
<input type="text" id="Q3" name="Q3" /><br />
<button type="submit">Get Counts</button>
</form>
<textarea id="output" readonly placeholder="Results will appear here..."></textarea>
<script>
document.getElementById('qidForm').addEventListener('submit', async function (e) {
e.preventDefault();
const formData = new FormData(this);
try {
const response = await fetch('get_text_data.php', {
method: 'POST',
body: formData
});
const text = await response.text();
document.getElementById('output').value = text;
} catch (error) {
document.getElementById('output').value = 'Error: ' + error.message;
}
});
</script>
</body>
</html>
+107
View File
@@ -0,0 +1,107 @@
<?php
header('Content-Type: application/json');
if (php_sapi_name() === 'cli') {
echo "Running from command line.\n";
$qid="QID64_TEXT";
$survey="SV_cwKjMqAqGxImjMG";
$q1 = 1;
$q2 = 2;
$q3 = 0;
} else {
//echo "Running from browser.\n";
// Basic input validation and sanitization
if (!isset($_POST['qid']) || empty($_POST['qid'])) {
echo json_encode(['error' => 'Missing QID parameter']);
exit;
}
$qid = $_POST['qid'];
$input = $_POST['survey'] ?? '';
if (preg_match('/^SV_[a-zA-Z0-9]+$/', $input)) {
// Input is valid
$survey = $input;
} else {
// Invalid format
die("Invalid survey ID format.");
}
$q1 = filter_input(INPUT_POST, 'Q1', FILTER_VALIDATE_INT);
$q2 = filter_input(INPUT_POST, 'Q2', FILTER_VALIDATE_INT);
$q3 = filter_input(INPUT_POST, 'Q3', FILTER_VALIDATE_INT);
}
$qualifier = " AND s.surveyId = '${survey}'";
if ($q1 > 0) {
$qualifier.=" AND r.Q1 = " . $q1;
}
if ($q2 > 0) {
$qualifier.=" AND r.Q2 = " . $q2;
}
if ($q3 > 0) {
$qualifier.=" AND r.Q3 = " . $q3;
}
// Database connection (adjust credentials accordingly)
//
$config = require 'config.php';
$host = $config['db_host'];
$db = $config['db_name'];
$user = $config['db_user'];
$pass = $config['db_pass'];
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
$sql = "
SELECT
a.text
FROM Answers a
INNER JOIN Responses r ON a.responseId = r.id
INNER JOIN Surveys s ON a.surveyId = s.id
WHERE a.QID = :qid
".$qualifier;
// echo $sql;
$stmt = $pdo->prepare($sql);
$stmt->execute(['qid' => $qid]);
$results = $stmt->fetchAll();
$json = json_encode($results);
echo $json;
if ($json === false) {
echo json_last_error_msg();
}
} catch (PDOException $e) {
echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
exit;
}