\n");
# Get the columns list
$columns = mysql_list_fields(DOCS_DATABASE, "sbmFIELDDESC");
# 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("\n");
# Now make the commit, reset, and cancel buttons for the form...
print(""
. "\n");
} // END enterEDSelementDescr()
//************
function charIsInt($thing)
{
/*******************************************************************
This function tests to see if a string only contains integer
characters.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 11/01/2001
Last Modified: 11/01/2001
*******************************************************************/
# Reset an error flag
$errorFlag = 0;
# get the length of the string..
$len = strlen($thing);
for($i = 0; $i < $len; $i++)
{
if($thing[$i] < "0" || $thing[$i] > "9")
{
$errorFlag = 1;
break;
} // END if
} // END for
# Return true/false depending upon string status
return ($errorFlag == 1) ? false : true;
} // END function charIsInt($thing)
//********
function insertBon($elename)
{
/*******************************************************************
This function has the task of displaying a message on the screen
to say that the insertion of the new element was successful. It
also displays a button to click to send the browser to the page
displaying the details of the new element description.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 11/01/2001
Last Modified: 11/01/2001
*******************************************************************/
print("Element Added.
Click To View details."
. "
\n"
. "\n\n");
} // END function insertBon()
//***********
function insertMal()
{
/*******************************************************************
This function handles the situation whereby the insert of the new
element description has failed, and we wish to inform the user,
and provide a button to click to goto the list all element
descriptions page.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 12/01/2001
Last Modified: 12/01/2001
*******************************************************************/
print("\nERROR:"
. " Unable to insert new element description.
\n"
. "\n");
print mysql_error();
} // END function insertMal()
//************
function emailRecord($elename)
{
/*******************************************************************
Since it is necessary to email the admin informing them about the
success of the addition of a new element description, this
function has been written, which does just that.
Author: Nicholas Robinson
Email: Nicholas.Robinson@cern.ch
ca8nro@yahoo.co.uk
Created: 11/01/2001
Last Modified: 25/01/2001
*******************************************************************/
$msgTxt = "A new element description was successfully added to the "
. DOCS_DATABASE . " database. This was the $elename element "
. "description.\n\nWebSubmit Administrator. (";
$msgTxt .= makeDate();
$msgTxt .= ")";
# Now send the mail..
mail(ADMIN_EMAIL, "$elename Element Description Added",
$msgTxt, "From: WebSubmit_Administrator");
} // END function emailRecord($elename)
function displayPage()
{
global $commitElement,$elename,$alephcode,$marccode,$size,$rows,$cols,$maxlength,$val,$fidesc,$cookie,$type,$modifytext;
if($commitElement)
{
# In this case, this is a self-referential call to the form, and
# it is time to process the addition of the new element.
- # Carry out some form validation (I'm not using JavaScript any
- # more for this, as it is rubbish), and take the relevant action
- # based upon the resuts...
+ # Carry out some form validation and take the relevant action
+ # based upon the resuts
if($type == "NONE_SELECTED")
{
# In this case, the user has not selected a type for the new
# element. Therefore redisplay the form with the values in
# that they have already entered.
print("Selection Of Element "
. "Type is Mandatory.
\n");
enterEDSelementDescr($elename, $alephcode, $size,
$rows, $cols, $maxlength, stripslashes($val),
stripslashes($fidesc), $cookie, "",$modifytext);
} // END if
else
{
# The element type was selected, but we must now ensure that
- # the other various field combos were correct...
+ # the other various field combos were correct
if(!$elename)
{
# User has not input the element name, or aleph code.
print("The Element Name "
. "Field Is Mandatory.
\n");
enterEDSelementDescr($elename, $alephcode, $size,
$rows, $cols, $maxlength, stripslashes($val),
stripslashes($fidesc), $cookie, $type, $modifytext);
} // END if
else
{
if(!test_key_legal($elename))
{
- # Damn...invalid characters in either the alephcode or
- # the element name...
-
+ # invalid characters in either the alephcode or the element name
print("The Element Name "
. "May Only Contain Alphabetical"
. " Characters, Integer Digits or Underscores.
\n");
enterEDSelementDescr("", $alephcode, $size,
$rows, $cols, $maxlength, stripslashes($val),
stripslashes($fidesc), $cookie, $type,$modifytext);
} // END if
else
{
# General Mandatory fields all filled correctly. Now
- # make specialised tests...
+ # make specialised tests
if($type == "T")
{
# Element is TextArea - can have rows and cols.
if($rows)
{
if(!charIsInt($rows))
{
- # Damn...user has given a non-int value for
- # $rows
+ # non-int value given for $rows
print("The No. Rows Field Must Have"
. " an Integer Value.
");
- # Make an error flag to mark this fact...
+ # Make an error flag to mark this fact
$rowsInvalid = true;
enterEDSelementDescr($elename,
$alephcode,
$size, "", $cols, $maxlength,
stripslashes($val), stripslashes($fidesc),
$cookie, $type,$modifytext);
} // END if
} // END if
if($cols && !$rowsInvalid)
{
if(!charIsInt($cols))
{
- # Damn...user has given a non-int value for
- # $rows
+ # non-int value given for $rows
print("The No. Cols Field Must Have"
. " an Integer Value.
");
# Set an error flag to mark this failure
$colsInvalid = true;
enterEDSelementDescr($elename,
$alephcode, $size, $rows, "", $maxlength,
stripslashes($val),
stripslashes($fidesc), $cookie, $type,$modifytext);
} // END if
} // END if
if(!$rowsInvalid && !$colsInvalid)
{
# Well now. If we have reached this far, then the
- # data for the TEXTAREA must all be present and
- # valid, so we can finally make this new element
- # description, and commit it to the DB.
+ # TEXTAREA present and valid: make new element description and commit to DB
$insStr = "INSERT INTO sbmFIELDDESC (name, alephcode"
. ", marccode, type, size, rows, cols, maxlength, val, "
. "fidesc, cd, md, modifytext, fddfi2, cookie) VALUES"
. "('$elename', '$alephcode', '$marccode', '$type', NULL, ";
# Deal with rows
if(isset($rows) && $rows != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$rows', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
# Deal with cols
if(isset($cols) && $cols != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$cols', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
$insStr .= "NULL, NULL, NULL, NOW(), NOW(), ".(isset($modifytext)?"'$modifytext', ":"NULL, ") . " NULL, '$cookie')";
- # Execute the insertion
$insRes = mysql_query($insStr);
if($insRes)
{
- # In this case, the insertion of the new
- # element description has been successful.
- # Therefore we need to inform the user and
- # redirect the browser.
-
+ # insert of element description successful.
emailRecord($elename);
insertBon($elename);
} // END if
else
{
- # If the insert failed...
insertMal();
} // END else
} // END if
} // END if
elseif($type == "I")
{
- # Element is HTML text input - needs size, maxlength,
- # val
-
+ # Element is HTML text input - needs size, maxlength, val
if($size)
{
if(!charIsInt($size))
{
- # Damn...user has given a non-int value for
- # $size
+ # non-int value given for $size
print("The Size Field Must Have an"
. " Integer Value.
");
# Make a flag to mark this failure
$sizeFailed = true;
enterEDSelementDescr($elename,
$alephcode, "", $rows, $cols, $maxlength,
stripslashes($val), stripslashes($fidesc),
$cookie, $type,$modifytext);
} // END if
} // END if
if($maxlength && !$sizeFailed)
{
if(!charIsInt($maxlength))
{
- # User has given a non-int value for $maxlength
+ # non-int value given for $maxlength
print(""
. "The Max Length Field Must Have an "
. "Integer Value.
");
# Make a flag to mark this failure
$maxlengthFailed = true;
enterEDSelementDescr($elename,
$alephcode, $size, $rows, $cols, "",
stripslashes($val), stripslashes($fidesc),
$cookie, $type,$modifytext);
} // END if
} // END if
if(!$sizeFailed && !$maxlengthFailed)
{
- # Well now. If we have reached this far, then the
- # data for the input must all be present and
- # valid, so we can finally make this new element
- # description, and commit it to the DB.
+ # commit new element description to DB
$insStr = "INSERT INTO sbmFIELDDESC (name, alephcode, marccode"
. ", type, size, rows, cols, maxlength, val, "
. "fidesc, cd, md, modifytext, fddfi2, cookie) "
. "VALUES('$elename', '$alephcode', '$marccode', '$type', ";
# Deal with size
if(isset($size) && $size != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$size', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
$insStr .= "NULL, NULL, ";
# Deal with maxlength
if(isset($maxlength) && $maxlength != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$maxlength', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
# Deal with val
if(isset($val) && $val != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$val', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
$insStr .= "NULL, NOW(), NOW(), ".(isset($modifytext)?"'$modifytext', ":"NULL, ")."NULL, "
. "'$cookie')";
- # Execute the insertion
$insRes = mysql_query($insStr);
if($insRes)
{
- # In this case, the insertion of the new
- # element description has been successful.
- # Therefore we need to inform the user and
- # redirect the browser.
-
+ # insert of element description successful
emailRecord($elename);
insertBon($elename);
} // END if
else
{
- # Insert failed...
insertMal();
} // END else
} // END if
} // END elseif
elseif($type == "H")
{
# Element is hidden - can have val
-
$insStr = "INSERT INTO sbmFIELDDESC (name, alephcode, marccode, "
. "type, size, rows, cols, maxlength, val, fidesc, "
. "cd, md, modifytext, fddfi2, cookie) VALUES('"
. "$elename', '$alephcode', '$marccode', '$type', NULL, NULL, "
. "NULL, NULL, ";
# Deal with val
if(isset($val) && $val != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$val', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
$insStr .= "NULL, NOW(), NOW(), ".(isset($modifytext)?"'$modifytext', ":"NULL, ")."NULL, "
. "'$cookie')";
-
- # Execute the insertion
$insRes = mysql_query($insStr);
if($insRes)
{
- # In this case, the insertion of the new element
- # description has been successful. Therefore we
- # need to inform the user and redirect the
- # browser.
-
+ # Insert successful
emailRecord($elename);
insertBon($elename);
} // END if
else
{
# Insert failed
insertMal();
} // END else
} // END elseif
elseif($type == "F")
{
# Element is file - needs size, maxlength
-
if($size)
{
if(!charIsInt($size))
{
- # Damn...user has given a non-int value for
- # $size
+ # non-int value given for $size
print("The Size Field Must Have "
. "an Integer Value.
");
# Make a flag to mark this failure
$sizeFailed = true;
enterEDSelementDescr($elename,
$alephcode, "", $rows, $cols, $maxlength,
stripslashes($val), stripslashes($fidesc),
$cookie, $type,$modifytext);
} // END if
} // END if
if($maxlength && !$sizeFailed)
{
if(!charIsInt($maxlength))
{
- # User has given a non-int value for $maxlength
+ # non-int value given for $maxlength
print(""
. "The Max Length Field Must Have an "
. "Integer Value.
");
# Make a flag to mark this failure
$maxlengthFailed = true;
enterEDSelementDescr($elename,
$alephcode, $size, $rows, $cols, "",
stripslashes($val), stripslashes($fidesc),
$cookie, $type,$modifytext);
} // END if
} // END if
if(!$sizeFailed && !$maxlengthFailed)
{
- # Well now. If we have reached this far, then the
- # data for the input must all be present and
- # valid, so we can finally make this new element
- # description, and commit it to the DB.
-
+ # commit new element to DB
$insStr = "INSERT INTO sbmFIELDDESC (name, alephcode"
. ", marccode, type, size, rows, cols, maxlength, val, "
. "fidesc, cd, md, modifytext, fddfi2, cookie) "
. "VALUES('$elename', '$alephcode', '$marccode', '$type', ";
# Deal with size
if(isset($size) && $size != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$size', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
$insStr .= "NULL, NULL, ";
# Deal with maxlength
if(isset($maxlength) && $maxlength != "")
{
- # A value was provided for rows...
+ # A value was provided for rows
$insStr .= "'$maxlength', ";
} // END if
else
{
- # No value was provided for rows...
+ # No value was provided for rows
$insStr .= "NULL, ";
} // END else
$insStr .= "NULL, NULL, NOW(), NOW(), ".(isset($modifytext)?"'$modifytext', ":"NULL, ")."NULL,"
. " '$cookie')";
# Execute the insertion
$insRes = mysql_query($insStr);
if($insRes)
{
- # In this case, the insertion of the new
- # element description has been successful.
- # Therefore we need to inform the user and
- # redirect the browser.
-
emailRecord($elename);
insertBon($elename);
} // END if
else
{
- # Insert failed
insertMal();
} // END else
} // END if
} // END elseif
elseif($type == "D")
{
# Element is user defined - needs fidesc
-
$insStr = "INSERT INTO sbmFIELDDESC (name, alephcode, marccode, "
. "type, size, rows, cols, maxlength, val, fidesc, "
. "cd, md, modifytext, fddfi2, cookie) VALUES('"
. "$elename', '$alephcode', '$marccode', '$type', NULL, NULL, "
. "NULL, NULL, NULL, ";
$insStr .= "'$fidesc', NOW(), NOW(), ".(isset($modifytext)?"'$modifytext', ":"NULL, ")."NULL, "
. "'$cookie')";
# Execute the insertion
$insRes = mysql_query($insStr);
if($insRes)
{
- # In this case, the insertion of the new element
- # description has been successful. Therefore we
- # need to inform the user and redirect the
- # browser.
-
+ # Insert succesful
emailRecord($elename);
insertBon($elename);
} // END if
else
{
# Insert failed
insertMal();
} // END else
} // END elseif
elseif($type == "R")
{
# Element is of response type - needs fidesc
-
$insStr = "INSERT INTO sbmFIELDDESC (name, alephcode, marccode, "
. "type, size, rows, cols, maxlength, val, fidesc, "
. "cd, md, modifytext, fddfi2, cookie) VALUES('"
. "$elename', '$alephcode', '$marccode', '$type', NULL, NULL, "
. "NULL, NULL, NULL, ";
$insStr .= "'$fidesc', NOW(), NOW(), ".(isset($modifytext)?"'$modifytext', ":"NULL, ")."NULL, "
. "'$cookie')";
- # Execute the insertion
$insRes = mysql_query($insStr);
if($insRes)
{
- # In this case, the insertion of the new element
- # description has been successful. Therefore we
- # need to inform the user and redirect the
- # browser.
-
emailRecord($elename);
insertBon($elename);
} // END if
else
{
- # Insert failed
insertMal();
} // END else
} // END elseif
elseif($type == "S")
{
# Element is user defined - needs fidesc
-
$insStr = "INSERT INTO sbmFIELDDESC (name, alephcode, marccode, "
. "type, size, rows, cols, maxlength, val, fidesc, "
. "cd, md, modifytext, fddfi2, cookie) VALUES('"
. "$elename', '$alephcode', '$marccode', '$type', NULL, NULL, "
. "NULL, NULL, NULL, ";
$insStr .= "'$fidesc', NOW(), NOW(), ".(isset($modifytext)?"'$modifytext', ":"NULL, ")."NULL, "
. "'$cookie')";
-
- # Execute the insertion
$insRes = mysql_query($insStr);
if($insRes)
{
- # In this case, the insertion of the new element
- # description has been successful. Therefore we
- # need to inform the user and redirect the
- # browser.
-
emailRecord($elename);
insertBon($elename);
} // END if
else
{
- # Insert failed
insertMal();
} // END else
} // END elseif
else
{
- # Oops! Element type invalid! We must deny
- # commitment, and represent the form for the user to
- # once again attempt to fill in.
-
+ # Element type invalid! deny commit, redisplay form
print("Invalid "
. "Element Type is Mandatory.
\n");
-
enterEDSelementDescr($elename, $alephcode,
$size, $rows, $cols, $maxlength,
stripslashes($val), stripslashes($fidesc),
$cookie,"",$modifytext);
} // END else
} // END else
} // END else
} // END else
} // END if
else
{
# In this case, this is not a self-referential call to this page,
# and it is therefore time to display a form in which the user
# can enter the details of the element description...
-
enterEDSelementDescr();
} // 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***************************/
?>