<?php
/**
 * @author Kaerañ AKA Aymeric le Gouvello
 * @version 0.5
 * @copyright Kaerañ & Gomoz AKA Mistral Oz 2008
 */

//Essentiel pour un bon branchement sur phpBB
/*define('IN_PHPBB', true);
$phpbb_root_path = $_SERVER['DOCUMENT_ROOT'].'/phpBB2/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.php');*/

/**
 * classe permettant d'acceder (authentifié) à un certain nombre d'actions des forums phpBB
 *
 */
class wsBB_Accessor{
	/** Database access Object
	 *  
	 * @var sql_db
	 */
	private $wsdb;
	
	/**
	 * Constructeur de la classe
	 * 
	 * @return void
	 */
	function __construct(){
		define('IN_PHPBB', true);
		$phpbb_root_path = $_SERVER['DOCUMENT_ROOT'].'/phpBB2/';
		include($phpbb_root_path . 'extension.inc');
		include($phpbb_root_path . 'common.php');
		global $db;
		$this->wsdb = $db;
	}
	/**
	 * Retourne la liste des utilisateurs du forum
	 * 
	 * @return string[] la liste des utilisateurs
	 */
	function get_forum_users(){
		//global $db;
		$sql = "SELECT user_id as ID, username as Name
		FROM " . USERS_TABLE . "
		WHERE user_id <> " . ANONYMOUS . "
		ORDER BY user_id";
		if( !($result = $this->wsdb->sql_query($sql)) )
		{
			//message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);
			return array('fault'=>"Could not query users");
		}
		$data = $this->wsdb->sql_fetchrowset($result);
		return $data;
	}
	/**
	 * Retourne l'ID si le user existe, Null sinon
	 *
	 * @param string $username
	 * @return integer
	 */
	function user_exists(string $username){
		return "145623";
	}
}
?>