<?php
// -----------------------------------------------------------------------
//
// $Id: edit.php 2 2012-01-24 17:39:30Z raoul $
//
// Copyright (C) 2003-2012 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.
//
// -----------------------------------------------------------------------
include('./../includes/common.php');
page_header($lang['COMMENTS_EDIT_TITLE']);
// From edit form ?
if (isset($_POST['edit_comment']))
{
if (!trim($_POST['comment_text']))
{
error_template($lang['NO_COMMENT_TEXT']);
}
else
{
if ($settings['allow_html'] == 0)
{
$comment_text = chars2entities($_POST['comment_text'], ENT_QUOTES);
}
else
{
$comment_text = do_html($_POST['comment_text']);
}
$comment_text = make_clickable($comment_text);
$comment_text = do_bbcodes($comment_text);
if ($settings['allow_smilies'] != 0)
{
$comment_text = do_smilies($comment_text);
}
$sql->query('UPDATE ' . TABLE_COMMENTS . '
SET comment_text = \'' . $comment_text . '\', comment_edition = \'' . time() . '\'
WHERE comment_id = \'' . $_POST['comment_id'] . '\'');
success_template($lang['COMMENTS_EDIT_SUCCESS'], './../comments/index.php?news_id=' . $_POST['news_id'] . '&story_id=' . $_POST['story_id']);
}
}
// Edit form
else
{
// Check query
if (!empty($_GET['comment_id']))
{
$sql->query('SELECT comment_subject, comment_text, news_id, story_id
FROM ' . TABLE_COMMENTS . '
WHERE comment_id = \'' . $_GET['comment_id'] . '\'
AND user_id = \'' . $_SESSION['user_id'] . '\'');
$table_comments = $sql->fetch();
// Check poster
if (!$table_comments['comment_subject'])
{
error_template($lang['COMMENTS_EDIT_ERROR1']);
}
else
{
if ($settings['allow_html'] == 0)
{
$html_support = $lang['HTML_DISABLED'];
}
else
{
$html_support = $lang['HTML_ENABLED'];
}
$comment_text = undo_smilies($table_comments['comment_text']);
$comment_text = undo_bbcodes($comment_text);
$template->set_file('edit', 'comments/edit.htpl');
$template->set_var(array('BACK_HOME' => $lang['BACK_HOME'],
'COMMENT_ID' => $_GET['comment_id'],
'COMMENT_SUBJECT' => $table_comments['comment_subject'],
'COMMENT_TEXT' => $comment_text,
'COMMENTS_EDIT_HEADER' => $lang['COMMENTS_EDIT_HEADER'],
'EDIT' => $lang['EDIT'],
'FORM_COMMENT_SUBJECT' => $lang['FORM_COMMENT_SUBJECT'],
'FORM_COMMENT_TEXT' => $lang['FORM_COMMENT_TEXT'],
'HTML_SUPPORT' => $html_support,
'NEWS_ID' => $table_comments['news_id'],
'SMILIES_LIST' => get_smilies_list(0),
'STORY_ID' => $table_comments['story_id']));
$template->parse('edit');
}
}
else
{
error_template($lang['COMMENTS_EDIT_ERROR2']);
}
}
page_footer();
?>