<?php
include("header.php");
include_once(XOOPS_ROOT_PATH."/class/xoopscomments.php");
if ( isset($HTTP_POST_VARS['op']) ){
	switch($HTTP_POST_VARS['op']){
	    case "preview":
		include(XOOPS_ROOT_PATH."/header.php");
		$myts =& MyTextSanitizer::getInstance();
		$p_subject = $myts->makeTboxData4Preview($HTTP_POST_VARS['subject']);
		if ( $HTTP_POST_VARS['nosmiley'] == 1) {
			$p_comment = $myts->makeTareaData4Preview($HTTP_POST_VARS['message'],0,0,1);
		} else {
			$p_comment = $myts->makeTareaData4Preview($HTTP_POST_VARS['message'],0,1,1);
		}
		themecenterposts($p_subject,$p_comment);
		$icon = $HTTP_POST_VARS['icon'];
		$noname = $HTTP_POST_VARS['noname'];
		$nohtml = 1;
		$nosmiley = $HTTP_POST_VARS['nosmiley'];
		$pid = $HTTP_POST_VARS['pid'];
		$item_id = $HTTP_POST_VARS['item_id'];
		$comment_id = $HTTP_POST_VARS['comment_id'];
		$order = $HTTP_POST_VARS['order'];
		$subject = $myts->makeTboxData4PreviewInForm($HTTP_POST_VARS['subject']);
		$message = $myts->makeTareaData4PreviewInForm($HTTP_POST_VARS['message']);
		OpenTable();
		include(XOOPS_ROOT_PATH."/include/commentform.inc.php");
		CloseTable();
		break;
	    case "post":
		if ( !empty($HTTP_POST_VARS['comment_id']) ) {
			$pollcomment = new XoopsComments($xoopsDB->prefix("xoopspollcomments"),$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($xoopsDB->prefix(xoopspollcomments));
			$pollcomment->setVar("pid", $HTTP_POST_VARS['pid']);
			$pollcomment->setVar("item_id", $HTTP_POST_VARS['item_id']);
			$pollcomment->setVar("ip", $GLOBALS['REMOTE_ADDR']);
			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("nohtml", 1);
		$pollcomment->setVar("nosmiley", $HTTP_POST_VARS['nosmiley']);
		$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(XOOPS_ROOT_PATH."/footer.php");
?>