123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <?php
-
- require_once 'config.php';
- require_once 'dbh.inc.php';
- require_once 'checkLogin.php';
-
-
-
-
-
-
-
- if(isset($_POST['updateQuestion'])) {
-
-
-
- $questionID = mysqli_real_escape_string($connection, trim($_POST['questionID']));
-
-
-
- if($questionID === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify experience ID."));
- exit();
- } else if(mysqli_query($connection, "SELECT * FROM question WHERE id = '$questionID';")->num_rows !== 1) {
- http_response_code(400);
- echo json_encode(array("error" => "Given experience ID ($id) not in database."));
- exit();
- }
-
-
-
-
- if(isset($_POST['update_q_premise'])) {
-
- $premise = mysqli_real_escape_string($connection, trim($_POST['update_q_premise']));
-
-
-
- if($premise === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Question premise can't be empty."));
- exit();
- } else if(mb_strlen($premise) > 600) {
- http_response_code(400);
- echo json_encode(array("error" => "Question premise too long (max. is 600 characters)."));
- exit();
- }
-
- $query = "UPDATE `question` SET `premise` = '$premise' WHERE `id` = '$questionID';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- }
-
-
-
-
-
- if(isset($_POST['update_q_type'])) {
-
- $typeID = mysqli_real_escape_string($connection, trim($_POST['update_q_type']));
-
-
-
- if($typeID === "" || ($typeID != "1" && $typeID != "2")) {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify a type (1 for scaled, 2 for open)."));
- exit();
- }
-
-
-
-
- if($typeID === "1") {
-
-
-
- $minVal = mysqli_real_escape_string($connection, trim($_POST['update_min_val']));
- $maxVal = mysqli_real_escape_string($connection, trim($_POST['update_max_val']));
- $minText = mysqli_real_escape_string($connection, trim($_POST['update_min_text']));
- $maxText = mysqli_real_escape_string($connection, trim($_POST['update_max_text']));
-
-
-
- if($minVal !== "1") {
- http_response_code(400);
- echo json_encode(array("error" => "Minimum value has to be 1."));
- exit();
- }
-
-
-
- if($minText === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify a valid minimum text."));
- exit();
- } else if(mb_strlen($minText) > 40) {
- http_response_code(400);
- echo json_encode(array("error" => "Minimum text '$minText' too long (max. is 40 characters)."));
- exit();
- }
-
-
-
-
-
-
-
- if(!is_numeric($maxVal)) {
- http_response_code(400);
- echo json_encode(array("error" => "Maximum value has to be numeric."));
- exit();
- } else if(intval($maxVal) < 2) {
- http_response_code(400);
- echo json_encode(array("error" => "Maximum value has to be greater or equal to 2."));
- exit();
- }
-
-
-
- if($maxText === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify a valid maximum text."));
- exit();
- } else if(mb_strlen($maxText) > 40) {
- http_response_code(400);
- echo json_encode(array("error" => "Maximum text '$maxText' too long (max. is 40 characters)."));
- exit();
- }
-
-
-
- if(mb_strtolower($maxText) === mb_strtolower($minText)) {
- http_response_code(400);
- echo json_encode(array("error" => "Labels must be different."));
- exit();
- }
-
-
-
-
- $query = "UPDATE `question` SET `id_type` = '$typeID' WHERE `id` = '$questionID'";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
-
-
- if(mysqli_query($connection, "SELECT * FROM question_type WHERE id_question = '$questionID';")->num_rows === 4) {
-
-
- $query = "UPDATE `question_type` SET value = '$minVal' WHERE `id_type` = '$typeID' AND `id_question` = '$questionID' AND `label` = 'min_val';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- $query = "UPDATE `question_type` SET value = '$minText' WHERE `id_type` = '$typeID' AND `id_question` = '$questionID' AND `label` = 'min_texto';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- $query = "UPDATE `question_type` SET value = '$maxVal' WHERE `id_type` = '$typeID' AND `id_question` = '$questionID' AND `label` = 'max_val';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- $query = "UPDATE `question_type` SET value = '$maxText' WHERE `id_type` = '$typeID' AND `id_question` = '$questionID' AND `label` = 'max_texto';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
-
- } else {
-
-
- $query = "INSERT INTO `question_type` (`id_type`, `id_question`, `label`, `value`) VALUES ('$typeID', '$questionID', 'min_val', '$minVal');";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- $query = "INSERT INTO `question_type` (`id_type`, `id_question`, `label`, `value`) VALUES ('$typeID', '$questionID', 'min_texto', '$minText');";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- $query = "INSERT INTO `question_type` (`id_type`, `id_question`, `label`, `value`) VALUES ('$typeID', '$questionID', 'max_val', '$maxVal');";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- $query = "INSERT INTO `question_type` (`id_type`, `id_question`, `label`, `value`) VALUES ('$typeID', '$questionID', 'max_texto', '$maxText');";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- }
-
-
-
- } else if($typeID === "2") {
-
-
- $query = "UPDATE `question` SET `id_type` = '$typeID' WHERE `id` = '$questionID';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
-
- $query = "DELETE FROM `question_type` WHERE `id_question` = '$questionID'";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- }
-
-
-
-
-
-
-
- if(isset($_POST['update_q_category'])) {
-
- $categoryID = mysqli_real_escape_string($connection, trim($_POST['update_q_category']));
-
-
-
- if($categoryID === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify category ID."));
- exit();
- } else if(mysqli_query($connection, "SELECT * FROM category WHERE id = '$categoryID';")->num_rows !== 1) {
- http_response_code(400);
- echo json_encode(array("error" => "Given category ID ($categoryID) not in database."));
- exit();
- }
-
- $query = "UPDATE `question` SET `id_category` = '$categoryID' WHERE `id` = '$questionID';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- }
-
-
-
-
- if(isset($_POST['update_q_subcategory'])) {
-
- $subcategoryID = mysqli_real_escape_string($connection, trim($_POST['update_q_subcategory']));
-
-
-
- if($subcategoryID === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify subcategory ID."));
- exit();
- } else if(mysqli_query($connection, "SELECT * FROM subcategory WHERE id = '$subcategoryID';")->num_rows !== 1) {
- http_response_code(400);
- echo json_encode(array("error" => "Given subcategory ID ($subcategoryID) not in database."));
- exit();
- }
-
- $query = "UPDATE `question` SET `id_subcategory` = '$subcategoryID' WHERE `id` = '$questionID';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
- }
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
|