Files
pedidor/index.php
2015-12-25 20:30:06 +01:00

88 lines
2.4 KiB
PHP
Executable File

<?php
/*
Pedidor Project
http://git.lutran.fr/pedidor.git
Copyright (C) 2015 François Lutran & Clara Floren Zabala
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 3 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, see http://www.gnu.org/licenses
*/
/* Requests Handler */
//Start buffering
ob_start();
require_once '../objects/class_management.php';
$oClassManagement = new ClassManagement('pedidor');
ToolBox::cleanPost($_POST);
ToolBox::cleanPost($_GET);
ToolBox::cleanPost($_REQUEST);
ToolBox::fixGlobalVars(isset($argv)?$argv:array());
//Available variables
$sToken = isset($_GET['token'])?$_GET['token']:'';
$sAction = isset($_REQUEST['a'])?$_REQUEST['a']:'';
$sPage = isset($_GET['p'])?$_GET['p']:'index';
$sType = isset($_GET['t'])?$_GET['t']:'';
$iApiKey = isset($_GET['api'])?$_GET['api']:'';
$sContent = isset($_POST['content'])?$_POST['content']:'';
$iId = isset($_REQUEST['id'])?$_REQUEST['id']:0;
$asItem = isset($_GET['item'])?$_GET['item']:0;
//Initiate class
$oPedidor = new Pedidor($oClassManagement, __FILE__);
$bLoggedIn = $oPedidor->isLoggedIn();
$sResult = '';
if($sAction=='logmein') $sResult = $oPedidor->logMeIn($sToken);
elseif($sAction!='' && $bLoggedIn)
{
switch($sAction)
{
case 'products':
$sResult = $oPedidor->getProducts();
break;
case 'product':
$sResult = $oPedidor->modifyProduct($sType, $asItem);
break;
case 'dl_products':
$oPedidor->downloadProducts();
break;
default:
$sResult = Pedidor::getJsonResult(false, Pedidor::NOT_FOUND);
}
}
elseif($sAction!='' && !$bLoggedIn)
{
if($oPedidor->checkApiKey($iApiKey))
{
switch($sAction)
{
case '':
//$sResult = $oPedidor->
break;
default:
$sResult = Pedidor::getJsonResult(false, Pedidor::NOT_FOUND);
}
}
else $sResult = Pedidor::getJsonResult(false, Pedidor::UNAUTHORIZED);
}
else $sResult = $oPedidor->getPage($bLoggedIn);
$sDebug = ob_get_clean();
if(Settings::DEBUG && $sDebug!='') $oPedidor->addUncaughtError($sDebug);
echo $sResult;
?>