Commit 8092e5172051ba6be158161b4f49eabe652bd878
1 parent
af8535a2
Make code easier to understand by flattening nested if statements.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3056 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
193 additions
and
178 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php
| ... | ... | @@ -33,185 +33,200 @@ require_once("../../../../config/dmsDefaults.php"); |
| 33 | 33 | |
| 34 | 34 | KTUtil::extractGPC('fFolderID', 'fStore', 'fDocumentTypeID', 'fName', 'fDependantDocumentID'); |
| 35 | 35 | |
| 36 | -if (checkSession()) { | |
| 37 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); | |
| 38 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMetaData.inc"); | |
| 39 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); | |
| 40 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | |
| 41 | - require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | |
| 42 | - require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | |
| 43 | - require_once("$default->fileSystemRoot/lib/documentmanagement/DependantDocumentInstance.inc"); | |
| 44 | - require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentLink.inc"); | |
| 45 | - require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | |
| 46 | - require_once("$default->fileSystemRoot/lib/web/WebDocument.inc"); | |
| 47 | - require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); | |
| 48 | - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | |
| 49 | - require_once("$default->fileSystemRoot/presentation/Html.inc"); | |
| 50 | - require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | |
| 51 | - require_once("addDocumentUI.inc"); | |
| 52 | - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc"); | |
| 53 | - | |
| 54 | - if (isset($fFolderID)) { | |
| 55 | - $oFolder = Folder::get($fFolderID); | |
| 56 | - if (Permission::userHasFolderWritePermission($oFolder)) { | |
| 57 | - //user has permission to add document to this folder | |
| 58 | - if (isset($fStore)) { | |
| 59 | - // check that a document type has been selected | |
| 60 | - if ($fDocumentTypeID) { | |
| 61 | - // make sure the user actually selected a file first | |
| 62 | - // and that something was uploaded | |
| 63 | - if ( (strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0) { | |
| 64 | - //if the user selected a file to upload | |
| 65 | - //create the document in the database | |
| 66 | - $oDocument = & PhysicalDocumentManager::createDocumentFromUploadedFile($_FILES['fFile'], $fFolderID); | |
| 67 | - // set the document title | |
| 68 | - $oDocument->setName($fName); | |
| 69 | - // set the document type id | |
| 70 | - $oDocument->setDocumentTypeID($fDocumentTypeID); | |
| 71 | - if (!(Document::documentExists($oDocument->getFileName(), $oDocument->getFolderID()))) { | |
| 72 | - if ($oDocument->create()) { | |
| 73 | - //if the document was successfully created in the db, then store it on the file system | |
| 74 | - if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "None", $_FILES['fFile']['tmp_name'])) { | |
| 75 | - //create the web document link | |
| 76 | - $oWebDocument = & new WebDocument($oDocument->getID(), -1, 1, NOT_PUBLISHED, getCurrentDateTime()); | |
| 77 | - if ($oWebDocument->create()) { | |
| 78 | - $default->log->error("addDocumentBL.php created web document for document ID=" . $oDocument->getID()); | |
| 79 | - } else { | |
| 80 | - $default->log->error("addDocumentBL.php couldn't create web document for document ID=" . $oDocument->getID()); | |
| 81 | - } | |
| 82 | - //create the document transaction record | |
| 83 | - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document created", CREATE); | |
| 84 | - if ($oDocumentTransaction->create()) { | |
| 85 | - $default->log->debug("addDocumentBL.php created create document transaction for document ID=" . $oDocument->getID()); | |
| 86 | - } else { | |
| 87 | - $default->log->error("addDocumentBL.php couldn't create create document transaction for document ID=" . $oDocument->getID()); | |
| 88 | - } | |
| 89 | - | |
| 90 | - //the document was created/uploaded due to a collaboration step in another | |
| 91 | - //document and must be linked to that document | |
| 92 | - if (isset($fDependantDocumentID)) { | |
| 93 | - $oDependantDocument = DependantDocumentInstance::get($fDependantDocumentID); | |
| 94 | - $oDocumentLink = & new DocumentLink($oDependantDocument->getParentDocumentID(), $oDocument->getID()); | |
| 95 | - if ($oDocumentLink->create()) { | |
| 96 | - //no longer a dependant document, but a linked document | |
| 97 | - $oDependantDocument->delete(); | |
| 98 | - } else { | |
| 99 | - //an error occured whilst trying to link the two documents automatically. Email the parent document | |
| 100 | - //original to inform him/her that the two documents must be linked manually | |
| 101 | - $oParentDocument = Document::get($oDependantDocument->getParentDocumentID()); | |
| 102 | - $oUserDocCreator = User::get($oParentDocument->getCreatorID()); | |
| 103 | - | |
| 104 | - $sBody = $oUserDocCreator->getName() . ", an error occured whilst attempting to automatically link the document, '" . | |
| 105 | - $oDocument->getName() . "' to the document, '" . $oParentDocument->getName() . "'. These two documents " . | |
| 106 | - " are meant to be linked for collaboration purposes. As creator of the document, ' " . $oParentDocument->getName() . "', you are requested to " . | |
| 107 | - "please link them manually by browsing to the parent document, " . | |
| 108 | - generateControllerLink("viewDocument","fDocumentID=" . $oParentDocument->getID(), $oParentDocument->getName()) . | |
| 109 | - " and selecting the link button. " . $oDocument->getName() . " can be found at " . $oDocument->getDisplayPath(); | |
| 110 | - | |
| 111 | - $oEmail = & new Email(); | |
| 112 | - $oEmail->send($oUserDocCreator->getEmail(), "Automatic document linking failed", $sBody); | |
| 113 | - | |
| 114 | - //document no longer dependant document, but must be linked manually | |
| 115 | - $oDependantDocument->delete(); | |
| 116 | - } | |
| 117 | - } | |
| 118 | - | |
| 119 | - // now handle meta data, pass new document id to queries | |
| 120 | - $aQueries = constructQuery(array_keys($_POST), array("document_id" =>$oDocument->getID())); | |
| 121 | - for ($i=0; $i<count($aQueries); $i++) { | |
| 122 | - $sql = $default->db; | |
| 123 | - if ($sql->query($aQueries[$i])) { | |
| 124 | - $default->log->info("addDocumentBL.php query succeeded=" . $aQueries[$i]); | |
| 125 | - } else { | |
| 126 | - $default->log->error("addDocumentBL.php query failed=" . $aQueries[$i]); | |
| 127 | - } | |
| 128 | - } | |
| 129 | - | |
| 130 | - // fire subscription alerts for the new document | |
| 131 | - $count = SubscriptionEngine::fireSubscription($fFolderID, SubscriptionConstants::subscriptionAlertType("AddDocument"), | |
| 132 | - SubscriptionConstants::subscriptionType("FolderSubscription"), | |
| 133 | - array( "newDocumentName" => $oDocument->getName(), | |
| 134 | - "folderName" => Folder::getFolderName($fFolderID))); | |
| 135 | - $default->log->info("addDocumentBL.php fired $count subscription alerts for new document " . $oDocument->getName()); | |
| 136 | - | |
| 137 | - $default->log->info("addDocumentBL.php successfully added document " . $oDocument->getFileName() . " to folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); | |
| 138 | - //redirect to the document details page | |
| 139 | - controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); | |
| 140 | - } else { | |
| 141 | - // couldn't store document in db | |
| 142 | - $default->log->error("addDocumentBL.php Filesystem error attempting to store document " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . "; id=$fFolderID"); | |
| 143 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 144 | - // delete the document from the database | |
| 145 | - $oDocument->delete(); | |
| 146 | - $oPatternCustom = & new PatternCustom(); | |
| 147 | - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("An error occured while storing the document on the file system, please try again.") . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>")); | |
| 148 | - $main->setCentralPayload($oPatternCustom); | |
| 149 | - $main->render(); | |
| 150 | - } | |
| 151 | - } else { | |
| 152 | - // couldn't store document on fs | |
| 153 | - $default->log->error("addDocumentBL.php DB error storing document in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); | |
| 154 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 155 | - $oPatternCustom = & new PatternCustom(); | |
| 156 | - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("An error occured while storing the document in the database, please try again.") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 157 | - $main->setCentralPayload($oPatternCustom); | |
| 158 | - $main->render(); | |
| 159 | - } | |
| 160 | - } else { | |
| 161 | - // document already exists in folder | |
| 162 | - $default->log->error("addDocumentBL.php Document exists with name " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); | |
| 163 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 164 | - $oPatternCustom = & new PatternCustom(); | |
| 165 | - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("A document with this file name already exists in this folder") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 166 | - $main->setCentralPayload($oPatternCustom); | |
| 167 | - $main->render(); | |
| 168 | - } | |
| 169 | - } else { | |
| 170 | - // no uploaded file | |
| 171 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 172 | - $oPatternCustom = & new PatternCustom(); | |
| 173 | - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("You did not select a valid document to upload") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 174 | - $main->setCentralPayload($oPatternCustom); | |
| 175 | - $main->render(); | |
| 176 | - } | |
| 177 | - } else { | |
| 178 | - // no document type was selected | |
| 179 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 180 | - $oPatternCustom = & new PatternCustom(); | |
| 181 | - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("A valid document type was not selected.") . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>")); | |
| 182 | - $main->setCentralPayload($oPatternCustom); | |
| 183 | - $main->render(); | |
| 184 | - } | |
| 185 | - } else { | |
| 186 | - //we're still just browsing | |
| 187 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 188 | - $oPatternCustom = & new PatternCustom(); | |
| 189 | - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID)); | |
| 190 | - $main->setCentralPayload($oPatternCustom); | |
| 191 | - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID" . | |
| 192 | - (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "") . | |
| 193 | - (isset($fDocumentTypeID) ? "&fDocumentTypeID=$fDocumentTypeID" : "")); | |
| 194 | - $main->setFormEncType("multipart/form-data"); | |
| 195 | - $main->setHasRequiredFields(true); | |
| 196 | - $main->render(); | |
| 197 | - } | |
| 198 | - } else { | |
| 199 | - //user does not have write permission for this folder, | |
| 200 | - //so don't display add button | |
| 201 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 202 | - $oPatternCustom = & new PatternCustom(); | |
| 203 | - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID, _("You do not have permission to add a document to this folder") . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>")); | |
| 204 | - $main->setCentralPayload($oPatternCustom); | |
| 205 | - $main->render(); | |
| 206 | - } | |
| 36 | +if (!checkSession()) { | |
| 37 | + exit(0); | |
| 38 | +} | |
| 39 | + | |
| 40 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); | |
| 41 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMetaData.inc"); | |
| 42 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); | |
| 43 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | |
| 44 | +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | |
| 45 | +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | |
| 46 | +require_once("$default->fileSystemRoot/lib/documentmanagement/DependantDocumentInstance.inc"); | |
| 47 | +require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentLink.inc"); | |
| 48 | +require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | |
| 49 | +require_once("$default->fileSystemRoot/lib/web/WebDocument.inc"); | |
| 50 | +require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); | |
| 51 | +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | |
| 52 | +require_once("$default->fileSystemRoot/presentation/Html.inc"); | |
| 53 | +require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | |
| 54 | +require_once("addDocumentUI.inc"); | |
| 55 | +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc"); | |
| 56 | + | |
| 57 | +if (!isset($fFolderID)) { | |
| 58 | + //no folder id was set when coming to this page, | |
| 59 | + //so display an error message | |
| 60 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 61 | + $oPatternCustom = & new PatternCustom(); | |
| 62 | + $oPatternCustom->setHtml("<p class=\"errorText\">" . _("You haven't selected a folder to add a document to.") . "</p>\n"); | |
| 63 | + $main->setCentralPayload($oPatternCustom); | |
| 64 | + $main->render(); | |
| 65 | + exit(0); | |
| 66 | +} | |
| 67 | + | |
| 68 | +$oFolder = Folder::get($fFolderID); | |
| 69 | +if (!Permission::userHasFolderWritePermission($oFolder)) { | |
| 70 | + //user does not have write permission for this folder, | |
| 71 | + //so don't display add button | |
| 72 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 73 | + $oPatternCustom = & new PatternCustom(); | |
| 74 | + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID, _("You do not have permission to add a document to this folder") . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>")); | |
| 75 | + $main->setCentralPayload($oPatternCustom); | |
| 76 | + $main->render(); | |
| 77 | + exit(0); | |
| 78 | +} | |
| 79 | + | |
| 80 | +//user has permission to add document to this folder | |
| 81 | +if (!isset($fStore)) { | |
| 82 | + //we're still just browsing | |
| 83 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 84 | + $oPatternCustom = & new PatternCustom(); | |
| 85 | + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID)); | |
| 86 | + $main->setCentralPayload($oPatternCustom); | |
| 87 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID" . | |
| 88 | + (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "") . | |
| 89 | + (isset($fDocumentTypeID) ? "&fDocumentTypeID=$fDocumentTypeID" : "")); | |
| 90 | + $main->setFormEncType("multipart/form-data"); | |
| 91 | + $main->setHasRequiredFields(true); | |
| 92 | + $main->render(); | |
| 93 | + exit(0); | |
| 94 | +} | |
| 95 | + | |
| 96 | +// check that a document type has been selected | |
| 97 | +if (!$fDocumentTypeID) { | |
| 98 | + // no document type was selected | |
| 99 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 100 | + $oPatternCustom = & new PatternCustom(); | |
| 101 | + $oPatternCustom->setHtml(getStatusPage($fFolderID, _("A valid document type was not selected.") . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>")); | |
| 102 | + $main->setCentralPayload($oPatternCustom); | |
| 103 | + $main->render(); | |
| 104 | + exit(0); | |
| 105 | +} | |
| 106 | + | |
| 107 | +// make sure the user actually selected a file first | |
| 108 | +// and that something was uploaded | |
| 109 | +if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) { | |
| 110 | + // no uploaded file | |
| 111 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 112 | + $oPatternCustom = & new PatternCustom(); | |
| 113 | + $oPatternCustom->setHtml(getStatusPage($fFolderID, _("You did not select a valid document to upload") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 114 | + $main->setCentralPayload($oPatternCustom); | |
| 115 | + $main->render(); | |
| 116 | + exit(0); | |
| 117 | +} | |
| 118 | + | |
| 119 | +//if the user selected a file to upload | |
| 120 | +//create the document in the database | |
| 121 | +$oDocument = & PhysicalDocumentManager::createDocumentFromUploadedFile($_FILES['fFile'], $fFolderID); | |
| 122 | +// set the document title | |
| 123 | +$oDocument->setName($fName); | |
| 124 | +// set the document type id | |
| 125 | +$oDocument->setDocumentTypeID($fDocumentTypeID); | |
| 126 | + | |
| 127 | +if (Document::documentExists($oDocument->getFileName(), $oDocument->getFolderID())) { | |
| 128 | + // document already exists in folder | |
| 129 | + $default->log->error("addDocumentBL.php Document exists with name " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); | |
| 130 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 131 | + $oPatternCustom = & new PatternCustom(); | |
| 132 | + $oPatternCustom->setHtml(getStatusPage($fFolderID, _("A document with this file name already exists in this folder") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 133 | + $main->setCentralPayload($oPatternCustom); | |
| 134 | + $main->render(); | |
| 135 | + exit(0); | |
| 136 | +} | |
| 137 | + | |
| 138 | +if (!$oDocument->create()) { | |
| 139 | + // couldn't store document on fs | |
| 140 | + $default->log->error("addDocumentBL.php DB error storing document in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); | |
| 141 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 142 | + $oPatternCustom = & new PatternCustom(); | |
| 143 | + $oPatternCustom->setHtml(getStatusPage($fFolderID, _("An error occured while storing the document in the database, please try again.") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 144 | + $main->setCentralPayload($oPatternCustom); | |
| 145 | + $main->render(); | |
| 146 | + exit(0); | |
| 147 | +} | |
| 148 | + | |
| 149 | +//if the document was successfully created in the db, then store it on the file system | |
| 150 | +if (!PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "None", $_FILES['fFile']['tmp_name'])) { | |
| 151 | + // couldn't store document on filesystem | |
| 152 | + $default->log->error("addDocumentBL.php Filesystem error attempting to store document " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . "; id=$fFolderID"); | |
| 153 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 154 | + // delete the document from the database | |
| 155 | + $oDocument->delete(); | |
| 156 | + $oPatternCustom = & new PatternCustom(); | |
| 157 | + $oPatternCustom->setHtml(getStatusPage($fFolderID, _("An error occured while storing the document on the file system, please try again.") . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>")); | |
| 158 | + $main->setCentralPayload($oPatternCustom); | |
| 159 | + $main->render(); | |
| 160 | + exit(0); | |
| 161 | +} | |
| 162 | + | |
| 163 | +// ALL SYSTEMS GO! | |
| 164 | + | |
| 165 | + | |
| 166 | +//create the web document link | |
| 167 | +$oWebDocument = & new WebDocument($oDocument->getID(), -1, 1, NOT_PUBLISHED, getCurrentDateTime()); | |
| 168 | +if ($oWebDocument->create()) { | |
| 169 | + $default->log->error("addDocumentBL.php created web document for document ID=" . $oDocument->getID()); | |
| 170 | +} else { | |
| 171 | + $default->log->error("addDocumentBL.php couldn't create web document for document ID=" . $oDocument->getID()); | |
| 172 | +} | |
| 173 | +//create the document transaction record | |
| 174 | +$oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document created", CREATE); | |
| 175 | +if ($oDocumentTransaction->create()) { | |
| 176 | + $default->log->debug("addDocumentBL.php created create document transaction for document ID=" . $oDocument->getID()); | |
| 177 | +} else { | |
| 178 | + $default->log->error("addDocumentBL.php couldn't create create document transaction for document ID=" . $oDocument->getID()); | |
| 179 | +} | |
| 180 | + | |
| 181 | +//the document was created/uploaded due to a collaboration step in another | |
| 182 | +//document and must be linked to that document | |
| 183 | +if (isset($fDependantDocumentID)) { | |
| 184 | + $oDependantDocument = DependantDocumentInstance::get($fDependantDocumentID); | |
| 185 | + $oDocumentLink = & new DocumentLink($oDependantDocument->getParentDocumentID(), $oDocument->getID()); | |
| 186 | + if ($oDocumentLink->create()) { | |
| 187 | + //no longer a dependant document, but a linked document | |
| 188 | + $oDependantDocument->delete(); | |
| 207 | 189 | } else { |
| 208 | - //no folder id was set when coming to this page, | |
| 209 | - //so display an error message | |
| 210 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 211 | - $oPatternCustom = & new PatternCustom(); | |
| 212 | - $oPatternCustom->setHtml("<p class=\"errorText\">" . _("You haven't selected a folder to add a document to.") . "</p>\n"); | |
| 213 | - $main->setCentralPayload($oPatternCustom); | |
| 214 | - $main->render(); | |
| 190 | + //an error occured whilst trying to link the two documents automatically. Email the parent document | |
| 191 | + //original to inform him/her that the two documents must be linked manually | |
| 192 | + $oParentDocument = Document::get($oDependantDocument->getParentDocumentID()); | |
| 193 | + $oUserDocCreator = User::get($oParentDocument->getCreatorID()); | |
| 194 | + | |
| 195 | + $sBody = $oUserDocCreator->getName() . ", an error occured whilst attempting to automatically link the document, '" . | |
| 196 | + $oDocument->getName() . "' to the document, '" . $oParentDocument->getName() . "'. These two documents " . | |
| 197 | + " are meant to be linked for collaboration purposes. As creator of the document, ' " . $oParentDocument->getName() . "', you are requested to " . | |
| 198 | + "please link them manually by browsing to the parent document, " . | |
| 199 | + generateControllerLink("viewDocument","fDocumentID=" . $oParentDocument->getID(), $oParentDocument->getName()) . | |
| 200 | + " and selecting the link button. " . $oDocument->getName() . " can be found at " . $oDocument->getDisplayPath(); | |
| 201 | + | |
| 202 | + $oEmail = & new Email(); | |
| 203 | + $oEmail->send($oUserDocCreator->getEmail(), "Automatic document linking failed", $sBody); | |
| 204 | + | |
| 205 | + //document no longer dependant document, but must be linked manually | |
| 206 | + $oDependantDocument->delete(); | |
| 215 | 207 | } |
| 216 | 208 | } |
| 209 | + | |
| 210 | +// now handle meta data, pass new document id to queries | |
| 211 | +$aQueries = constructQuery(array_keys($_POST), array("document_id" =>$oDocument->getID())); | |
| 212 | +for ($i=0; $i<count($aQueries); $i++) { | |
| 213 | + $sql = $default->db; | |
| 214 | + if ($sql->query($aQueries[$i])) { | |
| 215 | + $default->log->info("addDocumentBL.php query succeeded=" . $aQueries[$i]); | |
| 216 | + } else { | |
| 217 | + $default->log->error("addDocumentBL.php query failed=" . $aQueries[$i]); | |
| 218 | + } | |
| 219 | +} | |
| 220 | + | |
| 221 | +// fire subscription alerts for the new document | |
| 222 | +$count = SubscriptionEngine::fireSubscription($fFolderID, SubscriptionConstants::subscriptionAlertType("AddDocument"), | |
| 223 | + SubscriptionConstants::subscriptionType("FolderSubscription"), | |
| 224 | + array( "newDocumentName" => $oDocument->getName(), | |
| 225 | + "folderName" => Folder::getFolderName($fFolderID))); | |
| 226 | +$default->log->info("addDocumentBL.php fired $count subscription alerts for new document " . $oDocument->getName()); | |
| 227 | + | |
| 228 | +$default->log->info("addDocumentBL.php successfully added document " . $oDocument->getFileName() . " to folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); | |
| 229 | +//redirect to the document details page | |
| 230 | +controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); | |
| 231 | + | |
| 217 | 232 | ?> | ... | ... |