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
|
<?php //-----------------------------Date------------------------------------ setlocale (LC_TIME, 'th'); //------------------------------------ if($_GET['currID']){ $_POST['currID']=$_GET['currID'];} //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- if($day==""){ $day=date("d"); } if ($month==""){ $month = date("n"); } if ($year==""){ $year = date("Y"); } $currentYear=date("Y"); //----------------------------------------------------------------------------- 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 IGNORE FROM tbl_promotion_file WHERE file_name = '".$_POST['RmPic']."' ";
mysql_query($query); } //----------------------------------------------------------------------------- //echo $_POST['action']." << action<br>"; if($_POST['action']=='Add'){ $_POST['date_act']=$_POST['syear']."-".$_POST['smonth']."-".$_POST['sdate']; if($_POST['currID']==''){ $query="INSERT IGNORE INTO `tbl_promotion_data` " ." ( `id` , `topic_th` , `topic_en` , `detail_th` , `detail_en` , `date_act`, `cate_id` , `reff`, `reff_en`, `language`) " ." VALUES " ." ('' , '".$_POST['topic_th']."', '".$_POST['topic_en']."', '".$_POST['detail_th']."', '".$_POST['detail_en']."', '".$_POST['date_act']."' , '".$_POST['cate_id']."' , '".$_POST['reff']."' , '".$_POST['reff_en']."' , '".$_SESSION['language']."') "; mysql_query($query); $_POST['currID'] =mysql_insert_id(); }else{ $query="UPDATE IGNORE tbl_promotion_data SET " ." `topic_th`= '".$_POST['topic_th']."' , `topic_en`='".$_POST['topic_en']."' , `detail_th`='".$_POST['detail_th']."' , `detail_en`= '".$_POST['detail_en']."' , `date_act`='".$_POST['date_act']."' , `cate_id` = '".$_POST['cate_id']."' " ." , `reff` ='".$_POST['reff']."' , `reff_en`= '".$_POST['reff_en']."' " ." WHERE id = '".$_POST['currID']."' "; mysql_query($query); }//$_POST['currID'] //>>>>>>------add img // echo $query; if($_POST['currID']){ for($i=0;$i<count($_FILES["uploadfile"]["name"]);$i++) { if($_FILES['uploadfile']['tmp_name'][$i]!=""){ $info = pathinfo($_FILES['uploadfile']['name'][$i]); $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')){ $_POST['file_type']=1; }else{ $_POST['file_type']=2; } //------------------------------------------------- GetNewFileName($_FILES['uploadfile']['tmp_name'][$i],$_FILES['uploadfile']['name'][$i],$i); move_uploaded_file($_FILES['uploadfile']['tmp_name'][$i], $path_product.$_FILES['uploadfile']['name'][$i]); //------------------------------------------------ $query=" INSERT IGNORE INTO `tbl_promotion_file` ( `id` , `w_th` , `w_en`, `file_name` , `news_id` , `file_type`, `origin_name_th` ) " ." VALUES " ." ( '', '".$_POST['w_th']."', '".$_POST['w_en']."', '".$_FILES['uploadfile']['name'][$i]."', '".$_POST['currID']."', '".$_POST['file_type']."','".$_POST['origin_file_name'][$i]."') "; //echo $query."<br>"; mysql_query($query); } } } // end add image------------------ ////////////////////////////// txt Image /////////////////////////////////// wth wen hiddenID for($i=1;$i <$_POST['hiddenLoops'];$i++){ $query="UPDATE IGNORE tbl_promotion_file SET `w_th`='".$_POST['wth'][$i]."' , `w_en` ='".$_POST['wen'][$i]."' WHERE id ='".$_POST['hiddenID'][$i]."' "; mysql_query($query) ; } } if($_POST['currID']){ $query="SELECT * FROM tbl_promotion_data WHERE id = '".$_POST['currID']."' "; $result=mysql_query($query); $currentData =mysql_fetch_assoc($result); $dateArray=explode("-",$currentData['date_act']); $day=$dateArray[2]; $month=$dateArray[1]; $year=$dateArray[0]; //--------------select img--------------// $query="SELECT * FROM `tbl_promotion_file` WHERE `news_id` = '".$_POST['currID']."' ORDER BY file_type ASC, id ASC"; $resultPic=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 checkForm(){ if(document.form1.topic_th.value==''){ alert('กรุณาใส่หัวข้อ'); return false; }else{ document.form1.action.value='Add'; } } function removePic(pic){ if(confirm('ต้องการลบไฟล์นี้')){ document.form1.RmPic.value=pic; document.form1.action.value='deletePic'; document.form1.submit(); }else{ return false; } } </script> </head>
<body><form action="<?php $_SERVER['PHP_SELF']?>" method="post" name="form1" enctype="multipart/form-data" onsubmit="return checkForm()"> <table width="99%" border="0" align="center" cellpadding="2" cellspacing="2"> <tr class="red"> <td width="4%" height="25" align="center" bgcolor="#D9D9B3"><img src="images/black_icon/16x16/app_window.png" width="16" height="16" /></td> <td width="96%" bgcolor="#D9D9B3">เพิ่ม/แกไข ข้อมูลโปรโมชั่น</td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" align="center" class="txt10-black"><table width="100%" border="0" cellpadding="2" cellspacing="2" class="txt10-black"> <!-- <tr> <td width="21%"><?php echo _txtSelectCagegory?></td> <td width="79%"><select name="cate_id" id="cate_id"> <option value="0">---- <?php echo _txtSelectCagegory?>-----</option> <option value="1" <?php if($currentData['cate_id']=='1') echo "selected";?>><?php echo _txtRubberNews?></option> <option value="2" <?php if($currentData['cate_id']=='2') echo "selected";?>><?php echo _txtAutomobileNews?></option> <option value="3" <?php if($currentData['cate_id']=='3') echo "selected";?>><?php echo _txtEconomicNews?></option> </select></td> </tr> --> <tr> <td><?php echo _txtTopicinput?></td> <td><input name="topic_th" type="text" id="topic_th" size="60" maxlength="255" value="<?php echo $currentData['topic_th']?>"/></td> </tr> <tr> <td><?php echo _txtDetaulinput?></td> <td><textarea name="detail_th" cols="40" rows="5" id="detail_th"><?php echo $currentData['detail_th']?></textarea> <script language="javascript1.2" type="text/javascript">generate_wysiwyg('detail_th'); </script></td> </tr> <!-- <tr> <td><?php echo _txtReff?></td> <td><label for="reff"></label> <input name="reff" type="text" id="reff" size="60" value="<?php echo $currentData['reff']?>"/></td> </tr> --> <tr> <td>หัวข้อ [english]</td> <td><input name="topic_en" type="text" id="topic_en" size="60" maxlength="255" value="<?php echo $currentData['topic_en']?>"/></td> </tr> <tr> <td>รายละเอียด [english]</td> <td><textarea name="detail_en" cols="40" rows="5" id="detail_en"><?php echo $currentData['detail_en']?></textarea><script language="JavaScript1.2" type="text/javascript">generate_wysiwyg('detail_en'); </script></td> </tr> <tr> <td><?php echo _txtDateSelect?></td> <td><select name="sdate"> <?php for($i=1;$i < 32 ;$i ++){ if($i <10) { $value = "0".$i; }else{ $value=$i;} ?> <option value="<?php echo $value;?>" <?php if($day==$i) echo "selected";?>><?php echo $i?></option> <?php }?> </select> <select name="smonth"> <?php while (list($key, $val) = each($monthnames2)) { ?> <option value="<?php echo $key;?>" <?php if($month==$key) echo "selected";?>><?php echo $val?></option> <?php } ?> </select> <select name="syear"> <?php for($i=0;$i<4;$i++){ $stable=$currentYear-1; ?> <option value="<?php echo $stable+$i;?>" <?php if($year==($stable+$i)) echo "selected";?>><?php echo $stable+$i+$Range543;?></option> <?php }?> </select></td> </tr> <!--<tr> <td>ที่มา [english]</td> <td><label for="reff_en"></label> <input name="reff_en" type="text" id="reff_en" size="60" value="<?php echo $currentData['reff_en']?>"/></td> </tr> --> <tr> <td><input type="hidden" name="action" id="action" /> <input type="hidden" name="currID" id="currID" value="<?php echo $_POST['currID']?>" /> <input type="hidden" name="RmPic" id="RmPic" /></td> <td> </td> </tr> <tr> <td bgcolor="#F4F4F4"><?php echo _txtFileAndIMG?></td> <td bgcolor="#F4F4F4" class="red"><label for="uploadfile[]"></label> <input type="file" name="uploadfile[]" id="uploadfile[]" multiple="multiple"/> <br /> **การเลือกไฟล์ได้ครั้งหละหลายไฟล์ รองรับ jpg ,gif, png<br /> ***การเลือกไฟล์แต่ละครั้งขนาดไฟล์รวมกันไม่เกิน 8 เมกกะไบต์</td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" align="center" bgcolor="#FFCC00"><input type="submit" name="button" id="button" value="<?php echo _txtBtnAddEdit?>" /></td> </tr> <tr> <td colspan="2"><!--////////////////////////// --> <table width="" border="0" cellpadding="0" cellspacing="0" bgcolor=""> <tr> <td width="16"><?php if($_POST['currID']){ ?> <table width="" border="0" cellpadding="5" cellspacing="5"> <tr> <?php $col=3;$n=1;$num=1; $n_width=205;$n_height=115; $max_x =200; $max_y =200; while($pic = mysql_fetch_assoc($resultPic)){ echo "<td bgcolor='#F8F8F8' nowarp height=25 align ='center' valign='bottom'> "; $info = pathinfo($path_product."/".$pic['file_name']); //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['file_name'])){ list($width, $height, $type, $attr) = getimagesize($path_product.$pic['file_name']); create_thub($path_product."/",$pic['file_name'],$n_width,$n_height); } echo "<a href='".$path_product."/".$pic['file_name']."' target='_blank'>"; echo "<img src='".$path_product."/thb/".$pic['file_name']."' border =0>"; echo "</a>"; echo "<br> "; }else{ echo "<a href='".$path_product."/".$pic['file_name']."' target='_blank'>"; echo "<img src='images/black_icon/48x48/doc_empty.png' /><br>"; echo $pic['oldFilename']; echo "</a>"; echo "<br> "; } //echo "<br>"._txtFileDesc." <br> <input type='text' size='30' name='wth[".$num."]' value='".$pic['w_th']."'> "; //echo "<br>คำบรรยายอังกฤษ <br> <input type='text' size='30' name='wen[".$num."]' value='".$pic['w_en']."'>"; echo "<input type='hidden' name='hiddenID[".$num."]' value='".$pic['id']."' > "; echo "<br><a href=# onclick=removePic('".$pic['file_name']."'); >"; echo "<img src='images/20x20_trash.gif' border=0 align =absmiddle hspace='5' vspace='5' /> ลบ"; echo "</a></td> "; if($n==$col){ echo "</tr>\n"; $n=0;}; $n++; $num++; } ?> </tr> </table></td> </tr> </table> <?php }?> <!-- ///////////////////////// --></td> </tr> <tr> <td colspan="2" align="center" bgcolor="#FFCC00"><input type="submit" name="button" id="button" value="<?php echo _txtBtnAddEdit?>" /></td> </tr> </table></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> </body> </html>
|