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_edit.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. # @todo Fix multiple authors and bounty preview
  3. /*
  4. * Yeah, that's right, edit and new are the same place again.
  5. * It makes the page uglier to read but ultimately better as the alternative means
  6. * maintaining 2 copies of almost identical files.
  7. */
  8. $NewRequest = $_GET['action'] === 'new';
  9. if (!$NewRequest) {
  10. $RequestID = $_GET['id'];
  11. if (!is_number($RequestID)) {
  12. error(404);
  13. }
  14. }
  15. $Disabled = "";
  16. if ($NewRequest && ($LoggedUser['BytesUploaded'] < 250 * 1024 * 1024 || !check_perms('site_submit_requests'))) {
  17. error('You do not have enough uploaded to make a request');
  18. }
  19. if (!$NewRequest) {
  20. if (empty($ReturnEdit)) {
  21. $Request = Requests::get_request($RequestID);
  22. if ($Request === false) {
  23. error(404);
  24. }
  25. // Define these variables to simplify _GET['groupid'] requests later on
  26. $CategoryID = $Request['CategoryID'];
  27. $Title = $Request['Title'];
  28. $TitleRJ = $Request['TitleRJ'];
  29. $TitleJP = $Request['TitleJP'];
  30. $CatalogueNumber = $Request['CatalogueNumber'];
  31. $DLsiteID = $Request['DLsiteID'];
  32. $Image = $Request['Image'];
  33. $GroupID = $Request['GroupID'];
  34. $VoteArray = Requests::get_votes_array($RequestID);
  35. $VoteCount = count($VoteArray['Voters']);
  36. $IsFilled = !empty($Request['TorrentID']);
  37. $CategoryName = $Categories[$CategoryID - 1];
  38. $ProjectCanEdit = (check_perms('project_team') && !$IsFilled && $CategoryID === '0');
  39. $CanEdit = ((!$IsFilled && $LoggedUser['ID'] === $Request['UserID'] && $VoteCount < 2) || $ProjectCanEdit || check_perms('site_moderate_requests'));
  40. if (!$CanEdit) {
  41. error(403);
  42. }
  43. $ArtistForm = Requests::get_artists($RequestID);
  44. $Tags = implode(', ', $Request['Tags']);
  45. }
  46. }
  47. if ($NewRequest && !empty($_GET['artistid']) && is_number($_GET['artistid'])) {
  48. $DB->query("
  49. SELECT Name
  50. FROM artists_group
  51. WHERE artistid = ".$_GET['artistid']."
  52. LIMIT 1");
  53. list($ArtistName) = $DB->next_record();
  54. $ArtistForm = array(
  55. 1 => array(array('name' => trim($ArtistName))),
  56. );
  57. } elseif ($NewRequest && !empty($_GET['groupid']) && is_number($_GET['groupid'])) {
  58. $ArtistForm = Artists::get_artist($_GET['groupid']);
  59. $DB->query("
  60. SELECT
  61. tg.Name,
  62. tg.NameRJ,
  63. tg.NameJP,
  64. tg.Year,
  65. tg.Studio,
  66. tg.Series,
  67. tg.CatalogueNumber,
  68. tg.DLsiteID,
  69. tg.WikiImage,
  70. GROUP_CONCAT(t.Name SEPARATOR ', '),
  71. tg.CategoryID
  72. FROM torrents_group AS tg
  73. JOIN torrents_tags AS tt ON tt.GroupID = tg.ID
  74. JOIN tags AS t ON t.ID = tt.TagID
  75. WHERE tg.ID = ".$_GET['groupid']);
  76. if (list($Title, $TitleRJ, $TitleJP, $Year, $Studio, $Series, $CatalogueNumber, $DLsiteID, $Image, $Tags, $CategoryID) = $DB->next_record()) {
  77. $GroupID = trim($_REQUEST['groupid']);
  78. $CategoryName = $Categories[$CategoryID - 1];
  79. $Disabled = 'readonly="readonly"';
  80. }
  81. }
  82. View::show_header(($NewRequest ? 'Create Request' : 'Edit Request'), 'bbcode,requests,form_validate');
  83. ?>
  84. <!-- HTML title -->
  85. <div class="thin">
  86. <div class="header">
  87. <h2><?= ($NewRequest ? 'Create Request' : 'Edit Request') ?></h2>
  88. </div>
  89. <!-- New request hidden fields -->
  90. <div class="box pad">
  91. <form action="" method="post" id="request_form" onsubmit="Calculate();">
  92. <div>
  93. <?php if (!$NewRequest) { ?>
  94. <input type="hidden" name="requestid"
  95. value="<?= $RequestID ?>" />
  96. <?php } ?>
  97. <input type="hidden" name="auth"
  98. value="<?= $LoggedUser['AuthKey'] ?>" />
  99. <input type="hidden" name="action"
  100. value="<?= ($NewRequest ? 'takenew' : 'takeedit') ?>" />
  101. </div>
  102. <!-- Main table -->
  103. <table class="layout">
  104. <tr>
  105. <td colspan="2" class="center">Please make sure your request follows <a href="rules.php?p=requests">the request rules</a>!</td>
  106. </tr>
  107. <?php if ($NewRequest || $CanEdit) { ?>
  108. <!-- Category -->
  109. <tr>
  110. <td class="label">Type</td>
  111. <td>
  112. <?php if (!empty($Disabled)) { ?>
  113. <input type="hidden" name="type"
  114. value="<?= $CategoryName ?>" />
  115. <select id="categories" name="type" onchange="Categories();" disabled="disabled">
  116. <?php } else { ?>
  117. <select id="categories" name="type" onchange="Categories();">
  118. <?php } ?>
  119. <?php foreach (Misc::display_array($Categories) as $Cat) { ?>
  120. <option value="<?= $Cat ?>" <?= (!empty($CategoryName) && ($CategoryName === $Cat) ? ' selected="selected"' : '') ?>><?=$Cat?>
  121. </option>
  122. <?php } ?>
  123. </select>
  124. </td>
  125. </tr>
  126. <!-- Catalogue number -->
  127. <tr id="cataloguenumber_tr">
  128. <td class="label">Accession Number</td>
  129. <td>
  130. <input type="text" id="catalogue" name="cataloguenumber" size="15"
  131. value="<?= (isset($CatalogueNumber)?$CatalogueNumber:'') ?>"
  132. <?= $Disabled ?>/>
  133. <?php if (empty($Disabled)) { ?>
  134. <input type="button" autofill="jav" value="Autofill"></input>
  135. <?php } ?>
  136. </td>
  137. </tr>
  138. <!-- Three titles -->
  139. <tr>
  140. <td class="label">Torrent Title</td>
  141. <td>
  142. <input type="text" id="title" name="title" size="45"
  143. value="<?= (!empty($Title) ? $Title : '') ?>"
  144. <?= $Disabled ?>/>
  145. </td>
  146. </tr>
  147. <tr>
  148. <td class="label">Organism</td>
  149. <td>
  150. <input type="text" id="title_rj" name="title_rj" size="45"
  151. value="<?= (!empty($TitleRJ) ? $TitleRJ : '') ?>"
  152. <?= $Disabled ?>/>
  153. </td>
  154. </tr>
  155. <tr>
  156. <td class="label">Strain/Variety</td>
  157. <td>
  158. <input type="text" id="title_jp" name="title_jp" size="45"
  159. value="<?= !empty($TitleJP)?$TitleJP:'' ?>"
  160. <?= $Disabled ?>/>
  161. </td>
  162. </tr>
  163. <?php } # Ends if NewRequest line 123 ?>
  164. <!-- Multiple artists -->
  165. <tr id="artist_tr">
  166. <td class="label">Author(s)</td>
  167. <td id="artistfields">
  168. <?php
  169. if (!empty($ArtistForm)) {
  170. $First = true;
  171. foreach ($ArtistForm as $Artist) {
  172. # Cycle autocomplete
  173. ?>
  174. <input type="text" id="artist_0" name="artists[]" <?php Users::has_autocomplete_enabled('other'); ?>
  175. size="45" value="<?= display_str($Artist['name']) ?>" <?= $Disabled ?>/>
  176. <?php
  177. if (empty($Disabled)) {
  178. if ($First) { ?>
  179. <a class="add_artist_button brackets">+</a>
  180. <a class="remove_artist_button brackets">&minus;</a>
  181. <?php
  182. }
  183. $First = false;
  184. }
  185. ?>
  186. <br />
  187. <?php
  188. }
  189. } else {
  190. ?>
  191. <input type="text" id="artist_0" name="artists[]" <?php Users::has_autocomplete_enabled('other'); ?>
  192. size="45" <?= $Disabled ?>/>
  193. <?php if (empty($Disabled)) { ?>
  194. <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
  195. <?php
  196. }
  197. }
  198. ?>
  199. </td>
  200. </tr>
  201. <!-- Picture -->
  202. <?php if ($NewRequest || $CanEdit) { ?>
  203. <tr id="image_tr">
  204. <td class="label">Picture</td>
  205. <td>
  206. <input type="text" id="image" name="image" size="45"
  207. value="<?= (!empty($Image) ? $Image : '') ?>"
  208. <?= $Disabled ?>/>
  209. </td>
  210. </tr>
  211. <?php } ?>
  212. <!-- Tags -->
  213. <tr>
  214. <td class="label">Tags</td>
  215. <td>
  216. <?php
  217. $GenreTags = $Cache->get_value('genre_tags');
  218. if (!$GenreTags) {
  219. $DB->query('
  220. SELECT Name
  221. FROM tags
  222. WHERE TagType = \'genre\'
  223. ORDER BY Name');
  224. $GenreTags = $DB->collect('Name');
  225. $Cache->cache_value('genre_tags', $GenreTags, 3600 * 6);
  226. }
  227. if (!empty($Disabled)) {
  228. ?>
  229. <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;" disabled="disabled">
  230. <?php } else { ?>
  231. <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;">
  232. <?php } ?>
  233. <option>---</option>
  234. <?php foreach (Misc::display_array($GenreTags) as $Genre) { ?>
  235. <option value="<?= $Genre ?>"><?= $Genre ?>
  236. </option>
  237. <?php } ?>
  238. </select>
  239. <input type="text" id="tags" name="tags" size="45"
  240. value="<?= (!empty($Tags) ? display_str($Tags) : '') ?>"
  241. <?php Users::has_autocomplete_enabled('other'); ?>
  242. <?= $Disabled ?>/>
  243. </td>
  244. </tr>
  245. <!-- Description -->
  246. <tr>
  247. <td class="label">Description</td>
  248. <td>
  249. <?php new TEXTAREA_PREVIEW('description', 'req_desc', $Request['Description']??''); ?>
  250. </td>
  251. </tr>
  252. <!-- Existing torrent groups -->
  253. <?php if (check_perms('site_moderate_requests')) { ?>
  254. <tr>
  255. <td class="label">Torrent Group</td>
  256. <td>
  257. If this request matches a torrent group <strong>already existing</strong> on the site, please indicate that here.<br />
  258. <?= site_url() ?>torrents.php?id=<input type="text"
  259. name="groupid"
  260. value="<?= isset($GroupID)?$GroupID:'' ?>"
  261. size="15" />
  262. </td>
  263. </tr>
  264. <?php
  265. } elseif (!empty($GroupID)
  266. #&& ($CategoryID !== 5) # ?
  267. #&& ($CategoryID !== 0) # ?
  268. ) {
  269. ?>
  270. <!-- Torrent group admin -->
  271. <tr>
  272. <td class="label">Torrent Group</td>
  273. <td>
  274. <a href="torrents.php?id=<?= $GroupID ?>"><?= site_url() ?>torrents.php?id=<?= $GroupID ?></a><br />
  275. This request <?= ($NewRequest ? 'will be' : 'is') ?> associated with the above torrent group.
  276. <?php if (!$NewRequest) { ?>
  277. If this is incorrect, please
  278. <a href="reports.php?action=report&amp;type=request&amp;id=<?= $RequestID ?>">report this request</a>
  279. so that staff can fix it.
  280. <?php } ?>
  281. <input type="hidden" name="groupid"
  282. value="<?= $GroupID ?>" />
  283. </td>
  284. </tr>
  285. <!-- Bounty -->
  286. <?php } if ($NewRequest) { ?>
  287. <tr id="voting">
  288. <td class="label">Bounty</td>
  289. <td>
  290. <input type="text" id="amount_box" size="8"
  291. value="<?= (!empty($Bounty) ? $Bounty : '100') ?>"
  292. onchange="Calculate();" />
  293. <select id="unit" name="unit" onchange="Calculate();">
  294. <option value="mb" <?= (!empty($_POST['unit']) && $_POST['unit'] === 'mb' ? ' selected="selected"' : '') ?>>MB
  295. </option>
  296. <option value="gb" <?= (!empty($_POST['unit']) && $_POST['unit'] === 'gb' ? ' selected="selected"' : '') ?>>GB
  297. </option>
  298. </select>
  299. <input type="button" value="Preview" onclick="Calculate();" />
  300. <strong>The system deducts <?= ($RequestTax * 100) ?>% as tax</strong>
  301. </td>
  302. </tr>
  303. <!-- New stats -->
  304. <tr>
  305. <td class="label">New Stats</td>
  306. <td>
  307. <input type="hidden" id="amount" name="amount"
  308. value="<?= (!empty($Bounty) ? $Bounty : '100') ?>" />
  309. <input type="hidden" id="current_uploaded"
  310. value="<?= $LoggedUser['BytesUploaded'] ?>" />
  311. <input type="hidden" id="current_downloaded"
  312. value="<?= $LoggedUser['BytesDownloaded'] ?>" />
  313. <ul>
  314. <!-- @todo Return this feature
  315. <li><strong>Bounty:</strong> <span id="bounty_after_tax">90.00 MB</span></li> -->
  316. <li><strong>Uploaded:</strong> <span id="new_uploaded"><?= Format::get_size($LoggedUser['BytesUploaded']) ?></span></li>
  317. <li><strong>Ratio:</strong> <span id="new_ratio"><?= Format::get_ratio_html($LoggedUser['BytesUploaded'], $LoggedUser['BytesDownloaded']) ?></span></li>
  318. </ul>
  319. </td>
  320. </tr>
  321. <!-- Submit -->
  322. <tr>
  323. <td colspan="2" class="center">
  324. <input type="submit" id="button" value="Create" disabled="disabled" />
  325. </td>
  326. </tr>
  327. <?php } else { ?>
  328. <tr>
  329. <td colspan="2" class="center">
  330. <input type="submit" id="button" value="Edit" />
  331. </td>
  332. </tr>
  333. <?php } ?>
  334. </table>
  335. </form>
  336. </div>
  337. </div>
  338. <?php
  339. View::show_footer();