deleteDocumentBL.php
4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Business logic concerned with the deletion of a document.
* Will use documentDeleteUI for presentation information
*
* @author Rob Cherry, Jam Warehouse South Africa (Pty) Ltd
* @date 19 February 2003
* @package presentation.lookAndFeel.knowledgeTree.documentmanagement
*/
require_once("../../../../config/dmsDefaults.php");
require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
require_once("$default->fileSystemRoot/lib/users/User.inc");
require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc");
require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc");
require_once("$default->fileSystemRoot/presentation/Html.inc");
require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
require_once("deleteDocumentUI.inc");
if (checkSession()) {
if (isset($fDocumentID)) {
if (Permission::userHasDocumentWritePermission($fDocumentID)) {
if (isset($fDeleteConfirmed)) {
//deletion of document is confirmed
$oDocument = Document::get($fDocumentID);
if (isset($oDocument)) {
$sDocumentPath = Folder::getFolderPath($oDocument->getFolderID()) . $oDocument->getFileName();
$oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document deleted", DELETE);
$oDocumentTransaction->create();
if ($oDocument->delete()) {
if (unlink($sDocumentPath)) {
// successfully deleted the document from the file system
// fire subscription alerts for the deleted document
$count = SubscriptionEngine::fireSubscription($oDocument->getFolderID(), SubscriptionConstants::subscriptionAlertType("RemoveDocument"),
SubscriptionConstants::subscriptionType("FolderSubscription"),
array( "removedDocumentName" => $oDocument->getName(),
"folderName" => Folder::getFolderName($oDocument->getFolderID())));
$default->log->info("deleteDocumentBL.php fired $count subscription alerts for removed document " . $oDocument->getName());
// redirect to the browse folder page
redirect("$default->rootUrl/control.php?action=browse&fFolderID=" . $oDocument->getFolderID());
} else {
//could not delete the document from the file system
//reverse the document deletion
$oDocument->create();
//get rid of the document transaction
$oDocumentTransaction->delete();
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml("");
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("The document could not be deleted from the file system");
$main->render();
}
} else {
//could not delete the document in the db
$oDocumentTransaction->delete();
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml("");
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("The document could not be deleted from the database");
$main->render();
}
} else {
//could not load document object
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml("");
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("An error occured whilst retrieving the document from the database");
$main->render();
}
} else {
//get confirmation first
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oDocument = Document::get($fDocumentID);
$oPatternCustom->setHtml(getPage($fDocumentID, $oDocument->getFolderID(), $oDocument->getName()));
$main->setCentralPayload($oPatternCustom);
$main->render();
}
} else {
//user does not have permission to delete the document
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml("");
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("You do not have permission to delete this document");
$main->render();
}
} else {
//no document selected for deletion
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml("");
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("No document currently selected");
$main->render();
}
}