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

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

<?php if(empty($ptype)){$ptype="search";}?>
<?php if(empty($pclass)){$pclass="";}?>
<?php if(empty($pobj)){$pobj=3;} ?>
<?php if(empty($ponclick)){$ponclick="";} ?>
<?php if(empty($ponblur)){$ponblur="";} ?>
<?php if(empty($plong)){$plong=240;} ?>
<?php if(empty($prows)){$prows=1;} ?>
<?php if(empty($pcols)){$pcols=$plong;} ?>
<?php if(empty($psize)){$psize=12;} ?>
<?php if(empty($pbutton)){$pbutton='';} ?>
<?php if(empty($pidtxt)){$pidtxt=$pcaption;} ?>
<?php if(empty($pcaption)){$pcaption=$pidtxt;}?>
<?php if(empty($pphold) and $pobj==1){$pphold=$pcaption;}?>
<?php if(empty($pwhere)){$pwhere="";}?>
<?php if(empty($plist)){$plist='';}?>
<?php if(empty($pvalue)){$pvalue=$pdefa;} ?>
<?php if(empty($ptitle)){$ptitle=$pcaption;}?>

<?php $plong1=$plong; ?>

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

<?php if($prows>=2){$ptype='area';}?>

<?php if($pdefa!=''){$prows=ceil(strlen($pdefa)/$pcols);}?>
<?php if($prows==1){$ttupper=1;}else{$ttupper=0;}?>

<?php if($ptype=='color'){$plong=5;}?>


<?php if(strlen($ptabla)==4){$ptabla.='0';}?>
<?php
	if(!empty($ptabla) and !empty($pcolu) and $prows==1)
  {
// 		$sql_getcod='show columns from '.$ptabla.' where field="'.$pcolu.'"';
// 		$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);
// 			$plong=str_replace('int(','',$plong);
// 			$plong=$plong+2;
// 		}
    
		$sql_getcod='describe '.$ptabla.'';
		$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);
			$plong=str_replace('int(','',$plong);
      $plong=$plong+2;
		}
    
    
  }
?>

<?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($link_vcrx)){$ptabla=@msql_result($res_gettab,0,'docu_tabla').'12';}
		} 
?>
<?php if(empty($ptabla)){$ptabla='';} ?>
<?php if(empty($pcolu)){$pcolu='';} ?>
<?php if(!empty($pdocu) or !empty($plist)){$pdldown=2;} ?>
<?php $plong=$plong+$pdldown;?>
<?php //if(!mb_stristr($$plong,'%')){$plong=$plong+$pdldown};?>
<?php $pmaxlong=$prows*$pcols; ?>
<?php $rdatalist=0; ?>

<?php $pemail='0';?>
<?php if(mb_stristr($pidtxt,'email')){$pemail='1';} ?>

<?php //$ttupper=1; ?>
<?php if(mb_stristr($pidtxt,'email')){$ttupper=0;} ?>
<?php if(mb_stristr($pidtxt,'user')){$ttupper=0;} ?>
<?php if(mb_stristr($pidtxt,'usuario')){$ttupper=0;} ?>
<?php if(mb_stristr($pidtxt,'pass')){$ttupper=0;} ?>
<?php if(mb_stristr($pidtxt,'clave')){$ttupper=0;} ?>
<?php if($ppass==1){$ttupper=0;} ?>

<?php $ponclick= str_replace('"',"'",$ponclick); ?>
<?php $ponenter= str_replace('"',"'",$ponenter); ?>
<?php $ponenter.=';'.$ponclick; ?>

<?php
	if($mobile=='true')
	{
		$ponenter=$ponclick;
		$ponclick='';
	}

?>



<?php if($pobj==2){?>
<th colspan="1" id="th_<?php echo $pidtxt; ?>" class="<?php //echo $pclass; ?>" width="<?php if(mb_stristr($plong1,'%')){echo $plong1;}else{echo $plong.'px;';} ?>" valign="top"  style="<?php if($phide==1){echo 'display:none;';} ?>"  >
<?php } ?>
<?php if($pobj==3){?>
<td class="<?php //echo $pclass; ?>" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>

<div class="<?php echo $pclass; ?>" <?php if($pobj==2){echo 'align="center"';}?>>
<?php if($pobj==2 or $pobj==3){?>
  
  <input type="button" 
         id="<?php echo $pidtxt; ?>_btn" 
				 class="gettxt_btn"
         value="<?php echo $pcaption;?>" 
         style="
								font-size:<?php echo $psize;?>px;
								<?php if($pobj==2 or $pobj==3){echo 'display:block;';}else{echo 'display:none;';}?>;
								<?php if($pobj==2)
                  {
                    if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                    else
                    {
                    if(strlen($pcaption)<=$plong){echo 'width:100%;';}
                    if(strlen($pcaption)>$plong){echo 'width:'.(strlen($pcaption)*$psize).'px;';}
                    }
                  }
								?>
								<?php if($pobj==3)
                  {
                    if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                    else
                    {
                    if(strlen($pcaption)<=$plong){echo 'width:100%;';}
                    if(strlen($pcaption)>$plong){echo 'width:'.(strlen($pcaption)*$psize).'px;';}
//                       echo 'width:100%;';
                    };
                  }
                ?>;
								"
				 <?php if($mobile!='true') { echo 'tabIndex="-1"';}?>
	       onClick="_valtxt(event,'<?php echo $pidtxt; ?>','<?php echo $ptabla; ?>','<?php //echo $pnotob;?>');
									<?php if($ppass==1 and $mobile=='true') { ?>_passtxt(event,'<?php echo $pidtxt; ?>');<?php } ?>
									<?php if($ppass==1 and $mobile!='true') {echo $ponclick;}?>;"
				 <?php if($ppass==1 and $mobile!='true') { ?>
         onmouseover ="_passtxt(event,'<?php echo $pidtxt; ?>','text');" 
         onmouseout ="_passtxt(event,'<?php echo $pidtxt; ?>','password');" 
				 <?php } ?>
				 ></input>
<?php  } ?>
	</div>
<?php // } ?>
<?php if($pobj==3){?>
</td>
<td class="<?php echo $pclass; ?>" align="left" valign="top" style="<?php if($phide==1){echo 'display:none;';} ?>">
<?php } ?>
	<div class="<?php echo $pclass; ?>" <?php if($pobj==1){echo 'valign="middle"';}?> <?php if($pobj==2){echo 'align="center"';}?> style="position:relative;">

<?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 } ?>

  <?php //if($ptype=='color'){ echo '<span style="display:none;">'.$pvalue.'</span>';} ?>
  
  <?php if($ptype!='area'){?>
  <input
         value="<?php echo $pvalue; ?>" 
         type="<?php if($ppass==1){echo 'password';}else{if($preado==1){echo 'text';}else{echo $ptype;}}?>"
         <?php if($preado==1){echo ' readonly ';}?>
         <?php if(mb_stristr('USUARIO',strtoupper($pcaption))){echo ' autofocus ';}?>
         class="gettxt_txt"
         id="<?php echo $pidtxt; ?>" 
         name="<?php echo $pidtxt; ?>" 
				 accesskey="<?php echo substr($pcaption,0,1);?>"
				 cols="<?php echo $pcols ?>" 
				 maxlength="240"
				 list="<?php if($plist!=''){echo $plist;}else{echo 'dl'.$pidtxt;} ?>"
				 rows="<?php echo '1'; ?>" 
         style="
                <?php if(!mb_stristr($plong1,'%')){echo 'min-width:'.$plong*$psize.';';}?>
								<?php if($pobj==1)
                    {
                      if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                      else{echo 'width:'.($plong*$psize+$psize).'px;';}
                    }
								?>
								<?php if($pobj==2)
                    {
                      if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                      else{echo 'width:'.($plong*$psize+$psize).'px;';}
                    }
								?>
								<?php if($pobj==3)
                    {
                      if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                      else
                      {
                      if($plong==0){echo 'width:100%;';}
                      else
                      {
                        if($preado)
                        {echo 'width:'.(($plong*$psize)+$psize).';';}
                        else
                        {echo 'width:'.(($plong*$psize)+$psize*3).';';}
                        
                      }
                      }
                    }
								?>
                
								<?php if($ttupper==1){echo 'text-transform:uppercase;';} ?>
								<?php if($pobj>1){echo 'font-weight:bold;';} ?>
								<?php //if($phide==0){echo 'display:block;';}else{echo 'display:none;';} ?>
								font-size:<?php echo $psize+2;?>px;
								" 
         onfocus="{this.style.background='<?php echo $pbground;?>';}"
         
         onblur ="
 									_valtxt(event,this.id,'<?php echo $ptabla;?>','<?php //echo $pnotob;?>');
									<?php echo $ponblur;?>;{this.style.background='white';}" 
         onKeyUp="_okuptxt(event,this.id,'<?php echo $ptabla;?>','<?php //echo $pnotob;?>');
									<?php if($rdatalist==1){?>
									_datalist(event,this.id);
									<?php } ?>
									" 
         onKeyDown ="_okdntxt(event,this.id,'<?php echo $ptabla;?>','<?php //echo $pnotob;?>');
									{if(event.keyCode==13){<?php echo $ponenter; ?>}}
										 " 
         <?php if($pphold!=""){echo 'placeholder="'.$pphold.'"';}?>
				 android:singleLine="true"
				 title="<?php echo strtolower($ptitle); ?>" 
				 onenter="<?php echo $ponenter;?>"
				 defa="<?php echo $pdefa;?>"
				 pass="<?php echo $ppass;?>"
				 email="<?php echo $pemail;?>"
				 docu="<?php echo $pdocu;?>"
         <?php if(!empty($ptabla)){ ?>
				 tabla="<?php echo $ptabla;?>"
         <?php } ?>
         <?php if(!empty($pline)){ ?>
				 line="<?php echo $pline;?>"
         <?php } ?>
				 colu="<?php echo $pcolu;?>"
				 ttupper="<?php echo $ttupper;?>"
				 >
			</input>
<?php }else{?>
  <textarea
         value="<?php echo $pvalue;?>" 
         class="gettxt_txta"
				 accesskey="<?php echo substr($pcaption,0,1);?>"
         id="<?php echo $pidtxt; ?>" 
         name="<?php echo $pidtxt; ?>" 
				 cols="<?php echo $pcols; ?>" 
				 maxlength="240"
				 list="<?php echo $plist; ?>"
				 rows="<?php echo $prows; ?>" 
         onfocus="{this.style.background='<?php echo $pbground;?>';}"
         style="font-size:<?php echo $psize+2;?>px;
								<?php if($pobj>1){echo 'font-weight:bold;';} ?>
                resize:none;
								<?php if($pobj==1)
                    {
                      if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                      else{echo 'width:'.($plong*$psize+$psize).'px;';}
                    }
								?>
								<?php if($pobj==2)
                    {
                      if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                      else{echo 'width:'.($plong*$psize+$psize).'px;';}
                    }
								?>
								<?php if($pobj==3)
                    {
                      if(mb_stristr($plong1,'%')){echo 'width:'.($plong1).';';}
                      else
                      {
                      if($plong==0){echo 'width:100%;';}
                      else
                      {
                        if($preado)
                        {echo 'width:'.(($plong*$psize)+$psize).';';}
                        else
                        {echo 'width:'.(($plong*$psize)+$psize*3).';';}
                        
                      }
                      }
                    }
								?>
            
								<?php // if($pobj==2){echo 'width=100%;';} ?>;
								<?php
//                 if($pobj==3)
//                 {
//                   if($plong==0){echo 'width:100%;';}
//                   else{echo 'width:'.($plong*$psize+$psize).';';}
//                 }
                ?>;
                border-style:solid;
                border-width:1px;                
								" 
            
            
         onKeyUp="_okuptxt(event,this.id,'<?php echo $ptabla;?>','<?php echo $pdefa;?>','<?php echo $pnotob;?>');" 
         onblur ="_valtxt(event,this.id,'<?php echo $ptabla;?>','<?php echo $pdefa;?>','<?php echo $pnotob;?>');<?php echo $ponblur;?>;{this.style.background='white';}" 
				 title="<?php echo strtolower($ptitle); ?>" 
         text="<?php echo $pdefa;?>" 
				 defa="<?php echo $pdefa;?>" 
				 pass="<?php echo $ppass;?>"
				 email="<?php echo $pemail;?>"
				 docu="<?php echo $pdocu;?>"
				 colu="<?php echo $pcolu;?>"
				 ttupper="<?php echo $ttupper;?>"
				 onenter="<?php echo $ponenter;?>"
				 ><?php echo $pdefa;?></textarea>
<?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 } ?>
</div>



<span id="<?php echo $pidtxt; ?>_error" class="txt_error" style="color:red;"></span>
<span>
<datalist id="dl<?php echo $pidtxt; ?>" style="display:none;">
<?php
	if(!empty($ptabla) and !empty($pcolu) and $plist=='')
	{
    $prefix='';
    if(substr($ptabla,-1,1)=='0')
    {$prefix=substr($ptabla,0,4).'_';}
    
//     $pcolu.=',';
//     $pcolu=str_replace(',,','',$pcolu);
    $pconcat=$pcolu;
    $pconcat=str_replace(',',',"-",',$pconcat);
      
    $sql_list='select distinct ';
    $sql_list.= $pcolu.'';
//     $sql_list.=' concat('.str_replace(',','," .",',$pcolu).') as datalist, ';
    $sql_list.=',concat('.$pconcat.') as datalist ';
    $sql_list.=' from '.$ptabla;
    $sql_list.=' where '.$prefix.'status!="X" ';
    $sql_list.=' and '.$prefix.'status!="O" ';

      
//       echo '*/*/*/'.$sql_list;

    if($cfg_tipo=='cong')
    {if($pdocu!='DPU2'){$sql_list.=' and cong="'.$_SESSION['cong_codigo'].'" ';}}
    
    if(!empty($pdocu))
    {$sql_list.=' and docu like "'.$pdocu.'%" ';}
    
    if($pwhere!=""){$sql_list.=' '.$pwhere.' ';}
    $sql_list.=' order by '.$pcolu;
    $res_list=msql_query($sql_list,$link_vcrx);
//     echo $sql_list;echo msql_error($link_vcrx);die();
//     $countdl=msql_num_rows($res_list);
    while($aso_list=msql_fetch_assoc($res_list))
    {
      echo '<option value="'.$aso_list['datalist'].'">';
    }
	}
?>	
</datalist>
</span>




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


<?php $pphold='';?>
<?php $pcaption='';?>
<?php $ptabla='';?>
<?php $pdocu='';?>
<?php $pcolu='';?>
<?php $pline='';?>
<?php $pidtxt='';?>
<?php $plong='';?>
<?php $pobj='';?>
<?php $pdefa='';?>
<?php $ponblur='';?>
<?php $ponclick='';?>
<?php $ponenter='';?>
<?php $pbutton='';?>
<?php $psize=0;?>
<?php $phide=0;?>
<?php $pclass='';?>
<?php $pwhere='';?>
<?php $plist='';?>
<?php $ptitle='';?>
<?php $preado=0;?>

<?php $pemail='0';?>
<?php $pvalue='';?>
<?php $pdefa='';?>


<?php $ptype='';?>
<?php $pcols='';?>
<?php $prows='';?>
<?php $ppass=0;?>

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