Page MenuHomec4science

newSubmissionEDS.php.wml
No OneTemporary

File Metadata

Created
Tue, Nov 19, 02:56

newSubmissionEDS.php.wml

## $Id$
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio 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.
##
## CDS Invenio 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 CDS Invenio; 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="Create a new action for the <i><protect><?print $doctype;?></protect></I> document type" \
navtrail_previous_links="<a class=navtrail href=<WEBURL>/admin/<lang:star: index.*.html>>_(Admin Area)_</a> &gt; <a class=navtrail href=<WEBURL>/admin/websubmit/>_(WebSubmit Administration)_</a>" \
navbar_name="admin" \
navbar_select="websubmit"
<?
<protect>
## $Id$
## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDS Invenio WML SOURCES.
/*********************Function Declarations***************************/
function sendToDocDets($doctype)
{
/*******************************************************************
For many situations in the process of creating a new submission,
it is necessary to redirect the browser focus to the page that
displays the details of a doctype and it's submissions. For this
reason, this function was created. It simply saves on the
duplication of this code.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 12/12/2000
Last Modified: 12/12/2000
*******************************************************************/
# We can now redirect the browser to the the page showing the
# details of this document type & its submissions
print("<FORM ACTION='documentEDS.php' METHOD='post' "
. "NAME='referForm'>\n"
. "<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'>\n"
. "</FORM>\n");
print("<SCRIPT LANGUAGE=\"JavaScript\">\n"
. "setTimeout(\"document.referForm.submit();\", 1000);\n"
. "</SCRIPT>\n");
} // END function sendToDocDets($doctype)
//*************
function addAct($doctype, $formsAction,
$actSelected = 0, $subToAdd = 0)
{
/*****************************************************************
This function has the task of displaying the forms that allow the
user to add a submission to a document type. The function has
been built to know what kind of call to the page it is by means
of hidden inputs in the forms it makes. If this is the first
call to the function (i.e. a call whereby a user must select an
action to add), it only displays the actions that are available
for adding to the document. Otherwise, it also displays the
other document types that have this submission, and offers the
user the chance to clone the submission from one of these other
document types. It also displays the button that is clicked to
submit the submission addition at this point.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
Created: 07/12/2000 (ammended from it's WebSubmit Manager add
a new action to a doctype
counterpart)
Last Modified: 15/03/2001
****************************************************************/
# Make a title for the page, and indeed some sort of informative
# introduction paragraph to explain the purpose of the page to 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\">The form below is used to add a new "
. "submission to the <EM>$doctype</EM> document type.<BR>The "
. "addition of the new submission is only allowed if it is not "
. "already part of the <EM>$doctype</EM> document type.<BR><BR>It "
. "is also possible to clone a submission from the same submission "
. "as it appears under another doctype.<BR>To do this, the doctype "
. "whose submission is to be cloned must be chosen from the "
. "relevant list box.</P>\n</TD>\n</TR>\n</TABLE>\n");
# Make a horizontal rule to divide the page sections...
drawSeparator();
# First, output a table to encapsulate the table that will contain
# the list-boxes that allow the user to add a new submission to a
# doctype
print("<TABLE WIDTH='90%' CELLSPACING=0 CELLPADDING=0 BORDER=1 "
. "ALIGN='center' BGCOLOR='#ADD8E6'>\n<TR>\n<TD ALIGN='left'>\n"
. "Select an action to add from the list. If you wish to clone "
. "another action, select the doctype whose action is to be "
. "cloned<BR>\n");
# Now make a unique list of all of the actions in the sbmIMPLEMENT
# table that the current document type already has...
$queryResult = mysql_query("SELECT actname FROM sbmIMPLEMENT WHERE "
. "docname = '$doctype' ORDER BY actname");
if($queryResult)
{
# If this query was successful, continue with the process
# Put the results of the above query into a 2d array...
$gotSubs = resToArray($queryResult);
# Free the resultset pointer occupied by the above query result
mysql_free_result($queryResult);
# Now, conduct another SQL query to get a distinct list of all
# actions in EDS that the current doctype does not have...
# First get the size of the array holding the actions that the
# doctype already has (i.e. the number of actions it already
# has)...
$numActions = sizeof($gotSubs);
$selectStr = "SELECT distinct(sactname), lactname FROM sbmACTION";
# If the current doctype has actions...
if($numActions > 0)
{
$selectStr .= " WHERE sactname != '" . $gotSubs[0][0] . "'";
for($i = 1; $i < $numActions; $i++)
{
$selectStr .= " AND sactname != '" . $gotSubs[$i][0] . "'";
} // END for
} // END if
$selectStr .= " ORDER BY sactname";
# Open a table, in which to place the inputs for adding a new
# submission type
print("<BR><TABLE BORDER=1 BGCOLOR='#FFFFCC' ALIGN='center' "
. "WIDTH='85%' CELLSPACING=0 CELLPADDING=0>\n<TR>\n");
# Execute our 2nd query...
$scndRes = mysql_query($selectStr);
if($scndRes)
{
# Now, we can display the controls for adding the new
# submission type to the current document type...
print("<FORM ACTION='$formsAction' METHOD='post'>\n"
. "<INPUT TYPE='hidden' NAME='actSelected' VALUE='true'>\n"
. "<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'>\n"
. "<TD ALIGN='center' VALIGN='top' WIDTH='50%'>\n"
. "<H5>Select an action to add to $doctype:</H5>\n"
. "<BR>\n");
# Now make the select list to choose the action from...
print("<SELECT NAME='subToAdd'"
. " onChange=\"if(this.options[this.selectedIndex].value !="
. " 'NO_SUB') { submit(); }\">\n"
. "<OPTION VALUE='NO_SUB'>Select...</OPTION>\n");
while(list($sub, $nom) = mysql_fetch_row($scndRes))
{
print("<OPTION VALUE='" . ereg_replace("'", "&#39;",
htmlspecialchars($sub)) . "'");
if($actSelected && $sub == $subToAdd)
{
print(" SELECTED");
} // END if
print(">" . ereg_replace("'", "&#39;",
htmlspecialchars($sub))
. " (" . ereg_replace("'", "&#39;",
htmlspecialchars($nom))
. ")</OPTION>\n");
} // END while
# Close up the SELECT list, and the current table cell
print("</SELECT>\n<BR>\n&nbsp;</TD>\n</FORM>\n");
# Make a new form...
print("<FORM ACTION='$formsAction' METHOD='post'>\n"
. "<INPUT TYPE='hidden' NAME='doctype' VALUE="
. "'$doctype'>\n"
. "<INPUT TYPE='hidden' NAME='subToAdd' VALUE="
. "'$subToAdd'>\n"
. "<INPUT TYPE='hidden' NAME='reqToAdd' VALUE="
. "'true'>\n");
print("<TD ALIGN='center' WIDTH='50%' BGCOLOR='#FFFFCC'>\n");
if($actSelected) # If the call to the script is to offer
# the option to clone a submission...
{
# In this case, we can make a drop-down list of all of the
# other submissions of the same type for a different
# document type. The user will then be able to choose the
# submission to clone...
# Query EDS to obtain this list of submissions...
$docsQuery = mysql_query("SELECT docname, subname FROM "
. "sbmIMPLEMENT WHERE actname = '$subToAdd'");
if($docsQuery)
{
if(mysql_num_rows($docsQuery) < 1)
{
print("<H4 STYLE=\"text-align: center; "
. "background-color:"
. " transparent\">No doctypes use this action"
. "</H4>\n");
} // END if
else
{
# Output a description for the input...
print("<H5>"
. "Clone the submission from that of another "
. "doctype?</H5>\n");
# Open a select list...
print("<SELECT NAME='toClone' SIZE=5>\n"
. "<OPTION SELECTED VALUE='NO_CLONE'>NO CLONE"
. "</OPTION>\n");
# Fill the list with values...
while(list($doc, $subnm) =
mysql_fetch_row($docsQuery))
{
print("<OPTION VALUE='"
. ereg_replace("'", "&#39;",
htmlspecialchars($doc))
. "'>"
. ereg_replace("'", "&#39;",
htmlspecialchars($doc))
. "</OPTION>\n");
} // END while
print("</SELECT>\n");
} // END else
} // END if
# Close up the cell that was used to contain the drop down
# list of doctypes to clone...
print("</TD>\n</TR>\n</TABLE>\n");
# Now, offer a submit button to allow the user to actually
# submit their update.
print("<BR>\n<TABLE ALIGN='center' WIDTH='100%' BORDER=0"
. " CELLSPACING=0 CELLPADDING=0>\n<TR><TD ALIGN='center'"
. ">\n<INPUT TYPE='button' VALUE='ADD SUBMISSION' "
. "onClick=\" if(confirm('Warning:\\n\\nYou are about to"
. " add a submission to the $doctype document type.\\n"
. "\\nAre you sure you wish to undertake this action?'))"
. " { submit(); }\">\n</TD>\n</TR>\n</TABLE>\n</FORM>\n");
} // END if
else
{
# If the user has not yet selected an action to add,
# simply leave the cell for the action to clone blank in
# anticipation of the action to add being selected
print("&nbsp;</TD>\n</TR>\n</TABLE>\n<BR>\n</FORM>\n");
} // END else
} // END if
} // END if
else
{
# In this case, the query to retrieve the list of actions that
# the current doctype does not have submissions for has failed.
# This means that we must terminate processing, as we cannot risk
# allowing impurities to get into the EDS database
print("<P CLASS='errorMsg'><SPAN STYLE=\"color: red\">ERROR:"
. "</SPAN> Unable To Retrieve Data Of <EM>$doctype</EM> Doctypes"
. " Submissions.<BR>Submission Addition Impossible</P>\n");
} // END else
# Now that we have made the main part of the interface for adding a
# new action, we can close up the table, as this part is finished...
print("</TD>\n</TR>\n</TABLE>\n");
# We can now add a "CANCEL" button for the user
# Make a horizontal rule to divide the page sections...
drawSeparator();
# Now make the button.
print("<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH='100%' "
. "ALIGN='center'>\n<TR>\n<FORM ACTION='documentEDS.php' METHOD="
. "'post'>\n<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'>"
. "<TD ALIGN='center'>\n<INPUT TYPE='button' VALUE='CANCEL' onCli"
. "ck=\"submit();\"></TD>\n</FORM>\n</TR>\n</TABLE>\n");
} // END function addAct()
//*************
function newSubmInputForm($subToAdd, $doctype)
{
/*******************************************************************
This function is called when the user has chosen to add a new
submission type to a given document type, but has chosen not to
clone this new submission from the same submission as it appears
for another doctype. In this situation, it is necessary to
present the user with an input form that contains all of the
fields that are required for inputting the details of the new
submission for the given doctype. The user can then fill in this
form, and submit it to continue with the process.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 08/12/2000 (Modified from actInputForm, a
function in the WebSubmit Manager that
is used for adding a new action
to a doctype without cloning
another).
Last Modified: 08/12/2000
*******************************************************************/
# Get a list of columns in the sbmIMPLEMENT table...
$columns = mysql_list_fields(DOCS_DATABASE, "sbmIMPLEMENT");
print("<FORM ACTION='newSubmissionEDS.php' METHOD='post'>\n"
. "<TABLE ALIGN='center' CELLPADDING=0 BORDER=0 CELLSPACING=0 "
. "WIDTH='100%'>\n");
# Now we can begin to make the input form in which the details of
# the new submission can be entered...
print("<P STYLE=\"font-size: large; color: navy; text-align: "
. "center\">Enter Details For The <EM>$subToAdd"
. "$doctype</EM> Submission</P>\n");
# 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\">You have "
. "chosen to create the <EM>${subToAdd}$doctype</EM> "
. "submission without cloning another submission.<BR>Please "
. "enter the description details for this new submission type"
. " in the form below and click <EM>SAVE</EM>.<BR><BR>If you "
. "have chosen this option erroneously, click cancel and no "
. "new submission will be created.</P>\n</TD>\n</TR>\n"
. "</TABLE>\n");
# Make a horizontal rule to divide the page sections...
drawSeparator();
# Get the date, so that it can be committed for the modification
# date field (md) and the creation date field (cd)...
$theDate = makeEDSmdDate();
# Now make a table in which to enter the submission type dets
# Make some readonly fields in which the details of fields that
# should not be set by the user can be displayed...
print("<FORM ACTION='newSubmissionEDS.php' METHOD='post'>"
. "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN='center"
. "' WIDTH='100%'>\n<TR>\n<TH BGCOLOR='#D3DCE3' ALIGN='right'"
. " WIDTH='20%'>\nDoctype Code:&nbsp;</TH>\n<TD ALIGN='left' "
. "BGCOLOR='#FFFFCC' WIDTH='80%'><INPUT TYPE='readonly' NAME='"
. "docname' VALUE='$doctype'>\n</TD>\n</TR>\n<TR>\n<TH BGCOLOR='"
. "#D3DCE3' ALIGN='right' WIDTH='20%'>\nAction Code:&nbsp;</TH>"
. "\n<TD ALIGN='left' BGCOLOR='#FFFFCC' WIDTH='80%'><INPUT "
. "TYPE='readonly' NAME='actname' VALUE='$subToAdd'>\n</TD>\n</TR>"
. "\n<TR>\n<TH BGCOLOR='#D3DCE3' ALIGN='right' WIDTH='20%'>\n"
. "Submission Name:&nbsp;</TH>\n<TD ALIGN='left' BGCOLOR='#FFFFCC'"
. " WIDTH='80%'><INPUT TYPE='readonly' NAME='subname' VALUE='"
. "${subToAdd}$doctype'>\n</TD>\n</TR>\n<TR>\n<TH BGCOLOR='#D3DCE3'"
. " ALIGN='right' WIDTH='20%'>\nNumber of Pages:&nbsp;</TH>\n<TD "
. "ALIGN='left' BGCOLOR='#FFFFCC' WIDTH='80%'><INPUT TYPE='"
. "readonly' NAME='nbpg' VALUE='0'>\n</TD>\n</TR>\n<TR>\n<TH "
. "BGCOLOR='#D3DCE3' ALIGN='right' WIDTH='20%'>\nCreation Date:"
. "&nbsp;</TH>\n<TD ALIGN='left' BGCOLOR='#FFFFCC' WIDTH='80%'><"
. "INPUT TYPE='readonly' NAME='cd' VALUE='$theDate'>\n</TD>\n</TR>"
. "\n<TR>\n<TH BGCOLOR='#D3DCE3' ALIGN='right' WIDTH='20%'>\nModifi"
. "cation Date:&nbsp;</TH>\n<TD ALIGN='left' BGCOLOR='#FFFFCC' WIDT"
. "H='80%'><INPUT TYPE='readonly' NAME='md' VALUE='$theDate'>\n"
. "</TD>\n</TR>\n");
# Now that we have displayed the non-user-editable fields, we can
# display a set of free input text fields in which the user can
# enter their data.
print("<TR>\n<TH BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\n"
. "On Submission Page:&nbsp;</TH>\n<TD ALIGN='left' WIDTH='80%' "
. "BGCOLOR='#FFFFCC'>\n<SELECT NAME='displayed'>"
. "<OPTION value='Y'>YES<OPTION value='N'>NO</SELECT>\n</TD>\n</TR>\n<TR>\n<TH "
. "BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\nButton Order:"
. "&nbsp;</TH>\n<TD ALIGN='left' WIDTH='80%' BGCOLOR='#FFFFCC'>\n"
. "<INPUT TYPE='text' NAME='buttonorder' SIZE=40>\n"
. "</TD>\n</TR>\n<TR>\n<TH "
. "BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\nStatus Text:&nbsp;"
. "</TH>\n<TD ALIGN='left' WIDTH='80%' BGCOLOR='#FFFFCC'>\n<INPUT "
. "TYPE='text' NAME='statustext' SIZE=40 "
. ">\n</TD>\n</TR><TR>\n<TH "
. "BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\nGroup Number:&nbsp;"
. "</TH>\n<TD ALIGN='left' WIDTH='80%' BGCOLOR='#FFFFCC'>\n<INPUT "
. "TYPE='text' NAME='level' SIZE=40 "
. " value='0'>\n</TD>\n</TR><TR>\n<TH "
. "BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\nScore:&nbsp;"
. "</TH>\n<TD ALIGN='left' WIDTH='80%' BGCOLOR='#FFFFCC'>\n<INPUT "
. "TYPE='text' NAME='score' SIZE=40 "
. " value='0'>\n</TD>\n</TR><TR>\n<TH "
. "BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\nStarting Page Number:&nbsp;"
. "</TH>\n<TD ALIGN='left' WIDTH='80%' BGCOLOR='#FFFFCC'>\n<INPUT "
. "TYPE='text' NAME='stpage' SIZE=40 "
. " value='1'>\n</TD>\n</TR><TR>\n<TH "
. "BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\nEnd Text:&nbsp;"
. "</TH>\n<TD ALIGN='left' WIDTH='80%' BGCOLOR='#FFFFCC'>\n<INPUT "
. "TYPE='text' NAME='endtxt' SIZE=40 "
. " value=''>\n</TD>\n</TR>\n</TABLE>\n");
# We have now created the visible inputs of the form, so we must add
# any hidden inputs that are required, and display the set of
# buttons that are required to submit, reset, cancel the submission
# addition action.
print("<INPUT TYPE='hidden' NAME='addSansClone' VALUE='true'>\n"
. "<TABLE ALIGN='center' BORDER=0 CELLSPACING=1 CELLPADDING=1"
. ">\n<TR>\n<TD ALIGN='right'>\n<INPUT TYPE='button' "
. "VALUE='SAVE' onClick=\""
. "if(confirm('Really Add This Submission?')) { submit() }\">"
. "</TD>\n<TD ALIGN='center'>\n<INPUT TYPE='button' VALUE='RESET' "
. "onClick=\"reset();\"></TD>\n</FORM><FORM ACTION='documentEDS."
. "php' METHOD='post'>\n<INPUT TYPE='hidden' NAME='doctype' VALUE='"
. "$doctype'><TD ALIGN='left'>\n<INPUT TYPE='button' VALUE='CANCEL'"
. "onClick=\"submit();\"></TD>\n</TR>\n</FORM>\n</TABLE>\n");
} // END function newSubmInputForm($subToAdd, $doctype)
//***************
function processAdditionSansClone($docname, $actname, $subname,
$nbpg, $cd, $md, $displayed, $buttonorder, $statustext, $level, $score, $stpage, $endtxt)
{
/*******************************************************************
This function has the task of adding a new submission to a given
EDS document type, without cloning the submission from another
doctype. The function is passed several arguments by the calling
function. The first of these arguments is the $link variable.
The second is the $docname variable. The third is the $actname
value. The fourth is the $subname value. The fifth is the $nbpg
value. The sixth is the $cd value. The seventh is the $md
value. The eighth is the $level value. The nineth is the
$buttonorder value. The tenth is the $statustext value. Most of
these values can be commited to the sbmIMPLEMENT table to become
part of the new submission types details.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 08/12/2000 (Adapted from it's
counterpart for adding a
new action to the WebSubmit
database)
Last Modified: 25/01/2001
*******************************************************************/
# Ensure that the value of level is in upper case...
$displayed = strtoupper($displayed);
# Make a query string...
$newSubQStr = "INSERT INTO sbmIMPLEMENT (docname, actname,"
. " displayed, subname, nbpg, cd, md, buttonorder, statustext, level, score, stpage, endtxt) "
. "VALUES('$docname', '$actname', '$displayed', '$subname', '$nbpg', "
. "'$cd', '$md', '$buttonorder', '$statustext', '$level', '$score', '$stpage', '$endtxt')";
# Now, we can actually execute the new query, hence adding the new
# submission to the current doctype...
$addSubRes = mysql_query($newSubQStr);
# Take the relevant action depending upon whether or not the query
# was executed successfully
if($addSubRes)
{
# In this case, the query was executed successfully
# Update the doctype modification date in the sbmDOCTYPE table
updateEDSDOCTYPEmd($docname, $md);
# Now output an alert to state that the new submission has been
# entered, and that the user must add their own actions, pages,
# etc to it.
print("<SCRIPT TYPE='text/javascript'>alert('The $subname "
. "submission has been added to the $docname doctype.\\n"
. "It was not cloned from any other submission, so it will"
. " be necessary\\nto manually add pages and elements to it."
. "');</SCRIPT>\n");
# Now, we can email the administrator to let them know of this
# new submission addition for the current doctype.
$msgTxt = "The $subname submission has been added to the "
. "$docname document type. It was not cloned from another "
. "submission.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "EDS: $subname Submission Added", $msgTxt,
"From: WebSubmit_Administrator");
} // END if
else
{
# In this case, the query failed, and therefore no new submission
# has been created for the current doctype. In this case, we can
# simply display the error, and redirect the browser to
# "documentEDS.php", where the details of the current doctype
# will be displayed.
print("<P CLASS=\"errorMsg\"><SPAN STYLE=\"color: red\">ERROR:"
. "</SPAN> Unable to commit the details of the new submission "
. "to the sbmIMPLEMENT table.<BR>Please Inform System Administrator"
. ".</P>\n");
} // END else
# redirect the browser to documentEDS.php...
sendToDocDets($docname);
} // END function processAdditionSansClone()
//****************
function processSubmissionCloning($doctype, $toClone, $subToAdd)
{
/*******************************************************************
This function has the 'broad task' of processing the cloning of a
given submission for a given doctype, from another doctype.
Effectively, the function is passed 4 variables. The first
variable is $link. This contains a link to the MySQL database
server. The second variable is $doctype. This variable contains
the unique code of the document that is to have the cloned
submission added to it. The third variable is $toClone. This
variable contains the unique code of the doctype that is to have
one of its actions cloned. The fourth variable is the $subToAdd
variable. This variable contains the unique code of the
submission that is to be added (and hence cloned) to the doctype
referenced by the contents of $doctype.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 11/12/2000 (This functions has
been adapted from
its WebSubmit counterpart
for cloning actions)
Last Modified: 25/01/2001
*******************************************************************/
# The first step is to get the details of the submission to be
# cloned from the doctype to which it belongs, out of the
# sbmIMPLEMENT table.
$subQStrng = "SELECT * FROM sbmIMPLEMENT WHERE actname = '$subToAdd'"
. " AND docname = '$toClone'";
# Now that we have made the query string, we can execute the query
# to get the details of this given submission for the given doctype.
$subQRes = mysql_query($subQStrng);
# Ensure that the query executed properly, as if it was not
# executed, we don't want to begin committing values to the DB and
# corrupting it.
if($subQRes)
{
# In this case, the query has executed fine
if(mysql_num_rows($subQRes) > 0)
{
# In this case, there are rows for the given submission type
# for the given doctype, and we can proceed with the cloning.
# Read the information from the query into an array...
$cloneSubDets = mysql_fetch_array($subQRes);
# Now that we have this information from the sbmIMPLEMENT table,
# we can commit the same information, but for the doctype that
# the submission is to be added to, into the sbmIMPLEMENT table.
# It is worth noting here that if a submission that is to be
# added appears twice for a doctype from whom it is to be
# cloned, (this should not happen if DB consistency is good),
# this script will clone the first ocurrence of this
# submission. This should not matter for the rest of the
# action cloning, such as the functions etc).
# Get the date, so that it can be committed for the
# modification date field (md) and the creation date field
# (cd)
$theDate = makeEDSmdDate();
# Now make the insert query string.
$submInsStr = "INSERT INTO sbmIMPLEMENT (docname, actname,"
. " displayed, subname, nbpg, cd, md, buttonorder, statustext, level, score, stpage, endtxt) "
. "VALUES('$doctype', '$subToAdd', '" . $cloneSubDets["displayed"]
. "', '${subToAdd}$doctype', '" . $cloneSubDets["nbpg"]
. "', '$theDate', '" . "$theDate', '"
. $cloneSubDets["buttonorder"] . "', '"
. $cloneSubDets["statustext"] . "', '"
. $cloneSubDets["level"] . "', '"
. $cloneSubDets["score"] . "', '"
. $cloneSubDets["stpage"] . "', '"
. $cloneSubDets["endtxt"] . "')";
# Now execute the query to insert this data into the database
$submInsRes = mysql_query($submInsStr);
# Test it worked...
if($submInsRes)
{
# Cool...the query worked, and we can proceed to clone all
# of the submissions details.
# Free the result set of the $submInsRes query, as it is no
# longer needed. We can also now begin to clone all of the
# details for all of the pages and elements of this new
# submission...
mysql_free_result($submInsRes);
# Now, we need to query the field table, and obtain the
# details of all elements that belong to the given
# submission (that to be added) of the doctype from which
# it is to be cloned...
$elmntsQStr = "SELECT * FROM sbmFIELD WHERE subname = '"
. "${subToAdd}$toClone' ORDER BY pagenb, fieldnb";
$elmntsQRes = mysql_query($elmntsQStr);
# Ensure this query worked...
if($elmntsQRes)
{
# The query to retrieve all elements executed fine
# Now, for each of the elements, change the subname to
# reflect that of the new submission, the creation date
# and modification date to the current date (that when
# the new submission was created - today!!). Then
# commit the new details (of the new element for the new
# submission to the EDS database into the sbmFIELD table.
while($element = mysql_fetch_array($elmntsQRes))
{
$eleInsStr = "INSERT INTO sbmFIELD (subname, pagenb, "
. "fieldnb, fidesc, fitext, level, sdesc, checkn, "
. "cd, md, fiefi1, fiefi2) VALUES('"
. "${subToAdd}$doctype', '" . $element["pagenb"]
. "', '" . mysql_escape_string($element["fieldnb"]) . "', '"
. mysql_escape_string($element["fidesc"]) . "', '" . mysql_escape_string($element["fitext"])
. "', '" . mysql_escape_string($element["level"]) . "', '"
. mysql_escape_string($element["sdesc"]) . "', '" . mysql_escape_string($element["checkn"])
. "', '$theDate', '$theDate', '" . mysql_escape_string($element["fiefi1"])
. "', '" . mysql_escape_string($element["fiefi2"]) . "')";
# Now execute the above query string...
$eleInsRes = mysql_query($eleInsStr);
# Test that the query worked...
if($eleInsRes && mysql_affected_rows($eleInsRes) < 1)
{
# In this case, the query was successful, and we
# can delete the query result pointer to stop
# memory wastage...
mysql_free_result($eleInsRes);
} // END if
else
{
# In this case our query to add the element has
# failed. We must therefore output an alert for
# our users benefit, and then inform the
# administrator that an element could not be
# commited. We can however carry on cloning the
# other elements.
print("<SCRIPT TYPE=\"text/javascript\">alert('"
. "ERROR: Unable to commit a value for the "
. $element["fidesc"] . " element\\nwhich should"
. " appear in position " . $element["fieldnb"]
. " of page " . $element["pagenb"] . "\\nfor "
. "the new ${subToAdd}$doctype submission.\\n\\n"
. "Please inform the system administrator.');"
. "</SCRIPT>\n");
# Now make a message to send to the administrator
$msgTxt = "An error ocurred when a new submission"
. " was added to the $doctype document type. Thi"
. "s new submission is the ${subToAdd}$doctype "
. "submission and was cloned from the $toClone "
. "document type.\n\nIt was not possible to add "
. "the " . $element["fidesc"] . " element which "
. "should appear in position "
. $element["fieldnb"] . " on page "
. $element["pagenb"] . " of this new submission."
. "\n\nThe cloning of the rest of this submission"
. " was however continued, which means that there"
. " may be problems with elements being out of or"
. "der on this page of the submission.\n\nYou sho"
. "uld examine this and correct any problems imme"
. "diately.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "ERROR: Unable to Add "
. $element["fidesc"] . " Element "
. "to ${subToAdd}$doctype", $msgTxt,
"From: WebSubmit_Administrator");
} // END else
} // END while
# Now we also clone the functions used in this submission
$res = mysql_query("SELECT action,function,score,step FROM sbmFUNCTIONS WHERE action='$subToAdd' and doctype='$toClone'");
while ($row = mysql_fetch_array($res))
{
$res2 = mysql_query("SELECT 1 from sbmFUNCTIONS where action='".$row['action']."' and doctype='$doctype' and function='".$row['function']."' and score='".$row['score']."' and step='".$row['step']."'");
if (mysql_num_rows($res2) < 1)
mysql_query("INSERT INTO sbmFUNCTIONS (action,doctype,function,score,step) VALUES ('".$row['action']."','$doctype','".$row['function']."','".$row['score']."','".$row['step']."')");
}
#clone parameters
$res = mysql_query("select * from sbmPARAMETERS where doctype='$toClone'");
while ($row = mysql_fetch_array($res))
{
$res2 = mysql_query("select * from sbmPARAMETERS where doctype='$doctype' and name='".$row['name']."'");
if (mysql_num_rows($res2) < 1)
mysql_query("insert into sbmPARAMETERS(doctype, name, value) values ('$doctype','".$row['name']."','".$row['value']."')");
}
# Now that the submission has been cloned, it is
# possible to present the user with a message saying
# this, and redirect their browser to the
# "documentEDS.php" page so that they can look into the
# details of this new submission, and change anything
# that they might feel appropriate. A javascript alert
# should also be displayed however, advising them to
# check all of the values for their new submission and
# ensure that they are correct. We can then mail the
# administrator to let them know that a new submission
# has been created, and that it was cloned from another
# doctype.
print("<SCRIPT TYPE=\"text/javascript\">alert('The "
. "${subToAdd}$doctype has been created. However, "
. "it should be noted that\\nit may not have been poss"
. "ible to clone all elements for this submission,\\n"
. "and you should check that the new submission contai"
. "ns all of the desired elements.\\nYour browser has "
. "been directed to the page where you can do this.');"
. "</SCRIPT>\n");
# Now mail the administrator...
$msgTxt = "The ${subToAdd}$doctype submission type has"
. " been created for the $doctype document type. This"
. " new submission was cloned from the $toClone docume"
. "nt type.\n\nWebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
mail(ADMIN_EMAIL, "${subToAdd}$doctype Submission Added"
. " to $doctype", $msgTxt, "From: WebSubmit_Administrator");
# Now redirect the browser to documentEDS.php
sendToDocDets($doctype);
} // END if
else
{
# Oh dear! We were unable to retrieve the details of
# any elements belonging to the given submission to be
# cloned. We had better terminate the new submission
# addition process here, warn the user that the details
# of the new submission have been added to sbmIMPLEMENT but
# we couldn't get the element details from sbmFIELD, and
# then we should also mail the administrator to inform
# them of this problem.
print("<SCRIPT TYPE=\"text/javascript\">alert('"
. "ERROR: It was not possible to retrieve details for "
. "any of the elements of the ${subToAdd}$toClone "
. "submission from the sbmFIELD table.\\nThis means "
. "that none of the pages or elements for this "
. "submission could be cloned.\\nThere was however a "
. "row commited to the sbmIMPLEMENT table for the new "
. "${subToAdd}$doctype submission.\\nThis means that "
. "the submission will now exist for the new doctype, "
. "but\\nit will be necessary to manually add elements "
. "to the pages.');</SCRIPT>\n");
# Now make a message to send to the administrator
$msgTxt = "An error ocurred when a new submission"
. " was being added to the $doctype document type. Thi"
. "s new submission is the ${subToAdd}$doctype "
. "submission and was to be cloned from the $toClone "
. "document type.\n\nHowever, it was not possible to "
. "retrieve the details of the submission pages and "
. "elements of the $toClone document type from the "
. "sbmFIELD table. This means that it has not been "
. "possible to clone these details. An entry was "
. "however made for the new doctype in the new "
. "submission (${subToAdd}$doctype) in the sbmIMPLEMENT "
. "table, so this new submission will exist, but it "
. "will have empty pages.\n\nThis problem should be "
. "examined, and any inconsistencies in the data for "
. "this new submission should be corrected.\n\nEDS "
. "Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "ERROR: ${subToAdd}${doctype}: Unable"
. "$toClone Details For Cloning", $msgTxt, "From: "
. "WebSubmit_Administrator");
# Now redirect the browser to documentEDS.php
sendToDocDets($doctype);
} // END else
# Update the doctype modification date in the sbmDOCTYPE table
# so that the actual doctype reflects having been modified
updateEDSDOCTYPEmd($doctype, $theDate);
} // END if
else
{
# In this case, our query to add the details of this newly
# cloned submission failed, so we must output an alert to
# signify this to the user, email the administrators to let
# them know, and terminate the addition of the new
# submission.
print("<SCRIPT TYPE=\"text/javascript\">alert('"
. "ERROR: It was not possible to commit details for "
. "the new ${subToAdd}$doctype submission to the "
. "sbmIMPLEMENT table.\\nThis means that the new "
. "submission could not be created.\\n\\nPlease inform"
. " the system administrator of this problem.');</SCRI"
. "PT>\n");
# Now make a message to send to the administrator
$msgTxt = "An error ocurred when a new submission"
. " was being added to the $doctype document type. Thi"
. "s new submission is the ${subToAdd}$doctype "
. "submission and was to be cloned from the $toClone "
. "document type.\n\nHowever, it was not possible to "
. "commit the details of this new submission to the "
. "sbmIMPLEMENT table. This means that it was not possibl"
. "e to create this new submission.\n\nThis problem "
. "should be examined and corrected ASAP.\n\nEDS "
. "Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "ERROR: Unable to Commit "
. "${subToAdd}$doctype Submission Details", $msgTxt,
"From: WebSubmit_Administrator");
# Now redirect the browser focus to documentEDS.php
sendToDocDets($doctype);
} // END else
} // END if
} // END if
else
{
# In this case the query to retrieve details of the submission to
# be cloned has failed. We must therefore alert the user and
# redirect the browser.
print("<SCRIPT TYPE=\"text/javascript\">alert('ERROR: It was not"
. " possible to retrieve the details of ${subToAdd}$toClone "
. "submission from the sbmIMPLEMENT table.\\nThis meant that it "
. "could not be cloned, and hence no new submission addition for"
. "\\nthe $doctype document type has been created.');"
. "</SCRIPT>\n");
# Now redirect the browser to the documentEDS.php page
sendToDocDets($doctype);
} // END else
} // END function processSubmissionCloning()
function displayNewSubmissionForm($doctype,$actSelected,$addSansClone,$reqToAdd)
{
global $toClone,$subToAdd,$actSelected,$docname, $actname, $subname,$nbpg, $cd, $md, $displayed, $buttonorder, $statustext, $level, $score, $stpage, $endtxt;
if($actSelected)
{
# In this case, the submission to be added to the current doctype
# has been selected. This means that the offer to clone the same
# submission as it appears for another doctype can now be
# presented to the user...
addAct($doctype, "newSubmissionEDS.php", $actSelected,
$subToAdd);
# We can now also display a cancel button.
} // END if
elseif($addSansClone)
{
# In this case, the user has chosen the submission that they wish
# to add to the current document type, but they have also opted
# not to clone the submission from the same submission as it
# appears for another doctype. This means that we can now build
# a query string, and commit the details of the new submission
# for the current doctype to the database.
processAdditionSansClone($docname, $actname, $subname,
$nbpg, $cd, $md, $displayed, $buttonorder, $statustext, $level, $score, $stpage, $endtxt);
} // END elseif
elseif($reqToAdd)
{
# In this case, the user has chosen to add the new submission,
# with or without cloning it from another doctype. If the choice
# is to clone the submission from another doctype, then we can
# now process the cloning, and commit the relevant values to the
# database.
# Otherwise, if the user has opted to create the new submission
# without cloning it from another doctype, we can display a form
# in which the user will need to enter the relevant details of
# the new submission.
if($toClone == "NO_CLONE")
{
# In this case, the user does not wish to clone the new
# submission type from another doctype. This means that we
# must present them with a form in which to enter the details
# of the submission type.
newSubmInputForm($subToAdd, $doctype);
} // END if
elseif($toClone)
{
# In this case, the user has opted to clone the new submission
# from the same submission under another doctype. This means
# that it is possible to process the cloning of this new
# submission, and then redirect the browser to the
# "documentEDS.php" page so that the user can see the details
# of the new submission and explore them.
processSubmissionCloning($doctype, $toClone,
$subToAdd);
} // END elseif
else
{
# In this case, the user has erroneously failed to select the
# option of either cloning or not, and we must therefore just
# assume that they do not wish to clone anything, and treat
# the addition as a none clone submission addition...
newSubmInputForm($subToAdd, $doctype);
} // END else
} // END elseif
else
{
# This is the default call to the page. It is the first call to
# the page, whereby we simply need to display the first part of
# the forms (that which lists all of the actions that it is legal
# to add as submission types for the current doctype).
addAct($doctype, "newSubmissionEDS.php");
} // END else
}
/**********************Start of main script***************************/
# Connect to the MySQL server
serverConnect(MYSQLDOCMACHINE, MYSQLDOCUSERID, MYSQLDOCPASSWORD);
# Select the CDS Search database...
dbSelect(DOCS_DATABASE);
$auth = canUseWebSubmitAdmin($uid,$doctype);
if (!$auth[0])
outWarning($auth[1]. "<br><br>" . "You are not allowed to access WebSubmit Admin for this type of documents");
else
displayNewSubmissionForm($doctype,$actSelected,$addSansClone,$reqToAdd);
/************************End of main script***************************/
</protect>
?>

Event Timeline