<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
    Header("Location: index.php");
    die();
}

    for ($i=0; $i<sizeof($assotop); $i++) { $associated .= "$assotop[$i]-"; }

    if ($automated == 1) {
        if ($day < 10) {
            $day = "0$day";
        }
        if ($month < 10) {
            $month = "0$month";
        }
        $sec = "00";
        $date = "$year-$month-$day $hour:$min:$sec";
        if ($uid == 1) $author = "";
        if ($hometext == $bodytext) $bodytext = "";
        $subject = stripslashes(FixQuotes($subject));
        $hometext = stripslashes(FixQuotes($hometext));
        $bodytext = stripslashes(FixQuotes($bodytext));
        $notes = stripslashes(FixQuotes($notes));
        $new_sql  = "insert into `".TABLE_AUTONEWS."` values (NULL, '$catid', '$aid', '$subject', '$date', '$hometext', '$bodytext', '$topic', '$author', '$notes', '$ihome', '$alanguage', '$acomm', '$associated' )";
        $result = $GLOBALS['db']->sql_query($new_sql);
        if (!$result) { return; }
        $result = $GLOBALS['db']->sql_query("select `sid` from `".TABLE_STORIES."` WHERE `title`='$subject' order by `time` DESC limit 0,1");
        list($artid) = $GLOBALS['db']->sql_fetchrow($result);
        $artid = $GLOBALS['db']->XMFnum($artid);
        if ($uid != 1) {
            $GLOBALS['db']->sql_query("update `".TABLE_USERS."` set `counter`=counter+1 where `user_id`='$uid'");
            // Copyright (c) 2000-2005 by NukeScripts Network
            if($ne_config['notifyauth'] == 1) {
                $urow = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `username`, `user_email` FROM `".TABLE_USERS."` WHERE `user_id`='$uid'"));
                $Mto = $urow['username']." <".$urow['user_email'].">";
                $Msubject = _NE_ARTPUB;
                $Mbody = _NE_HASPUB."\n$nukeurl/modules.php?name=News&file=article&sid=$artid";
                $Mheaders  = "From: ".$sitename." <$adminmail>\r\n";
                $Mheaders .= "Reply-To: $adminmail\r\n";
                $Mheaders .= "Return-Path: $adminmail\r\n";
                $Mheaders .= "Organization: $sitename\r\n";
                $Mheaders .= "MIME-Version: 1.0\r\n";
                $Mheaders .= "Content-Type: text/plain\r\n";
                $Mheaders .= "Content-Transfer-Encoding: 8bit\r\n";
                $Mheaders .= "X-MSMail-Priority: High\r\n";
                $Mheaders .= "X-Mailer: NSN News          \r\n";
                @mail($Mto, $Msubject, $Mbody, $Mheaders);
            }
               // $row = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='4'"));
                $GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `points`=points+$row[points] where `user_id`='$uid'");
        }
        $GLOBALS['db']->sql_query("update `".TABLE_AUTHORS."` set `counter`=counter+1 where `aid`='$aid'");
        if ($ultramode) { ultramode(); }
        $qid = $GLOBALS['db']->XMFnum($qid);
        $GLOBALS['db']->sql_query("delete from `".TABLE_QUEUE."` where `qid`='$qid'");
        redirect_url("".$admin_file.".php?op=submissions");
    } else {
        if ($uid == 1) $author = "";
        if ($hometext == $bodytext) $bodytext = "";
        $subject = stripslashes(FixQuotes($subject));
        $hometext = stripslashes(FixQuotes($hometext));
        $bodytext = stripslashes(FixQuotes($bodytext));
        $notes = stripslashes(FixQuotes($notes));
        if (($pollTitle != "") AND ($optionText[1] != "") AND ($optionText[2] != "")) {
            $haspoll = 1;
            $timeStamp = time();
            $pollTitle = FixQuotes($pollTitle);
            if(!$GLOBALS['db']->sql_query("INSERT INTO `".TABLE_POLL_DESC."` VALUES (NULL, '$pollTitle', '$timeStamp', '0', '$alanguage', '0')")) {
                return;
            }
            $object = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `pollID` FROM `".TABLE_POLL_DESC."` WHERE `pollTitle`='$pollTitle'"));
            $id = $object['pollID'];
            $id = $GLOBALS['db']->XMFnum($id);
            for($i = 1; $i <= sizeof($optionText); $i++) {
                if($optionText[$i] != "") {
                    $optionText[$i] = FixQuotes($optionText[$i]);
                }
                if(!$GLOBALS['db']->sql_query("INSERT INTO `".TABLE_POLL_DATA."` (pollID, optionText, optionCount, voteID) VALUES ('$id', '$optionText[$i]', '0', '$i')")) {
                    return;
                }
            }
        } else {
            $haspoll = 0;
            $id = 0;
        }
        $new_sql  = "insert into `".TABLE_STORIES."` values (NULL, '$catid', '$aid', '$subject', now(), '$hometext', '$bodytext', '0', '0', '$topic', '$author', '$notes', '$ihome', '$alanguage', '$acomm', '$haspoll', '$id', '0', '0', '$associated' )";
        $result = $GLOBALS['db']->sql_query($new_sql);
        $result = $GLOBALS['db']->sql_query("select `sid` from `".TABLE_STORIES."` WHERE `title`='$subject' order by `time` DESC limit 0,1");
        list($artid) = $GLOBALS['db']->sql_fetchrow($result);
        $artid = $GLOBALS['db']->XMFnum($artid);
        $GLOBALS['db']->sql_query("UPDATE `".TABLE_POLL_DESC."` SET `artid`='$artid' WHERE `pollID`='$id'");
        if (!$result) { return; }
        if ($uid != 1) {
            $GLOBALS['db']->sql_query("update `".TABLE_USERS."` set `counter`=counter+1 where `user_id`='$uid'");
            // Copyright (c) 2000-2005 by NukeScripts Network
            if($ne_config['notifyauth'] == 1) {
                $urow = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `username`, `user_email` FROM `".TABLE_USERS."` WHERE `user_id`='$uid'"));
                $Mto = $urow['username']." <".$urow['user_email'].">";
                $Msubject = _NE_ARTPUB;
                $Mbody = _NE_HASPUB."\n$nukeurl/modules.php?name=News&file=article&sid=$artid";
                $Mheaders  = "From: ".$sitename." <$adminmail>\r\n";
                $Mheaders .= "Reply-To: $adminmail\r\n";
                $Mheaders .= "Return-Path: $adminmail\r\n";
                $Mheaders .= "Organization: $sitename\r\n";
                $Mheaders .= "MIME-Version: 1.0\r\n";
                $Mheaders .= "Content-Type: text/plain\r\n";
                $Mheaders .= "Content-Transfer-Encoding: 8bit\r\n";
                $Mheaders .= "X-MSMail-Priority: High\r\n";
                $Mheaders .= "X-Mailer: NSN News          \r\n";
                @mail($Mto, $Msubject, $Mbody, $Mheaders);
            }
               // $row = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='4'"));
                $GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `points`=points+$row[points] where `user_id`='$uid'");
            $GLOBALS['db']->sql_query("update `".TABLE_USERS."` set `counter`=counter+1 where `user_id`='$uid'");
        }
        $GLOBALS['db']->sql_query("update `".TABLE_AUTHORS."` set `counter`=counter+1 where `aid`='$aid'");
        if ($ultramode) { ultramode(); }
include_once("modules/News/admin/includes/DeleteStory.php");
        DeleteStory($qid);
    }