<?php
session_start();
foreach($_GET as $campo => $valor){${$campo}=$valor;} 
foreach($_POST as $campo => $valor){${$campo}=$valor;} 
include_once('lib_main.php');

if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}

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

$response=$elem_o->appendChild($elem_o->createElement("response"));
$result=$response->appendChild($elem_o->createElement("result"));

$tabla='plan';

if($optlist=='plan')
{

     $docu='PLA1';

     $sql_docu ='select * ';
     $sql_docu.='from '.$tabla.'1 ';
     $sql_docu.='left join '.$tabla.'2 on idnum1=idnum2 ';
     // $sql_docu.='left join asub0 on asub=asub_codigo ';
     $sql_docu.='where status not in ("O","X") ';
     if(!empty($clie))
     {$sql_docu.='and enti like "'.substr($clie,0,10).'%" ';}
     $sql_docu.='and docu like "'.$docu.'%"';
     $sql_docu.='and asub like "%0000"';
     $sql_docu.='order by fecha desc ';
     $sql_docu.='limit 5';
     $res_docu=msql_query($sql_docu,$link_data);

     // $element=$result->appendChild($elem_o->createElement("msgalert","test1"));
     // $element=$result->appendChild($elem_o->createElement("msgalert",$sql_docu));
     // $options=$result->appendChild($elem_o->createElement("options"," "));
     $zoptions='';
     while($aso_docu=msql_fetch_assoc($res_docu))
     {
          $xnumero=$aso_docu['numero'];
          $xasub0 =substr($aso_docu['asub'],0,4);
     //      $xasubdes =$aso_docu['asub_descri'];

          $xconcepto =$aso_docu['concepto'];
          $xconcepto =str_replace($xasub0,'',$xconcepto);
          $xconcepto =str_replace($xasubdes,'',$xconcepto);

          $xvalue =$xnumero;
          $xvalue.='-'.$xasub0;
          $xvalue.='-'.$xasubdes;

          $xoption ='';
          $xoption.='-'.$xconcepto;
          $xoption=str_replace('--','-',$xoption);
          $xoption=str_replace('--','-',$xoption);
          $zoptions.=$xvalue.','.$xoption.';';
     }
}


if($optlist=='asub')
{
     $docu='PLA1';
     

     $sql_docu ='select * ';
     $sql_docu.='from '.$tabla.'1 ';
     $sql_docu.='left join '.$tabla.'2 on idnum1=idnum2 ';
     $sql_docu.='left join asub0 on asub=asub_codigo ';
     $sql_docu.='where status not in ("O","X") ';
     if(!empty($clie))
     {$sql_docu.='and enti like "'.substr($clie,0,10).'%" ';}
     $sql_docu.='and docu like "'.$docu.'%"';
     $sql_docu.='and numero = '.($plan*1).' ';
     $sql_docu.='and asub not like "%0000"';
     $sql_docu.='order by asub ';
//      $sql_docu.='order by fecha desc ';
//      $sql_docu.='limit 5';
     $res_docu=msql_query($sql_docu,$link_data);

     // $element=$result->appendChild($elem_o->createElement("msgalert","test1"));
     // $element=$result->appendChild($elem_o->createElement("msgalert",$sql_docu));
     // $options=$result->appendChild($elem_o->createElement("options"," "));
     $zoptions='';
     while($aso_docu=msql_fetch_assoc($res_docu))
     {
//           $xnumero=$aso_docu['numero'];
//           $xasub0 =substr($aso_docu['asub'],0,4);
//      //      $xasubdes =$aso_docu['asub_descri'];

//           $xconcepto =$aso_docu['concepto'];
//           $xconcepto =str_replace($xasub0,'',$xconcepto);
//           $xconcepto =str_replace($xasubdes,'',$xconcepto);

//           $xvalue =$xnumero;
//           $xvalue.=' -'.$xasub0;
//           $xvalue.=' -'.$xasubdes;

//           $xoption ='';
//           $xoption.=' -'.$xconcepto;
//           $xoption=str_replace('--','-',$xoption);
//           $xoption=str_replace('--','-',$xoption);
          
          $xvalue=$aso_docu['asub'];
          $xoption=$aso_docu['asub_descri'];
          $zoptions.=$xvalue.','.$xoption.';';
     }
}


// echo '*/*/*/*'.$plan1;

$zdom=$domd_o;
$zele=$response;
// $zvalue=$plan;
$zvalue=$plan1;
// $zdefa=$plan1;
$zmaintag='result';
include ('ele_select.php');

echo $domd_o->saveXML();
?>

