Location: PHPKode > projects > Gnew > Gnew-2013.1/news/submit.php
<?php
// -----------------------------------------------------------------------------
// $Id: submit.php 682 2013-03-28 14:17:41Z raoul $
//
// Copyright (C) 2013 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
// -----------------------------------------------------------------------------
// 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 3 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, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

include('./../includes/common.php');

page_header($lang['NEWS_SUBMIT']);

// Submit function enabled?
if ($settings['news_submitting'] == 0)
{
    error_template($lang['ERROR_SUBMITTING_DISABLED']);
}
// User logged?
elseif ($_SESSION['user_id'] > 0)
{
    // From submit form?
    if (isset($_POST['submit']) || isset($_POST['preview']))
    {
        $error = '';
        $sql->query('SELECT user_submissions
                     FROM ' . TABLE_USERS . '
                     WHERE user_id = \'' . $_SESSION['user_id'] . '\'');
        $table_users = $sql->fetch();
        // Check number of user submissions
        if ($table_users['user_submissions'] == $settings['max_submissions_per_user'])
        {
            $error .= sprintf($lang['ERROR_SUBMIT_LIMIT'], $settings['max_submissions_per_user']);
        }
        else
        {
            // Categories not created yet?
            if (empty($_POST['category_id']))
            {
                $error .= $lang['ERROR_NO_CATEGORY'];
            }
            if (!trim($_POST['news_subject']))
            {
                $error .= $lang['ERROR_NO_SUBJECT'];
            }
            if (!trim($_POST['news_text']))
            {
                $error .= $lang['ERROR_NO_TEXT'];
            }
        }
        if ($error)
        {
            error_template($error);
        }
        else
        {
            $news_subject = utf8_entities($_POST['news_subject']);
            if ($settings['allow_html'])
            {
                $news_source2 = do_html($_POST['news_source']);
                $news_text2 = do_html($_POST['news_text']);
            }
            else
            {
                $news_source2 = utf8_entities($_POST['news_source']);
                $news_text2 = utf8_entities($_POST['news_text']);
            }
            $news_source = $news_source2;
            $news_text = $news_text2;
            $news_source2 = make_clickable($news_source2);
            $news_text2 = make_clickable($news_text2);
            $news_source2 = do_bbcodes($news_source2);
            $news_text2 = do_bbcodes($news_text2);
            if ($settings['allow_emoticons'])
            {
                $news_text2 = do_emoticons($news_text2);
            }
            // Preview form
            if (isset($_POST['preview']))
            {
                // remove_form_data();
                if (!empty($_POST['news_source']))
                {
                    $news_source2 = undo_escape_sequences($news_source2);
                    $news_source2 = sprintf($lang['SOURCE'], $news_source2);
                }
                else
                {
                    $news_source2 = '<!-- empty -->';
                }
                $news_text2 = undo_escape_sequences($news_text2);
                if ($settings['allow_html'])
                {
                    $html_support = $lang['HTML_ENABLED'];
                }
                else
                {
                    $html_support = $lang['HTML_DISABLED'];
                }
                $category_id_options = '';
                $sql->query('SELECT category_id, category_image, category_name
                             FROM ' . TABLE_CATEGORIES . '
                             WHERE category_level IN (\'2\', \'4\')
                             ORDER BY category_name');
                while ($table_categories = $sql->fetch())
                {
                    if ($table_categories['category_id'] == $_POST['category_id'])
                    {
                        $category_id_options .= '<option value="' . $table_categories['category_id'] . '" selected="selected">' . $table_categories['category_name'] . '</option>';
                        $category_image = $table_categories['category_image'];
                        $category_name = $table_categories['category_name'];
                    }
                    else
                    {
                        $category_id_options .= '<option value="' . $table_categories['category_id'] . '">' . $table_categories['category_name'] . '</option>';
                    }
                }
                $template->set_file('preview', 'news/preview.htpl');
                $template->set_var(array('CATEGORY_ID' => $_POST['category_id'],
                                         'CATEGORY_ID_OPTIONS' => $category_id_options,
                                         'CATEGORY_IMAGE' => $category_image,
                                         'CATEGORY_NAME' => $category_name,
                                         'EMOTICONS_LIST' => get_emoticons_list(0),
                                         'HTML_SUPPORT' => $html_support,
                                         'NEWS_COMMENTS' => 0,
                                         'NEWS_POSTED' => sprintf($lang['POSTED_BY'], $_SESSION['user_id'], $users['user_name'], format_date(time())),
                                         'NEWS_SOURCE' => $news_source,
                                         'NEWS_SOURCE2' => $news_source2,
                                         'NEWS_SUBJECT' => $news_subject,
                                         'NEWS_TEXT' => $news_text,
                                         'NEWS_TEXT2' => $news_text2));
                $template->parse('preview');
            }
            else
            {
                $sql->query('INSERT INTO ' . TABLE_NEWS . ' (category_id, user_id, news_month, news_source, news_subject, news_text, news_year, news_creation)
                             VALUES (\'' . $_POST['category_id'] . '\', \'' . $_SESSION['user_id'] . '\', \'' . date('m', time()) . '\', \'' . $news_source2 . '\', \'' . $news_subject . '\', \'' . $news_text2 . '\', \'' . date('Y', time()) . '\', \'' . time() . '\')');
                $sql->query('UPDATE ' . TABLE_USERS . '
                             SET user_submissions = user_submissions + 1
                             WHERE user_id = \'' . $_SESSION['user_id'] . '\'');
                // For the time being inactive news are not displayed
                // $GLOBALS['cache']->clean(TABLE_NEWS);
                // For the time being user_submissions is not displayed
                // $GLOBALS['cache']->clean(TABLE_USERS);
                success_template($lang['NEWS_SUBMITTED'], './../index.php');
            }
        }
    }
    // Submit form
    else
    {
        $category_id_options = '';
        $sql->query('SELECT category_id, category_name
                     FROM ' . TABLE_CATEGORIES . '
                     WHERE category_level IN (\'2\', \'4\')
                     ORDER BY category_name');
        while ($table_categories = $sql->fetch())
        {
            $category_id_options .= '<option value="' . $table_categories['category_id'] . '">' . $table_categories['category_name'] . '</option>';
        }
        if ($settings['allow_html'])
        {
            $html_support = $lang['HTML_ENABLED'];
        }
        else
        {
            $html_support = $lang['HTML_DISABLED'];
        }
        $template->set_file('submit', 'news/submit.htpl');
        $template->set_var(array('CATEGORY_ID_OPTIONS' => $category_id_options,
                                 'EMOTICONS_LIST' => get_emoticons_list(0),
                                 'HTML_SUPPORT' => $html_support));
        $template->parse('submit', null, false, array(TABLE_CATEGORIES, TABLE_EMOTICONS));
    }
}
else
{
    error_template($lang['ERROR_USER_OFFLINE']);
}

page_footer();

?>
Return current item: Gnew