Senin, 18 Oktober 2021

.htaccess Pewaktuan

 





.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]

index.php
<html>
<head>
<script type="text/javascript">
function Ajax(){
var $http,$self = arguments.callee;

if (window.XMLHttpRequest) {$http = new XMLHttpRequest();} 
else if (window.ActiveXObject) {
try {$http = new ActiveXObject('Msxml2.XMLHTTP');} 
catch(e) {$http = new ActiveXObject('Microsoft.XMLHTTP');}
}

if ($http) {
$http.onreadystatechange = function(){
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function(){$self();}, 1000);
}
};
$http.open('GET', 'timer.php' + '?' + new Date().getTime(), true);
$http.send(null);
}
}
</script>
<script type="text/javascript">setTimeout(function() {Ajax();}, 1000);</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php

$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$ar=explode("/",$url);
$jd=count($ar);
$nama= $ar[$jd-1];
$nama=str_replace("+"," ",$nama);
$nama=str_replace("-"," ",$nama);
$nama=str_replace("%20"," ",$nama);
echo "<h1>Yth, $nama</h1>";
?>

</body>
</html>

timer.php
<?php
date_default_timezone_set("Asia/Jakarta");

$tglacara="2025-12-25";
$jamacara="00:00:00";

$tglnow=date("Y-m-d");
$jamnow=date("H:m:s");

$acara = new DateTime($tglacara." ".$jamacara);
$sekarang = new DateTime();


$tanggal=WKT($tglnow);
echo  "<b>MEETING :".WKT($tglacara)."</b><br>";
echo  "<b>TODAY :$tanggal $jamnow Wib</b>";

$diff  = date_diff( $acara,$sekarang );
echo"<hr>";
echo $diff->y . " tahun<br>";
echo $diff->m . " bulan<br>";
echo $diff->d . " hari<br>";
echo $diff->h . " jam<br>";
echo $diff->i . " menit<br>";
echo $diff->s . " detik<br>";

?>










<?php
function WKT($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,0,4);

$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");
$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;
return $wk;
}
?>








Senin, 04 Oktober 2021

Laravel View Code DB

 <?php

/*

$ARR= DB::table('barang')->get();

foreach($ARR as $key => $value){

echo $value->nama_barang."<hr>";

}

*/


//$hasil=\App\Barang::find(3)->value('nama_barang');

//echo $hasil;

//$count = DB::table('barang')->count();

//echo $count;



?>

Minggu, 03 Oktober 2021

Laravel Hack Code

 

buat helper.php pada folder Helpers

Pada composer tanbahkan pada bagian autoload

    "autoload": {

        "psr-4": {

            "App\\": "app/"

        },

        "classmap": [

            "database/seeds",

            "database/factories"

        ],

"files":  [ 

"app/Helpers/helper.php"

]

    },


jalankan perintah pada terminal

composer update -vvv 

atau

composer dump-autoload



<?php

//$username=Session::get('key');

//https://laravel.com/docs/8.x/queries#aggregates


//https://blog.quickadminpanel.com/5-ways-to-use-raw-database-queries-in-laravel/


function getListMasuk($kode){ 


$sql= "SELECT `mdetail`.`id_barang`,`mdetail`.`jumlah`,`mdetail`.`subtotal` FROM `pemasukan`,`mdetail` WHERE `pemasukan`.`id_pemasukan`=`mdetail`.`id_pemasukan` and `pemasukan`.`id_pemasukan`= '$kode'";

    $results = DB::select($sql);

$gab="";

$total=0;

foreach($results as $i){

$id_barang= $i->id_barang;

$jumlah= $i->jumlah;

$subtotal= $i->subtotal;

$nb=getNamaBarang($id_barang);

$gab.="$nb ($jumlah),";

$total+=$subtotal;

}

$gab.="Total:".RP($total);

return $gab;

}


function getNamaBarang($kode){ 

//ModelName::find(id)->value('column_name');

$hasil=\App\Barang::find($kode)->value('nama_barang');//BEST


//$results = DB::select('select `nama_barang` from `barang` where `id_barang` = ?', [$kode]);

//$hasil=$results[0]->nama_barang;

//$sql= "SELECT `nama_barang` FROM `barang` WHERE `id_barang`= '".$kode."'";

    //$results = DB::select($sql);

//$hasil=$results[0]->nama_barang;

//$results = DB::table('barang')->select('nama_barang')->where('id_barang', '=', $kode)->orderBy('id_barang','asc')->get();//ARRAY

//$hasil=$results[0]->nama_barang;

//foreach($results as $i){echo $i->user_id;}


//$results = DB::table('barang')->select('nama_barang')->where('id_barang','=', $kode)->first();

//$hasil=$results->nama_barang;

//$results = DB::table('barang')->select('nama_barang')->where('id_barang', $kode)->first();//first=return no array

//$hasil=$results->nama_barang;

//$hasil=DB::table('barang')->where('id_barang', $kode)->value('nama_barang');//L5

//$hasil=DB::table('barang')->where('id_barang', $kode)->pluck('nama_barang');//L4

//$hasil = DB::table('barang')->where('id_barang', $kode)->select('nama_barang')->pluck('nama_barang')->first();


//$hasil=DB::table('barang')->where('id_barang', $kode)->orderBy('id_barang', 'desc')->value('nama_barang');

//$hasil =\App\Barang::where('id_barang', $kode)->first()->nama_barang;

//$hasil = \App\Barang::where('id_barang',$kode)->value('nama_barang');


return $hasil;

}


//exe

//DB::statement('UPDATE users SET role_id = 1 WHERE role_id IS NULL AND YEAR(created_at) > 2020');

//DB::statement('DROP TABLE users');

//DB::statement('ALTER TABLE projects AUTO_INCREMENT=123');



//LIBRARY SQL //RAW

//\App\User::whereIn('mobile',['971700000', '965000000'])->select('id')->pluck('id')->all();


/*

$users = DB::table('users')

    ->selectRaw('count(*) as user_count, status')

    ->where('status', '<>', 1)

    ->groupBy('status')

    ->get();

$products = DB::table('products')

    ->leftjoin('category','category.product_id','=','products.id')

    ->selectRaw('COUNT(*) as nbr', 'products.*')

    ->groupBy('products.id')

    ->get();

$salaries = DB::table('salaries')

    ->selectRaw('companies.name as company_name, avg(salary) as avg_salary, count(*) as people_count')

    ->join('companies', 'salaries.company_id', '=', 'companies.id')

    ->groupBy('companies.id')

    ->orderByDesc('avg_salary')

    ->get();

$results = User::selectRaw('YEAR(birth_date) as year, COUNT(id) as amount')

    ->groupByRaw('YEAR(birth_date)')

    ->havingRaw('YEAR(birth_date) > 2000')

    ->orderByRaw('YEAR(birth_date)')

    ->get();

$products = Product::select('id', 'name')

    ->selectRaw('price - discount_price AS discount')

    ->get();


$users = DB::table('users')

    ->select('name', 'surname')  

    ->selectRaw("(CASE WHEN (gender = 1) THEN 'M' ELSE 'F' END) as gender_text")

    ->get();

 

https://laravel.com/docs/8.x/requests

use Illuminate\Http\Request;

public function store(Request $request){

$name = $request->input('name');

$uri = $request->path();

$url = $request->url();

$urlWithQueryString = $request->fullUrl();

$request->fullUrlWithQuery(['type' => 'phone']);

$method = $request->method();

if ($request->isMethod('post')) {}


$value = $request->header('X-Header-Name');

$value = $request->header('X-Header-Name', 'default');


if ($request->hasHeader('X-Header-Name')) {}

$token = $request->bearerToken();

$ipAddress = $request->ip();


$contentTypes = $request->getAcceptableContentTypes();



if ($request->accepts(['text/html', 'application/json'])) {}

$preferred = $request->prefers(['text/html', 'application/json']);


if ($request->expectsJson()) {}

$input = $request->all();

$input = $request->collect();

$request->collect('users')->each(function ($user) {});

$name = $request->input('name');

$name = $request->input('name', 'Sally');


$name = $request->input('products.0.name');

$names = $request->input('products.*.name');

$input = $request->input();

$name = $request->query('name');

$name = $request->query('name', 'Helen');

$query = $request->query();

$name = $request->input('user.name');

$archived = $request->boolean('archived');

$name = $request->name;

$input = $request->only(['username', 'password']);

$input = $request->only('username', 'password');

$input = $request->except(['credit_card']);

$input = $request->except('credit_card');

if ($request->has('name')) {}

if ($request->has(['name', 'email'])) {}

$request->whenHas('name', function ($input) {});


if ($request->hasAny(['name', 'email'])) {}

if ($request->filled('name')) {}

$request->whenFilled('name', function ($input) {});

if ($request->missing('name')) {}

$request->flash();

$request->flashOnly(['username', 'email']);

$request->flashExcept('password');


return redirect('form')->withInput();

return redirect()->route('user.create')->withInput();

return redirect('form')->withInput(

$request->except('password')

);


$username = $request->old('username');

<input type="text" name="username" value="{{ old('username') }}">

$value = $request->cookie('name');

$file = $request->file('photo');

$file = $request->photo;

if ($request->hasFile('photo')) {}

if ($request->file('photo')->isValid()) {}

$path = $request->photo->path();

$extension = $request->photo->extension();

$path = $request->photo->store('images');

$path = $request->photo->store('images', 's3');

$path = $request->photo->storeAs('images', 'filename.jpg');

$path = $request->photo->storeAs('images', 'filename.jpg', 's3');

https://laravel.com/docs/8.x/requests

}//public






*/


function RP($angka){ 

    $hasil =  number_format($angka,0, ',' , '.'); 

    return $hasil.";"; 

}

function terbilang($i){

  $huruf = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas");

  

  if ($i < 12) return " " . $huruf[$i];

  elseif ($i < 20) return terbilang($i - 10) . " Belas";

  elseif ($i < 100) return terbilang($i / 10) . " Puluh" . terbilang($i % 10);

  elseif ($i < 200) return " Seratus" . terbilang($i - 100);

  elseif ($i < 1000) return terbilang($i / 100) . " Ratus" . terbilang($i % 100);

  elseif ($i < 2000) return " Seribu" . terbilang($i - 1000);

  elseif ($i < 1000000) return terbilang($i / 1000) . " Ribu" . terbilang($i % 1000);

  elseif ($i < 1000000000) return terbilang($i / 1000000) . " Juta" . terbilang($i % 1000000);    

}



?>




<?php function RP2($rupiah){return number_format($rupiah,"2",",",".");}?>

<?php

function WKT($sekarang){

if($sekarang=="0000-00-00"){$sekarang=date("Y-m-d");}


$tanggal = substr($sekarang,8,2)+0;

$bulan = substr($sekarang,5,2);

$tahun = substr($sekarang,0,4);


$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");

$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;

return $wk;

}

?>

<?php

function WKTP($sekarang){

$tanggal = substr($sekarang,8,2)+0;

$bulan = substr($sekarang,5,2);

$tahun = substr($sekarang,2,2);


$judul_bln=array(1=> "Jan", "Feb", "Mar", "Apr", "Mei","Jun", "Jul", "Agu", "Sep","Okt", "Nov", "Des");

$wk=$tanggal." ".$judul_bln[(int)$bulan]."'".$tahun;

return $wk;

}

?>




<?php

function BAL($tanggal){

$arr=explode(" ",$tanggal);

if($arr[1]=="Januari"||$arr[1]=="January"){$bul="01";}

else if($arr[1]=="Februari"||$arr[1]=="February"){$bul="02";}

else if($arr[1]=="Maret"||$arr[1]=="March"){$bul="03";}

else if($arr[1]=="April"){$bul="04";}

else if($arr[1]=="Mei"||$arr[1]=="May"){$bul="05";}

else if($arr[1]=="Juni"||$arr[1]=="June"){$bul="06";}

else if($arr[1]=="Juli"||$arr[1]=="July"){$bul="07";}

else if($arr[1]=="Agustus"||$arr[1]=="August"){$bul="08";}

else if($arr[1]=="September"){$bul="09";}

else if($arr[1]=="Oktober"||$arr[1]=="October"){$bul="10";}

else if($arr[1]=="November"){$bul="11";}

else if($arr[1]=="Nopember"){$bul="11";}

else if($arr[1]=="Desember"||$arr[1]=="December"){$bul="12";}

return "$arr[2]-$bul-$arr[0]";

}

?>



<?php

function BALP($tanggal){

$arr=split(" ",$tanggal);

if($arr[1]=="Jan"){$bul="01";}

else if($arr[1]=="Feb"){$bul="02";}

else if($arr[1]=="Mar"){$bul="03";}

else if($arr[1]=="Apr"){$bul="04";}

else if($arr[1]=="Mei"){$bul="05";}

else if($arr[1]=="Jun"){$bul="06";}

else if($arr[1]=="Jul"){$bul="07";}

else if($arr[1]=="Agu"){$bul="08";}

else if($arr[1]=="Sep"){$bul="09";}

else if($arr[1]=="Okt"){$bul="10";}

else if($arr[1]=="Nov"){$bul="11";}

else if($arr[1]=="Nop"){$bul="11";}

else if($arr[1]=="Des"){$bul="12";}

return "$arr[2]-$bul-$arr[0]";

}

?>



Mencari Tanggal Terakhir Suatu Bulan

  $a_date = "$tahun-$bulan-01"; $lastdate= date('t',strtotime($a_date));//Y-m-t <?php require_once"koneksivar.php&...