<?php
// $Id: submit.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/xoopstree.php");
include_once("class/class.newsstory.php");
include_once("cache/config.php");

if ($xoopsUser) {
	$uid = $xoopsUser->uid();
	} elseif ($newsConfig['anonsubmit'] == 1) {
		$uid = 0;
		} else {
			redirect_header("index.php", 3, _NW_ANONNOTALLOWED);
			exit();
		}

switch($HTTP_POST_VARS['op']) {

case "preview":
	$xt = new XoopsTopic($db->prefix("topics"), $HTTP_POST_VARS['topic_id']);
	include_once(XOOPS_ROOT_PATH."/header.php");
	OpenTable();
	$p_subject = $myts->makeTboxData4Preview($xt->topic_title("P").": ".$HTTP_POST_VARS['subject']);
	$hometext  = $HTTP_POST_VARS['hometext'];
	$moretext  = $HTTP_POST_VARS['moretext'];

	( empty($xoopsConfig['allow_html']) || empty($HTTP_POST_VARS['allow_html']) ) ? $html = 0 : $html = intval($HTTP_POST_VARS['allow_html']);
	if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
		$myts->setType('admin');
		} else {
			$myts->setType('user');
		}
	$p_message  = $myts->makeTareaData4Preview($hometext, $html, intval($HTTP_POST_VARS['allow_smileys']), intval($HTTP_POST_VARS['allow_bbcode']));
	if ( !empty($moretext) ) {
	if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
		$myts->setType('admin');
		} else {
			$myts->setType('user');
		}
		$p_message .= "<br /><br />".$myts->makeTareaData4Preview($moretext, $html, intval($HTTP_POST_VARS['allow_smileys']), intval($HTTP_POST_VARS['allow_bbcode']));
	}

	$subject       = $myts->makeTboxData4PreviewInForm($HTTP_POST_VARS['subject']);
	$hometext      = $myts->makeTboxData4PreviewInForm($hometext);
	$moretext      = $myts->makeTboxData4PreviewInForm($moretext);
	$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']);
	$notifypub     = intval($HTTP_POST_VARS['notifypub']);

	echo "<b>"._NW_SUBMITNEWS."</b><br /><br />";
	OpenTable("85%");
	themecenterposts($p_subject, $p_message);
	CloseTable();
	include_once("include/storyform.inc.php");
	CloseTable();
	include_once(XOOPS_ROOT_PATH."/footer.php");
	break;

case "post":
	$story = new NewsStory();
	$story->setTitle($HTTP_POST_VARS['subject']);
	$story->setHometext($HTTP_POST_VARS['hometext']);
	$story->setBodytext($HTTP_POST_VARS['moretext']);
	$story->setUid($uid);
	$story->setTopicId($HTTP_POST_VARS['topic_id']);
	$story->setHostname(_REMOTE_ADDR);
	$story->setHtml($HTTP_POST_VARS['allow_html']);
	$story->setSmileys($HTTP_POST_VARS['allow_smileys']);
	$story->setBBcode($HTTP_POST_VARS['allow_bbcode']);
	$story->setNotifyPub($HTTP_POST_VARS['notifypub']);
	if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
		$story->setType('admin');
		} else {
			$story->setType('user');
		}
	$result = $story->store();
	if ($result && $newsConfig['notifysubmit'] == 1) {
		$xoopsMailer =& getMailer();
		$xoopsMailer->useMail();
		$xoopsMailer->setToEmails($xoopsConfig['adminmail']);
		$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
		$xoopsMailer->setFromName($meta['title']);
		$xoopsMailer->setSubject(_NW_NOTIFYSBJCT);
		$xoopsMailer->setBody(_NW_NOTIFYMSG);
		$xoopsMailer->send();
		}
	redirect_header("index.php", 2, _NW_THANKS);
	break;

default:
	$xt = new XoopsTopic($db->prefix("topics"));
	include_once(XOOPS_ROOT_PATH."/header.php");
	OpenTable();
	echo "<h3>"._NW_SUBMITNEWS."</h3>";
	$subject  = "";
	$message  = "";
	$moretext = "";
	include_once("include/storyform.inc.php");
	CloseTable();
	include_once(XOOPS_ROOT_PATH."/footer.php");
	break;
}
?>
