<commit_before><?php
include_once 'book_info.php';

function generate_confirmation_table($title, $user, $books, $confirmation = null) {
  $card_types = [
      'MasterCard',
      'VISA'
  ];

  /* TODO: receive $user from arguments */
  $user = [
      'username' => 'coolguy49',
      'first_name' => 'Luke',
      'last_name' => 'Skywalker',
      'address' => '48 Williams St.',
      'city' => 'Tatooine',
      'state' => 'MI',
      'zip' => '48197',
      'card_type' => 'VISA',
      'card_number' => '1111222233334444',
      'card_expiration' => '04/16'
  ];

  /* TODO: generate rows from db */
  $book = [
      'id' => 1,
      'title' => 'Absolute Java',
      'author' => '<NAME>',
      'price' => '149.99',
      'quantity' => '2',
      'publisher' => 'Addison-Wesley',
      'isbn' => '978-0132834230'
  ];

  $books = [
      $book
  ];

  /* generate the info above the table */
  $to_return = '<div id="user-checkout-info" class="box"><h2>' . $title . '</h2>
          <div id="address-info" class="user-info-box box">
            <h3>Shipping Address</h3>' . $user['first_name'] . ' ' . $user['last_name'] . '<br>' . $user['address'] . '<br>' . $user['city'] .
       '<br>' . $user['state'] . ' ' . $user['zip'] . '</div>
          <div id="card-info" class="user-info-box box">
            <h3>Credit Card</h3>';

  if ($confirmation) {
    $to_return .= $user['card_type'] . ': ' . $user['card_number'] . '</div>';
  } else {
    $to_return .= '<input type="radio" name="card-selection" value="current-card">
                <div id="current-card" class="user-info-box">
                  Use card on file<br>' . $user['card_type'] . ': ' . $user['card_number']
                .'</div>
                <br>
                <input type="radio" name="card-selection" value="new-card">
                <div id="new-card" class="user-info-box">
                  <input type="text" placeholder="Card number">
                  <select name="card-type">';

    foreach($card_types as $card_type) {
      $value = strtolower($card_type);
      $to_return .= '<option value="' . $value . '">' . $card_type . '</option>';
    }

    $to_return .= '</select>
            </div>
          </div>';
  }

  if ($confirmation) {
    $to_return .= '<div id="address-info" class="user-info-box box">
          <h3>Confirmation Info</h3>
          <label class="short">Username</label>' . $confirmation['username'] . '<br>
          <label class="short">Date</label>' . $confirmation['date'] . '<br>
          <label class="short">Time</label>' . $confirmation['time'] . '<br>
        </div>';
  }

  $to_return .= '</div>';

  /* generate the table */
  $to_return .= '<table id="books-in-cart" class="wide">
              <tr>
                <th>Book Description</th>
                <th class="thin-cell">Qty</th>
                <th class="thin-cell">Price</th>
              </tr>';

  foreach($books as $book) {
    $to_return .= '<tr>
                  <td class="book-info">' . generateBookInfo($book) . '</td>
                  <td class="book-info"><input type="number" name="quantity" class="quantity-box centered-input" value="' . $book['quantity'] . '"></td>
                  <td class="book-info">$' . $book['quantity'] * $book['price'] . '</td>
                </tr>';
  }

  $to_return .= '</table>';

  return $to_return;
}

?><commit_msg>Add total/subtotal to checkout screens<commit_after><?php
include_once 'book_info.php';

function generate_confirmation_table($title, $user, $books, $confirmation = null) {
  $card_types = [
      'MasterCard',
      'VISA'
  ];

  /* TODO: receive $user from arguments */
  $user = [
      'username' => 'coolguy49',
      'first_name' => 'Luke',
      'last_name' => 'Skywalker',
      'address' => '48 Williams St.',
      'city' => 'Tatooine',
      'state' => 'MI',
      'zip' => '48197',
      'card_type' => 'VISA',
      'card_number' => '1111222233334444',
      'card_expiration' => '04/16'
  ];

  /* TODO: generate rows from db */
  $dummy_book = [
      'id' => 1,
      'title' => 'Absolute Java',
      'author' => '<NAME>',
      'price' => '149.99',
      'quantity' => '2',
      'publisher' => 'Addison-Wesley',
      'isbn' => '978-0132834230'
  ];

  $books = [
      $dummy_book, $dummy_book
  ];
  
  $subtotal = 0;
  $shipping = 4;

  /* generate the info above the table */
  $to_return = '<div id="user-checkout-info" class="box"><h2>' . $title . '</h2>
          <div id="address-info" class="user-info-box box">
            <h3>Shipping Address</h3>' . $user['first_name'] . ' ' . $user['last_name'] . '<br>' . $user['address'] . '<br>' . $user['city'] .
       '<br>' . $user['state'] . ' ' . $user['zip'] . '</div>
          <div id="card-info" class="user-info-box box">
            <h3>Credit Card</h3>';

  if ($confirmation) {
    $to_return .= $user['card_type'] . ': ' . $user['card_number'] . '</div>';
  } else {
    $to_return .= '<input type="radio" name="card-selection" value="current-card">
                <div id="current-card" class="user-info-box">
                  Use card on file<br>' . $user['card_type'] . ': ' . $user['card_number']
                .'</div>
                <br>
                <input type="radio" name="card-selection" value="new-card">
                <div id="new-card" class="user-info-box">
                  <input type="text" placeholder="Card number">
                  <select name="card-type">';

    foreach($card_types as $card_type) {
      $value = strtolower($card_type);
      $to_return .= '<option value="' . $value . '">' . $card_type . '</option>';
    }

    $to_return .= '</select>
            </div>
          </div>';
  }

  if ($confirmation) {
    $to_return .= '<div id="address-info" class="user-info-box box">
          <h3>Confirmation Info</h3>
          <label class="short">Username</label>' . $confirmation['username'] . '<br>
          <label class="short">Date</label>' . $confirmation['date'] . '<br>
          <label class="short">Time</label>' . $confirmation['time'] . '<br>
        </div>';
  }

  $to_return .= '</div>';

  /* generate the table */
  $to_return .= '<table id="books-in-cart" class="wide">
              <tr>
                <th>Book Description</th>
                <th class="thin-cell">Qty</th>
                <th class="thin-cell">Price</th>
              </tr>';

  foreach($books as $book) {
    $cost = $book['quantity'] * $book['price'];
    $subtotal += $cost;
    $to_return .= '<tr>
                  <td class="book-info">' . generateBookInfo($book) . '</td>
                  <td class="book-info"><input type="number" name="quantity" class="quantity-box centered-input" value="' . $book['quantity'] . '"></td>
                  <td class="book-info">$' . $cost . '</td>
                </tr>';
  }

  $to_return .= '</table>';
  $to_return .= '<div class="box">
                  <table id="total" class="right-aligned">
                    <tr>
                      <td class="book-info">Subtotal</td>
                      <td class="right-aligned book-info">' . 
                        sprintf("$%.2f", $subtotal) . 
                      '</td>
                    </tr>
                    <tr>
                      <td class="book-info">Subtotal</td>
                      <td class="right-aligned book-info">' . 
                        sprintf("$%.2f", $shipping) . 
                      '</td>
                    </tr>
                    <tr>
                      <td class="book-info">Total</td>
                      <td class="right-aligned book-info">' . 
                        sprintf("$%.2f", $subtotal + $shipping) . 
                      '</td>
                    </tr>
                  </table>
                </div>';

  return $to_return;
}

?>
{'fraction_non_alphanumeric': 0.20749390478634672, 'fraction_numerical': 0.015270114205055819, 'mean_word_length': 1.9017125837676843, 'pattern_counts': {'":': 0, '<': 151, '<?xml version=': 0, '>': 185, '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': '2113783', 'n_tokens_mistral': 2650, 'n_tokens_neox': 2487, 'n_words': 482}