Else {
echo"<p class=userinp>Sorry no other detail data of this user</p>";
}
?>
4.2.3.7. Halaman Post Topic
Halaman ini berfungsi untuk melakukan post topic pertama dari forum.
Segmen program 4.21. Script untuk melakukan post topic pada forum adalah:
<?
if ( isset($_COOKIE["web_user"])) {
$statusr = "<span class=\"style4\">Logged in as <strong><a href=showprofile.php?user=". $_COOKIE["web_user"] .">".
$_COOKIE["web_user"] ."</a></strong></font><br>";
$statusr .= "<span class = \"style4\"><a href=\"profile.php\">edit profile</a></font>";
$usrnya = $_COOKIE["web_user"];
} else {
$statusr = "Not Logged in";
}
function ambiltanggal() {
$tmp = getdate();
$tglskr = $tmp["mday"];
$blnskr = $tmp["mon"];
$thnskr = $tmp["year"];
$jam = $tmp["hours"];
$mnt = $tmp["minutes"];
$dtk = $tmp["seconds"];
return
$thnskr."/".$blnskr."/".$tglskr."".$jam.":".$mnt.":".$dtk;
}
function settampilan(&$tmp) {
$tmp = str_replace("\r\n","<br>", $tmp);
$tmp = str_replace("[b]","<strong>",$tmp);
$tmp = str_replace("[/b]","</strong>",$tmp);
$tmp = str_replace("[i]","<i>",$tmp);
$tmp = str_replace("[/i]","</i>",$tmp);
$tmp = str_replace("[u]","<u>",$tmp);
$tmp = str_replace("[/u]","</u>",$tmp);
$tmp = str_replace(":angel:","<img src=image/smilies/angel.gif alt=:angel: width=17 height=19 class=nobdr />",$tmp);
$tmp = str_replace(":arg:","<img src=image/smilies/arg.png alt=:arg: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":D","<img src=image/smilies/big_smile.png alt=:D width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(";)","<img src=image/smilies/blink.png alt=;) width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":blush:","<img src=image/smilies/blush.gif alt=:blush: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":cool:","<img src=image/smilies/cool.png alt=:cool: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":kuat:", "<img src=image/smilies/kuat.gif alt=:kuat: width=15 height=15 class=nobdr />", $tmp);
$tmp = str_replace(":lol:", "<img src=image/smilies/lol.gif alt=:lol: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":lol2:","<img src=image/smilies/lol2.png alt=:lol2: width=15 height=15 class=nobdr />", $tmp);
$tmp = str_replace(":love:", "<img src=image/smilies/love.gif alt=:love: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":mabok:", "<img src=image/smilies/mabok.gif alt=:mabok: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":nyerah:", "<img
src=image/smilies/nyerah.gif alt=:nyerah: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":oh:", "<img src=image/smilies/oh.gif alt=:oh: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":rock:", "<img src=image/smilies/rock.gif alt=:rock: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":(", "<img src=image/smilies/sad.png alt=:(
width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":ss:", "<img src=image/smilies/sembah.gif alt=:ss: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":)", "<img src=image/smilies/smile.png alt=:) width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":gila:", "<img src=image/smilies/stress.gif alt=:gila: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":thumb:", "<img src=image/smilies/thumb.gif alt=:thumb: width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":p", "<img src=image/smilies/wek.png alt=:p width=15 height=15 class=nobdr />",$tmp);
$tmp = str_replace(":zzz:", "<img src=image/smilies/zzz.gif alt=:zzz: width=15 height=15 class=nobdr />",$tmp);
return $tmp;
}
if ($_POST["Submit"] == "Submit") {
$tpcpos = strpos($_POST["req_message"], "\r");
$tpc = substr($_POST["req_message"],0,$tpcpos);
$tpc = settampilan($tpc);
$tglskr = ambiltanggal();
$pesan = settampilan($_POST["req_message"]);
$ortu = $_POST["parent"];
if (isset($_POST["type"])){
$typems = $_POST["type"];
}
else {
$typems = "post";
}
$Q1 = "insert into
topic(id,parent,usrname,inforum,title,message,typemsg,tglpost)";
$Q1 .= "values
(null,$ortu,\"".$usrnya."\",0,\"".$tpc."\",\"".$pesan."\",\"$typem s\",\"".$tglskr."\")";
$res = mysql_query($Q1) or die("Error while writing files");
$idmsg = mysql_insert_id();
if ($ortu!=0) {
//proses update latest post kalo yang dimasukkan adalah post biasa bukan topic
$qtemp = "select idmsg,titlemsg from lastpost where norec = 2";
$tmp = mysql_query($qtemp);
$tmprow = mysql_fetch_array ($tmp);
$tmpidmsg = $tmprow["idmsg"];
$tmptit = $tmprow["titlemsg"];
$qpost = "update lastpost set idmsg=\"$tmpidmsg\", titlemsg=\"$tmptit\" where norec = 3";
$qtemp = "select idmsg,titlemsg from lastpost where norec = 1";
$tmp = mysql_query($qtemp);
$tmprow = mysql_fetch_array ($tmp);
$tmpidmsg = $tmprow["idmsg"];
$tmptit = $tmprow["titlemsg"];
$qpost = "update lastpost set idmsg=\"$tmpidmsg\", titlemsg=\"$tmptit\" where norec = 2";
$qpost = "update lastpost set idmsg=LAST_INSERT_ID(), titlemsg=\"$tpc\" where norec = 1";
$hslpost = mysql_query($qpost) or die("Error in writing record posting new");
} else {
//proses updating recent topic....
$qtemp = "select idmsg,titlemsg from recent where norec = 2";
$tmp = mysql_query($qtemp);
$tmprow = mysql_fetch_array ($tmp);
$tmpidmsg = $tmprow["idmsg"];
$tmptit = $tmprow["titlemsg"];
$qpost = "update recent set idmsg=\"$tmpidmsg\", titlemsg=\"$tmptit\" where norec = 3";
$hslpost = mysql_query($qpost) or die("Error in writing record");
$qtemp = "select idmsg,titlemsg from recent where norec = 1";
$tmp = mysql_query($qtemp);
$tmprow = mysql_fetch_array ($tmp);
$tmpidmsg = $tmprow["idmsg"];
$tmptit = $tmprow["titlemsg"];
$qpost = "update recent set idmsg=\"$tmpidmsg\", titlemsg=\"$tmptit\" where norec = 2";
$hslpost = mysql_query($qpost) or die("Error in writing record");
$qpost = "update recent set idmsg=LAST_INSERT_ID(), titlemsg=\"$tpc\" where norec = 1";
$hslpost = mysql_query($qpost) or die("Error in writing record");
}
header("location:viewtopic.php?msgid=$idmsg");
}
if ($_POST["Submit"] == "Preview") {
$simpan = $_POST["req_message"];
$pesan = settampilan($simpan);
header("location: tampil.php?tampil=".$pesan);
}
?>
<?
if (isset($_GET["idnya"])) {
//Menampilkan topic yang akan direply $idtpc = $_GET["idnya"];
$q1 = "select * from topic where id = $idtpc";
$hdltopic = mysql_query($q1);
$datatopic = mysql_fetch_array($hdltopic);
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\"
cellspacing=\"0\" class=tepi>
?>
<?
if ($_COOKIE["leveluser"]>0) {
echo'<input name="type" type="radio" value="Post" checked> Post <input name="type" type="radio" value="News">News';
}
if (isset($_GET["idnya"])) {
echo "<input type=\"hidden\" name=\"parent\"
value=\"$idtpc\">";
} else {
echo "<input type=\"hidden\" name=\"parent\" value=0>";
}
?>