Institutional Repository | Satya Wacana Christian University: Perancangan Aplikasi Web E-Commerce WK Komputer Berbasis Multimedia
73
Lampiran
1.
Kode Website
Kode Website 1
Halaman Utama
<?php
error_reporting(E_ALL ^ E_NOTICE); include "include/koneksi.php"; include "include/setting.php"; ?>
<HTML>
<HEAD><TITLE><?php echo"$judul";?></TITLE> <META content="562011602" name=author> <META content="WK Komputer" name=copyright> <META content="7 days" name=revisit-after> <META content=Global name=distribution> <META content=general name=rating>
<META content="<?php echo"$keyword";?>" name=keywords> <META content="<?php echo"$deskripsi";?>"
name=description>
<META content=True name=MSSmartTagsPreventParsing> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/style.css" type="text/css">
<scripttype="text/javascript" src="jquery/jquery.js"></script> <style type="text/css">
<!--
.style4 {color: #FF3300} -->
</style> </head>
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="83%">
<tr>
<td width="50%" background="gambar/bg.gif"><img src="gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
<td valign="bottom" background="gambar/bg_left.gif"><img src="gambar/bg_left.gif" alt="" width="17" height="16" border="0"></td>
<td><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include "header.php"; ?></td> </tr>
<tr> <td>
(2)
74
<?php include "menu_atas.php"; ?></td> </tr>
<tr>
<td background="gambar/fon_top.jpg"><p> </td>
</tr> </table>
<table width="774" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="115" valign="top"><p> <?php include "menu_kiri.php"; ?> </p></td>
<td width="572" valign="top"><br><table width="508" border="0" align="center">
<?php
$a="select*from tblcms,tblkategori,user where tblcms.idkategori=tblkategori.idkategori and
tblcms.user=user.username and tblcms.status='Y' order by id DESC limit 5";
$b=mysql_query($a);
while($c=mysql_fetch_array($b)) {
// Tampilkan hanya sebagian isi berita
$isi_berita = htmlentities(strip_tags($c['content'])); $isi = substr($isi_berita,0,220);
$isi = substr($isi_berita,0,strrpos($isi," ")); ?>
<tr>
<td colspan=2><b><?php echo $c['judul'];?></b></td> </tr>
<tr>
<?php if(empty($c['gambar'])){ echo "<td colspan=2><p
align='justify'><font color='#0033CC'>Dikirim oleh: $c[nama_lengkap] - Kategori: $c[kategori]</font><br> $isi... <a
href='berita.php?id=$c[id]'>Selengkapnya</a></p></td>"; }else{
echo "<td width=140><img src='gambar/berita/$c[gambar]' width=120 height=100 align='left' hspace=10 border=0></td>
<td width='357'><p align='justify'><font
color='#0033CC'>Dikirim oleh: $c[nama_lengkap] - Kategori: $c[kategori]</font><br>
$isi... <a
href='berita.php?id=$c[id]'>Selengkapnya</a></p></td>"; }
?> <tr>
<td colspan=2><hr /></td> </tr>
<?php }?> </table> <p> </p> </td>
(3)
75
<td width="81" valign="top" bgcolor="#FFFFFF"><?php include "menu_kanan.php"; ?></td>
</tr> </table>
<div class="px" align="center"><img
src="gambar/bot01.jpg" width="845" height="9" alt="" border="0"></div>
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
<tr>
<td><p align="center">
<?php include "footer.php"; ?> </p></td>
<td height="50"> <p class="bot"> </p>
</td> </tr>
</table> </td>
<td valign="bottom"
background="gambar/bg_right.gif"><img
src="gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="gambar/bg.gif"><img src="gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr> </table> </body> </html>
Kode Website
2 Fungsi Simpan Belanja
<?php
session_start();
include "include/koneksi.php"; include "include/library.php";
$sql=mysql_query("insert into orders(nama_kustomer, alamat, telpon, tgl_order, jam_order)
values('$_POST[nama]','$_POST[alamat]','$_POST[telpon], '$tgl_sekarang', '$jam_sekarang')");
$sql2=mysql_query("select id_orders from orders order by id_orders desc");
$r=mysql_fetch_array($sql2); $id_orders=$r[id_orders];
$cartContent = getCartContent(); $jml = count($cartContent); for ($i = 0; $i < $jml; $i++) { $sql3=mysql_query("insert into
(4)
76
values('$id_orders',{$cartContent[$i]['id_produk']}, {$cartContent[$i]['jumlah']})");
} ?>
Kode Website 3
Simpan Pembelian
<?php
session_start();
include "include/koneksi.php"; include "include/library.php"; function getCartContent(){
$cartContent = array(); $sid = session_id();
$sql = mysql_query("SELECT * FROM orders_temp WHERE id_session='$sid'");
while ($row = mysql_fetch_array($sql)) { $cartContent[] = $row;
}
return $cartContent; }
$sql=mysql_query("insert into orders(nama_kustomer, alamat, telpon, tgl_order, jam_order)
values('$_POST[nama]','$_POST[alamat]','$_POST[telpon]', '$tgl_sekarang', '$jam_sekarang')");
$id_orders=mysql_insert_id();
$cartContent = getCartContent(); $jml = count($cartContent); for ($i = 0; $i < $jml; $i++) { $sql3=mysql_query("insert
intoorders_detail(id_orders, id_produk, jumlah)
values('$id_orders',{$cartContent[$i]['id_produk']}, {$cartContent[$i]['jumlah']})");
}
for ($i = 0; $i < $jml; $i++) {
$sql4 = mysql_query("DELETE FROM orders_temp
WHERE id_orders_temp = {$cartContent[$i]['id_orders_temp']}"); }
(5)
77
Kode Website
4 Simpan Transaksi
<?php
error_reporting(E_ALL ^ E_NOTICE); session_start();
include "include/koneksi.php"; include "include/setting.php"; ?>
<HTML>
<HEAD><TITLE><?php echo"$judul";?></TITLE> <META content="Agung Nugroho" name=author> <META content="WK.com" name=copyright> <META content=Global name=distribution> <META content=general name=rating>
<META content="<?php echo"$keyword";?>" name=keywords> <META content="<?php echo"$deskripsi";?>"
name=description>
<META content=True name=MSSmartTagsPreventParsing> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/style.css" type="text/css">
<script type="text/javascript" src="jquery/jquery.js"></script> </head>
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="83%">
<tr>
<td width="50%" background="gambar/bg.gif"><img src="gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
<td valign="bottom"
background="gambar/bg_left.gif"><img
src="gambar/bg_left.gif" alt="" width="17" height="16" border="0"></td>
<td><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include "header.php"; ?></td> </tr>
<tr> <td>
<?php include "menu_atas.php"; ?></td> </tr>
<tr>
<td background="gambar/fon_top.jpg"><p> </td>
</tr> </table>
<table width="774" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="115" valign="top"><p> <?php include "menu_kiri.php"; ?>
(6)
78
</p></td>
<?php echo "
<td width='572' valign='top'><p
align='center'><strong>Detail Belanja Anda </strong></p> <table width='508' border='0' align='center'
cellpadding='1' cellspacing='0'> <tr>
<td>";
include "include/koneksi.php"; function format_rupiah($angka){
$rupiah=number_format($angka,0,',','.'); return $rupiah;
}
// fungsi untuk mendapatkan isi keranjang belanja function isi_keranjang(){
$isikeranjang = array(); $sid = session_id();
$sql = mysql_query("SELECT * FROM orders_temp WHERE id_session='$sid'");
while ($r=mysql_fetch_array($sql)) { $isikeranjang[] = $r;
}
return $isikeranjang; }
$tgl_skrg = date("Ymd"); $jam_skrg = date("H:i:s"); // simpan data pemesanan
if(empty($_POST[nama]) || empty($_POST[alamat]) || empty($_POST[telpon]) || empty($_POST[email])) {
echo "<script>alert('Data belum lengkap, silahkan periksa data isian anda!');javascript:history.go(-1);</script>"; }else{
mysql_query("INSERT INTO orders(nama_kustomer, alamat, telpon, email, tgl_order, jam_order)
VALUES('$_POST[nama]','$_POST[alamat]','$_POST[telpon]', '$_POST[email]', '$tgl_skrg', '$jam_skrg')");
// mendapatkan nomor orders (id_orders dari tabel orders) $id_orders=mysql_insert_id();
// panggil fungsi isi_keranjang dan hitung jumlah produk yang dipesan
$isikeranjang = isi_keranjang(); $jml = count($isikeranjang); // simpan data detail pemesanan for ($i = 0; $i < $jml; $i++){
mysql_query("INSERT INTO orders_detail(id_orders, id_produk, jumlah)
(7)
79
VALUES('$id_orders',{$isikeranjang[$i]['id_produk']}, {$isikeranjang[$i]['jumlah']})");
}
// update/kurangi stok produk for ($i = 0; $i < $jml; $i++) {
mysql_query("UPDATE produk SET stok = stok - {$isikeranjang[$i]['jumlah']}
WHERE id_produk = {$isikeranjang[$i]['id_produk']}"); }
// update/tambahkan produk yang dibeli (best seller) for ($i = 0; $i < $jml; $i++) {
mysql_query("UPDATE produk SET dibeli = dibeli + {$isikeranjang[$i]['jumlah']}
WHERE id_produk = {$isikeranjang[$i]['id_produk']}"); }
// setelah data pemesanan tersimpan, hapus data pemesanan di tabel pemesanan sementara
for ($i = 0; $i < $jml; $i++) {
mysql_query("DELETE FROM orders_temp
WHERE id_orders_temp = {$isikeranjang[$i]['id_orders_temp']}"); }
// tampilkan data kustomer beserta ordernya di browser echo "Terimakasih telah berbelanja di website kami. <br /> Data pemesan beserta ordernya adalah sebagai
berikut: <br /><br />
Nama : <b>$_POST[nama]</b><br /> Alamat : $_POST[alamat] <br /> Telpon : $_POST[telpon] <br />
E-mail : $_POST[email] <br /><hr /><br /> Nomor Order: <b>$id_orders</b><br /><br />"; $daftarproduk=mysql_query("SELECT * FROM
orders_detail,produk
WHERE
orders_detail.id_produk=produk.id_produk
AND id_orders='$id_orders'"); echo "<table cellpadding=5>
<tr bgcolor=#D3DCE3><th>Nama
Produk</th><th>Jumlah</th><th>Harga</th><th>Total</th></tr >";
while ($d=mysql_fetch_array($daftarproduk)){ $subtotal = $d[harga] * $d[jumlah]; $total = $total + $subtotal;
$subtotal_rp = format_rupiah($subtotal); $total_rp = format_rupiah($total); $harga = format_rupiah($d[harga]);
(8)
80
echo "<tr
bgcolor=#cccccc><td>$d[nama_produk]</td><td>$d[jumlah]</td ><td>Rp. $harga</td><td>Rp. $subtotal_rp</td></tr>"; }
echo "<tr><td colspan=3 align=right>Total</td><td>Rp. <b>$total_rp</b></td></tr>
</table><br />";
$pesan.="<br /><br />Yth. Saudara : <b>$_POST[nama] - $_POST[email]</b>
<br />Email ini anda terima karena anda atau seseorang telah menggunakan email ini untuk melakukan pemesanan produk kami di $domain
<br />Nomor Order anda :<b>$id_orders</b> <br />Total Belanja Anda : <b>Rp.
$total_rp</b>
<br /><br />Silahkan transfer data pembayaran anda ke $bank dan konfirmasikan via sms ke HP pengelola yaitu $telp dengan format sms
Nomor_Order # Nama_Lengkap # Total_belanja. Setelah konfirmasi, pesanan anda akan segera diproses dan produk segera dikirim ke alamat anda.<br><br>
Terima kasih atas kepercayaan
anda.<br><b>Pengelola,<br><br>$nama<br>$email.</b>"; $subjek="Data Pesanan anda di $domain";
// Kirim email dalam format HTML $dari = "From: $email \n";
$dari .= "Content-type: text/html \r\n"; // Kirim email ke kustomer
/*mail($_POST[$email],$subjek,$pesan,$dari); // Kirim email ke pengelola toko online mail("$email",$subjek,$pesan,$dari); */
echo "<p>Silahkan transfer data pembayaran anda ke $bank dan konfirmasikan via sms ke HP pengelola yaitu $telp dengan format sms
Nomor_Order # Nama_Lengkap # Total_belanja. Setelah konfirmasi, pesanan anda akan segera diproses dan produk segera dikirim ke alamat anda.
Data pemesanan juga sudah terkirim ke email anda.<br><br> Terima kasih atas kepercayaan
anda.<br><b>Pengelola,<br><br>$nama<br>$email.</b>"; }
?> </td> </tr>
</table></td>
<td width="81" valign="top" bgcolor="#FFFFFF"><?php include "menu_kanan.php"; ?></td>
</tr> </table>
<div class="px" align="center"><img
src="gambar/bot01.jpg" width="845" height="9" alt="" border="0"></div>
(9)
81
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
<tr>
<td><p align="center">
<?php include "footer.php"; ?> </p></td>
<td height="50"> <p class="bot"> </p>
</td> </tr>
</table> </td>
<td valign="bottom"
background="gambar/bg_right.gif"><img
src="gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="gambar/bg.gif"><img src="gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr> </table> </body> </html>
Kode Website 5
Hapus User
<?php
session_start();
include "../include/koneksi.php"; if (isset($_SESSION['level']) && isset($_SESSION['username'])) {
if ($_SESSION['level'] == "admin") {
if (isset($_GET[username])) { $username = $_GET[username]; } else {
die ("Error. Username belum dipilih! "); }
if (!empty($username)) {
$SQL = "delete from user where username='$username'"; if(! mysql_query($SQL))
{
echo "Data tidak terhapus!<br>\n"; }
header("location:user.php"); }
} else
(10)
82
{
// jika levelnya bukan admin, tampilkan pesan echo "<script>alert('Sorry ya Coy.. Anda bukan admin');javascript:history.go(-1);</script>";
} } else {
echo "<script>alert('Eeeh Maling.. Login dulu dong!!');javascript:history.go(-1);</script>"; }
?>
Kode Website 6
Fungsi Berita admin
<?php
error_reporting(E_ALL ^ E_NOTICE); session_start();
include "../include/koneksi.php"; if (isset($_SESSION['level']) && isset($_SESSION['username'])) {
if ($_SESSION['level'] == "admin") {
if(isset($_POST['simpan'])){ $idkategori=$_POST['idkategori']; $judul=$_POST['judul'];
$content=$_POST['content']; $status=$_POST['status'];
$gambar=$_FILES['gambar']['name']; if(strlen($gambar)>0){
if(is_uploaded_file($_FILES['gambar']['tmp_name'])) {
move_uploaded_file($_FILES['gambar']['tmp_name'],". ./gambar/berita/".$gambar);
} }
$a="insert into
tblcms(id,judul,idkategori,content,gambar,user,status)valu es('','$judul','$idkategori','$content','$gambar','$_SESSI ON[username]','$status')";
$b=mysql_query($a); if($b){
echo "<script type='text/javascript'> onload =function(){
alert('Berita telah tersimpan'); }
</script>"; }else{
echo "<script type='text/javascript'> onload =function(){
alert('Berita gagal disimpan'); }
(11)
83
} }
//Proses edit
//tampilkan data yang diedit $id=$_GET['id'];
$sql="select * from tblcms where id='$id'"; $query=mysql_query($sql);
$baris=mysql_fetch_array($query); if(isset($_POST['Edit'])){
$idkategori=$_POST['idkategori']; $judul=$_POST['judul'];
$content=$_POST['content']; $status=$_POST['status'];
$gambar=$_FILES['gambar']['name']; if(strlen($gambar)>0){
if(is_uploaded_file($_FILES['gambar']['tmp_name'])) {
move_uploaded_file($_FILES['gambar']['tmp_name'],". ./gambar/berita/".$gambar);
}
mysql_query("update tblcms set gambar='$gambar' where id='$id'");
}
$a="Update tblcms set
judul='$judul',idkategori='$idkategori',content='$content' ,status='$status' where id='$id'";
$b=mysql_query($a); if($b){
header("location:berita.php"); }else{
echo "<script type='text/javascript'> onload =function(){
alert('Berita gagal diubah!'); }
</script>"; }
} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Administrator Area - Kelola Berita</title> <!-- TinyMCE -->
<script language="javascript" type="text/javascript" src="../tinymcpuk/tiny_mce.js"></script>
<script language="javascript" type="text/javascript"> tinyMCE.init({
mode : "textareas", theme : "advanced", plugins :
"table,save,advhr,advimage,advlink,emotions,iespell,insert datetime,preview,zoom,flash,searchreplace,print,paste,dire ctionality,fullscreen,noneditable,contextmenu",
(12)
84
theme_advanced_buttons1_add_before : "save,newdocument,separator",
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
theme_advanced_buttons2_add :
"separator,insertdate,inserttime,preview,zoom,separator,fo recolor,backcolor,liststyle",
theme_advanced_buttons2_add_before:
"cut,copy,paste,pastetext,pasteword,separator,search,repla ce,separator",
theme_advanced_buttons3_add_before : "tablecontrols,separator",
theme_advanced_buttons3_add :
"emotions,iespell,flash,advhr,separator,print,separator,lt r,rtl,separator,fullscreen",
theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom",
plugin_insertdate_dateFormat : "%Y-%m-%d", plugin_insertdate_timeFormat : "%H:%M:%S", extended_valid_elements :
"hr[class|width|size|noshade]",
file_browser_callback : "fileBrowserCallBack",
paste_use_dialog : false, theme_advanced_resizing : true,
theme_advanced_resize_horizontal : false, theme_advanced_link_targets :
"_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
apply_source_formatting : true });
function fileBrowserCallBack(field_name, url, type, win) {
var connector =
"../../filemanager/browser.html?Connector=connectors/php/c onnector.php";
var enableAutoTypeSelection = true; var cType;
tinymcpuk_field = field_name; tinymcpuk = win;
switch (type) { case "image":
cType = "Image"; break;
case "flash":
cType = "Flash"; break;
case "file":
cType = "File"; break;
}
(13)
85
connector += "&Type=" + cType; }
window.open(connector, "tinymcpuk", "modal,width=600,height=400");
} </script>
<!-- /TinyMCE --></head>
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="83%">
<tr>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
<td valign="bottom"
background="../gambar/bg_left.gif"><img
src="../gambar/bg_left.gif" alt="" width="17" height="16" border="0"></td>
<td><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include "header.php"; ?></td> </tr>
<tr>
<td background="../gambar/fon02.gif" height="34"><div align="center"></div></td>
</tr> </table>
<p align="center" class="px"> <?php include "menu.php"; ?>
<table width="644" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="549"><h3 align="center">KELOLA BERITA </h3> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="600" border="0" align="center"> <tr>
<td width="98"><strong>Judul Berita </strong></td> <td width="295"><label>
<input name="judul" type="text" id="judul" size="50" value="<?php echo $baris['judul'];?>"/>
</label></td> </tr>
<tr> <td><strong>Kategori</strong></td> <td><label>
<?php if($_GET[id]==1){ echo "<input type='text' name='idkategori' value='Tidak Dikategori' readonly>";
}else{
echo "<select name='idkategori' id='idkategori'>";
$kategori=mysql_query("select * from tblkategori");
(14)
86
while($data=mysql_fetch_array($kategori)){ $pilih =
($baris['idkategori']==$data['idkategori'])?"selected" : "";
echo"<option value=\"$data[idkategori]\"
$pilih>$data[kategori]</option>"; }
} ?> </select>
</label></td> </tr>
<tr>
<td><strong>Content</strong></td> <td><label>
<textarea name="content" cols="80" rows="15"
id="content"><?php echo $baris['content'];?></textarea> </label></td>
</tr>
<tr> <td><strong>Gambar</strong></td> <td><label>
<?php if($_GET['id']){ //tampilkan foto saat mau ngedit
echo "<img src='../gambar/berita/$baris[gambar]' width=150 height=110><br />";
} ?>
<input name="gambar" type="file" id="gambar" /> </label></td>
</tr>
<tr>
<td>Status</td>
<td>: <input type="radio" name="status" value="Y" <?php if($baris['status']=="Y"){ echo "checked";}?>> Ya
<input type="radio" name="status" value="T" <?php if($baris['status']=="T"){ echo "checked";}?>> Tidak</td>
</tr> <tr>
<tr> <td> </td>
<td><label>
<?php if(!$_GET['id']){
//bila mau tambah data yang tampil tombol simpan
echo "<input name=\"simpan\"
type=\"submit\" id=\"simpan\" value=\"Simpan\" /> "; echo "<input name=\"batal\" type=\"reset\" id=\"batal\" value=\"Batal\" />";
} else {
//Apabila mau edit yg tampil tombol edit dan hapus
(15)
87
echo "<input name=\"Edit\" type=\"submit\" id=\"edit\" value=\"Edit\" />";
} ?> </label></td> </tr>
</table> </form>
<p align="center"><strong>Tabel Berita </strong></p> <table width="644" border="1" align="center"
cellspacing="0"> <tr bgcolor="#FFFF99">
<td width="36" height="25"><div
align="center"><strong>No</strong></div></td> <td width="237"><div
align="center"><strong>Judul</strong></div></td> <td width="143"><div align="center">
<blockquote>
<p><strong>Kategori</strong></p> </blockquote>
</div></td>
<td width="95"><strong>Pengirim</strong></td> <td width="42"><div
align="center"><strong>Status</strong></div></td> <td width="65"><div
align="center"><strong>Aksi</strong></div></td> </tr>
<?php
$sql="select * from tblcms where id=1";
$query=mysql_query($sql); $data=mysql_fetch_array($query); ?>
<tr>
<td><div align="center">1</div></td> <td><?php echo $data['judul']; ?></td> <td>Home</td>
<td>Admin</td>
<td><div align="center">Y</div></td>
<td><div align="center"><a href="berita.php?id=<?php echo $data['id']; ?>"><img src="../gambar/button-edit.gif" width="20" height="20" /></a></div></td>
</tr> <?php
$sql="select * from tblcms,tblkategori where
tblcms.idkategori=tblkategori.idkategori and tblcms.id<>1 order by id DESC";
$query=mysql_query($sql); $no=2;
while($data=mysql_fetch_array($query)){ ?>
<tr>
<td><div align="center"><?php echo $no; ?></div></td> <td><?php echo $data['judul']; ?></td>
<td><?php echo $data['kategori']; ?></td> <td><?php echo $data['user']; ?></td>
(16)
88
?></div></td>
<td><div align="center"><a href="berita.php?id=<?php echo $data['id']; ?>"><img src="../gambar/button-edit.gif" width="20" height="20" /></a>
<a
href="javascript:if(confirm('Anda yakin akan menghapus data ini??')){document.location='hapus.php?id=<?php echo $data['id']; ?>';}"><img src="../gambar/button-cross.gif" width="20" height="20" /></a></div></td>
</tr>
<?php $no++;}?> </table>
<p align="center"> </p> <p> </p>
</td> </tr> </table>
<div class="px" align="center"><img
src="../gambar/bot01.jpg" width="780" height="9" alt="" border="0"></div>
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
<tr>
<td><p align="center">
<?php include "footer.php"; ?> </p></td>
<td height="50"> <p class="bot"> </p>
</td> </tr>
</table> </td>
<td valign="bottom"
background="../gambar/bg_right.gif"><img
src="../gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr> </table> </body> </html> <?php } else {
// jika levelnya bukan admin, tampilkan pesan echo "<script>alert('Sorry ya Coy.. Anda bukan admin');javascript:history.go(-1);</script>";
} } else {
echo "<script>alert('Eeeh Maling.. Login dulu dong!!');javascript:history.go(-1);</script>"; }
(17)
89
?>
Kode Website 7
Fungsi Order Admin
<?php
error_reporting(E_ALL ^ E_NOTICE); session_start();
include "../include/koneksi.php"; include "../include/fungsi_seo.php"; include "../include/fungsi_indotgl.php"; if (isset($_SESSION['level']) &&
isset($_SESSION['username'])) {
if ($_SESSION['level'] == "admin") {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Administrator Area - Kelola Berita</title> </head>
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="83%">
<tr>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
<td valign="bottom"
background="../gambar/bg_left.gif"><img
src="../gambar/bg_left.gif" alt="" width="17" height="16" border="0"></td>
<td><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include "header.php"; ?></td> </tr>
<tr>
<td background="../gambar/fon02.gif" height="34"><div align="center"></div></td>
</tr> </table>
<p align="center" class="px"> <?php include "menu.php"; ?>
<table width="644" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="549"><h3 align="center">KELOLA PESANAN </h3> <p align="center"> </p>
(18)
90
cellspacing="0"> <tr bgcolor="#FFFF99">
<td width="49" height="25"><div align="center"><strong>No Order</strong></div></td>
<td width="200"><div align="center"><strong>Nama Konsumen</strong></div></td>
<td width="170"><div align="center"><strong>Tgl Order</strong></div></td>
<td width="78"><div align="center"><strong>Jam</strong></div></td> <td width="60"><div
align="center"><strong>Status</strong></div></td> <td width="60"><div
align="center"><strong>Aksi</strong></div></td> </tr>
<?php
$sql="SELECT * FROM orders ORDER BY id_orders DESC";
$query=mysql_query($sql); $no=1;
while($data=mysql_fetch_array($query)){
$tanggal=tgl_indo($data['tgl_order']); ?>
<tr>
<td><div align="center"><?php echo $data['id_orders']; ?></div></td>
<td><?php echo $data['nama_kustomer']; ?></td> <td><?php echo $tanggal; ?></td>
<td><?php echo $data['jam_order']; ?></td> <td><div
align="center"><?php echo $data['status_order']; ?></div></td>
<td><div align="center"><a
href="detail_order.php?id_orders=<?php echo $data['id_orders']; ?>"><img src="../gambar/button-edit.gif" width="20" height="20" /></a>
<a
href="javascript:if(confirm('Anda yakin akan menghapus data
ini??')){document.location='hapus_order.php?id_orders=<?ph p echo $data['id_orders']; ?>';}"><img
src="../gambar/button-cross.gif" width="20" height="20" /></a></div></td>
</tr>
<?php $no++;}?> </table>
<p align="center"> </p> <p> </p>
</td> </tr> </table>
<div class="px" align="center"><img
src="../gambar/bot01.jpg" width="780" height="9" alt="" border="0"></div>
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
(19)
91
<tr>
<td><p align="center">
<?php include "footer.php"; ?> </p></td>
<td height="50"> <p class="bot"> </p>
</td> </tr>
</table> </td>
<td valign="bottom"
background="../gambar/bg_right.gif"><img
src="../gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr> </table> </body> </html> <?php } else {
// jika levelnya bukan admin, tampilkan pesan echo "<script>alert('Sorry ya Coy.. Anda bukan admin');javascript:history.go(-1);</script>";
} } else {
echo "<script>alert('Eeeh Maling.. Login dulu dong!!');javascript:history.go(-1);</script>"; }
?>
Kode Website
8 Fungsi Produk Admin
<?php
error_reporting(E_ALL ^ E_NOTICE); session_start();
include "../include/koneksi.php"; include "../include/fungsi_seo.php"; if (isset($_SESSION['level']) && isset($_SESSION['username'])) {
if ($_SESSION['level'] == "admin") {
if(isset($_POST['simpan'])){ $id_kategori=$_POST['id_kategori']; $nama_produk=$_POST['nama_produk'];
$produk_seo=seo_title($_POST['nama_produk']); $deskripsi=$_POST['deskripsi'];
(20)
92
$harga=$_POST['harga']; $stok=$_POST['stok']; $tgl_masuk=date("d-m-Y");
$gambar=$_FILES['gambar']['name']; if(strlen($gambar)>0){
if(is_uploaded_file($_FILES['gambar']['tmp_name'])) {
move_uploaded_file($_FILES['gambar']['tmp_name'],". ./gambar/produk/".$gambar);
} }
$a="insert into
produk(id_produk,id_kategori,nama_produk,produk_seo,deskri psi,harga,stok,tgl_masuk,gambar)values('','$id_kategori',' $nama_produk','$produk_seo','$deskripsi','$harga','$stok', '$tgl_masuk','$gambar')";
$b=mysql_query($a); if($b){
echo "<script type='text/javascript'> onload =function(){
alert('Produk telah tersimpan'); }
</script>"; }else{
echo "<script type='text/javascript'> onload =function(){
alert('Produk gagal disimpan'); }
</script>"; }
}
//Proses edit
//tampilkan data yang diedit $id_produk=$_GET['id_produk'];
$sql="select * from produk where id_produk='$id_produk'"; $query=mysql_query($sql);
$baris=mysql_fetch_array($query); if(isset($_POST['Edit'])){
$id_kategori=$_POST['id_kategori']; $nama_produk=$_POST['nama_produk'];
$produk_seo=seo_title($_POST['nama_produk']); $deskripsi=$_POST['deskripsi'];
$harga=$_POST['harga']; $stok=$_POST['stok']; $tgl_masuk=date("d-m-Y");
$gambar=$_FILES['gambar']['name']; if(strlen($gambar)>0){
if(is_uploaded_file($_FILES['gambar']['tmp_name'])) {
move_uploaded_file($_FILES['gambar']['tmp_name'],". ./gambar/produk/".$gambar);
}
mysql_query("update produk set gambar='$gambar' where id_produk='$id_produk'");
}
$a="Update produk set
id_kategori='$id_kategori',nama_produk='$nama_produk',prod uk_seo='$produk_seo',deskripsi='$deskripsi',harga='$harga'
(21)
93
,stok='$stok',tgl_masuk='$tgl_masuk' where id_produk='$id_produk'";
$b=mysql_query($a); if($b){
header("location:produk.php"); }else{
echo "<script type='text/javascript'> onload =function(){
alert('Produk gagal diubah!'); }
</script>"; }
} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Administrator Area - Kelola Berita</title> <!-- TinyMCE -->
<script language="javascript" type="text/javascript" src="../tinymcpuk/tiny_mce.js"></script>
<script language="javascript" type="text/javascript"> tinyMCE.init({
mode : "textareas", theme : "advanced", plugins :
"table,save,advhr,advimage,advlink,emotions,iespell,insert datetime,preview,zoom,flash,searchreplace,print,paste,dire ctionality,fullscreen,noneditable,contextmenu",
theme_advanced_buttons1_add_before : "save,newdocument,separator",
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
theme_advanced_buttons2_add :
"separator,insertdate,inserttime,preview,zoom,separator,fo recolor,backcolor,liststyle",
theme_advanced_buttons2_add_before:
"cut,copy,paste,pastetext,pasteword,separator,search,repla ce,separator",
theme_advanced_buttons3_add_before : "tablecontrols,separator",
theme_advanced_buttons3_add :
"emotions,iespell,flash,advhr,separator,print,separator,lt r,rtl,separator,fullscreen",
theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom",
plugin_insertdate_dateFormat : "%Y-%m-%d", plugin_insertdate_timeFormat : "%H:%M:%S", extended_valid_elements :
"hr[class|width|size|noshade]",
(22)
94
"fileBrowserCallBack",
paste_use_dialog : false, theme_advanced_resizing : true,
theme_advanced_resize_horizontal : false, theme_advanced_link_targets :
"_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
apply_source_formatting : true });
function fileBrowserCallBack(field_name, url, type, win) {
var connector =
"../../filemanager/browser.html?Connector=connectors/php/c onnector.php";
var enableAutoTypeSelection = true; var cType;
tinymcpuk_field = field_name; tinymcpuk = win;
switch (type) { case "image":
cType = "Image"; break;
case "flash":
cType = "Flash"; break;
case "file":
cType = "File"; break;
}
if (enableAutoTypeSelection && cType) { connector += "&Type=" + cType; }
window.open(connector, "tinymcpuk", "modal,width=600,height=400");
} </script>
<!-- /TinyMCE --> </head>
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="83%">
<tr>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
<td valign="bottom"
background="../gambar/bg_left.gif"><img
src="../gambar/bg_left.gif" alt="" width="17" height="16" border="0"></td>
<td><table width="780" border="0" cellspacing="0" cellpadding="0">
(23)
95
<td><?php include "header.php"; ?></td> </tr>
<tr>
<td background="../gambar/fon02.gif" height="34"><div align="center"></div></td>
</tr> </table>
<p align="center" class="px"> <?php include "menu.php"; ?>
<table width="644" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="549"><h3 align="center">KELOLA PRODUK </h3> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="600" border="0" align="center"> <tr>
<td><strong>Kategori</strong></td> <td><label>
<?php
echo "<select name='id_kategori' id='id_kategori'>"; $kategori=mysql_query("select * from kategori"); while($data=mysql_fetch_array($kategori)){ $pilih =
($baris['id_kategori']==$data['id_kategori'])?"selected" : "";
echo"<option value=\"$data[id_kategori]\" $pilih>$data[nama_kategori]</option>"; }
?> </select> </label></td>
</tr> <tr>
<td width="98"><strong>Nama Produk </strong></td> <td width="295"><label>
<input name="nama_produk" type="text" id="nama_produk" size="50" value="<?php echo $baris['nama_produk'];?>"/> </label></td>
</tr> <tr>
<td><strong>Deskripsi</strong></td> <td><label>
<textarea name="deskripsi" cols="80" rows="15" id="deskripsi"><?php echo
$baris['deskripsi'];?></textarea> </label></td>
</tr>
<tr> <td><strong>Harga</strong></td> <td>Rp <label>
<input name="harga" type="text" id="harga" value="<?php echo $baris['harga'];?>"/></label></td>
</tr>
<tr> <td><strong>Stok</strong></td> <td><label>
<input name="stok" type="text" id="stok" value="<?php echo $baris['stok'];?>" />
</label></td> </tr>
(24)
96
<tr>
<td><strong>Gambar</strong></td> <td><label>
<?php if($_GET['id_produk']){ //tampilkan foto saat mau ngedit
echo "<img src='../gambar/produk/$baris[gambar]' width=150 height=110><br />";
} ?>
<input name="gambar" type="file" id="gambar" /> </label></td>
</tr><tr> <td> </td> <td><label>
<?php if(!$_GET['id_produk']){
//bila mau tambah data yang tampil tombol simpan
echo "<input name=\"simpan\" type=\"submit\" id=\"simpan\" value=\"Simpan\" /> ";
echo "<input name=\"batal\" type=\"reset\" id=\"batal\" value=\"Batal\" />";
} else {
//Apabila mau edit yg tampil tombol edit dan hapus echo "<input name=\"Edit\" type=\"submit\" id=\"edit\" value=\"Edit\" />";
} ?>
</label></td> </tr>
</table> </form>
<p align="center"><strong>Tabel Produk
</strong></p><table width="635" border="1" align="center" cellspacing="0">
<tr bgcolor="#FFFF99">
<td width="29" height="25"><div
align="center"><strong>No</strong></div></td> <td width="199"><div
align="center"><strong>Nama_Produk</strong></div></td> <td width="123">
<p align="center"><strong>Kategori</strong></p></td> <td width="93"><div
align="center"><strong>Harga</strong></div></td> <td width="39"><div
align="center"><strong>Stok</strong></div></td> <td width="64"><div align="center"><strong>Tgl Masuk</strong></div></td>
<td width="58"><div
align="center"><strong>Aksi</strong></div></td> </tr>
<?php
$sql="select * from produk,kategori where
produk.id_kategori=kategori.id_kategori order by id_produk DESC";
$query=mysql_query($sql); $no=1;
while($data=mysql_fetch_array($query)){ ?>
<tr>
(25)
97
<td><?php echo $data['nama_produk']; ?></td> <td><?php echo $data['nama_kategori']; ?></td> <td>Rp <?php echo $data['harga']; ?></td>
<td><div align="center"><?php echo $data['stok']; ?></div></td>
<td><div align="center"><?php echo $data['tgl_masuk']; ?></div></td>
<td><div align="center"><a
href="produk.php?id_produk=<?php echo $data['id_produk']; ?>"><img src="../gambar/button-edit.gif" width="20" height="20" /></a>
<a href="javascript:if(confirm('Anda yakin akan menghapus data
ini??')){document.location='hapus_produk.php?id_produk=<?p hp echo $data['id_produk']; ?>';}"><img
src="../gambar/button-cross.gif" width="20" height="20" /></a></div></td>
</tr>
<?php $no++;}?> </table>
<p align="center"> </p> <p> </p>
</td> </tr> </table>
<div class="px" align="center"><img
src="../gambar/bot01.jpg" width="780" height="9" alt="" border="0"></div>
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
<tr>
<td><p align="center">
<?php include "footer.php"; ?> </p></td>
<td height="50">
<p class="bot"> </p> </td>
</tr> </table> </td>
<td valign="bottom"
background="../gambar/bg_right.gif"><img
src="../gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr> </table> </body> </html> <?php } else {
// jika levelnya bukan admin, tampilkan pesan echo "<script>alert('Sorry ya Coy.. Anda bukan admin');javascript:history.go(-1);</script>";
(26)
98
} } else {
echo "<script>alert('Eeeh Maling.. Login dulu dong!!');javascript:history.go(-1);</script>"; }
(27)
(28)
(1)
95
<td><?php include "header.php"; ?></td> </tr>
<tr>
<td background="../gambar/fon02.gif" height="34"><div align="center"></div></td>
</tr> </table>
<p align="center" class="px"> <?php include "menu.php"; ?>
<table width="644" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="549"><h3 align="center">KELOLA PRODUK </h3> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="600" border="0" align="center"> <tr>
<td><strong>Kategori</strong></td> <td><label>
<?php
echo "<select name='id_kategori' id='id_kategori'>"; $kategori=mysql_query("select * from kategori"); while($data=mysql_fetch_array($kategori)){ $pilih = ($baris['id_kategori']==$data['id_kategori'])?"selected" : ""; echo"<option value=\"$data[id_kategori]\" $pilih>$data[nama_kategori]</option>"; } ?> </select> </label></td>
</tr> <tr>
<td width="98"><strong>Nama Produk </strong></td> <td width="295"><label>
<input name="nama_produk" type="text" id="nama_produk" size="50" value="<?php echo $baris['nama_produk'];?>"/> </label></td>
</tr> <tr>
<td><strong>Deskripsi</strong></td> <td><label>
<textarea name="deskripsi" cols="80" rows="15" id="deskripsi"><?php echo
$baris['deskripsi'];?></textarea> </label></td>
</tr>
<tr> <td><strong>Harga</strong></td> <td>Rp <label>
<input name="harga" type="text" id="harga" value="<?php echo $baris['harga'];?>"/></label></td>
</tr>
<tr> <td><strong>Stok</strong></td> <td><label>
<input name="stok" type="text" id="stok" value="<?php echo $baris['stok'];?>" />
</label></td> </tr>
(2)
96
<tr>
<td><strong>Gambar</strong></td> <td><label>
<?php if($_GET['id_produk']){ //tampilkan foto saat mau ngedit
echo "<img src='../gambar/produk/$baris[gambar]' width=150 height=110><br />";
} ?>
<input name="gambar" type="file" id="gambar" /> </label></td>
</tr><tr> <td> </td> <td><label>
<?php if(!$_GET['id_produk']){
//bila mau tambah data yang tampil tombol simpan
echo "<input name=\"simpan\" type=\"submit\" id=\"simpan\" value=\"Simpan\" /> ";
echo "<input name=\"batal\" type=\"reset\" id=\"batal\" value=\"Batal\" />";
} else {
//Apabila mau edit yg tampil tombol edit dan hapus echo "<input name=\"Edit\" type=\"submit\" id=\"edit\" value=\"Edit\" />"; } ?> </label></td> </tr> </table> </form>
<p align="center"><strong>Tabel Produk
</strong></p><table width="635" border="1" align="center" cellspacing="0">
<tr bgcolor="#FFFF99">
<td width="29" height="25"><div
align="center"><strong>No</strong></div></td> <td width="199"><div align="center"><strong>Nama_Produk</strong></div></td> <td width="123"> <p align="center"><strong>Kategori</strong></p></td> <td width="93"><div align="center"><strong>Harga</strong></div></td> <td width="39"><div align="center"><strong>Stok</strong></div></td> <td width="64"><div align="center"><strong>Tgl Masuk</strong></div></td>
<td width="58"><div
align="center"><strong>Aksi</strong></div></td> </tr>
<?php
$sql="select * from produk,kategori where
produk.id_kategori=kategori.id_kategori order by id_produk DESC"; $query=mysql_query($sql); $no=1; while($data=mysql_fetch_array($query)){ ?> <tr>
(3)
97
<td><?php echo $data['nama_produk']; ?></td> <td><?php echo $data['nama_kategori']; ?></td> <td>Rp <?php echo $data['harga']; ?></td>
<td><div align="center"><?php echo $data['stok']; ?></div></td>
<td><div align="center"><?php echo $data['tgl_masuk']; ?></div></td>
<td><div align="center"><a
href="produk.php?id_produk=<?php echo $data['id_produk']; ?>"><img src="../gambar/button-edit.gif" width="20" height="20" /></a>
<a href="javascript:if(confirm('Anda yakin akan menghapus data
ini??')){document.location='hapus_produk.php?id_produk=<?p hp echo $data['id_produk']; ?>';}"><img
src="../gambar/button-cross.gif" width="20" height="20" /></a></div></td> </tr> <?php $no++;}?> </table> <p align="center"> </p> <p> </p> </td> </tr> </table>
<div class="px" align="center"><img
src="../gambar/bot01.jpg" width="780" height="9" alt="" border="0"></div>
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
<tr>
<td><p align="center">
<?php include "footer.php"; ?> </p></td> <td height="50"> <p class="bot"> </p> </td> </tr> </table> </td> <td valign="bottom" background="../gambar/bg_right.gif"><img
src="../gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td> </tr> </table> </body> </html> <?php } else {
// jika levelnya bukan admin, tampilkan pesan echo "<script>alert('Sorry ya Coy.. Anda bukan admin');javascript:history.go(-1);</script>";
(4)
98
} } else {
echo "<script>alert('Eeeh Maling.. Login dulu dong!!');javascript:history.go(-1);</script>"; }
(5)
(6)