BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

new_handle.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. #declare(strict_types=1);
  3. authorize();
  4. include(SERVER_ROOT.'/classes/validate.class.php');
  5. $Val = new Validate;
  6. $P = [];
  7. $P = db_array($_POST);
  8. if ($P['category'] > 0 || check_perms('site_collages_renamepersonal')) {
  9. $Val->SetFields('name', '1', 'string', 'The name must be between 5 and 255 characters.', array('maxlength' => 255, 'minlength' => 5));
  10. } else {
  11. // Get a collage name and make sure it's unique
  12. $name = $LoggedUser['Username']."'s personal collage";
  13. $P['name'] = db_string($name);
  14. $DB->query("
  15. SELECT ID
  16. FROM collages
  17. WHERE Name = '".$P['name']."'");
  18. $i = 2;
  19. while ($DB->has_results()) {
  20. $P['name'] = db_string("$name no. $i");
  21. $DB->query("
  22. SELECT ID
  23. FROM collages
  24. WHERE Name = '".$P['name']."'");
  25. $i++;
  26. }
  27. }
  28. $Val->SetFields('description', '1', 'string', 'The description must be between 10 and 65535 characters.', array('maxlength' => 65535, 'minlength' => 10));
  29. $Err = $Val->ValidateForm($_POST);
  30. if (!$Err && $P['category'] === '0') {
  31. $DB->query("
  32. SELECT COUNT(ID)
  33. FROM collages
  34. WHERE UserID = '$LoggedUser[ID]'
  35. AND CategoryID = '0'
  36. AND Deleted = '0'");
  37. list($CollageCount) = $DB->next_record();
  38. if (($CollageCount >= $LoggedUser['Permissions']['MaxCollages']) || !check_perms('site_collages_personal')) {
  39. $Err = 'You may not create a personal collage.';
  40. } elseif (check_perms('site_collages_renamepersonal') && !stristr($P['name'], $LoggedUser['Username'])) {
  41. $Err = "Your personal collage's title must include your username.";
  42. }
  43. }
  44. if (!$Err) {
  45. $DB->query("
  46. SELECT ID, Deleted
  47. FROM collages
  48. WHERE Name = '$P[name]'");
  49. if ($DB->has_results()) {
  50. list($ID, $Deleted) = $DB->next_record();
  51. if ($Deleted) {
  52. $Err = 'That collection already exists but needs to be recovered. Please <a href="staffpm.php">contact</a> the staff team.';
  53. } else {
  54. $Err = "That collection already exists: <a href='/collages.php?id=$ID'>$ID</a>.";
  55. }
  56. }
  57. }
  58. if (!$Err) {
  59. if (empty($CollageCats[$P['category']])) {
  60. $Err = 'Please select a category';
  61. }
  62. }
  63. if ($Err) {
  64. $Name = $_POST['name'];
  65. $Category = $_POST['category'];
  66. $Tags = $_POST['tags'];
  67. $Description = $_POST['description'];
  68. include(SERVER_ROOT.'/sections/collages/new.php');
  69. error();
  70. }
  71. $TagList = explode(',', $_POST['tags']);
  72. foreach ($TagList as $ID => $Tag) {
  73. $TagList[$ID] = Misc::sanitize_tag($Tag);
  74. }
  75. $TagList = implode(' ', $TagList);
  76. $DB->query("
  77. INSERT INTO collages
  78. (Name, Description, UserID, TagList, CategoryID)
  79. VALUES
  80. ('$P[name]', '$P[description]', $LoggedUser[ID], '$TagList', '$P[category]')");
  81. $CollageID = $DB->inserted_id();
  82. $Cache->delete_value("collage_$CollageID");
  83. Misc::write_log("Collage $CollageID (".$_POST['name'].') was created by '.$LoggedUser['Username']);
  84. header("Location: collages.php?id=$CollageID");