original push
This commit is contained in:
+159
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /App.php
|
||||
Desc. : v3 - HTML5 Page Generator v3 (jQuery & CoreUI)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 10th, 2008.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3;
|
||||
|
||||
final class App {
|
||||
public $version = "3.0.0";
|
||||
private $apps = array();
|
||||
private $auser = array();
|
||||
private $cache = null;
|
||||
private $menu = null;
|
||||
private $reg = null;
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$this->apps = $_SESSION['__WEB_APP'];
|
||||
$this->apps['TEMPLATE'] = "index.php";
|
||||
if (isset($_SESSION['__WEB_USER'])) {
|
||||
$this->auser = $_SESSION['__WEB_USER'];
|
||||
$this->auser['user_info'] = tgl_sql2str($this->auser['Last_Date'], true) ." // ". $this->auser['Last_IP'].'<input type="hidden" id="Desktop_User_ID" value="'.intval($this->auser['UserID']).'"><input type="hidden" id="Desktop_User_Level" value="'.intval($this->auser['Level']).'"><input type="hidden" id="Desktop_User_UID" value="'.$this->auser['Username'].'">';
|
||||
$this->auser['user_img'] = "profile.webp";
|
||||
if (file_exists($this->apps['REAL_PATH']."assets/images/profiles/".$this->auser['ID'].".webp")) {
|
||||
$this->auser['user_img'] = $this->auser['ID'].".webp";
|
||||
}
|
||||
}
|
||||
$this->reg = new \siaupheng\fonia3\Web\Register($this->__db);
|
||||
$this->cache = new \siaupheng\fonia3\Data\Cache($this->__db);
|
||||
$this->menu = new \siaupheng\fonia3\Web\Menu($this->__db);
|
||||
}
|
||||
|
||||
public function TampilApp($aoption = array()) {
|
||||
// cek register
|
||||
if ($this->reg->reg_check()) {
|
||||
if (!user_logged()) {
|
||||
$this->apps['TEMPLATE'] = "login.php";
|
||||
}
|
||||
} else {
|
||||
$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']);
|
||||
$compos = 0;
|
||||
if (strpos(strtoupper($buffer), "<!DOCTYPE") !== false) {
|
||||
$compos = strpos(strtoupper($buffer), "<!DOCTYPE");
|
||||
}
|
||||
$buffer = substr($buffer, $compos);
|
||||
}
|
||||
|
||||
// penambahan file css + js + app-js
|
||||
$headers = '<link rel="stylesheet" type="text/css" href="'.$this->cache->Main("css").'">'."\n";
|
||||
$headers .= '<script type="text/javascript" src="'.$this->cache->Main("js").'"></script>'."\n";
|
||||
if (user_logged()) $headers .= '<script type="text/javascript" src="'.$this->cache->Apps().'"></script>'."\n";
|
||||
|
||||
$_secret = $this->apps['APP_CODE'] .";". $this->apps['APP_SID'] .";". $_SERVER['HTTP_HOST'] .";". $this->apps['WEB_PATH'] .";". "http://".$_SERVER['HTTP_HOST'].$this->apps['WEB_PATH'] .";". ($this->apps['AUTH_LEVEL']?$this->apps['AUTH_LEVEL']:0) .";". $this->version;
|
||||
$_suser = (user_logged()) ? $this->auser['Username'] .";". $this->auser['UserID'] .";". $this->auser['Grup_MenuID'] .";". $this->auser['Level'] : "";
|
||||
$tnaviside = $tnavihead = "";
|
||||
$headers .= '<script type="text/javascript" language="javascript">'."\n";
|
||||
$headers .= 'FoniaJS.setConfig("'.base64_encode($_secret).'", "'.base64_encode($_suser).'");';
|
||||
$headers .= '$(document).ready(function(){';
|
||||
if (user_logged()) {
|
||||
$headers .= 'FoniaJS.loadMenu();';
|
||||
$tnaviside = $this->menu->Menu_Sidebar();
|
||||
$tnavihead = $this->menu->Menu_Header();
|
||||
}
|
||||
$headers .= '});';
|
||||
$headers .= '</script>'."\n";
|
||||
|
||||
// informasi tahun aplikasi dan pembuatan menu
|
||||
if (strpos($buffer, '_CREATOR_YEAR_')===false) {
|
||||
$this->apps['REG_YEAR'] = ($this->apps['REG_YEAR']!=date('Y')) ? $this->apps['REG_YEAR']." - ".date('Y') : $this->apps['REG_YEAR'];
|
||||
} else {
|
||||
$this->apps['CREATOR_YEAR'] = ($this->apps['CREATOR_YEAR']!=date('Y')) ? $this->apps['CREATOR_YEAR']." - ".date('Y') : $this->apps['CREATOR_YEAR'];
|
||||
}
|
||||
|
||||
// perubahan variabel dari data konfigurasi
|
||||
$asrc = array("[_CREATOR_NAME_]", "[_CREATOR_WEBSITE_]", "[_CREATOR_YEAR_]", "[_APP_NAME_VER_]", "[_APP_NAMES_VER_]", "[_APP_NAME_]", "[_APP_NAMES_]", "[_APP_NAMES_UP_]", "[_APP_VER_]", "[_APP_UPDATED_]", "[_REG_ID_]", "[_REG_NAME_]", "[_REG_NAME_UP_]", "[_REG_ADDRESS_]", "[_REG_CITY_]", "[_REG_CITY_UP_]", "[_REG_PHONE_]", "[_REG_FAX_]", "[_REG_EMAIL_]", "[_REG_POSTCODE_]", "[_REG_WEBSITE_]", "[_REG_YEAR_]", "[_USER_LASTLOG_]", "[_USER_IMG_]", "[_WEB_PATH_]", "[_NAVI_SIDEBAR_]", "[_NAVI_HEADER_]");
|
||||
$adst = array($this->apps['CREATOR_NAME'], $this->apps['CREATOR_WEBSITE'], $this->apps['CREATOR_YEAR'], $this->apps['APP_NAME']." v".$this->apps['APP_VER'], $this->apps['APP_NAMES']." v".$this->apps['APP_VER'], $this->apps['APP_NAME'], $this->apps['APP_NAMES'], strtoupper($this->apps['APP_NAMES']), $this->apps['APP_VER'], $this->apps['APP_UPDATED'], $this->reg->reg_id(), $this->apps['REG_NAME'], strtoupper($this->apps['REG_NAME']), $this->apps['REG_ADDRESS'], $this->apps['REG_CITY'], strtoupper($this->apps['REG_CITY']), $this->apps['REG_PHONE'], $this->apps['REG_FAX'], $this->apps['REG_EMAIL'], $this->apps['REG_POSTCODE'], $this->apps['REG_WEBSITE'], $this->apps['REG_YEAR'], $this->auser['user_info'] ?? "[none]", "profiles/".$this->auser['user_img'], $this->apps['WEB_PATH'], $tnaviside, $tnavihead);
|
||||
$buffer = str_replace($asrc, $adst, $buffer);
|
||||
|
||||
if (isset($this->auser) && is_array($this->auser)) {
|
||||
$buffer = str_replace("[_USER_ID_]", $this->auser['UserID'], $buffer);
|
||||
$buffer = str_replace("[_USER_USER_]", $this->auser['Username'], $buffer);
|
||||
$buffer = str_replace("[_USER_NAME_]", $this->auser['Nama'], $buffer);
|
||||
$buffer = str_replace("[_USER_POSISI_]", $this->auser['Posisi'], $buffer);
|
||||
|
||||
// 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 {
|
||||
if ($this->apps['PARENT_SUB']==true) {
|
||||
$tmp_url = parse_url($this->apps['PARENT_SITE']);
|
||||
$href1 = $tmp_url['scheme'] . "://";
|
||||
$href2 = ".".$tmp_url['host'];
|
||||
} else {
|
||||
$href1 = $this->apps['PARENT_SITE'].'/';
|
||||
$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="c-icon mr-2 '.$modul['Icon'].'"></i> '.$modul['Judul'].'</a>';
|
||||
}
|
||||
}
|
||||
$buffer = str_replace("[_MENU_MODUL_]", $t_modul, $buffer);
|
||||
}
|
||||
|
||||
// penyisipan header
|
||||
$headpos = 0;
|
||||
if (strpos(strtolower($buffer), "</head>") !== false) {
|
||||
$headpos = strpos(strtolower($buffer), "</head>");
|
||||
}
|
||||
$split_1_buffer = substr($buffer, 0, $headpos);
|
||||
$split_2_buffer = substr($buffer, $headpos);
|
||||
$buffer = $split_1_buffer.$headers.$split_2_buffer;
|
||||
|
||||
// penyisipan option (pilihan tahun, tanggal login, dll)
|
||||
if (count($aoption) > 0) {
|
||||
foreach ($aoption as $__key => $val) {
|
||||
if (strpos($__key, "OPTION")!==false) {
|
||||
$opt_var = (new cFORM())->option("Pilihan", $__key, $val['value'], true, $val['option']);
|
||||
$buffer = str_replace("[_".$__key."_]", $opt_var, $buffer);
|
||||
} else if (strpos($__key, "PICKDATE")!==false) {
|
||||
$txt_var = (new cFORM())->datebox("Tanggal", $__key, $val['value'], true);
|
||||
$buffer = str_replace("[_".$__key."_]", $txt_var, $buffer);
|
||||
} else if (strpos($__key, "CUSTOM")!==false) {
|
||||
$buffer = str_replace("[_".$__key."_]", $val['value'], $buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $buffer;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /DB/CheckSQL.php
|
||||
Desc. : v3 - Class Check SQL / Repair Database
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : May 11th, 2011.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\DB;
|
||||
|
||||
final class CheckSQL {
|
||||
private $__atabel = array();
|
||||
private $__aignore = array();
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$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>');
|
||||
}
|
||||
}
|
||||
|
||||
public function ignore_table() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$this->__aignore = $tmp_arr;
|
||||
}
|
||||
|
||||
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>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$hasil = $atabel[0] . $atabel[2] ." ... ". $pesan ."<br>";
|
||||
}
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function count_db() {
|
||||
return count($this->__atabel);
|
||||
}
|
||||
|
||||
public function check_db() {
|
||||
$hasil = "=== CEK DATABASE ===<br>";
|
||||
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;
|
||||
}
|
||||
|
||||
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>";
|
||||
}
|
||||
}
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /DB/DumpSQL.php
|
||||
Desc. : v3 - Class Dump Data SQL
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : May 11th, 2011.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\DB;
|
||||
|
||||
final class DumpSQL {
|
||||
private $__adata = array();
|
||||
private $__aignore = array("vi_%","rep_%");
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$this->__adata = $this->__db->getConfig();
|
||||
}
|
||||
|
||||
public function set_db($nama_db = "") {
|
||||
if ($nama_db<>"") $this->__adata['db'] = $nama_db;
|
||||
}
|
||||
|
||||
public function ignore_table() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$this->__aignore = array_merge($this->__aignore, $tmp_arr);
|
||||
}
|
||||
|
||||
private function ignore_prepare() {
|
||||
$ahasil = array();
|
||||
foreach($this->__aignore as $_val) {
|
||||
if (strpos($_val, "%")===false) {
|
||||
$ahasil[] = $_val;
|
||||
} else {
|
||||
$this->__db->Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$this->__db->getDBName()."' AND TABLE_NAME LIKE '".$_val."'");
|
||||
while ($this->__db->Next()) {
|
||||
$ahasil[] = $this->__db->Row("TABLE_NAME");
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ahasil;
|
||||
}
|
||||
|
||||
public function create_backup($folder="backups") {
|
||||
$namafile = date("Ymd").".gz";
|
||||
$folder = $_SESSION['__WEB_APP']['REAL_PATH'].$folder."/".date("Y");
|
||||
if (!is_dir($folder)) mkdir($folder);
|
||||
if (file_exists($folder."/".$namafile)) unlink($folder."/".$namafile);
|
||||
$_cmd = "mysqldump -C --hex-blob -h ".$this->__adata['host']." -P ".$this->__adata['port']." -u ".$this->__adata['user']." -p".$this->__adata['pwd']." ".$this->__adata['db'];
|
||||
$itable = $this->ignore_prepare();
|
||||
foreach($itable as $_val) $_cmd .= " --ignore-table=".$this->__adata['db'].".".$_val;
|
||||
$_cmd .= " | gzip -9 > ".$folder."/".$namafile;
|
||||
system($_cmd);
|
||||
}
|
||||
|
||||
private function get_file_list($directory) {
|
||||
$arrayItems = array();
|
||||
$skipByExclude = false;
|
||||
$handle = opendir($directory);
|
||||
if ($handle) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
preg_match("/(^(([\.]){1,2})$|(\.(svn|git|md))|(Thumbs\.db|\.DS_STORE))$/iu", $file, $skip);
|
||||
$skipByExclude = in_array($file, array(",",".."));
|
||||
if (!$skip && !$skipByExclude) {
|
||||
if (is_dir($directory. DIRECTORY_SEPARATOR . $file)) {
|
||||
$arrayItems = array_merge($arrayItems, $this->get_file_list($directory. DIRECTORY_SEPARATOR . $file));
|
||||
} else {
|
||||
$file = $directory . DIRECTORY_SEPARATOR . $file;
|
||||
$arrayItems[] = str_replace("\\", "/", $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
return $arrayItems;
|
||||
}
|
||||
|
||||
private function format_bytes($bytes) {
|
||||
if ($bytes < 1024) return $bytes.' B';
|
||||
elseif ($bytes < 1048576) return uang2($bytes / 1024).' KB';
|
||||
elseif ($bytes < 1073741824) return uang2($bytes / 1048576).' MB';
|
||||
elseif ($bytes < 1099511627776) return uang2($bytes / 1073741824).' GB';
|
||||
else return uang2($bytes / 1099511627776).' TB';
|
||||
}
|
||||
|
||||
public function disk_space() {
|
||||
$_free = disk_free_space($_SESSION['__WEB_APP']['REAL_PATH']);
|
||||
$_tot = disk_total_space($_SESSION['__WEB_APP']['REAL_PATH']);
|
||||
$_used = $_tot - $_free;
|
||||
$_aret = array();
|
||||
$_aret['TOTAL'] = $this->format_bytes($_tot);
|
||||
$_aret['USED'] = $this->format_bytes($_used);
|
||||
$_aret['FREE'] = $this->format_bytes($_free);
|
||||
$_aret['USED_P'] = ($_used/$_tot) * 100;
|
||||
$_aret['FREE_P'] = ($_free/$_tot) * 100;
|
||||
return $_aret;
|
||||
}
|
||||
|
||||
public function update_list($folder="backups") {
|
||||
$folder = $_SESSION['__WEB_APP']['REAL_PATH'].$folder;
|
||||
$this->__db->Query("TRUNCATE TABLE app_backup");
|
||||
$afile = $this->get_file_list($folder);
|
||||
foreach($afile as $_key => $_val) {
|
||||
if (file_exists($_val)) {
|
||||
$_file = str_replace($folder."/", "", $_val);
|
||||
$_waktu = date("Y-m-d H:i:s", filemtime($_val));
|
||||
$_ukuran = $this->format_bytes(filesize($_val));
|
||||
$this->__db->Query("INSERT INTO app_backup SET Nama_File='".$_file."',Tanggal='".$_waktu."',Ukuran='".$_ukuran."'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /DB/MySQL.php
|
||||
Desc. : v3 - Class database MySQL / MariaDB
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 2nd, 2007.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\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 = 0; //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, $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'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /DB/SQL.php
|
||||
Desc. : v3 - Class Query database
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 2nd, 2007.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\DB;
|
||||
|
||||
final class SQL {
|
||||
private $__ttable = "";
|
||||
private $__afield = array();
|
||||
private $__avalue = array();
|
||||
private $__anomor = array();
|
||||
private $__twhere = "";
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
}
|
||||
|
||||
public function SafeSQL($ttext = "") {
|
||||
return $this->__db->SafeSQL($ttext);
|
||||
}
|
||||
|
||||
public function set_table($ttable = "") {
|
||||
$this->__ttable = $ttable;
|
||||
}
|
||||
|
||||
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_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_stamp($tparam = "DateStamp") {
|
||||
$this->__afield[] = $tparam;
|
||||
$this->__avalue[] = "NOW()";
|
||||
$this->__anomor[] = true;
|
||||
}
|
||||
|
||||
public function add_param_unix() {
|
||||
$this->__afield[] = "Unix";
|
||||
$this->__avalue[] = user_unix();
|
||||
$this->__anomor[] = false;
|
||||
}
|
||||
|
||||
public function add_param_userid($tparam = "UserID") {
|
||||
$this->__afield[] = $tparam;
|
||||
$this->__avalue[] = user_id();
|
||||
$this->__anomor[] = false;
|
||||
}
|
||||
|
||||
public function add_where_unix() {
|
||||
$this->__twhere .= (($this->__twhere=="") ? " WHERE " : " AND ") . "(Unix='".user_unix()."')";
|
||||
}
|
||||
|
||||
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($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 clear_param() {
|
||||
$this->__afield = array();
|
||||
$this->__avalue = array();
|
||||
$this->__anomor = array();
|
||||
}
|
||||
|
||||
public function clear_where() {
|
||||
$this->__twhere = "";
|
||||
}
|
||||
|
||||
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])?"":"'");
|
||||
}
|
||||
$tsql .= substr($tfield,1);
|
||||
$tsql .= ") VALUES (";
|
||||
$tsql .= substr($tvalue,1);
|
||||
$tsql .= ")";
|
||||
$this->__db->Query($tsql);
|
||||
}
|
||||
|
||||
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])?"":"'");
|
||||
}
|
||||
$tsql .= substr($tfield,1);
|
||||
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
|
||||
$this->__db->Query($tsql);
|
||||
}
|
||||
|
||||
public function DeleteDB() {
|
||||
$tsql = "DELETE FROM ".$this->__ttable;
|
||||
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
|
||||
$this->__db->Query($tsql);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/CSV.php
|
||||
Desc. : v3 - Class pembuatan file CSV
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 2rd, 2011.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
define( DELI_CSV, ";" );
|
||||
define( CRLF_CSV, "\r\n" );
|
||||
|
||||
final class CSV {
|
||||
private $__avalue = array();
|
||||
private $__atabel = array();
|
||||
|
||||
public function add_field($tnama="", $ffunc="") {
|
||||
$this->__atabel[] = array($tnama, $ffunc);
|
||||
}
|
||||
|
||||
public function add_value() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$tmp_out = "";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];
|
||||
if (is_array($this->__atabel[$i][1]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = $this->__atabel[$i][1][$tmp_val];
|
||||
} else if (function_exists($this->__atabel[$i][1]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->__atabel[$i][1], $tmp_val);
|
||||
}
|
||||
$tmp_out .= DELI_CSV . $tmp_val;
|
||||
}
|
||||
$tmp_out = substr($tmp_out, 1);
|
||||
$this->__avalue[] = $tmp_out;
|
||||
}
|
||||
|
||||
public function download($nama_file="export.csv") {
|
||||
$out = "";
|
||||
// add header
|
||||
$tmp_out = "";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$tmp_out .= DELI_CSV . $this->__atabel[$i][0];
|
||||
}
|
||||
$out .= substr($tmp_out, 1) . CRLF_CSV;
|
||||
// add content
|
||||
for ($i=0; $i<count($this->__avalue); $i++) {
|
||||
$out .= $this->__avalue[$i] . CRLF_CSV;
|
||||
}
|
||||
|
||||
header("Content-type: application/octet-stream");
|
||||
header("Content-Disposition: attachment; filename=\"".$nama_file."\"");
|
||||
echo $out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/Cache.php
|
||||
Desc. : v3 - Class cache aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : March 16th, 2008.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
use MatthiasMullie\Minify;
|
||||
|
||||
final class Cache {
|
||||
private $__cachedays = 0;
|
||||
private $__cachedir = "";
|
||||
private $__cssdir = "";
|
||||
private $__localedir = "";
|
||||
private $__jsdir = "";
|
||||
private $__jsapp = "";
|
||||
private $__realpath = "";
|
||||
private $__ini = array();
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$rootdir = $_SESSION['__WEB_APP']['REAL_PATH'];
|
||||
$this->__cachedir = $rootdir . 'cache/';
|
||||
$this->__cssdir = __DIR__ . '/../../assets/css/';
|
||||
$this->__localedir = $rootdir . 'assets/locale/';
|
||||
$this->__jsdir = __DIR__ . '/../../assets/js/';
|
||||
$this->__jsapp = $rootdir . 'apps/js/';
|
||||
$this->__realpath = $rootdir;
|
||||
if (!file_exists($this->__cachedir . "cache.ini")) {
|
||||
$this->__ini = array('css'=>array('login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>""), 'js'=>array('login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>""));
|
||||
$this->save_ini();
|
||||
}
|
||||
$this->__ini = parse_ini_file($this->__cachedir . "cache.ini", true);
|
||||
}
|
||||
|
||||
private function gen_file($type="css", $mode="index") {
|
||||
$afile = array();
|
||||
if ($type == "css") {
|
||||
$_afile = array_unique($GLOBALS['A_CSS']);
|
||||
foreach ($_afile as $__key => $val) {
|
||||
$afile[] = $this->__cssdir .$val;
|
||||
}
|
||||
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;
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
} else if ($type == "js") {
|
||||
$_afile = array_unique($GLOBALS['A_JS']);
|
||||
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);
|
||||
}
|
||||
}
|
||||
// add locale file
|
||||
$ljs = (isset($_SESSION['__WEB_USER']['LOCALE'])?$_SESSION['__WEB_USER']['LOCALE']:$_SESSION['__WEB_APP']['DEF_LOCALE']).".js";
|
||||
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));
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
return $lastmod;
|
||||
}
|
||||
|
||||
private function create_cache($type="css", $mode="index", $afile=array(), $lastmod=0) {
|
||||
$contents = '';
|
||||
$bpublic = ($_SERVER['SERVER_ADDR'] == "127.0.0.1") ? false : true;
|
||||
if ($bpublic == true) {
|
||||
if ($type=="css") {
|
||||
$smini = new Minify\CSS;
|
||||
} else {
|
||||
$smini = new Minify\JS;
|
||||
}
|
||||
}
|
||||
foreach ($afile as $nfile) {
|
||||
if (file_exists($nfile)) {
|
||||
if ($bpublic == true) {
|
||||
$smini->add($nfile);
|
||||
} else {
|
||||
$contents .= "\n". file_get_contents($nfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
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(){
|
||||
$content = "";
|
||||
foreach ($this->__ini as $key => $elem) {
|
||||
$content .= ($content==""?"":"\n"). "[".$key."]\n";
|
||||
foreach ($elem as $key2 => $elem2) {
|
||||
if ($elem2=="") $content .= $key2." = \n";
|
||||
else $content .= $key2." = \"".$elem2."\"\n";
|
||||
}
|
||||
}
|
||||
file_put_contents($this->__cachedir . "cache.ini", $content);
|
||||
}
|
||||
|
||||
public function Main($type="css") {
|
||||
$mode = (isset($_SESSION['__WEB_USER']) && is_array($_SESSION['__WEB_USER']) && $_SESSION['__WEB_USER']['UserID']>0) ? "index" : "login";
|
||||
$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);
|
||||
}
|
||||
return $_SESSION['__WEB_APP']['WEB_PATH'] ."cache/". $this->__ini[$type][$mode.'_file'];
|
||||
}
|
||||
|
||||
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'] ."cache/". $appfile;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/PDF.php
|
||||
Desc. : v3 - Class pembuatan file PDF
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 18th, 2015.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2015 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
use Mpdf;
|
||||
|
||||
final class PDF {
|
||||
private $__avalue = array();
|
||||
private $__atabel = array();
|
||||
private $__theader = "";
|
||||
private $__tcolname = "";
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="", $nkol=1) {
|
||||
$this->__atabel[] = array($tnama, $nlebar.'%', $ffunc, $talign, $nkol);
|
||||
}
|
||||
|
||||
public function show_fields() {
|
||||
$tmp_out = "<thead><tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
if ($this->__atabel[$i][4]==0) continue;
|
||||
$tmp_out .= $this->set_align($this->__atabel[$i][0], $this->__atabel[$i][1], "C", false, true, $this->__atabel[$i][4]);
|
||||
}
|
||||
$tmp_out .= "</tr></thead>";
|
||||
$this->__tcolname = $tmp_out;
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
$this->__avalue = array();
|
||||
$this->__theader = "";
|
||||
$this->__tcolname = "";
|
||||
}
|
||||
|
||||
public function set_header($tlapor="", $tperiod="") {
|
||||
$thasil = '<div style="text-align:center;font-size:12pt;"><b>'.strtoupper($_SESSION['__WEB_APP']['REG_NAME']);
|
||||
$thasil .= (($tlapor=="") ? "" : '<br>'.$tlapor) . '</b>';
|
||||
$thasil .= ($tperiod=="") ? "" : '<br><span style="font-size:11pt;">'.$tperiod.'</span>';
|
||||
$thasil .= '</div><br>';
|
||||
$this->__theader = $thasil;
|
||||
}
|
||||
|
||||
public function add_value() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];
|
||||
if (is_array($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = $this->__atabel[$i][2][$tmp_val];
|
||||
} else if (function_exists($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->__atabel[$i][2], $tmp_val);
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val, $this->__atabel[$i][1], $this->__atabel[$i][3]);
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
}
|
||||
|
||||
public function add_span() {
|
||||
$tmp_arr = func_get_args();
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($tmp_arr); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];// CONTENT, COLSPAN=1, L, FUNC
|
||||
if (function_exists($tmp_val[3]) && trim($tmp_val[0])<>"") {
|
||||
$tmp_val[0] = call_user_func($tmp_val[3], $tmp_val[0]);
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val[0], 0, $tmp_val[2], false, false, $tmp_val[1]);
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
}
|
||||
|
||||
public function add_empty() {
|
||||
$this->__avalue[] = $this->set_align(" ", 0, "L,NB", true);
|
||||
}
|
||||
|
||||
public function add_stamp($ctk_ke=1, $bnama=false) {
|
||||
$this->__avalue[] = $this->set_align($_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):""), 0, "L,NB", true);
|
||||
}
|
||||
|
||||
public function get_stamp($ctk_ke=1, $bnama=false) {
|
||||
return $_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):"");
|
||||
}
|
||||
|
||||
public function createPDF($nama_file = "Nama_File.pdf", $nfontz = 8, $orien = "P") {
|
||||
$html = '
|
||||
<style>
|
||||
#pdf_area {
|
||||
width: 100%;
|
||||
color: #000;
|
||||
}
|
||||
#pdf_area p { margin: 0; padding: 0; }
|
||||
#pdf_cont table {
|
||||
border: 1px solid #ccc;
|
||||
border-spacing: 0;
|
||||
border-collapse: collapse;
|
||||
overflow: auto;
|
||||
}
|
||||
#pdf_cont table th, #pdf_cont table td {
|
||||
font-size: 12pt;
|
||||
text-align: left;
|
||||
}
|
||||
#pdf_cont table th {
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
padding: 2mm;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
#pdf_cont table td {
|
||||
padding: 1mm;
|
||||
}
|
||||
#pdf_cont table td.left { text-align: left; }
|
||||
#pdf_cont table td.center { text-align: center; }
|
||||
#pdf_cont table td.right { text-align: right; }
|
||||
#pdf_cont table td.bold { font-weight: bold; }
|
||||
#pdf_cont table td.italic { font-style: italic; }
|
||||
</style>
|
||||
<body class="pdf_area">
|
||||
<htmlpagefooter name="RepFoot">
|
||||
<table width="100%" style="border:none;"><tr><td width="50%" style="text-align:left;border:none;">'.$this->get_stamp(1, true).'</td><td width="50%" style="text-align:right;font-style:italic;border:none;">Halaman : {PAGENO} dari {nbpg}</td></tr></table>
|
||||
</htmlpagefooter>
|
||||
<sethtmlpagefooter name="RepFoot" show-this-page="1" value="on" />';
|
||||
if ($this->__theader<>"") $html .= $this->__theader;
|
||||
$html .= '<div id="pdf_cont"><table>';
|
||||
if ($this->__tcolname<>"") $html .= $this->__tcolname;
|
||||
$html .= '<tbody>';
|
||||
|
||||
// content out
|
||||
for ($i=0; $i<count($this->__avalue); $i++) {
|
||||
$html .= $this->__avalue[$i];
|
||||
}
|
||||
$html .= '</tbody></table></div></div></body>';
|
||||
$mpdf = new mPDF('c', 'A4'.($orien=="L"?"-L":""), $nfontz, '', 5, 5, 5, 10, 5, 5);
|
||||
$mpdf->useSubstitutions = false;
|
||||
$mpdf->WriteHTML($html);
|
||||
$mpdf->Output($nama_file.".pdf", "I");
|
||||
}
|
||||
|
||||
public function set_align($ttext, $nlen, $tdir="L", $bline=false, $bhead=false, $ncol=1) {
|
||||
$tstyle = $this->create_style($tdir);
|
||||
if (strpos(strtolower($ttext), "<tr>")===false) { //jika tidak ada <tr> up 2011-04-14
|
||||
if ($bline===true) {
|
||||
return '<tr><td colspan="'.count($this->__atabel).'" class="'.$tstyle.'">'.$ttext."</td></tr>";
|
||||
} else {
|
||||
return (($bhead===true)?"<th":"<td").(($ncol>1)?' colspan="'.$ncol.'"':"").' class="'.$tstyle.'" '.(($bhead===true)?'width="'.$nlen.'"':"").">".$ttext.(($bhead===true)?"</th>":"</td>");
|
||||
}
|
||||
} else {
|
||||
return (($bline===true) ? $ttext : (($bhead===true)?"<th":"<td").(($ncol>1)?" colspan=\"".$ncol."\"":"")." class=\"".$tstyle." \" ".(($bhead===true)?"width=\"".$nlen."\"":"").">".$ttext.(($bhead===true)?"</th>":"</td>"));
|
||||
}
|
||||
}
|
||||
|
||||
private function create_style($tstyle="L") {
|
||||
$apad = array("L"=>"left", "R"=>"right", "C"=>"center", "NB"=>"nb", "NL"=>"noleft", "NR"=>"noright", "B"=>"bold", "I"=>"italic");
|
||||
$_astyle = explode(",", $tstyle);
|
||||
$thasil = "";
|
||||
foreach ($_astyle as $_key => $_val) {
|
||||
$thasil .= " ".$apad[$_val];
|
||||
}
|
||||
return substr($thasil,1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Function/Auth.php
|
||||
Desc. : Fungsi Custom Auth
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 27th, 2008.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if (!function_exists('user_level')) {
|
||||
function user_level($level = 9) {
|
||||
if ($_SESSION['__WEB_USER']['Level'] <= $level) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_logged')) {
|
||||
function user_logged() {
|
||||
if (isset($_SESSION['__WEB_USER'])) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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 (!function_exists('user_user')) {
|
||||
function user_user() {
|
||||
return $_SESSION['__WEB_USER']['Username'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_unix')) {
|
||||
function user_unix() {
|
||||
return $_SESSION['__WEB_USER']['UNIX'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_nama')) {
|
||||
function user_nama() {
|
||||
return $_SESSION['__WEB_USER']['Nama'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Function/JSON.php
|
||||
Desc. : Fungsi Custom JSON
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 14th, 2012.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2012 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Function/Misc.php
|
||||
Desc. : Fungsi Custom Lain Lain
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 27th, 2008.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
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('rupiah2')) {
|
||||
function rupiah2($angka = 0) {
|
||||
return rupiah($angka, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('rupiah30')) {
|
||||
function rupiah30($angka = 0) {
|
||||
$nilai = explode(".", $angka);
|
||||
$hasil = (intval($nilai[1])==0) ? rupiah($angka, 0) : rupiah($angka, 3);
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('kurung_rup')) {
|
||||
function kurung_rup($angka = 0, $desi = 0) {
|
||||
$thasil = rupiah(abs($angka), $desi);
|
||||
if ($angka<0) return "(".$thasil.")";
|
||||
return $thasil." ";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('kurung')) {
|
||||
function kurung($angka = 0, $desi = 0) {
|
||||
$thasil = uang(abs($angka), $desi);
|
||||
if ($angka<0) return "(".$thasil.")";
|
||||
return $thasil." ";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('kurung2')) {
|
||||
function kurung2($angka = 0) {
|
||||
return kurung($angka, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('uang')) {
|
||||
function uang($angka = 0, $desi = 0) {
|
||||
$angka = str_replace(",","",$angka);
|
||||
return number_format(doubleval($angka), intval($desi));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('uang2')) {
|
||||
function uang2($angka = 0) {
|
||||
return uang($angka, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('koma30')) {
|
||||
function koma30($angka = 0) {
|
||||
$nilai = explode(".", $angka);
|
||||
$hasil = (intval($nilai[1])==0) ? uang($angka, 0) : uang($angka, 3);
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('items')) {
|
||||
function items($item = 0) {
|
||||
return rupiah($item)." Items";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('records')) {
|
||||
function records($item = 0) {
|
||||
return rupiah($item)." Records";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('baris')) {
|
||||
function baris($item = 0) {
|
||||
return rupiah($item)." Baris";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('npwp')) {
|
||||
function npwp($nomor = "000000000000000") {
|
||||
return substr($nomor,0,2).".".substr($nomor,2,3).".".substr($nomor,5,3).".".substr($nomor,8,1)."-".substr($nomor,9,3).".".substr($nomor,12,3);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('romawi')) {
|
||||
function romawi($n) {
|
||||
$hasil = "";
|
||||
$iromawi = array("","I","II","III","IV","V","VI","VII","VIII","IX","X",20=>"XX",30=>"XXX",40=>"XL",50=>"L",60=>"LX",70=>"LXX",80=>"LXXX",90=>"XC",100=>"C",200=>"CC",300=>"CCC",400=>"CD",500=>"D",600=>"DC",700=>"DCC",800=>"DCCC",900=>"CM",1000=>"M",2000=>"MM",3000=>"MMM");
|
||||
if (array_key_exists($n,$iromawi)) {
|
||||
$hasil = $iromawi[$n];
|
||||
} else if ($n >= 11 && $n <= 99) {
|
||||
$i = $n % 10;
|
||||
$hasil = $iromawi[$n-$i] . Romawi($n % 10);
|
||||
} else if ($n >= 101 && $n <= 999) {
|
||||
$i = $n % 100;
|
||||
$hasil = $iromawi[$n-$i] . Romawi($n % 100);
|
||||
} else {
|
||||
$i = $n % 1000;
|
||||
$hasil = $iromawi[$n-$i] . Romawi($n % 1000);
|
||||
}
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('abjad')) {
|
||||
function abjad($n) {
|
||||
$_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
return substr($_str, ($n-1), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************** FORM CONTROL *****************************/
|
||||
|
||||
if (!function_exists('checkbox')) {
|
||||
function checkbox($nilai = 0) {
|
||||
$bhasil = ((is_string($nilai) && ($nilai=="N" || $nilai=="0")) or (is_numeric($nilai) && $nilai==0) or (is_bool($nilai) && $nilai==false)) ? true : false;
|
||||
return '<input type="checkbox" '.(($bhasil)?"":"checked").' readonly />';
|
||||
}
|
||||
}
|
||||
|
||||
/*************************** FORMAT TANGGAL / KALENDER *****************************/
|
||||
|
||||
if (!function_exists('sqltgl')) {
|
||||
function sqltgl($waktu = "0") {
|
||||
return tgl_sql2str($waktu);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sqltgls')) {
|
||||
function sqltgls($waktu = "0") {
|
||||
return tgl_sql2str($waktu, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sqljam')) {
|
||||
function sqljam($waktu = "0") {
|
||||
return tgl_sql2str($waktu, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sqljams')) {
|
||||
function sqljams($waktu = "0") {
|
||||
return tgl_sql2str($waktu, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_sql2str')) {
|
||||
function tgl_sql2str($waktu = "0", $jam = false, $short = false) {
|
||||
if ($waktu=="0" || $waktu=="") return;
|
||||
$atgl = explode(" ", $waktu);
|
||||
$sjam = ($jam) ? ((empty($atgl[1]))?date("H:i:s"):$atgl[1]) : "";
|
||||
$atgl = explode("-", $atgl[0]);
|
||||
$stgl = $atgl[2]."-".$atgl[1]."-".$atgl[0];
|
||||
if ($short) $stgl = $atgl[2].".".$atgl[1].".".substr($atgl[0],2);
|
||||
return $stgl.(($jam)?" ".$sjam:"");
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_ymd')) {
|
||||
function tgl_ymd($jam = false) {
|
||||
return (($jam) ? date("Y-m-d H:i:s") : date("Y-m-d"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_dmy')) {
|
||||
function tgl_dmy($jam = false) {
|
||||
return (($jam) ? date("d-m-Y H:i:s") : date("d-m-Y"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_operasi')) {
|
||||
function tgl_operasi($dtgl = "", $nhari = 0, $nbln = 0, $nthn = 0) {
|
||||
$atgl = explode("-", $dtgl);
|
||||
return date("d-m-Y", mktime(0,0,0, $atgl[1]+$nbln, $atgl[0]+$nhari, $atgl[2]+$nthn));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_range_hari')) {
|
||||
function tgl_range_hari($dftgl="", $dttgl="", $bhitung_awal=false) {
|
||||
$_start = strtotime(tgl_sql2str($dftgl));
|
||||
$_end = strtotime(tgl_sql2str($dttgl));
|
||||
return ceil(abs($_end - $_start) / 86400) + (($bhitung_awal==true)?1:0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('bulan_array')) {
|
||||
function bulan_array() {
|
||||
return array("1"=>"Januari","2"=>"Februari","3"=>"Maret","4"=>"April","5"=>"Mei","6"=>"Juni","7"=>"Juli","8"=>"Agustus","9"=>"September","10"=>"Oktober","11"=>"November","12"=>"Desember");
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_akhbln')) {
|
||||
function tgl_akhbln($tgl) {
|
||||
$atgl = explode("-", $tgl);
|
||||
$ablna = array(31,28,31,30,31,30,31,31,30,31,30,31);
|
||||
// jika tahun masehi dan bulan 2
|
||||
if ( (round($atgl[2]/4)==($atgl[2]/4)) && intval($atgl[1])==2 ) return "29-02-".$atgl[2];
|
||||
return $ablna[(intval($atgl[1])-1)]."-".isi_nol($atgl[1],2)."-".$atgl[2];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_panjang')) {
|
||||
function tgl_panjang($dtgl = "") {
|
||||
if (trim($dtgl)=="") $dtgl = tgl_dmy();
|
||||
$atgl = explode("-", $dtgl);
|
||||
$abulan = bulan_array();
|
||||
return $atgl[0]." ".$abulan[intval($atgl[1])]." ".$atgl[2];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('tgl_hari')) {
|
||||
function tgl_hari($dtgl = "") {
|
||||
$nhari = date("w");
|
||||
if (trim($dtgl)!="") {
|
||||
//$atgl = getdate($dtgl);
|
||||
//$nhari = $atgl[wday];
|
||||
$nhari = date("w", strtotime(tgl_sql2str($dtgl)));
|
||||
}
|
||||
$ahari = array("0"=>"Minggu","1"=>"Senin","2"=>"Selasa","3"=>"Rabu","4"=>"Kamis","5"=>"Jum'at","6"=>"Sabtu");
|
||||
return $ahari[$nhari];
|
||||
}
|
||||
}
|
||||
if (!function_exists('tgl_triwulan')) {
|
||||
function tgl_triwulan($dtgl = "") {
|
||||
if ($dtgl == "") {
|
||||
$dtgl = date("m");
|
||||
} else {
|
||||
$atgl = explode("-", $tgl);
|
||||
$dtgl = $atgl[1];
|
||||
}
|
||||
$hasil = 0;
|
||||
if ($dtgl >= 1 && $dtgl <= 3) $hasil = 1;
|
||||
if ($dtgl >= 4 && $dtgl <= 6) $hasil = 2;
|
||||
if ($dtgl >= 7 && $dtgl <= 9) $hasil = 3;
|
||||
if ($dtgl >= 10 && $dtgl <= 12) $hasil = 4;
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************** FORMAT TAMPILAN & ERROR *****************************/
|
||||
|
||||
if (!function_exists('subjudul')) {
|
||||
function subjudul($tjudul) {
|
||||
return '<table border="0" align="center" valign="middle" width="100%" height="26px"><tr><td width="50%"><hr /></td><td> <span style="text-align:center;font-weight:bold;white-space:nowrap;">'.$tjudul.'</span> </td><td width="50%"><hr /></td></tr></table>';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('showerror')) {
|
||||
function showerror($terror) {
|
||||
echo '<input type="hidden" id="_Error" class="error" value="'.$terror.'!" />';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('br2nl')) {
|
||||
function br2nl($string) {
|
||||
return preg_replace('/\<br(\s*)?\/?\>/i', "\n\r", $string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('isi_nol')) {
|
||||
function isi_nol($nilai = "0", $panjang = 1) {
|
||||
$nilai = strval($nilai);
|
||||
return str_repeat("0", $panjang-strlen($nilai)).$nilai;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('isLinux')) {
|
||||
function isLinux() {
|
||||
$agen = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||
if (stripos($agen, 'linux') !== false) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('isIE')) {
|
||||
function isIE() {
|
||||
$agen = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||
if (stripos($agen,'msie') !== false) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('isChrome')) {
|
||||
function isChrome() {
|
||||
$agen = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||
if (stripos($agen,'chrome') !== false) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('isFirefox')) {
|
||||
function isFirefox() {
|
||||
$agen = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||
if (stripos($agen,'firefox') !== false) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('potong')) {
|
||||
function potong($nilai) {//utk rkpd
|
||||
return substr($nilai, 0, 60);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Auth.php
|
||||
Desc. : v3 - Fungsi login dan user checking
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : March 16th, 2008.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Auth {
|
||||
private $__id_reg = 0;
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$this->__id_reg = $_SESSION['__WEB_APP']['REG_ID'];
|
||||
}
|
||||
|
||||
public function set_id_reg($id = 0) {
|
||||
if ($id > 0) $this->__id_reg = $id;
|
||||
}
|
||||
|
||||
public function user_check($user, $pass) {
|
||||
$i_hasil = 0;
|
||||
$this->__db->Query("SELECT COUNT(*) Ada FROM app_operator WHERE Username='".$this->__db->safeSQL($user)."' AND Password=MD5('".$this->__db->safeSQL($pass)."') AND Aktif=1");
|
||||
if ($this->__db->Next()) $i_hasil = $this->__db->Row("Ada", 0);
|
||||
return ($i_hasil > 0 ? true : false);
|
||||
}
|
||||
|
||||
public function user_data($user) {
|
||||
$adata = array();
|
||||
$this->__db->Query("SELECT *,DECODE(Menu,'".$this->__id_reg."') Menu2 FROM app_operator WHERE Username='".$this->__db->SafeSQL($user)."'");
|
||||
if ($this->__db->Next()) {
|
||||
$adata = $this->__db->AllRow();
|
||||
$adata['Menu'] = $adata['Menu2'];
|
||||
unset($adata['Menu2']);
|
||||
}
|
||||
if (!isset($_SESSION['APP_TOKEN'])) {
|
||||
$_token = $this->genToken(60);
|
||||
$_SESSION['APP_TOKEN'] = $_token;
|
||||
$this->__db->Query("INSERT INTO app_token SET Token='".$_token."',UserID='".$adata['UserID']."',IP='".$_SERVER['REMOTE_ADDR']."'");
|
||||
}
|
||||
$adata['UNIX'] = time();
|
||||
$adata['LOCALE'] = $_SESSION['__WEB_APP']['DEF_LOCALE'];
|
||||
return $adata;
|
||||
}
|
||||
|
||||
public function gen_module_menu() {
|
||||
$amodul = array();
|
||||
$aallow = array();
|
||||
if ($_SESSION['__WEB_APP']['APP_MODULE']) {
|
||||
$this->__db->Query("SELECT * FROM app_menu_grup WHERE Grup_MenuID='".$_SESSION['__WEB_USER']['Grup_MenuID']."' LIMIT 1");
|
||||
if ($this->__db->Next()) $aallow = ($this->__db->Row("Modul_Akses")=="") ? array() : explode(",", $this->__db->Row("Modul_Akses"));
|
||||
if (count($aallow) > 0) {
|
||||
$this->__db->Query("SELECT * FROM (SELECT APP_MODULE,APP_PATH FROM app_config) A LEFT JOIN (SELECT Modul,Urut,Judul,Icon FROM app_menu WHERE Level=0) B ON (A.APP_MODULE=B.Modul) ORDER BY B.Urut");
|
||||
while ($this->__db->Next()) {
|
||||
if (!in_array($this->__db->Row("Modul"), $aallow) || $this->__db->Row("Modul")==$_SESSION['__WEB_APP']['APP_MODULE']) continue;
|
||||
$amodul[] = $this->__db->AllRow();
|
||||
}
|
||||
}
|
||||
}
|
||||
$_SESSION['__WEB_USER']['MENU_MODUL'] = $amodul;
|
||||
}
|
||||
|
||||
public function user_allmenu($id_grup = 0) {
|
||||
$allmenu = "";
|
||||
$this->__db->Query("SELECT DECODE(Menu,'".$this->__id_reg."') MenuX FROM app_menu_grup WHERE Grup_MenuID='".$id_grup."'");
|
||||
if ($this->__db->Next()) $allmenu = $this->__db->Row("MenuX");
|
||||
return $allmenu;
|
||||
}
|
||||
|
||||
public function user_check_level($user, $level = 9) {
|
||||
$i_hasil = 0;
|
||||
$this->__db->Query("SELECT COUNT(*) Ada FROM app_operator WHERE Username='".$this->__db->safeSQL($user)."' AND Level<='".$this->__db->safeSQL($level)."' AND Aktif=1");
|
||||
if ($this->__db->Next()) $i_hasil = $this->__db->Row("Ada", 0);
|
||||
return ($i_hasil > 0 ? true : false);
|
||||
}
|
||||
|
||||
public function user_log() {
|
||||
if ($_SESSION['__WEB_APP']['USER_LOG'] == false) return;
|
||||
$a_hasil = array();
|
||||
$this->__db->Query("SELECT * FROM app_logs WHERE UserID='".user_id()."' ORDER BY Last_Date DESC LIMIT 1");
|
||||
if ($this->__db->Next()) $a_hasil = $this->__db->AllRow();
|
||||
if (count($a_hasil) > 0) {
|
||||
$this->__db->Query("UPDATE app_operator SET Last_IP='".$a_hasil['Last_IP']."',Last_Date='".$a_hasil['Last_Date']."' WHERE UserID='".user_id()."'");
|
||||
}
|
||||
//$tgl_lalu = tgl_sql2str(tgl_operasi(tgl_dmy(), 0, -3));
|
||||
//$this->__db->Query("DELETE FROM app_logs WHERE UserID='".user_id()."' AND Last_Date<'".$tgl_lalu."'");
|
||||
$this->__db->Query("INSERT IGNORE INTO app_logs SELECT UserID,Token,IP,DateStamp FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
$this->__db->Query("DELETE FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
}
|
||||
|
||||
public function token_check() {
|
||||
$hasil = false;
|
||||
$this->__db->Query("SELECT * FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
if ($this->__db->Next()) $hasil = true;
|
||||
if ($hasil == true) $this->__db->Query("UPDATE app_token SET DateStamp=NOW() WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function token_update() {
|
||||
$this->__db->Query("UPDATE app_token SET DateStamp=NOW() WHERE Token='".$_SESSION['APP_TOKEN']."'");
|
||||
}
|
||||
|
||||
public function redirect($appUrl) {
|
||||
$source = parse_url($appUrl);
|
||||
$desti = "";
|
||||
$this->__db->Query("SELECT * FROM app_host WHERE Nama_Host='".$source['host']."'");
|
||||
if ($this->__db->Next()) {
|
||||
$desti = $source['scheme'].$source['host'].$source['path'].'?'.'auth='.$_SESSION['APP_TOKEN'];
|
||||
}
|
||||
return $desti;
|
||||
}
|
||||
|
||||
private function genToken($length = 16) {
|
||||
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
return substr(str_shuffle(str_repeat($pool, 5)), 0, $length);
|
||||
}
|
||||
|
||||
public function getUserByToken($token) {
|
||||
$hasil = "";
|
||||
$this->__db->Query("SELECT * FROM app_operator WHERE UserID IN (SELECT UserID FROM app_token WHERE Token='".$token."') LIMIT 1");
|
||||
if ($this->__db->Next()) $hasil = $this->__db->Row("Username");
|
||||
return $hasil;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Form.php
|
||||
Desc. : v3 - Form Generator v3 (jQuery & CoreUI)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 27th, 2008.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Form {
|
||||
private $__aform = array();
|
||||
private $__ahide = array();
|
||||
private $__button = null;
|
||||
private $__nbtnsize = 2;
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$this->__button = new Button();
|
||||
}
|
||||
|
||||
public function option($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null, $bmulti=false) {//oke
|
||||
$_enab = ($benable==true) ? "" : ' disabled=true';
|
||||
$_req = ($breq==true) ? " required=true" : "";
|
||||
$_change = ($tchange==null) ? "" : ' onchange="'.$tchange.'"';
|
||||
$_multi = ($bmulti==true) ? ' multiple=true' : "";
|
||||
$tout = '<select class="form-control option-tags" id="'.$tfield.'" name="'.$tfield.'"'.$_enab.$_change.$_req.$_multi.' >';
|
||||
if (count($aarr)>0) {
|
||||
foreach ($aarr as $key => $val) {
|
||||
$_val2 = $val; $olabel = "";
|
||||
if (is_array($val)) {
|
||||
$_val2 = $val[0];
|
||||
$olabel = (isset($val[1])) ? ' olabel="'.$val[1].'"' : "";
|
||||
}
|
||||
$tout .= '<option value="'.$key.'"'.$olabel;
|
||||
$aval = array($tvalue);
|
||||
if ($bmulti==true) $aval = explode(",", $tvalue);
|
||||
$tout .= (in_array($key, $aval)) ? ' selected="selected"' : "";
|
||||
$tout .= '>'.$_val2.'</option>';
|
||||
}
|
||||
}
|
||||
$tout .= '</select>';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function option_db($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $ttable=null, $afield=null, $twhere=null, $addarray=null, $thelp="", $tchange=null) {//oke
|
||||
$afield = ($afield==null) ? array("ID", "Nama", "Label") : $afield;
|
||||
$_twhere = ($twhere==null) ? "" : " WHERE ".$twhere;
|
||||
$_twhere .= ($twhere===null || stripos($twhere,"ORDER BY")===false) ? " ORDER BY ".$afield[1] : "";
|
||||
$ahasil = array();
|
||||
if (is_array($addarray)) $ahasil[$addarray[0]] = (!isset($afield[2])) ? $addarray[1] : array($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]) : array($this->__db->Row($afield[1]), $this->__db->Row($afield[2]));
|
||||
}
|
||||
}
|
||||
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function option_que($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $tquery=null, $afield=null, $addarray=null, $thelp="", $tchange=null) {//oke
|
||||
$afield = ($afield==null) ? array("ID", "Nama", "Label") : $afield;
|
||||
$ahasil = array();
|
||||
if (is_array($addarray)) $ahasil[$addarray[0]] = (!isset($afield[2])) ? $addarray[1] : array($addarray[1], $addarray[2]);
|
||||
if ($tquery<>null) {
|
||||
$this->__db->Query($tquery);
|
||||
while ($this->__db->Next()) {
|
||||
$ahasil[$this->__db->Row($afield[0])] = (!isset($afield[2])) ? $this->__db->Row($afield[1]) : array($this->__db->Row($afield[1]), $this->__db->Row($afield[2]));
|
||||
}
|
||||
}
|
||||
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function option_jkl($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {//oke
|
||||
$akel = array("L" => "Laki-Laki", "P" => "Perempuan");
|
||||
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $akel, $thelp, $tchange);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function option_ulevel($tlabel="", $tfield, $tvalue=9, $benable=true, $breq=false, $thelp="", $tchange=null) {//oke
|
||||
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $_SESSION['__WEB_APP']['USER_LEVEL'], $thelp, $tchange);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function radio($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null) {//oke
|
||||
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 mr-2"><input class="form-check-input" id="'.$tfield.$key.'" type="radio" value="'.$key.'" name="'.$tfield.'"';
|
||||
$tout .= ($key == $tvalue) ? ' checked="checked"' : '';
|
||||
$tout .= ' onclick="if(this.checked)$(\'#'.$tfield.'\').val(this.value);"'.$_enab.$_change.$_req;
|
||||
$tout .= '><label class="form-check-label" for="'.$tfield.$key.'">'.$val.'</label></div>';
|
||||
}
|
||||
}
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function radio_jkl($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {//oke
|
||||
$tout = $this->radio($tlabel, $tfield, $tvalue, $benable, $breq, array("L" => "Laki-Laki", "P" => "Perempuan"), $thelp, $tchange);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function radio_gd($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {//oke
|
||||
$tvalue = ($tvalue=="") ? "X" : $tvalue;
|
||||
$tout = $this->radio($tlabel, $tfield, $tvalue, $benable, $breq, array("A"=>"A", "B"=>"B", "AB"=>"AB", "O"=>"O", "X"=>"NONE"), $thelp, $tchange);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function checkbox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $avalue=array(), $thelp="", $tchange=null) {//oke
|
||||
$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 = ($tchange==null) ? ' onchange="this.value=(this.checked)?\''.$avalue[0].'\':\''.$avalue[1].'\';"' : ' onchange="this.value=(this.checked)?\''.$avalue[0].'\':\''.$avalue[1].'\';'.$tchange.'"';
|
||||
$tout .= '<div class="form-check form-check-inline mr-1"><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 .= '></div>';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function switch_sq($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null) {//oke
|
||||
$_key = array_keys($aarr); $_val = array_values($aarr);
|
||||
$_enab = ($benable==true) ? "" : ' disabled=true';
|
||||
$_req = ($breq==true) ? " required=true" : "";
|
||||
$_change = ($tchange==null) ? ' onchange="this.value=(this.checked)?\''.$_key[0].'\':\''.$_key[1].'\';"' : ' onchange="this.value=(this.checked)?\''.$_key[0].'\':\''.$_key[1].'\';'.$tchange.'"';
|
||||
$tout = '<label class="c-switch c-switch-label c-switch-info"><input class="c-switch-input" type="checkbox" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'"'.$_enab.$_change.$_req;
|
||||
$tout .= ($_key[0] == $tvalue) ? ' checked="checked"' : '';
|
||||
$tout .= '><span class="c-switch-slider" data-checked="'.$_val[0].'" data-unchecked="'.$_val[1].'"></span></label>';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
/* belum diupgrade !! */
|
||||
public function form_group_cbox($tfield, $tkey=null, $tclass=null, $ttable=null, $afield=null, $ncol=2) {
|
||||
if ($ttable==null) return;
|
||||
$avalue = explode(",", $tkey);
|
||||
$afield = ($afield==null) ? array("ID", "Nama") : $afield;
|
||||
$_twhere = ($twhere=="") ? " ORDER BY ".$afield[0] : " WHERE ".$twhere;
|
||||
$tout = "<input id=\"".$tfield."\" value=\"".$tkey."\" type='hidden' class='cgrpbox' /><table width='100%' style='margin:1px 0;padding:2px 2px;'><tr>";
|
||||
|
||||
$nkol = 1;
|
||||
$this->__db->Query("SELECT ".implode(",", $afield)." FROM ".$ttable.$_twhere);
|
||||
while ($this->__db->Next()) {
|
||||
$tout .= "<td width='".round(100/$ncol)."%'><label><input type='checkbox' id='".$tfield."_cgrpbox_".$this->__db->Row($afield[0])."' value='".$this->__db->Row($afield[0])."'";
|
||||
for ($i=0; $i<count($avalue); $i++) {
|
||||
if ($avalue[$i]==$this->__db->Row($afield[0])) {
|
||||
$tout .= " checked=\"checked\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$tout .= " class='text ".$tclass."' /> ".$this->__db->Row($afield[1])."</label></td>";
|
||||
if ($nkol==$ncol) {
|
||||
$tout .= "</tr><tr>";
|
||||
$nkol = 0;
|
||||
}
|
||||
$nkol++;
|
||||
}
|
||||
$tout .= "</tr></table>";
|
||||
$this->__aform[$tfield] = $tout;
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function textbox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $ttype="text", $holdtxt=null, $nmaxsize=null, $thelp="", $tkeyup=null, $tblur=null) {//oke
|
||||
$_enab = ($benable==true) ? "" : ' readonly';
|
||||
$_req = ($breq==true) ? " required=true" : "";
|
||||
$_max = ($nmaxsize==null) ? "" : ' maxlength="'.$nmaxsize.'"';
|
||||
$_keyup = ($tkeyup==null) ? "" : ' onkeyup="'.$tkeyup.'"';
|
||||
$_blur = ($tblur==null) ? "" : ' onblur="'.$tblur.'"';
|
||||
$_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"';
|
||||
$_tclass = "";
|
||||
if (in_array($ttype,array("pickdate","picktime"))) {
|
||||
$_tclass = ' '.$ttype;
|
||||
$ttype = "text";
|
||||
}
|
||||
if (in_array($ttype,array("double"))) {
|
||||
$_tclass = ' '.$ttype;
|
||||
$tvalue = uang2($tvalue);
|
||||
}
|
||||
$tout = '<input type="'.$ttype.'" class="form-control'.$_tclass.'" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'"'.$_enab.$_max.$_keyup.$_blur.$_holdtxt.$_req.' />';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function textauto($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $holdtxt=null, $nmaxsize=null, $thelp="") {//oke
|
||||
$tvalue = ($tvalue==null) ? array('value'=>0, 'text'=>"") : $tvalue;
|
||||
$_enab = ($benable==true) ? "" : ' disabled=true';
|
||||
$_req = ($breq==true) ? " required=true" : "";
|
||||
$_max = ($nmaxsize==null) ? "" : ' maxlength="'.$nmaxsize.'"';
|
||||
$_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"';
|
||||
$tout = '<select class="form-control" id="'.$tfield.'" name="'.$tfield.'" default-value="'.$tvalue['value'].'" default-text="'.$tvalue['text'].'"'.$_enab.$_max.$_holdtxt.$_req.' /></select>';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function datebox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tkeyup=null, $tblur=null) {//oke
|
||||
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 .= '<div class="input-group-append"><span class="input-group-text"><i class="cui-calendar"></i></span></div></div>';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function timebox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tkeyup=null, $tblur=null) {//oke
|
||||
$tout = $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "picktime", "hh:mm:ss", 10, $thelp, $tkeyup, $tblur);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function textarea($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $nrows=1, $holdtxt=null, $thelp="", $tkeyup=null, $tblur=null) {//oke
|
||||
$_enab = ($benable==true) ? "" : ' disabled=true';
|
||||
$_req = ($breq==true) ? " required=true" : "";
|
||||
$_rows = ($nrows==null) ? "" : ' rows="'.$nrows.'"';
|
||||
$_keyup = ($tkeyup==null) ? "" : ' onkeyup="'.$tkeyup.'"';
|
||||
$_blur = ($tblur==null) ? "" : ' onblur="'.$tblur.'"';
|
||||
$_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"';
|
||||
$tout = '<textarea class="form-control" id="'.$tfield.'" name="'.$tfield.'"'.$_enab.$_rows.$_keyup.$_blur.$_holdtxt.$_req.' >'.$tvalue.'</textarea>';
|
||||
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function password($tlabel="", $tfield, $tvalue="", $benable=true, $breq=false, $holdtxt=null, $nmaxsize=null, $thelp="", $tkeyup=null) {//oke
|
||||
$tout = $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "password", $holdtxt, $nmaxsize, $thelp, $tkeyup, $tblur);
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function hidden($tfield, $tvalue="", $tclass="text") {//oke
|
||||
$tout = '<input type="hidden" id="'.$tfield.'" value="'.$tvalue.'" class="'.$tclass.'" />';
|
||||
$this->__ahide[$tfield] = $tout;
|
||||
return $tout;
|
||||
}
|
||||
|
||||
public function clear() {//oke
|
||||
$this->__aform = array();
|
||||
}
|
||||
|
||||
public function show($tstr) {//oke
|
||||
foreach ($this->__aform as $_key => $_val) {
|
||||
$tval = '<div class="form-row mb-1"><label class="col-sm-5 col-lg-4 col-form-label" for="'.$_key.'">'.$_val['label'].'</label><div class="col-sm-7 col-lg-8">'.$_val['form'].($_val['help']==""?'':'<span class="help-block"><small>'.$_val['help'].'</small></span>').'</div></div>';
|
||||
$tstr = str_replace("_".$_key."_", $tval, $tstr);
|
||||
}
|
||||
$txtbtn = $this->__button->Button($this->__nbtnsize);
|
||||
if (""<>$txtbtn) {
|
||||
$tstr .= '<div class="row mb-1"><div class="col"><hr class="my-2"></div></div>';
|
||||
$tstr .= $txtbtn;
|
||||
}
|
||||
foreach ($this->__ahide as $_key => $_val) {
|
||||
$tstr = str_replace("_".$_key."_", $_val, $tstr);
|
||||
}
|
||||
$tstr = str_replace("\n", "", $tstr);
|
||||
$tstr = str_replace("\t", "", $tstr);
|
||||
echo $tstr;
|
||||
}
|
||||
|
||||
public function btn_separator() {//oke
|
||||
$this->__button->separator();
|
||||
}
|
||||
public function btn_primary($id="", $label="", $bmiss=false) {//oke
|
||||
$this->__button->primary($id, $label, $bmiss);
|
||||
}
|
||||
public function btn_info($id="", $label="", $bmiss=false) {//oke
|
||||
$this->__button->info($id, $label, $bmiss);
|
||||
}
|
||||
public function btn_danger($id="", $label="", $bmiss=false) {//oke
|
||||
$this->__button->danger($id, $label, $bmiss);
|
||||
}
|
||||
public function btn_warning($id="", $label="", $bmiss=false) {//oke
|
||||
$this->__button->warning($id, $label, $bmiss);
|
||||
}
|
||||
public function btn_success($id="", $label="", $bmiss=false) {//oke
|
||||
$this->__button->success($id, $label, $bmiss);
|
||||
}
|
||||
public function btn_secondary($id="", $label="", $bmiss=false) {//oke
|
||||
$this->__button->secondary($id, $label, $bmiss);
|
||||
}
|
||||
public function Button($size=2) {//oke
|
||||
$this->__nbtnsize = $size;
|
||||
}
|
||||
}
|
||||
|
||||
class Button {
|
||||
private $__abutton = array();
|
||||
private $__bsepa = false;
|
||||
|
||||
public function __construct() {}
|
||||
private function add($type="info", $id="", $label="", $bmiss=false) {//oke
|
||||
if ($id=="") $id = "random".rand(1000, 10000);
|
||||
$this->__abutton[] = array('type'=>$type, 'id'=>$id, 'label'=>$label, 'bmiss'=>$bmiss);
|
||||
}
|
||||
|
||||
public function separator() {//oke
|
||||
$this->__abutton[] = array('type'=>"separator");
|
||||
$this->__bsepa = true;
|
||||
}
|
||||
public function primary($id="", $label="", $bmiss=false) {//oke
|
||||
$this->add("primary", $id, $label, $bmiss);
|
||||
}
|
||||
public function info($id="", $label="", $bmiss=false) {//oke
|
||||
$this->add("info", $id, $label, $bmiss);
|
||||
}
|
||||
public function danger($id="", $label="", $bmiss=false) {//oke
|
||||
$this->add("danger", $id, $label, $bmiss);
|
||||
}
|
||||
public function warning($id="", $label="", $bmiss=false) {//oke
|
||||
$this->add("warning", $id, $label, $bmiss);
|
||||
}
|
||||
public function success($id="", $label="", $bmiss=false) {//oke
|
||||
$this->add("success", $id, $label, $bmiss);
|
||||
}
|
||||
public function secondary($id="", $label="", $bmiss=false) {//oke
|
||||
$this->add("secondary", $id, $label, $bmiss);
|
||||
}
|
||||
|
||||
public function Button($size=2) {//oke
|
||||
if (0==count($this->__abutton)) return "";
|
||||
$items = count($this->__abutton) - ($this->__bsepa==true ? 1 : 0);
|
||||
$sepa_size = (12 == $items*$size) ? 0 : 12 - ($items*$size);
|
||||
$_out = '<div class="row mb-3">';
|
||||
foreach ($this->__abutton as $item) {
|
||||
if ("separator" == $item['type']) {
|
||||
if (0 < $sepa_size) $_out .= '<div class="d-none d-lg-block col-lg-'.$sepa_size.'"> </div>';
|
||||
} else {
|
||||
$_out .= '<div class="col-md-'.floor($size*2).' col-lg-'.$size.' mb-1 mb-sm-0"><button type="button" class="btn btn-block btn-'.$item['type'].'" id="'.$item['id'].'"'.(true==$item['bmiss']?' data-dismiss="modal"':'').'>'.$item['label'].'</button></div>';
|
||||
}
|
||||
}
|
||||
$_out .= '</div>';
|
||||
return $_out;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Menu.php
|
||||
Desc. : v3 - Class menu
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 16th, 2008.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Menu {
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
}
|
||||
|
||||
private function Menu_Query($qry = "", $order = "Kode") {
|
||||
$twhere = ($qry!="") ? "WHERE ".$qry : "";
|
||||
$this->__db->Query("SELECT * FROM app_menu ".$twhere." ORDER BY ".$order." ASC");
|
||||
$ahasil = array();
|
||||
while ($this->__db->Next()) {
|
||||
$ahasil[] = $this->__db->AllRow();
|
||||
}
|
||||
return $ahasil;
|
||||
}
|
||||
|
||||
public function Menu_Sidebar() {
|
||||
$a_modul = array();
|
||||
$is_modul = (isset($_SESSION['__WEB_APP']['APP_MODULE']) && $_SESSION['__WEB_APP']['APP_MODULE'] <> "") ? true : false;
|
||||
if ($is_modul == true) {
|
||||
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
|
||||
} else {
|
||||
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
|
||||
for ($i=0; $i<count($atmp); $i++) {
|
||||
$a_modul[] = $atmp[$i]['Modul'];
|
||||
}
|
||||
}
|
||||
|
||||
$my_menu = explode(",", (($_SESSION['__WEB_USER']['Menu_Grup'])?$_SESSION['__WEB_USER']['Menu_Grup'].",":"").$_SESSION['__WEB_USER']['Menu']);
|
||||
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
|
||||
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
|
||||
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
|
||||
|
||||
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
|
||||
$thasil = '';
|
||||
|
||||
$last_level = 0; $last_divider = false;
|
||||
for ($i=0; $i<count($amodul); $i++) {
|
||||
if (($i>0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) {
|
||||
$thasil .= str_repeat("</ul></li>", $amodul[$i-1]['Level']-$amodul[$i]['Level']);
|
||||
}
|
||||
if (($amodul[$i]['Level']>=0) && (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level']))) {
|
||||
$ticon = ($amodul[$i]['Icon']) ? $amodul[$i]['Icon'] : "cui-puzzle";
|
||||
$thasil .= '<li class="c-nav-item c-nav-dropdown '.($i==0?'c-open':'').'"><a class="c-nav-link c-nav-dropdown-toggle" title="'.$amodul[$i]['Judul'].'"><i class="c-nav-icon '.$ticon.'"></i> '.$amodul[$i]['Menu'].'</a><ul class="c-nav-dropdown-items">';
|
||||
} else if (trim($amodul[$i]['Menu'])=="-") {
|
||||
$thasil .= '<li class="c-nav-divider"></li>';
|
||||
} else {
|
||||
$thasil .= '<li class="c-nav-item"><a class="c-nav-link mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'"><span class="c-nav-icon"></span> '.$amodul[$i]['Menu'].'</a></li>';
|
||||
}
|
||||
$last_level = $amodul[$i]['Level'];
|
||||
}
|
||||
if ($last_level>1) $thasil .= str_repeat("</ul></li>", $last_level-1);
|
||||
return $thasil;
|
||||
}
|
||||
|
||||
public function Menu_Header() {
|
||||
$a_modul = array();
|
||||
$is_modul = (isset($_SESSION['__WEB_APP']['APP_MODULE']) && $_SESSION['__WEB_APP']['APP_MODULE'] <> "") ? true : false;
|
||||
$mulai_level = 0;
|
||||
if ($is_modul == true) {
|
||||
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
|
||||
$mulai_level = 1;
|
||||
} else {
|
||||
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
|
||||
for ($i=0; $i<count($atmp); $i++) {
|
||||
$a_modul[] = $atmp[$i]['Modul'];
|
||||
}
|
||||
}
|
||||
|
||||
$my_menu = explode(",", (($_SESSION['__WEB_USER']['Menu_Grup'])?$_SESSION['__WEB_USER']['Menu_Grup'].",":"").$_SESSION['__WEB_USER']['Menu']);
|
||||
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
|
||||
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
|
||||
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
|
||||
|
||||
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
|
||||
$thasil = '';
|
||||
|
||||
$last_level = 0;
|
||||
for ($i=0; $i<count($amodul); $i++) {
|
||||
if (($i>0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) {
|
||||
$thasil .= str_repeat("</ul></li>", $amodul[$i-1]['Level']-$amodul[$i]['Level']);
|
||||
}
|
||||
if (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level'])) {
|
||||
if ($amodul[$i]['Level']==$mulai_level) {
|
||||
$ticon = ($amodul[$i]['Icon']) ? " mr-1 ".$amodul[$i]['Icon'] : "";
|
||||
$thasil .= '<li class="c-header-nav-item px-3"><a class="c-header-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="'.$amodul[$i]['Judul'].'"><i class="c-nav-icon'.$ticon.'"></i> '.$amodul[$i]['Menu'].'<b class="caret"></b></a><ul class="dropdown-menu multi-level">';
|
||||
} else if ($amodul[$i]['Level']==($mulai_level+1)) {
|
||||
$thasil .= '<li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle slink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="'.$amodul[$i]['Judul'].'"><i class="c-nav-icon"></i> '.$amodul[$i]['Menu'].'</a><ul class="dropdown-menu">';
|
||||
}
|
||||
} else if (trim($amodul[$i]['Menu'])=="-" && $amodul[$i]['Level']>$mulai_level) {
|
||||
$thasil .= '<li class="dropdown-divider"></li>';
|
||||
} else if ($amodul[$i]['Level']==$mulai_level) {
|
||||
$ticon = ($amodul[$i]['Icon']) ? " mr-1 ".$amodul[$i]['Icon'] : "";
|
||||
$thasil .= '<li class="c-header-nav-item px-3"><a class="c-header-nav-link mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'"><span class="c-nav-icon'.$ticon.'"></span> '.$amodul[$i]['Menu'].'</a></li>';
|
||||
} else {
|
||||
$thasil .= '<li><a class="dropdown-item mlink" data-toggle="collapse" data-target=".dropdown-menu.show" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'">'.$amodul[$i]['Menu'].'</a></li>';
|
||||
}
|
||||
$last_level = $amodul[$i]['Level'];
|
||||
}
|
||||
if ($last_level>$mulai_level) $thasil .= str_repeat("</ul></li>", $last_level-$mulai_level);
|
||||
return $thasil;
|
||||
}
|
||||
|
||||
static function MenuJSON($db = null, $page = "", $tquery = "") {
|
||||
if (is_resource($db)) { $_mdb = $db; }
|
||||
else $_mdb = new \siaupheng\fonia3\DB\MySQL();
|
||||
$_query = ($tquery=="") ? "" : ",'".$tquery."'";
|
||||
$ajson = array('login' => true);
|
||||
$apage = array('Link' => "");
|
||||
|
||||
$acus_page = array(
|
||||
'SYSP' => array('Kode'=>"SYSP", 'Judul'=>"Profil Pengguna", 'Link'=>"sys/profile.php", 'JS'=>"SYSProfileJS", 'Width'=>600, 'Button'=>"_,C,S"),
|
||||
'SYSC' => array('Kode'=>"SYSC", 'Judul'=>"Ubah Password", 'Link'=>"sys/chpasswd.php", 'JS'=>"SYSChpasswdJS", 'Width'=>400, 'Button'=>"_,C,S")
|
||||
);
|
||||
|
||||
if ($acus_page[$page]) {
|
||||
$apage = $acus_page[$page];
|
||||
} else if ($page <> "") {
|
||||
$_mdb->Query("SELECT * FROM app_menu WHERE Kode='".$page."'");
|
||||
if ($_mdb->Next()) $apage = $_mdb->AllRow();
|
||||
}
|
||||
|
||||
$ajson['iswindow'] = ($apage['Width'] > 0) ? true : false;
|
||||
$ajson['width'] = $apage['Width'];
|
||||
$ajson['title'] = $apage['Judul'];
|
||||
$ajson['button'] = $apage['Button'];
|
||||
$ajson['php'] = $apage['Link'];
|
||||
$ajson['func'] = $apage['JS'];
|
||||
$ajson['kode'] = $apage['Kode'];
|
||||
|
||||
if ($ajson['iswindow'] == false) {
|
||||
$tsql = (isset($_SESSION['__WEB_APP']['APP_MODULE']) && $_SESSION['__WEB_APP']['APP_MODULE'] <> "") ? " AND Modul='".$_SESSION['__WEB_APP']['APP_MODULE']."' AND Level>0" : "";
|
||||
$a_bread = array(); $i_level = null;
|
||||
$_mdb->Query("SELECT Kode,Level,Menu FROM app_menu WHERE Kode<='".$page."'".$tsql." ORDER BY Kode DESC");
|
||||
while ($_mdb->Next()) {
|
||||
if ($page == $_mdb->Row("Kode") || $i_level > $_mdb->Row("Level")) {
|
||||
$a_bread[] = $_mdb->Row("Menu");
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$i_level = $_mdb->Row("Level");
|
||||
}
|
||||
$a_bread[] = "Beranda";
|
||||
$ajson['bread'] = $a_bread;
|
||||
}
|
||||
if (!file_exists($_SESSION['__WEB_APP']['REAL_PATH']."apps/php/".$apage['Link'])) $ajson['php'] = "";
|
||||
return $ajson;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Param.php
|
||||
Desc. : Class akses data parameter dari client side
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 14th, 2013.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2013 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Param {
|
||||
private static $__ahasil = array();
|
||||
|
||||
public function __construct() {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
}
|
||||
|
||||
private static function __data() {
|
||||
$_asumber = array_merge($_REQUEST, $_POST, $_GET);
|
||||
foreach ($_asumber as $__key => $__val) {
|
||||
self::$__ahasil[$__key] = self::safeSQL($__val);
|
||||
}
|
||||
}
|
||||
|
||||
public static function safeSQL($tstr = "") {
|
||||
$_se = array("\\","\0","\n","\r","\x1a","'",'"');
|
||||
$_re = array("\\\\","\\0","\\n","\\r","\Z","\'",'\"');
|
||||
return str_replace($_se, $_re, $tstr);
|
||||
}
|
||||
|
||||
public static function Get($tkey = "", $tdef = null) {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
if (isset(self::$__ahasil[$tkey]) && self::$__ahasil[$tkey]) return self::$__ahasil[$tkey];
|
||||
return $tdef;
|
||||
}
|
||||
|
||||
public static function Get_Text($tkey = "", $tdef = null) {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
$_str = (isset(self::$__ahasil[$tkey])) ? self::$__ahasil[$tkey] : $tdef;
|
||||
$_str = str_replace("\\r", "", $_str);
|
||||
$_str = str_replace("\\n", " ", $_str);
|
||||
$_str = str_replace("\\t", " ", $_str);
|
||||
return (trim($_str));
|
||||
}
|
||||
|
||||
public static function Get_Array() {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
return self::$__ahasil;
|
||||
}
|
||||
|
||||
public static function Get_ArrayCBOX() {
|
||||
if (count(self::$__ahasil)==0) self::__data();
|
||||
$_ahasil = array();
|
||||
foreach (self::$__ahasil as $__key => $__val) {
|
||||
if (strpos($__key, "_cbox_")>0) {
|
||||
$_tmpkey = substr($__key, strpos($__key, "_cbox_")+6);
|
||||
$_ahasil[$_tmpkey] = $__val;
|
||||
}
|
||||
}
|
||||
return $_ahasil;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,451 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Print.php
|
||||
Desc. : Fungsi-fungsi pembuatan laporan
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : June 15th, 2008.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Print {
|
||||
private $__avalue = array();
|
||||
private $__astyle = array();
|
||||
private $__atabel = array();
|
||||
private $__css = "pnormal";
|
||||
|
||||
public function __construct() {//
|
||||
}
|
||||
|
||||
public function set_css($style = "") {//
|
||||
if ($style=="") return;
|
||||
$this->__css = $style;
|
||||
}
|
||||
|
||||
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="", $nkol=1) {//up 2012-03-07
|
||||
$this->__atabel[] = array($tnama, $nlebar, $ffunc, $talign, $nkol);
|
||||
}
|
||||
|
||||
public function show_fields() {//
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
if ($this->__atabel[$i][4]==0) continue;
|
||||
$tmp_out .= $this->set_align($this->__atabel[$i][0], $this->__atabel[$i][1], "C", false, true, $this->__atabel[$i][4]);
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
$this->__astyle[] = "L";
|
||||
}
|
||||
|
||||
public function clear() {//
|
||||
$this->__avalue = array();
|
||||
$this->__astyle = array();
|
||||
}
|
||||
|
||||
public function add_value() {//
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0]; //up 2009-09-27
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];
|
||||
if (is_array($this->__atabel[$i][2]) && trim($tmp_val)<>"") { //up 2010-05-28
|
||||
$tmp_val = $this->__atabel[$i][2][$tmp_val];
|
||||
} else if (function_exists($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->__atabel[$i][2], $tmp_val);
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val, $this->__atabel[$i][1], $this->__atabel[$i][3]);
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
$this->__astyle[] = "L";
|
||||
}
|
||||
|
||||
public function add_span() {
|
||||
$tmp_arr = func_get_args();
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($tmp_arr); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];// CONTENT, COLSPAN=1, L, FUNC, EXTRA
|
||||
if (!isset($tmp_val[1])) $tmp_val[1] = 1;
|
||||
if (!isset($tmp_val[2])) $tmp_val[2] = "L";
|
||||
if (!isset($tmp_val[4])) $tmp_val[4] = "";
|
||||
if (isset($tmp_val[3])) {
|
||||
if (function_exists($tmp_val[3]) && trim($tmp_val[0])<>"") {
|
||||
$tmp_val[0] = call_user_func($tmp_val[3], $tmp_val[0]);
|
||||
}
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val[0], 0, $tmp_val[2], false, false, $tmp_val[1], $tmp_val[4]);
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
$this->__astyle[] = "L";
|
||||
}
|
||||
|
||||
public function add($ttext = "", $tstyle = "L") {//todo:delete
|
||||
$this->__avalue[] = $ttext;
|
||||
$this->__astyle[] = $tstyle;
|
||||
}
|
||||
|
||||
public function addl($ttext = "") {//todo:delete
|
||||
$this->add($ttext);
|
||||
}
|
||||
|
||||
public function addr($ttext = "") {//todo:delete
|
||||
$this->add($ttext, "R");
|
||||
}
|
||||
|
||||
public function addc($ttext = "") {//todo:delete
|
||||
$this->add($ttext, "C");
|
||||
}
|
||||
|
||||
public function add_line() {//todo:delete
|
||||
$this->add("__LINE ");
|
||||
}
|
||||
|
||||
public function add_empty($nrep = 1) {//todo:delete
|
||||
for ($i=0;$i<$nrep;$i++) $this->add(" ");
|
||||
}
|
||||
|
||||
public function add_pagebreak() {//up 2012-10-11
|
||||
$this->add("</tbody></table><p id=\"linebreak\">................ page break ................</p>", "PB");
|
||||
$this->add("<p id=\"pagebreak\"> </p><table class=\"".$this->__css."\" border=\"0\" width=\"100%\" cellspading=\"0\" cellspacing=\"0\"><tbody>", "PB");
|
||||
}
|
||||
|
||||
public function show_pagebreak() {//del
|
||||
echo "<p id=\"linebreak\">................ page break ................</p><p id=\"pagebreak\"> </p>";
|
||||
}
|
||||
|
||||
public function add_stamp($ctk_ke=1, $bnama=false) {//up 2011-03-25
|
||||
$this->add($_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):""), "NB");
|
||||
}
|
||||
|
||||
public function get_stamp($ctk_ke=1, $bnama=false) {//up 2012-10-11
|
||||
return $_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):"");
|
||||
}
|
||||
|
||||
public function show($jumlah_ctk=1) {//up 2012-10-11
|
||||
$out = "<p id=\"autopage\"> </p>";
|
||||
$out .= "<table class=\"".$this->__css."\" width=\"100%\"><tbody>";
|
||||
|
||||
// content out
|
||||
for ($i=0; $i<count($this->__avalue); $i++) {
|
||||
$tmp_str = $this->__avalue[$i];
|
||||
if ($this->__astyle[$i]=="PB") {
|
||||
$out .= $tmp_str;
|
||||
continue;
|
||||
}
|
||||
if (strpos($tmp_str, "_LINE")>0) $tmp_str = "<hr />";
|
||||
$out .= $this->set_align($tmp_str, 0, $this->__astyle[$i], true);
|
||||
}
|
||||
$out .= "</tbody></table>";
|
||||
|
||||
for ($i=1; $i<=$jumlah_ctk; $i++) echo $out;
|
||||
}
|
||||
|
||||
public function set_align($ttext, $nlen, $tdir="L", $bline=false, $bhead=false, $ncol=1, $textra="") {//up 2011-04-14
|
||||
$tstyle = $this->create_style($tdir);
|
||||
if (strpos(strtolower($ttext), "<tr>")===false) { //jika tidak ada <tr> up 2011-04-14
|
||||
if ($bline===true) {
|
||||
return "<tr><td colspan=\"".count($this->__atabel)."\" class=\"".$tstyle." ".$textra."\">".$ttext."</td></tr>";
|
||||
} else {
|
||||
return (($bhead===true)?"<th":"<td").(($ncol>1)?" colspan=\"".$ncol."\"":"")." class=\"".$tstyle." ".$textra."\" ".(($bhead===true)?"width=\"".$nlen."\"":"").">".$ttext.(($bhead===true)?"</th>":"</td>");
|
||||
}
|
||||
} else {
|
||||
return (($bline===true) ? $ttext : (($bhead===true)?"<th":"<td").(($ncol>1)?" colspan=\"".$ncol."\"":"")." class=\"".$tstyle." ".$textra."\" ".(($bhead===true)?"width=\"".$nlen."\"":"").">".$ttext.(($bhead===true)?"</th>":"</td>"));
|
||||
}
|
||||
}
|
||||
|
||||
private function create_style($tstyle="L") { //up 2014-10-12
|
||||
// style = Left Right Center No-Border No-Left No-Right Bold Italic
|
||||
$apad = array("L"=>"left", "R"=>"right", "C"=>"center", "NB"=>"nb", "NL"=>"noleft", "NR"=>"noright", "B"=>"bold", "I"=>"italic");
|
||||
$_astyle = explode(",", $tstyle);
|
||||
$thasil = "";
|
||||
foreach ($_astyle as $_key => $_val) {
|
||||
$thasil .= " ".$apad[$_val];
|
||||
}
|
||||
return substr($thasil,1);
|
||||
}
|
||||
}
|
||||
|
||||
class RawPrint {
|
||||
private $_header = array();
|
||||
private $_avalue = array();
|
||||
private $_atabel = array();
|
||||
private $_ncont = 0;
|
||||
private $_maxchr = 40;
|
||||
private $_spacekol = " ";
|
||||
private $_config = array(
|
||||
'fontsize' => "01",
|
||||
'nvlogo' => false,
|
||||
'opendraw' => false,
|
||||
'opendrawbegin' => false,
|
||||
'cutpaper' => false );
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function set_opendrawer($bbegin = true) {
|
||||
$this->_config['opendraw'] = true;
|
||||
$this->_config['opendrawbegin'] = $bbegin;
|
||||
}
|
||||
|
||||
public function set_cutpaper() {
|
||||
$this->_config['cutpaper'] = true;
|
||||
}
|
||||
|
||||
public function set_maxchr($nmax = 0) {//up: 2015-03-22
|
||||
if ($nmax > 0) $this->_maxchr = $nmax;
|
||||
}
|
||||
|
||||
public function set_fontsize($nsize = 1) {//up: 2015-09-30
|
||||
if ($nsize > 0) $this->_config['fontsize'] = str_pad($nsize, 2, "0", STR_PAD_LEFT);
|
||||
|
||||
}
|
||||
|
||||
public function set_printnv_logo() {//up: 2015-03-23
|
||||
$this->_config['nvlogo'] = true;
|
||||
}
|
||||
|
||||
public function add_header($nvlogo = false, $extra = array()) {//up: 2016-11-12
|
||||
$this->_config['nvlogo'] = $nvlogo;
|
||||
$this->_header[] = $_SESSION['__WEB_APP']['REG_NAME'];
|
||||
if (count($extra) > 0) {
|
||||
foreach ($extra as $_val) {
|
||||
$this->_header[] = $_val;
|
||||
}
|
||||
}
|
||||
$this->_header[] = $_SESSION['__WEB_APP']['REG_CITY'];
|
||||
}
|
||||
|
||||
public function add_sheet() {//up: 20170321
|
||||
$this->_ncont++;
|
||||
}
|
||||
|
||||
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="") {
|
||||
$this->_atabel[] = array($tnama, $nlebar, $ffunc, $talign);
|
||||
}
|
||||
|
||||
public function show_fields() {
|
||||
$tmp_out = "<b>";
|
||||
for ($i=0; $i<count($this->_atabel); $i++) {
|
||||
$tmp_out .= $this->set_align($this->_atabel[$i][0], $this->_atabel[$i][1], "C");
|
||||
if ($i < (count($this->_atabel)-1)) $tmp_out .= $this->_spacekol;
|
||||
}
|
||||
$tmp_out .= "</b>";
|
||||
$this->_avalue[$this->_ncont][] = "__LINE -";
|
||||
$this->_avalue[$this->_ncont][] = $tmp_out;
|
||||
$this->_avalue[$this->_ncont][] = "__LINE -";
|
||||
}
|
||||
|
||||
public function add_value() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0]; //up 2009-09-27
|
||||
$tmp_out = "";
|
||||
for ($i=0; $i<count($this->_atabel); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];
|
||||
if (is_array($this->_atabel[$i][2]) && trim($tmp_val)<>"") { //up 2010-05-28
|
||||
$tmp_val = $this->_atabel[$i][2][$tmp_val];
|
||||
} else if (function_exists($this->_atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->_atabel[$i][2], $tmp_val);
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val, $this->_atabel[$i][1], $this->_atabel[$i][3]);
|
||||
if ($i < (count($this->_atabel)-1)) $tmp_val .= $this->_spacekol;
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$this->_avalue[$this->_ncont][] = $tmp_out;
|
||||
}
|
||||
|
||||
public function add($ttext = "") {
|
||||
$this->_avalue[$this->_ncont][] = $ttext;
|
||||
}
|
||||
|
||||
public function add_line($tmp = "-") {
|
||||
$this->add("__LINE ".$tmp);
|
||||
}
|
||||
|
||||
public function add_empty($nrep = 1) {
|
||||
for ($i=0;$i<$nrep;$i++) $this->add("");
|
||||
}
|
||||
|
||||
public function add_stamp($ctk_ke=1, $bnama=false) {
|
||||
$this->add($_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):""));
|
||||
}
|
||||
|
||||
private function _json_out() {//up: 2016-11-12
|
||||
$acontent = array();
|
||||
$nmax = $this->_maxchr;
|
||||
|
||||
for ($s=0; $s<count($this->_avalue); $s++) {
|
||||
for ($i=0; $i<count($this->_avalue[$s]); $i++) {
|
||||
$tmp_str = $this->_avalue[$s][$i];
|
||||
if (strpos($tmp_str, "_LINE")>0) {
|
||||
$tmp_arr = explode(" ", $tmp_str);
|
||||
$tmp_str = str_pad($tmp_arr[1], $nmax, $tmp_arr[1]);
|
||||
}
|
||||
$acontent[$s][] = $tmp_str;
|
||||
}
|
||||
}
|
||||
|
||||
$aout = array('type' => "escp");
|
||||
$aout['config'] = $this->_config;
|
||||
$aout['header'] = $this->_header;
|
||||
$aout['content'] = $acontent;
|
||||
send_json($aout);
|
||||
}
|
||||
|
||||
public function show($jumlah_ctk=1) {
|
||||
$this->_config['times'] = $jumlah_ctk;
|
||||
$this->_json_out();
|
||||
}
|
||||
|
||||
public function set_align($ttext, $nlen, $tdir="L") {
|
||||
$apad = array("L"=>STR_PAD_RIGHT, "R"=>STR_PAD_LEFT, "C"=>STR_PAD_BOTH);
|
||||
$ttext = (strlen($ttext)>$nlen) ? substr($ttext, 0, $nlen) : $ttext;
|
||||
return str_pad($ttext, $nlen, " ", $apad[$tdir]);
|
||||
}
|
||||
}
|
||||
|
||||
/* VERSI BARU DENGAN MULTI SHEET */
|
||||
class POSPrint {//up: 20180108
|
||||
private $_header = array();
|
||||
private $_avalue = array();
|
||||
private $_astyle = array();
|
||||
private $_ncont = 0;
|
||||
private $_maxchr = 40;
|
||||
private $_config = array(
|
||||
'fontsize' => 1,
|
||||
'nvlogo' => false,
|
||||
'opendraw' => false,
|
||||
'opendrawbegin' => true,
|
||||
'cutpaper' => false,
|
||||
'logo' => null );
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function set_opendrawer($bbegin = true) {
|
||||
$this->_config['opendraw'] = true;
|
||||
$this->_config['opendrawbegin'] = $bbegin;
|
||||
}
|
||||
|
||||
public function set_cutpaper() {
|
||||
$this->_config['cutpaper'] = true;
|
||||
}
|
||||
|
||||
public function set_maxchr($nmax = 0) {//up: 2015-03-22
|
||||
if ($nmax > 0) $this->_maxchr = $nmax;
|
||||
}
|
||||
|
||||
public function set_fontsize($nsize = 1) {//up: 2015-09-30
|
||||
if ($nsize > 0) $this->_config['fontsize'] = $nsize;
|
||||
}
|
||||
|
||||
public function set_printnv_logo() {//up: 2015-03-23
|
||||
$this->_config['nvlogo'] = true;
|
||||
}
|
||||
|
||||
public function set_header_logo($logo_file = "") {//up: 2019-01-08
|
||||
if ($logo_file=="") return;
|
||||
if (file_exists($_SESSION['__WEB_APP']['REAL_PATH']."assets/images/".$logo_file)) {
|
||||
$this->_config['logo'] = $_SESSION['__WEB_APP']['WEB_PATH']."assets/images/".$logo_file;
|
||||
}
|
||||
}
|
||||
|
||||
public function add_header($nvlogo = false, $extra = array()) {//up: 2018-12-25
|
||||
$this->_config['nvlogo'] = $nvlogo;
|
||||
if ($nvlogo==false && $this->_config['logo']==null) $this->_header[] = $_SESSION['__WEB_APP']['REG_NAME'];
|
||||
if (count($extra) > 0) {
|
||||
foreach ($extra as $_val) {
|
||||
$this->_header[] = $_val;
|
||||
}
|
||||
}
|
||||
$this->_header[] = $_SESSION['__WEB_APP']['REG_CITY'];
|
||||
}
|
||||
|
||||
public function add_sheet() {//up: 20170321
|
||||
$this->_ncont++;
|
||||
}
|
||||
|
||||
public function add() {//up: 20180524
|
||||
$val_arr = func_get_args(); $ttext = ""; $tstyle = "L";
|
||||
if (is_array($val_arr[0])) {
|
||||
foreach($val_arr as $aval) {
|
||||
$ttext .= $this->set_align((isset($aval[0])?$aval[0]:""), (isset($aval[1])?$aval[1]:0), (isset($aval[2])?$aval[2]:$tstyle));
|
||||
}
|
||||
} else {
|
||||
$ttext = (isset($val_arr[0])) ? $val_arr[0] : "";
|
||||
$tstyle = (isset($val_arr[1])) ? $val_arr[1] : $tstyle;
|
||||
}
|
||||
$this->_avalue[$this->_ncont][] = $ttext;
|
||||
$this->_astyle[$this->_ncont][] = $tstyle;
|
||||
}
|
||||
|
||||
public function addl($ttext = "") {
|
||||
$this->add($ttext);
|
||||
}
|
||||
|
||||
public function addr($ttext = "") {
|
||||
$this->add($ttext, "R");
|
||||
}
|
||||
|
||||
public function addc($ttext = "") {
|
||||
$this->add($ttext, "C");
|
||||
}
|
||||
|
||||
public function add_line($tmp = "-") {
|
||||
$this->add("__LINE ".$tmp);
|
||||
}
|
||||
|
||||
public function add_empty($nrep = 1) {
|
||||
for ($i=0;$i<$nrep;$i++) $this->add("");
|
||||
}
|
||||
|
||||
public function add_stamp($ctk_ke=1, $bnama=false) {
|
||||
$this->add($_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):""));
|
||||
}
|
||||
|
||||
private function _json_out() {//up: 2016-11-12
|
||||
$acontent = array();
|
||||
$nmax = $this->_maxchr;
|
||||
|
||||
for ($s=0; $s<count($this->_avalue); $s++) {
|
||||
for ($i=0; $i<count($this->_avalue[$s]); $i++) {
|
||||
$tmp_str = $this->_avalue[$s][$i];
|
||||
if (strpos($tmp_str, "_LINE")>0) {
|
||||
$tmp_arr = explode(" ", $tmp_str);
|
||||
$tmp_str = str_pad($tmp_arr[1], $nmax, $tmp_arr[1]);
|
||||
}
|
||||
$acontent[$s][] = ($this->_astyle[$s][$i]=="X") ? $tmp_str : $this->set_align($tmp_str, $nmax, $this->_astyle[$s][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$aout = array('type' => "escp");
|
||||
$aout['config'] = $this->_config;
|
||||
$aout['header'] = $this->_header;
|
||||
$aout['content'] = $acontent;
|
||||
send_json($aout);
|
||||
}
|
||||
|
||||
public function show($jumlah_ctk=1) {
|
||||
$this->_config['times'] = $jumlah_ctk;
|
||||
$this->_json_out();
|
||||
}
|
||||
|
||||
public function set_align($ttext, $nlen=0, $tdir="L") {//up: 20180524
|
||||
$apad = array("L"=>STR_PAD_RIGHT, "R"=>STR_PAD_LEFT, "C"=>STR_PAD_BOTH);
|
||||
$nlen = ($nlen==0) ? strlen($ttext) : $nlen;
|
||||
$ttext = (strlen($ttext)>$nlen) ? substr($ttext, 0, $nlen) : $ttext;
|
||||
return str_pad($ttext, $nlen, " ", $apad[$tdir]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Register.php
|
||||
Desc. : v3 - Class Registrasi Aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23th, 2011.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Register {
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
}
|
||||
|
||||
static public function reg_id() {
|
||||
$id = $_SESSION['__WEB_APP']['REG_ID'];
|
||||
return (substr($id,0,3).".".substr($id,3,3).".".substr($id,6));
|
||||
}
|
||||
|
||||
static public function reg_code() {
|
||||
$id = $_SESSION['__WEB_APP']['REG_CODE'];
|
||||
return (substr($id,0,6)."-".substr($id,6,5)."-".substr($id,11,5)."-".substr($id,16,5)."-".substr($id,21,5)."-".substr($id,26,6));
|
||||
}
|
||||
|
||||
public function reg_check() {
|
||||
$isreg = false;
|
||||
$this->__db->Query("SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1)) KODE_REGISTER FROM app_config WHERE REG_ID='".$_SESSION['__WEB_APP']['APP_CODE']."' LIMIT 1");
|
||||
if ($this->__db->Next()) {
|
||||
if ($this->__db->Row("KODE_REGISTER","")==$_SESSION['__WEB_APP']['REG_CODE']) $isreg = true;
|
||||
}
|
||||
return $isreg;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Table.php
|
||||
Desc. : v3 - HTML Table v3 (jQuery & CoreUI)
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : January 16th, 2008.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Table {
|
||||
private $__tquery = "";
|
||||
private $__tquery_footer = "";
|
||||
private $__aheader = array();
|
||||
private $__afield = array();
|
||||
private $__astyle = array();
|
||||
private $__aformat = array();
|
||||
private $__afooter = array();
|
||||
private $__arowcol = array();
|
||||
private $__arow_func = array();
|
||||
private $__tfunc_select = "";
|
||||
private $__tfunc_navi = "";
|
||||
private $__btxtbutton = false;
|
||||
private $__bnobutton = false;
|
||||
private $__bscrollbar = false;
|
||||
private $__acontrol = array('field'=>false, 'value'=>"");
|
||||
private $__acbox = array();
|
||||
private $__aoption = array();
|
||||
private $__npage_rec = 10; //baris per halaman
|
||||
private $__nreclimit = 0;
|
||||
private $__nscrollheight = 0;
|
||||
private $__ord_field = "";
|
||||
private $__ord_dir = "A";
|
||||
private $__tcss = "";
|
||||
protected $__cdb = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__cdb = $db; }
|
||||
else $this->__cdb = new \siaupheng\fonia3\DB\MySQL();
|
||||
}
|
||||
|
||||
public function set_query($tquery = "") {
|
||||
$this->__tquery = $tquery;
|
||||
}
|
||||
|
||||
public function set_query_footer($tquery = "") {
|
||||
$this->__tquery_footer = $tquery;
|
||||
}
|
||||
|
||||
public function set_css($tcss = "") {
|
||||
$this->__tcss = $tcss;
|
||||
}
|
||||
|
||||
public function set_limit($nlimit = 0) {
|
||||
$this->__nreclimit = $nlimit;
|
||||
}
|
||||
|
||||
public function set_field_order($tfield = "", $torder = "A") {
|
||||
$this->__ord_field = $tfield;
|
||||
$this->__ord_dir = $torder;
|
||||
}
|
||||
|
||||
public function set_textbtn($bistxt = true) {
|
||||
$this->__btxtbutton = $bistxt;
|
||||
}
|
||||
|
||||
public function set_scrollbar($bisscroll = true, $nheight = 200) {
|
||||
$this->__bscrollbar = $bisscroll;
|
||||
$this->__nscrollheight = $nheight;
|
||||
}
|
||||
|
||||
public function set_row_color($tfield = "", $tval = "", $tcss = "") {
|
||||
if ($tfield=="") return;
|
||||
$this->__arowcol[] = array('F'=>$tfield, 'V'=>$tval, 'C'=>$tcss);
|
||||
}
|
||||
|
||||
public function set_func_navi($tfunc = "") {
|
||||
$this->__tfunc_navi = $tfunc;
|
||||
}
|
||||
|
||||
public function set_func_select($tfunc = "") {
|
||||
$this->__tfunc_select = $tfunc;
|
||||
}
|
||||
|
||||
public function set_func_btn($tfunc = "", $tlabel = "") {
|
||||
$this->__arow_func[] = array('label' => $tlabel, 'func' => $tfunc);
|
||||
}
|
||||
|
||||
public function set_row_control($tfield = "", $tvalue = "Y") {
|
||||
$this->__acontrol['field'] = $tfield;
|
||||
$this->__acontrol['value'] = $tvalue;
|
||||
}
|
||||
|
||||
public function add_row_btn($ticon = "", $tlabel = "", $tfunc = "", $tfield = "", $tvalue = "") {
|
||||
$this->__aoption[] = array('type' => "button", 'func' => $tfunc, 'icon' => $ticon, 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue);
|
||||
}
|
||||
|
||||
public function add_row_del($tlabel = "", $tfunc = "", $tfield = "Unix", $tvalue = "") {
|
||||
$this->__aoption[] = array('type' => "button", 'func' => $tfunc, 'icon' => "x", 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue);
|
||||
}
|
||||
|
||||
public function add_row_edit($tlabel = "", $tfunc = "") {
|
||||
$this->add_row_btn("note", $tlabel, $tfunc);
|
||||
}
|
||||
|
||||
public function add_row_checkbox($tfield = "ID", $tcontrol = "Edit", $avalue = array("Y","N")) {
|
||||
$this->__acbox['field'] = $tfield;
|
||||
$this->__acbox['control'] = $tcontrol;
|
||||
$this->__acbox['avalue'] = $avalue;
|
||||
$this->__aoption[] = array('type' => "checkbox", 'field' => $tfield, 'avalue' => $avalue);
|
||||
}
|
||||
|
||||
public function no_button() {
|
||||
$this->__bnobutton = true;
|
||||
}
|
||||
|
||||
public function add_field($tfield = "", $theader = "", $tstyle = "left", $tformat = "", $tfooter = "") {
|
||||
$this->__aheader[] = $theader;
|
||||
$this->__afield[] = $tfield;
|
||||
$this->__astyle[] = $tstyle;
|
||||
$this->__aformat[] = $tformat;
|
||||
$this->__afooter[] = $tfooter;
|
||||
}
|
||||
|
||||
public function json_table($nama_tabel = "tabel_", $baris_tabel = 10) {
|
||||
$adata = array();
|
||||
$dbpage = intval(\siaupheng\fonia3\Web\Param::Get($nama_tabel.'_pg', 0));
|
||||
|
||||
// adding header
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$adata['header'][] = array('f'=>$this->__astyle[$i], 'o'=>$this->__afield[$i], 'c'=>$this->__aheader[$i]);//add width later
|
||||
$njml_kol += ($this->__astyle[$i]=="hidden") ? 0 : 1;
|
||||
}
|
||||
|
||||
// adding footer
|
||||
if ($this->__tquery_footer) {
|
||||
$this->__cdb->Query($this->__tquery_footer);
|
||||
$this->__cdb->Next();
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tval = $this->__cdb->Row($this->__afield[$i], 0);
|
||||
if (is_array($this->__afooter[$i])) {
|
||||
$tval2 = $this->__afooter[$i][$tval];
|
||||
} else if (function_exists($this->__afooter[$i])) {
|
||||
$tval2 = call_user_func($this->__afooter[$i], $tval);
|
||||
} else {
|
||||
$tval2 = ($this->__afooter[$i]<>"") ? $this->__afooter[$i] : $tval;
|
||||
}
|
||||
$adata['footer'][] = array('c'=>$tval2);
|
||||
}
|
||||
}
|
||||
|
||||
$acontent = array();
|
||||
$this->__cdb->Query($this->__tquery);
|
||||
while ($this->__cdb->Next()) {
|
||||
$abaris = array();
|
||||
$aoption = array('button'=>array());
|
||||
if (count($this->__aoption)>0) {
|
||||
if ((($this->__acontrol['field']===false) || ($this->__cdb->Row($this->__acontrol['field'])==$this->__acontrol['value'])) && $this->__bnobutton===false) {
|
||||
// adding all option
|
||||
for ($i=0; $i<count($this->__aoption); $i++) {
|
||||
if ($this->__aoption[$i]['type']=="button") {
|
||||
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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// adding checkbox option
|
||||
if (array_key_exists("field", $this->__acbox)) {
|
||||
$aoption['checkbox']['field'] = $this->__cdb->Row($this->__acbox['field']);
|
||||
$aoption['checkbox']['value'] = $this->__cdb->Row($this->__acbox['control']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($this->__arowcol)>0) {//up: 2014-06-13
|
||||
for ($i=0; $i<count($this->__arowcol); $i++) {
|
||||
if ($this->__cdb->Row($this->__arowcol[$i]['F']) == $this->__arowcol[$i]['V']) $aoption['rowcss'] = $this->__arowcol[$i]['C'];
|
||||
}
|
||||
}
|
||||
$abaris[] = $aoption;
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tval = stripslashes($this->__cdb->Row($this->__afield[$i]));//up: 2015-01-05
|
||||
if (is_array($this->__aformat[$i])) {
|
||||
$tval = $this->__aformat[$i][$tval];
|
||||
} else if (function_exists($this->__aformat[$i])) {
|
||||
$tval = call_user_func($this->__aformat[$i], $tval);
|
||||
}
|
||||
$abaris[] = $tval;
|
||||
}
|
||||
$acontent[] = $abaris;
|
||||
}
|
||||
|
||||
// navigator
|
||||
$anavi = array('func_navi' => $this->__tfunc_navi, 'button' => $this->__arow_func );
|
||||
|
||||
$adata['type'] = "table";
|
||||
$adata['id'] = $nama_tabel;
|
||||
$adata['config'] = array('css' => $this->__tcss, 'page' => $dbpage, '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);
|
||||
$adata['option'] = $this->__aoption;
|
||||
$adata['navi'] = $anavi;
|
||||
$adata['content'] = $acontent;
|
||||
return $adata;
|
||||
}
|
||||
|
||||
public function json_table_db($nama_tabel = "tabel_", $baris_tabel = 10) {//new
|
||||
$adata = array();
|
||||
$dbpage = \siaupheng\fonia3\Web\Param::Get($nama_tabel.'_pg', 0);
|
||||
|
||||
// adding header
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$adata['header'][] = array('f'=>$this->__astyle[$i], 'o'=>$this->__afield[$i], 'c'=>$this->__aheader[$i]);//add width later
|
||||
$njml_kol += ($this->__astyle[$i]=="hidden") ? 0 : 1;
|
||||
}
|
||||
|
||||
// adding footer
|
||||
if ($this->__tquery_footer) {
|
||||
$this->__cdb->Query($this->__tquery_footer);
|
||||
$this->__cdb->Next();
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tval = $this->__cdb->Row($this->__afield[$i], 0);
|
||||
if (is_array($this->__afooter[$i])) {
|
||||
$tval2 = $this->__afooter[$i][$tval];
|
||||
} else if (function_exists($this->__afooter[$i])) {
|
||||
$tval2 = call_user_func($this->__afooter[$i], $tval);
|
||||
} else {
|
||||
$tval2 = ($this->__afooter[$i]<>"") ? $this->__afooter[$i] : $tval;
|
||||
}
|
||||
$adata['footer'][] = array('c'=>$tval2);
|
||||
}
|
||||
}
|
||||
|
||||
$acontent = array();
|
||||
$this->__cdb->Query($this->__tquery);
|
||||
while ($this->__cdb->Next()) {
|
||||
$abaris = array();
|
||||
$aoption = array('button'=>array());
|
||||
if (count($this->__aoption)>0) {
|
||||
if ((($this->__acontrol['field']===false) || ($this->__cdb->Row($this->__acontrol['field'])==$this->__acontrol['value'])) && $this->__bnobutton===false) {
|
||||
// adding all option
|
||||
for ($i=0; $i<count($this->__aoption); $i++) {
|
||||
if ($this->__aoption[$i]['type']=="button") {
|
||||
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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// adding checkbox option
|
||||
if (array_key_exists("field", $this->__acbox)) {
|
||||
$aoption['checkbox']['field'] = $this->__cdb->Row($this->__acbox['field']);
|
||||
$aoption['checkbox']['value'] = $this->__cdb->Row($this->__acbox['control']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($this->__arowcol)>0) {//up: 2014-06-13
|
||||
for ($i=0; $i<count($this->__arowcol); $i++) {
|
||||
if ($this->__cdb->Row($this->__arowcol[$i]['F']) == $this->__arowcol[$i]['V']) $aoption['rowcss'] = $this->__arowcol[$i]['C'];
|
||||
}
|
||||
}
|
||||
$abaris[] = $aoption;
|
||||
for ($i=0; $i<count($this->__afield); $i++) {
|
||||
$tval = stripslashes($this->__cdb->Row($this->__afield[$i]));//up: 2015-01-05
|
||||
if (is_array($this->__aformat[$i])) {
|
||||
$tval = $this->__aformat[$i][$tval];
|
||||
} else if (function_exists($this->__aformat[$i])) {
|
||||
$tval = call_user_func($this->__aformat[$i], $tval);
|
||||
}
|
||||
$abaris[] = $tval;
|
||||
}
|
||||
$acontent[] = $abaris;
|
||||
}
|
||||
|
||||
// navigator
|
||||
$anavi = array('func_navi' => $this->__tfunc_navi, 'button' => $this->__arow_func );
|
||||
|
||||
$adata['type'] = "table";
|
||||
$adata['id'] = $nama_tabel;
|
||||
$adata['config'] = array('page'=>$dbpage, '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);
|
||||
$adata['option'] = $this->__aoption;
|
||||
$adata['navi'] = $anavi;
|
||||
$adata['content'] = $acontent;
|
||||
return $adata;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Terbilang.php
|
||||
Desc. : Class Format Angka & Terbilang
|
||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||
Created Date : February 12th, 2009.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2009 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Terbilang {
|
||||
private $numb = array("","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan");
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function Terbilang($nilai=0, $muang="Rupiah") {
|
||||
$number = 0;
|
||||
$hasil = "";
|
||||
$int = trim($nilai);
|
||||
if (is_int(strpos($int,"-"))) {
|
||||
$number = substr($int,strpos($int,"-")+1,strlen($int));
|
||||
$hasil = "Minus";
|
||||
} else {
|
||||
$number = $int;
|
||||
}
|
||||
|
||||
# strpost : untuk mencari "." pada variabel number
|
||||
$xpos = strpos($number,".");
|
||||
if (is_int($xpos)) {
|
||||
# round : Untuk pembulatan angka desimal, strlen : untuk menghitung jumlah karakter
|
||||
$pecahan = round(substr($number,$xpos,strlen($number)),2);
|
||||
$last = substr($number,0,$xpos);
|
||||
} else {
|
||||
$pecahan = "";
|
||||
$last = $number;
|
||||
}
|
||||
if ($last==0 || $number==0) {
|
||||
return $hasil."NOL ".$muang;
|
||||
} else {
|
||||
# floor : Pembulatan angka terbaik dari desimal, pow : Ekspresi Eksponensial
|
||||
$triliun = floor($last/pow(10,12));
|
||||
$last = $this->mod($last,1000000000000);
|
||||
|
||||
$miliar = floor($last/pow(10,9));
|
||||
$last = $this->mod($last,1000000000);
|
||||
|
||||
$juta = floor($last/pow(10,6));
|
||||
$last = $this->mod($last,1000000);
|
||||
|
||||
$ribu = floor($last/pow(10,3));
|
||||
$last = $this->mod($last,1000);
|
||||
|
||||
$kata = $this->tigadigit($triliun, "Triliun");
|
||||
$kata .= $this->tigadigit($miliar, "Miliar");
|
||||
$kata .= $this->tigadigit($juta, "Juta");
|
||||
$kata .= $this->tigadigit($ribu, "Ribu");
|
||||
$kata .= $this->tigadigit($last, "");
|
||||
$kata .= " ".$muang;
|
||||
}
|
||||
if ($pecahan>0) {
|
||||
$kata .= " Dan". $this->tigadigit(round($pecahan*100),"Sen");
|
||||
}
|
||||
return $hasil . $kata;
|
||||
}
|
||||
|
||||
private function mod($a, $b) {
|
||||
return $a-$b*floor($a/$b);
|
||||
}
|
||||
|
||||
private function tigadigit($amount, $suffix="") {
|
||||
$last = (int) $amount;
|
||||
$kata = "";
|
||||
if ($last == 1 && $suffix=="Ribu") {
|
||||
$kata = " Seribu";
|
||||
return $kata;
|
||||
}
|
||||
if ($last < 20 && $last > 10) {
|
||||
if ($last==11) {
|
||||
$kata = " Sebelas";
|
||||
} else {
|
||||
$kata = " ".$this->numb[$last-10]." Belas";
|
||||
}
|
||||
if ($suffix != "") {
|
||||
$kata .= " ". $suffix;
|
||||
}
|
||||
return $kata;
|
||||
}
|
||||
$ratus = floor($last/100);
|
||||
if ($ratus <= 0) {
|
||||
$kata .= "";
|
||||
} elseif ($ratus == 1) {
|
||||
$kata .= " Seratus";
|
||||
} else {
|
||||
$kata .= " ".$this->numb[$ratus]." Ratus";
|
||||
}
|
||||
$last = $this->mod($last,100);
|
||||
if ($last < 20 && $last > 10) {
|
||||
if ($last == 11) {
|
||||
$kata .= " Sebelas ". $suffix;
|
||||
} else {
|
||||
$kata .= " ".$this->numb[$last-10]." Belas ". $suffix;
|
||||
}
|
||||
return $kata;
|
||||
}
|
||||
$puluh = floor($last/10);
|
||||
if ($puluh == 0) {
|
||||
$kata .= "";
|
||||
} elseif ($puluh == 1) {
|
||||
$kata .= " Sepuluh";
|
||||
} else {
|
||||
$kata .= " ".$this->numb[$puluh]." Puluh";
|
||||
}
|
||||
$last = $this->mod($last,10);
|
||||
if ($last>0 && $last<=9) {
|
||||
$kata .= " ".$this->numb[$last];
|
||||
}
|
||||
if ($amount>0 && $amount<=1000) {
|
||||
$kata .= " ".$suffix;
|
||||
}
|
||||
return $kata;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Web/Update.php
|
||||
Desc. : Class Update Aplikasi Otomatis
|
||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||
Created Date : June 14th, 2013.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2013 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Web;
|
||||
|
||||
final class Update {
|
||||
private $__amysql = array();
|
||||
protected $__linkdb = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__linkdb = $db; }
|
||||
else $this->__linkdb = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$this->__amysql = $this->__linkdb->getConfig();
|
||||
}
|
||||
|
||||
public function check_update() {
|
||||
$_ainfo['build_cur'] = $_SESSION['__WEB_APP']['APP_BUILD'];
|
||||
$_ainfo['svr_status'] = "Server Online";
|
||||
$_read = array("","","");
|
||||
|
||||
$_url = "https://update.3fonia.com/".$_SESSION['__WEB_APP']['REG_ID']."/update.csv";
|
||||
$_fp = @fopen ($_url, 'r') or $_ainfo['svr_status'] = "Server Offline";
|
||||
if ($_fp) {
|
||||
$_read = fgetcsv ($_fp);
|
||||
fclose ($_fp);
|
||||
}
|
||||
|
||||
$_ainfo['build_new'] = $_read[0];
|
||||
$_ainfo['file_web'] = $_read[1];
|
||||
$_ainfo['file_sql'] = $_read[2];
|
||||
return $_ainfo;
|
||||
}
|
||||
|
||||
public function go_update($file_src="", $build_code="") {
|
||||
if ($file_src=="") return false;
|
||||
|
||||
$_folder = $_SESSION['__WEB_APP']['REAL_PATH']."temp";
|
||||
if (!is_dir($_folder)) mkdir($_folder);
|
||||
|
||||
$_dst = $_folder."/update.web.zip";
|
||||
if ($_dst) unlink($_dst);
|
||||
|
||||
$new_data = file_get_contents($file_src);
|
||||
if (!$new_data) return false;
|
||||
|
||||
$han_file = @fopen($_dst, 'w');
|
||||
if (!$han_file) return false;
|
||||
|
||||
if ( fwrite($han_file, $new_data) ) {
|
||||
fclose($han_file);
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($_dst) === true) {
|
||||
$zip->extractTo($_SESSION['__WEB_APP']['REAL_PATH']);
|
||||
$zip->close();
|
||||
$_SESSION['__WEB_APP']['APP_BUILD'] = $build_code;
|
||||
$this->__linkdb->Query("UPDATE app_config SET APP_BUILD='".$build_code."' WHERE REG_ID='".$_SESSION['__WEB_APP']['APP_CODE']."' LIMIT 1");
|
||||
}
|
||||
}
|
||||
if (file_exists($_dst)) unlink($_dst);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update_mysql($file_sql="") {
|
||||
if ($file_sql=="") return false;
|
||||
|
||||
$_folder = $_SESSION['__WEB_APP']['REAL_PATH']."temp";
|
||||
if (!is_dir($_folder)) mkdir($_folder);
|
||||
|
||||
$_dst = $_folder."/update.sql.zip";
|
||||
if ($_dst) unlink($_dst);
|
||||
|
||||
$new_data = file_get_contents($file_sql);
|
||||
if (!$new_data) return false;
|
||||
|
||||
$han_file = @fopen($_dst, 'w');
|
||||
if (!$han_file) return false;
|
||||
|
||||
if ( fwrite($han_file, $new_data) ) {
|
||||
fclose($han_file);
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($_dst) === true) {
|
||||
$zip->extractTo($_folder);
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
if (file_exists($_dst)) unlink($_dst);
|
||||
if (!is_readable($_folder."/update.sql")) return false;
|
||||
|
||||
$_link = @new mysqli($this->__amysql['host'], $this->__amysql['user'], $this->__amysql['pwd'], $this->__amysql['db'], $this->__amysql['port'], $this->__amysql['sock']);
|
||||
if (!$_link->connect_error) return false;
|
||||
|
||||
$aSQL = file($_folder."/update.sql");
|
||||
foreach ($aSQL as $stmt) {
|
||||
if ($_link->query($stmt) === false) {
|
||||
$sqlECode = $_link->mysql_errno;
|
||||
$sqlEText = $_link->error;
|
||||
$sqlStmt = $stmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (file_exists($_folder."/update.sql")) unlink($_folder."/update.sql");
|
||||
if ($sqlECode == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
/*echo "FAIL!<br/>";
|
||||
echo "Error code: $sqlErrorCode<br/>";
|
||||
echo "Error text: $sqlErrorText<br/>";
|
||||
echo "Statement:<br/> $sqlStmt<br/>";*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user