Web Programming >> PHP Programming
|
[목차] |
제19장 대화방 만들기(MySQL)
3. 대화방 수정(폰트크기, 색깔, 진하게, 기울림)
1. 대화창 화면 바꾸기
위의 그림에서 위부분에 프레임이 하나 추가 되었다. 그리고 이번에 추가할 기능은 대화내용을 진하게, 기울림, 색깔, 크기등을 수정할 수 있게 수정하고자 한다.
2. 대화창 수정하기 파일명 : room_login.html <? if(!$user_id || !$user_name) { echo "<SCRIPT>self.close();</SCRIPT>"; exit; }
echo (" <frameset rows='50,*,60' frameborder='NO' border='0' framespacing='0'> <frame name='room_top' scrolling='NO' noresize src='room_top.html?room_uid=$room_uid'> <frameset cols='*,200' frameborder='NO' border='0' framespacing='0'> <frame name='msg_list' src='say.html?room_uid=$room_uid'> <frame name='chat_list' src='chat_list.html?room_uid=$room_uid' scrolling='NO' noresize > </frameset> <frame name='msg_input' scrolling='NO' noresize src='chat.html?room_uid=$room_uid'> </frameset> <noframes><body bgcolor='#FFFFFF'> "); ?>
파일명 : room_top.html <? if(!$user_id || !$user_name) { echo "<SCRIPT>window.close();</SCRIPT>"; exit; } ?>
<body bgcolor="#EEEEEE"> <table width=600 align=left><tr><td align="left"><font size=3><b>LeeLAB 대화방</td><td align="right" height=45 valign="bottom">
</td></tr></table> </body></html>
3. 대화입력창의 폰트크기, 색깔, 진하게, 기울림 기능 추가하기 파일명 : chat.html <? if(!$user_id || !$user_name) { echo "<SCRIPT>self.close();</SCRIPT>"; exit; }
########## 데이터베이스 서버에 연결한다. ########## $dbconn = mysql_connect("localhost","php","php99") or die("DB서버 연결에 실패하였습니다!");
########## 작업 데이터베이스로 sample을 선택한다. ########## $status = mysql_select_db("sample",$dbconn); if(!$status) { $errNO = mysql_errno($dbconn); $errMSG = mysql_error($dbconn);
echo("서버의 sample 데이터베이스연결에 실패하였습니다!<br>"); echo("에러코드 $errNO : $errMSG<br>"); exit; }
//message 디랙토리 절대경로 $message_dir = "./data";
//대화방 퇴장시 연결될 페이지 URL $redirect_url = "./room_list.html";
if(!$fontcolor) $fontcolor = "black"; if(!$fontsize) $fontsize = "3"; if(!$bold) $bold = "N"; if(!$italic) $italic = "N";
// 서브루틴 function error() { header("Content-type: text/html"); return print"<body bgcolor=ffffff><h1>에러임돠 열심히 해보세요</body></html>"; exit;
}
function write($username, $room_uid, $message, $tomsg, $ear,$message_dir){ global $fontsize, $fontcolor, $bold, $italic,$user_name;
$lines = file("${message_dir}/${room_uid}.html");
if($tomsg == "") { $tomsg = all; }
$total = count($lines); $start = $total - 20; if($start < 0) $start = 0; $end = $total;
if($bold == "Y") $message = "<b>$message</b>"; if($italic == "Y") $message = "<i>$message</i>"; $message = "<font size='${fontsize}' color='${fontcolor}'><b>$user_name</b> : ${message}</font>";
$newmessage = "$tomsg|$username|$message<br>";
$fp=fopen ("${message_dir}/${room_uid}.html", "w");
for ($i = $start; $i < $end; $i++) { fwrite($fp, "$lines[$i]"); }
fwrite($fp, "$newmessage\n"); fclose($fp);
}
// if($room == "") { error; }
// LOG OUT if (!strcmp($logoff ,"ok")) { $date = date( "l dS of F Y h:i:s A" ); $message = "$message($date)"; write($user_name, $ucolor, $room_uid, $message, $tomsg, $ear,$message_dir);
// $query="delete from room_login where chat_id='$user_id' "; $result= mysql_query($query, $dbconn);
// 대화방에 입실한 회원이 없으면 대화방을 삭제하는 부분 $result= mysql_query("select * from room_login where room_uid='$room_uid' ", $dbconn); $Total = mysql_num_rows($result); if(!$Total) { $query="delete from room where uid='$room_uid' "; $result= mysql_query($query, $dbconn);
unlink("${message_dir}/${room_uid}.html");
}
print "<META HTTP-EQUIV=Refresh CONTENT='0; url=$redirect_url'>"; exit; }
header("Content-type: text/html"); print" <HTML> <HEAD> <TITLE>대화방</TITLE> <style> a:link, a:visited, a:active { text-decoration:none; color:#003366; } A:hover{color:blue;} body, tr, td { font-size : 10pt;} </style>
<SCRIPT LANGUAGE='JavaScript'> <!-- function FocusOn() { document.form_submit.message.focus(); return; }
function chat() { form_submit.submit();
}
//--> </SCRIPT>
</HEAD> <BODY bgcolor=#FFFFFF text=#000000 topmargin=5 onLoad=FocusOn()> <table cellspacing=0 cellpadding=1 border=0> <tr> <form name='form_submit' action='chat.html' method='post'> <input name=room_uid type=hidden value='$room_uid'> <td align=\"left\"> <input type=text name=message value='' size=45> <a href='javascript:form1.submit()'>Logout</a> </td> </tr> <tr> <td align=\"left\"> <INPUT TYPE=\"checkbox\" NAME=\"bold\" value='Y'"; if(!strcmp($bold,"Y")) echo(" checked"); print ">진하게 <INPUT TYPE=\"checkbox\" NAME=\"italic\" value='Y'"; if(!strcmp($italic,"Y")) echo(" checked"); print ">기울림 <select name=\"fontcolor\"> <option value=\"black\" "; if(!strcmp($fontcolor,"black")) echo(" selected"); print ">black</option> <option value=\"#004080\" "; if(!strcmp($fontcolor,"#004080")) echo(" selected"); print ">dark blue</option> <option value=\"#3232CD\""; if(!strcmp($fontcolor,"#3232CD")) echo(" selected"); print ">medium blue</option> <option value=\"purple\""; if(!strcmp($fontcolor,"purple")) echo(" selected"); print ">purple</option> <option value=\"green\""; if(!strcmp($fontcolor,"green")) echo(" selected"); print ">green</option> <option value=\"orange\""; if(!strcmp($fontcolor,"orange")) echo(" selected"); print ">orange</option> <option value=\"brown\""; if(!strcmp($fontcolor,"brown")) echo(" selected"); print ">brown</option> <option value=\"gray\""; if(!strcmp($fontcolor,"gray")) echo(" selected"); print ">gray</option> <option value=\"#007FFF\""; if(!strcmp($fontcolor,"#007FFF")) echo(" selected"); print ">slate blue</option> <option value=\"orchid\""; if(!strcmp($fontcolor,"orchid")) echo(" selected"); print ">orchid</option> <option value=\"fuchsia\""; if(!strcmp($fontcolor,"fuchsia")) echo(" selected"); print ">magenta</option> <option value=\"#FF7F00\""; if(!strcmp($fontcolor,"#FF7F00")) echo(" selected"); print ">coral</option> <option value=\"#9F5F9F\""; if(!strcmp($fontcolor,"#9F5F9F")) echo(" selected"); print ">blue violet</option> <option value=\"violet\""; if(!strcmp($fontcolor,"violet")) echo(" selected"); print ">violet</option> <option value=\"#FF6EC7\""; if(!strcmp($fontcolor,"#FF6EC7")) echo(" selected"); print ">neon pink</option> <option value=\"#D98719\""; if(!strcmp($fontcolor,"#D98719")) echo(" selected"); print ">cooper</option> <option value=\"#9932CD\""; if(!strcmp($fontcolor,"#9932CD")) echo(" selected"); print ">dark orchid</option> <option value=\"#7093DB\""; if(!strcmp($fontcolor,"#7093DB")) echo(" selected"); print ">dark turquoise</option> <option value=\"#8E236B\""; if(!strcmp($fontcolor,"#8E236B")) echo(" selected"); print ">maroon</option> <option value=\"mediumpurple\""; if(!strcmp($fontcolor,"mediumpurple")) echo(" selected"); print ">medium orchid</option> <option value=\"#4D4DFF\""; if(!strcmp($fontcolor,"#4D4DFF")) echo(" selected"); print ">neon blue</option> <option value=\"#EAADEA\""; if(!strcmp($fontcolor,"#EAADEA")) echo(" selected"); print ">plum</option> <option value=\"#8C1717\""; if(!strcmp($fontcolor,"#8C1717")) echo(" selected"); print ">scarlet</option> <option value=\"#238E68\""; if(!strcmp($fontcolor,"#238E68")) echo(" selected"); print ">sea green</option> <option value=\"#3299CC\""; if(!strcmp($fontcolor,"#3299CC")) echo(" selected"); print ">sky blue</option> <option value=\"#38B0DE\""; if(!strcmp($fontcolor,"#38B0DE")) echo(" selected"); print ">summer sky</option> <option value=\"#CC3229\""; if(!strcmp($fontcolor,"#CC3229")) echo(" selected"); print ">violet red</option> <option value=\"#32CD99\""; if(!strcmp($fontcolor,"#32CD99")) echo(" selected"); print ">aquamarine</option> <option value=\"cadetblue\""; if(!strcmp($fontcolor,"cadetblue")) echo(" selected"); print ">cadetblue</option> <option value=\"chocolate\""; if(!strcmp($fontcolor,"chocolate")) echo(" selected"); print ">chocolate</option> <option value=\"darkgoldenrod\""; if(!strcmp($fontcolor,"darkgoldenrod")) echo(" selected"); print ">darkgoldenrod</option> <option value=\"darkkhaki\""; if(!strcmp($fontcolor,"darkkhaki")) echo(" selected"); print ">darkkhaki</option> <option value=\"darkred\""; if(!strcmp($fontcolor,"darkred")) echo(" selected"); print ">darkred</option> <option value=\"darksalmon\""; if(!strcmp($fontcolor,"darksalmon")) echo(" selected"); print ">darksalmon</option> <option value=\"darkslateblue\""; if(!strcmp($fontcolor,"darkslateblue")) echo(" selected"); print ">darkslateblue</option> <option value=\"lightslategray\""; if(!strcmp($fontcolor,"lightslategray")) echo(" selected"); print ">lightslategray</option> <option value=\"salmon\""; if(!strcmp($fontcolor,"salmon")) echo(" selected"); print ">salmon</option> <option value=\"silver\""; if(!strcmp($fontcolor,"silver")) echo(" selected"); print ">silver</option> <option value=\"tan\""; if(!strcmp($fontcolor,"tan")) echo(" selected"); print ">tan</option> <option value=\"tomato\""; if(!strcmp($fontcolor,"tomato")) echo(" selected"); print ">tomato</option> <option value=\"turquoise\""; if(!strcmp($fontcolor,"turquoise")) echo(" selected"); print ">turquoise</option> <option value=\"#FF9696\""; if(!strcmp($fontcolor,"#FF9696")) echo(" selected"); print ">난이옷</option> <option value=\"#A537DC\""; if(!strcmp($fontcolor,"#A537DC")) echo(" selected"); print ">보라색</option></select> <select name=\"fontsize\"> <option value=\"2\""; if(!strcmp($fontsize,"2")) echo(" selected"); print ">작게</option> <option value=\"3\""; if(!strcmp($fontsize,"3")) echo(" selected"); print ">보통</option> <option value=\"4\""; if(!strcmp($fontsize,"4")) echo(" selected"); print ">크게</option> <option value=\"5\""; if(!strcmp($fontsize,"5")) echo(" selected"); print ">아주크게</option> </select> </td> </tr> </form> <form name= form1 action='chat.html' method='post' target=_top> <input name=room_uid type=hidden value='$room_uid'> <input name='logoff' type=hidden value='ok'> <input type=hidden name=message value='님이 퇴장하셨습니다!'> </form> </table> ";
if ($message) { write($user_id, $room_uid, $message, $tomsg, $ear,$message_dir); echo(" <SCRIPT LANGUAGE='JavaScript'> <!-- top.msg_list.document.location.href='say.html?room_uid=$room_uid&message=$message' //--> </SCRIPT>"); } exit;
?> </body></html>
|
[목차] |