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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
<?php $error=0; if($_GET['currID']){ $_POST['currID']=$_GET['currID']; } //----------------------------------------------------------------------------------------- if($_POST['action']=='deletePic'){ if(file_exists($path_product."/thb/".$RmPic)){ @unlink ($path_product."/thb/".$RmPic); } if(file_exists($path_product."/".$RmPic)){ @unlink ($path_product."/".$RmPic); } $query = "DELETE FROM tbl_home_gallery WHERE image_file = '".$_POST['RmPic']."' "; mysql_query($query); } if($_POST['action']=='deletePic2'){ if(file_exists($path_product."/thb/".$RmPic)){ @unlink ($path_product."/thb/".$RmPic); } if(file_exists($path_product."/".$RmPic)){ @unlink ($path_product."/".$RmPic); } $query = "DELETE FROM tbl_home_plan WHERE image_file = '".$_POST['RmPic']."' "; mysql_query($query); } //--------------------------------------------------------------------------------------- if($_POST['action']=='addImage'){ if($_POST['addimagetype']=='gallery'){ if($_FILES['uploadfile']['name']!=""){ $tempFileName = $_FILES['uploadfile']['name']; GetNewFileName($_FILES['uploadfile']['tmp_name'],$_FILES['uploadfile']['name'],$i); move_uploaded_file($_FILES['uploadfile']['tmp_name'], $path_product.$_FILES['uploadfile']['name']); $query = "INSERT INTO `tbl_home_gallery` " ." (`id` ,`home_id` ,`image_name` ,`image_file` ) " ." VALUES ('', '".$_POST['currID']."' , '".$tempFileName."' , '".$_FILES['uploadfile']['name']."') "; mysql_query($query); } }else if($_POST['addimagetype']=='plan'){ if($_FILES['uploadfile2']['name']!=""){ $tempFileName = $_FILES['uploadfile2']['name']; GetNewFileName($_FILES['uploadfile2']['tmp_name'],$_FILES['uploadfile2']['name'],$i); move_uploaded_file($_FILES['uploadfile2']['tmp_name'], $path_product.$_FILES['uploadfile2']['name']); $query = "INSERT INTO `tbl_home_plan` " ." (`id` ,`home_id` ,`image_name` ,`image_file` ) " ." VALUES ('', '".$_POST['currID']."' , '".$tempFileName."' , '".$_FILES['uploadfile2']['name']."') "; mysql_query($query); } } } //--------------------------------------------------------------------------------------- if($_POST['action']=='Add'){ if($_POST['currID']==''){ /*if($_FILES['home_firstpage']['name']!=""){ GetNewFileName($_FILES['home_firstpage']['tmp_name'],$_FILES['home_firstpage']['name'],$i); move_uploaded_file($_FILES['home_firstpage']['tmp_name'], $path_product.$_FILES['home_firstpage']['name']); } if($_FILES['home_plan']['name']!=""){ GetNewFileName($_FILES['home_plan']['tmp_name'],$_FILES['home_plan']['name'],$i); move_uploaded_file($_FILES['home_plan']['tmp_name'], $path_product.$_FILES['home_plan']['name']); } */ $query="INSERT INTO `tbl_home_data` ( `id` ,`home_name` ,`home_code_id` ,`home_type_id` ,`home_area` " ." ,`home_scale` ,`total_unit` ,`home_desc` ,`finance`) " ." VALUES " ." ( '' , '".$_POST['home_name']."', '".$_POST['home_code_id']."' , '".$_POST['home_type_id']."' , '".$_POST['home_area']."' " ." , '".$_POST['home_scale']."' , '".$_POST['total_unit']."' , '".$_POST['home_desc']."' , '".$_POST['finance']."' ) "; mysql_query($query); $_POST['currID']=mysql_insert_id(); /* for($i=1;$i < $_POST['CodeLoops'];$i++){ if($_POST['checkbox'][$i]){ $query="INSERT INTO tbl_home_data_code (id, home_code_id , home_id ) VALUES ('' , '".$_POST['checkbox'][$i]."' , '".$_POST['currID']."') "; mysql_query($query); } }*/ }else{ /* if($_FILES['home_firstpage']['name']!=""){ GetNewFileName($_FILES['home_firstpage']['tmp_name'],$_FILES['home_firstpage']['name'],$i); move_uploaded_file($_FILES['home_firstpage']['tmp_name'], $path_product.$_FILES['home_firstpage']['name']); @unlink($path_product.$_FILES['home_firstpage']['name']); @unlink($path_product."thb/".$_FILES['home_firstpage']['name']); }else{ $_FILES['home_firstpage']['name']=$_POST['home_firstpage_chk']; } if($_FILES['home_plan']['name']!=""){ GetNewFileName($_FILES['home_plan']['tmp_name'],$_FILES['home_plan']['name'],$i); move_uploaded_file($_FILES['home_plan']['tmp_name'], $path_product.$_FILES['home_plan']['name']); @unlink($path_product.$_FILES['home_plan']['name']); @unlink($path_product."thb/".$_FILES['home_plan']['name']); }else{ $_FILES['home_firstpage']['name']=$_POST['home_plan_chk']; } */ $query="UPDATE tbl_home_data SET " ." `home_name`= '".$_POST['home_name']."' ,`home_code_id`= '".$_POST['home_code_id']."' ,`home_type_id`= '".$_POST['home_type_id']."' ,`home_area`= '".$_POST['home_area']."' " ." ,`home_scale` ='".$_POST['home_scale']."' ,`total_unit` = '".$_POST['total_unit']."' ,`home_desc`= '".$_POST['home_desc']."' ,`finance` ='".$_POST['finance']."' " ." WHERE id = '".$_POST['currID']."' "; mysql_query($query); } } //---------------------SELECT DATA--------------------------------------------// $query="SELECT * FROM tbl_home_data WHERE id = '".$_POST['currID']."' "; $result=mysql_query($query); $currentData=mysql_fetch_assoc($result); $query="SELECT * FROM tbl_home_code ORDER BY code_name ASC "; $resultCode=mysql_query($query); $query="SELECT * FROM tbl_product_cate WHERE mainCateId='0' ORDER BY number ASC "; $resultCate=mysql_query($query); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script language="javascript"> //-------------------------------- function FormValid(){ if(document.form1.home_name.value==''){ alert("กรุณาใส่ชื่อบ้าน"); return false; }else if(document.form1.home_type_id.value=='xxx'){ alert("กรุณาเลือกประเภทอาคาร "); return false; }else if(document.form1.home_code_id.value=='xxx'){ alert("กรุณาเลือกรหัสบ้าน "); return false; }else { document.form1.action.value = 'Add'; } } //----------------------------------------------- function GetSubCate(MainCateID, SubCate){ var str=Math.random(); var isNS4 = (navigator.appName=="Netscape")?1:0; var mydata='MainCateID='+MainCateID+'&SubCate='+SubCate+'&str='+str; ajax = new sack('getSubCate.php'); ajax.element ="showSubCate"; ajax.runAJAX(mydata) } //------------------------------------ function removePic(pic){ if(confirm('ต้องการลบรุปนี้')){ document.form1.RmPic.value=pic; document.form1.action.value='deletePic'; document.form1.submit(); }else{ return false; } } //------------------------------------ function removePic2(pic){ if(confirm('ต้องการลบรุปนี้')){ document.form1.RmPic.value=pic; document.form1.action.value='deletePic2'; document.form1.submit(); }else{ return false; } } //-------------------------------- function addImage(actiontype){ document.form1.addimagetype.value=actiontype; document.form1.action.value='addImage'; document.form1.submit(); } </script> </head>
<body> <form action="<?php $_SERVER['PHP_SELF']?>" method="post" name="form1" enctype="multipart/form-data" onSubmit="return FormValid();"> <table width="100%" border="0" cellspacing="3" cellpadding="3"> <tr> <td class="txt10-black"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td colspan="2" align="left" bgcolor="#ECECD9"><img src="images/black_icon/16x16/sq_plus.png" width="16" height="16" hspace="5" border="0" align="absmiddle" />เพิมสินค้าใหม่</td> </tr> <tr> <td colspan="2" align="left"> <table width="100%" border="0" cellspacing="2" cellpadding="2"> <tr> <td width="26%" align="right">ชื่อบ้าน</td> <td width="74%"><input name="home_name" type="text" id="home_name" value="<?php echo $currentData['home_name']?>" size="40" /></td> </tr> <tr> <td align="right">ประเภทอาคาร</td> <td><label for="home_type_id"></label> <select name="home_type_id" id="home_type_id"> <option value="xxx">-----เลือกประเภท----</option> <?php while($cate=mysql_fetch_assoc($resultCate)){ ?> <option value="<?php echo $cate['id']?>" <?php if($currentData['home_type_id']==$cate['id']) echo "selected";?>><?php echo $cate['cate_name']?></option> <?php } ?> </select> </td> </tr> <tr> <td align="right">พื้นที่บ้าน (ตร.ม.)</td> <td><input name="home_area" type="text" id="home_area" value="<?php echo $currentData['home_area']?>" size="40" /></td> </tr> <tr> <td align="right">ขนาดที่ดินโดยประมาณ</td> <td><input name="home_scale" type="text" id="home_scale" value="<?php echo $currentData['home_scale']?>" size="40" /></td> </tr> <tr> <td align="right">จำนวนหน่วย</td> <td><input name="total_unit" type="text" id="total_unit" value="<?php echo $currentData['total_unit']?>" size="20" /> unit</td> </tr> <tr> <td align="right">รหัส</td> <td> <select name="home_code_id"> <option value="xxx">---เลือกรหัสบ้าน---</option> <?php while($code=mysql_fetch_assoc($resultCode)){ ?> <option value="<?php echo $code['id']?>" <?php if($code['id']==$currentData['home_code_id']){echo "selected";}?>><?php echo $code['code_name']?></option> <?php } ?> </select> <input type="hidden" name="CodeLoops" value="<?php echo $x?>" />
</td> </tr> <tr> <td align="right">รายละเอียด</td> <td><textarea name="home_desc" id="home_desc" cols="60" rows="6"><?php echo $currentData['home_desc']?></textarea><script language="javascript1.2"> generate_wysiwyg('home_desc'); </script> </td> </tr> <tr> <td align="right">คำนวณสินเชื่อ</td> <td><textarea name="finance" id="finance" cols="60" rows="6"><?php echo $currentData['finance']?></textarea><script language="javascript1.2"> generate_wysiwyg('finance'); </script></td> </tr> </table> </td> </tr> <tr> <td width="26%" align="right"> <input type="hidden" name="addimagetype" id="addimagetype" /> <input type="hidden" name="RmPic" /> <input type="hidden" name="action" id="action" /> <input type="hidden" name="currID" id="currID" value="<?php echo $_POST['currID']?>" /></td> </tr> <tr> <td align="center"><input type="submit" name="button" id="button" value="เพิม / แก้ไขข้อมูล" /></td> </tr> <tr> <td> <?php if($_POST['currID']){ ?> <table class="tableborder_full" height="251" cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="navbar_selected" valign="top" nowrap="nowrap" height="28" colspan="2" background="images/bgcategory01.png"><img src="images/black_icon/16x16/picture.png" width="16" height="16" hspace="5" vspace="5" align="absmiddle" />ไฟล์รูป gallery บ้าน</td> </tr> <tr> <td height="40" bgcolor="#f0f0f0" class="NAV_URL"> </td> <td bgcolor="#f0f0f0" class="NAV_URL"><span class="txt10-black">หากท่านต้องการเพิ่มไฟล์รูปภาพ ทำได้โดยกดปุ่ม Browse เพื่อทำการเลือกไฟล์ภาพ จากนั้นกดปุ่มเพิ่มรูปภาพ/ไฟล์ โดยระบบสามารถเพิ่มไฟล์ได้ไม่จำกัด และรูปภาพควรมีขนาดไม่เกิน กว้าง 660 สูง 444 pixel (รองรับไฟล์ .jpg .gif .png );</span></td> </tr> <tr> <td width="40" height="50" bgcolor="#f0f0f0" class="NAV_URL"><label></label></td> <td width="608" bgcolor="#f0f0f0" class="NAV_URL">เลือกไฟล์ <input name="uploadfile" type="file" id="uploadfile" /> <input name="Button2" type="button" value=" เพิ่มรูปภาพ / ไฟล์ " onclick="addImage('gallery');" /></td> </tr> <tr> <td height="5" bgcolor="#f0f0f0" class="NAV_URL"></td> <td bgcolor="#f0f0f0" class="NAV_URL"></td> </tr> <tr> <td height="5" colspan="2" bgcolor="#FFFFFF" class="NAV_URL"><!-- ////////////// --> <table width="" border="0" cellpadding="0" cellspacing="0" bgcolor=""> <tr> <td> <table width="" border="0" cellpadding="5" cellspacing="5"> <tr>
<?php $query="SELECT * FROM tbl_home_gallery WHERE home_id = '".$_POST['currID']."' ORDER BY id ASC "; $resultPic=mysql_query($query); $col=3;$n=1;$loops=1; $n_width=180;$n_height=180; $n_width2=340;$n_height2=220; while($pic = mysql_fetch_assoc($resultPic)){ if($loops==1){ $firstPic=$pic['image_file']; } echo "<td bgcolor='#F8F8F8' nowarp height=25 align ='center' valign='bottom'> "; $info = pathinfo($path_product."/".$pic['image_file']); //echo $info[extension]; $info[extension]=strtolower($info[extension]); if(($info[extension]=='pjpeg') || ($info[extension]=='gif') || ($info[extension]=='png') || ($info[extension]=='x-png') || ($info[extension]=='jpeg') || ($info[extension]=='jpg')){ if(!file_exists($path_product1."/thb/".$pic['image_file'])){ list($width, $height, $type, $attr) = getimagesize($path_product.$pic['image_file']); create_thub($path_product."/",$pic['image_file'],$n_width,$n_height); create_thub2($path_product."/",$pic['image_file'],$n_width2,$n_height2); } echo "<a href='".$path_product."/".$pic['image_file']."' target='_blank'>"; echo "<img src='".$path_product."/thb/".$pic['image_file']."' border =0>"; echo "</a>"; echo "<br> "; }else{ echo "<a href='".$path_product."/".$pic['image_file']."' target='_blank'>"; echo "<img src='images/MyDocuments.png' width='130' height='130' /><br>"; echo $pic['oldFilename']; echo "</a>"; echo "<br> "; } echo "<a href=# onclick=removePic('".$pic['image_file']."'); >"; echo "<img src='images/black_icon/16x16/delete.png' border=0 align =absmiddle hspace='5' vspace='5' /> ลบ"; echo "</a></td> "; if($n==$col){ echo "</tr>\n"; $n=0;}; $n++; $loops++; } //---------------update firstpic-----------------// $query="UPDATE tbl_home_data SET home_firstpage ='".$firstPic."' WHERE id = '".$_POST['currID']."' "; mysql_query($query); ?> </tr> </table></td> </tr> </table> <!-- ////////////// --> </td> </tr> <tr> <td height="5" bgcolor="#f0f0f0" class="NAV_URL"></td> <td bgcolor="#f0f0f0" class="NAV_URL"></td> </tr> </tbody> </table> <table class="tableborder_full" height="251" cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="navbar_selected" valign="top" nowrap="nowrap" height="28" colspan="2" background="images/bgcategory01.png"><img src="images/black_icon/16x16/picture.png" width="16" height="16" hspace="5" vspace="5" align="absmiddle" />ไฟล์รูปแปลน</td> </tr> <tr> <td height="40" bgcolor="#f0f0f0" class="NAV_URL"> </td> <td bgcolor="#f0f0f0" class="NAV_URL"><span class="txt10-black">หากท่านต้องการเพิ่มไฟล์รูปภาพ ทำได้โดยกดปุ่ม Browse เพื่อทำการเลือกไฟล์ภาพ จากนั้นกดปุ่มเพิ่มรูปภาพ/ไฟล์ โดยระบบสามารถเพิ่มไฟล์ได้ไม่จำกัด และรูปภาพควรมีขนาดไม่เกิน กว้าง 800 สูง 600 pixel (รองรับไฟล์ .jpg .gif .png );</span></td> </tr> <tr> <td width="40" height="50" bgcolor="#f0f0f0" class="NAV_URL"><label></label></td> <td width="608" bgcolor="#f0f0f0" class="NAV_URL">เลือกไฟล์ <input name="uploadfile2" type="file" id="uploadfile2" /> <input name="Button" type="button" value=" เพิ่มรูปภาพ / ไฟล์ " onclick="addImage('plan');" /></td> </tr> <tr> <td height="5" bgcolor="#f0f0f0" class="NAV_URL"></td> <td bgcolor="#f0f0f0" class="NAV_URL"></td> </tr> <tr> <td height="5" colspan="2" bgcolor="#FFFFFF" class="NAV_URL"><!-- ////////////// --> <table width="" border="0" cellpadding="0" cellspacing="0" bgcolor=""> <tr> <td><table width="" border="0" cellpadding="5" cellspacing="5"> <tr> <?php $query="SELECT * FROM tbl_home_plan WHERE home_id = '".$_POST['currID']."' ORDER BY id ASC "; $resultPic=mysql_query($query); $col=3;$n=1;$loops=1; $n_width=150;$n_height=150; while($pic = mysql_fetch_assoc($resultPic)){ if($loops==1){ $firstPic=$pic['image_file']; } echo "<td bgcolor='#F8F8F8' nowarp height=25 align ='center' valign='bottom'> "; $info = pathinfo($path_product."/".$pic['image_file']); //echo $info[extension]; $info[extension]=strtolower($info[extension]); if(($info[extension]=='pjpeg') || ($info[extension]=='gif') || ($info[extension]=='png') || ($info[extension]=='x-png') || ($info[extension]=='jpeg') || ($info[extension]=='jpg')){ if(!file_exists($path_photo."/thb/".$path_product.$pic['image_file'])){ list($width, $height, $type, $attr) = getimagesize($path_product.$pic['image_file']); create_thub($path_product."/",$pic['image_file'],$n_width,$n_height); } echo "<a href='".$path_product."/".$pic['image_file']."' target='_blank'>"; echo "<img src='".$path_product."/thb/".$pic['image_file']."' border =0>"; echo "</a>"; echo "<br> "; }else{ echo "<a href='".$path_product."/".$pic['image_file']."' target='_blank'>"; echo "<img src='images/MyDocuments.png' width='130' height='130' /><br>"; echo $pic['oldFilename']; echo "</a>"; echo "<br> "; } echo "<a href=# onclick=removePic2('".$pic['image_file']."'); >"; echo "<img src='images/black_icon/16x16/delete.png' border=0 align =absmiddle hspace='5' vspace='5' /> ลบ"; echo "</a></td> "; if($n==$col){ echo "</tr>\n"; $n=0;}; $n++; $loops++; } //---------------update firstpic-----------------// $query="UPDATE tbl_home_data SET home_plan ='".$firstPic."' WHERE id = '".$_POST['currID']."' "; mysql_query($query); ?> </tr> </table></td> </tr> </table> <!-- ////////////// --></td> </tr> <tr> <td height="5" bgcolor="#f0f0f0" class="NAV_URL"></td> <td bgcolor="#f0f0f0" class="NAV_URL"></td> </tr> </tbody> </table> <br /> <?php }?> </td> </tr> <tr> <td align="right"> </td> </tr> </table></td> </tr> </table> <br /> </form> </body> </html>
|