Page MenuHomec4science

addFunctions.php.wml
No OneTemporary

File Metadata

Created
Wed, Jul 31, 02:03

addFunctions.php.wml

## $Id$
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005, 2006 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="Add a functions for <i><protect><?print "$action </i>on<i> $doctype";?></protect></I>" \
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 CDSware WML SOURCES.
?>
<SCRIPT TYPE='text/javascript'>
<!-- hide
function checkScoreStep(score, step)
// This function checks that the user has entered numeric
// values for the score and step fields
{
// create a variable, foundNonNumeric, which will be a boolean
// variable, to determine whether or not the user has input a
// non-numeric value for score or step.
var foundNonNumericScore = false;
var foundNonNumericStep = false;
if(score != "" && step != "")
{
for(index = 0; index < score.length; index++)
{
if(!(score.charAt(index) >= "0" && score.charAt(index) <= "9"))
{
foundNonNumericScore = true;
break;
} // End if
} // End for
if(!foundNonNumericScore)
{
for(index = 0; index < step.length; index++)
{
if(!(step.charAt(index) >= "0" && step.charAt(index) <= "9"))
{
foundNonNumericStep = true;
break;
} // End if
} // End for
if(!foundNonNumericStep)
{
return true;
} // end if
else
{
alert('Only Numeric Values Are Legal For score and step'
+ ' fields!');
return false;
} // End else
} // End if
else
{
alert('Only Numeric Values Are Legal For score');
return false;
} // End else
} // End if
else
{
alert('It is necessary to enter values into both\n the score'
+ ' and step fields!');
return false;
} // End else
} // End function checkScoreStep(score, step)
// -->
</SCRIPT>
<?
/**********************Function Declarations**************************/
function createActFunsList($selQRes, $action, $doctype)
{
/*****************************************************************
This function has the task of displaying either a table of
functions belonging to a given action on a given doctype, or
displaying a message informing the user that the action for the
doctype has no functions if this is the case.
The function is used in this script to display the functions &
their details (step etc) in a table alongside the new function
input form, so that the user can see the current functions etc
for an action on a doctype as they decide uppon values for their
new function.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
Created: 10/10/2000
Lsat Modified: 05/02/2001
*****************************************************************/
# Display an explanation for the top of the column...
print("<H4 STYLE=\"background-color: transparent; text-align: "
. "center\">Functions of the $action action<BR>on the $doctype"
. " document type</H4>\n");
if(mysql_num_rows($selQRes) > 0)
{
# If this clause has been reached, there are functions
# belonging to the current action on the given doctype, and
# therefore we can create a table to display them in for
# reference when adding the new function.
# Get the fields names of the fields in the relevant functions
# table...
$tableFields = mysql_list_fields(DOCS_DATABASE, "sbmFUNCTIONS");
print("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 "
. "ALIGN='center'>\n<TR BGCOLOR='#CCDDFF'>");
# Display the column titles in the table
makeTableHeaderRow($tableFields, 2);
print("</TR>");
# Now that the table headers have been displayed, it is
# possible to display the table body.
makeTbleBdy($selQRes,2);
# Now close the table, as it is finished.
print("</TABLE>\n");
# Destroy all query result sets etc that are no longer needed
mysql_free_result($tableFields);
} // END if
else
{
# If this clause has been reached, it means that there are no
# functions belonging to the current action on the current
# doctype, and so we should just display a message stating
# this, as opposed to a table of functions.
print("<H4 STYLE=\"text-align: center\">The $action action on"
. " the $doctype<BR>document type has no functions</H4>");
} // END else
} // END function createActFunsList($selQRes)
//*****************
function makeTbleBdy($result, $forIndxStrt = 0)
{
/*******************************************************************
This function is a very simple function that creates the body of
a table, with no bells or whistles, by taking a result set, and
displaying each row of the result set in a row of the table. It
closes each row after it has been displayed. The function is
passed the $result variable, which contains the result set, and
the $forIndxStrt variable, which simply contains an integer,
allowing the function to commence each row at a given cell index.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
Created: 10/10/2000
Last Modified: 10/10/2000
*******************************************************************/
# Get the number of fields in the result set
$numTblFlds = mysql_num_fields($result);
while($dataRow = mysql_fetch_array($result))
{
print("<TR BGCOLOR='#FFFFCC'>\n");
# Display each field in a given row...
for($indx = $forIndxStrt; $indx < $numTblFlds; $indx++)
{
print("<TD ALIGN='center'>"
. ereg_replace("'", "&#39;",
htmlspecialchars($dataRow[$indx]))
. "</TD>\n");
} // END for
# Now close up the table row...
print("</TR>\n");
} // END while
} // END function
//**********************
function pageFocusHome()
{
/******************************************************************
This function is just a simple page to redirect the browser to
the prototype.php page (the administrators home page).
is the page that displays details of a document type and all of
its actions. The function makes a quick form with no inputs, but
an action of prototype.php.
It then pauses for 2 seconds, before submitting this form, and
hence calling the prototype.php script.
This function uses client-side JavaScript to automatically submit
the form after a time delay.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
Created: 04/09/2000
Last Modified: 06/02/2001
******************************************************************/
# Make the invisible html form...
print("<FORM ACTION='index.php' METHOD='post' NAME='referForm'>\n"
. "<INPUT TYPE='hidden'>\n"
. "</FORM>\n");
# Now, pause for 2 seconds, and then submit the form...
print("<SCRIPT TYPE='text/javascript'>\n"
. "setTimeout(\"document.referForm.submit();\", 2000);\n"
. "</SCRIPT>\n");
} // END function pageFocusHome()
//***************
function makeSelectList($queryResult, $listName, $defaultCode,
$defaultText, $valueIndex, $textIndex)
{
/****************************************************************
This function has the task of making a drop down list (type
SELECT in HTML). The list made is of course part of a form, but
this form is not made by this function. It is intended that this
function will be called after the form has been opened, and when
it is desired that a SELECT list be added to a form.
This function is passed 6 variables upon calling. They are as
follows:
1. $queryResult. This is the result of mysql_query - a select
query.
2. $listName. This is the name that the SELECT list will be
given.
3. $defaultCode. This is the default value of the first selected
item of the list.
4. $defaultText. This is the text of the first default selected
item.
5. $valueIndex. The values for each <OPTION> of the SELECT list
will be taken from the array dataRow, which will contain all
fields of a single row of queryResult. $valueIndex will be
the array index for the cell of dataRow that contains the
value desired for the VALUE attribute of the OPTION.
6. $textIndex. This is another index of the dataRow array. It
will contain the text that is to go between OPTION tags, and
hence what the user sees.
I hope this makes sense!
The function will basically build the SELECT list, and will fill
it with the desired values from each row of queryResult. The
SELECT list will then be closed, but note that the form WILL NOT
BE CLOSED.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
Created: 29/08/2000
Last Modified: 06/02/2001
****************************************************************/
print("<SELECT NAME='$listName'>\n"
. "<OPTION SELECTED VALUE='$defaultCode'>$defaultText"
. "</OPTION>\n");
# If the query executed successfully, utilise the data
# provided by it. This basically means that if the query was
# unable to trawl any data from the table for cloning it will simply
# ignore the next section of code, and the list will only have the
# default value in it, and hence PHP won't throw out any errors,
# etc...
if($queryResult)
{
while($dataRow = mysql_fetch_array($queryResult))
{
print("<OPTION VALUE='"
. htmlspecialchars($dataRow[$valueIndex])
. "'>");
print(ereg_replace("'", "&#39;",
htmlspecialchars($dataRow[$textIndex])));
print("</OPTION>\n");
} // END while
} // END if
print("</SELECT>\n");
} // END function makeSelectList()
function displayPage($doctype)
{
global $addNow,$funToAdd,$score,$step,$action;
# Now conduct a test to determine the type of call to the page this
# actually is (it can either be the first call to the page, whereby
# the ability to input the new functions details is given to the
# user, or the second call to the page, whereby the actual addition
# processing is done.
if($addNow)
{
# If this condition has been reached, this call to the page is a
# call to actually commit the new function for the given action
# on the given doctype to the relevant functions table.
# It is now possible to commit the new function for the given
# action on the given doctype into the database...
$comStr = "INSERT INTO sbmFUNCTIONS (doctype, function, score, step, action) VALUES('$doctype', '$funToAdd', '$score', '$step','$action')";
$comRes = mysql_query($comStr);
if($comRes)
{
# Display an alert message on the screen of the user informing
# them of the sucessful addition of the new function to the
# given action on the given doctype.
print("<SCRIPT TYPE='text/javascript'>alert('The $funToAdd "
. "function was added to the $action action\\non the "
. "$doctype document type.\\n\\nYou should now examine the"
. " values for each\\nof the functions parameters, and "
. " ensure that\\nthere is an entry for them.\\n\\nYour"
. " browser has been diverted to the screen where you can"
. " investigate this.')</SCRIPT>\n");
# Now redirect the browser to the func.php page...
print("<FORM ACTION='func.php' METHOD='post' NAME='sub'>\n"
. "<INPUT TYPE='hidden' NAME='returnTo' "
. "VALUE='actionFunctions.php'>\n"
. "<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'>\n"
. "<INPUT TYPE='hidden' NAME='action' VALUE='$action'>\n"
. "<INPUT TYPE='hidden' NAME='functionName' "
. "VALUE='$funToAdd'>\n"
. "</FORM>\n"
. "<SCRIPT TYPE='text/javascript'>\n"
. "setTimeout(\"document.sub.submit();\", 0);\n"
. "</SCRIPT>\n");
# Get the current date and time...
$dateDets = getdate();
# Make the message...
$msgTxt = "Please be informed that the $funToAdd function was"
. " added to the $action action of the $doctype document "
. "type on "
. $dateDets['weekday'] . " " . $dateDets['mday'] . " "
. $dateDets['month'] . " " . $dateDets['year']
. ", at " . $dateDets['hours'] . ":"
. $dateDets['minutes'] . "."
. "\n\nWebSubmit Administrator.";
# Send the message...
mail(ADMIN_EMAIL, "$funToAdd Function Added to $action"
. ".$doctype Action", $msgTxt, "From: WebSubmit_Administrator");
} // END if
else
{
# If this clause has been reached, it means that the insert of
# the new function to the relevant functions has failed. As a
# result, the user should be informed of this by a javascript
# alert, and the browser should redirect to the WebSubmit
# Asdministrator main page.
print("<SCRIPT TYPE='text/javascript'>alert('The $funToAdd "
. "function could not be commited to the functions table,"
. "\\nand hence could not be added to the $action action for"
. " the $doctype document type.\\n\\nPlease Inform System "
. "Administrator.');</SCRIPT>\n");
# We should also email the administrator to inform them of
# this fault, or it may go unnoticed...
# Get the current date and time...
$dateDets = getdate();
# Make the message...
$msgTxt = "I have encountered an error!\n\nI was unable to "
. " add the $funToAdd function to the $action action of the"
. " $doctype document type. This is because I could not "
. "commit the details to the functions table.\n\nThis "
. "fault ocurred on "
. $dateDets['weekday'] . " " . $dateDets['mday'] . " "
. $dateDets['month'] . " " . $dateDets['year']
. ", at " . $dateDets['hours'] . ":"
. $dateDets['minutes'] . "."
. "\n\nYou should investigate this problem as soon as "
. "possible.\n\nWebSubmit Administrator.";
# Send the message...
mail(ADMIN_EMAIL, "ERROR: $funToAdd Function Not Added To "
. "${action}.$doctype", $msgTxt, "From: WebSubmit_Administrator");
# Now redirect the browser to the Administrator main page...
pageFocusHome();
} // END else
} // END if
else
{
# If this clause has been reached, it means that this is the
# first call to the page, whereby the details for inputting a new
# function should be presented to the user.
$selStr = "SELECT * FROM sbmFUNCTIONS WHERE doctype='$doctype' and action='$action'"
. " ORDER BY step, score";
# Execute this query...
$selQRes = mysql_query($selStr) or die("<H4>Unable to obtain a "
. "list of function for the $doctype doctype from the "
. "functions table. Processing Terminated.</H4>\n</TD>\n"
. "</TR>\n</TABLE>\n</BODY>\n</HTML>\n");
# Open a table with two columns, in which to display the page
print("<TABLE BORDER=0 ALIGN='center' WIDTH='100%' CELLSPACING=0"
. " CELLPADDING=0>\n<TR>\n<TD WIDTH='29%'"
. " ALIGN='center' VALIGN='top'>\n");
createActFunsList($selQRes, $action, $doctype);
# free space associated with unused variables/result sets
mysql_free_result($selQRes);
unset($selStr);
# Close the current page dividing table cell, then reopen another
# for the input new function form...
print("</TD>\n<TD WIDTH='1%'>\n&nbsp;</TD>\n<TD WIDTH='60%' "
. "VALIGN='top' ALIGN='center'>\n");
# Now that we have displayed the current usage of functions for
# the given action on the given doctype, it is possible to
# produce the 'addition of another function' facility...
print("<SPAN STYLE='text-align: center; color: navy; font-size:"
. " medium; font-weight: bold'>Add a function to the $action "
. "action of the $doctype document type</SPAN>\n");
# The first task is to obtain a list of all functions in WebSubmit
$funcQuery = mysql_query("SELECT function FROM sbmALLFUNCDESCR ORDER
BY function");
if($funcQuery)
{
# If the query has worked, we can create a select drop-down
# list to contain the functions. The user can then choose one
# of them to add to their action.
# Make a table to contain an input form...
print("<FORM ACTION='addFunctions.php' METHOD='post'>\n"
. "<INPUT TYPE='hidden' NAME='addNow' VALUE='true'>\n"
. "<INPUT TYPE='hidden' NAME='doctype' "
. "VALUE='$doctype'>\n"
. "<INPUT TYPE='hidden' NAME='action' VALUE='$action'>\n"
. "<TABLE WIDTH='100%' BORDER=0 ALIGN='center' "
. "CELLSPACING=0 CELLPADDING=0>\n<TR>\n<TD ALIGN='right'"
. ">\n<H4 STYLE=\"text-align: right\">Function to "
. "add:</H4></TD>\n<TD>&nbsp;</TD>\n<TD ALIGN='left'>\n");
# Create the list of functions...
makeSelectList($funcQuery, "funToAdd", "NO_FUNC",
"Select...", 0, 0);
print("</TD>\n</TR>\n<TR>\n<TD ALIGN='right'>\n<H4 STYLE=\""
. "text-align: right\">\nScore:</H4>\n</TD>\n"
. "<TD>&nbsp;</TD>\n<TD ALIGN="
. "'left'>\n<INPUT TYPE='text' SIZE=3 NAME='score'>\n"
. "</TD>\n</TR>\n<TR>\n<TD ALIGN='right'>\n<H4 STYLE=\""
. "text-align: right\">\nStep:</H4>\n</TD>\n<TD>&nbsp;"
. "</TD>\n<TD ALIGN='"
. "left'>\n<INPUT TYPE='text' SIZE=3 NAME='step'>\n"
. "</TD>\n</TR>\n<TD>&nbsp;</TD>\n</TR>\n<TR>\n<TD "
. "ALIGN='right'>\n<INPUT "
. "TYPE='button' VALUE='SAVE DETAILS' "
. "onClick=\"if(funToAdd.options[funToAdd.selectedIndex]"
. ".value != 'NO_FUNC') { if(checkScoreStep(score.value, "
. "step.value)) { if(confirm('You are about to add a "
. "function to the\\n$action action for the $doctype "
. "doctype.\\n\\nThis action will require you to manually"
. " provide values for \\nthe function parameters under "
. "this doctype.\\n\\nAre You Sure You Wish To Do "
. "This?')) { submit(); } } } else { alert('Select a "
. " function to add!'); }\">"
. "\n</TD>\n</FORM><FORM ACTION='actionFunctions.php?action=$action&doctype=$doctype' "
. "METHOD='post'>\n<INPUT TYPE='hidden' NAME='doctype' "
. "VALUE='$doctype'>\n<TD>&nbsp;</TD>\n<TD ALIGN='left'>"
. "\n<INPUT "
. "TYPE='button' VALUE='CANCEL' onClick=\"submit();\">\n"
. "</TD>\n</TR>\n</TABLE>\n</FORM>\n");
} // END if
else
{
# If this clause has been reached, the script has been able to
# query the sbmALLFUNCDESCR table in order to obtain a list of
# all of the WebSubmit functions. In this case, it is simply
# appropriate to display a suitable error message, and send
# the browser focus to the WebSubmit Administrator home page, as it
# is obviously not possible to add a function in this case...
print("<H3>ERROR: Unable To Retrieve WebSubmit Functions List"
. "</H3>\n");
# Now redirect the browser...
pageFocusHome();
} // END else
# Now that the main page has been displayed, it possible to
# close up the page organisation table.
print("</TD>\n</TR>\n</TABLE>\n");
} // 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
displayPage($doctype);
/************************End of main script***************************/
</protect>
?>

Event Timeline