Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.65 KB | None | 0 0
  1. [fsk141@FSK-Main ~/gazelle/v1/branches/v1.5/sections/torrents]$ cat edit.php takeedit.php
  2. <?
  3. //*********************************************************************//
  4. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Edit form ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  5. // This page relies on the TORRENT_FORM class. All it does is call //
  6. // the necessary functions. //
  7. //---------------------------------------------------------------------//
  8. // At the bottom, there are grouping functions which are off limits to //
  9. // most members. //
  10. //*********************************************************************//
  11.  
  12. require_once(SERVER_ROOT.'/classes/class_torrent_form.php');
  13.  
  14. if(!is_number($_GET['id']) || !$_GET['id']) { error('','Invalid form data', '', '', true); }
  15.  
  16. $TorrentID = $_GET['id'];
  17.  
  18. $DB->query("SELECT
  19. t.Year AS RemasterYear,
  20. t.Remastered,
  21. t.RemasterTitle,
  22. t.FreeTorrent,
  23. t.Dupable,
  24. t.DupeReason,
  25. t.Description AS TorrentDescription,
  26. tg.CategoryID,
  27. tg.Name AS Title,
  28. tg.Year,
  29. tg.ArtistID,
  30. a.Name AS ArtistName,
  31. t.GroupID,
  32. t.UserID,
  33. t.FreeTorrent,
  34. t.DiskNumber,
  35. t.NativeTitle,
  36. t.Runtime,
  37. t.Color,
  38. t.Rating,
  39. t.SourceMedia,
  40. t.SourceResolution,
  41. t.ScreenFormat,
  42. t.Language,
  43. t.AudioFormat,
  44. t.AudioChannel,
  45. t.Subtitle,
  46. t.TorrentLog
  47. FROM torrents AS t
  48. JOIN torrents_group AS tg ON tg.ID=t.GroupID
  49. LEFT JOIN artists AS a ON a.ID=tg.ArtistID
  50. WHERE t.ID='$TorrentID'");
  51.  
  52. list($Properties) = $DB->to_array(false,MYSQLI_BOTH);
  53. $UploadForm = $Categories[$Properties['CategoryID']-1];
  54.  
  55. if($LoggedUser['Err']) {
  56. $Err = $LoggedUser['Err'];
  57. unset($_SESSION['logged_user']['Err']);
  58. }
  59.  
  60. show_header('Edit torrent', 'upload');
  61.  
  62. if(!$Properties) { error('', 'Torrent does not exist!', '', '', true); }
  63.  
  64. if($LoggedUser['ID']!=$Properties['UserID'] && !check_perms('torrents_edit')) {
  65. error(403);
  66. }
  67. $TorentForm = new TORRENT_FORM($Properties, $Err, false);
  68.  
  69. $TorentForm->head();
  70. switch ($UploadForm) {
  71. case 'Movies':
  72. $TorentForm->movies_form('');
  73. break;
  74. case 'Television':
  75. $TorentForm->television_form();
  76. break;
  77. default:
  78. $TorentForm->movies_form('');
  79. }
  80. $TorentForm->foot();
  81. if(check_perms('torrents_edit') && $Properties['CategoryID'] == 1){
  82. ?>
  83. <div class="thin">
  84. <h2>Change Group</h2>
  85. <form action="torrents.php" method="post">
  86. <table>
  87. <tr>
  88. <td class="label">Group ID</td>
  89. <td>
  90. <input type="hidden" name="action" value="editgroupid" />
  91. <input type="hidden" name="torrentid" value="<?=$TorrentID?>" />
  92. <input type="hidden" name="oldgroupid" value="<?=$Properties['GroupID']?>" />
  93. <input type="text" name="groupid" value="<?=$Properties['GroupID']?>" size="10" />
  94. </td>
  95. </tr>
  96. <tr>
  97. <td colspan="2" class="center">
  98. <input type="submit" value="Change group ID" />
  99. </td>
  100. </tr>
  101. </table>
  102. </form>
  103. <h2>Split off into new group</h2>
  104. <form action="torrents.php" method="post">
  105. <table>
  106. <tr>
  107. <td class="label">Director</td>
  108. <td>
  109. <input type="hidden" name="action" value="newgroup" />
  110. <input type="hidden" name="torrentid" value="<?=$TorrentID?>" />
  111. <input type="hidden" name="oldgroupid" value="<?=$Properties['GroupID']?>" />
  112. <input type="hidden" name="oldartistid" value="<?=$Properties['ArtistID']?>" />
  113. <input type="text" name="artist" value="<?=$Properties['ArtistName']?>" size="50" />
  114. </td>
  115. </tr>
  116. <tr>
  117. <td class="label">Title</td>
  118. <td>
  119. <input type="text" name="title" value="<?=$Properties['Title']?>" size="50" />
  120. </td>
  121. </tr>
  122. <tr>
  123. <td class="label">Year</td>
  124. <td>
  125. <input type="text" name="year" value="<?=$Properties['Year']?>" size="10" />
  126. </td>
  127. </tr>
  128. <tr>
  129. <td colspan="2" class="center">
  130. <input type="submit" value="Split into new group" />
  131. </td>
  132. </tr>
  133. </table>
  134. </form>
  135.  
  136. <br />
  137. </div>
  138. <?
  139. } // if check_perms('torrents_edit')
  140.  
  141. show_footer();
  142. ?>
  143. <?
  144. //******************************************************************************//
  145. //--------------- Take edit ----------------------------------------------------//
  146. // This pages handles the backend of the 'edit torrent' function. It checks //
  147. // the data, and if it all validates, it edits the values in the database //
  148. // that correspond to the torrent in question. //
  149. //******************************************************************************//
  150.  
  151.  
  152. enforce_login();
  153.  
  154. require_once(SERVER_ROOT.'/classes/class_validate.php');
  155. $Validate = new VALIDATE;
  156.  
  157. //******************************************************************************//
  158. //--------------- Set $Properties array ----------------------------------------//
  159. // This is used if the form doesn't validate, and when the time comes to enter //
  160. // it into the database. //
  161.  
  162. $Properties=array();
  163. $TypeID = (int)$_POST['type'];
  164. $Type = $Categories[$TypeID-1];
  165. $TorrentID = (int)$_POST['torrentid'];
  166. $Properties['Remastered'] = (isset($_POST['remaster']))? 1 : 0;
  167. if($Properties['Remastered']) {
  168. $Properties['RemasterYear'] = $_POST['remaster_year'];
  169. $Properties['RemasterTitle'] = $_POST['remaster_title'];
  170. } else {
  171. $Properties['RemasterYear'] = '';
  172. $Properties['RemasterTitle'] = '';
  173.  
  174. }
  175. $Properties['TorrentDescription'] = $_POST['release_desc'];
  176. $Properties['NativeTitle'] = $_POST['native_title'];
  177. $Properties['Runtime'] = $_POST['runtime'];
  178. $Properties['Color'] = $_POST['color'];
  179. $Properties['Rating'] = $_POST['rating'];
  180. $Properties['DiskNumber'] = $_POST['disknumber'];
  181. $Properties['SourceMedia'] = $_POST['sourcemedia'];
  182. $Properties['SourceResolution'] = $_POST['sourceresolution'];
  183. $Properties['ScreenFormat'] = $_POST['screenformat'];
  184. $Properties['Language'] = $_POST['language'];
  185. $Properties['AudioFormat'] = $_POST['audioformat'];
  186. $Properties['AudioChannel'] = $_POST['audiochannel'];
  187. $Properties['Subtitle'] = $_POST['subtitle'];
  188. $Properties['TorrentLog'] = $_POST['torrent_log'];
  189.  
  190. if($_POST['album_desc']) {
  191. $Properties['GroupDescription'] = $_POST['album_desc'];
  192. }
  193. if(check_perms('torrents_freeleech')) {
  194. $Properties['FreeTorrent'] = (isset($_POST['freeleech']))? "'1'" : "'0'";
  195. } else {
  196. $Properties['FreeTorrent'] = 'freetorrent';
  197. }
  198.  
  199. //******************************************************************************//
  200. //--------------- Validate data in edit form -----------------------------------//
  201.  
  202. $DB->query('SELECT UserID FROM torrents WHERE ID='.$TorrentID);
  203. list($UserID) = $DB->next_record();
  204.  
  205. if($LoggedUser['ID']!=$UserID && !check_perms('torrents_edit')) {
  206. error(403);
  207. }
  208.  
  209. $Validate->SetFields('type','1','number','Not a valid type.',array('maxlength'=>count($Categories), 'minlength'=>1));
  210. $Validate->SetFields('type','1','number','Invalid torrent ID.',array('maxlength'=>1000000000, 'minlength'=>1)); // we shouldn't have torrent IDs higher than a billion
  211. switch ($Type) {
  212. case 'Movies':
  213. if(isset($_POST['remaster'])) {
  214. $Validate->SetFields('remaster_year',
  215. '1','number','Year of remaster/re-issue must be entered.');
  216.  
  217. $Validate->SetFields('remaster_title',
  218. '0','string','Remaster title must be between 2 and 40 characters.',array('maxlength'=>40, 'minlength'=>2));
  219. }
  220.  
  221. $Validate->SetFields('color',
  222. '1','inarray','Please select a valid "Color".',array('inarray'=>$Color));
  223.  
  224. $Validate->SetFields('rating',
  225. '1','inarray','Please select a valid "Rating".',array('inarray'=>$Rating));
  226.  
  227. $Validate->SetFields('disknumber',
  228. '1','inarray','Please select a valid "Disk Number".',array('inarray'=>$DiskNumber));
  229.  
  230. $Validate->SetFields('sourcemedia',
  231. '1','inarray','Please select a valid "Source Media".',array('inarray'=>$SourceMedia));
  232.  
  233. $Validate->SetFields('sourceresolution',
  234. '1','inarray','Please select a valid "Source Resolution".',array('inarray'=>$SourceResolution));
  235.  
  236. $Validate->SetFields('screenformat',
  237. '1','inarray','Please select a valid "Screen Format".',array('inarray'=>$ScreenFormat));
  238.  
  239. $Validate->SetFields('language',
  240. '1','string','Language must be between 1 and 200 characters.',array('maxlength'=>200, 'minlength'=>1));
  241.  
  242. $Validate->SetFields('image',
  243. '0','link','The image URL you entered was invalid.',array('maxlength'=>255, 'minlength'=>12));
  244.  
  245. $Validate->SetFields('release_desc',
  246. '0','string','The release description has a minimum length of 10 characters.',array('maxlength'=>1000000, 'minlength'=>10));
  247.  
  248. break;
  249. }
  250.  
  251. $Err=$Validate->ValidateForm($_POST); // Validate the form
  252.  
  253. if($Err){ // Show the upload form, with the data the user entered
  254. $_SESSION['logged_user']['Err'] = $Err;
  255. header('Location: '.$_SERVER['HTTP_REFERER']);
  256. die();
  257. }
  258.  
  259.  
  260. //******************************************************************************//
  261. //--------------- Make variables ready for database input ----------------------//
  262.  
  263. // Shorten and escape $Properties for database input
  264. $T = array();
  265. while(list($Key, $Value) = each($Properties)){
  266. $T[$Key]="'".db_string(trim($Value))."'";
  267. if(!$T[$Key]){
  268. $T[$Key] = NULL;
  269. }
  270. }
  271.  
  272.  
  273. //******************************************************************************//
  274. //--------------- Start database stuff -----------------------------------------//
  275.  
  276. // Update info for the torrent
  277. $DB->query("
  278. UPDATE torrents SET
  279. Year=$T[RemasterYear],
  280. Remastered=$T[Remastered],
  281. RemasterTitle=$T[RemasterTitle],
  282. Description=$T[TorrentDescription],
  283. FreeTorrent=$Properties[FreeTorrent],
  284. NativeTitle=$T[NativeTitle],
  285. Runtime=$T[Runtime],
  286. Color=$T[Color],
  287. Rating=$T[Rating],
  288. DiskNumber=$T[DiskNumber],
  289. SourceMedia=$T[SourceMedia],
  290. SourceResolution=$T[SourceResolution],
  291. ScreenFormat=$T[ScreenFormat],
  292. Language=$T[Language],
  293. AudioFormat=$T[AudioFormat],
  294. AudioChannel=$T[AudioChannel],
  295. Subtitle=$T[Subtitle],
  296. flags='2'
  297. WHERE ID=$TorrentID
  298. ");
  299.  
  300. $DB->query("SELECT GroupID FROM torrents WHERE ID='$TorrentID'");
  301. list($GroupID) = $DB->next_record();
  302.  
  303. write_log("Torrent $TorrentID ($Name) was edited by " . $LoggedUser['Username']); // TODO: this is probably broken
  304.  
  305. $Cache->delete_value('detail_'.$GroupID.'_');
  306. // All done!
  307.  
  308. header("Location: torrents.php?id=$GroupID");
  309.  
  310. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement