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

<?php //if(file_exists('../cfg/res.php')){include('../cfg/res.php');} ?>	

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

<?php
  if($ptabla!='')
  {
		$sql_getcod='describe '.$ptabla.'0';
		$res_getcod=@msql_query($sql_getcod,$link_vcrx);
		if(!msql_error($link_vcrx))	
		{
			$plong=@msql_result($res_getcod,0,'type');
			$plong=str_replace(')','',$plong);
			$plong=str_replace('varchar(','',$plong);
			$plong=str_replace('char(','',$plong);
		}
  }

	$plimit='999999999';
?>

<?php if(empty($pclass)){$pclass="";}?>
<?php if($pidtxt==''){$pidtxt=$ptabla;}?>
<?php if(empty($pidtxt)){$pidtxt=$ptabla;}?>
<?php if(empty($ponblur)){$ponblur="";}?>
<?php if(empty($ponchange)){$ponchange="";}?>
<?php if(empty($pnotob)){$pnotob="";}?>
<?php if(empty($ptabla)){$ptabla="";}?>
<?php if(empty($pdocu)){$pdocu="";}?>
<?php if(empty($plong)){$plong="";}?>
<?php if(empty($pdisab)){$pdisab="";}?>
<?php if(empty($pobj)){$pobj=3;} ?>
<?php if(empty($psize)){$psize=12;} ?>
<?php if(empty($pcolu)){$pcolu='';} ?>
<?php if(empty($pcolu2)){$pcolu;} ?>
<?php if(empty($pwhere)){$pwhere='';} ?>
<?php if(empty($ponclick)){$ponclick="";}?>
<?php $ponclick=str_replace('"',"'",$ponclick); ?>
<?php if(empty($pvalue)){$pvalue=$pdefa;} ?>

<?php if($pobj>5){$pobj=3;} ?>
<?php //if(empty($pcolu)){$pcolu=$ptabla.'_descri,'.$ptabla.'_codigo';} ?>
<?php if(empty($pcolu)){$pcolu=$ptabla.'_codigo,'.$ptabla.'_descri';} ?>
<?php //if(empty($poptions)){$poptions='1,uno;2,dos;3,tres;45,cuarenta y cinco';} ?>
<?php 
	if(!empty($pdocu))
	{
		$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';}
	} 
?>


<?php
// if($ptabla!="")
// $poptions='';
// echo '*/*/*/'.$poptions;
$pdefad='';

// poptn1 y poptn2 para listas numericas... desde hasta
if($poptn1>0 and $poptn2>$poptn1)
{
	$poptions='';
	if($pdefa!=''){$poptions.=$pdefa.','.$pdefa.';';}
  if($ptodos==1){$poptions.=' '.','.' - TODO - '.';';}
// 	if($ptodos==1){$poptions.=''.','.' - TODO - '.';';}
// 	if($ptodos==1){$poptions=''.','.' - TODO - '.';'.$poptions;}
	for($coptn=$poptn1; $coptn<=$poptn2; $coptn++)
	{$poptions.=$coptn.','.$coptn.';';	}
}
else
{
	
}


if($poptions!='')
{
  if($pdefa=='')
  {if($ptodos==1){$poptions=' '.','.' - TODO - '.';'.$poptions;}}
  else
  {
    if($ptodos==1){$poptions=' '.','.' - TODO - '.';'.$poptions;}
    $poptions=$pdefa.';'.$poptions;
  }
  
// 	if($ptodos==1){$poptions=''.','.' - TODO - '.';'.$poptions;}
// 	if($ptodos==1){$poptions.='todo'.','.' - TODO - '.';';}
// echo '<br><br>*/*/*/*'.$poptions;
}


if($poptions=='')
{	
	if($pdocu=='')
	{
		if ($pdefa!='')
		{
			$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');}
		}
		
		$sql_sele ='select * from '.$ptabla.'0 ';
		$sql_sele.='where '.$ptabla.'_descri!="" ';
    if($ptabla!='stat')
    {$sql_sele.=' and '.$ptabla.'_codigo!="-" ';}
		$sql_sele.=' and '.$ptabla.'_descri!="NO DEFINIDO" ';
		$sql_sele.=' and '.$ptabla.'_status!="I" ';
		$sql_sele.=' and '.$ptabla.'_status!="O" ';
		$sql_sele.=' and '.$ptabla.'_status!="X" ';
		if($pwhere!='')
		{$sql_sele.=' and ('.$pwhere.')';}
		if($pcolu!='')
		{$sql_sele.=' group by '.$pcolu.' ';}	
		$sql_sele.=' order by '.$ptabla.'_codigo ';

		$res_sele=@msql_query($sql_sele,$link_vcrx);
// la		echo explain_sql($sql_sele);
		$poptions.=$pdefa.','.$pdefad.';';
    if($ptodos==1){$poptions.=' '.','.' - TODO - '.';';}

    
		if(msql_num_rows($res_sele)>0)
		{
			while ($aso_sele=msql_fetch_assoc($res_sele))
			{$poptions.=$aso_sele[$ptabla.'_codigo'].','.$aso_sele[$ptabla.'_descri'].';';}
		}
	}
	else
	{
		if ($pdefa!='')
		{
			$defa_sql ='select * from '.$ptabla.'2 ';
			$defa_sql.='where docu like "'.$pdocu.'%"';
			$defa_sql.=' and '.$pcolu.'="'.$pdefa.'"';
			$defa_sql.=' and status!="O" ';
			$defa_sql.=' and status!="X" ';
// 			$defa_sql='select * from '.$ptabla.'2 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,$pcolu2);}
		}

		$sql_sele ='select * from '.$ptabla.'2 ';
		$sql_sele.='where docu like "'.$pdocu.'%"';
		$sql_sele.=' and status!="O" ';
		$sql_sele.=' and status!="X" ';
		if($pwhere!='')
		{$sql_sele.=' and ('.$pwhere.')';}
		$sql_sele.=' group by '.$pcolu2;
		$sql_sele.=' order by '.$pcolu2;

		$res_sele=msql_query($sql_sele,$link_vcrx);
	// 	echo explain_sql($sql_sele);
		$poptions.=$pdefa.','.$pdefad.';';
		if(msql_num_rows($res_sele)>0)
		{
			while ($aso_sele=msql_fetch_assoc($res_sele))
			{$poptions.=$aso_sele[$pcolu].','.$aso_sele[$pcolu2].';';}
		}
	}
}

// echo '<br>*/*/*/*/'.$poptions;
// $poptions=str_replace(':',',',$poptions);
$plong=strlen($pcaption);

$poptions=explode(';',$poptions);
for ($copt=0; $copt<count($poptions); $copt++)
{ 
 $optval=explode(',',$poptions[$copt]); 
 $seloptv1= $optval[0]; 
 $seloptv2= $optval[1]; 
 $xlong=strlen($seloptv2);
 if($xlong>$plong){$plong=$xlong;}
} 



// echo $poptions;
?>

<?php if($pobj==2 or $pobj==4){?>
<th id="th_<?php echo $pidtxt ?>" class="<?php echo $pclass; ?>" width="<?php if($plong==0){}else{echo $plong.'px';} ?>" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>
	
<?php if($pobj==3){?>
<?php //if($pobj==3 or $pobj==5){?>
<td id="td_btn<?php echo $pidtxt ?>" class="<?php echo $pclass; ?>" align="right"  valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>
<?php if($pobj==5){?>
<!-- <td id="td_txt<?php echo $pidtxt ?>" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>"> -->
<?php } ?>
	<div class="<?php echo $pclass; ?>" >
	<input type="button" 
         class="selopt_btn"
         id="<?php echo $pidtxt ?>_btn" 
         onClick="<?php echo $ponclick;?>"
				 tabIndex="-1"
         style="
								font-size:<?php if($pobj==2 and mb_stristr($pcaption,'%')){echo round($psize*0.8,0);}else{echo $psize;}?>px;
								<?php if($pobj==1 or $pobj==5){echo 'display:none;';} ?>
								<?php if($pobj==2)
											{
												if(mb_stristr($pcaption,'%'))
												{echo 'width:'.(4*$psize).'px;';}
												else
												{
// 												if(strlen($pcaption)<=$plong)
                        {echo 'width:100%;';}
// 												if(strlen($pcaption)>$plong){echo 'width:'.(strlen($pcaption)*$psize).'px;';}
												}
											}
								?>;
								" 
         value="<?php echo ($pcaption) ?>"
				 />
	</div>
<?php if($pobj==3){?>
<?php //if($pobj==3 or $pobj==5){?>
</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 } ?>
<?php if($pobj==5){?>
<?php } ?>
	<div class="<?php echo $pclass; ?>" >

		<select id="<?php echo $pidtxt ?>"  
     name="<?php echo $pidtxt ?>"
     class="selopt_opt"
         onfocus="{this.style.background='<?php echo $pbground;?>';}"
        onblur="{this.style.background='white';}"
        onchange="<?php echo $ponchange; ?>"
		 style="
        <?php if($phide==1){echo 'display:none;';} ?>            
				<?php if($pobj>1){echo 'font-weight:bold;';} ?>
								<?php if($pobj==2)
											{
												if(mb_stristr($pcaption,'%'))
												{echo 'width:'.(4*$psize).'px;';}
												else
												{
// 												if(strlen($pcaption)<=$plong)
                        {echo 'width:100%;';}
// 												if(strlen($pcaption)>$plong){echo 'width:'.(strlen($pcaption)*$psize).'px;';}
												}
											}
								?>;
            
				font-size:<?php if($pobj==2){echo $psize;}else{echo $psize+2;} ?>px;
				"
	>
               <?php sort($poptions); ?>
		<?php for ($copt=0; $copt<count($poptions); $copt++){ ?>
			<?php $optval=explode(',',$poptions[$copt]); ?>
			<?php //$optval=explode(':',$poptions[$copt]); ?>
			<?php $seloptv1= $optval[0]; ?>
			<?php $seloptv2= $optval[1]; ?>
			<?php if($seloptv2==""){$seloptv2=$seloptv1;}?>
			<?php if($seloptv1!=""){?>
				<option value="<?php echo $seloptv1; ?>" 
                <?php
                  if($ptabla=='clor')
                  {
                    $fcolor='black';
                    $bcolor=r_fiel('clor',$seloptv1,'hexa');
                    echo 'style="font-weight:bold;color:'.$fcolor.';background-color:'.$bcolor.';"';
                  }
                ?>
                > <?php echo $seloptv2; ?></option>
			<?php } ?>
		<?php } ?>
      
		<?php if($ptodos==1){?>
<!-- 			<option value=""> - TODOS - </option> -->
<!--       <option disabled selected value> - escoja una opcion - </option>       -->
		<?php } ?>
      
	</select>

      
<?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==2 or $pobj==4){?>
</th>
<?php } ?>

  <?php // } ?>
</div>
	
<?php if($pobj==4 and 1==2){?>
<th id="th_<?php echo $pidtxt ?>_descri" class="<?php echo $pclass; ?>" width="<?php echo $plong ?>px" valign="top" >
	<div>
	<input type="button"
				 id="<?php echo $pidtxt ?>_nombre"
				 onclick="<?php echo $ponclick;?>;"				 
         style="
								border-radius:0px;
								padding:2px;
								margin:0px;
								width:100%;
								font-weight:bold;
								font-family:arial;
								font-size:<?php echo $psize;?>px;
								" 
				 tabIndex="-1"
				 value="<?php echo substr($pcaption,0,1) ?>_Descrip"
				 ></input>
	</div>	
	<div>
<?php } ?>

<?php if(($pobj==4 or $pobj==5) and 1==2){?>
	<input type="text"
				 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="
								width:150px;
								background-color:white;
								font-weight:bold;
								padding:2px;
								margin:0px;
								font-family:arial;
								font-size:<?php echo $psize;?>px;
								<?php if($pobj==1 or $pobj==2 or $pobj==3){echo 'display:none;';} ?>
								" 
				 tabIndex="-1"
				 value="<?php if($pdefad!=''){echo $pdefad;}?>"
				 title=""
				 >
		</input>
<?php }?>
<!-- 	</span> -->


<?php if($pobj==4){?>
</div>
<?php } ?>


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

<?php $pdisab='';?>
<?php $pcaption='';?>
<?php $ptabla='';?>
<?php $pdocu='';?>
<?php $pcolu='';?>
<?php $pcolu2='';?>
<?php $pidtxt='';?>
<?php $plong='';?>
<?php $pobj='';?>
<?php $ponblur='';?>
<?php $ponchange='';?>
<?php $pnotob='';?>
<?php $pdefa='';?>
<?php $psize='';?>
<?php $poptn1='';?>
<?php $poptn2='';?>
<?php $phide=0; ?>
<?php $poptions=''; ?>
<?php $ptodos=0; ?>
<?php $preado=0; ?>
<?php $pwhere=''; ?>
<?php $pclass='';?>
<?php $pvalue='';?>

<?php $obstart = ob_get_clean(); ?>
<?php //alltrim($obstart); ?>
<?php $obstart = limpiahtml($obstart) ?>

<?php echo $obstart; ?>
