<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.2 www.exoops.info 2006/03 
// $Id: submit.php,v 1.1 2003/08/31 12:16:44 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// 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($_POST['op']) {
case "preview":
        $xt = new XoopsTopic($db->prefix("topics"), $_POST['topic_id']);
        include_once(XOOPS_ROOT_PATH."/header.php");
        OpenTable();
        $p_subject = $myts->makeTboxData4Preview($xt->topic_title("P").": ".$_POST['subject']);
        $hometext  = $_POST['hometext'];
        $moretext  = $_POST['moretext'];
        ( empty($bcoosConfig['allow_html']) || empty($_POST['allow_html']) ) ? $html = 0 : $html = intval($_POST['allow_html']);
        if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
                $myts->setType('admin');
                } else {
                        $myts->setType('user');
                }
        $p_message  = $myts->makeTareaData4Preview($hometext, $html, intval($_POST['allow_smileys']), intval($_POST['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($_POST['allow_smileys']), intval($_POST['allow_bbcode']));
        }
        $subject       = $myts->makeTboxData4PreviewInForm($_POST['subject']);
        $hometext      = $myts->makeTboxData4PreviewInForm($hometext);
        $moretext      = $myts->makeTboxData4PreviewInForm($moretext);
        $noname        = intval($_POST['noname']);
        $allow_html    = intval($_POST['allow_html']);
        $allow_smileys = intval($_POST['allow_smileys']);
        $allow_bbcode  = intval($_POST['allow_bbcode']);
        $notifypub     = intval($_POST['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($_POST['subject']);
        $story->setHometext($_POST['hometext']);
        $story->setBodytext($_POST['moretext']);
        $story->setUid($uid);
        $story->setTopicId($_POST['topic_id']);
        $story->setHostname(_REMOTE_ADDR);
        $story->setHtml($_POST['allow_html']);
        $story->setSmileys($_POST['allow_smileys']);
        $story->setBBcode($_POST['allow_bbcode']);
        $story->setNotifyPub($_POST['notifypub']);
        if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
                $story->setType('admin');
                } else {
                        $story->setType('user');
                }
        if ( $newsConfig['autoapprove'] == 1 ) {
                $approve = 1;
                $story->setApproved($approve);
            $story->setPublished(time());
                $story->setTopicalign('R');
        }
        $result = $story->store();
        if ($result && $newsConfig['notifysubmit'] == 1) {
                $xoopsMailer =& getMailer();
                $xoopsMailer->useMail();
                $xoopsMailer->setToEmails($bcoosConfig['adminmail']);
                $xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
                $xoopsMailer->setFromName($bcoosConfig['title']);
                $xoopsMailer->setSubject(_NW_NOTIFYSBJCT);
                $xoopsMailer->setBody(_NW_NOTIFYMSG);
                $xoopsMailer->send();
                }
        redirect_header("index.php", 2, _THANKSSUBMIT);
        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;
}
?>
