execute.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. $http_host = $_SERVER['HTTP_HOST'];
  3. $default_host = substr($http_host, 0, strpos($http_host, ':'));
  4. include("../functions.php");
  5. $con = startdb('rw');
  6. if (!checkSession($con)){
  7. exit (-1);
  8. }
  9. else{
  10. //Get year
  11. $year = date("Y");
  12. //Get data to calculate
  13. $action = mysqli_real_escape_string($con, $_POST['action']);
  14. $table = mysqli_real_escape_string($con, $_POST['table']);
  15. $field = mysqli_real_escape_string($con, $_POST['field']);
  16. $type = mysqli_real_escape_string($con, $_POST['type']);
  17. $id = mysqli_real_escape_string($con, $_POST['id']);
  18. $value = mysqli_real_escape_string($con, urldecode($_POST['value']));
  19. //Validate tables where values can be inserted
  20. if ($table != 'festival' and $table != 'festival_day' and $table != 'festival_event' and $table != 'festival_event_image' and $table != 'festival_offer'){
  21. //TODO: If I got here, somebody is doing something nasty. Log it.
  22. exit (-1);
  23. }
  24. switch ($action){
  25. case "delete":
  26. mysqli_query($con, "DELETE FROM $table WHERE id = $id;");
  27. break;
  28. case "update":
  29. switch($type){
  30. case "text":
  31. mysqli_query($con, "UPDATE $table SET $field = '$value' WHERE id = $id;");
  32. error_log("UPDATE $table SET $field = '$value' WHERE id = $id;");
  33. break;
  34. case "number":
  35. mysqli_query($con, "UPDATE $table SET $field = $value WHERE id = $id;");
  36. error_log("UPDATE $table SET $field = $value WHERE id = $id;");
  37. break;
  38. //TODO: add a case for dates
  39. }
  40. }
  41. }
  42. ?>