Page MenuHomec4science

newFunc.php.wml
No OneTemporary

File Metadata

Created
Fri, May 3, 23:02

newFunc.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="Add a function" \
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_listfunctions"
<?
<protect>
## $Id$
## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDS Invenio WML SOURCES.
/*************************Function Declarations***********************/
function changePageFocusButton($action, $buttonTxt)
{
/**************************************************************
This function has the purpose of outputting a finish button to
allow the user to end the actions that they are carrying out.
The function basically outputs a form with only one input button,
which is clicked by the user to leave the current page. Clicking
the finish button sends the page focus to whatever page name is
passed as an argument to the function.
Created: 01/10/2000
Last Modified: 03/10/2000
**************************************************************/
print("<TABLE ALIGN=\"center\" BORDER=0 CELLPADDING=0 "
. "CELLSPACING=0>\n<TR>\n<TD ALIGN=\"center\">\n"
. "<FORM ACTION=\"$action\" METHOD=\"post\">\n"
. "<INPUT TYPE=\"button\" VALUE='$buttonTxt' "
. "onClick=\"submit();\">\n"
. "</FORM>\n</TD>\n</TR>\n</TABLE>\n");
} // END function changePageFocusButton($action, $buttonTxt)
//****************
function displayBlankForm()
{
/***************************************************************
This function will display a blank form that will allow the user
to enter a new function into the WebSubmit system. The function will
produce a form with 2 inputs - one for the function name, and
another for the function description.
Created: 02/10/2000
Last Modified: 03/10/2000
***************************************************************/
global $URLPATH;
// Add a description of the page...
print("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 "
. "ALIGN=\"center\" BGCOLOR=\"#E0E0E0\">\n<TR><TD "
. "ALIGN=\"left\">\n<SMALL><I>Using this facility, it is"
. " possible to add new functions to the WebSubmit system. "
. "The first stage, is to enter the name and the "
. "description of the function into the form below, and "
. "then submit these details...</I>\n</SMALL>\n"
. "</TD>\n</TR>\n</TABLE>\n");
// Get a list of the fields in the sbmALLFUNCDESCR table
$fields = mysql_list_fields(DOCS_DATABASE, "sbmALLFUNCDESCR");
// Get the length of the function field...
$funcLen = mysql_field_len($fields, 0);
// Now get the length of the description field...
$descLen = mysql_field_len($fields, 1);
// Open an HTML form to allow the user to enter the details of
// the function name, and description fields...
print("<FORM METHOD=\"post\" ACTION=\"newFunc.php\">\n"
. "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>\n"
. "<TR>\n<TD ALIGN=\"right\"><STRONG><H4>"
. "function:</H4></STRONG></TD>\n"
. "<TD>&nbsp;&nbsp;</TD>\n<TD ALIGN=\"left\"><INPUT TYPE="
. "\"text\" NAME=\"thefunction\" SIZE=$funcLen>\n"
. "</TD>\n</TR>\n<TR>\n<TD ALIGN=\"right\"><STRONG>"
. "<H4>description:</H4></STRONG></TD>\n"
. "<TD>&nbsp;&nbsp;</TD>\n<TD ALIGN=\"left\">"
. "<INPUT TYPE=\"text\" NAME=\"description\" "
. " SIZE=60></TD>\n</TR>\n</TABLE>\n");
print("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 "
. "ALIGN=\"center\">\n"
. "<INPUT TYPE=\"hidden\" NAME=\"commitFunction\" "
. "VALUE=\"true\">\n"
. "<TR>\n<TD ALIGN=\"center\">\n<INPUT TYPE=\"button\" "
. "VALUE=\"SAVE DETAILS\" onClick=\"if(thefunction.value =="
. " '') { alert('A function name must be entered!'); }"
. " else if(confirm('Are you sure you wish to commit this"
. " function to WebSubmit?')) { submit(); "
. "}\">\n</TD>\n</FORM>\n"
. "<FORM ACTION=\"listFunctions.php\" METHOD=\"post\">\n<TD>\n"
. "<INPUT TYPE=\"button\" VALUE=\"CANCEL\" "
. "onClick=\"submit();\">\n</TD>\n</FORM>\n</TR>\n"
. "</TABLE>\n");
}
//***************
function displayPage ()
{
global $commitFunction,$thefunction,$description,$tableSelected,$insertParam,$function,$newParam,$theParam,$updateFunDets;
// Test to see which type of call to this page this actually is, and
// take the appropriate action based upon this...
if($commitFunction)
{
// user entered the name &/or description for the new function, and has
// chosen to commit it to the database.
if($lockRes = mysql_query("LOCK TABLES sbmALLFUNCDESCR WRITE"))
{
$commitResult = mysql_query("INSERT INTO sbmALLFUNCDESCR
(function, description) VALUES ('$thefunction',
'$description')");
$unlockRes = mysql_query("UNLOCK TABLES");
if($commitResult)
{
// function has been successfully added to DB
// Send an email to the administrator, informing them
// that a new function has been added to the system..
$dateDets = getDate();
$messageText = "The $thefunction "
. "function was added to the submission system on " . $dateDets['weekday']
. " " . $dateDets['mday'] . " " . $dateDets['month'] . " "
. $dateDets['year'] . ", at " . $dateDets['hours'] . ":"
. $dateDets['minutes'] . ".\n\nWebSubmit Administrator.";
mail(ADMIN_EMAIL, "Warning: $thefunction Function Created",
$messageText, "From: WebSubmit_Administrator");
print("<H3 ALIGN=\"center\">The <EM>$thefunction</EM> "
. "Function Has Been Added</H3>\n<BR>\n");
// Now display all of the functions details, and offer the
// opportunity to add parameters to the function
makePageBody($thefunction, "newFunc.php");
changePageFocusButton("listFunctions.php", "FINISHED");
}
else
{
// unable to insert new function data
print("<DIV STYLE=\"color: navy; font-weight: bold; font-size:"
. " large; text-align: center\"><SPAN STYLE=\"color: red\">Error"
. ":</SPAN> Unable to commit function details.</DIV>\n<BR>\n");
}
}
else
{
// couldn't get write lock -> output error message.
print("<DIV STYLE=\"color: navy; font-weight: bold; font-size:"
. " large; text-align: center\"><SPAN STYLE=\"color: red\">Error"
. ":</SPAN> Unable to commit details.</DIV>\n<BR>\n");
displayBlankForm();
}
}
elseif($tableSelected || $insertParam)
{
// Add parameter to function
if(isset($tableSelected))
{
print("<H3 ALIGN=\"center\">The <EM>$function</EM>"
. " Function</H3>\n<BR>\n");
// Make the page, including the table of parameters
makePageBody($function, "newFunc.php");
changePageFocusButton("listFunctions.php", "FINISHED");
} // END if
elseif($insertParam)
{
// here, we actually commit the new paramater, and then recall
// the whole thing
if($lockRes = mysql_query("LOCK TABLES sbmFUNDESC WRITE"))
{
if ($newParam != "")
$insertParamRes = mysql_query("INSERT INTO sbmFUNDESC
VALUES('$function', '$newParam')");
else
$insertParamRes = mysql_query("INSERT INTO sbmFUNDESC
VALUES('$function', '$theParam')");
$unlockRes = mysql_query("UNLOCK TABLES");
// email admin to let them know that the parameter has been added
$dateDets = getDate();
$messageText = "A parameter was "
. "added to the new $function function on "
. $dateDets['weekday']
. " " . $dateDets['mday'] . " " . $dateDets['month'] . " "
. $dateDets['year'] . ", at " . $dateDets['hours'] . ":"
. $dateDets['minutes'] . ".\n\n"
. "If the function is to be used by any doctypes/actions, rows "
. "should be added for the relevant doctype in the "
. "relevant tables of the various parameters."
. "\n\nWebSubmit Administrator.";
mail(ADMIN_EMAIL, "Parameter Added To New $function "
. "Function",
$messageText, "From: WebSubmit_Administrator");
}
else
{
// Unable to lock table.
print("<DIV STYLE=\"color: navy; font-weight: bold; "
. "font-size: large; text-align: center\"><SPAN "
. "STYLE=\"color: red\">Error:</SPAN> Unable to commit"
. " updates.</DIV>\n<BR>\n");
}
print("<H3 ALIGN=\"center\">The <EM>$function</EM>"
. " Function</H3>\n<BR>\n");
// Display the page again, so more parameters can be added.
makePageBody($function, "newFunc.php");
changePageFocusButton("listFunctions.php", "FINISHED");
} // END elseif($insertParam)
} // END elseif($tableSelected || $insertParam)
elseif($updateFunDets)
{
// update the value of the description field
unset($updateFunDets);
// Place WRITE lock on the sbmALLFUNCDESCR table
if($lockRes = mysql_query("LOCK TABLES sbmALLFUNCDESCR WRITE"))
{
$updateDescRes = mysql_query("UPDATE sbmALLFUNCDESCR SET
description = '$description' WHERE function
= '$function'");
$unlockRes = mysql_query("UNLOCK TABLES");
if(!$updateDescRes)
{
// unable to update the value of description for some reason, and the
// user should be informed of this
print("<SCRIPT TYPE=\"text/javascript\">alert('ERROR:\\n\\n"
. "Unable to update value of description for $function\\n"
. "function in sbmALLFUNCDESCR table.\\n\\n"
. "Please inform administrator.</SCRIPT>\n");
} // END if
mysql_free_result($updateDescRes);
} // END if
else
{
// Couldn't lock table. Output error message.
print("<DIV STYLE=\"color: navy; font-weight: bold; font-size:"
. " large; text-align: center\"><SPAN STYLE=\"color: "
. "red\">Error:</SPAN> Unable to retrieve information.</DIV>\n"
. mysql_error()."<BR>\n");
}
print("<H3 ALIGN=\"center\">The <EM>$function</EM>"
. " Function</H3>\n<BR>\n");
makePageBody($function, "newFunc.php");
changePageFocusButton("listFunctions.php", "FINISHED");
}
else
{
// Display a blank form into which the details of the function can
// be entered by the user
displayBlankForm();
}
}
/**********************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