the problem & context

the problem: I hate having 4 windows/tabs open when on a trade binge. trade form, the cards you need (either in a notepad, excel, or written down irl), your trading pile, and the other person's trade post. I want to condense and eliminate having to jump windows all the time. I'm just lazy and don't always use my second monitor.

the solution: Combine a bunch of different functionalities already out there. Trade form already exists in your etcg, your trade pile already has a card search (AND IF IT DOESNT WHAT ARE YOU DOING WITH YOUR LIFE), and there's a mod already out there for cards needed. Just combine it into one!

caveats: I take no credit for any of these things. I'm just putting them on one page and its super easy, and also explaining to people who don't know that there's a show needed cards function

example:

Untitled

the mod

I'm just making a new page within the trade post directory (NOT etcg directory) using the same header/func.php/mods.php stuff that we already have. The output will look something like the above depending how you customize it (I ended up making mine look like it does with its own header file).

You need the pending function and show_needed mod. The original mod can be found here. I'll paste it here for ease, and because I changed it (not sure if it didn't work with new etcg or not, but I ran into issues using verbatim).

Add this to your mods.php. This is the pending function:

function pending($tcg, $card){
            $database = new Database;
            $sanitize = new Sanitize;
            $tcg = $sanitize->for_db($tcg);

            $tcginfo = $database->get_assoc("SELECT * FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
            $tcgid = $tcginfo['id'];
            $pending = $database->num_rows("SELECT * FROM `trades` WHERE `tcg`='$tcgid' AND `receiving` LIKE '%$card%'");
            return $pending;
          }

Add this to your mods.php. This is the show_needed function:

function show_needed($tcg, $category, $count = 20, $pend = 0, $low = 0) {
            $total = array();
            if (strtolower($category)==='collecting'){
              $database = new Database;
              $sanitize = new Sanitize;
              $tcg = $sanitize->for_db($tcg);
              $tcginfo = $database->get_assoc("SELECT * FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
              $tcgid = $tcginfo['id'];
              $worth = intval($count);
              $result = $database->query("SELECT * FROM `collecting` WHERE `tcg` = '$tcgid' AND `mastered` = '0' ORDER BY `sort`, `deck`");
              $cards = '';
              while ( $row = mysqli_fetch_assoc($result) ) {
                $cards .= $row['cards'].', '; $total[$row['deck']] = $row['count'];
              }
              $cards = substr($cards,0,-2);}
              else {    $cards = get_category($tcg, $category); }
              $cards = explode(', ',$cards);
              $cards = array_unique($cards); array_walk($cards, 'trim_value');
              $deck = array( );
              //Get decks
              foreach ($cards as $card) {$deck[ ] = substr($card, 0, -2);}
              $group = array_combine($cards,$deck);
              $deck = array_unique($deck);
              //Results
              foreach ($deck as $check) {
                if(isset($total[$check])){$all = $total[$check];} else{$all = $count;}
                $mine = array();
                $got = array_keys($group, $check);
                foreach ($got as $num) {$mine[ ] = substr($num, -2); }
                $def = range(1,$all);
                $default = array( );
                foreach($def as $no){if($no < 10){$default[ ] = '0'.$no;} else {$default[ ] = $no;}}
                $diff = array_diff($default,$mine);
                foreach($diff as &$might){
                  $pending = pending($tcg, $check.$might);
                  if($pending > 0){
                    if($pend === 1){$might = ''.$might.'';}
                    else{ $might = '';}
                  }
                }
                $diff = array_filter($diff, 'strlen');
                $need = count($diff);
                if($low === 0 || $need <= $low){
                  $diff = implode('/',$diff);
                  echo $check.': '.$diff.'
';
                }
              }
            }

REITERATE: I did not make this. The source can be found at the link above.

  1. Create a new .php file. I named mine dashboard.php. You can name it anything your heart desires. This is what mine looks like.
<?php if (!$_SERVER['QUERY_STRING']) { /* -----THIS IS THE MAIN PAGE -----*/?>
              <?php define('VALID_INC', TRUE); include '/home/qwpbypug/public_html/tcg/func.php';
              include('header.php'); ?> // literally just copied and pasted my original idolise.php file

              <object data="/etcg/newtrade.php" width="600" height="400"> // embed your trade form. if your directory path is different then you'll want to edit both of these
              <embed src="/etcg/newtrade.php" width="600" height="400"> </embed>
              Error: Embedded data could not be displayed.
              </object><br><br>

              //show needed for collecting and keeping categories, or whatever you call them
              Needed: <br><?php show_needed( 'idolise', 'Collecting'); ?>
              <?php show_needed( 'idolise', 'keeping'); ?><br><br>

              //card search script. this assumes you have the card search script in your header file.
              <form action onSubmit="return false;">
              <input name="search" id="search" />
              <input value="Search" type="submit" onClick="highlightImage();"/>
              <input value="Clear" type="submit" onClick="clearHighlight();"/>
              </form>
              <div id="cardlist"></div><br>

              //have your trade pile. you can show other categories too. i set this div to display none because i only care about the card search portion.
              <div style="display:none;">
              <?php show_cards('idolise','trading'); ?>
              </div>

              <?php include('footer.php'); ?>
              <?php } ?>