/**
  * Inserts files into database, which have not been a temporary file before.
  *@param $nameOfFile string
  *@param $fileStage constant, ARTICLE_FILE_SUBMISSION or ARTICLE_FILE_SUPP
  *@param $fileType string, txt/plain or application/pdf
  *@param $article_id string
  *@param $pathToFile string, path were to find the file which is inserted here
  */
 function insertArticleFile($nameOfFile, $fileStage, $fileType, $article_id, $pathToFile, $origFileName = NULL)
 {
     import('classes.file.ArticleFileManager');
     $articleFileManager = new ArticleFileManager($article_id);
     $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
     $fileTypePath = $articleFileManager->typeToPath($fileStage);
     $dir = $articleFileManager->filesDir . $fileTypePath . '/';
     $articleFile =& $articleFileManager->generateDummyFile($articleFileManager->article);
     $articleFile->setFileType($fileType);
     if ($origFileName == NULL) {
         $origFileName = $nameOfFile;
     }
     $articleFile->setOriginalFileName($origFileName);
     $articleFile->setType($fileTypePath);
     $articleFile->setRound($articleFileManager->article->getCurrentRound());
     $articleFile->setAssocId(null);
     $newFileName = $articleFileManager->generateFilename($articleFile, $fileStage, $articleFile->getOriginalFileName());
     if (!$articleFileManager->copyFile($pathToFile . $nameOfFile, $dir . $newFileName)) {
         // Delete the dummy file we inserted
         $articleFileDao->deleteArticleFileById($articleFile->getFileId());
         return false;
     }
     $articleFile->setFileSize(filesize($dir . $newFileName));
     $articleFileDao->updateArticleFile($articleFile);
     $articleFileManager->removePriorRevisions($articleFile->getFileId(), $articleFile->getRevision());
     return $articleFile->getFileId();
 }