Commit a47c54f4fd305545af6fc0c2e3c7ea78b8b76de2

Authored by nbm
1 parent 4cddc0d4

Been moved into a folder action.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4152 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/bulkUploadBL.php deleted
1 -<?php  
2 -/**  
3 - * $Id$  
4 - *  
5 - * Contains the business logic required to build the bulk uploadpage.  
6 - * Will use bulkUploadUI.inc for presentation logic  
7 - *  
8 - * Expected form variable:  
9 - * o $fFolderID - primary key of folder user is currently browsing  
10 - *  
11 - * This program is free software; you can redistribute it and/or modify  
12 - * it under the terms of the GNU General Public License as published by  
13 - * the Free Software Foundation; either version 2 of the License, or  
14 - * (at your option) any later version.  
15 - *  
16 - * This program is distributed in the hope that it will be useful,  
17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
19 - * GNU General Public License for more details.  
20 - *  
21 - * You should have received a copy of the GNU General Public License  
22 - * along with this program; if not, write to the Free Software  
23 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
24 - *  
25 - * @version $Revision$  
26 - * @author Adam Monsen  
27 - * @package documentmanagement  
28 - */  
29 -  
30 -require_once("../../../../config/dmsDefaults.php");  
31 -  
32 -KTUTil::extractGPC('fDocumentTypeID', 'fFolderID', 'fStore');  
33 -  
34 -if (!checkSession()) {  
35 - die("Session check failed");  
36 -}  
37 -  
38 -require_once("$default->fileSystemRoot/lib/database/datetime.inc");  
39 -require_once("$default->fileSystemRoot/lib/documentmanagement/BulkUploadManager.inc");  
40 -require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");  
41 -require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc");  
42 -require_once("$default->fileSystemRoot/lib/security/Permission.inc");  
43 -require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc");  
44 -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");  
45 -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMetaData.inc");  
46 -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc");  
47 -require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");  
48 -require_once("$default->fileSystemRoot/presentation/Html.inc");  
49 -require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
50 -require_once("bulkUploadUI.inc");  
51 -  
52 -require_once(KT_LIB_DIR . '/foldermanagement/Folder.inc');  
53 -require_once(KT_LIB_DIR . '/users/User.inc');  
54 -  
55 -require_once(KT_LIB_DIR . '/import/bulkimport.inc.php');  
56 -require_once(KT_LIB_DIR . '/import/zipimportstorage.inc.php');  
57 -  
58 -$oPatternCustom = & new PatternCustom();  
59 -  
60 -/* CHECK: system has required features to handle bulk upload */  
61 -/*  
62 -if (!BulkUploadManager::isBulkUploadCapable()) {  
63 - // can't do bulk uploading  
64 - $sErrorMessage = _("This system is not capable of handling bulk uploads") . ". <br/>\n"  
65 - . _("Please contact your system administrator") . "<br />\n"  
66 - . getCancelButton($fFolderID);  
67 - $main->setErrorMessage($sErrorMessage);  
68 - $main->setCentralPayload($oPatternCustom);  
69 - $main->render();  
70 - exit(0);  
71 -}  
72 -*/  
73 -  
74 -$postExpected = KTUtil::arrayGet($_REQUEST, "postExpected");  
75 -$postReceived = KTUtil::arrayGet($_REQUEST, "postReceived");  
76 -if (!is_null($postExpected) && is_null($postReceived)) {  
77 - // A post was to be initiated by the client, but none was received.  
78 - // This means post_max_size was violated.  
79 - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
80 - $oPatternCustom = & new PatternCustom();  
81 - $errorMessage = _("You tried to upload a file that is larger than the PHP post_max_size setting.");  
82 - $oPatternCustom->setHtml("<font color=\"red\">" . $errorMessage . "</font><br /><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>");  
83 - $main->setCentralPayload($oPatternCustom);  
84 - $main->render();  
85 - exit(0);  
86 -}  
87 -  
88 -/* CHECK: folder ID passed in */  
89 -if (isset($fFolderID)) {  
90 - $oFolder = Folder::get($fFolderID);  
91 -} else {  
92 - // no folder id was set when coming to this page,  
93 - // so display an error message  
94 - $sErrorMessage = _("You haven't selected a folder to bulk upload to") . ".";  
95 - $main->setErrorMessage($sErrorMessage);  
96 - $main->setCentralPayload($oPatternCustom);  
97 - $main->render();  
98 - exit(0);  
99 -}  
100 -  
101 -/* CHECK: user has write perms for current folder */  
102 -if (!Permission::userHasFolderWritePermission($oFolder)) {  
103 - // user does not have write permission for this folder  
104 - $sErrorMessage = getCancelButton($fFolderID)  
105 - . _("You do not have permission to add a document to this folder") . ".";  
106 - $main->setErrorMessage($sErrorMessage);  
107 - $main->setCentralPayload($oPatternCustom);  
108 - $main->render();  
109 - exit(0);  
110 -}  
111 -  
112 -/* CHECK: user selected a document type */  
113 -if (!$fDocumentTypeID) {  
114 - // show document type chooser form  
115 - $oPatternCustom->setHtml(getChooseDocumentTypePage($fFolderID));  
116 - $main->setFormAction($_SERVER["PHP_SELF"]);  
117 - $main->setErrorMessage($sErrorMessage);  
118 - $main->setCentralPayload($oPatternCustom);  
119 - $main->render();  
120 - exit(0);  
121 -}  
122 -  
123 -/* CHECK: user submitted a file for upload */  
124 -if (!$fStore) {  
125 - // show upload/metatdata form  
126 - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID));  
127 - $main->setFormAction($_SERVER["PHP_SELF"] . "?postExpected=1&fFolderID=$fFolderID");  
128 - $main->setFormEncType("multipart/form-data");  
129 - $main->setHasRequiredFields(true);  
130 - $main->setErrorMessage($sErrorMessage);  
131 - $main->setCentralPayload($oPatternCustom);  
132 - $main->render();  
133 - exit(0);  
134 -}  
135 -  
136 -// make sure the user actually selected a file first  
137 -// and that something was uploaded  
138 -if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) {  
139 - // no uploaded file  
140 - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
141 - $oPatternCustom = & new PatternCustom();  
142 - $message = _("You did not select a valid document to upload");  
143 -  
144 - $errors = array(  
145 - 1 => _("The uploaded file is larger than the PHP upload_max_filesize setting"),  
146 - 2 => _("The uploaded file is larger than the MAX_FILE_SIZE directive that was specified in the HTML form"),  
147 - 3 => _("The uploaded file was not fully uploaded to KnowledgeTree"),  
148 - 4 => _("No file was selected to be uploaded to KnowledgeTree"),  
149 - 6 => _("An internal error occurred receiving the uploaded document"),  
150 - );  
151 - $message = KTUtil::arrayGet($errors, $_FILES['fFile']['error'], $message);  
152 -  
153 - if (@ini_get("file_uploads") == false) {  
154 - $message = _("File uploads are disabled in your PHP configuration");  
155 - }  
156 -  
157 - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID));  
158 - $main->setFormAction($_SERVER["PHP_SELF"]);  
159 - $main->setFormEncType("multipart/form-data");  
160 - $main->setHasRequiredFields(true);  
161 - $main->setErrorMessage($message);  
162 - $main->setCentralPayload($oPatternCustom);  
163 - $main->render();  
164 - exit(0);  
165 -}  
166 -  
167 -// if changing this function, also change related error message  
168 -function isValidBulkUpload() {  
169 - return (strlen($_FILES['fFile']['name']) > 0)  
170 - && file_exists($_FILES['fFile']['tmp_name'])  
171 - && $_FILES['fFile']['size'] > 0  
172 - && (!$_FILES['fFile']['error'])  
173 - && preg_match('/\.zip/i', $_FILES['fFile']['name']);  
174 -}  
175 -  
176 -/* CHECK: bulk upload is valid */  
177 -if (!isValidBulkUpload()) {  
178 - $sErrorMessage = getInvalidBulkUploadErrorMsg() . getRetryUploadButton($fFolderID, $fDocumentTypeID);  
179 - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID));  
180 - $main->setFormAction($_SERVER["PHP_SELF"]);  
181 - $main->setFormEncType("multipart/form-data");  
182 - $main->setHasRequiredFields(true);  
183 - $main->setErrorMessage($message);  
184 - $main->setCentralPayload($oPatternCustom);  
185 - $main->render();  
186 - exit(0);  
187 -}  
188 -  
189 -$matches = array();  
190 -$aFields = array();  
191 -foreach ($_REQUEST as $k => $v) {  
192 - if (preg_match('/^emd(\d+)$/', $k, $matches)) {  
193 - $aFields[] = array(DocumentField::get($matches[1]), $v);  
194 - }  
195 -}  
196 -$aOptions = array(  
197 - 'metadata' => $aFields,  
198 -);  
199 -  
200 -$fs =& new KTZipImportStorage($_FILES['fFile']['tmp_name']);  
201 -$oUser =& User::get($_SESSION['userID']);  
202 -$bm =& new KTBulkImportManager($oFolder, $fs, $oUser, $aOptions);  
203 -  
204 -DBUtil::startTransaction();  
205 -$res = $bm->import();  
206 -if (PEAR::isError($res)) {  
207 - DBUtil::rollback();  
208 - $_SESSION["KTErrorMessage"][] = _("Bulk import failed") . ": " . $res->getMessage();  
209 -} else {  
210 - DBUtil::commit();  
211 -}  
212 -  
213 -controllerRedirect("browse", 'fFolderID=' . $oFolder->getID());  
214 -  
215 -?>  
presentation/lookAndFeel/knowledgeTree/documentmanagement/bulkUploadUI.inc deleted
1 -<?php  
2 -/**  
3 - * $Id$  
4 - *  
5 - * Contains HTML information required to build the bulk upload page.  
6 - * Will be used by bulkUploadBL.php  
7 - *  
8 - * This program is free software; you can redistribute it and/or modify  
9 - * it under the terms of the GNU General Public License as published by  
10 - * the Free Software Foundation; either version 2 of the License, or  
11 - * (at your option) any later version.  
12 - *  
13 - * This program is distributed in the hope that it will be useful,  
14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
16 - * GNU General Public License for more details.  
17 - *  
18 - * You should have received a copy of the GNU General Public License  
19 - * along with this program; if not, write to the Free Software  
20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
21 - *  
22 - * @version $Revision$  
23 - * @author Adam Monsen  
24 - * @package documentmanagement  
25 - */  
26 -  
27 -require_once(KT_LIB_DIR . '/documentmanagement/DocumentField.inc');  
28 -  
29 -/**  
30 - * Displays the generic meta data fields form  
31 - */  
32 -function getGenericMetaDataForm() {  
33 - $oTemplating = KTTemplating::getSingleton();  
34 - $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/editable_metadata_fields");  
35 - $aTemplateData = array(  
36 - 'caption' => _('Generic meta data'),  
37 - 'empty_message' => _("No Generic Meta Data"),  
38 - 'fields' => DocumentField::getList(array('is_generic = ?', array(true))),  
39 - );  
40 - return $oTemplate->render($aTemplateData);  
41 -}  
42 -  
43 -/**  
44 - * Displays the type specific meta data fields form  
45 - */  
46 -function getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID) {  
47 - global $default;  
48 - /*ok*/ $sQuery = array("SELECT DF.id AS id " .  
49 - "FROM document_fields AS DF LEFT JOIN document_type_fields_link AS DTFL ON DTFL.field_id = DF.id " .  
50 - "WHERE DF.is_generic = ? " .  
51 - "AND DTFL.document_type_id = ?", array(false, $iDocumentTypeID));  
52 -  
53 - $aIDs = DBUtil::getResultArray($sQuery);  
54 -  
55 - $aFields = array();  
56 - foreach ($aIDs as $iID) {  
57 - $aFields[] =& call_user_func(array('DocumentField', 'get'), $iID);  
58 - }  
59 - $aTemplateData = array(  
60 - 'caption' => _('Type specific meta data'),  
61 - 'empty_message' => _("No Type Specific Meta Data"),  
62 - 'fields' => $aFields,  
63 - );  
64 - $oTemplating = KTTemplating::getSingleton();  
65 - $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/editable_metadata_fields");  
66 - return $oTemplate->render($aTemplateData);  
67 -}  
68 -  
69 -function getMetaDataForm($iFolderID, $iDocumentTypeID) {  
70 - $oGenericPattern = getGenericMetaDataForm();  
71 - $oTypeSpecificPattern = getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID);  
72 - $sToRender .= "<table border=\"0\" width=\"100%\">\n";  
73 - $sToRender .= "<tr><td><b>" . _("Document Meta Data") . "<b></td></tr>\n";  
74 - $sToRender .= "<tr><td valign=\"top\">" . $oGenericPattern . "</td></tr>";  
75 - $sToRender .= "<tr><td valign=\"top\">" . $oTypeSpecificPattern . "</td></tr>";  
76 - $sToRender .= "</table>";  
77 -  
78 - // validation starts  
79 - $sToRender .= "\n\n<script language=\"javascript\">\n<!--\n";  
80 - $sToRender .= "function validateForm(theForm) {\n";  
81 - // document title  
82 - $sToRender .= "\tif (!(validRequired(theForm.fName, 'Document Title'))) {\n";  
83 - $sToRender .= "\t\treturn false;\n\t}\n";  
84 - // filename  
85 - $sToRender .= "\tif (!(validRequired(theForm.fFile, 'Document Filename'))) {\n";  
86 - $sToRender .= "\t\treturn false;\n\t}\n";  
87 - $sToRender .= "return true;\n}\n";  
88 - $sToRender .= "//-->\n</script>\n\n";  
89 -  
90 - return $sToRender;  
91 -}  
92 -  
93 -function getDocumentType($iFolderID) {  
94 - global $default;  
95 -  
96 - $sWhereClause = "FDL.folder_id = $iFolderID";  
97 - $oPatternListBox = & new PatternListBox("$default->document_types_table", "name", "id", "fDocumentTypeID",$sWhereClause);  
98 - $oPatternListBox->setIncludeDefaultValue(false);  
99 - $oPatternListBox->setFromClause("INNER JOIN $default->folder_doctypes_table AS FDL ON ST.id = FDL.document_type_id");  
100 - $oPatternListBox->setEmptyErrorMessage(_("No document types defined") . "! " . _("Please contact an Administrator"));  
101 -  
102 - $sHeading = "Please select the document type:";  
103 -  
104 - $sToRender = "<table><tr><td><b>$sHeading<b></td></tr><tr><td>" . $oPatternListBox->render() . "</td></tr></table>";  
105 -  
106 - return $sToRender;  
107 -}  
108 -  
109 -function getChooseDocumentTypePage($iFolderID) {  
110 - global $default;  
111 -  
112 - $oFolder = Folder::get($iFolderID);  
113 - if (Permission::userHasFolderWritePermission($oFolder)) {  
114 - $sToRender .= getDocumentType($iFolderID);  
115 - $sActionButtons .= getCancelButton($iFolderID);  
116 - $sActionButtons .= "<input type=\"image\" src=\"" . KTHtml::getAddButton() . "\" border=\"0\"/>";  
117 -  
118 - $sToRender .= "<table border=\"0\" width=\"100%\" >\n";  
119 - $sToRender .= "<tr><td>$sActionButtons</td></tr>";  
120 - $sToRender .= "</table>";  
121 - }  
122 -  
123 - // display subfolders, if any  
124 - $sToRender .= getSubfolderBrowser($iFolderID, $iDocumentTypeID);  
125 -  
126 - return $sToRender;  
127 -}  
128 -  
129 -// display subfolders, if any  
130 -function getSubfolderBrowser($iFolderID, $iDocumentTypeID) {  
131 - $sToRender .= "<table border=\"0\" width=\"100%\">\n";  
132 - $sToRender .= "<tr>\n";  
133 - $sToRender .= "\t<td>" . renderFolderList($iFolderID, generateControllerUrl("bulkUpload", "fDocumentTypeID=$iDocumentTypeID", false)) . "<td>\n";  
134 - $sToRender .= "</tr>\n";  
135 - $sToRender .= "<tr>\n";  
136 - $sToRender .= "</tr>";  
137 - $sToRender .= "</table><br>\n";  
138 - return $sToRender;  
139 -}  
140 -  
141 -function getPage($iFolderID, $iDocumentTypeID) {  
142 - global $default;  
143 -  
144 - $sToRender .= renderFolderPath($iFolderID, generateControllerUrl("bulkUpload", "fDocumentTypeID=$iDocumentTypeID", false), true);  
145 -  
146 - $sToRender .= "<input type=\"hidden\" name=\"fDocumentTypeID\" value=\"$iDocumentTypeID\">";  
147 - $sToRender .= "<input type=\"hidden\" name=\"fStore\" value=\"1\">";  
148 - $sToRender .= "<input type=\"hidden\" name=\"postReceived\" value=\"1\">";  
149 - $sToRender .= "<table>\n";  
150 - $sToRender .= "<tr>\n";  
151 - $sToRender .= "<td colspan=\"2\"><b>" . _("Bulk Upload Zipfile") . ": <b></td>\n";  
152 - $sToRender .= "</tr>\n";  
153 - $sToRender .= "<tr><td>File: </td><td><input type=\"file\" name=\"fFile\"></td></tr>\n";  
154 - $sToRender .= "<tr><td colspan=\"2\">(" . _("Note: file should be a ZIP file without subdirectories. Details entered below apply to ALL documents to be added.") . ")</td></tr>\n";  
155 - $sToRender .= "</table>\n";  
156 -  
157 - $sToRender .= "<table><tr><td><b>" . _("Document Type") . "<b></td></tr><tr><td>" . lookupName($default->document_types_table, $iDocumentTypeID) . "</td></tr></table>";  
158 - $sToRender .= getMetaDataForm($iFolderID, $iDocumentTypeID);  
159 -  
160 - // create "BACK" button (to go back to choose document type id)  
161 - $sToRender .= getBackButton($iFolderID);  
162 - // create "CANCEL" button (to go back to browsing)  
163 - $sToRender .= getCancelButton($iFolderID);  
164 - // create "SUBMIT" button (to actually do the upload)  
165 - $sToRender .= "<input type=\"image\" src=\"" . KTHtml::getSubmitButton() . "\" border=\"0\"/>";  
166 -  
167 - // display subfolders, if any  
168 - $sToRender .= getSubfolderBrowser($iFolderID, $iDocumentTypeID);  
169 -  
170 - return $sToRender;  
171 -}  
172 -  
173 -function getInvalidBulkUploadErrorMsg() {  
174 - return _("You did not select a valid document to upload") . ". <br />\n" .  
175 - _("Bulk upload currently only supports .ZIP files without subdirectories") . ".<br />\n";  
176 -}  
177 -  
178 -// image link ... BACK (try bulk upload again)  
179 -function getRetryUploadButton($iFolderID, $iDocumentTypeID) {  
180 - global $default;  
181 - $sQueryString = "fFolderID=$iFolderID"."&"."fDocumentTypeID=$iDocumentTypeID";  
182 - return generateControllerLink("bulkUpload", $sQueryString, "<img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"/>");  
183 -}  
184 -  
185 -// image link ... BACK (choose document type id again)  
186 -function getBackButton($iFolderID) {  
187 - global $default;  
188 - return generateControllerLink("bulkUpload", "fFolderID=$iFolderID", "<img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"/>");  
189 -}  
190 -  
191 -// image link ... DONE, return to browsing  
192 -function getDoneButton($iFolderID) {  
193 - global $default;  
194 - return generateControllerLink("browse", "fFolderID=$iFolderID", "<img src=\"" . KTHtml::getDoneButton() . "\" border=\"0\"/>");  
195 -}  
196 -  
197 -// image link ... return to browsing  
198 -function getCancelButton($iFolderID) {  
199 - global $default;  
200 - return generateControllerLink("browse", "fFolderID=$iFolderID", "<img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"/>");  
201 -}  
202 -  
203 -?>