diff --git a/IF3110-Tubes-I.zip b/IF3110-Tubes-I.zip new file mode 100644 index 0000000..9bed938 Binary files /dev/null and b/IF3110-Tubes-I.zip differ diff --git a/MEMBER.md b/MEMBER.md new file mode 100644 index 0000000..bdbadea --- /dev/null +++ b/MEMBER.md @@ -0,0 +1,5 @@ +Data Kelompok +============= + +Okaswara Perkasa - 13510051 - 13510051 di std.stei.itb.ac.id - okaswara-p +Sandy Gunawan Tanuwijaya - 13510025 - 13510025 di std.stei.itb.ac.id - 4XPG diff --git a/db/readme.txt b/db/readme.txt new file mode 100644 index 0000000..98f8a6f --- /dev/null +++ b/db/readme.txt @@ -0,0 +1,5 @@ +Gunakan file ruserba.sql sebagai source pembuatan database, BUKAN ruserba_original.sql. +Lakukan create database terlebih dahulu dengan nama database: "ruserba". + +Tambahan: +Password untuk user John Smith: "letmein" (dalam database disimpan dalam bentuk MD5) diff --git a/db/ruserba.sql b/db/ruserba.sql new file mode 100644 index 0000000..588e300 --- /dev/null +++ b/db/ruserba.sql @@ -0,0 +1,123 @@ +-- MySQL dump 10.13 Distrib 5.5.32, for Win32 (x86) +-- +-- Host: localhost Database: ruserba +-- ------------------------------------------------------ +-- Server version 5.5.32 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `barang` +-- + +DROP TABLE IF EXISTS `barang`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `barang` ( + `id_barang` int(11) NOT NULL AUTO_INCREMENT, + `id_kategori` int(11) NOT NULL, + `nama_barang` varchar(256) NOT NULL, + `harga` int(11) NOT NULL, + `satuan` varchar(32) NOT NULL, + `deskripsi` varchar(1024) DEFAULT NULL, + `jumlah_pembelian` int(11) DEFAULT '0', + `jumlah_stok` int(11) DEFAULT '0', + `nama_gambar` varchar(256) NOT NULL, + `nama_gambar_thumb` varchar(256) NOT NULL, + PRIMARY KEY (`id_barang`), + KEY `id_kategori` (`id_kategori`), + CONSTRAINT `barang_ibfk_1` FOREIGN KEY (`id_kategori`) REFERENCES `kategori` (`id_kategori`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `barang` +-- + +LOCK TABLES `barang` WRITE; +/*!40000 ALTER TABLE `barang` DISABLE KEYS */; +INSERT INTO `barang` VALUES (1,4,'Apel',3390,'100 gram','Buah yang berkhasiat untuk menjauhkan dokter dari Anda.',43,73,'buah_apel.jpg','buah_apel_thumb.jpg'),(2,3,'Brokoli',1390,'100 gram','Sayuran yang mengandung banyak vitamin C dan serat. Menurut Wikipedia, sebaiknya diolah dengan cara dikukus agar nutrisinya tetap terjaga.',24,16,'sayur_brokoli.jpg','sayur_brokoli_thumb.jpg'),(3,1,'Beras',8900,'kilogram','Makanan pokok',53,134,'beras_putih.jpg','beras_putih_thumb.jpg'),(4,4,'Ceri',2300,'100 gram','Deskripsi ceri disini.',85,41,'buah_cherry.jpg','buah_cherry_thumb.jpg'),(5,4,'Durian',2900,'100 gram','Deskripsi durian disini.',41,42,'buah_durian.jpg','buah_durian_thumb.jpg'),(6,4,'Jambu batu',2490,'100 gram','Deskripsi jambu batu disini.',35,31,'buah_jambubatu.jpg','buah_jambubatu_thumb.jpg'),(7,4,'Jeruk',3280,'100 gram','Deskripsi jeruk disini.',53,31,'buah_jeruk.jpg','buah_jeruk_thumb.jpg'),(8,4,'Kiwi',5190,'100 gram','Deskripsi kiwi disini.',56,56,'buah_kiwi.jpg','buah_kiwi_thumb.jpg'),(9,4,'Mangga',2390,'100 gram','Deskripsi mangga disini.',73,76,'buah_mangga.jpg','buah_mangga_thumb.jpg'),(10,4,'Manggis',2290,'100 gram','Deskripsi manggis disini.',86,24,'buah_manggis.jpg','buah_manggis_thumb.jpg'),(11,4,'Melon',2470,'100 gram','Deskripsi melon disini.',41,41,'buah_melon.jpg','buah_melon_thumb.jpg'),(12,4,'Nanas',3190,'100 gram','Deskripsi nanas disini.',96,67,'buah_nanas.jpg','buah_nanas_thumb.jpg'),(13,4,'Pisang',2340,'100 gram','Deskripsi pisang disini.',45,87,'buah_pisang.jpg','buah_pisang_thumb.jpg'),(14,4,'Semangka',3500,'100 gram','Deskripsi semangka disini.',65,31,'buah_semangka.jpg','buah_semangka_thumb.jpg'),(15,4,'Stroberi',4120,'100 gram','Deskripsi stroberi disini.',32,41,'buah_stroberi.jpg','buah_stroberi_thumb.jpg'),(16,4,'Zaitun',2340,'100 gram','Deskripsi zaitun disini.',52,23,'buah_zaitun.jpg','buah_zaitun_thumb.jpg'),(17,1,'Kacang hijau',2320,'100 gram','Kacang hijau baik untuk kesehatan.',41,49,'kacang_hijau.jpg','kacang_hijau_thumb.jpg'),(18,1,'Beras merah',3890,'100 gram','Deskripsi untuk beras merah disini',34,41,'beras_merah.jpg','beras_merah_thumb.jpg'),(19,5,'Bawang putih',2340,'100 gram','Deskripsi untuk bawang putih disini',34,41,'bumbu_bawangputih.jpg','bumbu_bawangputih_thumb.jpg'),(20,5,'Bawang merah',2190,'100 gram','Deskripsi untuk bawang merah disini',41,87,'bumbu_bawangmerah.jpg','bumbu_bawangmerah_thumb.jpg'),(21,5,'Kayu manis',3430,'100 gram','Deskripsi untuk kayu manis disini',12,32,'bumbu_kayumanis.jpg','bumbu_kayumanis_thumb.jpg'),(22,2,'Daging ayam',4290,'100 gram','Deskripsi untuk daging ayam disini',76,46,'daging_ayam.jpg','daging_ayam_thumb.jpg'),(23,2,'Daging sapi',6890,'100 gram','Deskripsi untuk daging sapi disini',32,21,'daging_sapi.jpg','daging_sapi_thumb.jpg'),(24,2,'Daging ikan',5470,'100 gram','Deskripsi untuk daging ikan disini',67,32,'daging_ikan.jpg','daging_ikan_thumb.jpg'),(25,3,'Bayam',3290,'100 gram','Deskripsi untuk bayam disini',58,32,'sayur_bayam_hijau.jpg','sayur_bayam_hijau_thumb.jpg'),(26,3,'Buncis',2990,'100 gram','Deskripsi untuk buncis disini',46,31,'sayur_buncis.jpg','sayur_buncis_thumb.jpg'); +/*!40000 ALTER TABLE `barang` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `kategori` +-- + +DROP TABLE IF EXISTS `kategori`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `kategori` ( + `id_kategori` int(11) NOT NULL AUTO_INCREMENT, + `nama_kategori` varchar(256) NOT NULL, + PRIMARY KEY (`id_kategori`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `kategori` +-- + +LOCK TABLES `kategori` WRITE; +/*!40000 ALTER TABLE `kategori` DISABLE KEYS */; +INSERT INTO `kategori` VALUES (1,'Beras dan kacang-kacangan'),(2,'Daging dan telur'),(3,'Sayur-mayur'),(4,'Buah-buahan'),(5,'Bumbu dapur'); +/*!40000 ALTER TABLE `kategori` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user` ( + `id_user` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(256) NOT NULL, + `email` varchar(256) NOT NULL, + `password` varchar(256) NOT NULL, + `nama_lengkap` varchar(256) NOT NULL, + `provinsi` varchar(256) DEFAULT NULL, + `kota` varchar(256) DEFAULT NULL, + `alamat` varchar(32) DEFAULT NULL, + `kode_pos` varchar(32) DEFAULT NULL, + `kontak` varchar(32) DEFAULT NULL, + `nomor_kartu` varchar(256) DEFAULT NULL, + `nama_kartu` varchar(256) DEFAULT NULL, + `ekspirasi_kartu` date DEFAULT NULL, + `admin` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id_user`), + UNIQUE KEY `username` (`username`), + UNIQUE KEY `email` (`email`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user` +-- + +LOCK TABLES `user` WRITE; +/*!40000 ALTER TABLE `user` DISABLE KEYS */; +INSERT INTO `user` VALUES (1,'johnny','john@yahoo.com','0d107d09f5bbe40cade3de5c71e9e9b7','John Smith','Jawa Barat','Bandung','Jl. Ganeca No.42A','14562','081347556202','3141-5156-1425-5421','John Smith','2016-09-01',0); +/*!40000 ALTER TABLE `user` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2013-11-27 18:47:08 diff --git a/db/ruserba_original.sql b/db/ruserba_original.sql new file mode 100644 index 0000000..9548ce4 --- /dev/null +++ b/db/ruserba_original.sql @@ -0,0 +1,39 @@ +create table user( + id_user int auto_increment, + username varchar(256) not null, + email varchar(256) not null, + password varchar(256) not null, + nama_lengkap varchar(256) not null, + provinsi varchar(256) default null, + kota varchar(256) default null, + alamat varchar(32) default null, + kode_pos varchar(32) default null, + kontak varchar(32) default null, + nomor_kartu varchar(256) default null, + nama_kartu varchar(256) default null, + ekspirasi_kartu date default null, + primary key(user_id), + unique(username), + unique(email) +); + +create table kategori( + id_kategori int auto_increment, + nama_kategori varchar(256) not null, + primary key(id_kategori) +); + +create table barang( + id_barang int auto_increment, + id_kategori int not null, + nama_barang varchar(256) not null, + harga int not null, + satuan varchar(32) not null, + deskripsi varchar(1024) default null, + jumlah_pembelian int default 0, + jumlah_stok int default 0, + nama_gambar varchar(256) not null, + nama_gambar_thumb varchar(256) not null, + primary key(id_barang), + foreign key(id_kategori) references kategori(id_kategori) on delete cascade on update cascade +); diff --git a/src/classes/com/ruserba/model/Category.class b/src/classes/com/ruserba/model/Category.class new file mode 100644 index 0000000..332be94 Binary files /dev/null and b/src/classes/com/ruserba/model/Category.class differ diff --git a/src/classes/com/ruserba/model/Database.class b/src/classes/com/ruserba/model/Database.class new file mode 100644 index 0000000..13ed5ed Binary files /dev/null and b/src/classes/com/ruserba/model/Database.class differ diff --git a/src/classes/com/ruserba/model/Product.class b/src/classes/com/ruserba/model/Product.class new file mode 100644 index 0000000..53c3c66 Binary files /dev/null and b/src/classes/com/ruserba/model/Product.class differ diff --git a/src/classes/com/ruserba/model/SearchAttribute.class b/src/classes/com/ruserba/model/SearchAttribute.class new file mode 100644 index 0000000..0d26f72 Binary files /dev/null and b/src/classes/com/ruserba/model/SearchAttribute.class differ diff --git a/src/classes/com/ruserba/model/User.class b/src/classes/com/ruserba/model/User.class new file mode 100644 index 0000000..6c8b72b Binary files /dev/null and b/src/classes/com/ruserba/model/User.class differ diff --git a/src/classes/com/ruserba/web/CheckUsernameService.class b/src/classes/com/ruserba/web/CheckUsernameService.class new file mode 100644 index 0000000..fa6112a Binary files /dev/null and b/src/classes/com/ruserba/web/CheckUsernameService.class differ diff --git a/src/classes/com/ruserba/web/CobaServlet.class b/src/classes/com/ruserba/web/CobaServlet.class new file mode 100644 index 0000000..581ae5f Binary files /dev/null and b/src/classes/com/ruserba/web/CobaServlet.class differ diff --git a/src/classes/com/ruserba/web/DatabaseInit.class b/src/classes/com/ruserba/web/DatabaseInit.class new file mode 100644 index 0000000..77f00b0 Binary files /dev/null and b/src/classes/com/ruserba/web/DatabaseInit.class differ diff --git a/src/classes/com/ruserba/web/LoginService.class b/src/classes/com/ruserba/web/LoginService.class new file mode 100644 index 0000000..adb6cba Binary files /dev/null and b/src/classes/com/ruserba/web/LoginService.class differ diff --git a/src/classes/com/ruserba/web/RegisterUserService.class b/src/classes/com/ruserba/web/RegisterUserService.class new file mode 100644 index 0000000..519c5e7 Binary files /dev/null and b/src/classes/com/ruserba/web/RegisterUserService.class differ diff --git a/src/classes/com/ruserba/web/WebUtil.class b/src/classes/com/ruserba/web/WebUtil.class new file mode 100644 index 0000000..82ff5de Binary files /dev/null and b/src/classes/com/ruserba/web/WebUtil.class differ diff --git a/src/compile.bat b/src/compile.bat new file mode 100644 index 0000000..0511eb6 --- /dev/null +++ b/src/compile.bat @@ -0,0 +1 @@ +javac -cp .;C:\xampp\tomcat\lib\servlet-api.jar;classes -d classes src\com\ruserba\web\*.java src\com\ruserba\model\*.java diff --git a/src/compile_install.bat b/src/compile_install.bat new file mode 100644 index 0000000..d0cf559 --- /dev/null +++ b/src/compile_install.bat @@ -0,0 +1,2 @@ +call compile.bat +call install.bat diff --git a/src/etc/web.xml b/src/etc/web.xml new file mode 100644 index 0000000..58fcb30 --- /dev/null +++ b/src/etc/web.xml @@ -0,0 +1,63 @@ + + + + db_url + jdbc:mysql://localhost/ + + + db_name + ruserba + + + db_username + root + + + db_password + + + + + Login + com.ruserba.web.LoginService + + + Login + /login + + + + CobaServlet + com.ruserba.web.CobaServlet + + + CobaServlet + /cobaservlet + + + + CheckUsername + com.ruserba.web.CheckUsernameService + + + CheckUsername + /checkusername + + + + RegisterUser + com.ruserba.web.RegisterUserService + + + RegisterUser + /registeruser + + + +com.ruserba.web.DatabaseInit + + + diff --git a/src/install.bat b/src/install.bat new file mode 100644 index 0000000..64ebf3d --- /dev/null +++ b/src/install.bat @@ -0,0 +1,8 @@ +set webappdir=C:\xampp\tomcat\webapps\ruserba +rmdir %webappdir% /S /Q +mkdir %webappdir% +xcopy classes\* %webappdir%\WEB-INF\classes\ /E /Y /I +xcopy web\* %webappdir%\ /E /Y /I +xcopy lib\* %webappdir%\WEB-INF\lib\ /E /Y /I +xcopy jsp\* %webappdir%\WEB-INF\jsp\ /E /Y /I +xcopy etc\web.xml %webappdir%\WEB-INF\ /I /Y diff --git a/src/jsp/Readme.txt b/src/jsp/Readme.txt new file mode 100644 index 0000000..4e08a86 --- /dev/null +++ b/src/jsp/Readme.txt @@ -0,0 +1 @@ +This is folder for private JSP files. (will be installed to WEB-INF/jsp directory) \ No newline at end of file diff --git a/src/jsp/begin.jsp b/src/jsp/begin.jsp new file mode 100644 index 0000000..76ceccf --- /dev/null +++ b/src/jsp/begin.jsp @@ -0,0 +1,62 @@ +<%-- + Input Specs + ----------- + + page_title: Title dari halaman, dalam string. + css_file: File CSS custom, dalam string/arraylist. + js_file: File javascript custom, dalam string/arraylist. + + Semua dalam attribute, bukan parameter. +--%> + +<%@ page import="java.util.ArrayList" %> + + + + + + <%= (String)request.getAttribute("page_title") %> + + + <% + // Urus custom CSS dan javascript. + ArrayList css_file; + ArrayList js_file; + int css_cnt = 0, js_cnt = 0; + + if (request.getAttribute("css_file") instanceof String) + { + css_file = new ArrayList(); + css_file.add((String)request.getAttribute("css_file")); + } + else + { + css_file = (ArrayList)request.getAttribute("css_file"); + } + if (request.getAttribute("js_file") instanceof String) + { + js_file = new ArrayList(); + js_file.add((String)request.getAttribute("js_file")); + } + else + { + js_file = (ArrayList)request.getAttribute("js_file"); + } + + if (css_file != null) css_cnt = css_file.size(); + for (int i = 0; i < css_cnt; i++) + { + out.write(""); + } + + if (js_file != null) js_cnt = js_file.size(); + for (int i = 0; i < js_cnt; i++) + { + out.write(""); + } + %> + +
+
+ +
diff --git a/src/jsp/coba.jsp b/src/jsp/coba.jsp new file mode 100644 index 0000000..ca16b86 --- /dev/null +++ b/src/jsp/coba.jsp @@ -0,0 +1,5 @@ +<% + request.setAttribute("msg", "Halo dunia! Pesan ini datang dari JSP attribute."); + RequestDispatcher disp = request.getRequestDispatcher("/hello.jsp"); + disp.forward(request, response); +%> diff --git a/src/jsp/end.jsp b/src/jsp/end.jsp new file mode 100644 index 0000000..a9d5f4f --- /dev/null +++ b/src/jsp/end.jsp @@ -0,0 +1,8 @@ +
+ +
+ + + diff --git a/src/jsp/header.jsp b/src/jsp/header.jsp new file mode 100644 index 0000000..f85db21 --- /dev/null +++ b/src/jsp/header.jsp @@ -0,0 +1,75 @@ +<%@ page import="com.ruserba.model.Database" %> +<%@ page import="com.ruserba.model.Category" %> +<%@ page import="java.util.ArrayList" %> + +<% + Database db = (Database)application.getAttribute("db"); + ArrayList cat_list = db.getCategory(); +%> + + diff --git a/src/jsp/product_browse.jsp b/src/jsp/product_browse.jsp new file mode 100644 index 0000000..a38b38d --- /dev/null +++ b/src/jsp/product_browse.jsp @@ -0,0 +1,15 @@ +<%@ page import="com.ruserba.web.WebUtil" %> + + + +
+ + <%= produk.getNamaBarang() %> + + + <%= produk.getNamaBarang() %>
Rp <%= produk.getHarga() %>,00 / <%= produk.getSatuan() %> +
+ + Total penjualan: <%= produk.getJumlahPembelian() %> unit + +
diff --git a/src/jsp/product_category.jsp b/src/jsp/product_category.jsp new file mode 100644 index 0000000..5dcf270 --- /dev/null +++ b/src/jsp/product_category.jsp @@ -0,0 +1,35 @@ +<%@ page import="com.ruserba.web.WebUtil" %> + + + + +
+ + <%= produk.getNamaBarang() %> + + + <%= produk.getNamaBarang() %>
Rp <%= produk.getHarga() %>,00 / <%= produk.getSatuan() %> +
+ + /> + + +
+ + +
+
diff --git a/src/lib/mysql-connector-java-5.1.9.jar b/src/lib/mysql-connector-java-5.1.9.jar new file mode 100644 index 0000000..275c28d Binary files /dev/null and b/src/lib/mysql-connector-java-5.1.9.jar differ diff --git a/src/src/com/ruserba/model/Category.java b/src/src/com/ruserba/model/Category.java new file mode 100644 index 0000000..95933c3 --- /dev/null +++ b/src/src/com/ruserba/model/Category.java @@ -0,0 +1,22 @@ +package com.ruserba.model; + +public class Category implements java.io.Serializable { + + private int id_kategori; + private String nama_kategori; + + public int getIdKategori(){ + return this.id_kategori; + } + public void setIdKategori(int id_kategori){ + this.id_kategori = id_kategori; + } + + public String getNamaKategori(){ + return this.nama_kategori; + } + public void setNamaKategori(String nama_kategori){ + this.nama_kategori = nama_kategori; + } + +} \ No newline at end of file diff --git a/src/src/com/ruserba/model/Database.java b/src/src/com/ruserba/model/Database.java new file mode 100644 index 0000000..3481a27 --- /dev/null +++ b/src/src/com/ruserba/model/Database.java @@ -0,0 +1,243 @@ +package com.ruserba.model; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.PreparedStatement; + +import java.util.ArrayList; + +public class Database { + + public static final int COMP_LT = 1; + public static final int COMP_LTE = 2; + public static final int COMP_GT = 3; + public static final int COMP_GTE = 4; + public static final int SORT_ASC = 1; + public static final int SORT_DESC = 2; + public static final int ORDERBY_PRODUCTNAME = 1; + public static final int ORDERBY_PRICE = 2; + public static final int ORDERBY_SOLDQTY = 3; + + private Connection conn = null; + + public Database(String url, String user_name, String password) + { + try { + Class.forName("com.mysql.jdbc.Driver"); + this.conn = DriverManager.getConnection(url, user_name, password); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // Untuk custom query. + public Connection getConnection() + { + return this.conn; + } + + // Untuk custom query. + // Not recommended. Sebaiknya menggunakan getConnection() + prepared statement. + public ResultSet runQuery(String sql) throws SQLException + { + Statement sta = conn.createStatement(); + return sta.executeQuery(sql); + } + + private Product getProductDataFromResultSet(ResultSet res) throws SQLException + { + // Id produk tidak ditemukan. + if (!res.next()) return null; + + // Dikuli... Semoga nggak ada typo... :p + Product prod = new Product(); + prod.setIdBarang(res.getInt("id_barang")); + prod.setIdKategori(res.getInt("id_kategori")); + prod.setHarga(res.getInt("harga")); + prod.setJumlahPembelian(res.getInt("jumlah_pembelian")); + prod.setJumlahStok(res.getInt("jumlah_stok")); + prod.setNamaBarang(res.getString("nama_barang")); + prod.setSatuan(res.getString("satuan")); + prod.setDeskripsi(res.getString("deskripsi")); + prod.setNamaGambar(res.getString("nama_gambar")); + prod.setNamaGambarThumb(res.getString("nama_gambar_thumb")); + + return prod; + } + + // Mengambil seluruh data produk. + public Product getProductData(int product_id) throws SQLException + { + PreparedStatement stat = getConnection().prepareStatement("select * from barang where id_barang=?"); + stat.setInt(1, product_id); + ResultSet res = stat.executeQuery(); + + return getProductDataFromResultSet(res); + } + + private User getUserDataFromResultSet(ResultSet res) throws SQLException { + // Id produk tidak ditemukan. + if (!res.next()) return null; + + // Dikuli... Lagi... + User user = new User(); + user.setIdUser(res.getInt("id_user")); + user.setUsername(res.getString("username")); + user.setEmail(res.getString("email")); + user.setPassword(res.getString("password")); + user.setNamaLengkap(res.getString("nama_lengkap")); + user.setProvinsi(res.getString("provinsi")); + user.setKota(res.getString("kota")); + user.setAlamat(res.getString("alamat")); + user.setKodePos(res.getString("kode_pos")); + user.setKontak(res.getString("kontak")); + user.setNomorKartu(res.getString("nomor_kartu")); + user.setNamaKartu(res.getString("nama_kartu")); + user.setEkspirasiKartu(res.getString("ekspirasi_kartu")); + + return user; + } + + public User getUserData(int user_id) throws SQLException + { + PreparedStatement stat = getConnection().prepareStatement("select * from user where id_user=?"); + stat.setInt(1, user_id); + ResultSet res = stat.executeQuery(); + + return getUserDataFromResultSet(res); + } + + public User getUserDataFromUsername(String username) throws SQLException + { + PreparedStatement stat = getConnection().prepareStatement("select * from user where username=?"); + stat.setString(1, username); + ResultSet res = stat.executeQuery(); + + return getUserDataFromResultSet(res); + } + + public Category getCategoryData(int category_id) throws SQLException + { + PreparedStatement stat = getConnection().prepareStatement("select * from kategori where id_kategori=?"); + stat.setInt(1, category_id); + ResultSet res = stat.executeQuery(); + + // Id produk tidak ditemukan. + if (!res.next()) return null; + + // Dikuli... Lagi... + Category cat = new Category(); + cat.setIdKategori(res.getInt("id_kategori")); + cat.setNamaKategori(res.getString("nama_kategori")); + + return cat; + } + + public ArrayList getCategory() throws SQLException + { + PreparedStatement stat = getConnection().prepareStatement("select * from kategori"); + ResultSet res = stat.executeQuery(); + + ArrayList lst = new ArrayList(); + while (res.next()) + { + Category cat = new Category(); + cat.setIdKategori(res.getInt("id_kategori")); + cat.setNamaKategori(res.getString("nama_kategori")); + lst.add(cat); + } + return lst; + } + + private String getComparisonString(int compare_id) + { + if (compare_id == COMP_LT) return "<"; + else if (compare_id == COMP_LTE) return "<="; + else if (compare_id == COMP_GT) return ">"; + else if (compare_id == COMP_GTE) return ">="; + else return "<"; + } + + // Diasumsikan query sudah sesuai spesifikasi. + public ArrayList getProductSearchResult(SearchAttribute attr) throws SQLException + { + StringBuilder qb = new StringBuilder(); + + qb.append("select * from barang "); + + ArrayList query_where_lst = new ArrayList(); + if (!attr.getNamaBarang().equals("")) + query_where_lst.add("nama_barang like (\'%" + attr.getNamaBarang() + "%\')"); + if (attr.getIdKategori() > 0) + query_where_lst.add("id_kategori = " + attr.getIdKategori()); + if (attr.getIdPerbandingan() > 0 && attr.getHarga() >= 0) + query_where_lst.add("harga " + getComparisonString(attr.getIdPerbandingan()) + " " + attr.getHarga()); + + // Buat query where. + StringBuilder query_where_strb = new StringBuilder(); + for (int i = 0; i < query_where_lst.size(); i++) + { + if (i != 0) query_where_strb.append(" and "); + query_where_strb.append(query_where_lst.get(i)); + } + String query_where = query_where_strb.toString(); + + ArrayList query_end_lst = new ArrayList(); + String sort_attr; + if (attr.getIdPengurutan() == ORDERBY_PRODUCTNAME) sort_attr = "nama_barang"; + else if (attr.getIdPengurutan() == ORDERBY_PRICE) sort_attr = "harga"; + else if (attr.getIdPengurutan() == ORDERBY_SOLDQTY) sort_attr = "jumlah_pembelian"; + else sort_attr = "nama_barang"; + query_end_lst.add("order by " + sort_attr); + + String sort_method; + if (attr.getIdMetodePengurutan() == SORT_DESC) sort_method = "desc"; + else sort_method = "asc"; + query_end_lst.add(sort_method); + + if (attr.getJumlah() < 0) attr.setJumlah(2147483647); + query_end_lst.add("limit " + attr.getIndeks() + ", " + attr.getJumlah()); + + // Buat query end. + StringBuilder query_end_strb = new StringBuilder(); + for (int i = 0; i < query_end_lst.size(); i++) + { + if (i != 0) query_end_strb.append(" "); + query_end_strb.append(query_end_lst.get(i)); + } + String query_end = query_end_strb.toString(); + + // Append query where. + if (query_where_lst.size() > 0) qb.append("where " + query_where + " "); + + // Tambahkan akhir query. + qb.append(query_end); + + // Ambil hasil dari query. + String final_query = qb.toString(); + + //return final_query; + + PreparedStatement stat = getConnection().prepareStatement(final_query); + ResultSet res = stat.executeQuery(); + + ArrayList prod_list = new ArrayList(); + + while (true) + { + Product prod = getProductDataFromResultSet(res); + if (prod == null) break; + prod_list.add(prod); + } + + return prod_list; + } + +} diff --git a/src/src/com/ruserba/model/Product.java b/src/src/com/ruserba/model/Product.java new file mode 100644 index 0000000..1ee1c44 --- /dev/null +++ b/src/src/com/ruserba/model/Product.java @@ -0,0 +1,86 @@ +package com.ruserba.model; + +public class Product implements java.io.Serializable { + + private int id_barang; + private int id_kategori; + private String nama_barang; + private int harga; + private String satuan; + private String deskripsi; + private int jumlah_pembelian; + private int jumlah_stok; + private String nama_gambar; + private String nama_gambar_thumb; + + public int getIdBarang(){ + return this.id_barang; + } + public void setIdBarang(int id_barang){ + this.id_barang = id_barang; + } + + public int getIdKategori(){ + return this.id_kategori; + } + public void setIdKategori(int id_kategori){ + this.id_kategori = id_kategori; + } + + public int getHarga(){ + return this.harga; + } + public void setHarga(int harga){ + this.harga = harga; + } + + public int getJumlahPembelian(){ + return this.jumlah_pembelian; + } + public void setJumlahPembelian(int jumlah_pembelian){ + this.jumlah_pembelian = jumlah_pembelian; + } + + public int getJumlahStok(){ + return this.jumlah_stok; + } + public void setJumlahStok(int jumlah_stok){ + this.jumlah_stok = jumlah_stok; + } + + public String getNamaBarang(){ + return this.nama_barang; + } + public void setNamaBarang(String nama_barang){ + this.nama_barang = nama_barang; + } + + public String getSatuan(){ + return this.satuan; + } + public void setSatuan(String satuan){ + this.satuan = satuan; + } + + public String getDeskripsi(){ + return this.deskripsi; + } + public void setDeskripsi(String deskripsi){ + this.deskripsi = deskripsi; + } + + public String getNamaGambar(){ + return this.nama_gambar; + } + public void setNamaGambar(String nama_gambar){ + this.nama_gambar = nama_gambar; + } + + public String getNamaGambarThumb(){ + return this.nama_gambar_thumb; + } + public void setNamaGambarThumb(String nama_gambar_thumb){ + this.nama_gambar_thumb = nama_gambar_thumb; + } + +} \ No newline at end of file diff --git a/src/src/com/ruserba/model/SearchAttribute.java b/src/src/com/ruserba/model/SearchAttribute.java new file mode 100644 index 0000000..99d1391 --- /dev/null +++ b/src/src/com/ruserba/model/SearchAttribute.java @@ -0,0 +1,71 @@ +package com.ruserba.model; + +public class SearchAttribute implements java.io.Serializable { + + private String nama_barang; // tidak ada = empty string. + private int id_kategori; // Semua kategori dicari = 0. + private int harga; // Tidak ada harga = (< 0). + private int id_perbandingan; // <, <=, >, <=; 0 jika tidak ada harga. + private int id_pengurutan; // Id product name, id harga; 1 (product name) default. + private int id_metode_pengurutan; // Ascending, descending; 1 (ascending) default. + private int indeks; // Indeks awal yang ditampilkan pada hasil query; 0 default. + private int jumlah; // Jumlah record yang ditampilkan; 3 default. + + public String getNamaBarang(){ + return this.nama_barang; + } + public void setNamaBarang(String nama_barang){ + this.nama_barang = nama_barang; + } + + public int getIdKategori(){ + return this.id_kategori; + } + public void setIdKategori(int id_kategori){ + this.id_kategori = id_kategori; + } + + public int getHarga(){ + return this.harga; + } + public void setHarga(int harga){ + this.harga = harga; + } + + public int getIdPerbandingan(){ + return this.id_perbandingan; + } + public void setIdPerbandingan(int id_perbandingan){ + this.id_perbandingan = id_perbandingan; + } + + public int getIdPengurutan(){ + return this.id_pengurutan; + } + public void setIdPengurutan(int id_pengurutan){ + this.id_pengurutan = id_pengurutan; + } + + public int getIdMetodePengurutan(){ + return this.id_metode_pengurutan; + } + public void setIdMetodePengurutan(int id_metode_pengurutan){ + this.id_metode_pengurutan = id_metode_pengurutan; + } + + public int getIndeks(){ + return this.indeks; + } + public void setIndeks(int indeks){ + this.indeks = indeks; + } + + public int getJumlah(){ + return this.jumlah; + } + public void setJumlah(int jumlah){ + this.jumlah = jumlah; + } + + +} \ No newline at end of file diff --git a/src/src/com/ruserba/model/User.java b/src/src/com/ruserba/model/User.java new file mode 100644 index 0000000..636e284 --- /dev/null +++ b/src/src/com/ruserba/model/User.java @@ -0,0 +1,118 @@ +package com.ruserba.model; + +public class User implements java.io.Serializable { + + private int id_user; + private String username; + private String email; + private String password; // ??! + private String nama_lengkap; + private String provinsi; + private String kota; + private String alamat; + private String kode_pos; + private String kontak; + private String nomor_kartu; + private String nama_kartu; + private String ekspirasi_kartu; + private boolean admin; + + public int getIdUser(){ + return this.id_user; + } + public void setIdUser(int id_user){ + this.id_user = id_user; + } + + public String getUsername(){ + return this.username; + } + public void setUsername(String username){ + this.username = username; + } + + public String getEmail(){ + return this.email; + } + public void setEmail(String email){ + this.email = email; + } + + public String getPassword(){ + return this.password; + } + public void setPassword(String password){ + this.password = password; + } + + public String getNamaLengkap(){ + return this.nama_lengkap; + } + public void setNamaLengkap(String nama_lengkap){ + this.nama_lengkap = nama_lengkap; + } + + public String getProvinsi(){ + return this.provinsi; + } + public void setProvinsi(String provinsi){ + this.provinsi = provinsi; + } + + public String getKota(){ + return this.kota; + } + public void setKota(String kota){ + this.kota = kota; + } + + public String getAlamat(){ + return this.alamat; + } + public void setAlamat(String alamat){ + this.alamat = alamat; + } + + public String getKodePos(){ + return this.kode_pos; + } + public void setKodePos(String kode_pos){ + this.kode_pos = kode_pos; + } + + public String getKontak(){ + return this.kontak; + } + public void setKontak(String kontak){ + this.kontak = kontak; + } + + public String getNomorKartu(){ + return this.nomor_kartu; + } + public void setNomorKartu(String nomor_kartu){ + this.nomor_kartu = nomor_kartu; + } + + public String getNamaKartu(){ + return this.nama_kartu; + } + public void setNamaKartu(String nama_kartu){ + this.nama_kartu = nama_kartu; + } + + public String getEkspirasiKartu(){ + return this.ekspirasi_kartu; + } + public void setEkspirasiKartu(String ekspirasi_kartu){ + this.ekspirasi_kartu = ekspirasi_kartu; + } + + public boolean getAdmin() { + return this.admin; + } + public void setAdmin(boolean admin){ + this.admin = admin; + } + +} diff --git a/src/src/com/ruserba/web/CheckUsernameService.java b/src/src/com/ruserba/web/CheckUsernameService.java new file mode 100644 index 0000000..a723e1f --- /dev/null +++ b/src/src/com/ruserba/web/CheckUsernameService.java @@ -0,0 +1,53 @@ +package com.ruserba.web; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.security.MessageDigest; +import java.sql.SQLException; + +import com.ruserba.model.Database; +import com.ruserba.model.User; +import com.ruserba.web.WebUtil; + +public class CheckUsernameService extends HttpServlet +{ + public void doPost(HttpServletRequest request, HttpServletResponse response) + { + response.setContentType("text/plain"); + + PrintWriter out = null; + try { + out = response.getWriter(); + } + catch (Exception ex) {} + + String username = request.getParameter("username"); + String msg; + + if (username != null) + { + Database db = WebUtil.getDatabase(getServletContext()); + + User user = null; + try + { + user = db.getUserDataFromUsername(username); + } + catch(Exception ex) {} + + if (user != null) msg = "1"; + else msg = "0"; + } + else + { + msg = "0"; + } + + out.write(msg + "\n"); + + } +} diff --git a/src/src/com/ruserba/web/CobaServlet.java b/src/src/com/ruserba/web/CobaServlet.java new file mode 100644 index 0000000..e162782 --- /dev/null +++ b/src/src/com/ruserba/web/CobaServlet.java @@ -0,0 +1,56 @@ +package com.ruserba.web; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.security.MessageDigest; +import java.sql.SQLException; + +import com.ruserba.model.Database; +import com.ruserba.model.User; +import com.ruserba.model.SearchAttribute; +import com.ruserba.web.WebUtil; + +public class CobaServlet extends HttpServlet +{ + public void doGet(HttpServletRequest request, HttpServletResponse response) + { + response.setContentType("text/plain"); + + PrintWriter out = null; + try { + out = response.getWriter(); + } + catch (Exception ex) {} + + out.write("Hello"); + + Database db = WebUtil.getDatabase(getServletContext()); + + SearchAttribute attr = new SearchAttribute(); + + /* + attr.setNamaBarang("tomat"); + attr.setIdKategori(2); + attr.setHarga(3143); + attr.setIdPerbandingan(2); + attr.setIdPengurutan(Database.ORDERBY_PRODUCTNAME); + attr.setIdMetodePengurutan(Database.SORT_ASC); + attr.setIndeks(0); + attr.setJumlah(5); + */ + + attr.setNamaBarang(""); + attr.setIdKategori(3); + attr.setHarga(-1); + attr.setIdPerbandingan(0); + attr.setIdPengurutan(Database.ORDERBY_SOLDQTY); + attr.setIdMetodePengurutan(Database.SORT_DESC); + attr.setIndeks(0); + attr.setJumlah(3); + + } +} diff --git a/src/src/com/ruserba/web/DatabaseInit.java b/src/src/com/ruserba/web/DatabaseInit.java new file mode 100644 index 0000000..2b54ee8 --- /dev/null +++ b/src/src/com/ruserba/web/DatabaseInit.java @@ -0,0 +1,26 @@ +package com.ruserba.web; + +import com.ruserba.model.Database; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +public class DatabaseInit implements ServletContextListener { + + public void contextInitialized(ServletContextEvent event) { + ServletContext sc = event.getServletContext(); + + String db_url = sc.getInitParameter("db_url"); + String db_username = sc.getInitParameter("db_username"); + String db_password = sc.getInitParameter("db_password"); + String db_name = sc.getInitParameter("db_name"); + Database db = new Database(db_url + db_name, db_username, db_password); + sc.setAttribute("db", db); + } + + public void contextDestroyed(ServletContextEvent arg0) { + + } + +} diff --git a/src/src/com/ruserba/web/LoginService.java b/src/src/com/ruserba/web/LoginService.java new file mode 100644 index 0000000..508ecb4 --- /dev/null +++ b/src/src/com/ruserba/web/LoginService.java @@ -0,0 +1,87 @@ +package com.ruserba.web; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.security.MessageDigest; +import java.sql.SQLException; + +import com.ruserba.model.Database; +import com.ruserba.model.User; +import com.ruserba.web.WebUtil; + +public class LoginService extends HttpServlet +{ + public void doPost(HttpServletRequest request, HttpServletResponse response) + { + response.setContentType("text/plain"); + + PrintWriter out = null; + try { + out = response.getWriter(); + } + catch (Exception ex) {} + + String username = request.getParameter("username"); if (username == null) username = ""; + String password = request.getParameter("password"); if (password == null) password = ""; + Database db = WebUtil.getDatabase(getServletContext()); + + String msg_out; + + User user; + try + { + user = db.getUserDataFromUsername(username); + } + catch(Exception ex) + { + user = null; + } + + if (user != null) + { + MessageDigest md = null; + try + { + md = MessageDigest.getInstance("MD5"); + } + catch(Exception ex) + { + md = null; + } + md.update(password.getBytes()); + byte pass_byte[] = md.digest(); + + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < pass_byte.length; i++) { + sb.append(Integer.toString((pass_byte[i] & 0xff) + 0x100, 16).substring(1)); + } + + String password_hash = sb.toString(); + + if (password_hash.equals(user.getPassword())) + { + Cookie id_cookie = new Cookie("id_user", Integer.toString(user.getIdUser())); // Bad practice, but who cares? :p + id_cookie.setPath("/"); id_cookie.setMaxAge(2592000); + response.addCookie(id_cookie); + + Cookie username_cookie = new Cookie("username", user.getUsername()); // Bad practice, but who cares? :p + username_cookie.setPath("/"); username_cookie.setMaxAge(2592000); + response.addCookie(username_cookie); + msg_out = "1"; + } + else + { + msg_out = "0"; + } + } + else + { + msg_out = "0"; + } + out.write(msg_out + "\n"); // No JSON, no XML, just pure "linebreak separated"... + } +} diff --git a/src/src/com/ruserba/web/RegisterUserService.java b/src/src/com/ruserba/web/RegisterUserService.java new file mode 100644 index 0000000..a2a981d --- /dev/null +++ b/src/src/com/ruserba/web/RegisterUserService.java @@ -0,0 +1,93 @@ +package com.ruserba.web; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.security.MessageDigest; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.PreparedStatement; + +import com.ruserba.model.Database; +import com.ruserba.model.User; +import com.ruserba.web.WebUtil; + +public class RegisterUserService extends HttpServlet +{ + public void doPost(HttpServletRequest request, HttpServletResponse response) + { + response.setContentType("text/plain"); + + /*PrintWriter out = null; + try { + out = response.getWriter(); + } + catch (Exception ex) {} + + out.write("Hello");*/ + + MessageDigest md = null; + try { + md = MessageDigest.getInstance("MD5"); + } catch (Exception ex) {} + md.update(request.getParameter("password").getBytes()); + + byte byteData[] = md.digest(); + + //convert the byte to hex format method 1 + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < byteData.length; i++) + { + sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); + } + String pass_enc = sb.toString(); + + // Ambil data. + + User user = new User(); + user.setUsername(request.getParameter("username")); + user.setEmail(request.getParameter("email")); + user.setPassword(pass_enc); + user.setNamaLengkap(request.getParameter("namaLengkap")); + user.setProvinsi(request.getParameter("provinsi")); + user.setKota(request.getParameter("kota")); + user.setAlamat(request.getParameter("alamat")); + user.setKodePos(request.getParameter("kodePos")); + user.setKontak(request.getParameter("kontak")); + + Database db = WebUtil.getDatabase(getServletContext()); + + PreparedStatement stat = null; + try + { + stat = db.getConnection().prepareStatement("insert into user(username, email, password, nama_lengkap, provinsi, kota, alamat, kode_pos, kontak, admin) " + + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, 0)"); + + stat.setString(1, user.getUsername()); + stat.setString(2, user.getEmail()); + stat.setString(3, user.getPassword()); + stat.setString(4, user.getNamaLengkap()); + stat.setString(5, user.getProvinsi()); + stat.setString(6, user.getKota()); + stat.setString(7, user.getAlamat()); + stat.setString(8, user.getKodePos()); + stat.setString(9, user.getKontak()); + stat.executeUpdate(); + } + catch (Exception ex) {} + + Cookie id_cookie = new Cookie("id_user", Integer.toString(user.getIdUser())); // Bad practice, but who cares? :p + id_cookie.setPath("/"); id_cookie.setMaxAge(2592000); + response.addCookie(id_cookie); + + Cookie username_cookie = new Cookie("username", user.getUsername()); // Bad practice, but who cares? :p + username_cookie.setPath("/"); username_cookie.setMaxAge(2592000); + response.addCookie(username_cookie); + } +} diff --git a/src/src/com/ruserba/web/WebUtil.java b/src/src/com/ruserba/web/WebUtil.java new file mode 100644 index 0000000..b330a07 --- /dev/null +++ b/src/src/com/ruserba/web/WebUtil.java @@ -0,0 +1,51 @@ +package com.ruserba.web; + +import javax.servlet.ServletContext; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.sql.SQLException; + +import com.ruserba.model.Database; + +public class WebUtil +{ + public static boolean isLoggedIn(ServletContext context, HttpServletRequest request) throws SQLException + { + Cookie[] cookies = request.getCookies(); + int user_id; + if (cookies != null) + { + for (int i = 0; i < cookies.length; i++) + { + if (cookies[i].getName().equals("id_user")) + { + user_id = Integer.parseInt(cookies[i].getValue()); + + // Periksa kebenaran user ID. + Database db = getDatabase(context); + if (db.getUserData(user_id) != null) return true; + else return false; + } + } + } + return false; + } + + public static Database getDatabase(ServletContext context) + { + return (Database)context.getAttribute("db"); + } + + public static String getProductImagePath(String product_image_filename) + { + return "images/products/" + product_image_filename; + } + + public static String getProductPage(int product_id) + { + return "product.jsp?product_id=" + product_id; + } + +} diff --git a/src/web/admin.jsp b/src/web/admin.jsp new file mode 100644 index 0000000..32488d1 --- /dev/null +++ b/src/web/admin.jsp @@ -0,0 +1,23 @@ + + + + + + + + + + + + + +

HALAMAN KONTROL ADMIN

+ Tampilkan Daftar Barang +
+ Modifikasi Daftar Barang +
+ Tambah/Hapus Daftar Barang + + \ No newline at end of file diff --git a/src/web/adminadd.jsp b/src/web/adminadd.jsp new file mode 100644 index 0000000..f2b251d --- /dev/null +++ b/src/web/adminadd.jsp @@ -0,0 +1,42 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +Tambah Entri Barang + + +
+Tambah entri barang, tanda * berarti wajib diisi +
+
+ID Barang*:
+ID Kategori*:
+Nama Barang*:
+Harga:
+Satuan:
+Deskripsi:
+Jumlah Pembelian:
+Jumlah Stok:
+Nama Gambar:
+Nama Thumbnail:
+
+ + + + + + +INSERT INTO barang VALUES (id_barang, id_kategori, nama_barang', harga, satuan, deskripsi, jumlah_pembelian, jumlah_stok, nama_gambar, nama_gambar_thumb); + + +
+ + + + + \ No newline at end of file diff --git a/src/web/admindisplay.jsp b/src/web/admindisplay.jsp new file mode 100644 index 0000000..68f275b --- /dev/null +++ b/src/web/admindisplay.jsp @@ -0,0 +1,25 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +ADMIN: Pilih Kategori + + +

HALAMAN KONTROL ADMIN

+
+Pilih kategori barang +
+
+ + + \ No newline at end of file diff --git a/src/web/adminedit.jsp b/src/web/adminedit.jsp new file mode 100644 index 0000000..8de3601 --- /dev/null +++ b/src/web/adminedit.jsp @@ -0,0 +1,40 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +Modifikasi Daftar Barang + + +
+Pilih bagian yang ingin diedit, tanda * berarti wajib diisi +
+
+ID Barang:
+ID Kategori:
+Nama Barang:
+Harga:
+Satuan:
+Deskripsi:
+Jumlah Pembelian:
+Jumlah Stok:
+Nama Gambar:
+Nama Thumbnail:
+
+ + + + + + UPDATE barang SET id_barang = id_barang, id_kategori=id_kategori, nama_barang=nama_barang,harga=harga,satuan=satuan,deskripsi=deskripsi,jumlah_pembelian=jumlah_pembelian,jumlah_stok=jumlah_stok,nama_gambar=nama_gambar,nama_gambar_thumb=nama_gambar_thumb; + + +
+ +
+ + \ No newline at end of file diff --git a/src/web/adminpage1.jsp b/src/web/adminpage1.jsp new file mode 100644 index 0000000..38e0409 --- /dev/null +++ b/src/web/adminpage1.jsp @@ -0,0 +1,90 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +ADMIN: ID1 Beras dan kacang-kacangan + + + + + + +SELECT * from barang WHERE ID_kategori=1; + + +
+ID 1 : Beras dan kacang-kacangan
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID_barangID_kategoriNama_barangHargaSatuanDeskripsiJumlah_pembelianJumlah_stokNama_gambarNama_gambar_thumb
+
+
+Modifikasi entri barang: ID +
+
+
+Hapus entri barang: ID +
+
+
+Tambah entri barang +
+ + + \ No newline at end of file diff --git a/src/web/adminpage2.jsp b/src/web/adminpage2.jsp new file mode 100644 index 0000000..7be2caf --- /dev/null +++ b/src/web/adminpage2.jsp @@ -0,0 +1,91 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +ADMIN: ID2 Daging dan telur + + + + + + +SELECT * from barang WHERE ID_kategori=2; + +
+ID 2 : Daging dan telur
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID_barangID_kategoriNama_barangHargaSatuanDeskripsiJumlah_pembelianJumlah_stokNama_gambarNama_gambar_thumb
+
+
+Modifikasi entri barang: ID +
+
+
+Hapus entri barang: ID +
+
+
+Tambah entri barang +
+ + + \ No newline at end of file diff --git a/src/web/adminpage3.jsp b/src/web/adminpage3.jsp new file mode 100644 index 0000000..c1c9fbc --- /dev/null +++ b/src/web/adminpage3.jsp @@ -0,0 +1,89 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +ADMIN: ID3 Sayur-mayur + + + + + + +SELECT * from barang WHERE ID_kategori=3; + +
+ID 3 : Sayur-mayur
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID_barangID_kategoriNama_barangHargaSatuanDeskripsiJumlah_pembelianJumlah_stokNama_gambarNama_gambar_thumb
+
+
+Modifikasi entri barang: ID +
+
+
+Hapus entri barang: ID +
+
+
+Tambah entri barang +
+ + + \ No newline at end of file diff --git a/src/web/adminpage4.jsp b/src/web/adminpage4.jsp new file mode 100644 index 0000000..81fb7e9 --- /dev/null +++ b/src/web/adminpage4.jsp @@ -0,0 +1,90 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +ADMIN: ID4 Buah-buahan + + + + + + +SELECT * from barang WHERE ID_kategori=4; + +
+ID 4 : Buah-buahan
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID_barangID_kategoriNama_barangHargaSatuanDeskripsiJumlah_pembelianJumlah_stokNama_gambarNama_gambar_thumb
+
+
+Modifikasi entri barang: ID +
+
+
+Hapus entri barang: ID +
+
+
+Tambah entri barang +
+ + + \ No newline at end of file diff --git a/src/web/adminpage5.jsp b/src/web/adminpage5.jsp new file mode 100644 index 0000000..b42f456 --- /dev/null +++ b/src/web/adminpage5.jsp @@ -0,0 +1,90 @@ +<%@ page import="java.io.*,java.util.*,java.sql.*"%> +<%@ page import="javax.servlet.http.*,javax.servlet.*" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> + + + +ADMIN: ID5 Bumbu dapur + + + + + + +SELECT * from barang WHERE ID_kategori=5; + +
+ID 5 : Bumbu dapur
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID_barangID_kategoriNama_barangHargaSatuanDeskripsiJumlah_pembelianJumlah_stokNama_gambarNama_gambar_thumb
+
+
+Modifikasi entri barang: ID +
+
+
+Hapus entri barang: ID +
+
+
+Tambah entri barang +
+ + + \ No newline at end of file diff --git a/src/web/category.jsp b/src/web/category.jsp new file mode 100644 index 0000000..f7707a6 --- /dev/null +++ b/src/web/category.jsp @@ -0,0 +1,73 @@ +<%@ page import="com.ruserba.web.WebUtil" %> +<%@ page import="com.ruserba.model.Database" %> +<%@ page import="com.ruserba.model.Category" %> +<%@ page import="com.ruserba.model.Product" %> +<%@ page import="com.ruserba.model.SearchAttribute" %> +<%@ page import="java.util.ArrayList" %> + +<% request.setAttribute("page_title", "RuSerBa - Kategori Produk"); %> +<% request.setAttribute("css_file", "styles/browse_product.css"); %> + + +<% + Database db = WebUtil.getDatabase(getServletContext()); + + int category_id = Integer.parseInt(request.getParameter("category_id")); + + String sort_category_id_str = request.getParameter("sort_category_id"); + int sort_category_id; + if (sort_category_id_str == null) sort_category_id = 1; + else sort_category_id = Integer.parseInt(sort_category_id_str); + + String sort_method_str = request.getParameter("sort_method"); + int sort_method; + if (sort_method_str == null) sort_method = 1; + else sort_method = Integer.parseInt(sort_method_str); + + String category_name = db.getCategoryData(category_id).getNamaKategori(); +%> + +

<%= category_name %>

+ +
+
+ + + + + +
+
+ +<% + SearchAttribute attr = new SearchAttribute(); + + attr.setNamaBarang(""); + attr.setIdKategori(category_id); + attr.setHarga(-1); + attr.setIdPerbandingan(0); + attr.setIdPengurutan(sort_category_id); + attr.setIdMetodePengurutan(sort_method); + attr.setIndeks(0); + attr.setJumlah(-1); + + ArrayList prod_lst = db.getProductSearchResult(attr); + + out.write("
"); + for (int j = 0; j < prod_lst.size(); j++) + { + request.setAttribute("produk", prod_lst.get(j)); + %> + + <% + } + out.write("
"); +%> + + diff --git a/src/web/hello.jsp b/src/web/hello.jsp new file mode 100644 index 0000000..1e27f58 --- /dev/null +++ b/src/web/hello.jsp @@ -0,0 +1,23 @@ +<%@ page import="com.ruserba.model.Database" %> +<%@ page import="java.sql.ResultSet" %> +<%@ page import="java.sql.SQLException" %> + + + + Hello World! + + + <% + String msg = (String)request.getAttribute("msg"); + if (msg == null) msg = "No message."; + %> +

<%= msg %>

+ <% + Database db = (Database)pageContext.getServletContext().getAttribute("db"); + //System.out.println(db); + request.setAttribute("product", db.getProductData(3)); + %> + +

+ + diff --git a/src/web/images/bag.jpg b/src/web/images/bag.jpg new file mode 100644 index 0000000..9f019f0 Binary files /dev/null and b/src/web/images/bag.jpg differ diff --git a/src/web/images/blank.jpg b/src/web/images/blank.jpg new file mode 100644 index 0000000..b26c0eb Binary files /dev/null and b/src/web/images/blank.jpg differ diff --git a/src/web/images/close.png b/src/web/images/close.png new file mode 100644 index 0000000..53d4162 Binary files /dev/null and b/src/web/images/close.png differ diff --git a/src/web/images/icon_error.png b/src/web/images/icon_error.png new file mode 100644 index 0000000..22418fc Binary files /dev/null and b/src/web/images/icon_error.png differ diff --git a/src/web/images/icon_error_small.png b/src/web/images/icon_error_small.png new file mode 100644 index 0000000..0a14364 Binary files /dev/null and b/src/web/images/icon_error_small.png differ diff --git a/src/web/images/icon_ok.png b/src/web/images/icon_ok.png new file mode 100644 index 0000000..ab66463 Binary files /dev/null and b/src/web/images/icon_ok.png differ diff --git a/src/web/images/icon_ok_small.png b/src/web/images/icon_ok_small.png new file mode 100644 index 0000000..5b7f012 Binary files /dev/null and b/src/web/images/icon_ok_small.png differ diff --git a/src/web/images/icon_warning.png b/src/web/images/icon_warning.png new file mode 100644 index 0000000..ef8e345 Binary files /dev/null and b/src/web/images/icon_warning.png differ diff --git a/src/web/images/icon_warning_small.png b/src/web/images/icon_warning_small.png new file mode 100644 index 0000000..0edef7e Binary files /dev/null and b/src/web/images/icon_warning_small.png differ diff --git a/src/web/images/logo.gif b/src/web/images/logo.gif new file mode 100644 index 0000000..a610879 Binary files /dev/null and b/src/web/images/logo.gif differ diff --git a/src/web/images/products/beras_merah.jpg b/src/web/images/products/beras_merah.jpg new file mode 100644 index 0000000..4aff4e3 Binary files /dev/null and b/src/web/images/products/beras_merah.jpg differ diff --git a/src/web/images/products/beras_merah_thumb.jpg b/src/web/images/products/beras_merah_thumb.jpg new file mode 100644 index 0000000..0971525 Binary files /dev/null and b/src/web/images/products/beras_merah_thumb.jpg differ diff --git a/src/web/images/products/beras_putih.jpg b/src/web/images/products/beras_putih.jpg new file mode 100644 index 0000000..feb4d09 Binary files /dev/null and b/src/web/images/products/beras_putih.jpg differ diff --git a/src/web/images/products/beras_putih_thumb.jpg b/src/web/images/products/beras_putih_thumb.jpg new file mode 100644 index 0000000..b87d590 Binary files /dev/null and b/src/web/images/products/beras_putih_thumb.jpg differ diff --git a/src/web/images/products/buah_apel.jpg b/src/web/images/products/buah_apel.jpg new file mode 100644 index 0000000..86b8b18 Binary files /dev/null and b/src/web/images/products/buah_apel.jpg differ diff --git a/src/web/images/products/buah_apel_thumb.jpg b/src/web/images/products/buah_apel_thumb.jpg new file mode 100644 index 0000000..af4a8de Binary files /dev/null and b/src/web/images/products/buah_apel_thumb.jpg differ diff --git a/src/web/images/products/buah_cherry.jpg b/src/web/images/products/buah_cherry.jpg new file mode 100644 index 0000000..e0fac3f Binary files /dev/null and b/src/web/images/products/buah_cherry.jpg differ diff --git a/src/web/images/products/buah_cherry_thumb.jpg b/src/web/images/products/buah_cherry_thumb.jpg new file mode 100644 index 0000000..c909937 Binary files /dev/null and b/src/web/images/products/buah_cherry_thumb.jpg differ diff --git a/src/web/images/products/buah_durian.jpg b/src/web/images/products/buah_durian.jpg new file mode 100644 index 0000000..1822216 Binary files /dev/null and b/src/web/images/products/buah_durian.jpg differ diff --git a/src/web/images/products/buah_durian_thumb.jpg b/src/web/images/products/buah_durian_thumb.jpg new file mode 100644 index 0000000..3727996 Binary files /dev/null and b/src/web/images/products/buah_durian_thumb.jpg differ diff --git a/src/web/images/products/buah_jambubatu.jpg b/src/web/images/products/buah_jambubatu.jpg new file mode 100644 index 0000000..b599c64 Binary files /dev/null and b/src/web/images/products/buah_jambubatu.jpg differ diff --git a/src/web/images/products/buah_jambubatu_thumb.jpg b/src/web/images/products/buah_jambubatu_thumb.jpg new file mode 100644 index 0000000..792c20d Binary files /dev/null and b/src/web/images/products/buah_jambubatu_thumb.jpg differ diff --git a/src/web/images/products/buah_jeruk.jpg b/src/web/images/products/buah_jeruk.jpg new file mode 100644 index 0000000..4cb4d9a Binary files /dev/null and b/src/web/images/products/buah_jeruk.jpg differ diff --git a/src/web/images/products/buah_jeruk_thumb.jpg b/src/web/images/products/buah_jeruk_thumb.jpg new file mode 100644 index 0000000..98f29e7 Binary files /dev/null and b/src/web/images/products/buah_jeruk_thumb.jpg differ diff --git a/src/web/images/products/buah_kiwi.jpg b/src/web/images/products/buah_kiwi.jpg new file mode 100644 index 0000000..948509b Binary files /dev/null and b/src/web/images/products/buah_kiwi.jpg differ diff --git a/src/web/images/products/buah_kiwi_thumb.jpg b/src/web/images/products/buah_kiwi_thumb.jpg new file mode 100644 index 0000000..d2f4a60 Binary files /dev/null and b/src/web/images/products/buah_kiwi_thumb.jpg differ diff --git a/src/web/images/products/buah_mangga.jpg b/src/web/images/products/buah_mangga.jpg new file mode 100644 index 0000000..a3073a5 Binary files /dev/null and b/src/web/images/products/buah_mangga.jpg differ diff --git a/src/web/images/products/buah_mangga_thumb.jpg b/src/web/images/products/buah_mangga_thumb.jpg new file mode 100644 index 0000000..bd0d269 Binary files /dev/null and b/src/web/images/products/buah_mangga_thumb.jpg differ diff --git a/src/web/images/products/buah_manggis.jpg b/src/web/images/products/buah_manggis.jpg new file mode 100644 index 0000000..ae45186 Binary files /dev/null and b/src/web/images/products/buah_manggis.jpg differ diff --git a/src/web/images/products/buah_manggis_thumb.jpg b/src/web/images/products/buah_manggis_thumb.jpg new file mode 100644 index 0000000..a38d48d Binary files /dev/null and b/src/web/images/products/buah_manggis_thumb.jpg differ diff --git a/src/web/images/products/buah_melon.jpg b/src/web/images/products/buah_melon.jpg new file mode 100644 index 0000000..8317a51 Binary files /dev/null and b/src/web/images/products/buah_melon.jpg differ diff --git a/src/web/images/products/buah_melon_thumb.jpg b/src/web/images/products/buah_melon_thumb.jpg new file mode 100644 index 0000000..d01694c Binary files /dev/null and b/src/web/images/products/buah_melon_thumb.jpg differ diff --git a/src/web/images/products/buah_nanas.jpg b/src/web/images/products/buah_nanas.jpg new file mode 100644 index 0000000..43ab383 Binary files /dev/null and b/src/web/images/products/buah_nanas.jpg differ diff --git a/src/web/images/products/buah_nanas_thumb.jpg b/src/web/images/products/buah_nanas_thumb.jpg new file mode 100644 index 0000000..7a3ed43 Binary files /dev/null and b/src/web/images/products/buah_nanas_thumb.jpg differ diff --git a/src/web/images/products/buah_pisang.jpg b/src/web/images/products/buah_pisang.jpg new file mode 100644 index 0000000..ee97c7b Binary files /dev/null and b/src/web/images/products/buah_pisang.jpg differ diff --git a/src/web/images/products/buah_pisang_thumb.jpg b/src/web/images/products/buah_pisang_thumb.jpg new file mode 100644 index 0000000..38b2b33 Binary files /dev/null and b/src/web/images/products/buah_pisang_thumb.jpg differ diff --git a/src/web/images/products/buah_semangka.jpg b/src/web/images/products/buah_semangka.jpg new file mode 100644 index 0000000..bdde717 Binary files /dev/null and b/src/web/images/products/buah_semangka.jpg differ diff --git a/src/web/images/products/buah_semangka_thumb.jpg b/src/web/images/products/buah_semangka_thumb.jpg new file mode 100644 index 0000000..24f95ad Binary files /dev/null and b/src/web/images/products/buah_semangka_thumb.jpg differ diff --git a/src/web/images/products/buah_stroberi.jpg b/src/web/images/products/buah_stroberi.jpg new file mode 100644 index 0000000..16c2526 Binary files /dev/null and b/src/web/images/products/buah_stroberi.jpg differ diff --git a/src/web/images/products/buah_stroberi_thumb.jpg b/src/web/images/products/buah_stroberi_thumb.jpg new file mode 100644 index 0000000..42b485e Binary files /dev/null and b/src/web/images/products/buah_stroberi_thumb.jpg differ diff --git a/src/web/images/products/buah_zaitun.jpg b/src/web/images/products/buah_zaitun.jpg new file mode 100644 index 0000000..d81a9e2 Binary files /dev/null and b/src/web/images/products/buah_zaitun.jpg differ diff --git a/src/web/images/products/buah_zaitun_thumb.jpg b/src/web/images/products/buah_zaitun_thumb.jpg new file mode 100644 index 0000000..0cd18b0 Binary files /dev/null and b/src/web/images/products/buah_zaitun_thumb.jpg differ diff --git a/src/web/images/products/bumbu_bawangmerah.jpg b/src/web/images/products/bumbu_bawangmerah.jpg new file mode 100644 index 0000000..882e7b7 Binary files /dev/null and b/src/web/images/products/bumbu_bawangmerah.jpg differ diff --git a/src/web/images/products/bumbu_bawangmerah_thumb.jpg b/src/web/images/products/bumbu_bawangmerah_thumb.jpg new file mode 100644 index 0000000..465f568 Binary files /dev/null and b/src/web/images/products/bumbu_bawangmerah_thumb.jpg differ diff --git a/src/web/images/products/bumbu_bawangputih.jpg b/src/web/images/products/bumbu_bawangputih.jpg new file mode 100644 index 0000000..c8148ed Binary files /dev/null and b/src/web/images/products/bumbu_bawangputih.jpg differ diff --git a/src/web/images/products/bumbu_bawangputih_thumb.jpg b/src/web/images/products/bumbu_bawangputih_thumb.jpg new file mode 100644 index 0000000..154fd42 Binary files /dev/null and b/src/web/images/products/bumbu_bawangputih_thumb.jpg differ diff --git a/src/web/images/products/bumbu_kayumanis.jpg b/src/web/images/products/bumbu_kayumanis.jpg new file mode 100644 index 0000000..4ab6956 Binary files /dev/null and b/src/web/images/products/bumbu_kayumanis.jpg differ diff --git a/src/web/images/products/bumbu_kayumanis_thumb.jpg b/src/web/images/products/bumbu_kayumanis_thumb.jpg new file mode 100644 index 0000000..88a6d96 Binary files /dev/null and b/src/web/images/products/bumbu_kayumanis_thumb.jpg differ diff --git a/src/web/images/products/bumbu_kemiri.jpg b/src/web/images/products/bumbu_kemiri.jpg new file mode 100644 index 0000000..7268a88 Binary files /dev/null and b/src/web/images/products/bumbu_kemiri.jpg differ diff --git a/src/web/images/products/bumbu_kemiri_thumb.jpg b/src/web/images/products/bumbu_kemiri_thumb.jpg new file mode 100644 index 0000000..03f5e57 Binary files /dev/null and b/src/web/images/products/bumbu_kemiri_thumb.jpg differ diff --git a/src/web/images/products/bumbu_kencur.jpg b/src/web/images/products/bumbu_kencur.jpg new file mode 100644 index 0000000..5038315 Binary files /dev/null and b/src/web/images/products/bumbu_kencur.jpg differ diff --git a/src/web/images/products/bumbu_kencur_thumb.jpg b/src/web/images/products/bumbu_kencur_thumb.jpg new file mode 100644 index 0000000..2898030 Binary files /dev/null and b/src/web/images/products/bumbu_kencur_thumb.jpg differ diff --git a/src/web/images/products/bumbu_ketumbar.jpg b/src/web/images/products/bumbu_ketumbar.jpg new file mode 100644 index 0000000..f5255ca Binary files /dev/null and b/src/web/images/products/bumbu_ketumbar.jpg differ diff --git a/src/web/images/products/bumbu_ketumbar_thumb.jpg b/src/web/images/products/bumbu_ketumbar_thumb.jpg new file mode 100644 index 0000000..fdab126 Binary files /dev/null and b/src/web/images/products/bumbu_ketumbar_thumb.jpg differ diff --git a/src/web/images/products/bumbu_kunyit.jpg b/src/web/images/products/bumbu_kunyit.jpg new file mode 100644 index 0000000..238f228 Binary files /dev/null and b/src/web/images/products/bumbu_kunyit.jpg differ diff --git a/src/web/images/products/bumbu_kunyit_thumb.jpg b/src/web/images/products/bumbu_kunyit_thumb.jpg new file mode 100644 index 0000000..f19da9e Binary files /dev/null and b/src/web/images/products/bumbu_kunyit_thumb.jpg differ diff --git a/src/web/images/products/bumbu_rempah.jpg b/src/web/images/products/bumbu_rempah.jpg new file mode 100644 index 0000000..7e33c70 Binary files /dev/null and b/src/web/images/products/bumbu_rempah.jpg differ diff --git a/src/web/images/products/bumbu_rempah_thumb.jpg b/src/web/images/products/bumbu_rempah_thumb.jpg new file mode 100644 index 0000000..528e561 Binary files /dev/null and b/src/web/images/products/bumbu_rempah_thumb.jpg differ diff --git a/src/web/images/products/daging_ayam.jpg b/src/web/images/products/daging_ayam.jpg new file mode 100644 index 0000000..ececd31 Binary files /dev/null and b/src/web/images/products/daging_ayam.jpg differ diff --git a/src/web/images/products/daging_ayam_thumb.jpg b/src/web/images/products/daging_ayam_thumb.jpg new file mode 100644 index 0000000..3811a8f Binary files /dev/null and b/src/web/images/products/daging_ayam_thumb.jpg differ diff --git a/src/web/images/products/daging_ikan.jpg b/src/web/images/products/daging_ikan.jpg new file mode 100644 index 0000000..fce5ac3 Binary files /dev/null and b/src/web/images/products/daging_ikan.jpg differ diff --git a/src/web/images/products/daging_ikan_thumb.jpg b/src/web/images/products/daging_ikan_thumb.jpg new file mode 100644 index 0000000..fe433fb Binary files /dev/null and b/src/web/images/products/daging_ikan_thumb.jpg differ diff --git a/src/web/images/products/daging_sapi.jpg b/src/web/images/products/daging_sapi.jpg new file mode 100644 index 0000000..3e7bc42 Binary files /dev/null and b/src/web/images/products/daging_sapi.jpg differ diff --git a/src/web/images/products/daging_sapi_thumb.jpg b/src/web/images/products/daging_sapi_thumb.jpg new file mode 100644 index 0000000..dad1036 Binary files /dev/null and b/src/web/images/products/daging_sapi_thumb.jpg differ diff --git a/src/web/images/products/garam.jpg b/src/web/images/products/garam.jpg new file mode 100644 index 0000000..1646fc8 Binary files /dev/null and b/src/web/images/products/garam.jpg differ diff --git a/src/web/images/products/garam_thumb.jpg b/src/web/images/products/garam_thumb.jpg new file mode 100644 index 0000000..6ecb585 Binary files /dev/null and b/src/web/images/products/garam_thumb.jpg differ diff --git a/src/web/images/products/kacang_hijau.jpg b/src/web/images/products/kacang_hijau.jpg new file mode 100644 index 0000000..1a20612 Binary files /dev/null and b/src/web/images/products/kacang_hijau.jpg differ diff --git a/src/web/images/products/kacang_hijau_thumb.jpg b/src/web/images/products/kacang_hijau_thumb.jpg new file mode 100644 index 0000000..0b1eb87 Binary files /dev/null and b/src/web/images/products/kacang_hijau_thumb.jpg differ diff --git a/src/web/images/products/kacang_tanah.jpg b/src/web/images/products/kacang_tanah.jpg new file mode 100644 index 0000000..40ad093 Binary files /dev/null and b/src/web/images/products/kacang_tanah.jpg differ diff --git a/src/web/images/products/kacang_tanah_thumb.jpg b/src/web/images/products/kacang_tanah_thumb.jpg new file mode 100644 index 0000000..f6813d9 Binary files /dev/null and b/src/web/images/products/kacang_tanah_thumb.jpg differ diff --git a/src/web/images/products/sayur_bayam_hijau.jpg b/src/web/images/products/sayur_bayam_hijau.jpg new file mode 100644 index 0000000..7f05bff Binary files /dev/null and b/src/web/images/products/sayur_bayam_hijau.jpg differ diff --git a/src/web/images/products/sayur_bayam_hijau_thumb.jpg b/src/web/images/products/sayur_bayam_hijau_thumb.jpg new file mode 100644 index 0000000..74d73bc Binary files /dev/null and b/src/web/images/products/sayur_bayam_hijau_thumb.jpg differ diff --git a/src/web/images/products/sayur_bayam_merah.jpg b/src/web/images/products/sayur_bayam_merah.jpg new file mode 100644 index 0000000..8959ec5 Binary files /dev/null and b/src/web/images/products/sayur_bayam_merah.jpg differ diff --git a/src/web/images/products/sayur_bayam_merah_thumb.jpg b/src/web/images/products/sayur_bayam_merah_thumb.jpg new file mode 100644 index 0000000..96180ad Binary files /dev/null and b/src/web/images/products/sayur_bayam_merah_thumb.jpg differ diff --git a/src/web/images/products/sayur_brokoli.jpg b/src/web/images/products/sayur_brokoli.jpg new file mode 100644 index 0000000..0900fd6 Binary files /dev/null and b/src/web/images/products/sayur_brokoli.jpg differ diff --git a/src/web/images/products/sayur_brokoli_thumb.jpg b/src/web/images/products/sayur_brokoli_thumb.jpg new file mode 100644 index 0000000..89ee05c Binary files /dev/null and b/src/web/images/products/sayur_brokoli_thumb.jpg differ diff --git a/src/web/images/products/sayur_buncis.jpg b/src/web/images/products/sayur_buncis.jpg new file mode 100644 index 0000000..def0cdd Binary files /dev/null and b/src/web/images/products/sayur_buncis.jpg differ diff --git a/src/web/images/products/sayur_buncis_thumb.jpg b/src/web/images/products/sayur_buncis_thumb.jpg new file mode 100644 index 0000000..419e68b Binary files /dev/null and b/src/web/images/products/sayur_buncis_thumb.jpg differ diff --git a/src/web/images/products/sayur_choi_sum.jpg b/src/web/images/products/sayur_choi_sum.jpg new file mode 100644 index 0000000..44dd686 Binary files /dev/null and b/src/web/images/products/sayur_choi_sum.jpg differ diff --git a/src/web/images/products/sayur_choi_sum_thumb.jpg b/src/web/images/products/sayur_choi_sum_thumb.jpg new file mode 100644 index 0000000..30cec03 Binary files /dev/null and b/src/web/images/products/sayur_choi_sum_thumb.jpg differ diff --git a/src/web/images/products/sayur_kacang_panjang.jpg b/src/web/images/products/sayur_kacang_panjang.jpg new file mode 100644 index 0000000..1a75dff Binary files /dev/null and b/src/web/images/products/sayur_kacang_panjang.jpg differ diff --git a/src/web/images/products/sayur_kacang_panjang_thumb.jpg b/src/web/images/products/sayur_kacang_panjang_thumb.jpg new file mode 100644 index 0000000..b418765 Binary files /dev/null and b/src/web/images/products/sayur_kacang_panjang_thumb.jpg differ diff --git a/src/web/images/products/sayur_kacang_selisa.jpg b/src/web/images/products/sayur_kacang_selisa.jpg new file mode 100644 index 0000000..d66b87f Binary files /dev/null and b/src/web/images/products/sayur_kacang_selisa.jpg differ diff --git a/src/web/images/products/sayur_kacang_selisa_thumb.jpg b/src/web/images/products/sayur_kacang_selisa_thumb.jpg new file mode 100644 index 0000000..155e7ba Binary files /dev/null and b/src/web/images/products/sayur_kacang_selisa_thumb.jpg differ diff --git a/src/web/images/products/sayur_kailan.jpg b/src/web/images/products/sayur_kailan.jpg new file mode 100644 index 0000000..459644d Binary files /dev/null and b/src/web/images/products/sayur_kailan.jpg differ diff --git a/src/web/images/products/sayur_kailan_thumb.jpg b/src/web/images/products/sayur_kailan_thumb.jpg new file mode 100644 index 0000000..23a324b Binary files /dev/null and b/src/web/images/products/sayur_kailan_thumb.jpg differ diff --git a/src/web/images/products/sayur_pare.jpg b/src/web/images/products/sayur_pare.jpg new file mode 100644 index 0000000..07856ab Binary files /dev/null and b/src/web/images/products/sayur_pare.jpg differ diff --git a/src/web/images/products/sayur_pare_thumb.jpg b/src/web/images/products/sayur_pare_thumb.jpg new file mode 100644 index 0000000..d9878fa Binary files /dev/null and b/src/web/images/products/sayur_pare_thumb.jpg differ diff --git a/src/web/images/products/sayur_sawi_hijau.jpg b/src/web/images/products/sayur_sawi_hijau.jpg new file mode 100644 index 0000000..53578e2 Binary files /dev/null and b/src/web/images/products/sayur_sawi_hijau.jpg differ diff --git a/src/web/images/products/sayur_sawi_hijau_thumb.jpg b/src/web/images/products/sayur_sawi_hijau_thumb.jpg new file mode 100644 index 0000000..988db1f Binary files /dev/null and b/src/web/images/products/sayur_sawi_hijau_thumb.jpg differ diff --git a/src/web/images/products/sayur_sawi_putih.jpg b/src/web/images/products/sayur_sawi_putih.jpg new file mode 100644 index 0000000..5fde52b Binary files /dev/null and b/src/web/images/products/sayur_sawi_putih.jpg differ diff --git a/src/web/images/products/sayur_sawi_putih_thumb.jpg b/src/web/images/products/sayur_sawi_putih_thumb.jpg new file mode 100644 index 0000000..153faf7 Binary files /dev/null and b/src/web/images/products/sayur_sawi_putih_thumb.jpg differ diff --git a/src/web/images/products/sayur_seledri.jpg b/src/web/images/products/sayur_seledri.jpg new file mode 100644 index 0000000..a2c914e Binary files /dev/null and b/src/web/images/products/sayur_seledri.jpg differ diff --git a/src/web/images/products/sayur_seledri_thumb.jpg b/src/web/images/products/sayur_seledri_thumb.jpg new file mode 100644 index 0000000..9522562 Binary files /dev/null and b/src/web/images/products/sayur_seledri_thumb.jpg differ diff --git a/src/web/images/products/telur_ayam.jpg b/src/web/images/products/telur_ayam.jpg new file mode 100644 index 0000000..54fd096 Binary files /dev/null and b/src/web/images/products/telur_ayam.jpg differ diff --git a/src/web/images/products/telur_ayam_thumb.jpg b/src/web/images/products/telur_ayam_thumb.jpg new file mode 100644 index 0000000..30e303d Binary files /dev/null and b/src/web/images/products/telur_ayam_thumb.jpg differ diff --git a/src/web/index.jsp b/src/web/index.jsp new file mode 100644 index 0000000..3ea785b --- /dev/null +++ b/src/web/index.jsp @@ -0,0 +1,50 @@ +<%@ page import="com.ruserba.web.WebUtil" %> +<%@ page import="com.ruserba.model.Database" %> +<%@ page import="com.ruserba.model.Category" %> +<%@ page import="com.ruserba.model.Product" %> +<%@ page import="com.ruserba.model.SearchAttribute" %> +<%@ page import="java.util.ArrayList" %> + +<% request.setAttribute("page_title", "RuSerBa - Halaman Utama"); %> +<% request.setAttribute("css_file", "styles/browse_product.css"); %> + + +

Produk dengan Pembelian Terbanyak

+ +<% + Database db = WebUtil.getDatabase(getServletContext()); + + ArrayList cat_lst = db.getCategory(); + + for (int i = 0; i < cat_lst.size(); i++) + { + out.write("

" + cat_lst.get(i).getNamaKategori() + "

"); + + SearchAttribute attr = new SearchAttribute(); + + attr.setNamaBarang(""); + attr.setIdKategori(cat_lst.get(i).getIdKategori()); + attr.setHarga(-1); + attr.setIdPerbandingan(0); + attr.setIdPengurutan(Database.ORDERBY_SOLDQTY); + attr.setIdMetodePengurutan(Database.SORT_DESC); + attr.setIndeks(0); + attr.setJumlah(3); + + ArrayList prod_lst = db.getProductSearchResult(attr); + + out.write("
"); + for (int j = 0; j < prod_lst.size(); j++) + { + request.setAttribute("produk", prod_lst.get(j)); + %> + + <% + } + out.write("
"); + + } + +%> + + diff --git a/src/web/product.jsp b/src/web/product.jsp new file mode 100644 index 0000000..c5a042a --- /dev/null +++ b/src/web/product.jsp @@ -0,0 +1,50 @@ +<%@ page import="com.ruserba.web.WebUtil" %> +<%@ page import="com.ruserba.model.Database" %> +<%@ page import="com.ruserba.model.Category" %> +<%@ page import="com.ruserba.model.Product" %> +<%@ page import="com.ruserba.model.SearchAttribute" %> +<%@ page import="java.util.ArrayList" %> + +<% request.setAttribute("page_title", "RuSerBa - Informasi Produk"); %> +<% request.setAttribute("js_file", "scripts/product.js"); %> + + +<% + Database db = WebUtil.getDatabase(getServletContext()); + Product produk = db.getProductData(Integer.parseInt(request.getParameter("product_id"))); +%> + +

+gambar_product +

+
+

+

<%= produk.getNamaBarang() %>

+

+

+<%= produk.getDeskripsi() %> +

+

+

+Harga: Rp<%= produk.getHarga() %>,- / <%= produk.getSatuan() %> +

+

+Sisa stok: <%= produk.getJumlahStok() %> +

+

+Jumlah beli: +

+

+Keterangan: +

+ +

+

+ +

+

+
+ + diff --git a/src/web/register.jsp b/src/web/register.jsp new file mode 100644 index 0000000..837eb90 --- /dev/null +++ b/src/web/register.jsp @@ -0,0 +1,60 @@ +<%@ page import="com.ruserba.web.WebUtil" %> +<%@ page import="com.ruserba.model.Database" %> +<%@ page import="com.ruserba.model.Category" %> +<%@ page import="com.ruserba.model.Product" %> +<%@ page import="com.ruserba.model.SearchAttribute" %> +<%@ page import="java.util.ArrayList" %> + +<% request.setAttribute("page_title", "RuSerBa - Registrasi"); %> +<% request.setAttribute("css_file", "styles/register.css"); %> +<% request.setAttribute("js_file", "scripts/register.js"); %> + + +<% + if (WebUtil.isLoggedIn(application, request)) { + response.sendRedirect("index.jsp"); return; + } +%> + +

+Silakan registrasi. bagian yang berlabel bintang (*) wajib diisi. + +

+

+
+ + +
+
+ + +
+
+ + +
+ + +
+
+ + +
+
+ + +
+ + +
+ + +
+ + +
+
+ + +
+
\ No newline at end of file diff --git a/src/web/sample.jsp b/src/web/sample.jsp new file mode 100644 index 0000000..ea36337 --- /dev/null +++ b/src/web/sample.jsp @@ -0,0 +1,5 @@ +<% request.setAttribute("page_title", "Hello RuSerBa!"); %> + +

Hello!

+<% request.removeAttribute("msg"); %> + \ No newline at end of file diff --git a/src/web/scripts/editProfile.js b/src/web/scripts/editProfile.js new file mode 100644 index 0000000..d23ab73 --- /dev/null +++ b/src/web/scripts/editProfile.js @@ -0,0 +1,45 @@ +function cekUsername(){ + var username = getElementById("username").value; + var text = "User name harus terdiri atas 5 karakter dan belum terpakai dalam database. Silakan coba lagi."; + if (username.length > 5){ + if (){ + text = "User name tersedia."; + } + } + getElementById("responseUsername").innerHTML = text; +} + +function cekEmail(){ + var email = getElementById("email").value.split('@'); + var text = "Email tidak valid."; + if (email.length == 2 && email[0].length > 0){ + var email1 = email.split('.'); + if (email1.length > 1 && email1[0].length > 0 + && email1[email1.length-1].length > 1){ + text = "Email valid."; + } + } + getElementById("responseEmail").innerHTML = text; +} + +function cekPasswordMatch(pass, passC){ + var text = ""; + if (pass.localeCompare(passC) != 0){ + text = ""; + } + getElementById("responsePassword").innerHTML = text; +} + +function cekFullname(){ + var username = getElementById("fullname").value; + + if (x != null) +} + +function cekAngka(angka){ + if (!isNaN(parseFloat(angka)) && isFinite(angka)){ + + } else { + + } +} diff --git a/src/web/scripts/global.js b/src/web/scripts/global.js new file mode 100644 index 0000000..f2ba295 --- /dev/null +++ b/src/web/scripts/global.js @@ -0,0 +1,194 @@ +// global.js +// Deklarasi fungsi-fungsi Javascript yang umum. + +// Fungsi untuk membuat XMLHttpRequest. +function createXMLHttpRequest() { + var xmlhttp; + if (window.XMLHttpRequest) + {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else + {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + return xmlhttp; +} + +// Credit goes to quirksmode.org. +function createCookie(name,value,days) { + if (days) { + var date = new Date(); + date.setTime(date.getTime()+(days*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + } + else var expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; +} +function readCookie(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); + } + return null; +} +function eraseCookie(name) { + createCookie(name,"",-1); +} + +function getOkSmall(message) { + return "\"OK\"" + message + ""; +} + +function getWarningSmall(message) { + return "\"Warning\"" + message + ""; +} + +function getErrorSmall(message) { + return "\"Error\"" + message + ""; +} + +function getUsername() { + return readCookie("username"); +} + +function getUserId() { + return parseInt(readCookie("id")); +} + +function isLoggedIn() { + return readCookie("id_user") !== null && getUsername() != null; +} + +function setShoppingBag(bag) { + localStorage.setItem("bag", JSON.stringify(bag)); +} +function getShoppingBag() { + if (localStorage.getItem("bag") === null) setShoppingBag({}); + return JSON.parse(localStorage.getItem("bag")); +} +function deleteShoppingBag() { + localStorage.removeItem("bag"); +} +function setProductQuantity(product_id, quantity) { + var bag = getShoppingBag(); + if (bag[product_id] === undefined) { + bag[product_id] = {}; + bag[product_id]["note"] = ""; + } + bag[product_id]["quantity"] = quantity; + setShoppingBag(bag); +} +function setProductNote(product_id, note) { + var bag = getShoppingBag(); + if (bag[product_id] === undefined) { + bag[product_id] = {}; + bag[product_id]["quantity"] = 0; + } + bag[product_id]["note"] = note; + setShoppingBag(bag); +} +function getProductQuantity(product_id) { + var bag = getShoppingBag(); + if (bag[product_id] === undefined) return 0; + else return bag[product_id]["quantity"]; +} +function getProductNote(product_id) { + var bag = getShoppingBag(); + if (bag[product_id] === undefined) return ""; + else return bag[product_id]["note"]; +} + +// Fungsi-fungsi untuk core +// ------------------------------ + +window.addEventListener("load", function() { + document.getElementById("headerloginbutton").onclick = showLogin; + document.getElementById("headerlogoutbutton").onclick = requestLogout; + updateHeaderLogin(); + document.getElementById("p3_button").onclick = function() { + var jml_stok = document.getElementById("p3_stock").value; + var jml_beli = document.getElementById("p3_quantity").value; + var msg = document.getElementById("p3_message"); + if (jml_beli > jml_stok) msg.innerHTML = getErrorSmall("Stok tidak mencukupi."); + else { + setProductQuantity(3, jml_beli); + msg.innerHTML = getOkSmall("Barang berhasil ditambahkan ke shopping bag."); + } + }; +}); + +// Insialisasi komponen login dari header. +function updateHeaderLogin() { + var divloggedin = document.getElementById("headerloggedin"); + var divnotloggedin = document.getElementById("headernotloggedin"); + if (isLoggedIn()) { + divloggedin.style.display = "block"; divnotloggedin.style.display = "none"; + // Tuliskan username. + document.getElementById("headerusername").innerHTML = getUsername(); + } else { + divloggedin.style.display = "none"; divnotloggedin.style.display = "block"; + } +} + +function getRequestString(requestobject) { + var dataArray = []; + for (var key in requestobject) { + var encodedData = encodeURIComponent(key); + encodedData += "="; + encodedData += encodeURIComponent(requestobject[key]); + dataArray.push(encodedData); + } + return dataArray.join("&"); +} + +function showLogin() { + var popuplayer = document.getElementById("popuplayer"); + var loginelmtstr = + '
\ +
\ +
Blank
\ + \ +

Login Form

\ +

\ +

\ +

\ +
\ +
'; + popuplayer.innerHTML = loginelmtstr; + document.getElementById("logindialogclosebutton").onclick = hideLogin; + document.getElementById("logindialogbutton").onclick = requestLogin; +} + +function hideLogin() { + var popuplayer = document.getElementById("popuplayer"); + popuplayer.innerHTML = ""; +} + +function requestLogin() { + var username = document.getElementById("logindialogusername").value; + var password = document.getElementById("logindialogpassword").value; + var reqobj = {}; + reqobj['username'] = username; + reqobj['password'] = password; + var req = createXMLHttpRequest(); + req.onreadystatechange = function() { + if (req.readyState == 4 && req.status == 200) { + var ret = req.responseText.split("\n"); + if (ret[0] == "1") { hideLogin(); updateHeaderLogin(); } + else document.getElementById("logindialogmessage").innerHTML = getErrorSmall("Login tidak berhasil dilakukan."); + } + } + req.open("POST","login",true); // Bad... + req.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + req.send(getRequestString(reqobj)); + document.getElementById("logindialogmessage").innerHTML = getRequestString(reqobj); +} + +function requestLogout() { + eraseCookie("id_user"); eraseCookie("username"); updateHeaderLogin(); +} diff --git a/src/web/scripts/product.js b/src/web/scripts/product.js new file mode 100644 index 0000000..7f7419b --- /dev/null +++ b/src/web/scripts/product.js @@ -0,0 +1,37 @@ +function setProductOrder() { + var jumlah = document.getElementById("jumlahproduk"); + var keterangan = document.getElementById("keteranganproduk"); + var stok = document.getElementById("jumlahstok"); + var parts = window.location.search.substr(1).split("&"); + var $_GET = {}; + for (var i = 0; i < parts.length; i++) { + var temp = parts[i].split("="); + $_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]); + } + + if(parseInt(jumlah.value) <= parseInt(stok.innerHTML)){ + setProductQuantity($_GET['product_id'], jumlah.value); + document.getElementById("errorjumlah").innerHTML = getOkSmall('Penambahan produk ke shopping bag berhasil'); + }else{ + document.getElementById("errorjumlah").innerHTML = getErrorSmall('Jumlah stok tidak mencukupi'); + } + setProductNote($_GET['product_id'], keterangan.value); +} + +window.addEventListener("load", function(){ + document.getElementById("buybutton").onclick = setProductOrder; + var parts = window.location.search.substr(1).split("&"); + var $_GET = {}; + for (var i = 0; i < parts.length; i++) { + var temp = parts[i].split("="); + $_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]); + } + var jumlahdibag = getProductQuantity($_GET['product_id']); + var keterangandibag = getProductNote($_GET['product_id']); + + var jumlah = document.getElementById("jumlahproduk"); + var keterangan = document.getElementById("keteranganproduk"); + + jumlah.value = jumlahdibag; + keterangan.value = keterangandibag; +}); \ No newline at end of file diff --git a/src/web/scripts/profile.js b/src/web/scripts/profile.js new file mode 100644 index 0000000..d23ab73 --- /dev/null +++ b/src/web/scripts/profile.js @@ -0,0 +1,45 @@ +function cekUsername(){ + var username = getElementById("username").value; + var text = "User name harus terdiri atas 5 karakter dan belum terpakai dalam database. Silakan coba lagi."; + if (username.length > 5){ + if (){ + text = "User name tersedia."; + } + } + getElementById("responseUsername").innerHTML = text; +} + +function cekEmail(){ + var email = getElementById("email").value.split('@'); + var text = "Email tidak valid."; + if (email.length == 2 && email[0].length > 0){ + var email1 = email.split('.'); + if (email1.length > 1 && email1[0].length > 0 + && email1[email1.length-1].length > 1){ + text = "Email valid."; + } + } + getElementById("responseEmail").innerHTML = text; +} + +function cekPasswordMatch(pass, passC){ + var text = ""; + if (pass.localeCompare(passC) != 0){ + text = ""; + } + getElementById("responsePassword").innerHTML = text; +} + +function cekFullname(){ + var username = getElementById("fullname").value; + + if (x != null) +} + +function cekAngka(angka){ + if (!isNaN(parseFloat(angka)) && isFinite(angka)){ + + } else { + + } +} diff --git a/src/web/scripts/register.js b/src/web/scripts/register.js new file mode 100644 index 0000000..fec3e9a --- /dev/null +++ b/src/web/scripts/register.js @@ -0,0 +1,165 @@ +function cekUsername(){ + var valid = true; + var username = document.getElementById("username").value; + var text = "User name harus terdiri atas 5 karakter dan belum terpakai dalam database. Silakan coba lagi."; + if (username.length >= 5) { + // Periksa apakah username sudah ada. + var reqobj = {}; + + reqobj['username'] = username; + + var req = createXMLHttpRequest(); + req.onreadystatechange = function() { + if (req.readyState == 4 && req.status == 200) { + var ret = req.responseText.split("\n"); + if (ret[0] == "1") + { + text = "Username sudah digunakan." + valid = false; + } + else + { + text = "Username valid." + } + } + } + req.open("POST","checkusername",false); // Bad... + req.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + req.send(getRequestString(reqobj)); + } else { + valid = false; + } + document.getElementById("responseUsername").innerHTML = text; + return valid; +} + +function cekEmail(){ + var valid = true; + var email = document.getElementById("email").value.split('@'); + var text = "Email tidak valid."; + if (email.length == 2 && email[0].length > 0){ + var email1 = email[1].split('.'); + if (email1.length > 1 && email1[0].length > 0 && email1[email1.length-1].length > 0) { + text = "Email valid."; + } else valid = false; + } else valid = false; + document.getElementById("responseEmail").innerHTML = text; + + return valid; +} + +function cekPassword(){ + var valid = true; + var pass = document.getElementById("password").value; + var cpass = document.getElementById("confirm_pwd").value; + var text = ""; + + if (pass === "") + { + text = "Password tidak boleh kosong." + valid = false; + } + else if (pass.length < 8) + { + text = "Password harus minimal terdiri dari 8 karakter." + valid = false; + } + else + { + if (pass === cpass) + { + var email = document.getElementById("email").value; + var username = document.getElementById("username").value; + + if (pass === email) + { + text = "Password tidak boleh sama dengan email"; + valid = false; + } + else if (pass === username) + { + text = "Password tidak boleh sama dengan username"; + valid = false; + } + else + { + text = "Password sama"; + } + } + else + { + text = "Password tidak sama"; + valid = false; + } + } + + document.getElementById("responsePassword").innerHTML = text; + + return valid; +} + +function cekFullname(){ + var valid = true; + var nama_lengkap = document.getElementById("nama_lengkap").value; + if (nama_lengkap.indexOf(" ") == -1) + { + document.getElementById("responseFullname").innerHTML = "Nama lengkap harus terdiri dari minimal dua kata."; + valid = false; + } else { + document.getElementById("responseFullname").innerHTML = "Nama lengkap valid."; + } + return valid; +} + +function cobaRegister() { + var username = document.getElementById("username").value; + var email = document.getElementById("email").value; + var password = document.getElementById("password").value; + var nama_lengkap = document.getElementById("nama_lengkap").value; + var provinsi = document.getElementById("provinsi").value; + var kota = document.getElementById("kota").value; + var alamat = document.getElementById("alamat").value; + var kode_pos = document.getElementById("kode_pos").value; + var telepon = document.getElementById("telepon").value; + + var valid1 = cekUsername(); + var valid2 = cekEmail(); + var valid3 = cekPassword(); + var valid4 = cekFullname(); + + var valid = valid1 && valid2 && valid3 && valid4; + + if (!valid) + { + document.getElementById("responseRegister").innerHTML = "Terdapat masukan yang tidak valid; registrasi dibatalkan."; + } + else + { + document.getElementById("responseRegister").innerHTML = "Memroses form registrasi..."; + var user = {}; + + user['username'] = username; + user['email'] = email; + user['password'] = password; + user['namaLengkap'] = nama_lengkap; + user['provinsi'] = provinsi; + user['kota'] = kota; + user['alamat'] = alamat; + user['kodePos'] = kode_pos; + user['kotak'] = telepon; + + var req = createXMLHttpRequest(); + req.onreadystatechange = function() { + if (req.readyState == 4 && req.status == 200) { + window.location = "index.jsp"; + //alert(req.responseText); + //var ret = req.responseText.split("\n"); + //if (ret[0] == "1") { hideLogin(); updateHeaderLogin(); } + //else document.getElementById("logindialogmessage").innerHTML = getErrorSmall("Login tidak berhasil dilakukan."); + } + } + req.open("POST","registeruser",true); // Bad... + req.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + req.send(getRequestString(user)); + } +} diff --git a/src/web/scripts/sample.js b/src/web/scripts/sample.js new file mode 100644 index 0000000..0053cdc --- /dev/null +++ b/src/web/scripts/sample.js @@ -0,0 +1,8 @@ +//window.addEventListener("load", alert("Hello RuSerBa!")); + +/*window.addEventListener("load", function() { + document.getElementById("paragraf").onclick = function() { + alert("Ini adalah suatu paragraf Lorem Ipsum."); + }; +}); +*/ diff --git a/src/web/scripts/sample2.js b/src/web/scripts/sample2.js new file mode 100644 index 0000000..d3da1b8 --- /dev/null +++ b/src/web/scripts/sample2.js @@ -0,0 +1,3 @@ +window.addEventListener("load", function() { + deleteShoppingBag(); +}); diff --git a/src/web/search.jsp b/src/web/search.jsp new file mode 100644 index 0000000..f8f7b35 --- /dev/null +++ b/src/web/search.jsp @@ -0,0 +1,90 @@ +<%@ page import="com.ruserba.web.WebUtil" %> +<%@ page import="com.ruserba.model.Database" %> +<%@ page import="com.ruserba.model.Category" %> +<%@ page import="com.ruserba.model.Product" %> +<%@ page import="com.ruserba.model.SearchAttribute" %> +<%@ page import="java.util.ArrayList" %> + +<% request.setAttribute("page_title", "RuSerBa - Hasil Pencarian"); %> +<% request.setAttribute("css_file", "styles/browse_product.css"); %> + + +<% + Database db = WebUtil.getDatabase(getServletContext()); + + String product_name = request.getParameter("product_name"); + if (product_name == null) product_name = ""; + + String category_id_str = request.getParameter("category_id"); + int category_id; + if (category_id_str == null) category_id = 0; + else category_id = Integer.parseInt(category_id_str); + + String price_str = request.getParameter("price"); + int price; + if (price_str == null || price_str.equals("")) price = -1; + else price = Integer.parseInt(price_str); + + String price_comparison_str = request.getParameter("price_comparison"); + int price_comparison; + if (price_comparison_str == null) price_comparison = 0; + else price_comparison = Integer.parseInt(price_comparison_str); + + String sort_category_id_str = request.getParameter("sort_category_id"); + int sort_category_id; + if (sort_category_id_str == null) sort_category_id = 1; + else sort_category_id = Integer.parseInt(sort_category_id_str); + + String sort_method_str = request.getParameter("sort_method"); + int sort_method; + if (sort_method_str == null) sort_method = 1; + else sort_method = Integer.parseInt(sort_method_str); +%> + +

Hasil Pencarian

+ +
+
+ + + + + + + + +
+
+ +<% + SearchAttribute attr = new SearchAttribute(); + + attr.setNamaBarang(product_name); + attr.setIdKategori(category_id); + attr.setHarga(price); + attr.setIdPerbandingan(price_comparison); + attr.setIdPengurutan(sort_category_id); + attr.setIdMetodePengurutan(sort_method); + attr.setIndeks(0); + attr.setJumlah(-1); + + ArrayList prod_lst = db.getProductSearchResult(attr); + + out.write("
"); + for (int j = 0; j < prod_lst.size(); j++) + { + request.setAttribute("produk", prod_lst.get(j)); + %> + + <% + } + out.write("
"); +%> + + diff --git a/src/web/styles/browse_product.css b/src/web/styles/browse_product.css new file mode 100644 index 0000000..1d871d4 --- /dev/null +++ b/src/web/styles/browse_product.css @@ -0,0 +1,19 @@ +#content .browseproduct .browseproductspan { + display: inline-block; + vertical-align: middle; + margin-right: 20px; +} + +#content .browseproduct .browseproductspan input { + margin-left: 5px; + margin-right: 10px; +} + +#content .browseproduct, #content h1, #content h2 { + text-align: center; +} + +#content h2 { + margin: 0px; + margin-top: 30px; +} diff --git a/src/web/styles/editProfile.css b/src/web/styles/editProfile.css new file mode 100644 index 0000000..a2dadad --- /dev/null +++ b/src/web/styles/editProfile.css @@ -0,0 +1,26 @@ +/* Agar tidak mengubah non-content, selalu tambahkan "#content" sebelum elemen yang diacu. */ +#register_form { + width:95%; + margin:auto; + padding-top:15px; + padding-bottom:15px; + display:block; +} + +#button_right { + margin-left:20px; +} + +#register_form label{ + display : inline-block; + margin:auto; + width: 20%; + font-family: Tahoma; + color: #3B5999; + line-height: 40px; + letter-spacing:1px; +} + +#register_form input{ + width: 20%; +} \ No newline at end of file diff --git a/src/web/styles/global.css b/src/web/styles/global.css new file mode 100644 index 0000000..282baff --- /dev/null +++ b/src/web/styles/global.css @@ -0,0 +1,185 @@ +#popuplayer #cover { + position: fixed; + z-index: 100; + left: 0px; + right: 0px; + top: 0px; + bottom: 0px; + background-color: rgba(0,0,0,0.5); +} + +#logindialogclose { + float: right; + text-align: right; + vertical-align: top; + width: 30px; + margin-top: 5px; + margin-right: 5px; + padding: 0px; +} + +#logindialoginvisible { + float: left; + text-align: left; + vertical-align: top; + width: 30px; + margin-top: 5px; + margin-left: 5px; + padding: 0px; +} + +#logindialog { + position: fixed; + z-index: 101; + top: 30%; + left: 50%; + margin-left: -125px; + width: 250px; + background-color: #FFF; + border-radius: 10px; + +} + +#logindialog h1, #logindialog p { + text-align: center; +} + +#logindialog h1 { + font-family: serif; + font-size: 18pt; +} + +#logindialog #logindialogmessage { + text-align: center; + margin: 10px; +} + +#core { + margin: 20px 10% 20px 10%; +} + +#content { + margin: 20px 20px 20px 20px; + padding: 20px; + border: 1px solid #ccc; + border-radius: 10px; +} + +#footer { + border: 1px solid #ccc; + border-radius: 10px; + text-align: center; +} + +/* +#header p, #footer p { + color: black; +} +*/ + +#header .headertabs { + position: relative; + min-height: 80px; + clear: none; + margin: 25px 0; +} + +#header .headertab { + float: left; +} + +#header .headertab > label { + background: #eee; + padding: 10px 50px 10px 50px; + border: 1px solid #ccc; + border-radius: 10px 10px 0px 0px; + margin-left: -1px; + position: relative; + left: 1px; +} + +#header .headertab [type=radio] { + display: none; +} + +#header .headertabcontent { + position: absolute; + top: 28px; + left: 0; + background: white; + border-radius: 0px 10px 10px 10px; + right: 0; + bottom: 0; + padding-top: 15px; + padding-left: 15px; + border: 1px solid #ccc; +} + +#header .headertabcontent a { + margin-right: 30px; + text-decoration: none; +} + +#header .headertabcontent label { + margin-right: 5px; +} + +#header .headertabcontent #headersearchname, +#header .headertabcontent #headersearchcategory { + margin-right: 10px; +} + +#header .headertabcontent input[type=submit] { + margin-left: 10px; +} + +#header .headertabcontent a:hover { + text-decoration: underline; +} + +#header [type=radio]:checked ~ label { + background: white; + border-bottom: 1px solid white; + z-index: 2; +} + +#header [type=radio]:checked ~ label ~ .headertabcontent { + z-index: 1; +} + +#header #headershoppingbag { + float: right; + width: 50px; + margin-top: -25px; + text-align: right; + padding: 0px; + position: relative; + z-index: 1; +} + +#header #headerloggedin, #header #headernotloggedin { + float: right; + text-align: right; + line-height: 3px; + width: 300px; + clear: none; +} + +#header #headerlogoutbutton { + margin-left: 20px; +} + +.systemmessagesmall { + font: 11pt sans-serif; + color: #333; +} + +.systemmessagesmall img { + margin-right: 5px; + vertical-align: middle; +} + +#categorysortdiv { + text-align: right; + margin-bottom: 20px; +} \ No newline at end of file diff --git a/src/web/styles/profile.css b/src/web/styles/profile.css new file mode 100644 index 0000000..a2dadad --- /dev/null +++ b/src/web/styles/profile.css @@ -0,0 +1,26 @@ +/* Agar tidak mengubah non-content, selalu tambahkan "#content" sebelum elemen yang diacu. */ +#register_form { + width:95%; + margin:auto; + padding-top:15px; + padding-bottom:15px; + display:block; +} + +#button_right { + margin-left:20px; +} + +#register_form label{ + display : inline-block; + margin:auto; + width: 20%; + font-family: Tahoma; + color: #3B5999; + line-height: 40px; + letter-spacing:1px; +} + +#register_form input{ + width: 20%; +} \ No newline at end of file diff --git a/src/web/styles/register.css b/src/web/styles/register.css new file mode 100644 index 0000000..a2dadad --- /dev/null +++ b/src/web/styles/register.css @@ -0,0 +1,26 @@ +/* Agar tidak mengubah non-content, selalu tambahkan "#content" sebelum elemen yang diacu. */ +#register_form { + width:95%; + margin:auto; + padding-top:15px; + padding-bottom:15px; + display:block; +} + +#button_right { + margin-left:20px; +} + +#register_form label{ + display : inline-block; + margin:auto; + width: 20%; + font-family: Tahoma; + color: #3B5999; + line-height: 40px; + letter-spacing:1px; +} + +#register_form input{ + width: 20%; +} \ No newline at end of file diff --git a/src/web/styles/sample.css b/src/web/styles/sample.css new file mode 100644 index 0000000..a2d2a93 --- /dev/null +++ b/src/web/styles/sample.css @@ -0,0 +1,28 @@ +/* Agar tidak mengubah non-content, selalu tambahkan "#content" sebelum elemen yang diacu. */ +#content p { + color: #444; + line-height: 40px; +} + +#content #gambar { + float: right; + width: 200px; + margin: 20px; +} + +#register_form { + width:95%; + margin:auto; + height:520px; + padding-top:30px; + display:block; +} + +#register_form label{ + display : inline-block; + width: 30%; + font-family: Tahoma; + color: #3B5999; + line-height: 40px; + letter-spacing:1px; +} \ No newline at end of file