<?php
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
// Based on:								     //
// myPHPNUKE Web Portal System - http://myphpnuke.com/	  		     //
// PHP-NUKE Web Portal System - http://phpnuke.org/	  		     //
// Thatware - http://thatware.org/					     //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //
include("header.php");
include_once(XOOPS_ROOT_PATH."/class/xoopstree.php");
include_once("class/class.newsstory.php");
include("cache/config.php");
switch($op){
	default:
		$xt = new XoopsTopic($xoopsDB->prefix("topics"));
		include (XOOPS_ROOT_PATH."/header.php");
		OpenTable();
		echo "<h3>"._NW_SUBMITNEWS."</h3>";
		$submit_page = "submit.php";
		$subject = "";
		$message = "";
		include("include/storyform.inc.php");
		CloseTable();
		include (XOOPS_ROOT_PATH."/footer.php");
		break;

	case "preview":
		$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
		$xt = new XoopsTopic($xoopsDB->prefix("topics"), $HTTP_POST_VARS['topic_id']);
		include (XOOPS_ROOT_PATH."/header.php");
		OpenTable();
		$p_subject = $myts->makeTboxData4Preview($HTTP_POST_VARS['subject']);
  		if ( !empty($HTTP_POST_VARS['nosmiley']) && !empty($HTTP_POST_VARS['nohtml']) ){
			$p_message = $myts->makeTareaData4Preview($HTTP_POST_VARS['message'],0,0,1);
		} elseif ( !empty($HTTP_POST_VARS['nohtml']) ) {
			$p_message = $myts->makeTareaData4Preview($HTTP_POST_VARS['message'],0,1,1);
		} elseif ( !empty($HTTP_POST_VARS['nosmiley']) ) {
			$p_message = $myts->makeTareaData4Preview($HTTP_POST_VARS['message'],1,0,1);
		} else {
			$p_message = $myts->makeTareaData4Preview($HTTP_POST_VARS['message'],1,1,1);
		}
		$subject = $myts->makeTboxData4PreviewInForm($HTTP_POST_VARS['subject']);
  		$message = $myts->makeTareaData4PreviewInForm($HTTP_POST_VARS['message']);
		$noname = intval($HTTP_POST_VARS['noname']);
		$nosmiley = intval($HTTP_POST_VARS['nosmiley']);
		$nohtml = intval($HTTP_POST_VARS['nohtml']);
		$notifypub = intval($HTTP_POST_VARS['notifypub']);
		echo "<b>"._NW_SUBMITNEWS."</b><br><br>";
		OpenTable("75%");
		echo "<img src='images/topics/".$xt->topic_imgurl()."' border='0' align='right' />";
		echo "<p><b>".$p_subject."</b><br /><br />".$p_message."<br /><br /></p>";
		CloseTable();
		$submit_page = "submit.php";
		include("include/storyform.inc.php");
		CloseTable();
		include (XOOPS_ROOT_PATH."/footer.php");
		break;
	case "post":
		if ($xoopsUser) {
			$uid = $xoopsUser->uid();
		} else {
			if ($xoopsConfig['anonpost'] == 1) {
				$uid = 0;
			} else {
				redirect_header("index.php",3,_NW_ANONNOTALLOWED);
				exit();
			}
		}
		$story = new NewsStory(); 
		$story->setTitle($HTTP_POST_VARS['subject']);
		$story->setHometext($HTTP_POST_VARS['message']);
		$story->setUid($uid);
		$story->setTopicId($HTTP_POST_VARS['topic_id']);
		$story->setHostname($GLOBALS['REMOTE_ADDR']);
		$story->setNohtml($HTTP_POST_VARS['nohtml']);
		$story->setNosmiley($HTTP_POST_VARS['nosmiley']);
		$story->setNotifyPub($HTTP_POST_VARS['notifypub']);
		$story->setType("user");
		$result = $story->store();
		if ($result && $xoops_newsConfig['notifysubmit'] == 1) {
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail();
			$xoopsMailer->setToEmails($xoopsConfig['adminmail']);
			$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
			$xoopsMailer->setFromName($xoopsConfig['sitename']);
			$xoopsMailer->setSubject(_NW_NOTIFYSBJCT);
			$xoopsMailer->setBody(_NW_NOTIFYMSG);
			$xoopsMailer->send();
		}
		redirect_header("index.php",2,_NW_THANKS);
		break;
}
?>