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 14KB

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