standardSearchBL.php
10.7 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
/**
* Business logic used to perform document searches
*
* Expected form variables
* o fSearchText - text to search on
* o fBrowseType - current browse type
* o fFolderID - folder currently being browsed (if a folder is being browsed)
* o fDocumentID - document currently being browsed (if a document is being browsed)
* o fCategoryName - name of category being browsed (if a category is being browsed)
* o fDocTypeID - name of document type being browsed (if a doc type is being browsed)
*
*
*/
require_once("../../../../config/dmsDefaults.php");
if (checkSession()) {
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
require_once("standardSearchUI.inc");
if (!isset($fStartIndex)) {
$fStartIndex = 0;
}
if (strlen($fBrowseType) > 0) {
//the user was browsing by a specific type
switch ($fBrowseType) {
case "folder" :
//user was browsing a specific folder - search that folder
if (!$fFolderID) {
//start at the root folder
$fFolderID = 0;
$sFolderString = getApprovedFolderString($fFolderID);
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
} else {
$sFolderString = getApprovedFolderString($fFolderID);
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
}
break;
case "category" :
//user was browsing by category - search all documents in that category
if (!$fCategoryName) {
//no category name specified, so just start at the root folder
$fFolderID = 0;
$sFolderString = getApprovedFolderString($fFolderID);
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
} else {
$sFolderString = getApprovedFolderStringFromCategory($fCategoryName);
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
}
break;
case "documentType" :
//user was browsing by document type - search all documents in that doc type
if (!$fDocumentTypeID) {
//no document type specified, so just start at the root folder
$fFolderID = 0;
$sFolderString = getApprovedFolderString($fFolderID);
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
} else {
//TODO ONCE DOC TYPE/FOLDERS HAVE BEEN CHANGED
}
break;
default:
//search from the root folder down i.e. all documents
break;
}
} else if (strlen($fFolderID) > 0) {
//the user was browsing a folder, search that folder
//var_dump(Folder::getChildren($fFolderID));
echo count(Folder::getChildren($fFolderID));
} else if (strlen($fDocumentID) > 0) {
//the user was viewing a document, search in that document's folder
$oDocument = Document::get($fDocumentID);
$sFolderString = getApprovedFolderString($oDocument->getFolderID());
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
} else {
//search from the root folder down i.e. all documents
$fFolderID = 0;
$sFolderString = getApprovedFolderString($fFolderID);
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
$oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
$main->setCentralPayload($oPatternCustom);
$main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
$main->setHasRequiredFields(true);
$main->render();
}
}
function searchByFolder($iFolderID, $sSearchText) {
global $default;
//get a list of documents in the folder
//TODO - CHECK THAT USER HAS READ RIGHTS TO THIS FOLDER
echo getSearchByFolderPage($iFolderID, $sSearchText);
}
function getApprovedFolderString($iFolderID) {
$aChildren = Folder::getChildren($iFolderID);
$aApprovedChildren = array();
//filter out all the folders the user does
//not have permission to see
for ($i = 0; $i < count($aChildren); $i++) {
$oFolder = Folder::get($aChildren[$i]);
//if the folder is already approved, continue
if (in_array($oFolder->getID(), $aApprovedChildren)) {
//echo "Already in: " . $oFolder->getID() . "<br>";
continue;
}
$aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs());
//if one of the folder's parents is already approved, add the folder
for ($j = 0; $j < count($aParentFolderIDs); $j++) {
if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) {
if (in_array($oFolder->getID(), $aApprovedChildren)) {
$aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
}
continue;
}
}
//check if the user has read permission for this folder
if (Permission::userHasFolderReadPermission($oFolder->getID())) {
$aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
continue;
}
}
return implode(",", $aApprovedChildren);
}
function getApprovedFolderStringFromCategory($sCategory) {
global $default;
$sQuery = "SELECT DISTINCT D.folder_id " .
"FROM $default->owl_documents_table AS D inner join $default->owl_document_fields_table AS DFL ON D.id = DFL.document_id " .
"INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " .
"WHERE DF.name LIKE 'Category' " .
"AND DFL.value LIKE '$sCategory'";
$sql = $default->db;
$sql->query($sQuery);
if ($sql->next_record()) {
//get all the folders in the category
$aFolders = array($sql->f("folder_id"));
while ($sql->next_record()) {
$aFolders[count($aFolders)] = $sql->f("folder_id");
}
$aApprovedChildren = array();
//filter out all the folders the user does
//not have permission to see
for ($i = 0; $i < count($aFolders); $i++) {
$oFolder = Folder::get($aFolders[$i]);
//if the folder is already approved, continue
if (in_array($oFolder->getID(), $aApprovedChildren)) {
//echo "Already in: " . $oFolder->getID() . "<br>";
continue;
}
$aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs());
//if one of the folder's parents is already approved, add the folder
for ($j = 0; $j < count($aParentFolderIDs); $j++) {
if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) {
if (in_array($oFolder->getID(), $aApprovedChildren)) {
$aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
}
continue;
}
}
//check if the user has read permission for this folder
if (Permission::userHasFolderReadPermission($oFolder->getID())) {
$aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
continue;
}
}
return implode(",", $aApprovedChildren);
}
return "0";
}
function getSQLSearchString($sSearchString) {
$aWords = explode(" ", $sSearchString);
$sSQLSearchString;
for ($i = 0; $i < count($aWords) - 1; $i++) {
$sSQLSearchString .= "(WL.word LIKE '%" . $aWords[$i] . "%') OR ";
}
$sSQLSearchString .= "(WL.word LIKE '%" . $aWords[count($aWords) -1] . "%')";
return $sSQLSearchString;
}
function searchByCategory($sCategoryName) {
}
function searchByDocType($iDocTypeID) {
}
?>