apply.php 3.2 KB

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