<?php
/*
 * checkRef.php
 *
 * Copyright 2015 Christophe Battarel <christophe.battarel@altairis.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal

$res=@include("../../main.inc.php");					// For root directory
if (! $res) $res=@include("../../../main.inc.php");		// For "custom" directory

$element = GETPOST('element');
$ref = GETPOST('ref');

require_once DOL_DOCUMENT_ROOT .'/core/lib/admin.lib.php';

$verdol=versiondolibarrarray();

switch($element)
{
	case 'propal':
	case 'propale':
		require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
		$object = new Propal($db);
		break;
	case 'commande':
		require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
		$object = new Commande($db);
		break;
	case 'facture':
		require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
		$object = new Facture($db);
		break;
	case 'expedition':
		require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
		$object = new Expedition($db);
		break;
}

$object->fetch(null,$ref);

echo  json_encode(array("ok"=>$object->id));

?>
