add.php 2.8 KB

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