<?php
//-----------------------------------------------------------------------------
//
// Copyright (C) 2003-2005 Oy Realnode Ab
//
//-----------------------------------------------------------------------------
//
// book_edit.php
// Part of the Emilda Project (http://www.emilda.org/)
//
// Description
// Book Edit.
//
// 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_edit.php,v 1.70.2.2 2005/03/17 12:02:43 eberglun Exp $
//
//-----------------------------------------------------------------------------
// Id used to identify this page within functions.
$PageID = "BOOK_EDIT";
require_once "common.inc";
require_once "config.inc";
require_once "constants.inc";
require_once "layout.inc";
require_once "language.inc";
require_once "search.inc";
require_once "MARC.inc";
require_once "mgmnt.inc";
// New search class.
$search = new Search;
layout_header();
if((isset($_REQUEST['book_id']) || isset($_REQUEST['book_control_number'])) && !isset($_REQUEST['result']))
{
if(isset($_REQUEST['book_id']) && !is_book_id($_REQUEST['book_id'])) {
layout_page_title(_("Invalid Item ID"), 'error');
unset($_REQUEST['book_id']);
unset($_REQUEST['book_control_number']);
}
else
{
if(isset($_REQUEST['book_id']) && is_book_id($_REQUEST['book_id']))
$_REQUEST['book_id'] = raw_book_id($_REQUEST['book_id']);
if(isset($_REQUEST['book_id']) && (!isset($_REQUEST['book_control_number']) || $_REQUEST['book_control_number'] == ""))
{
$result = sql_query("SELECT book_control_number FROM books WHERE book_id='" . $_REQUEST['book_id'] . "'");
if(mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$_REQUEST['book_control_number'] = format_control_number($row['book_control_number']);
$book_exists = 1;
}
else {
$book_exists = 0;
}
}
else {
$book_exists = 1;
}
if($book_exists)
{
$url = "";
$from_page = $PageID;
$session = mysql_fetch_array(sql_query("SELECT session_last_page FROM sessions WHERE session_id='" . $_REQUEST['id'] . "'"));
$history = explode(':', $session['session_last_page']);
if ($history[1] != $PageID) {
$from_page = $history[1];
}
// Returning to redirect will cause errors, as variables do not exist.
if($from_page == "REDIRECT") {
$from_page = $PageID;
}
$search->init();
$search->search_by_cn($_REQUEST['book_control_number']);
$record = $search->next(1);
$MARC_raw = $search->additional("raw");
$row = createMARCRow_edit($record, $MARC_editable);
//if(isset($_REQUEST['search_criteria']) && isset($_REQUEST['search_query']) && isset($_REQUEST['search_position']))
// $back_url = "search.php?id=".$_REQUEST['id']."&auth=".$_REQUEST['auth']."&criteria=".$_REQUEST['search_criteria']."&query=".$_REQUEST['search_query']."&position=".$_REQUEST['search_position'];
layout_page_title(_("Step 2"));
//if($back_url)
// print "<a href='".$back_url."'>(- ".$langText['BACK_TO_SEARCH']." -)</a><br><br>";
?>
<form name='book_edit' action='perl/MARC.pl' method='post' onSubmit="create_csv(this.subjects, this.subjects_csv);">
<input type='hidden' name='id' value='<?php echo $_REQUEST['id']?>'>
<input type='hidden' name='auth' value='<?php echo $_REQUEST['auth']?>'>
<input type='hidden' name='perl_id' value='<?php echo $config['perl_id']?>'>
<input type='hidden' name='perl_auth' value='<?php echo md5($config['perl_auth'])?>'>
<input type='hidden' name='from_page' value='<?php echo strtolower($from_page) ?>'>
<input type='hidden' name='url' value='<?php echo $url ?>'>
<input type='hidden' name='raw_marc' value='<?php echo $MARC_raw ?>'>
<input type='hidden' name='native_cn' value='<?php echo $_REQUEST['book_control_number'] ?>'>
<input type='hidden' name='copies' value='zero'>
<?php
$my_table =& edit_table($record);
if(isset($_REQUEST['exact_query']) && $_REQUEST['exact_query'] != "")
{
$back = "<input type='button' class='button' value='<< " . _("Back") .
"' onClick='location.href=\"search.php?id=" . $_REQUEST['id'] .
"&auth=" . $_REQUEST['auth'] .
"&criteria=" . $_REQUEST['search_criteria'] .
"&query=" . $_REQUEST['search_query'] .
"&position=" . $_REQUEST['search_position'] .
"&url=".$url .
"&location=".$_REQUEST['search_location'] .
"&exact_query=".$_REQUEST['exact_query'];
if (isset($_REQUEST['in_shelf'])) $back .= "&in_shelf";
if (isset($_REQUEST['not_reserved'])) $back .= "¬_reserved";
$back .= "\"'>";
}
else
{
$back = "<input type='button' class='button' value='<< " . _("Back") . "' onClick='history.go(-1);'>";
}
$footer = '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" valign="bottom">
' . $back . '
</td>
<td align="right" valign="bottom">
<input type="reset" name="reset" class="button" value="' . _("Reset") . '">
<input type="submit" name="submit" class="button" value="' . _("Accept") . ' >>">
</td>
</tr>
</table>
';
$my_table->set_footer($footer);
$my_table->render();
print '</form>';
// Logging
writeLog("Item ".format_book_id($_REQUEST["book_control_number"])." has been edited");
}
else {
layout_page_title(_("No Such Item Exists"), 'error');
unset($_REQUEST['book_id']);
unset($_REQUEST['book_control_number']);
}
}
}
if((!isset($_REQUEST['book_id']) && !isset($_REQUEST['book_control_number'])) || isset($_REQUEST['result']))
{
if(isset($_REQUEST['result'])) {
if ($_REQUEST['result'] == 'success') {
$result = _("Item Edited");
$class = 'ok';
}
else {
$result = _("Edit Failed");
$class = 'error';
}
layout_page_title($result, $class);
}
layout_page_title(_("Step 1"));
?>
<form name='book_edit' action='book_edit.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") ?>: <input type='text' name='book_id' size=20>
<input type='submit' name='submit' class='button' value='<?php echo _("Edit") ?>'>
</form>
<?php
}
// Terminate search connection
$search->terminate();
layout_footer();
?>