$to_buy) { if ($to_buy > 0) { $result = $db->query('SELECT item_name, item_quantity, item_cost FROM '.$db->prefix.'items WHERE item_id = '.$item_id) or error('Unable to fetch item information', __FILE__, __LINE__, $db->error()); if ($db->num_rows($result) > 0) { $item_info = $db->fetch_assoc($result); if ($to_buy > $item_info['item_quantity']) message('You can not buy '.$to_buy.' '.pun_htmlspecialchars($item_info['item_name']).'(s): there is/are only '.$item_info['item_quantity'].' left!'); if (($to_buy * $item_info['item_cost']) > $pun_user['cm_cash']) message('You don\'t have enough '.pun_htmlspecialchars($pun_config['cm_cur_name']).' to buy '.$to_buy.' '.pun_htmlspecialchars($item_info['item_name']).'.'); $sql[] = '('.$item_id.', '.$pun_user['id'].', '.$to_buy.')'; $deduct_cash += $to_buy * $item_info['item_cost']; } else { message($lang_common['Bad request']); } } } // If we're here, all of the items are valid to buy foreach ($items as $item_id => $to_buy) { $db->query('UPDATE '.$db->prefix.'items set item_quantity = item_quantity - '.$to_buy.' WHERE item_id = '.$item_id) or error('Unable to deduct item from store', __FILE__, __LINE__, $db->error()); } $db->query('UPDATE '.$db->prefix.'users SET cm_cash = cm_cash - '.$deduct_cash.' WHERE id = '.$pun_user['id']) or error('Unable to deduct cash', __FILE__, __LINE__, $db->error()); $db->query('INSERT INTO '.$db->prefix.'inventory (item_id, user_id, quantity) VALUES '.implode(',', $sql).' ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)') or error('Unable to add items to inventory', __FILE__, __LINE__, $db->error()); redirect($_SERVER['REQUEST_URI'], 'Items purchased. Redirecting …'); } $page_title = pun_htmlspecialchars($pun_config['o_board_title'].' - Shop'); define('PUN_ALLOW_INDEX', 1); require PUN_ROOT.'header.php'; ?>
If you are looking to buy user account changes, then please go to the Shop which will sell these to you. This section is for Chibis, Edible Items, and Misc Items.