All pastes #80775 Raw Edit

Martindale

public php v1 · immutable
·published 2006-07-06 20:20 UTC
rendered paste body
// start mod save posts as drafts// in the below added code, we delete the old topic from the topics table if the post// was a draft getting finally submitted as a real post and it is the first post of the topic;// and we also in that case reset $topic_id to match the new $topic_id of the new topic inserted above;// and finally if there is a poll in the topic we change the vote_desc_table so that it now points to the new topic_id rather than the old one...		if ($was_a_draft && !$save_as_draft && $post_data['first_post'])		{			$relevant_topic_id = $topic_id;			$topic_id = $db->sql_nextid();			$sql = "DELETE FROM " . TOPICS_TABLE . " WHERE topic_id = $relevant_topic_id";			if (!$db->sql_query($sql))			{				message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);			}			if ( $topic_vote == 1 )			{				$sql = "UPDATE " . VOTE_DESC_TABLE . "					SET topic_id = $topic_id					WHERE topic_id = $relevant_topic_id";				if (!$db->sql_query($sql))				{					message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);				}			}		}// end mod save posts as drafts	}// start mod save posts as drafts	// we'll add an if !$was_a_draft clause to avoid updating the edit stats if we are dealing with a draft,	// since to the outside world the draft, when posted, should not look like it was edited	if (!$was_a_draft)	{	$edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1 " : "";	}	// in the next two lines we set post_draft to correct value so that the proper value can be inserted in the posts table	// and we set relevant_post_id to equal post_id...releavnt post id (used to find the post text in the post text table) will normally be whatever the post_id is except where we are replacing an old post_id with a new one upon taking a draft and finally submitting it...	$post_draft = ($save_as_draft) ? 1 : 0;	$relevant_post_id = $post_id;	// Below, we have added to the definition of $sql a test to see if the post was a draft that is now being submitted as a live post...if so,	// the post gets submitted as a new post with a new post_id and the old will (a bit later on) get deleted,	$sql = (($mode != "editpost") || ($was_a_draft && !$save_as_draft)) ? "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig, post_draft) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '$user_ip', $bbcode_on, $html_on, $smilies_on, $attach_sig, $post_draft)" : "UPDATE " . POSTS_TABLE . " SET post_username = '$post_username', enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig, post_draft = $post_draft" . $edited_sql . " WHERE post_id = $post_id";	// if this is already a draft getting saved again as a draft, change the $sql so that it updates the post time...	if($was_a_draft && $save_as_draft)	{	$sql = "UPDATE " . POSTS_TABLE . " SET post_username = '$post_username', post_time = $current_time, enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig, post_draft = $post_draft" . $edited_sql . " WHERE post_id = $post_id";	}// end mod save posts as drafts	if (!$db->sql_query($sql, BEGIN_TRANSACTION))	{		message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);	}	if ($mode != 'editpost')	{		$post_id = $db->sql_nextid();	}// start mod save posts as drafts// in the below added code, we delete the old post from the posts table if the post was a draft getting finally submitted as a real post; and we also in that case save the $relevant_post_id for purposes of fidning the text in the topic table and then reset $post_id to match the new $post_id of the new post inserted above		if ($was_a_draft && !$save_as_draft)		{			$relevant_post_id = $post_id;			$post_id = $db->sql_nextid();			$sql = "DELETE FROM " . POSTS_TABLE . " WHERE post_id = $relevant_post_id";			if (!$db->sql_query($sql))			{				message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);			}		}// end mod save posts as drafts	$sql = ($mode != 'editpost') ? "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($post_id, '$post_subject', '$bbcode_uid', '$post_message')" : "UPDATE " . POSTS_TEXT_TABLE . " SET post_id = '$post_id',post_text = '$post_message',  bbcode_uid = '$bbcode_uid', post_subject = '$post_subject' WHERE post_id = $relevant_post_id";// start mod save posts as drafts (and end mod too)...changed the SET part of the preceding sql definition to point to text that has $relevant_post_id (and update post_id) in case we are submitting as final a draft and as a result post_id is a new number different from the post_id where the text currently is...	if (!$db->sql_query($sql))	{		message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);	}// start mod save posts as drafts// Here, we added an if clause around the add_search_words function to prevent it from adding words from draft posts to the search indexif (!$save_as_draft){	add_search_words('single', $post_id, stripslashes($post_message), stripslashes($post_subject));}// end mod save posts as drafts	//	// Add poll	// 	if (($mode == 'newtopic' || ($mode == 'editpost' && $post_data['edit_poll'])) && !empty($poll_title) && count($poll_options) >= 2)	{		$sql = (!$post_data['has_poll']) ? "INSERT INTO " . VOTE_DESC_TABLE . " (topic_id, vote_text, vote_start, vote_length) VALUES ($topic_id, '$poll_title', $current_time, " . ($poll_length * 86400) . ")" : "UPDATE " . VOTE_DESC_TABLE . " SET vote_text = '$poll_title', vote_length = " . ($poll_length * 86400) . " WHERE topic_id = $topic_id";		if (!$db->sql_query($sql))		{			message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);		}		$delete_option_sql = '';		$old_poll_result = array();		if ($mode == 'editpost' && $post_data['has_poll'])		{			$sql = "SELECT vote_option_id, vote_result  				FROM " . VOTE_RESULTS_TABLE . " 				WHERE vote_id = $poll_id 				ORDER BY vote_option_id ASC";			if (!($result = $db->sql_query($sql)))			{				message_die(GENERAL_ERROR, 'Could not obtain vote data results for this topic', '', __LINE__, __FILE__, $sql);			}			while ($row = $db->sql_fetchrow($result))			{				$old_poll_result[$row['vote_option_id']] = $row['vote_result'];				if (!isset($poll_options[$row['vote_option_id']]))				{					$delete_option_sql .= ($delete_option_sql != '') ? ', ' . $row['vote_option_id'] : $row['vote_option_id'];				}			}		}		else		{			$poll_id = $db->sql_nextid();		}		@reset($poll_options);		$poll_option_id = 1;		while (list($option_id, $option_text) = each($poll_options))		{			if (!empty($option_text))			{				$option_text = str_replace("\'", "''", htmlspecialchars($option_text));				$poll_result = ($mode == "editpost" && isset($old_poll_result[$option_id])) ? $old_poll_result[$option_id] : 0;				$sql = ($mode != "editpost" || !isset($old_poll_result[$option_id])) ? "INSERT INTO " . VOTE_RESULTS_TABLE . " (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($poll_id, $poll_option_id, '$option_text', $poll_result)" : "UPDATE " . VOTE_RESULTS_TABLE . " SET vote_option_text = '$option_text', vote_result = $poll_result WHERE vote_option_id = $option_id AND vote_id = $poll_id";				if (!$db->sql_query($sql))				{					message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);				}				$poll_option_id++;			}		}		if ($delete_option_sql != '')		{			$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " 				WHERE vote_option_id IN ($delete_option_sql) 					AND vote_id = $poll_id";			if (!$db->sql_query($sql))			{				message_die(GENERAL_ERROR, 'Error deleting pruned poll options', '', __LINE__, __FILE__, $sql);			}		}	}	$cash_message = $GLOBALS['cm_posting']->update_post($mode, $post_data, $forum_id, $topic_id, $post_id, $topic_type, $bbcode_uid, $post_username, $post_message);	$meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">';	$message = $lang['Stored'] . '<br />' . $cash_message . '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');	return false;}