<?php
declare(strict_types=0);
//
{
// FILES DOCU
// 1 solo foto defa
// 2 fotos(S) orient H/V  (seleccionar default)
// 3 foto(S) mini y descri 
// 4 foto y descri (2 col)
// 5 lineal
// 9 full columnas

// $zobj=9     
     
}
     
// $zcodigo=trim($zcodigo);
$zalign='left';
$tdstyle='';

if($zobj==5){$zalign='';}
if(empty($zorient)){$zorient=0;}
if(empty($ztabla)){$ztabla='fdoc';}
// if(empty($zstockv)){$zstockv=0;}
// if(empty($zstock012)){$zstock012=0;}
if(empty($zfoto012)){$zfoto012=0;}
// if(empty($zstock)){$zstock=0;}
// if(empty($zid)){$zid=microtime()*1000000;}
if(empty($zid)){$zid=microtime()*1000000;}
if(empty($zobj)){$zobj=3;}
if(empty($zsize)){$zsize=1;}
// if(esMovil()){$zsize=$zsize*1.1;}
// if(empty($zlabel)){$zlabel=$zcaption;}
if(!empty($zsize) and $zsize!=1){$zstyle.='font-size:'.($zsize).'em;';}
if(!empty($zcolor)){$zstyle.='background:'.$zcolor.';';}
if($zobj==5 and getPlatform()=='Android'){$zobj=1;}
if($zobj==5 or $zorient==1){$zfixh=0;}

$i_limit=10;
if($zobj==1 or $zobj==5){$i_limit=1;}

if($zobj==2){$zstockv=0;}
if($zobj==2 and $zupld==1){$zstockv=1; $zprecio='';}

// $ztabla='img'.substr($ztabla,0,1);

$ztabla0=$ztabla.'0';

if($ztcell>=2){$zstyle.='width:100%;';}

if(!empty($zstockv))
{
//      $stock=sal_item($zcodigo,$zbode,'D');
//      $zstock=$stock['uni_fin'];
//      echo '<br>**/*/'.$zstock;
}

$maxcarr=99999;
if($zstockv==2)
{
//      if(mb_stristr('gmny.gnya',$cfg_empr)){$maxcarr=999;}
//      if(mb_stristr('orel',$cfg_empr)){$maxcarr=9999;}
}

// $ver_tallas=0;
// if(mb_stristr('gmny.gnya',$cfg_empr)){$ver_tallas=2;}
// if(mb_stristr('gmny.gnya',$cfg_empr)){$solo_ctlg=1;}


// if($tctlg==1){$sql_item.='and ifnull(item_ctlg,0)=1 ';}
// if($tctlg==2){$sql_item.='and ifnull(item_ctlg,0)!=1 ';}


$zdocu0=data_maes('docu',$zdocu);

$ztabla1=$zdocu0['docu_tabla'].'1';
$ztabla2=$zdocu0['docu_tabla'].'2';

// count(item_tlla) as item_ctalla
// if(!empty($ztabla))


{
   $sql_filedocu ='select * ';
   $sql_filedocu.='from '.$ztabla0.' ';
   $sql_filedocu.='left join '.$ztabla1.' on '.$ztabla.'_idnum =idnum1 ';
   $sql_filedocu.='left join '.$ztabla2.' on '.$ztabla.'_idnum =idnum2 and '.$ztabla.'_iddet =iddet  ';
//    $sql_filedocu.='left join '.$ztabla0.' on idnum1='.$ztabla.'_idnum ';
//    $sql_filedocu.='left join '.$ztabla.'0 on left('.$ztabla.'_codigo,10) = left('.$ztabla.'_'.$ztabla.',10) ';
   $sql_filedocu.='left join item0 on item=item_codigo ';
//    $sql_filedocu.='left join mrca0 on '.$ztabla.'_mrca=mrca_codigo ';
//    $sql_filedocu.='left join tlla0 on '.$ztabla.'_tlla=tlla_codigo ';
//    $sql_filedocu.='left join clor0 on '.$ztabla.'_clor=clor_codigo ';
//    $sql_filedocu.='left join kldd0 on '.$ztabla.'_kldd=kldd_codigo ';
   $sql_filedocu.='where '.$ztabla.'_status not in ("O","X") ';
//    $sql_filedocu.='and status not in ("O","X") ';
   $sql_filedocu.='and '.$ztabla.'_docu="'.$zdocu.'" ';
   $sql_filedocu.='and '.$ztabla.'_idnum="'.$zidnum.'" ';
   if(!empty($ziddet))
   {$sql_filedocu.='and '.$ztabla.'_iddet='.$ziddet.' ';}
//    $sql_filedocu.='and '.$ztabla.'_status not in ("O","X") ';
//    $sql_filedocu.='and '.$ztabla.'_status not in ("O","X") ';
//    $sql_filedocu.='order by '.$ztabla.'_defa desc,'.$ztabla.'_docu,'.$ztabla.'_docu ';
   $sql_filedocu.='order by '.$ztabla.'_idnum, '.$ztabla.'_iddet, '.$ztabla.'_defa desc ';
//    $sql_filedocu.='limit '.$i_limit;
   $res_filedocu=msql_query($sql_filedocu,$link_data);
     
}

if(msql_num_rows($res_filedocu)==0)
{
//      $sql_filedocu=str_replace('left join '.$ztabla.'0 on '.$ztabla.'_codigo ='.$ztabla.'_'.$ztabla.' ','left join '.$ztabla.'0 on left('.$ztabla.'_codigo,10) = left('.$ztabla.'_'.$ztabla.',10) ',$sql_filedocu);
//      $res_filedocu=msql_query($sql_filedocu,$link_data);
}

if(msql_num_rows($res_filedocu)==0)
{
//      $sql_filedocu=str_replace('and '.$ztabla.'_status not in ("O","X") ','',$sql_filedocu);
//      $res_filedocu=msql_query($sql_filedocu,$link_data);
}


//      echo '<br>***'.$zcodigo;
//      echo '<br>***'.msql_num_rows($res_filedocu);
//      echo '<br>***'.$sql_filedocu;
//      echo '<br>***'.msql_num_rows($res_filedocu);

if(msql_num_rows($res_filedocu)!=0)
{
     msql_data_seek($res_filedocu,0);
     $aso_filedocu=msql_fetch_assoc($res_filedocu);

//      $img_codigo=trim($aso_filedocu[$ztabla.'_mdlo']);
//      if(strlen($img_codigo)<6){$img_codigo=$aso_filedocu[$ztabla.'_rfer'];}
//      if(strlen($img_codigo)<6){$img_codigo=$aso_filedocu[$ztabla.'_codigo'];}
//      if(strlen($img_codigo)<6){$img_codigo=$zcodigo;}

//      if(mb_stristr('orel.amay',$cfg_empr))
//      {$img_codigo=trim($aso_filedocu[$ztabla.'_codigov']);}

//      if(mb_stristr('gmny',$cfg_empr))
//      {$img_codigo=trim($aso_filedocu[$ztabla.'_mdlo']);}

//      $img_rfer=trim($aso_filedocu[$ztabla.'_rfer']);
//      if(strlen($img_rfer)<6){$img_rfer=$aso_filedocu[$ztabla.'_codigo'];}

     $imgi_file=trim($aso_filedocu[$ztabla.'_file']);
     $img_descri=trim($aso_filedocu[$ztabla.'_descri']);
//      $lsub_descri=trim($aso_filedocu['lsub_descri']);
//      $mrca_descri=trim($aso_filedocu['mrca_descri']);
//      $tlla_descri=trim($aso_filedocu['tlla_descri']);
//      $kldd_descri=trim($aso_filedocu['kldd_descri']);
//      $item_composi=trim($aso_filedocu['item_composi']);
//      $item_umdd=trim($aso_filedocu['item_umdd']);
//      $item_duni=$aso_filedocu['item_duni'];
//      $item_dpre=trim($aso_filedocu['item_dpre']);
//      $item_ctlg=trim($aso_filedocu['item_ctlg']);
//      $clor_descri=trim($aso_filedocu['clor_descri']);
//      $clor_hexa=trim($aso_filedocu['clor_hexa']);

//      $img_descri=str_replace($mrca_descri,'',$img_descri);     

//      if($item_dpre<2 or mb_stristr($zprecio,'pvp')){$item_dpre=2;}     
//      if(mb_stristr('imcp',$cfg_empr)){$item_dpre=4;}

//      echo '*/*/*/'.$zprecio;
     
//      if(!empty($zprecio))
//      {
//           $zprecio=strtolower($zprecio);
//           $xprecio=$aso_filedocu['item_'.$zprecio];
//      }

     if($ztabla=='item' and $ver_tallas>0)
     {
//           $sql_tllas ='select * ';
//           $sql_tllas.='from item0 left join tlla0 on item_tlla=tlla_codigo ';
//           $sql_tllas.='where item_status not in("O","X") ';
//           $sql_tllas.='and length(trim(item_codigo))>=6 ';
//           $sql_tllas.='and item_codigo like "'.$img_rfer.'%" ';
// //           $sql_tllas.='and item_codigo like "'.substr($img_rfer,0,8).'%" ';
//      //      $sql_tllas.='and tlla_codigo*1>0 ';
          
// //           if($solo_ctlg==1)
// //           {$sql_tllas.='and item_ctlg=1 ';}
// //           echo '<br>*/*/*/'.$tctlg;
//           if($tctlg==1){$sql_tllas.='and ifnull(item_ctlg,0)=1 ';}
//           if($tctlg==2){$sql_tllas.='and ifnull(item_ctlg,0)!=1 ';}
// //           if($format==5)
// //           {
// // //           echo '<br>*/*/'.$ctlg;               
// //           }
// //           else
// //           {
// //           if($solo_ctlg==1)
// //           {$sql_tllas.='and item_ctlg=1 ';}
// //           }
          
//           $sql_tllas.='order by tlla_codigo ';
//           $sql_tllas.='';
//           $sql_tllas.='';
//           $res_tllas=msql_query($sql_tllas,$link_data);
//           $ctllas=msql_num_rows($res_tllas);
// // echo '<br>*/*/*/'.$sql_tllas;
//           $tlla_descri2='';

//           if(empty($user_codigo))
//           {
//                msql_data_seek($res_tllas,0);
//                while($aso_tllas=msql_fetch_assoc($res_tllas))
//                {
//                     if((int)$aso_tllas['item_tlla']>0 or ((int)$aso_tllas['item_tlla']==0 and $ctllas==1))
//                     {$tlla_descri2.=$aso_tllas['tlla_descri'].' ';}
//                }
//           }
     }     

     
                    $xheader='';
                    $xheader.=$zdocu.' - '.(int)$aso_filedocu['numero'];
                    $xheader2='';
                    $xheader2.=''.$aso_filedocu['iddet'];
                    $xheader2.=' - '.$aso_filedocu['item_descri'];
     
     
     $domd0 = new DOMDocument();
          $domd0->encoding = 'utf-8';
          $domd0->xmlVersion = '1.0';
          $domd0->formatOutput = true;
     $elem0=$domd0;

     if(!empty($zdom)){$domd0=$zdom;}
     if(!empty($zele)){$elem0=$zele;}

     if($ztcell>=2)
     {
          $element=$elem0->appendChild($domd0->createElement("td"));
               if(!empty($zid))
               {$element->setAttribute("id",$zid);}
               $element->setAttribute("valign","top");
     }
     else
     {
          $spandiv='div';

          $element=$elem0->appendChild($domd0->createElement($spandiv,""));
               if(empty($zdom))
               {$zstyle.="float:".$zalign.";";
               $element->setAttribute("style",$zstyle);}
               if(empty($zdom))
               {$element->setAttribute("style","float:".$zalign.";margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:".$zsize*(0)."em;");}

               if(!empty($zid))
               {$element->setAttribute("id",$zid);}
               $element->setAttribute("img-span",'');
     }

     if(!empty($zhide)){$element->setAttribute("hide","");}

     $trheight="";
     // if(mb_stristr('orel',$cfg_empr))
     // {$trheight='height:25em;';}
     // if(mb_stristr('gmny.gnya',$cfg_empr))
     // {$trheight='height:30em;';}

     $tbheight=0;
//      if(mb_stristr('orel',$cfg_empr))
//      {$tbheight=35;}
//      if(mb_stristr('gmny.gnya',$cfg_empr))
//      {$tbheight=40;}
     if($zobj==5){$tbheight=0;}     

//      $cfotos=0;
//      msql_data_seek($res_filedocu,0);
//      while($aso_filedocu=msql_fetch_assoc($res_filedocu))
//      {if(!empty($aso_filedocu[$ztabla.'_file'] and $aso_filedocu[$ztabla.'_status'])){$cfotos++;}}
//      echo '*/*/*/*'.$cfotos;

//      $cfotos=0;
//      $sql_filedocu ='select * from imgi0 ';
//      $sql_filedocu.='where imgi_item like "'.$zcodigo.'%" and ifnull(imgi_file,"")!="" and imgi_status!="X" ';
//      $sql_filedocu.='order by imgi_defa desc, imgi_codigo ';
//      $sql_filedocu.='limit '.$i_limit;
// //      if($zobj==1 or $zobj==5){$i_limit=1;}
//      $res_filedocu=msql_query($sql_filedocu,$link_data);     
//      while($aso_filedocu=msql_fetch_assoc($res_filedocu))
//      {if(!empty($aso_filedocu[$ztabla.'_file'] and $aso_filedocu[$ztabla.'_status'])){$cfotos++;}}
     
     $cfotos=msql_num_rows($res_filedocu);
//      echo '*/*/*/*'.$cfotos;
     
//      if($cfotos==0){$tbheight=15;}   
     if(empty($cfotos)){$tbheight=15;}

          $table=$element->appendChild($domd0->createElement("table",""));
     //           $table->setAttribute("border",'1');
               $table->setAttribute("name",$zcodigo);
               $table->setAttribute("cellpadding",'0');
     //           $table->setAttribute("img-table",'');
               if($zobj==5)
               {$table->setAttribute("img-list",'');}
               else
               {$table->setAttribute("img-table",'');}

               $table->setAttribute("class",'img-table');
               if(!empty($tbheight))
               {$table->setAttribute("style","min-height:".$tbheight."em;");}

          $trow=$table->appendChild($domd0->createElement("tr",""));

          $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("colspan",'99');
               $tcell->setAttribute("style","height:2em;");

          // header
          msql_data_seek($res_filedocu,0);
          $aso_filedocu=msql_fetch_assoc($res_filedocu);
          $hr=$tcell->appendChild($domd0->createElement("hr",""));
               $hr->setAttribute("color",$empr0['empr_color1']);
               $hr->setAttribute("size","5");
               $hr->setAttribute("noshade","");

          $onclick='{window.location.href="?scri=ctlg_item3&buscar='.$zcodigo.'&format='.$format.'"}';
          $onclick2='{window.location.href="?scri=ctlg_item3&lsub='.trim(substr($lsub_descri,0,40)).'&format='.$format.'"}';
          $onclick='';
          $onclick2='';
     
          if($zobj!=2)
          {
               if($zobj!=4 and $zobj!=5)
               {
//                     $xheader='';
//                     $xheader.=$zdocu.' - '.(int)$aso_filedocu['numero'];
//                     $xheader2='';
//                     $xheader2.=''.$aso_filedocu['iddet'];
//                     $xheader2.=' - '.$aso_filedocu['item_descri'];
                    
                    $span=$tcell->appendChild($domd0->createElement("a",htmlspecialchars($xheader)));
                              $span->setAttribute("name",'codigo');
                              $span->setAttribute("bold",'');
                              $span->setAttribute("onclick",$onclick);
                    
                    if(!empty($xheader2))
                    {
                         $div=$tcell->appendChild($domd0->createElement("div",htmlspecialchars($xheader2)));
                              $div->setAttribute("size80",'');
                              $div->setAttribute("bold",'');
                              $div->setAttribute("onclick",$onclick2);
                         
                    }
                    
//                     $div=$tcell->appendChild($domd0->createElement("div",$lsub_descri));
//                          $div->setAttribute("size80",'');
//                          $div->setAttribute("bold",'');
//                          $div->setAttribute("onclick",$onclick2);
               }

               $trow=$table->appendChild($domd0->createElement("tr",""));
//                echo '*/*/'.$zcodigo.$cfotos;
               if($cfotos==0)
               {$trow->setAttribute("style",'height:5em;');}
               if($cfotos>=1)
               {$trow->setAttribute("style",$trheight);}
               
               if($cfotos>1)
               {
                    $tcell=$trow->appendChild($domd0->createElement("td",""));
                         $tcell->setAttribute("width",'10%');
                         $tcell->setAttribute("style",$trheight);          
               }
          }

     
          // detail
//           if($zobj==2 and $zupld==1)
          if($zobj==2)
          {
               //input file
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("style","min-width:24em; text-align:left !important;");
               $tcell->setAttribute("colspan","9");
               
//                $tcell->setAttribute("align","left");
               
//                $div=$tcell->appendChild($domd0->createElement("div","CODIGO : ".$img_codigo));
               $div=$tcell->appendChild($domd0->createElement("span","".$xheader));
               $div->setAttribute("bold","");
               $div->setAttribute("style","color:".$empr0['empr_color1'].";");
               
               if(!empty($xheader2))
               {
               $div=$tcell->appendChild($domd0->createElement("span",' /'.$xheader2));
                    $div->setAttribute("bold",'');
                    $div->setAttribute("onclick",$onclick2);
               }

               
               if($ver_tallas==0)
               {
//                $div=$tcell->appendChild($domd0->createElement("div",""));
//                $input=$div->appendChild($domd0->createElement("input",""));
//                $input->setAttribute("id","ctlg".$zcodigo);
//                $input->setAttribute("type","checkbox");
//                $input->setAttribute("rel-left","");
//                if($item_ctlg==1)               
//                {$input->setAttribute("checked","");}
//                $input->setAttribute("onclick","save_chkbox('".$ztabla."','".$ztabla."_ctlg',".$zcodigo.",this.checked)");
//                $label=$div->appendChild($domd0->createElement("label","_Catálogo"));
//                     $label->setAttribute("for","ctlg".$zcodigo);
//                     $label->setAttribute("rel-left","");
//                $spant=$div->appendChild($domd0->createElement("div"," "));
//                $spant->setAttribute("style","height:1em;");
               }

               
               if($ver_tallas==2)
               {
                    msql_data_seek($res_tllas,0); 
                    $divt=$tcell->appendChild($domd0->createElement("div",""));
                    while($aso_tllas=msql_fetch_assoc($res_tllas))
                    {
                         if((int)$aso_tllas['item_tlla']>0 or ((int)$aso_tllas['item_tlla']==0 and $ctllas==1) )
                         {
                              $zcodigo_tlla=$aso_tllas['item_codigo'];

                              $input=$divt->appendChild($domd0->createElement("input",""));
                              $input->setAttribute("id","ctlg".$zcodigo_tlla);
                              $input->setAttribute("type","checkbox");
                              $input->setAttribute("rel-left","");
                              if($aso_tllas['item_ctlg']==1)               
                              {$input->setAttribute("checked","");}
                              $input->setAttribute("onclick","save_chkbox('".$ztabla."','".$ztabla."_ctlg',".$zcodigo_tlla.",this.checked)");
                              $label=$divt->appendChild($domd0->createElement("label","_".$aso_tllas['tlla_descri']));
                                   $label->setAttribute("for","ctlg".$zcodigo_tlla);
                              $label->setAttribute("rel-left","");
                              $label->setAttribute("nowrap","");
                              
                              $spant=$divt->appendChild($domd0->createElement("div","."));
                              $spant->setAttribute("rel-left","");
                              $spant->setAttribute("style","min-width:1em;");
                         }
                    }
                    $spant=$divt->appendChild($domd0->createElement("div"," "));
                    $spant->setAttribute("style","height:1em;");
               }
               /////////
               
//                $div=$tcell->appendChild($domd0->createElement("div"," "));
//                     $div->setAttribute("style","height:1em;");
//                $divf=$tcell->appendChild($domd0->createElement("div"," "));
//                $input=$tcell->appendChild($domd0->createElement("input",""));
//                $input->setAttribute("id","if".$zcodigo);
//                $input->setAttribute("type","file");
//                $input->setAttribute("hide","");
//                $input->setAttribute("multiple","");
//                $input->setAttribute("accept","filedocu/*");
//                $input->setAttribute("onchange","{document.getElementById('sf".$zcodigo."').value=this.files.length+' archivo(s)';}");
               
//                $label=$divf->appendChild($domd0->createElement("label","Seleccionar FotosX : "));
//                     $label->setAttribute("for","if".$zcodigo);
//                     $label->setAttribute("rel-left","");
               
//                $input=$divf->appendChild($domd0->createElement("input",""));     
//                     $input->setAttribute("id","sf".$zcodigo);
//                     $input->setAttribute("readonly","");
//                     $input->setAttribute("sel-file","");
//                     $input->setAttribute("onclick","{document.getElementById('if".$zcodigo."').click();}");
//                     $input->setAttribute("rel-left","");

//                $button=$divf->appendChild($domd0->createElement("button","Subir Archivos"));                         
//                     $button->setAttribute("btn-file","");
//                     $button->setAttribute("zoom80","");
//                     $button->setAttribute("onclick","upld_filedocu('".$ztabla."',".$zcodigo.",'if".$zcodigo."')");
//                     $button->setAttribute("rel-left","");

               
//                               $zdom=$domg;
//                               $zele=$tcell;
//                               $zobj=1;
//                               $zid='fdoc_'.$fdoc_docu.'_'.$fdoc_idnum.'_'.$fdoc_iddet;
//                               $zlabel='Subir Archivos';
//                               $ztype='file';
//                               $zmulti=1;
// //                               $zaccept='.xml,.txt,.pdf';
//                               $zaccept='.pdf,.doc,.png,.jpg,.jpeg';
//                               $zlabel2='';
//                               $zsize=0.8;
//                               $zalign='right';
//                               $zonclick2="{upld_filedocu('".$fdoc_docu."','".$fdoc_idnum."','".$fdoc_iddet."','".$zid."');}";
// //                               $zhide=1;
// //                               $zlabel2='🔼';
// //                               $zlabel2='📁';
//                               include('ele_input.php');
               
               
               
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               
               
//                echo '<br>*/*/*/'.$cfotos;
//                echo '<br>*/*/*/'.$ztabla;
//                echo '<br>*/*/*/'.$aso_filedocu[$ztabla.'_codigo'];
//                echo '<br>*/*/*/'.$aso_filedocu[$ztabla.'_file'];
//                if(empty($imgi_file) or empty($cfotos))
//                if(empty($aso_filedocu[$ztabla.'_file']) or empty($cfotos))
//                if(empty($cfotos))
               if($cfotos==0)
               {
                    $tcell=$trow->appendChild($domd0->createElement("td","NO Hay Archivos"));
                    $tcell->setAttribute('style','height:5em;');
               }
               
               
               
          }
               
          if($zobj==2 and $cfotos>=1)
          {
               if($zorient==0)
               {$trow=$table->appendChild($domd0->createElement("tr",""));}


//                     $tcell=$trow->appendChild($domd0->createElement("td",""));
//                     $tcell=$tcell->appendChild($domd0->createElement("span",""));
               
               
               msql_data_seek($res_filedocu,0);
               while($aso_filedocu=msql_fetch_assoc($res_filedocu))
               {
                    if($zorient==1)
                    {$trow=$table->appendChild($domd0->createElement("tr",""));}
                    $tcell=$trow->appendChild($domd0->createElement("td",""));
                    $tcell=$tcell->appendChild($domd0->createElement("span",""));
                    
                         $tcell->setAttribute("style",'width:auto');
                         $tcell->setAttribute("id",'td'.$aso_filedocu[$ztabla.'_codigo']);
//                          if($aso_filedocu[$ztabla.'_status']=='X')
                         if(empty($aso_filedocu[$ztabla.'_file']))
                         {$tcell->setAttribute("hide"," ");}
                    
                    if($zupld==1)
                    {
                         $div=$tcell->appendChild($domd0->createElement("div",""));                         
                         $div->setAttribute("style","border:1px;border-style:solid;border-color:black;background-color:".$empr0['empr_color2'].";");
                         $div->setAttribute("onclick","document.getElementById('rd".$aso_filedocu[$ztabla.'_codigo']."').click();");
                         $div->setAttribute("title","Fijar Principal");
                         
                         $radio=$div->appendChild($domd0->createElement("input",""));                         
                         $radio->setAttribute("type",'radio');
                         $radio->setAttribute("name",$zcodigo);
                         $radio->setAttribute("id","rd".$aso_filedocu[$ztabla.'_codigo']);
                         $radio->setAttribute("valign-t","");
                         if($aso_filedocu[$ztabla.'_defa']==1)
                         {$radio->setAttribute("checked","");}
                         $radio->setAttribute("onclick","defa_filedocu('".$ztabla."',".$aso_filedocu[$ztabla.'_codigo'].")");
                         $radio->setAttribute("tabindex","-1");
                         
//                          echo '<br>*/*/'.$aso_filedocu[$ztabla.'_defa'];
                    }

                    
                    if($zdele==1)
                    {
                         $div=$tcell->appendChild($domd0->createElement("div",""));                         
//                          $div=$tcell->appendChild($domd0->createElement("span",""));                         
                         $button=$div->appendChild($domd0->createElement("button","X"));                         
                         $button->setAttribute("tabindex","-1");
                         $button->setAttribute("btn-elim","");
                         $button->setAttribute("style","font-size:0.7em;");
                         $button->setAttribute("onclick","dele_filedocu('".$ztabla."',".$aso_filedocu[$ztabla.'_codigo'].")");
                    }
                    
                    
                    $div=$tcell->appendChild($domd0->createElement("div",""));                         
//                     $div=$tcell->appendChild($domd0->createElement("span",""));                         
                    $filedocu=$div->appendChild($domd0->createElement("img",""));
                         $filedocu->setAttribute("id",'img_'.$aso_filedocu[$ztabla.'_codigo']);
//                          $filedocu->setAttribute("src",'../'.$cfg_empr.'/'.$ztabla.'/'.$aso_filedocu[$ztabla.'_file']);
                         $filedocu->setAttribute("src",'//'.$file_server.'/'.$cfg_empr.'/'.$ztabla.'/'.$aso_filedocu[$ztabla.'_file']);
                    
                         $filedocu->setAttribute("style",'width:auto');
                         if($zorient==0)
                         {
//                               $filedocu->setAttribute("rel-left",'');
                              $filedocu->setAttribute("style",'max-width:'.intval(12*$zsize).'em;' );
                         }
                    
//                     if($zupld==1)
//                     if($zupld==1 or $zdele==1)
//                     {
//                          $div=$tcell->appendChild($domd0->createElement("div",""));                         
//                          $button=$div->appendChild($domd0->createElement("button","X"));                         
//                          $button->setAttribute("tabindex","-1");
//                          $button->setAttribute("btn-elim","");
//                          $button->setAttribute("onclick","dele_filedocu('".$ztabla."',".$aso_filedocu[$ztabla.'_codigo'].")");
//                     }
                    
                    
               }
          }

     
          if($zobj==2 and $zupld==1)
          {
//                //input file
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("colspan",3);
//                $div=$tcell->appendChild($domd0->createElement("div",$img_descri));
//                     if(strlen($img_descri)>40){$div->setAttribute("size80",'');}
//                     if(strlen($img_descri)>60){$div->setAttribute("size60",'');}
          }
               
//           echo '<br>==='.$sql_filedocu;
     
          if($zobj>2 and $cfotos>1)
          {    
               msql_data_seek($res_filedocu,0);
               while($aso_filedocu=msql_fetch_assoc($res_filedocu))
               {
//                     echo '<br>/*/*/*'.$aso_filedocu[$ztabla.'_file'];
//                     echo '<br>/*/*/*'.$file_server.'/'.$cfg_empr.'/'.$ztabla.'/'.$aso_filedocu[$ztabla.'_file'];
                    $div=$tcell->appendChild($domd0->createElement("div",""));
                    $filedocu=$div->appendChild($domd0->createElement("img",""));
                    $filedocu->setAttribute("src",'//'.$file_server.'/'.$cfg_empr.'/'.$ztabla.'/'.$aso_filedocu[$ztabla.'_file']);
                    $filedocu->setAttribute("onmouseover","{document.getElementById('".$zid."_img').src=this.src;}");
//                     $filedocu->setAttribute("onmouseover","{document.getElementById('".$zcodigo."_img').src=this.data;}");
                    $filedocu->setAttribute("style",'max-width:'.intval(4*$zsize).'em');
                    if(empty($aso_filedocu[$ztabla.'_file']))
                    {$tcell->setAttribute("hide"," ");}
               }
          }

          // main
          if($zobj!=2)
          {
//                msql_data_seek($res_filedocu,0);
//                $aso_filedocu=msql_fetch_assoc($res_filedocu);
//                $img_file=$aso_filedocu[$ztabla.'_file'];
//                $img_stat=$aso_filedocu[$ztabla.'_status'];
               
               msql_data_seek($res_filedocu,0);
               $aso_filedocu=msql_fetch_assoc($res_filedocu);
               $img_file=$aso_filedocu[$ztabla.'_file'];
               $img_stat=$aso_filedocu[$ztabla.'_status'];
               
//                echo '<br>'.$img_file;
//                if(empty($img_file))
               if(empty($img_file) or $img_stat=='X')
               {
                    $tcell=$trow->appendChild($domd0->createElement("td"," "));
                    $div=$tcell->appendChild($domd0->createElement("div"," "));
                         $div->setAttribute("style","height:1em;");
                    $div=$tcell->appendChild($domd0->createElement("div","Sin Foto"));
                         $div->setAttribute("style","height:2em;");
                         if($zobj==4)
                         {$div->setAttribute("style","height:2em; width:21em;");}
                    $div=$tcell->appendChild($domd0->createElement("div"," "));
                         $div->setAttribute("style","height:1em;");
               }
               else
               {
                    $tcell=$trow->appendChild($domd0->createElement("td",""));
                         if($cfotos>1)
                         {$tdstyle.='min-width:'.intval(17*$zsize).'em;';}
                         else
                         {$tdstyle.='min-width:'.intval(21*$zsize).'em;';}
                         if($zobj==5)
                         {$tdstyle='width:'.intval(7*$zsize).'em; ';}
                    
                         if($zfixh==1)
                         {$trow->setAttribute("style","height:".intval(28*$zsize)."em;");}
                    
                         $tcell->setAttribute("style",$tdstyle);

                    
                    $filedocu=$tcell->appendChild($domd0->createElement("img",""));   
                         $filedocu->setAttribute("id",$zid.'_img');
                         $filedocu->setAttribute("ondblclick","{_clickfdoc('".$zdocu."','".$zidnum."','".$aso_filedocu['iddet']."');}");
                         $filedocu->setAttribute("src",'//'.$file_server.'/'.$cfg_empr.'/'.$ztabla.'/'.$img_file);
                         $istyle='width:'.intval(21*$zsize).'em; ';

//                     $filedocu=$tcell->appendChild($domd0->createElement("object",""));   
//                          $filedocu->setAttribute("id",$zid.'_pdf');
//                          $filedocu->setAttribute("ondblclick","{_clickfdoc('".$zdocu."','".$zidnum."','".$aso_filedocu['iddet']."');}");
// //                          $filedocu2->setAttribute("src",'//'.$file_server.'/'.$cfg_empr.'/'.$ztabla.'/'.$img_file);
// //                          $istyle='width:'.intval(21*$zsize).'em; ';

//                          $filedocu->setAttribute("data",'//'.$file_server.'/'.$cfg_empr.'/'.$ztabla.'/'.$img_file);
//                          $filedocu->setAttribute("type",'application/pdf');
//                          $filedocu->setAttribute("width",'100%');
// //                          $filedocu2->setAttribute("height",'100px');
                    
                    
// <object data="/uploads/media/default/0001/01/540cb75550adf33f281f29132dddd14fded85bfc.pdf" type="application/pdf" width="100%" height="500px">
//       <p>Unable to display PDF file. <a href="/uploads/media/default/0001/01/540cb75550adf33f281f29132dddd14fded85bfc.pdf">Download</a> instead.</p>
//     </object>                    
                    
//                          if($zfixh==1)
                    
                    
                         if($zobj==5)
                         {$istyle='width:'.intval(4*$zsize).'em; ';}
                         $filedocu->setAttribute("style",$istyle);
                    
//                          if(!empty($zfixh))
//                          {
//                               $istyle='width:auto; ';
//                               $istyle.='height:'.intval(12*$zsize).'em; ';
// //                               $istyle.='max-height:'.intval(21*$zsize).'em; ';
// //                               $istyle.='min-height:'.intval(4*$zsize).'em;';
//                          }
                    
                    
               }
          }

          // foot
          msql_data_seek($res_filedocu,0);
          $aso_filedocu=msql_fetch_assoc($res_filedocu);

          if($zobj==4 or $zobj==5)
          {$tcell=$trow->appendChild($domd0->createElement("td",""));}
     
               if($cfotos>1)
               {$tdstyle='min-width:'.intval(17*$zsize).'em;';}
               else
               {$tdstyle='min-width:'.intval(21*$zsize).'em;';}
     
               if($zobj==5)
               {$tdstyle='width:'.intval(21*$zsize).'em;';}

//                if($zobj==2 and $zupld==1)
               if($zobj==2 and $zorient==0)
               {$tdstyle='width:auto';}

               $tcell->setAttribute("style",$tdstyle);
     
//           if($zobj!=2)
          {
               if($zobj==4 or $zobj==5)
               {
                    $span=$tcell->appendChild($domd0->createElement("a",'CODIGO : '.$img_codigo));
                              $span->setAttribute("name",'codigo');
                              $span->setAttribute("bold",'');
                              $span->setAttribute("onclick",$onclick);

                    $div=$tcell->appendChild($domd0->createElement("div",' '.$lsub_descri));
                         $div->setAttribute("bold",'');
                         $div->setAttribute("style",'min-height:'.intval(4*$zsize).'em;');
                         $div->setAttribute("onclick",$onclick2);
               }

               if($zobj==5)
               {
                    $tcell=$trow->appendChild($domd0->createElement("td",""));
                    $tdstyle='width:'.intval(21*$zsize).'em; ';
                    $tcell->setAttribute("style",$tdstyle);
               }

               //DESCRIPCION
               if($zobj!=2 or $zupld==1)
               {

               $div=$tcell->appendChild($domd0->createElement("div",'CANT : '.number_format($zcant,2)));
                    $div->setAttribute("bold","");
                    $div->setAttribute("size80","");
               $div=$tcell->appendChild($domd0->createElement("div",htmlspecialchars($zdescri2)));
                    $div->setAttribute("id",$zid.'_desc');
               if($zobj==4)
               {$div->setAttribute("style",'min-width:'.intval(21*$zsize).'em;'.'min-height:'.intval(4*$zsize).'em;');}
               else
               {
                    if(strlen($img_descri)>40){$div->setAttribute("size80",'');}
                    if(strlen($img_descri)>60){$div->setAttribute("size60",'');}
               }

               // ADICIONALES
               if(!empty($kldd_descri))
               {
                    $div=$tcell->appendChild($domd0->createElement("div",''.$kldd_descri.' /'.$item_composi));
                         if($zobj==4)
                         {$div->setAttribute("style",'min-height:'.intval(2*$zsize).'em;');}
                         else
                         {$div->setAttribute("size80",'');}
                         $div->setAttribute("italic",'');
               }

               if(strlen($clor_descri)>=3)
               {
                    $xclor='COLOR : '.$clor_descri;
                    if($zsize<1){$xclor=$clor_descri;  }
                    $div=$tcell->appendChild($domd0->createElement("div",$xclor));
                    $div->setAttribute("size80",'');
                    if(!empty($clor_hexa))
                    {
                         $div->setAttribute("bold",'');
                         $div->setAttribute("style",'border:4px solid;border-color:'.$clor_hexa.';');
                    }                         
               }

               if(!empty($tlla_descri2))
               {
                    $div=$tcell->appendChild($domd0->createElement("div",'TALLAS : '.$tlla_descri2));
                    if($zobj==4)
                    {$div->setAttribute("style",'min-height:'.intval(2*$zsize).'em;');}
                    else
                    {$div->setAttribute("size80",'');}
               }

//                     echo '*/*/*'.$zstockv;
               if(!empty($zstockv))
               {
                    $alertmsg='';
                    $sstyle='';
                    $maxcarr=(int)$zstock;
                    if($zstock>0)
                    {
                         if($zstockv==1){$valstock='STOCK : '.number_format($zstock,$item_duni).' '.$item_umdd;}
                         if($zstockv>=2){$valstock='DISPONIBLE';}
                         if($zstockv==3){$alertmsg="{_clickdispon('".$zid."_desc','".number_format($zstock,$item_duni).' '.$item_umdd."');}";}
                    }
//                     else{$valstock='NO DISPONIBLE'; $sstyle='color:darkred;';}

                    $div=$tcell->appendChild($domd0->createElement("div",$valstock));
                         if($zobj==4)
                         {$div->setAttribute("style",'min-height:'.intval(3*$zsize).'em;');}
                         else
                         {$div->setAttribute("size80",'');}
                         $div->setAttribute("bold",'');
                         if(!empty($sstyle))
                         {$div->setAttribute("style",$sstyle);}
                         if(!empty($alertmsg))
                         {
                              $div->setAttribute("unselect",'');
                              $div->setAttribute("onclick",$alertmsg);
                         }
               }

               if(!empty($xprecio))
               {
                    $lblprecio='PVP : $ '.number_format($xprecio,$item_dpre);;
                    if(mb_stristr($zprecio,'puni')){$lblprecio='P.Uni : $ '.number_format($xprecio,$item_dpre).' +imp.';}
                    $div=$tcell->appendChild($domd0->createElement("div",$lblprecio))     ;
                         if($zobj==4)
                         {$div->setAttribute("style",'min-height:'.intval(3*$zsize).'em;');}
                         else
                         {$div->setAttribute("size80",'');}
                         $div->setAttribute("bold",'');
               }

               if(!empty($zcarr) and !empty($user_codigo))
               {
                    if($zobj==5)
                    {
                         $tcell=$trow->appendChild($domd0->createElement("td",""));
                         $tdstyle='width:'.intval(21*$zsize).'em; ';
                         $tcell->setAttribute("style",$tdstyle);
                    }

                    if($ver_tallas==0)
                    {
                         $sql_carr ='select cant from carr1 ';
                         $sql_carr.='left join carr2 on idnum1=idnum2 ';
                         $sql_carr.='left join item0 on item=item_codigo ';
                         $sql_carr.='where iuser="'.$user_codigo.'" ';
                         $sql_carr.='and item like "'.$zcodigo.'%"';
                         $sql_carr.='and docu like "'.$zdcarr .'%"';
                         $res_carr=msql_query($sql_carr,$link_data);
                         $cantcarr=msql_result($res_carr,0,'cant');
                         $idcantcarr=$zid.'_cant';

                         if(empty($item_umdd) or substr($item_umdd,0,2)=='UN')
                         {$cantcarr=(int)$cantcarr;}

          //                if($maxcarr>0)
                         {
                         $divt=$tcell->appendChild($domd0->createElement("div"," "));
//                               $divt->setAttribute("autocomplete","off");
//                               $divt->setAttribute("flex-center","");
                                                            
//                          $div=$divt->appendChild($domd0->createElement("label","Carrito : "));
//                               $div->setAttribute("for",$idcantcarr);
//                               $div->setAttribute("valign-m","");
                              
                         $button=$divt->appendChild($domd0->createElement("button","-"));
                              $button->setAttribute("onclick","$(this).next()[0].stepDown();$(this).next()[0].oninput();");
                              $button->setAttribute("valign-t","");
                              $button->setAttribute("style","width:3em;height:2em;");
                              
                         $div=$divt->appendChild($domd0->createElement("input",""));
                              $div->setAttribute("id",$idcantcarr);
                              $div->setAttribute("type","number");
                              $div->setAttribute("value",$cantcarr);
                              $div->setAttribute("autocomplete","off");
                              $div->setAttribute("cantcarr","");
                              $div->setAttribute("min","0");
                              $div->setAttribute("max",$maxcarr);
                              $div->setAttribute("oninput","{save_carr('".$zcodigo."',this.value);}");
                              $div->setAttribute("onchange","{val_minmax(this.id)}");
                              
                         $button=$divt->appendChild($domd0->createElement("button","+"));
                              $button->setAttribute("onclick","$(this).prev()[0].stepUp();$(this).prev()[0].oninput();");
                              $button->setAttribute("valign-t","");
                              $button->setAttribute("style","width:3em;height:2em;");
                              
                         }

                    }

                    if($ver_tallas==2)
                    {
                         msql_data_seek($res_tllas,0); 
                         while($aso_tllas=msql_fetch_assoc($res_tllas))
                         {
                              if((int)$aso_tllas['item_tlla']>0 or ((int)$aso_tllas['item_tlla']==0 and $ctllas==1) )
                              {
                              $sql_carr ='select cant from carr1 ';
                              $sql_carr.='left join carr2 on idnum1=idnum2 ';
                              $sql_carr.='left join item0 on item=item_codigo ';
                              $sql_carr.='where iuser="'.$user_codigo.'" ';
                              $sql_carr.='and item like "'.$aso_tllas['item_codigo'].'%"';
                              $res_carr=msql_query($sql_carr,$link_data);
                              $cantcarr=msql_result($res_carr,0,'cant');
                              $idcantcarr=$zid.'_cant';

                              if(empty($item_umdd) or substr($item_umdd,0,2)=='UN')
                              {$cantcarr=(int)$cantcarr;}

                              $divt=$tcell->appendChild($domd0->createElement("div"," "));
//                               $divt->setAttribute("style","margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:".$zsize*(0.0)."em; position:relative;float:left;");
                              $divt->setAttribute("style","margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:".$zsize*(0.0)."em;");
                              $divt->setAttribute("rel-left","");

                              $div=$divt->appendChild($domd0->createElement("label",$aso_tllas['tlla_descri']));
                                   $div->setAttribute("for",$idcantcarr);
                                   
                              $button=$divt->appendChild($domd0->createElement("button","+"));
                                   $button->setAttribute("onclick","$(this).next()[0].stepUp();$(this).next()[0].oninput();");
                                   $button->setAttribute("valign-t","");
                                   $button->setAttribute("style","width:4em;height:2em;display:block;color:grey;");
                                   
                              $div=$divt->appendChild($domd0->createElement("input",""));
                                   $div->setAttribute("cantcarr","");
                                   $div->setAttribute("id",$idcantcarr);
                                   $div->setAttribute("type","number");
                                   $div->setAttribute("min","0");
                                   $div->setAttribute("max","99");
                                   $div->setAttribute("value",$cantcarr);
                                   $div->setAttribute("oninput","{save_carr('".$aso_tllas['item_codigo']."',this.value);}");
                                   $div->setAttribute("style","width:3em;margin-bottom:0em;");
                                   $div->setAttribute("autocomplete","off");
                                   
                              $button=$divt->appendChild($domd0->createElement("button","-"));
                                   $button->setAttribute("onclick","$(this).prev()[0].stepDown();$(this).prev()[0].oninput();");
                                   $button->setAttribute("valign-t","");
                                   $button->setAttribute("style","width:4em;height:2em;display:block;color:grey;");
                              
                                   
                              }

                         }
                    }

                    if($ztotpvp>0)
                    {
                         $div=$tcell->appendChild($domd0->createElement("div",'Sub-Tot : $ '.number_format($ztotpvp,2)));
                         $div->setAttribute("bold"," ");
                         $div->setAttribute("style","clear:both;");
                         $div->setAttribute("onclick","{location.reload();}");
                    }

               }

                    
               }

          }

          $trow=$table->appendChild($domd0->createElement("tr",""));
          $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("colspan",'99');
     //           $tcell->setAttribute("style",'height:1em;');
//           $hr=$trow->appendChild($domd0->createElement("hr",""));
          $hr=$tcell->appendChild($domd0->createElement("hr",""));
               $hr->setAttribute("size","4");
               $hr->setAttribute("noshade","");
               if($zobj==5)
               {$hr->setAttribute("hide"," ");}

          if(empty($zdom))
          {
               if($zxml==1){$zxml=$domd0->saveXML();}
               else{echo $domd0->saveXML();}
          }     

}

include ('ele_reset.php');

?>



