Advertisement
Guest User

masteredphp

a guest
May 7th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.27 KB | None | 0 0
  1. <?php include 'header.php'; if ( !isset($_GET['id']) || $_GET['id'] == '' ) { ?>
  2.  
  3. <h1>Collecting Cards</h1>
  4.  
  5. <?php } else if ( $_GET['id'] != '' ) {
  6.  
  7. function trim_value(&$value) { $value = trim($value); }
  8.  
  9. $id = intval($_GET['id']);
  10. $database = new Database;
  11.  
  12. $tcginfo = $database->get_assoc("SELECT * FROM `tcgs` WHERE `id`='$id' LIMIT 1");
  13. $altname = strtolower(str_replace(' ','',$tcginfo['name']));
  14.  
  15. if ( isset($_POST['update']) ) {
  16.  
  17. $sanitize = new Sanitize;
  18.  
  19. $catid = intval($_POST['id']);
  20. $cards = $sanitize->for_db($_POST['cards']);
  21. $worth = intval($_POST['worth']);
  22. $count = intval($_POST['count']);
  23. $break = intval($_POST['break']);
  24. $filler = $sanitize->for_db($_POST['filler']);
  25. $pending = $sanitize->for_db($_POST['pending']);
  26. $puzzle = intval($_POST['puzzle']);
  27. $mastereddate = $sanitize->for_db($_POST['mastereddate']);
  28. $auto = intval($_POST['auto']);
  29. $autourl = $sanitize->for_db($_POST['autourl']);
  30. if ( $autourl == '' ) { $autourl = 'default'; }
  31. if ( $autourl != 'default' && substr($autourl, -1) != '/' ) { $autourl = "$autourl/"; }
  32.  
  33. if ( $worth === '' ) { $error[] = 'Card worth must be defined.'; }
  34. else if ( $count === '' ) { $error[] = 'Card count must be defined.'; }
  35. else if ( $break === '' ) { $error[] = 'Break field must be defined. Set it to 0 if you don\'t want line breaks.'; }
  36. else if ( $filler === '' ) { $error[] = 'Please define a filler card.'; }
  37. else if ( $pending === '' ) { $error[] = 'Please define a pending card.'; }
  38. else if ( $puzzle != 1 && $puzzle != 0 ) { $error[] = 'Invalid Puzzle value.'; }
  39. else if ( $auto != 1 && $auto != 0 ) { $error[] = 'Invalid Auto value.'; }
  40. else if ( $autourl != 'default' && !filter_var($autourl, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) ) { $error[] = 'Invalid auto upload URL.'; }
  41. else {
  42.  
  43. $deck = $database->get_assoc("SELECT `deck` FROM `collecting` WHERE `id`='$catid'");
  44. $deck = $deck['deck'];
  45.  
  46. $cards = explode(',',$cards);
  47.  
  48. function adddeck(&$value,$key,$deck) {
  49. $value = trim($value);
  50. $value = ''.$deck.''.$value.'';
  51. }
  52. array_walk($cards,'adddeck',$deck);
  53.  
  54. if ( $tcginfo['autoupload'] == 1 && $auto == 1 ) {
  55. foreach ( $cards as $card ) {
  56. if ( !isset($error) ) {
  57. $filename = ''.$tcginfo['cardspath'].''.$card.'.'.$tcginfo['format'].'';
  58.  
  59. if ( !file_exists($filename) ) {
  60.  
  61. if ( $autourl == 'default' ) { $defaultauto = $tcginfo['defaultauto']; }
  62. else { $defaultauto = $autourl; }
  63. $imgurl = ''.$defaultauto.''.$card.'.'.$tcginfo['format'].'';
  64.  
  65. if ( !$img = file_get_contents($imgurl) ) { $error[] = "Couldn't find the file named $card.$format at $defaultauto"; }
  66. else {
  67. if ( !file_put_contents($filename,$img) ) { $error[] = "Failed to upload $filename"; }
  68. else { $success2 = " and all missing cards have been uploaded"; }
  69. }
  70.  
  71. }
  72.  
  73. }
  74. }
  75. }
  76.  
  77. $cards = implode(', ',$cards);
  78.  
  79. $result = $database->query("UPDATE `collecting` SET `cards`='$cards', `worth`='$worth', `count`='$count', `break`='$break', `filler`='$filler', `pending`='$pending', `puzzle`='$puzzle', `auto`='$auto', `uploadurl`='$autourl', `mastereddate`='$mastereddate' WHERE `id`='$catid' LIMIT 1");
  80. if ( !$result ) { $error[] = "Failed to update the collecting deck. ".mysql_error().""; }
  81. else { $success[] = "The deck has been updated$success2!"; }
  82.  
  83. }
  84.  
  85. }
  86.  
  87. if ( isset($_POST['newcat']) ) {
  88.  
  89. $sanitize = new Sanitize;
  90.  
  91. $deck = $sanitize->for_db($_POST['deck']);
  92. $cards = $sanitize->for_db($_POST['cards']);
  93. $findcards = intval($_POST['findcards']);
  94. $worth = intval($_POST['worth']);
  95. $count = intval($_POST['count']);
  96. $break = intval($_POST['break']);
  97. $filler = $sanitize->for_db($_POST['filler']);
  98. $pending = $sanitize->for_db($_POST['pending']);
  99. $puzzle = intval($_POST['puzzle']);
  100. $auto = intval($_POST['auto']);
  101. $autourl = $sanitize->for_db($_POST['autourl']);
  102. if ( $autourl == '' ) { $autourl = 'default'; }
  103. if ( $autourl != 'default' && substr($autourl, -1) != '/' ) { $autourl = "$autourl/"; }
  104. if ( $cards == 'cards (01, 02, 03)' ) { $cards = ''; }
  105.  
  106. if ( $worth === '' || $deck == 'worth' ) { $error[] = 'Card worth must be defined.'; }
  107. else if ( $deck === '' || $deck == 'deck' ) { $error[] = 'Deck name must be defined.'; }
  108. else if ( $count === '' || $deck == 'count' ) { $error[] = 'Card count must be defined.'; }
  109. else if ( $break === '' || $deck == 'break' ) { $error[] = 'Break field must be defined. Set it to 0 if you don\'t want line breaks.'; }
  110. else if ( $filler === '' ) { $error[] = 'Please define a filler card.'; }
  111. else if ( $pending === '' ) { $error[] = 'Please define a pending card.'; }
  112. else if ( $puzzle != 1 && $puzzle != 0 ) { $error[] = 'Invalid Puzzle value.'; }
  113. else if ( $auto != 1 && $auto != 0 ) { $error[] = 'Invalid Auto value.'; }
  114. else if ( $findcards != 1 && $findcards != 0 ) { $error[] = 'Invalid FindCards value.'; }
  115. else if ( $autourl != 'default' && !filter_var($autourl, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) ) { $error[] = 'Invalid auto upload URL.'; }
  116. else {
  117.  
  118. if ( $findcards == 0 ) {
  119.  
  120. $cards = explode(',',$cards);
  121.  
  122. function adddeck(&$value,$key,$deck) {
  123. $value = trim($value);
  124. $value = ''.$deck.''.$value.'';
  125. }
  126. array_walk($cards,'adddeck',$deck);
  127.  
  128. if ( $tcginfo['autoupload'] == 1 && $auto == 1 ) {
  129. foreach ( $cards as $card ) {
  130. if ( !isset($error) ) {
  131. $filename = ''.$tcginfo['cardspath'].''.$card.'.'.$tcginfo['format'].'';
  132.  
  133. if ( !file_exists($filename) ) {
  134.  
  135. if ( $autourl == 'default' ) { $defaultauto = $tcginfo['defaultauto']; }
  136. else { $defaultauto = $autourl; }
  137. $imgurl = ''.$defaultauto.''.$card.'.'.$tcginfo['format'].'';
  138.  
  139. if ( !$img = file_get_contents($imgurl) ) { $error[] = "Couldn't find the file named $card.$format at $defaultauto"; }
  140. else {
  141. if ( !file_put_contents($filename,$img) ) { $error[] = "Failed to upload $filename"; }
  142. else { $success2 = " and all missing cards have been uploaded"; }
  143. }
  144.  
  145. }
  146.  
  147. }
  148. }
  149. }
  150.  
  151. $cards = implode(', ',$cards);
  152.  
  153. }
  154.  
  155. else {
  156.  
  157. $result = $database->query("SELECT * FROM `cards` WHERE `tcg`='$id' ORDER BY `priority` DESC");
  158.  
  159. while ( $row = mysql_fetch_array($result) ) {
  160.  
  161. if ( !isset($error) ) {
  162.  
  163. $cards = explode(',',$row['cards']);
  164.  
  165. array_walk($cards, 'trim_value');
  166.  
  167. $i = 0;
  168. foreach ( $cards as $card ) {
  169. if ( preg_match("/".$deck."[0-9]{1,5}/i", $card) && strpos($newcards,$card) === false ) {
  170. if ( $newcards == '' ) { $newcards = $card; } else { $newcards .= ', '.$card.''; }
  171. $cards[$i] = '';
  172. }
  173. $i++;
  174. }
  175.  
  176. $cards = array_filter($cards);
  177. sort($cards);
  178. $cards = implode(', ',$cards);
  179.  
  180. $categid = $row['id'];
  181. $resultt = $database->query("UPDATE `cards` SET `cards`='$cards' WHERE `id`='$categid'");
  182. if ( !$resultt ) { $error[] = "Error updating cards from category ".$row['category'].""; }
  183.  
  184. }
  185.  
  186. }
  187.  
  188. $cards = $newcards;
  189.  
  190. }
  191.  
  192. if ( !isset($error) ) {
  193. $today = date("Y-m-d");
  194. $result = $database->query("INSERT INTO `collecting` (`tcg`,`deck`,`cards`,`worth`,`count`,`break`,`filler`,`pending`,`puzzle`,`auto`,`uploadurl`,`mastered`,`mastereddate`) VALUE ('$id','$deck','$cards','$worth','$count','$break','$filler','$pending','$puzzle','$auto','$autourl','1','$today')");
  195. if ( !$result ) { $error[] = "Failed to add the deck."; }
  196. else { $success[] = "The new mastered deck has been added$success2."; }
  197. }
  198.  
  199. }
  200.  
  201. }
  202.  
  203. if ( $_GET['action'] == 'delete' && isset($_GET['cat']) ) {
  204.  
  205. $catid = intval($_GET['cat']);
  206. $exists = $database->num_rows("SELECT * FROM `collecting` WHERE `id`='$catid'");
  207.  
  208. if ( $exists === 1 ) {
  209.  
  210. $result = $database->query("DELETE FROM `collecting` WHERE `id` = '$catid' LIMIT 1");
  211. if ( !$result ) { $error[] = "There was an error while attempting to remove the collecting set. ".mysql_error().""; }
  212. else { $success[] = "The mastered deck and containing cards have been removed."; }
  213.  
  214. }
  215.  
  216. else { $error[] = "The set no longer exists."; }
  217.  
  218. }
  219.  
  220. if ( isset($_POST['upload']) ) {
  221.  
  222.  
  223. if ( $_FILES["file"]["type"] != "image/gif" && $_FILES["file"]["type"] != "image/jpeg" && $_FILES["file"]["type"] != "image/pjpeg" && $_FILES["file"]["type"] != "image/png" ) { $error[] = "Invalid file type."; }
  224. else {
  225.  
  226. if ( move_uploaded_file($_FILES["file"]["tmp_name"],"".$tcginfo['cardspath']."".$_FILES["file"]["name"]."") ) {
  227.  
  228. $filename = $_FILES["file"]["name"];
  229. $result = $database->query("UPDATE `collecting` SET `badge` = '$filename' WHERE `id`='".$_GET['deck']."'");
  230. if ( !$result ) { $error[] = "Failed to update badge. ".mysql_error().""; }
  231. else { $success[] = "The new badge has been added."; }
  232.  
  233. }
  234.  
  235. else { $error[] = "Could not upload the file."; }
  236.  
  237. }
  238.  
  239. }
  240.  
  241. ?>
  242.  
  243. <h1>Mastered: <?php echo $tcginfo['name']; ?></h1>
  244. <p>Selecting the <strong>auto</strong> option will allow the auto upload system to automatically upload cards that are added to that category through the Easy Updater. The auto upload feature must be enabled in the TCG's settings as well for this to work. Deselect the auto checkbox to disable auto uploading for that category. Leave the <strong>upload url</strong> as <em>default</em> unless the Auto Upload URL for that category is different from the default defined in the TCG's settings.</p>
  245. <p>Upload filler and pending cards to your cards folder. Only type the file name into the filler/pending fields (ex. if the file name is filler.gif, just type 'filler')</p>
  246. <p>&raquo; <a href="cards.php?id=<?php echo $id; ?>">View Categories</a> <br />&raquo; <a href="collecting.php?id=<?php echo $id; ?>">View Collecting</a></p>
  247.  
  248. <?php if ( isset($error) ) { foreach ( $error as $msg ) { ?><div class="errors"><strong>ERROR!</strong> <?php echo $msg; ?></div><?php } } ?>
  249. <?php if ( isset($success) ) { foreach ( $success as $msg ) { ?><div class="success"><strong>SUCCESS!</strong> <?php echo $msg; ?></div><?php } } ?>
  250.  
  251. <?php if ( !isset($_GET['deck']) || $_GET['deck'] === '' ) { ?>
  252. <br />
  253. <form action="mastered.php?id=<?php echo $id; ?>" method="post">
  254. <p align="center"><strong>New Mastered</strong>:</p>
  255. <table cellspacing="5" cellpadding="0" align="center">
  256. <tr>
  257. <td><input name="deck" type="text" id="deck" value="deck" onfocus="if (this.value=='deck') this.value='';" onblur="if (this.value=='') this.value='deck';"></td>
  258. <td><input name="worth" type="text" id="worth" value="worth" size="3" onfocus="if (this.value=='worth') this.value='';" onblur="if (this.value=='') this.value='worth';"></td>
  259. <td><input name="count" type="text" id="count" value="count" size="3" onfocus="if (this.value=='count') this.value='';" onblur="if (this.value=='') this.value='count';"></td>
  260. <td><input name="break" type="text" id="break" value="break" size="3" onfocus="if (this.value=='break') this.value='';" onblur="if (this.value=='') this.value='break';"></td>
  261. <td><input name="filler" type="text" id="filler" value="filler" size="8" onfocus="if (this.value=='filler') this.value='';" onblur="if (this.value=='') this.value='filler';"></td>
  262. <td><input name="pending" type="text" id="pending" value="pending" size="8" onfocus="if (this.value=='pending') this.value='';" onblur="if (this.value=='') this.value='pending';"></td>
  263. </tr>
  264. <tr>
  265. <td colspan="3"><input name="cards" type="text" id="cards" value="cards (01, 02, 03)" size="35" onfocus="if (this.value=='cards (01, 02, 03)') this.value='';" onblur="if (this.value=='') this.value='cards (01, 02, 03)';" /></td>
  266. <td><strong>OR</strong></td>
  267. <td colspan="2">grab from categories: <input name="findcards" type="checkbox" value="1" id="findcards"></td>
  268. </tr>
  269. <tr>
  270. <td colspan="3">auto url: <input name="autourl" type="text" value="default" id="autourl" /></td>
  271. <td colspan="3">auto: <input name="auto" type="checkbox" value="1" id="auto" /></td>
  272. </tr>
  273. <tr>
  274. <td colspan="6" align="right"><input name="newcat" type="submit" value="Submit" id="newcat"></td>
  275. </tr>
  276. </table>
  277. </form>
  278. <?php } ?>
  279.  
  280. <?php if ( !isset($_GET['deck']) || $_GET['deck'] === '' ) { ?>
  281.  
  282. <?php
  283.  
  284. $result = $database->query("SELECT * FROM `collecting` WHERE `tcg`='$id' AND `mastered` = '1' ORDER BY `mastereddate`");
  285. while ( $row = mysql_fetch_assoc($result) ) {
  286. echo '<a href="mastered.php?id='.$id.'&deck='.$row['id'].'"><img src="'.$tcginfo['cardsurl'].''.$row['badge'].'" alt="'.$row['deck'].'" title="'.$row['deck'].': Mastered '.$row['mastereddate'].'" /></a> ';
  287.  
  288. ?>
  289.  
  290. <?php } else if ( isset($_GET['deck']) && $_GET['deck'] !== '' ) { $deckid = intval($_GET['deck']); ?>
  291.  
  292. <?php
  293. $deckinfo = $database->get_assoc("SELECT * FROM `collecting` WHERE `id`='$deckid' LIMIT 1");
  294.  
  295. $cards = explode(',',$deckinfo['cards']);
  296.  
  297. array_walk($cards, 'trim_value');
  298.  
  299. $count = count($cards);
  300. ?>
  301.  
  302. <br />
  303. <h2><?php echo $deckinfo['deck']; ?> <a href="mastered.php?id=<?php echo $id; ?>&action=delete&cat=<?php echo $deckinfo['id']; ?>" onclick="go=confirm('Are you sure that you want to permanently delete this deck? The contents will be lost completely.'); return go;"><img src="images/delete.gif" alt="delete" /></a></h2>
  304. &laquo; <a href="mastered.php?id=<?php echo $id; ?>">Back to Mastered Decks</a><br />
  305. <p align="center">
  306. <?php
  307. for ( $i = 1; $i <= $deckinfo['count']; $i++ ) {
  308.  
  309. $number = $i;
  310. if ( $number < 10 ) { $number = "0$number"; }
  311. $card = "".$deckinfo['deck']."$number";
  312.  
  313. $pending = $database->num_rows("SELECT * FROM `trades` WHERE `tcg`='$id' AND `receiving` LIKE '%$card%'");
  314.  
  315. if ( in_array($card, $cards) ) echo '<img src="'.$tcginfo['cardsurl'].''.$card.'.'.$tcginfo['format'].'" alt="" />';
  316. else if ( $pending > 0 ) { echo '<img src="'.$tcginfo['cardsurl'].''.$deckinfo['pending'].'.'.$tcginfo['format'].'" alt="" />'; }
  317. else { echo '<img src="'.$tcginfo['cardsurl'].''.$deckinfo['filler'].'.'.$tcginfo['format'].'" alt="" />'; }
  318.  
  319. if ( $deckinfo['puzzle'] == 0 ) { echo ' '; }
  320. if ( $deckinfo['break'] !== '0' && $i % $deckinfo['break'] == 0 ) { echo '<br />'; }
  321.  
  322. }
  323. ?>
  324. </p>
  325.  
  326.  
  327. <form enctype="multipart/form-data" action="" method="post">
  328. <table align="center" cellspacing="5" cellpadding="5" class="style1">
  329. <tr>
  330. <td rowspan="3"><img src="<?php echo $tcginfo['cardsurl']; echo $deckinfo['badge']; ?>" alt="" /></td>
  331. <td><strong>Master Badge</strong></td>
  332. </tr><tr>
  333. <td><input id="file" type="file" name="file"></td>
  334. </tr><tr>
  335. <td><input name="upload" type="submit" id="upload" value="Change Badge"></td>
  336. </tr>
  337. </table>
  338. </form>
  339.  
  340. <br /><br />
  341. <form action="" method="post">
  342. <input name="id" type="hidden" value="<?php echo $deckinfo['id']; ?>" />
  343. <table width="400" align="center" cellspacing="5" cellpadding="5">
  344. <tr>
  345. <td colspan="6" class="top">Deck Settings</td>
  346. </tr><tr>
  347. <td colspan="3" align="center">
  348. <input name="cards" type="text" id="cards" value="<?php echo str_replace($deckinfo['deck'],'',$deckinfo['cards']); ?>" size="60">
  349. </td>
  350. </tr><tr>
  351. <td>worth: <input name="worth" type="text" id="worth" value="<?php echo $deckinfo['worth']; ?>" size="2" /></td>
  352. <td>count: <input name="count" type="text" id="count" value="<?php echo $deckinfo['count']; ?>" size="2" /></td>
  353. <td>break: <input name="break" type="text" id="break" value="<?php echo $deckinfo['break']; ?>" size="2" /></td>
  354. </tr><tr>
  355. <td>filler: <input name="filler" type="text" id="filler" value="<?php echo $deckinfo['filler']; ?>" size="8" /></td>
  356. <td>pending: <input name="pending" type="text" id="pending" value="<?php echo $deckinfo['pending']; ?>" size="8" /></td>
  357. <td>puzzle: <input name="puzzle" type="checkbox" id="puzzle" value="1" <?php if ( $deckinfo['puzzle'] == 1 ) { echo 'checked="checked"'; } ?> /></td>
  358. </tr><tr>
  359. <td colspan="2">auto url: <input name="" type="text" value="<?php echo $deckinfo['uploadurl']; ?>" /></td>
  360. <td>auto: <input name="auto" type="checkbox" id="auto" value="1" <?php if ( $deckinfo['auto'] == 1 ) { echo 'checked="checked"'; } ?> /></td>
  361. </tr><tr>
  362. <td colspan="3" align="right">mastered: <input name="mastereddate" type="text" id="mastereddate" value="<?php echo $deckinfo['mastereddate']; ?>" size="10"> <input name="update" type="submit" value="Update" id="update" /></td>
  363. </tr>
  364. </table>
  365. </form>
  366.  
  367. <?php } } include 'footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement