add.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. else{
  10. //Get POST data
  11. $title_es = mysqli_real_escape_string($con, $_POST['title_es']);
  12. $title_eu = mysqli_real_escape_string($con, $_POST['title_eu']);
  13. $title_en = mysqli_real_escape_string($con, $_POST['title_en']);
  14. $text_es = mysqli_real_escape_string($con, $_POST['text_es']);
  15. $text_eu = mysqli_real_escape_string($con, $_POST['text_eu']);
  16. $text_en = mysqli_real_escape_string($con, $_POST['text_en']);
  17. $comments = mysqli_real_escape_string($con, $_POST['comments']);
  18. $visible = mysqli_real_escape_string($con, $_POST['visible']);
  19. $public = mysqli_real_escape_string($con, $_POST['public']);
  20. $populate = mysqli_real_escape_string($con, $_POST['populate']);
  21. //Check spanish title and generate permalink
  22. if ($title_es == null){
  23. exit();
  24. }
  25. else{
  26. $permalink = permalink($title_es);
  27. $i = 2;
  28. $ok = false;
  29. $tmppermalink = $permalink;
  30. while ($ok == false){
  31. $query = mysqli_query($con, "SELECT id FROM post WHERE permalink = '$tmppermalink';");
  32. if (mysqli_num_rows($query) > 0){
  33. $tmppermalink = $permalink . "-" . $i;
  34. $i ++;
  35. }
  36. else{
  37. $permalink = $tmppermalink;
  38. $ok = true;
  39. }
  40. }
  41. }
  42. //Check titles with no text
  43. if (strlen($title_eu) > 0 && strlen($text_eu) < 1)
  44. exit();
  45. if (strlen($title_en) > 0 && strlen($text_en) < 1)
  46. exit();
  47. //Check text with no titles
  48. if (strlen($text_eu) > 0 && strlen($title_eu) < 1)
  49. exit();
  50. if (strlen($text_en) > 0 && strlen($title_en) < 1)
  51. exit();
  52. //Check booleans and assign default values if not
  53. if ($comments == 'off')
  54. $comments = 0;
  55. else
  56. $comments = 1;
  57. if ($visible == 'off')
  58. $visible = 0;
  59. else
  60. $visible = 1;
  61. if ($public == 'on')
  62. $public = 1;
  63. else
  64. $public = 0;
  65. if ($populate == 'on')
  66. $populate = 1;
  67. else
  68. $populate = 0;
  69. // If no translations, same text in all languages
  70. if (strlen($text_eu) == 0){
  71. $text_eu = $text_es;
  72. $title_eu = $title_es;
  73. }
  74. if (strlen($text_en) == 0){
  75. $text_en = $text_es;
  76. $title_en = $title_es;
  77. }
  78. //Insert into database and get id
  79. mysqli_query($con, "INSERT INTO album (permalink, title_es, title_eu, title_en, description_es, description_eu, description_en, open) VALUES ('$permalink', '$title_es', '$title_eu', '$title_en', '$text_es', '$text_eu', '$text_en', $public);");
  80. $res_album = mysqli_query($con, "SELECT id FROM album WHERE permalink = '$permalink' ORDER BY dtime DESC LIMIT 1;");
  81. $row_album = mysqli_fetch_array($res_album);
  82. $album_id = $row_album['id'];
  83. version();
  84. //Redirect
  85. if ($populate == 1){
  86. header("Location: /galeria/");
  87. }
  88. else{
  89. header("Location: /galeria/upload.php?album=$album_id");
  90. }
  91. }
  92. ?>