<?
////////////////////////////////////////////////////
// Conciliación: gestión de conciliación de activos
// Version: 1.0
//
// Copyright (C) 2014  Eustotem Multimedia, S.L.
//
// License: MIT, see LICENSE
////////////////////////////////////////////////////


include("../conf/preferences.php");
session_name(SYS_APP_SESSNAME);
session_start();
include("../conf/langs/".$langs[$_SESSION['userlang']][0]."/MAIN.php");
include("../conf/langs/".$langs[$_SESSION['userlang']][0]."/XHR.core.php");
include("../conf/connections.php");
include("../phplib/auth.php");
require_once("../phplib/utils.php");
require_once("../core/plugins.php");

$resId=$_REQUEST['resId'];
if(isset($_REQUEST['parentId'])) $parentId=$_REQUEST['parentId'];
$conf=simplexml_load_file("../conf/resources/".$langs[$_SESSION['userlang']][0]."/".$_SESSION['conf'][$resId]->masterview);
$accion=$_REQUEST['action'];

$obj=NULL;		
$result="";		

switch($accion){
	case "close_session":
		$errores='';
		if(!isset($_REQUEST['userid'])){
			$errores=XHR_NOSESSID;
		}else{
			if($_REQUEST['userid']==$_REQUEST['selfid']){
				$errores=XHR_DONTBANYOURSELF;
			}else{
				$sql="DELETE FROM " . SYS_SESSION_TABLE . " WHERE userid={$_REQUEST['userid']}";
				if($q=mysql_query($sql)){
				}else{
					$errores=XHR_SESSIONCLOSEERROR;
				}
			}
		}
		if($errores==''){
			$obj->result="ok";
			$obj->msg=XHR_SESSIONCLOSED;
		}else{
			$obj->result="ko";
			$obj->msg=$errores;
		}
		$result=json_encode($obj);
		break;
	case "clear_history":
		$sql="DELETE FROM " . SYS_ACCESS_LOG . "";
		$q=mysql_query($sql);
		$obj->result="ok";
		$result=json_encode($obj);
		break;
	case "clear_log":
		$sql="DELETE FROM " . SYS_LOG_TABLE . "";
		$q=mysql_query($sql);
		$obj->result="ok";
		$result=json_encode($obj);
		break;
}
echo $result;
?>