<?php
/**
 * Online players file
 * @author Lauri Lüüs <mad@webpoint.ee>
 * @version $Id: OnlinePlayers.php 15 2005-05-29 17:32:41Z madest $
 * @package AccountManager
 * @filesource
 */
 
/**
 * Online players module
 * @author Lauri Lüüs <mad@webpoint.ee>
 * @version $Id: OnlinePlayers.php 15 2005-05-29 17:32:41Z madest $
 * @package AccountManager
 */
class OnlinePlayers extends Module
{
	function OnlinePlayers()
	{
		$this->Module();
		if($this->template = temp_load($this->config->manager['template_path']."online_players.htm"))
		{
			$this->makeList();
			$this->output = $this->template;
		} else {
			$this->output = $this->modulename." - Error template not found.";
		}
	}
	
	function makeList()
	{
		if($this->config->manager['online_page'] == true)
		{
			if(isset($_GET['ord']))
			{
				$ord = $_GET['ord'];
				switch ($ord) {
					// Name Order
					case "nameac":
						$q = "SELECT * FROM characters WHERE online = 1 ORDER BY char_name ASC";
						$links['name_ord'] = "namedc";
						
						$links['class_ord'] = "classac";
						$links['lvl_ord'] = "levelac";
						break;
					case "namedc":
						$q = "SELECT * FROM characters WHERE online = 1 ORDER BY char_name DESC";
						$links['name_ord'] = "nameac";
						
						$links['class_ord'] = "classac";
						$links['lvl_ord'] = "levelac";
						break;
					// Class Order
					case "classac":
						$q = "SELECT * FROM characters WHERE online = 1 ORDER BY classid ASC";
						$links['class_ord'] = "classdc";
						
						$links['name_ord'] = "nameac";
						$links['lvl_ord'] = "levelac";
						break;
					case "classdc":
						$q = "SELECT * FROM characters WHERE online = 1 ORDER BY classid DESC";
						$links['class_ord'] = "classac";
						
						$links['name_ord'] = "nameac";
						$links['lvl_ord'] = "levelac";
						break;						
					// Level Order
					case "levelac":
						$q = "SELECT * FROM characters WHERE online = 1 ORDER BY level ASC";
						$links['lvl_ord'] = "leveldc";
						
						$links['name_ord'] = "nameac";
						$links['class_ord'] = "classac";
						break;
					case "leveldc":
						$q = "SELECT * FROM characters WHERE online = 1 ORDER BY level DESC";
						$links['lvl_ord'] = "levelac";
						
						$links['name_ord'] = "nameac";
						$links['class_ord'] = "classac";
						break;					
					// Default (no valid $_GET[ord])
					default:
						$q = "SELECT * FROM characters WHERE online = 1";
						$links['name_ord'] = "nameac";
						$links['class_ord'] = "classac";
						$links['lvl_ord'] = "levelac";
						break;
				}			
			} else { // No order specified
				$q = "SELECT * FROM characters WHERE online = 1 ORDER BY {$this->config->manager['online_page_field']} {$this->config->manager['online_page_order']}";
				$links['name_ord'] = "nameac";
				$links['class_ord'] = "classac";
				$links['lvl_ord'] = "levelac";
			}
						
			$charBlock = temp_lock($this->template, "characters");
			if($aq=mysql_query($q))
			{
				while($r = mysql_fetch_array($aq))
				{
					$className = mysql_fetch_array(mysql_query("SELECT ClassName FROM char_templates WHERE ClassId={$r['classid']}"));
					$r['class'] = $className['ClassName'];
					$charBlock['add'] = temp_subs($charBlock['tpl'], "char", $r);
					$charBlock = temp_done($charBlock);
				}
				$this->template = temp_unlock($charBlock, "characters");
				$this->template = temp_subs($this->template,"link", $links);
			} else {
				$this->template = "<font color=red>エラー: オンラインステータスはなく、古いSQL構造だと思われます！あるいはまったくキャラクターテーブルがありません。</font>";
			}
		} else {
			$this->template = "<font color=red>オンラインキャラクターページが使用不可です！</font>";
		}
	}
	
	function TopHundred()
	{
		
	}
}