Anda di halaman 1dari 100

MODUL TUTORIAL

APLIKASI INVENTARIS SARANA DAN


PRASARANA DI SMK
BERBASIS WEB

By Team RPL
2019
A. Pembuatan Database
1. Buatlah database dengan nama invenity

Gbr. 1 database invenity

2. Setelah database terbentuk, selanjutnya membuat 13 tabel dengan nama :


1) component dengan jumlah kolom 10, yaitu component_id, component_name,
component_page, component_type, active, created_by, created_date, update_by,
update_date, revision

Gbr. 2 tabel component

2
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
2) device_changes dengan jumlah kolom 5, yaitu changes_id, device_id, changes, update_by,
update_date

Gbr. 3 tabel device_changes

3) device_list dengan jumlah kolom 17, yaitu device_id, type_id, device_code, device_brand,
device_model, device_serial, device_color, device_description, device_photo, device_status,
location_id, device_deployment_date, created_by, created_date, updated_by, updated_date,
revision

Gbr. 4 tabel device_list

3
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
4) device_type dengan jumlah kolom 9, type_id, type_name, type_code, active, created_by,
created_date, updated_by, updated_date, revision

Gbr. 5 tabel device_type

5) location dengan jumlah kolom 9, yaitu location_id, location_name, location_photo, active,


created_by, created_date, updated_by, updated_date, revision

Gbr. 6 tabel location

4
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
6) location_building dengan jumlah kolom 8, yaitu building_id, building_name, active,
created_by, created_date, updated_by, updated_date, revision

Gbr. 7 tabel location_building

7) location_details dengan jumlah kolom 11, yaitu detail_id, location_id, place_id, building_id,
floor_id, active, created_by, created_date, updated_by, updated_date, revision

Gbr. 8 tabel location_details

5
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
8) location_floor dengan jumlah kolom 8, yaitu floor_id, floor_name, active, created_by,
created_date, updated_by, updated_date, revision

Gbr. 9 tabel location_floor

9) location_place dengan jumlah kolom 8, yaitu place_id, place_name, active, created_by,


created_date, updated_by, updated_date, revision

Gbr. 10 tabel location_place

10) system_logs dengan jumlah kolom 4, yaitu log_id, log_date, username, description

Gbr. 11 tabel system_logs

6
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
11) system_settings dengan jumlah kolom 8, yaitu setting_name, setting_value, active,
created_by, created_date, updated_by, updated_date, revision

Gbr. 12 tabel system_settings

12) users dengan jumlah kolom 13, yaitu username, password, salt, level, active, first_name,
last_name, photo, created_by, created_date, updated_by, updated_date, revision

Gbr. 13 tabel users

13) user_privileges dengan jumlah kolom 7, yaitu username, privileges, created_by, created_date,
updated_by, updated_date, revision

Gbr. 14 tabel user_privileges

7
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
B. Pembuatan Script PHP
Setelah database selesai dibuat selanjutnya membuat file php yang disimpan dalam folder yang
terletak di C:\xampp\htdocs\invenity dan disimpan dengan ekstensi ( .php).
Folder invenity berisi : folder assets, folder class, folder include, folder js, folder lib, file
component_management.php, dashboard.php, device_management.php, index.php,
location_management.php, my_profile.php, process.php, report.php, report_detailed.php,
report_summary.php, system_log.php, system_settings.php, user_edit.php, user_management.php
 Folder assets berisi :
* Folder angularicons
* Folder css
* Folder fonts
* Folder images
* Folder js
* Folder plugins
* File index.php
 Folder class berisi file component.class.php, device.class.php, index.php, inventory.class.php,
location.class.php, system.class.php, user.class.php
 Folder include file include_dashboard_chart.php, include_footer.php, include_header.php,
include_modal.php, include_modal_component.php, include_modal_device.php,
include_modal_device_detail.php, include_modal_device_edit.php,
include_modal_device_type.php, include_modal_location.php, include_modal_user.php,
index.php, init_chosen.php, init_datatables.php, init_fancybox.php, init_showpassword.php,
init_tinymce.php, init_validetta.php, signin_status.php

SCRIPT PHP
1. component_management.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
require_once(__DIR__ . '/class/component.class.php');
$comClass = new ComponentClass();
// Check if user already logged in
include("./include/signin_status.php");
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<?php
if (isset($_SESSION['save_status']) && $_SESSION['save_status']!=""){

8
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
// show info
echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-
dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>$_SESSION[save_status]</div>";
// clear save_status session value
$_SESSION["save_status"] = "";
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-pushpin"></i> &nbsp; <?php echo $current_page_name; ?>
<span class="pull-right">
<button type="button" class="btn btn-default btn-sm" onclick="show_add_new_component()">
<i class="glyphicon glyphicon-plus"></i> Add New</button></span></h3>
<br></div>
<div class='panel-body'>
<?php
// Get current component
$data = $comClass->show_component();
$data_num = count($data);
// Show if exists
if ($data_num!=0) {
$data_table = "<table class='table table-bordered table-striped'
id='datatable'><thead><tr><th>Component Name</th><th>Component
Page</th><th>Active</th><th>Actions</th></tr></thead><tbody>";
foreach ($data as $dt_component) {
$component_id = $dt_component["component_id"];
$component_name = $dt_component["component_name"];
$component_page = $dt_component["component_page"];
$active = $dt_component["active"];
if ($active=="yes") {
$active_status = "<span class='label label-success'>Yes</span><input type='hidden'
id='cactive_$component_id' value='yes'>";
$button_status = "<button type='button' title='Deactive' class='btn btn-danger btn-sm'
onclick=\"component_change_status('$component_id', '$component_name', 'no')\"><i
class='glyphicon glyphicon-remove'></i></button>";
} elseif ($active=="no") {
$active_status = "<span class='label label-danger'>No</span><input type='hidden'
id='cactive_$component_id' value='no'>";
$button_status = "<button type='button' title='Activate' class='btn btn-success btn-sm'
onclick=\"component_change_status('$component_id', '$component_name', 'yes')\"><i
class='glyphicon glyphicon-ok'></i></button>";
}
$data_table .= "<tr>
<td id='cname_$component_id'>$component_name</td>
<td id='cpage_$component_id'>$component_page</td>
<td>$active_status</td>

9
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<td>$button_status <button type='button' title='Edit' class='btn btn-default btn-sm'
onclick=\"show_edit_component('$component_id')\"><i class='glyphicon glyphicon-
pencil'></i></button></td></tr>";
}
$data_table .= "</tbody></table>";
echo $data_table;
}
// No data found?
else {
echo "<p>No Data Found!</p>";
}
?>
</div> </div></div>
<?php
// get footer
include("./include/include_footer.php");
// get plugins
include("./include/init_datatables.php");
// get page setting
echo "<script type='text/javascript' src='./js/component_management.js'></script>";
include("./include/include_modal_component.php");
?>
2. dashboard.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userclass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
require_once(__DIR__ . '/class/device.class.php');
$devClass = new DeviceClass();
/**
* Check if user already logged in
*/
if (!isset($_SESSION['username']) && !isset($_SESSION['level'])) {
// form filled -> process sign in and refresh if success
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['action']) &&
$_POST['action']=="sign_in") {
$userclass->sign_in($_POST['username'], $_POST['password']);
}
// form didn't fill / illegal request -> redirect to login page
else {
header("Location: ./index.php");

10
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
die();
}
}
else if (isset($_SESSION['username']) && isset($_SESSION['level']) &&
$_SESSION['username']!="" && $_SESSION['level']!="") {
// already logged in
// sign out
if (isset($_POST['action']) && $_POST['action']=="sign_out") {
$userclass->sign_out();
}
else {
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><i class="glyphicon glyphicon-dashboard"></i> &nbsp; Status
Monitor</h3> <br>
</div>
<div class="panel-body">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<canvas id="canvas" class="img-thumbnail"></canvas>
</div> </div> </div> </div>
<?php
// get footer
include("./include/include_footer.php");
// get dashboard chart
include("./include/include_dashboard_chart.php");
}
}
?>
3. device_management.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
require_once(__DIR__ . '/class/location.class.php');
$locClass = new LocationClass();
require_once(__DIR__ . '/class/device.class.php');
$devClass = new DeviceClass();
// Location details settings
$setting_location_details = $invClass->setting_data("location_details");

11
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
// Check if user already logged in
include("./include/signin_status.php");
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<?php
if (isset($_SESSION['save_status']) && $_SESSION['save_status']!=""){
// show info
echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-
dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>$_SESSION[save_status]</div>";
// clear save_status session value
$_SESSION["save_status"] = "";
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-briefcase"></i> &nbsp; <?php echo $current_page_name; ?>
<span class="pull-right"><button type="button" class="btn btn-default btn-sm"
onclick="show_add_device_type()"><i class="glyphicon glyphicon-plus"></i> Add Device
Type</button></span>
<span class="pull-right"><button type="button" class="btn btn-default btn-sm"
onclick="show_add_device()"><i class="glyphicon glyphicon-plus"></i> Add
Device</button></span> </h3><br>
</div>
<div class='panel-body'>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#dev_list" id="dev_list_tab" role="tab" data-toggle="tab" aria-controls="dev_list" aria-
expanded="true"><i class="glyphicon glyphicon-hdd"></i> Device List</a> </li>
<li role="presentation">
<a href="#dev_type_list" id="dev_type_list_tab" role="tab" data-toggle="tab" aria-
controls="dev_type_list" aria-expanded="true"><i class="glyphicon glyphicon-pushpin"></i>
Device Type List</a></li></ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade active in" id="dev_list" aria-
labelledby="dev_list_tab">
<?php
// Get device list by type
if (isset($_GET['type_id']) && $_GET['type_id']!="") {
$dev_list = $devClass->show_device_by_type($_GET['type_id']);
if (count($dev_list)>0) {
$no = 0;
$content = "<table class='table table-striped table-bordered datatables'>
<thead>
<tr>
<th>No</th>

12
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<th>Code</th>
<th>Brand</th>
<th>Model</th>
<!--<th>SN</th>-->
<th>Status</th>
<th>Location</th>
<th>Actions</th>
</tr></thead>
<tbody>";
foreach ($dev_list as $device_data) {
$no++;
$device_id = $device_data["device_id"];
$device_code = $device_data["device_code"];
$type_id = $device_data["type_id"];
$type_name = $device_data["type_name"];
$device_brand = stripslashes($device_data["device_brand"]);
$device_model = stripslashes($device_data["device_model"]);
$device_color = stripslashes($device_data["device_color"]);
$device_serial = stripslashes($device_data["device_serial"]);
$device_description = $device_data["device_description"];
$device_photo = $device_data["device_photo"];
$device_photo_break = explode(".", strrev($device_data["device_photo"]), 2);
$device_photo_thumbnail = strrev($device_photo_break[1])."_thumbnail.".strrev($
device_photo_break[0]);
$device_status = $device_data["device_status"];
$location_id = $device_data["location_id"];
$location_name = $device_data["location_name"];
$device_deployment_date = $device_data["device_deployment_date"];
// If location details enable
$dev_details = "";
if ($setting_location_details=="enable") {
$place_id = $device_data["place_id"];
$building_id = $device_data["building_id"];
$floor_id = $device_data["floor_id"];
$place_name = $device_data["place_name"];
$building_name = $device_data["building_name"];
$floor_name = $device_data["floor_name"];
$dev_details = "<input type='hidden' id='l_place_id_$device_id' value='$place_id'>
<input type='hidden' id='l_building_id_$device_id' value='$building_id'>
<input type='hidden' id='l_floor_id_$device_id' value='$floor_id'>
<input type='hidden' id='l_place_name_$device_id' value='$place_name'>
<input type='hidden' id='l_building_name_$device_id' value='$building_name'>
<input type='hidden' id='l_floor_name_$device_id' value='$floor_name'>";
}
$content .= "<tr>
<td>$no</td>
<td>$device_code</td>
<td>$device_brand</td>
<td>$device_model</td>

13
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<!-- <td>$device_serial</td> -->
<td>$device_status</td>
<td>$location_name</td>
<input type='hidden' id='l_dev_id_$device_id' value='$device_id'>
<input type='hidden' id='l_dev_code_$device_id' value='$device_code'>
<input type='hidden' id='l_type_id_$device_id' value='$type_id'>
<input type='hidden' id='l_dev_brand_$device_id' value='$device_brand'>
<input type='hidden' id='l_dev_model_$device_id' value='$device_model'>
<input type='hidden' id='l_dev_color_$device_id' value='$device_color'>
<input type='hidden' id='l_dev_serial_$device_id' value='$device_serial'>
<input type='hidden' id='l_dev_description_$device_id' value='$device_description'>
<input type='hidden' id='l_dev_photo_real_$device_id' value='$device_photo'>
<input type='hidden' id='l_dev_photo_description_$device_id'
value='".strip_tags($device_description)."'>
<input type='hidden' id='l_dev_photo_$device_id' value='$device_photo_thumbnail'>
<input type='hidden' id='l_dev_status_$device_id' value='$device_status'>
<input type='hidden' id='l_dev_type_name_$device_id' value='$type_name'>
<input type='hidden' id='l_dev_location_id_$device_id' value='$location_id'>
<input type='hidden' id='l_dev_location_name_$device_id' value='$location_name'>
<input type='hidden' id='l_dev_deployment_date_$device_id'
value='$device_deployment_date'>
<!-- Device details -->
$dev_details
<td>
<button type='button' class='btn btn-primary' title='Show Detail'
onclick=\"show_device_detail('$device_id')\"><i class='glyphicon glyphicon-eye-open'>
</i></button>
<button type='button' class='btn btn-default' title='Edit Device' onclick=\"show_edit_device
('$device_id')\"><i class='glyphicon glyphicon-pencil'></i></button>
</td>
</tr>";
}
$content .= "</tbody></table>";
$content .= "<p class='text-center'><a href='device_management.php' class='btn btn-
primary'>Back to Device Type</a></p>";
// Legend
$legend = "<legend>$type_name</legend>";
echo $legend.$content;
}
else {
echo "<p class='text-center'>No Data Found!</p><p class='text-center'><a
href='device_management.php' class='btn btn-primary'>Back to Device Type</a></p>";
}
}
// Show device type
else {
?>
<legend>Device List</legend>
<div class="alert alert-info">

14
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Information :</strong> To view device list, you should choose device type first.
</div>
<?php
$dev_type_list = $devClass->show_device_type("","","yes");
if (count($dev_type_list)>0) {
$no = 0;
$content = "<table class='table table-striped table-bordered datatables'>
<thead>
<tr>
<th>No</th>
<th>Type Name</th>
<th>Code</th>
<th>Device Total</th>
<th>Actions</th>
</tr>
</thead>
<tbody>";
foreach ($dev_type_list as $type_data) {
$no++;
$type_id = $type_data["type_id"];
$type_name = stripslashes($type_data["type_name"]);
$type_code = stripslashes($type_data["type_code"]);
$device_total = $type_data["device_total"];
$active = $type_data["active"];
$content .= "<tr>
<td>$no</td>
<td>$type_name</td>
<td>$type_code</td>
<td>$device_total Devices</td>
<td><a href='?type_id=$type_id' class='btn btn-primary btn-sm'>Show Device</a></td>
</tr>";
}
$content .= "</tbody></table>";
echo $content;
}
else {
echo "<p>No Data Found!</p>";
}
}
?>
</div>
<div role="tabpanel" class="tab-pane fade" id="dev_type_list" aria-labelledby="dev_list_type_tab">
<legend>Device Type List</legend>
<?php
$dev_type_list = $devClass->show_device_type();
if (count($dev_type_list)>0) {
$no = 0;
$content = "<table class='table table-striped table-bordered datatables'>

15
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<thead>
<tr>
<th>No</th>
<th>Type Name</th>
<th>Type Code</th>
<th>Active</th>
<th>Actions</th>
</tr></thead>
<tbody>";
foreach ($dev_type_list as $type_data) {
$no++;
$type_id = $type_data["type_id"];
$type_name = stripslashes($type_data["type_name"]);
$type_code = stripslashes($type_data["type_code"]);
$active = $type_data["active"];
if ($active=="yes") {
$active_status = "<span class='label label-success'>Yes</span><input type='hidden'
id='dtactive_$type_id' value='yes'>";
$button_status = "<button type='button' title='Deactive' class='btn btn-danger btn-sm'
onclick=\"device_type_change_status('$type_id', '$type_name', 'no')\"><i class='glyphicon
glyphicon-remove'></i></button>";
}
elseif ($active=="no") {
$active_status = "<span class='label label-danger'>No</span><input type='hidden'
id='dtactive_$type_id' value='no'>";
$button_status = "<button type='button' title='Activate' class='btn btn-success btn-sm'
onclick=\"device_type_change_status('$type_id', '$type_name', 'yes')\"><i class='glyphicon
glyphicon-ok'></i></button>";
}
$content .= "<tr>
<td>$no</td>
<td>$type_name</td>
<td>$type_code</td>
<td>$active_status</td>
<td>$button_status</td>
</tr>";
}
$content .= "</tbody></table>";
echo $content;
}
else {
echo "<p>No Data Found!</p>";
}
?>
</div></div></div></div></div>
<?php
// get footer
include("./include/include_footer.php");
// get plugins

16
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
include("./include/init_tinymce.php");
include("./include/init_datatables.php");
include("./include/init_validetta.php");
include("./include/init_chosen.php");
include("./include/init_fancybox.php");
// get page setting
echo "<script type='text/javascript' src='./js/device_management.js'></script>";
include("./include/include_modal_device_detail.php");
include("./include/include_modal_device.php");
include("./include/include_modal_device_type.php");
// include("./include/include_modal_device_edit.php");
?>
4. index.php
<?php session_start();
// Check if user already logged in
if (isset($_SESSION['username']) && isset($_SESSION['level']) && $_SESSION['username']!=""
&& $_SESSION['level']!="") {
header("Location: ./dashboard.php");
die();
}
else {
require_once('./class/inventory.class.php');
$invClass = new Inventory();
?>
<!DOCTYPE html>
<html>
<head>
<title>
<?php
if ($invClass->setting_data("inventory_name")!="") {
echo $invClass->setting_data("inventory_name");
} else {
echo "Inventory System";
}
?>
</title>
<!-- Styling -->
<link rel="icon" href="./assets/images/favicon.ico">
<link rel="stylesheet" type="text/css" href="./assets/css/<?php if ($invClass-
>setting_data("color_scheme")!="") { echo $invClass->setting_data("color_scheme"); } else
{echo "site-default.min.css";} ?>">
<link rel="stylesheet" type="text/css" href="./assets/plugins/pace/pace.css">
</head>
<body background="./assets/images/backgrounds/<?php if ($invClass-
>setting_data("body_background")!="") { echo $invClass->setting_data("body_background"); }
else {echo "symphony.png";} ?>">
<div class="docs-header">
<!--nav-->

17
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<nav class="navbar navbar-default navbar-custom" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span></button>
<a class="navbar-brand" href="#">
<img src="assets/images/<?php if ($invClass->setting_data("inventory_logo")!="") { echo
$invClass->setting_data("inventory_logo"); } else {echo "logo.png";} ?>" height="40"></a></div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<!-- <li><a class="nav-link current" href="#">Home</a></li>
<li><a class="nav-link" href="#">About</a></li> --></ul>
</div></div></nav>
<!--header-->
<div class="topic">
<div class="container">
<div id="jGrowl-container" class="jGrowl top-right"></div>
<div class="col-md-7">
<h3>
<?php
if ($invClass->setting_data("inventory_name")!="") {
echo $invClass->setting_data("inventory_name");
} else {
echo "Inventory System";
}
?>
</h3>
<h4>
<?php
if ($invClass->setting_data("inventory_slogan")!="") {
echo $invClass->setting_data("inventory_slogan");
} else {
echo "Welcome to inventory system!";
}
?>
</h4></div>
<div class="col-md-5">
<div class="advertisement">
<form name="sign_in_form" id="sign_in_form" action="dashboard.php" method="post">
<div class="form-group">
<label for="username"><i class="glyphicon glyphicon-user"></i> &nbsp; Username</label>
<input type="text" name="username" id="username" maxlength="30" class="form-control"
autofocus required <?php if (isset($_SESSION['sign_in_username'])) { echo "
value='".$_SESSION['sign_in_username']."'";} ?>></div>
<div class="form-group">
<label for="password"><i class="glyphicon glyphicon-lock"></i> &nbsp; Password</label>

18
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<input type="password" name="password" id="password" class="form-control" required <?php
if (isset($_SESSION['sign_in_password'])) { echo " value='".$_SESSION['sign_in_password']."'";}
?>>
</div>
<div class="form-group">
<input type="hidden" name="action" value="sign_in">
<button type="submit" id="sign_in_initiate" class="btn btn-primary"><i class="glyphicon
glyphicon-log-in"></i> Sign In</button>
<span class="pull-right">Forgot your account?</span></div></form>
<?php // Error when signing in - alert and removem session
if (isset($_SESSION['sign_in_error']) && $_SESSION['sign_in_error']==1) {
echo "<div class='alert alert-danger alert-dismissable' id='sign_in_alert'><button type='button'
class='close' data-dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>Sign in failed!<br>Please check your username and
password.</div>";
session_destroy();
}
?>
</div></div></div></div></div>
<div class="container document">
<div class="row">
<div class="col-md-12 well">
<div style="margin-top: 30px;"></div>
<div class="col-md-6">
<h4>About</h4>
<?php echo $invClass->setting_data("inventory_description"); ?>
</div>
<div class="col-md-6">
<h4>Location</h4>
<?php echo $invClass->setting_data("inventory_location"); ?>
<p>
<i class="glyphicon glyphicon-phone-alt"></i> &nbsp;
Phone : <?php if ($invClass->setting_data("inventory_phone_number")!="") { echo $invClass-
>setting_data("inventory_phone_number"); } else {echo "-";} ?>
</p>
<p>
<i class="glyphicon glyphicon-print"></i> &nbsp;
Fax : <?php if ($invClass->setting_data("inventory_fax_number")!="") { echo $invClass-
>setting_data("inventory_fax_number"); } else {echo "-";} ?>
</p>
<p>
<i class="glyphicon glyphicon-envelope"></i> &nbsp;
<?php if ($invClass->setting_data("inventory_email")!="") { echo $invClass-
>setting_data("inventory_email"); } else {echo "-";} ?>
</p>
<p>
<i class="glyphicon glyphicon-globe"></i> &nbsp;
<?php if ($invClass->setting_data("inventory_website")!="") { echo $invClass-
>setting_data("inventory_website"); } else {echo "-";} ?>

19
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
</p>
</div></div></div></div>
</body></html>
<!-- Aditional Script -->
<script type="text/javascript" src="./assets/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="./assets/plugins/pace/pace.js"></script>
<?php
}
// /End else
?>
5. location_management.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/location.class.php');
$locationclass = new LocationClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
// Check if user already logged in
include("./include/signin_status.php");
// get header
include("./include/include_header.php");
// Location details settings
$setting_location_details = $invClass->setting_data("location_details");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<?php
if (isset($_SESSION['save_status']) && $_SESSION['save_status']!=""){
// show info
echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-
dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>$_SESSION[save_status]</div>";
// clear save_status session value
$_SESSION["save_status"] = "";
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-globe"></i> &nbsp; <?php echo $current_page_name; ?>
<span class="pull-right">
<button type="button" class="btn btn-default btn-sm" onclick="show_add_new_location()"><i
class="glyphicon glyphicon-plus"></i> New Location</button>

20
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<?php // If location details settings enabled, show add new button. else hide it
if ($setting_location_details == "enable") : ?>
<button type="button" class="btn btn-default btn-sm"
onclick="show_add_new_location_details('place')"><i class="glyphicon glyphicon-plus"></i>
New Place</button>
<button type="button" class="btn btn-default btn-sm"
onclick="show_add_new_location_details('building')"><i class="glyphicon glyphicon-
plus"></i> New Building</button>
<button type="button" class="btn btn-default btn-sm"
onclick="show_add_new_location_details('floor')"><i class="glyphicon glyphicon-plus"></i>
New Floor</button>
<?php endif; ?>
</span></h3>
<br>
</div>
<div class='panel-body'>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#loc_list" id="loc_list_tab" role="tab" data-toggle="tab" aria-controls="loc_list" aria-
expanded="true"><i class="glyphicon glyphicon-map-marker"></i> Locations</a>
</li>
<?php // If location details settings enabled, show add new button. else hide it
if ($setting_location_details == "enable") : ?>
<li role="presentation">
<a href="#loc_place_list" id="loc_place_list_tab" role="tab" data-toggle="tab" aria-
controls="loc_place_list" aria-expanded="true"><i class="glyphicon glyphicon-globe"></i>
Location Places</a></li>
<li role="presentation">
<a href="#loc_building_list" id="loc_building_list_tab" role="tab" data-toggle="tab" aria-
controls="loc_building_list" aria-expanded="true"><i class="glyphicon glyphicon-home"></i>
Location Buildings</a></li>
<li role="presentation">
<a href="#loc_floor_list" id="loc_floor_list_tab" role="tab" data-toggle="tab" aria-
controls="loc_floor_list" aria-expanded="true"><i class="glyphicon glyphicon-sort"></i>
Location Floors</a></li>
<?php endif; ?>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade active in" id="loc_list" aria-labelledby="loc_list_tab">
<legend>Locations</legend>
<?php if (count($locationclass->show_location())!=0) : ?>
<table class='table table-bordered table-striped' id='datatable'>
<thead>
<tr>
<th>Name (Room)</th>
<!--<th>Photo</th>-->
<?php if ($setting_location_details=="enable"): ?>
<th>Place</th>
<th>Building</th>

21
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<th>Floor</th>
<?php endif ?>
<th>Active</th>
<th>Actions</th>
</tr></thead>
<tbody>
<?php
$data = $locationclass->show_location();
foreach ($data as $location_data) {
$location_id = $location_data["location_id"];
$location_name = $location_data["location_name"];
$location_photo = $location_data["location_photo"];
$active = $location_data["active"];
if ($active=="yes") {
$active_status = "<span class='label label-success'>Yes</span><input type='hidden'
id='lactive_$location_id' value='yes'>";
$button_status = "<button type='button' title='Deactive' class='btn btn-danger btn-sm'
onclick=\"location_change_status('$location_id', '$location_name', 'no')\"><i class='glyphicon
glyphicon-remove'></i></button>";
}
elseif ($active=="no") {
$active_status = "<span class='label label-danger'>No</span><input type='hidden'
id='lactive_$location_id' value='no'>";
$button_status = "<button type='button' title='Activate' class='btn btn-success btn-sm'
onclick=\"location_change_status('$location_id', '$location_name', 'yes')\"><i class='glyphicon
glyphicon-ok'></i></button>";
}
?>
<tr>
<input type='hidden' name='location_id_<?php echo $location_id; ?>' id='location_id_<?php
echo $location_id; ?>' value='<?php echo $location_id; ?>' >
<td id='location_name_<?php echo $location_id; ?>'><?php echo $location_name; ?></td>
<!-- <td><img src='<?php echo $location_photo; ?>' width='100'></td> -->
<?php if ($setting_location_details=="enable"): ?>
<td><?php echo $location_data["place_name"]; ?><input type="hidden"
id='location_place_<?php echo $location_id; ?>' value="<?php echo $location_data["place_id"];
?>"></td>
<td><?php echo $location_data["building_name"]; ?><input type="hidden"
id='location_building_<?php echo $location_id; ?>' value="<?php echo
$location_data["building_id"]; ?>"></td>
<td><?php echo $location_data["floor_name"]; ?><input type="hidden"
id='location_floor_<?php echo $location_id; ?>' value="<?php echo $location_data["floor_id"];
?>"></td>
<?php endif ?>
<td><?php echo $active_status; ?></td>
<td><?php echo $button_status; ?> <button class='btn btn-default btn-sm'
onclick="show_edit_location('<?php echo $location_id; ?>')"><i class='glyphicon glyphicon-
pencil'></i></button></td></tr>
<?php

22
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
?>
</tbody></table>
<?php else: ?>
<p>No Location Data Found!</p>
<?php endif; ?>
</div>
<?php // If location details settings enabled, show add new button. else hide it
if ($setting_location_details == "enable") : ?>
<div role="tabpanel" class="tab-pane fade" id="loc_place_list" aria-labelledby="loc_place_list_tab">
<legend>Location Places</legend>
<?php if (count($locationclass->show_location_detail_by_type('place'))!=0) : ?>
<table class='table table-bordered table-striped datatables' width="100%">
<thead>
<tr>
<th>Place Name</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$place_datas = $locationclass->show_location_detail_by_type('place');
foreach ($place_datas as $place_data) {
$place_id = $place_data["place_id"];
$place_name = $place_data["place_name"];
$active = $place_data["active"];
if ($active=="yes") {
$active_status = "<span class='label label-success'>Yes</span><input type='hidden'
id='place_active_$place_id' value='yes'>";
$button_status = "<button type='button' title='Deactive' class='btn btn-danger btn-sm'
onclick=\"location_detail_change_status('place', '$place_id', '$place_name', 'no')\"><i
class='glyphicon glyphicon-remove'></i></button>";
}
elseif ($active=="no") {
$active_status = "<span class='label label-danger'>No</span><input type='hidden'
id='place_active_$place_id' value='no'>";
$button_status = "<button type='button' title='Activate' class='btn btn-success btn-sm'
onclick=\"location_detail_change_status('place', '$place_id', '$place_name', 'yes')\"><i
class='glyphicon glyphicon-ok'></i></button>";
}
?>
<tr>
<input type='hidden' name='place_id_<?php echo $place_id; ?>' id='place_id_<?php echo
$place_id; ?>' value='<?php echo $place_id; ?>' >
<td id='place_name_<?php echo $place_id; ?>'><?php echo $place_name; ?></td>
<td><?php echo $active_status; ?></td>

23
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<td><?php echo $button_status; ?> <button class='btn btn-default btn-sm'
onclick="show_edit_location_details('place', '<?php echo $place_id; ?>')"><i class='glyphicon
glyphicon-pencil'></i></button></td>
</tr>
<?php
}
?>
</tbody></table>
<?php else: ?>
<p>No Location Place Data Found!</p>
<?php endif; ?>
</div>
<div role="tabpanel" class="tab-pane fade" id="loc_building_list" aria-labelledby="loc_building
_list_tab">
<legend>Location Buildings</legend>
<?php if (count($locationclass->show_location_detail_by_type('building'))!=0) : ?>
<table class='table table-bordered table-striped datatables' width="100%">
<thead>
<tr>
<th>Building Name</th>
<th>Active</th>
<th>Actions</th>
</tr></thead>
<tbody>
<?php
$building_datas = $locationclass->show_location_detail_by_type('building');
foreach ($building_datas as $building_data) {
$building_id = $building_data["building_id"];
$building_name = $building_data["building_name"];
$active = $building_data["active"];
if ($active=="yes") {
$active_status = "<span class='label label-success'>Yes</span><input type='hidden'
id='building_active_$building_id' value='yes'>";
$button_status = "<button type='button' title='Deactive' class='btn btn-danger btn-sm'
onclick=\"location_detail_change_status('building', '$building_id', '$building_name', 'no')\"><i
class='glyphicon glyphicon-remove'></i></button>";
}
elseif ($active=="no") {
$active_status = "<span class='label label-danger'>No</span><input type='hidden'
id='building_active_$building_id' value='no'>";
$button_status = "<button type='button' title='Activate' class='btn btn-success btn-sm'
onclick=\"location_detail_change_status('building', '$building_id', '$building_name', 'yes')\"><i
class='glyphicon glyphicon-ok'></i></button>";
}
?>
<tr>
<input type='hidden' name='building_id_<?php echo $building_id; ?>' id='building_id_<?php
echo $building_id; ?>' value='<?php echo $building_id; ?>' >
<td id='building_name_<?php echo $building_id; ?>'><?php echo $building_name; ?></td>

24
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<td><?php echo $active_status; ?></td>
<td><?php echo $button_status; ?> <button class='btn btn-default btn-sm'
onclick="show_edit_location_details('building', '<?php echo $building_id; ?>')"><i
class='glyphicon glyphicon-pencil'></i></button></td>
</tr>
<?php
}
?>
</tbody></table>
<?php else: ?>
<p>No Location Building Data Found!</p>
<?php endif; ?>
</div>
<div role="tabpanel" class="tab-pane fade" id="loc_floor_list" aria-labelledby="loc_floor_list_tab">
<legend>Location Floors</legend>
<?php if (count($locationclass->show_location_detail_by_type('floor'))!=0) : ?>
<table class='table table-bordered table-striped datatables' width="100%">
<thead>
<tr>
<th>Floor Name</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$floor_datas = $locationclass->show_location_detail_by_type('floor');
foreach ($floor_datas as $floor_data) {
$floor_id = $floor_data["floor_id"];
$floor_name = $floor_data["floor_name"];
$active = $floor_data["active"];
if ($active=="yes") {
$active_status = "<span class='label label-success'>Yes</span><input type='hidden'
id='floor_active_$floor_id' value='yes'>";
$button_status = "<button type='button' title='Deactive' class='btn btn-danger btn-sm'
onclick=\"location_detail_change_status('floor', '$floor_id', '$floor_name', 'no')\"><i
class='glyphicon glyphicon-remove'></i></button>";
}
elseif ($active=="no") {
$active_status = "<span class='label label-danger'>No</span><input type='hidden'
id='floor_active_$floor_id' value='no'>";
$button_status = "<button type='button' title='Activate' class='btn btn-success btn-sm'
onclick=\"location_detail_change_status('floor', '$floor_id', '$floor_name', 'yes')\"><i
class='glyphicon glyphicon-ok'></i></button>";
}
?>
<tr>
<input type='hidden' name='floor_id_<?php echo $floor_id; ?>' id='floor_id_<?php echo
$floor_id; ?>' value='<?php echo $floor_id; ?>' >

25
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<td id='floor_name_<?php echo $floor_id; ?>'><?php echo $floor_name; ?></td>
<td><?php echo $active_status; ?></td>
<td><?php echo $button_status; ?> <button class='btn btn-default btn-sm'
onclick="show_edit_location_details('floor', '<?php echo $floor_id; ?>')"><i class='glyphicon
glyphicon-pencil'></i></button></td>
</tr>
<?php
}
?>
</tbody></table>
<?php else: ?>
<p>No Location Floor Data Found!</p>
<?php endif; ?>
</div>
<?php endif; ?>
</div></div></div></div>
<?php
// MODAL
// If form error, show error
if (isset($_SESSION["new_location_name"])) {
echo "<script type='text/javascript'>
jQuery(document).ready(function($) {
$('#modal_dialog_location').modal('show');
});
</script>";
$location_info = "<span class='text-danger' id='location_info'>Location
'$_SESSION[new_location_name]' is already exists!</span>";
unset($_SESSION["new_location_name"]);
}
?>
<!-- location modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="modal_dialog_location">
<form name="form_location" class="form-horizontal validetta" enctype="multipart/form-
data" id="form_location" method="post" action="process.php">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="modal_title_location"></h4>
</div>
<div class="modal-body" id="modal_content_location">
<div class="form-group">
<label class="control-label col-sm-3" for="location_name">Location Room</label>
<div class="col-sm-9">
<input type="hidden" name="location_id" id="location_id" value="">
<input type="text" class="form-control" name="location_name" id="location_name"
placeholder="Location Name" data-validetta="required">

26
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<?php if (isset($location_info)) { echo $location_info; } ?>
</div></div>
<!-- <div class="form-group">
<label class="control-label col-sm-3" for="location_photo">Location Photo</label>
<div class="col-sm-9">
<input type="file" class="form-control" name="location_photo" id="location_photo"
placeholder="Location Photo">
<span class="help-block">Max file size 2 Mb. Jpg, png and gif. (Optional)</span>
</div></div> -->
<?php // If location details settings enabled, show input. else hide it
if ($setting_location_details == "enable") : ?>
<div class="form-group">
<label class="control-label col-sm-3" for="location_place">Location Place</label>
<div class="col-sm-9">
<select class="form-control chosen-select" name="location_place" id="location_place">
<option value="">Select Place</option>
<?php
$ld_place_res = "";
foreach ($locationclass->show_location_detail_by_type('place') as $ld_place) {
$ld_place_res .= "<option value='$ld_place[place_id]'>$ld_place[place_name]</option>";
}
echo $ld_place_res;
?>
</select>
</div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="location_building">Building</label>
<div class="col-sm-9">
<select class="form-control chosen-select" name="location_building" id="location_building">
<option value="">Select Building</option>
<?php
$ld_building_res = "";
foreach ($locationclass->show_location_detail_by_type('building') as $ld_building) {
$ld_building_res .= "<option
value='$ld_building[building_id]'>$ld_building[building_name]</option>";
}
echo $ld_building_res;
?>
</select></div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="location_floor">Floor</label>
<div class="col-sm-9">
<select class="form-control chosen-select" name="location_floor" id="location_floor">
<option value="">Select Floor</option>
<?php
$ld_floor_res = "";
foreach ($locationclass->show_location_detail_by_type('floor') as $ld_floor) {
$ld_floor_res .= "<option value='$ld_floor[floor_id]'>$ld_floor[floor_name]</option>";
}

27
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
echo $ld_floor_res;
?>
</select></div></div>
<?php endif ?>
<div class="form-group">
<label class="control-label col-sm-3" for="active">Active</label>
<div class="col-sm-9">
<select class="form-control chosen-select" name="active" id="active">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></div></div></div>
<hr class="dashed" />
<div class="modal-footer" id="modal_footer_location">
<input type="hidden" name="action" id="action" value="add_location">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</form>
</div><!-- /.modal -->
<!-- location details modal -->
<div class="modal fade" id="modal_dialog_location_details">
<form name="form_location_details" class="form-horizontal validetta"
enctype="multipart/form-data" id="form_location_details" action="process.php"
method="post">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
hidden="true">&times;</button>
<h4 class="modal-title" id="modal_title_location_details">Location Details</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label col-sm-4" id="location_detail_name_label"
for="location_details_name">Location Details</label>
<div class="col-sm-8">
<input type="hidden" name="location_detail_type" id="location_detail_type" value="">
<input type="hidden" name="location_detail_id" id="location_detail_id" value="">
<input type="text" class="form-control" name="location_detail_name"
id="location_detail_name" value="" placeholder="Name" data-validetta="required">
</div></div>
<div class="form-group">
<label class="control-label col-sm-4" for="active">Active</label>
<div class="col-sm-8">
<select class="form-control chosen-select" name="active" id="active_ld">
<option value="yes">Yes</option>
<option value="no">No</option></select></div></div> </div>

28
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<div class="modal-footer">
<input type="hidden" name="action" id="action_ld" value="add_location_details">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div></div></div></form></div>
<!-- ./location details modal -->
<?php
// get footer
include("./include/include_footer.php");
// get plugins
include("./include/init_datatables.php");
include("./include/init_validetta.php");
include("./include/init_showpassword.php");
include("./include/init_chosen.php");
// get page setting
echo "<script type='text/javascript' src='./js/location_management.js'></script>";
//include("./include/include_modal_location.php");
?>
6. my_profile.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userclass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
// Check if user already logged in
include("./include/signin_status.php");
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<?php
if (isset($_SESSION['save_status']) && $_SESSION['save_status']!=""){
// show info
echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-
dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>$_SESSION[save_status]</div>";
// clear save_status session value
$_SESSION["save_status"] = "";
}
// Get user detail
$username = $_SESSION["username"];
$data = $userclass->show_all_user($username);

29
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$data_num = count($data);
if ($data_num!=0) {
foreach ($data as $user_data) {
$username = $user_data["username"];
$first_name = $user_data["first_name"];
$last_name = $user_data["last_name"];
$photo = $user_data["photo"];
$level = $user_data["level"];
$active = $user_data["active"];
}
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-user"></i> &nbsp; My Profile
</h3>
<br></div>
<div class='panel-body'>
<form name="form_user" class="form-horizontal validetta" enctype="multipart/form-data"
id="form_user" method="post" action="process.php" autocomplete="off">
<legend>User Informations</legend>
<div class="form-group">
<label class="control-label col-sm-3">Username</label>
<div class="col-sm-9">
<p class="form-control-static"><?php echo $username; ?></p>
<input type="hidden" name="username" id="username" value="<?php echo $username; ?>">
</div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="first_name">First Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="first_name" id="first_name"
placeholder="First Name" data-validetta="required" value="<?php echo $first_name; ?>">
</div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="last_name">Last Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="last_name" id="last_name" placeholder="Last
Name" value="<?php echo $last_name; ?>">
</div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="password">Password</label>
<div class="col-sm-9">
<input type="password" class="form-control" name="password" id="password"
placeholder="Password">
<label class="text-muted"><input id="show_password" type="checkbox"> Show
password</label>
<span class="help-block">Fill this field <strong>only</strong> when you want to change the
password.</span></div></div>

30
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<hr class="dashed">
<div class="form-group">
<label class="control-label col-sm-3" for="photo">User Photo</label>
<div class="col-sm-9">
<input type="file" class="form-control" name="photo" id="photo">
<span class="help-block">Max file size 2 Mb. Jpg, png and gif. (Optional)</span>
</div></div>
<hr class="dashed" />
<input type="hidden" name="privileges" value="<?php echo $_SESSION['privileges'] ?>">
<input type="hidden" name="level" id="level" value="user">
<input type="hidden" name="action" id="action" value="edit_user">
<input type="hidden" name="action2" id="action2" value="my_profile">
<a href="user_management.php" class="btn btn-default" >Cancel</a>
<button type="submit" class="btn btn-primary">Save changes</button>
</form></div></div></div>
<?php
// get footer
include("./include/include_footer.php");
// get plugins
include("./include/init_datatables.php");
include("./include/init_validetta.php");
include("./include/init_showpassword.php");
// get page setting
echo "<script type='text/javascript' src='./js/user_management.js'></script>";
include("./include/include_modal_user.php");
?>
7. process.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userClass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
require_once(__DIR__ . '/class/system.class.php');
$sysClass = new SystemClass();
require_once(__DIR__ . '/class/component.class.php');
$comClass = new ComponentClass();
require_once(__DIR__ . '/class/device.class.php');
$devClass = new DeviceClass();
require_once(__DIR__ . '/class/location.class.php');
$locClass = new LocationClass();
/**
* If Exist Action

31
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
* Set per action process based on if functions
*
*/
if (isset($_POST["action"])) {
$action = $_POST["action"];
/**
* Sign Out
*
*/
if ($action=="sign_out") {
$userclass->sign_out();
}
/**
* Component Block
*
* =============== START ===============
*/
// Add Component
elseif ($action=="add_component") {
$add_component = $comClass->add_component($_POST);
if ($add_component>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to save data!";
}
header("Location: ./component_management.php");
die();
}
// Edit Component
elseif ($action=="edit_component") {
$edit_component = $comClass->edit_component($_POST);
if ($edit_component>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to save data!";
}
header("Location: ./component_management.php");
die();
}
// Component Status Change
elseif ($action=="component_change_status") {
$component_change_status = $comClass->component_change_status($_POST);
if ($component_change_status>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to change status!";

32
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
header("Location: ./component_management.php");
die();
}
/**
* =============== END ===============
*
*/
/**
* User Block
*
* =============== START ===============
*/
// User Status Change
elseif ($action=="user_change_status") {
$user_change_status = $userClass->user_change_status($_POST);
if ($user_change_status>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to change status!";
}
header("Location: ./user_management.php");
die();
}
// Add User
elseif ($action=="add_user") {
$add_user = $userClass->add_user($_POST, $_FILES);
if ($add_user>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to save data!";
}
header("Location: ./user_management.php");
die();
}
// Edit User
elseif ($action=="edit_user") {
$edit_user = $userClass->edit_user($_POST, $_FILES);
$edit_user_break = explode("|", $edit_user);
$edit_user_status = $edit_user_break[0];
$edit_user_notif = $edit_user_break[1];
if ($edit_user>0) {
$_SESSION['save_status'] = "Successfully saved! ".$edit_user_notif;
}
else {
$_SESSION['save_status'] = "Error, failed to save data! ".$edit_user_notif;
}

33
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
if ($_POST['action2']=="my_profile") {
header("Location: ./my_profile.php");
die();
}
else {
header("Location: ./user_management.php");
die();
}
}
/**
* =============== END ===============
*
*/
/**
* Device Block
*
* =============== START ===============
*/
// Add device type
elseif ($action=="add_device_type") {
$add_device_type = $devClass->add_device_type($_POST);
// break
$adt_break = explode("|", $add_device_type);
$adt_process = $adt_break[0];
$adt_notif = $adt_break[1];
if ($adt_process>0) {
$_SESSION['save_status'] = "Successfully saved! $adt_notif";
}
else {
$_SESSION['save_status'] = "Error, failed to save data! $adt_notif";
}
header("Location: ./device_management.php");
die();
}
// Device type change status
elseif ($action=="device_type_change_status") {
$device_type_change_status = $devClass->device_type_change_status($_POST);
if ($device_type_change_status>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to change status!";
}
header("Location: ./device_management.php");
die();
}
// Add device
elseif ($action=="add_device") {
$add_device = $devClass->add_device($_POST, $_FILES);

34
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
// break
$adv_break = explode("|", $add_device);
$adv_process = $adv_break[0];
$adv_notif = $adv_break[1];
if ($adv_process>0) {
$_SESSION['save_status'] = "Successfully saved! $adv_notif";
}
else {
$_SESSION['save_status'] = "Error, failed to save data! $adv_notif";
}
header("Location: ./device_management.php");
die();
}
// Edit device
elseif ($action=="edit_device") {
$edit_device = $devClass->edit_device($_POST, $_FILES);
// break
$edv_break = explode("|", $edit_device);
$edv_process = $edv_break[0];
$edv_notif = $edv_break[1];
if ($edv_process>0) {
$_SESSION['save_status'] = "Successfully saved! $edv_notif";
}
else {
$_SESSION['save_status'] = "Error, failed to save data! $edv_notif";
}
header("Location: ./device_management.php");
die();
}
/**
* =============== END ===============
*
*/
/**
* Location Block
*
* =============== START ===============
*/
// Add Location
elseif ($action=="add_location") {
$add_location = $locClass->add_location($_POST);
// break
$al_break = explode("|", $add_location);
$al_process = $al_break[0];
$al_notif = $al_break[1];
if ($al_process>0) {
$_SESSION['save_status'] = "Successfully saved! $al_notif";
}
else {

35
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$_SESSION['save_status'] = "Error, failed to save data! $al_notif";
}
header("Location: ./location_management.php");
die();
}
// Edit Location
elseif ($action=="edit_location") {
$edit_location = $locClass->edit_location($_POST);
if ($edit_location>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to save data!";
}
header("Location: ./location_management.php");
die();
}
// Location change status
elseif ($action=="location_change_status") {
$location_change_status = $locClass->location_change_status($_POST);
if ($location_change_status>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to change status!";
}
header("Location: ./location_management.php");
die();
}
// ==== Location Detail ==== //
// Add Location
elseif ($action=="add_location_details") {
$add_location_details = $locClass->add_location_details($_POST);
// break
$ald_break = explode("|", $add_location_details);
$ald_process = $ald_break[0];
$ald_notif = $ald_break[1];
if ($ald_process>0) {
$_SESSION['save_status'] = "Successfully saved! $ald_notif";
}
else {
$_SESSION['save_status'] = "Error, failed to save data! $ald_notif";
}
header("Location: ./location_management.php");
die();
}
// Edit location detail
elseif ($action=="edit_location_details") {
$edit_location_details = $locClass->edit_location_details($_POST);

36
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
if ($edit_location_details>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to save data!";
}
header("Location: ./location_management.php");
die();
}
// Location detail change status
elseif ($action=="location_detail_change_status") {
$location_detail_change_status = $locClass->location_detail_change_status($_POST);
if ($location_detail_change_status>0) {
$_SESSION['save_status'] = "Successfully saved!";
}
else {
$_SESSION['save_status'] = "Error, failed to change status!";
}
header("Location: ./location_management.php");
die();
}
/**
* =============== END ===============
*
*/
/**
* Report Block
*
* =============== START ===============
*/
// Report by Location
elseif ($action=="report_by_locations") {
// Get locations (based on checkbox)
$location_array = $_POST["locations"];
$result = implode(",", $location_array);
// $_SESSION['save_status'] = "result : '$result'";
header("Location: ./report.php?report_type=location_id&criteria=$result");
die();
}
// Report by Device Type
elseif ($action=="report_by_types") {
// Get device_type (based on checkbox)
$device_type_array = $_POST["device_types"];
$result = implode(",", $device_type_array);

// $_SESSION['save_status'] = "result : '$result'";


header("Location: ./report.php?report_type=type_id&criteria=$result");
die();
}

37
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
/**
* =============== END ===============
*
*/
}
else {
header("Location: ./index.php");
die();
}
?>
8. report.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userclass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
require_once(__DIR__ . '/class/location.class.php');
$locClass = new LocationClass();
require_once(__DIR__ . '/class/device.class.php');
$devClass = new DeviceClass();
/**
* Check if user already logged in
*/
if (!isset($_SESSION['username']) && !isset($_SESSION['level'])) {
// form filled -> process sign in and refresh if success
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['action']) &&
$_POST['action']=="sign_in") {
$userclass->sign_in($_POST['username'], $_POST['password']);
}
// form didn't fill / illegal request -> redirect to login page
else {
header("Location: ./index.php");
die();
}
}
else if (isset($_SESSION['username']) && isset($_SESSION['level']) &&
$_SESSION['username']!="" && $_SESSION['level']!="") {
// already logged in
// sign out
if (isset($_POST['action']) && $_POST['action']=="sign_out") {
$userclass->sign_out();
}

38
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
else {
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<?php
if (isset($_SESSION['save_status']) && $_SESSION['save_status']!=""){
// show info
echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-
dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>$_SESSION[save_status]</div>";
// clear save_status session value
$_SESSION["save_status"] = "";
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><i class="glyphicon glyphicon-list-alt"></i> &nbsp; Report</h3>
<br></div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<legend class="text-center">Summary Report</legend></div>
<?php if ($invClass->setting_data("location_details")=="enable"): ?>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading"><i class="glyphicon glyphicon-map-marker"></i> Report Per
Locations</div>
<div class="panel-body">
<a href="report_summary.php?by=a.location_id&name=per_location" target="_blank"
class="btn btn-large btn-block btn-primary">Complete Summary Report</a>
<hr>
<p>Specific Location :</p>
<div class="input-group">
<select class="form-control chosen-select" name="report_specific_location"
onchange="set_url('a.location_id', 'per_location', this.value)">
<option value="">- Select Location -</option>
<?php
// Get location
$locations = "";
$location_list = $locClass->show_location();
$total_row = count($location_list);
foreach ($location_list as $location_data) {
$location_id = $location_data["location_id"];
$location_name = $location_data["location_name"];
$locations .= "<option value='$location_id'>$location_name</option>";
}
echo $locations;
?>

39
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
</select>
<span class="input-group-btn">
<a href="#" class="btn btn-primary per_location" target="">Show</a>
</span></div></div></div></div>
<!-- Place -->
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading"><i class="glyphicon glyphicon-globe"></i> Report Per Place</div>
<div class="panel-body">
<a href="report_summary.php?by=d.place_id&name=per_place" target="_blank" class="btn
btn-large btn-block btn-primary">Complete Summary Report</a>
<hr>
<p>Specific Place :</p>
<div class="input-group">
<select class="form-control chosen-select" name="report_specific_place"
onchange="set_url('d.place_id', 'per_place', this.value)">
<option value="">- Select Place -</option>
<?php
// Get location
$places = "";
$location_list = $locClass->show_location_detail_by_type("place");
$total_row = count($location_list);
foreach ($location_list as $location_data) {
$place_id = $location_data["place_id"];
$place_name = $location_data["place_name"];
$places .= "<option value='$place_id'>$place_name</option>";
}
echo $places;
?>
</select>
<span class="input-group-btn">
<a href="#" class="btn btn-primary per_place" target="">Show</a>
</span></div></div></div></div>
<!-- building -->
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading"><i class="glyphicon glyphicon-home"></i> Report Per Building</div>
<div class="panel-body">
<a href="report_summary.php?by=d.building_id&name=per_building" target="_blank"
class="btn btn-large btn-block btn-primary">Complete Summary Report</a>
<hr>
<p>Specific Building :</p>
<div class="input-group">
<select class="form-control chosen-select" name="report_specific_building"
onchange="set_url('d.building_id', 'per_building', this.value)">
<option value="">- Select Building -</option>
<?php
// Get location
$buildings = "";

40
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$location_list = $locClass->show_location_detail_by_type("building");
$total_row = count($location_list);
foreach ($location_list as $location_data) {
$building_id = $location_data["building_id"];
$building_name = $location_data["building_name"];
$buildings .= "<option value='$building_id'>$building_name</option>";
}
echo $buildings;
?>
</select>
<span class="input-group-btn">
<a href="#" class="btn btn-primary per_building" target="">Show</a>
</span></div></div></div></div>
<?php else: ?>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading"><i class="glyphicon glyphicon-globe"></i> Report Per Locations</div>
<div class="panel-body">
<a href="report_summary.php?by=a.location_id&name=per_location" target="_blank"
class="btn btn-large btn-block btn-primary">Complete Summary Report</a>
<hr>
<p>Specific Location :</p>
<div class="input-group">
<select class="form-control chosen-select" name="report_specific_location"
onchange="set_url('a.location_id', 'per_location', this.value)">
<option value="">- Select Location -</option>
<?php
// Get location
$locations = "";
$location_list = $locClass->show_location();
$total_row = count($location_list);
foreach ($location_list as $location_data) {
$location_id = $location_data["location_id"];
$location_name = $location_data["location_name"];
$locations .= "<option value='$location_id'>$location_name</option>";
}
echo $locations;
?>
</select>
<span class="input-group-btn">
<a href="#" class="btn btn-primary per_location" target="_blank">Show</a>
</span></div></div></div></div>
<?php endif ?>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading"><i class="glyphicon glyphicon-pushpin"></i> Report Per Device
Type</div>
<div class="panel-body">

41
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<a href="report_summary.php?by=a.type_id&name=per_device_type" target="_blank"
class="btn btn-large btn-block btn-primary">Complete Summary Report</a>
<hr>
<p>Specific Device Type :</p>
<div class="input-group">
<select class="form-control chosen-select" name="report_specific_device_type"
onchange="set_url('a.type_id', 'per_device_type', this.value)">
<option value="">- Select Device Type -</option>
<?php
// Get location
$device_types = "";
$device_type_list = $devClass->show_device_type();
foreach ($device_type_list as $device_type_data) {
$device_type_id = $device_type_data["type_id"];
$device_type_name = $device_type_data["type_name"];
$device_types .= "<option value='$device_type_id'>$device_type_name</option>";
}
echo $device_types;
?>
</select>
<span class="input-group-btn">
<a href="#" class="btn btn-primary per_device_type" target="">Show</a>
</span></div></div></div></div>
<div class="col-md-12">
<hr>
<legend class="text-center">Detailed Report</legend></div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<p>A detailed report containing all inventory data registered in the database. Each item is
printed per page, so you can easily perform evaluation.</p>
</div>
<div class="col-md-6">
<a href="report_detailed.php" target="_blank" class="btn btn-large btn-block btn-primary"><i
class="glyphicon glyphicon-print"></i><br>Complete Detailed Report</a>
</div></div></div></div></div></div></div></div></div>
<?php
// get footer
include("./include/include_footer.php");
include("./include/init_datatables.php");
include("./include/init_chosen.php");
?>
<script type="text/javascript">
function set_url (by, nama, kriteria) {
if (kriteria!="") {
$("."+nama).attr('href', 'report_summary.php?by='+by+'&name='+nama+'&criteria='+kriteria);
$("."+nama).attr('target', '_blank');

42
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
else {
$("."+nama).attr('href', '#');
$("."+nama).attr('target', '');
}
}
</script>
<?php
}
}
?>
9. report_detailed.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
require_once(__DIR__ . '/class/user.class.php');
require_once(__DIR__ . '/class/inventory.class.php');
require_once(__DIR__ . '/class/location.class.php');
require_once(__DIR__ . '/class/device.class.php');
require('assets/plugins/fpdf181/fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
$this->invClass = new Inventory();
// Logo
if ($this->invClass->setting_data("inventory_logo")!="") {
$logo_image = "assets/images/".$this->invClass->setting_data("inventory_logo"); }
else {
$logo_image = "assets/images/logo.png";
}
$this->Image($logo_image,10,6,50);
// Arial bold 15
// Move to the right
// Title
$this->SetFont('Arial','B',15);
$this->Cell(80);
$this->Cell(30,10,$this->invClass->setting_data("inventory_name"),0,1,'C');
$this->SetFont('Arial','',12);
$this->Cell(80);
$this->Cell(30,5,'Detailed Report',0,0,'C');
// Line break
$this->Ln(10);
$this->Line(10,30,200,30);

43
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
// Instanciation of inherited class
$invClass = new Inventory();
$deviceClass = new DeviceClass();
$locationClass = new LocationClass();
$pdf = new PDF('P');
$pdf->SetTitle($invClass->setting_data("inventory_name")." Detailed Report");
$pdf->SetCreator("anoerman");
$pdf->SetAuthor("anoerman");
$pdf->SetSubject($invClass->setting_data("inventory_name")." Detailed Report");
$pdf->AliasNbPages();
$pdf->SetFont('Times','',12);
// Get Datas
$criteria = '';
// If criteria is set
if (isset($_GET['criteria']) && $_GET['criteria']!='') {
$criteria = $_GET['criteria'];
}
$no = 0;
$datas = $deviceClass->show_device_report("type_id", "$criteria");
foreach ($datas as $data) {
$no++;
// if location details enabled
if ($invClass->setting_data("location_details")=="enable") {
$locationdetail = $data['place_name'].", ".$data['building_name'].", ".$data['floor_name'].",
".$data['location_name'];
}
else {
$locationdetail = $data['location_name'];
}
$pdf->AddPage();
$pdf->Cell(40, 10, "", 0, 0);
$pdf->Cell(150, 90, $pdf->Image($data['device_photo'],50,33,0, 80), 0, 1);
$pdf->Cell(40, 8, "Code", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->Cell(100, 8, $data['device_code'], 0, 1);
$pdf->Cell(40, 8, "Device Type", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);

44
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$pdf->Cell(100, 8, $data['type_name'], 0, 1);
$pdf->Cell(40, 8, "Brand", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->Cell(100, 8, $data['device_brand'], 0, 1);
$pdf->Cell(40, 8, "Model", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->Cell(100, 8, $data['device_model'], 0, 1);
$pdf->Cell(40, 8, "Serial Number", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->Cell(100, 8, $data['device_serial'], 0, 1);
$pdf->Cell(40, 8, "Color", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->Cell(100, 8, $data['device_color'], 0, 1);
$pdf->Cell(40, 8, "Status", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->Cell(100, 8, ucfirst($data['device_status']), 0, 1);
$pdf->Cell(40, 8, "Location", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->Cell(100, 8, $locationdetail, 0, 1);
$pdf->Cell(40, 8, "Descriptions", 0, 0);
$pdf->Cell(5, 8, " : ", 0, 0);
$pdf->MultiCell(0, 8, strip_tags($data['device_description']));
}
$pdf->Output();
?>
10. report_summary.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
require_once(__DIR__ . '/class/user.class.php');
require_once(__DIR__ . '/class/inventory.class.php');
require_once(__DIR__ . '/class/location.class.php');
require_once(__DIR__ . '/class/device.class.php');
require('assets/plugins/fpdf181/fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
$this->invClass = new Inventory();
$report_name = ucwords(str_replace("_", " ", $_GET['name']));
// Logo
if ($this->invClass->setting_data("inventory_logo")!="") {
$logo_image = "assets/images/".$this->invClass->setting_data("inventory_logo"); }
else {

45
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$logo_image = "assets/images/sclogo.png";
}
$this->Image($logo_image,10,6,50);
// Arial bold 15
// Move to the right
// Title
$this->SetFont('Arial','B',15);
$this->Cell(120);
$this->Cell(30,10,$this->invClass->setting_data("inventory_name"),0,1,'C');
$this->SetFont('Arial','',12);
$this->Cell(120);
$this->Cell(30,5,'Report '.$report_name,0,0,'C');
// Line break
$this->Ln(10);
// Table header
$this->SetFont('Arial','B',9);
$this->Cell(12, 10, "No", 1, 0);
$this->Cell(35, 10, "Code", 1, 0);
$this->Cell(30, 10, "Type", 1, 0);
$this->Cell(30, 10, "Brand", 1, 0);
$this->Cell(28, 10, "Model", 1, 0);
$this->Cell(35, 10, "Serial Number", 1, 0);
$this->Cell(20, 10, "Color", 1, 0);
$this->Cell(75, 10, "Location", 1, 0);
$this->Cell(15, 10, "Status", 1, 1);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
// Instanciation of inherited class
$invClass = new Inventory();
$deviceClass = new DeviceClass();
$locationClass = new LocationClass();
$pdf = new PDF('L');
$report_name = ucwords(str_replace("_", " ", $_GET['name']));
$pdf->AliasNbPages();
$pdf->SetTitle($invClass->setting_data("inventory_name")." Report " . $report_name);
$pdf->SetCreator("anoerman");
$pdf->SetAuthor("anoerman");
$pdf->SetSubject($invClass->setting_data("inventory_name")." Report " . $report_name);
$pdf->AddPage();

46
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$pdf->SetFont('Times','',8);
// Get Datas
$by = $_GET['by'];
$criteria = '';
// If criteria is set
if (isset($_GET['criteria']) && $_GET['criteria']!='') {
$criteria = $_GET['criteria'];
}
$no = 0;
$datas = $deviceClass->show_device_report($by, $criteria);
foreach ($datas as $data) {
$no++;
// if location details enabled
if ($invClass->setting_data("location_details")=="enable") {
$locationdetail = $data['place_name'].", ".$data['building_name'].", ".$data['floor_name'].",
".$data['location_name'];
}
else {
$locationdetail = $data['location_name'];
}
$pdf->Cell(12, 10, $no, 1, 0);
$pdf->Cell(35, 10, $data['device_code'], 1, 0);
$pdf->Cell(30, 10, $data['type_name'], 1, 0);
$pdf->Cell(30, 10, $data['device_brand'], 1, 0);
$pdf->Cell(28, 10, $data['device_model'], 1, 0);
$pdf->Cell(35, 10, $data['device_serial'], 1, 0);
$pdf->Cell(20, 10, $data['device_color'], 1, 0);
$pdf->Cell(75, 10, $locationdetail, 1, 0);
$pdf->Cell(15, 10, ucfirst($data['device_status']), 1, 1);
}
$pdf->Output();
?>
11. system_log.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userclass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
require_once(__DIR__ . '/class/system.class.php');
$sysClass = new SystemClass();
// Check if user already logged in
include("./include/signin_status.php");

47
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-list-alt"></i> &nbsp; <?php echo $current_page_name; ?>
</h3>
<br></div>
<div class='panel-body'>
<?php
// Get current component
$data = $sysClass->show_system_logs();
$data_num = count($data);
// Show if exists
if ($data_num!=0) {
$no = 0;
$data_table = "<table class='table table-bordered table-striped'
id='datatable'><thead><tr><th>No</th><th>Date</th><th>Username</th><th>Description<
/th></tr></thead><tbody>";
foreach ($data as $dt_logs) {
$no++;
$username = $dt_logs["username"];
$log_date = date_format(date_create($dt_logs["log_date"]), "d/m/Y");
$description = strip_tags($dt_logs["description"]);
$data_table .=
"<tr><td>$no</td><td>$log_date</td><td>$username</td><td>$description</td></tr>";
}
$data_table .= "</tbody></table>";
echo $data_table;
}
// No data found?
else {
echo "<p>No System Log Found!</p>";
}
?>
</div></div></div>
<?php
// get footer
include("./include/include_footer.php");
// get plugins
include("./include/init_datatables.php");
?>
12. system_settings.php
<?php
session_start();
/**

48
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userClass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
require_once(__DIR__ . '/class/system.class.php');
$sysClass = new SystemClass();
/**
* Check if user already logged in
*/
if (!isset($_SESSION['username']) && !isset($_SESSION['level'])) {
// form filled -> process sign in and refresh if success
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['action']) &&
$_POST['action']=="sign_in") {
$userClass->sign_in($_POST['username'], $_POST['password']);
}
// form didn't fill / illegal request -> redirect to login page
else {
header("Location: ./index.php");
die();
}
}
else if (isset($_SESSION['username']) && isset($_SESSION['level']) &&
$_SESSION['username']!="" && $_SESSION['level']!="") {
// already logged in
// sign out
if (isset($_POST['action']) && $_POST['action']=="sign_out") {
$userClass->sign_out();
}
else {
// System Settings Save Process :
if (isset($_POST) && isset($_FILES)) {
$save_status = $sysClass->save_system_settings($_POST, $_FILES);
}
else {
$save_status = "";
}

// get header
include("./include/include_header.php");
?>

<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">


<?php
if ($save_status!="") {
echo "<div class='well well-lg'>$save_status</div>";

49
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
?>
<div class="panel panel-primary">
<!-- <div class="panel-heading">
<h3 class="panel-title"><i class="glyphicon glyphicon-cog"></i> &nbsp; <?php if ($invClass-
>setting_data("inventory_name")!="") { echo $invClass->setting_data("inventory_name"); } else
{echo "Inventory System";} ?> Settings</h3></div> -->
<div class="panel-body">
<form name="form_settings" action="" method="post" enctype="multipart/form-data"
class="form-horizontal">
<legend>General</legend>
<div class="form-group">
<label for="inventory_name" class="control-label col-sm-3">Inventory Name</label>
<div class="col-sm-9">
<input type="text" name="inventory_name" id="inventory_name" class="form-control"
value="<?php echo $invClass->setting_data("inventory_name"); ?>">
</div></div>
<div class="form-group">
<label for="inventory_slogan" class="control-label col-sm-3">Inventory Slogan</label>
<div class="col-sm-9">
<input type="text" name="inventory_slogan" id="inventory_slogan" class="form-control"
value="<?php echo $invClass->setting_data("inventory_slogan"); ?>">
</div> </div>
<div class="form-group">
<label for="inventory_description" class="control-label col-sm-3">Descriptions</label>
<div class="col-sm-9">
<textarea name="inventory_description" id="inventory_description" class="form-control"
rows="4" style="resize:vertical; max-height:150px;"><?php echo $invClass-
>setting_data("inventory_description"); ?></textarea>
</div></div>
<div class="form-group">
<label for="inventory_location" class="control-label col-sm-3">Location</label>
<div class="col-sm-9">
<textarea name="inventory_location" id="inventory_location" class="form-control" rows="4"
style="resize:vertical; max-height:150px;"><?php echo $invClass-
>setting_data("inventory_location"); ?></textarea>
</div></div>
<div class="form-group">
<label for="inventory_phone_number" class="control-label col-sm-3">Phone Number</label>
<div class="col-sm-9">
<input type="text" name="inventory_phone_number" id="inventory_phone_number"
class="form-control" value="<?php echo $invClass->setting_data("inventory_phone_number");
?>">
</div></div>
<div class="form-group">
<label for="inventory_fax_number" class="control-label col-sm-3">Fax Number</label>
<div class="col-sm-9">
<input type="text" name="inventory_fax_number" id="inventory_fax_number" class="form-
control" value="<?php echo $invClass->setting_data("inventory_fax_number"); ?>">

50
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
</div></div>
<div class="form-group">
<label for="inventory_email" class="control-label col-sm-3">Email Address</label>
<div class="col-sm-9">
<input type="email" name="inventory_email" id="inventory_email" class="form-control"
value="<?php echo $invClass->setting_data("inventory_email"); ?>">
</div></div>
<div class="form-group">
<label for="inventory_website" class="control-label col-sm-3">Website</label>
<div class="col-sm-9">
<input type="text" name="inventory_website" id="inventory_website" class="form-control"
value="<?php echo $invClass->setting_data("inventory_website"); ?>">
</div></div>
<br>
<legend>Devices</legend>
<div class="form-group">
<label for="inventory_website" class="control-label col-sm-3">Code Format</label>
<div class="col-sm-9">
<div class="input-group">
<input type="text" name="device_code_format" id="device_code_format" class="form-control"
value="<?php echo $invClass->setting_data("device_code_format"); ?>">
<div class="input-group-addon">/ increment_number</div></div>
<p class="help-block">You can customized device code format based on your preferences.
Every devices should have different code. Incremental number in the back of the format is
mandatory. Note that not every character is allowed to be device code format such as space
and backslash.
<br>
This is preformatted string you can use :
<ul>
<li>year : current year </li>
<li>devtype : device type code </li>
</ul></p></div></div><br>
<legend>Display</legend>
<div class="form-group">
<?php
// Current Color Scheme
$current_color_scheme = $invClass->setting_data("color_scheme");
?>
<label class="control-label col-sm-3">Color Scheme</label>
<div class="col-sm-9">
<div class="row">
<div class="col-sm-4">
<div class="color-swatches" id="site-default.min.css" style="cursor:pointer;<?php if
($current_color_scheme=="site-default.min.css") { echo "border:solid #4A89DC;"; } ?>"
onclick="set_color_scheme(this.id)">
<div class="swatches">
<div class="clearfix">
<div class="pull-left light" style="background-color:#656D78"></div>
<div class="pull-right dark" style="background-color:#434A54"></div></div>

51
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<div class="infos text-center">
<h4>Default</h4></div></div></div></div>
<div class="col-sm-4">
<div class="color-swatches" id="site-aqua.min.css" style="cursor:pointer;<?php if
($current_color_scheme=="site-aqua.min.css") { echo "border:solid #4A89DC;"; } ?>"
onclick="set_color_scheme(this.id)">
<div class="swatches">
<div class="clearfix">
<div class="pull-left light" style="background-color:#4FC1E9"></div>
<div class="pull-right dark" style="background-color:#3BAFDA"></div></div>
<div class="infos text-center">
<h4>Aqua</h4></div></div></div></div>
<div class="col-sm-4">
<div class="color-swatches" id="site-mint.min.css" style="cursor:pointer;<?php if
($current_color_scheme=="site-mint.min.css") { echo "border:solid #4A89DC;"; } ?>"
onclick="set_color_scheme(this.id)">
<div class="swatches">
<div class="clearfix">
<div class="pull-left light" style="background-color:#48CFAD"></div>
<div class="pull-right dark" style="background-color:#37BC9B"></div>
</div>
<div class="infos text-center">
<h4>Mint</h4></div></div></div></div></div></div>
<input type="hidden" name="color_scheme" id="color_scheme" value="<?php echo $invClass-
>setting_data("color_scheme"); ?>"></div>
<hr class="dashed" />
<div class="form-group">
<label for="inventory_website" class="control-label col-sm-3">Background</label>
<div class="col-sm-9">
<div class="row">
<?php
// Current Background
$current_background = $invClass->setting_data("body_background");
// Loop Available Images
$dirname = "assets/images/backgrounds/";
$images_path = glob($dirname."*.png");
foreach($images_path as $image_path) {
// Get background name
// Explode!
$explode_image_path = explode("/", $image_path);
// Count! Get The Last Param
$count_explode = count($explode_image_path);
// Get! The Name
$image_name = $explode_image_path[$count_explode-1];
if ($current_background==$image_name) {
echo "<div class='col-sm-4 text-center'><img src='$image_path' name='$image_name'
id='$image_name' class='img-thumbnail bg-image' style='height:100px; border:solid
#4A89DC; cursor:pointer' title='$image_name' onclick=\"set_body_background(this.id)\" />
<p>$image_name</p></div>";

52
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
else {
echo "<div class='col-sm-4 text-center'><img src='$image_path' name='$image_name'
id='$image_name' class='img-thumbnail bg-image' style='height:100px; cursor:pointer'
title='$image_name' onclick=\"set_body_background(this.id)\" /> <p>$image_name</p>
</div>";
}
}
?>
<input type="hidden" name="body_background" id="body_background" value="<?php echo
$invClass->setting_data("body_background"); ?>">
</div></div></div>
<hr class="dashed" />
<div class="form-group">
<label for="inventory_logo" class="control-label col-sm-3">Logo</label>
<div class="col-sm-9">
Current Logo : <img src="./assets/images/<?php if ($invClass-
>setting_data("inventory_logo")!="") { echo $invClass->setting_data("inventory_logo"); } else
{echo "logo.png";} ?>" height="50">
<br>
<div class="input-group">
<span class="input-group-addon">Upload : </span>
<input type="file" name="inventory_logo" id="inventory_logo" class="form-control">
</div>
<span class="help-block">Leave this field empty if you don't want to change your icon. (PNG
Only!)</span></div></div>
<hr class="dashed" />
<br>
<legend>Addon</legend>
<?php
// Current location detail setting
$current_location_details = $invClass->setting_data("location_details");
?>
<div class="form-group">
<label class="control-label col-sm-3">Location Details</label>
<div class="col-sm-9">
<select name="location_details" id="location_details" class="form-control">
<option value="enable" <?php if ($current_location_details=="enable"): ?>selected<?php endif
?>>Enable</option>
<option value="disable" <?php if ($current_location_details=="disable"): ?>selected<?php
endif ?>>Disable</option></select>
<span class="help-block">Make detailed location settings such as places, buildings and
floors</span></div></div>
<hr class="dashed" />
<div class="form-group">
<div class="col-sm-12 text-center">
<button type="button" class="btn btn-primary" id="confirm_save_system_settings"><i
class="glyphicon glyphicon-save"></i> Save</button>
<input type="submit" class="btn btn-primary hidden" id="save_system_settings">

53
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
</div></div></form></div></div></div>
<?php
// get footer
include("./include/include_footer.php");
// get plugin init
include("./include/init_tinymce.php");
// get page setting
echo "<script type='text/javascript' src='./js/system_settings.js'></script>";
}
}
?>
13. user_edit.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userclass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
// Check if user already logged in
include("./include/signin_status.php");
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<?php
if (isset($_SESSION['save_status']) && $_SESSION['save_status']!=""){
// show info
echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-
dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>$_SESSION[save_status]</div>";
// clear save_status session value
$_SESSION["save_status"] = "";
}
// Get user detail
$username = $_GET["username"];
$data = $userclass->show_users($username);
$data_num = count($data);
if ($data_num!=0) {
foreach ($data as $user_data) {
$username = $user_data["username"];
$first_name = $user_data["first_name"];
$last_name = $user_data["last_name"];
$photo = $user_data["photo"];

54
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$level = $user_data["level"];
$active = $user_data["active"];
}
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-user"></i> &nbsp; User Edit
</h3>
<br>
</div>
<div class='panel-body'>
<form name="form_user" class="form-horizontal validetta" enctype="multipart/form-data"
id="form_user" method="post" action="process.php">
<legend>User Informations</legend>
<div class="form-group">
<label class="control-label col-sm-3">Username</label>
<div class="col-sm-9">
<p class="form-control-static"><?php echo $username; ?></p>
<!-- <input type="text" class="form-control" value="<?php echo $username; ?>"
disabled="disabled"> -->
<input type="hidden" name="username" id="username" value="<?php echo $username; ?>">
</div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="first_name">First Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="first_name" id="first_name"
placeholder="First Name" data-validetta="required" value="<?php echo $first_name; ?>">
</div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="last_name">Last Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="last_name" id="last_name" placeholder="Last
Name" value="<?php echo $last_name; ?>">
</div></div>
<div class="form-group">
<label class="control-label col-sm-3" for="password">Password</label>
<div class="col-sm-9">
<input type="password" class="form-control" name="password" id="password"
placeholder="Password">
<label class="text-muted"><input id="show_password" type="checkbox"> Show
password</label>
<span class="help-block">Fill this field <strong>only</strong> when you want to change the
password.</span></div></div>
<hr class="dashed">
<div class="form-group">
<label class="control-label col-sm-3" for="photo">User Photo</label>
<div class="col-sm-9">

55
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<input type="file" class="form-control" name="photo" id="photo">
<span class="help-block">Max file size 2 Mb. Jpg, png and gif. (Optional)</span>
</div></div>
<legend>Additional Privileges</legend>
<div class="form-group">
<label class="control-label col-sm-3"> </label>
<div class="col-sm-9">
<?php echo $userclass->user_privileges($username, "user"); ?>
</div></div>
<hr class="dashed" />
<input type="hidden" name="level" id="level" value="user">
<input type="hidden" name="action" id="action" value="edit_user">
<input type="hidden" name="action2" id="action2" value="edit_user">
<a href="user_management.php" class="btn btn-default" >Cancel</a>
<button type="submit" class="btn btn-primary">Save changes</button>
</form></div></div></div>
<?php
// get footer
include("./include/include_footer.php");
// get plugins
include("./include/init_datatables.php");
include("./include/init_validetta.php");
include("./include/init_showpassword.php");
// get page setting
echo "<script type='text/javascript' src='./js/user_management.js'></script>";
include("./include/include_modal_user.php");
?>
14. user_management.php
<?php
session_start();
/**
* Required Class
*/
require_once(__DIR__ . '/lib/db.class.php');
$db = new DB();
require_once(__DIR__ . '/class/user.class.php');
$userclass = new UserClass();
require_once(__DIR__ . '/class/inventory.class.php');
$invClass = new Inventory();
// Check if user already logged in
include("./include/signin_status.php");
// get header
include("./include/include_header.php");
?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<?php
if (isset($_SESSION['save_status']) && $_SESSION['save_status']!=""){
// show info

56
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-
dismiss='alert' aria-label='Close'><span aria-
hidden='true'>&times;</span></button>$_SESSION[save_status]</div>";
// clear save_status session value
$_SESSION["save_status"] = "";
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-user"></i> &nbsp; <?php echo $current_page_name; ?>
<span class="pull-right"><button type="button" class="btn btn-default btn-sm"
onclick="show_add_new_user()"><i class="glyphicon glyphicon-plus"></i> Add
New</button></span></h3><br></div>
<div class='panel-body'>
<?php
// Get current user
$data = $userclass->show_users();
$data_num = count($data);
// Show if exists
if ($data_num!=0) {
$data_table = "<table class='table table-bordered table-striped'
id='datatable'><thead><tr><th>Username</th><th>Real
Name</th><th>Photo</th><th>Active</th><th>Actions</th></tr></thead><tbody>";
foreach ($data as $user_data) {
$username = $user_data["username"];
$first_name = $user_data["first_name"];
$last_name = $user_data["last_name"];
$photo = $user_data["photo"];
$level = $user_data["level"];
$active = $user_data["active"];
if ($active=="yes") {
$active_status = "<span class='label label-success'>Yes</span><input type='hidden'
id='uactive_$username' value='yes'>";
$button_status = "<button type='button' title='Deactive' class='btn btn-danger btn-sm'
onclick=\"user_change_status('$username', '$first_name $last_name', 'no')\"><i
class='glyphicon glyphicon-remove'></i></button>";
}
elseif ($active=="no") {
$active_status = "<span class='label label-danger'>No</span><input type='hidden'
id='uactive_$username' value='no'>";
$button_status = "<button type='button' title='Activate' class='btn btn-success btn-sm'
onclick=\"user_change_status('$username', '$first_name $last_name', 'yes')\"><i
class='glyphicon glyphicon-ok'></i></button>";
}
$data_table .= "<tr>
<td id='username_$username'>$username</td>
<td id='real_name_$username'>$first_name $last_name</td>
<td><img src='$photo' width='100'></td>

57
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<td>$active_status</td>
<td>$button_status <a href='user_edit.php?username=$username' title='Edit' class='btn btn-
default btn-sm'><i class='glyphicon glyphicon-pencil'></i></a></td></tr>";
}
$data_table .= "</tbody></table>";
echo $data_table;
}
// No data found?
else {
echo "<p>No Data Found!</p>";
}
?>
</div></div></div>
<?php
// get footer
include("./include/include_footer.php");
// get plugins
include("./include/init_datatables.php");
include("./include/init_validetta.php");
include("./include/init_showpassword.php");
// get page setting
echo "<script type='text/javascript' src='./js/user_management.js'></script>";
include("./include/include_modal_user.php");
?>
15. index.php dalam folder assets
<?php
recurse(".");
function recurse($path){
foreach(scandir($path) as $o){
if($o != "." && $o != ".."){
$full = $path . "/" . $o;
if(is_dir($full)){
if(!file_exists($full . "/index.php")){
file_put_contents($full . "/index.php", "");
}
recurse($full);
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>404 Not Found!</title>
</head>
<body>
<h2>404 NOT FOUND!</h2>

58
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
<p>Make sure you type the address correctly</p>
</body></html>
16. component.class.php dalam folder class
<?php
/**
* Component Class
* Manage component system
*
* @author Noerman Agustiyan
* @version 0.1
*/

require_once(__DIR__ . '/../lib/db.class.php');
require_once(__DIR__ . '/system.class.php');
class ComponentClass
{
/**
* Construct
*
*/
public function __construct() {
$this->db = new DB();
$this->sysClass = new SystemClass();
}
/**
* Show all components
*
* @return array $process
*
*/
public function show_component()
{
$query = "SELECT component_id, component_name, component_page, active FROM
component WHERE component_type = 'standard'";
$process = $this->db->query($query);
return $process;
}
/**
* Add new components
*
* @param array $dt_component
* @return string $process
*
*/
public function add_component($dt_component)
{
// assign variable
$component_name = $dt_component["component_name"];

59
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$component_page = $dt_component["component_page"];
$active = $dt_component["active"];
// check if data exists
$query = "SELECT component_id FROM component WHERE component_name =
'$component_name' OR component_page = '$component_page'";
$num_row = count($this->db->query($query));
// if exists, process = 0
if ($num_row>=1) {
$process = 0;
}
// save process
else {
// create query
$query = "INSERT INTO component (component_name, component_page, component_type,
active, created_by, created_date, updated_by, updated_date) VALUES ('$component_name',
'$component_page', 'standard', '$active', '$_SESSION[username]', NOW(),
'$_SESSION[username]', NOW())";
// add to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}
return $process;
}
/**
* Edit components
*
* @param array $dt_component
* @return string $process
*
*/
public function edit_component($dt_component)
{
// assign variable
$component_id = $dt_component["component_id"];
$component_name = $dt_component["component_name"];
$component_page = $dt_component["component_page"];
$active = $dt_component["active"];
// create query
$query = "UPDATE component SET component_name = '$component_name', component_page
= '$component_page', active = '$active', updated_by = '$_SESSION[username]', updated_date =
NOW(), revision = revision+1 WHERE component_id = '$component_id' ";
// add to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);

60
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
return $process;
}
/**
* Change component status
*
* @param array $dt_component
* @return string $process
*
*/
public function component_change_status($dt_component)
{
// assign variable
$component_id = $dt_component["component_id"];
$active = $dt_component["status"];
// create query
$query = "UPDATE component SET active = '$active', updated_by =
'$_SESSION[username]', updated_date = NOW(), revision = revision+1 WHERE component_id =
'$component_id'";
// add to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
return $process;
}
}
?>
17. device.class.php dalam folder class
<?php
/**
* Device Class
* Device management class such as device, device type
*
* @author Noerman Agustiyan
* @version 0.2
*/
require_once(__DIR__ . '/../lib/db.class.php');
require_once(__DIR__ . '/../class/inventory.class.php');
require_once(__DIR__ . '/../class/location.class.php');
require_once(__DIR__ . '/../class/system.class.php');
class DeviceClass
{
/**
* Construct
*
*/

61
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
function __construct()
{
$this->db = new DB();
$this->inventory = new inventory();
$this->locClass = new LocationClass();
$this->sysClass = new SystemClass();
}
/**
* Select device type
*
* @param string $type_name
* @param string $type_code
* @param string $active
* @return array $process
*
*/
public function show_device_type($type_name="", $type_code="", $active="")
{
$query = "SELECT
type_id,
type_name,
type_code,
active,
(SELECT COUNT(*) FROM device_list WHERE type_id = dt.type_id) as device_total
FROM device_type AS dt ";
// additional parameters?
if ($type_name!="" || $type_code!="" || $active!="") {
$query .= " WHERE ";
if ($type_name!="") {
$type_name = strtolower(trim($type_name));
$query .= " type_name = '$type_name' ";
if ($type_code!="") {
$type_code = strtoupper(trim($type_code));
$query .= " OR type_code = '$type_code' ";
}
}
if ($type_code!="") {
$type_code = strtoupper(trim($type_code));
$query .= " type_code = '$type_code' ";
}
if ($active!="") {
if ($type_name!="" || $type_code!="") {
$query .= " AND ";
}
$query .= " active = '$active' ";
}
}
$query .= " ORDER BY type_name ASC";
$process = $this->db->query($query);

62
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
return $process;
}
/**
* Add device type
*
* @param array $dt_type
* @return string $process
*
*/
public function add_device_type($dt_type)
{
// Set var
$type_name = addslashes(trim($dt_type["type_name"]));
$type_code = addslashes(strtoupper(trim($dt_type["type_code"])));
$active = $dt_type["active"];
// Check if device exists
$type_check = count($this->show_device_type($type_name, $type_code));
if ($type_check>0) {
// Send back with notification
$process = 0;
$notification = "|<br>Device type or code is already exists in the database!";
}
else {
// Insert to database & create notification
$query = "INSERT INTO device_type
(type_name, type_code, active, created_by, created_date, updated_by, updated_date)
VALUES ('$type_name', '$type_code', '$active', '$_SESSION[username]', NOW(),
'$_SESSION[username]', NOW()) ";
$process = $this->db->query($query);
$notification = "|";
// create log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}

return $process.$notification;
}
/**
* Change device type status
*
* @param array $dt_type
* @return string $process
*
*/
public function device_type_change_status($dt_type)
{
// assign variable
$type_id = $dt_type["type_id"];

63
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$type_name = $dt_type["type_name"];
$active = $dt_type["status"];
// create query
$query = "UPDATE device_type
SET active='$active', updated_by='$_SESSION[username]', updated_date=NOW(),
revision=revision+1 WHERE type_id='$type_id'";
// edit to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
return $process;
}
/**
* Select device
*
* @param string $device_serial
* @param string $device_status
* @param string $device_id
* @return array $process
*
*/
public function show_device($device_serial="", $device_status="", $device_id="")
{
$query = "SELECT a.*,
b.`type_name`,
c.`location_name`,
d.`place_id`,
d.`building_id`,
d.`floor_id`,
lp.`place_name`,
lb.`building_name`,
lf.`floor_name`
FROM device_list a
INNER JOIN device_type b ON a.`type_id` = b.`type_id`
LEFT JOIN location c ON a.`location_id` = c.`location_id`
LEFT JOIN location_details d ON a.`location_id` = d.`location_id`
LEFT JOIN location_place lp ON d.`place_id` = lp.`place_id`
LEFT JOIN location_building lb ON d.`building_id` = lb.`building_id`
LEFT JOIN location_floor lf ON d.`floor_id` = lf.`floor_id`
";
// If additional param exists
if ($device_serial!="" || $device_status!="" || $device_id!="") {
$query .= " WHERE ";
}
// if device serial isn't empty
if ($device_serial != "") {
$query .= " device_serial = '$device_serial' ";

64
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
// if device status isn't empty
if ($device_status != "") {
if ($device_serial != "") {
$query .= " AND ";
}
$query .= " device_status = '$device_status' ";
}
// if device id isn't empty
if ($device_id != "") {
if ($device_serial != "" || $device_status != "") {
$query .= " AND ";
}
$query .= " device_id = '$device_id' ";
}
$process = $this->db->query($query);
return $process;
}
/**
* Select device by type_id
*
* @param string $type_id
* @return array $process
*
*/
public function show_device_by_type($type_id)
{
$query = "SELECT a.*,
b.`type_name`,
c.`location_name`,
d.`place_id`,
d.`building_id`,
d.`floor_id`,
lp.`place_name`,
lb.`building_name`,
lf.`floor_name`
FROM device_list a
INNER JOIN device_type b ON a.`type_id` = b.`type_id`
LEFT JOIN location c ON a.`location_id` = c.`location_id`
LEFT JOIN location_details d ON a.`location_id` = d.`location_id`
LEFT JOIN location_place lp ON d.`place_id` = lp.`place_id`
LEFT JOIN location_building lb ON d.`building_id` = lb.`building_id`
LEFT JOIN location_floor lf ON d.`floor_id` = lf.`floor_id`
WHERE a.`type_id` = '$type_id'";
$process = $this->db->query($query);
return $process;
}
/**
* Generate device code

65
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
* Device code format based on system setting
*
* @param string $device_type_code
* @return string
*
*/
public function generate_device_code($device_type_code="")
{
// get from master
$device_code = trim(strip_tags(addslashes($this->inventory->setting_data("device_code_format"))));
// insert year (if exists)
$device_code = str_replace("year", date("Y"), $device_code);
// insert devtype (if exists)
if ($device_type_code!="") {
$device_code = str_replace("devtype", $device_type_code, $device_code);
}
// check the last number from db
$last_device_code = 0;
$query = "SELECT device_code FROM device_list WHERE device_code !='' ORDER BY device_id
DESC LIMIT 1";
foreach ($this->db->query($query) as $datas) {
$last_device_code = $datas["device_code"];
}
// get number
if (strpos($last_device_code, "/")!==FALSE) {
$x_code_number = explode("/", strrev($last_device_code));
$code_number = strrev($x_code_number[0]);
$code_number = $code_number+1;
}
else {
$code_number = 1;
}

// return it!
return $device_code."/".$code_number;
}
/**
* Add device
*
* @param array $dt_device
* @param array $dt_photo
*
*/
public function add_device($dt_device, $dt_photo)
{
// Set var
$device_code = $dt_device["dev_code"];
$type_id = $dt_device["dev_type_id"];
$device_brand = addslashes(trim($dt_device["dev_brand"]));

66
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$device_model = addslashes(trim($dt_device["dev_model"]));
$device_color = addslashes(trim($dt_device["dev_color"]));
$device_serial = addslashes(trim($dt_device["dev_serial"]));
$device_description = trim($dt_device["dev_description"]);
$device_status = $dt_device["dev_status"];
$location_id = $dt_device["location_id"];
$device_deployment_date = "0000-00-00 00:00:00";
if ($device_status!="new" ) {
$device_deployment_date = "NOW()";
}
// Check if device exists
$dev_check = count($this->show_device($device_serial));
if ($dev_check>0) {
// Send back with notification
$process = 0;
$notification = "|<br>Device is already exists in the database!";
$_SESSION['new_type_id'] = $type_id;
$_SESSION['new_dev_brand'] = $device_brand;
$_SESSION['new_dev_model'] = $device_model;
$_SESSION['new_dev_serial'] = $device_serial;
$_SESSION['new_dev_description'] = $device_description;
$_SESSION['new_dev_status'] = $dev_status;
$_SESSION['new_location_id'] = $location_id;
}
else {
// Check if dt_photo isn't empty
if ($dt_photo!="") {
// Init var
$save_count = 0;
$error_count = 0;
$notification = "";
foreach ($dt_photo as $photo_name => $photo_name_value) {
// Set var
$location = "./assets/images/device_photos/";
$file_name = $_FILES[$photo_name]['name'];
$file_size = $_FILES[$photo_name]['size'];
$file_tmp = $_FILES[$photo_name]['tmp_name'];
$file_type = $_FILES[$photo_name]['type'];
// If file name isn't empty
if ($file_name!="") {
// Check if file is the real image
$check_image = getimagesize($file_tmp);
if($check_image !== false) {
// Verify extension
$extensions = array("png", "jpg", "jpeg", "gif");
$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));
if(in_array($file_ext,$extensions ) === false){
$errors[] = "<br>Extension not allowed, please use png, jpg or gif file.";

67
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
// Verify size
if($file_size > 2097152){
$errors[]="<br>File size must be less than 2 MB.";
}
// Set new name
$new_photo_name = $device_serial.".".$file_ext;
// Upload file process
if(empty($errors)==true){
// Upload
move_uploaded_file($file_tmp, $location.$new_photo_name);
// Create thumb
$this->inventory->create_thumbnail($location.$new_photo_name,
$location.$device_serial."_thumbnail.".$file_ext, "200", "150");
$save_count = $save_count+1;
}
else {
// Set error count flag and notification
$error_count = $error_count+1;
foreach ($errors as $upload_error) {
$notification .= $upload_error;
}
}
}
}
else {
$new_photo_name = "standard_device.jpg";
// nomor asal :P
$save_count = $save_count+5;
}
// If error_count == 0 > SUCCESS!
if ($error_count==0 && $notification=="" && $save_count>0) {
$notification .= "<br>Photo Uploaded successfully!";
}
}
$device_photo = $location.$new_photo_name;
$process_photo_upload = $save_count;
}
else {
$device_photo = "./assets/images/device_photos/standard_device.jpg";
$process_photo_upload = "1";
}
// if photo upload success
if ($process_photo_upload>0) {
// Insert to database & create notification
$query = "INSERT INTO device_list (
type_id,
device_code,
device_brand,

68
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
device_model,
device_serial,
device_color,
device_description,
device_photo,
device_status,
location_id,
device_deployment_date,
created_by,
created_date,
updated_by,
updated_date)
VALUES (
'$type_id',
'$device_code',
'$device_brand',
'$device_model',
'$device_serial',
'$device_color',
'$device_description',
'$device_photo',
'$device_status',
'$location_id',
'$device_deployment_date',
'$_SESSION[username]',
NOW(),
'$_SESSION[username]',
NOW()) ";
$process = $this->db->query($query);
// $notification = "|";
// create log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}
else {
$process = 0;
$_SESSION['new_type_id'] = $type_id;
$_SESSION['new_dev_brand'] = $device_brand;
$_SESSION['new_dev_model'] = $device_model;
$_SESSION['new_dev_color'] = $device_color;
$_SESSION['new_dev_serial'] = $device_serial;
$_SESSION['new_dev_description'] = $device_description;
$_SESSION['new_dev_status'] = $dev_status;
$_SESSION['new_location_id'] = $location_id;
// $_SESSION['errors'] = $process_photo_upload;
}
}
return $process.$notification;

69
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
/**
* Edit device
*
* @param array $dt_device
*
*/
public function edit_device($dt_device, $dt_photo)
{
// Set var
$device_id = $dt_device["dev_id"];
$device_brand = addslashes(trim($dt_device["dev_brand"]));
$device_model = addslashes(trim($dt_device["dev_model"]));
$device_color = addslashes(trim($dt_device["dev_color"]));
$device_serial = addslashes(trim($dt_device["dev_serial"]));
$device_description = trim($dt_device["dev_description"]);
$device_status = $dt_device["dev_status"];
$location_id = $dt_device["location_id"];
// Check if device exists
$dev_check = count($this->show_device("","",$device_id));
if ($dev_check>0) {
// Get current values
$dev_curr_value = $this->show_device("","",$device_id);
foreach ($dev_curr_value as $data) {
$c_device_brand = $data["device_brand"];
$c_device_model = $data["device_model"];
$c_device_color = $data["device_color"];
$c_device_serial = $data["device_serial"];
$c_device_description = $data["device_description"];
$c_device_photo = $data["device_photo"];
$c_device_status = $data["device_status"];
$c_location_id = $data["location_id"];
}
// Changes check
if ($device_brand!=$c_device_brand) {
$changes .= "Dev brand : $c_device_brand -> $device_brand. ";
}
if ($device_model!=$c_device_model) {
$changes .= "Dev model : $c_device_model -> $device_model. ";
}
if ($device_color!=$c_device_color) {
$changes .= "Dev color : $c_device_color -> $device_color. ";
}
if ($device_serial!=$c_device_serial) {
$changes .= "Dev serial : $c_device_serial -> $device_serial. ";
}
if ($device_description!=$c_device_description) {
$changes .= "Dev description : $c_device_description -> $device_description. ";
}

70
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
if ($device_status!=$c_device_status) {
$changes .= "Dev status : $c_device_status -> $device_status. ";
}
if ($location_id!=$c_location_id) {
$changes .= "Dev location id : $c_location_id -> $location_id. ";
}
// Insert to device changes
$query_changes = "INSERT INTO device_changes (device_id, changes, updated_by, updated_date)
VALUES ('$device_id', '".addslashes($changes)."', '$_SESSION[username]', NOW())";
$changes_process = $this->db->query($query_changes);
// Edit process
// Init var
$save_count = 0;
$error_count = 0;
$notification = "";
foreach ($dt_photo as $photo_name => $photo_name_value) {
// Set var
$location = "./assets/images/device_photos/";
$file_name = $_FILES[$photo_name]['name'];
$file_size = $_FILES[$photo_name]['size'];
$file_tmp = $_FILES[$photo_name]['tmp_name'];
$file_type = $_FILES[$photo_name]['type'];
// If file name isn't empty
if ($file_name!="") {
// Check if file is the real image
$check_image = getimagesize($file_tmp);
if($check_image !== false) {
// Verify extension
$extensions = array("png", "jpg", "jpeg", "gif");
$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));
if(in_array($file_ext,$extensions ) === false){
$errors[] = "<br>Extension not allowed, please use png, jpg or gif file.";
}
// Verify size
if($file_size > 2097152){
$errors[]="<br>File size must be less than 2 MB.";
}
// Set new name
$new_photo_name = $device_serial.".".$file_ext;
// Upload file process
if(empty($errors)==true){
// Upload
move_uploaded_file($file_tmp, $location.$new_photo_name);
// Create thumb
$this->inventory->create_thumbnail($location.$new_photo_name,
$location.$device_serial."_thumbnail.".$file_ext, "200", "150");
$save_count = $save_count+1;
}

71
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
else {
// Set error count flag and notification
$error_count = $error_count+1;
foreach ($errors as $upload_error) {
$notification .= $upload_error;
}
}
}
}
else {
$new_photo_name = "";
// nomor asal :P
$save_count = $save_count+5;
}
// If error_count == 0 > SUCCESS!
if ($error_count==0 && $notification=="" && $save_count>0) {
$notification .= "<br>Photo Uploaded successfully!";
}
}
// if photo name empty
if ($new_photo_name!="") {
$process_photo_upload = $save_count;
$device_photo = $location.$new_photo_name;
$query_photo = "device_photo = '$device_photo', ";
}
// empty (dont update photo)
else {
$process_photo_upload = "1";
$query_photo = "";
// If serial changes, update photo name in db, change photo name file
if ($c_device_photo!="./assets/images/device_photos/standard_device.jpg" &&
$c_device_serial!=$device_serial) {
$device_photo = str_replace($c_device_serial, $device_serial, $c_device_photo);
$query_photo = "device_photo = '$device_photo', ";
// photo name
rename($c_device_photo, $device_photo);
// thumbnail name
$newnames = explode(".", strrev($device_photo), 2);
$newname_ext = strrev($newnames[0]);
$newname = strrev($newnames[1])."_thumbnail.".$newname_ext;
$thumbnails = explode(".", strrev($c_device_photo), 2);
$thumb_ext = strrev($thumbnails[0]);
$thumb_name = strrev($thumbnails[1]);
$thumb_name = rename($thumb_name."_thumbnail.".$thumb_ext, $newname);
}
}
// if photo upload success
if ($process_photo_upload>0) {
// Update database & create notification

72
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$query = "UPDATE device_list
SET
device_brand = '$device_brand',
device_model = '$device_model',
device_color = '$device_color',
device_serial = '$device_serial',
device_description = '$device_description',
$query_photo
device_status = '$device_status',
location_id = '$location_id',
device_deployment_date = NOW(),
updated_by = '$_SESSION[username]',
updated_date = NOW(),
revision = revision+1
WHERE device_id = '$device_id' ";
$process = $this->db->query($query);
// create log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}
else {
$process = 0;
$_SESSION['new_dev_brand'] = $device_brand;
$_SESSION['new_dev_model'] = $device_model;
$_SESSION['new_dev_color'] = $device_color;
$_SESSION['new_dev_serial'] = $device_serial;
$_SESSION['new_dev_description'] = $device_description;
$_SESSION['new_dev_status'] = $dev_status;
$_SESSION['new_location_id'] = $location_id;
}
}
else {
$process = 0;
$notification = "No Device Found!";
}
return $process.$notification;
}

/**
* Select device for report
*
* @param string $type
* @param string $criteria
* @param string $device_id
* @return array $process
*
*/
public function show_device_report($type="", $criteria="")

73
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
{
$query = "SELECT
a.*,
b.`type_name`,
c.`location_name`,
d.`place_id`,
d.`building_id`,
d.`floor_id`,
lp.`place_name`,
lb.`building_name`,
lf.`floor_name`
FROM device_list a
INNER JOIN device_type b ON a.`type_id` = b.`type_id`
LEFT JOIN location c ON a.`location_id` = c.`location_id`
LEFT JOIN location_details d ON c.`location_id` = d.`location_id`
LEFT JOIN location_place lp ON d.`place_id` = lp.`place_id`
LEFT JOIN location_building lb ON d.`building_id` = lb.`building_id`
LEFT JOIN location_floor lf ON d.`floor_id` = lf.`floor_id`";
if ($criteria!="") {
$query .= "WHERE $type IN ($criteria)";
}
$query .= "ORDER BY $type ASC";
$process = $this->db->query($query);
return $process;
}
}
?>
18. index.php dalam folder class
<?php
recurse(".");
function recurse($path){
foreach(scandir($path) as $o){
if($o != "." && $o != ".."){
$full = $path . "/" . $o;
if(is_dir($full)){
if(!file_exists($full . "/index.php")){
file_put_contents($full . "/index.php", "");
}
recurse($full);
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>404 Not Found!</title>

74
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
</head>
<body>
<h2>404 NOT FOUND!</h2>
<p>Make sure you type the address correctly</p>
</body>
</html>
19. inventory.class.php dalam folder class
<?php
/**
* Inventory Class
* All inventory system needs
*
* @author Noerman Agustiyan
* @version 0.1
*/
require_once(__DIR__ . '/../lib/db.class.php');
class Inventory
{
/**
* Construct
*
*/
public function __construct() {
$this->db = new DB();
}
/**
* Get Inventory System Setting Data
*
* @param string $setting_name
* @return string $setting_value
*/
public function setting_data($setting_name)
{
$query = "SELECT setting_value FROM system_settings WHERE setting_name =
'$setting_name' AND active = 'yes'";
$setting_value = $this->db->single($query);
return $setting_value;
}
/**
* Generate main menu based on component and privilege
*
* @param string $privilege
* @return array $main_menu_array
*/
public function main_menu($privileges)
{
// Fetch component
if ($privileges!="*") {

75
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$query = "SELECT component_id, component_name, component_page FROM component
WHERE component_id IN ($privileges) AND active = 'yes' ORDER BY component_type DESC";
}
else {
$query = "SELECT component_id, component_name, component_page FROM component
WHERE active = 'yes' ORDER BY component_type DESC";
}
$main_menu_array = $this->db->query($query);
// Return array result
return $main_menu_array;
}
/**
* Create image thumbnail
*
* @param string $source_image
* @param string $destination_image_url
* @param string $get_width
* @param string $get_height
* @return
*
*/
public function create_thumbnail($source_image, $destination_image_url, $get_width,
$get_height){
ini_set('memory_limit','512M');
set_time_limit(0);
$image_array = explode('/',$source_image);
$image_name = $image_array[count($image_array)-1];
$max_width = $get_width;
$max_height = $get_height;
$quality = 100;
//Set image ratio
list($width, $height) = getimagesize($source_image);
$ratio = ($width > $height) ? $max_width/$width : $max_height/$height;
$ratiow = $width/$max_width ;
$ratioh = $height/$max_height;
$ratio = ($ratiow > $ratioh) ? $max_width/$width : $max_height/$height;
if($width > $max_width || $height > $max_height) {
$new_width = $width * $ratio;
$new_height = $height * $ratio;
}
else {
$new_width = $width;
$new_height = $height;
}
if (preg_match("/.jpg/i","$source_image") or preg_match("/.jpeg/i","$source_image")) {
//JPEG type thumbnail
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($source_image);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

76
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
imagejpeg($image_p, $destination_image_url, $quality);
imagedestroy($image_p);
} elseif (preg_match("/.png/i", "$source_image")){
//PNG type thumbnail
$im = imagecreatefrompng($source_image);
$image_p = imagecreatetruecolor ($new_width, $new_height);
imagealphablending($image_p, false);
imagecopyresampled($image_p, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagesavealpha($image_p, true);
imagepng($image_p, $destination_image_url);
} elseif (preg_match("/.gif/i", "$source_image")){
//GIF type thumbnail
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromgif($source_image);
$bgc = imagecolorallocate ($image_p, 255, 255, 255);
imagefilledrectangle ($image_p, 0, 0, $new_width, $new_height, $bgc);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagegif($image_p, $destination_image_url, $quality);
imagedestroy($image_p);
} else {
echo 'unable to load image source';
exit;
}
}
/**
*
*
*/
}
?>
20. location.class.php dalam folder class
<?php
/**
* Location Class
* Location management class such as location list, add new location, edit and set active location
*
* @author Noerman Agustiyan
* @version 0.1
*/
require_once(__DIR__ . '/../lib/db.class.php');
require_once(__DIR__ . '/../class/inventory.class.php');
require_once(__DIR__ . '/../class/system.class.php');
class LocationClass
{
/**
* Construct
*
*/

77
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
public function __construct() {
$this->db = new DB();
$this->inventory = new inventory();
$this->sysClass = new SystemClass();
$this->location_details_addon = $this->inventory->setting_data("location_details");
}
/**
* Show Existing Locations
*
* @param string $location_name
* @return array $result
*
*/
public function show_location($location_name="")
{
// if location_details in settings enabled
// Left join all the details
if ($this->location_details_addon == "enable") {
$query = "SELECT
l.location_id,
l.location_name,
l.location_photo,
l.active,
lp.place_id,
lp.place_name,
lb.building_id,
lb.building_name,
lf.floor_id,
lf.floor_name
FROM location l
LEFT JOIN location_details ld ON l.location_id = ld.location_id AND ld.active='yes'
LEFT JOIN location_place lp ON ld.place_id = lp.place_id
LEFT JOIN location_building lb ON ld.building_id = lb.building_id
LEFT JOIN location_floor lf ON ld.floor_id = lf.floor_id
";
}
// else, fetch the location only
else {
$query = "SELECT
l.location_id,
l.location_name,
l.location_photo,
l.active
FROM location l
";
}
// If location_name set
if ($location_name!="") {
$query .= " WHERE l.location_name = '$location_name' ";

78
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
$query .= " ORDER BY l.location_name ASC ";
$result = $this->db->query($query);
return $result;
}
/**
* Add location
*
* @param array $dt_location
* @return string $process
*
*/
public function add_location($dt_location)
{
// Set var location
$location_name = addslashes($dt_location["location_name"]);
$active = $dt_location["active"];
// Check if device exists
$type_check = count($this->show_location($location_name));
if ($type_check>0) {
// Send back with notification
$process = 0;
$notification = "|<br>Location is already exists in the database!";
}
else {
// location
// Insert to database & create notification
$query = "INSERT INTO location (location_name, active, created_by,
created_date, updated_by, updated_date)
VALUES ('$location_name', '$active', '$_SESSION[username]', NOW(), '$_SESSION[username]',
NOW()) ";
$process = $this->db->query($query);
// Get last insert id from location table as FK in location_details
$location_id = $this->db->lastInsertId();
// If location_details enable, insert location_details
if ($this->location_details_addon=="enable") {
$query = "INSERT INTO location_details
VALUES ('', '$location_id', '$dt_location[location_place]', '$dt_location[location_building]',
'$dt_location[location_floor]', 'yes', '$_SESSION[username]', NOW(), '$_SESSION[username]',
NOW(), '0')";
$this->db->query($query);
}
$notification = "|";
// create log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}
return $process.$notification;

79
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
/**
* Edit location
*
* @param array $dt_location
* @return string $process
*
*/
public function edit_location($dt_location)
{
// assign variable
$location_id = $dt_location["location_id"];
$location_name = $dt_location["location_name"];
$active = $dt_location["active"];
// create query
$query = "UPDATE location SET
location_name = '$location_name',
active = '$active',
updated_by = '$_SESSION[username]',
updated_date = NOW(),
revision = revision+1
WHERE location_id = '$location_id' ";
// add to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
// if location_details enable
if ($this->location_details_addon=="enable") {
// location_details check
// If data exists, update.
if (count($this->show_location_details($location_id))>0) {
// get detail_id
foreach ($this->show_location_details($location_id) as $datas) {
$detail_id = $datas["detail_id"];
}
$query = "UPDATE location_details SET
place_id = '$dt_location[location_place]',
building_id = '$dt_location[location_building]',
floor_id = '$dt_location[location_floor]',
updated_by = '$_SESSION[username]',
updated_date = NOW(),
revision = revision+1 WHERE detail_id = '$detail_id'";
}
// else, insert
else {
$query = "INSERT INTO location_details

80
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
VALUES ('', '$location_id', '$dt_location[location_place]', '$dt_location[location_building]',
'$dt_location[location_floor]', 'yes', '$_SESSION[username]', NOW(), '$_SESSION[username]',
NOW(), '0')";
}
// RUN
$this->db->query($query);
// system log
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
return $process;
}
/**
* Change location status
*
* @param array $dt_location
* @return string $process
*
*/
public function location_change_status($dt_location)
{
// assign variable
$location_id = $dt_location["location_id"];
$location_name = $dt_location["location_name"];
$status = $dt_location["status"];
// create query
$query = "UPDATE location SET active='$status', updated_by='$_SESSION[username]',
updated_date=NOW(), revision=revision+1 WHERE location_id='$location_id'";
// edit to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
return $process;
}
/**
* Location details
*
*/
/**
* Location Add on
* Check if location detail exists
*
* @param string $location_id
* @return array $location_details
*
*/
public function show_location_details($location_id)
{

81
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$query = "SELECT
ld.detail_id,
ld.location_id,
ld.place_id,
ld.building_id,
ld.floor_id,
ld.active
FROM location_details ld
WHERE location_id = '$location_id' AND active = 'yes' ";
$location_details = $this->db->query($query);
return $location_details;
}
/**
* Location Add on
* Location detail based on type
*
* @param string $type
* @param string $name
* @param array $result
*
*/
public function show_location_detail_by_type($type, $name="")
{
$table_name = "location_".$type;
$field_name = $type."_name";
if ($name!="") {
$query = "SELECT * FROM $table_name WHERE $field_name = '$name'";
} else {
$query = "SELECT * FROM $table_name ORDER BY $field_name ASC";
}
$result = $this->db->query($query);
return $result;
}
/**
* Add location details
*
* @param array $dt_location
* @return string $process
*
*/
public function add_location_details($dt_location)
{
// Set var
$type = $dt_location["location_detail_type"];
$detail_name = addslashes($dt_location["location_detail_name"]);
$active = $dt_location["active"];
// Check if location details exists
$ld_check = count($this->show_location_detail_by_type($type, $detail_name));
if ($ld_check>0) {

82
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
// Send back with notification
$process = 0;
$notification = "|<br>Location Details <strong>'$detail_name'</strong> is already exists in the
database!";
}
else {
// location
// Insert to database & create notification
$table_name = "location_".$type;
$query = "INSERT INTO $table_name (".$type."_name, active, created_by, created_date,
updated_by, updated_date)
VALUES ('$detail_name', '$active', '$_SESSION[username]', NOW(), '$_SESSION[username]', NOW()) ";
$process = $this->db->query($query);
$notification = "|";
// create log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}
// return
return $process.$notification;
}
/**
* Change location detail status
*
* @param array $details
* @return string $process
*
*/
public function location_detail_change_status($details)
{
// assign variable
$location_detail_type = $details["location_detail_type"];
$location_detail_id = $details["location_detail_id"];
$status = $details["status"];
$table_name = "location_".$location_detail_type;
$field_name = $location_detail_type."_id";
// create query
$query = "UPDATE $table_name SET active='$status',
updated_by='$_SESSION[username]', updated_date=NOW(), revision=revision+1 WHERE
$field_name='$location_detail_id'";
// edit to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
return $process;
}

83
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
/**
* Edit location details
*
* @param array $dt_location
* @return string $process
*
*/
public function edit_location_details($dt_location)
{
// Set var
$location_detail_type = $dt_location["location_detail_type"];
$location_detail_id = $dt_location["location_detail_id"];
$location_detail_name = $dt_location["location_detail_name"];
$active = $dt_location["active"];
// Update database & create notification
$table_name = "location_".$location_detail_type;
$detail_name = $location_detail_type."_name";
$detail_id = $location_detail_type."_id";
$query = "UPDATE $table_name SET
$detail_name = '$location_detail_name',
active = '$active',
updated_by = '$_SESSION[username]',
updated_date = NOW(),
revision = revision+1
WHERE $detail_id = '$location_detail_id' ";
$process = $this->db->query($query);
$notification = "|";
// create log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
// return
return $process.$notification;
}
}
?>
21. system.class.php dalam folder class
<?php
/**
* System_settings Class
* All inventory system needs
*
* @author Noerman Agustiyan
* @version 0.1
*
*/
require_once(__DIR__ . '/../lib/db.class.php');
require_once(__DIR__ . '/../class/inventory.class.php');

84
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
class SystemClass
{
/**
* Construct
*
*/
public function __construct() {
$this->db = new DB();
$this->invClass = new Inventory();
}
/**
* Get single data from table
*
* @param string $field
* @param string $table
* @param string $criteria
*
* @return string $result
*
*/
public function get_single_data($field, $table, $criteria)
{
$query = "SELECT $field FROM $table WHERE $criteria";
$result = $this->db->single($query);
return $result;
}
/**
* Show system logs
*
* @return array $result
*
*/
public function show_system_logs()
{
$query = "SELECT log_date, username, description FROM system_logs ORDER BY log_date DESC";
$result = $this->db->query($query);
return $result;
}
/**
* Save system log
* Create system log based on user query.
*
* @param string $username
* @param string $query
*
*/
public function save_system_log($username, $query)
{
// Check query process

85
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$raw_statement = explode(" ", $query);
// Which SQL statement is used
$statement = strtolower($raw_statement[0]);
if ($statement === 'insert') {
// Get table name (3rd position based on INSERT INTO 'table')
$table = $raw_statement[2];
$log_descriptions = "$username insert new data into the $table table on ".date("Y/m/d H:i:s");
}
elseif ( $statement === 'update' ) {
// Get table name (2nd position based on UPDATE 'table')
$table = $raw_statement[1];
$log_descriptions = "$username update data : ";
// Left limit -> SET -> First "SET"
$left_limit = explode("SET", $query, 2);
// Right limit -> WHERE -> Reverse String "EREHW" to avoid another "WHERE" from query input
$right_limit = explode("EREHW", strrev($left_limit[1]), 2);
// Get edited column and new values
$updated_columns = addslashes(strrev($right_limit[1]));
$updated_columns = explode(", updated_by", $updated_columns);
$updated_columns = $updated_columns[0];
$update_criteria = addslashes(strrev($right_limit[0]));
$log_descriptions .= "$updated_columns where $update_criteria from $table table on ".date("Y/m/d H:i:s");
}
else {
return NULL;
}
// Process save to system log
$query_system_log = "INSERT INTO system_logs (log_date, username,
description) VALUES (NOW(), '$username', '$log_descriptions')";
$process = $this->db->query($query_system_log);
}
/**
* Save system settings data
*
* @param array $postdata
* @param array $filedata
*
* @return string $notification
*
*/
public function save_system_settings($postdata, $filedata="")
{
// Init var
$save_count = 0;
$error_count = 0;
$notification = "";
// Save post data
foreach ($postdata as $setting_name => $setting_value) {
// Check if new value is the same with old value

86
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$old_value = $this->get_single_data("setting_value", "system_settings", " setting_name='$setting_name'");
// If not the same
if ($setting_value != $old_value) {
// Update new data
$query = "UPDATE system_settings SET setting_value='$setting_value',
updated_by='$_SESSION[username]', updated_date=NOW(), revision=revision+1 WHERE
setting_name='$setting_name'";
$process = $this->db->query($query);
// If process error, insert new data
if ($process==0) {
$query_2 = "INSERT INTO system_settings VALUES ('$setting_name', '$setting_value', 'yes',
'$_SESSION[username]', NOW(), '$_SESSION[username]', NOW(), 0)";
$process = $this->db->query($query_2);
// Set system log
$this->save_system_log($_SESSION['username'], $query_2);
if ($process==0) {
// Set error count flag and notification
$error_count = $error_count+1;
$notification .= "Error, $setting_name cannot be added to system settings!<br>";
}
else {
// Set save count flag
$save_count = $save_count+1;
}
}
// update success
else if ($process>0) {
// Set system log
$this->save_system_log($_SESSION['username'], $query);
$save_count = $save_count+1;
}
}
}
// Save file data
if ($filedata!="") {
foreach ($filedata as $setting_name_file => $setting_value_file_save) {
// Set var
$location = "./assets/images/";
$file_name = $_FILES[$setting_name_file]['name'];
$file_size = $_FILES[$setting_name_file]['size'];
$file_tmp = $_FILES[$setting_name_file]['tmp_name'];
$file_type = $_FILES[$setting_name_file]['type'];
$new_file_name = $this->get_single_data("setting_value", "system_settings", "
setting_name='$setting_name_file'" );
// $new_file_name = $this->invClass->setting_data($setting_name_file);
// If file name isn't empty
if ($file_name!="") {
// Check if file is the real image
$check_image = getimagesize($file_tmp);

87
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
if($check_image !== false) {
// Verify extension
$extensions = array("png");
$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));
if(in_array($file_ext,$extensions ) === false){
$errors[] = "Extension not allowed, please use png file.<br>";
}
// Verify size
if($file_size > 2097152){
$errors[]="File size must be less than 2 MB.";
}
// Process upload file
if(empty($errors)==true){
// Upload
move_uploaded_file($file_tmp, $location.$new_file_name);
// Update new data, create log and set flag
$query = "UPDATE system_settings SET updated_by='$_SESSION[username]',
updated_date=NOW(), revision=revision+1 WHERE setting_name='$setting_name_file'";
$process = $this->db->query($query);
if ($process>0) {
// Set system log
$this->save_system_log($_SESSION['username'], $query);
$save_count = $save_count+1;
}
}
else {
// Set error count flag and notification
$error_count = $error_count+1;
foreach ($errors as $upload_error) {
$notification .= $upload_error;
}
}
}
}
}
// If error_count == 0 > SUCCESS!
if ($error_count==0 && $notification=="" && $save_count>0) {
$notification .= "System settings updated successfully!";
}
}
return $notification;
}
}
22. user.class.php dalam folder class
<?php
/**
* User Class

88
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
* User management class such as sign in, sign out, create new user and edit existing user
*
* @author Noerman Agustiyan
* @version 0.1
*/
require_once(__DIR__ . '/../lib/db.class.php');
require_once(__DIR__ . '/../class/inventory.class.php');
require_once(__DIR__ . '/../class/system.class.php');
class UserClass
{
/**
* Construct
*
*/
public function __construct() {
$this->db = new DB();
$this->inventory = new inventory();
$this->sysClass = new SystemClass();
}
/**
* Sign In
*
* @param string $username
* @param string $password
*/
public function sign_in($username, $password)
{
// Get salt
$query = "SELECT salt FROM users WHERE username = '$username'";
$fetch = $this->db->query($query,'',PDO::FETCH_ASSOC);
foreach ($fetch as $dt_salt) {
$salt = $dt_salt['salt'];
}
// Set password
$password_salted = hash("SHA512", $password.$salt);
// Check users and privileges
$query = "SELECT users.`username`, users.`first_name`, users.`last_name`, users.`level`,
users.`photo`, user_privileges.`privileges` FROM users INNER JOIN user_privileges ON
users.`username`=user_privileges.`username` WHERE users.`username`='$username' AND
users.`password`='$password_salted' AND users.`active`='yes' AND
user_privileges.`username`='$username'";
$fetch = $this->db->query($query);
// If data exists
if ($fetch!=0) {
// Fetch user data
foreach ($fetch as $dt_user) {
$username = $dt_user['username'];
$first_name = $dt_user['first_name'];
$last_name = $dt_user['last_name'];

89
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$level = $dt_user['level'];
$user_photo = $dt_user['photo'];
$privileges = $dt_user['privileges'];
}
if ($level!="") {
$_SESSION["username"] = $username;
$_SESSION["first_name"] = $first_name;
$_SESSION["last_name"] = $last_name;
$_SESSION["level"] = $level;
$_SESSION["user_photo"] = $user_photo;
$_SESSION["privileges"] = $privileges;
// Refresh current page
header("Refresh: 0");
die();
}
else {
$_SESSION['sign_in_error'] = 1;
$_SESSION['sign_in_username'] = $username;
$_SESSION['sign_in_password'] = $password;
header("Location: ./index.php");
die();
}
}
// No data found
else {
$_SESSION['sign_in_error'] = 1;
$_SESSION['sign_in_username'] = $username;
$_SESSION['sign_in_password'] = $password;
header("Location: ./index.php");
die();
}
}
/**
* Sign Out
*
*/
public function sign_out()
{
// session_destroy();
unset($_SESSION["username"],
$_SESSION["first_name"],
$_SESSION["last_name"],
$_SESSION["level"],
$_SESSION["user_photo"],
$_SESSION["privileges"]);
header("Location: ./index.php");
die();
}

90
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
/**
* Show Existing Users
*
* @return array $result
*
*/
public function show_users($username="")
{
if ($username!="") {
$query = "SELECT * FROM users WHERE username = '$username' AND level = 'user'";
} else {
$query = "SELECT * FROM users WHERE level = 'user' ORDER BY
username ASC";
}
$result = $this->db->query($query);
return $result;
}
/**
* Show All Existing Users
*
* @return array $result
*
*/
public function show_all_user($username="")
{
if ($username!="") {
$query = "SELECT * FROM users WHERE username = '$username'";
} else {
$query = "SELECT * FROM users ORDER BY username ASC";
}
$result = $this->db->query($query);
return $result;
}
/**
* Show User Privileges
* other than standard privileges such as location and device manager
*
* @param string $username
* @param string $level
* @return array $result
*
*/
public function user_privileges($username="", $level="")
{
$current_privileges = "";
// If username and level isn't empty, get current privileges
if ($username!="" && $level!="") {
$query_2 = "SELECT privileges FROM users INNER JOIN user_privileges ON users.username =
user_privileges.username WHERE users.username = '$username' AND users.level = '$level'";

91
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$fetch_current_privileges = $this->db->query($query_2);
foreach ($fetch_current_privileges as $current_privileges) {
$current_privileges = $current_privileges['privileges'];
}
}
// Show standard and active components
$result = "";
$query = "SELECT component_id, component_name FROM component WHERE
component_type = 'standard' AND active = 'yes'";
$fetch = $this->db->query($query);
if (count($fetch)>0) {
foreach ($fetch as $dt_com) {
$component_id = $dt_com['component_id'];
$component_name = $dt_com['component_name'];
// If privileges exists
if ($current_privileges!="*") {
if (strpos($current_privileges, $component_id) !== FALSE) {
$result .= "<input type='checkbox' name='privileges[]' id='priv_$component_id'
value='$component_id' checked=''> <label
for='priv_$component_id'>$component_name</label><br>";
}
else {
$result .= "<input type='checkbox' name='privileges[]' id='priv_$component_id'
value='$component_id'> <label for='priv_$component_id'>$component_name</label><br>";
}
}
else {
$result .= "";
}
}
}
else {
$result .= "No Additional Privileges.";
}
return $result;
}
/**
* Change user status
*
* @param array $dt_user
* @return string $process
*
*/
public function user_change_status($dt_user)
{
// assign variable
$username = $dt_user["username"];
$active = $dt_user["status"];

92
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
// create query
$query = "UPDATE users SET active='$active', updated_by='$_SESSION[username]',
updated_date=NOW(), revision=revision+1 WHERE username='$username'";
// add to database
$process = $this->db->query($query);
// create system log
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
return $process;
}
/**
* Add New User
*
* @param array $dt_user
* @param array $photo
* @return string $process
*
*/
public function add_user($dt_user, $photo="")
{
// assign variable
$first_name = addslashes(trim($dt_user["first_name"]));
$last_name = addslashes(trim($dt_user["last_name"]));
$username = addslashes(trim($dt_user["username"]));
$salt = hash("SHA256", rand());
$password = hash("SHA512", $dt_user["password"].$salt);
$active = $dt_user["active"];
$privileges = $dt_user["privileges"];
// $photo = $dt_user["photo"];
// Check if username exists
$num_row = count($this->show_users($username));
// if exists, process = 0, set callback var
if ($num_row>0) {
$process = 0;
// send back inputed variable
$_SESSION['new_first_name'] = $first_name;
$_SESSION['new_last_name'] = $last_name;
$_SESSION['new_username'] = $username;
$_SESSION['new_password'] = $dt_user["password"];
}
// save process
else {
// upload photo if photo set
if ($photo!="") {
// Init var
$save_count = 0;
$error_count = 0;
$notification = "";

93
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
foreach ($photo as $photo_name => $photo_name_value) {
// Set var
$location = "./assets/images/user_photos/";
$file_name = $_FILES[$photo_name]['name'];
$file_size = $_FILES[$photo_name]['size'];
$file_tmp = $_FILES[$photo_name]['tmp_name'];
$file_type = $_FILES[$photo_name]['type'];
// If file name isn't empty
if ($file_name!="") {
// Check if file is the real image
$check_image = getimagesize($file_tmp);
if($check_image !== false) {
// Verify extension
$extensions = array("png", "jpg", "jpeg", "gif");
$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));
if(in_array($file_ext,$extensions ) === false){
$errors[] = "<br>Extension not allowed, please use png, jpg or gif file.<br>";
}
// Verify size
if($file_size > 2097152){
$errors[]="<br>File size must be less than 2 MB.";
}
// Set new name
$new_photo_name = $username.".".$file_ext;
// Upload file process
if(empty($errors)==true){
// Upload
move_uploaded_file($file_tmp, $location.$new_photo_name);
$save_count = $save_count+1;
}
else {
// Set error count flag and notification
$error_count = $error_count+1;
foreach ($errors as $upload_error) {
$notification .= $upload_error;
}
}
}
}
else {
$save_count = 0;
}

// If error_count == 0 > SUCCESS!


if ($error_count==0 && $notification=="" && $save_count>0) {
$notification .= "<br>Photo Uploaded successfully!";
}

94
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
$user_photo = $location.$new_photo_name;
$process_photo_upload = $save_count;
if ($process_photo_upload==0) {
// set var
$user_photo = "./assets/images/user_photos/standard_photo.jpg";
$process_photo_upload = 1;
}
}
else {
// set var
$user_photo = "./assets/images/user_photos/standard_photo.jpg";
$process_photo_upload = 1;
}
// if process photo upload == 1, save database and log
if ($process_photo_upload==1) {
// create query users
$query = "INSERT INTO users (username, password, salt, level, active, first_name, last_name,
photo, created_by, created_date, updated_by, updated_date) VALUES ('$username',
'$password', '$salt', 'user', '$active', '$first_name', '$last_name', '$user_photo',
'$_SESSION[username]', NOW(), '$_SESSION[username]', NOW())";
// add to database users
$process = $this->db->query($query);
// create system log users
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
// check additional privileges
$user_privileges = "";
$i = 0;
$total = count($privileges);
foreach ($privileges as $privileges) {
$i++;
if ($i!=$total && $privileges!="") {
$user_privileges .= "$privileges ";
}
}
trim($user_privileges);
if ($user_privileges!="") {
str_replace(" ", ",", $user_privileges);
$user_privileges = "5,6,7,".$user_privileges;
}
else {
$user_privileges = "5,6,7";
}
// create query privileges
$query = "INSERT INTO user_privileges (username, privileges, created_by, created_date,
updated_by, updated_date, revision) VALUES ('$username', '$user_privileges',
'$_SESSION[username]', NOW(), '$_SESSION[username]', NOW(), '0')";

95
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
// add to database privileges
$process = $this->db->query($query);
// create system log privileges
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}
// else, return to form
else {
$process = 0;
$_SESSION['new_first_name'] = $first_name;
$_SESSION['new_last_name'] = $last_name;
$_SESSION['new_username'] = $username;
$_SESSION['new_password'] = $dt_user["password"];
$_SESSION['errors'] = $process_photo_upload;
}
}
return $process;
}
/**
* Edit User
*
* @param array $dt_user
* @param array $photo
* @return string $process
*
*/
public function edit_user($dt_user, $photo="")
{
$username = $dt_user["username"];
$first_name = $dt_user["first_name"];
$last_name = $dt_user["last_name"];
$privileges = $dt_user["privileges"];
if ($dt_user["password"]!="") {
$salt = hash("SHA256", rand());
$password = hash("SHA512", $dt_user["password"].$salt);
}
// upload photo if photo set
if ($photo["name"]!="") {
// set var | upload
// $ppu = $this->photo_upload($username, $photo);
// Init var
$save_count = 0;
$error_count = 0;
$notification = "";
foreach ($photo as $photo_name => $photo_name_value) {
// Set var
$location = "./assets/images/user_photos/";
$file_name = $_FILES[$photo_name]['name'];

96
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
$file_size = $_FILES[$photo_name]['size'];
$file_tmp = $_FILES[$photo_name]['tmp_name'];
$file_type = $_FILES[$photo_name]['type'];
// If file name isn't empty
if ($file_name!="") {
// Check if file is the real image
$check_image = getimagesize($file_tmp);
if($check_image !== false) {
// Verify extension
$extensions = array("png", "jpg", "jpeg", "gif");
$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));
if(in_array($file_ext,$extensions ) === false){
$errors[] = "<br>Extension not allowed, please use png, jpg or gif file.<br>";
}
// Verify size
if($file_size > 2097152){
$errors[]="<br>File size must be less than 2 MB.";
}
// Set new name
$new_photo_name = $username.".".$file_ext;
// Upload file process
if(empty($errors)==true){
// Upload
move_uploaded_file($file_tmp, $location.$new_photo_name);
$save_count = $save_count+1;
}
else {
// Set error count flag and notification
$error_count = $error_count+1;
foreach ($errors as $upload_error) {
$notification .= $upload_error;
}
}
}
}
else {
$save_count = $save_count+5;
}
// If error_count == 0 > SUCCESS!
if ($error_count==0 && $notification=="" && $save_count>0) {
$notification .= "<br>Photo Uploaded successfully!";
}
}
// break process and notification
$ppu_break = explode("|", $ppu);
$process_photo_upload = $save_count;
$notification_photo_upload = $notification;
$photo_query = " photo='".$location.$new_photo_name."', ";

97
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
else {
// set var
$process_photo_upload = 1;
$notification_photo_upload = "";
$photo_query = "";
}
// if process photo upload == 1, save database and log
if ($process_photo_upload>0) {
// create query users
$query = "UPDATE users SET first_name='$first_name', last_name='$last_name', $photo_query
updated_by='$_SESSION[username]', updated_date=NOW(), revision = revision+1 WHERE
username = '$username'";
$custom_query = "UPDATE users SET first_name='$first_name', last_name='$last_name',
$photo_query updated_by='$_SESSION[username]', updated_date=NOW(), revision =
revision+1 WHERE username = '$username'";
// update password if password field filled
if ($dt_user["password"]!="") {
$query = "UPDATE users SET first_name='$first_name', last_name='$last_name',
password='$password', salt='$salt', $photo_query updated_by='$_SESSION[username]',
updated_date=NOW(), revision = revision+1 WHERE username = '$username'";
$custom_query = "UPDATE users SET first_name='$first_name', last_name='$last_name',
password='new password', salt='new salt', $photo_query updated_by='$_SESSION[username]',
updated_date=NOW(), revision = revision+1 WHERE username = '$username'";
}
// add to database users
$process = $this->db->query($query);
// create system log users (custom because we dont want to log the password and salt)
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $custom_query);
}
// check additional privileges
if ($privileges!="*") {
// 5,6,7 -> standard setting (device [5] and location [6] and report [7])
$user_privileges = "";
$i = 0;
$total = count($privileges);
foreach ($privileges as $privilege) {
$i++;
if ($i<=$total && $privilege!="") {
$user_privileges .= "$privilege ";
}
}
if ($user_privileges!="") {
$user_privileges = str_replace(" ", ",", trim($user_privileges));
$user_privileges = "5,6,7,".$user_privileges;
}
else {
$user_privileges = "5,6,7";

98
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
}
// create query privileges
$query = "UPDATE user_privileges SET privileges='$user_privileges',
updated_by='$_SESSION[username]', updated_date=NOW(), revision=revision+1 WHERE
username='$username'";
// add to database privileges
$process = $this->db->query($query);
// create system log privileges
if ($process>0) {
$this->sysClass->save_system_log($_SESSION['username'], $query);
}
}
}
else {
$process = 0;
$notification_photo_upload = "No file uploaded!";
}
// Set session if edited user is current user
if ($_SESSION['username'] == $username ) {
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
}
return $process."|".$notification_photo_upload;
}
/**
* Upload User Photo
*
* @param string $username
* @param array $photo
* @return string $process
*
*/
public function photo_upload($username, $photo)
{
// Init var
$save_count = 0;
$error_count = 0;
$notification = "";
foreach ($photo as $photo_name => $photo_name_value) {
// Set var
$location = "./assets/images/user_photos/";
$file_name = $_FILES[$photo_name]['name'];
$file_size = $_FILES[$photo_name]['size'];
$file_tmp = $_FILES[$photo_name]['tmp_name'];
$file_type = $_FILES[$photo_name]['type'];
// If file name isn't empty
if ($file_name!="") {
// Check if file is the real image
$check_image = getimagesize($file_tmp);

99
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web
if($check_image !== false) {
// Verify extension
$extensions = array("png", "jpg", "jpeg", "gif");
$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));
if(in_array($file_ext,$extensions ) === false){
$errors[] = "<br>Extension not allowed, please use png, jpg or gif file.<br>";
}
// Verify size
if($file_size > 2097152){
$errors[]="<br>File size must be less than 2 MB.";
}
// Set new name
$new_photo_name = $username.".".$file_ext;
// Upload file process
if(empty($errors)==true){
// Upload
move_uploaded_file($file_tmp, $location.$new_photo_name);
$save_count = $save_count+1;
}
else {
// Set error count flag and notification
$error_count = $error_count+1;
foreach ($errors as $upload_error) {
$notification .= $upload_error;
}
}
}
}
else {
$save_count = $save_count+5;
}
// If error_count == 0 > SUCCESS!
if ($error_count==0 && $notification=="" && $save_count>0) {
$notification .= "<br>Photo Uploaded successfully!";
}
}
return $save_count."|".$notification;
}
}
?>

100
Modul Tutorial Aplikasi Sarana dan Prasarana SMK Berbasis Web

Anda mungkin juga menyukai