<commit_before><?php 
class User {
	public static $info, $on_hold;
	
	function setInfo($info) {
		User::$info = $info;
	}
	
	function getInfo($session_id=false) {
		global $CFG;
		
		$session_id = preg_replace("/[^0-9]/", "",$session_id);
		
		if (!($session_id > 0) || !$CFG->session_active)
			return false;
	
		$result = db_query_array('SELECT site_users.first_name,site_users.last_name,site_users.pass,site_users.country,site_users.email, site_users.default_currency FROM sessions LEFT JOIN site_users ON (sessions.user_id = site_users.id) WHERE sessions.session_id = '.$session_id);
		return $result[0];
	}
	
	function logOut($session_id=false) {
		if (!($session_id > 0))
			return false;
		
		$session_id = preg_replace("/[^0-9]/", "",$session_id);
		
		return db_delete('sessions',$session_id,'session_id');
	}
	
	function getOnHold($for_update=false,$user_id=false) {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
		
		$user_info = ($user_id > 0) ? DB::getRecord('site_users',$user_id,0,1,false,false,false,$for_update) : User::$info;
		$user_fee = FeeSchedule::getRecord($user_info['fee_schedule']);
		$lock = ($for_update) ? 'FOR UPDATE' : '';
	
		$sql = " SELECT currencies.currency AS currency, requests.amount AS amount FROM requests LEFT JOIN currencies ON (currencies.id = requests.currency) WHERE requests.site_user = ".$user_info['id']." AND requests.request_type = {$CFG->request_widthdrawal_id} AND (requests.request_status = {$CFG->request_pending_id} OR requests.request_status = {$CFG->request_awaiting_id}) ".$lock;
		$result = db_query_array($sql);
		if ($result) {
			foreach ($result as $row) {
				$on_hold[$row['currency']]['withdrawal'] += floatval($row['amount']);
				$on_hold[$row['currency']]['total'] += floatval($row['amount']);
			}
		}
	
		$sql = " SELECT currencies.currency AS currency, orders.fiat AS amount, orders.btc AS btc_amount, orders.order_type AS type FROM orders LEFT JOIN currencies ON (currencies.id = orders.currency) WHERE orders.site_user = ".$user_info['id']." ".$lock;
		$result = db_query_array($sql);
		if ($result) {
			foreach ($result as $row) {
				if ($row['type'] == $CFG->order_type_bid) {
					$on_hold[$row['currency']]['order'] += floatval($row['amount']) + (floatval($row['amount']) * ($user_fee['fee'] * 0.01));
					$on_hold[$row['currency']]['total'] += floatval($row['amount']) + (floatval($row['amount']) * ($user_fee['fee'] * 0.01));
				}
				else {
					$on_hold['BTC']['order'] += floatval($row['btc_amount']);
					$on_hold['BTC']['total'] += floatval($row['btc_amount']);
				}
			}
		}
		self::$on_hold = $on_hold;
		return $on_hold;
	}
	
	function getAvailable() {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
	
		self::$on_hold = (is_array(self::$on_hold)) ? self::$on_hold : self::getOnHold();
		if ($CFG->currencies) {
			$available['BTC'] = User::$info['btc'] - self::$on_hold['BTC']['total'];
			$available['BTC'] = ($available['BTC'] < 0.00000001) ? 0 : $available['BTC'];
			foreach ($CFG->currencies as $currency) {
				if (User::$info[strtolower($currency['currency'])] - self::$on_hold[$currency['currency']]['total'] == 0)
					continue;
	
				$available[$currency['currency']] = User::$info[strtolower($currency['currency'])] - self::$on_hold[$currency['currency']]['total'];
			}
		}
		return $available;
	}
	
	function hasCurrencies() {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
		
		$found = false;
		if (!(User::$info['btc'] > 0)) {
			foreach ($CFG->currencies as $currency => $info) {
				if (User::$info[strtolower($currency)] > 0) {
					$found = true;
					break;
				}
			}
		}
		else
			$found = true;
		
		return $found;
	}
	
	function getVolume() {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
	
		$sql = "SELECT SUM(transactions.btc * transactions.btc_price * currencies.usd_ask) AS volume FROM transactions
				LEFT JOIN currencies ON (currencies.id = transactions.currency)
				WHERE (site_user = ".User::$info['id']." OR site_user1 = ".User::$info['id'].")
				AND transactions.date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
				LIMIT 0,1";
		$result = db_query_array($sql);
			return $result[0]['volume'];
	}
	
	function getNewId() {
		$sql = 'SELECT FLOOR(10000000 + RAND() * 89999999) AS random_num
				FROM site_users
				WHERE "random_num" NOT IN (SELECT user FROM site_users)
				LIMIT 1 ';
		$result = db_query_array($sql);
		return $result[0]['random_num'];<commit_msg>Fixed generation of new user ID when no users.<commit_after><?php 
class User {
	public static $info, $on_hold;
	
	function setInfo($info) {
		User::$info = $info;
	}
	
	function getInfo($session_id=false) {
		global $CFG;
		
		$session_id = preg_replace("/[^0-9]/", "",$session_id);
		
		if (!($session_id > 0) || !$CFG->session_active)
			return false;
	
		$result = db_query_array('SELECT site_users.first_name,site_users.last_name,site_users.pass,site_users.country,site_users.email, site_users.default_currency FROM sessions LEFT JOIN site_users ON (sessions.user_id = site_users.id) WHERE sessions.session_id = '.$session_id);
		return $result[0];
	}
	
	function logOut($session_id=false) {
		if (!($session_id > 0))
			return false;
		
		$session_id = preg_replace("/[^0-9]/", "",$session_id);
		
		return db_delete('sessions',$session_id,'session_id');
	}
	
	function getOnHold($for_update=false,$user_id=false) {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
		
		$user_info = ($user_id > 0) ? DB::getRecord('site_users',$user_id,0,1,false,false,false,$for_update) : User::$info;
		$user_fee = FeeSchedule::getRecord($user_info['fee_schedule']);
		$lock = ($for_update) ? 'FOR UPDATE' : '';
	
		$sql = " SELECT currencies.currency AS currency, requests.amount AS amount FROM requests LEFT JOIN currencies ON (currencies.id = requests.currency) WHERE requests.site_user = ".$user_info['id']." AND requests.request_type = {$CFG->request_widthdrawal_id} AND (requests.request_status = {$CFG->request_pending_id} OR requests.request_status = {$CFG->request_awaiting_id}) ".$lock;
		$result = db_query_array($sql);
		if ($result) {
			foreach ($result as $row) {
				$on_hold[$row['currency']]['withdrawal'] += floatval($row['amount']);
				$on_hold[$row['currency']]['total'] += floatval($row['amount']);
			}
		}
	
		$sql = " SELECT currencies.currency AS currency, orders.fiat AS amount, orders.btc AS btc_amount, orders.order_type AS type FROM orders LEFT JOIN currencies ON (currencies.id = orders.currency) WHERE orders.site_user = ".$user_info['id']." ".$lock;
		$result = db_query_array($sql);
		if ($result) {
			foreach ($result as $row) {
				if ($row['type'] == $CFG->order_type_bid) {
					$on_hold[$row['currency']]['order'] += floatval($row['amount']) + (floatval($row['amount']) * ($user_fee['fee'] * 0.01));
					$on_hold[$row['currency']]['total'] += floatval($row['amount']) + (floatval($row['amount']) * ($user_fee['fee'] * 0.01));
				}
				else {
					$on_hold['BTC']['order'] += floatval($row['btc_amount']);
					$on_hold['BTC']['total'] += floatval($row['btc_amount']);
				}
			}
		}
		self::$on_hold = $on_hold;
		return $on_hold;
	}
	
	function getAvailable() {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
	
		self::$on_hold = (is_array(self::$on_hold)) ? self::$on_hold : self::getOnHold();
		if ($CFG->currencies) {
			$available['BTC'] = User::$info['btc'] - self::$on_hold['BTC']['total'];
			$available['BTC'] = ($available['BTC'] < 0.00000001) ? 0 : $available['BTC'];
			foreach ($CFG->currencies as $currency) {
				if (User::$info[strtolower($currency['currency'])] - self::$on_hold[$currency['currency']]['total'] == 0)
					continue;
	
				$available[$currency['currency']] = User::$info[strtolower($currency['currency'])] - self::$on_hold[$currency['currency']]['total'];
			}
		}
		return $available;
	}
	
	function hasCurrencies() {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
		
		$found = false;
		if (!(User::$info['btc'] > 0)) {
			foreach ($CFG->currencies as $currency => $info) {
				if (User::$info[strtolower($currency)] > 0) {
					$found = true;
					break;
				}
			}
		}
		else
			$found = true;
		
		return $found;
	}
	
	function getVolume() {
		global $CFG;
		
		if (!$CFG->session_active)
			return false;
	
		$sql = "SELECT SUM(transactions.btc * transactions.btc_price * currencies.usd_ask) AS volume FROM transactions
				LEFT JOIN currencies ON (currencies.id = transactions.currency)
				WHERE (site_user = ".User::$info['id']." OR site_user1 = ".User::$info['id'].")
				AND transactions.date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
				LIMIT 0,1";
		$result = db_query_array($sql);
			return $result[0]['volume'];
	}
	
	function getNewId() {
		$sql = 'SELECT FLOOR(10000000 + RAND() * 89999999) AS random_num
				FROM site_users
				WHERE "random_num" NOT IN (SELECT user FROM site_users)
				LIMIT 1 ';
		$result = db_query_array($sql);
		
		if (!$result) {
			$sql = 'SELECT FLOOR(10000000 + RAND() * 89999999) AS random_num ';
			$result = db_query_array($sql);
		}
		
		return $result[0]['random_num'];
{'fraction_non_alphanumeric': 0.18942973299637403, 'fraction_numerical': 0.013185364245687286, 'mean_word_length': 4.523058252427185, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '5643401', 'n_tokens_mistral': 3676, 'n_tokens_neox': 3126, 'n_words': 618}