<?php ob_start(); ?>

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

<?php $pbground='#D4FEF9'; ?>

<?php if(file_exists('../_cfg/config.php')){include('../_cfg/config.php');} ?>

<?php if($pidtxt==''){$pidtxt=$ptabla;}?>
<?php if(empty($pidtxt)){$pidtxt=$ptabla;}?>
<?php if(empty($pcaption)){$pcaption=$pidtxt;}?>
<?php if(empty($pphold) and $pobj==1 and $pcaption!=$pidtxt){$pphold=$pcaption;}?>
<?php if(empty($pphold) and $pobj==1){$pphold=$pdefa;}?>
<?php if(empty($ponblur)){$ponblur="";}?>
<?php if(empty($pwhere)){$pwhere="";}?>
<?php if(empty($pclass)){$pclass="";}?>
<?php if(empty($ponchange)){$ponchange="";}?>
<?php if(empty($pnotob)){$pnotob="";}?>
<?php if(empty($pdisab)){$pdisab="";}?>
<?php if(empty($pobj)){$pobj=3;} ?>
<?php if(empty($psize)){$psize=12;} ?>
<?php if(empty($pexact)){$pexact=0;} ?>
<?php if(empty($phide)){$phide=0;} ?>
<?php if(empty($preado)){$preado=0;} ?>
<?php if(empty($pdldown)){$pdldown=2;} ?>
<?php if($pobj>6){$pobj=3;} ?>
<?php if(empty($pcolu)){$pcolu=$ptabla.'_codigo,'.$ptabla.'_descri,'.$ptabla.'_codigo';} ?>
<?php if($preado==1){$pdldown=-0.5;} ?>
<?php if(empty($plist)){$plist='';}?>
<?php if(empty($pvalue)){$pvalue=$pdefa;} ?>
<?php if(empty($ptitle) and !empty($pvalue)){$ptitle=r_fiel($ptabla,$pvalue);}?>
<?php if(empty($ptitle)){$ptitle=strtolower($pcaption);}?>
<?php $plong1=$plong; ?>

<?php
if(empty($pvalue) and $ptabla=='lsub')
{
  if($cfg_empr=='saar'){$pvalue='ELED-';}
  if($cfg_empr=='hfre'){$pvalue='INAG-';}
  if($cfg_empr=='orel'){$pvalue='ELCA-';}
}



?>



<?php
		$sql_getcod='describe '.$ptabla.'0';
		$res_getcod=msql_query($sql_getcod,$link_vcrx);
		if(!msql_error($link_vcrx))	
		{
// echo '<br>****'.print_r($res_getcod);
			$plong=msql_result($res_getcod,0,'type');
// echo '<br>======'.$plong;
			$plong=str_replace(')','',$plong);
			$plong=str_replace('varchar(','',$plong);
			$plong=str_replace('char(','',$plong);
			$plong=str_replace('int(','',$plong);
      
                if($plong<=4){$plong=$plong+1;}
		}

	$plimit='999999';
	$rdatalist=0;
// 	if(mb_stristr('enti.item',$ptabla) and $plist=='dl'.$pidtxt)
	if(mb_stristr('enti.item',$ptabla))
	{
		$fecha2=date('Ymd',strtotime('-12 month'));
		$coun_sql ='select count(*) as contador from '.$ptabla.'0 ';
		$coun_sql.=' where '.$ptabla.'_lused>="'.$fecha2.'"';
// 		$coun_res=msql_query($coun_sql,$link_vcrx);
// 		$contador=msql_result($coun_res,0,'contador');
		if($contador>1000 and  1==1)
		{
// 			$plimit='100';
// 			$rdatalist=1;
		}
		$pdldown=2;
	}

	if(!mb_stristr('enti.item',$ptabla))
	{
		$sql_updt ='updtate '.$ptabla.'0 set ';
		$sql_updt.=' '.$ptabla.'_status="-"';
		$sql_updt.=' where ('.$ptabla.'_status="" or '.$ptabla.'_status=null)';
    $res_updt=msql_query($sql_updt,$link_vcrx);
	}


//   if($preado==0)
  {$plong=$plong+$pdldown;}
//   {$plong=$plong+1;}//search
?>

<?php
$pdefad='';
if ($pdefa=='')
{
	if(mb_stristr('caja.ctab.bode',$ptabla))
	{
// 		$defa_sql='select * from '.$ptabla.'0 order by '.$ptabla.'_lused desc limit 1';
// 		$defa_res=msql_query($defa_sql,$link_vcrx);
// 		if(msql_num_rows($defa_res)!=0)
// 		{
// 			$pdefa=msql_result($defa_res,0,$ptabla.'_codigo');
// 			$pdefad=msql_result($defa_res,0,$ptabla.'_descri');
// 		}
	}
}
else
{
	$defa_sql='select * from '.$ptabla.'0 where '.$ptabla.'_codigo="'.$pdefa.'"';
	$defa_res=msql_query($defa_sql,$link_vcrx);
	if(msql_num_rows($defa_res)!=0){$pdefad=msql_result($defa_res,0,$ptabla.'_descri');}
}


?>


<?php $pphold=ucwords(strtolower($pphold));?>
<?php $pwhere=trim($pwhere); ?>
<?php if(substr($pwhere,0,1)=='('){$pwhere=' and'.$pwhere;} ?>

<?php if($pobj==2 or $pobj==4){?>
<th id="th_<?php echo $pidtxt; ?>" class="<?php echo $pclass; ?>" width="<?php echo $plong; ?>px" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>
<?php if($pobj==3 or $pobj==6){?>
<td id="td_btn<?php echo $pidtxt; ?>" class="<?php echo $pclass; ?>" align="right" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>
<div class="<?php echo $pclass; ?>" >
<?php if($pobj!=1 and $pobj!=5){?>
	<input type="button" 
         class="getcod_btn"
         id="<?php echo $pidtxt; ?>_btn" 
         onClick="
                  {_defacod(event,'<?php echo $pidtxt;?>','<?php echo $pdefa;?>');}
									<?php if($pexact==0 and 1==2) {?>
									list_codigo('<?php echo $pidtxt; ?>','<?php echo $ptabla ?>','<?php echo $pidtxt; ?>','<?php echo $pidtxt; ?>_descri');
									<?php } ?>
									<?php echo $ponclick;?>" 
				 tabIndex="-1"
         style="
								min-width:<?php echo strlen($pcaption)*$psize-$psize;?>px;
								font-size:<?php echo $psize;?>px;
								<?php if($pobj==1 or $pobj==5){echo 'display:none;';} ?>
								" 
         value="<?php echo ($pcaption) ?>"
				 /></input>
<?php } ?>    
	</div>
<?php if($pobj==3 or $pobj==6){?>
</td>
<td id="td_txt<?php echo $pidtxt; ?>" class="<?php //echo $pclass; ?>" align="left" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>
	<div class="<?php echo $pclass; ?>" style="" >
	<?php $ptype='search'; ?>	
	<?php if($pexact==1 and mb_stristr('enti.item.cntn.tlfn',$ptabla) and $mobile=='true'){$ptype='number';}?>	
    
<?php if($pobj==2 or $pobj==4){?>
<!-- <div style="float:center;position:;"> -->
<?php }else{ ?>  
<!-- <div style="float:left;position:;"> -->
<?php } ?>  
  
<?php if($pobj==1){?>
<td id="td_txt<?php echo $pidtxt; ?>" class="<?php echo $pclass; ?>" align="left" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>
<!-- 				 accesskey="<?php //echo substr($pcaption,0,1)?>" -->

  <input
         value="<?php echo $pvalue;?>" 
         type="<?php echo $ptype; ?>" 
         class="getcod_txt"
				 <?php if($preado==1){echo ' readonly ';}?>
				 <?php if(mb_stristr('modu.docu.enti.user',$ptabla) or mb_stristr('USUARIO',strtoupper($pcaption)) ){echo ' autofocus ';}?>
				 autocomplete="off"
         id="<?php echo $pidtxt; ?>"  
         name="<?php echo $pidtxt; ?>"  
				 onchange ="
										{this.oninput();}
										<?php echo $ponchange;?>;
                    _valcod(event,'<?php echo $pidtxt;?>','<?php echo $ptabla;?>','<?php echo $pnotob;?>');
										" 
				 onclick =""
         onfocus="{this.style.background='<?php echo $pbground;?>';}"
				 onblur ="<?php echo $ponblur;?>;{this.style.background='white';}" 
         onKeyUp="
									_okupcod(event,'<?php echo $pidtxt;?>','<?php echo $ptabla;?>','<?php echo $pnotob;?>');
									<?php if($rdatalist==1){?>
									_datalist(event,'<?php echo $pidtxt;?>');
									<?php } ?>
                  <?php if($pobj>1){?>
									if(document.getElementById('<?php echo $pidtxt;?>').value.length<<?php echo $plong-4;?>)
									{document.getElementById('<?php echo $pidtxt;?>_descri').innerHTML='';}
                  <?php } ?>
									" 
				 oninput="_onincod(event,'<?php echo $pidtxt;?>');
                  <?php if(1==2){?>
										{
										if(document.getElementById('<?php echo $pidtxt;?>').value.indexOf('/')>0)
										{
											sel_data=document.getElementById('<?php echo $pidtxt;?>').value;
											document.getElementById('<?php echo $pidtxt;?>').value=sel_data.substring(sel_data.indexOf('//')+2); 
											document.getElementById('<?php echo $pidtxt;?>_descri').innerHTML=sel_data.substring(0,sel_data.indexOf('//'));
										}
										if(document.getElementById('<?php echo $pidtxt;?>').value.indexOf('=>')>0)
										{
											sel_data=document.getElementById('<?php echo $pidtxt;?>').value;
											document.getElementById('<?php echo $pidtxt;?>').value=sel_data.substring(0,sel_data.indexOf('=>')); 
											document.getElementById('<?php echo $pidtxt;?>_descri').innerHTML=sel_data.substring(sel_data.indexOf('=>')+2);
										}
										}
                  <?php } ?>
								  "
				 <?php if($pexact==0){?>
				 list="<?php if($plist!=''){echo $plist;}else{echo 'dl'.$pidtxt;} ?>"
				 <?php } ?>
				 <?php if($pdisab=='1'){?> disabled <?php } ?>
                    style="
								font-size:<?php echo $psize+2;?>px;
								width:<?php if(mb_stristr($plong,'%;')){echo $plong;}else{echo ($plong*$psize*.8+$psize).'px;';}?>;
								"
         <?php if($pphold!=""){echo 'placeholder="'.$pphold.'"';}?>
				 title="<?php echo $ptitle; ?>" 
				 ctadet="<?php echo $pctadet; ?>" 
         exact="<?php echo $pexact; ?>"
				 defa="<?php echo $pdefa;?>" 
				 docu="<?php echo $ptabla;?>"
				 colu="<?php echo $pcolu;?>"
				 <?php if($ptabla=='docu'){ ?>
				 autonum="0"
				 autofec="0"
				 <?php}?>
         />
  <br>
  
<?php if($mobile=='true'){ ?>
   <?php if($pobj>1){?>
		<div
		   id="<?php echo $pidtxt; ?>_descri"
         class="getcod_desc <?php echo $pclass;?>"
			style="position:;
					font-size:<?php echo $psize;?>px;
					<?php if($pobj!=3){echo 'display:none;';} ?>
				" 
					>
					<?php echo $pdefad;?>
		</div>
   <?php } ?>
<?php } ?>  
<?php if(@mb_stristr('sist.supe.admi',$user_tipo) and $pobj>1 ){ ?>  
    <input type="button" 
         class="getcod_btne"
         id="<?php echo $pidtxt; ?>_editcod" 
         onClick="
									<?php if($ptabla=='enti'){echo '_editenti';} ?>
									<?php if($ptabla=='cntn'){echo '_editcodi';} ?>
									('<?php echo $pidtxt; ?>');" 
				 tabIndex="-1"
         style="
                float:bottom;
								display:none;
								font-size:<?php echo $psize-4;?>px;
							"
				 title="Editar Datos"
         value="E" 
         />
<?php } ?>
  <?php if(1==2) {?>  
	<input type="button" 
         class="getcod_btne"
         id="<?php echo $pidtxt; ?>_vericod" 
         onClick="
									<?php if($ptabla=='enti'){echo '_vericedruc';} ?>
									<?php if($ptabla=='vhcl'){echo '_verivhcl';} ?>
									<?php if($ptabla=='cntn'){echo '_vericntn';} ?>
									('<?php echo $pidtxt; ?>');" 
				 tabIndex="-1"
         style="
								display:none;
								font-size:<?php echo $psize-4;?>px;
								"
				 title="Verificar Datos"
         value="V" 
         />	
  <?php } ?>  
  
</div>    

<?php if($mobile!='true'){ ?>
   <?php if($pobj>1){ ?>
		<div id="<?php echo $pidtxt; ?>_descri"
            class="getcod_desc <?php echo $pclassX;?>"
				style="position:;
					<?php if($pobj!=3){echo 'display:none;';} ?>
					<?php //if($pobj==4){echo 'display:none;';} ?>
						font-size:<?php echo $psize;?>px;
						" 
		>
		<?php echo $pdefad;?>
		</div>
   <?php } ?>
  
<?php } ?>
   
   
   
   

<?php if($mobile=='true' and $preado==0){ ?><div class="" style="height:50px;"></div><?php } ?>
<?php if($mobile=='true' and $preado==1){ ?><div class="" style="height:25px;"></div><?php } ?>
   

   
   
   
   
  
<?php if($pobj==1){?>
  </td>
<?php } ?>
  
<?php if($pobj==2 or $pobj==4){?>
</th>
<?php } ?>
	


 
  
  
<?php if($pobj==4){?>
<th id="th_<?php echo $pidtxt; ?>_descri" class="<?php echo $pclass; ?>" width="<?php echo $plong ?>px" valign="top" >
	<div class="<?php echo $pclass; ?>" >
	<input type="button"
         class="getcod_btn"
				 id="<?php echo $pidtxt; ?>_nombre"
         style="<?php if($phide==1){echo 'display:none;';} ?>
								font-size:<?php echo $psize;?>px;
								" 
				 tabIndex="-1"
				 value="<?php echo substr($pcaption,0,1) ?>_Descrip"
				 ></input>
	</div>	
	<div class="<?php echo $pclass; ?>" >
<?php } ?>

    
    
<?php //if($pobj==4 or $pobj==5){?>
 <?php if($pobj>1 or 1==1){?>
    
	<input type="text"
         class="getcod_txt"
				 disabled
				 id="<?php echo $pidtxt; ?>_descrit"
         onblur ="_valcod(event,'<?php echo $pidtxt;?>','<?php echo $ptabla;?>','<?php echo $pnotob;?>');<?php echo $ponblur;?>;" 
         onKeyUp="_okupcod(event,'<?php echo $pidtxt;?>','<?php echo $ptabla;?>','<?php echo $pnotob;?>');" 
				 style="<?php if($phide==1){echo 'display:none;';} ?>
								font-size:<?php echo $psize;?>px;
								<?php if($pobj==1 or $pobj==2 or $pobj==3 or $pobj==6){echo 'display:none;';} ?>
								" 
				 tabIndex="-1"
				 value="<?php if($pdefad!=''){echo $pdefad;}?>"
				 title="<?php echo $ptitle; ?>"
				 >
		</input>
 <?php } ?>
<?php //}?>


<!-- 	</span> -->



<?php if($pobj==4){?>
</div>
<?php } ?>
<div>
	<span id="<?php echo $pidtxt; ?>_error" class="txt_error" style="color:red;"></span>
</div>
<div align="left">
	<input type="text" id="<?php echo $pidtxt; ?>_codi2" style="display:none;" ></input>
	<input type="text" id="<?php echo $pidtxt; ?>_ruc" style="display:none;" ></input>
	<input type="text" id="<?php echo $pidtxt; ?>_cedula" style="display:none;" ></input>
	<input type="text" id="<?php echo $pidtxt; ?>_mod10" style="display:none;" ></input>
	<input type="text" id="<?php echo $pidtxt; ?>_mod11" style="display:none;" ></input>
</div>




<?php if($pobj==2 or $pobj==4){?>
</th>
<?php } ?>




<?php //if($pobj==3 or $pobj==5){?>
<?php if($pobj==3){?>
</td>
<?php } ?>

<span>
<datalist id="dl<?php echo $pidtxt; ?>" style="display:none; font-family:arial;">
<?php
// 	if($pdldown==1 or 1==1)
	if($pdldown==2 and $plist=='' and $preado==0)
	{
	$list_sql='select ';
// 	if(mb_stristr('enti',$ptabla))
	$list_sql.= $ptabla.'_codigo as codigo, ';
	$list_sql.= $ptabla.'_descri as descri, ';
	if(mb_stristr('item',$ptabla))
	{
  	$list_sql.= $ptabla.'_codigov as codigov, ';
  	$list_sql.= $ptabla.'_puni as puni, ';
  	$list_sql.= $ptabla.'_pvp1 as pvp1, ';
//   	$list_sql.= 'tlla_descri as talla, ';
//   	$list_sql.= 'color_descri as color, ';
  }
    
	if(mb_stristr('item.enti',$ptabla))
	{
		$list_sql.= 'year('.$ptabla.'_lused) as fanio, ';
		$list_sql.= 'month('.$ptabla.'_lused) as fmes, ';
	}
	$list_sql.= $ptabla.'_status as status ';
	$list_sql.=' from '.$ptabla.'0 ';
	if(mb_stristr('item',$ptabla))
	{
// 		$list_sql.= 'left join tlla0 on item_tlla=tlla_codigo ';
// 		$list_sql.= 'left join clor0 on item_clor=clor_codigo ';
	}
	$list_sql.=' where '.$ptabla.'_status!="X" ';
	$list_sql.=' and '.$ptabla.'_descri not like "%<LINK%" ';
// 	$list_sql.=' and '.$ptabla.'_descri not like "%***%" ';
     if($pwhere!=""){$list_sql.=' '.$pwhere.' ';}
	$list_sql.=' and '.$ptabla.'_status!="I" ';
    
//     echo '*/*/*/'.$list_sql;
		
	if(mb_stristr('item.enti',$ptabla))
	{
		$lyear=strtotime('-12 month');
		$lyear=date('Y-m-'.'01',$lyear);
		$list_sql.=' and '.$ptabla.'_lused>="'.$lyear.'" ';
	}

	if(mb_stristr('item.enti',$ptabla))
	{
    $xorder='fanio desc, fmes desc,'.$ptabla.'_descri';
    if($mobile=='true')
    {$xorder=''.$ptabla.'_descri';}
	}	
	else
	{
		if(mb_stristr('docu.ctas.suco.cair.fpag.cntn.vhcl.tlla.asub',$ptabla) or mb_stristr('orat.bsqj',$ptabla))
		{$xorder=''.$ptabla.'_codigo';}	
		else
		{$xorder=''.$ptabla.'_descri';}
	}
  $list_sql.=' order by '.$xorder;

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

	if(mb_stristr('item.enti',$ptabla))
	{
	}
		
		
	$list_res=msql_query($list_sql,$link_vcrx);
	while($list_aso=msql_fetch_assoc($list_res))
	{
      $xvalue=$list_aso['codigo'];
      $xoption=$list_aso['descri'];
      if(mb_stristr($osver,'Edg')){$xvalue.='=>'.$xoption; $xoption='';}
          
		$option='';
// 		$option.='<option style="font-family:arial;" value="'.$list_aso['codigo'].'">';
		$option.='<option value="'.$xvalue.'">';
// 		$option.='---';
		$option.=$xoption;

    if($ptabla=='item' and $list_aso['codigov']!='')
    {$option.=' ('.$list_aso['codigov'].')';}
    else
    {$option.=' ('.$list_aso['codigo'].')';}

    
		$option.='</option>';
		echo $option;
	}	
	}
?>	
</datalist>
</span>




<?php $pdldown=0;?>
<?php $pphold='';?>
<?php $preado='';?>
<?php $pdisab='';?>
<?php $pcaption='';?>
<?php $ptabla='';?>
<?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 $plist='';?>
<?php $ptitle='';?>
<?php $pvalue='';?>
<?php $obstart = ob_get_clean(); ?>
<?php //$obstart=alltrim($obstart); ?>
<?php $obstart = limpiahtml($obstart) ?>
<?php echo $obstart; ?>
