[ticket/11566] add error functionality

add $error which stores the captcha error when captcha validation fails

PHPBB3-11566
This commit is contained in:
Dhruv 2013-06-10 23:52:41 +05:30
parent 7a2e3b4354
commit eafd0ae29f

View file

@ -140,90 +140,101 @@ if ($config['enable_post_confirm'] && !$user->data['is_registered'])
$captcha->init(CONFIRM_POST);
}
$error = array();
// Submit report?
if ($submit && $reason_id)
{
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
$vc_response = $captcha->validate();
if ($vc_response)
{
trigger_error('EMPTY_REPORT');
$error[] = $vc_response;
}
$sql_ary = array(
'reason_id' => (int) $reason_id,
'post_id' => $post_id,
'pm_id' => $pm_id,
'user_id' => (int) $user->data['user_id'],
'user_notify' => (int) $user_notify,
'report_closed' => 0,
'report_time' => (int) time(),
'report_text' => (string) $report_text
);
$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$report_id = $db->sql_nextid();
if ($post_id)
if (!sizeof($error))
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_reported = 1
WHERE post_id = ' . $post_id;
$db->sql_query($sql);
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$report_data['topic_reported'])
if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_reported = 1
WHERE topic_id = ' . $report_data['topic_id'] . '
OR topic_moved_id = ' . $report_data['topic_id'];
$db->sql_query($sql);
trigger_error('EMPTY_REPORT');
}
$lang_return = $user->lang['RETURN_TOPIC'];
$lang_success = $user->lang['POST_REPORTED_SUCCESS'];
}
else
{
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
SET message_reported = 1
WHERE msg_id = ' . $pm_id;
$db->sql_query($sql);
$sql_ary = array(
'msg_id' => $pm_id,
'user_id' => ANONYMOUS,
'author_id' => (int) $report_data['author_id'],
'pm_deleted' => 0,
'pm_new' => 0,
'pm_unread' => 0,
'pm_replied' => 0,
'pm_marked' => 0,
'pm_forwarded' => 0,
'folder_id' => PRIVMSGS_INBOX,
'reason_id' => (int) $reason_id,
'post_id' => $post_id,
'pm_id' => $pm_id,
'user_id' => (int) $user->data['user_id'],
'user_notify' => (int) $user_notify,
'report_closed' => 0,
'report_time' => (int) time(),
'report_text' => (string) $report_text
);
$sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$report_id = $db->sql_nextid();
$lang_return = $user->lang['RETURN_PM'];
$lang_success = $user->lang['PM_REPORTED_SUCCESS'];
if ($post_id)
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_reported = 1
WHERE post_id = ' . $post_id;
$db->sql_query($sql);
if (!$report_data['topic_reported'])
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_reported = 1
WHERE topic_id = ' . $report_data['topic_id'] . '
OR topic_moved_id = ' . $report_data['topic_id'];
$db->sql_query($sql);
}
$lang_return = $user->lang['RETURN_TOPIC'];
$lang_success = $user->lang['POST_REPORTED_SUCCESS'];
}
else
{
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
SET message_reported = 1
WHERE msg_id = ' . $pm_id;
$db->sql_query($sql);
$sql_ary = array(
'msg_id' => $pm_id,
'user_id' => ANONYMOUS,
'author_id' => (int) $report_data['author_id'],
'pm_deleted' => 0,
'pm_new' => 0,
'pm_unread' => 0,
'pm_replied' => 0,
'pm_marked' => 0,
'pm_forwarded' => 0,
'folder_id' => PRIVMSGS_INBOX,
);
$sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$lang_return = $user->lang['RETURN_PM'];
$lang_success = $user->lang['PM_REPORTED_SUCCESS'];
}
meta_refresh(3, $redirect_url);
$message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
if ($return_forum_url)
{
$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
}
trigger_error($message);
}
meta_refresh(3, $redirect_url);
$message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
if ($return_forum_url)
{
$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
}
trigger_error($message);
}
// Generate the reasons
@ -231,14 +242,16 @@ display_reasons($reason_id);
$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false))
if ((isset($captcha) && $captcha->is_solved() === false))
{
$template->assign_vars(array(
'S_CONFIRM_CODE' => true,
'CAPTCHA_TEMPLATE' => $captcha->get_template(),
));
}
$template->assign_vars(array(
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
'S_REPORT_POST' => ($pm_id) ? false : true,
'REPORT_TEXT' => $report_text,
'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),