Page MenuHomec4science

viewEditSubmissionEDS.php.wml
No OneTemporary

File Metadata

Created
Sat, Jul 20, 23:58

viewEditSubmissionEDS.php.wml

## $Id$
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002 CERN.
##
## The CDSware 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.
##
## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
<?
require("commonPhpFunctions.php");
?>
#include "cdspage.wml" \
title="Submission Pages of <protect><?print "$subname";?></protect>" \
navtrail_previous_links="<a class=navtrail href=<WEBURL>/admin/<lang:star: index.*.html>><MSG_ADMIN_AREA></a> &gt; <a class=navtrail href=<WEBURL>/admin/websubmit/><MSG_ADMIN_SUBMIT></a>" \
navbar_name="admin" \
navbar_select="websubmit"
<?
<protect>
## $Id$
## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
?>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide
function checkRequired(param)
// This is a function to ensure that the user enters the required
// parameter for the action.
// Author: Nicholas Robinson
// Email: Nicholas.Robinson@cern.ch
// ca8nro@yahoo.co.uk
// Created: Long ago!
// Last Modified: 23/11/2000
{
// If the field is left blank by the user...
if((param == "") || ((param.toUpperCase() != "Y") &&
(param.toUpperCase() != "N") && (param.toUpperCase() != "O")))
{ // Alert them, and return false.
alert("You must enter a value of Y, N, or O in the displayed field.");
return false;
} // End if
else // If displayed has been filled by the user...
{
return true;
} // End else
} // End function checkRequired(param)<
function verifyChanges(curLevel, sugLevel, curButtonorder, sugButtonorder,
curStatustext, sugStatustext)
// Function to test whether the values for the parameters to be changed
// have actually been changed by the user when they submit them to the
// database for update. If not, the function returns false. If so, the
// function returns true.
// Author: Nicholas Robinson
// Email: Nicholas.Robinson@cern.ch
// Created: 27/07/2000
// Last Modified: 23/11/2000
{
if(((curLevel == sugLevel) || (sugLevel == curLevel.toLowerCase())) &&
(curButtonorder == sugButtonorder) &&
(curStatustext == sugStatustext))
{
alert("No Change In The Data Has Been Made! Cannot Submit.");
return false;
} // End if
else
{
return true;
} // End else
} // End function verifyChanges()
// -->
</SCRIPT>
<?php
/*********************Function Descriptions***************************/
function displayEDSsubDetsForm($subname, $doctype)
{
/*******************************************************************
This function has the task of actually creating the main page
that shows the details of a submission. It conducts the query,
and from this data, builds an HTML form containing the details of
the given submission type. The user can then alter these details
as they see fit. Links to the pages that the submission is
composed of are also provided. The user can follow these links
to see the details of each of these pages.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 23/11/2000
Last Modified: 15/03/2001
*******************************************************************/
global $IMAGES;
# Execute a select query top get the data for the given submission
$queryResult = mysql_query("SELECT * FROM sbmIMPLEMENT WHERE subname ="
. " '$subname'");
# Now check to ensure that the query executed correctly
if($queryResult)
{
# Everything was fine with the query
# Now check the No. rows returned by the query (should be 1)
if(mysql_num_rows($queryResult) == 1)
{
# In this case, everything is as expected...
# Now, display a quick set of page instructions for the user..
print("<TABLE WIDTH='90%' BGCOLOR='#D3DCE3' ALIGN='center' "
. "CELLSPACING=0 CELLPADDING=0 BORDER=1>\n<TR><TD "
. "ALIGN='center'>\n<P STYLE=\"color: blue; text-align: "
. "center; font-size: small; font-weight: bold\">Shown below,"
. " are the details of the \"$subname\" EDS submission.<BR>"
. "Each page number is a link that when clicked, allows you "
. " to further view and or edit the details of that page.<BR>"
. "<BR><BR>It is "
. "also possible to add another page to this submission. "
. "Click \"ADD PAGE\" to do this.</P>\n"
. "</TD>\n</TR>\n</TABLE>\n");
# Make a horizontal rule to divide the page sections...
drawSeparator();
# Now, we can display the details of the submission in a table
print("<FORM ACTION='viewEditSubmissionEDS.php' METHOD='post'"
. ">\n<INPUT TYPE='hidden' NAME='update' VALUE='true'>\n"
. "<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'>"
. "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN='center"
. "' WIDTH='100%'>\n");
# Now make the table: names & fields...
# Get a list of the columns in the sbmIMPLEMENT table...
$columns = mysql_list_fields(DOCS_DATABASE, "sbmIMPLEMENT");
# Get the number of fields
$numTblFlds = mysql_num_fields($columns);
# Get the row of data
$dataRow = mysql_fetch_array($queryResult);
# Before we display most of the table, we can first display
# the upper part of the table, which will contain fields
# should be seen, but not be modifiable...
print("<TABLE WIDTH='100%' ALIGN='center' CELLSPACING=0 "
. "CELLPADDING=0 BORDER=0>\n<TR>\n<TH BGCOLOR='#D3DCE3' ALIGN"
. "='right' WIDTH='20%'>\nSubmission Code:&nbsp;</TH>\n<TD "
. "ALIGN='left' BGCOLOR='#FFFFCC' WIDTH='80%'><INPUT "
. "TYPE='readonly' NAME='subname' VALUE='"
. $dataRow["subname"] . "'>\n</TD>\n</TR>\n<TR>\n<TH "
. "BGCOLOR='#D3DCE3' ALIGN='right' WIDTH='20%'>\nNumber of "
. "Pages:&nbsp;</TH>\n<TD WIDTH='80%' ALIGN='left' BGCOLOR="
. "'#FFFFCC'><INPUT TYPE='readonly' NAME='nbpg' VALUE='"
. $dataRow["nbpg"] . "'>\n</TD>\n</TR>\n<TR>\n<TH "
. "BGCOLOR='#D3DCE3' ALIGN='right' WIDTH='20%'>\nCreation "
. "Date:&nbsp;</TH>\n<TD WIDTH='80%' ALIGN='left' BGCOLOR="
. "'#FFFFCC'><INPUT TYPE='readonly' NAME='cd' VALUE='"
. $dataRow["cd"] . "'>\n</TD>\n</TR>\n<TR>\n<TH WIDTH='20%'"
. " BGCOLOR='#D3DCE3' ALIGN='right'>\nModification "
. "Date:&nbsp;</TH>\n<TD WIDTH='80%' ALIGN='left' "
. "BGCOLOR='#FFFFCC'><INPUT TYPE='readonly' NAME='md' "
. "VALUE='" . $dataRow["md"] . "'>\n</TD>\n</TR>\n");
# Now fill this new table with all of the details...
for($indx = 0; $indx < $numTblFlds; $indx++)
{
# Get the name of the current field...
$currentField = mysql_field_name($columns, $indx);
# Ensure that we don't once again print our non-editable
# fields out...
} // END for
# Now add the list of pages into the equation...
print("<TR>\n<TH BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>"
. "\nSubmission Pages:&nbsp;</TH>\n<TD ALIGN='left' WIDTH="
. "'80%' BGCOLOR='#FFFFCC'>\n");
# Display a link to each page...
print("<TABLE BORDER=0 ALIGN='left' CELLPADDING=0 CELLSPACING"
. "=0><TR>");
for($count = 1; $count <= $dataRow["nbpg"]; $count++)
{
print("<TD ALIGN='center'>[<A HREF='pageDetsEDS.php?subna"
. "me=" . $dataRow["subname"] . "&pageNumber=$count&nPgs="
. $dataRow["nbpg"] . "&doctype=$doctype'>"
. $dataRow["subname"] . " Page $count</A>]&nbsp;</TD>");
} // END for
print("</TR>\n<TR>\n");
# Now add "move a page higher in the order" and "move a page
# lower in the order" buttons...
for($count = 1; $count <= $dataRow["nbpg"]; $count++)
{
print("<TD ALIGN='center'><TABLE BORDER=0 CELLSPACING=0 "
. "CELLPADDING=0 ALIGN='center'><TR><TD ALIGN='center'>");
# Test to see if this is the first page or the last page.
# If so, then we must only print an image <IMG> of an
# arrow, as opposed to an <A><IMG></A> arrow, as we don't
# want the page to be moved beyond the page 1, or page x
# (at the end) boundaries.
# Add the "left" arrow...
if($count == 1)
{
# Only use a picture
print("<IMG SRC='".$IMAGES."/forbidden_left.gif' ALT='"
. "Unable To Increase Page Order Weighting: Already "
. "First Page!' HEIGHT=14 WIDTH=14>");
} // END if
else
{
print("<A HREF='viewEditSubmissionEDS.php?doctype="
. "$doctype&pageNumber=$count&nPgs=" . $dataRow["nbpg"]
. "&subname=" . $dataRow["subname"] . "&pageLeft=true'"
. " onClick=\"if(confirm('Taking this action will move "
. "a page and all of its elements one page sooner in "
. "the page order sequence.\\nAre you sure you want to "
. "do this?')) { return true; } else { return false; "
. "}\"><IMG BORDER=0 SRC='".$IMAGES."/left.gif' ALT='Incre"
. "ase Page Weighting Order...' HEIGHT=14 WIDTH=14>"
. "</A>");
} // END else
print("</TD><TD ALIGN='center'>");
# Add the "right" arrow...
if($count == $dataRow["nbpg"])
{
# Last page, so only use a picture
print("<IMG SRC='".$IMAGES."/forbidden_right.gif' ALT='"
. "Unable To Decrease Page Order Weighting: Already "
. "Last Page!' HEIGHT=14 WIDTH=14>");
} // END if
else
{
print("<A HREF='viewEditSubmissionEDS.php?doctype="
. "$doctype&pageNumber=$count&nPgs=" . $dataRow["nbpg"]
. "&subname=" . $dataRow["subname"] . "&pageRight=true'"
. " onClick=\"if(confirm('Taking this action will move "
. "a page and all of its elements one page later in the"
. " page order sequence.\\nAre you sure you want to do "
. "this?')) { return true; } else { return false; }\">"
. "<IMG BORDER=0 SRC='".$IMAGES."/right.gif' ALT='Decreas"
. "e Page Weighting Order...' HEIGHT=14 WIDTH=14></A>");
} // END else
print("</TD></TR></TABLE></TD>\n");
} // END for
print("</TR>\n<TR>\n");
# Now add a delete button for each page of the submission
for($count = 1; $count <= $dataRow["nbpg"]; $count++)
{
print("<TD ALIGN='center'><A HREF='viewEditSubmissionEDS."
. "php?doctype=$doctype&pageNumber=$count&nPgs="
. $dataRow["nbpg"] . "&subname=" . $dataRow["subname"]
. "&deletePage=true' onClick=\"if(confirm('Warning: Taking"
. " this action will delete this submission page and all "
. "of the elements on it.\\nThis action is irreversable!"
. "\\nAre you sure you want to do this?'))"
. "{ return true; } else { return false; }\"><IMAGE "
. "SRC='".$IMAGES."/answer_bad.gif' BORDER=0 WIDTH=12 HEIGHT="
. "12 ALT='Delete Page And All Elements'></A></TD>");
} // END for
# Now close up the inner table...
print("</TR>\n</TABLE>");
# Now that the table has been filled with all of the actions
# details, it can be closed..
print("&nbsp;</TD>\n</TR>\n</TABLE>\n</TABLE>\n");
# Now make the buttons (SAVE CHANGES, ADD PAGE, and FINISH)...
print("<TABLE ALIGN='center' CELLSPACING=2 CELLPADDING=0 "
. "BORDER=0><TR><TD ALIGN='center'></TD></FORM>"
. "<FORM ACTION='viewEditSubmissionEDS.php' METHOD='post'>"
. "<INPUT TYPE='hidden' NAME='nPgs' VALUE='"
. $dataRow["nbpg"] . "'>"
. "<INPUT TYPE='hidden' NAME='addPage' VALUE='true'><INPUT "
. "TYPE='hidden' NAME='subname' VALUE='$subname'><INPUT TYPE="
. "'hidden' NAME='doctype' VALUE='$doctype'><TD><INPUT "
. "TYPE='button' VALUE='ADD A PAGE' onClick=\"if(confirm('Are"
. " You Certain You Wish To Add Another Page To This "
. "Submission?')) { submit(); } else { return false; }\">"
. "</TD></FORM><FORM ACTION='documentEDS.php' METHOD='post'>"
. "<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'><TD>"
. "<INPUT TYPE='button' VALUE='FINISHED' onClick=\"submit();"
. "\"></TD></FORM></TR></TABLE>");
} // END if
elseif(mysql_num_rows($queryResult) > 1)
{
# Oops, we have too many rows in the result set. This
# indicates some sort of key duplication in the sbmIMPLEMENT
# table.
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">"
. "ERROR:</SPAN> More "
. "than one row of data concerning the <EM>$subname</EM> "
. "action was returned from the <EM>sbmIMPLEMENT</EM> table of "
. "the" . DOCS_DATABASE . " database.<BR>This indicates "
. "primary key duplication in this table.<BR>Please inform "
. "system administrator.</P>\n");
# Send a mail to the system admin people to warn them about
# this serious error..
$msgTxt = "When a user attempted to look further into the "
. "details of the $subname submission using the EDS "
. "Administrator, several rows were returned for this "
. "submission from the sbmIMPLEMENT table."
. " The query was made using the \"subname\" as the search"
. " key. As the \"subname\" field is the primary key for "
. "the sbmIMPLEMENT table, this means that there must be key "
. "violations in this table.\n\nThis problem should be "
. "corrected immediately.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "sbmIMPLEMENT Table Key Violation!", $msgTxt,
"From: WebSubmit_Administrator");
} // END elseif
elseif(mysql_num_rows($queryResult) == 0)
{
# Oops, we have no rows returned...how can this be?
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">"
. "ERROR:</SPAN> No data concerning the <EM>$subname</EM> "
. "submission was found in the <EM>sbmIMPLEMENT</EM> table.<BR>"
. "This suggests a data consistency error in the "
. DOCS_DATABASE . " database.<BR>Please inform the system "
. "administrator.</P>\n");
# Now send an email to the administrator(s) to inform them of
# this serious error...
$msgTxt = "When a user attempted to look further into the "
. "details of the $subname submission using the EDS "
. "Administrator, no rows were returned from the sbmIMPLEMENT "
. "table for this submission.\n\nBecause the user had to "
. "click a link to view the details of this submission, it "
. "must be referred to in other tables of EDS. This suggests"
. " that there are data inconsistencies within EDS.\n\nThis "
. "should be investigated and corrected ASAP.\n\nEDS "
. "Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "Possible Data Inconsistency Error!",
$msgTxt, "From: WebSubmit_Administrator");
} // END elseif
else
{
# Some sort of weird query error must have ocurred.
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">"
. "ERROR:</SPAN> Unable to correctly retrieve data from the "
. "<EM>sbmIMPLEMENT</EM> table of " . DOCS_DATABASE
. ".<BR>Please inform system administrator.</P>\n");
} // END else
} // END if
else
{
# In this case, the query failed...
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">ERROR:"
. "</SPAN> Unable to query the <EM>sbmIMPLEMENT</EM> table.<BR>"
. "Please inform system administrator.</P>\n");
} // END else
} // END function displayEDSsubDetsForm($subname, $doctype)
//**************
function moveSubPage($doctype, $pageNumber, $nPgs, $subname,
$page2move2)
{
/*****************************************************************
This function has the task of moving a page either to the left,
or to the right, depending upon which direction button the user
has pressed for the movement. The function is passed a variable
$page2move2, which holds the value of the page that the current
page is to be moved to. This must always be either $pageNumber
+ 1, or $pageNumber - 1. This is important, and the way that I
have written this script will only call this function in the
correct manner. This function should not be used for swapping
pages that are separated by other pages, as that should not be
done. If a page is ever to be moved to a location several pages
away, the other pages should be displaced like dominos into the
position to fill the gap!
This function saves a lot of code duplication, as there are many
errors that could happen during the execution of a page movement.
Some of these errors could be rather serious, and so it is
necessary to give both the user amd the system administrator a
detailed explanation of what has happened in each case. This
means big error message sections.
In the EDS database, there is no such entity as a "submission
page". Instead, there are elements, which have a page number and
a submission name. This means that when we move a page, we must
first move all of the elements on it to a temporary page. In
this case, the chosen temporary page number is 0. Next, all
elements on the page whose position our page is being moved to
are given a page number of that of the page that we are moving.
Finally, all of the elements with a page number of 0 are given a
page number of the position that we wanted to move the page to.
This is how this function works - a simple "swap" algorithm.
In the even of an error occurring, the function attempts to put
everything back to the way it was when it started the movement.
Of course this may not be possible. The function gives error
message feedback at all stages possible, letting the admin/user
know whether or not recovery succeeded etc, or where it failed,
and offers suggestions on how to correct the problems.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 18/12/2000
Last Modified: 18/12/2000
*****************************************************************/
# Get the current date for the "md" field...
$modifiedDate = makeEDSmdDate();
# Make a query string to set the 'pagenb' field of all elements on
# the current page to '0' (zero). Done as a temporary measure for
# swapping pages around.
$qStr1 = "UPDATE sbmFIELD SET pagenb = '0' WHERE subname = '$subname'"
. " AND pagenb = '$pageNumber'";
# Now execute the query
$qRes1 = mysql_query($qStr1);
if($qRes1)
{
# Query worked fine, so carry on alterring values
# Set the value of the pagenb field for all elements of the page
# before the page to be moved to have a pagenb value of the
# current page (that which we are moving).
$qStr2 = "UPDATE sbmFIELD SET pagenb = '$pageNumber', md = '"
. "$modifiedDate' WHERE subname = '$subname' AND pagenb = '"
. "$page2move2'";
# Now execute the query
$qRes2 = mysql_query($qStr2);
if($qRes2)
{
# In this case, the query was fine, and we have just moved all
# elements of the page that was before the page we are moving
# to effectively be in the place of the page that we are
# moving...i.e. the page before it now sits in its place.
# Now make a query string to move the elements that are on
# "page zero" to their final position...
$qStr3 = "UPDATE sbmFIELD SET pagenb = '$page2move2"
. "', md = '$modifiedDate' WHERE subname = '$subname' AND "
. "pagenb = '0'";
# Now execute this query...
$qRes3 = mysql_query($qStr3);
if($qRes3)
{
# In this case, the query has been successful, and we
# should now have fully switched our pages around. We
# should now update the md field of the submission in
# sbmIMPLEMENT, and the doctype in sbmDOCTYPE...
# Update the submissions md field...
$mdResult = mysql_query("UPDATE sbmIMPLEMENT SET md = "
. "'$modifiedDate' WHERE subname = '$subname'");
if($mdResult)
{
# Free the result left by this update
mysql_free_result($mdResult);
} // END if
else
{
# The update the date query has failed for some reason
print("<SCRIPT LANGUAGE=\"JavaScript\">alert('Error: "
. "Couldn't update the md in sbmIMPLEMENT!');</SCRIPT>\n");
} // END else
# We must also modify the md field of the doctype record to
# which this submission belongs
updateEDSDOCTYPEmd($doctype, $modifiedDate);
# Now alert the user of the success
print("<SCRIPT TYPE='text/javascript'>\nalert('Page Moved "
. "Successfully.');\n</SCRIPT>\n");
# Now let the admin know of the page movement...
$msgTxt = "Page $pageNumber of the $subname submission of "
. "the $doctype document type has been moved to another "
. "position.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Page Movement",
$msgTxt, "From: WebSubmit_Administrator");
} // END if
else
{
# Nightmare! We now have really messed up data. We have
# the data of the page we wanted to move on a temporary
# page 0. The data of the page whose position we wanted to
# move our original page to is now on our original page!
# The final thing is that we now can't move our data from
# page zero to its final location. I think the best thing
# to do here is to attempt to move the data that is now on
# the original page (the elements we moved in query 2, to
# their original position, and then move the data from page
# Zero back to our current page - hence undoing the whole
# lot of trouble. Hope it works!
$majorRecoveryStr1 = "UPDATE sbmFIELD SET pagenb = '"
. "$page2move2' WHERE subname = '$subname' AND "
. "pagenb = '$pageNumber'";
$majorRecoveryRes1 = mysql_query($majorRecoveryStr1);
if($majorRecoveryRes1)
{
# Nice...first step recovered! Now attempt to return
# the elements on page 0 to their original page...
$majorRecoveryStr2 = "UPDATE sbmFIELD SET pagenb = '"
. "$pageNumber' WHERE subname = '$subname' AND pagenb ="
. " '0'";
$majorRecoveryRes2 = mysql_query($majorRecoveryStr2);
if($majorRecoveryRes2)
{
# Very nice....we have managed to completely recover
# from the whole mess, so we can just inform the user
# that the page movement did not work. Phew!
print("<SCRIPT TYPE='text/javascript'>\nalert('An "
. "error occurred when an attempt was made to move "
. "the requested submission page.\\nWhen a "
. "submission page is moved, all of "
. "the elements on the page to be moved are given a"
. " temporary page number of 0.\\nThe elements of "
. "the page whose position it is to be moved to are"
. " then given a page number of the current page\\n"
. "and then the elements with a page number of 0 are"
. " then given a page number of the page that they "
. "are to be moved to.\\n\\nWhen this page movent "
. "was carried out however, the elements of page to"
. " be moved were moved to\\npage 0 without trouble."
. " The elements of the page whose position the "
. "page to be moved to was to be moved to\\nwere "
. "moved to the position of the page to be moved "
. "without any problem.\\nHowever, when an attempt "
. "was made to move the elements of the temporary "
. "page 0\\nto their new location, this was not "
. "possible.\\n\\nTo rectify this situation, an "
. "attempt was made to return the elements that were"
. " moved to page $pageNumber\\nback to page "
. "$page2move2, which suceeded. An attempt"
. " was then made to move all elements from\\nthe "
. "temporary page 0 back to page $pageNumber (the "
. "page on which they were originally positioned)."
. "\\nThis attempt succeeded.\\n\\nThis means that "
. "the $subname submission should appear as if it "
. "were never changed.\\nYou should however ensure "
. "that the pages of this submission are "
. "un-corrupted by checking each page manually.\\n"
. "\\nYou should inform the system administrator of "
. "this problem.');\n</SCRIPT>\n");
# Now email the administrator and say the same thing
$msgTxt = "A major problem has ocurred with the data"
. " for the $subname submission. An attempt was "
. "made to move page $pageNumber to another position"
. ".\n\nWhen a page is moved, all of the elements on"
. " the page to be moved are given a temporary page "
. "number of 0. The elements of the page whose "
. "position it is to be moved to are then given a "
. "page number of the current page and then the "
. "elements with a page number of 0 are then given a"
. " page number of the page that they are to be "
. "moved to.\n\nWhen this page movent was carried "
. "out for page $pageNumber however, the "
. "elements of page to be moved were moved to page 0"
. " without trouble. The elements of the page whose"
. "position page $pageNumber was to be moved to were"
. " moved to the position of page $pageNumber "
. "without any problem. However, when an attempt "
. "was made to move the elements of the temporary "
. "page 0 to their new location, this was not "
. "possible.\n\nTo rectify this situation, an "
. "attempt was made to return the "
. "elements that were moved to page $pageNumber back"
. " to page $page2move2, which suceeded. "
. " When an attempt was made to move the elements of"
. " the temporary page 0 back to page $pageNumber, "
. "this also succeeded.\n\nThis all means that the "
. "submission SHOULD look as though it were never "
. "altered, and the pages should appear as normal, "
. "as the system correction of the problem appears "
. "to have succeeded. However, you should manually"
. " check this submission to ensure that this is the"
. " case, as it is possible that some elements from "
. "the pages may have been lost.\n\nEDS "
. "Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Page Movement"
. " Error", $msgTxt, "From: WebSubmit_Administrator");
} // END if
else
{
# Couldnt return our page 0 elements to their orig
# page.
# Let the user know
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR"
. ": A major problem has ocurred with the data for "
. "this submission.\\nWhen a page is moved, all of "
. "the elements on the page to be moved are given a"
. " temporary page number of 0.\\nThe elements of "
. "the page whose position it is to be moved to are"
. " then given a page number of the current page\\n"
. "and then the elements with a page number of 0 are"
. " then given a page number of the page that they "
. "are to be moved to.\\n\\nWhen this page movent "
. "was carried out however, the elements of page to"
. " be moved were moved to\\npage 0 without trouble."
. " The elements of the page whose position the "
. "page to be moved to was to be moved to\\nwere "
. "moved to the position of the page to be moved "
. "without any problem.\\nHowever, when an attempt "
. "was made to move the elements of the temporary "
. "page 0\\nto their new location, this was not "
. "possible.\\n\\nTo rectify this situation, an "
. "attempt was made to return the elements that were"
. " moved to page $pageNumber\\nback to page "
. "$page2move2, which suceeded. When an "
. " attempt was made to move the elements of the "
. "temporary page 0 back to page $pageNumber,\\nthis"
. " failed, therefore the elements that were "
. "origionally on page $pageNumber before the move "
. "was attempted\\nare now sitting on the temporary"
. " page 0. This means that when an attempt is made "
. "to view the elements of page $pageNumber,\\nthere"
. " will be nothing there.\\n\\nPlease inform the "
. "system administrator of this problem immediately "
. "so that it can be corrected.');\n</SCRIPT>\n");
# Now email the sys admin to let them know
$msgTxt = "A major problem has ocurred with the data"
. " for the $subname submission. An attempt was "
. "made to move page $pageNumber to another position"
. ".\n\nWhen a page is moved, all of the elements on"
. " the page to be moved are given a temporary page "
. "number of 0. The elements of the page whose "
. "position it is to be moved to are then given a "
. "page number of the current page and then the "
. "elements with a page number of 0 are then given a"
. " page number of the page that they are to be "
. "moved to.\n\nWhen this page movent was carried "
. "out for page $pageNumber however, the "
. "elements of page to be moved were moved to page 0"
. " without trouble. The elements of the page whose"
. "position page $pageNumber was to be moved to were"
. " moved to the position of page $pageNumber "
. "without any problem. However, when an attempt "
. "was made to move the elements of the temporary "
. "page 0 to their new location, this was not "
. "possible.\n\nTo rectify this situation, an "
. "attempt was made to return the "
. "elements that were moved to page $pageNumber back"
. " to page $page2move2, which suceeded. "
. " When an attempt was made to move the elements of"
. " the temporary page 0 back to page $pageNumber, "
. "this failed, therefore the elements that were "
. "origionally on page $pageNumber before the move "
. "was attempted are now sitting on the temporary "
. "page 0.\n\nYou can probably correct this problem "
. "by using the following query. However, you "
. "should investigate first, as this is only a "
. "suggestion.\n\nUPDATE sbmFIELD SET pagenb = '"
. "$pageNumber' WHERE pagenb = '0' AND subname = '"
. "$subname';\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Page Movement"
. " Error", $msgTxt, "From: WebSubmit_Administrator");
} // END else
} // END if
else
{
# In this case, we couldn't recover from the major error
# at all....We must let both the user & admin know.
# Let the user know.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: "
. "A major problem has ocurred with the data for "
. "this submission.\\nWhen a page is moved, all of "
. "the elements on the page to be moved are given a"
. " temporary page number of 0.\\nThe elements of "
. "the page whose position it is to be moved to are"
. " then given a page number of the current page\\n"
. "and then the elements with a page number of 0 are"
. " then given a page number of the page that they "
. "are to be moved to.\\n\\nWhen this page movent "
. "was carried out however, the elements of page to"
. " be moved were moved to\\npage 0 without trouble."
. " The elements of the page whose position the "
. "page to be moved to was to be moved to\\nwere "
. "moved to the position of the page to be moved "
. "without any problem.\\nHowever, when an attempt "
. "was made to move the elements of the temporary "
. "page 0\\nto their new location, this was not "
. "possible.\\n\\nTo rectify this situation, an "
. "attempt was made to return the elements that were"
. " moved to page $pageNumber\\nback to page "
. "$page2move2.\\nThis attempt failed, "
. "which meant that the elements on page 0 could not"
. " be moved to page $pageNumber\\nas there are "
. "already elements belonging to another page on "
. "there.\\n\\nThe system can do no more to fix this"
. " problem, and you should contact the system "
. "administrator immediately\\nto ensure that this "
. "situation is rectified.');\n</SCRIPT>\n");
# Let the administrator know...
$msgTxt = "A major problem has ocurred with the data"
. " for the $subname submission. An attempt was "
. "made to move page $pageNumber to another position"
. ".\n\nWhen a page is moved, all of the elements on"
. " the page to be moved are given a temporary page "
. "number of 0. The elements of the page whose "
. "position it is to be moved to are then given a "
. "page number of the current page and then the "
. "elements with a page number of 0 are then given a"
. " page number of the page that they are to be "
. "moved to.\n\nWhen this page movent was carried "
. "out for page $pageNumber however, the "
. "elements of page to be moved were moved to page 0"
. " without trouble. The elements of the page whose"
. "position page $pageNumber was to be moved to were"
. " moved to the position of page $pageNumber "
. "without any problem. However, when an attempt "
. "was made to move the elements of the temporary "
. "page 0 to their new location, this was not "
. "possible.\n\nTo rectify this situation, an "
. "attempt was made to return the "
. "elements that were moved to page $pageNumber back"
. " to page $page2move2. This however"
. " failed, which meant that the elements on page 0 "
. "had to remain on page 0.\n\nThis means that there"
. " is a situation where by the elements that belong"
. " on page $pageNumber are now on page 0, and the "
. "elements that belong on page $page2move2"
. " are now on page $pageNumber.\n\nYou should "
. "ensure that this situation is corrected ASAP.\n\n"
. "WebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Page Movement "
. "Error", $msgTxt, "From: WebSubmit_Administrator");
} // END else
} // END else
} // END if
else
{
# We now have a problem. We have altered the current pages
# elements to be on page zero, but we can't seem to alter the
# position of the elements on the page before our current
# page. We had better just put back our page zero elements to
# the current page (and hope this works!), and leave the whole
# thing unchenged. We had also better inform our user & the
# administrator of the error.
# Move our page zero elements back - fast!
$errorCorrect = mysql_query("UPDATE sbmFIELD SET pagenb = '"
. "$pageNumber' WHERE subname = '$subname' AND pagenb = '"
. "0'");
if($errorCorrect)
{
# Query worked. Database info is safe! Phew! Just inform
# of the errors...
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: It"
. " was not possible to move the elements of the page that"
. "\\nwhose position page $pageNumber is to be moved to."
. "\\nThis has meant that it is not possible to move page "
. "$pageNumber.\\n\\nPlease inform the system "
. "administrator of this problem.');\n</SCRIPT>\n");
} // END if
else
{
# Oh dear..we have major problems! Nothing more that we
# can do, but inform the user and the administrator.
# Hey hey, let the user know
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: A "
. "major problem has ocurred with the data for this "
. "submission.\\nWhen a page is moved, all of the elements"
. " on the page to be moved are given a temporary page "
. "number of 0.\\nThe elements of the page whose position "
. "it is to be moved to are then given a page number of "
. "the current page\\nand then the elements with a page "
. "number of 0 are then given a page number of the page "
. "that they are to be moved to.\\n\\nHowever, in this "
. "case we moved the current pages elements to page 0, but"
. " when we attempted to move the elements\\nof the page, "
. "whose sequence number is the destination of the current"
. " page, to the current page\\nwe were unable to do this."
. " Then when we recognised this error, and attempted "
. "to\\ncorrect it by moving the page 0 elements back to "
. "their original page, we were\\nunable to do this!\\n\\n"
. "This means that the page that you have tried to move "
. "will now have no elements, as they are all on page 0!"
. "\\n\\nThe administrator should be informed of this "
. "immediately!');\n</SCRIPT>\n");
# Now email the administrator and let them know of this
# major error!
$msgTxt = "A serious error has ocurred while trying to "
. "move a page of a submission to another position.\n\n"
. "When a page is moved, all of the elements on the page "
. "to be moved are given a temporary page number of 0. "
. "The elements of the page whose position it is to be "
. "moved to are then given a page number of that of the "
. "page that we are actually moving, and then the elements"
. " with a page number of 0 are then given a page number "
. "of the page that they are to be moved to.\n\nHowever, "
. "when an attempt was made to move page $pageNumber of "
. "the $subname submission of the $doctype document type "
. "to another position, the elements of page $pageNumber "
. "were moved to 'page 0', but when an attempt was made "
. "to move the elements of the page whose sequence number "
. "is the destination of the current page to the current "
. "page, it was not possible to do this. When this error "
. "was reconised, an attempt was made to correct the "
. "problem by moving all elements of page 0 of the "
. "$subname submission (the temporary page) back to page "
. "$pageNumber. The query to do this also failed, which "
. "effectively left the elements of page $pageNumber of "
. "the $subname submission stranded on page 0.\n\nThis is "
. "a serious problem, but can be corrected by running an "
. "update query to move the elements back to the correct "
. "page. Use the following query to do this manually:\n\n"
. "UPDATE sbmFIELD SET pagenb = '$pageNumber' WHERE subname ="
. " '$subname' and pagenb = '0';\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Page Movement "
. "Error", $msgTxt, "From: WebSubmit_Administrator");
} // END else
} // END else
} // END if
else
{
# We couldn't change the pagenb field for the elements on the
# current field...error!
# Display JavaScript alert giving details of the error...
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: It was not"
. " possible to alter the page numbers for the elements on the "
. "page to be moved.\\nThis error ocurred in the sbmFIELD table.\\n"
. "Unable to carry out page movement - inform system "
. "administrator.');\n</SCRIPT>\n");
# Now email the administrator about the problem that ocurred...
$msgTxt = "An error has ocurred while attempting to move a "
. "submission page. The submission was the $subname submission "
. "of the $doctype document type, and an attempt was made to "
. "move page $pageNumber.\n\nIt was not possible to assign a "
. "temporary value of 0 (zero) to the 'pagenb' field of the "
. "elements belonging to this page in the sbmFIELD table. This "
. "meant that it was not possible to carry out the movement of "
. "the page.\n\nThis problem should be investigated as soon as "
. "possible.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Page Movement Error",
$msgTxt, "From: WebSubmit_Administrator");
} // END else
} // END function moveSubPage()
//*************
function deleteSubmissionPage($subname, $pageNumber, $nPgs, $doctype)
{
/******************************************************************
The task of this function is to delete a page from a given
submission of a given doctype. The function is passed several
variables which allow it to do this.
The function deletes the given page, and then renumbers all
elements for each page after the deleted page. It then the value
for the number of pages that the submission has by 1. It also
updates all relevant modified date fields (elements, submission
and doctype).
In the event of an error occurring, the relevant people are
informed. If an error ocurrs during the renumberring, the
renumberring is terminated to avoid further data corruption. The
admin is informed of this situation, and told what actions should
be taken.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 18/12/2000
Last Modified: 18/12/2000
******************************************************************/
$updStr = "DELETE FROM sbmFIELD WHERE subname = '$subname' AND "
. "pagenb = '$pageNumber'";
# Execute the above query...
$updRes = mysql_query($updStr);
if($updRes)
{
# In this case, the deletion of the given page has been
# successful, so we can now move any page elements after it down
# to fill in the gap left by the absence of the page...
# Get the current date...
$modifiedDate = makeEDSmdDate();
# Create an error flag & initialise it to 0...
$errorOn = 0;
for($i = $pageNumber + 1; $i <= $nPgs; $i++)
{
# Make the re-order query string...
$reorderStr = "UPDATE sbmFIELD SET pagenb = '" . ($i - 1)
. "', md = '$modifiedDate' WHERE subname = '$subname' AND"
. " pagenb = '$i'";
# Now execute the reorder query...
$reorderRes = mysql_query($reorderStr);
if($reorderRes)
{
# The query worked so free its result...
mysql_free_result($reorderRes);
} // END if
else
{
# Damn, we could not reorder the elements of this page to
# appear on another. The best thing to do is to stop any
# further reordering, and then warn both the user and the
# admin, telling the admin how it can be fixed...
# Let the user know...
print("<SCRIPT TYPE='text/javascript'>\nalert('Error: "
. "During the process of deleting the page, it is "
. "necessary to first delete the elements of the current"
. "\\npage, and then move the elements of all pages after"
. " the deleted page down one page in turn in order to "
. "fill\\nin the gap left by the deleted page. When page"
. " $pageNumber was deleted however, during the process "
. "of moving the pages after it down into the gaps,\\nit "
. "was not possible to move the elements of page $i onto "
. "page " . ($i - 1) . ".\\nThis meant that it was "
. "necessary to stop the process of reordering, as it "
. "would have resulted in further corruption if the "
. "process had been continued.\\n\\nThis problem should "
. "be corrected manually, and you should inform the system"
. " administrator ASAP.');\n</SCRIPT>\n");
# Now email the system admin about this...
$msgTxt = "An error has ocurred during the deletion of a "
. "page from the $subname submission of the $doctype "
. "document type. When a page is deleted from a "
. "submission, the first step is to delete the page to "
. "be deleted. The next step is to move any pages, after"
. " the deleted page, down by 1 position. This involves "
. "renumberring any elements of these pages to have a "
. "value of pagenb - 1.\n\nDuring the renumberring of "
. "elements after the deletion of page $pageNumber from "
. "the $subname submission however, an error ocurred which"
. " meant it was not possible to give the elements that "
. " currently lie on page $i a value of pagenb = "
. ($i - 1) . ".\n\nTo avoid further data corruption, the "
. "re-numberring was terminated after this error, so it "
. "will be necessary to manually decrement by 1 the "
. "'pagenb field for all elements on page $i and each page"
. " after this. It will then be necessary to decrement "
. "the value of the 'nbpg' field in the 'sbmIMPLEMENT' table "
. "for the '$subname' submission.\n\nBEFORE TAKING THESE "
. "ACTIONS, EXAMINE THE DATA TO ENSURE THAT THE USER HAS "
. "NOT ALREADY DONE THIS.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Page Deletion Error",
$msgTxt, "From: WebSubmit_Administrator");
# Now set the value of the $errorOn flag to mark the fact
# that an error has ocurred...
$errorOn = 1;
# Break free of the loop...
break;
} // END else
} // END for
# Now, if $errorOn has not been set, decrement the value of the
# nbpg field in sbmIMPLEMENT for the current submission, and update
# the md field of the current doctype & submission...
if(!$errorOn)
{
# Update the number of pages for this submission
$nmPgUpdtStr = "UPDATE sbmIMPLEMENT SET nbpg = '" . ($nPgs - 1)
. "', md = '$modifiedDate' WHERE subname = '$subname'";
$nmPgUpdtRes = mysql_query($nmPgUpdtStr);
if(!$nmPgUpdtRes)
{
# In this case, the query has failed, so we must inform the
# administrator that they must decrement the number of
# pages for the submission by 1.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: The"
. " page has been deleted successfully, but it was not "
. "possible\\nto decrement the number of submission pages "
. "for this submission.\\n\\nPlease inform the system "
. "administrator of this.');\n</SCRIPT>\n");
$msgTxt = "An error has ocurred during the deletion of "
. "page $pageNumber of the $subname submission. The page"
. " was successfully deleted, but it was not possible to "
. "decrement the value of the 'nbpg' field for this "
. "submission in the sbmIMPLEMENT table.\n\nThis should be "
. "done manually as soon as possible, as there is now a "
. "blank page in the submission.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Page Deletion Error",
$msgTxt, "From: WebSubmit_Administrator");
} // END if
else
{
# All went well, so we will inform both the user and the
# administrator that the page was deleted successfully.
# Inform the user
print("<SCRIPT TYPE='text/javascript'>\nalert('The page "
. "has been deleted successfully.');\n</SCRIPT>\n");
# Inform the sys admin
$msgTxt = "Page $pageNumber has been deleted from the "
. "$subname submission type.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Page $pageNumber "
. "Deleted", $msgTxt, "From: WebSubmit_Administrator");
} // END else
# Update the md field for our doctype
updateEDSDOCTYPEmd($doctype, $modifiedDate);
} // END if
} // END if
else
{
# We were unable to delete the page, so we can simply let the
# user know this, as there has been no change to the data.
print("<SCRIPT TYPE='text/javascript'>\nalert('An error ocurred"
. " when trying to delete this page, which meant that its "
. "deletion was impossible.\\nNo change to the submission data "
. "has been made.\\n\\nTry again, or inform the system "
. "administrator.');\n</SCRIPT>\n");
} // END else
} // END function deleteSubmissionPage()
function displayPage($update)
{
global $buttonorder,$displayed,$statustext,$subname,$doctype,$addPage,$nPgs,$pageNumber,$pageLeft,$pageRight,$deletePage;
if(isset($update))
{
# If this variable has been set, it means that this call to the
# page is a call to update the detials of a submission type.
# Ensure that "displayed" is storedin the database in uppercase...
$displayed = strtoupper($displayed);
# Get the data, so that it can be committed for the modification
# date field (md)...
$modifiedDate = makeEDSmdDate();
# Make a query update string...
$updStr = "UPDATE sbmIMPLEMENT SET displayed = '$displayed', buttonorder =";
# Ensure that we don't accidentally put the value '0' into the
# buttonorder field, when we actually want to put a NULL into it
# (and vice- versa)...
if(!$buttonorder)
{
if($buttonorder == '0')
$updStr .= " '$buttonorder', ";
else
$updStr .= " NULL, ";
} // END if
else
{
$updStr .= " '$buttonorder', ";
} // END else
$updStr .= "statustext = '$statustext', md = "
. "'$modifiedDate' WHERE subname = '$subname'";
# Now carry out the query execution
$updateRs = mysql_query($updStr);
if($updateRs)
{
# If the query could actually be executed without error
if(mysql_affected_rows() == 1)
{
# In this case, only 1 row was updated, which is as
# expected
# Update the md field for our doctype
updateEDSDOCTYPEmd($doctype, $modifiedDate);
# Display a nice message informing the user that the update
# has been carried out...
print("<SMALL STYLE=\"color: green; font-weight: bold; "
. "text-align: center\">Update Complete</SMALL>\n<BR>\n");
# Send the administrator a message to inform them of the
# update that has taken place...
$msgTxt = "An update has been carried out on the $subname "
. "submission type in the " . DOCS_DATABASE
. " database.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$subname Submission Type Updated",
$msgTxt, "From: WebSubmit_Administrator");
# Now that we have updated the submission details, we can
# redisplay them in the form for further editing...
displayEDSsubDetsForm($subname, $doctype);
} // END if
elseif(mysql_affected_rows() > 1)
{
# More than 1 row was updated -> bad news: key duplication
# Display an error message about this...
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">"
. "ERROR:</SPAN> Multiple rows have been updated in the "
. "<EM>sbmIMPLEMENT</EM> table.<BR>This has resulted from an "
. "attempt to update the <EM>$subname</EM> submission "
. "type.<BR>Please inform the system administrator."
. "</P>\n");
# Update the md field for our doctype
updateEDSDOCTYPEmd($doctype, $modifiedDate);
# Now, email the administrator to let them know this, as it
# is a potentially dangerous error.
$msgTxt = "When a user updated the details of "
. "the $subname submission type using the EDS Administra"
. "tor, several rows were affected in the sbmIMPLEMENT table."
. " The update was conducted using the \"subname\" field "
. "as the key. As the \"subname\" field is the primary "
. "key for the sbmIMPLEMENT table, this means that there must"
. " be key violations in this table. There should only "
. "have been 1 row affected by this update.\n\nThis proble"
. "m should be investigated and corrected immediately.\n\n"
. "WebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "ERROR: sbmIMPLEMENT Table Multiple Row "
. "Update!", $msgTxt, "From: WebSubmit_Administrator");
} // END elseif
else
{
# No rows were updated -> Something strange here!
# Display an error message about this...
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">"
. "ERROR:</SPAN> No rows have been updated in the <EM>"
. "sbmIMPLEMENT</EM> table.<BR>This suggests that there could"
. " be data inconsistencies or concurrency problems.<BR>"
. "Please inform the system administrator.</P>\n");
# Better email the administrator & let them know...
$msgTxt = "When a user attempted to update the details of "
. "the $subname submission type using the EDS Administrat"
. "or, no rows were affected in the sbmIMPLEMENT table by "
. "this update.\n\nBecause the user must have altered a "
. "submission types details to submit an update on it, it "
. "must have been present at around the time that the user"
. " submitted their update.\n\nThis suggests the possibili"
. "ty of concurrency or data inconsistency problems in thi"
. "s table.\n\nThis should be investigated and corrected "
. "ASAP.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "Error: Possible Concurrency Problems",
$msgTxt, "From: WebSubmit_Administrator");
} // END else
} // END if
else
{
# Display an error message about this...
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">"
. "ERROR:</SPAN> No rows have been updated in the <EM>"
. "sbmIMPLEMENT</EM> table.<BR>This suggests that there could"
. " be data inconsistencies or concurrency problems.<BR>Plea"
. "se inform the system administrator.</P>\n");
} // END else
} // END if
elseif($addPage)
{
# In this case, the user has clicked on the button to add a new
# page to the submission. In this case, we must get the current
# number of pages in the document, increment it by 1, and then
# redirect the browser focus to the "pageDetsEDS.php" for the new
# page (which will of course have no elements on it)...
# We have been passed a value for the number of pages, so the
# first thing to do is to increment it
$nPgs++;
# Get the date for modification date details
$modifiedDate = makeEDSmdDate();
# Now, we can update the "nbpg" field in the sbmIMPLEMENT table to
# the value of this "$nPgs" variable, to reflect the addition of
# the new page.
$updRes = mysql_query("UPDATE sbmIMPLEMENT SET nbpg = '$nPgs', md ="
. " '$modifiedDate' WHERE subname = '$subname'");
# Now ensure that this update has been successful...
if($updRes)
{
# In this case, the query has executed without error, but we
# should also ensure that it has only updated one row. This
# should be the case of course, because there should only be
# one row for the current submission in the sbmIMPLEMENT table.
if(mysql_affected_rows() > 1)
{
# In this case, too many rows have been updated. This is
# actually quite a serious error, as it implies a key
# duplication situation in the sbmIMPLEMENT table.
# Update the md field for our doctype
updateEDSDOCTYPEmd($doctype, $modifiedDate);
# Output a JavaScript alert about this...
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: "
. "Several rows were updated in the sbmIMPLEMENT table for "
. "the $subname submission when we added a page to "
. "it.\\nBecause the \"subname\" field is the primary key"
. "for the sbmIMPLEMENT table, this suggests a primary key "
. "violation.\\n\\nPlease inform the system administrator "
. "administrator');</SCRIPT>\n");
# Now we had better mail the administrator and ensure that
# they know about this problem...
$msgTxt = "An error has ocurred when a new page was added "
. "to the $subname submission. When this action was under"
. "taken, more than 1 rows was updated in the sbmIMPLEMENT "
. "table. This means that there must be more than 1 "
. "instance of this submission in this table.\n\nBecause "
. "the \"subname\" field is the primary key for the "
. "sbmIMPLEMENT table, this it is illegal to have more than "
. "one row for the same submission, and this is therefore "
. "a primary key violation.\n\nYou should look into this "
. "situation immediately, as it is a serious error, and "
. "could cause system problems.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "Error - $subname Submission "
. "Duplication",
$msgTxt, "From: WebSubmit_Administrator");
# Finally, we can redisplay the current submission pages
# details
displayEDSsubDetsForm($subname, $doctype);
} // END if
elseif(mysql_affected_rows() <= 0)
{
# In this case, no rows have been updated, or a query error
# has ocurred (if the result set is -1)...
# Better output a quick message..
print("<P CLASS=\"errorMsg\"><SPAN STYLE=\"color: red\">"
. "ERROR:</SPAN> Unable to update $subname submission det"
. "ails. No page added.</P>");
# We'd better output a JavaScript alert informing the user
# that no rows were updated...
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: No "
. "rows were updated in the sbmIMPLEMENT table when an "
. "attempt was made\\nto add a new page to the $subname "
. "submission.\\nThis suggests that there is no data in "
. "the table for this submission, which suggests\\nsome "
. "sort of problem with concurrency.\\nIt is possible that"
. " another user deleted this submission at the same "
. "time\\nas the page was added.\\n\\nThe System Administr"
. "ator should be informed of this problem.');\n"
. "</SCRIPT>\n");
# Now email the administrator and let them know the problem
$msgTxt = "An error has ocurred when trying to add a new "
. "page to the $subname submission of the $doctype documen"
. "t type. When an attempt was made to increment the valu"
. "e of the nbpg field in the sbmIMPLEMENT table by 1 for "
. "this submission, no rows were affected by the update.\n"
. "\nThis suggests that the submission does not exist in "
. "this table. There could be concurrency problems, as it"
. " is possible that during the time between the details "
. "of the submission being displayed, and the 'ADD PAGE' "
. "button being pressed by the user, the submission was "
. "deleted by another user.\n\nThis situation should be "
. "investigated.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "EDS Error - $subname Not Found",
$msgTxt, "From: WebSubmit_Administrator");
# Here, instead of redisplaying the details of this
# submission, we must redirect the browser to the
# "documentEDS.php" page, as there is no point in
# redisplaying the submission details if it is possible
# that another user has deleted it. If it still exists,
# the user can simply look at the submission again.
print("<FORM NAME='referForm ACTION='documentEDS.php' "
. "METHOD='post'>\n<INPUT TYPE='hidden' NAME='doctype' "
. "VALUE='$doctype'>\n</FORM>\n<SCRIPT TYPE='text/javas"
. "cript'>\nsetTimeout(\"document.referForm.submit();\","
. " 1000);\n</SCRIPT>\n");
} // END elseif
else
{
# In this case, the query was perfect, and only 1 row was
# updated, exactly as planned. In this case, we can output
# a JavaScript alert letting the user know of the success,
# email the admin informing them of the success, and
# redirect the browser to the "pageDetsEDS.php" page.
# Update the md field for our doctype
updateEDSDOCTYPEmd($doctype, $modifiedDate);
# Now display a quick message on screen...
print("<P STYLE=\"color: green; text-align: center; font-"
. "size: large\">New Page Added To <EM>$subname</EM> "
. "Submission.</P>\n");
# Now we can display a JavaScript Alert to say pretty much
# the same thing in a little more detail
print("<SCRIPT TYPE='text/javascript'>\nalert('A new page "
. "has been added to the $subname submission type.\\nThis "
. "new page has been added into position $nPgs.\\nThe new "
. "page currently has no elements on it, and your browser "
. "has been redirected to the \"pageDetsEDS.php\" page\\n"
. "where you can examine this new submission page, and add"
. " new elements to it.');\n</SCRIPT>\n");
# Now we can email the administrator to say much the same
$msgTxt = "A new page has been added to the $subname "
. "submission of the $doctype document type. This new "
. "page has been inserted as the last page in the "
. "submission and therefore is page number $nPgs.\n\nEDS"
. " Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "Page $nPgs Added To $subname "
. "Submission", $msgTxt, "From: WebSubmit_Administrator");
# Now redirect the browser to "pageDetsEDS.php"
sendToPageDets($subname, $nPgs, $nPgs, $doctype);
} // END else
} // END if
else
{
# In this case, the query has failed due to some kind of
# error. We'd better let the user know this & the admin, and
# then simply redisplay the details of the current submission
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: It was "
. "not possible to add a page to the $subname submission of "
. "the $doctype document type.\\nThe system administrator "
. "should be informed of this problem.');\n</SCRIPT>\n");
# Finally, we can redisplay the current submission pages
# details
displayEDSsubDetsForm($subname, $doctype);
} // END else
} // END elseif
elseif(isset($pageLeft))
{
# If this clause has been reached, the user has chosen to move a
# page of the current submission to the left. This means to give
# it a lower page number, and hence give it a higher priority in
# the page order sequence.
moveSubPage($doctype, $pageNumber, $nPgs, $subname,
$pageNumber - 1);
# Now simply redisplay the page that gives details of the
# submission...
displayEDSsubDetsForm($subname, $doctype);
} // END elseif
elseif(isset($pageRight))
{
# If this clause has been reached, the user has chosen to move a
# page of the current submission to the right (give it a higher
# page number, and hence a lower priority in the order sequence)
moveSubPage($doctype, $pageNumber, $nPgs, $subname,
$pageNumber + 1);
# Now simply redisplay the page that gives details of the
# submission...
displayEDSsubDetsForm($subname, $doctype);
} // END elseif
elseif(isset($deletePage))
{
# If this clause has been reached, the user has chosen to delete
# a page and all of its elements from the current submission.
# Process the deletion of an element
deleteSubmissionPage($subname, $pageNumber, $nPgs, $doctype);
# Now simply redisplay the page that gives details of the
# submission...
displayEDSsubDetsForm($subname, $doctype);
} // END elseif
else
{
# In this case, this is the first call to the page. We can
# therefore simply display the details of the submission
displayEDSsubDetsForm($subname, $doctype);
} // END else
}
/**********************Start of main script***************************/
# Connect to the MySQL server
serverConnect(MYSQLDOCMACHINE, MYSQLDOCUSERID, MYSQLDOCPASSWORD);
# Select the CDS Search database...
dbSelect(DOCS_DATABASE);
if (!canUseWebSubmitAdmin($uid,$doctype))
outWarning("You are not allowed to access WebSubmit Admin for this "
. "type of documents");
else
displayPage($update);
/************************End of main script***************************/
</protect>
?>

Event Timeline