-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct_add.php
331 lines (312 loc) · 12.5 KB
/
product_add.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
include("config.php");
include("includes/session_auto_destroy.php");
$page = 'product_add';
$iProductId = intval($_REQUEST['id']);
if($iProductId > 0){
$sql = $gcr->gc_query("SELECT * FROM products WHERE iProductId = '".$iProductId."'");
$row = $gcr->gc_fetch_array($sql);
extract($row);
$vName = htmlentities($vName);
$tDescription = htmlentities($tDescription);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?=($iProductId > 0)?'Edit':'Add New'?> Product</title>
<!-- Global stylesheets -->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.min.css">
<link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="assets/css/core.css" rel="stylesheet" type="text/css">
<link href="assets/css/components.css" rel="stylesheet" type="text/css">
<link href="assets/css/colors.css" rel="stylesheet" type="text/css">
<!-- /global stylesheets -->
<!-- Core JS files -->
<script type="text/javascript" src="assets/js/plugins/loaders/pace.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/loaders/blockui.min.js"></script>
<!-- /core JS files -->
<!-- Theme JS files -->
<script type="text/javascript" src="assets/js/plugins/forms/selects/select2.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>
<script type="text/javascript" src="assets/js/core/app.js"></script>
<!-- /theme JS files -->
<script src="assets/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/pickers/pickadate/picker.js"></script>
<script type="text/javascript" src="assets/js/plugins/pickers/pickadate/picker.date.js"></script>
</head>
<body class=" pace-done">
<?php include("includes/topbar.php"); ?>
<div class="page-container">
<div class="page-content">
<?php include("includes/siderbar.php"); ?>
<div class="page-header">
<div class="page-header-content">
<div class="page-title">
<h4><i class="icon-arrow-left52 position-left"></i> <span class="text-semibold"><?=($iProductId > 0)?'Edit Model':'Add New Model'?></span></h4>
</div>
</div>
<div class="breadcrumb-line">
<ul class="breadcrumb">
<li><a href="index"><i class="icon-home2 position-left"></i> Dashboard</a></li>
<li class="active"><i class="<?=($iProductId > 0)?'fa fa-pencil-square':'fa fa-plus-square'?> position-left"></i> <?=($iProductId > 0)?'Edit Product':'Add New Product'?></li>
</ul>
</div>
</div>
<!-- Page Content Start -->
<div class="content">
<div class="col-md-12">
<form id="form-data">
<input type="hidden" name="do_action" value="Add_Edit">
<input type="hidden" name="iEditId" value="<?=$iProductId?>">
<div class="panel panel-flat">
<div class="panel-body">
<fieldset>
<div class="row">
<div class="col-md-12">
<div id="alert"></div>
<div class="row">
<div class="col-md-6 col-xs-12">
<div class="form-group">
<label>Category *</label>
<select data-placeholder="Please Select" class="select2 required" name="iCategoryId" id="iCategoryId">
<option value=""></option>
<?php
$sql = $gcr->gc_query("SELECT * FROM product_category ORDER BY vCategoryName ASC");
while($row = $gcr->gc_fetch_array($sql)){
$selected = '';
if($row['iCategoryId'] == $iCategoryId){
$selected = 'selected';
}
?>
<option <?=$selected?> value="<?=$row['iCategoryId']?>"><?=$row['vCategoryName']?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group">
<label>Model Name *</label>
<input type="text" class="form-control required" name="vName" value="<?=$vName?>" />
</div>
</div>
<div class="clearfix"></div>
<div class="col-md-12 col-xs-12">
<div class="form-group">
<label>Description</label>
<textarea class="form-control" name="tDescription" rows="4"><?=$tDescription?></textarea>
</div>
</div>
<div class="clearfix"></div>
<div class="col-md-6 col-xs-12">
<div class="form-group">
<label>Product Image <small>(JPG - 540X540 in Pixel)</small></label>
<input type="file" name="tImagePath" class="file-styled">
<?php if($tImagePath != ''){ ?>
<div class="pro_img_view">
<img src="uploads/products/<?=$tImagePath?>" />
<div class="btn btn-primary btn-sm" onclick="delete_pro_img(this,'<?=$iProductId?>','main','')"><i class="fa fa-trash"></i></div>
</div>
<?php } ?>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group">
<label>Additional Image <small>(JPG - 540X540 in Pixel)</small></label>
<input type="file" name="tAddiImagePath[]" class="file-styled" multiple>
<?php
if($tAddiImagePath != ''){
foreach(explode(',',$tAddiImagePath) as $vImgName){
?>
<div class="pro_img_view">
<img src="uploads/products/additional/<?=$vImgName?>" />
<div class="btn btn-primary btn-sm" onclick="delete_pro_img(this,'<?=$iProductId?>','addi','<?=$vImgName?>')"><i class="fa fa-trash"></i></div>
</div>
<?php } } ?>
</div>
</div>
<div class="clearfix"></div>
<div class="col-md-6 col-xs-12">
<div class="form-group">
<label>Add in Latest Products</label>
<br/>
<label class="form-check-label">
<input type="checkbox" name="eLatestProduct" class="form-check-input-styled" value="Yes" <?=($eLatestProduct == 'Yes')?'checked':''?>> Yes
</label>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group">
<label>Display Order</label>
<input type="text" class="form-control number" name="iDisplayOrder" value="<?=$iDisplayOrder?>" />
</div>
</div>
</div>
<div class="clearfix"></div>
<fieldset>
<legend class="text-semibold">Specifications</legend>
<?php
$i = 0;
$sqlItems = $gcr->gc_query("SELECT * FROM product_specifications WHERE iProductId = ".$iProductId);
$iItemTotal = $gcr->gc_affected_rows();
while($rowItems = $gcr->gc_fetch_array($sqlItems)){ $i++;
?>
<input type="hidden" name="upd_<?=$i?>" value="<?=$rowItems['iId']?>" />
<div class="itemPart">
<div class="row">
<div class="col-md-6 col-xs-12">
<div class="row">
<div class="col-md-5 col-xs-12">
<div class="form-group">
<?php if($i == 1){ ?><label>Name</label><?php } ?>
<input type="text" name="vName_<?=$i?>" value="<?=$rowItems['vName']?>" class="form-control" />
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group">
<?php if($i == 1){?><label>Value</label><?php } ?>
<input type="text" name="vValue_<?=$i?>" value="<?=$rowItems['vValue']?>" class="form-control" />
</div>
</div>
<div class="col-md-1 col-xs-1">
<div class="form-group">
<?php if($i == 1){ ?><label> </label><?php } ?>
<button type="button" class="btn btn-primary btn-sm " onclick="removerow(this,<?=$rowItems['iId']?>)"><i class="fa fa-trash"></i> </button>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<span id="moreLineDiv"></span>
</fieldset>
<div class="col-md-6 col-xs-12">
<div class="text-right"><button type="button" class="btn btn-primary btn-sm " onclick="get_specification()"><i class="fa fa-plus"></i> Add </button></div>
</div>
<input type="hidden" name="totalLines" id="totalLines" value="<?=$iItemTotal?>" />
<div class="clearfix"></div>
<button type="button" id="btn_sub" class="btn btn-primary" onclick="frmsubmit()">Submit <i class="icon-arrow-right14 position-right"></i></button>
</div>
</div>
</fieldset>
<div class="text-right"></div></div>
</div>
</div>
</form>
</div>
</div>
<!-- End Content -->
<!-- Page Content End -->
<?php include("includes/footer.php"); ?>
</div>
</div>
<script>
$( document ).ready(function() {
$('.number').keypress(function(event) {
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
// Single file uploader
$("#form-data").validate({
ignore: ":hidden"
});
$('.select2').select2();
$(".styled, .multiselect-container input").uniform({ radioClass: 'choice' });
$('.file-styled').uniform({
fileButtonHtml: '<i class="icon-googleplus5"></i>',
//wrapperClass: 'bg-file-icon'
});
$('.form-check-input-styled').uniform();
});
function frmsubmit(){
if($('#form-data').valid()){
$('#btn_sub').attr('disabled',true);
var formData = new FormData($("#form-data")[0]);
$.ajax({
type: 'POST',
url: 'process/product_action',
data: formData,
async: false,
dataType: "json",
success: function (data) {
$('#btn_sub').attr('disabled',false);
//$('html, body').animate({ scrollTop: 0 }, 'slow', );
if(data.flg == 1){
//$('#form-data')[0].reset();
$('#alert').html('<div class="alert alert-success no-border"><button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button><span class="text-semibold">'+data.msg+'</a></div>');
setTimeout(function(){
window.location = 'product_manage';
}, 2000);
}else{
$('#alert').html('<div class="alert alert-danger no-border"><button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button><span class="text-semibold">'+data.msg+'</a></div>');
}
},
cache: false,
contentType: false,
processData: false
});
}
}
function get_specification(){
var totalLines = $('#totalLines').val();
lineNo = parseInt(totalLines) + 1;
$('#totalLines').val(lineNo);
$.ajax({
type: 'POST',
url: 'process/get_specification',
data: {'lineNo':lineNo},
async: false,
success: function (data){
$('#moreLineDiv').append(data);
$('.select_'+lineNo).select2();
},
});
}
function removerow(th,iItemId){
if(iItemId != ''){
$.ajax({
type: 'POST',
url: 'process/product_action',
data: {'do_action':'remove_specification','iId':iItemId},
async: false,
dataType: "json",
success: function (data) {
if(data.flg == 1){
th.closest('.itemPart').remove();
}
},
cache: false,
//contentType: false,
//processData: false
});
}else{
th.closest('.itemPart').remove();
}
}
function delete_pro_img(ths,iProductId,eType,vImageName){
$.ajax({
type: 'POST',
url: 'process/product_action',
data: {'do_action':'remove_image','iProductId':iProductId,'eType':eType,'vImageName':vImageName},
async: false,
dataType: "json",
success: function (data) {
ths.closest('.pro_img_view').remove();
},
cache: false,
//contentType: false,
//processData: false
});
}
</script>
</body>
</html>