<?php

include '../../conexion/session.php';
include '../../conexion/conn.php';

$folio_planilla = $_REQUEST['folio_planilla'];


$rs = mysql_query("SELECT MAX(num_pallet) as cont FROM contenedor_estiba WHERE folio_planilla='$folio_planilla'");
if ($row = mysql_fetch_array($rs)) {
    $cont = $row['cont'];
    if ($cont == null) {
        $cont = $cont + 1;
    } else {
        $cont = $cont + 1;
    }
}

$sql =  ("INSERT INTO contenedor_estiba (
                    folio_planilla,
                    num_pallet,
                    sincro,
                    cumple_norma
                ) VALUES(
                    '$folio_planilla',
                    '$cont',
                    'N',
                    'SI'
                )");


$result = @mysql_query($sql);

$rs = mysql_query("SELECT COUNT(*) as cont FROM contenedor_estiba WHERE folio_planilla='$folio_planilla'");
if ($row = mysql_fetch_array($rs)) {
    $cont = $row['cont'];
}

$sql7 = "UPDATE contenedor_planilla 
SET cant_pallet='$cont'
WHERE folio_planilla='$folio_planilla'";
$result7 = @mysql_query($sql7);

if ($result7) {
    echo json_encode(array('success' => true, 'result' => "hola"));
} else {
    echo json_encode(array('success' => false, 'sql_message' => mysql_error(), ));
}