<?php
$inputtag='input';
$pclear=1;
$pstep=(int)$pstep;
$pstyle='height:1.2em;';
$pstyle1='';
$pstyle3='';

if(empty($pobj)){$pobj=3;}
if(empty($ptype)){$ptype='search';}
if(empty($psize)){$psize=1;}
if(empty($pmaxlen)){$pmaxlen=0;}
if(empty($pid)){$pid=$ptabla;}
if(empty($pid)){$pid=$plabel;}
if(empty($plabel)){$plabel=$pid;}
if(empty($pid)){$pid=microtime()*1000000;}
if(empty($pplace) and $pobj==1){$pplace=$plabel;}
if(empty($pvalue) and !empty($pdefa)){$pvalue=$pdefa;}
if(mb_stristr($pclass,'numeric')){$ptype='number';}
if(mb_stristr($pclass,'numeric-int')){$pstep=intval($pstep*1);}
if(mb_stristr($pclass,'numeric-dec') and empty($pstep)){$pstep='any';}
if($ptype=='pass'){$ptype='password';}
if($ptype=='area'){$inputtag='textarea'; $pstyle='resize:none;';}  
if($ptype=='area' and $pobj>2){$pobj=2;}  
if(($pobj==2 or $pobj==3) and $ptcells<=1 and getPlatform()=='Android'){$pobj=4;}

if(!empty($ptabla))
{
   $sql_input='describe '.$ptabla.'0';
   $res_input=msql_query($sql_input,$link_data);
   
   if(!msql_error($link_data))	
   {
      $pmaxlen=msql_result($res_input,0,1);
      $pmaxlen=str_replace(')','',$pmaxlen);
      $pmaxlen=str_replace('varchar(','',$pmaxlen);
      $pmaxlen=str_replace('char(','',$pmaxlen);
      $pmaxlen=str_replace('int(','',$pmaxlen);
      $ptype='search';
      $pwidth=0;
   }else{$ptabla='';}
}
if(!empty($ptabla)){$ponblur.='{data_maes("'.$ptabla.'",this.value,"'.$pid.'_r");}';}
if(!empty($ptabla) and empty($plist)){$plist='dl_'.$ptabla;}
// if(!empty($ptabla) and empty($plist)){$plist=$pid.'_dl';}
if(!empty($preado)){$pclear=0;}
if(!empty($preado)){$plist='';}
$plistd=$pid."_dl";
if(!empty($pexact)){$plist=''; $plistd='';}

if(empty($pmaxlen) and mb_stristr($pclass,'numeric')){$pmaxlen=6;}
if(empty($pwidth) and !empty($pmaxlen)){$pwidth=(int)$pmaxlen*(.7);}

// $pwidth=0;


if(!empty($psize) and $psize!=1){$pstyle.='font-size:'.($psize).'em;';}
if(!empty($psize) and $psize!=1){$pstyle1.='font-size:'.($psize).'em;';}
if(!empty($psize) and $psize!=1){$pstyle3.='font-size:'.($psize).'em;';$pstyle3.='height:'.($psize).'em;';}

$pstyle1.='vertical-align:top;';
if($ptcells>=2){$pstyle1.='width:100%;';}

if(mb_stristr('date.time.datetime-local',$ptype)){$pmaxlen=0; $pwidth=0; if($psize==0){$psize=1;}}

if(empty($pmax) and $ptype=='number'){$pmax=pow(10,$pmaxlen)-1; $pmin=$pmax*(-1);$pmaxlen=0;}


// if(mb_stristr($pwidth,'%')){$pstyle.='width:'.$pwidth.';';}
// else
{
     if(empty($pwidth)){$pwidth=10;}
     if($ptype=='text'){$pstyle.='width:'.($pwidth).'em;';}
     if($ptype=='password'){$pstyle.='width:'.($pwidth).'em;';}
     if($ptype=='number'){$pstyle.='width:'.($pwidth).'em;';}
     if($ptype=='search'){$pstyle.='width:'.($pwidth).'em;';}
     if($ptype=='date'){$pstyle.='width:'.(9).'em;';}
     if($ptype=='time'){$pstyle.='width:'.(5).'em;';}
     if($ptype=='datetime'){$ptype='datetime-local';}
     if($ptype=='datetime-local'){$pstyle.='width:'.(11).'em;';}
}

// if(!empty($pwidth)){$pstyle.='width:'.$pwidth.';';}
// if($pexact==1 and mb_stristr('enti.item.tlfn.cntn',$ptabla) and $mobile=='true'){$ptype='number';}


$domi = new DOMDocument();
     $domi->encoding = 'utf-8';
     $domi->xmlVersion = '1.0';
     $domi->formatOutput = true;
$elem=$domi;


if(!empty($pdom)){$domi=$pdom;}
if(!empty($pele)){$elem=$pele;}

// if($pobj>1)
{
     
if($ptcells>=2 and $pobj>=2 and $pobj<=3)
{
     $vrinput=$elem->appendChild($domi->createElement("td"));
     $vrinput->setAttribute("valign","top");
}
else
{
     $vrinput=$elem->appendChild($domi->createElement("span"));
     $vrinput->setAttribute("style","float:left;");
     if(mb_stristr($pwidth,'%'))
     {$vrinput->setAttribute("style","width:".$pwidth."");}
     
}
     
if(!empty($palign)){$vrinput->setAttribute("align",$palign);}

  // windows
   if($pobj==2 or $pobj==3)
   {
      $pclass1='';
      $label=$vrinput->appendChild($domi->createElement("button",$plabel));   
//       $label=$vrinput->appendChild($domi->createElement("input",$plabel));   
      if(!empty($pid))
      {
        $label->setAttribute("id",$pid.'_l');
        $label->setAttribute("type","button");
        $label->setAttribute("tabindex","-1");
      }
      if(!empty($plabel)){$label->setAttribute("value",$plabel);}
      if(!empty($pstyle1)){$label->setAttribute("style",$pstyle1);}
      if(!empty($pclass1)){$label->setAttribute("class",$pclass1);}
   }

}


if($ptcells>=2)
{
  $vrinput=$elem->appendChild($domi->createElement("td"));
  $vrinput->setAttribute("colspan",$ptcells);
  $vrinput->setAttribute("valign","top");
}
// else
// {if(!empty($pwidth)){$vrinput->setAttribute("width",$pwidth);}}

    //android
   if($pobj==4)
   {
      $pclass1='input-label';
      $label=$vrinput->appendChild($domi->createElement("label",$plabel));   
      if(!empty($pid)){$label->setAttribute("id",$pid.'_l');}
      if(!empty($pid)){$label->setAttribute("for",$pid);}
      if(!empty($pstyle1)){$label->setAttribute("style",$pstyle1);}
      if(!empty($pclass1)){$label->setAttribute("class",$pclass1);}
   }

//    $div=$vrinput->appendChild($domi->createElement("div"));
   $div=$vrinput->appendChild($domi->createElement("span"));
     $div->setAttribute("class","clearable-input");
//      if(!empty($pdom))
     if(mb_stristr($pwidth,'%'))
     {$div->setAttribute("style","width:".$pwidth."");}
//      $div->setAttribute("style","vertical-align:top;");

//    if(empty($preado))
   if($pclear)
   {
        $span=$div->appendChild($domi->createElement("span","×"));   
          $span->setAttribute("data-clear-input","");
          if(!empty($psize)){$span->setAttribute("style",'font-size:'.($psize+1).'em;');}
   }

   $input=$div->appendChild($domi->createElement($inputtag," "));   
   if(!empty($pid)){$input->setAttribute("id",$pid);}
   if(!empty($ptype)){$input->setAttribute("type",$ptype);}
   if(!empty($pname)){$input->setAttribute("name",$pname);}
   if(!empty($pclass)){$input->setAttribute("class",$pclass);}
   if(!empty($pplace)){$input->setAttribute("placeholder",$pplace);}
   if(!empty($preado)){$input->setAttribute("readonly","");}
   if(!empty($pmin)){$input->setAttribute("min",$pmin);}
   if(!empty($pmax)){$input->setAttribute("max",$pmax);}
   if(!empty($pstep)){$input->setAttribute("step",$pstep);}
   if(!empty($prows)){$input->setAttribute("rows",$prows);}
   
   if(!empty($poninput)){$input->setAttribute("oninput",$poninput);}
   if(!empty($ponkeyd)){$input->setAttribute("onkeydown",$ponkeyd);}
   if(!empty($ponblur)){$input->setAttribute("onblur",$ponblur);}
   if(!empty($pvalue)){$input->setAttribute("value",$pvalue);}
   if(!empty($pmaxlen)){$input->setAttribute("maxlength",$pmaxlen);}
   if(!empty($pstyle)){$input->setAttribute("style",$pstyle);}

   if(!empty($ptabla))
   {
     $input->setAttribute("list",$plist);
     $input->setAttribute("listp",$plist);
     $input->setAttribute("listd",$plistd);
   }


     if($pobj==3)
     {
          $output=$vrinput->appendChild($domi->createElement("output",""));   
//                $output->setAttribute("class","input-output");
               $output->setAttribute("input-output","");
          if(!empty($pid)){$output->setAttribute("id",$pid.'_o');}
          if(!empty($pid)){$output->setAttribute("for",$pid);}
          if(!empty($pstyle3)){$output->setAttribute("style",$pstyle3);}
     }

     if(!empty($ptabla))
     {
          $dlist=$vrinput->appendChild($domi->createElement("datalist",""));   
          $dlist->setAttribute("id",$pid.'_dl');
     }

     $result=$vrinput->appendChild($domi->createElement("result",""));   
          $result->setAttribute("id",$pid.'_r');
          $result->setAttribute("style","display:none;");

if(empty($pdom))
{
     if($pxml==1){$pxml=$domi->saveXML();}
     else{echo $domi->saveXML();}
}     

$pid='';
$pdom='';
$pele='';
$plabel='';
$ptabla='';
$pcolu='';
$plist=''; 
$preado='';
$ponblur='';
$ponkeyd='';
$poninput='';
$pvalue='';
$pclass='';
$pclass1='';
$pclass3='';
$pmaxlen=0;
$pmin=0;
$pmax=0;
$pstep='';
$prows=0;
$pobj=0;
$pexact=0;

$ptype='';
$pplace='';
$pstyle='';
$pstyle1='';
$pstyle3='';
$pwidth='';
$psize='';
$palign='';

?>