Location: PHPKode > projects > Emilda > emilda-1.2.3/src/book_delete.php
<?php

//-----------------------------------------------------------------------------
//
// Copyright (C) 2003-2005 Oy Realnode Ab
//
//-----------------------------------------------------------------------------
//
// book_delete.php
//     Part of the Emilda Project (http://www.emilda.org/)
//
// Description
//     Book Delete.
//
// Authors
//     Christoffer Landtman <landtman (at) realnode com>
//     Erik Berglund <berglund (at) realnode com>
//     Mattias Nordstrom <nordstrom (at) realnode com>
//
//-----------------------------------------------------------------------------
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//-----------------------------------------------------------------------------
//
// $Id: book_delete.php,v 1.44 2005/01/10 22:11:49 mnordstr Exp $
//
//-----------------------------------------------------------------------------

// Id used to identify this page within functions.
$PageID = "BOOK_DELETE";

require_once "common.inc";

require_once "config.inc";
require_once "constants.inc";
require_once "db.inc";
require_once "error.inc";
require_once "layout.inc";
require_once "language.inc";
require_once "MARC.inc";
require_once "search.inc";

// New search class
$search = new Search;

layout_header();

if(isset($_REQUEST['book_id']) && $_REQUEST['book_id'] != "" && !isset($_REQUEST['action']))
{
	$plain_id = substr($_REQUEST['book_id'], 0,-1);
	// Check if borrowed
	$res = sql_query("SELECT book_id FROM books WHERE book_borrowed=1 AND book_id=".$plain_id);
	if(mysql_num_rows($res)) {
		layout_page_title(_("Item Is Borrowed"), 'error');
		unset($_REQUEST['book_id']);
	}
	// Check if reserved
	$res = sql_query("SELECT book_id FROM books WHERE book_reserved=1 AND book_id=".$plain_id);
	if(mysql_num_rows($res)) {
		layout_page_title(_("Item Is Reserved"), 'error');
		unset($_REQUEST['book_id']);
	}
}

if(isset($_REQUEST['book_id']) && $_REQUEST['book_id'] != "" && !isset($_REQUEST['action']))
{
	if(is_book_id($_REQUEST['book_id']))
	{
		$plain_id = substr($_REQUEST['book_id'], 0,-1);
		$result = sql_query("SELECT book_id, book_control_number, book_location FROM books WHERE book_id=".$plain_id);
		if(mysql_num_rows($result))
		{
			$row = mysql_fetch_array($result);
			$location = mysql_fetch_array(sql_query("SELECT location_name FROM locations WHERE location_id=".$row['book_location']));
			$headers = array(_("Book ID"), _("Location"));
			$content = array(format_book_id($row['book_id']), $location['location_name']);
			$color = 1;

			$search->init();
			$rpn = $search->ccl2rpn($search->generate_ccl(array('001' => format_control_number($row['book_control_number']))), generate_ccl_conf());
			$search->perform($rpn);
			$record = $search->next(1);
			
			$row = createMARCRow($record, return_with_format_syntax($MARC_display_in_list));

			layout_page_title(_("Step 2"));

			foreach ($MARC_display_in_list as $value)
			{
				array_push($headers, _($MARC_config_desc[$value]));
			}

			while(list($key, $value) = each($row))
			{
				array_push($content, $row[$key]);
			}
			
			$footer = "
				<form name='delete' action='book_delete.php' method='get'>
					<input type='hidden' name='id' value='". $_REQUEST['id'] . "'>
					<input type='hidden' name='auth' value='" . $_REQUEST['auth'] . "'>
					<input type='hidden' name='book_id' value='" . $_REQUEST['book_id'] . "'>
					<input type='submit' name='action' class='button' value='" . _("Delete") . "'>
				</form>
			";

			$my_table =& new Table($headers);
			$my_table->add_row($content);
			$my_table->set_footer($footer);
			$my_table->render();

		}
		else {
			layout_page_title(_("No Such Item Exists"), 'error');
			unset($_REQUEST['book_id']);
		}
	}
	else {
		layout_page_title(_("Invalid Item ID"), 'error');
		unset($_REQUEST['book_id']);
	}
}

if(	(!isset($_REQUEST['book_id']) && !isset($_REQUEST['action'])) ||
	(isset($_REQUEST['book_id']) && !isset($_REQUEST['action']) && !is_book_id($_REQUEST['book_id'])) ||
	(isset($_REQUEST['book_id']) && isset($_REQUEST['action'])))
{
	if(isset($_REQUEST['book_id']) && !is_book_id($_REQUEST['book_id'])) {
		layout_page_title(_("Invalid Item ID"), 'error');
	}

	if(isset($_REQUEST['book_id']) && isset($_REQUEST['action']))
	{
		if(is_book_id($_REQUEST['book_id']))
		{
			$old = mysql_fetch_array(sql_query("SELECT * FROM books WHERE book_id=".raw_book_id($_REQUEST['book_id'])));
			$new = sql_query("INSERT INTO deleted_books SET
									del_book_id=".$old['book_id'].",
									del_book_control_number=".$old['book_control_number'].",
									del_book_date_added=".$old['book_date_added'].",
									del_book_date_deleted=NOW(),
									del_book_borrowed=0,
									del_book_reserved=0,
									del_book_borrow_count=".$old['book_borrow_count'].",
									del_book_location=".$old['book_location']);
			$res = sql_query("DELETE FROM books WHERE book_id=".raw_book_id($_REQUEST['book_id']));
			if(mysql_affected_rows()) {
				layout_page_title(_("Item Deleted"), 'ok');
				// Logging
				writeLog("Item ".format_book_id($old["book_id"])." has been deleted");
			}
			else {
				layout_page_title(_("Delete Failed"), 'error');
			}
		}
		else
			layout_page_title(_("Invalid Item ID"), 'error');
	}

	layout_page_title(_("Step 1"));

	?>

	<form name='book_delete' action='book_delete.php' method='get'>
		<input type='hidden' name='id' value='<?php echo $_REQUEST['id']?>'>
		<input type='hidden' name='auth' value='<?php echo $_REQUEST['auth']?>'>
		<?php echo _("Item ID") ?>:&nbsp;<input type='text' name='book_id' size=20>
		&nbsp;&nbsp;<input type='submit' name='submit' class='button' value='<?php echo _("Continue") ?>'>
	</form>

	<?php
}

layout_footer();

// Terminate connection
$search->terminate();

?>
Return current item: Emilda