<?php
declare(strict_types=0);
// session_start();
// foreach($_GET as $campo => $valor){${$campo}=trim($valor);} 
// foreach($_POST as $campo => $valor){${$campo}=trim($valor);} 
foreach($_GET  as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}  
foreach($_POST as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}

include_once('lib_main.php');
if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}
$user_codigo=$_SESSION['user_codigo'];
$user0=data_maes('user',$user_codigo);

if($valor=='.'){$valor='';}
if($valor=='...'){$valor='';}
if($valor=='--'){$valor='';}
if($valor=='---'){$valor='';}
if(substr($valor,0,1)=='.'){$valor=substr($valor,1);}

// if($valor==0.001){$valor='';}

$sql_save ='update ';
if(!empty($codigo))
{
     $sql_desc='describe '.$tabla.'0';
     $res_desc=msql_query($sql_desc,$link_data);
     $xtype=msql_result($res_desc,0,'Type');
     
     
     $sql_save.=$tabla.'0 set ';
     $sql_save.=$tabla.'_'.$field.'="'.$valor.'" ';
//      $sql_save.=$tabla.'_uuser="'.$user_codigo.'", ';
//      $sql_save.=$tabla.'_udate=now() ';
     $sql_save.='where '.$tabla.'_codigo="'.$codigo.'" ';
     if(!mb_stristr2($xtype,'int'))
     {$sql_save.='and length('.$tabla.'_codigo)>=4 ';}
     if($tabla=='enti'){$sql_save.='and length('.$tabla.'_codigo)>=10 ';}
     if($tabla=='item'){$sql_save.='and length('.$tabla.'_codigo)>=8 ';}
}     

if(!empty($idnum))
{
     if(empty($iddet))
     {
          $sql_save.=$tabla.'1 set ';
          $sql_save.=$field.'="'.$valor.'", ';
          $sql_save.='uuser="'.$user_codigo.'", ';
          $sql_save.='udate=now() ';
          $sql_save.='where idnum1="'.$idnum.'" ';
     }else{
          $sql_save.=$tabla.'2 set ';
          $sql_save.=$field.'="'.$valor.'", ';
//           $sql_save.='uuser="'.$user_codigo.'", ';
          $sql_save.='idate2=now() ';
          $sql_save.='where idnum2="'.$idnum.'" ';
          $sql_save.='and iddet="'.$iddet.'" ';
     }
}

$sql_save.='limit 1 ';
$res_save=msql_query($sql_save,$link_data);


     $dom = new DOMDocument();
          $dom->encoding = 'utf-8';
          $dom->xmlVersion = '1.0';
          $dom->formatOutput = true;

     $response=$dom->appendChild($dom->createElement("response"));
//      $msgsys=$response->appendChild($dom->createElement("msgsys",$sql_save)); 
     $msgswal=$response->appendChild($dom->createElement("msgswal")); 
          $msgswal->setAttribute("id","msgswal");
     $msgsys=$response->appendChild($dom->createElement("msgsys")); 
          $msgsys->appendChild($dom->createElement("date",date('H:i:s'))); 
     
          echo $dom->saveXML();
     
         
?>

