save.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. session_start();
  3. $http_host = $_SERVER["HTTP_HOST"];
  4. $doc_root = $_SERVER["DOCUMENT_ROOT"] . "/";
  5. include $doc_root . "functions.php";
  6. $proto = get_protocol();
  7. $con = start_db();
  8. $server = $proto . $http_host;
  9. $pserver = substr($server, 0, strpos($http_host, ':')); // public server
  10. if (!check_session($con)){
  11. http_response_code(401);
  12. header("Location: /authentication.php");
  13. }
  14. else{
  15. $table = mysqli_real_escape_string($con, $_GET["t"]);
  16. $column = mysqli_real_escape_string($con, $_GET["c"]);
  17. $value = htmlspecialchars_decode(mysqli_real_escape_string($con, $_GET["v"]));
  18. $id = mysqli_real_escape_string($con, $_GET["i"]);
  19. // TODO: Validation!
  20. if ($table == 'text'){
  21. if (mysqli_query($con, "UPDATE text SET text = '$value' WHERE id = '$id' AND lang = '$column';")){
  22. http_response_code(200); // OK.
  23. }
  24. else{
  25. http_response_code(500); // Generic internal error.
  26. }
  27. }
  28. else{
  29. if (mysqli_query($con, "UPDATE $table SET $column = '$value' WHERE id = $id;")){
  30. http_response_code(200); // OK.
  31. }
  32. else{
  33. http_response_code(500); // Generic internal error.
  34. }
  35. }
  36. }
  37. ?>