diff --git a/modules/websubmit/web/admin/addElementDescrEDS.php.wml b/modules/websubmit/web/admin/addElementDescrEDS.php.wml index 25f33b79e..0b1cb6e1e 100644 --- a/modules/websubmit/web/admin/addElementDescrEDS.php.wml +++ b/modules/websubmit/web/admin/addElementDescrEDS.php.wml @@ -1,1001 +1,930 @@ ## $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. #include "cdspage.wml" \ title="Add an element description" \ navtrail_previous_links="/admin/> > /admin/websubmit/>" \ navbar_name="admin" \ navbar_select="websubmit_listelements" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. /*********************Function Descriptions***************************/ function enterEDSelementDescr($elename = "", $alephcode = "", $size = "", $rows = "", $cols = "", $maxlength = "", $val = "", $fidesc = "", $cookie = 0, $type = "", $modifytext = "") { /******************************************************************* This function has the task of creating the form that allows a user to enter the details of a new element description. Author: Nicholas Robinson Email: Nicholas.Robinson@cern.ch ca8nro@yahoo.co.uk Created: 10/01/2001 Last Modified: 08/02/2001 *******************************************************************/ # Now, display a quick set of page instructions for the user.. print("\n\n" . "\n
\n

Below, is " . "a form in which you can enter the details of a new " . "element description." . "

When you enter a new element description, it will " . "not be accepted by the system unless you have given it a " . "unique
\"Element Name\".
" . "
You can commit this new element description to the " . "database by clicking on \"SAVE DETAILS\".

\n
\n"); # Make a horizontal rule to divide the page sections... drawSeparator(); print("
\n" . "\n" . "\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("
"); # Now create the fields that the user can edit... # Make the name field... print("\n\n\n\n"); # Make the modify text field... print("\n\n\n\n"); # Make the type field... print("\n\n\n" . "\n"); 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 != "name") && ($currentField != "type") && ($currentField != "cookie") && ($currentField != "modifytext") && ($currentField != "fddfi2")) { # First display the form field label... print("\n\n\n\n"); } // END if } // END for print("\n\n\n
\n" . "Element Name " . "(Req'd)\n\n
\n" . "Modification Text: \n\n
\n" . "Element Type (Req'd): " . "\n" . "\n
\n"); if($currentField == "alephcode") { print("Aleph Code " . ":"); } // END if elseif($currentField == "marccode") { print("Marc Code:"); } // END elseif elseif($currentField == "size") { print("Size (Text" . "):"); } // END elseif elseif($currentField == "rows") { print("No. Rows (TextArea)" . ":"); } // END elseif elseif($currentField == "cols") { print("No. Cols (TextArea)" . ":"); } // END elseif elseif($currentField == "maxlength") { print("Max Length (Text)" . ":"); } // END elseif elseif($currentField == "val") { print("Value (Text" . "/Hidden):"); } // END elseif elseif($currentField == "fidesc") { print("Item Description " . "(User Defined):"); } // END elseif else { print("$currentField:"); } // END else print(" \n"); if($currentField == "fidesc") { # Here, we ought to make a textarea for fidesc... print("\n"); } // END if else { # Just a normal text input will do... print("\n"); } // END else print("
\n" . "Sets Cookie?: "); printCookie($cookie); # Close up the cookie row, and the table! print("\n
\n"); # Now make the commit, reset, and cancel buttons for the form... print("" . "\n\n\n\n\n\n\n
\n\n\n\n
\n\n
" . "\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\n\n\n\n\n
\n\n
\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\n\n" . "\n
\n" . "
\n\n
\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***************************/ ?>