<?php
/***************************************************************************
 *                                webservice.php
 *                            -------------------
 *   begin                : Tuesday, Mar 25, 2008
 *   copyright            : (C) 2008 Le Web en Plus
 *   email                : kaeran@free.fr
 *
 *
 ***************************************************************************/

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

//Temporaire pour debug (les fichiers WSDL sont mis en cache par PHP pour 24 heures !)
ini_set('soap.wsdl_cache_enabled', 0);

/**
 * classe du Web Service pour phpBB traitant les users
 *
 */
class phpBB_USER{
	/**
	 * fonction de test du webservice
	 *
	 * @return datetime 
	 */
	function getServerDate() {
		return array('date'=>date('Y-m-d\TH:i:s O'));
	}
	/**
	 * méthode listant tous les logins de la base phpBB
	 *
	 * @return string[]
	 */
	function getUsers() {
		global $db;
		$sql = "SELECT user_id as ID, username as Name
		FROM " . USERS_TABLE . "
		WHERE user_id <> " . ANONYMOUS . "
		ORDER BY user_id";
		if( !($result = $db->sql_query($sql)) )
		{
			//message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);
			return array('fault'=>"Could not query users");
		}
		$data = $db->sql_fetchrowset($result);
		/*$ans = "";
		 foreach ($data as $data_row) {
			$ans .= "<user>";
			$ans .= "<ID xsd:type='integer'>".$data_row['ID']."</ID>";
			$ans .= "<Name xsd:type='string'>".$data_row['Name']."</Name>";
			$ans .= "</user>";
			}*/
		return array('value'=>array($data));
	}
}

try{
	$bbws = new SoapServer('fichier.wsdl', array('trace' => 1, 'soap_version' => SOAP_1_1));
	$bbws->setClass('phpBB_USER');
} catch (Exception $e){
	echo $e;
}
if($_SERVER['REQUEST_METHOD']=='POST'){
	$bbws->handle();
} else {
	echo '<strong>Ce serveur SOAP peut traiter les fonctions suivantes : </strong>';
	echo '<ul>';
	foreach($bbws->getFunctions() as $func){
		echo '<li>',$func,'</li>';
	}
	echo '</ul>';
}
?>