if (isset($_POST['newlisting'])) {
    $name = $_POST['listingName'];
    $desc = $_POST['listingDescription'];
    $reserve_price = $_POST['reservePrice'];
    $starting_price = $_POST['startingPrice'];
    $category_id = $_POST['category'];
    $end_date = strtotime($_POST['endDate']);
    $image = NULL;
    $imageProperties = NULL;
    if (count($_FILES) > 0) {
        if (is_uploaded_file($_FILES['userImage']['tmp_name'])) {
            $image = addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
            $imageProperties = getimagesize($_FILES['userImage']['tmp_name'])['mime'];
        }
    }
    $item_id = new_item($name, $desc, $image, $imageProperties);
    new_item_category($category_id, $item_id);
    new_auction($item_id, $starting_price, $reserve_price, $end_date, $_SESSION["id"]);
    header("Location: index.php");
    die;
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>EBid: New Listing</title>

    <!-- Bootstrap -->
         // lookup children
         if ($res->num_rows > 0) {
             // cycle through all the children
             $cnt = 1;
             $itemitem = array('master_item_id' => $newid);
             $sort = 10;
             while ($row = $res->fetch_assoc()) {
                 $itemitem['sort_index'] = $sort;
                 $itemitem['qty_required'] = $row['qty_required'];
                 $row['old_id'] = $coldid = $row['id'];
                 // set tracking column
                 $coldsku = $row['sku'];
                 unset($row['id'], $row['qty_required'], $row['sort_index']);
                 $row['sku'] = 'US-' . $item['item_sequence'] . '-' . (strlen($cnt) > 1 ? '' : '0') . $cnt;
                 $row['item_sequence'] = $item['item_sequence'];
                 if ($cnewid = new_item($row, $coldid, $coldsku)) {
                     // handles the insert of a new child product
                     $itemitem['child_item_id'] = $cnewid;
                     // create the parent child association record
                     if (!insert_item_item($itemitem)) {
                         fwrite($log, "FAILED to insert items_items {$cnewid} - {$coldid} :: " . $dbh->error . "\n");
                     }
                 }
                 $cnt++;
                 $sort += 10;
             }
         }
     }
 } elseif ($item['item_type_id'] == '1' && $data[2]) {
     alt_item_item($item['item_sequence'], $newid);
 }