<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: submit.php,v 1.31.2.9 2004/08/22 14:33:49 kirilt Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.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.       */
/************************************************************************/

function defaultDisplay() {
    global $phpEx, $user, $mpnTables, $anonymous;
    include ("header.$phpEx");
    OpenTable();
    echo "<font size=4><b>".translate("Submit News")."</b><font size=2>";

    $cookie = ( _MPN_USER ) ? ( cookiedecode() ) : ( NULL );

    echo "<br /><br /><FORM action=\"submit.$phpEx\" method=\"post\" name=\"coolsus\">"
        ."<b>".translate("Your Name")."</b> ";

    if ( ! empty( $cookie ) )
    {
        echo "<a href='user.php'>$cookie[1]</a> <font size=2>[ <a href=\"user.$phpEx?op=logout\">".translate("Logout")."</a> ]</font>";
    }
    else
    {
        echo "$anonymous <font size=2>[ <a href='user.php'>".translate("New User")."</a> ]</font>";
    }
    ?>
    <br /><br /><B><?php echo translate("Title"); ?></B>
    (<?php echo translate("Be Descriptive, Clear and Simple"); ?>)<BR>
    <input class=textbox type="text" NAME="subject" SIZE=60 maxlength=80><BR><FONT size=2>(<?php echo translate("bad titles='Check This Out!' or 'An Article'."); ?>)</FONT>
    <BR>
    <br /><br /><b><?php echo translate("Topic"); ?></b> <SELECT class=textbox NAME=topic>
    <?PHP
    if (!isset($topic))
    {
        $topic = null;
    }

    if (!isset($sel))
    {
        $sel = null;
    }

    $toplist = mysql_query("select topicid, topictext from ".$mpnTables['topics']." order by topictext");
        echo "<OPTION VALUE=\"\">".translate("Select Topic")."</option>\n";
        while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
            if ($topicid==$topic) { $sel = "selected "; }
            echo "<option $sel value=\"$topicid\">$topics</option>\n";
        $sel = "";
        }
    ?>
    </select>
    <br /><br /><B><?php echo translate("The Scoop"); ?></B>
    (<?php echo translate("HTML is fine, but double check those URLs and HTML tags!"); ?>)<br /><br />
    <TEXTAREA class="textbox" wrap="virtual" cols="70" rows="20" name="story"></TEXTAREA><br /><br />
    <?php HTMLbuttons(); ?>

   <?php

      /*echo "<SELECT name=\"posttype\"><OPTION value=\"exttrans\">".translate("Extrans (html tags to text)")."<OPTION value=\"html\" >".translate("HTML Formatted")."<OPTION value=\"plaintext\" SELECTED>".translate("Plain Old Text")."</SELECT><BR>";*/

    // Kiril: New Sanitizer

    addFormatOption();

    echo "<input type='hidden' name='clickit_form' value='story' />\n";
    echo "<input type='hidden' name='stripit_form' value='subject' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='1' />\n";

    // End Sanitizer

    ?>

    <FONT size="2">(<?php echo translate("Are you sure you included a URL? Did you test them for typos?"); ?>)</FONT><br /><br />
    <INPUT class='button' type="submit" name="op" value="<?php echo translate("Preview"); ?>"> (<?php echo translate("You must preview once before you can submit"); ?>)</FORM>
    <?PHP
    CloseTable();
    include ("footer.$phpEx");
}

function PreviewStory($name, $address, $subject, $story, $topic, $posttype) {
    global $user, $tipath, $mpnTables,$phpEx, $anonymous;
    include ("header.$phpEx");
    OpenTable();

    // Kiril: Start New Sanitizer

    $f_subject = $p_subject = $subject;
    $f_story = $p_story = $story;

    $_SERVER['SAN'] -> adjustFormat( $p_story, 3, 10 );

    // End New Sanitizer

    echo "<font size=3><b>".translate("Submit News")."</b></font><br><br>";
    echo "<p><FORM action=\"submit.$phpEx\" method=\"post\" name=\"coolsus\">"
        ."<b>".translate("Your Name")."</b> ";
    if (_MPN_USER) {
        $cookie = cookiedecode($user);
        echo "<a href='user.php'>$cookie[1]</a> <font size=2>[ <a href=\"user.$phpEx?op=logout\">".translate("Logout")."</a> ]</font>";
    } else {
        echo "$anonymous";
    } ?>

    <?PHP

    echo "<br><br><center>\n";


    echo "<table border=0 width=100%><tr><td>";
    if ($topic=="") {
        $topicimage="AllTopics.gif";
        $warning = "<center><blink><b>".translate("Please Select A Topic")."</b></blink></center>";
    } else {
        $warning = "";
        $result = mysql_query("select topicimage from ".$mpnTables['topics']." where topicid='$topic'");
        list($topicimage) = mysql_fetch_row($result);
    }

    echo "<img src=\"".$tipath.$topicimage."\" border=0 align=\"right\">";


    themepreview($p_subject, $p_story);

    echo "<br /><br />\n";
    echo "$warning";

    echo "</td></tr></table></center>";
    ?>

    <p><b><?php echo translate("Title"); ?></b><br>
        <input class=textbox type="text" NAME="subject" SIZE=70 maxlength=80 value="<?PHP echo"$f_subject"; ?>">

    <p><b><?php echo translate("Topic"); ?></b><select class=textbox name=topic>
    <?PHP
    $toplist = mysql_query("select topicid, topictext from ".$mpnTables['topics']." order by topictext");
    echo "<OPTION VALUE=\"\">".translate("Select Topic")."</option>\n";
        $sel = "";
        while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
            if ($topicid==$topic) { $sel = "selected "; }
            echo "<option $sel value=\"$topicid\">$topics</option>\n";
        $sel = "";
        }
    ?>
    </select>
    <br /><br /><B><?php echo translate("The Scoop"); ?></B>
    (<?php echo translate("HTML is fine, but double check those URLs and HTML tags!"); ?>)<br /><br />
    <TEXTAREA class="textbox" wrap="virtual" cols="70" rows="18" name="story"><?PHP echo $f_story; ?></TEXTAREA><br /><br />
    <?php
    HTMLbuttons();

    ?><br /><br />
    <FONT size=2>(<?php echo translate("Are you sure you included a URL? Did you test them for typos?"); ?>)</FONT><br /><br />

    <?php

    addFormatOption();

    echo "<input type='hidden' name='clickit_form' value='story' />\n";
    echo "<input type='hidden' name='stripit_form' value='subject' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='1' />\n";

    ?>

    <INPUT class='button' type="submit" name="op" value="<?php echo translate("Preview"); ?>"> <INPUT class='button' type="submit" name="op" value="<?php echo translate("Ok!"); ?>">
    </FORM>

    <?PHP
    CloseTable();
    include ("footer.$phpEx");
}

function submitStory($name, $address, $subject, $story, $topic, $posttype) {
    global $user, $notify, $notify_email, $notify_subject, $notify_message, $notify_from;
    global $mpnTables,$phpEx, $mailmethod, $sitename, $smtp, $mpn_anonymous_id;
        require_once ('class.phpmailer.php');
        $mail = new phpmailer();

        /* SET MAIL DELIVERY OPTIONS */
        $mail->IsHTML(true);
        if ($mailmethod == "0") {
            $mail->IsMail();
        } else {
            $mail->IsSMTP();
           $mail->Host = $smtp;
        }

    if ($user) {
        $cookie = cookiedecode($user);
        $uid = $cookie[0];
        $name = $cookie[1];
    } else {
        $uid = $mpn_anonymous_id;
        $name = "Anonymous";
    }

    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'subject', 'story' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary, TRUE );

    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer

    $result = mysql_query("insert into ".$mpnTables['queue']." values (NULL, '$uid', '$name', '$subject', '$story', now(), '$topic')");
    if(!$result) {
        echo mysql_errno(). ": ".mysql_error(). "<br>";
        exit();
    }
    if(isset($notify) && $notify == 1) {
                $mail->From = "$notify_from";
                $mail->FromName = $sitename . translate(' Mailer');
                $mail->AddAddress($notify_email);
                $mail->Subject = stripslashes($notify_subject);
                $mail->Body = nl2br( stripslashes($notify_message) );
                $mail->AltBody = strip_tags( stripslashes($notify_message) );
                $mail->Send();
    }

    // REFERENCE: goHome( $refresh = FALSE, $msg = NULL, $uri = 'index.php', $auto_time = 0 )

    goHome( translate( 'Thanks for your submission.' ) );
}

if (!isset( $op ))
{
    $op = null;
}

switch($op)
{
    case translate("Preview"):
        if (!isset($name))
        {
            $name = null;
        }

        if (!isset($address))
        {
            $address = null;
        }

        PreviewStory($name, $address, $subject, $story, $topic, $posttype);
        break;

    case translate("Ok!"):
        if (!isset($name))
        {
            $name = null;
        }

        if (!isset($address))
        {
            $address = null;
        }

        SubmitStory($name, $address, $subject, $story, $topic, $posttype);
        break;

    default:
        defaultDisplay();
        break;

}

?>
