001.
<?
002.
session_start();
003.
session_save_path(
"./session/"
);
004.
005.
$maxboarduser=$_SESSION[
'maxboarduser'
];
006.
$maxboardpwd=$_SESSION[
'maxboardpwd'
];
007.
008.
Header(
'Content-Type: text/html; charset=TIS-620'
);
009.
$types = $_POST[
'types'
];
010.
$littletype = $_POST[
'littletype'
];
011.
$status = $_POST[
'status'
];
012.
$name = $_POST[
'name'
];
013.
$city = $_POST[
'city'
];
014.
$contact = $_POST[
'contact'
];
015.
$topic = $_POST[
'topic'
];
016.
$detail = $_POST[
'detail'
];
017.
$user = $_POST[
'user'
];
018.
$pwd = $_POST[
'pwd'
];
019.
$tel = $_POST[
'tel'
];
020.
$mobile = $_POST[
'mobile'
];
021.
$fax = $_POST[
'fax'
];
022.
$links = $_POST[
'links'
];
023.
$statusproduct = $_POST[
'statusproduct'
];
024.
$price = $_POST[
'price'
];
025.
$send = $_POST[
'send'
];
026.
$email = $_POST[
'email'
];
027.
$textcode = $_POST[
'textcode'
];
028.
$code = $_POST[
'code'
];
029.
$key1 = $_POST[
'key1'
];
030.
$key2 = $_POST[
'key2'
];
031.
$key3 = $_POST[
'key3'
];
032.
$key4 = $_POST[
'key4'
];
033.
$key5 = $_POST[
'key5'
];
034.
$key6 = $_POST[
'key6'
];
035.
$id = $_POST[
'id'
];
036.
$idup = $_POST[
'idup'
];
037.
$picc = $_POST[
'picc'
];
038.
$updatea = $_POST[
'updatea'
];
039.
$typeid = $_POST[
'typeid'
];
040.
$littleid = $_POST[
'littleid'
];
041.
042.
043.
$dateupdate = date(
"Y-m-d H:i:s"
);
044.
$date = Date(
"j/m/Y"
);
045.
$time = Date(
"H:i"
);
046.
$ip = getenv(
"REMOTE_ADDR"
);
047.
048.
049.
$filename =$HTTP_POST_FILES[
'img'
][
'name'
];
050.
$filetempname =$HTTP_POST_FILES[
'img'
][
'tmp_name'
];
051.
$filesize =$HTTP_POST_FILES[
'img'
][
'size'
];
052.
$filetype =$HTTP_POST_FILES[
'img'
][
'type'
];
053.
054.
?>
055.
<title>เพิ่มหัวข้อใหม่</title>
056.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=Tis-620"
>
057.
<LINK REL=
"stylesheet"
TYPE=
"text/css"
HREF=
"maxstyle.css"
>
058.
<script>
059.
function goback() {
060.
history.go(-1);
061.
}
062.
</script>
063.
<?
064.
065.
#วางโค๊ดตรวจสอบการโพสซ้ำๆที่นี่
066.
067.
if
($textcode != $code) {
068.
echo
"<center><br><br>กรุณากรอก Security code ให้ถูกต้อง<br><br>"
;
069.
echo
"<a href='javascript:goback()'>กลับไปแก้ไข</a></center>"
;
070.
exit();
071.
}
072.
073.
074.
#ตรวจสอบอีกครั้งหนึ่งว่าใส่ข้อมูลครบหรือไม่
075.
if
(($types==
""
)||($littletype==
""
)||($status==
""
)||($name==
""
)||($city==
""
)||($contact==
""
)||($topic==
""
)||($detail==
""
)){
076.
print $not_ok_add ;
077.
exit();};
078.
079.
#ตรวจสอบว่ามีการกรอกอีเมล์ให้ตอบกลับหรือไม่และใช่ email หรือไม่
080.
#จบตรวจสอบอีเมล์
081.
082.
include(
"config.in.php"
);
083.
#ตรวจสอบว่าใช่สมาชิกหรือไม่
084.
$db_conn = mysql_connect($host,$username,$password) or die (
"ไม่สามารถติดต่อดาต้าเบสได้"
);
085.
mysql_select_db($dbname,$db_conn);
086.
$query =
"select * from member where login = '$user' AND pass = '$pwd' "
;
087.
$result = mysql_query($query,$db_conn);
088.
$idmember = mysql_fetch_row($result);
089.
$memRow = mysql_num_rows($result);
090.
if
($memRow == 0) {
091.
$login =
""
;
092.
}
else
{ $login =
"$idmember[1]"
; };
093.
#จบตรวจสอบสมาชิก
094.
095.
#ตัดสคริป html ที่ส่งเข้ามาในส่วนที่ไม่ต้องการให้แสดง
096.
$name = htmlspecialchars( $name );
097.
$contact = htmlspecialchars( $contact );
098.
$topic = htmlspecialchars( $topic );
099.
$detail = $detail ;
100.
#จบส่วนตัดสคริป
101.
102.
#ป้องกันคำหยาบและคำไม่สุภาพต่างๆ
103.
$word = $maxboardban;
104.
$ban = $ban_change;
105.
for
($i=0 ; $i<
sizeof
($word) ; $i++) {
106.
$topic = eregi_replace($word[$i],$ban,$topic);
107.
$name = eregi_replace($word[$i],$ban,$name);
108.
$detail = eregi_replace($word[$i],$ban,$detail);
109.
};
110.
#จบการป้องกันคำหยาบ
111.
112.
#กำหนดวันที่ เวลา และหมายเลขไอพี
113.
114.
#จบการตรวจสอบ วันที่ เวลา และหมายเลขไอพี
115.
116.
#ตรวจสอบโค๊ดอังกฤษเพื่อนำไปใส่ใน id ของหัวข้อกระทู้และรูป
117.
$c_eng =
"select * from typesub where littletype = '$littletype' "
;
118.
mysql_query(
'SET NAMES tis620'
);
119.
$c_eng_check = mysql_db_query($dbname,$c_eng) or die (
"ไม่สามารถสั่งให้ database ทำงานเช็คประเภทย่อยได้ในขณะนี้"
);
120.
$eng_c = mysql_fetch_row( $c_eng_check);
121.
$little_code = $eng_c[3] ;
122.
#จบการตรวจสอบโค๊ดอังกฤษ
123.
124.
###ตรวจสอบหัวข้อกระทู้ก่อนเพิ่มหัวข้อใหม่
125.
$chk_topic =
"select * from topic order by pk DESC"
;
126.
$chk_topic_re = mysql_db_query($dbname,$chk_topic) or die (
"ไม่สามารถสั่งให้ database เพื่อทำการตรวจสอบหัวข้อกระทู้ได้"
);
127.
$idtopic = mysql_fetch_row( $chk_topic_re );
128.
$TopicRow = mysql_num_rows($chk_topic_re);
129.
$topic_id = $idtopic[0]+1 ;
130.
#เป็นการเพิ่ม 0001 ในหัวข้อคำถามเพื่อแสดงและเพิ่มในดาต้าเบส
131.
$numtopic = $topic_id ;
132.
if
($numtopic>=100){$numtopic=
"0$numtopic"
;}
133.
else
{
if
($numtopic>=10){$numtopic=
"00$numtopic"
;}
134.
else
{$numtopic=
"000$numtopic"
;}
135.
};
136.
###จบตรวจสอบหัวข้อกระทู้
137.
$topic_run=Date(
"jmYHis"
);
138.
$topic_run1 =
"$little_code$numtopic"
; #บวกเอาโค๊ดภาษาอังกฤษเข้ากับตัวเลขกระทู้
139.
#ลบภาพเก่าออกจาก Folder
140.
141.
142.
if
($img==
""
){ }
else
{
143.
if
($picc==
""
){ }
else
{
144.
$picc2 =
"item/$picc"
; #ไฟล์รูปความเห็น
145.
if
(file_exists( $picc2 )) { unlink(
"$picc2"
); }
else
{ }; #ทำการลบรูปออกไป
146.
};
147.
}
148.
149.
#ตรวจสอบขนาดของรูปที่ Post เข้ามา
150.
if
( $filesize > $max_photo_size ) {
151.
print $photo_size_over ;
152.
exit(); };
153.
#สิ้นสุดการตรวจสอบขนาดรูป
154.
155.
#ทำการอัพโหลดและเปลี่ยนชื่อรูปลงดาต้าเบส หากต้องการไฟล์ชนิดอื่นก็เพิ่มเข้าไป
156.
if
( $filetype ==
"image/gif"
)
157.
{
158.
$filename = $topic_run.
".gif"
;
159.
}
160.
if
( $filetype ==
"image/png"
)
161.
{
162.
$filename = $topic_run.
".png"
;
163.
}
164.
elseif (($filetype==
"image/jpg"
)||($filetype==
"image/jpeg"
)||($filetype==
"image/pjpeg"
))
165.
{
166.
$filename = $topic_run.
".jpg"
;
167.
}
168.
@copy ($filetempname ,
"item/"
. $filename );
169.
#สิ้นสุดการอัพโหลดรูป
170.
171.
172.
#สิ้นสุดการอัพโหลดรูป
173.
174.
#ทำการเพิ่มข้อมูลลงไปในดาต้าเบส
175.
include(
"config.in.php"
);
176.
$create_topic_db = mysql_connect($host,$username,$password) or die (
"ไม่สามารถติดต่อ database ทำการเพิ่มข้อมูลได้"
);
177.
mysql_select_db($dbname,$create_topic_db) or die (
"ไม่สามารถเลือก database ทำการเพิ่มข้อมูลได้"
);
178.
179.
180.
if
($updatea==
""
){
181.
182.
$create_topic =
183.
"insert into topic (id,topic,type,littletype,status,detail,price,weblink,numpost,numvisit, imgname,login,name,email,date,time,ip,address,statusproduct,sendproduct,city,tel,fax,mobile,callback,key1,key2,key3,key4,key5,key6,dateupdate,typeid,littleid) values ('$topic_run1','$topic','$types','$littletype','$status','$detail','$price','$links','0','0','$filename','$login','$name','$email','$date','$time','$ip','$contact','$statusproduct','$send','$city','$tel','$fax','$mobile','$callback','$key1','$key2','$key3','$key4','$key5','$key6','$dateupdate','$typeid','$littleid')"
;
184.
185.
$create_topic_re = mysql_db_query($dbname,$create_topic) or die (
"ไม่สามารถสั่งให้ database ทำการเพิ่มข้อมูลได้"
);
186.
print $add_topic_ok ;
187.
}
else
{
188.
189.
if
($img==
""
){
190.
$picture1=$picc;
191.
}
else
{
192.
$picture1=$filename;
193.
}
194.
195.
196.
$create_topic = "update topic
set
197.
topic=
'$topic'
,
198.
type=
'$types'
,
199.
littletype=
'$littletype'
,
200.
status=
'$status'
,
201.
detail=
'$detail'
,
202.
price=
'$price'
,
203.
weblink=
'$links'
,
204.
imgname=
'$picture1'
,
205.
login=
'$login'
,
206.
name=
'$name'
,
207.
email=
'$email'
,
208.
date=
'$date'
,
209.
time=
'$time'
,
210.
ip=
'$ip'
,
211.
address=
'$contact'
,
212.
statusproduct=
'$statusproduct'
,
213.
sendproduct=
'$send'
,
214.
city=
'$city'
,
215.
tel=
'$tel'
,
216.
fax=
'$fax'
,
217.
mobile=
'$mobile'
,
218.
callback=
'$callback'
,
219.
key1=
'$key1'
,
220.
key2=
'$key2'
,
221.
key3=
'$key3'
,
222.
key4=
'$key4'
,
223.
key5=
'$key5'
,
224.
key6=
'$key6'
,
225.
dateupdate=
'$dateupdate'
226.
where pk=$id";
227.
228.
$create_topic_re = mysql_db_query($dbname,$create_topic) or die (
"ไม่สามารถ Update ทำการเพิ่มข้อมูลได้"
);
229.
print $edit_topicupdate_ok ;
230.
231.
232.
}
233.
?>