-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddledger.php
173 lines (129 loc) · 4.07 KB
/
addledger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
include_once 'controller/product.php';
session_start();
$_Product = new Product();
if(!$_SESSION['email'])
{
header("Location: login.php");//redirect to login page to secure the welcome page without login access.
}
if(isset($_GET['edit'])){
$id = $_GET['edit'];
$ledger = $_Product->getLedger($id);
if(isset($_POST['update'])){
$ledger_name = trim($_POST['ledger_name']);
echo $ledger_name;
$_Product->updateLedger($id,$ledger_name);
}
}
if(isset($_GET['del'])){
$id = $_GET['del'];
$ledger= $_Product->deleteLedger($id);
}
if(isset($_POST['submit'])){
$data_missing = array();
if(empty($_POST['ledger_name'])){
$data_missing[] = ' Ledger Name ';
} else{
$ledger_name = trim($_POST['ledger_name']);
}
if(empty($data_missing)){
$connection = mysqli_connect("localhost","root","","hstore");
$query = "INSERT INTO product_type(type_name) VALUES ('$ledger_name');";
$result = mysqli_query($connection, $query);
if ($result)
//success
echo "successful";
else
{
die("Database query not working. " . mysqli_error($connection));
}
} else {
echo 'You need to enter the following data<br />';
foreach($data_missing as $missing){
echo "$missing<br />";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Ledger Management</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="resources/js/script.js" charset="utf-8"></script>
<script src="resources/js/jquery.min.js"></script>
<link rel="stylesheet" href="./resources/css/master.css">
</head>
<body>
<header>
<?php include_once 'template/header.php'; ?>
</header>
<div class="smallcontainer">
<form name="regform" action="" method="POST">
<div class="center">
<h1> Add Ledger </h1>
</div>
<table class="table table-condensed">
<tr>
<td>Name :</td><td><input type="text" name="ledger_name" value="<?php
if(isset($_GET['edit'])){
echo $ledger['type_name'];
}
?>" placeholder="Ledger Name" class="form-control"></td>
</tr>
<div class="right" >
<tr>
<td></td><td><input type="submit"
name=<?php if(isset($_GET['edit']))
echo "update";
else
echo "submit";
?> value="
<?php if(isset($_GET['edit']))
echo "Update";
else
echo "Submit";
?> " class="btn btn-primary btn-block" ></td>
</tr>
</div>
</table>
</form>
</div>
<div class="panel panel-body">
<table class="table table-bordered table-striped" style="border: 1px solid;border-color: rgba(7,71,166,0.62)">
<?php
$Result = $_Product->getAllLedger();
//if DAO access is successful to load all the users then show them one by one
if(isset($Result)){
?>
<tr style="background-color: rgba(7,71,166,0.62)">
<th>Ledger Id</th>
<th>Ledger Name</th>
<th>Edit</th>
<th style="color: darkred">Delete</th>
</tr>
<?php
while($row=mysqli_fetch_array($Result,MYSQLI_ASSOC)){
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['type_name']; ?></td>
<td>
<a href="?edit=<?php echo $row['id']; ?>" onclick="return confirm('sure to edit !'); " >Edit</a>
</td>
<td>
<a class="text-danger" href="?del=<?php echo $row['id']; ?>" onclick="return confirm('sure to delete !'); " >delete</a>
</td>
</tr>
<?php
}
}
else{
echo 'Problem in Reading Ledger list'; //giving failure message
}
?>
</table>
</div>
</body>
</head>
</html>