<?php
session_start();
include('wap_common.php');
if(!isset($_SESSION['un']) || $_SESSION['un'] = ""){
wapheader();
start_card("id","Error");
print("<p>You must be logged in to post</p>");
print("<p>Hit the back button on your browser or login <a href=\"wap_login.php\">HERE</a></p>");
end_card();
print("</wml>");
}else{
$forum = $HTTP_POST_VARS['forum'];
$topic = $HTTP_POST_VARS['topic'];
$poster = $_SESSION['id'];
$op = $HTTP_POST_VARS['op'];
switch($op){
case "reply":
wapheader();
start_card("id","Post Reply");
print("<p>");
print("Subject: (Optional)<br/>");
print("<input type=\"text\" name=\"subject\" /><br/>");
print("Text: <br/>");
print("<input type=\"text\" name=\"text\" size=\"256\"/><br/>");
print("</p>");
print("<do type=\"accept\" label=\"Submit Reply\">");
print("<go method=\"post\" href=\"wap_post.php\">");
print("<postfield name=\"subject\" value=\"$(subject)\"/>");
print("<postfield name=\"text\" value=\"$(text)\"/>");
print("<postfield name=\"op\" value=\"submitreply\"/>");
//print("<postfield name=\"login\" value=\"login\"/>");
print("<postfield name=\"forum\" value=\"$forum\"/>");
print("<postfield name=\"topic\" value=\"$topic\"/>");
print("<postfield name=\"uid\" value=\"$poster\"/>");
print("</go>");
print("</do>");
break;
case "new":
wapheader();
start_card("id","Post New Topic");
print("<p>");
print("Subject: (Required)<br/>");
print("<input type=\"text\" name=\"subject\" /><br/>");
print("Text: <br/>");
print("<input type=\"text\" name=\"text\" size=\"256\"/><br/>");
print("</p>");
print("<do type=\"accept\" label=\"Submit New Post\">");
print("<go method=\"post\" href=\"wap_post.php\">");
print("<postfield name=\"subject\" value=\"$(subject)\"/>");
print("<postfield name=\"text\" value=\"$(text)\"/>");
print("<postfield name=\"op\" value=\"submitnew\"/>");
//print("<postfield name=\"login\" value=\"login\"/>");
print("<postfield name=\"forum\" value=\"$forum\"/>");
//print("<postfield name=\"topic\" value=\"$topic\"/>");
print("<postfield name=\"uid\" value=\"$poster\"/>");
print("</go>");
print("</do>");
break;
case "submitreply":
$error="";
$subject=$HTTP_POST_VARS['subject'];
$posttext=$HTTP_POST_VARS['text'];
$forum=$HTTP_POST_VARS['forum'];
$topic=$HTTP_POST_VARS['topic'];
$poster=$HTTP_POST_VARS['uid'];
$time=time();
$ip = getenv ("REMOTE_ADDR");
$ip=encode_ip($ip);
$sql="INSERT INTO " . $TABLE_PREFIX . "posts ( topic_id, forum_id, poster_id, post_time, poster_ip, enable_sig, enable_smilies, enable_html, enable_bbcode, post_username) VALUES ($topic, $forum, $poster, $time, '$ip', 1,1,0,0,'')";
if(!$db->sql_query($sql)){
$error.="r0";
$ERR = $db->sql_error();
}
$postid = $db->sql_nextid();
$bbcode_uid = make_bbcode_uid();
$sql="INSERT INTO " . $TABLE_PREFIX . "posts_text (post_id, post_subject, post_text, bbcode_uid, enable_bbcode) VALUES ($postid,'$subject','$posttext','$bbcode_uid',0)";
if(!$db->sql_query($sql)){
$error.="r2";
$ERR = $db->sql_error();
}
$sql="SELECT topic_replies FROM ". $TABLE_PREFIX . "topics WHERE topic_id = '$topic'";
$result=$db->sql_query($sql);
if(!$result) {
$error.="r3";
$ERR = $db->sql_error();
}
$row=$db->sql_fetchrow($result);
$numreplies=++$row['topic_replies'];
$sql="UPDATE " . $TABLE_PREFIX . "topics SET topic_replies = $numreplies, topic_last_post_id = $postid WHERE topic_id = $topic";
if(!$db->sql_query($sql)) {
$error.="r4";
$ERR = $db->sql_error();
}
$sql="UPDATE " . $TABLE_PREFIX . "users SET user_posts = user_posts + 1 WHERE user_id = $poster";
if(!$db->sql_query($sql)) {
$error.="r5";
$ERR = $db->sql_error();
}
$sql="UPDATE " . $TABLE_PREFIX ."forums SET forum_posts = forum_posts + 1 WHERE forum_id = $forum";
if(!$db->sql_query($sql)){
$error.="r6";
$ERR = $db->sql_error();
}
$sql="UPDATE " . $TABLE_PREFIX ."forums SET forum_last_post_id = $postid WHERE forum_id = $forum";
if(!$db->sql_query($sql)){
$error.="r7";
$ERR = $db->sql_error();
}
wapheader();
start_card("id","Posted");
//print("<p>Post ID $postid Forum $forum Topic $topic Poster $poster Text $posttext subject $subject BBCodeUid $bbcode_uid IP $ip Time $time</p>");
print("<p>Reply Posted</p>");
print("<p><a href=\"wap_index.php\">Main Menu</a></p>");
if($DEBUG) print( $ERR['message'] . " " . $ERR['code']);
break;
case "submitnew":
$error="";
$subject=$HTTP_POST_VARS['subject'];
$posttext=$HTTP_POST_VARS['text'];
$forum=$HTTP_POST_VARS['forum'];
//$topic=$HTTP_POST_VARS['topic'];
$poster=$HTTP_POST_VARS['uid'];
$time=time();
$ip = getenv ("REMOTE_ADDR");
$ip=encode_ip($ip);
$sql="INSERT INTO " . $TABLE_PREFIX ."topics ( forum_id, topic_title, topic_poster, topic_time) VALUES ($forum, '$subject', $poster, $time)";
if(!$db->sql_query($sql)){
$error.="n0";
$ERR = $db->sql_error();
}
$topic=$db->sql_nextid();
$sql="INSERT INTO " . $TABLE_PREFIX ."posts (topic_id, forum_id, poster_id, post_time, poster_ip) VALUES ($topic, $forum, $poster, $time, '$ip')";
if(!$db->sql_query($sql)){
$error.="n1";
$ERR = $db->sql_error();
}
$post=$db->sql_nextid();
$bbcode_uid = make_bbcode_uid();
$sql="INSERT INTO " . $TABLE_PREFIX . "posts_text (post_id, post_subject, post_text, bbcode_uid, enable_bbcode) VALUES ($post,'$subject','$posttext','$bbcode_uid',0)";
if(!$db->sql_query($sql)){
$error.="n2";
$ERR = $db->sql_error();
}
$sql="UPDATE " . $TABLE_PREFIX . "topics SET topic_first_post_id = $post WHERE topic_id = $topic";
if(!$db->sql_query($sql)){
$error.="n3";
$ERR = $db->sql_error();
}
$sql="UPDATE " . $TABLE_PREFIX ."users SET user_posts = user_posts + 1 WHERE user_id = $poster";
if(!$db->sql_query($sql)){
$error.="n4";
$ERR = $db->sql_error();
}
$sql="UPDATE " . $TABLE_PREFIX ."forums SET forum_posts = forum_posts + 1, forum_topics = forum_topics + 1 WHERE forum_id = $forum";
if(!$db->sql_query($sql)){
$error.="n5";
$ERR = $db->sql_error();
}
$sql="UPDATE " . $TABLE_PREFIX ."forums SET forum_last_post_id = $post WHERE forum_id = $forum";
if(!$db->sql_query($sql)){
$error.="n6";
$ERR = $db->sql_error();
}
wapheader();
start_card("id","Posted");
print("<p>New Topic Posted</p>");
print("<p><a href=\"wap_index.php\">Main Menu</a></p>");
print( $error . " " . $ERR['message'] . " " . $ERR['code']);
break;
default:
wapheader();
start_card("id","Ooops");
print("<p>No Mode Specified</p>");
print("<p><a href=\"wap_index.php\">Main Menu</a></p>");
if($DEBUG) print( $error . " " . $ERR['message'] . " " . $ERR['code']);
break;
}
end_card();
print("</wml>");
}
?>