first commit
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Auth.php
|
||||
Desc. : Fungsi login dan user checking
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : March 16th, 2008.
|
||||
Last Modified : April 3rd, 2022.
|
||||
|
||||
(c) 2008 - 2022, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Auth {
|
||||
private $__id_reg = 0;
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
|
||||
$this->__id_reg = $_SESSION['__WEB_APP']['REG_ID'];
|
||||
}
|
||||
|
||||
public function set_id_reg($id = 0) {
|
||||
if ($id > 0) $this->__id_reg = $id;
|
||||
}
|
||||
|
||||
public function user_check($user, $pass) {
|
||||
$i_hasil = 0;
|
||||
$this->__db->Query("SELECT COUNT(*) Ada FROM app_operator WHERE Username='".$this->__db->safeSQL($user)."' AND Password=MD5('".$this->__db->safeSQL($pass)."') AND Aktif=1");
|
||||
if ($this->__db->Next()) $i_hasil = $this->__db->Row("Ada", 0);
|
||||
return ($i_hasil > 0 ? true : false);
|
||||
}
|
||||
|
||||
public function user_data($user) {
|
||||
$adata = [];
|
||||
$this->__db->Query("SELECT *,DECODE(Menu,'".$this->__id_reg."') Menu2 FROM app_operator WHERE Username='".$this->__db->SafeSQL($user)."'");
|
||||
if ($this->__db->Next()) {
|
||||
$adata = $this->__db->AllRow();
|
||||
$adata['Menu'] = $adata['Menu2'];
|
||||
unset($adata['Menu2']);
|
||||
}
|
||||
if (!isset($_SESSION['APP_TOKEN'])) {
|
||||
$_token = $this->genToken(60);
|
||||
$_SESSION['APP_TOKEN'] = $_token;
|
||||
$this->__db->Query("INSERT INTO app_token SET Token='".$_token."',UserID='".$adata['UserID']."',IP='".$_SERVER['REMOTE_ADDR']."'");
|
||||
}
|
||||
if (intval($adata['Grup_MenuID']) > 0) $adata['Menu_Grup'] = $this->user_allmenu($adata['Grup_MenuID']);
|
||||
$adata['UNIX'] = time();
|
||||
$adata['LOCALE'] = $_SESSION['__WEB_APP']['DEF_LOCALE'];
|
||||
return $adata;
|
||||
}
|
||||
|
||||
public function gen_module_menu() {
|
||||
$amodul = []; $aallow = [];
|
||||
if ($_SESSION['__WEB_APP']['APP_MODULE']) {
|
||||
$this->__db->Query("SELECT * FROM app_menu_grup WHERE Grup_MenuID='".$_SESSION['__WEB_USER']['Grup_MenuID']."' LIMIT 1");
|
||||
if ($this->__db->Next()) $aallow = ($this->__db->Row("Modul_Akses")=="") ? array() : explode(",", $this->__db->Row("Modul_Akses"));
|
||||
if (count($aallow) > 0) {
|
||||
$this->__db->Query("SELECT * FROM (SELECT APP_MODULE,APP_PATH FROM app_config) A LEFT JOIN (SELECT Modul,Urut,Judul,Icon FROM app_menu WHERE Level=0) B ON (A.APP_MODULE=B.Modul) ORDER BY B.Urut");
|
||||
while ($this->__db->Next()) {
|
||||
if (!in_array($this->__db->Row("Modul"), $aallow) || $this->__db->Row("Modul")==$_SESSION['__WEB_APP']['APP_MODULE']) continue;
|
||||
$amodul[] = $this->__db->AllRow();
|
||||
}
|
||||
}
|
||||
}
|
||||
$_SESSION['__WEB_USER']['MENU_MODUL'] = $amodul;
|
||||
}
|
||||
|
||||
public function user_allmenu($id_grup = 0) {
|
||||
$allmenu = "";
|
||||
$this->__db->Query("SELECT DECODE(Menu,'".$this->__id_reg."') MenuX FROM app_menu_grup WHERE Grup_MenuID='".$id_grup."'");
|
||||
if ($this->__db->Next()) $allmenu = $this->__db->Row("MenuX");
|
||||
return $allmenu;
|
||||
}
|
||||
|
||||
public function user_check_level($user, $level = 9) {
|
||||
$i_hasil = 0;
|
||||
$this->__db->Query("SELECT COUNT(*) Ada FROM app_operator WHERE Username='".$this->__db->safeSQL($user)."' AND Level<='".$this->__db->safeSQL($level)."' AND Aktif=1");
|
||||
if ($this->__db->Next()) $i_hasil = $this->__db->Row("Ada", 0);
|
||||
return ($i_hasil > 0 ? true : false);
|
||||
}
|
||||
|
||||
public function user_log() {
|
||||
if ($_SESSION['__WEB_APP']['USER_LOG'] == false) return;
|
||||
$a_hasil = array();
|
||||
$this->__db->Query("SELECT * FROM app_logs WHERE UserID='".user_id()."' ORDER BY Last_Date DESC LIMIT 1");
|
||||
if ($this->__db->Next()) $a_hasil = $this->__db->AllRow();
|
||||
if (count($a_hasil) > 0) {
|
||||
$this->__db->Query("UPDATE app_operator SET Last_IP='".$a_hasil['Last_IP']."',Last_Date='".$a_hasil['Last_Date']."' WHERE UserID='".user_id()."'");
|
||||
}
|
||||
$this->__db->Query("INSERT IGNORE INTO app_logs SELECT UserID,Token,IP,DateStamp FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
$this->__db->Query("DELETE FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
}
|
||||
|
||||
public function token_check() {
|
||||
$hasil = false;
|
||||
$this->__db->Query("SELECT * FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
if ($this->__db->Next()) $hasil = true;
|
||||
if ($hasil == true) $this->__db->Query("UPDATE app_token SET DateStamp=NOW() WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function token_update() {
|
||||
$this->__db->Query("UPDATE app_token SET DateStamp=NOW() WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
}
|
||||
|
||||
public function redirect($appUrl) {
|
||||
$source = parse_url($appUrl);
|
||||
$desti = "";
|
||||
$this->__db->Query("SELECT * FROM app_host WHERE Nama_Host='".$source['host']."'");
|
||||
if ($this->__db->Next()) {
|
||||
$desti = $source['scheme'].$source['host'].$source['path'].'?'.'auth='.$_SESSION['APP_TOKEN'];
|
||||
}
|
||||
return $desti;
|
||||
}
|
||||
|
||||
private function genToken($length = 16) {
|
||||
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
return substr(str_shuffle(str_repeat($pool, 5)), 0, $length);
|
||||
}
|
||||
|
||||
public function getUserByToken($token) {
|
||||
$hasil = "";
|
||||
$this->__db->Query("SELECT * FROM app_operator WHERE UserID IN (SELECT UserID FROM app_token WHERE Token='".$token."') LIMIT 1");
|
||||
if ($this->__db->Next()) $hasil = $this->__db->Row("Username");
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Button.php
|
||||
Desc. : Button Generator (jQuery & Bootstrap)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 27th, 2008.
|
||||
Last Modified : January 22nd, 2024.
|
||||
|
||||
(c) 2008 - 2024, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
class Button {
|
||||
private $__abutton =[];
|
||||
|
||||
public function __construct() {}
|
||||
private function add($type="info", $id="", $label="", $bmiss=false) {
|
||||
if ($id=="") $id = "random".rand(1000, 10000);
|
||||
$this->__abutton[] = ['type'=>$type, 'id'=>$id, 'label'=>$label, 'bmiss'=>$bmiss];
|
||||
}
|
||||
|
||||
public function separator() {
|
||||
$this->__abutton[] = ['type'=>"separator"];
|
||||
}
|
||||
public function primary($id="", $label="", $bmiss=false) {
|
||||
$this->add("primary", $id, $label, $bmiss);
|
||||
}
|
||||
public function info($id="", $label="", $bmiss=false) {
|
||||
$this->add("info", $id, $label, $bmiss);
|
||||
}
|
||||
public function danger($id="", $label="", $bmiss=false) {
|
||||
$this->add("danger", $id, $label, $bmiss);
|
||||
}
|
||||
public function warning($id="", $label="", $bmiss=false) {
|
||||
$this->add("warning", $id, $label, $bmiss);
|
||||
}
|
||||
public function success($id="", $label="", $bmiss=false) {
|
||||
$this->add("success", $id, $label, $bmiss);
|
||||
}
|
||||
public function secondary($id="", $label="", $bmiss=false) {
|
||||
$this->add("secondary", $id, $label, $bmiss);
|
||||
}
|
||||
|
||||
public function Button($size=2) {
|
||||
if (0==count($this->__abutton)) return "";
|
||||
$_out = '<div class="row mb-1"><div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-start">'; $_ma = ' me-sm-2';
|
||||
foreach ($this->__abutton as $item) {
|
||||
if ("separator" == $item['type']) {
|
||||
$_out .= '</div><div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-end">'; $_ma = ' ms-sm-2';
|
||||
} else {
|
||||
$_out .= '<button type="button" class="btn btn-'.$item['type'].' mb-2 mb-sm-0'.$_ma.' col-10 col-sm-auto shadow-none" id="'.$item['id'].'"'.(true==$item['bmiss']?' data-bs-dismiss="modal"':'').'>'.$item['label'].'</button>';
|
||||
}
|
||||
}
|
||||
$_out .= '</div></div>';
|
||||
return $_out;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Form.php
|
||||
Desc. : Form Generator (jQuery & Bootstrap)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 27th, 2008.
|
||||
Last Modified : December 26th, 2025.
|
||||
|
||||
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
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;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\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 = '<select class="form-select option-tags" id="'.$tfield.'" name="'.$tfield.'"'.$_enab.$_change.$_req.$_multi.' >';
|
||||
if (count($aarr)>0) {
|
||||
$n_group = 0;
|
||||
foreach ($aarr as $key => $val) {
|
||||
$_val2 = $val; $olabel = "";
|
||||
if (is_array($val)) {
|
||||
$_val2 = $val[0];
|
||||
if ($bgroup) {
|
||||
if (1==$val[1]) {
|
||||
if (0 < $n_group++) $tout .= '</optgroup>';
|
||||
$tout .= '<optgroup label="'.$_val2.'">';
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$olabel = (isset($val[1])) ? ' olabel="'.$val[1].'"' : "";
|
||||
}
|
||||
}
|
||||
$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>';
|
||||
}
|
||||
$tout .= '</select>';
|
||||
$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 = '<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>';
|
||||
}
|
||||
}
|
||||
$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 = '<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"' : '';
|
||||
$tout .= '></div>';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, '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>";
|
||||
|
||||
$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."' /> ".$this->__db->Row($afield[1])."</label></td>";
|
||||
if ($nkol==$ncol) {
|
||||
$tout .= "</tr><tr>";
|
||||
$nkol = 0;
|
||||
}
|
||||
$nkol++;
|
||||
}
|
||||
$tout .= "</tr></table>";
|
||||
$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 = '<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);
|
||||
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);
|
||||
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);
|
||||
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 = '<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);
|
||||
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;
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
$this->__aform = array();
|
||||
}
|
||||
|
||||
public function show($tstr) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Menu.php
|
||||
Desc. : Class menu
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 16th, 2008.
|
||||
Last Modified : December 26th, 2025.
|
||||
|
||||
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Menu {
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
$this->__db = $db ?? new \siaupheng\webapp\DB\MySQL();
|
||||
}
|
||||
|
||||
private function Menu_Query($qry = "", $order = "Kode") {
|
||||
$twhere = ($qry!="") ? "WHERE ".$qry : "";
|
||||
$this->__db->Query("SELECT * FROM app_menu ".$twhere." ORDER BY ".$order." ASC");
|
||||
$ahasil = array();
|
||||
while ($this->__db->Next()) {
|
||||
$ahasil[] = $this->__db->AllRow();
|
||||
}
|
||||
return $ahasil;
|
||||
}
|
||||
|
||||
public function Menu_Sidebar() {//oke
|
||||
$a_modul = array();
|
||||
$is_modul = (($_SESSION['__WEB_APP']['APP_MODULE'] ?? "") <> "") ? true : false;
|
||||
if ($is_modul == true) {
|
||||
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
|
||||
} else {
|
||||
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
|
||||
for ($i=0; $i<count($atmp); $i++) {
|
||||
$a_modul[] = $atmp[$i]['Modul'];
|
||||
}
|
||||
}
|
||||
|
||||
$my_menu = array_unique(array_filter(explode(",", $_SESSION['__WEB_USER']['Menu_Grup'].",".$_SESSION['__WEB_USER']['Menu'])));
|
||||
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
|
||||
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
|
||||
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
|
||||
|
||||
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
|
||||
$thasil = '';
|
||||
|
||||
$last_level = 0;
|
||||
for ($i=0; $i<count($amodul); $i++) {
|
||||
if (($i>0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) {
|
||||
$thasil .= str_repeat("</ul></li>", $amodul[$i-1]['Level']-$amodul[$i]['Level']);
|
||||
}
|
||||
$ticon = ($amodul[$i]['Icon']) ? '<i class="me-2 '.$amodul[$i]['Icon'].'"></i>' : "";
|
||||
if (($amodul[$i]['Level']>=0) && (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level']))) {
|
||||
$thasil .= '<li class="nav-item has-submenu"><a class="nav-link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'<i class="bi-caret-down float-end"></i></a><ul class="submenu collapse">';
|
||||
} else if (trim($amodul[$i]['Menu'])=="-") {
|
||||
$thasil .= '<li class="nav-divider"></li>';
|
||||
} else {
|
||||
$thasil .= '<li class="nav-item"><a class="nav-link mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a></li>';
|
||||
}
|
||||
$last_level = $amodul[$i]['Level'];
|
||||
}
|
||||
if ($last_level>1) $thasil .= str_repeat("</ul></li>", $last_level-1);
|
||||
return $thasil;
|
||||
}
|
||||
|
||||
public function Menu_Header() {//oke
|
||||
$a_modul = array();
|
||||
$is_modul = (($_SESSION['__WEB_APP']['APP_MODULE'] ?? "") <> "") ? true : false;
|
||||
$mulai_level = 0;
|
||||
if ($is_modul == true) {
|
||||
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
|
||||
$mulai_level = 1;
|
||||
} else {
|
||||
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
|
||||
for ($i=0; $i<count($atmp); $i++) {
|
||||
$a_modul[] = $atmp[$i]['Modul'];
|
||||
}
|
||||
}
|
||||
|
||||
$my_menu = array_unique(array_filter(explode(",", $_SESSION['__WEB_USER']['Menu_Grup'].",".$_SESSION['__WEB_USER']['Menu'])));
|
||||
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
|
||||
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
|
||||
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
|
||||
|
||||
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
|
||||
$thasil = '';
|
||||
|
||||
$last_level = 0;
|
||||
for ($i=0; $i<count($amodul); $i++) {
|
||||
if (($i>0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) {
|
||||
$thasil .= str_repeat("</ul></li>", $amodul[$i-1]['Level']-$amodul[$i]['Level']);
|
||||
}
|
||||
$ticon = ($amodul[$i]['Icon']) ? '<i class="me-2 '.$amodul[$i]['Icon'].'"></i>' : "";
|
||||
if (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level'])) {//have submenu
|
||||
if ($amodul[$i]['Level']==$mulai_level) {
|
||||
$thasil .= '<li class="nav-item pe-4 dropdown"><a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a><ul class="dropdown-menu" data-bs-popper="none">';
|
||||
} else {
|
||||
$thasil .= '<li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle slink" data-bs-toggle="dropdown" aria-expanded="false" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a><ul class="dropdown-menu" data-bs-popper="none">';
|
||||
}
|
||||
} else if (trim($amodul[$i]['Menu'])=="-" && $amodul[$i]['Level']>$mulai_level) {//divider
|
||||
$thasil .= '<li class="dropdown-divider"></li>';
|
||||
} else if ($amodul[$i]['Level']==$mulai_level) {//level = 1 + no submenu
|
||||
$thasil .= '<li class="nav-item pe-4"><a class="nav-link mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a></li>';
|
||||
} else {// level > 1 + no submenu
|
||||
$thasil .= '<li><a class="dropdown-item mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a></li>';
|
||||
}
|
||||
$last_level = $amodul[$i]['Level'];
|
||||
}
|
||||
if ($last_level>$mulai_level) $thasil .= str_repeat("</ul></li>", $last_level-$mulai_level);
|
||||
return $thasil;
|
||||
}
|
||||
|
||||
static function MenuJSON($db = null, $page = "", $tquery = "") {//oke
|
||||
$_mdb = $db ?? new \siaupheng\webapp\DB\MySQL();
|
||||
$_query = ($tquery=="") ? "" : ",'".$tquery."'";
|
||||
$ajson = ['login' => true];
|
||||
$apage = ['Link' => ""];
|
||||
|
||||
$acus_page = [
|
||||
'SYSP' => ['Kode'=>"SYSP", 'Judul'=>"Profil Pengguna", 'Link'=>"sys/profile.php", 'JS'=>"SYSProfileJS", 'Width'=>600, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]'],
|
||||
'SYSC' => ['Kode'=>"SYSC", 'Judul'=>"Ubah Password", 'Link'=>"sys/chpasswd.php", 'JS'=>"SYSChpasswdJS", 'Width'=>500, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]']
|
||||
];
|
||||
|
||||
if ($acus_page[$page] ?? false) {
|
||||
$apage = $acus_page[$page];
|
||||
} else if ($page <> "") {
|
||||
$_mdb->Query("SELECT * FROM app_menu WHERE Kode='".$page."'");
|
||||
if ($_mdb->Next()) $apage = $_mdb->AllRow();
|
||||
$apage['Width'] = intval($apage['Width']);
|
||||
}
|
||||
|
||||
$ajson['iswindow'] = ($apage['Width'] > 0) ? true : false;
|
||||
$ajson['width'] = $apage['Width'];
|
||||
$ajson['title'] = $apage['Judul'];
|
||||
$ajson['button'] = is_json($apage['Button']) ? json_decode($apage['Button']) : $apage['Button'];
|
||||
$ajson['php'] = $apage['Link'];
|
||||
$ajson['func'] = $apage['JS'];
|
||||
$ajson['kode'] = $apage['Kode'];
|
||||
|
||||
if (!file_exists($_SESSION['__WEB_APP']['REAL_PATH']."apps/php/".$apage['Link'])) $ajson['php'] = "";
|
||||
return $ajson;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Param.php
|
||||
Desc. : Class data parameter dari client side
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 14th, 2013.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2013 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Param {
|
||||
private static $__ahasil = [];
|
||||
|
||||
public function __construct() {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
}
|
||||
|
||||
private static function __data() {
|
||||
$_asumber = array_merge($_REQUEST, $_POST, $_GET);
|
||||
foreach ($_asumber as $__key => $__val) {
|
||||
self::$__ahasil[$__key] = self::safeSQL($__val);
|
||||
}
|
||||
}
|
||||
|
||||
public static function safeSQL($tstr = "") {
|
||||
$_se = array("\\","\0","\n","\r","\x1a","'",'"');
|
||||
$_re = array("\\\\","\\0","\\n","\\r","\Z","\'",'\"');
|
||||
return str_replace($_se, $_re, $tstr);
|
||||
}
|
||||
|
||||
public static function Get($tkey = "", $tdef = null) {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
if (isset(self::$__ahasil[$tkey]) && self::$__ahasil[$tkey]) return self::$__ahasil[$tkey];
|
||||
return $tdef;
|
||||
}
|
||||
|
||||
public static function Get_Text($tkey = "", $tdef = null) {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
$_str = (isset(self::$__ahasil[$tkey])) ? self::$__ahasil[$tkey] : $tdef;
|
||||
$_str = str_replace("\\r", "", $_str);
|
||||
$_str = str_replace("\\n", " ", $_str);
|
||||
$_str = str_replace("\\t", " ", $_str);
|
||||
return (trim($_str));
|
||||
}
|
||||
|
||||
public static function Get_Array() {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
return self::$__ahasil;
|
||||
}
|
||||
|
||||
public static function Get_ArrayCBOX() {//note: bisa tidak dipakai lagi
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
$_ahasil = [];
|
||||
foreach (self::$__ahasil as $__key => $__val) {
|
||||
if (strpos($__key, "_cbox_")>0) {
|
||||
$_tmpkey = substr($__key, strpos($__key, "_cbox_")+6);
|
||||
$_ahasil[$_tmpkey] = $__val;
|
||||
}
|
||||
}
|
||||
return $_ahasil;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Register.php
|
||||
Desc. : Class Registrasi Aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23th, 2011.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Register {
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
|
||||
}
|
||||
|
||||
static public function reg_id() {
|
||||
$id = $_SESSION['__WEB_APP']['REG_ID'] ?? "";
|
||||
return (substr($id,0,3).".".substr($id,3,3).".".substr($id,6));
|
||||
}
|
||||
|
||||
static public function reg_code() {
|
||||
$id = $_SESSION['__WEB_APP']['REG_CODE'];
|
||||
return (substr($id,0,6)."-".substr($id,6,5)."-".substr($id,11,5)."-".substr($id,16,5)."-".substr($id,21,5)."-".substr($id,26,6));
|
||||
}
|
||||
|
||||
public function reg_check() {
|
||||
$isreg = false;
|
||||
$this->__db->Query("SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1)) KODE_REGISTER FROM app_config WHERE REG_ID='".$_SESSION['__WEB_APP']['APP_CODE']."' LIMIT 1");
|
||||
if ($this->__db->Next()) {
|
||||
if ($this->__db->Row("KODE_REGISTER","")==$_SESSION['__WEB_APP']['REG_CODE']) $isreg = true;
|
||||
}
|
||||
return $isreg;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Table.php
|
||||
Desc. : HTML Table (jQuery & Bootstrap)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 16th, 2008.
|
||||
Last Modified : January 26th, 2026.
|
||||
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Table {
|
||||
private $__ttable = "";
|
||||
private $__tfield = "";
|
||||
private $__twhere = "";
|
||||
private $__tquery = "";
|
||||
private $__tquery_footer = "";
|
||||
private $__aheader = [];
|
||||
private $__afield = [];
|
||||
private $__astyle = [];
|
||||
private $__aformat = [];
|
||||
private $__afooter = [];
|
||||
private $__aotype = [];
|
||||
private $__arowcol = [];
|
||||
private $__arow_func = [];
|
||||
private $__tfunc_select = "";
|
||||
private $__tfunc_navi = "";
|
||||
private $__btxtbutton = false;
|
||||
private $__bnobutton = false;
|
||||
private $__bscrollbar = false;
|
||||
private $__acontrol = ['field'=>false, 'value'=>""];
|
||||
private $__acbox = [];
|
||||
private $__aoption = [];
|
||||
private $__npage_rec = 10;
|
||||
private $__nreclimit = 0;
|
||||
private $__nscrollheight = 0;
|
||||
private $__ord_field = "";
|
||||
private $__ord_dir = "A";
|
||||
private $__tcss = "";
|
||||
private $__livedata = false;
|
||||
protected $__cdb = null;
|
||||
protected $__cpa = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__cdb = $db; }
|
||||
else { $this->__cdb = new \siaupheng\webapp\DB\MySQL(); }
|
||||
$this->__cpa = new \siaupheng\webapp\Web\Param();
|
||||
}
|
||||
|
||||
public function set_table($ttable = "", $tfield = "", $twhere = "") {
|
||||
$this->__ttable = $ttable;
|
||||
if ($tfield != "") $this->__tfield = $tfield;
|
||||
if ($twhere != "") $this->__twhere = $twhere;
|
||||
}
|
||||
|
||||
public function set_query($tquery = "") {
|
||||
$this->__tquery = $tquery;
|
||||
}
|
||||
|
||||
public function set_query_footer($tquery = "") {
|
||||
$this->__tquery_footer = $tquery;
|
||||
}
|
||||
|
||||
public function set_css($tcss = "") {
|
||||
$this->__tcss = $tcss;
|
||||
}
|
||||
|
||||
public function set_limit($nlimit = 0) {
|
||||
$this->__nreclimit = $nlimit;
|
||||
}
|
||||
|
||||
public function set_field_order($tfield = "", $torder = "A") {
|
||||
$this->__ord_field = $tfield;
|
||||
$this->__ord_dir = $torder;
|
||||
}
|
||||
|
||||
public function set_textbtn($bistxt = true) {
|
||||
$this->__btxtbutton = $bistxt;
|
||||
}
|
||||
|
||||
public function set_scrollbar($bisscroll = true, $nheight = 200) {
|
||||
$this->__bscrollbar = $bisscroll;
|
||||
$this->__nscrollheight = $nheight;
|
||||
}
|
||||
|
||||
public function set_row_color($tfield = "", $tval = "", $tcss = "") {
|
||||
if ($tfield=="") return;
|
||||
$this->__arowcol[] = ['F'=>$tfield, 'V'=>$tval, 'C'=>$tcss];
|
||||
}
|
||||
|
||||
public function set_func_navi($tfunc = "") {
|
||||
$this->__tfunc_navi = $tfunc;
|
||||
}
|
||||
|
||||
public function set_func_select($tfunc = "") {
|
||||
$this->__tfunc_select = $tfunc;
|
||||
}
|
||||
|
||||
public function set_func_btn($tfunc = "", $tlabel = "") {
|
||||
$this->__arow_func[] = ['label' => $tlabel, 'func' => $tfunc];
|
||||
}
|
||||
|
||||
public function set_row_control($tfield = "", $tvalue = "Y") {
|
||||
$this->__acontrol['field'] = $tfield;
|
||||
$this->__acontrol['value'] = $tvalue;
|
||||
}
|
||||
|
||||
public function add_row_form($ticon = "pencil", $tlabel = "", $tfunc = "", $tfield = "", $tvalue = "") {
|
||||
if ($tfunc == "") {
|
||||
$this->__aoption[] = ['type' => "button-dt", 'func' => $tlabel, 'icon' => "pencil", 'label' => $ticon];
|
||||
} else {//todo: new format with icon, upgrade all later !
|
||||
$this->__aoption[] = ['type' => "button-dt", 'func' => $tfunc, 'icon' => $ticon, 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue];
|
||||
}
|
||||
}
|
||||
|
||||
public function add_row_btn($ticon = "", $tlabel = "", $tfunc = "", $tfield = "", $tvalue = "", $tfield_css = "", $avalue_css = []) {
|
||||
$this->__aoption[] = ['type' => "button", 'func' => $tfunc, 'icon' => $ticon, 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue, 'field_css' => $tfield_css, 'avalue_css' => $avalue_css];
|
||||
}
|
||||
|
||||
public function add_row_del($tlabel = "", $tfunc = "", $tfield = "Unix", $tvalue = "") {
|
||||
$this->__aoption[] = ['type' => "button", 'func' => $tfunc, 'icon' => "x", 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue];
|
||||
}
|
||||
|
||||
public function add_row_edit($tlabel = "", $tfunc = "") {
|
||||
$this->add_row_btn("note", $tlabel, $tfunc);
|
||||
}
|
||||
|
||||
public function add_row_checkbox($tfield = "ID", $tcontrol = "Edit", $avalue = ["Y","N"]) {
|
||||
$this->__acbox['field'] = $tfield;
|
||||
$this->__acbox['control'] = $tcontrol;
|
||||
$this->__acbox['avalue'] = $avalue;
|
||||
$this->__aoption[] = ['type' => "checkbox", 'field' => $tfield, 'avalue' => $avalue];
|
||||
}
|
||||
|
||||
public function no_button() {
|
||||
$this->__bnobutton = true;
|
||||
}
|
||||
|
||||
public function add_field($tfield = "", $theader = "", $tstyle = "l", $tformat = "", $tfooter = "", $totype = "") {
|
||||
$this->__aheader[] = $theader;
|
||||
$this->__afield[] = $tfield;
|
||||
$this->__astyle[] = $tstyle;
|
||||
$this->__aformat[] = $tformat;
|
||||
$this->__afooter[] = $tfooter;
|
||||
$this->__aotype[] = $totype;
|
||||
}
|
||||
|
||||
public function json_table($nama_tabel = "tabel_", $baris_tabel = 10) {
|
||||
$adata = []; $njml_kol = 0;
|
||||
|
||||
// adding header
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$adata['header'][] = ['f'=>$this->__astyle[$i], 'o'=>$this->__afield[$i], 'c'=>$this->__aheader[$i], 's'=>$this->__aotype[$i]];
|
||||
$njml_kol += ($this->__astyle[$i]=="hidden") ? 0 : 1;
|
||||
}
|
||||
|
||||
// adding footer
|
||||
if ($this->__tquery_footer) {
|
||||
$this->__cdb->Query($this->__tquery_footer);
|
||||
$this->__cdb->Next();
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tval = $this->__cdb->Row($this->__afield[$i], 0);
|
||||
if (is_array($this->__afooter[$i])) {
|
||||
$tval2 = $this->__afooter[$i][$tval];
|
||||
} else if (!is_null($this->__afooter[$i]) && function_exists($this->__afooter[$i])) {
|
||||
$tval2 = call_user_func($this->__afooter[$i], $tval);
|
||||
} else {
|
||||
$tval2 = ($this->__afooter[$i]<>"") ? $this->__afooter[$i] : $tval;
|
||||
}
|
||||
$adata['footer'][] = ['c'=>$tval2];
|
||||
}
|
||||
}
|
||||
|
||||
$acontent = [];
|
||||
if (!$this->__livedata) {
|
||||
$this->__cdb->Query($this->__tquery);
|
||||
while ($this->__cdb->Next()) {
|
||||
$abaris = [];
|
||||
$aoption = ['button'=>[]];
|
||||
if (count($this->__aoption)>0) {
|
||||
if ((($this->__acontrol['field']===false) || ($this->__cdb->Row($this->__acontrol['field'])==$this->__acontrol['value'])) && $this->__bnobutton===false) {
|
||||
// adding all option
|
||||
for ($i=0; $i<count($this->__aoption); $i++) {
|
||||
if (in_array($this->__aoption[$i]['type'], ["button","button-dt"])) {
|
||||
if (!isset($this->__aoption[$i]['field'])) continue;
|
||||
if (($this->__aoption[$i]['field']!="") && ($this->__cdb->Row($this->__aoption[$i]['field'])<>(trim("".$this->__aoption[$i]['value'])!="" ? $this->__aoption[$i]['value'] : $_SESSION['__WEB_USER']['UNIX']))) {} else {
|
||||
$aoption['button'][] = [$this->__aoption[$i]['icon'], (empty($this->__aoption[$i]['field_css'])?'':$this->__aoption[$i]['avalue_css'][$this->__cdb->Row($this->__aoption[$i]['field_css'])]??'')];
|
||||
}
|
||||
}
|
||||
}
|
||||
// adding checkbox option
|
||||
if (array_key_exists("field", $this->__acbox)) {
|
||||
$aoption['checkbox']['field'] = $this->__cdb->Row($this->__acbox['field']);
|
||||
$aoption['checkbox']['value'] = $this->__cdb->Row($this->__acbox['control']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($this->__arowcol)>0) {//up: 2014-06-13
|
||||
for ($i=0; $i<count($this->__arowcol); $i++) {
|
||||
if ($this->__cdb->Row($this->__arowcol[$i]['F']) == $this->__arowcol[$i]['V']) $aoption['rowcss'] = $this->__arowcol[$i]['C'];
|
||||
}
|
||||
}
|
||||
$abaris[] = $aoption;
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tval = stripslashes($this->__cdb->Row($this->__afield[$i]));//up: 2015-01-05
|
||||
if (is_array($this->__aformat[$i])) {
|
||||
$tval = $this->__aformat[$i][$tval];
|
||||
} else if (!is_null($this->__aformat[$i]) && function_exists($this->__aformat[$i])) {
|
||||
$tval = call_user_func($this->__aformat[$i], $tval);
|
||||
}
|
||||
$abaris[] = $tval;
|
||||
}
|
||||
$acontent[] = $abaris;
|
||||
}
|
||||
}
|
||||
|
||||
// navigator
|
||||
$anavi = [ 'func_navi' => $this->__tfunc_navi, 'button' => $this->__arow_func ];
|
||||
|
||||
$adata['type'] = "table";
|
||||
$adata['id'] = $nama_tabel;
|
||||
$adata['config'] = ['css' => $this->__tcss, 'row_count' => $baris_tabel, 'func_select' => $this->__tfunc_select, 'nobutton' => $this->__bnobutton, 'txtbutton' => $this->__btxtbutton, 'scrollbar' => $this->__bscrollbar, 'scroll_height' => $this->__nscrollheight, 'sort_col' => $this->__ord_field, 'sort_dir' => $this->__ord_dir, 'live' => $this->__livedata];
|
||||
$adata['option'] = [];
|
||||
foreach ($this->__aoption as $aval) {
|
||||
if ($aval['type']!=="checkbox") unset($aval['field']); unset($aval['value']); unset($aval['field_css']); unset($aval['value_css']); $adata['option'][] = $aval;
|
||||
}
|
||||
$adata['navi'] = $anavi;
|
||||
$adata['content'] = $acontent;
|
||||
return $adata;
|
||||
}
|
||||
|
||||
public function db_table($nama_tabel = "tabel_", $baris_tabel = 10) {
|
||||
$adata = [];
|
||||
$this->__livedata = true;
|
||||
$this->prepare_query();
|
||||
$id_draw = intval($this->__cpa->Get("draw", 0));
|
||||
$i_start = intval($this->__cpa->Get("start", 0));
|
||||
$i_length = intval($this->__cpa->Get("length", 0));
|
||||
$i_order = $this->__cpa->Get("order", 0);
|
||||
|
||||
if ($id_draw > 0) {
|
||||
$record = 0;
|
||||
$this->__cdb->Query("SELECT COUNT(*) Item FROM ".$this->__ttable.$this->__twhere);
|
||||
if ($this->__cdb->Next()) $record = intval($this->__cdb->Row("Item", 0));
|
||||
$adata['type'] = "table-live";
|
||||
$adata['id'] = $nama_tabel;
|
||||
$adata['config'] = ['draw' => $id_draw, 'recordsTotal' => $record, 'recordsFiltered' => $record];
|
||||
|
||||
$t_order = "ASC";
|
||||
if ($i_order <> 0) {
|
||||
$t_order = ($i_order[0]['dir']=="asc") ? "ASC" : "DESC";
|
||||
$i_order = $i_order[0]['column'];
|
||||
}
|
||||
if (($i_length > $record) || ($i_start >= $record) || ($record <= 10)) $i_length = -1;
|
||||
$sql_limit = ($i_start>=0 && $i_length != -1) ? " LIMIT ".$i_start.", ".$i_length : "";
|
||||
$sql_order = ($this->__afield[$i_order]) ? " ORDER BY ".$this->__afield[$i_order]." ".$t_order : "";
|
||||
|
||||
$adata['data'] = [];
|
||||
$this->__cdb->Query("SELECT ".$this->__tfield." FROM ".$this->__ttable.$this->__twhere.$sql_order.$sql_limit);
|
||||
while ($this->__cdb->Next()) {
|
||||
$abaris = [];
|
||||
$aoption = ['button'=>[]];
|
||||
if (count($this->__aoption)>0) {
|
||||
if ((($this->__acontrol['field']===false) || ($this->__cdb->Row($this->__acontrol['field'])==$this->__acontrol['value'])) && $this->__bnobutton===false) {
|
||||
// adding all option
|
||||
for ($i=0; $i<count($this->__aoption); $i++) {
|
||||
if (in_array($this->__aoption[$i]['type'], ["button","button-dt"])) {
|
||||
if (($this->__aoption[$i]['field']!="") && ($this->__cdb->Row($this->__aoption[$i]['field'])<>(trim("".$this->__aoption[$i]['value'])!="" ? $this->__aoption[$i]['value'] : $_SESSION['__WEB_USER']['UNIX']))) {} else {
|
||||
$aoption['button'][] = [$this->__aoption[$i]['icon'], (empty($this->__aoption[$i]['field_css'])?'':$this->__aoption[$i]['avalue_css'][$this->__cdb->Row($this->__aoption[$i]['field_css'])]??'')];
|
||||
}
|
||||
}
|
||||
}
|
||||
// adding checkbox option
|
||||
if (array_key_exists("field", $this->__acbox)) {
|
||||
$aoption['checkbox']['field'] = $this->__cdb->Row($this->__acbox['field']);
|
||||
$aoption['checkbox']['value'] = $this->__cdb->Row($this->__acbox['control']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($this->__arowcol)>0) {//up: 2014-06-13
|
||||
for ($i=0; $i<count($this->__arowcol); $i++) {
|
||||
if ($this->__cdb->Row($this->__arowcol[$i]['F']) == $this->__arowcol[$i]['V']) $aoption['rowcss'] = $this->__arowcol[$i]['C'];
|
||||
}
|
||||
}
|
||||
$abaris[] = $aoption;
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tval = stripslashes($this->__cdb->Row($this->__afield[$i]));//up: 2015-01-05
|
||||
if (is_array($this->__aformat[$i])) {
|
||||
$tval = $this->__aformat[$i][$tval];
|
||||
} else if (!is_null($this->__aformat[$i]) && function_exists($this->__aformat[$i])) {
|
||||
$tval = call_user_func($this->__aformat[$i], $tval);
|
||||
}
|
||||
$abaris[] = $tval;
|
||||
}
|
||||
$adata['data'][] = $abaris;
|
||||
}
|
||||
} else {
|
||||
$adata = $this->json_table($nama_tabel, $baris_tabel);
|
||||
}
|
||||
return $adata;
|
||||
}
|
||||
|
||||
private function prepare_query() {
|
||||
if ($this->__tfield == "") $this->__tfield = "`".implode('`,`', $this->__afield)."`";
|
||||
if ($this->__twhere != "") $this->__twhere = " WHERE " . $this->__twhere;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Terbilang.php
|
||||
Desc. : Class Format Angka & Terbilang
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 12th, 2009.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2009 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Terbilang {
|
||||
private $numb = array("","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan");
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function Terbilang($nilai=0, $muang="Rupiah") {
|
||||
$number = 0;
|
||||
$hasil = "";
|
||||
$int = trim($nilai);
|
||||
if (is_int(strpos($int,"-"))) {
|
||||
$number = substr($int,strpos($int,"-")+1,strlen($int));
|
||||
$hasil = "Minus";
|
||||
} else {
|
||||
$number = $int;
|
||||
}
|
||||
|
||||
# strpost : untuk mencari "." pada variabel number
|
||||
$xpos = strpos($number,".");
|
||||
if (is_int($xpos)) {
|
||||
# round : Untuk pembulatan angka desimal, strlen : untuk menghitung jumlah karakter
|
||||
$pecahan = round(substr($number,$xpos,strlen($number)),2);
|
||||
$last = substr($number,0,$xpos);
|
||||
} else {
|
||||
$pecahan = "";
|
||||
$last = $number;
|
||||
}
|
||||
if ($last==0 || $number==0) {
|
||||
return $hasil."NOL ".$muang;
|
||||
} else {
|
||||
# floor : Pembulatan angka terbaik dari desimal, pow : Ekspresi Eksponensial
|
||||
$triliun = floor($last/pow(10,12));
|
||||
$last = $this->mod($last,1000000000000);
|
||||
|
||||
$miliar = floor($last/pow(10,9));
|
||||
$last = $this->mod($last,1000000000);
|
||||
|
||||
$juta = floor($last/pow(10,6));
|
||||
$last = $this->mod($last,1000000);
|
||||
|
||||
$ribu = floor($last/pow(10,3));
|
||||
$last = $this->mod($last,1000);
|
||||
|
||||
$kata = $this->tigadigit($triliun, "Triliun");
|
||||
$kata .= $this->tigadigit($miliar, "Miliar");
|
||||
$kata .= $this->tigadigit($juta, "Juta");
|
||||
$kata .= $this->tigadigit($ribu, "Ribu");
|
||||
$kata .= $this->tigadigit($last, "");
|
||||
$kata .= " ".$muang;
|
||||
}
|
||||
if ($pecahan>0) {
|
||||
$kata .= " Dan". $this->tigadigit(round($pecahan*100),"Sen");
|
||||
}
|
||||
return $hasil . $kata;
|
||||
}
|
||||
|
||||
private function mod($a, $b) {
|
||||
return $a-$b*floor($a/$b);
|
||||
}
|
||||
|
||||
private function tigadigit($amount, $suffix="") {
|
||||
$last = (int) $amount;
|
||||
$kata = "";
|
||||
if ($last == 1 && $suffix=="Ribu") {
|
||||
$kata = " Seribu";
|
||||
return $kata;
|
||||
}
|
||||
if ($last < 20 && $last > 10) {
|
||||
if ($last==11) {
|
||||
$kata = " Sebelas";
|
||||
} else {
|
||||
$kata = " ".$this->numb[$last-10]." Belas";
|
||||
}
|
||||
if ($suffix != "") {
|
||||
$kata .= " ". $suffix;
|
||||
}
|
||||
return $kata;
|
||||
}
|
||||
$ratus = floor($last/100);
|
||||
if ($ratus <= 0) {
|
||||
$kata .= "";
|
||||
} elseif ($ratus == 1) {
|
||||
$kata .= " Seratus";
|
||||
} else {
|
||||
$kata .= " ".$this->numb[$ratus]." Ratus";
|
||||
}
|
||||
$last = $this->mod($last,100);
|
||||
if ($last < 20 && $last > 10) {
|
||||
if ($last == 11) {
|
||||
$kata .= " Sebelas ". $suffix;
|
||||
} else {
|
||||
$kata .= " ".$this->numb[$last-10]." Belas ". $suffix;
|
||||
}
|
||||
return $kata;
|
||||
}
|
||||
$puluh = floor($last/10);
|
||||
if ($puluh == 0) {
|
||||
$kata .= "";
|
||||
} elseif ($puluh == 1) {
|
||||
$kata .= " Sepuluh";
|
||||
} else {
|
||||
$kata .= " ".$this->numb[$puluh]." Puluh";
|
||||
}
|
||||
$last = $this->mod($last,10);
|
||||
if ($last>0 && $last<=9) {
|
||||
$kata .= " ".$this->numb[$last];
|
||||
}
|
||||
if ($amount>0 && $amount<=1000) {
|
||||
$kata .= " ".$suffix;
|
||||
}
|
||||
return $kata;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Update.php
|
||||
Desc. : Class Update Aplikasi Otomatis
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : June 14th, 2013.
|
||||
Last Modified : March 3rd, 2026.
|
||||
|
||||
(c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Update {
|
||||
protected $__conf = [];
|
||||
protected $is_git = false;
|
||||
|
||||
public function __construct(){
|
||||
$this->__conf = $_SESSION['__WEB_APP'];
|
||||
$this->get_current();
|
||||
}
|
||||
|
||||
public function get_current() {
|
||||
$_target = $this->__conf['REAL_PATH'];
|
||||
if (isset($_target)) chdir($_target);
|
||||
|
||||
try {
|
||||
$output = shell_exec("git log -1 --pretty=format:\"%H||%s||%ci\" --abbrev-commit 2>&1");
|
||||
if ($output) {
|
||||
$_ainfo = explode("||", $output);
|
||||
$this->__conf['GIT_SHA1'] = $_ainfo[0];
|
||||
$this->__conf['GIT_DATE'] = $_ainfo[2];
|
||||
$this->is_git = true;
|
||||
}
|
||||
$output = shell_exec("git config --get remote.origin.url 2>&1");
|
||||
if ($output) {
|
||||
$output = str_replace(["http://","https://",".git"], "", $output);
|
||||
$_ainfo = explode("/", trim($output));
|
||||
$this->__conf['GIT_OWNER'] = $_ainfo[1];
|
||||
$this->__conf['GIT_REPO'] = $_ainfo[2];
|
||||
}
|
||||
$output = shell_exec("git branch --show-current 2>&1");
|
||||
if ($output) {
|
||||
$this->__conf['GIT_BRANCH'] = $output;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public function check_update() {
|
||||
$_ainfo['cur_version'] = $this->__conf['APP_BUILD'];
|
||||
$_ainfo['cur_sha'] = substr($this->__conf['GIT_SHA1'], 0, 10);
|
||||
$_ainfo['cur_sha1'] = $this->__conf['GIT_SHA1'];
|
||||
$_ainfo['cur_date'] = $this->__conf['GIT_DATE'];
|
||||
$_ainfo['svr_status'] = 0;
|
||||
$_ainfo['svr_message'] = "Server Offline";
|
||||
|
||||
if (!$this->is_git) return $_ainfo;
|
||||
|
||||
try {
|
||||
$_url = "https://git.trifonia.cloud/api/v1/repos/".$this->__conf['GIT_OWNER']."/".$this->__conf['GIT_REPO']."/commits?limit=1";
|
||||
$_conten = file_get_contents($_url);
|
||||
$ajson = json_decode($_conten, true);
|
||||
|
||||
if (count($ajson) > 0) {
|
||||
$_ainfo['new_sha'] = substr($ajson[0]['sha'], 0, 10);
|
||||
$_ainfo['new_sha1'] = $ajson[0]['sha'];
|
||||
$_ainfo['new_date'] = date("Y-m-d H:i:s O", strtotime($ajson[0]['created']));
|
||||
$_ainfo['new_message'] = $ajson[0]['commit']['message'];
|
||||
$_ainfo['svr_status'] = 1;
|
||||
$_ainfo['svr_message'] = "Server Online";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
return $_ainfo;
|
||||
}
|
||||
|
||||
public function go_update() {
|
||||
$_target = $this->__conf['REAL_PATH'];
|
||||
$_branch = $this->__conf['GIT_BRANCH'] ?? "main";
|
||||
if (isset($_target)) {
|
||||
chdir($_target);
|
||||
$output = shell_exec("git reset --hard HEAD && git pull origin {$_branch} 2>&1");
|
||||
return ['success'=>true,'message'=>$output];
|
||||
} else return ['success'=>false,'message'=>"Tanpa REAL_PATH !"];
|
||||
}
|
||||
|
||||
public function update_mysql() {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user