Page MenuHomec4science

removeDoctypeEDS.php.wml
No OneTemporary

File Metadata

Created
Thu, Jul 11, 11:55

removeDoctypeEDS.php.wml

## $Id$
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005 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="Referees" \
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_deldoctype"
<?
<protect>
## $Id$
## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
function displayRemoveDoctypePage($killIt)
{
global $doc2delete;
if($killIt)
{
# In this case, this is the second call to this script, and the
# user has selected the doctype that they wish to kill, and have
# confirmed that they indeed wish to kill it. We can therefore
# begin the removing process. We need to delete from the
# "sbmCATEGORIES", "sbmDOCTYPE", "sbmIMPLEMENT", and "sbmFIELD" tables.
# Get all rows of the sbmIMPLEMENT table relating to this doctype...
$q1Res = mysql_query("SELECT subname FROM sbmIMPLEMENT WHERE "
. "docname = '$doc2delete'");
if($q1Res)
{
# Cool, query worked. Now for each of the subnames, delete
# all of its elements.
while($sub = mysql_fetch_array($q1Res))
{
# Delete all elements & pages for the given submission.
$q2Str = "DELETE FROM sbmFIELD WHERE subname = '"
. $sub["subname"] . "'";
$q2Res = mysql_query($q2Str);
if(!$q2Res)
{
# Bad. Query failed. Output the detailed error message
# on the screen.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:"
. "\\n\\nIt was not possible to conduct a delete query"
. " in order to remove any rows belonging to the "
. $sub["subname"] . " submission\\nof the $doc2delete "
. "document type from the sbmFIELD table.\\n\\nWhen the "
. "delete query was executed, it produced an error. "
. "This means that it is necessary\\nto manually remove"
. " any rows belonging to the " . $sub["subname"]
. " submission of the $doc2delete document type from "
. "the sbmFIELD table.');\n</SCRIPT>\n");
} // END if
} // END while
# Now delete all of the submissions for the current document
# type from the sbmIMPLEMENT table...
$q3Str = "DELETE FROM sbmIMPLEMENT WHERE docname = "
. "'$doc2delete'";
$q3Res = mysql_query($q3Str);
if(!$q3Res)
{
# Bad, query didn't work. Alert the user.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n"
. "\\nIt was not possible to conduct a delete query in "
. "order to remove any rows belonging to the $doc2delete"
. " document type from the sbmIMPLEMENT table.\\nWhen the "
. "delete query was executed, it produced an error. This"
. " means that it is necessary\\nto manually remove any "
. "rows belonging to the $doc2delete doctype that may be "
. "present in the sbmIMPLEMENT table.');\n</SCRIPT>\n");
} // END if
# Now delete the record of the doctype from the "sbmCATEGORIES"
# table...
$q4Res = mysql_query("DELETE FROM sbmCATEGORIES WHERE doctype = "
. "'$doc2delete'");
if(!$q4Res)
{
# Oh dear. Unable to delete the doctypes dets from the
# sbmCATEGORIES table. Alert the user.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n"
. "\\nIt was not possible to conduct a delete query in "
. "order to remove any rows belonging to the $doc2delete "
. "document type from the sbmCATEGORIES table.\\nWhen the "
. "delete query was executed, it produced an error. This "
. "means that it is necessary\\nto manually remove any "
. "rows belonging to the $doc2delete doctype that may be "
. "present in the sbmCATEGORIES table.');\n</SCRIPT>\n");
} // END if
# Now delete the entries for the doctype's function in the actual functions
# table.
$q6Res = mysql_query("DELETE FROM sbmFUNCTIONS WHERE doctype = '"
. "$doc2delete'");
if(!$q6Res)
{
# Unable to delete. Alert the user.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n"
. "\\nIt was not possible to delete the functions\\nof the "
. "$doc2delete document type from the functions table.\\n"
. "\\nThis means that it will be necessary to manually "
. "delete any rows in this table relating to the "
. "$doc2delete doctype.');\n</SCRIPT>\n");
} // END if
# Now delete the entries for the doctype's parameters in the actual parameters
# table.
$q7Res = mysql_query("DELETE FROM sbmPARAMETERS WHERE doctype = '"
. "$doc2delete'");
if(!$q7Res)
{
# Unable to delete. Alert the user.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n"
. "\\nIt was not possible to delete the parameters\\nof the "
. "$doc2delete document type from the parameters table.\\n"
. "\\nThis means that it will be necessary to manually "
. "delete any rows in this table relating to the "
. "$doc2delete doctype.');\n</SCRIPT>\n");
} // END if
# Now delete the entry for the doctype in the "sbmSUBMISSIONS"
# table.
$q8Res = mysql_query("DELETE FROM sbmSUBMISSIONS WHERE doctype = '"
. "$doc2delete'");
if(!$q8Res)
{
# Unable to delete. Alert the user.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n"
. "\\nIt was not possible to delete the details\\nof the "
. "$doc2delete document type from the sbmSUBMISSIONS table.\\n"
. "\\nThis means that it will be necessary to manually "
. "delete any rows in this table relating to the "
. "$doc2delete doctype.');\n</SCRIPT>\n");
} // END if
# Now delete the entry for the doctype in the "sbmCOLLECTION_sbmDOCTYPE"
# table.
$q9Res = mysql_query("DELETE FROM sbmCOLLECTION_sbmDOCTYPE WHERE id_son = '"
. "$doc2delete'");
if(!$q9Res)
{
# Unable to delete. Alert the user.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n"
. "\\nIt was not possible to delete the details\\nof the "
. "$doc2delete document type from the sbmCOLLECTION_sbmDOCTYPE table.\\n"
. "\\nThis means that it will be necessary to manually "
. "delete any rows in this table relating to the "
. "$doc2delete doctype.');\n</SCRIPT>\n");
} // END if
# Now delete the entry for the doctype in the actual "sbmDOCTYPE"
# table.
$q5Res = mysql_query("DELETE FROM sbmDOCTYPE WHERE sdocname = '"
. "$doc2delete'");
if(!$q5Res)
{
# Unable to delete the record of the doctype from the
# sbmDOCTYPE table. Alert the user.
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n"
. "\\nIt was not possible to delete the details\\nof the "
. "$doc2delete document type from the sbmDOCTYPE table.\\n"
. "\\nThis means that it will be necessary to manually "
. "delete any rows in this table relating to the "
. "$doc2delete doctype.');\n</SCRIPT>\n");
} // END if
# Our work here is done, so we can alert the user of this, and
# then redirect the browser to the "home page".
print("<P STYLE=\"text-size: medium; color: green; text-align"
. ": center; font-weight: bold\">The $doc2delete document typ"
. "e has been deleted from the " . DOCS_DATABASE
. " database.</P>\n");
print("<SCRIPT TYPE='text/javascript'>\nalert('The "
. "$doc2delete document type has been deleted from the "
. DOCS_DATABASE . " database.\\n\\nYou should not ignore any "
. "warnings that you may have received on the screen during "
. "the process of this deletion, as these may refer to\\nrows"
. " that could not be deleted for this doctype.');\n"
. "</SCRIPT>\n");
# Redirect the browser...
print("<FORM ACTION='index.php' METHOD='post' "
. "NAME='referForm'>\n"
. "<INPUT TYPE='hidden'>\n</FORM>\n");
print("<SCRIPT TYPE='text/javascript'>\n"
. "setTimeout(\"document.referForm.submit();\", 0);\n"
. "</SCRIPT>\n");
} // END if
else
{
# Damn, query failed...
# Alert the user, and redirect browser to
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:\\n\\n"
. "It was not possible to conduct a query to retrieve the "
. "details of the submissions belonging\\nto the $doc2delete "
. "document type from the sbmIMPLEMENT table of the "
. DOCS_DATABASE . " database.\\n\\nWhen the query to retrieve "
. "this information was executed, it produced an error.\\n\\n"
. "This meant that it was not possible to delete the details "
. "of the $doc2delete document type from the " . DOCS_DATABASE
. " database,\\nas if it has any submissions, they could not "
. "be deleted, and as a result, data inconsistencies would be"
. " created.\\n\\nAs no further action can be taken by the "
. "WebSubmit Administrator regarding this doctype deletion, your "
. "browser has\\nbeen redirected to the main page. However, "
. "you should look into the cause of this query error,\\nas "
. "it should not have occurred.');\n</SCRIPT>\n");
} // END else
} // END if
else
{
# In this case, this is the first call to the script, so we just
# need to display the interface for selecting which doctype to
# delete.
# Display a title...
print("<P CLASS=\"errorMsg\">Delete A Doctype</P>\n");
# Get all of the doctypes...
$myRes = mysql_query("SELECT sdocname, ldocname FROM sbmDOCTYPE "
. "ORDER BY ldocname");
if($myRes)
{
# In this case, the query worked...
# Make a little info box...
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 can "
. "delete a doctype and all of its submissions and their "
. "elements.<BR>Simply choose the doctype from the list, "
. "and click on the \"REMOVE DOCTYPE\" button.</P>\n</TD>\n"
. "</TR>\n</TABLE>\n");
# Make the input form for the element deletion...
print("<FORM ACTION='removeDoctypeEDS.php' METHOD='post'>\n"
. "<INPUT TYPE='hidden' NAME='killIt' VALUE='true'>\n"
. "<TABLE ALIGN='center' CELLSPACING=0 CELLPADDING=0 "
. "BORDER=0>\n<TR>\n<TH ALIGN='right' BGCOLOR='#87CEFA'>"
. "Document Type:&nbsp;</TH>\n<TD BGCOLOR='#FFFFCC' "
. "ALIGN='center'><SELECT NAME='doc2delete'><OPTION SELECTED "
. "VALUE='DO_NOT_DELETE'>Select A Doctype To Delete"
. "</OPTION>");
# Now fill the select list with all of the doctype values
while(list($code, $desc) = mysql_fetch_row($myRes))
{
print("<OPTION VALUE='"
. ereg_replace("'", "&#39;",
htmlspecialchars($code))
. "'>"
. ereg_replace("'", "&#39;",
htmlspecialchars($desc))
. "</OPTION>\n");
} // END while
# Close up the table...
print("</SELECT></TD>\n</TR>\n</TABLE>\n");
# Produce the submit button...
print("<TABLE ALIGN='center' BORDER=0>\n<TR>\n<TD ALIGN='"
. "center'><INPUT TYPE='button' VALUE='REMOVE DOCTYPE' "
. "onClick=\"for(i=0; i < doc2delete.length; i++) { "
. "if(doc2delete[i].selected) { break; } }"
. " if(doc2delete[i].value != 'DO_NOT_DELETE') { "
. "if(confirm('WARNING! YOU ARE ABOUT TO REMOVE THIS "
. "DOCTYPE FROM EDS!\\n ARE YOU SURE?')) { submit(); }}"
. " else { alert('Select A document Type from the list!'); "
. "}\">\n</TD>\n</TR>\n</TABLE>\n</FORM>\n");
} // END if
else
{
# In this case, the query failed, so we can just output the
# relevant error message, and provide a button for the user to
# click to get back to the "index.php" page.
# Make a message on the screen...
print("<P CLASS=\"errorMsg\"><SPAN STYLE=\"color: red\">ERRO"
. "R:</SPAN> It was not possible to obtain a list of documen"
. "t types from the sbmDOCTYPE table.<BR>This means that it is "
. "not possible to delete a doctype.</P>\n");
# Provide a button for the user to press to escape this
# situation
print("<FORM ACTION='index.php' METHOD='post'>\n<TABLE ALIG"
. "N='center' BORDER=0 CELLSPACING=0 CELLPADDING=0>\n<TR>\n<"
. "TD ALIGN='center'>\n<INPUT TYPE='button' VALUE='OK' "
. "onClick=\"submit();\">\n</TD>\n</TR>\n</TABLE>\n</FORM>"
. "\n");
} // END else
} // 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);
if (!$auth[0])
outWarning($auth[1]);
else
displayRemoveDoctypePage($killIt);
/************************End of main script***************************/
</protect>
?>

Event Timeline