DBHost = $DBHost; $this->DBUser = $DBUser; $this->DBPassword = $DBPassword; $this->DBName = $DBName; } function connect() { $this->connection = mysql_connect($this->DBHost, $this->DBUser, $this->DBPassword); mysql_select_db($this->DBName, $this->connection); } function returnConnect() { return $this->connection; } function close() { mysql_close($this->connection); } } ## Document Class class Document { var $id; var $writer; var $passwd; var $email; var $homepage; var $wdate; var $indent; var $subject; var $contents; var $category; var $count; function printData() { echo (" id = $this->id
writer = $this->writer
passwd = $this->passwd
email = $this->email
homepage = $this->homepage
subject = $this->subject
contents = $this->contents
category = $this->category
indent = $this->indent
wdate = $this->wdate
count = $this->count
"); } function read($id, $writer='', $passwd='', $email='', $homepage='', $subject='', $contents='', $category=0, $indent = 0, $wdate = 0, $count = 0) { $this->id = $id; $this->writer = $writer; $this->passwd = $passwd; $this->email = $email; $this->homepage = $homepage; $this->subject = $subject; $this->contents = $contents; $this->category = $category; $this->indent = $indent; $this->wdate = $wdate; $this->count = $count; } function write() { global $PHP_SELF; global $table; global $width; global $colorBlack; global $colorNotice; global $colorTitle; global $colorSub; global $colorAct; global $colorWhite; global $categorySize; global $categoryName; global $categoryImage; echo ("
\"µ¹¾Æ°¡±â\" \"¸ñ·ÏÀ¸·Î\"
"); echo ("

±Û¾´ÀÌ ¾ÏÈ£
EMAIL ±ÛÁ¾·ù
HOMEPAGE
Á¦¸ñ
³»¿ë

"); } function answer() { global $PHP_SELF; global $table; global $width; $colorBlack = "#3366CC"; $colorNotice = "#FF3300"; $colorTitle = "#6699CC"; $colorSub = "#99CCFF"; $colorAct = "#FFFFCC"; $colorWhite = "#FFFFFF"; global $categorySize; global $categoryName; global $categoryImage; $this->wdate = date("Y.m.d H:i:s", $this->wdate); $this->contents = str_replace("\n", "\n> ", $this->contents); $this->contents = ">\n>   $this->writer ´Ô²²¼­ $this->wdate ¿¡ ¾²½Å ±ÛÀÔ´Ï´Ù\n>\n> " . $this->contents; $this->contents .= "\n>\n\n"; $this->subject = "RE: " . $this->subject; $this->indent++; echo ("
\"µ¹¾Æ°¡±â\" \"¸ñ·ÏÀ¸·Î\"
"); echo ("
id\"> indent\">

±Û¾´ÀÌ ¾ÏÈ£
EMAIL ±ÛÁ¾·ù
HOMEPAGE
Á¦¸ñ subject\">
³»¿ë

"); } function authen() { global $PHP_SELF; global $table; global $width; global $colorBlack; global $colorNotice; global $colorTitle; global $colorSub; global $colorAct; global $colorWhite; echo ("
±ÛÀ» »èÁ¦Çϱâ À§Çؼ­´Â ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ¼Å¾ß ÇÕ´Ï´Ù.
ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä.
"); } function store() { global $PHP_SELF; global $DBHost; global $DBUser; global $DBPassword; global $DBName; global $table; $this->writer = trim($this->writer); //$this->writer = addslashes($this->writer); $this->subject = trim($this->subject); //$this->subject = addslashes($this->subject); $this->contents = trim($this->contents); //$this->contents = addslashes($this->contents); $this->homepage = trim($this->homepage); $this->email = trim($this->email); $this->homepage = str_replace("http://", "", $this->homepage); $this->wdate = time(); $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); $result = mysql_query("select * from $table order by id desc limit 1", $connection); $total = mysql_num_rows($result); if ($total) { $this->id = mysql_result($result, 0, "id"); $this->id++; } else { $this->id = 1; } mysql_query("INSERT INTO $table(id, passwd, writer, email, homepage, wdate, indent, subject, contents, category, count) values($this->id, '$this->passwd', '$this->writer', '$this->email', '$this->homepage', $this->wdate, $this->indent, '$this->subject', '$this->contents', $this->category, $this->count)", $connection); $db->close(); echo (" "); } function storeAnswer() { global $table; global $DBHost; global $DBUser; global $DBPassword; global $DBName; $this->writer = trim($this->writer); //$this->writer = addslashes($this->writer); $this->subject = trim($this->subject); //$this->subject = addslashes($this->subject); $this->contents = trim($this->contents); //$this->contents = addslashes($this->contents); $this->homepage = trim($this->homepage); $this->email = trim($this->email); $this->homepage = str_replace("http://", "", $this->homepage); $this->wdate = time(); $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); mysql_query("update $table set id = id + 1 where id >= $this->id", $connection); mysql_query("insert into $table(id, passwd, writer, email, homepage, wdate, indent, subject, contents, category, count) values($this->id, '$this->passwd', '$this->writer', '$this->email', '$this->homepage', $this->wdate, $this->indent, '$this->subject', '$this->contents', $this->category, $this->count)", $connection); $db->close(); } function load() { global $DBHost; global $DBUser; global $DBPassword; global $DBName; global $table; $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); $result = mysql_query("select * from $table where id = $this->id limit 1", $connection); $this->writer = mysql_result($result, 0, "writer"); $this->passwd = mysql_result($result, 0, "passwd"); $this->email = mysql_result($result, 0, "email"); $this->homepage = mysql_result($result, 0, "homepage"); $this->subject = mysql_result($result, 0, "subject"); $this->contents = mysql_result($result, 0, "contents"); $this->category = mysql_result($result, 0, "category"); $this->wdate = mysql_result($result, 0, "wdate"); $this->indent = mysql_result($result, 0, "indent"); $this->count = mysql_result($result, 0, "count"); $db->close(); } function plusCount() { global $table; global $DBHost; global $DBUser; global $DBPassword; global $DBName; $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); mysql_query("UPDATE $table SET COUNT = COUNT + 1 WHERE ID = $this->id", $connection); $this->count++; $db->close(); } function loadList() { global $DBHost; global $DBUser; global $DBPassword; global $DBName; global $table; $result = mysql_query("select * from $table where id = $this->id limit 1"); $this->writer = mysql_result($result, 0, "writer"); $this->email = mysql_result($result, 0, "email"); $this->subject = mysql_result($result, 0, "subject"); $this->category = mysql_result($result, 0, "category"); $this->indent = mysql_result($result, 0, "indent"); $this->wdate = mysql_result($result, 0, "wdate"); $this->count = mysql_result($result, 0, "count"); } function printContents() { global $PHP_SELF; global $DBHost; global $DBUser; global $DBPassword; global $DBName; global $table; global $width; global $colorBlack; global $colorNotice; global $colorTitle; global $colorSub; global $colorAct; global $colorWhite; global $categoryName; global $categoryImage; $category = $this->category; $this->writer = stripslashes($this->writer); $this->subject = stripslashes($this->subject); $this->contents = stripslashes($this->contents); $this->subject = htmlspecialchars($this->subject); $this->wdate = date("Y.m.d H:i:s", $this->wdate); $this->contents = nl2br($this->contents); if ($this->email) $this->writer = "email\">$this->writer"; if ($this->homepage) $this->homepage = "homepage\" TARGET=\"_new\">\"ȨÆäÀÌÁö\""; echo ("
$categoryName[$category] $this->subject id\">\"¼öÁ¤\" id\">\"»èÁ¦\"
No.$this->id ±Û¾´ÀÌ: $this->writer $this->homepage ( $this->wdate ) Cnt: $this->count

$this->contents
"); $width2 = $width / 4; $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); $result = mysql_query("SELECT id FROM $table", $connection); $total = mysql_num_rows($result); $db->close(); $nextId = $this->id + 1; $prevId = $this->id - 1; if ($nextId <= $total) $nextIcon = "\"À­±Û\""; else $nextIcon = "\"ÀÌ"; if ($prevId > 0) $prevIcon = "\"¾Æ·§±Û\""; else $prevIcon = "\"ÀÌ"; echo ("
\"¸ñ·Ïº¸±â\" id\">\"´äÀå $nextIcon $prevIcon

"); } function printList() { global $PHP_SELF; global $colorBlack; global $colorNotice; global $colorTitle; global $colorSub; global $colorAct; global $colorWhite; global $categoryName; global $categoryImage; global $subjectSize; global $hot; global $maxIndent; global $page; $this->writer = stripslashes($this->writer); $this->subject = stripslashes($this->subject); $this->subject = htmlspecialchars($this->subject); $this->wdate = date("Y.m.d", $this->wdate); if (strlen($this->subject) > $subjectSize) { $this->subject = substr($this->subject, 0, $subjectSize); $this->subject .= "..."; } $today = date("Y.m.d", time()); if ($this->email) { $this->writer = "email\">$this->writer"; } if ($this->indent) { for ($j = 0; $j < $this->indent && $j < $maxIndent; $j++) { $indentImage .= "   "; } $indentImage .= ""; } $newImage = ($this->wdate == $today) ? "" : ""; $hotImage = ($this->count >= $hot) ? "" : ""; $bgColor = ($this->indent) ? $color4 : $color5; $category = $this->category; // php¿¡¼­ ¹è¿­ À妽º¿¡´Â ¸â¹ö º¯¼ö°¡ µé¾î°¥ ¼ö ¾ø´Ù. echo (" $this->id \"$categoryName[$category]\" $this->writer $indentImageid&page=$page\"> $this->subject $newImage $hotImage $this->wdate $this->count "); } function printModifyForm() { global $PHP_SELF; global $table; global $width; global $colorBlack; global $colorNotice; global $colorTitle; global $colorSub; global $colorAct; global $colorWhite; global $categorySize; global $categoryName; global $categoryImage; $this->writer = stripslashes($this->writer); $this->subject = stripslashes($this->subject); $this->contents = stripslashes($this->contents); $this->subject = htmlspecialchars($this->subject); echo ("
\"µ¹¾Æ°¡±â\" \"¸ñ·ÏÀ¸·Î\"
id\">

±Û¾´ÀÌ writer\"> ¾ÏÈ£
EMAIL email\"> ±ÛÁ¾·ù
HOMEPAGE homepage\">
Á¦¸ñ subject\">
³»¿ë

"); } function isWriter($passwd) { if ($passwd == $this->passwd) return TRUE; else return FALSE; } function doHaveAnswer() { global $table; global $DBHost; global $DBUser; global $DBPassword; global $DBName; if ($this->id < 2) return FALSE; $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); $id = $this->id - 1; $result = mysql_query("SELECT * FROM $table WHERE id = $id ORDER BY id DESC LIMIT 1", $connection); $indent = mysql_result($result, 0, "indent"); $db->close(); if ($indent > $this->indent) return TRUE; else return FALSE; } function restore() { global $PHP_SELF; global $table; global $DBHost; global $DBUser; global $DBPassword; global $DBName; $this->writer = trim($this->writer); //$this->writer = addslashes($this->writer); $this->subject = trim($this->subject); //$this->subject = addslashes($this->subject); $this->contents = trim($this->contents); //$this->contents = addslashes($this->contents); $this->homepage = trim($this->homepage); $this->email = trim($this->email); $this->homepage = str_replace("http://", "", $this->homepage); $this->wdate = time(); $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); mysql_query("update $table set writer = '$this->writer', email = '$this->email', homepage = '$this->homepage', wdate = '$this->wdate', subject = '$this->subject', contents = '$this->contents', category = '$this->category' where id = '$this->id'", $connection); $db->close(); echo (" "); } function delete() { global $table; global $DBHost; global $DBUser; global $DBPassword; global $DBName; $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); mysql_query("DELETE FROM $table WHERE id = $this->id", $connection); mysql_query("UPDATE $table SET id = id - 1 WHERE id > $this->id", $connection); $db->close(); } } ## BBS Class class BBS { function printPage($page) { global $PHP_SELF; global $DBHost; global $DBUser; global $DBPassword; global $DBName; global $table; global $height; global $width; global $pages; global $colorBlack; global $colorNotice; global $colorTitle; global $colorSub; global $colorAct; global $colorWhite; global $field; global $search; $document = new Document; if ($field) { $sql = "SELECT id FROM $table WHERE $field like '%$search%' ORDER BY id DESC"; } else { if ($search) { $sql = "SELECT id FROM $table WHERE writer like '%$search%' OR subject like '%$search%' OR contents like '%$search%' ORDER BY id DESC"; } else { $sql = "SELECT id FROM $table ORDER BY id DESC"; } } $db = new DB($DBHost, $DBUser, $DBPassword, $DBName); $db->connect(); $connection = $db->returnConnect(); $result = mysql_query($sql, $connection); $total = mysql_num_rows($result); if ($total == 0) $page = 1; $totalPages = $total / $height; $totalPages += ($total % $height) ? 1 : 0; $totalPages = (int)$totalPages; echo ("
ÃÑ $total °³ÀÇ ±ÛÀÌ °Ë»öµÇ¾ú½À´Ï´Ù. (page $page/$totalPages)
"); echo (" "); for ($i = ($page - 1) * $height; ($i < ($page * $height)) && ($i < $total); $i++) { $id = mysql_result($result, $i, "ID"); $document->read($id); $document->loadList(); $document->printList(); } echo ("
¹øÈ£ Á¾·ù ±Û¾´ÀÌ Á¦¸ñ ³¯Â¥ Á¶È¸¼ö
"); $db->close(); $begin = ($page - $pages); $begin = ($begin > 1) ? $begin : 1; $end = ($page + $pages); $end = ($end > $totalPages) ? $totalPages : $end; echo ("
"); echo ("Pages : "); if ($begin != 1) echo ("[1] ... "); for ($i = $begin; $i <= $end; $i++) { if ($i == $page) echo ("[$i]"); else echo ("[$i]"); } if ($end != $totalPages) echo (" ... [$totalPages]"); echo("
"); $width2 = $width / 3; echo ("
"); $width2 = $width / 4; $prevPage = $page - 1; $nextPage = $page + 1; if ($prevPage > 0) $prevIcon = "
\"ÀÌÀü"; else $prevIcon = "\"ÀÌ"; if ($nextPage <= $totalPages) $nextIcon = "\"´ÙÀ½"; else $nextIcon = "\"ÀÌ"; echo ("
\"¸Ç \"±Û $prevIcon $nextIcon
"); } function goPrepage($msg) { echo (" "); } function golistpage() { global $PHP_SELF; global $table; echo (" "); } } ## °Ë»ö¸ðµå¸¦ À§ÇØ Äí۸¦ ¼³Á¤ switch($switch) { case 1 : // ÄíŰ ¼³Á¤ setcookie("cookfield", $field); setcookie("cooksearch", $search); break; case -1 : // ÄíŰ ÇØÁ¦ setcookie("cookfield", ''); setcookie("cooksearch", ''); $field = ''; $search = ''; break; default : // ÄíŰ À¯Áö $field = $cookfield; $search = $cooksearch; break; } ?> Square BBS ver 0.2.3 printPage($page); exit(); } if ($mode == "write") { $document->write(); exit(); } if ($mode == "store") { $document->read($id, $writer, $passwd, $email, $homepage, $subject, $contents, $category); $document->store(); exit(); } if ($mode == "contents") { $document->read($id); $document->load(); $document->plusCount(); $document->printContents(); $page = ($page) ? $page : 1; $bbs->printPage($page); exit(); } if ($mode == "modify") { $document->read($id); $document->load(); $document->printModifyForm(); exit(); } if ($mode == "restore") { $document->read($id); $document->load(); if ($document->isWriter($passwd)) { $document->read($id, $writer, $passwd, $email, $homepage, $subject, $contents, $category); $document->restore(); } else { $bbs->goPrepage("¾ÏÈ£°¡ Ʋ¸³´Ï´Ù. ´Ù½Ã ÀÔ·ÂÇØ ÁֽʽÿÀ"); } exit(); } if ($mode == "answer") { $document->read($id); $document->load(); $document->answer(); exit(); } if ($mode == "storeAnswer") { $document->read($id, $writer, $passwd, $email, $homepage, $subject, $contents, $category, $indent); $document->storeAnswer(); $bbs->goListPage(); exit(); } if ($mode == "authen") { $document->read($id); $document->authen(); } if ($mode == "delete") { $document->read($id); $document->load(); if (!$document->isWriter($passwd)) { $bbs->goPrepage("¾ÏÈ£°¡ Ʋ¸³´Ï´Ù. ´Ù½Ã ÀÔ·ÂÇØ ÁֽʽÿÀ"); } else if ($document->doHaveAnswer()) { $bbs->goPrepage("°ü·Ã±ÛÀÌ ÀÖÀ¸¸é, Áö¿ï ¼ö ¾ø½À´Ï´Ù. °ü·Ã±ÛÀ» ¸ÕÀú »èÁ¦ÇØ ÁÖ¼¼¿ä"); } else { $document->delete(); $bbs->goListPage(); } } ?>