-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
352 lines (285 loc) · 8.88 KB
/
server.js
File metadata and controls
352 lines (285 loc) · 8.88 KB
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
var exp=require("express");
var mysql=require("mysql");
var bodyparser=require("body-parser");
var multer=require("multer");
var i=0;
var j=0;
s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
p=["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"];
var l,p,q=0,r,s,t,u,na;
con=exp();
con.use(bodyparser.json());
con.use(bodyparser.urlencoded({extended: true}));
con.use(exp.static("public"));
var sql=mysql.createConnection({
host: "localhost",
user: "root",
password: "Arizona"
})
sql.connect(function(err) {
if (err) {
console.log(err);
}
console.log("Connected!");
});
con.get("/",function(req,res){
res.render("myweb.ejs");
res.end();
})
con.post("/det",function(req,res){
res.render("initiali.ejs");
res.end();
})
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './public')
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
})
var upload = multer({ storage: storage })
sql.query("CREATE DATABASE IF NOT EXISTS web");
sql.query("USE web");
con.post("/reg",upload.single("pro"),function(req,res){
var a1,a2,a3,a4;
a1=req.body.name;
na=a1;
a2=req.body.cono;
a3=req.body.details;
a4=req.file.originalname;
sql.query("CREATE TABLE IF NOT EXISTS myref(Name varchar(20) not null, Details varchar(500) not null, Contact_no varchar(10) not null,Pic varchar(20))");
sql.query("INSERT INTO myref(Name,Details,Contact_no,Pic) VALUES (?,?,?,?)",[a1,a3,a2,a4],function(err,res,fields){if(err) throw err});
res.render("sample1.ejs");
res.end();
})
con.post("/details",upload.single("pro"),function(req,res){
var logo=req.file.originalname;
var org=req.body.organization;
u=org;
var pro=req.body.prono;
var adv=req.body.advno;
i=adv;
j=pro
var combo=req.body.combono;
alp=combo;
var comboino=req.body.comboino;
t=comboino;
var tag=req.body.tagline;
var info={
pro: pro,
adv: adv,
combo: combo,
};
console.log(info);
sql.query("CREATE TABLE IF NOT EXISTS Initial(Name varchar(30) not null,Organization_Name varchar(50) not null,Tagline varchar(100),Product_Types int not null default 0,Advertisement int not null default 0, Combo int not null default 0,Combo_items int not null default 0,Logo varchar(50))");
sql.query("INSERT INTO Initial(Organization_Name,Tagline,Product_Types,Advertisement,Combo,Combo_items,Logo,Name) VALUES (?,?,?,?,?,?,?,?)",[org,tag,pro,adv,combo,comboino,logo,na],function(err,res,fields){if(err) throw err;});
res.render("sample1-cont.ejs",info);
res.end();
})
con.post("/furdet",upload.array("adv",3),function(req,res){
var n;
var filename=["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"];
console.log(i);
for(n=0;n<i;n++){
filename[n]=req.files[n].originalname;
}
console.log(req.body);
sql.query("CREATE TABLE IF NOT EXISTS details(Product_name varchar(20) not null, Productno int not null default 0, Organization_Name varchar(20) not null)");
for(n=0;n<j;n++){
var m=req.body.product[n];
p[n]=m
var k=req.body.Prono[n];
s[n]=k;
sql.query("INSERT INTO details(Product_name,Productno,Organization_Name) VALUES (?,?,?)",[m,k,u],function(err,res,fields){if(err) throw err});
}
sql.query("CREATE TABLE IF NOT EXISTS Advertisement(Advertisement_img varchar(20) not null,Organization_Name varchar(20) not null)");
for(n=0;n<i;n++){
var g=filename[n];
sql.query("INSERT INTO Advertisement(Advertisement_img,Organization_Name) VALUES (?,?)",[g,u],function(err,res,fields){if(err) throw err});
}
for(l=0;l<j;l++){
var aa=p[l]
sql.query("CREATE TABLE IF NOT EXISTS "+aa+ "(Product_name varchar(20) not null,Product_Price int not null default 0,Product_sdetails varchar(100), Product_detail varchar(500),Product_img1 varchar(50),Product_img2 varchar(50),Product_img3 varchar(50),Organization_Name varchar(20) not null)",function
(err,res,fields){if(err) throw err;});
}
var cc={
nc: alp
};
res.render("combo.ejs",cc);
res.end();
})
sql.query("CREATE TABLE IF NOT EXISTS Combo(comboname varchar(20), combo_price int not null default 0,Organization_Name varchar(20) not null)");
con.post("/prod",upload.array("pro"),function(req,res){
n=0;
for(r=0;r<t;r++){
sql.query("ALTER TABLE Combo ADD COLUMN itempic"+r+" varchar(50)");
}
for(r=0;r<alp;r++){
var oo=req.body.cname[r];
var ll=req.body.cprice[r];
sql.query("INSERT INTO Combo(comboname,combo_price,Organization_Name) VALUES (?,?,?)",[oo,ll,u]);
var gg=(r+1)*t;
for (;n<gg;n++)
{
var al=n%t;
var tt=req.files[n].originalname;
sql.query("UPDATE Combo SET itempic"+al+"=? WHERE comboname = ?",[tt,oo]);
}
}
q++;
var po={
proname:p[0],
prono:s[0]
};
if(q<=j){
res.render("sample1-prod1.ejs",po);
}
res.end();
})
con.post("/prod1",upload.array("pro"),function(req,res){
var bb=p[0];
for(g=0;g<s[0];g++){
var a1=req.body.product[g];
var a2=req.body.description[g];
var a3=req.body.details[g];
var a4=req.body.price[g];
var kk=3*g;
var a5=req.files[kk].originalname;
var a6=req.files[kk+1].originalname;
var a7=req.files[kk+2].originalname;
sql.query("INSERT INTO "+bb+ "(Product_name,Product_Price,Product_sdetails, Product_detail,Product_img1,Product_img2,Product_img3,Organization_Name) VALUES (?,?,?,?,?,?,?,?)",[a1,a4,a2,a3,a5,a6,a7,u],function(err,res,fields){
if(err) throw err;
})
}
q++;
if(p[1]){
var po={
proname:p[1],
prono:s[1]
};
}
if(q<=j){
res.render("sample1-prod2.ejs",po);
}
else{
res.render("done.ejs");
}
})
con.post("/prod2",upload.array("pro"),function(req,res){
var bb=p[1];
for(g=0;g<s[1];g++){
var a1=req.body.product[g];
var a2=req.body.description[g];
var a3=req.body.details[g];
var a4=req.body.price[g];
var n1=3*g;
var a5=req.files[n1].originalname;
var a6=req.files[n1+1].originalname;
var a7=req.files[n1+2].originalname;
sql.query("INSERT INTO "+bb+ "(Product_name,Product_Price,Product_sdetails, Product_detail,Product_img1,Product_img2,Product_img3,Organization_Name) VALUES (?,?,?,?,?,?,?,?)",[a1,a4,a2,a3,a5,a6,a7,u],function(err,res,fields){
if(err) throw err;
})
}
q++;
if(p[2]){
var po={
proname:p[2],
prono:s[2]
};
}
if(q<=j){
res.render("sample1-prod3.ejs",po);
}
else{
res.render("done.ejs");
}
})
con.post("/prod3",upload.array("pro"),function(req,res){
var bb=p[2];
for(g=0;g<s[2];g++){
var a1=req.body.product[g];
var a2=req.body.description[g];
var a3=req.body.details[g];
var a4=req.body.price[g];
var n1=3*g;
var a5=req.files[n1].originalname;
var a6=req.files[n1+1].originalname;
var a7=req.files[n1+2].originalname;
sql.query("INSERT INTO "+bb+ "(Product_name,Product_Price,Product_sdetails, Product_detail,Product_img1,Product_img2,Product_img3,Organization_Name) VALUES (?,?,?,?,?,?,?,?)",[a1,a4,a2,a3,a5,a6,a7,u],function(err,res,fields){
if(err) throw err;
})
}
q++;
if(p[3]){
var po={
proname:p[3],
prono:s[3]
};
}
if(q<=j){
res.render("sample1-prod4.ejs",po);
}
else{
res.render("done.ejs");
}
})
con.post("/prod4",upload.array("pro"),function(req,res){
var bb=p[3];
for(g=0;g<s[3];g++){
var a1=req.body.product[g];
var a2=req.body.description[g];
var a3=req.body.details[g];
var a4=req.body.price[g];
var n1=3*g;
var a5=req.files[n1].originalname;
var a6=req.files[n1+1].originalname;
var a7=req.files[n1+2].originalname;
sql.query("INSERT INTO "+bb+ "(Product_name,Product_Price,Product_sdetails, Product_detail,Product_img1,Product_img2,Product_img3,Organization_Name) VALUES (?,?,?,?,?,?,?,?)",[a1,a4,a2,a3,a5,a6,a7,u],function(err,res,fields){
if(err) throw err;
})
}
q++;
if(p[4]){
var po={
proname:p[4],
prono:s[4]
}
};
if(q<=j){
res.render("sample1-prod5.ejs",po);
}
else{
res.render("done.ejs");
}
})
con.post("/prod5",upload.array("pro"),function(req,res){
var bb=p[4];
for(g=0;g<s[4];g++){
var a1=req.body.product[g];
var a2=req.body.description[g];
var a3=req.body.details[g];
var a4=req.body.price[g];
var n1=3*g;
var a5=req.files[n1].originalname;
var a6=req.files[n1+1].originalname;
var a7=req.files[n1+2].originalname;
sql.query("INSERT INTO "+bb+ "(Product_name,Product_Price,Product_sdetails, Product_detail,Product_img1,Product_img2,Product_img3,Organization_Name) VALUES (?,?,?,?,?,?,?,?)",[a1,a4,a2,a3,a5,a6,a7,u],function(err,res,fields){
if(err) throw err;
})
}
q++;
if(p[5]){
var po={
proname:p[5],
prono:s[5]
};
}
if(q<=j){
res.render("sample1-prod6.ejs",po);
}
else{
res.render("done.ejs");
}
})
con.listen(3000);