From 6cf83a1a5e5b4f2720d7f20b0a1766f4311e5837 Mon Sep 17 00:00:00 2001 From: Peter Edmond Date: Sat, 31 May 2025 20:36:28 +0100 Subject: [PATCH] Created code to extract qualifiers directly from the QUALTRIX system --- get_qualifiers.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 get_qualifiers.php diff --git a/get_qualifiers.php b/get_qualifiers.php new file mode 100644 index 0000000..b145ab3 --- /dev/null +++ b/get_qualifiers.php @@ -0,0 +1,88 @@ + 'Missing surveyId parameter']); + exit; + } + + $input = $_POST['surveyId'] ?? ''; + + + if (preg_match('/^SV_[a-zA-Z0-9]+$/', $input)) { + // Input is valid + $surveyId = $input; + } else { + // Invalid format + die("Invalid survey ID format."); + } + + +} + + +// 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 FilterQuestion, FilterOption, Text + FROM Filters + WHERE surveyId = :surveyid + ORDER BY FilterQuestion, FilterOption + "; + + //echo $sql; + + $stmt = $pdo->prepare($sql); + $stmt->execute(['surveyid' => $surveyId]); + $results = $stmt->fetchAll(); + + //print_r($results); + + $grouped = []; + foreach ($results as $result) { + $question = $result['FilterQuestion']; + $option = $result['FilterOption']; + $text = $result['Text']; + $grouped[$question][$option] = $text; + } + + echo json_encode($grouped); + +} catch (PDOException $e) { + echo json_encode(['error' => 'Database error: ' . $e->getMessage()]); + exit; +} + + + + + + + + + + +