__db = $db; } else { $this->__db = new \siaupheng\fonia3\DB\MySQL(); } $this->__button = new Button(); } public function option($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null, $bmulti=false, $bgroup=false) { $_enab = ($benable==true) ? "" : ' disabled=true'; $_req = ($breq==true) ? " required=true" : ""; $_change = ($tchange==null) ? '' : ' onchange="'.$tchange.'"'; $_multi = ($bmulti==true) ? ' multiple' : ''; $tout = ''; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } public function option_db($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $ttable=null, $afield=null, $twhere=null, $addarray=null, $thelp=null, $tchange=null, $bmulti=false) { $afield = ($afield==null) ? array("ID", "Nama", "Label") : $afield; $_twhere = ($twhere==null) ? "" : " WHERE ".$twhere; $_twhere .= ($twhere===null || stripos($twhere,"ORDER BY")===false) ? " ORDER BY ".$afield[1] : ""; $ahasil = []; if (is_array($addarray)) $ahasil[$addarray[0]] = (!isset($afield[2])) ? $addarray[1] : [$addarray[1], $addarray[2]]; if ($ttable<>null) { $this->__db->Query("SELECT ".implode(",", $afield)." FROM ".$ttable.$_twhere); while ($this->__db->Next()) { $ahasil[$this->__db->Row($afield[0])] = (!isset($afield[2])) ? $this->__db->Row($afield[1]) : [$this->__db->Row($afield[1]), $this->__db->Row($afield[2])]; } } $tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange, $bmulti); return $tout; } public function option_que($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $tquery=null, $afield=null, $addarray=null, $thelp="", $tchange=null) { $afield = ($afield==null) ? array("ID", "Nama", "Label") : $afield; $ahasil = array(); if (is_array($addarray)) $ahasil[$addarray[0]] = (!isset($afield[2])) ? $addarray[1] : array($addarray[1], $addarray[2]); if ($tquery<>null) { $this->__db->Query($tquery); while ($this->__db->Next()) { $ahasil[$this->__db->Row($afield[0])] = (!isset($afield[2])) ? $this->__db->Row($afield[1]) : array($this->__db->Row($afield[1]), $this->__db->Row($afield[2])); } } $tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange); return $tout; } public function option_jkl($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) { $akel = array("L" => "Laki-Laki", "P" => "Perempuan"); $tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $akel, $thelp, $tchange); return $tout; } public function option_ulevel($tlabel="", $tfield, $tvalue=9, $benable=true, $breq=false, $thelp="", $tchange=null) { $tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $_SESSION['__WEB_APP']['USER_LEVEL'], $thelp, $tchange); return $tout; } public function radio($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null) { if ($tvalue == null) { $tmp_key = array_keys($aarr); $tvalue = $tmp_key[0]; } $_enab = ($benable==true) ? "" : ' disabled=true'; $_req = ($breq==true) ? " required=true" : ""; $_change = ($tchange==null) ? "" : ' onchange="'.$tchange.'"'; $tout = ''; if (count($aarr)>0) { foreach ($aarr as $key => $val) { $tout .= '
'.$val.'
'; } } $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } public function radio_jkl($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) { $tout = $this->radio($tlabel, $tfield, $tvalue, $benable, $breq, array("L" => "Laki-Laki", "P" => "Perempuan"), $thelp, $tchange); return $tout; } public function radio_gd($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) { $tvalue = ($tvalue=="") ? "X" : $tvalue; $tout = $this->radio($tlabel, $tfield, $tvalue, $benable, $breq, array("A"=>"A", "B"=>"B", "AB"=>"AB", "O"=>"O", "X"=>"NONE"), $thelp, $tchange); return $tout; } public function checkbox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $avalue=array(), $thelp="", $tchange=null) { $bhasil = ((is_string($tvalue) && in_array($tvalue,array("N","T","0"))) or (is_numeric($tvalue) && $tvalue==0) or (is_bool($tvalue) && $tvalue===false) or empty($tvalue)) ? true : false; $_enab = ($benable==true) ? "" : ' disabled=true'; $_req = ($breq==true) ? " required=true" : ""; $_change = ' onchange="this.value=(this.checked)?\''.$avalue[0].'\':\''.$avalue[1].'\';'.($tchange==null?'':$tchange).'"'; $tout = '
__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } //todo: perlu test lagi !! public function switch_sq($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null) { $_key = array_keys($aarr); $_val = array_values($aarr); $_enab = ($benable==true) ? "" : ' disabled=true'; $_req = ($breq==true) ? " required=true" : ""; $_change = ($tchange==null) ? ' onchange="this.value=(this.checked)?\''.$_key[0].'\':\''.$_key[1].'\';"' : ' onchange="this.value=(this.checked)?\''.$_key[0].'\':\''.$_key[1].'\';'.$tchange.'"'; $tout = '
 
'; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } //todo: belum diupgrade !! public function form_group_cbox($tfield, $tkey=null, $tclass=null, $ttable=null, $afield=null, $ncol=2) { if ($ttable==null) return; $avalue = explode(",", $tkey); $afield = ($afield==null) ? array("ID", "Nama") : $afield; $_twhere = ($twhere=="") ? " ORDER BY ".$afield[0] : " WHERE ".$twhere; $tout = ""; $nkol = 1; $this->__db->Query("SELECT ".implode(",", $afield)." FROM ".$ttable.$_twhere); while ($this->__db->Next()) { $tout .= ""; if ($nkol==$ncol) { $tout .= ""; $nkol = 0; } $nkol++; } $tout .= "
"; $this->__aform[$tfield] = $tout; return $tout; } public function textbox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $ttype="text", $holdtxt=null, $nmaxsize=null, $thelp="", $tkeyup=null, $tblur=null) { $_enab = ($benable==true) ? "" : ' readonly'; $_req = ($breq==true) ? " required=true" : ""; $_max = ($nmaxsize==null) ? "" : ' maxlength="'.$nmaxsize.'"'; $_keyup = ($tkeyup==null) ? "" : ' onkeyup="'.$tkeyup.'"'; $_blur = ($tblur==null) ? "" : ' onblur="'.$tblur.'"'; $_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"'; $_tclass = ""; if (in_array($ttype,array("pickdate","picktime"))) { $_tclass = ' '.$ttype; $ttype = "text"; } if (in_array($ttype,array("double"))) { $_tclass = ' '.$ttype; $tvalue = uang2($tvalue); } $tout = ''; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } public function textauto($tlabel="", $tfield, $avalue=['value'=>0,'text'=>""], $benable=true, $breq=false, $holdtxt=null, $nmaxsize=null, $thelp="") { $_enab = ($benable==true) ? "" : ' disabled=true'; $_req = ($breq==true) ? " required=true" : ""; $_max = ($nmaxsize==null) ? "" : ' maxlength="'.$nmaxsize.'"'; $_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"'; $tout = ''; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } /*public function textauto($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $holdtxt=null, $nmaxsize=null, $thelp="") { $tvalue = ($tvalue==null) ? array('value'=>0, 'text'=>"") : $tvalue; $_enab = ($benable==true) ? "" : ' disabled=true'; $_req = ($breq==true) ? " required=true" : ""; $_max = ($nmaxsize==null) ? "" : ' maxlength="'.$nmaxsize.'"'; $_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"'; $tout = ''; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; }*/ public function datebox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tkeyup=null, $tblur=null) { if ($tvalue<>null) $tvalue = tgl_sql2str($tvalue); $tout = '
'; $tout .= $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "pickdate", "dd-mm-yyyy", 12, $thelp, $tkeyup, $tblur); $tout .= '
'; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } public function timebox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tkeyup=null, $tblur=null) { $tout = $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "picktime", "hh:mm:ss", 10, $thelp, $tkeyup, $tblur); return $tout; } public function textarea($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $nrows=1, $holdtxt=null, $thelp="", $tkeyup=null, $tblur=null) { $_enab = ($benable==true) ? "" : ' disabled=true'; $_req = ($breq==true) ? " required=true" : ""; $_rows = ($nrows==null) ? "" : ' rows="'.$nrows.'"'; $_keyup = ($tkeyup==null) ? "" : ' onkeyup="'.$tkeyup.'"'; $_blur = ($tblur==null) ? "" : ' onblur="'.$tblur.'"'; $_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"'; $tout = ''; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout); return $tout; } public function plaintext($tlabel="", $tfield, $tvalue=null) { $tout = ''; $this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>"", 'form'=>$tout); return $tout; } public function password($tlabel="", $tfield, $tvalue="", $benable=true, $breq=false, $holdtxt=null, $nmaxsize=null, $thelp="", $tkeyup=null) { $tout = $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "password", $holdtxt, $nmaxsize, $thelp, $tkeyup, $tblur); return $tout; } public function hidden($tfield, $tvalue="", $tclass="text") { $tout = ''; $this->__ahide[$tfield] = $tout; return $tout; } public function clear() { $this->__aform = array(); } public function show($tstr) { foreach ($this->__aform as $_key => $_val) { $tval = '
'.$_val['form'].($_val['help']==""?'':''.$_val['help'].'').'
'; $tstr = str_replace("_".$_key."_", $tval, $tstr); } $txtbtn = $this->__button->Button($this->__nbtnsize); if (""<>$txtbtn) { $tstr .= '

'; $tstr .= $txtbtn; } foreach ($this->__ahide as $_key => $_val) { $tstr = str_replace("_".$_key."_", $_val, $tstr); } $tstr = str_replace("\n", "", $tstr); $tstr = str_replace("\t", "", $tstr); echo $tstr; } public function btn_separator() { $this->__button->separator(); } public function btn_primary($id="", $label="", $bmiss=false) { $this->__button->primary($id, $label, $bmiss); } public function btn_info($id="", $label="", $bmiss=false) { $this->__button->info($id, $label, $bmiss); } public function btn_danger($id="", $label="", $bmiss=false) { $this->__button->danger($id, $label, $bmiss); } public function btn_warning($id="", $label="", $bmiss=false) { $this->__button->warning($id, $label, $bmiss); } public function btn_success($id="", $label="", $bmiss=false) { $this->__button->success($id, $label, $bmiss); } public function btn_secondary($id="", $label="", $bmiss=false) { $this->__button->secondary($id, $label, $bmiss); } public function Button($size=2) { $this->__nbtnsize = $size; } } ?>