<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.6 www.exoops.info 2006/08 GPL
// $Id: postcomment.php,v 1.5 2003/03/31 10:00:39 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// 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($_POST['op']) ) {
switch($_POST['op']) {
case "preview":
	include_once(XOOPS_ROOT_PATH."/header.php");
	( empty($bcoosConfig['allow_html']) || empty($_POST['allow_html']) ) ? $html = 0 : $html = intval($_POST['allow_html']);
	$p_subject = $myts->makeTboxData4Preview($_POST['subject']);
	if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
		$myts->setType('admin');
		} else {
			$myts->setType('user');
		}
	$p_comment = $myts->makeTareaData4Preview($_POST['message'], $html, intval($_POST['allow_smileys']), intval($_POST['allow_bbcode']));
	themecenterposts($p_subject, $p_comment);
	$icon          = $_POST['icon'];
	$noname        = $_POST['noname'];
	$allow_html    = intval($_POST['allow_html']);
	$allow_smileys = intval($_POST['allow_smileys']);
	$allow_bbcode  = intval($_POST['allow_bbcode']);
	$pid           = intval($_POST['pid']);
	$item_id       = intval($_POST['item_id']);
	$comment_id    = intval($_POST['comment_id']);
	$order         = intval($_POST['order']);
	$subject       = $myts->makeTboxData4PreviewInForm($_POST['subject']);
	$message       = $myts->makeTboxData4PreviewInForm($_POST['message']);
	$anonuser       = $myts->makeTboxData4PreviewInForm($_POST['anonuser']);
	OpenTable();
	include_once(XOOPS_ROOT_PATH."/include/commentform.inc.php");
	CloseTable();
	break;
case "post":
	if ( !empty($_POST['comment_id']) ) {
		$pollcomment = new XoopsComments($db->prefix("xoopspollcomments"), intval($_POST['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($_POST['item_id'])."&amp;comment_id=".intval($_POST['comment_id'])."&amp;order=".intval($_POST['order']),1,_PL_EDITNOTALLOWED);
			exit();
		}
		} else {
			$pollcomment = new XoopsComments($db->prefix(xoopspollcomments));
			$pollcomment->setVar("pid", intval($_POST['pid']));
			$pollcomment->setVar("item_id", intval($_POST['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 ( $bcoosConfig['anonpost'] == 1 ) {
						$uid = 0;
						} else {
						redirect_header("pollresults.php?poll_id=".intval($_POST['item_id'])."&amp;comment_id=".intval($_POST['comment_id'])."&amp;order=".intval($_POST['order'])."&amp;pid=".intval($_POST['pid'])."",1,_PL_ANONNOTALLOWED);
						exit();
						}
				}
			$pollcomment->setVar("user_id", $uid);
		}
		
	if (!$xoopsUser && $bcoosConfig['anonpost'] && $bcoosConfig['captcha_comments'] && function_exists('imagecreate')) {
		include_once(XOOPS_ROOT_PATH."/class/rc4.crypt.php");
		$rc4 = new rc4_crypt();
		$rc4->key(strtoupper($verify_text));
		$verify_crc = base64_decode($verify_crc);
		$rc4->decrypt($verify_crc);
		if ( empty($verify_text) || $verify_crc != "verified" ) {
		
				include_once(XOOPS_ROOT_PATH."/header.php");
				( empty($bcoosConfig['allow_html']) || empty($_POST['allow_html']) ) ? $html = 0 : $html = intval($_POST['allow_html']);
				$p_subject = $myts->makeTboxData4Preview($_POST['subject']);
				if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) { $myts->setType('admin'); }
				else { $myts->setType('user'); }
	
				$p_comment = $myts->makeTareaData4Preview($_POST['message'], $html, intval($_POST['allow_smileys']), intval($_POST['allow_bbcode']));
				echo "<b>"._US_BADVERIF."</b>";
				themecenterposts($p_subject, $p_comment);
				$icon          = $_POST['icon'];
				$noname        = $_POST['noname'];
				$allow_html    = intval($_POST['allow_html']);
				$allow_smileys = intval($_POST['allow_smileys']);
				$allow_bbcode  = intval($_POST['allow_bbcode']);
				$pid           = intval($_POST['pid']);
				$item_id       = intval($_POST['item_id']);
				$comment_id    = intval($_POST['comment_id']);
				$order         = intval($_POST['order']);
				$subject       = $myts->makeTboxData4PreviewInForm($_POST['subject']);
				$message       = $myts->makeTboxData4PreviewInForm($_POST['message']);
				$anonuser       = $myts->makeTboxData4PreviewInForm($_POST['anonuser']);
				OpenTable();
				include_once(XOOPS_ROOT_PATH."/include/commentform.inc.php");
				CloseTable();
				include_once(XOOPS_ROOT_PATH."/footer.php");//content
				exit();
		}
	}
	
	$pollcomment->setVar("subject", $_POST['subject']);
	$pollcomment->setVar("comment", $_POST['message']);
	$pollcomment->setVar("allow_html", intval($_POST['allow_html']));
	$pollcomment->setVar("allow_smileys", intval($_POST['allow_smileys']));
	$pollcomment->setVar("allow_bbcode", intval($_POST['allow_bbcode']));
	$pollcomment->setVar("icon", $_POST['icon']);
	$pollcomment->setVar("anonuser", $_POST['anonuser']);
	$new_comment_id = $pollcomment->store();
	redirect_header("pollresults.php?poll_id=".intval($_POST['item_id'])."&amp;comment_id=".$new_comment_id."&amp;order=".intval($_POST['order'])."",2,_THANKSSUBMIT);
	exit();
	break;
}
} else {
	redirect_header("index.php", 2);
	exit();
}
include_once(XOOPS_ROOT_PATH."/footer.php");
?>
