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.

mass_user_bookmarks_editor.class.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. //require_once 'mass_user_torrents_editor.class.php';
  3. /**
  4. * This class helps with mass-editing bookmarked torrents.
  5. *
  6. * It can later be used for other bookmark tables.
  7. *
  8. */
  9. class MASS_USER_BOOKMARKS_EDITOR extends MASS_USER_TORRENTS_EDITOR
  10. {
  11. public function __construct($Table = 'bookmarks_torrents')
  12. {
  13. $this->set_table($Table);
  14. }
  15. /**
  16. * Runs a SQL query and clears the Cache key
  17. *
  18. * G::$Cache->delete_value didn't always work, but setting the key to null, did. (?)
  19. *
  20. * @param string $sql
  21. */
  22. protected function query_and_clear_cache($sql)
  23. {
  24. $QueryID = G::$DB->get_query_id();
  25. if (is_string($sql) && G::$DB->query($sql)) {
  26. G::$Cache->delete_value('bookmarks_group_ids_' . G::$LoggedUser['ID']);
  27. }
  28. G::$DB->set_query_id($QueryID);
  29. }
  30. /**
  31. * Uses (checkboxes) $_POST['remove'] to delete entries.
  32. *
  33. * Uses an IN() to match multiple items in one query.
  34. */
  35. public function mass_remove()
  36. {
  37. $SQL = [];
  38. foreach ($_POST['remove'] as $GroupID => $K) {
  39. if (is_number($GroupID)) {
  40. $SQL[] = sprintf('%d', $GroupID);
  41. }
  42. }
  43. if (!empty($SQL)) {
  44. $SQL = sprintf(
  45. '
  46. DELETE FROM %s
  47. WHERE UserID = %d
  48. AND GroupID IN (%s)',
  49. $this->Table,
  50. G::$LoggedUser['ID'],
  51. implode(', ', $SQL)
  52. );
  53. $this->query_and_clear_cache($SQL);
  54. }
  55. }
  56. /**
  57. * Uses $_POST['sort'] values to update the DB.
  58. */
  59. public function mass_update()
  60. {
  61. $SQL = [];
  62. foreach ($_POST['sort'] as $GroupID => $Sort) {
  63. if (is_number($Sort) && is_number($GroupID)) {
  64. $SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, G::$LoggedUser['ID']);
  65. }
  66. }
  67. if (!empty($SQL)) {
  68. $SQL = sprintf(
  69. '
  70. INSERT INTO %s
  71. (GroupID, Sort, UserID)
  72. VALUES
  73. %s
  74. ON DUPLICATE KEY UPDATE
  75. Sort = VALUES (Sort)',
  76. $this->Table,
  77. implode(', ', $SQL)
  78. );
  79. $this->query_and_clear_cache($SQL);
  80. }
  81. }
  82. }