ซื้อขายบ้านมือสอง

วันอังคารที่ 9 ตุลาคม พ.ศ. 2550

ระบบ Simple Webboard upload รูปภาพได้






ดาวน์โหลด โปรแกรม webboard ได้ที่นี่

ระบบ Simple Webboard


โปรแกรมระบบเว็บบอร์ด เป็นระบบที่สามารถ โพสหัวข้อคำถาม และสามารถ ตอบคำถามในหัวข้อนั้นๆ สามารถที่จะ ลบหัวข้อ และ ลบคำตอบ มีรายลเอียดดังนี้


1. แสดงรายการคำถามทั้งหมด


2. เพิ่มหัวข้อคำถามได้


3. โพสรูปได้


4. มีส่วนตอบคำถาม


5. admin สามารถ ลบข้อมูลคำถาม และคำตอบได้



โครงสร้างของระบบ




อธิบายการทำงาน


Level 0 หน้า question list เป็นส่วนที่แสดง รายการ คำถามทั้งหมด


Level 1 หน้า เพิ่มคำถาม เป็นส่วนที่ใช้สำหรับ เพิ่ม คำถามใหม่เข้าสู่ระบบ


Level 2 หน้า ดูรายละเอียดคำถาม และคำตอบ


Level 2.1 หน้า เพิ่มคำตอบของคำถามนั้นๆ


Level 3 หน้า Login admin เป็นส่วนที่ใช้สำหรับให้ Login เข้าไปเพื่อ ลบ คำถาม คำตอบ


Level 3.1 หน้า ลบคำถาม


Level 3.2 หน้า ลบคำตอบ




สร้างฐานข้อมูลชื่อ webboardDB และสร้า ตาราง 2 ตารางดังนี้


สร้างตารางชื่อ tblquestion มีรายละเอียดดังนี้




code:







CREATE TABLE tblquestion (


qno INT ( 10 ) NOT NULL ,


qtopic VARCHAR( 255 ) NOT NULL ,


qname VARCHAR( 50 ) NOT NULL ,


qdetail MEDIUMTEXT NOT NULL ,


qdate DATETIME NOT NULL ,


qemail VARCHAR( 100 ) NULL ,


qpicture VARCHAR( 100 ) NULL ,


qreply INT( 5 ) NOT NULL ,


qview INT( 5 ) NOT NULL ,


date_order DATETIME NOT NULL ,


PRIMARY KEY ( qno ) );


สร้างตารางชื่อ tblanswer มีรายละเอียดดังนี้



code:







CREATE TABLE tblanswer (


ano INT( 11 ) NOT NULL AUTO_INCREMENT ,


qno VARCHAR( 10 ) NOT NULL ,


aname VARCHAR( 50 ) NOT NULL ,


aemail VARCHAR( 100 ) NULL ,


adetail MEDIUMTEXT NOT NULL ,


adate DATETIME NOT NULL ,


apicture VARCHAR( 100 ) NULL ,


PRIMARY KEY ( ano ) );




ระบบเว็บบอร์ด จะมี รายละเอียดไฟล์ดังต่อไปนี้

















































































ชือไฟล์


คำอธิบาย


หมายเหตุ


css



โฟรเดอร์ css


- style.css


เก็บ css สำหรับจัดการกับหน้าเว็บ


ไฟล์ในโฟรเดอร์


includes



โฟรเดอร์


- admin_secure.php


เก็บ usernameกับรหัส admin login


ไฟล์ในโฟรเดอร์


- function_validate.php


เก็บฟังชั่นสำหรับ


include


- include_class.php


เก็บไฟล์ class


include


image_upload


เป็นโฟรเดอร์ที่เก็บไฟล์ upload


โฟรเดอร์


index.php


ไฟล์ redirect ไปหน้า question list



question_list.php


ไฟล์ แสดงหน้า รายละเอียดคำถาม



config.php


ไฟล์ กำหนดค่า เริ่มต้น


include


menu.php


ไฟล์ เมนู ต่างๆ


include


add_board.php


ไฟล์ ฟอร์มโพสคำถาม



add_anssave.php


ไฟล์ โปรแกรม insert คำถาม



view_question.php


ไฟล์ ดูคำถาม คำตอบ



add_anssave.php


ไฟล์ โปรแกรม insert คำตอบ



admin.php


ไฟล์ ฟอร์ม login



chklogin.php


ไฟล์ check login



admin_logout.php


ไฟล์ logout




ไฟล์ Style.css


SMALL {FONT-FAMILY: MS Sans Serif; FONT-SIZE: 10pt ;color: #666666;}


B {FONT-FAMILY: MS Sans Serif; FONT-SIZE: 10pt}


table { FONT-FAMILY: MS Sans Serif; FONT-SIZE: 10pt ; color: #333333;}


.Bfont {FONT-FAMILY: MS Sans Serif; FONT-SIZE: 12pt ; color: #666666;}


.sfont {FONT-FAMILY: MS Sans Serif; FONT-SIZE: 8pt ;}


A {COLOR: #000099; FONT-FAMILY: MS Sans Serif; FONT-SIZE: 10pt; TEXT-DECORATION: none}


A:visited {COLOR: #000099; FONT-SIZE: 10pt; TEXT-DECORATION: none; MS: AngsanaUPC}


a:visited:hover {font-family: MS Sans Serif; font-size: 10px; color: #000000;}


A:hover {COLOR:#FF0000; FONT-FAMILY: MS Sans Serif,AngsanaUPC; FONT-SIZE: 10pt; text-decoration: none ;}


.headmenu {


border-color: #C5C7CF #C5C7CF #C5C7CF #C5C7CF ;


border-style: solid; border-top-width: 1px; border-right-width: 0px;


border-bottom-width: 0px; border-left-width: 0px;


filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#F8F8F8,,endcolorstr=#E1E2E6);


}


.gradian_up {


filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#FCFBFF,,endcolorstr=#D7D7D7);


}


.dot {


border-top-width: 1px; border-right-width: 1px;


border-bottom-width: 1px; border-left-width: 1px;


border-top-style: #A1A1A1; border-right-style: #A1A1A1;


border-bottom-color: #A1A1A1; border-bottom-style: dotted;


border-left-color: #A1A1A1;


}





admin_secure.php


<?php


$admin_user="admin";


$admin_pass="123";


?>



ไฟล์ function_validate.php


<?php


// function สำหรับ ติดต่อ กับ ดาต้าเบส


function connectDB() {


global $host,$username,$password,$connect,$dberr,$db,$useerr;


// Connect mysql


if (@$connect = mysql_connect($host, $username, $password)){


if (@!mysql_select_db($db, $connect)){


exit($useerr);


}


}else{


exit($dberr);


}


return false;


}


// function สำหรับ ตัดการเชื่อมต่อกับ


function closeDB() {


global $connect;


return mysql_close($connect);


return false;


}


// ฟังชั่นที่ใช้ในการแสดง list ข้อมูลใน combo box


function listcatmember($sql,$var=""){


connectDB(); // ติดต่อดาต้าเบส


if (!@$result=mysql_query($sql)) {


$showlist= "<option>ไม่สามารถแสดงรายการได้ </option>"; // return error หากไม่สามารถแสดงข้อมูลได้


}else{


//========== หากแสดงข้อมูลเรียบร้อย =============


while ($dbarr=mysql_fetch_array($result)) {


$showlist .="<option value=".$dbarr[0]." " .chkselected($dbarr[0],$var).">".$dbarr[1]."</option>\n";


}


// ========================================


} // จบคำสั่ง if


closeDB(); //ปิดการเชื่อมต่อกับดาต้าเบส


return $showlist; // return ค่า showlist


}


// ========================================


// function chkselected ทำหน้าที่ตรวจเช็คข้อมูลประเภท Control Select 2 ข้อมูลว่า ได้ถูก เลือกอยู่หรือเปล่าโดยเปรียบเทียบค่าที่อยู่ในฐานข้อมูลกับค่าที่จะแสดงโดยอัตโนมัติ


// วิธีการใช้งานคือchkselected(ค่าที่อยู่ในฐานข้อมูล,ค่าของตัวมันเอง);


function chkselected($var1,$var2){


if ($var1 == $var2){


$chkselected = "Selected";


}


else {


$chkselected = "";


}


return $chkselected;


}


function genuploadname($img) {


$imgname = date("Y").date("m").date("j").date("H").date("i").date("s").$img;


return $imgname;


}


// ฟังชั่นที่ใช้ในการ format วันที่


function formatdate($vardate){


$formatdatetime=explode(" ",$vardate);


$formatdate=explode("-",$formatdatetime[0]);


$qdate=$formatdate[2]."/".$formatdate[1]."/".$formatdate[0]." ".$formatdatetime[1];


return $qdate;


}



// function chktextbox ทำหน้าที่ ตรวจเช็คค่าจาก textbox ว่ามีค่าหรือเปล่า ถ้าไม่มีค่า จะไม่สามารถทำงานต่อไปได้


function chktextbox($varvalue,$varname){


if (Trim($varvalue) == ""){


print("<center><font color=\"#000000\" style=\"font-size:14pt\">กรุณาป้อน <font color=\"#FF0000\" style=\"font-size:14pt\">" . $varname . "</font> ด้วยครับ<br>");


print("<a href=\"#\" onclick=\"history.back()\"> Back </a></font></center>");


exit();


}


}


?>



ไฟล์ include_class.php


<?php


// สร้าง class ที่ใช้จัดการ เกี่ยวกับ การ upload รูปภาพ


class upload {


// สร้าง property


var $maxfile;


var $hostfile;


var $file_path;


// สร้าง method ในการตรวจสอบขนาดไฟล์


function chksize() {


// ถ้าไม่มีไฟร์


if ($this->hostfile['size'] == 0) {


echo "<b>Can't not Upload " . "ไม่มีไฟล์นี้ / ไฟล์มีขนาดเป็นศูนย์ คลิก Back </b>";


exit();


}


}


// สร้าง method ในการ จำกัดขนาดของไฟล์


function chkmaxsize() {


// จำกัดขนาดของไฟล์


$limitSize = $this->maxfile * 1024 ; // 200 kByte


if ($this->hostfile['size'] >$limitSize ) {


echo "<b>File ใหญ่เกิน " . ($limitSize / 1024) . " KB คลิก Back กลับไปเลือกใหม่</b>";


exit();


}


}


// สร้าง method ในการ ตรวจสอบ ชนิดของไฟล์


function chktype() {


// จะต้องเป็นไฟร์รูปภาพเท่านั้น


if (substr($this->hostfile['type'],0,5) <> "image") {


echo "<center>อนุญาติให้ Upload เฉพาะรูปภาพเท่านั้น คลิ๊ก <a href=\"javascript:history.back();\">Back</a>กลับไปเพื่อเลือกไฟร์ใหม่</center>";


exit();


}


}


// method สำหรับ upload ไฟล์


function uploadfile() {


$this->chksize();


$this->chkmaxsize();


$this->chktype();


// ขั้นตอนการ copy ไฟร์


$file_name=substr($this->hostfile['name'],-4);


$file_name=genuploadname($file_name);



$uploadfilepath = $this->file_path.$file_name;


if (!copy($this->hostfile['tmp_name'], $uploadfilepath)) {


echo "<b>ไม่สามารถ copy ไฟร์นี้ได้\n";


}


return $uploadimage = $file_name;


}


}


?>


ไฟล์ index.php // ทำหน้าที่ redirect ไปยังหน้า question list


<?php


header("Location:question_list.php"); // สั่ง redirect ไปยังหน้า หัวข้อบอร์ด


?>



ไฟล์ config.php


<?php


session_start();


$host = "localhost" ;


$username = "root" ; // ชื่อในการติดต่อ mysql


$password = "" ; // password ของคุณในการเชื่อมต่อกับฐานข้อมูล


$db = "elearningdb" ; // ชื่อฐานข้อมูลของคุณ กรุณาระบุให้ครบถ้วนนะครับ



$dberr ="<center>เกิดความผิดพลาดของ Server ขึ้น ในขณะ ติดต่อกับ ฐานข้อมูล เนื่องจาก MySQL ของ Server นี้ ไม่ค่อยดีเท่าไหร่ <br>ให้ลองกด Refresh หรือ Reload จนกว่าจะได้</center>";


$useerr = "เรียกใช้ ฐานข้อมูลไม่สำเร็จ";


$inserterr = "เกิดข้อผิดพลาดในการ insert ข้อมูล เพิ่มข้อมูลไม่สำเร็จ กรุณาเช็ค ข้อมูลอีกครั้งว่าถูกต้องหรือไม่";


$selecterr = "ไม่สามารถ นำข้อมูลออกมาจากฐานข้อมูได้ เนื่องจากปัญหาเกี่ยวกับ คำสั่ง query กรุณาเช็คคำสั่งอีกครั้ง";


$updateerr = "เกิดข้อผิดพลาดในการ update ข้อมูล กรุณาเช็ค ข้อมูลอีกครั้งว่าถูกต้องหรือไม่";


$Dirpath="image_upload/";


$realdate=date("Y-m-j H:i:s");



// include ไฟล์ function


include "includes/function_validate.php";


include "includes/include_class.php";


?>



ไฟล์ menu.php


<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">


<tr>


<td bgcolor="#CCCCFF"><font size="5"><strong>ระบบถาม-ตอบ</strong></font> version


1.0<br>


<?php


if ($_SESSION["session_user"]<>"") {


echo "ยินดีต้อนรับคุณ ". $_SESSION["session_user"] ." <a href=\"admin_logout.php\">ออกจากระบบ</a>";


}else{


echo " <a href=\"admin.php\"> [สำหรับผู้ดูแล]</a>";


}


?>


</td>


</tr>


</table>



<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">


<tr>


<td bgcolor="#EAEAEA"><div align="center"><strong><a href="add_board.php">[เพิ่มหัวข้อ]</a> <a href="question_list.php"> [แสดงข้อความ]</a></strong></div></td>


</tr>


</table>



ไฟล์ question_list.php


<?php


include "config.php";


// รับค่าตัวแปร query string เพื่อลบข้อมูล


if ($_SESSION["session_user"]<>"") { // เฉพาะ admin ถึงจะมีสิทธิ ลบข้อมูล


$delqid=$_GET["delqid"];


if ($delqid<>"") {


$sqladel="delete from tblanswer where qno=".$delqid;


$sqlqdel="delete from tblquestion where qno=".$delqid;


connectDB(); // ติดต่อฐานข้อมูล


mysql_query($sqladel); // ลบข้อมูลคำตอบ ในหัวข้อที่จะลบ


mysql_query($sqlqdel); // ลบข้อมูลคำถาม ในหัวข้อที่จะลบ


closeDB(); // ปิดการเชื่อมต่อกับฐานข้อมูล


}


}


// =============================================


?>


<html>


<head>


<title>Untitled Document</title>


<meta http-equiv="Content-Type" content="text/html; charset=tis-620">


<link rel="stylesheet" type="text/css" href="css/style.css">


</head>


<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">


<?php


include "menu.php";


?>


<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" align="center">


<tr>


<td width="80" class="headmenu"><div align="center"><strong>รหัสหัวข้อ</strong></div></td>


<td class="headmenu"><div align="center"><strong>หัวเรื่อง</strong></div></td>


<td width="100" class="headmenu"> <div align="center"><strong>ผู้โพส</strong></div></td>


<td width="80" class="headmenu"> <div align="center"><strong>ตอบ</strong></div></td>


<td width="80" class="headmenu"> <div align="center"><strong>อ่าน</strong></div></td>


<td width="170" class="headmenu">


<div align="center"><strong>วันที่</strong></div></td>


</tr>


<?php


// แสดงหัวข้อ webboard


connectDB(); // ติดต่อฐานข้อมูล


$sql="select * from tblquestion";


$result=mysql_query($sql);


// ===== กำหนด ข้อมูลในการแบ่งหน้า =======


$totalrecord=mysql_num_rows($result);


$pagesize = 2; //กำหนดจำนวนเรคอร์ดที่ต้องการแสดงผลใน 1 หน้า


// คำนวนหาค่าของ page เริ่มต้น


/* คำนวณจำนวนหน้าที่ต้องใช้ในการแสดงผลเรคอร์ดทั้งหมด โดยเก็บไว้ในตัวแปร


ฟังชั่น ceil เป็นฟังชั่นที่ใช้ในการปัดเศษขึ้น ให้เป็นจำนวนเต็ม และจะปัดขึ้นทั้งหมด*/


$totalpage = ceil($totalrecord / $pagesize);


/* $pageid คือตัวแปรที่จะถูกส่งผ่านมาทาง query string เมื่อผู้ใช้คลิกไฮเปอร์ลิงค์


เพื่อเลือกดูหน้าที่ต้องการ */


$pageid=$_GET["pageid"];


if (isset($pageid)) {


//คำนวณหาหมายเลขเรคอร์ดแรกที่เราจะเลือกมา


$start = $pagesize * ($pageid - 1);


}else {


$pageid = 1;


$start = 0;


}


// ===== แสดงผล การแบ่งหน้า ==========================


$sql.=" order by date_order desc LIMIT $start,$pagesize";


if (!$result=mysql_query($sql)) {


exit("ไม่สามารถแสดงข้อมูลได้");


}


// ===============================


$count=1;


while ($dbarr=mysql_fetch_array($result)){


$maxQno=sprintf("Q%05d",$dbarr["qno"]);


if (($count%2))


$bgcolor="#E7EBFE";


else


$bgcolor="#D9DFFD";


$qdate=formatdate($dbarr["qdate"]);


?>


<tr bgcolor="<?php echo $bgcolor;?>">


<td width="80" > <div align="center"><?php echo $maxQno;?>


</div></td>


<td ><a href="view_question.php?qno=<?php echo $dbarr["qno"];?>" target="_blank"><?php echo $dbarr["qtopic"];?></a>


<?php


if ($_SESSION["session_user"]<>"") {


echo "<a href=".$_SERVER["PHP_SELF"]."?delqid=".$dbarr["qno"].">[ลบ]</a>";


}


?></td>


<td width="100" ><div align="center"><?php echo $dbarr["qname"];?> </div></td>


<td width="80" > <div align="center"><?php echo $dbarr["qreply"];?></div></td>


<td width="80" > <div align="center"><?php echo $dbarr["qview"];?></div></td>


<td width="170" >


<div align="right"><?php echo $qdate;?>


</div></td>


</tr>


<?php


$count++;


}


closeDB(); // ปิดการเชื่อมต่อกับฐานข้อมูล


?>


</table>


<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" align="center">


<tr>


<td align="center">


<?php


//ส่วนนี้เป็นการสร้างไฮเปอร์ลิงค์เพื่อให้ผู้ใช้คลิกดูข้อมูลส่วน (หน้า) อื่นๆ


echo "หน้าที่ : ";


for ($i=1; $i<=$totalpage; $i++) {


if ($i == $pageid) {


echo $i . "&nbsp;";


}


else {


echo "[<a href=\"".$_SERVER["PHP_SELF"]."?pageid=$i\">$i</a>]&nbsp;";


}


}


echo " จากทั้งหมด $totalpage หน้า";


?>


</td>


</tr>


</table>


</body>


</html>



ไฟล์ add_board.php


<html>


<head>


<title>Untitled Document</title>


<meta http-equiv="Content-Type" content="text/html; charset=windows-874">


<link rel="stylesheet" type="text/css" href="css/style.css">


</head>


<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">


<?php


include "menu.php";


?>


<form action="add_boardsave.php" method="post" enctype="multipart/form-data">


<table width="500" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">


<tr>


<td colspan="2"><strong>โพสข้อความถาม-ตอบ</strong></td>


</tr>


<tr>


<td width="158" bgcolor="#EAEAEA"><div align="right">หัวเรื่อง :</div></td>


<td width="331" bgcolor="#EAEAEA"><input name="txttopic" type="text" id="txttopic"></td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="right">ชื่อ :</div></td>


<td bgcolor="#EAEAEA"><input name="txtname" type="text" id="txtname"></td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="right">e-mail :</div></td>


<td bgcolor="#EAEAEA"><input name="txtemail" type="text" id="txtemail" size="30"></td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="right">ข้อความ :</div></td>


<td bgcolor="#EAEAEA"><textarea name="txtmessage" cols="40" rows="5" id="txtmessage"></textarea></td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="right">รูปภาพ :</div></td>


<td bgcolor="#EAEAEA"><input name="ufile" type="file" id="ufile"></td>


</tr>


<tr>


<td bgcolor="#EAEAEA">&nbsp;</td>


<td bgcolor="#EAEAEA"><input name="cmdsubmit" type="submit" id="cmdsubmit" value="Submit">


<input name="cmdreset" type="reset" id="cmdreset" value="Reset"></td>


</tr>


</table>


</form>


</body>


</html>



ไฟล์ add_boardsave.php


<?php


include "config.php";


// =========== รับค่าจากฟอร์ม ===============


$submit = $_POST["cmdsubmit"];


$topic = $_POST["txttopic"];


$name = $_POST["txtname"];


$email = $_POST["txtemail"];


$message = $_POST["txtmessage"];


$pimage = $HTTP_POST_FILES['ufile'];


// validate ข้อมูล


chktextbox($topic,"หัวเรื่อง");


chktextbox($name,"ชื่อ");


chktextbox($message,"ข้อความ");


// ==================


if ($pimage["name"]<>"") {


// เพิ่มรูปภาพ


$myUpload=new upload; // ประกาศตัวแปร object เพื่อเรียกใช้งาน class upload


$myUpload->maxfile=200; // ค่าสูงสุดของ การ upload รูปภาพ


$myUpload->hostfile=$pimage; // ชื่อไฟล์


$myUpload->file_path=$Dirpath; // ที่อยู่ของ path


$imgupload = $myUpload->uploadfile(); // เรียกใช้ method สำหรับ upload


// =========================


}else{


$imgupload="";


}


// =====================================


connectDB(); // ติดต่อดาต้าเบส


if ($submit<>"") {


// หาค่า maxid ของบอร์ดล่าสุด


$sqlmax="select max(qno) as maxqno from tblquestion";


$result=mysql_query($sqlmax);


$num=mysql_num_rows($result);


$dbmax=mysql_fetch_array($result);


if ($num>0){


$maxid=$dbmax[0] + 1; // นำค่า ของ qno ล่าสุดมา บอก 1 เป็นค่าถัดไป


}else{


$maxid=1; // หากไม่มีข้อมูลในฐานข้อมูล ให้ กำหนดค่าเป็น 1


}


// ====================


$sqlinsert="insert into tblquestion (qno,qtopic,qname,qdetail,qdate,qemail,qpicture,date_order) values \n".


"('".$maxid."','".$topic."','".$name."','".$message."','".$realdate."','".$email."','".$imgupload."','".$realdate."')";


// เพิ่มข้อมูล


if (!$resultinsert=mysql_query($sqlinsert)) {


exit("ไม่สามารถเพิ่มข้อมูลได้");


}


// ====================


}


closeDB(); // ปิดการติดต่อดาต้าเบส


?>


<html>


<head><title>ขอบคุณมากครับ</title>


<meta http-equiv="Content-Type" content="text/html; charset=windows-874">


<link rel="stylesheet" type="text/css" href="css/style.css">


<meta http-equiv="refresh" content="3;URL=question_list.php">


</head>


<body class="gradian_up">


<table width="300" height="100" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">


<tr>


<td colspan="3" bgcolor="#EAEAEA"><table width="300" border="0" cellspacing="2" cellpadding="0">


<tr>


<td height="30"> <div align="center"><font color="#000000"><strong>เพิ่มหัวข้อเรียบร้อย</strong></font></div></td>


</tr>


<tr>


<td height="30"> <div align="center"><font color="#000000"><strong>โปรดรอซัก


3 วินาที </strong></font></div></td>


</tr>


</table></td>


</tr>


</table>


</body>


</html>



ไฟล์ view_question.php


<?php


include "config.php";


// รับค่าตัวแปร query string เพื่อลบข้อมูล


if ($_SESSION["session_user"]<>"") { // เฉพาะ admin ถึงจะมีสิทธิ ลบข้อมูล


$delaid=$_GET["delaid"];


if ($delaid<>"") {


$sqladel="delete from tblanswer where ano=".$delaid;


connectDB(); // ติดต่อฐานข้อมูล


mysql_query($sqladel); // ลบข้อมูลคำตอบ ในหัวข้อที่จะลบ


closeDB(); // ปิดการเชื่อมต่อกับฐานข้อมูล


}


}


// =============================================


// รับค่าตัวแปร แบบ get


$qno=$_GET["qno"];


// =============================


// แสดงข้อมูลคำถาม


connectDB(); // ติดต่อดาต้าเบส


// ======= update ผู้เข้าชม ======================


$sqlview="update tblquestion set qview=qview+1 where qno=".$qno;


mysql_query($sqlview); // ส่ง sqlcommand เพื่อ update qview


// =============================


$sqlquestion="select * from tblquestion where qno=".$qno;


if (!$resultq=mysql_query($sqlquestion)) {


exit("ไม่สามารถแสดงข้อมูลคำถามได้");


}


// นำข้อมูลคำถามเก็บเข้าตัวแปร array


$dbarrq=mysql_fetch_array($resultq);


$qdate=formatdate($dbarrq["qdate"]);


// =============================


?>


<html>


<head>


<title>Untitled Document</title>


<meta http-equiv="Content-Type" content="text/html; charset=tis-620">


<link rel="stylesheet" type="text/css" href="css/style.css">


<script language="javascript">


<!--


function reloadpage(){


window.opener.location.reload();


}


//-->


</script>


</head>


<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onunload="reloadpage();">


<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#333333">


<tr bgcolor="#999999">


<td colspan="2"><table width="100%" border="0" cellspacing="1" cellpadding="3">


<tr>


<td><strong>หัวเรื่อง : <?php echo $dbarrq["qtopic"];?><br>


เมื่อ : <?php echo $qdate;?></strong></td>


<td width="80">


<div align="right"><strong>อ่าน (<?php echo $dbarrq["qview"];?>)</strong></div></td>


</tr>


</table></td>


</tr>


<tr>


<td width="17%" rowspan="2" bgcolor="#EAEAEA" valign="top"><div align="center"><strong>คุณ


:<?php echo $dbarrq["qname"];?><br>


<a href="mailto:<?php echo $dbarrq["qemail"];?>">[email]</a></strong></div></td>


<td width="83%" bgcolor="#ffffff">


<?php echo $dbarrq["qdetail"];?>


<?php


// หากมีรูปภาพให้แสดง


if ($dbarrq["qpicture"]<>""){


echo "<table width=\"10\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#000000\" align=\"center\">


<tr><td><img src='".$Dirpath.$dbarrq["qpicture"]."'></td></tr></table>";


} // =========================


?>


</td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="center"><strong><a href="javascript:window.print();">พิมพ์</a> <a href="#answer">ตอบกลับ</a> <a href="javascript:window.close();">ปิดหน้าต่าง</a></strong></div></td>


</tr>


</table><br>


<table width="100%" border="0" cellspacing="1" cellpadding="2" class="borderdot">


<tr>


<td bgcolor="#CCCCCC">


<div align="center"><strong>ส่วนตอบคำถาม</strong></div></td>


</tr>


</table>


<?php


// ส่วนตอบคำถาม ===========================


$sqlans="select * from tblanswer where qno=".$qno." order by ano desc";


$resultans=mysql_query($sqlans);


$numrow=mysql_num_rows($resultans);


if ($numrow<>0) { // ตรวจสอบว่า มีข้อมูลหรือไม่


$count=$numrow;


while ($dbarrans=mysql_fetch_array($resultans)) { // วนข้อมูล คำตอบจากฐานข้อมูล


$adate=formatdate($dbarrans["adate"]);


?>


<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D6D6D6" >


<tr bgcolor="#999999">


<td colspan="2"><table width="100%" border="0" cellspacing="1" cellpadding="3">


<tr>


<td class="gradian_up"><strong>ความคิดเห็นที่ <?php echo $count;?><br>


เมื่อ : <?php echo $adate;?></strong></td>


</tr>


</table></td>


</tr>


<tr>


<td width="17%" rowspan="2" bgcolor="#EAEAEA" valign="top"><div align="center"><strong>คุณ


: <?php echo $dbarrans["aname"];?><br>


<a href="mailto:<?php echo $dbarrans["aemail"];?>">[email]</a><br>


<?php


if ($_SESSION["session_user"]<>"") {


echo "<a href=".$_SERVER["PHP_SELF"]."?delaid=".$dbarrans["ano"]."&qno=".$qno.">[ลบ]</a>";


}


?>


</strong></div></td>


<td width="83%" bgcolor="#ffffff">


<?php echo $dbarrans["adetail"];?>


<?php


// หากมีรูปภาพให้แสดง


if ($dbarrans["apicture"]<>""){


echo "<table width=\"10\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#000000\" align=\"center\">tr><td><img src='".$Dirpath.$dbarrans["apicture"]."'></td>


</tr></table>";


}// =========================


?>


</td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="center"><strong><a href="#answer">ตอบกลับ</a></strong></div></td>


</tr>


</table>


<br>


<?php


$count--;


} // จบการวนข้อมูล


} // จบ การตรวจสอบ if เลือกข้อมูลตอบคำถาม


// จบส่วนตอบคำถาม =============================


// ปิดการเชื่อมต่อกับฐานข้อมูล


closeDB();


?>


<br>


<form action="add_anssave.php" method="post" enctype="multipart/form-data">


<table width="500" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000000">


<tr bgcolor="#CCCCCC">


<td colspan="2"><strong>ตอบคำถาม</strong><a name="answer"></td>


</tr>


<tr>


<td width="158" bgcolor="#EAEAEA"><div align="right">ชื่อ :</div></td>


<td width="331" bgcolor="#EAEAEA"><input name="txtname" type="text" id="txtname"></td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="right">e-mail :</div></td>


<td bgcolor="#EAEAEA"><input name="txtemail" type="text" id="txtemail" size="30"></td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="right">ข้อความ :</div></td>


<td bgcolor="#EAEAEA"><textarea name="txtmessage" cols="40" rows="5" id="txtmessage"></textarea></td>


</tr>


<tr>


<td bgcolor="#EAEAEA"><div align="right">รูปภาพ :</div></td>


<td bgcolor="#EAEAEA"><input name="ufile" type="file" id="ufile"></td>


</tr>


<tr>


<td bgcolor="#EAEAEA">&nbsp;</td>


<td bgcolor="#EAEAEA">


<input type="hidden" name="qno" value="<?php echo $qno;?>">


<input name="cmdsubmit" type="submit" id="cmdsubmit" value="Submit">


<input name="cmdreset" type="reset" id="cmdreset" value="Reset"></td>


</tr>


</table>


</form>


</body>


</html>



ไฟล์ add_anssave.php


<?php


include "config.php";


// =========== รับค่าจากฟอร์ม ===============


$submit = $_POST["cmdsubmit"];


$qno=$_POST["qno"];


$name = $_POST["txtname"];


$email = $_POST["txtemail"];


$message = $_POST["txtmessage"];


$pimage = $HTTP_POST_FILES['ufile'];


// validate ข้อมูล



chktextbox($name,"ชื่อ");


chktextbox($message,"ข้อความ");


// ==================


if ($pimage["name"]<>"") {


// เพิ่มรูปภาพ


$myUpload=new upload; // ประกาศตัวแปร object เพื่อเรียกใช้งาน class upload


$myUpload->maxfile=200; // ค่าสูงสุดของ การ upload รูปภาพ


$myUpload->hostfile=$pimage; // ชื่อไฟล์


$myUpload->file_path=$Dirpath; // ที่อยู่ของ path


$imgupload = $myUpload->uploadfile(); // เรียกใช้ method สำหรับ upload


// =========================


}else{


$imgupload="";


}


// =====================================


connectDB(); // ติดต่อดาต้าเบส


if ($submit<>"") {


$sqlinsert="insert into tblanswer (qno,aname,adetail,adate,aemail,apicture) values \n". "('".$qno."','".$name."','".$message."','".$realdate."','".$email."','".$imgupload."')";


// เพิ่มข้อมูล


if (!$resultinsert=mysql_query($sqlinsert)) {


exit("ไม่สามารถเพิ่มข้อมูลได้");


}


// ====================



// ======= update คำตอบ ======================


$sqlreply="update tblquestion set qreply=qreply+1 where qno=".$qno;


mysql_query($sqlreply); // ส่ง sqlcommand เพื่อ update qview


// =============================


// ======= update date order ======================


$sqlreply="update tblquestion set date_order='".$realdate."' where qno=".$qno;


mysql_query($sqlreply); // ส่ง sqlcommand เพื่อ update qview


// =============================


closeDB(); // ปิดการติดต่อดาต้าเบส


?>


<html>


<head><title>ขอบคุณมากครับ</title>


<meta http-equiv="Content-Type" content="text/html; charset=windows-874">


<link rel="stylesheet" type="text/css" href="css/style.css">


<meta http-equiv="refresh" content="3;URL=view_question.php?qno=<?php echo $qno;?>">


</head>


<body class="gradian_up">


<table width="300" height="100" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">


<tr>


<td colspan="3" bgcolor="#EAEAEA"><table width="300" border="0" cellspacing="2" cellpadding="0">


<tr>


<td height="30"> <div align="center"><font color="#000000"><strong>เพิ่มคำตอบเรียบร้อย</strong></font></div></td>


</tr>


<tr>


<td height="30"> <div align="center"><font color="#000000"><strong>โปรดรอซัก


3 วินาที </strong></font></div></td>


</tr>


</table></td>


</tr>


</table>


</body>


</html>



ไฟล์ admin.php


<?php


session_start();


session_unregister("session_user");


echo $_SESSION["err"];


?><html>


<head>


<title>Untitled Document</title>


<meta http-equiv="Content-Type" content="text/html; charset=tis-620">


<link rel="stylesheet" type="text/css" href="css/style.css">


</head>



<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">


<?php


include "menu.php";


?>


<form action="chklogin.php" method="post">


<table width="250" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" align="center">


<tr bgcolor="#CCCCCC">


<td colspan="2">กรอกข้อมูล</td>


</tr>


<tr bgcolor="#E5E5E5">


<td width="25%">username</td>


<td width="75%"><input name="txtuser" type="text" id="txtuser"></td>


</tr>


<tr bgcolor="#E5E5E5">


<td>password</td>


<td><input name="txtpass" type="text" id="txtpass"></td>


</tr>


<tr bgcolor="#E5E5E5">


<td>&nbsp;</td>


<td><input type="submit" name="cmdsubmit" value="Submit">


<input type="reset" name="cmdreset" value="Reset"></td>


</tr>


</table>


</form>



</body>


</html>



ไฟล์ chklogin.php


<?php


session_start();


include "includes/admin_secure.php";


$submit=$_POST["cmdsubmit"];


if (isset($submit)) {


$txtuser=$_POST["txtuser"];


$txtpass=$_POST["txtpass"];


if ($txtuser==$admin_user and $txtpass==$admin_pass) {


session_unregister("err");


$_SESSION["session_user"] = $txtuser; // สร้างตัวแปร session ไว้สำหรับเก็บค่า txtuser


header("Location:question_list.php"); // redirect ไปยังหน้า page 3


}else{


$err = "<font color=\"#ff0000\">Login ไม่ ถูกต้อง กรุณา login ใหม่</font>";


$_SESSION["err"] = $err; // สร้างตัวแปร session err ไว้สำหรับ เก็บค่า err


header("Location:admin.php");


}


}


?>



ไฟล์ admin_logout.php


<?php


// ทำลายตัวแปร session ทั้งหมด


Session_Start();


Session_destroy();


?>


<head><title>ขอบคุณมากครับ</title>


<meta http-equiv="Content-Type" content="text/html; charset=windows-874">


<link rel="stylesheet" type="text/css" href="css/style.css">


<meta http-equiv="refresh" content="3;URL=index.php">


</head>


<body class="gradian_up">


<table width="300" height="100" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">


<tr>


<td colspan="3" bgcolor="#EAEAEA"><table width="300" border="0" cellspacing="2" cellpadding="0">


<tr>


<td height="30"> <div align="center"><font color="#000000"><strong>ออกจากระบบเรียบร้อย</strong></font></div></td>


</tr>


<tr>


<td height="30"> <div align="center"><font color="#000000"><strong>โปรดรอซัก


3 วินาที </strong></font></div></td>


</tr>


<tr>


<td height="30"> <div align="center"><font color="#000000"><strong>จะกลับไปหน้า


homepage</strong></font> </div></td>


</tr>


</table></td>


</tr>


</table>


</body>

163 ความคิดเห็น: