fileSystemRoot/lib/documentmanagement/Document.inc"); require_once("$default->fileSystemRoot/lib/documentmanagement/DependantDocumentInstance.inc"); require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentLink.inc"); require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); require_once("$default->fileSystemRoot/lib/web/WebDocument.inc"); require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); require_once("$default->fileSystemRoot/presentation/Html.inc"); require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); require_once("addDocumentUI.inc"); require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc"); require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); $oStorage =& KTStorageManagerUtil::getSingleton(); $postExpected = KTUtil::arrayGet($_REQUEST, "postExpected"); $postReceived = KTUtil::arrayGet($_REQUEST, "postReceived"); if (!is_null($postExpected) && is_null($postReceived)) { // A post was to be initiated by the client, but none was received. // This means post_max_size was violated. require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); $errorMessage = _("You tried to upload a file that is larger than the PHP post_max_size setting."); $oPatternCustom->setHtml(getStatusPage($fFolderID, $errorMessage . "rootUrl/control.php?action=browse&fFolderID=$fFolderID\">")); $main->setCentralPayload($oPatternCustom); $main->render(); exit(0); } if (!isset($fFolderID)) { //no folder id was set when coming to this page, //so display an error message require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); $oPatternCustom->setHtml("

" . _("You haven't selected a folder to add a document to.") . "

\n"); $main->setCentralPayload($oPatternCustom); $main->render(); exit(0); } $oFolder = Folder::get($fFolderID); if (!Permission::userHasFolderWritePermission($oFolder)) { //user does not have write permission for this folder, //so don't display add button require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID, _("You do not have permission to add a document to this folder") . "rootUrl/control.php?action=browse&fFolderID=$fFolderID\">")); $main->setCentralPayload($oPatternCustom); $main->render(); exit(0); } //user has permission to add document to this folder if (!isset($fStore)) { //we're still just browsing require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID)); $main->setCentralPayload($oPatternCustom); $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&postExpected=1" . (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "") . (isset($fDocumentTypeID) ? "&fDocumentTypeID=$fDocumentTypeID" : "")); $main->setFormEncType("multipart/form-data"); $main->setHasRequiredFields(true); $main->render(); exit(0); } // check that a document type has been selected if (!$fDocumentTypeID) { // no document type was selected require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); $oPatternCustom->setHtml(getStatusPage($fFolderID, _("A valid document type was not selected.") . "rootUrl/control.php?action=browse&fFolderID=$fFolderID\">")); $main->setCentralPayload($oPatternCustom); $main->render(); exit(0); } // make sure the user actually selected a file first // and that something was uploaded if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) { // no uploaded file require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); $message = _("You did not select a valid document to upload"); $errors = array( 1 => _("The uploaded file is larger than the PHP upload_max_filesize setting"), 2 => _("The uploaded file is larger than the MAX_FILE_SIZE directive that was specified in the HTML form"), 3 => _("The uploaded file was not fully uploaded to KnowledgeTree"), 4 => _("No file was selected to be uploaded to KnowledgeTree"), 6 => _("An internal error occurred receiving the uploaded document"), ); $message = KTUtil::arrayGet($errors, $_FILES['fFile']['error'], $message); if (@ini_get("file_uploads") == false) { $message = _("File uploads are disabled in your PHP configuration"); } $oPatternCustom->setHtml(getStatusPage($fFolderID, $message . "rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\">")); $main->setCentralPayload($oPatternCustom); $main->render(); exit(0); } function localRenderError($oDocument) { print $oDocument->toString(); return; } DBUtil::startTransaction(); $matches = array(); $aFields = array(); foreach ($_REQUEST as $k => $v) { if (preg_match('/^emd(\d+)$/', $k, $matches)) { $aFields[] = array(DocumentField::get($matches[1]), $v); } } $aOptions = array( 'contents' => new KTFSFileLike($_FILES['fFile']['tmp_name']), 'documenttype' => DocumentType::get($fDocumentTypeID), 'metadata' => $aFields, 'description' => $fName, ); $oUser =& User::get($_SESSION["userID"]); $oDocument =& KTDocumentUtil::add($oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions); if (PEAR::isError($oDocument)) { localRenderError($oDocument); exit(0); } //the document was created/uploaded due to a collaboration step in another //document and must be linked to that document if (isset($fDependantDocumentID)) { $oDependantDocument = DependantDocumentInstance::get($fDependantDocumentID); $oDocumentLink = & new DocumentLink($oDependantDocument->getParentDocumentID(), $oDocument->getID(), -1); // XXX: KT_LINK_DEPENDENT if ($oDocumentLink->create()) { //no longer a dependant document, but a linked document $oDependantDocument->delete(); } else { //an error occured whilst trying to link the two documents automatically. Email the parent document //original to inform him/her that the two documents must be linked manually $oParentDocument = Document::get($oDependantDocument->getParentDocumentID()); $oUserDocCreator = User::get($oParentDocument->getCreatorID()); $sBody = $oUserDocCreator->getName() . ", an error occured whilst attempting to automatically link the document, '" . $oDocument->getName() . "' to the document, '" . $oParentDocument->getName() . "'. These two documents " . " are meant to be linked for collaboration purposes. As creator of the document, ' " . $oParentDocument->getName() . "', you are requested to " . "please link them manually by browsing to the parent document, " . generateControllerLink("viewDocument","fDocumentID=" . $oParentDocument->getID(), $oParentDocument->getName()) . " and selecting the link button. " . $oDocument->getName() . " can be found at " . $oDocument->getDisplayPath(); $oEmail = & new Email(); $oEmail->send($oUserDocCreator->getEmail(), "Automatic document linking failed", $sBody); //document no longer dependant document, but must be linked manually $oDependantDocument->delete(); } } DBUtil::commit(); //redirect to the document details page controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); ?>