-
Notifications
You must be signed in to change notification settings - Fork 0
/
product-details.php
194 lines (178 loc) · 8.56 KB
/
product-details.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php include "header.php"; ?>
<div class="page-section pt-5">
<div class="container">
<nav aria-label="Breadcrumb">
<ul class="breadcrumb p-0 mb-0 bg-transparent">
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
<li class="breadcrumb-item"><a href="productlist.php">Product List</a></li>
</ul>
</nav>
<div class="row">
<div class="col-lg-12">
<div class="blog-single-wrap">
<h1 class="post-title">Product Name</h1>
<div class="post-meta">
<div class="post-date">
<span class="icon">
<span class="mai-time-outline"></span>
</span>
<a href="">Create Date: <i id="productCreateTime"></i></a>
</div>
</div>
<div class="post-content">
<form id="detaproduct" class="contact-form">
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Product Name</label>
<input disabled type="text" id="productname" name="productname"
class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Price</label>
<input disabled type="text" id="price" name="price" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="subject">Category</label>
<input disabled type="text" id="category_id" name="category_id"
class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="description">Description</label>
<textarea disabled name="description" id="description" cols="30" rows="5"
class="form-control"></textarea>
</div>
</div>
<input hidden name="token" id="token" value="<?php echo $_SESSION['token']; ?>">
</form>
<div class="row form-group mt-4">
<div class="col-md-12">
<button type="button" class="btn btn-danger" onclick="deleteProject('<?php echo $_GET['id']; ?>');">Delete
Product
</button>
</div>
</div>
</div>
</div>
<div class="comment-form-wrap pt-5">
<h2 class="mb-5">Edit Product</h2>
<form id="updateproduct" class="contact-form">
<h2 class="mb-4 font-weight-medium text-secondary">Create</h2>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Product Name</label>
<input type="text" id="productname" name="productname" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Price</label>
<input type="text" id="price" name="price" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="subject">Category</label>
<select name="category_id" id="category_id" class="form-control"></select>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="description">Description</label>
<textarea name="description" id="description" cols="30" rows="5"
class="form-control"></textarea>
</div>
</div>
<input hidden name="token" id="token" value="<?php echo $_SESSION['token']; ?>">
<input hidden name="product_id" id="product_id" value="<?php echo $_GET['id']; ?>">
<div class="row form-group mt-4">
<div class="col-md-12">
<button type="button" class="btn btn-primary" onclick="updateProject();">Update
Product
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php include "footer.php"; ?>
<script>
$(document).ready(function () {
productDetail();
readListCategory();
});
function deleteProject(product_id) {
let token = "<?php echo $_SESSION['token'] ?>";
$.ajax({
url: "api/product/delete.php",
type: "DELETE",
data: {
id: product_id,
token: token,
},
dataType: "json",
success: function (response) {
console.log(response);
// window.location.href = 'productlist.php';
},
});
}
function productDetail() {
let token = "<?php echo $_SESSION['token'] ?>";
$.ajax({
url: "api/product/read_one.php",
type: "GET",
data: {
id: "<?php echo $_GET['id']; ?>",
token: token,
},
dataType: "json",
beforeSend: function (response) {
console.log(response);
},
success: function (response) {
console.log(response);
$("#detaproduct #productname").val(response['name']);
$("#detaproduct #price").val(response['price']);
$("#detaproduct #category_id").val(response['category_name']);
$("#detaproduct #description").val(response['description']);
$("#detaproduct #productCreateTime").html(response['created']);
$("#updateproduct #productname").val(response['name']);
$("#updateproduct #price").val(response['price']);
$("#updateproduct #category_id").append("<option selected value='" + response['category_id'] + "'> " + response['category_name'] +"</option>");
$("#updateproduct #description").val(response['description']);
// $.each(response.records, function (rd, rowData) {
// Categorys.append("<option value='" + rowData.id + "'> " + rowData.name +"</option>");
// });
},
});
}
function readListCategory() {
var Categorys = $("#updateproduct #category_id");
$.ajax({
url: "api/category/read.php",
type: "GET",
dataType: "json",
beforeSend: function (response) {
console.log(response);
},
success: function (response) {
$.each(response.records, function (rd, rowData) {
Categorys.append("<option value='" + rowData.id + "'> " + rowData.name +"</option>");
});
},
error: function (response) {
console.log(response);
__Alert('Hata', "Category not working...", 'error');
}
});
}
</script>