/**
  * @Override FC_Document_Manager::postDocumentUpload().
  *
  * This is a copy and past of the overriden function except
  * that we now create a new InternDocument object
  * and save it to databse.
  */
 public function postDocumentUpload()
 {
     // importPost in File_Common
     $result = $this->document->importPost('file_name');
     if (\PHPWS_Error::isError($result) || !$result) {
         \PHPWS_Error::log($result);
         $vars['timeout'] = '3';
         $vars['refresh'] = 0;
         javascript('close_refresh', $vars);
         return dgettext('filecabinet', 'An error occurred when trying to save your document.');
     } elseif ($result) {
         $result = $this->document->save();
         if (\PHPWS_Error::logIfError($result)) {
             $content = dgettext('filecabinet', '<p>Could not upload file to folder. Please check your directory permissions.</p>');
             $content .= sprintf('<a href="#" onclick="window.close(); return false">%s</a>', dgettext('filecabinet', 'Close this window'));
             Layout::nakedDisplay($content);
             exit;
         }
         //\PHPWS_Core::initModClass('filecabinet', 'File_Assoc.php');
         //\FC_File_Assoc::updateTag(\FC_DOCUMENT, $this->document->id, $this->document->getTag());
         $this->document->moveToFolder();
         // If the document's id is set in the request
         // then we are updating a file. Not need to insert
         // it into database.
         if (!isset($_REQUEST['document_id'])) {
             // Save InternDocument in database.
             $doc = new InternDocument();
             $doc->internship_id = $_REQUEST['internship'];
             $doc->document_fc_id = $this->document->id;
             $result = $doc->save();
         }
         // Choose the proper notification text...
         if (isset($_REQUEST['document_id']) && $_REQUEST['document_id'] && $result) {
             \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, "File saved.");
         } else {
             if ($result) {
                 \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, "File added.");
             } else {
                 if (\PHPWS_Error::logIfError($result)) {
                     \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, $result->toString());
                 }
             }
         }
         \NQ::close();
         if (!isset($_POST['im'])) {
             javascript('close_refresh');
         } else {
             javascript('/filecabinet/refresh_manager', array('document_id' => $this->document->id));
         }
     } else {
         return $this->edit();
     }
 }