<?php
/* Include Files ***************************/
require_once('../db-config.php');
	if(  defined('LTDVERSION')  )
		die('0|DEMO VERSION!');
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('delete-recipe', false) )
	die('0|'.__('Security Alert: Direct access not permitted!','recipeshelf'));

if(  $user->_readonly  )
	die('0|'.__('Restricted for READ ONLY users.','recipeshelf'));


$rDel = 0;
$id = esc_sql( (int)$_POST['recipe-id'] );
$rSel = $rSdb->fetchRow("SELECT id FROM {$rSdb->DBrecipes} WHERE id='{$id}'");

if( $_POST['recipe-id']<>'' && $rSel->id!='' ){

	$rDel = $rSdb->fetch("DELETE FROM {$rSdb->DBrecipes} WHERE id='{$id}'");

    chdir(dirname(__FILE__).'/../photos/');
	$arrIMGs = glob(  $id.'*.*'  );
	foreach( $arrIMGs as $f )
        $r = unlink($f);

}

if( $rSel->id!='' )
	echo '1|'.__('Recipe deleted (I wanted to suggest that anyway...)','recipeshelf');
else
	echo '0|'.__('Recipe not deleted (database error).','recipeshelf');
?>