<?php
/**
 * $Source: /home/cvs/nukescripts/News/admin/includes/PostAdminStory.php,v $
 * $Revision: 1.1.6 $
 * $Author: cyril $
 * $Date: 2006/08/18 13:53:09 $
 * Bug 137
 */
/************************************************************************/
/* 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";
        $notes = "";
        $author = $aid;
        $subject = stripslashes(FixQuotes($subject));
        $subject = ereg_replace("\"", "''", $subject);
        $hometext = stripslashes(FixQuotes($hometext));
        $bodytext = stripslashes(FixQuotes($bodytext));
        $new_sql  = "insert into ".TABLE_AUTONEWS." values (NULL, '$catid', '$aid', '$subject', '$date', '$hometext', '$bodytext', '$topic', '$author', '$notes', '$ihome', '$alanguage', '$acomm', '$assotop' ) ";
        $result = $db->sql_query($new_sql);
        if (!$result) { exit(); }
        $result = $db->sql_query("update ".TABLE_AUTHORS." set counter=counter+1 where aid='$aid'");
        if ($ultramode) {
            ultramode();
        }
        redirect_url("".$admin_file.".php?op=homenews");
    } else {
        $subject = stripslashes(FixQuotes($subject));
        $hometext = stripslashes(FixQuotes($hometext));
        $bodytext = stripslashes(FixQuotes($bodytext));
        if (($pollTitle != "") AND ($optionText[1] != "") AND ($optionText[2] != "")) {
            $haspoll = 1;
            $timeStamp = time();
            $pollTitle = FixQuotes($pollTitle);
            if(!$db->sql_query("INSERT INTO ".TABLE_POLL_DESC." VALUES (NULL, '$pollTitle', '$timeStamp', '0', '$alanguage', '0')")) {
                return;
            }
            $object = $db->sql_fetchrow($db->sql_query("SELECT pollID FROM ".TABLE_POLL_DESC." WHERE pollTitle='$pollTitle'"));
            $id = $object['pollID'];
            $id = $db->XMFnum($id);
            for($i = 1; $i <= sizeof($optionText); $i++) {
                if($optionText[$i] != "") {
                    $optionText[$i] = FixQuotes($optionText[$i]);
                }
                if(!$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', '$aid', '$notes', '$ihome', '$alanguage', '$acomm', '$haspoll', '$id', '0', '0', '$associated' ) ";
        $result = $db->sql_query($new_sql);
        $result = $db->sql_query("select sid from ".TABLE_STORIES." WHERE title='$subject' order by time DESC limit 0,1");
        $rar = $db->sql_fetchrow($result);
        $artid = $db->XMFnum($rar['artid']);
        $db->sql_query("UPDATE ".TABLE_POLL_DESC." SET artid='$artid' WHERE pollID='$id'");
        if (!$result) {
            exit();
        }
        $result = $db->sql_query("update ".TABLE_AUTHORS." set counter=counter+1 where aid='$aid'");
        if ($ultramode) {
            ultramode();
        }
        redirect_url("".$admin_file.".php?op=homenews");
    }