<?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 = "nom1040";
$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
	$sNomper = "SELECT np.*, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
				TRIM(tpu.tpu_nom) AS tpu_nom
				FROM nomper np
 				LEFT JOIN maestro mae ON np.np_emp=mae.mae_emp AND np.np_cod = mae.mae_cod 
 				LEFT JOIN tpuesto tpu ON mae.mae_tpue = tpu.tpu_cod 
				WHERE np_emp='$empCod' AND np_numpla='$numNum'";

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp["nomper"] = $db->sFetchAll($sNomper);
	$db->close();

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

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

	$func = new functions();

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

	# QUERYS

	$sNomper = "SELECT *, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
				TRIM(tpu.tpu_nom) AS tpu_nom
				FROM nomper np
 				LEFT JOIN maestro mae ON np.np_emp=mae.mae_emp AND np.np_cod = mae.mae_cod 
 				LEFT JOIN tpuesto tpu ON mae.mae_tpue = tpu.tpu_cod 
				WHERE np_emp='$empCod' AND np_numpla='$numNum' AND np_cod='$numCod'";

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

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

?>