Location: PHPKode > scripts > ezStats for PlayStation Network > ezStats2_psn/classes/player.php
<?php
	class Player {
		private $sql = NULL;
		private $tpl = NULL;
		private $func = NULL;
		private $settings = NULL;
		
		public function __construct() {
			$this->sql  = new MySQL();
			$this->func = new Functions();
			$this->settings = new Settings();
			$this->tpl  = new Templates();
			$this->tpl->load_phrases("admin", true);
		}
		
		
		public function add($name) {
			$name = trim($name);
			
			// Test ob Name übergeben wurde 
			if ($name == "") {
				return $this->tpl->phrase("message_no_player_given");
			}
			
			// Name wurde übergeben
			else {
				// Überprüfen ob der Name in der Datenbank vorhanden ist
				$this->sql->query('SELECT id FROM '.$this->sql->prefix.'player WHERE name = "'.$name.'"');
				
				if($this->sql->count()) {
					// Name ist schon in der DB vorhanden / Message generieren / Spielername in die Phrase laden 
					$message = $this->tpl->phrase("message_player_already_added");
					eval ( "\$message = \"$message\";" );
					return $message;
				} 
				else {
					// Name ist noch nicht in der DB vorhanden / Spieler in die DB speichern
					$this->sql->query('INSERT INTO '.$this->sql->prefix.'player (name) VALUES ("'.$name.'")');
					$playerid = $this->sql->id;
					
					// Spieler updaten mit der Spieler-ID
					$result = $this->update($playerid, $name);
					
					// Daten der Aktualisierung in die Spielereigenschaften schreiben
					$this->sql->query('
						UPDATE `'.$this->sql->prefix.'player` SET
							`last_update` = "'.time().'"
						WHERE `id` = "'.$playerid.'"
					');
					
					// Message generieren / Spielername in die Phrase laden
					$message = $this->tpl->phrase("message_add_player");
					eval ( "\$message = \"$message\";" );
					return $message;
				}
			}
		}
		
		
		public function delete($playerid = NULL, $name = "NoName") {
			if ($playerid === NULL) {
				return "ERROR: No Player-ID given";
			} else {
				$this->sql->query('DELETE FROM '.$this->sql->prefix.'player WHERE id = "'.$playerid.'"');
				
				$message = $this->tpl->phrase("message_delete_player");
				eval ( "\$message = \"$message\";" );
				return $message;
			}
		}
		
		
		public function update($playerid, $name) {
			### STATS-DATEN ABRUFEN ###
			$psn = new PSN();
			
			$user    = $psn->get_jid($name);
			$profile = $psn->get_prof($user['region'], $user['jid']);
			$scores  = $psn->get_count($user['jid']);
			$games   = $psn->get_games($user['jid']);
			
			if (isset($user['jid']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `jid` = "'.$user['jid'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($user['region']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `region` = "'.$user['region'].'" WHERE `id` = "'.$playerid.'"');
			
			if (isset($profile[0]['name']))			$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `name` = "'.$profile[0]['name'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($profile[0]['country']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `country` = "'.$profile[0]['country'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($profile[0]['aboutme']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `aboutme` = "'.$profile[0]['aboutme'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($profile[0]['avatar']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `avatar` = "'.$profile[0]['avatar'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($profile[0]['psnplus']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `psnplus` = "'.$profile[0]['psnplus'].'" WHERE `id` = "'.$playerid.'"');
			
			if (isset($scores[0]['points']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `points` = "'.$scores[0]['points'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['level']))			$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `level` = "'.$scores[0]['level'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['base']))			$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `base` = "'.$scores[0]['base'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['next']))			$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `next` = "'.$scores[0]['next'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['progress']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `progress` = "'.$scores[0]['progress'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['platinum']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `platinum` = "'.$scores[0]['platinum'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['gold']))			$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `gold` = "'.$scores[0]['gold'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['silver']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `silver` = "'.$scores[0]['silver'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['bronze']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `bronze` = "'.$scores[0]['bronze'].'" WHERE `id` = "'.$playerid.'"');
			if (isset($scores[0]['total']))			$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `total` = "'.$scores[0]['total'].'" WHERE `id` = "'.$playerid.'"');
			
			if (isset($games['totalGames']))		$this->sql->query('UPDATE `'.$this->sql->prefix.'player` SET `totalGames` = "'.$games['totalGames'].'" WHERE `id` = "'.$playerid.'"');
			
			if (isset($user['jid'])) return true; else return false;
		}
		
		
		private function convert($obj) {
			// Funktion: Objekt in JSON-String konvertieren und Slashes maskieren
			$string = json_encode($obj);
			if (get_magic_quotes_gpc()) $string = stripslashes($string);
			if (function_exists("mysql_real_escape_string")) $string = mysql_real_escape_string($string); else $string = addslashes($string);
			return $string;
		}
	}
?>
Return current item: ezStats for PlayStation Network