Journal_Display; }
    
    #######################################Error 5a###############################################################
      if(!$sql1)
      { $msg = $result1."\n";
        $msg .= "####Error 5a####";
		if($debug == '1') echo $msg;
        trigger_error($msg, E_USER_ERROR); }
  
    #############################################################################################################
    
    
    
    $autcount=0;
     $AuthorArray = explode(";", $formAuthor);
     while($i = each($AuthorArray))
     {
      $Author = trim($i[1]);
      
    // ist der Autor bereits bekannt?
      if($Author) 
      {
      $resulta = "SELECT ID_Author FROM authors " .
                            "WHERE Author = '$Author'";
      $sqla = mysql_query($resulta);
      while($row = mysql_fetch_object($sqla))
      {$ID_Author_Test = $row->ID_Author; }
                              
#######################################Error Author-A###############################################################
if(!$sqla)
{ $msg = $resulta."\n";
  $msg .= "####Error Author-A####";
  if($debug == '1') echo $msg;
  trigger_error($msg, E_USER_ERROR);  }
  
############################################################################################################# 
      if(mysql_num_rows($sqla)) 
      {$IDAuthor[$autcount++] = mysql_result($sqla, 0, 0);}
      
      
       
// wenn unbekannt, insert
        
        else 
        {
         $resultb = "INSERT INTO authors (Author, Created_Who) " .
                     "VALUES('$Author','$log')";
         $sqlb = mysql_query($resultb);
         $IDAuthor[$autcount++]=mysql_insert_id();
#######################################Error Author-B###############################################################
if(!$sqlb)
{ $msg = $resultb."\n";
  $msg .= "####Error Author-B####";
  if($debug == '1') echo $msg;
  trigger_error($msg, E_USER_ERROR);  }
  
#############################################################################################################        	
        }
      }                                   
    }// Ende der Autorenschleife  
    
    
    $resultc = "DELETE FROM publications_authors WHERE FK_Publications = '$formPublication'";
    $sqlc = mysql_query($resultc);
    
    
    
    #######################################Error Author-C###############################################################
if(!$sqlc)
{ $msg = $resultc."\n";
  $msg .= "####Error c####";
  if($debug == '1') echo $msg;
  trigger_error($msg, E_USER_ERROR);  }
  
#############################################################################################################  
if($sqlc)
{
   
   
    ############################################################################################################# 
for($i=0; $i<$autcount; $i++)
    {
    if($i!=0) $sql .= ",";
    $sql .= "($formPublication, $IDAuthor[$i])";
    
    $resultd = "INSERT INTO publications_authors (FK_Publications, FK_Author, Created_Who) " .
                "VALUES ('$formPublication','$IDAuthor[$i]','$log')";
                
    $sqld = mysql_query($resultd);
  
                
#######################################Error Author-D###############################################################
if(!$sqld)
{ $msg = $resultd."\n";
  $msg .= "####Error d####";
  if($debug == '1') echo $msg;
  trigger_error($msg, E_USER_ERROR);  }
  
#############################################################################################################                 
    }
    }
    
    
    if($sql0)
    {
    
        $result2 = "SELECT authors.ID_Author, " .
                   "authors.Author AS Author1 " .
                   "FROM authors, publications_authors " .
                   "WHERE authors.ID_Author = publications_authors.FK_Author " .
                   "  AND publications_authors.FK_Publications = '$formPublication'";
        
        $sql2 = mysql_query($result2);
        
        #######################################Error 7###############################################################
      if(!$sql2)
      { $msg = $result2."\n";
        $msg .= "####Error 7####";
		if($debug == '1') echo $msg;
        trigger_error($msg, E_USER_ERROR); }
  
      #############################################################################################################
        
        while($row = mysql_fetch_object($sql2))
        {
        if(isset($Author1[$row->ID_Publication]))
        {$Author1[$row->ID_Publications] .= ", "; }
        else {$Author1[$row->IDPublications] = ""; }
        
        $tmp = $row->Author1;
        $Author1[$row->ID_Publications] .= $tmp; 
        
        }
        
        $Paper = $Author1[$row->ID_Publications];
        if(isset($formEds)) { $Paper .= " ".$formEds; }
        $Paper .= " (".$formYear."): ".$formTitle;
        if($formJournal) { $Paper .= " ".$Journal; }
        if(!$formJournal) { $Paper .= " IN: ".$formBook." ".$formPublisher; }
        if($formVolume) { $Paper .= " ".$formVolume.": "; }
        if($formPages) { $Paper .= " ".$formPages."."; }
        
        $result3 = "UPDATE publications_amplifications SET Paper_Cache = '$Paper' WHERE FK_Publications = '$formPublication'";
        $sql3 = mysql_query($result3);
        
        #######################################Error 8###############################################################
      if(!$sql3)
      { $msg = $result3."\n";
        $msg .= "####Error 8####";
		if($debug == '1') echo $msg;
        trigger_error($msg, E_USER_ERROR); }
  
      #############################################################################################################
      
    if($sql2 and $sql3)
    {echo "Data have been saved!"; }  
    }
    
    
    }
?>
 
    | Author | 
    
    
     | or show all datasets |  |  
    
      | Year |  |  
         
      | Title |  |  
    | Journal | 
         
    
     |  
    | Book |  |  
    | Publisher |  |  
    | Online version available |  |  
    
     |  |  
Authors have been deleted!"; } }
        
    if($_GET['deletejournal'] == 'true')
      { $resultdeleteb = "DELETE FROM journals WHERE ID_Journal NOT IN (SELECT FK_Journal FROM publications)";
        $sqldeleteb = mysql_query($resultdeleteb);
        if($sqldeleteb) { echo "Journals have been deleted!"; } }    
   
   
   
   $resulttesta = "SELECT DISTINCT ID_Author, Author FROM authors WHERE ID_Author NOT IN (SELECT FK_Author FROM publications_authors)";
      $sqltesta = mysql_query($resulttesta);
      
      $resulttestb = "SELECT DISTINCT ID_Journal, Journal_Display FROM journals WHERE ID_Journal NOT IN (SELECT FK_Journal FROM publications)";
      $sqltestb = mysql_query($resulttestb);
    if(mysql_num_rows($sqltesta)) 
    {echo "| Note: For the following authors don't exist publications: ";
      while($row = mysql_fetch_object($sqltesta))
      { echo "".$row->Author. "; "; } 
      echo "Do you want to delete this authors from database? Yes |  "; }
      
      
      
      if(mysql_num_rows($sqltestb)) 
    {echo "| Note: For the following journals don't exist publications: ";
      while($row = mysql_fetch_object($sqltestb))
      { echo "".$row->Journal_Display. "; "; } 
      echo "Do you want to delete this journals from database? Yes |  "; }
      
    ?>  
    
    
    
    Please select a publication!"; }
    else {    
    if(isset($_POST['x']))
    { $mykey = key($_POST['formPublications']);
     if($mykey = $_POST['x'])
        { 
        $IDPublication = $_POST['formPublications'][$mykey];
     } }  //if($_POST['x']!="")
      $result = "SELECT ID_Pub_Amp FROM publications_amplifications WHERE FK_Publications = '$IDPublication'";
      $sql = mysql_query($result);
      
      #######################################Error 1###############################################################
      if(!$sql)
      { $msg = $result."\n";
        $msg .= "####Error 1####";
		if($debug == '1') echo $msg;
        trigger_error($msg, E_USER_ERROR); }
  
      #############################################################################################################
      
      $number = mysql_num_rows($sql);
      
      if($number >= 1 and $formAction == '1')
      
      { echo "Publikation kann nicht gelöscht werden, da ".$number." Amplifikationen mit ihr verknüpft sind!"; }
      if($number == 0 and $formAction == '1')
      { $result = "DELETE FROM publications WHERE FK_Publications = '$IDPublication'"; 
        $sql = mysql_query($result);
        
        
        #######################################Error 2###############################################################
      if(!$sql)
      { $msg = $result."\n";
        $msg .= "####Error 2####";
		if($debug == '1') echo $msg;
        trigger_error($msg, E_USER_ERROR); }
  
      #############################################################################################################
       else { echo "Publikation wurde gelöscht!"; }
        }
        
      if($formAction == '2')
      {
      
      $result1 = "SELECT publications.ID_Publications, " .
                "publications.Editors, " .
                "publications.Year, " .
                "publications.Title, " .
                "journals.Journal_Display, " .
                "publications.Volume, " .
                "publications.Pages, " .
                "publications.Book, " .
                "publications.Publisher, " .
                "publications.Link " .
                "FROM publications
                LEFT JOIN journals ON publications.FK_Journal = journals.ID_Journal " .
                "WHERE publications.ID_Publications = '$IDPublication'";
       $sql1 = mysql_query($result1);
       
       #######################################Error 3###############################################################
      if(!$sql1)
      { $msg = $result1."\n";
        $msg .= "####Error 3####";
		if($debug == '1') echo $msg;
        trigger_error($msg, E_USER_ERROR); }
  
      #############################################################################################################
       
       while($row = mysql_fetch_object($sql1))
       {  $Editors = $row->Editors;
          $Year = $row->Year;
          $Title = $row->Title;
          $JournalView = $row->Journal_Display;
          $Volume = $row->Volume;
          $Pages = $row->Pages;
          $Book = $row->Book;
          $Publisher = $row->Publisher;
          $Link = $row->Link;      }
          
        $result2 = "SELECT authors.ID_Author, " .
                   "authors.Author " .
                   "FROM authors, publications_authors " .
                   "WHERE authors.ID_Author = publications_authors.FK_Author " .
                   "  AND publications_authors.FK_Publications = '$IDPublication'";
        $sql2 = mysql_query($result2);
        
        #######################################Error 4###############################################################
      if(!$sql2)
      { $msg = $result2."\n";
        $msg .= "####Error 4####";
		if($debug == '1') echo $msg;
        trigger_error($msg, E_USER_ERROR); }
  
      #############################################################################################################
        
        while($row = mysql_fetch_object($sql2))
        {
        if(isset($Author[$row->ID_Publication]))
        {$Author[$row->ID_Publications] .= ";"; }
        else {$Author[$row->IDPublications] = ""; }
        
        $tmp = $row->Author;
        $Author[$row->ID_Publications] .= $tmp; 
        
        }
          
        echo "";      
        }  
   
    }
    }
    
        
    
    
     
    if($formSubmitSearch)
    {
    
    $result = "";
    $sqlcreate = "CREATE TEMPORARY TABLE tmpPublicationIDs AS ";
    
    include("date.php");
    $tr = "=";
    $no = "!=";
    $lk = "like";
    $bt = ">=";
    $st = "<=";
    $parr = $_POST;
    array($parr);
    foreach ($parr as $var)
    {
        $i ++;
        if(!empty($var) and $var!="Search" and $var!="formShowAll")
        {
            switch (key($parr))
            {
            
                case 'formAuthor':
                    $str = "authors.ID_Author ".$tr."'".$var."' AND "; 
                    $description = " Author = ";
                    $value = $formAuthor;
                    break;
                case 'formSearchYear':
                    $str = "publications.Year ".$lk."'%".$var."%' AND "; 
                    $description = " Year = ";
                    $value = $formSearchYear;
                    break;    
                case 'formSearchTitle':
                    $str = "publications.Title ".$lk."'%".$var."%' AND "; 
                    $description = " Title = ";
                    $value = $formSearchTitle;
                    break;
                case 'formJournal':
                    $str = "(journals.Journal_All ".$lk."'%".$var."%' OR "; 
                    $str .= "journals.Journal_Display ".$lk."'%".$var."%') AND ";
                    $description = " Journal = ";
                    $value = $formJournal;
                    break;
                case 'formSearchBook':
                    $str = "publications.Book ".$lk."'%".$var."%' AND "; 
                    $description = " Book = ";
                    $value = $formSearchBook;
                    break;
                case 'formSearchPublisher':
                    $str = "publications.Publisher ".$lk."'%".$var."%' AND "; 
                    $description = " Publisher = ";
                    $value = $formSearchPublisher;
                    break;
                case 'formOnline':
                    $str = "publications.Link ".$no."'' AND "; 
                    $description = " Online version = ";
                    $value = "available";
                    break;
            }           
            $where[$i] = $str;
            $descriptionall[$i] = $description;
            $valueall[$i] = $value;
        }
        next($parr);
    }
    if(empty($str) and empty($formShowAll))
    {  echo ""; }
    if(!empty($str) and !empty($formShowAll))
    {  echo "| Please either enter a search key or select the checkbox! |   "; }
    
    else {
    foreach($where AS $a) $string .= $a;
        $l=strlen ($string);
        $max = $l-4;
        $where_str = substr($string, 0, $max);
        $wherestr = ' WHERE ' . $where_str;
     
            $result = $sqlcreate .
            $result = "SELECT DISTINCT publications.ID_Publications " .
                      "FROM publications
                       LEFT JOIN journals ON publications.FK_Journal = journals.ID_Journal
                       LEFT JOIN publications_authors ON publications.ID_Publications = publications_authors.FK_Publications
                       LEFT JOIN authors ON publications_authors.FK_Author = authors.ID_Author";
           
           if(!empty($str)) {$result .= $wherestr; }
   $sql = mysql_query($result) or die($result.' '.mysql_error());
if(!empty($result)) 
 {
    // just in case it is still here: drop tmpPublicationIDs
   mysql_query("DROP TABLE IF EXISTS tmpPublicationIDs");
   mysql_query($result);
   if(!mysql_affected_rows()) 
   {echo "No hits found."; }
else {
$result1 = "SELECT publications.ID_Publications, " .
                   "publications.Year, " .
                   "publications.Title, " .
                   "publications.Volume, " .
                   "publications.Pages, " .
                   "publications.Book, " .
                   "publications.Publisher, " .
                   "publications.Link, " .
                   "publications.Created_Who, " .
                   "publications.Created_When, " .
                   "journals.Journal_Display, " .
                   "journals.Journal_All " .
                   "FROM publications JOIN tmpPublicationIDs
                   LEFT JOIN journals ON publications.FK_Journal = journals.ID_Journal " .
                   "WHERE publications.ID_Publications = tmpPublicationIDs.ID_Publications";
                 
$sql1 = mysql_query($result1);
echo " |  ";
echo "
  |  ";
echo "| Action: |  |  ";
echo "
  |  ";
    }
    }
    }
    }
    ?>
    
 
 |