<?php
include_once('../../../php/sessionStart.php');
include_once('../../../php/db/dbExec.php');
include_once('../../../php/functions.php');
include_once('../../../php/timezone.php');
include_once('../../../php/privileges.php');
include_once('../../../php/maxExecTime.php');

$bitForm = "nom1075";
$bitMod = "nom";
$empCod = $_SESSION['empCod'];
$usuCod = utf8_decode($_SESSION['usuCod']);
$usuNom = utf8_decode($_SESSION['usuNom']);

switch ($_POST['action']) {
	case 'consultarPla':
		echo consultarPla();
		break;
	case 'consultarNp':
		echo consultarNp();
		break;

}

function consultarPla() {
	global $empCod, $usuNom;

	$priv = new privileges();
	if (!$priv->consult($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorConsult());
	}

	$func = new functions();

	$numNum=$_POST['numNum'];

	# QUERYS
	$sCtrpla = "SELECT *
				FROM ctrpla 
				WHERE ctrp_emp='$empCod' AND ctrp_num='$numNum'";

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp["ctrpla"] = $db->sFetchAssoc($sCtrpla);
	$db->close();

	$func = new functions();
	return $func->jsonEncodeArray($resp, 'ctrpla');
}

function consultarNp() {
	global $empCod, $usuNom;

	$func = new functions();

	$numNum=$_POST['numNum'];
	$numCod=$_POST['numCod'];

	# QUERYS

	$sAnti = "SELECT *, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
				TRIM(tpu.tpu_nom) AS tpu_nom
				FROM antipla ant
 				LEFT JOIN maestro mae ON ant.ant_emp=mae.mae_emp AND ant.ant_cod = mae.mae_cod 
 				LEFT JOIN tpuesto tpu ON mae.mae_tpue = tpu.tpu_cod 
				WHERE ant_emp='$empCod' AND ant_numpla='$numNum' AND ant_cod='$numCod'";

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp["antipla"] = $db->sFetchAssoc($sAnti);
	$db->close();

	$func = new functions();
	return $func->jsonEncodeArray($resp, 'antipla');
}

?>