/
createproduct.php
executable file
·316 lines (269 loc) · 9.34 KB
/
createproduct.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
<?php
require_once("header.php");
if(!$session->is_logged_in())
{
header("location: index.php");
}
else
{
$user = User::get_by_id($session->userid);
if($user->enabled == DISABLED)
{
header("location: index.php");
}
}
$pathinfo = pathinfo($_SERVER["PHP_SELF"]);
$basename = $pathinfo["basename"];
$currentFile = str_replace(".php","", $basename);
?>
<div class="container-fluid">
<div class="row-fluid">
<div class="span5">
<form id="theform" class="form-horizontal" method="post" action="#" enctype="multipart/form-data">
<fieldset>
<legend>
Create Product
</legend>
<div class="control-group">
<label class="control-label" for="moto">Photo</label>
<div class="controls">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: height: 200px;"><img src="public/img/thumbnail.png" /></div>
<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 200px; line-height: 20px;"></div>
<div>
<span class="btn btn-file">
<span class="fileupload-new">Select image</span>
<span class="fileupload-exists">Change</span>
<input name="MAX_FILE_SIZE" hidden value="2097152" />
<input name="picture" type="file" />
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
<a class="mytooltip" data-toggle="tooltip" data-placement="right"
title=
"
OPTIONAL: extensions allowed: JPEG/JPG and PNG
, Up to 2MB, Recommended size: 200x200
">
<span class="label label">?</span>
</a>
</div>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">* Name</label>
<div class="controls">
<input type="text" placeholder="name" class="input-xlarge">
</div>
</div>
<div class="control-group">
<label class="control-label" for="description">Description</label>
<div class="controls">
<textarea id="description" name="description" class="span8" placeholder="description" style="width:285px; height:100px"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="price">* Price</label>
<div class="controls">
<input id="price" name="price" type="text" placeholder="price" class="input-xlarge">
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">* Product Type</label>
<div class="controls">
<select name="producttypeid" id="producttypeid">
<?php
$producttypes = ProductType::get_all();
if(count($producttypes) > 0)
{
foreach ($producttypes as $producttype)
{
echo "<option value='".$producttype->id."'>".$producttype->name."</option>";
}
}
else
{
echo "<option value='0'>no product types yet</option>";
}
?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">* Store</label>
<div class="controls">
<select name="storeid" id="storeid">
<?php
$items = Store::get_all();
if(count($items) > 0)
{
foreach ($items as $item)
{
echo "<option value='".$item->id."'>".$item->name."</option>";
}
}
else
{
echo "<option value='0'>no stores yet</option>";
}
?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="pending">Status</label>
<div class="controls">
<input type="hidden" name="pending" value="0" id="btn-input2" />
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" value="0" id="btn-enabled2" class="btn active">Approved</button>
<button type="button" value="1" id="btn-disabled2" class="btn">Pending</button>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="enabled">Access</label>
<div class="controls">
<input type="hidden" name="enabled" value="1" id="btn-input3" />
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" value="1" id="btn-enabled3" class="btn active">Enabled</button>
<button type="button" value="0" id="btn-disabled3" class="btn">Disabled</button>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="btncreate"></label>
<div class="controls">
<button id="btncreate" name="btncreate" class="btn btn-primary">Create</button>
</div>
</div>
</fieldset>
</form>
</div>
<br /><br /><br /><br />
<div class="span6 well" style="max-height:600px; height:600px; overflow:scroll;">
<legend>
Products <button onclick="loadtable(); return false;" class="btn btn-mini btn-success"><i class="icon-large icon-refresh icon-white"></i></button> <span id="loading" class="label">Loading...</span>
</legend>
<div class="input-prepend">
<span class="add-on">Search</span>
<input class="span12" id="tablesearch" type="text" placeholder="search">
</div>
<table id="table" class="table table-bordered">
</table>
</div>
</div><!--/row-->
<script>
$("#tablesearch").keyup(function()
{
loadtable();
});
var loading = $("#loading");
function loadtable()
{
loading.removeClass("hide");
$.ajax(
{
url: 'includes/webservices/gettable.php?itemtype=product&input='+$("#tablesearch").val(),
success: function(result)
{
$("#table").html(result);
loading.addClass("hide");
}
});
}
loadtable();
$(document).on("click", ".btndelete", function()
{
var id = $(this).find("span").text();
$(this).text("Processing..");
$(this).attr("disabled", "disabled");
$.ajax(
{
type: 'get',
url: 'includes/webservices/delete.php?itemid='+id+'&itemtype=product',
success: function(result)
{
loadtable();
}
});
});
$(function ()
{
$("#btncreate").click(function()
{
var formData = new FormData($("#theform")[0]);
$("#btncreate").text("Processing");
$("#btncreate").attr("disabled", "disabled");
$.ajax(
{
type: 'POST',
url: 'includes/webservices/createproduct.php',
data: formData,
cache: false,
contentType: false,
processData: false,
xhr: function()
{
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload)
{
myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
}
return myXhr;
},
success: function(result)
{
if(result == "success")
{
showToast("Successfully Created", "success");
$("#btncreate").text("Create");
$("#btncreate").removeAttr("disabled");
$('#theform')[0].reset();
loadtable();
}
else
{
bootbox.alert(result);
$("#btncreate").text("Create");
$("#btncreate").removeAttr("disabled");
}
}
});
return false;
});
$(':file').change(function()
{
var file = this.files[0];
name = file.name;
size = file.size;
type = file.type;
});
function progressHandlingFunction(e)
{
if(e.lengthComputable)
{
// $('.progress').attr({value:e.loaded,max:e.total});
console.log("progress: " + e.loaded);
}
}
var btns2 = ['btn-enabled2', 'btn-disabled2'];
var input2 = document.getElementById('btn-input2');
for(var i = 0; i < btns2.length; i++)
{
document.getElementById(btns2[i]).addEventListener('click', function()
{
input2.value = this.value;
});
}
var btns3 = ['btn-enabled3', 'btn-disabled3'];
var input3 = document.getElementById('btn-input3');
for(var i = 0; i < btns3.length; i++)
{
document.getElementById(btns3[i]).addEventListener('click', function()
{
input3.value = this.value;
});
}
});
</script>
<?php require_once("footer.php"); ?>