function bid($amount) { global $CFG; date_default_timezone_set($CFG->default_timezone); if (!($this->id > 0)) { return false; } if ($this->is_expired) { return false; } if (!is_numeric($amount)) { $this->errors[] = $CFG->auction_invalid_bid_error; return false; } if (User::isLoggedIn()) { if (DB::tableExists($this->table . '_bids')) { $user_id = User::$info['id']; $this->minimum_increase = !($this->high_bid > 0) ? $this->initial_bid : $this->minimum_increase; if ($amount >= $this->item_info['high_bid'] + $this->minimum_increase || $this->high_bid_user_id == User::$info['id'] && $amount > $this->item_info['high_bid']) { if ($this->proxy_bids) { $proxy = Auction::getHighestProxy(); if ($this->high_bid_user_id != User::$info['id']) { if ($amount <= $proxy['amount']) { $proxy_increase = $amount + $this->minimum_increase <= $proxy['amount'] ? $amount + $this->minimum_increase : $proxy['amount']; DB::insert($this->table . '_bids', array('item_id' => $this->id, 'item_table' => $this->table, 'user_id' => $user_id, 'amount' => $amount, 'date' => $this->now)); DB::insert($this->table . '_bids', array('item_id' => $this->id, 'item_table' => $this->table, 'user_id' => $this->high_bid_user_id, 'amount' => $proxy_increase, 'is_proxy' => 'Y', 'date' => $this->now)); DB::update($this->table, array('high_bid' => $proxy_increase), $this->id); //Auction::realizeBids($proxy_increase); $this->high_bid = $proxy_increase; $outbid = true; } elseif ($amount > $proxy['amount'] && $amount < $proxy['amount'] + $this->minimum_increase && $proxy['user_id'] != $user_id) { $this->errors[] = str_ireplace('[field]', $this->minimum_increase, $CFG->auction_min_increase_error); DB::insert($this->table . '_bids', array('item_id' => $this->id, 'item_table' => $this->table, 'user_id' => $user_id, 'amount' => $amount, 'date' => $this->now)); DB::insert($this->table . '_bids', array('item_id' => $this->id, 'item_table' => $this->table, 'user_id' => $this->high_bid_user_id, 'amount' => $proxy['amount'], 'is_proxy' => 'Y', 'date' => $this->now)); DB::update($this->table, array('high_bid' => $proxy['amount']), $this->id); //Auction::realizeBids($proxy['amount']); $this->high_bid = $proxy['amount']; $outbid = true; } else { if ($proxy['amount'] > $this->high_bid) { if ($proxy['amount'] > $this->high_bid + $this->minimum_increase) { $this->high_bid = $proxy['amount']; } } if ($amount > $proxy['amount'] + $this->minimum_increase) { DB::insert($this->table . '_bids', array('item_id' => $this->id, 'item_table' => $this->table, 'user_id' => $user_id, 'amount' => $amount, 'is_proxy' => 'N', 'is_realized' => 'N', 'date' => $this->now)); $this->high_bid = $proxy['amount']; } } } else { if ($amount < $proxy['amount']) { $this->errors[] = str_ireplace('[field]', $amount, $CFG->auction_outbid_self_proxy_error); $outbid = true; } else { $this->messages[] = str_ireplace('[field]', $amount, $CFG->auction_new_proxy_message); DB::insert($this->table . '_bids', array('item_id' => $this->id, 'item_table' => $this->table, 'user_id' => $user_id, 'amount' => $amount, 'is_proxy' => 'N', 'is_realized' => 'N', 'date' => $this->now)); $bypass = true; } } } if ($this->anti_sniping && $this->anti_sniping_increase) { if ($this->time_remaining < $this->anti_sniping) { if (!($this->proxy_bids && $this->high_bid_user_id == User::$info['id'])) { Auction::addTime($this->anti_sniping_increase); } } } //DB::insert($this->table.'_bids',array('item_id'=>$15this->id,'item_table'=>$this->table,'user_id'=>$user_id,'amount'=>$amount)); if (!$outbid) { $new_bid = $this->proxy_bids ? $this->high_bid + $this->minimum_increase : $amount; $new_bid = $this->proxy_bids && $this->high_bid_user_id == $user_id ? $this->high_bid : $new_bid; //$new_bid = (!($this->high_bid > 0)) ? $amount : $new_bid; $this->high_bid = $new_bid; $this->high_bid_user_id = $user_id; $is_proxy = $this->proxy_bids && $amount > $this->high_bid + $this->minimum_increase ? 'Y' : 'N'; Auction::realizeBids($new_bid); if (!$bypass) { DB::insert($this->table . '_bids', array('item_id' => $this->id, 'item_table' => $this->table, 'user_id' => $user_id, 'amount' => $new_bid, 'is_proxy' => $is_proxy, 'date' => $this->now)); } DB::update($this->table, array('high_bid' => $new_bid, 'high_bid_user_id' => $user_id), $this->id); $this->messages[] = $CFG->auction_high_bid_message; return true; } else { if (!is_array($this->errors)) { $this->errors[] = $CFG->auction_outbid_error; } return false; } } elseif ($amount >= $this->item_info['high_bid'] && $amount < $this->item_info['high_bid'] + $this->minimum_increase) { $this->errors[] = str_ireplace('[field]', $this->minimum_increase, $CFG->auction_min_increase_error); return false; } elseif ($amount < $this->item_info['high_bid'] && $this->item_info['high_bid_user_id'] != $user_id) { $this->errors[] = str_ireplace('[field]', $this->high_bid, $CFG->auction_bid_too_low_error); return false; } elseif ($amount < $this->item_info['high_bid'] && $this->item_info['high_bid_user_id'] == $user_id) { $this->errors[] = $CFG->auction_outbid_self_error; return false; } } else { $this->errors[] = $CFG->auction_table_error; } } else { $this->errors[] = $CFG->auction_login_error; } }