<?php
class debbo { // If its not possible, write: return false;
		function SSO($username) {
	$check = mysql_query("SELECT * FROM users WHERE name = '$username'");
	$info = mysql_fetch_array( $check );
	$habbo = $info['name'];
	$rand1=mt_rand(100000,999999) ;
	$rand2=mt_rand(10000,99999) ;
	$rand3=mt_rand(10000,99999) ;
	$rand4=mt_rand(10000,99999) ;
	$rand5=mt_rand(10000,99999) ;
	$rand6=mt_rand(0,9) ;
	$ssoticket="ST-".$rand1."-".$rand2.$rand3.$rand4.$rand5."-es-fe".$rand6 ;
		mysql_query("INSERT INTO sso (id,name,ticket) VALUES ('1','$username','$ssoticket')") ;
		if (''. $habbo .'' == ''. $username .'') {
			return $ssoticket;
		} else { 
return false;
	}
}
  function users($name) {
  $namecheck = mysql_query("SELECT * FROM users WHERE name = '$name'");
  if(!mysql_num_rows($namecheck)=="0"){
  $check = mysql_fetch_array($namecheck);
  return false;
  } else {
  return true;
  }
  }
   function profile($data, $user, $update, $datatwo, $sex) {
   if($data == 'update') {
   if($datatwo == 'figure') {
   $update = "UPDATE users set figure = '$update' WHERE name = '$user'";
   $update = "UPDATE users set sex = '$sex' WHERE name = '$user'";
   }
   }
   if($data == 'get') {
  $get = "SELECT * FROM `users` WHERE `name` = '$user'";
  $info = mysql_fetch_array(mysql_query($get), MYSQL_ASSOC);
  return $info;
  }
  }
   function texts() {
  $texts = "SELECT * FROM `texts` WHERE `name` = 'texts'";
  $texts = mysql_fetch_array(mysql_query($texts), MYSQL_ASSOC);
  return $texts[next];
  }
  function rank($username) {
  $sql = 'SELECT * FROM `users` WHERE `name` = \''. $username .'\' LIMIT 1';
  $rank = mysql_fetch_array(mysql_query($sql), MYSQL_ASSOC);
  return $rank[rank];
  }
	function GetUser($username, $data) {
		if ($data == 'hc') {
		$sql = 'SELECT `hcdays` FROM `users` WHERE `name` = \''. $username .'\' LIMIT 1';
			$reply = mysql_fetch_array(mysql_query($sql), MYSQL_ASSOC);
			if ($reply[hcdays] == '0') {			
			return false;
			} 
			else return $reply[hcdays];
		} elseif ($data == 'habboname') {
			$sql = 'SELECT `name` FROM `users` WHERE `name` = \''. $username .'\' LIMIT 1';
			$reply = mysql_fetch_array(mysql_query($sql), MYSQL_ASSOC);
			return $reply[habboname];
		} elseif($data == 'exist') {
			$sql = 'SELECT `name` FROM `users` WHERE `name` = \''. $username .'\' LIMIT 1';
			if (mysql_num_rows($sql) == 1) return true;
			else return false;
		} elseif($data == 'credits') {
			$sql = 'SELECT `credits` FROM `users` WHERE `name` = \''. $username .'\' LIMIT 1';
			$reply = mysql_fetch_array(mysql_query($sql), MYSQL_ASSOC);
			return $reply[credits];
		}
	}
	function Login($username, $password) {
		$sql = 'SELECT `name`, `pass` FROM `users` WHERE `name` = \''.strtolower($username).'\' LIMIT 1';
		$result = mysql_query($sql);
		if(mysql_num_rows($result) != 1) return 'No such user found!';
		$userlogin = mysql_fetch_array($result, MYSQL_ASSOC);
		if($userlogin[pass] == $password) { return $userlogin[name]; }
		else { return 'Incorrect password!'; }
	}
	function Register($username, $password, $figure, $sex, $email, $birthday) {
	$date = date("d-M-Y H:i:s");
		$register1 = 'INSERT INTO `users` (`app`, `badgeonoff`, `badges`, `birth`, `consolemission`, `credits`, `curbadge`, `email`, `favourites`, `figure`, `poolfigure`, `film`, `friendlist`, `registered`, `hand`, `hcdays`, `hcupdate`, `inquiries`, `lastonline`, `mission`, `name`, `num`, `pass`, `periods`, `rank`, `roomlist`, `rooms`, `sex`, `showexpire`, `tickets`, `commands_queue`, `transactions`, `msgcount`, `messages`, `tutorial`, `group_active`, `group_others`, `shockwaveid`) VALUES (\''. $figure .'\', \'0\', \';\', \''. $birthday .'\', \''. $name .'\', \'500\', \'\', \''. $email .'\', \';\', \'ch=s02/53,51,44\', \'.\', \'\', \'<>\', \''. $date .'\', \' ; \', \' 0 \', \''. $date .'\', \'\', \'\', \'\', \''. $username .'\', \'\', \''. $password .'\', \'0\', \'habbo\', \'\', \'0\', \''. $sex .'\', \'0\', \'0\', \'\', \'\', \'0\', \'\', \'\', \'\', \'\', \'\');';
		mysql_query($register1);
		$register2 = 'SELECT * FROM `debbo_index` LIMIT 1';
		$users = mysql_fetch_array(mysql_query($register2), MYSQL_ASSOC);
		$users = ($users[users] + 1);
		$register3 = 'UPDATE `debbo_index` set `users` = \''. $users .'\' LIMIT 1';
		mysql_query($register3);
		$register4 = "INSERT INTO `homes` (`owner`, `bg`, `badge`, `habboname`) VALUES ('$username', 'b_bg_metal2', '', '$username');";
		mysql_query($register4);
		return true;
	}
	function UsersOnline() {
			$sql = 'SELECT * FROM `debbo_index` LIMIT 1';
			$reply = mysql_fetch_array(mysql_query($sql), MYSQL_ASSOC);
			return $reply[online_count];
	}
	function coinbuy($username, $amount) {
			$sql = 'UPDATE `users` set `credits` = \''. $amount .'\' WHERE `name` = \''. $_SESSION['username'] .'\'  LIMIT 1';
			mysql_query($sql);
			return true;
	}
	function code($username, $code) {
			$sql = 'SELECT * FROM `vouchers` WHERE `code` = \''. $code .'\' LIMIT 1';
			$reply = mysql_fetch_array(mysql_query($sql), MYSQL_ASSOC);
			return $reply[amount];
	}
	function delvoucher($voucher, $amount) {
			$sql = 'DELETE FROM `vouchers` WHERE `amount` = \''. $voucher .'\' AND `code` = \''. $amount .'\'  LIMIT 1';
			mysql_query($sql);
			return true;
	}
}
?>