rendered paste body/* --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ [The Code (functions.php)]/* --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */<?phpfunction CompleteSet($set){ global $globset; $the_complete = array(); $handle = file_get_contents('./cards'); $array = explode(chr(10), $handle); reset($array); $gotcards = array(); foreach ($array AS $value) { list($card_set, $card_number, $r) = explode(':', $value); if ($card_set == $set) { $gotcards[] = $card_number; } } $the_complete['gots'] = count($gotcards); $the_complete['tots'] = $globset[$set]; $the_complete['need'] = ($the_complete['tots'] - $the_complete['gots']); @$the_complete['percentage'] = round(($the_complete['gots'] / $the_complete['tots']) * 100, 1); return $the_complete;}function FetchMoney(){ $money = file_get_contents('./money'); return $money;}function FetchName(){ $name = file_get_contents('./user'); return $name;}function FetchCount($t){ if ($t == 1) { $count = file_get_contents('./sold'); } if ($t == 2) { $count = file_get_contents('./got'); } if ($t == 3) { $count = file_get_contents('./boost'); } if ($t == 4) { $count = file_get_contents('./specs'); } if ($t == 5) { $count = file_get_contents('./cardmoney'); } return $count;}function CountAdd($t){ switch ($t) { case '1': $file = "./sold"; break; case '2': $file = "./got"; break; case '3': $file = "./boost"; break; case '4': $file = "./specs"; break; default: $file = "./sold"; break; } $count = file_get_contents($file); if (!$count) { $count = 0; } $some = $count + 1; $handle = fopen($file, 'r+'); fwrite($handle, $some); fclose($handle);}function CardMoneyAdd($value){ $money = file_get_contents('./cardmoney'); if (!$money) { $money = 0; } $some = $money + $value; $handle = fopen('./cardmoney', 'r+'); fwrite($handle, $some); fclose($handle);}function SellCard($value){ SetMoney('a', $value); CountAdd(1); CardMoneyAdd($value); echo "[[inFunction_SellCard(): <b>\$value=</b>{$value}]]";}function SetMoney($type, $new){ $money = FetchMoney(); switch($type) { case 'a': $newmoney = ($money + trim($new)); break; case 's': $newmoney = ($money - trim($new)); break; default: $newmoney = $money; break; } echo "[[inFunction_SetMoney(): <b>\$type=</b>{$type} <b>\$new=</b>{$new} <b>\$money=</b>{$money} <b>\$newmoney=</b>{$newmoney}]]"; $file = "./money"; $handle = fopen($file, 'r+'); fwrite($handle, $newmoney); fclose($handle);}function ResetData(){ global $backlink; $files = "./money|./cards|./sold|./got|./boost|./specs|./cardmoney"; $some = explode('|', $files); reset($some); $file = array(); foreach ($some AS $value) { $file[] = $value; } for ($i=0; $i<count($file); $i++) { echo "Erasing File #" . ($i + 1) . ": " . $file[$i] . "<br>"; switch($file[$i]) { case './money': $value = '32000'; break; case './cards': $value = ''; break; case './sold': $value = '0'; break; case './got': $value = '0'; break; case './boost': $value = '0'; break; case './specs': $value = '0'; break; case './cardmoney': $value = '0'; break; default: $value = ''; break; } if (file_exists($file[$i])) { unlink($file[$i]); } $handle = fopen($file[$i], 'x'); fwrite($handle, $value); fclose($handle); } echo "Data has been erased!<br><br>{$backlink}";}function GetCards($set){ global $backlink, $globset; $iscomplete = CompleteSet($set); $variable = "<table class=\"tblbdr\" border=1 cellpadding=3 width=100%><tr><td class='newbg' colspan=4 align='center' valign='middle'>Printing Set # " . $set . " (owned cards) [" . $iscomplete['gots'] . " / " . $iscomplete['tots'] . "] " . $iscomplete['percentage'] . "%</td></tr><tr><td align='center' valign='middle' class='newbg'>Number</td><td align='center' valign='middle' class='newbg'>Name</td><td align='center' valign='middle' class='newbg'>Rarity</td><td align='center' valign='middle' class='newbg'>Number Owned</td></tr>"; $handle = file_get_contents('./cards'); $array = explode(chr(10), $handle); reset($array); $gotcards = array(); foreach ($array AS $value) { list($card_set, $card_number, $r) = explode(':', $value); if ($card_set == $set) { $gotcards[] = $card_number; } } //draw list $handle2 = file_get_contents('./sets'); $array2 = explode(chr(10), $handle2); reset($array2); foreach ($array2 AS $value) { list($card_set, $card_number, $card_name, $card_rarity, $card_value) = explode(':', $value); if ($card_set == $set) { $havegot = array_keys($gotcards, $card_number); $card_qty = count($havegot); $newbg = ""; if ($card_qty) { $newbg = "class='newbg'"; } $variable .= "<tr><td align='center' valign='middle' " . $newbg . ">" . $card_number . " / " . $globset[$set] . "</td><td align='center' valign='middle' " . $newbg . ">" . $card_name . "</td><td align='center' valign='middle' " . $newbg . ">" . $card_rarity . "</td><td align='center' valign='middle' " . $newbg . ">" . $card_qty . "</td></tr>"; } } $variable .= "</table>" . $backlink . ""; return $variable;}function AddCards($set, $card){ $var = $set . ":" . $card . ":" . chr(10); $handle = fopen('./cards', 'a'); fwrite($handle, $var); fclose($handle); CountAdd(2);}function DoHolo(){ $rand = rand(1,2); if ($rand == '1') //holo! { $holo = true; } if ($rand == '2') //rare.. { $holo = false; } return $holo;}function SpecialCard(){ $rand = rand(1,300); // 1 in 300 chance of getting a holo in pack, despite already having a holo or rare $rand2 = rand(1, 300); if ($rand == $rand2) { $holo = true; CountAdd(4); } else { $holo = false; } return $holo;}function BuyBooster($set, $cost){ global $backlink; $funds = FetchMoney(); if ($funds < $cost) { die("You do not have enough money to purchase this. Please try selling some duplicate unwanted cards in order to make some return in order to buy more cards.<br><br>" . $backlink); } if ($funds >= $cost) //proceed { $new = ($funds - $cost); SetMoney('s', $cost); echo "-" . $cost . "\$<br>(" . $new . "\$)<br><br>"; } $cards = array(); $handle2 = file_get_contents('./cards'); $array2 = explode(chr(10), $handle2); reset($array2); $gotcards = array(); foreach ($array2 AS $value) { list($card_set, $card_number, $r) = explode(':', $value); if ($card_set == $set) { $gotcards[] = $card_number; } } $loosepacket = CallSetGatherer($set); $packet = explode('¬', $loosepacket); foreach ($packet AS $value) { $cards[] = $value; } $handle = file_get_contents('./sets'); $array = explode(chr(10), $handle); reset($array); $inset = array(); foreach ($array AS $value) { list($c_set, $c_num, $c_name, $c_rarity, $c_value) = explode(':', $value); if ($c_set == $set) { $inset[] = $c_num . "¬" . $c_name . "¬" . $c_rarity . "¬" . $c_value . "¬"; } } $tempgotarray = array(); //array to prevent multi adding duplicate cards $tempvalue = 0; for ($i=0; $i<(count($cards)-1); $i++) { $cnum = ($cards[$i]-1); list($c_num, $c_name, $c_rarity, $c_value) = explode("¬", $inset[$cnum]); echo "[[inFunction_BuyBooster(): <b>\$inset[{$cnum}]=</b>{$inset[$cnum]} <b>\$c_num=</b>{$c_num} <b>\$c_name=</b>{$c_name} <b>\$c_rarity=</b>{$c_rarity} <b>\$c_value=</b>{$c_value}]]"; $prevar = $c_num . "¬" . $c_name . "¬" . $c_rarity . "¬" . $c_value; $havegot = array_keys($gotcards, $c_num); $card_qty = count($havegot); if ($card_qty) { SellCard($c_value); $tempvalue = $tempvalue + $c_value; $tag1 = ""; $tag2 = ""; } if (!$card_qty) { $hgot = array_keys($tempgotarray, $c_num); $cqty = count($hgot); if ($cqty) //found a duplicate card already in this packet; sell it { SellCard($c_value); $tempvalue = $tempvalue + $c_value; $tag1 = ""; $tag2 = ""; } if (!$cqty) { AddCards($set, $cards[$i]); $tag1 = "<strong>"; $tag2 = "</strong>"; } } $tempgotarray[] = $c_num; echo "(" . ($i + 1) . ") Obtained: " . $tag1 . $c_name . $tag2 . " [" . $tag1 . $c_rarity . $tag2 . "], " . $tag1 . "card #" . $c_num . $tag2 . "<br>"; } $newsum = FetchMoney(); echo "<br>+{$tempvalue}\$<br>({$newsum}\$)<br><br>" . $backlink; CountAdd(3);}?>