<?php
// $Id: postcomment.php,v 1.1 2004/07/11 10:29:11 Farsus Exp $
// -------------------------------------------------------------------------//
//			       RUNCMS                                                   //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// 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        = $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         = intval($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']) ) {
		$pollcomment = new XoopsComments($db->prefix("xoopspollcomments"), intval($HTTP_POST_VARS['comment_id']));
		$accesserror = 0;
		if ($xoopsUser) {
			if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
				if ( $pollcomment->getVar("user_id") != $xoopsUser->getVar("uid") ) {
					$accesserror = 1;
				}
			}
			} else {
				$accesserror = 1;
			}
		if ( $accesserror == 1 ) {
			redirect_header("pollresults.php?poll_id=".intval($HTTP_POST_VARS['item_id'])."&amp;comment_id=".intval($HTTP_POST_VARS['comment_id'])."&amp;order=".intval($HTTP_POST_VARS['order']), 1, _PL_EDITNOTALLOWED);
			exit();
		}
		} else {
			$pollcomment = new XoopsComments($db->prefix(xoopspollcomments));
			$pollcomment->setVar("pid", intval($HTTP_POST_VARS['pid']));
			$pollcomment->setVar("item_id", intval($HTTP_POST_VARS['item_id']));
			$pollcomment->setVar("ip", _REMOTE_ADDR);
			if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
				$pollcomment->setVar('type', 'admin');
				} else {
					$pollcomment->setVar('type', 'user');
				}
			if ( $xoopsUser ) {
				$uid = $xoopsUser->getVar("uid");
				} else {
					if ( $xoopsConfig['anonpost'] == 1 ) {
						$uid = 0;
						} else {
						redirect_header("pollresults.php?poll_id=".intval($HTTP_POST_VARS['item_id'])."&amp;comment_id=".intval($HTTP_POST_VARS['comment_id'])."&amp;order=".intval($HTTP_POST_VARS['order'])."&amp;pid=".intval($HTTP_POST_VARS['pid'])."", 1, _PL_ANONNOTALLOWED);
						exit();
						}
				}
			$pollcomment->setVar("user_id", $uid);
		}
	$pollcomment->setVar("subject", $HTTP_POST_VARS['subject']);
	$pollcomment->setVar("comment", $HTTP_POST_VARS['message']);
	$pollcomment->setVar("allow_html", intval($HTTP_POST_VARS['allow_html']));
	$pollcomment->setVar("allow_smileys", intval($HTTP_POST_VARS['allow_smileys']));
	$pollcomment->setVar("allow_bbcode", intval($HTTP_POST_VARS['allow_bbcode']));
	$pollcomment->setVar("icon", $HTTP_POST_VARS['icon']);
	$new_comment_id = $pollcomment->store();
	redirect_header("pollresults.php?poll_id=".intval($HTTP_POST_VARS['item_id'])."&amp;comment_id=".$new_comment_id."&amp;order=".intval($HTTP_POST_VARS['order'])."",2,_PL_THANKSFORPOST);
	exit();
	break;
}

} else {
	redirect_header("index.php", 2);
	exit();
}
include_once(XOOPS_ROOT_PATH."/footer.php");
?>
