upgrade first session to flightphp
This commit is contained in:
-172
@@ -1,172 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /App.php
|
||||
Desc. : HTML5 Page Generator (jQuery & Bootstrap)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 10th, 2008.
|
||||
Last Modified : July 25th, 2026.
|
||||
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp;
|
||||
|
||||
final class App {
|
||||
public $version = "4.1.0";
|
||||
private $apps = [];
|
||||
private $auser = [];
|
||||
private $cache = null;
|
||||
private $menu = null;
|
||||
private $reg = null;
|
||||
protected $__db = null;
|
||||
protected $__form = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
|
||||
$this->__form = new \siaupheng\webapp\Web\Form($this->__db);
|
||||
|
||||
$this->apps = $_SESSION['__WEB_APP'];
|
||||
if (isset($_SESSION['__WEB_USER'])) {
|
||||
$this->apps['TEMPLATE'] = "index.php";
|
||||
$this->auser = $_SESSION['__WEB_USER'];
|
||||
$this->auser['user_img'] = "profiles/profile.png";
|
||||
if (file_exists($this->apps['REAL_PATH']."assets/images/profiles/".$this->auser['UserID'].".png")) {
|
||||
$this->auser['user_img'] = "profiles/".$this->auser['UserID'].".png";
|
||||
}
|
||||
}
|
||||
$this->reg = new \siaupheng\webapp\Web\Register($this->__db);
|
||||
$this->cache = new \siaupheng\webapp\Data\Cache($this->__db);
|
||||
$this->menu = new \siaupheng\webapp\Web\Menu($this->__db);
|
||||
}
|
||||
|
||||
public function TampilApp($aoption = []) {
|
||||
if ($this->reg->reg_check()) {
|
||||
if (!user_logged()) {
|
||||
$this->apps['TEMPLATE'] = "login.php";
|
||||
}
|
||||
} else {
|
||||
$this->apps['TEMPLATE'] = "404.php";
|
||||
}
|
||||
|
||||
// gunakan template khusus sesuai request
|
||||
if (($aoption['PAGE_404']['value'] ?? 0) == 1) {
|
||||
$this->apps['TEMPLATE'] = "404.php";
|
||||
}
|
||||
|
||||
// loading template file {{}}
|
||||
$buffer = "";
|
||||
if (file_exists($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE'])) {
|
||||
$buffer = file_get_contents($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE']);
|
||||
$buffer = preg_replace("/(?:(?:\\/\\*(?:[^*]|(?:\\*+[^*\\/]))*\\*+\\/)|(?:(?<!\\:)\\/\\/. *))/", "", $buffer);
|
||||
}
|
||||
|
||||
$aoption = [...$this->apps, 'CSS_JS' => ""];
|
||||
|
||||
// penambahan file css + js + app-js
|
||||
$aoption['CSS_JS'] = '<link rel="stylesheet" type="text/css" href="'.$this->cache->Main("css").'">'."\n";
|
||||
$aoption['CSS_JS'] .= '<script type="text/javascript" src="'.$this->cache->Main("js").'"></script>'."\n";
|
||||
if (user_logged()) $aoption['CSS_JS'] .= '<script type="text/javascript" src="'.$this->cache->Apps().'"></script>'."\n";
|
||||
|
||||
$_secret = $aoption['APP_CODE'] .";". $aoption['APP_SID'] .";". $_SERVER['HTTP_HOST'] .";". $aoption['WEB_PATH'] .";". "http://".$_SERVER['HTTP_HOST'].$aoption['WEB_PATH'] .";". isMobile() .";". ($aoption['AUTH_LEVEL']?$aoption['AUTH_LEVEL']:0) .";". $this->version;
|
||||
$_suser = (user_logged()) ? $this->auser['Username'] .";". $this->auser['UserID'] .";". $this->auser['Grup_MenuID'] .";". $this->auser['Level'] : "nobody;999;999;9";
|
||||
|
||||
$aoption['CSS_JS'] .= '<script type="text/javascript" language="javascript">'."\n";
|
||||
$aoption['CSS_JS'] .= 'FoniaJS.setConfig("'.base64_encode($_secret).'", "'.base64_encode($_suser).'");';
|
||||
$aoption['CSS_JS'] .= '$(document).ready(function(){';
|
||||
$tnaviside = ""; $tnavihead = "";
|
||||
if (user_logged()) {
|
||||
$aoption['CSS_JS'] .= 'FoniaJS.loadMenu();';
|
||||
$tnaviside = $this->menu->Menu_Sidebar();
|
||||
$tnavihead = $this->menu->Menu_Header();
|
||||
}
|
||||
$aoption['CSS_JS'] .= '});';
|
||||
$aoption['CSS_JS'] .= '</script>'."\n";
|
||||
|
||||
// informasi tahun aplikasi dan pembuatan menu
|
||||
if (strpos($buffer, '{{CREATOR_YEAR}}')===false) {
|
||||
$aoption['REG_YEAR'] = ($aoption['REG_YEAR']!=date('Y')) ? $aoption['REG_YEAR']." - ".date('Y') : $aoption['REG_YEAR'];
|
||||
} else {
|
||||
$aoption['CREATOR_YEAR'] = ($aoption['CREATOR_YEAR']!=date('Y')) ? $aoption['CREATOR_YEAR']." - ".date('Y') : $aoption['CREATOR_YEAR'];
|
||||
}
|
||||
|
||||
// perubahan variabel dari data konfigurasi
|
||||
$aoption['APP_NAME_VER'] = $aoption['APP_NAME']." v".$aoption['APP_VER'];
|
||||
$aoption['APP_NAMES_VER'] = $aoption['APP_NAMES']." v".$aoption['APP_VER'];
|
||||
$aoption['APP_NAMES_UP'] = strtoupper($aoption['APP_NAMES'] ?? "");
|
||||
$aoption['REG_ID'] = $this->reg->reg_id();
|
||||
$aoption['REG_NAME_UP'] = strtoupper($aoption['REG_NAME'] ?? "");
|
||||
$aoption['REG_CITY_UP'] = strtoupper($aoption['REG_CITY'] ?? "");
|
||||
$aoption['USER_IMG'] = $this->auser['user_img'] ?? "";
|
||||
$aoption['NAVI_SIDEBAR'] = $tnaviside;
|
||||
$aoption['NAVI_HEADER'] = $tnavihead;
|
||||
|
||||
if (isset($this->auser) && is_array($this->auser)) {
|
||||
$aoption['USER_ID'] = $this->auser['UserID'] ?? "";
|
||||
$aoption['USER_USER'] = $this->auser['Username'] ?? "";
|
||||
$aoption['USER_NAME'] = $this->auser['Nama'] ?? "";
|
||||
$aoption['USER_POSISI'] = $this->auser['Posisi'] ?? "";
|
||||
|
||||
// menu modul
|
||||
$t_modul = "";
|
||||
if (isset($this->auser['MENU_MODUL']) && is_array($this->auser['MENU_MODUL']) && count($this->auser['MENU_MODUL'])>0) {
|
||||
$t_modul = '<div class="dropdown-divider"></div>';
|
||||
if ($_SERVER['SERVER_ADDR'] == "127.0.0.1") {
|
||||
$href1 = $this->apps['WEB_PATH'].'../';
|
||||
$href2 = "";
|
||||
} else {
|
||||
$_host = $_SERVER['HTTP_ORIGIN'] ?? $_SERVER['HTTP_HOST'] ?? $this->apps['PARENT_SITE'];
|
||||
$_host = str_replace(['http://','https://'], "", $_host);
|
||||
if ($this->apps['PARENT_SUB']==true) {
|
||||
$_subs = explode('.', $_host);
|
||||
if (count($_subs) > 2) array_shift($_subs);
|
||||
$href1 = "//";
|
||||
$href2 = "." . implode('.', $_subs);
|
||||
} else {
|
||||
$href1 = "//" . $_host . '/';
|
||||
$href2 = "";
|
||||
}
|
||||
}
|
||||
foreach ($this->auser['MENU_MODUL'] as $modul) {
|
||||
$href = $href1.$modul['APP_PATH'].$href2;
|
||||
$href .= '/?auth='.$_SESSION['APP_TOKEN'];
|
||||
$t_modul .= '<a class="dropdown-item slink" href="'.$href.'"><i class="'.$modul['Icon'].' me-2"></i> '.$modul['Judul'].'</a>';
|
||||
}
|
||||
}
|
||||
// menu extra
|
||||
$amodul_ext = $aoption['MENU_MODUL'] ?? [];
|
||||
if (count($amodul_ext) > 0) {
|
||||
$t_modul .= '<div class="dropdown-divider"></div>';
|
||||
foreach ($amodul_ext as $modul) {
|
||||
$t_modul .= '<a class="dropdown-item slink" id="'.$modul['Id'].'"><i class="'.$modul['Icon'].' me-2"></i> '.$modul['Judul'].'</a>';
|
||||
}
|
||||
}
|
||||
$aoption['MENU_MODUL'] = $t_modul;
|
||||
}
|
||||
|
||||
// penyisipan option (pilihan tahun, tanggal login, dll)
|
||||
if (count($aoption) > 0) {
|
||||
foreach ($aoption as $__key => $val) {
|
||||
$opt_var = $val['value'];
|
||||
if (strpos($__key, "OPTION")!==false) {
|
||||
$opt_var = $this->__form->option("_", $__key, $val['value'], true, true, $val['option']);
|
||||
} else if (strpos($__key, "RADIO")!==false) {
|
||||
$opt_var = $this->__form->radio("_", $__key, $val['value'], true, true, $val['radio']);
|
||||
} else if (strpos($__key, "PICKDATE")!==false) {
|
||||
$opt_var = $this->__form->datebox("_", $__key, $val['value'], true, true);
|
||||
}
|
||||
$aoption[$__key] = $opt_var;
|
||||
}
|
||||
}
|
||||
|
||||
$output = preg_replace_callback('/\{\{([a-zA-Z0-9_]+)\}\}/', fn($matches) => isset($aoption[$matches[1]]) ? $aoption[$matches[1]] : "", $buffer);
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+48
-54
@@ -6,56 +6,68 @@
|
||||
Desc. : Class Check SQL / Repair Database
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : May 11th, 2011.
|
||||
Last Modified : May 8th, 2021.
|
||||
Last Modified : August 13th, 2026.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 2011 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\DB;
|
||||
|
||||
use Exception;
|
||||
use flight\Engine;
|
||||
use flight\Session;
|
||||
use flight\database\SimplePdo;
|
||||
|
||||
final class CheckSQL {
|
||||
private $__atabel = [];
|
||||
private $__aignore = [];
|
||||
protected $__db = null;
|
||||
private Array $__atabel = [];
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
|
||||
public function __construct(?Engine $app = null){
|
||||
$this->app = (empty($app) === true) ? \Flight::app() : $app;
|
||||
$this->db = $this->app->db();
|
||||
|
||||
$this->__db->Query("SELECT TABLE_NAME,ENGINE,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$this->__db->getDBName()."' AND TABLE_TYPE='BASE TABLE'");
|
||||
while ($this->__db->Next()) {
|
||||
$this->__atabel[] = array($this->__db->Row("TABLE_NAME"), ' <i>('.$this->__db->Row("ENGINE").')</i>',' <i>('.uang($this->__db->Row("TABLE_ROWS")).' Records)</i>');
|
||||
$nama_db = $this->db->fetchField('SELECT DATABASE()');
|
||||
$arow = $this->db->fetchAll("SELECT TABLE_NAME,ENGINE,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$nama_db."' AND TABLE_TYPE='BASE TABLE'");
|
||||
foreach ($arow as $row) {
|
||||
$this->__atabel[] = [ $row['TABLE_NAME'], $row['ENGINE'], ' <i>('.$row['ENGINE'].')</i>',' <i>('.$row['TABLE_ROWS'].' Records)</i>' ];
|
||||
}
|
||||
}
|
||||
|
||||
public function ignore_table() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$this->__aignore = $tmp_arr;
|
||||
$farray = array_filter($this->__atabel, fn($child) => !in_array($child[0], $tmp_arr));
|
||||
$this->__atabel = array_values($farray);
|
||||
}
|
||||
|
||||
private function _check_db($atabel=array()) {
|
||||
$hasil = "";
|
||||
if (!in_array($atabel[0], $this->__aignore)) {
|
||||
$pesan = "<span style=\"color:blue;\">OK</span>";
|
||||
$this->__db->Query("CHECK TABLE ".$atabel[0]);
|
||||
if ($this->__db->Next()) {
|
||||
if (strtoupper($this->__db->Row("Msg_text"))<>"OK") {
|
||||
$pesan = "<span style=\"color:red;\">ERROR</span>";
|
||||
$this->__db->Query("REPAIR TABLE ".$atabel[0]);
|
||||
if ($this->__db->Next()) {
|
||||
if (strtoupper($this->__db->Row("Msg_text"))=="OK") {
|
||||
$pesan .= " -> <span style=\"color:blue;\">FIXED</span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
private function _check_db(array $atabel=[]) {
|
||||
$pesan = '<span style="color:blue;">OK</span>';
|
||||
$row = $this->db->runQuery('CHECK TABLE '.$atabel[0].' QUICK')->fetch(SimplePdo::FETCH_ASSOC);
|
||||
if (($row['Msg_text'] ?? '') !== 'OK') {
|
||||
$pesan = '<span style="color:red;">ERROR</span>';
|
||||
try {
|
||||
$row2 = $this->db->runQuery('REPAIR TABLE '.$atabel[0])->fetch(SimplePdo::FETCH_ASSOC);
|
||||
$pesan .= ' -> Auto Repair <span style="color:blue;">'. (($row2['Msg_text'] ?? '') === 'OK' ? 'FIXED' : 'ERROR') .'</span>';
|
||||
} catch (Exception $e) {
|
||||
$pesan .= ' -> Auto Repair <span style="color:red;">' . $e->getMessage() . '</span>';
|
||||
}
|
||||
$hasil = $atabel[0] . $atabel[2] ." ... ". $pesan ."<br>";
|
||||
}
|
||||
return $hasil;
|
||||
return $atabel[0] . $atabel[3] ." ... ". $pesan ."<br>";
|
||||
}
|
||||
|
||||
private function _opti_db(array $atabel=[]) {
|
||||
$pesan = '<span style="color:orange;">SKIP</span>';
|
||||
if ($atabel[1] === 'MyISAM') {
|
||||
$pesan = '<span style="color:blue;">OK</span>';
|
||||
$row = $this->db->runQuery('OPTIMIZE TABLE '.$atabel[0])->fetch(SimplePdo::FETCH_ASSOC);
|
||||
if (!in_array(strtoupper($row['Msg_text'] ?? ''), ['OK','TABLE IS ALREADY UP TO DATE'])) $pesan = '<span style="color:red;">ERROR</span>';
|
||||
}
|
||||
return $atabel[0] . $atabel[2] ." ... ". $pesan ."<br>";
|
||||
}
|
||||
|
||||
public function count_db() {
|
||||
@@ -64,45 +76,27 @@ final class CheckSQL {
|
||||
|
||||
public function check_db() {
|
||||
$hasil = "=== CEK DATABASE ===<br>";
|
||||
for ($n=0;$n<count($this->__atabel);$n++) {
|
||||
for ($n=0; $n<count($this->__atabel); $n++) {
|
||||
$hasil .= $this->_check_db($this->__atabel[$n]);
|
||||
}
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function check_db_step($n) {
|
||||
$hasil .= $this->_check_db($this->__atabel[$n]);
|
||||
}
|
||||
|
||||
public function repair_db() {
|
||||
$hasil = "=== REPAIR DATABASE ===<br>";
|
||||
for ($n=0;$n<count($this->__atabel);$n++) {
|
||||
if (!in_array($this->__atabel[$n][0], $this->__aignore)) {
|
||||
$pesan = "<span style=\"color:blue;\">OK</span>";
|
||||
$this->__db->Query("REPAIR TABLE ".$this->__atabel[$n][0]);
|
||||
while ($this->__db->Next()) {
|
||||
$pesan = (strtoupper($this->__db->Row("Msg_text"))=="OK") ? "<span style=\"color:blue;\">OK</span>" : "<span style=\"color:red;\">ERROR</span>";
|
||||
}
|
||||
$hasil .= $this->__atabel[$n][0] . $this->__atabel[$n][1] ." ... ". $pesan ."<br>";
|
||||
}
|
||||
}
|
||||
return $hasil;
|
||||
return $this->_check_db($this->__atabel[$n]);
|
||||
}
|
||||
|
||||
public function optimize_db() {
|
||||
$hasil = "=== OPTIMALISASI DATABASE ===<br>";
|
||||
for ($n=0;$n<count($this->__atabel);$n++) {
|
||||
if (!in_array($this->__atabel[$n][0], $this->__aignore)) {
|
||||
$pesan = "<span style=\"color:blue;\">OK</span>";
|
||||
$this->__db->Query("OPTIMIZE TABLE ".$this->__atabel[$n][0]);
|
||||
while ($this->__db->Next()) {
|
||||
$pesan = (strtoupper($this->__db->Row("Msg_text"))=="OK" || strtoupper($this->__db->Row("Msg_text"))=="TABLE IS ALREADY UP TO DATE") ? "<span style=\"color:blue;\">OK</span>" : "<span style=\"color:red;\">ERROR</span>";
|
||||
}
|
||||
$hasil .= $this->__atabel[$n][0] . $this->__atabel[$n][1] ." ... ". $pesan ."<br>";
|
||||
}
|
||||
$hasil .= $this->_opti_db($this->__atabel[$n]);
|
||||
}
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function optimize_db_step($n) {
|
||||
return $this->_opti_db($this->__atabel[$n]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /DB/MySQL.php
|
||||
Desc. : Class database MySQL / MariaDB
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 2nd, 2007.
|
||||
Last Modified : October 19th, 2023.
|
||||
|
||||
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\DB;
|
||||
|
||||
final class MySQL {
|
||||
private $cnn;
|
||||
private $rs = 0;
|
||||
private $rec = array();
|
||||
private $row = 0;
|
||||
private $halt_on_error = 1; //1: halt w message, 2: not halt w message, 3: not halt no message
|
||||
private $auto_free = 1; //1: free query automatically, 0: must call free method to free query
|
||||
private $db_config = null;
|
||||
private $err_num = 0;
|
||||
private $err_msg = '';
|
||||
private $debug_msg = 1;
|
||||
private $ischangingdb = false;
|
||||
|
||||
public function __construct() {
|
||||
if (!is_array($this->db_config)) $this->setConfig();
|
||||
$this->debug_msg = ($_SERVER['SERVER_ADDR'] == "127.0.0.1") ? 1 : 0;
|
||||
}
|
||||
|
||||
private function setConfig() {
|
||||
global $APP_DATA;
|
||||
if (!is_array($APP_DATA)) {
|
||||
if (file_exists($_SESSION['__WEB_APP']['REAL_PATH']."apps/cfg/mysql.php"))
|
||||
require_once($_SESSION['__WEB_APP']['REAL_PATH']."apps/cfg/mysql.php");
|
||||
}
|
||||
$this->db_config = $APP_DATA;
|
||||
}
|
||||
|
||||
public function getConfig() {
|
||||
return $this->db_config;
|
||||
}
|
||||
|
||||
function Connect() {
|
||||
if (!$this->cnn) {
|
||||
$this->cnn = @mysqli_connect($this->db_config['host'], $this->db_config['user'], $this->db_config['pwd'], $this->db_config['db'], intval($this->db_config['port']), $this->db_config['sock']);
|
||||
if (!$this->cnn) {
|
||||
$this->ErrHandler("Connection failed!");
|
||||
return 0;
|
||||
} else {
|
||||
@mysqli_query($this->cnn, "SET NAMES utf8");
|
||||
@mysqli_query($this->cnn, "SET CHARACTER SET utf8");
|
||||
@mysqli_query($this->cnn, "SET character_set_connection=utf8");
|
||||
}
|
||||
}
|
||||
return $this->cnn;
|
||||
}
|
||||
|
||||
function Connection() {
|
||||
return $this->cnn;
|
||||
}
|
||||
|
||||
function ResultSet() {
|
||||
return $this->rs;
|
||||
}
|
||||
|
||||
function Free() {
|
||||
if (is_resource($this->rs)) @mysqli_free_result($this->rs);
|
||||
$this->rs = 0;
|
||||
$this->row = 0;
|
||||
$this->rec = array();
|
||||
$this->err_num = 0;
|
||||
$this->err_msg = '';
|
||||
}
|
||||
|
||||
function SafeSQL($str) {
|
||||
if (!$this->cnn) $this->Connect();
|
||||
return mysqli_real_escape_string($this->cnn, strval($str));
|
||||
}
|
||||
|
||||
function &Query($stqry = "", $dbname = "") {
|
||||
if ($stqry == "") return 0;
|
||||
if (!$this->Connect()) return 0;
|
||||
if ($dbname != "" || $this->ischangingdb) {
|
||||
if ($dbname != "") {
|
||||
if (!@mysqli_select_db($this->cnn, $dbname)) {
|
||||
$this->ErrHandler("Cannot select database!");
|
||||
return 0;
|
||||
}
|
||||
$this->ischangingdb = true;
|
||||
} else {
|
||||
if (!@mysqli_select_db($this->cnn, $this->db_config['db'])) {
|
||||
$this->ErrHandler("Cannot select database!");
|
||||
return 0;
|
||||
}
|
||||
$this->ischangingdb = false;
|
||||
}
|
||||
}
|
||||
if ($this->rs) $this->Free();
|
||||
$this->rs = @mysqli_query($this->cnn, $stqry);
|
||||
$this->row = 0;
|
||||
$this->err_msg = @mysqli_error($this->cnn);
|
||||
if (!$this->rs) $this->ErrHandler("Invalid SQL!: ".$stqry);
|
||||
return $this->rs;
|
||||
}
|
||||
|
||||
function Next() {
|
||||
if (!$this->rs) {
|
||||
$this->ErrHandler("Cannot move cursor to next record!");
|
||||
return 0;
|
||||
}
|
||||
$this->rec = @mysqli_fetch_array($this->rs, MYSQLI_ASSOC);
|
||||
$this->row += 1;
|
||||
$this->err_msg = @mysqli_error($this->cnn);
|
||||
$result = is_array($this->rec);
|
||||
if (!$result && $this->auto_free) $this->Free();
|
||||
return $result;
|
||||
}
|
||||
|
||||
function Reset() {
|
||||
@mysqli_data_seek($this->rs, 0);
|
||||
}
|
||||
|
||||
function Seek($rownum = 0) {
|
||||
return @mysqli_data_seek($this->rs, $rownum);
|
||||
}
|
||||
|
||||
function Row($name = "", $defval = "") {
|
||||
if (isset($this->rec[$name])) {
|
||||
return (($this->rec[$name] == "") ? $defval : $this->rec[$name]);
|
||||
} else {
|
||||
return (($defval != "") ? $defval : "");
|
||||
}
|
||||
}
|
||||
|
||||
function RowNumeric($name = "", $defval = 0) {
|
||||
$defval = is_numeric($defval) ? $defval : 0;
|
||||
if (isset($this->rec[$name])) {
|
||||
if (is_numeric($this->rec[$name])) return $this->rec[$name];
|
||||
return $defval;
|
||||
} else return $defval;
|
||||
}
|
||||
|
||||
function RowFloat($name = "", $defval = 0) {
|
||||
$defval = is_numeric($defval) ? $defval : 0;
|
||||
if (isset($this->rec[$name])) {
|
||||
if ($this->rec[$name]) $defval = $this->rec[$name];
|
||||
}
|
||||
return floatval($defval);
|
||||
}
|
||||
|
||||
function AllRow() {
|
||||
return $this->rec;
|
||||
}
|
||||
|
||||
function ValueArray($colname = "") {
|
||||
$currrow = $this->row;
|
||||
@mysqli_data_seek($this->rs, 0);
|
||||
$result = array();
|
||||
while ($__row = mysqli_fetch_array($this->rs))
|
||||
if (isset($__row[$colname])) array_push($result, $__row[$colname]);
|
||||
@mysqli_data_seek($this->rs, $currrow);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function ValueArrayFormater($colname = "", $formater = "") {
|
||||
$currrow = $this->row;
|
||||
$formater = $formater == ""?$formater = "return \$__row[\$colname];":"return ".str_replace("<value>", "\$__row[\$colname]", $formater).";";
|
||||
@mysqli_data_seek($this->rs, 0);
|
||||
$result = array();
|
||||
while ($__row = mysqli_fetch_array($this->rs))
|
||||
if (isset($__row[$colname])) array_push($result, eval($formater));
|
||||
@mysqli_data_seek($this->rs, $currrow);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function ValueList($colname = "", $delim = ",") {
|
||||
$result = @$this->ValueArray($colname);
|
||||
return @implode($delim, $result);
|
||||
}
|
||||
|
||||
function CurrentRow() {
|
||||
return $this->row;
|
||||
}
|
||||
|
||||
function AffectedRows() {
|
||||
return @mysqli_affected_rows($this->cnn);
|
||||
}
|
||||
|
||||
function RecordCount() {
|
||||
return @mysqli_num_rows($this->rs);
|
||||
}
|
||||
|
||||
function NumFields() {
|
||||
return @mysqli_num_fields($this->rs);
|
||||
}
|
||||
|
||||
function LastInsertID() {
|
||||
$lastinsertid = -1;
|
||||
$crs = @mysqli_query($this->cnn, "SELECT LAST_INSERT_ID() AS lastinsertid");
|
||||
$crow = @mysqli_fetch_array($crs);
|
||||
if (isset($crow["lastinsertid"])) if (is_numeric($crow["lastinsertid"])) $lastinsertid = $crow["lastinsertid"];
|
||||
return $lastinsertid;
|
||||
}
|
||||
|
||||
function ErrHandler($err_msg = "") {
|
||||
$this->err_msg = @mysqli_error($this->cnn);
|
||||
if ($this->halt_on_error == 3) return;
|
||||
if ($err_msg == "") $err_msg = "Undefined error!";
|
||||
if ($this->debug_msg) {
|
||||
printf('<span style="font-size:1.2em;"><b>MySQL Error : %s</b> %s</span><br>', $this->db_config['db'], $this->err_msg);
|
||||
printf('<span style="font-size:1.2em;"><b>Database error : </b> %s</span><br>', $err_msg);
|
||||
}
|
||||
if ($this->halt_on_error == 1) die("");
|
||||
}
|
||||
|
||||
function getDBName() {
|
||||
return $this->db_config['db'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+122
-75
@@ -6,125 +6,172 @@
|
||||
Desc. : Class Query database
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 2nd, 2007.
|
||||
Last Modified : December 17th, 2023.
|
||||
Last Modified : August 14th, 2026.
|
||||
|
||||
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\DB;
|
||||
|
||||
use flight\Engine;
|
||||
use flight\Session;
|
||||
use flight\database\SimplePdo;
|
||||
use siaupheng\webapp\Web\Param;
|
||||
|
||||
final class SQL {
|
||||
private $__ttable = "";
|
||||
private $__afield = array();
|
||||
private $__avalue = array();
|
||||
private $__anomor = array();
|
||||
private $__twhere = "";
|
||||
protected $__db = null;
|
||||
private string $_ttable;
|
||||
private array $_afield = [];
|
||||
private array $_awhere = [];
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
|
||||
public function __construct(?Engine $app = null){
|
||||
$this->app = (empty($app) === true) ? \Flight::app() : $app;
|
||||
$this->db = $this->app->db();
|
||||
}
|
||||
|
||||
public function SafeSQL($ttext = "") {
|
||||
return $this->__db->SafeSQL($ttext);
|
||||
public function SafeSQL($ttext = "") {//delete
|
||||
return $ttext;
|
||||
}
|
||||
|
||||
public function set_table($ttable = "") {
|
||||
$this->__ttable = $ttable;
|
||||
public function set_table(string $table = ""): void {
|
||||
$this->_ttable = $table;
|
||||
}
|
||||
|
||||
public function add_param($tparam = "", $tvalue = null, $bnomor = false) {
|
||||
$this->__afield[] = $tparam;
|
||||
$this->__avalue[] = (is_null($tvalue) && isset($_REQUEST[$tparam])) ? $this->__db->SafeSQL($_REQUEST[$tparam]) : $tvalue;
|
||||
$this->__anomor[] = $bnomor;
|
||||
public function add_param(string $param = "", string|int|null $value = null, bool $nomor = false): void {
|
||||
$this->_afield[] = [
|
||||
'field' => $param,
|
||||
'value' => (is_null($value) && !empty(Param::Get($param))) ? Param::Get($param) : $value,
|
||||
'numbe' => $nomor,
|
||||
];
|
||||
}
|
||||
|
||||
public function add_param_date($tparam = "", $tvalue = null) {
|
||||
$this->__afield[] = $tparam;
|
||||
$this->__avalue[] = tgl_sql2str((is_null($tvalue) && isset($_REQUEST[$tparam])) ? $this->__db->SafeSQL($_REQUEST[$tparam]) : $tvalue);
|
||||
$this->__anomor[] = false;
|
||||
public function add_param_date(string $param = "", string|null $value = null): void {
|
||||
$this->_afield[] = [
|
||||
'field' => $param,
|
||||
'value' => tgl_sql2str((is_null($value) && !empty(Param::Get($param))) ? Param::Get($param) : $value),
|
||||
'numbe' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function add_param_stamp($tparam = "DateStamp") {
|
||||
$this->__afield[] = $tparam;
|
||||
$this->__avalue[] = "NOW()";
|
||||
$this->__anomor[] = true;
|
||||
public function add_param_stamp(string $param = "DateStamp"): void {
|
||||
$this->_afield[] = [
|
||||
'field' => $param,
|
||||
'value' => 'NOW()',
|
||||
'numbe' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function add_param_unix() {
|
||||
$this->__afield[] = "Unix";
|
||||
$this->__avalue[] = user_unix();
|
||||
$this->__anomor[] = false;
|
||||
public function add_param_unix(): void {
|
||||
$this->_afield[] = [
|
||||
'field' => 'Unix',
|
||||
'value' => user_unix(),
|
||||
'numbe' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function add_param_userid($tparam = "UserID") {
|
||||
$this->__afield[] = $tparam;
|
||||
$this->__avalue[] = user_id();
|
||||
$this->__anomor[] = false;
|
||||
public function add_param_userid(string $param = "UserID"): void {
|
||||
$this->_afield[] = [
|
||||
'field' => $param,
|
||||
'value' => user_id(),
|
||||
'numbe' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function add_where_unix() {
|
||||
$this->__twhere .= (($this->__twhere=="") ? " WHERE " : " AND ") . "(Unix='".user_unix()."')";
|
||||
public function add_where_unix(): void {
|
||||
$this->_awhere[] = [
|
||||
'field' => 'Unix',
|
||||
'value' => user_id(),
|
||||
'numbe' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function add_where_date($tfield = "", $tvalue = null) {
|
||||
$tvalue = ($tvalue == null) ? "0000-00-00" : tgl_sql2str($tvalue);
|
||||
$this->add_where($tfield, $tvalue);
|
||||
public function add_where_date(string $field = "", string|null $value = null): void {
|
||||
$this->_awhere[] = [
|
||||
'field' => $field,
|
||||
'value' => (is_null($value)) ? '0000-00-00' : tgl_sql2str($value),
|
||||
'numbe' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function add_where($tfield = "", $tvalue = null) {
|
||||
$__tvalue = (is_null($tvalue) && isset($_REQUEST[$tfield])) ? $this->__db->SafeSQL($_REQUEST[$tfield]) : $tvalue;
|
||||
$this->__twhere .= (($this->__twhere=="") ? " WHERE " : " AND ") . "(".$tfield."='".$__tvalue."')";
|
||||
public function add_where(string $field = "", string|int|null $value = null, bool $nomor = false): void {
|
||||
$this->_awhere[] = [
|
||||
'field' => $field,
|
||||
'value' => (is_null($value) && !empty(Param::Get($field))) ? Param::Get($field) : $value,
|
||||
'numbe' => $nomor,
|
||||
];
|
||||
}
|
||||
|
||||
public function clear_param() {
|
||||
$this->__afield = array();
|
||||
$this->__avalue = array();
|
||||
$this->__anomor = array();
|
||||
public function clear_param(): void {
|
||||
$this->_afield = [];
|
||||
}
|
||||
|
||||
public function clear_where() {
|
||||
$this->__twhere = "";
|
||||
public function clear_where(): void {
|
||||
$this->_awhere = [];
|
||||
}
|
||||
|
||||
public function InsertDB() {
|
||||
$tsql = "INSERT INTO ".$this->__ttable." (";
|
||||
$tfield = "";
|
||||
$tvalue = "";
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tfield .= ",".$this->__afield[$i];
|
||||
$tvalue .= ",".(($this->__anomor[$i])?"":"'").$this->__avalue[$i].(($this->__anomor[$i])?"":"'");
|
||||
public function InsertDB(): void {
|
||||
$__afield = [];
|
||||
$__aplace = [];
|
||||
$__aexec = [];
|
||||
foreach ($this->_afield as $col) {
|
||||
$__afield[] = '`'.$col['field'].'`';
|
||||
if ($col['numbe'] === true) {
|
||||
$__aplace[] = $col['value'];
|
||||
} else {
|
||||
$__aplace[] = '?';
|
||||
$__aexec[] = $col['value'];
|
||||
}
|
||||
}
|
||||
$tsql .= substr($tfield,1);
|
||||
$tsql .= ") VALUES (";
|
||||
$tsql .= substr($tvalue,1);
|
||||
$tsql .= ")";
|
||||
$this->__db->Query($tsql);
|
||||
$tsql = 'INSERT INTO '.$this->_ttable.' ('. implode(',', $__afield) .') VALUES ('. implode(',', $__aplace) .')';
|
||||
$this->db->runQuery($tsql, $__aexec);
|
||||
}
|
||||
|
||||
public function UpdateDB() {
|
||||
$tsql = "UPDATE ".$this->__ttable." SET ";
|
||||
$tfield = "";
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tfield .= ",".$this->__afield[$i]."=".(($this->__anomor[$i])?"":"'").$this->__avalue[$i].(($this->__anomor[$i])?"":"'");
|
||||
public function UpdateDB(): void {
|
||||
$__aplace = [];
|
||||
$__awhere = [];
|
||||
$__aexec = [];
|
||||
foreach ($this->_afield as $col) {
|
||||
if ($col['numbe'] === true) {
|
||||
$__aplace[] = '`'.$col['field'].'`='. $col['value'];
|
||||
} else {
|
||||
$__aplace[] = '`'.$col['field'].'`=?';
|
||||
$__aexec[] = $col['value'];
|
||||
}
|
||||
}
|
||||
$tsql .= substr($tfield,1);
|
||||
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
|
||||
$this->__db->Query($tsql);
|
||||
foreach ($this->_awhere as $col) {
|
||||
if ($col['numbe'] === true) {
|
||||
$__awhere[] = '`'.$col['field'].'`='. $col['value'];
|
||||
} else {
|
||||
$__awhere[] = '`'.$col['field'].'`=?';
|
||||
$__aexec[] = $col['value'];
|
||||
}
|
||||
}
|
||||
$tsql = 'UPDATE '.$this->_ttable.' SET '. implode(',', $__aplace) .' WHERE '. implode(' AND ', $__awhere);
|
||||
$this->db->runQuery($tsql, $__aexec);
|
||||
}
|
||||
|
||||
public function DeleteDB() {
|
||||
$tsql = "DELETE FROM ".$this->__ttable;
|
||||
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
|
||||
$this->__db->Query($tsql);
|
||||
public function DeleteDB(): void {
|
||||
$__awhere = [];
|
||||
$__aexec = [];
|
||||
foreach ($this->_awhere as $col) {
|
||||
if ($col['numbe'] === true) {
|
||||
$__awhere[] = '`'.$col['field'].'`='. $col['value'];
|
||||
} else {
|
||||
$__awhere[] = '`'.$col['field'].'`=?';
|
||||
$__aexec[] = $col['value'];
|
||||
}
|
||||
}
|
||||
$tsql = 'DELETE FROM '.$this->_ttable.' WHERE '. implode(' AND ', $__awhere);
|
||||
$this->db->runQuery($tsql, $__aexec);
|
||||
}
|
||||
|
||||
public function LastInsertID() {
|
||||
return $this->__db->LastInsertID();
|
||||
public function LastInsertID(): int {
|
||||
return $this->db->lastInsertId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+101
-98
@@ -3,133 +3,122 @@
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/Cache.php
|
||||
Desc. : Class cache aplikasi
|
||||
Desc. : Class cache css dan js aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : March 16th, 2008.
|
||||
Last Modified : July 25th, 2026.
|
||||
Last Modified : August 19th, 2026.
|
||||
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Data;
|
||||
|
||||
use flight\Engine;
|
||||
use FilesystemIterator;
|
||||
use MatthiasMullie\Minify;
|
||||
use SplFileInfo;
|
||||
|
||||
final class Cache {
|
||||
private $__cachedays = 0;
|
||||
private $__cachedir = "";
|
||||
private $__cssdir = "";
|
||||
private $__localedir = "";
|
||||
private $__jsdir = "";
|
||||
private $__jsapp = "";
|
||||
private $__realpath = "";
|
||||
private $__rootdir = "";
|
||||
private $__ini = [];
|
||||
protected $__db = null;
|
||||
protected Engine $app;
|
||||
protected array $__asset = [];
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\webapp\DB\MySQL();
|
||||
|
||||
$rootdir = $_SESSION['__WEB_APP']['REAL_PATH'];
|
||||
$this->__cachedir = $rootdir . 'chunks/';
|
||||
public function __construct(?Engine $app = null, array $asset = []) {
|
||||
$this->app = (empty($app) === true) ? Flight::app() : $app;
|
||||
$this->__asset = $asset;
|
||||
$rootdir = (defined('PROJECT_ROOT')) ? PROJECT_ROOT : $this->app->get('flight.root_dir');
|
||||
$this->__cachedir = $rootdir . '/public/chunks/';
|
||||
$this->__localedir = $rootdir . '/app/locale/';
|
||||
$this->__jsapp = $rootdir . '/app/scripts/';
|
||||
$this->__cssdir = __DIR__ . '/../../assets/css/';
|
||||
$this->__localedir = $rootdir . 'assets/locale/';
|
||||
$this->__jsdir = __DIR__ . '/../../assets/js/';
|
||||
$this->__jsapp = $rootdir . 'apps/js/';
|
||||
$this->__realpath = $rootdir;
|
||||
$this->__rootdir = $rootdir . '/';
|
||||
if (!is_dir($this->__cachedir)) mkdir($this->__cachedir, 0755, true);
|
||||
if (!file_exists($this->__cachedir . "cache.ini")) {
|
||||
$this->__ini = [
|
||||
'css' => ['login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>"",'display_stamp'=>"0",'display_file'=>""],
|
||||
'js' => ['login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>"",'display_stamp'=>"0",'display_file'=>""]
|
||||
'login' => [ 'stamp' => 0, 'css' => "", 'js' => "", 'app' => "", ],
|
||||
'index' => [ 'stamp' => 0, 'css' => "", 'js' => "", 'app' => "", ],
|
||||
'display' => [ 'stamp' => 0, 'css' => "", 'js' => "", 'app' => "", ],
|
||||
];
|
||||
$this->save_ini();
|
||||
}
|
||||
$this->__ini = parse_ini_file($this->__cachedir . "cache.ini", true);
|
||||
} else $this->__ini = parse_ini_file($this->__cachedir . "cache.ini", true);
|
||||
}
|
||||
|
||||
private function gen_file($type="css", $mode="index") {
|
||||
private function gen_file($mode = "index", $type = "css") {
|
||||
$itime = 0;
|
||||
$afile = [];
|
||||
if ($type == "css") {
|
||||
$_afile = array_unique($GLOBALS['A_CSS']);
|
||||
$_afile = array_unique($this->__asset['css'][$mode] ?? []);
|
||||
foreach ($_afile as $__key => $val) {
|
||||
$afile[] = $this->__cssdir .$val;
|
||||
if (!file_exists($this->__cssdir . $val)) continue;
|
||||
$_file = new SplFileInfo($this->__cssdir . $val);
|
||||
$afile[] = $_file->getRealPath();
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
if (file_exists($this->__realpath . 'assets/css/')) {
|
||||
if ($handle = opendir($this->__realpath . 'assets/css/')) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file == '.' || $file == '..' || is_dir($this->__realpath . 'assets/css/'.$file)) continue;
|
||||
$afile[] = $this->__realpath . 'assets/css/' . $file;
|
||||
if (is_dir($this->__rootdir . 'app/css/')) {
|
||||
$iterator = new FilesystemIterator($this->__rootdir . 'app/css/', FilesystemIterator::SKIP_DOTS);
|
||||
foreach ($iterator as $_file) {
|
||||
if ($_file->isFile()) {
|
||||
$afile[] = $_file->getRealPath();
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
} else if ($type == "js") {
|
||||
$_afile = array_unique($GLOBALS['A_JS']);
|
||||
$_afile = array_unique($this->__asset['js'][$mode] ?? []);
|
||||
foreach ($_afile as $__key => $val) {
|
||||
$afile[] = $this->__jsdir .$val;
|
||||
}
|
||||
if (file_exists($this->__realpath . 'assets/js/')) {
|
||||
if ($handle = opendir($this->__realpath . 'assets/js/')) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file == '.' || $file == '..' || is_dir($this->__realpath . 'assets/js/'.$file)) continue;
|
||||
$afile[] = $this->__realpath . 'assets/js/' . $file;
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
if (!file_exists($this->__jsdir . $val)) continue;
|
||||
$_file = new SplFileInfo($this->__jsdir . $val);
|
||||
$afile[] = $_file->getRealPath();
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
// add locale file
|
||||
$ljs = (isset($_SESSION['__WEB_USER']['LOCALE'])?$_SESSION['__WEB_USER']['LOCALE']:$_SESSION['__WEB_APP']['DEF_LOCALE']).".js";
|
||||
$ljs = ($this->app->session()->get('__WEB_USER')['LOCALE'] ?? $this->app->session()->get('__WEB_APP')['DEF_LOCALE']).'.js';
|
||||
if (is_dir($this->__localedir)) {
|
||||
if ($handle = opendir($this->__localedir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
$file = $this->__localedir . $file;
|
||||
if (substr($file, -5) == $ljs) $afile[] = $this->__localedir .basename(str_replace("\\", "/", $file));
|
||||
$iterator = new \FilesystemIterator($this->__localedir, \FilesystemIterator::SKIP_DOTS);
|
||||
foreach ($iterator as $_file) {
|
||||
if ($_file->isFile() && str_ends_with($_file->getFilename(), $ljs)) {
|
||||
$afile[] = $_file->getRealPath();
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
$afile[] = $this->__jsapp . $mode . ".js";
|
||||
} else if ($type == "app") {
|
||||
$afile[] = $this->__jsapp ."sys/profile.js";
|
||||
$afile[] = $this->__jsapp ."sys/chpasswd.js";
|
||||
$amenu = explode(",", $_SESSION['__WEB_USER']['Menu_Grup'] .",". $_SESSION['__WEB_USER']['Menu']);
|
||||
$tmenu = implode("','", array_unique($amenu));
|
||||
$this->__db->Query("SELECT * FROM app_menu WHERE Link<>'' AND Kode IN ('".$tmenu."') ORDER BY Level, Urut");
|
||||
while ($this->__db->Next()) {
|
||||
$afile[] = $this->__jsapp . str_replace("php", "js", $this->__db->Row("Link"));
|
||||
}
|
||||
}
|
||||
return $afile;
|
||||
}
|
||||
|
||||
private function check_file($afile) {
|
||||
$lastmod = 0;
|
||||
foreach ($afile as $nfile) {
|
||||
if (file_exists($nfile)) {
|
||||
$lastmod += filemtime($nfile);
|
||||
}
|
||||
}
|
||||
if ($this->__cachedays > 0) {
|
||||
if ($handle = opendir($this->__cachedir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file == '.' || $file == '..' || is_dir($this->__cachedir.$file)) continue;
|
||||
if ((time()-filemtime($this->__cachedir.$file)) > (86400*$this->__cachedays)) {
|
||||
unlink($this->__cachedir . $file);
|
||||
if ($mode === 'index') {
|
||||
if (is_dir($this->__jsapp)) {
|
||||
$dirIterator = new \RecursiveDirectoryIterator($this->__jsapp, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$iterator = new \RecursiveIteratorIterator($dirIterator);
|
||||
foreach ($iterator as $_file) {
|
||||
if ($_file->isFile() && !in_array($_file->getFilename(), ['login.js','display.js'])) {
|
||||
$afile[] = $_file->getRealPath();
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
} else {
|
||||
if (file_exists($this->__jsapp . $mode . '.js')) {
|
||||
$_file = new SplFileInfo($this->__jsapp . $mode . '.js');
|
||||
$afile[] = $_file->getRealPath();
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $lastmod;
|
||||
return [ $afile, $itime ];
|
||||
}
|
||||
|
||||
private function create_cache($type="css", $mode="index", $afile=[], $lastmod=0) {
|
||||
private function create_cache($type = "css", $afile = [], $cachefile = "") {
|
||||
$contents = ''; $smini = null;
|
||||
$bpublic = ($_SERVER['SERVER_ADDR'] == "127.0.0.1") ? false : true;
|
||||
$bpublic = ($this->app->request()->ip === '127.0.0.1') ? false : true;
|
||||
if ($bpublic == true) {
|
||||
if ($type=="css") {
|
||||
$smini = new Minify\CSS;
|
||||
@@ -147,15 +136,10 @@ final class Cache {
|
||||
}
|
||||
}
|
||||
if ($bpublic) $contents = $smini->minify();
|
||||
$cachefile = md5($mode . $lastmod) . ($type=="app"?".app":"") . ($type=="css" ? ".css" : ".js");
|
||||
file_put_contents($this->__cachedir . $cachefile, $contents);
|
||||
if ($type == "app") return;
|
||||
$this->__ini[$type][$mode.'_stamp'] = $lastmod;
|
||||
$this->__ini[$type][$mode.'_file'] = $cachefile;
|
||||
$this->save_ini();
|
||||
}
|
||||
|
||||
private function save_ini(){
|
||||
private function save_ini() {
|
||||
$content = "";
|
||||
foreach ($this->__ini as $key => $elem) {
|
||||
$content .= ($content==""?"":"\n"). "[".$key."]\n";
|
||||
@@ -167,27 +151,46 @@ final class Cache {
|
||||
file_put_contents($this->__cachedir . "cache.ini", $content);
|
||||
}
|
||||
|
||||
public function Main($type="css", $mode="") {
|
||||
if ($mode == "") $mode = "login";
|
||||
if (($_SESSION['__WEB_USER']['UserID'] ?? 0) > 0) $mode = "index";
|
||||
$afile = $this->gen_file($type, $mode);
|
||||
$lastmod = $this->check_file($afile);
|
||||
if ($lastmod <> intval($this->__ini[$type][$mode.'_stamp']) || !file_exists($this->__cachedir . $this->__ini[$type][$mode.'_file'])) {
|
||||
$this->create_cache($type, $mode, $afile, $lastmod);
|
||||
public function Cache($mode = "index") {
|
||||
$is_modif = false;
|
||||
foreach (['css','js','app'] as $type) {
|
||||
[ $afile, $lastmod ] = $this->gen_file($mode, $type);
|
||||
$cachefile = md5($mode . $type . $lastmod) . ($type=='css'?'.css':'.js');
|
||||
if (!file_exists($this->__cachedir . $cachefile) || ((time()-(int)$this->__ini[$mode]['stamp']) > (86400*14))) {
|
||||
$this->create_cache($type, $afile, $cachefile);
|
||||
$this->__ini[$mode][$type] = $cachefile;
|
||||
$this->__ini[$mode]['stamp'] = time();
|
||||
$is_modif = true;
|
||||
}
|
||||
}
|
||||
return $_SESSION['__WEB_APP']['WEB_PATH'] ."chunks/". $this->__ini[$type][$mode.'_file'];
|
||||
if ($is_modif === true) $this->save_ini();
|
||||
$acache = [ 'CSS' => [], 'JS' => [], 'JSX' => [] ];
|
||||
foreach ($this->__ini[$mode] as $_type => $_file) {
|
||||
if ($_type == 'stamp') continue;
|
||||
if (file_exists($this->__cachedir . $_file)) {
|
||||
if ($_type === 'css') {
|
||||
$acache['CSS'][] = 'chunks/' . $_file;
|
||||
} else $acache['JS'][] = 'chunks/' . $_file;
|
||||
}
|
||||
}
|
||||
|
||||
$session = $this->app->session();
|
||||
$aoption = $session->get('__WEB_APP');
|
||||
$auser = $session->get('__WEB_USER');
|
||||
$nonce = $this->app->get('csp_nonce');
|
||||
$_secret = $aoption['APP_CODE'] .";". $aoption['APP_SID'] .";". $this->app->request()->getVar('HTTP_HOST') .";". "http://".$this->app->request()->getVar('HTTP_HOST') .";". isMobile() .";". ($aoption['AUTH_LEVEL']?$aoption['AUTH_LEVEL']:0);
|
||||
$_suser = (user_logged()) ? $auser['Username'] .";". $auser['UserID'] .";". $auser['Grup_MenuID'] .";". $auser['Level'] : "nobody;999;999;9";
|
||||
|
||||
$acache['JSX'][] = '<script nonce="'.$nonce.'" type="text/javascript">';
|
||||
$acache['JSX'][] = 'FoniaJS.setConfig("'.base64_encode($_secret).'", "'.base64_encode($_suser).'");';
|
||||
$acache['JSX'][] = '$(document).ready(function(){';
|
||||
if (user_logged()) $acache['JSX'][] = 'FoniaJS.loadMenu();';
|
||||
$acache['JSX'][] = '});';
|
||||
$acache['JSX'][] = '</script>';
|
||||
|
||||
return $acache;
|
||||
}
|
||||
|
||||
public function Apps() {
|
||||
$id_user = (isset($_SESSION['__WEB_USER']) && is_array($_SESSION['__WEB_USER'])) ? $_SESSION['__WEB_USER']['UserID'] : 0;
|
||||
$afile = $this->gen_file("app", $id_user);
|
||||
$lastmod = $this->check_file($afile);
|
||||
$appfile = md5($id_user . $lastmod) . ".app.js";
|
||||
if (!file_exists($this->__cachedir . $appfile)) {
|
||||
$this->create_cache("app", $id_user, $afile, $lastmod);
|
||||
}
|
||||
return $_SESSION['__WEB_APP']['WEB_PATH'] ."chunks/". $appfile;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Display.php
|
||||
Desc. : HTML5 Page Generator (jQuery & Bootstrap)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 10th, 2008.
|
||||
Last Modified : July 25th, 2026.
|
||||
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp;
|
||||
|
||||
final class Display {
|
||||
public $version = "1.1.0";
|
||||
private $apps = [];
|
||||
private $cache = null;
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
|
||||
|
||||
$this->apps = $_SESSION['__WEB_APP'];
|
||||
if (($this->apps['TEMPLATE'] ?? "") == "") $this->apps['TEMPLATE'] = "display.php";
|
||||
|
||||
$this->cache = new \siaupheng\webapp\Data\Cache($this->__db);
|
||||
}
|
||||
|
||||
public function TampilDisplay() {
|
||||
// loading template file {{}}
|
||||
$buffer = "";
|
||||
if (file_exists($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE'])) {
|
||||
$buffer = file_get_contents($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE']);
|
||||
$buffer = preg_replace("/(?:(?:\\/\\*(?:[^*]|(?:\\*+[^*\\/]))*\\*+\\/)|(?:(?<!\\:)\\/\\/. *))/", "", $buffer);
|
||||
}
|
||||
|
||||
$aoption = [...$this->apps, 'CSS_JS' => ""];
|
||||
|
||||
// penambahan file css + js + app-js
|
||||
$aoption['CSS_JS'] = '<link rel="stylesheet" type="text/css" href="'.$this->cache->Main("css", "display").'">'."\n";
|
||||
$aoption['CSS_JS'] .= '<script type="text/javascript" src="'.$this->cache->Main("js", "display").'"></script>'."\n";
|
||||
|
||||
$_secret = $aoption['APP_DISPLAY'] .";". $aoption['APP_SID'] .";". $_SERVER['HTTP_HOST'] .";". $aoption['WEB_PATH'] .";". "http://".$_SERVER['HTTP_HOST'].$aoption['WEB_PATH'] .";". isMobile() .";". ($aoption['AUTH_LEVEL']?$aoption['AUTH_LEVEL']:0) .";". $this->version;
|
||||
$_suser = "nobody;999;999;9";
|
||||
|
||||
$aoption['CSS_JS'] .= '<script type="text/javascript" language="javascript">'."\n";
|
||||
$aoption['CSS_JS'] .= 'FoniaJS.setConfig("'.base64_encode($_secret).'", "'.base64_encode($_suser).'");';
|
||||
$aoption['CSS_JS'] .= '</script>'."\n";
|
||||
|
||||
// informasi tahun aplikasi dan pembuatan menu
|
||||
if (strpos($buffer, '{{CREATOR_YEAR}}')===false) {
|
||||
$aoption['REG_YEAR'] = ($aoption['REG_YEAR']!=date('Y')) ? $aoption['REG_YEAR']." - ".date('Y') : $aoption['REG_YEAR'];
|
||||
} else {
|
||||
$aoption['CREATOR_YEAR'] = ($aoption['CREATOR_YEAR']!=date('Y')) ? $aoption['CREATOR_YEAR']." - ".date('Y') : $aoption['CREATOR_YEAR'];
|
||||
}
|
||||
|
||||
// perubahan variabel dari data konfigurasi
|
||||
$aoption['APP_NAME_VER'] = $aoption['APP_NAME']." v".$aoption['APP_VER'];
|
||||
$aoption['APP_NAMES_VER'] = $aoption['APP_NAMES']." v".$aoption['APP_VER'];
|
||||
$aoption['APP_NAMES_UP'] = strtoupper($aoption['APP_NAMES'] ?? "");
|
||||
$aoption['REG_NAME_UP'] = strtoupper($aoption['REG_NAME'] ?? "");
|
||||
$aoption['REG_CITY_UP'] = strtoupper($aoption['REG_CITY'] ?? "");
|
||||
|
||||
$output = preg_replace_callback('/\{\{([a-zA-Z0-9_]+)\}\}/', fn($matches) => isset($aoption[$matches[1]]) ? $aoption[$matches[1]] : "", $buffer);
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -12,51 +12,51 @@
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
if (!function_exists('user_level')) {
|
||||
function user_level($level = 9) {
|
||||
if ($_SESSION['__WEB_USER']['Level'] <= $level) return true;
|
||||
if (Flight::session()->get('__WEB_USER', ['Level'=>9]) <= $level) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_level_not')) {
|
||||
function user_level_not($level = 9) {
|
||||
if ($_SESSION['__WEB_USER']['Level'] !== $level) return true;
|
||||
if (Flight::session()->get('__WEB_USER', ['Level'=>9]) !== $level) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_logged')) {
|
||||
function user_logged() {
|
||||
if (isset($_SESSION['__WEB_USER'])) return true;
|
||||
return false;
|
||||
return !empty(Flight::session()->get('__WEB_USER'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_id')) {
|
||||
function user_id($idigit = 0) {
|
||||
if ($idigit > 0) return isi_nol($_SESSION['__WEB_USER']['UserID'], $idigit);
|
||||
return $_SESSION['__WEB_USER']['UserID'];
|
||||
if ($idigit > 0) return isi_nol((int)Flight::session()->get('__WEB_USER', ['UserID'=>0])['UserID'], $idigit);
|
||||
return (int)Flight::session()->get('__WEB_USER', ['UserID'=>0])['UserID'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_user')) {
|
||||
function user_user() {
|
||||
return $_SESSION['__WEB_USER']['Username'];
|
||||
return (string)Flight::session()->get('__WEB_USER', ['Username'=>''])['Username'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_unix')) {
|
||||
function user_unix() {
|
||||
return $_SESSION['__WEB_USER']['UNIX'];
|
||||
return (string)Flight::session()->get('__WEB_USER', ['UNIX'=>'0'])['UNIX'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_nama')) {
|
||||
function user_nama() {
|
||||
return $_SESSION['__WEB_USER']['Nama'];
|
||||
return (string)Flight::session()->get('__WEB_USER', ['Nama'=>''])['Nama'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Function/JSON.php
|
||||
Desc. : Fungsi Custom JSON
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 14th, 2012.
|
||||
Last Modified : April 29th, 2022.
|
||||
|
||||
(c) 2012 - 2022, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if (!function_exists('is_json')) {
|
||||
function is_json($string) {
|
||||
json_decode($string);
|
||||
return json_last_error() === JSON_ERROR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('send_json')) {
|
||||
function send_json($ajson = array(), $bempty = false) {
|
||||
if (count($ajson) > 0 || $bempty == true) {
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Content-type: application/json');
|
||||
echo json_encode($ajson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+16
-7
@@ -16,9 +16,9 @@ declare(strict_types=1);
|
||||
|
||||
/*************************** FORMAT ANGKA / CURRENCY *****************************/
|
||||
|
||||
if (!function_exists('rupiah')) {
|
||||
function rupiah($angka = 0, $desi = 0) {
|
||||
return number_format(doubleval($angka), intval($desi), ",", ".");
|
||||
if (!function_exists('rupiah')) {//oke
|
||||
function rupiah(string|float $angka = 0, int $desi = 0) {
|
||||
return number_format((float)$angka, $desi, ",", ".");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ if (!function_exists('kurung2')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('uang')) {
|
||||
function uang($angka = 0, $desi = 0) {
|
||||
$angka = str_replace(",","",$angka);
|
||||
return number_format(doubleval($angka), intval($desi));
|
||||
if (!function_exists('uang')) {//oke
|
||||
function uang(string|float $angka = '0', int $desi = 0) {
|
||||
$angka = str_replace(",", "", (string)$angka);
|
||||
return number_format((float)$angka, $desi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,4 +350,13 @@ if (!function_exists('format_bytes')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('random_color')) {
|
||||
function random_color($trans = "0.6") {
|
||||
$col_r = mt_rand( 0, 255 );
|
||||
$col_g = mt_rand( 0, 255 );
|
||||
$col_b = mt_rand( 0, 255 );
|
||||
return "rgba(".$col_r.",".$col_g.",".$col_b.",".$trans.")";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+57
-62
@@ -3,7 +3,7 @@
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Auth.php
|
||||
Desc. : Fungsi login dan user checking
|
||||
Desc. : Class login dan user checking
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : March 16th, 2008.
|
||||
Last Modified : April 3rd, 2022.
|
||||
@@ -12,126 +12,121 @@
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Auth {
|
||||
private $__id_reg = 0;
|
||||
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->__id_reg = $_SESSION['__WEB_APP']['REG_ID'];
|
||||
final class Auth {
|
||||
private int $__id_reg = 0;
|
||||
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();
|
||||
$this->__id_reg = (int)$this->session->get('__WEB_APP', ['REG_ID'=>0])['REG_ID'];
|
||||
}
|
||||
|
||||
public function set_id_reg($id = 0) {
|
||||
if ($id > 0) $this->__id_reg = $id;
|
||||
if ($id > 0) $this->__id_reg = (int)$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);
|
||||
$i_hasil = $this->db->fetchField('SELECT COUNT(*) FROM app_operator WHERE Username=? AND Password=MD5(?) AND Aktif=1', [$user, $pass]);
|
||||
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'])) {
|
||||
$adata = $this->db->fetchRow('SELECT *,DECODE(Menu,?) Menu2 FROM app_operator WHERE Username=?', [$this->__id_reg, $user])->getData();
|
||||
$adata['Menu'] = $adata['Menu2'];
|
||||
unset($adata['Menu2']);
|
||||
|
||||
if (empty($this->session->get('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']."'");
|
||||
$this->session->set('APP_TOKEN', $_token);
|
||||
$this->db->insert('app_token', [ 'Token' => $_token, 'UserID' => $adata['UserID'], 'IP' => $this->app->request()->ip ]);
|
||||
}
|
||||
if (intval($adata['Grup_MenuID']) > 0) $adata['Menu_Grup'] = $this->user_allmenu($adata['Grup_MenuID']);
|
||||
if ((int)$adata['Grup_MenuID'] > 0) $adata['Menu_Grup'] = $this->user_allmenu($adata['Grup_MenuID']);
|
||||
$adata['UNIX'] = time();
|
||||
$adata['LOCALE'] = $_SESSION['__WEB_APP']['DEF_LOCALE'];
|
||||
$adata['LOCALE'] = $this->session->get('__WEB_APP', ['DEF_LOCALE'=>'id'])['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"));
|
||||
$amodul = []; $aallow = []; $tallow = '';
|
||||
if ($this->session->get('__WEB_APP', ['APP_MODULE'=>0])['APP_MODULE']) {
|
||||
$tallow = $this->db->fetchField('SELECT Modul_Akses FROM app_menu_grup WHERE Grup_MenuID=?', [$this->session->get('__WEB_USER', ['Grup_MenuID'=>0])['Grup_MenuID']]);
|
||||
$aallow = explode(",", $tallow);
|
||||
|
||||
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();
|
||||
$stat = $this->db->runQuery('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 ($row = $stat->fetch()) {
|
||||
if (!in_array($row['Modul'], $aallow) || $row['Modul']==$this->session->get('__WEB_APP')['APP_MODULE']) continue;
|
||||
$amodul[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
$_SESSION['__WEB_USER']['MENU_MODUL'] = $amodul;
|
||||
$auser = $this->session->get('__WEB_USER', []);
|
||||
$auser['MENU_MODUL'] = $amodul;
|
||||
$this->session->set('__WEB_USER', $auser);
|
||||
}
|
||||
|
||||
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");
|
||||
public function user_allmenu(int $id_grup = 0) {
|
||||
$allmenu = $this->db->fetchField('SELECT DECODE(Menu,?) MenuX FROM app_menu_grup WHERE Grup_MenuID=?', [$this->__id_reg, $id_grup]);
|
||||
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);
|
||||
$i_hasil = $this->db->fetchField('SELECT COUNT(*) FROM app_operator WHERE Username=? AND Level<=? AND Aktif=1', [$user, $level]);
|
||||
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();
|
||||
$a_hasil = $this->db->fetchRow('SELECT * FROM app_logs WHERE UserID=? ORDER BY Last_Date DESC LIMIT 1', [user_id()])->getData();
|
||||
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->update('app_operator', [ 'Last_IP' => $a_hasil['Last_IP'], 'Last_Date' => $a_hasil['Last_Date'] ], 'UserID=?', [user_id()]);
|
||||
}
|
||||
$this->__db->Query("INSERT IGNORE INTO app_logs SELECT UserID,Token,IP,DateStamp FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
$this->db->runQuery('INSERT IGNORE INTO app_logs SELECT UserID,Token,IP,DateStamp FROM app_token WHERE Token=?', [$this->session->get('APP_TOKEN')]);
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
$this->__db->Query("DELETE FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
$this->db->delete('app_token', 'Token=?', [$this->session->get('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']."'");
|
||||
public function token_check(string $token) {
|
||||
$hasil = (bool)$this->db->fetchField('SELECT 1 FROM app_token WHERE Token=?', [$token ?? $this->session->get('APP_TOKEN')]);
|
||||
if ($hasil === true) $this->db->update('app_token', ['DateStamp' => 'NOW()'], 'Token=?', [$token ?? $this->session->get('APP_TOKEN')]);
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function token_update() {
|
||||
$this->__db->Query("UPDATE app_token SET DateStamp=NOW() WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
$this->db->update('app_token', ['DateStamp' => 'NOW()'], 'Token=?', [$app->session->get('APP_TOKEN')]);
|
||||
}
|
||||
|
||||
public function redirect($appUrl) {
|
||||
public function redirect(string $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'];
|
||||
$hasil = (bool)$this->db->fetchField('SELECT 1 FROM app_host WHERE Nama_Host=?', [$source['host']]);
|
||||
if ($hasil === true) {
|
||||
$desti = $source['scheme'].$source['host'].$source['path'].'?'.'auth='.$app->session->get('APP_TOKEN');
|
||||
}
|
||||
return $desti;
|
||||
}
|
||||
|
||||
private function genToken($length = 16) {
|
||||
private function genToken(int $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");
|
||||
public function getUserByToken(string $token) {
|
||||
$hasil = $this->db->fetchField('SELECT Username FROM app_operator WHERE UserID IN (SELECT UserID FROM app_token WHERE Token=?) LIMIT 1', [$token ??$app->session->get('APP_TOKEN')]);
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
+167
-223
@@ -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."' /> ".$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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+42
-47
@@ -12,45 +12,43 @@
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
use flight\Engine;
|
||||
use flight\Session;
|
||||
use flight\database\SimplePdo;
|
||||
|
||||
final class Menu {
|
||||
protected $__db = null;
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
protected Session $session;
|
||||
|
||||
public function __construct($db = null){
|
||||
$this->__db = $db ?? new \siaupheng\webapp\DB\MySQL();
|
||||
public function __construct(?Engine $app = null){
|
||||
$this->app = (empty($app) === true) ? \Flight::app() : $app;
|
||||
$this->db = $this->app->db();
|
||||
$this->session = $this->app->session();
|
||||
}
|
||||
|
||||
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;
|
||||
public function Menu_Sidebar() {
|
||||
$a_modul = [];
|
||||
$is_modul = ($this->session->get('__WEB_APP', ['APP_MODULE'=>''])['APP_MODULE'] <> '') ? true : false;
|
||||
if ($is_modul == true) {
|
||||
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
|
||||
$a_modul[] = $this->session->get('__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'];
|
||||
$atmp = $this->db->fetchAll('SELECT * FROM app_menu WHERE Level=0 AND Aktif=1 AND Modul<>"IND" ORDER BY Urut');
|
||||
foreach ($atmp as $tmp) {
|
||||
$a_modul[] = $tmp['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");
|
||||
$my_menu = array_unique(array_filter(explode(",", $this->session->get('__WEB_USER', ['Menu_Grup'=>''])['Menu_Grup'].",".$this->session->get('__WEB_USER', ['Menu'=>''])['Menu'])));
|
||||
$tsql = 'SELECT * FROM app_menu WHERE Aktif=1 AND Modul IN (?) AND Kode IN (?)';
|
||||
if ($is_modul == true) $tsql .= ' AND Level>0';
|
||||
|
||||
$amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $my_menu]);
|
||||
$thasil = '';
|
||||
|
||||
$last_level = 0;
|
||||
@@ -72,26 +70,25 @@ final class Menu {
|
||||
return $thasil;
|
||||
}
|
||||
|
||||
public function Menu_Header() {//oke
|
||||
$a_modul = array();
|
||||
$is_modul = (($_SESSION['__WEB_APP']['APP_MODULE'] ?? "") <> "") ? true : false;
|
||||
public function Menu_Header() {
|
||||
$a_modul = [];
|
||||
$is_modul = ($this->session->get('__WEB_APP', ['APP_MODULE'=>''])['APP_MODULE'] <> '') ? true : false;
|
||||
$mulai_level = 0;
|
||||
if ($is_modul == true) {
|
||||
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
|
||||
$a_modul[] = $this->session->get('__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'];
|
||||
$atmp = $this->db->fetchAll('SELECT * FROM app_menu WHERE Level=0 AND Aktif=1 AND Modul<>"IND" ORDER BY Urut');
|
||||
foreach ($atmp as $tmp) {
|
||||
$a_modul[] = $tmp['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");
|
||||
$my_menu = array_unique(array_filter(explode(",", $this->session->get('__WEB_USER', ['Menu_Grup'=>''])['Menu_Grup'].",".$this->session->get('__WEB_USER', ['Menu'=>''])['Menu'])));
|
||||
$tsql = 'SELECT * FROM app_menu WHERE Aktif=1 AND Modul IN (?) AND Kode IN (?)';
|
||||
if ($is_modul == true) $tsql .= ' AND Level>0';
|
||||
|
||||
$amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $my_menu]);
|
||||
$thasil = '';
|
||||
|
||||
$last_level = 0;
|
||||
@@ -119,23 +116,22 @@ final class Menu {
|
||||
return $thasil;
|
||||
}
|
||||
|
||||
static function MenuJSON($db = null, $page = "", $tquery = "") {//oke
|
||||
$_mdb = $db ?? new \siaupheng\webapp\DB\MySQL();
|
||||
static function MenuJSON($db = null, $page = "", $tquery = "") {
|
||||
$_mdb = (empty($db) === true) ? new SimplePdo() : $db;
|
||||
$_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"}]']
|
||||
'SYSP' => ['Kode'=>"SYSP", 'Judul'=>"Profil Pengguna", 'Link'=>"system/profile", 'JS'=>"SYSProfileJS", 'Width'=>600, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]'],
|
||||
'SYSC' => ['Kode'=>"SYSC", 'Judul'=>"Ubah Password", 'Link'=>"system/chpasswd", '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']);
|
||||
$apage = $_mdb->fetchRow('SELECT * FROM app_menu WHERE Kode=?', [$page]);
|
||||
$apage['Width'] = (int)$apage['Width'];
|
||||
}
|
||||
|
||||
$ajson['iswindow'] = ($apage['Width'] > 0) ? true : false;
|
||||
@@ -146,7 +142,6 @@ final class Menu {
|
||||
$ajson['func'] = $apage['JS'];
|
||||
$ajson['kode'] = $apage['Kode'];
|
||||
|
||||
if (!file_exists($_SESSION['__WEB_APP']['REAL_PATH']."apps/php/".$apage['Link'])) $ajson['php'] = "";
|
||||
return $ajson;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-13
@@ -6,16 +6,19 @@
|
||||
Desc. : Class data parameter dari client side
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 14th, 2013.
|
||||
Last Modified : May 8th, 2021.
|
||||
Last Modified : August 8th, 2026.
|
||||
|
||||
(c) 2013 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
use \flight\Engine;
|
||||
|
||||
final class Param {
|
||||
private static $__ahasil = [];
|
||||
|
||||
@@ -24,7 +27,9 @@ final class Param {
|
||||
}
|
||||
|
||||
private static function __data() {
|
||||
$_asumber = array_merge($_REQUEST, $_POST, $_GET);
|
||||
global $app;
|
||||
if (empty($app)) $app = \Flight::app();
|
||||
$_asumber = array_merge($app->request()->query->getData(), $app->request()->data->getData());
|
||||
foreach ($_asumber as $__key => $__val) {
|
||||
self::$__ahasil[$__key] = self::safeSQL($__val);
|
||||
}
|
||||
@@ -56,16 +61,8 @@ final class Param {
|
||||
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;
|
||||
public static function Get_ArrayCBOX() {//delete
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
-18
@@ -6,41 +6,49 @@
|
||||
Desc. : Class Registrasi Aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23th, 2011.
|
||||
Last Modified : May 6th, 2021.
|
||||
Last Modified : August 11th, 2026.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 2011 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Register {
|
||||
protected $__db = null;
|
||||
use flight\Engine;
|
||||
use flight\database\SimplePdo;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
|
||||
final class Register {
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
|
||||
public function __construct(?Engine $app = null){
|
||||
$this->app = (empty($app) === true) ? \Flight::app() : $app;
|
||||
$this->db = $this->app->db();
|
||||
}
|
||||
|
||||
static public function reg_id() {
|
||||
$id = $_SESSION['__WEB_APP']['REG_ID'] ?? "";
|
||||
public static function reg_id() {
|
||||
$webapp = (array)\Flight::app()->session()->get('__WEB_APP');
|
||||
$id = (string)$webapp['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'];
|
||||
public static function reg_code() {
|
||||
$webapp = (array)\Flight::app()->session()->get('__WEB_APP');
|
||||
$id = (string)$webapp['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;
|
||||
public static function reg_check() {
|
||||
$webapp = (array)\Flight::app()->session()->get('__WEB_APP');
|
||||
return (bool)(isset($webapp['REG_STATUS']) && $webapp['REG_STATUS']) ?? false;
|
||||
}
|
||||
|
||||
public function reg_status(array $apps) {
|
||||
$kode_db = (bool)$this->db->fetchField('SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1))=REG_CODE FROM app_config WHERE REG_ID=?', [$apps['APP_CODE'] ?? '']);
|
||||
return [ 'REG_STATUS' => $kode_db === true ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+153
-160
@@ -6,214 +6,201 @@
|
||||
Desc. : HTML Table (jQuery & Bootstrap)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 16th, 2008.
|
||||
Last Modified : January 26th, 2026.
|
||||
Last Modified : August 16th, 2026.
|
||||
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
use flight\Engine;
|
||||
use flight\database\SimplePdo;
|
||||
|
||||
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 $__aparam = [];
|
||||
private $__tfooter = "";
|
||||
private $__afield = [];
|
||||
private $__arowcol = [];
|
||||
private $__arow_func = [];
|
||||
private $__tfunc_select = "";
|
||||
private $__tfunc_navi = "";
|
||||
private $__bno_navi = false;
|
||||
private $__btxtbutton = false;
|
||||
private $__bnobutton = false;
|
||||
private $__bscrollbar = false;
|
||||
private $__acontrol = ['field'=>false, 'value'=>""];
|
||||
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;
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
protected array $data;
|
||||
|
||||
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 __construct(?Engine $app = null) {
|
||||
$this->app = (empty($app) === true) ? \Flight::app() : $app;
|
||||
$this->db = $this->app->db();
|
||||
$this->data = $this->app->request()->data->getData();
|
||||
}
|
||||
|
||||
public function set_table($ttable = "", $tfield = "", $twhere = "") {
|
||||
$this->__ttable = $ttable;
|
||||
if ($tfield != "") $this->__tfield = $tfield;
|
||||
if ($twhere != "") $this->__twhere = $twhere;
|
||||
public function set_table(string $table = "", string $field = "", string $where = "", array $params = []): void {
|
||||
$this->__ttable = $table;
|
||||
$this->__aparam = $params;
|
||||
if (!empty($field)) $this->__tfield = $field;
|
||||
if (!empty($where)) $this->__twhere = $where;
|
||||
}
|
||||
|
||||
public function set_query($tquery = "") {
|
||||
$this->__tquery = $tquery;
|
||||
public function set_footer(string $field = ""): void {
|
||||
$this->__tfooter = $field;
|
||||
}
|
||||
|
||||
public function set_query_footer($tquery = "") {
|
||||
$this->__tquery_footer = $tquery;
|
||||
public function set_css(string $css = ""): void {
|
||||
$this->__tcss = $css;
|
||||
}
|
||||
|
||||
public function set_css($tcss = "") {
|
||||
$this->__tcss = $tcss;
|
||||
public function set_field_order(string $field = "", string $order = "A"): void {
|
||||
$this->__ord_field = $field;
|
||||
$this->__ord_dir = $order;
|
||||
}
|
||||
|
||||
public function set_limit($nlimit = 0) {
|
||||
$this->__nreclimit = $nlimit;
|
||||
public function set_textbtn(bool $istxt = true): void {
|
||||
$this->__btxtbutton = $istxt;
|
||||
}
|
||||
|
||||
public function set_field_order($tfield = "", $torder = "A") {
|
||||
$this->__ord_field = $tfield;
|
||||
$this->__ord_dir = $torder;
|
||||
public function set_scrollbar(bool $isscroll = true, int $height = 200): void {
|
||||
$this->__bscrollbar = $isscroll;
|
||||
$this->__nscrollheight = $height;
|
||||
}
|
||||
|
||||
public function set_textbtn($bistxt = true) {
|
||||
$this->__btxtbutton = $bistxt;
|
||||
public function set_row_color(string $field = "", string $val = "", string $css = ""): void {
|
||||
if (epmty($field)) return;
|
||||
$this->__arowcol[] = [ 'F' => $field, 'V' => $val, 'C' => $css ];
|
||||
}
|
||||
|
||||
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_navi(string $func = ""): void {//compatible
|
||||
$this->__bno_navi = ($func === '');
|
||||
}
|
||||
|
||||
public function set_func_select($tfunc = "") {
|
||||
$this->__tfunc_select = $tfunc;
|
||||
public function set_navi_off(): void {
|
||||
$this->__bno_navi = true;
|
||||
}
|
||||
|
||||
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 set_func_select(string $func = ""): void {
|
||||
$this->__tfunc_select = $func;
|
||||
}
|
||||
|
||||
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 set_func_btn(string $func = "", string $label = ""): void {
|
||||
$this->__arow_func[] = [ 'label' => $label, 'func' => $func ];
|
||||
}
|
||||
|
||||
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 set_row_control(string $field = "", string $value = "Y"): void {
|
||||
$this->__acontrol['field'] = $field;
|
||||
$this->__acontrol['value'] = $value;
|
||||
}
|
||||
|
||||
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 add_row_form(string $icon = "pencil", string $label = "", string $func = "", string $field = "", string $value = ""): void {
|
||||
$this->__aoption[] = [ 'type' => "button-dt", 'func' => $func, 'icon' => $icon, 'label' => $label, 'field' => $field, 'value' => $value ];
|
||||
}
|
||||
|
||||
public function add_row_btn(string $icon = "", string $label = "", string $func = "", string $field = "", string|int $value = "", string $field_css = "", array $avalue_css = []): void {
|
||||
$this->__aoption[] = [ 'type' => 'button', 'func' => $func, 'icon' => $icon, 'label' => $label, 'field' => $field, 'value' => (string)$value, 'field_css' => $field_css, 'avalue_css' => $avalue_css ];
|
||||
}
|
||||
|
||||
public function add_row_del(string $label = "", string $func = "", string $field = "Unix", string $value = ""): void {
|
||||
$this->__aoption[] = [ 'type' => 'button', 'func' => $func, 'icon' => 'x', 'label' => $label, 'field' => $field, 'value' => $value ];
|
||||
}
|
||||
|
||||
public function add_row_edit(string $label = "", string $func = ""): void {
|
||||
$this->add_row_btn('clipboard', $label, $func);
|
||||
}
|
||||
|
||||
public function no_button() {
|
||||
public function add_row_checkbox(string $field = "ID", string $control = "Edit", array $value = ['Y','N']): void {
|
||||
$this->__acbox = [ 'field' => $field, 'control' => $control, 'avalue' => $value ];
|
||||
$this->__aoption[] = ['type' => "checkbox", 'field' => $field, 'avalue' => $value];
|
||||
}
|
||||
|
||||
public function no_button(): void {
|
||||
$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 add_field(string $field = "", string $header = "", string $style = "l", string $format = "", string $footer = "", string $otype = ""): void {
|
||||
$this->__afield[] = [ 'a' => $field, 'h' => $header, 's' => $style, 'f' => $format, 't' => $footer, 'o' => $otype ];
|
||||
}
|
||||
|
||||
public function json_table($nama_tabel = "tabel_", $baris_tabel = 10) {
|
||||
$adata = []; $njml_kol = 0;
|
||||
public function json_table(string $nama_tabel = "tabel_", int $baris_tabel = 10): array {
|
||||
$this->prepare_query();
|
||||
$adata = [];
|
||||
|
||||
// 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;
|
||||
foreach ($this->__afield as $col) {
|
||||
$adata['header'][] = [ 'f' => $col['s'], 'o' => $col['a'], 'c' => $col['h'], 's' => $col['o'] ];
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (!empty($this->__tfooter)) {
|
||||
$row = $this->db->fetchRow("SELECT ".$this->__tfooter." FROM ".$this->__ttable.$this->__twhere, $this->__aparam);
|
||||
foreach ($this->__afield as $col) {
|
||||
$tval = $row[$col['a']] ?? '';
|
||||
if (is_set($col['t']) && !empty($col['t'])) {
|
||||
if (is_array($col['t'])) {
|
||||
$tval2 = $col['t'][$tval] ?? '';
|
||||
} else if (function_exists($col['t'])) {
|
||||
$tval2 = call_user_func($col['t'], $tval);
|
||||
}
|
||||
} else {
|
||||
$tval2 = ($this->__afooter[$i]<>"") ? $this->__afooter[$i] : $tval;
|
||||
$tval2 = $tval;
|
||||
}
|
||||
$adata['footer'][] = ['c'=>$tval2];
|
||||
$adata['footer'][] = [ 'c' => $tval2 ];
|
||||
}
|
||||
}
|
||||
|
||||
$acontent = [];
|
||||
if (!$this->__livedata) {
|
||||
$this->__cdb->Query($this->__tquery);
|
||||
while ($this->__cdb->Next()) {
|
||||
$stat = $this->db->runQuery("SELECT ".$this->__tfield." FROM ".$this->__ttable.$this->__twhere, $this->__aparam);
|
||||
while ($row = $stat->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$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) {
|
||||
if ((($this->__acontrol['field']===false) || ($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'])]??'')];
|
||||
foreach ($this->__aoption as $opsi) {
|
||||
if (in_array($opsi['type'], ["button","button-dt"])) {
|
||||
if (!isset($opsi['field'])) continue;
|
||||
if (!empty($opsi['field']) && ($row[$opsi['field']] !== (!empty($opsi['value']) ? $opsi['value'] : (string)$this->app->session()->get('__WEB_USER')['UNIX']))) {} else {
|
||||
$aoption['button'][] = [ $opsi['icon'], (empty($opsi['field_css'])?'':$opsi['avalue_css'][$row[$opsi['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 (array_key_exists('field', $this->__acbox)) {
|
||||
$aoption['checkbox']['field'] = $row[$this->__acbox['field']];
|
||||
$aoption['checkbox']['value'] = $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'];
|
||||
if (count($this->__arowcol) > 0) {
|
||||
foreach ($this->__arowcol as $rcol) {
|
||||
if ($row[$rcol['F']] == $rcol['V']) $aoption['rowcss'] = $rcol['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);
|
||||
foreach ($this->__afield as $col) {
|
||||
$tval = $row[$col['a']];
|
||||
if (is_array($col['f'])) {
|
||||
$tval = $col['f'][$tval];
|
||||
} else if (!is_null($col['f']) && function_exists($col['f'])) {
|
||||
$tval = call_user_func($col['f'], $tval);
|
||||
} else if (is_string($tval)) {
|
||||
$tval = stripslashes($tval);
|
||||
}
|
||||
$abaris[] = $tval;
|
||||
}
|
||||
@@ -222,80 +209,82 @@ final class Table {
|
||||
}
|
||||
|
||||
// navigator
|
||||
$anavi = [ 'func_navi' => $this->__tfunc_navi, 'button' => $this->__arow_func ];
|
||||
$anavi = [ 'no_navi' => $this->__bno_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;
|
||||
if ($aval['type'] !== 'checkbox') unset($aval['field'], $aval['value'], $aval['field_css'], $aval['avalue_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;
|
||||
public function db_table(string $nama_tabel = "tabel_", int $baris_tabel = 10): array {
|
||||
$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);
|
||||
$this->__livedata = true;
|
||||
$adata = [];
|
||||
$id_draw = (int) ($this->data['draw'] ?? 0);
|
||||
$i_start = (int) ($this->data['start'] ?? 0);
|
||||
$i_length = (int) ($this->data['length'] ?? 0);
|
||||
$a_order = (array) ($this->data['order'] ?? []);
|
||||
|
||||
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));
|
||||
$record = (int)$this->db->fetchField("SELECT COUNT(*) FROM ".$this->__ttable.$this->__twhere, $this->__aparam) ?? 0;
|
||||
$adata['type'] = "table-live";
|
||||
$adata['id'] = $nama_tabel;
|
||||
$adata['config'] = ['draw' => $id_draw, 'recordsTotal' => $record, 'recordsFiltered' => $record];
|
||||
$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 (count($a_order) > 0) {
|
||||
$t_order = ($a_order[0]['dir']=="asc") ? "ASC" : "DESC";
|
||||
$c_order = $a_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 : "";
|
||||
$sql_order = ($this->__afield[$c_order]) ? " ORDER BY ".$this->__afield[$c_order]['a']." ".$t_order : "";
|
||||
|
||||
$adata['data'] = [];
|
||||
$this->__cdb->Query("SELECT ".$this->__tfield." FROM ".$this->__ttable.$this->__twhere.$sql_order.$sql_limit);
|
||||
while ($this->__cdb->Next()) {
|
||||
$stat = $this->db->runQuery("SELECT ".$this->__tfield." FROM ".$this->__ttable.$this->__twhere.$sql_order.$sql_limit, $this->__aparam);
|
||||
while ($row = $stat->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$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) {
|
||||
if ((($this->__acontrol['field']===false) || ($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'])]??'')];
|
||||
foreach ($this->__aoption as $opsi) {
|
||||
if (in_array($opsi['type'], ["button","button-dt"])) {
|
||||
if (!isset($opsi['field'])) continue;
|
||||
if (!empty($opsi['field']) && ($row[$opsi['field']] !== (!empty($opsi['value']) ? $opsi['value'] : $this->app->session()->get('__WEB_USER')['UNIX']))) {} else {
|
||||
$aoption['button'][] = [ $opsi['icon'], (empty($opsi['field_css'])?'':$opsi['avalue_css'][$row[$opsi['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 (array_key_exists('field', $this->__acbox)) {
|
||||
$aoption['checkbox']['field'] = $row[$this->__acbox['field']];
|
||||
$aoption['checkbox']['value'] = $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'];
|
||||
if (count($this->__arowcol)>0) {
|
||||
foreach ($this->__arowcol as $rcol) {
|
||||
if ($row[$rcol['F']] == $rcol['V']) $aoption['rowcss'] = $rcol['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);
|
||||
foreach ($this->__afield as $col) {
|
||||
$tval = $row[$col['a']];
|
||||
if (is_array($col['f'])) {
|
||||
$tval = $col['f'][$tval];
|
||||
} else if (!is_null($col['f']) && function_exists($col['f'])) {
|
||||
$tval = call_user_func($col['f'], $tval);
|
||||
} else if (is_string($tval)) {
|
||||
$tval = stripslashes($tval);
|
||||
}
|
||||
$abaris[] = $tval;
|
||||
}
|
||||
@@ -308,9 +297,13 @@ final class Table {
|
||||
}
|
||||
|
||||
private function prepare_query() {
|
||||
if ($this->__tfield == "") $this->__tfield = "`".implode('`,`', $this->__afield)."`";
|
||||
if ($this->__twhere != "") $this->__twhere = " WHERE " . $this->__twhere;
|
||||
if (empty($this->__tfield)) $this->__tfield = '`'. implode('`,`', array_column($this->__afield, 'a')) .'`';
|
||||
if (!empty($this->__twhere)) $this->__twhere = ' WHERE ' . $this->__twhere;
|
||||
}
|
||||
|
||||
//public function set_query($tquery = "") {}
|
||||
//public function set_limit($nlimit = 0) {}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+25
-16
@@ -6,26 +6,31 @@
|
||||
Desc. : Class Update Aplikasi Otomatis
|
||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||
Created Date : June 14th, 2013.
|
||||
Last Modified : March 3rd, 2026.
|
||||
Last Modified : August 12th, 2026.
|
||||
|
||||
(c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Web;
|
||||
|
||||
final class Update {
|
||||
protected $__conf = [];
|
||||
protected $is_git = false;
|
||||
use flight\Engine;
|
||||
|
||||
public function __construct(){
|
||||
$this->__conf = $_SESSION['__WEB_APP'];
|
||||
$this->get_current();
|
||||
final class Update {
|
||||
protected Array $__conf = [];
|
||||
protected Bool $is_git = false;
|
||||
protected Engine $app;
|
||||
|
||||
public function __construct(?Engine $app = null){
|
||||
$this->app = (empty($app) === true) ? \Flight::app() : $app;
|
||||
$this->__conf = $app->session()->get('__WEB_APP');
|
||||
$this->current();
|
||||
}
|
||||
|
||||
public function get_current() {
|
||||
public function current() {
|
||||
$_target = $this->__conf['REAL_PATH'];
|
||||
if (isset($_target)) chdir($_target);
|
||||
|
||||
@@ -33,16 +38,16 @@ final class Update {
|
||||
$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->__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];
|
||||
$this->__conf['GIT_OWNER'] = $_ainfo[1] ?? '';
|
||||
$this->__conf['GIT_REPO'] = $_ainfo[2] ?? '';
|
||||
}
|
||||
$output = shell_exec("git branch --show-current 2>&1");
|
||||
if ($output) {
|
||||
@@ -52,15 +57,19 @@ final class Update {
|
||||
}
|
||||
}
|
||||
|
||||
public function check_update() {
|
||||
public function check() {
|
||||
$_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";
|
||||
$_ainfo['new_sha'] = 'check git config';
|
||||
$_ainfo['new_sha1'] = $this->__conf['GIT_SHA1'];
|
||||
$_ainfo['new_date'] = '';
|
||||
$_ainfo['new_message'] = 'check git config';
|
||||
|
||||
if (!$this->is_git) return $_ainfo;
|
||||
if (!$this->is_git || empty($this->__conf['GIT_OWNER']) || empty($this->__conf['GIT_REPO'])) return $_ainfo;
|
||||
|
||||
try {
|
||||
$_url = "https://git.trifonia.cloud/api/v1/repos/".$this->__conf['GIT_OWNER']."/".$this->__conf['GIT_REPO']."/commits?limit=1";
|
||||
@@ -80,7 +89,7 @@ final class Update {
|
||||
return $_ainfo;
|
||||
}
|
||||
|
||||
public function go_update() {
|
||||
public function go() {
|
||||
$_target = $this->__conf['REAL_PATH'];
|
||||
$_branch = $this->__conf['GIT_BRANCH'] ?? "main";
|
||||
if (isset($_target)) {
|
||||
@@ -90,7 +99,7 @@ final class Update {
|
||||
} else return ['success'=>false,'message'=>"Tanpa REAL_PATH !"];
|
||||
}
|
||||
|
||||
public function update_mysql() {
|
||||
public function mysql() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user