addDocumentBL.php
7.25 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Business Logic to add a new document to the
* database. Will use addDocumentUI.inc for presentation
*
* Expected form variable:
* o $fFolderID - primary key of folder user is currently browsing
*
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @date 28 January 2003
* @package presentation.lookAndFeel.knowledgeTree.documentmanagement
*/
require_once("../../../../config/dmsDefaults.php");
if (checkSession()) {
require_once("$default->owl_fs_root/lib/visualpatterns/PatternTableSqlQuery.inc");
require_once("$default->owl_fs_root/lib/visualpatterns/PatternCustom.inc");
require_once("$default->owl_fs_root/lib/foldermanagement/Folder.inc");
require_once("$default->owl_fs_root/lib/documentmanagement/Document.inc");
require_once("$default->owl_fs_root/lib/documentmanagement/DocumentTransaction.inc");
require_once("$default->owl_fs_root/lib/web/WebDocument.inc");
require_once("$default->owl_fs_root/lib/documentmanagement/PhysicalDocumentManager.inc");
require_once("$default->owl_fs_root/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
require_once("$default->owl_fs_root/presentation/Html.inc");
require_once("addDocumentUI.inc");
if (isset($fFolderID)) {
if (Permission::userHasFolderWritePermission($fFolderID)) {
//user has permission to add document to this folder
if (isset($fForStore)) {
//user wants to store a document
//make sure the user actually selected a file first
if (strlen($_FILES['fFile']['name']) > 0) {
//if the user selected a file to upload
//create the document in the database
$oDocument = & PhysicalDocumentManager::createDocumentFromUploadedFile($_FILES['fFile'], $fFolderID);
if (!(Document::documentExists($oDocument->getFileName(), $oDocument->getFolderID()))) {
if ($oDocument->create()) {
//if the document was successfully created in the db, then store it on the file system
if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "None", $_FILES['fFile']['tmp_name'])) {
//create the web document link
$oWebDocument = & new WebDocument($oDocument->getID(), -1, 1, NOT_PUBLISHED, getCurrentDateTime());
$oWebDocument->create();
//create the document transaction record
$oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document created", CREATE);
$oDocumentTransaction->create();
//redirect to the document view page
redirect("$default->owl_root_url/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID());
} else {
require_once("$default->owl_fs_root/presentation/webpageTemplate.inc");
$oDocument->delete();
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getBrowseAddPage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1");
$main->setFormEncType("multipart/form-data");
$main->setErrorMessage("An error occured while storing the document on the file system");
$main->render();
}
} else {
require_once("$default->owl_fs_root/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getBrowseAddPage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1");
$main->setFormEncType("multipart/form-data");
$main->setErrorMessage("An error occured while storing the document in the database");
$main->render();
}
} else {
require_once("$default->owl_fs_root/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getBrowseAddPage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1");
$main->setFormEncType("multipart/form-data");
$main->setErrorMessage("A document with this file name already exists in this folder");
$main->render();
}
} else {
require_once("$default->owl_fs_root/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getBrowseAddPage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1");
$main->setFormEncType("multipart/form-data");
$main->setErrorMessage("Please select a document by first clicking on 'Browse'. Then click 'Add'");
$main->render();
}
} else {
//we're still just browsing
require_once("$default->owl_fs_root/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getBrowseAddPage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1");
$main->setFormEncType("multipart/form-data");
$main->render();
}
} else {
//user does not have write permission for this folder,
//so don't display add button
require_once("$default->owl_fs_root/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getBrowsePage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("You do not have permission to add a document to this folder");
$main->render();
}
} else {
//no folder id was set when coming to this page,
//so display an error message
require_once("$default->owl_fs_root/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml("<p class=\"errorText\">No folder to which a document can be added is currently selected</p>\n");
$main->setCentralPayload($oPatternCustom);
$main->render();
}
}
?>