You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
276 lines
8.0 KiB
PHP
276 lines
8.0 KiB
PHP
<?php
|
|
|
|
use NN\files;
|
|
use NN\dd;
|
|
use NN\Post;
|
|
use NN\Session;
|
|
use NN\Module\DB;
|
|
use NN\Module\Help;
|
|
use NN\Link;
|
|
use NN\Enc;
|
|
use NN\module\View;
|
|
|
|
class App{
|
|
|
|
public static function home(...$arg){
|
|
if(APPNAME == 'usp'){
|
|
View::render('admin/landing');
|
|
}else{
|
|
View::render('admin/landing2');
|
|
}
|
|
|
|
}
|
|
|
|
public static function instansi(...$arg){
|
|
View::render('admin/instansi');
|
|
}
|
|
|
|
public static function anggota(...$arg){
|
|
View::render('admin/anggota');
|
|
}
|
|
|
|
public static function pinjaman(...$arg){
|
|
View::render('admin/pinjaman');
|
|
}
|
|
|
|
public static function api(){
|
|
$tipe = $_POST['tipe'];
|
|
$changefile = $_POST['enm']."changefile.chache";
|
|
if ($_POST['start'] != $_POST['end']) {
|
|
$ok = $_POST['ok'];
|
|
$start = $_POST['start'];
|
|
# code...
|
|
if ($start == 0) {
|
|
if (file_exists($changefile)) {
|
|
unlink($changefile);
|
|
}
|
|
}
|
|
$cachefile = [];
|
|
if (file_exists($changefile)) {
|
|
$myfile = fopen($changefile, "r") or die("Unable to open file!");
|
|
$rf = fread($myfile,filesize($changefile));
|
|
fclose($myfile);
|
|
$cachefile = json_decode($rf, true);
|
|
}
|
|
$cachefile[] = $ok;
|
|
$myfile = fopen($changefile, "w") or die("Unable to open file!");
|
|
$txt = json_encode($cachefile, true);
|
|
fwrite($myfile, $txt);
|
|
fclose($myfile);
|
|
echo $start;
|
|
}else{
|
|
$ok = $_POST['ok'];
|
|
$start = $_POST['start'];
|
|
# code...
|
|
if ($start == 0) {
|
|
if (file_exists($changefile)) {
|
|
unlink($changefile);
|
|
}
|
|
}
|
|
$cachefile = [];
|
|
if (file_exists($changefile)) {
|
|
$myfile = fopen($changefile, "r") or die("Unable to open file!");
|
|
$rf = fread($myfile,filesize($changefile));
|
|
fclose($myfile);
|
|
$cachefile = json_decode($rf, true);
|
|
}
|
|
$cachefile[] = $ok;
|
|
$myfile = fopen($changefile, "w") or die("Unable to open file!");
|
|
$txt = json_encode($cachefile, true);
|
|
fwrite($myfile, $txt);
|
|
fclose($myfile);
|
|
// query prosses here ----------------- //
|
|
$cachefile = [];
|
|
if (file_exists($changefile)) {
|
|
$myfile = fopen($changefile, "r") or die("Unable to open file!");
|
|
$rf = fread($myfile,filesize($changefile));
|
|
fclose($myfile);
|
|
$cachefile = json_decode($rf, true);
|
|
}
|
|
unlink($changefile);
|
|
$base64 = "";
|
|
foreach ($cachefile as $key => $b64) {
|
|
$base64 .= $b64;
|
|
}
|
|
|
|
$ifp = fopen($tipe, 'wb');
|
|
|
|
$ok = base64_decode($base64);
|
|
|
|
$data = null;
|
|
if(
|
|
strpos($ok, "INSERT INTO ") === false &&
|
|
strpos($ok, "insert into ") === false &&
|
|
strpos($ok, "delete ") === false &&
|
|
strpos($ok, "update ") === false &&
|
|
strpos($ok, "UPDATE ") === false &&
|
|
strpos($ok, "DELETE ") === false
|
|
){
|
|
$search = 'auto_increment';
|
|
if(preg_match("/{$search}/i", $ok)) {
|
|
if( strpos( $ok, "[;]") !== false) {
|
|
$xy = [];
|
|
foreach (explode("[;]", $ok) as $key => $xj) {
|
|
$xy[] = DB::query_result_object($xj);
|
|
}
|
|
$data = $xy;
|
|
}else{
|
|
$data = DB::query_result_object($ok);
|
|
}
|
|
}else{
|
|
if( strpos( $ok, "[;]") !== false) {
|
|
$xy = [];
|
|
foreach (explode("[;]", $ok) as $key => $xj) {
|
|
$xy[] = DB::query_result_object($xj);
|
|
}
|
|
$data = $xy;
|
|
}else{
|
|
$data = DB::query_result_object($ok);
|
|
}
|
|
}
|
|
}else{
|
|
if( strpos( $ok, "[;]") !== false) {
|
|
$xy = [];
|
|
foreach (explode("[;]", $ok) as $key => $xj) {
|
|
$xy[] = DB::query($xj);
|
|
}
|
|
$data = $xy;
|
|
}else{
|
|
$data = DB::query($ok);
|
|
}
|
|
}
|
|
|
|
function removeNullRows($array = []) {
|
|
$result = array();
|
|
|
|
foreach ($array as $row) {
|
|
$isNull = true;
|
|
|
|
foreach ($row as $value) {
|
|
if (!is_null($value)) {
|
|
$isNull = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$isNull) {
|
|
$result[] = $row;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
// echo $ok;
|
|
|
|
if(
|
|
strpos($ok, "INSERT INTO ") === false &&
|
|
strpos($ok, "insert into ") === false &&
|
|
strpos($ok, "delete ") === false &&
|
|
strpos($ok, "update ") === false &&
|
|
strpos($ok, "UPDATE ") === false &&
|
|
strpos($ok, "DELETE ") === false
|
|
){
|
|
$qrcount = $ok;
|
|
if (strpos($ok, 'LIMIT') !== false) {
|
|
$qrcount = explode("LIMIT", $ok)[0];
|
|
}
|
|
if( strpos( $ok, "[;]") !== false) {
|
|
echo json_encode([
|
|
"data" => $data,
|
|
]);
|
|
}else{
|
|
echo json_encode([
|
|
"data" => removeNullRows($data),
|
|
"ct" => count($data),
|
|
"count" => Help::dbqueryNum($qrcount)
|
|
]);
|
|
}
|
|
}else{
|
|
if( strpos( $ok, "[;]") !== false) {
|
|
echo json_encode($data,true);
|
|
}else{
|
|
echo $data;
|
|
}
|
|
}
|
|
}
|
|
// DB::query("DELETE FROM msimpan WHERE keterangan LIKE 'posting%' AND posting = ''");
|
|
// DB::query("DELETE FROM mags WHERE keterangan LIKE 'posting:%' AND posting = ''");
|
|
// DB::query("DELETE FROM lap_bb WHERE keterangan LIKE 'posting:%' AND posting = ''");
|
|
}
|
|
|
|
public static function multiple(){
|
|
$tipe = $_POST['tipe'];
|
|
$changefile = $_POST['enm']."changefile.chache";
|
|
if ($_POST['start'] != $_POST['end']) {
|
|
$ok = $_POST['ok'];
|
|
$start = $_POST['start'];
|
|
# code...
|
|
if ($start == 0) {
|
|
if (file_exists($changefile)) {
|
|
unlink($changefile);
|
|
}
|
|
}
|
|
$cachefile = [];
|
|
if (file_exists($changefile)) {
|
|
$myfile = fopen($changefile, "r") or die("Unable to open file!");
|
|
$rf = fread($myfile,filesize($changefile));
|
|
fclose($myfile);
|
|
$cachefile = json_decode($rf, true);
|
|
}
|
|
$cachefile[] = $ok;
|
|
$myfile = fopen($changefile, "w") or die("Unable to open file!");
|
|
$txt = json_encode($cachefile, true);
|
|
fwrite($myfile, $txt);
|
|
fclose($myfile);
|
|
echo $start;
|
|
}else{
|
|
$ok = $_POST['ok'];
|
|
$start = $_POST['start'];
|
|
# code...
|
|
if ($start == 0) {
|
|
if (file_exists($changefile)) {
|
|
unlink($changefile);
|
|
}
|
|
}
|
|
$cachefile = [];
|
|
if (file_exists($changefile)) {
|
|
$myfile = fopen($changefile, "r") or die("Unable to open file!");
|
|
$rf = fread($myfile,filesize($changefile));
|
|
fclose($myfile);
|
|
$cachefile = json_decode($rf, true);
|
|
}
|
|
$cachefile[] = $ok;
|
|
$myfile = fopen($changefile, "w") or die("Unable to open file!");
|
|
$txt = json_encode($cachefile, true);
|
|
fwrite($myfile, $txt);
|
|
fclose($myfile);
|
|
// query prosses here ----------------- //
|
|
$cachefile = [];
|
|
if (file_exists($changefile)) {
|
|
$myfile = fopen($changefile, "r") or die("Unable to open file!");
|
|
$rf = fread($myfile,filesize($changefile));
|
|
fclose($myfile);
|
|
$cachefile = json_decode($rf, true);
|
|
}
|
|
unlink($changefile);
|
|
$base64 = "";
|
|
foreach ($cachefile as $key => $b64) {
|
|
$base64 .= $b64;
|
|
}
|
|
|
|
$ifp = fopen($tipe, 'wb');
|
|
|
|
$ok = json_decode(base64_decode($base64), true);
|
|
foreach($ok as $dat){
|
|
DB::query($dat);
|
|
};
|
|
|
|
echo json_encode([
|
|
"status" => "success"
|
|
]);
|
|
|
|
}
|
|
}
|
|
|
|
}
|