addFolderBL.php
8.13 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Business logic page that provides business logic for adding a folder (uses
* addFolderUI.inc for HTML)
*
* The following form variables are expected:
* o $fFolderID - id of the folder the user is currently in
*
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @date 27 January 2003
* @package presentation.lookAndFeel.knowledgeTree.foldermanagement
*/
require_once("../../../../config/dmsDefaults.php");
if (checkSession()) {
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
$oPatternCustom = & new PatternCustom();
if (isset($fFolderID)) {
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
require_once("$default->fileSystemRoot/lib/foldermanagement/FolderDocTypeLink.inc");
require_once("$default->fileSystemRoot/lib/foldermanagement/PhysicalFolderManagement.inc");
require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc");
require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
require_once("$default->fileSystemRoot/presentation/Html.inc");
require_once("addFolderUI.inc");
if (!isset($fFolderName)) {
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
//we're still browsing
if (Permission::userHasFolderWritePermission($fFolderID)) {
//if the user is allowed to add folders, then display the add button
$oPatternCustom->setHtml(renderBrowseAddPage($fFolderID));
} else {
//otherwise just let the user browse
$oPatternCustom->setHtml(renderBrowsePage($fFolderID));
$main->setErrorMessage("You do not have permission to create new folders in this folder");
}
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
} else {fwabyw
//have a folder name to store
if (Permission::userHasFolderWritePermission($fFolderID)) {
//check for illegal characters in the folder name
if (strpos($fFolderName, "\\") === false && strpos($fFolderName, ">") === false &&
strpos($fFolderName, "<") === false && strpos($fFolderName, ":") === false &&
strpos($fFolderName, "*") === false && strpos($fFolderName, "?") === false &&
strpos($fFolderName, "|") === false && strpos($fFolderName, "/") === false &&
strpos($fFolderName, "\"") === false) {
if (Folder::folderExistsName($fFolderName, $fFolderID)) {
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom->setHtml(renderBrowseAddPage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("There is another folder named $fFolderName in this folder already");
$main->setHasRequiredFields(true);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->render();
} else {
$oParentFolder = Folder::get($fFolderID);
//create the folder in the db, giving it the properties of it's parent folder
$oFolder = & new Folder($fFolderName, "", $fFolderID, $_SESSION["userID"], $oParentFolder->getUnitID());
if ($oFolder->create()) {
$oFolderDocTypeLink = & new FolderDocTypeLink($oFolder->getID(), $fDocumentTypeID);
if ($oFolderDocTypeLink->create()) {
//create the folder on the file system
if (PhysicalFolderManagement::createFolder(Folder::getFolderPath($oFolder->getID()))) {
// fire subscription alerts for the new folder
$count = SubscriptionEngine::fireSubscription($oParentFolder->getID(), SubscriptionConstants::subscriptionAlertType("AddFolder"),
SubscriptionConstants::subscriptionType("FolderSubscription"),
array( "newFolderName" => $fFolderName,
"parentFolderName" => $oParentFolder->getName()) );
$default->log->info("addFolderBL.php fired $count subscription alerts for new folder $fFolderName");
redirect("$default->rootUrl/control.php?action=editFolder&fFolderID=" . $oFolder->getID());
} else {
//if we couldn't do that, remove the folder and its doc type link
//from the db and report and error
$oFolderDocTypeLink->delete();
$oFolder->delete();
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom->setHtml(renderBrowsePage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("There was an error creating the folder $fFolderName on the filesystem");
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
}
} else {
//couldn't associate the chosen document type with this folder
//remove the folder from the database
$oFolder->delete();
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom->setHtml(renderBrowsePage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("There was an error creating the folder $fFolderName on the filesystem");
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
}
} else {
//if we couldn't create the folder in the db, report an error
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom->setHtml(renderBrowsePage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("There was an error creating the folder $fFolderName in the database");
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->render();
}
}
} else {
//the user entered an illegal character in the folder name
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom->setHtml(renderBrowseAddPage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("Folder not created. Folder names may not contain: '<', '>', '*', '/', '\', '|', '?' or '\"' ");
$main->setHasRequiredFields(true);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->render();
}
} else {
//if the user doesn't have write permission for this folder,
//give them only browse facilities
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom->setHtml(renderBrowsePage($fFolderID));
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("You do not have permission to create new folders in this folder");
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->render();
}
}
} else {
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom->setHtml("");
$main->setCentralPayload($oPatternCustom);
$main->setErrorMessage("No folder currently selected");
$main->render();
}
}
?>