<?php defined("IN_DOCEBO") or die('Direct access is forbidden.');

/* ======================================================================== \
| 	DOCEBO - The E-Learning Suite											|
| 																			|
| 	Copyright (c) 2008 (Docebo)												|
| 	http://www.docebo.com													|
|   License 	http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt		|
\ ======================================================================== */

define('_REST_PARAM_NAME', 'q');
define('_REST_VALIDATOR_PARAM', 'restAPI');
define('_REST_MINIMUM_PARAMS', 3);
define('_REST_APINAME_INDEX', 2);
define('_REST_APIMETHOD_INDEX', 3);

if (!defined("_REST_AUTH_CODE")) define("_REST_AUTH_CODE", 0);
if (!defined("_REST_AUTH_TOKEN")) define("_REST_AUTH_TOKEN", 1);


/**
 * Retrieve an user id by token, if authenticated
 * @param <type> $token auth token
 * @return <type> the user associated to the token
 */
function getUserIdByToken($token) {

	$output = false;
	$query = "SELECT * FROM %adm_rest_authentication WHERE token='$token'";
	$res = sql_query($query);
	if(sql_num_rows($res) > 0) {
		$row = sql_fetch_assoc($res);
		$output = $row['id_user'];
	}
	return $output;
}
