<?php
// $Id: postcomment.php,v 1.1 2004/07/11 10:28:39 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

include_once("header.php");
include_once(XOOPS_ROOT_PATH."/class/xoopscomments.php");

if ( isset($HTTP_POST_VARS['op']) ) {

switch($HTTP_POST_VARS['op']) {

case "preview":
	include_once(XOOPS_ROOT_PATH."/header.php");
	( empty($xoopsConfig['allow_html']) || empty($HTTP_POST_VARS['allow_html']) ) ? $html = 0 : $html = intval($HTTP_POST_VARS['allow_html']);
	$p_subject = $myts->makeTboxData4Preview($HTTP_POST_VARS['subject']);
	if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
		$myts->setType('admin');
		} else {
			$myts->setType('user');
		}
	$p_comment = $myts->makeTareaData4Preview($HTTP_POST_VARS['message'], $html, intval($HTTP_POST_VARS['allow_smileys']), intval($HTTP_POST_VARS['allow_bbcode']));
	themecenterposts($p_subject, $p_comment);

	$icon          = $HTTP_POST_VARS['icon'];
	$noname        = intval($HTTP_POST_VARS['noname']);
	$allow_html    = intval($HTTP_POST_VARS['allow_html']);
	$allow_smileys = intval($HTTP_POST_VARS['allow_smileys']);
	$allow_bbcode  = intval($HTTP_POST_VARS['allow_bbcode']);
	$pid           = intval($HTTP_POST_VARS['pid']);
	$item_id       = intval($HTTP_POST_VARS['item_id']);
	$comment_id    = intval($HTTP_POST_VARS['comment_id']);
	$order         = $HTTP_POST_VARS['order'];
	$subject       = $myts->makeTboxData4PreviewInForm($HTTP_POST_VARS['subject']);
	$message       = $myts->makeTboxData4PreviewInForm($HTTP_POST_VARS['message']);
	OpenTable();
	include_once(XOOPS_ROOT_PATH."/include/commentform.inc.php");
	CloseTable();
	break;

case "post":
	if ( !empty($HTTP_POST_VARS['comment_id']) ) {
		$artcomment = new XoopsComments($db->prefix("comments"), $HTTP_POST_VARS['comment_id']);
		$accesserror = 0;
	if ( $xoopsUser ) {
		if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
			if ( $artcomment->getVar("user_id") != $xoopsUser->getVar("uid") ) {
				$accesserror = 1;
			}
		}
	} else {
		$accesserror = 1;
	}

	if ( $accesserror == 1 ) {
		redirect_header("article.php?storyid=".intval($HTTP_POST_VARS['item_id'])."&comment_id=".intval($HTTP_POST_VARS['comment_id'])."&order=".intval($HTTP_POST_VARS['order']),1,_NW_EDITNOTALLOWED);
		exit();
	}

	} else {
		$artcomment = new XoopsComments($db->prefix("comments"));
		$artcomment->setVar("pid", $HTTP_POST_VARS['pid']);
		$artcomment->setVar("item_id", $HTTP_POST_VARS['item_id']);
		$artcomment->setVar("ip", _REMOTE_ADDR);
		if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
			$artcomment->setVar('type', 'admin');
			} else {
				$artcomment->setVar('type', 'user');
			}
		if ( $xoopsUser ) {
			$uid = $xoopsUser->getVar("uid");
			} else {
				if ( $xoopsConfig['anonpost'] == 1 ) {
					$uid = 0;
					} else {
						redirect_header("article.php?storyid=".$HTTP_POST_VARS['itemid']."&comment_id=".$HTTP_POST_VARS['comment_id']."&order=".$HTTP_POST_VARS['order'],1,_NW_ANONNOTALLOWED);
						exit();
					}
		}
		$artcomment->setVar("user_id", $uid);
	}

	$artcomment->setVar("subject", $HTTP_POST_VARS['subject']);
	$artcomment->setVar("comment", $HTTP_POST_VARS['message']);
	$artcomment->setVar("allow_html", intval($HTTP_POST_VARS['allow_html']));
	$artcomment->setVar("allow_smileys", intval($HTTP_POST_VARS['allow_smileys']));
	$artcomment->setVar("allow_bbcode", intval($HTTP_POST_VARS['allow_bbcode']));
	$artcomment->setVar("icon", $HTTP_POST_VARS['icon']);
	$newtid = $artcomment->store();

	redirect_header("article.php?storyid=".intval($HTTP_POST_VARS['item_id'])."&comment_id=".$newtid."&order=".intval($HTTP_POST_VARS['order'])."#".$newtid."",2,_NW_THANKSFORPOST);
	exit();
	break;
}

	} else {
		redirect_header("index.php",2);
		exit();
	}

include_once(XOOPS_ROOT_PATH."/footer.php");
?>
