<?php
/*
Simple:Press Forum
Admin integration Update Support Functions
$LastChangedDate: 2009-12-28 20:54:01 +0000 (Mon, 28 Dec 2009) $
$Rev: 3149 $
*/

if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF']))
{
	die('Access Denied');
}

function sfa_save_integration_page_data()
{
	global $wpdb;

    check_admin_referer('forum-adminform_integration', 'forum-adminform_integration');

	$mess = '';
	$slugid = $_POST['slug'];

	if($slugid == '' || $slugid == 0)
	{
		$setslug = '';
		$setpage = 0;
	} else {
		$setpage = $slugid;
		$page = $wpdb->get_row("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = ".$slugid);
		$setslug = $page->post_name;

		if($page->post_parent)
		{
			$parent = $page->post_parent;
			while($parent)
			{
				$thispage = $wpdb->get_row("SELECT ID, post_name, post_parent FROM ".$wpdb->posts." WHERE ID = ".$parent);
				$setslug = $thispage->post_name.'/'.$setslug;
				$parent = $thispage->post_parent;
			}
		}
	}

	sf_update_option('sfpage', $setpage);
	sf_update_option('sfslug', $setslug);

	if(!$setpage)
	{
		$mess.= __("Page Slug Missing", "sforum").$endmsg;
		$mess.= __(" - Unable to determine forum permalink without it", "sforum");
	} else {
		$mess.= __('Forum Page and Slug Updated', "sforum");
		sf_update_option('sfpermalink', get_permalink($setpage));
	}

	return $mess;
}

?>