upgrade first session to flightphp

This commit is contained in:
2026-08-19 17:22:07 +07:00
parent 36395c2b55
commit 27ebdca49b
31 changed files with 1383 additions and 7659 deletions
+167 -223
View File
@@ -6,43 +6,51 @@
Desc. : Form Generator (jQuery & Bootstrap)
Created By : Siau Pheng ([email protected]).
Created Date : February 27th, 2008.
Last Modified : December 26th, 2025.
Last Modified : August 19th, 2026.
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Form {
private $__aform = array();
private $__ahide = array();
private $__button = null;
private $__nbtnsize = 2;
protected $__db = null;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
$this->__button = new Button();
final class Form {
private $__aform = [];
private $__ahide = [];
protected Engine $app;
protected SimplePdo $db;
protected Session $session;
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
$this->session = $this->app->session();
}
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 = '<select class="form-select option-tags" id="'.$tfield.'" name="'.$tfield.'"'.$_enab.$_change.$_req.$_multi.' >';
if (count($aarr)>0) {
public function option(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null, bool $multi=false, bool $group=false): string {//oke
$_opsi = '';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true';
if ($req===true) $_opsi .= ' required=true';
if ($multi===true) $_opsi .= ' multiple';
$tout = '<select class="form-select option-tags" id="'.$field.'" name="'.$field.'"'.$_opsi.' >';
if (count($arr)>0) {
$n_group = 0;
foreach ($aarr as $key => $val) {
$aval = [$value];
if ($multi===true) $aval = explode(",", ($value ?? "0"));
foreach ($arr as $key => $val) {
$_val2 = $val; $olabel = "";
if (is_array($val)) {
$_val2 = $val[0];
if ($bgroup) {
if (1==$val[1]) {
if ($group) {
if (1 == $val[1]) {
if (0 < $n_group++) $tout .= '</optgroup>';
$tout .= '<optgroup label="'.$_val2.'">';
continue;
@@ -52,274 +60,210 @@ final class Form {
}
}
$tout .= '<option value="'.$key.'"'.$olabel;
$aval = array($tvalue);
if ($bmulti==true) $aval = explode(",", ($tvalue ?? "0"));
$tout .= (in_array($key, $aval)) ? ' selected="selected"' : "";
$tout .= '>'.$_val2.'</option>';
}
if ($bgroup && $n_group>0) $tout .= '</optgroup>';
if ($group && $n_group>0) $tout .= '</optgroup>';
}
$tout .= '</select>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, '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] : "";
public function option_db(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, ?string $table=null, ?array $afield=null, ?string $where=null, ?array $aarray=null, ?string $help=null, ?string $change=null, bool $multi=false): string {//oke
$_twhere = '';
if (!is_array($afield)) $afield = ["ID", "Nama", "Label"];
if (!empty($where)) {
$_twhere = ' WHERE '.$where;
$_twhere .= (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])];
if (is_array($aarray)) $ahasil[$aarray[0]] = (!isset($afield[2])) ? $aarray[1] : [$aarray[1], $aarray[2]];
if (!empty($table)) {
$aopsi = $this->db->fetchAll("SELECT ".implode(",", $afield)." FROM ".$table.$_twhere);
foreach ($aopsi as $opsi) {
$ahasil[$opsi[$afield[0]]] = (!isset($afield[2])) ? $opsi[$afield[1]] : [$opsi[$afield[1]], $opsi[$afield[2]]];
}
}
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange, $bmulti);
return $tout;
return $this->option($label, $field, $value, $enable, $req, $ahasil, $help, $change, $multi);
}
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]));
public function option_que(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, ?string $query=null, ?array $afield=null, ?array $aarray=null, ?string $help=null, ?string $change=null): string {//oke
if (!is_array($afield)) $afield = ["ID", "Nama", "Label"];
$ahasil = [];
if (is_array($aarray)) $ahasil[$aarray[0]] = (!isset($afield[2])) ? $aarray[1] : [$aarray[1], $aarray[2]];
if (!empty($query)) {
$stat = $this->db->runQuery($query);
while ($row = $stat->fetch()) {
$ahasil[$row[$afield[0]]] = (!isset($afield[2])) ? $row[$afield[1]] : [$row[$afield[1]], $row[$afield[2]]];
}
}
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange);
return $tout;
return $this->option($label, $field, $value, $enable, $req, $ahasil, $help, $change);
}
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_jkl(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
return $this->option($label, $field, $value, $enable, $req, ["L" => "Laki-Laki", "P" => "Perempuan"], $help, $change);
}
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 option_ulevel(string $label, string $field, int $value=9, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
return $this->option($label, $field, $value, $enable, $req, $this->session->get('__WEB_APP')['USER_LEVEL'], $help, $change);
}
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 = '<input type="hidden" id="'.$tfield.'" value="'.$tvalue.'" />';
if (count($aarr)>0) {
foreach ($aarr as $key => $val) {
$tout .= '<div class="form-check form-check-inline me-2"><input class="form-check-input" id="'.$tfield.$key.'" type="radio" value="'.$key.'" name="'.$tfield.'"';
$tout .= ($key == $tvalue) ? ' checked="checked"' : '';
$tout .= ' onclick="if(this.checked)$(\'#'.$tfield.'\').val(this.value);"'.$_enab.$_change.$_req;
$tout .= '><label class="form-check-label" for="'.$tfield.$key.'">'.$val.'</label></div>';
public function radio(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string {//oke
$_val = array_values($arr);
if (empty($value)) $value = $_val[0];
$_opsi = '';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true';
if ($req===true) $_opsi .= ' required=true';
$tout = '<input type="hidden" id="'.$field.'" value="'.$value.'" />';
if (count($arr)>0) {
foreach ($arr as $key => $val) {
$tout .= '<div class="col-form-label form-check form-check-inline me-2"><input class="form-check-input" id="'.$field.$key.'" type="radio" value="'.$key.'" name="'.$field.'"'.$_opsi;
$tout .= ($key == $value) ? ' checked="checked"' : '';
$tout .= '><label class="form-check-label" for="'.$field.$key.'">'.$val.'</label></div>';
}
}
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, '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_jkl(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
return $this->radio($label, $field, $value, $enable, $req, ["L" => "Laki-Laki", "P" => "Perempuan"], $help, $change);
}
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 radio_gd(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
if (!empty($value)) $value = 'X';
return $this->radio($label, $field, $value, $enable, $req, ["A"=>"A", "B"=>"B", "AB"=>"AB", "O"=>"O", "X"=>"NONE"], $help, $change);
}
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 = '<input type="checkbox" class="form-check-input" id="'.$tfield.'" name="'.$tfield.'" value="'.($bhasil?$avalue[1]:$avalue[0]).'"'.$_enab.$_change.$_req;
$tout .= ($bhasil==false) ? ' checked="checked"' : '';
$tout .= '>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function switch($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null) {
$_val = array_values($aarr);
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_change = ($tchange==null) ? ' onchange="this.value=(this.checked)?\''.$_val[0].'\':\''.$_val[1].'\';"' : ' onchange="this.value=(this.checked)?\''.$_val[0].'\':\''.$_val[1].'\';'.$tchange.'"';
$tout = '<div class="form-check form-switch"><input class="form-check-input me-0" id="'.$tfield.'" name="'.$tfield.'" type="checkbox" role="switch" value="'.$tvalue.'"'.$_enab.$_change.$_req;
$tout .= ($_val[0] == $tvalue) ? ' checked="checked"' : '';
public function checkbox(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string {//oke
$_val = array_values($arr);
if (empty($value)) $value = $_val[1];
$_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true';
if ($req===true) $_opsi .= ' required=true';
$tout = '<div class="col-form-label form-check"><input type="checkbox" class="form-check-input" id="'.$field.'" name="'.$field.'" value="'.$value.'"'.$_opsi;
$tout .= ($_val[0] == $value) ? ' checked="checked"' : '';
$tout .= '></div>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, 'form' => $tout];
return $tout;
}
//todo: belum diupgrade !!
public function 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 = "<input id=\"".$tfield."\" value=\"".$tkey."\" type='hidden' class='cgrpbox' /><table width='100%' style='margin:1px 0;padding:2px 2px;'><tr>";
public function switch(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string {//oke
$_val = array_values($arr);
if (empty($value)) $value = $_val[1];
$_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true';
if ($req===true) $_opsi .= ' required=true';
$tout = '<div class="col-form-label form-check form-switch"><input class="form-check-input" id="'.$field.'" name="'.$field.'" type="checkbox" role="switch" value="'.$value.'"'.$_opsi;
$tout .= ($_val[0] == $value) ? ' checked="checked"' : '';
$tout .= '></div>';
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, 'form' => $tout ];
return $tout;
}
$nkol = 1;
$this->__db->Query("SELECT ".implode(",", $afield)." FROM ".$ttable.$_twhere);
while ($this->__db->Next()) {
$tout .= "<td width='".round(100/$ncol)."%'><label><input type='checkbox' id='".$tfield."_cgrpbox_".$this->__db->Row($afield[0])."' value='".$this->__db->Row($afield[0])."'";
for ($i=0; $i<count($avalue); $i++) {
if ($avalue[$i]==$this->__db->Row($afield[0])) {
$tout .= " checked=\"checked\"";
break;
}
}
$tout .= " class='text ".$tclass."' />&nbsp;".$this->__db->Row($afield[1])."</label></td>";
if ($nkol==$ncol) {
$tout .= "</tr><tr>";
$nkol = 0;
}
$nkol++;
public function textbox(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, string $type="text", ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {//oke
$_opsi = '';
if (!empty($keyup)) $_opsi .= ' okyup="'.$keyup.'"';
if (!empty($blur)) $_opsi .= ' oblur="'.$blur.'"';
if (!empty($holdtxt)) $_opsi .= ' placeholder="'.$holdtxt.'"';
if (!empty($maxsize)) $_opsi .= ' maxlength="'.$maxsize.'"';
if ($enable===false) $_opsi .= ' readonly';
if ($req===true) $_opsi .= ' required=true';
$_tclass = '';
if (in_array($type, ['pickdate','picktime','integer','angka','double'])) {
$_tclass = ' '.$type;
if ($type === 'double') $value = uang2($value);
$type = "text";
}
$tout .= "</tr></table>";
$this->__aform[$tfield] = $tout;
$tout = '<input type="'.$type.'" class="form-control'.$_tclass.'" id="'.$field.'" name="'.$field.'" value="'.$value.'"'.$_opsi.' />';
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, 'form' => $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 = '<input type="'.$ttype.'" class="form-control'.$_tclass.'" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'"'.$_enab.$_max.$_keyup.$_blur.$_holdtxt.$_req.' />';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
public function textauto(string $label, string $field, array $avalue=['value'=>0,'text'=>""], bool $enable=true, bool $req=false, ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null): string {//oke
$_opsi = '';
if (!empty($holdtxt)) $_opsi .= ' placeholder="'.$holdtxt.'"';
if (!empty($maxsize)) $_opsi .= ' maxlength="'.$maxsize.'"';
if ($enable===false) $_opsi .= ' disabled=true';
if ($req===true) $_opsi .= ' required=true';
$tout = '<input type="search" class="form-control" id="'.$field.'" name="'.$field.'" value="'.$avalue['text'].'"'.$_opsi.' autocomplete="off" />';
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, '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 = '<input type="search" class="form-control" id="'.$tfield.'" name="'.$tfield.'" value="'.$avalue['text'].'"'.$_enab.$_max.$_holdtxt.$_req.' autocomplete="off" />';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
public function datebox(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {//oke
if (!empty($value)) $value = tgl_sql2str($value);
$tout = '<div class="input-group date">';
$tout .= $this->textbox($label, $field, $value, $enable, $req, "pickdate", "dd-mm-yyyy", null, $help, $keyup, $blur);
$tout .= '<span class="input-group-text input-group-addon"><i class="bi-calendar4"></i></span></div>';
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, '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 = '<div class="input-group">';
$tout .= $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "pickdate", "dd-mm-yyyy", 12, $thelp, $tkeyup, $tblur);
$tout .= '<span class="input-group-text"><i class="bi-calendar4"></i></span></div>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
public function timebox(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {//oke
return $this->textbox($label, $field, $value, $enable, $req, "picktime", "hh:mm:ss", 10, $help, $keyup, $blur);
}
public function textarea(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, int $rows=1, ?string $holdtxt=null, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {//oke
$_opsi = '';
if (!empty($keyup)) $_opsi .= ' okyup="'.$keyup.'"';
if (!empty($blur)) $_opsi .= ' oblur="'.$blur.'"';
if (!empty($holdtxt)) $_opsi .= ' placeholder="'.$holdtxt.'"';
if ($enable===false) $_opsi .= ' disabled=true';
if ($req===true) $_opsi .= ' required=true';
$tout = '<textarea class="form-control" id="'.$field.'" name="'.$field.'" rows="'.$rows.'"'.$_opsi.' >'.$value.'</textarea>';
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, '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);
public function plaintext(string $label, string $field, string|int|null $value=null): string {//oke
$tout = '<input type="text" class="form-control-plaintext" id="'.$field.'" name="'.$field.'" value="'.$value.'" readonly />';
$this->__aform[$field] = ['label' => $label, 'help' => "", 'form' => $tout];
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 = '<textarea class="form-control" id="'.$tfield.'" name="'.$tfield.'"'.$_enab.$_rows.$_keyup.$_blur.$_holdtxt.$_req.' >'.$tvalue.'</textarea>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
public function password(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null, ?string $keyup=null): string {//oke
return $this->textbox($label, $field, $value, $enable, $req, "password", $holdtxt, $maxsize, $help, $keyup, null);
}
public function color(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
$_opsi = '';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true';
if ($req===true) $_opsi .= ' required=true';
$tout = '<input type="color" class="form-control form-control-color" id="'.$field.'" name="'.$field.'" value="'.$value.'"'.$_opsi.' />';
$this->__aform[$field] = ['label' => $label, 'help' => $help, 'form' => $tout];
return $tout;
}
public function plaintext($tlabel="", $tfield, $tvalue=null) {
$tout = '<input type="text" class="form-control-plaintext" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'" readonly />';
$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 color($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_change = ($tchange==null) ? '' : ' onchange="'.$tchange.'"';
$tout = '<input type="color" class="form-control form-control-color" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'"'.$_enab.$_change.$_req.' />';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function hidden($tfield, $tvalue="", $tclass="text") {
$tout = '<input type="hidden" id="'.$tfield.'" value="'.$tvalue.'" class="'.$tclass.'" />';
$this->__ahide[$tfield] = $tout;
public function hidden(string $field, string|int|null $value=null, string $class="text"): string {//oke
$tout = '<input type="hidden" id="'.$field.'" value="'.$value.'" class="'.$class.'" />';
$this->__ahide[$field] = $tout;
return $tout;
}
public function clear() {
$this->__aform = array();
$this->__aform = [];
}
public function show($tstr) {
if ($tstr === 0) $tstr = 4;//default
$col_left = 'col-sm-' . ($tstr+2) . ' col-lg-' . $tstr;
$col_right = 'col-sm-' . (10-$tstr) . ' col-lg-' . (12-$tstr);
$tres = '';
foreach ($this->__aform as $_key => $_val) {
$tval = '<div class="row mb-1"><label class="col-sm-5 col-lg-4 col-form-label" for="'.$_key.'">'.$_val['label'].'</label><div class="col-sm-7 col-lg-8">'.$_val['form'].($_val['help']==""?'':'<span class="help-block"><small>'.$_val['help'].'</small></span>').'</div></div>';
$tstr = str_replace("_".$_key."_", $tval, $tstr);
}
$txtbtn = $this->__button->Button($this->__nbtnsize);
if (""<>$txtbtn) {
$tstr .= '<div class="row mb-1"><div class="col"><hr class="my-2"></div></div>';
$tstr .= $txtbtn;
$tres .= sprintf('<div class="row mb-1"><label class="%s col-form-label" for="%s">%s</label><div class="%s">%s %s</div></div>', $col_left, $_key, $_val['label'], $col_right, $_val['form'], (empty($_val['help'])?'':'<span class="help-block"><small>'.$_val['help'].'</small></span>'));
}
foreach ($this->__ahide as $_key => $_val) {
$tstr = str_replace("_".$_key."_", $_val, $tstr);
$tres .= $_val;
}
$tstr = str_replace("\n", "", $tstr);
$tstr = str_replace("\t", "", $tstr);
echo $tstr;
return $tres;
}
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;
}
}
?>