<?php
/* Include Files ***************************/
require_once('../db-config.php');
require_once('../inc/lib-compat-class.php');
require_once('../inc/lib-db-class.php');
require_once('../inc/lib-login-class.php');
/*******************************************/
global $rSdb;

$user	= new userManagement();
if(  !$user->_logged_in  )
	die(__('Access denied.','recipeshelf'));

if( ! check_ajax_referer('star-recipe', false) )
	die(__('Security Alert: Direct access not permitted!','recipeshelf'));

### Grab Options
$useroptions	= $rSdb->get_option( $user->_user_name."_options" );
$faves	 		= $useroptions['rS_favorites'];
$id				= (int)$_POST['recipe-id'];

if(  $id>0  ){

	if( is_array($faves) ){

		if( in_array($id,$faves) ){
            foreach($faves as $key => $value){
				if ($value == $id)
					unset($faves[$key]);                ### remove
			}
		    $faves = array_values($faves);
		}else
		    array_push($faves, $id);	### add

	}else ### new fave array
    	$faves = array($id);            ### new

	### save user options
	$useroptions['rS_favorites'] = $faves;
	$rSdb->update_option( $user->_user_name."_options",$useroptions );

}

echo ($_POST['status']=='false')?'1':'0';
?>