<?php ob_start(); ?>
<?php $mobile= $_SESSION['user_mobile'];?>
<?php $touchs= $_SESSION['user_touchs'];?>
<?php $osver= $_SESSION['osver'];?>

<?php include('../_cfg/config.php'); ?>


<?php  
  $hlinker1=date('H:i:s');
?>

<?php if(empty($pdocu)){$pdocu='';}?>
<?php if(empty($ptabla)){
      $sql_gettab='select * from docu0 where docu_status!="X" and docu_codigo like "'.$pdocu.'%" order by docu_codigo';
      $res_gettab=msql_query($sql_gettab,$link_vcrx);
//       if(!msql_error()){$ptabla=@msql_result($res_gettab,0,'docu_tabla').'1';}
      if(!msql_error($link_vcrx)){$ptabla=@msql_result($res_gettab,0,'docu_tabla').'';}
}?>

<?php if(empty($pidtxt) and !empty($pdocu)){$pidtxt='dl_'.$pdocu;}?>
<?php if(empty($pidtxt) and !empty($ptabla)){$pidtxt='dl_'.$ptabla;}?>
<?php if(empty($pcolu)){$pcolu=$ptabla.'_codigo,'.$ptabla.'_descri';}?>
<?php if(empty($pwhere)){$pwhere="";}?>
<?php if(empty($pclass)){$pclass="";}?>

<?php

if(mb_stristr($pcolu,','))
{
  $pvalue=substr($pcolu,0,strpos($pcolu,','));
  $poption=substr($pcolu,strpos($pcolu,',')+1);
//   if($poption==''){$pvalue=$pcolu;$poption=$pcolu;}
//   else{$pvalue=substr($pcolu,0,strpos($pcolu,','));}
}
else
{$pvalue=$pcolu; $poption=$pcolu;}

$dlok=0;

// 	if($pdatalist==2)
	$sql_list='select distinct ';
// 	if(mb_stristr('enti',$ptabla))
	$sql_list.= $pvalue.',';
	$sql_list.= $poption.',';
	$sql_list.='concat('.str_replace(',','," .",',$poption).') as datalist, ';

	if(mb_stristr('item',$ptabla) and $pcolu=='')
	{
  	$sql_list.= $ptabla.'_codigov as codigov, ';
  	$sql_list.= $ptabla.'_puni as puni, ';
  	$sql_list.= $ptabla.'_pvp1 as pvp1, ';
//   	$sql_list.= 'tlla_descri as talla, ';
//   	$sql_list.= 'color_descri as color, ';
  }
    
	if(mb_stristr('item.enti',$ptabla) and $pcolu=='')
	{
		$sql_list.= 'year('.$ptabla.'_lused) as fanio,';
		$sql_list.= 'month('.$ptabla.'_lused) as fmes, ';
	}
    
	if($pdocu!='')
	{
		$sql_list.= 'year(fecha) as fanio, ';
		$sql_list.= 'month(fecha) as fmes, ';
	}
    
	$sql_list.= $ptabla.'_status as status ';

	$sql_list.=' from '.$ptabla.'0 ';
	if(mb_stristr('item',$ptabla))
	{
// 		$sql_list.= 'left join tlla0 on item_tlla=tlla_codigo ';
// 		$sql_list.= 'left join clor0 on item_clor=clor_codigo ';
	}

	$sql_list.=' where '.$ptabla.'_status!="X" ';
	$sql_list.=' and '.$ptabla.'_status!="I" ';
	if(mb_stristr('item.enti',$ptabla) and $pcolu=='')
     {$sql_list.=' and '.$ptabla.'_descri not like "%<LINK%" ';}
// 	$sql_list.=' and '.$ptabla.'_descri not like "%***%" ';
  if($pwhere!=""){$sql_list.=' and '.$pwhere.' ';}
//   if($pwhere!=""){$sql_list.=' '.$pwhere.' ';}
// 	$sql_list.=' and '.$ptabla.'_status!="I" ';

  if(!empty($pdocu))
  {
    $fecha0=date('Y-m-1',strtotime('-1 month'));
    $sql_list.=' and docu like "'.$pdocu.'%" ';
    $sql_list.=' and '.$pcolu.'!=""  ';
    $sql_list.=' and '.$pcolu.' is not null  ';
//     $sql_list.=' and fecha>="'.$fecha0.'"';
  }

	if($cfg_tipo=='cong')
	{if($pdocu!='DPU2' and $pdocu!=''){$sql_list.=' and cong="'.$_SESSION['cong_codigo'].'" ';}}


	if(mb_stristr('item.enti',$ptabla) and $pcolu=='')
	{
		$lyear=strtotime('-12 month');
		$lyear=date('Y-m-'.'01',$lyear);
		$sql_list.=' and '.$ptabla.'_lused>="'.$lyear.'" ';
	}

	if($pdocu!='')
	{
		$lyear=strtotime('-12 month');
  	if(mb_stristr('DPU1.DPU2',$pdocu))
    {$lyear=strtotime('-120 month');}
		$lyear=date('Y-m-'.'01',$lyear);
		$sql_list.=' and fecha>="'.$lyear.'" ';
	}


	if($pdocu!='')
	{$sql_list.= 'group by '.$pvalue;}


  $xorder=' order by '.$poption;

	if(mb_stristr('item.enti',$ptabla) and $pcolu=='')
	{$xorder=' order by fanio desc, fmes desc,'.$ptabla.'_descri';}	

// 	else
	{
  if(mb_stristr('docu',$ptabla))
  {$xorder=' order by '.$ptabla.'_tabla,'.$ptabla.'_codigo';}	
    
  if(mb_stristr('ctas.suco.cair.fpag.cntn.vhcl.',$ptabla))
  {$xorder=' order by '.$ptabla.'_codigo';}	
    
  if(mb_stristr('tlla.asub',$ptabla))
  {$xorder=' order by '.$ptabla.'_codigo';}	
    
  if(mb_stristr('orat.bsqj',$ptabla))
  {$xorder=' order by '.$ptabla.'_codigo';}	
    
    
	}


  $sql_list.=$xorder;

// if($plimit==0 and mb_stristr('item',$ptabla)){$plimit=1000;}


  if($plimit>0)
  {$sql_list.=' limit '.$plimit;}

	if(mb_stristr('item.enti',$ptabla))
	{
	}
		
	$res_list=msql_query($sql_list,$link_vcrx);

		if(!msql_error($link_vcrx)){$dlok=1;}
		else
		{
			$sql_list=str_replace($ptabla.'0 ',$ptabla.'00 ',$sql_list);
			$res_list=msql_query($sql_list,$link_vcrx);

      if(!msql_error($link_vcrx)){$dlok=1;}
			else
			{
				$sql_list=str_replace($ptabla.'00 ',$ptabla.'1 ',$sql_list);
				$sql_list=str_replace('_codigo','',$sql_list);
				$sql_list=str_replace($ptabla.'_status','status',$sql_list);
				$sql_list=str_replace('and status!="I"',$sql_list1,$sql_list);
				$res_list=msql_query($sql_list,$link_vcrx);

				if(!msql_error($link_vcrx)){$dlok=1;}
				else
				{
					$sql_list=str_replace($ptabla.'1 ',$ptabla.'12 ',$sql_list);
					$res_list=msql_query($sql_list,$link_vcrx);

					if(!msql_error($link_vcrx)){$dlok=1;}
				}
			}
		}
  

 ?>

<span>
     <?php //echo '*/*/*/'.$osver; ?>
<datalist id="<?php echo $pidtxt; ?>" name="<?php echo $pidtxt; ?>" style="display:none; font-family:arial;">
<?php
  echo '<options>';  
//   echo '**/*'.$sql_list;
  msql_data_seek($res_list,0);
	while($aso_list=msql_fetch_assoc($res_list))
	{
		$option='';
    $xvalue=trim($aso_list[$pvalue]);
    $xoption=trim($aso_list['datalist']);
//     if(mb_stristr($xoption,'***')){$xoption='';}
    if(mb_stristr($xoption,'->')){$xoption='';}
    if(!empty($xoption))
    {
//       if(mb_stristr($xvalue,'.') and ($xvalue*1)!=0){$xvalue=rtrim($xvalue,'0'); $xvalue.='0';}
//       if(mb_stristr($xoption,'.') and ($xoption*1)!=0){$xoption=rtrim($xoption,'0'); $xoption.='0';}
      if(mb_stristr($xvalue,'.') and ((int)$xvalue)!=0){$xvalue=rtrim($xvalue,'0'); $xvalue.='0';}
      if(mb_stristr($xoption,'.') and ((int)$xoption)!=0){$xoption=rtrim($xoption,'0'); $xoption.='0';}
      if(mb_stristr($osver,'Edg')){$xvalue.='=>'.$xoption; $xoption='';}
      $xdisabled='';
      $xoptgroup=0;
//       if($ptabla=='ctas')
      if($ptabla=='ctas' and $pctadet==1)
      {if(ctas_deta($xvalue)){$xoption='-->'.$xoption;}}
         
//       if($xoptgroup==1)
//          {$option.='<optgroup label="'.$xvalue.'-'.$xoption.'">';}
//          else
         {$option.='<option value="'.$xvalue.'" '.$xdisabled.'>';}
//       $option.='---';
          $option.=$xoption;
          if($ptabla=='item' and $aso_list['codigov']!='')
          {$option.=' ('.$aso_list['codigov'].')';}
          else
          {$option.=' ('.$aso_list['codigo'].')';}

         
         
//       if($xoptgroup==1)
//          {$option.='</optgroup>';}
//          else
         {$option.='</option>';}
         
      echo $option;
    }
	}	
  echo '</options>';  
?>	
</datalist>
</span>

<?php  
  $hlinker2=date('H:i:s');
  $hdif=date("H:i:s", strtotime("00:00:00") + strtotime($hlinker2) - strtotime($hlinker1) );

// echo '<br>';
// echo '<br> HS:'.$pidtxt.$dlok.' - '.$hdif;
// echo '<br> SQL:'.$sql_list;
?>


<?php $pdatalist=0;?>
<?php $pphold='';?>
<?php $preado='';?>
<?php $pdisab='';?>
<?php $pcaption='';?>
<?php $ptabla='';?>
<?php $pdocu='';?>
<?php $pvalue='';?>
<?php $poption='';?>
<?php $pidtxt='';?>
<?php $plong='';?>
<?php $pobj='';?>
<?php $ponblur='';?>
<?php $ponchange='';?>
<?php $pnotob='';?>
<?php $pdefa='';?>
<?php $psize='';?>
<?php $pcolu='';?>
<?php $phide=0; ?>
<?php $pexact=0; ?>
<?php $pctadet=0; ?>
<?php $pclass='';?>
<?php $pwhere='';?>
<?php $obstart = ob_get_clean(); ?>
<?php //$obstart=alltrim($obstart); ?>
<?php $obstart = limpiahtml($obstart) ?>

<?php echo $obstart; ?>


