<?php
/*
Simple:Press Forum
profiles Specials
$LastChangedDate: 2009-11-13 19:08:52 -0700 (Fri, 13 Nov 2009) $
$Rev: 2965 $
*/

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

sfa_admin_ahah_support();

# Check Whether User Can Manage Profiles
if (!sfc_current_user_can('SPF Manage Profiles'))
{
	echo (__('Access Denied', "sforum"));
	die();
}

global $wpdb, $SFPATHS;

$action = $_GET['action'];

if ($action == 'delete-cfield')
{
	$id = sf_esc_int($_GET['id']);
	$cfield = sf_esc_int($_GET['cfield']);
	$fname = sf_esc_str($_GET['fname']);

	# remove the custom field
	sf_delete_sfmeta($id);

	# remove any usermeta for the custom field
	$wpdb->query("DELETE FROM ".SFUSERMETA." WHERE meta_key='".$fname."'");

	# remove from admins required/display/include field lists
	$sfprofile = sf_get_option('sfprofile');
	$nrequire = array();
	$ninclude = array();
	$ndisplay = array();

	foreach($sfprofile['require'] as $key=>$value)
	{
		if($key != $fname)
		{
			$nrequire[$key]=$value;
			$ninclude[$key]=$sfprofile['include'][$key];
			$ndisplay[$key]=$sfprofile['include'][$key];
		}
	}
	$sfprofile['require']=$nrequire;
	$sfprofile['include']=$ninclude;
	$sfprofile['display']=$ndisplay;
	sf_update_option('sfprofile', $sfprofile);

}

if ($action == 'delavatar')
{
	$file = $_GET['file'];
	$path = SF_STORE_DIR.'/'.$SFPATHS['avatar-pool'].'/'.$file;
	@unlink($path);
	echo '1';
}

die();

?>