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
|
<?php //------------------------------------------------------------------------ if($_GET['currentID']){ $_POST['currentID']=$_GET['currentID']; } ########################################################################## if($_POST['action']=='Sort') { switch($_POST['toSort']) { case "up" : $numberUpDate=$_POST['number']-1; $query="UPDATE tbl_product_category SET num = num+1 WHERE num='".$numberUpDate."' AND mainCateId='".$_POST['subcateID']."' "; //echo $query."<br>"; mysql_query($query); $query="UPDATE tbl_product_category SET num = num-1 WHERE id='".$_POST['EditID']."' "; mysql_query($query); //echo $query."<br>"; break; case "down" : $numberUpDate=$_POST['number']+1; $query="UPDATE tbl_product_category SET num =num-1 WHERE num='".$numberUpDate."' AND mainCateId='".$_POST['subcateID']."' "; //echo $query."<br>"; mysql_query($query); $query="UPDATE tbl_product_category SET num =num+1 WHERE id='".$_POST['EditID']."' "; mysql_query($query); //echo $query."<br>"; break; } }//end Sort
#################################################### if($_POST['action']=='add'){ $query="SELECT MAX(num) Maxnum FROM tbl_product_category WHERE mainCateId='0' "; $result=mysql_query($query); $max=mysql_fetch_assoc($result); $maxNum=$max['Maxnum']+1; //---------------------------------------------------------------------------------------------------------- if($_FILES['productImage']['name']!=""){ $tempFileName = $_FILES['productImage']['name']; GetNewFileName($_FILES['productImage']['tmp_name'],$_FILES['productImage']['name'],$i); move_uploaded_file($_FILES['productImage']['tmp_name'], $path_product.$_FILES['productImage']['name']); $_POST['categoryImage']= $_FILES['productImage']['name']; //@unlink($path_product.$_POST['oldDesignImg']); //@unlink($path_product."/thb/".$_POST['OLDproduct_image']); } //------------------------------------------------------------------------------------------------------------ $query="INSERT INTO `tbl_product_category` " ."(`id` ,`cate_name` ,`external_link` ,`useLink` ,`num` ,`cate_name_en`,`categoryImage` ) " ." VALUES " ."( '' , '".$_POST['cate_name']."', '".$_POST['external_link']."' , '".$_POST['useLink']."', '".$maxNum."' , '".$_POST['cate_name_en']."' , '". $_POST['categoryImage']."')"; mysql_query($query); //$_POST['currentID']= mysql_insert_id(); } ####################################################,`categoryImage`= '". $_POST['categoryImage']."' if($_POST['action']=='update'){ //---------------------------------------------------------------------------------------------------------- if($_FILES['productImage']['name']!=""){ $tempFileName = $_FILES['productImage']['name']; GetNewFileName($_FILES['productImage']['tmp_name'],$_FILES['productImage']['name'],$i); move_uploaded_file($_FILES['productImage']['tmp_name'], $path_product.$_FILES['productImage']['name']); $_POST['categoryImage']= $_FILES['productImage']['name']; @unlink($path_product.$_POST['OLDcategoryImage']); @unlink($path_product."/thb/".$_POST['OLDcategoryImage']); }else{ $_POST['categoryImage']=$_POST['OLDcategoryImage']; } //---------------------------------------------------------------------------------------------------------- $query="UPDATE `tbl_product_category` SET `cate_name`= '".$_POST['cate_name']."' ,`external_link`='".$_POST['external_link']."' ,`useLink` ='".$_POST['useLink']."' ,`cate_name_en` = '".$_POST['cate_name_en']."' ,`categoryImage`= '". $_POST['categoryImage']."' " ." WHERE id = '".$_POST['currentID']."' "; //selectCateID if(mysql_query($query)){ ?> <script language="javascript"> window.location.href='main.php?work=addProductCategory'; </script> <?php } //echo $query; } ####################################################DelID number if($_POST['action']=='delete'){ //$query="SELECT SUM(id) SumID FROM tbl_product_category WHERE mainCateId='".$_POST['DelID']."' "; $query="SELECT COUNT(id) AS SumID FROM `tbl_product_data` WHERE mainCateId='".$_POST['DelID']."' "; $result=mysql_query($query); $data=mysql_fetch_assoc($result); if($data['SumID'] > 0){ ?> <script language="javascript"> alert('กรุณาลบสินค้าในหมวดนี้ให้หมดก่อน ถึงจะลบหมวดสินค้านี้ได้'); window.location.href='main.php?work=addProductCategory'; </script> <?php }else{ $query ="DELETE FROM tbl_product_category WHERE id = '".$_POST['DelID']."' "; mysql_query($query); //-------------resort-----------------------------------------number $query="UPDATE tbl_product_category SET num=num-1 WHERE num > '".$_POST['number']."' AND mainCateId='0' "; mysql_query($query);
} } #################################################### if($_POST['currentID']){ $query="SELECT * FROM tbl_product_category WHERE id = '".$_POST['currentID']."' "; $result=mysql_query($query); $currentData=mysql_fetch_assoc($result); } #################################################### $query="SELECT * FROM tbl_product_category WHERE mainCateId='0' ORDER BY num ASC "; $resultList=mysql_query($query); $Xrow=mysql_num_rows($resultList); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="style.css" rel="stylesheet" type="text/css" />
<style> a.tooltip {outline:none; } a.tooltip strong {line-height:30px;} a.tooltip:hover {text-decoration:none;} a.tooltip span { z-index:10;display:none; padding:14px 20px; margin-top:-30px; margin-left:28px; width:auto; line-height:16px; min-height:30px; } a.tooltip:hover span{ display:inline; position:absolute; color:#111; border:1px solid #DCA; background:#fffAF0;} .callout {z-index:20;position:absolute;top:30px;border:0;left:-12px;} /*CSS3 extras*/ a.tooltip span { border-radius:4px; box-shadow: 5px 5px 8px #CCC; } --> </style> <script language="javascript"> function checkForm(act){ if(document.form1.cate_name.value==''){ alert('กรุณาใส่หมวดสินค้าด้วยค่ะ'); return false }else{ document.form1.action.value = act; document.form1.submit(); } } //------------------------------ function DeleteThis(ids, nums){ if(confirm('ต้องการลบรายการนี้')){ document.form1.action.value = 'delete'; document.form1.DelID.value = ids; document.form1.number.value=nums; document.form1.submit(); } } function sortThis(number, toSort , ids , subcateID ){ document.form1.number.value=number; document.form1.toSort.value=toSort; document.form1.EditID.value=ids; document.form1.subcateID.value=subcateID; document.form1.action.value='Sort'; document.form1.submit(); } //-------------------------------------------------- function DeleteThis2(ids){ if(confirm('ตอ้งการลบรายการนี้')){ document.form1.action.value = 'delete'; document.form1.ids.value = ids; document.form1.submit(); } } </script> <form action="<?php $_SERVER['PHP_SELF']?>" method="post" name="form1" enctype="multipart/form-data"> <table width="100%" border="0" cellspacing="3" cellpadding="3"> <tr> <td class="txt10-black"><table width="100%" border="0" cellspacing="2" cellpadding="2"> <tr> <td width="22%" height="4" align="right" class="txt10-black">ชื่อหมวดสินค้า </td> <td width="78%"><span class="NAV_URL"> <input name="cate_name" type="text" id="cate_name" size="50" value="<?php echo $currentData['cate_name']?>" /> </span></td> </tr> <tr> <td height="2" align="right" class="txt10-black">รูปหมวดสินค้า</td> <td width="78%" class="red"> <?php if($currentData['categoryImage']){?> <?php $n_width=174;$n_height=116; list($width, $height, $type, $attr) = getimagesize($path_product.$currentData['categoryImage']); create_thub($path_product."/",$currentData['categoryImage'],$n_width,$n_height); ?> <a href="<?php echo $path_product.$currentData['categoryImage'];?>" target="_blank"> <img src="<?php echo $path_product."/thb/".$currentData['categoryImage'];?>" alt="" /></a><br /> <?php } ?> <input name="productImage" type="file" id="productImage" /> <input type="hidden" name="OLDcategoryImage" id="OLDcategoryImage" value="<?php echo $currentData['categoryImage']?>" /> <br /> กว้าง 227 pixel สูง155 pixel</td> </tr> <!-- <tr> <td height="25" align="right" class="txt10-black">link ภายนอก</td> <td > <input name="external_link" type="text" id="external_link" size="50" value="<?php echo $currentData['external_link']?>" /><span class="red">**ใส่ http:// </span></td> </tr> <tr> <td height="11" align="right" class="txt10-black">การใช้ link</td> <td><select name="useLink" id="useLink"> <option value="1" <?php if($currentData['useLink']==1){ echo "selected";}?>>ภายใน</option> <option value="2" <?php if($currentData['useLink']==2){ echo "selected";}?>>ภายนอก</option> </select></td> </tr> --> <tr> <td height="25" align="right"><span class="NAV_URL"> <input type="hidden" name="currentID" value="<?php echo $_POST['currentID']?>"/> <input type="hidden" name="DelID" /> <input name="action" type="hidden" id="action" /> <input type="hidden" name="ids" id="ids" /> <input type="hidden" name="number" /> <input type="hidden" name="toSort" /> <input type="hidden" name="EditID" /> <input type="hidden" name="subcateID" /> </span></td> <td><span class="NAV_URL"> <?php if($_POST['currentID']){?> <input name="Submit" type="submit" value=" แก้ไขข้อมูล " onclick="checkForm('update');"/> <?php }else{ ?> <input name="Submit" type="submit" value=" เพิ่ม " onclick="checkForm('add');" /> <?php } ?> </span></td> </tr> <tr> <td height="25" colspan="2" align="center"> </td> </tr> <tr> <td height="25" colspan="2" align="left" class="txt10-black">รายชื่อหมวดสินค้า</td> </tr> <tr> <td height="25" colspan="2" align="left"><table width="100%" border="0" cellpadding="1" cellspacing="1"> <tr class="h3"> <td height="30" colspan="3" align="center" bgcolor="#E0E0E0">ชื่อหมวดสินค้า <!--รูปหมวดสินค้า --></td> <td colspan="2" align="center" bgcolor="#E0E0E0">เรียงลำดับ</td> <td colspan="2" align="center" bgcolor="#E0E0E0"><!--เพิ่มหมวดย่อย -->แก้ไข</td> <td width="7%" align="center" bgcolor="#E0E0E0">ลบ</td> </tr> <?php $n=1; while($data=mysql_fetch_assoc($resultList)){ if($n%2){ $bgcolor='#F2F2F2';}else{ $bgcolor=''; } ?> <tr class="txt10-black"> <td width="5%" align="center" bgcolor="<?php echo $bgcolor?>"><img src="images/black_icon/16x16/folder.png" width="16" height="16" /></td> <td width="54%" bgcolor="<?php echo $bgcolor?>"> <?php echo $data['cate_name']?><br /> <!--
</a> --> </td> <td width="9%" align="center" bgcolor="<?php echo $bgcolor?>"><a href="#" title="<img src='<?php echo $path_product.$data['categoryImage']?>'>"> </a> <a href="#" class="tooltip"> <img src="images/black_icon/16x16/picture.png" width="16" height="16" /> <span> <img class="callout" src="images/callout.gif" /> <img src="<?php echo $path_product.$data['categoryImage']?>" style="float:right;" /> </span> </a></td> <td width="9%" align="center" bgcolor="<?php echo $bgcolor?>"><?php if($data['num']>1){?> <a href="javascript:void(0)" onclick="sortThis('<?php echo $data['num'];?>', 'up' , '<?php echo $data['id'];?>','<?php echo $data['mainCateId'];?>' )"> <img src="images/black_icon/16x16/sq_br_up.png" width="16" height="16" border="0" /> </a> <?php } ?></td> <td width="8%" align="center" bgcolor="<?php echo $bgcolor?>"><?php if($Xrow > $data['num']){?> <a href="javascript:void(0)" onclick="sortThis('<?php echo $data['num'];?>', 'down' , '<?php echo $data['id'];?>','<?php echo $data['mainCateId'];?>' )"> <img src="images/black_icon/16x16/sq_br_down.png" width="16" height="16" border="0" /></a> <?php } ?></td> <td colspan="2" align="center" bgcolor="<?php echo $bgcolor?>"><!--<?php //echo $data['num']?><a href="main.php?work=addProductCategory2&ManCateID=<?php echo $data['id']?>&MainCateName=<?php echo $data['cate_name']?>"><img src="images/black_icon/16x16/sq_plus.png" width="16" height="16" style="border:none" /></a> --><a href="main.php?work=addProductCategory¤tID=<?php echo $data['id']?>" title="แก้ไข <?php echo $data['cate_name']?>"><img src="images/black_icon/16x16/doc_edit.png" width="16" height="16" border="0" /></a></td> <td align="center" bgcolor="<?php echo $bgcolor?>"> <a href="#" title="ลบ <?php echo $data['cate_name']?>" onClick="DeleteThis('<?php echo $data['id']?>','<?php echo $data['num']?>')"><img src="images/black_icon/16x16/sq_minus.png" width="16" height="16" border="0" /></a></td> </tr> <tr> <td height="1" colspan="8" bgcolor="#DBDBDB"></td> </tr> <?php $n++; } ?> <tr> <td colspan="8"> </td> </tr> </table></td> </tr> </table></td> </tr> </table> </form>
|