Reference field is mandatory
"); $goOn = FALSE; } $testStr=trim($_POST['title']); if (empty($testStr)) { printf(" Title field is mandatory
"); $goOn = FALSE; } $testStr=trim($_POST['author']); if (empty($testStr)) { printf(" Author field is mandatory
"); $goOn = FALSE; } $testStr=trim($_POST['year']); if (empty($testStr)) { printf(" Year field is mandatory
"); $goOn = FALSE; } $testStr=trim($_POST['codenum']); if (empty($testStr)) { /*Record is brand new*/ echo "event: new record
"; $rectyp="new"; } else { /*Record is an old one*/ echo "event: old record modified
"; $rectyp="mod"; } if ($rectyp == "unk") { echo "Unexpected record format."; $goOn = FALSE; } if ( TRUE == $goOn ) { $year=htmlentities(trim($_POST['year']),ENT_QUOTES); $title=htmlentities(trim($_POST['title']),ENT_QUOTES); $title=str_replace("'","\\'",$title); $author=htmlentities(trim($_POST['author']),ENT_QUOTES); $author=str_replace("'","\\'",$author); $refs=htmlentities(trim($_POST['refs']),ENT_QUOTES); $refs=str_replace("'","\\'",$refs); $doi=htmlentities(trim($_POST['doi']),ENT_QUOTES); $preprint=htmlentities(trim($_POST['preprint']),ENT_QUOTES); $codenum=htmlentities(trim($_POST['codenum']),ENT_QUOTES); $oldfile=htmlentities(trim($_POST['oldfile']),ENT_QUOTES); if($rectyp == "new") { $codenum=$year."-".date("U"); $entryhtm=$codenum.".html"; while ( file_exists("RCDS/".$entryhtm)) { $codenum=$year."-".date("U"); $entryhtm=$codenum.".html"; } } else { $entryhtm=$codenum.".html"; if ($year != substr($codenum,0,4)) { echo "Warning: changing the year; also changing record label: "; $newcodenum=$year."-".date("U"); $newentryhtm=$newcodenum.".html"; while ( file_exists("RCDS/".$newentryhtm)) { $newcodenum=$year."-".date("U"); $newentryhtm=$newcodenum.".html"; } if (FALSE == copy("RCDS/".$entryhtm,"RCDS/".$newentryhtm)) { echo "Can't move record file".$entryhtm."->".$newentryhtm; echo ""; die(7); } if (!empty($oldfile)) { $newfile="PDFS/".$newcodenum.".pdf"; if (file_exists($oldfile)) { if (FALSE == copy($oldfile,$newfile)) { echo "Can't move pdf file".$oldfile."->".$newfile; echo ""; die(8); } unlink($oldfile); } else { echo "Error: ".$oldfile." does not exist.
"; echo ""; unlink("RCDS/".$newentryhtm); die(6); } $oldfile=$newfile; } unlink("RCDS/".$entryhtm); $codenum=$newcodenum; $entryhtm=$newentryhtm; echo "new label ".$codenum."
"; } } $fst = fopen("RCDS/".$entryhtm, 'w') ; if (FALSE == $fst ) { echo "Can't open record file".$entryhtm; echo ""; die(10); } fprintf($fst,""; /* print_r($_FILES); */ $file = $_FILES['paperfile']; if($file['error'] == UPLOAD_ERR_OK and is_uploaded_file($file['tmp_name'])) { move_uploaded_file($file['tmp_name'],$entrypdf); $oldfile=$entrypdf; } else { echo "
Error uploading file ".$file['name']." - too big (max 4MB)? empty?
"; print_r($_FILES); /* echo ""; unlink("RCDS/".$entryhtm); die(10); */ $oldfile=""; } } fprintf($fst,"\$oldfile='%s';\n",$oldfile); fprintf($fst,"$%s='%s';\n","year",$year); fprintf($fst,"$%s='%s';\n","title",$title); fprintf($fst,"$%s='%s';\n","author",$author); fprintf($fst,"$%s='%s';\n","refs",$refs); fprintf($fst,"$%s='%s';\n","doi",$doi); fprintf($fst,"$%s='%s';\n","preprint",$preprint); fprintf($fst,"$%s='%s';\n","codenum",$codenum); fprintf($fst,"?>\n"); include "newrecord.php"; } else { // $ goOn is FALSE: Some mandatory fields were empty $year=trim($_POST['year']); $title=trim($_POST['title']); $author=trim($_POST['author']); $refs=trim($_POST['refs']); $doi=trim($_POST['doi']); $preprint=trim($_POST['preprint']); $codenum=trim($_POST['codenum']); $oldfile=trim($_POST['oldfile']); include "form.php"; } } elseif ($_POST['retrieve'] == "retrieve") { /* Caller wants to retrieve and display an old record */ $codenum=trim($_POST['codenum']); $entryhtm=$codenum.".html"; if (!file_exists("RCDS/".$entryhtm)) { echo "unrecognized record label: ".$codenum."
"; //echo ""; $codenum=""; include "form.php"; } require "RCDS/".$entryhtm; if ($entryhtm != $codenum.".html") { echo "record label ".$codenum." in record file".$entryhtm; echo ""; die(9); } include "form.php"; } elseif ($_POST['retrieve'] == "delete") { /* Caller wants to delete an existing record */ $codenum=trim($_POST['codenum']); $entryhtm=$codenum.".html"; $entrypdf=$codenum.".pdf"; if (FALSE == file_exists("RCDS/".$entryhtm)) { echo "ERROR: File "."RCDS/".$entryhtm." does not exists.
"; } else { unlink("RCDS/".$entryhtm); echo "record ".$codenum." deleted.
"; } if (file_exists("PDFS/".$entrypdf)) { unlink("PDFS/".$entrypdf); } $codenum=""; include "form.php"; } else { echo "Invalid request. How did we come to this???"; echo "BACK TO FORM "; echo "GO TO LIST"; } ?>