<commit_before><?php
session_start();
require_once('../lib.php');

if (!Player::isLoggedIn() || !Player::getSessionPlayer()->isSuper()) {
  redirect("index.php");
}

$set = $_POST['cardsetname'];
$settype = $_POST['settype'];
$releasedate = $_POST['releasedate'];
$file = fopen($_FILES['cardsetfile']['tmp_name'], "r");

if ($file == FALSE) {
  die("Can't open the file you uploaded: {$_FILES['cardsetfile']['tmp_name']}");
}

//$set = "Put cardset name here";
//$file = fopen("Put spoiler text file name here.txt", "r");
$card = array();
$rarity = "Common";
$cardsinserted = 0;

$database = Database::getConnection();

// Insert the card set
$stmt = $database->prepare("INSERT INTO cardsets(released, name, type) values(?, ?, ?)");
$stmt->bind_param("sss", $releasedate, $set, $name); 

if (!$stmt->execute()) {
  echo "!!!!!!!!!! Set Insertion Error !!!!!!!!!<br /><br /><br />";
  die($stmt->error);
} else {
  echo "Inserted new set {$set}!<br /><br />";
}
$stmt->close();

$stmt = $database->prepare("INSERT INTO cards(cost, convertedcost, name, cardset, type,
  isw, isu, isb, isr, isg, isp, rarity) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");

while(!feof($file))
{
  $line = fgets($file);
  echo "Grabbing Line: {$line}<br />";
  if(preg_match("/^([^:]*):\s+(.*)$/", $line, $matches))
  {
    echo "Card Attribute : {$matches[1]}<br />";
    echo "Attribute Value: {$matches[2]}<br />";
    $card[$matches[1]] = $matches[2];
    if($matches[1] == "Set/Rarity")
    {
      preg_match("/$set (Land|Common|Uncommon|Rare|Mythic Rare)/", $card[$matches[1]], $submatches);
      $card[$matches[1]] = $submatches[1];
      $cardsinserted++;
      if ($card['Set/Rarity'] == 'Common') {
        insertCard($card, $set, $submatches[1], $stmt);
      }
    }
  }
  else
  {
      echo "Line is not usable content so will be ignored<br />";
  }
}

echo "End of File Reached<br />";
echo "Total Cards Inserted: {$cardsinserted}<br />";
$stmt->close();

function insertCard($card, $set, $rarity, $stmt) {
  $cmc = getConvertedCost($card['Cost']);
  # new gatherer - card type is now a . because of unicode
  $card['Type'] = str_replace('.', '-', $card['Type']);

  if (is_null($card['Cost'])) {$card['Cost'] = 0;}

  echo "Card Name:           {$card['Name']}<br />";
  echo "Card Mana Cost:      {$card['Cost']}<br />";
  echo "Converted Mana Cost: {$cmc}<br />";
  echo "Card Type:           {$card['Type']}<br />";
  echo "Card Rarity:         {$rarity}<br />";

  $isw = $isu = $isb = $isr = $isg = $isp = 0;
  if(preg_match("/W/", $card['Cost'])) {$isw = 1;echo "Card is:             White<br />";}
  if(preg_match("/U/", $card['Cost'])) {$isu = 1;echo "Card is:             Blue<br />";}
  if(preg_match("/B/", $card['Cost'])) {$isb = 1;echo "Card is:             Black<br />";}
  if(preg_match("/R/", $card['Cost'])) {$isr = 1;echo "Card is:             Red<br />";}
  if(preg_match("/G/", $card['Cost'])) {$isg = 1;echo "Card is:             Green<br />";}
  if(preg_match("/P/", $card['Cost'])) {$isp = 1;echo "Card is:             Phyrexian<br />";}

  echo "Card Set:            {$set}<br /><br />";

  $stmt->bind_param("sdsssdddddds", $card['Cost'], $cmc, $card['Name'], $set, $card['Type'], $isw, $isu, $isb, $isr, $isg, $isp, $rarity);

  if (!$stmt->execute()) {
    echo "!!!!!!!!!! Card Insertion Error !!!!!!!!!<br /><br /><br />";
    die($stmt->error);
  } else {
    echo "Card Inserted Successfully!<br /><br />";
  }
}
<commit_msg>Fix bugs with insert cardset, and make output look better.<commit_after><?php
session_start();
require_once('../lib.php');

if (!Player::isLoggedIn() || !Player::getSessionPlayer()->isSuper()) {
  redirect("index.php");
}

$set = $_POST['cardsetname'];
$settype = $_POST['settype'];
$releasedate = $_POST['releasedate'];
$file = fopen($_FILES['cardsetfile']['tmp_name'], "r");

if ($file == FALSE) {
  die("Can't open the file you uploaded: {$_FILES['cardsetfile']['tmp_name']}");
}

//$set = "Put cardset name here";
//$file = fopen("Put spoiler text file name here.txt", "r");
$card = array();
$rarity = "Common";
$cardsinserted = 0;

$database = Database::getConnection();

// Insert the card set
$stmt = $database->prepare("INSERT INTO cardsets(released, name, type) values(?, ?, ?)");
$stmt->bind_param("sss", $releasedate, $set, $settype);

if (!$stmt->execute()) {
  echo "!!!!!!!!!! Set Insertion Error !!!!!!!!!<br /><br /><br />";
  die($stmt->error);
} else {
  echo "Inserted new set {$set}!<br /><br />";
}
$stmt->close();

$stmt = $database->prepare("INSERT INTO cards(cost, convertedcost, name, cardset, type,
  isw, isu, isb, isr, isg, isp, rarity) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");

while(!feof($file))
{
  $line = fgets($file);
  ## echo "Grabbing Line: {$line}<br />";
  if(preg_match("/^([^:]*):\s+(.*)$/", $line, $matches))
  {
    ## echo "Card Attribute : {$matches[1]}<br />";
    ## echo "Attribute Value: {$matches[2]}<br />";
    $card[$matches[1]] = $matches[2];
    if($matches[1] == "Set/Rarity")
    {
      preg_match("/$set (Land|Common|Uncommon|Rare|Mythic Rare)/", $card[$matches[1]], $submatches);
      $card[$matches[1]] = $submatches[1];
      $cardsinserted++;
      if ($card['Set/Rarity'] == 'Common') {
        insertCard($card, $set, $submatches[1], $stmt);
      }
    }
  }
  else
  {
      ## echo "Line is not usable content so will be ignored<br />";
  }
}

echo "End of File Reached<br />";
echo "Total Cards Inserted: {$cardsinserted}<br />";
$stmt->close();

function insertCard($card, $set, $rarity, $stmt) {
  $card['CMC'] = getConvertedCost($card['Cost']);
  $card['Rarity'] = $rarity;
  $card['Cardset'] = $set;
  # new gatherer - card type is now a . because of unicode
  $card['Type'] = str_replace('.', '-', $card['Type']);

  if (is_null($card['Cost'])) {$card['Cost'] = 0;}

  echo "<table class=\"new_card\">";
  foreach (array('Name', 'Cost', 'CMC', 'Type', 'Rarity', 'Cardset') as $attr) {
    echo "<tr><th>{$attr}:</th><td>{$card[$attr]}</td></tr>";
  }
  echo "<tr><th>Card Colors:</th><td>";
  $isw = $isu = $isb = $isr = $isg = $isp = 0;
  if(preg_match("/W/", $card['Cost'])) {$isw = 1;echo "White ";}
  if(preg_match("/U/", $card['Cost'])) {$isu = 1;echo "Blue ";}
  if(preg_match("/B/", $card['Cost'])) {$isb = 1;echo "Black ";}
  if(preg_match("/R/", $card['Cost'])) {$isr = 1;echo "Red ";}
  if(preg_match("/G/", $card['Cost'])) {$isg = 1;echo "Green ";}
  if(preg_match("/P/", $card['Cost'])) {$isp = 1;echo "Phyrexian ";}
  echo "</td></tr>";

  $stmt->bind_param("sdsssdddddds", $card['Cost'], $card['CMC'], $card['Name'], $set, $card['Type'], $isw, $isu, $isb, $isr, $isg, $isp, $rarity);

  if (!$stmt->execute()) {
    echo "<tr><td colspan=\"2\" style=\"background-color: LightRed;\">!!!!!!!!!! Card Insertion Error !!!!!!!!!</td></tr>";
    echo "</table>";
    die($stmt->error);
  } else {
    echo "<tr><th colspan=\"2\" style=\"background-color: LightGreen;\">Card Inserted Successfully</th></tr>";
    echo "</table>";
  }
}

{'fraction_non_alphanumeric': 0.2691591462541183, 'fraction_numerical': 0.00544334622546913, 'mean_word_length': 4.005017921146953, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6054575', 'n_tokens_mistral': 2671, 'n_tokens_neox': 2581, 'n_words': 569}