apply.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. $http_host = $_SERVER['HTTP_HOST'];
  3. include("../../functions.php");
  4. $con = startdb('rw');
  5. if (!checkSession($con)){
  6. header("Location: /index.php");
  7. exit (-1);
  8. }
  9. //Get album fields
  10. $id = mysqli_real_escape_string($con, $_POST['id']);
  11. $title_en = mysqli_real_escape_string($con, $_POST['title_en']);
  12. $desc_en = mysqli_real_escape_string($con, $_POST['description_en']);
  13. $title_eu = mysqli_real_escape_string($con, $_POST['title_eu']);
  14. $desc_eu = mysqli_real_escape_string($con, $_POST['description_eu']);
  15. //Get photo fields
  16. $q_i = mysqli_query($con, "SELECT * FROM photo, photo_album WHERE photo.id = photo_album.photo AND album = $id;");
  17. $i = 0;
  18. $total_i = 0;
  19. while ($r_i = mysqli_fetch_array($q_i)){
  20. $p_id[$i] = $r_i['id'];
  21. $p_title_en[$i] = mysqli_real_escape_string($con, $_POST['photo_' . $p_id[$i] . '_title_en']);
  22. $p_desc_en[$i] = mysqli_real_escape_string($con, $_POST['photo_' . $p_id[$i] . '_description_en']);
  23. $p_title_eu[$i] = mysqli_real_escape_string($con, $_POST['photo_' . $p_id[$i] . '_title_eu']);
  24. $p_desc_eu[$i] = mysqli_real_escape_string($con, $_POST['photo_' . $p_id[$i] . '_description_eu']);
  25. $i ++;
  26. $total_i ++;
  27. }
  28. //Get current album data
  29. $q = mysqli_query($con, "SELECT * FROM album WHERE id = $id");
  30. if (mysqli_num_rows($q) > 0){
  31. $r = mysqli_fetch_array($q);
  32. //Update album fields
  33. if (strlen($title_en) > 0 && $title_en != $r['title_en']){
  34. mysqli_query($con, "UPDATE album SET title_en = '$title_en' WHERE id = $id;");
  35. }
  36. if (strlen($desc_en) > 0 && $desc_en != $r['description_en']){
  37. mysqli_query($con, "UPDATE album SET description_en = '$desc_en' WHERE id = $id;");
  38. }
  39. if (strlen($title_eu) > 0 && $title_eu != $r['title_eu']){
  40. mysqli_query($con, "UPDATE album SET title_eu = '$title_eu' WHERE id = $id;");
  41. }
  42. if (strlen($desc_eu) > 0 && $desc_eu != $r['description_eu']){
  43. mysqli_query($con, "UPDATE album SET description_eu = '$desc_eu' WHERE id = $id;");
  44. }
  45. version();
  46. }
  47. //Update photo entries
  48. for ($i = 0; $i < $total_i; $i ++){
  49. $q_i = mysqli_query($con, "SELECT * FROM photo WHERE id = $p_id[$i];");
  50. if (mysqli_num_rows($q_i) > 0){
  51. $r_i = mysqli_fetch_array($q_i);
  52. if (strlen($p_title_en[$i]) > 0 && $p_title_en[$i] != $r_i['title_en']){
  53. mysqli_query($con, "UPDATE photo SET title_en = '$p_title_en[$i]' WHERE id = $p_id[$i];");
  54. }
  55. if (strlen($p_desc_en[$i]) > 0 && $p_desc_en[$i] != $r_i['description_en']){
  56. mysqli_query($con, "UPDATE photo SET description_en = '$p_desc_en[$i]' WHERE id = $p_id[$i];");
  57. }
  58. if (strlen($p_title_eu[$i]) > 0 && $p_title_eu[$i] != $r_i['title_un']){
  59. mysqli_query($con, "UPDATE photo SET title_eu = '$p_title_eu[$i]' WHERE id = $p_id[$i];");
  60. }
  61. if (strlen($p_desc_eu[$i]) > 0 && $p_desc_eu[$i] != $r_i['description_eu']){
  62. mysqli_query($con, "UPDATE photo SET description_eu = '$p_desc_eu[$i]' WHERE id = $p_id[$i];");
  63. }
  64. }
  65. }
  66. header("Location: /galeria/translate/index.php");
  67. ?>