Page MenuHomec4science

addActionEDS.php.wml
No OneTemporary

File Metadata

Created
Mon, Nov 18, 12:51

addActionEDS.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="Create a new action" \
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 TYPE='text/javascript'>
<!-- hide
function validateIsInt(param)
// This function validates its parameter to ensure that it is an integer
// value.
// Author: Nicholas Robinson
// Email: Nicholas.Robinson@cern.ch
// ca8nro@yahoo.co.uk
// Created: 16/11/2000
// Last Modified: 16/11/2000
{
// Create a flag to indicate that we have found a non-digit value
var nonDigit = false;
for(index = 0; index < param.length; index++)
{
if(!(param[index] >= 0 && param[index] <= 9))
{
// In this case, we've found a non-digit value, and can stop
// searching, as the parameter is clearly not an integer
nonDigit = true;
break;
} // END if
} // END for
return true;
} // END function validateIsInt(param)
function checkRequired(sactname, lactname)
// This is a function to ensure that the user enters the required
// parameters for the action.
// Author: Nicholas Robinson
// Email: Nicholas.Robinson@cern.ch
// ca8nro@yahoo.co.uk
// Created: Long ago!
// Last Modified: 19/12/2000
{
// If the field is left blank by the user...
if((sactname == "") || (lactname == ""))
{ // Alert them, and return false.
alert("Values must be entered into the Action Code,"
+ "Long Action Name fields.");
return false;
} // End if
else // If level has been filled by the user...
{
return true;
} // End else
} // End function checkRequired(param)
// -->
</SCRIPT>
<?
/*********************Function Descriptions***************************/
function enterEDSaction($lactname = "", $dir = "",
$actionbutton = "", $statustext = "", $sactname = "")
{
/*******************************************************************
This function has the task of creating a form in which a user can
enter a new EDS action.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 19/12/2000
Last Modified: 17/01/2001
*******************************************************************/
# 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\">Below, is "
. "a form in which you can enter the details of a new action."
. "<BR><BR>When you enter a new action, it will not be "
. "accepted by the system unless you have given it a unique "
. "\"Action Code\".<BR>"
. "<BR>You can commit this new action to the database by "
. "clicking on \"SAVE DETAILS\".</P>\n</TD>\n</TR>\n</TABLE>"
. "\n");
# Make a horizontal rule to divide the page sections...
drawSeparator();
print("<FORM ACTION='addActionEDS.php' METHOD='post'>\n"
. "<INPUT TYPE='hidden' NAME='commitAct' VALUE='true'>\n"
. "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN='center' "
. "WIDTH='100%'>\n");
# Get the columns list
$columns = mysql_list_fields(DOCS_DATABASE, "sbmACTION");
# Get the number of fields
$numTblFlds = mysql_num_fields($columns);
# Get the data, so that it can be committed for the modification
# date field (md)...
$dateDets = makeEDSmdDate();
# Now display the upper part of the table - fields that are system
# generated...
print("<TABLE WIDTH='100%' ALIGN='center' CELLSPACING=0 "
. "CELLPADDING=0 BORDER=0>\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='"
. "$dateDets'>\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='$dateDets'>\n</TD>\n</TR>\n");
# Now create the fields that the user can edit...
# Make the sactname field...
print("<TR>\n<TH BGCOLOR='#87CEFA' ALIGN='right' WIDTH='20%'>\n"
. "Action Code:&nbsp;</TH>\n<TD ALIGN='left' WIDTH='80%' "
. "BGCOLOR='#FFFFCC'>\n<INPUT TYPE='text' NAME='sactname' SIZE="
. mysql_field_len($columns, 1) . " VALUE='"
. ereg_replace("'", "&#39;",
htmlspecialchars(${mysql_field_name($columns, 1)}))
. "'>\n</TD>\n</TR>\n");
print("<input type=\"hidden\" name=\"actionbutton\" value=\"\">");
for($indx = 0; $indx < $numTblFlds; $indx++)
{
# Get the name of the current field...
$currentField = mysql_field_name($columns, $indx);
# Ensure we dont once again print certain fields
if(($currentField != "cd") && ($currentField != "md")
&& ($currentField != "sactname")&& ($currentField != "actionbutton"))
{
# First display the form field label...
print("<TR>\n<TH BGCOLOR='#87CEFA' ALIGN='right' "
. "WIDTH='20%'>\n");
if($currentField == "lactname")
{
print("Action Description:&nbsp;");
} // END if
else
{
print("$currentField" . ":&nbsp;");
} // END else
print("&nbsp;</TH>\n<TD ALIGN='left' WIDTH='80%' "
. "BGCOLOR='#FFFFCC'>\n<INPUT TYPE='text' NAME="
. "'$currentField' SIZE=");
if(mysql_field_type($columns, $indx) == "blob")
{
print("60");
} // END if
else
{
print(mysql_field_len($columns, $indx));
} // END else
print(" VALUE='" . ereg_replace("'", "&#39;",
htmlspecialchars(${mysql_field_name($columns, $indx)}))
. "'>\n</TD>\n</TR>\n");
} // END if
} // END for
# Now that the table has been created, it can be closed...
print("</TABLE>\n");
# Now make the commit buttons that must be used for the form...
print("<TABLE ALIGN='center' CELLSPACING=2 CELLPADDING=2 BORDER=0>"
. "<TR>\n<TD ALIGN='left'>\n<INPUT TYPE='button' VALUE='SAVE DETAIL"
. "S' onClick=\"if(checkRequired(sactname.value, lactname.value"
. ")) { if(confirm('Really Commit This New Action"
. "?')) { submit(); } else { return false; } }\">\n</TD><TD ALIGN='"
. "center'>\n<INPUT TYPE='button' VALUE='RESET' onClick=\"reset();"
. "\">\n</TD>\n</FORM>\n<FORM ACTION='allActionsEDS.php' METHOD='po"
. "st'>\n<TD ALIGN='left'>\n<INPUT TYPE='button' VALUE='CANCEL' onC"
. "lick=\"submit();\">\n</TD>\n</FORM>\n</TR>\n</TABLE>\n");
} // END function enterEDSaction()
function displayPage()
{
global $commitAct,$sactname,$lactname,$dir,$actionbutton,$statustext;
if($commitAct)
{
# In this case, the user has entered the details of the new
# action, and these details should be committed to the DB.
# Make sure the sactname field is uppercase...
$sactname = strtoupper($sactname);
# First we can ensure that there is not already an action in the
# DB with the same name as that given to the new action...
# Lock table
mysql_query("LOCK TABLES sbmACTION READ");
$checkRes = mysql_query("SELECT sactname FROM sbmACTION WHERE "
. "sactname = '$sactname'");
if($checkRes)
{
# In this case, the query has worked , so carry on...
if(mysql_num_rows($checkRes) != 0)
{
# Ah-Hah! They have tried to add an action whose ID Code
# is already in use!
mysql_query("UNLOCK TABLES");
# Let the check result go...
mysql_free_result($checkRes);
# Give them an explanatory error message...
print("<P STYLE=\"color: red; text-align: center; font-"
. "size: small; font-weight: bold\">Unable To Commit These"
. " Details. The Action Code Used Already Exists. Try "
. "Again With A New Code.</P>\n");
# Now a JavaScript alert...
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: It "
. "was not possible to commit these details for the new "
. "action because the action code chosen already exists in"
. DOCS_DATABASE . ".\\n\\nTry submitting he details again "
. "with a new action code.</SCRIPT>\n");
# Now redisplay the page...
enterEDSaction($lactname, $dir, $actionbutton,
$statustext);
} // END if
else
{
# The details should now be fine to commit...
# Unlock tables.
mysql_query("UNLOCK TABLES");
# Let the previous result set go...
mysql_free_result($checkRes);
# Make the insert string...
$updStr = "INSERT INTO sbmACTION (lactname, sactname, dir, "
. "cd, md, actionbutton, statustext) VALUES"
. "('$lactname', '$sactname', '$dir', '$cd', '$md', "
. "'$actionbutton', '$statustext')";
# LOCK sbmACTION table as write.
mysql_query("LOCK TABLES sbmACTION WRITE");
# Commit the details...
$updRes = mysql_query($updStr);
if($updRes)
{
# Query worked...
if(mysql_affected_rows() == 1)
{
# Insertion successful...alert user, email admin, and
# redirect browser...
# UNLOCK TABLES.
mysql_query("UNLOCK TABLES");
print("<SCRIPT TYPE='text/javascript'>\nalert('New "
. "Action Added.');\n</SCRIPT>\n");
print("<P STYLE=\"color: green; text-align: center; "
. "font-size: large\">The New Action Has Been Added."
. "</P>\n");
$msgTxt = "A new action has been added to the "
. DOCS_DATABASE;
$msgTxt .= " database.";
$msgTxt .= " This action is the $sactname "
. "action.\n\n";
$msgTxt .= "WebSubmit Administrator (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$sactname Action Added to "
. "EDS/WebSubmit", $msgTxt,
"From: WebSubmit_Administrator");
# Redirect the browser...
print("<FORM ACTION='allActionsEDS.php' METHOD='post"
. "' NAME='referForm'>\n<INPUT TYPE='hidden'>"
. "</FORM>\n");
print("<SCRIPT TYPE='text/javascript'>\n"
. "setTimeout(\"document.referForm.submit();\", "
. "1000);\n</SCRIPT>\n");
} // END if
else
{
# Unable to add the thing...
# Now unlock the ACTION table.
mysql_query("UNLOCK TABLES");
# Alert the user...
print("<P STYLE=\"color: red; text-align: center; "
. "font-size: small; font-weight: bold\">Unable To "
. "Commit These Details. Try Again Later.</P>\n");
print("<SCRIPT TYPE='text/javascript'>\nalert('"
. "ERROR: It was not possible to commit the details"
. " for the new action.\\n\\nTry again, or contact "
. "the system administrator.');\n</SCRIPT>\n");
# Redisplay the form - with the details...
enterEDSaction($lactname, $dir, $actionbutton,
$statustext, $sactname);
} // END else
} // END if
else
{
# Couldn't execute insert query
# Now unlock the sbmACTION table.
mysql_query("UNLOCK TABLES");
# Alert the user...
print("<P STYLE=\"color: red; text-align: center; "
. "font-size: small; font-weight: bold\">Unable To "
. "Execute The Query To Commit These Details. Try "
. "Again Later.</P>\n");
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:"
. " It was not possible to execute the query to commit"
. " the details for the new action.\\n\\nTry again, or"
. " contact the system administrator.');\n</SCRIPT>\n");
# Redisplay the form - with the details...
enterEDSaction($lactname, $dir, $actionbutton,
$statustext, $sactname);
} // END else
} // END else
} // END if
else
{
# In this case, we were unable to read from the sbmACTION table
# to see if there was already a record withthe same action
# code as the action that we have just attempted to add. We
# should therefore not try to add the new action, incase we
# cause key inconsistencies in the sbmACTION table. Instead,
# simply redisplay the form, with the new action data in it.
# Unlock tables.
mysql_query("UNLOCK TABLES");
# Alert the user of the problem...
print("<P STYLE=\"color: red; text-align: center; font-size: "
. "small; font-weight: bold\">Unable To Commit These Details."
. " Try Again Later.</P>\n");
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: It was "
. "not possible to perform a query upon the sbmACTION table.\\n"
. "This meant that it was not possible to commit the new acti"
. "on\\n\\nTry again later, or inform the system administrato"
. "r.');\n</SCRIPT>\n");
# Now redisplay the form...
enterEDSaction($lactname, $dir, $actionbutton,
$statustext, $sactname);
} // END else
} // END if
else
{
# In this case, this is the first call to the page, so we should
# just display the form in which the new action will be entered.
enterEDSaction();
} // 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
displayPage();
/************************End of main script***************************/
</protect>
?>

Event Timeline