Page MenuHomec4science

actionFunctions.php.wml
No OneTemporary

File Metadata

Created
Sat, Sep 21, 03:03

actionFunctions.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="List of 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 CDS Invenio WML SOURCES.
/***********************Function Declarations************************/
function displayFunctions($doctype, $action)
{
global $IMAGES;
$lockStr = "LOCK TABLES sbmFUNCTIONS READ";
# Apply a read lock to the given functions table...
if($lockRes = mysql_query($lockStr))
{
# Execute a query selecting a listing of the functions that make
# up an action for the given document type
$queryResult = mysql_query("SELECT * FROM sbmFUNCTIONS WHERE
doctype='$doctype' and action='$action' ORDER BY step, score");
# We must unlock our table...
$unlockRes = mysql_query("UNLOCK TABLES");
# If there were rows returned by this query (i.e. there are
# functions composing the given action on the given doctype, we
# can display them.
if(mysql_num_rows($queryResult) > 0)
{
# We can now create a table to display the query dynaset in...
print("<TABLE ALIGN='center' BORDER=1 CELLSPACING=0 "
. "CELLPADDING=0>");
# Open the first table row for the column headings...
print("<TR BGCOLOR='#CCDDFF'>");
# Get information about the fields in the table...
$columns = mysql_list_fields(DOCS_DATABASE, "sbmFUNCTIONS");
# Display all of the column headings
for($headerIndex = 2; $headerIndex < mysql_num_fields($columns);
$headerIndex++)
{
print("<TH>&nbsp; ");
print(mysql_field_name($columns, $headerIndex));
print("</TH>");
if(mysql_field_name($columns, $headerIndex) == "function")
{ # Add another column...
print("<TH>&nbsp;</TH>");
}
} // END for
# Now that we have added all of the header columns, we can add
# one more column header offering the user the ability to
# delete a function from the current action on the current
# doctype...
print("<TH STYLE=\"color: red\">Delete</TH>\n");
print("</TR>");
# Make a counter for the rows...
$rowCount = 0;
# Put the contents of the query dynaset into a temporary
# array...
while($dataRow = mysql_fetch_array($queryResult))
{
$allRows[$rowCount] = $dataRow;
$rowCount++;
} // End while
# Reset $rowCount to 0 for use in further processing...
$rowCount = 0;
# Now, we can display the body of the table...
for($i = 0; $i < mysql_num_rows($queryResult); $i++)
{
print("<TR BGCOLOR='#FFFFCC'>");
# For each column...
for($colIndex = 2; $colIndex < mysql_num_fields($columns);
$colIndex++)
{
if(mysql_field_name($columns, $colIndex) == "function")
# If the column is the function name,
# create a link to the description of
# that function in the fundesc table.
{
print("<TD ALIGN='center'>");
print("<A ");
print("HREF='func.php?functionName=");
print(urlencode($allRows[$i][$colIndex]));
print("&doctype=$doctype&action=$action&returnTo="
. "actionFunctions.php' ");
print("onMouseOver=\"");
print("window.defaultstatus = ''; window.status = ");
print("'View parameters taken by ");
print($allRows[$i][$colIndex] . " function for the "
. "$action action, ");
print("on $doctype doctype'\">&nbsp;");
print(htmlspecialchars($allRows[$i][$colIndex]));
print("</A></TD>");
# Now we can add the up and down buttons to the
# table.
# Add the small "up" button...
print("<TD><TABLE BORDER=0 CELLSPACING=0 "
. "CELLPADDING=0"
. "><TR>"
. "<FORM ACTION='actionFunctions.php' "
. "METHOD='post'>"
. "<INPUT TYPE='hidden' NAME='calledBefore' "
. "VALUE='true'>"
. "<INPUT TYPE='hidden' NAME='doctype' "
. "VALUE='$doctype'>"
. "<INPUT TYPE='hidden' NAME='action' "
. "VALUE='$action'>"
. "<INPUT TYPE='hidden' NAME='up' VALUE='true'>"
. "<INPUT TYPE='hidden' NAME='function' VALUE='"
. $allRows[$i]['function'] . "'>"
. "<INPUT TYPE='hidden' NAME='currentScore' "
. "VALUE='" . $allRows[$i]['score'] . "'>"
. "<INPUT TYPE='hidden' NAME='currentStep' "
. "VALUE='" . $allRows[$i]['step'] . "'>");
if($rowCount == 0)
{
print("<TD>"
. "<IMG SRC='".$IMAGES."/up.gif' BORDER=0 HEIGHT=11"
. " WIDTH=11"
. " ALT='Function Already At Top Of Order. "
. " Unable To Move Up!'>");
} // END if
else
{
print("<INPUT TYPE='hidden' NAME='previousFunct"
. "ion'"
. " VALUE='" . $allRows[$i - 1]['function'] . "'>"
. "<INPUT TYPE='hidden' NAME='previousScore'"
. " VALUE='" . $allRows[$i - 1]['score'] . "'>"
. "<INPUT TYPE='hidden' NAME='previousStep' "
. "VALUE='"
. $allRows[$i - 1]['step'] . "'><TD>"
. "<INPUT TYPE=image SRC='".$IMAGES."/up.gif'"
. " BORDER=0 "
. "HEIGHT=11 WIDTH=11 onClick=\"submit()\">");
} // END else
# Add the small "down" button...
print("</TD></FORM></TR>"
. "<FORM ACTION='actionFunctions.php' "
. "METHOD='post'>"
. "<INPUT TYPE='hidden' NAME='calledBefore' "
. "VALUE='true'>"
. "<INPUT TYPE='hidden' NAME='doctype' "
. "VALUE='$doctype'>"
. "<INPUT TYPE='hidden' NAME='action' "
. "VALUE='$action'>"
. "<INPUT TYPE='hidden' NAME='down' VALUE='true'>"
. "<INPUT TYPE='hidden' NAME='function' VALUE='"
. $allRows[$i]['function'] . "'>"
. "<INPUT TYPE='hidden' NAME='currentScore' VALUE='"
. $allRows[$i]['score'] . "'>"
. "<INPUT TYPE='hidden' NAME='currentStep' VALUE='"
. $allRows[$i]['step'] . "'>");
if($rowCount == mysql_num_rows($queryResult) - 1)
{
print("<TD>"
. "<IMG SRC='".$IMAGES."/down.gif' BORDER=0"
. " HEIGHT=11 WIDTH=11"
. " ALT='Function Already At Bottom Of Order. "
. " Unable To Move Down!'>");
} // END if
else
{
print("<INPUT TYPE='hidden' NAME='nextFunction' "
. "VALUE='"
. $allRows[$i + 1]['function'] . "'>"
. "<INPUT TYPE='hidden' NAME='nextScore' VALUE='"
. $allRows[$i + 1]['score'] . "'>"
. "<INPUT TYPE='hidden' NAME='nextStep' VALUE='"
. $allRows[$i + 1]['step'] . "'><TD>"
. "<INPUT TYPE='image' SRC='".$IMAGES."/down.gif'"
. " BORDER=0 HEIGHT=11"
. " WIDTH=11 onClick=\"submit()\">");
} // END else
print("</TD></FORM></TR></TABLE></TD>");
}
else # Just display the value, as per normal.
{
print("<TD ALIGN='center'>&nbsp;");
print(htmlspecialchars($allRows[$i][$colIndex]));
print("</TD>\n");
} // End else
} // End for
# Now, we can fill the contents of the last column with the
# "delete button" for removing a function...
print("<FORM ACTION='actionFunctions.php' METHOD='post' "
. "onSubmit=\"if(confirm('Really delete this function from"
. " the $action action of the $doctype document type?')) {"
. " return true; } else { return false; }\">\n"
. "<INPUT TYPE='hidden' NAME='deleteFunc' "
. "VALUE='true'>\n<INPUT TYPE='hidden' NAME='doctype' "
. "VALUE='$doctype'>\n<INPUT TYPE='hidden' NAME='action' "
. "VALUE='$action'>\n<INPUT TYPE='hidden' NAME='"
. " calledBefore"
. "' VALUE='true'>\n<INPUT TYPE='hidden' NAME='function' "
. "VALUE='" . $allRows[$i]['function'] . "'>\n<INPUT TYPE='hidden' "
. "NAME='currentScore' VALUE='" . $allRows[$i]['score']
. "'>\n<INPUT TYPE='hidden' NAME='currentStep' VALUE='"
. $allRows[$i]['step'] . "'>\n<TD ALIGN='center'>\n<INPUT "
. "TYPE='image' SRC='".$IMAGES."/answer_bad.gif' BORDER=0 "
. "NAME='remove' HEIGHT=14 WIDTH=14 ALIGN='center'>\n"
. "</TD>\n</FORM>\n");
# We have now completed the current row, and can close it
print("</TR>");
# Increment the value of $rowCount...
$rowCount++;
} // End for
# Close the table, as it is now finished...
print("</TABLE>\n");
# Now, we can display a button to offer the user the chance to
# go back to the listing of actions for the given document
# type.
# This is done using a button.
print("<P><BR>\n<TABLE ALIGN='center' BORDER=0 "
. "CELLSPACING=0>\n"
. "<TR><FORM ACTION='addFunctions.php' METHOD='post'>\n"
. "<INPUT TYPE='hidden' NAME='action' VALUE='$action'>\n"
. "<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'>\n"
. "<TD ALIGN='center'><INPUT TYPE='button' VALUE='ADD "
. "FUNCTION' onClick=\"submit();\">\n</TD>\n</FORM>\n"
. "<FORM ACTION='documentEDS.php?doctype=$doctype' METHOD="
. "'post'>\n<INPUT TYPE='hidden' NAME='doctype' "
. "VALUE='$doctype'>\n<TD ALIGN='center'>\n"
. "<INPUT TYPE=button VALUE='FINISHED'"
. " onClick=\"submit()\">\n"
. "</TD>\n</FORM>\n</TR>\n</TABLE>\n");
} // End if
else
{
print("<BR><DIV STYLE='color: red; text-align: center; "
. "font-size"
. ": medium; font-weight: bold'>There Are No Functions "
. "Associated With The $action Action For The $doctype "
. "Document Type</DIV>\n");
# Now, we can offer the user the chance to add functions to
# the given action on the given doctype...
# This requires a table with a form in it, with a button to
# press in order to add the functions.
print("<BR>\n<BR>\n");
print("<TABLE ALIGN='center' BORDER=0 CELLSPACING=0><TR>"
. "<TD ALIGN='center'>");
print("\n<FORM ACTION='addFunctions.php' METHOD='post'>\n");
print("<INPUT TYPE='hidden' NAME='action' VALUE='$action'>\n");
print("<INPUT TYPE='hidden' NAME='doctype' VALUE='$doctype'>\n");
print("<INPUT TYPE='button' VALUE='ADD FUNCTIONS' onClick=\"");
print("submit()\">\n");
print("</FORM></TD>\n");
print("<TD>&nbsp;</TD>\n");
print("<TD ALIGN='center'><FORM ACTION='' "
. "METHOD='post'>");
print("<INPUT TYPE='button' VALUE='MAIN PAGE' "
. "onClick=\"submit()\">");
print("</FORM></TD>\n");
print("<TD>&nbsp;</TD>\n");
print("<TD ALIGN='center'><FORM>\n");
print("<INPUT TYPE='button' VALUE='BACK' ");
print("onClick=\"parent.history.back();\">\n");
print("</FORM></TD>\n");
print("</TR></TABLE>\n");
} // End else
} # END if
else
{
# Display error message (couldnt lock tables).
print("<DIV STYLE='text-align: center; font-weight: bold; "
. "font-size: large; color: navy'>\n<SPAN STYLE='color: red'>"
. "Error:</SPAN> Unable to retrieve information.</DIV>\n<BR>".mysql_error()."\n");
print("<TABLE ALIGN='center' CELLSPACING=0 CELLPADDING=0 BORDER="
. "0>\n<TR><FORM ACTION='documentEDS.php' METHOD='post'>\n<INPUT "
. "TYPE='hidden' NAME='doctype' VALUE='$doctype'>\n<TD "
. "ALIGN='center'>\n<INPUT TYPE=button VALUE='OK'"
. " onClick=\"submit()\">\n</TD>\n</FORM>\n</TR>\n</TABLE>\n");
} # END else
} // END function displayFunctions()
function displayPage()
{
global $calledBefore,$doctype,$action,$up,$x,$y,$previousScore,$currentStep,$previousStep,$function,$currentScore,$down,$nextStep,$nextScore,$deleteFunc,$previousFunction,$nextFunction;
if(!($calledBefore))
{
displayFunctions($doctype, $action);
} // END if
else
{
if(isset($up))
{
# Destroy memory space associated with x and y coordinates
# which were passed from the input image...
unset($x);
unset($y);
# Destroy $up...
unset($up);
# Make a query string to update the row to move, to its new
# score and step values...
$queryStringA = "UPDATE sbmFUNCTIONS SET score = "
. "'$previousScore'";
if($previousStep < $currentStep)
{ # If the function aboves step is lower, then we must also
# change this...
$queryStringA = $queryStringA . ", step = "
. "'$previousStep'";
} // END if
$queryStringA = $queryStringA . " WHERE doctype = '$doctype'"
. " AND function = '$function' AND score = "
. "'$currentScore' AND step = '$currentStep' and action='$action'";
# Now, make another query string to update the function that
# was above the function that we have just updated in the
# order. This function should be updated to have the values
# that the function that we just updated had!
$queryStringB = "UPDATE sbmFUNCTIONS SET score = "
. "'$currentScore'";
if($previousStep < $currentStep)
{ # If the function we are alterring to the one above has a
# lower step than the one that came after it in the list,
# we must change the steps around...
$queryStringB = $queryStringB . ", step = '$currentStep'";
} // END if
$queryStringB = $queryStringB . " WHERE doctype = '$doctype'"
. " AND function = '$previousFunction' AND "
. "score = '$previousScore' AND step = "
. "'$previousStep' and action='$action'";
# Lock our tables...
$lockStr = "LOCK TABLES sbmFUNCTIONS WRITE";
if($lockRes = mysql_query($lockStr))
{
# Execute the update on the first function...
$queryResultA = mysql_query($queryStringA) or
die("Could Not Update Table. Error: (A) $queryStringA");
# Execute the update on the second function...
$queryresultB = mysql_query($queryStringB) or
die("Could Not Update Table. Error: (B)");
# Unlock our tables...
$unlockRes = mysql_query("UNLOCK TABLES");
} # END if
else
{
# Couldn't lock tables, therefore couldn't allow write
print("<DIV STYLE='text-align: center; font-weight: bold; "
. "font-size: large; color: navy'>\n<SPAN STYLE='color: "
. "red'>Error:</SPAN> Unable to commit movement."
. "</DIV>\n<BR>\n");
} # END else
unset($lockStr);
# Display the table of functions once again...
displayFunctions($doctype, $action);
} // END if
elseif(isset($down))
{
# Destroy memory space associated with $x and $y coordinates
# which were passed from the input image...
unset($x);
unset($y);
# Destroy $down
unset($down);
# Make a query string to update the row to move, to it's new
# score and step values...
$queryStringA = "UPDATE sbmFUNCTIONS SET score = "
. "'$nextScore'";
if($currentStep < $nextStep)
{ # If the step requires changing also, change it...
$queryStringA = $queryStringA . ", step = '$nextStep'";
}
$queryStringA = $queryStringA . " WHERE doctype = '$doctype'"
. " AND function = '$function' AND score = "
. "'$currentScore' AND step = '$currentStep' and action='$action'";
# Now make another query string to update the function whose
# position in the order the other function is moving to...
$queryStringB = "UPDATE sbmFUNCTIONS SET score = "
. "'$currentScore'";
if($currentStep < $nextStep)
{ # If the step requires changing also, change it...
$queryStringB = $queryStringB . ", step = '$currentStep'";
}
$queryStringB = $queryStringB . " WHERE doctype = '$doctype'"
. "AND function = '$nextFunction' AND score = "
. "'$nextScore' AND step = '$nextStep' and action='$action'";
# Lock our tables...
$lockStr = "LOCK TABLES sbmFUNCTIONS WRITE";
if($lockRes = mysql_query($lockStr))
{
# Execute the query on the first data item...
$queryResultA = mysql_query($queryStringA) or
die("no query A!");
# Execute the query on the second data item...
$queryresultB = mysql_query($queryStringB) or
die("no query B!");
# Unlock our tables...
$unlockRes = mysql_query("UNLOCK TABLES");
} # END if
else
{
# Couldn't lock tables, therefore couldn't allow write
print("<DIV STYLE='text-align: center; font-weight: bold; "
. "font-size: large; color: navy'>\n<SPAN STYLE='color: "
. "red'>Error:</SPAN> Unable to commit movement."
. "</DIV>\n<BR>\n");
} # END else
unset($lockStr);
# Display the table of functions once more...
displayFunctions($doctype, $action);
} // END elseif
elseif(isset($deleteFunc))
{
# This is a call to delete a function from the current action
# of the current doctype.
# Free some wasted space.
unset($deleteFunc);
$delStr = "DELETE FROM sbmFUNCTIONS WHERE doctype = '$doctype"
. "' AND function = '$function' AND score = '$currentScore' "
. "AND step = '$currentStep' and action='$action'";
# Make our LOCK query...
$lockStr = "LOCK TABLES sbmFUNCTIONS WRITE";
if($lockRes = mysql_query($lockStr))
{
$delRes = mysql_query($delStr);
if($delRes)
{
# The deletion query was successful, but did it actually
# delete anything?
if(mysql_affected_rows() == 1)
{
# 1 row deleted as expected.
# unlock table
$unlockRes = mysql_query("UNLOCK TABLES");
# Mail the admin.
# Get the current date and time...
$dateDets = getdate();
$msgTxt = "The $function function with a score of "
. "$currentScore and step of $currentStep was "
. " deleted from 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.";
mail(ADMIN_EMAIL, "${action}.${doctype}.$function "
. "function Deletion", $msgTxt,
"From: WebSubmit_Administrator");
} // END if
elseif(mysql_affected_rows() > 1)
{
# deleted more than 1 row.
# Maybe we had a function in twice with exactly the
# same details?
# unlock table...
$unlockRes = mysql_query("UNLOCK TABLES");
# Free the lock & unlock query results...
mysql_free_result($lockRes);
mysql_free_result($unlockRes);
print("<SCRIPT TYPE='text/javascript'>\nalert('The "
. "deletion of the requested function caused "
. mysql_affected_rows() . " rows to be "
. "deleted.\\nIt is possible that the function had "
. "this many entries with exactly\\nthe same score "
. "and step.');\n</SCRIPT>\n");
} // END elseif
else
{
# deleted no function!
$unlockRes = mysql_query("UNLOCK TABLES");
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR:"
. " Unable to delete the requested function. Try "
. "again or inform system "
. "administrator.');\n</SCRIPT>\n");
} // END else
} // END if
else
{
# Deletion query failed.
$unlockRes = mysql_query("UNLOCK TABLES");
print("<SCRIPT TYPE='text/javascript'>\nalert('ERROR: "
. "Unable to delete the requested function. Try again "
. "or inform system administrator.');\n</SCRIPT>\n");
} // END else
} # END if
else
{
# Could not lock the table. No display allowed.
print("<DIV STYLE='text-align: center; font-weight: bold; "
. "font-size: large; color: navy'>\n<SPAN STYLE='color: "
. "red'>Error:</SPAN> Unable to delete function."
. "</DIV>\n<BR>\n");
} # END else
# Display the table of functions once more...
displayFunctions($doctype, $action);
} // END elseif
else
{
print("<BR><H3 STYLE='text-align: center; font-color: red'>"
. "\nERROR IN UPDATE</H3>\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] . "<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