Commit 381e35e40146919db615e15b23fb8528c5b276b7

Authored by Kevin G Fourie
1 parent d3a07e60

Merged "overridden" files in MultiSelect plugin.

plugins/multiselect/BulkImport.php
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * KnowledgeTree Community Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
8   - * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
10   - * This program is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU General Public License version 3 as published by the
12   - * Free Software Foundation.
13   - *
14   - * This program is distributed in the hope that it will be useful, but WITHOUT
15   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17   - * details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23   - * California 94120-7775, or email info@knowledgetree.com.
24   - *
25   - * The interactive user interfaces in modified source and object code versions
26   - * of this program must display Appropriate Legal Notices, as required under
27   - * Section 5 of the GNU General Public License version 3.
28   - *
29   - * In accordance with Section 7(b) of the GNU General Public License version 3,
30   - * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
35   - * Contributor( s): ______________________________________
36   - *
37   - */
38   -
39   -require_once(KT_LIB_DIR . "/actions/folderaction.inc.php");
40   -require_once(KT_LIB_DIR . "/import/fsimportstorage.inc.php");
41   -require_once(KT_LIB_DIR . "/import/bulkimport.inc.php");
42   -require_once(KT_LIB_DIR . "/documentmanagement/observers.inc.php");
43   -
44   -
45   -require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php");
46   -require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php");
47   -require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php");
48   -
49   -require_once(KT_LIB_DIR . "/validation/dispatchervalidation.inc.php");
50   -
51   -class InetBulkImportFolderMultiSelectAction extends KTFolderAction {
52   - var $sName = 'inet.actions.folder.bulkImport.multiselect';
53   -
54   - var $_sShowPermission = "ktcore.permissions.write";
55   - var $bAutomaticTransaction = false;
56   -
57   - /**
58   - * hide existing url and return name to new url | iNET Process
59   - * @Return string.
60   - * @param.
61   - */
62   - function getDisplayName() {
63   - if(!KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
64   - {
65   - $js = "<script src='plugins/multiselect/js/jquery-1.2.6.js' type='text/javascript'></script>";
66   - $js .= "<script src='plugins/multiselect/js/hidelink.js' type='text/javascript'></script>";
67   - return $js._kt('Import from Server Location');
68   - }
69   - else
70   - {
71   - return null;
72   - }
73   - }
74   -
75   - /**
76   - * check for permissions | iNET Process
77   - * @Return unknown.
78   - * @param.
79   - */
80   - function getInfo() {
81   - global $default;
82   - if($default->disableBulkImport){
83   - return null;
84   - }
85   -
86   - if (!Permission::userIsSystemAdministrator($this->oUser->getId())) {
87   - return null;
88   -
89   - }
90   - return parent::getInfo();
91   - }
92   -
93   - /**
94   - * This is Default function to be called load template for import action. | iNET Process
95   - * @Return template.
96   - * @param.
97   - */
98   - function do_main() {
99   - $this->oPage->setBreadcrumbDetails(_kt("bulk import"));
100   - $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkImport');
101   - $add_fields = array();
102   - $add_fields[] = new KTStringWidget(_kt('Path'), _kt('The path containing the documents to be added to the document management system.'), 'path', "", $this->oPage, true);
103   -
104   - $aVocab = array('' => _kt('- Please select a document type -'));
105   - foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) {
106   - if(!$oDocumentType->getDisabled()) {
107   - $aVocab[$oDocumentType->getId()] = $oDocumentType->getName();
108   - }
109   - }
110   -
111   - $fieldOptions = array("vocab" => $aVocab);
112   - $add_fields[] = new KTLookupWidget(_kt('Document Type'), _kt('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'), 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions);
113   -
114   - $fieldsets = array();
115   - $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
116   - $activesets = KTFieldset::getGenericFieldsets();
117   - foreach ($activesets as $oFieldset) {
118   - $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
119   - array_push($fieldsets, new $displayClass($oFieldset));
120   - }
121   -
122   - $oTemplate->setData(array(
123   - 'context' => &$this,
124   - 'add_fields' => $add_fields,
125   - 'generic_fieldsets' => $fieldsets,
126   - ));
127   - return $oTemplate->render();
128   - }
129   -
130   - /**
131   - * Performs actual import action. | iNET Process
132   - * @Return.
133   - * @param.
134   - */
135   - function do_import() {
136   -
137   - set_time_limit(0);
138   -
139   - $aErrorOptions = array(
140   - 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
141   - );
142   -
143   - $aErrorOptions['message'] = _kt('Invalid document type provided');
144   - $oDocumentType = $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId'], $aErrorOptions);
145   -
146   - $aErrorOptions['message'] = _kt('Invalid path provided');
147   - $sPath = $this->oValidator->validateString($_REQUEST['path'], $aErrorOptions);
148   -
149   - $matches = array();
150   - $aFields = array();
151   - foreach ($_REQUEST as $k => $v) {
152   - if (preg_match('/^metadata_(\d+)$/', $k, $matches)) {
153   -
154   - // multiselect change start
155   - $oDocField = DocumentField::get($matches[1]);
156   - if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v))
157   - {
158   - $v = join(", ", $v);
159   - }
160   - $aFields[] = array($oDocField, $v);
161   -
162   - // previously it was just one line which is commented, just above line
163   - // multiselect change end
164   - }
165   - }
166   -
167   - $aOptions = array(
168   - 'documenttype' => $oDocumentType,
169   - 'metadata' => $aFields,
170   - 'copy_upload' => 'true',
171   - );
172   -
173   - $po =& new JavascriptObserver($this);
174   - $po->start();
175   - $oUploadChannel =& KTUploadChannel::getSingleton();
176   - $oUploadChannel->addObserver($po);
177   -
178   - $fs =& new KTFSImportStorage($sPath);
179   - $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
180   - if(KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
181   - {
182   - require_once(KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php");
183   - $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
184   - }
185   - else
186   - {
187   - $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
188   - }
189   - DBUtil::startTransaction();
190   - $res = $bm->import();
191   - if (PEAR::isError($res)) {
192   - DBUtil::rollback();
193   - $_SESSION["KTErrorMessage"][] = _kt("Bulk import failed") . ": " . $res->getMessage();
194   - } else {
195   - DBUtil::commit();
196   - $this->addInfoMessage(_kt("Bulk import succeeded"));
197   - }
198   -
199   - $po->redirectToFolder($this->oFolder->getId());
200   - exit(0);
201   - }
202   -}
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * KnowledgeTree Community Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  8 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + * California 94120-7775, or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +require_once(KT_LIB_DIR . "/actions/folderaction.inc.php");
  40 +require_once(KT_LIB_DIR . "/import/fsimportstorage.inc.php");
  41 +require_once(KT_LIB_DIR . "/import/bulkimport.inc.php");
  42 +require_once(KT_LIB_DIR . "/documentmanagement/observers.inc.php");
  43 +
  44 +
  45 +require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php");
  46 +require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php");
  47 +require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php");
  48 +
  49 +require_once(KT_LIB_DIR . "/validation/dispatchervalidation.inc.php");
  50 +
  51 +class InetBulkImportFolderMultiSelectAction extends KTFolderAction {
  52 + var $sName = 'inet.actions.folder.bulkImport.multiselect';
  53 +
  54 + var $_sShowPermission = "ktcore.permissions.write";
  55 + var $bAutomaticTransaction = false;
  56 +
  57 + /**
  58 + * hide existing url and return name to new url | iNET Process
  59 + * @Return string.
  60 + * @param.
  61 + */
  62 + function getDisplayName() {
  63 + if(!KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
  64 + {
  65 + $js = "<script src='plugins/multiselect/js/jquery-1.2.6.js' type='text/javascript'></script>";
  66 + $js .= "<script src='plugins/multiselect/js/hidelink.js' type='text/javascript'></script>";
  67 + return $js._kt('Import from Server Location');
  68 + }
  69 + else
  70 + {
  71 + return null;
  72 + }
  73 + }
  74 +
  75 + /**
  76 + * check for permissions | iNET Process
  77 + * @Return unknown.
  78 + * @param.
  79 + */
  80 + function getInfo() {
  81 + global $default;
  82 + if($default->disableBulkImport){
  83 + return null;
  84 + }
  85 +
  86 + if (!Permission::userIsSystemAdministrator($this->oUser->getId())) {
  87 + return null;
  88 +
  89 + }
  90 + return parent::getInfo();
  91 + }
  92 +
  93 + /**
  94 + * This is Default function to be called load template for import action. | iNET Process
  95 + * @Return template.
  96 + * @param.
  97 + */
  98 + function do_main() {
  99 + $this->oPage->setBreadcrumbDetails(_kt("bulk import"));
  100 + $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkImport');
  101 + $add_fields = array();
  102 + $add_fields[] = new KTStringWidget(_kt('Path'), _kt('The path containing the documents to be added to the document management system.'), 'path', "", $this->oPage, true);
  103 +
  104 + $aVocab = array('' => _kt('- Please select a document type -'));
  105 + foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) {
  106 + if(!$oDocumentType->getDisabled()) {
  107 + $aVocab[$oDocumentType->getId()] = $oDocumentType->getName();
  108 + }
  109 + }
  110 +
  111 + $fieldOptions = array("vocab" => $aVocab);
  112 + $add_fields[] = new KTLookupWidget(_kt('Document Type'), _kt('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'), 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions);
  113 +
  114 + $fieldsets = array();
  115 + $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
  116 + $activesets = KTFieldset::getGenericFieldsets();
  117 + foreach ($activesets as $oFieldset) {
  118 + $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
  119 + array_push($fieldsets, new $displayClass($oFieldset));
  120 + }
  121 +
  122 + // Implement an electronic signature for accessing the admin section, it will appear every 10 minutes
  123 + global $default;
  124 + $iFolderId = $this->oFolder->getId();
  125 + if($default->enableESignatures){
  126 + $sUrl = KTPluginUtil::getPluginPath('electronic.signatures.plugin', true);
  127 + $heading = _kt('You are attempting to perform a bulk import');
  128 + $submit['type'] = 'button';
  129 + $submit['onclick'] = "javascript: showSignatureForm('{$sUrl}', '{$heading}', 'ktcore.transactions.bulk_import', 'bulk', 'bulk_import_form', 'submit', {$iFolderId});";
  130 + }else{
  131 + $submit['type'] = 'submit';
  132 + $submit['onclick'] = '';
  133 + }
  134 +
  135 + $oTemplate->setData(array(
  136 + 'context' => &$this,
  137 + 'submit' => $submit,
  138 + 'add_fields' => $add_fields,
  139 + 'generic_fieldsets' => $fieldsets,
  140 + ));
  141 + return $oTemplate->render();
  142 + }
  143 +
  144 + /**
  145 + * Performs actual import action. | iNET Process
  146 + * @Return.
  147 + * @param.
  148 + */
  149 + function do_import() {
  150 +
  151 + set_time_limit(0);
  152 +
  153 + $aErrorOptions = array(
  154 + 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
  155 + );
  156 +
  157 + $aErrorOptions['message'] = _kt('Invalid document type provided');
  158 + $oDocumentType = $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId'], $aErrorOptions);
  159 +
  160 + $aErrorOptions['message'] = _kt('Invalid path provided');
  161 + $sPath = $this->oValidator->validateString($_REQUEST['path'], $aErrorOptions);
  162 +
  163 + $matches = array();
  164 + $aFields = array();
  165 + foreach ($_REQUEST as $k => $v) {
  166 + if (preg_match('/^metadata_(\d+)$/', $k, $matches)) {
  167 +
  168 + // multiselect change start
  169 + $oDocField = DocumentField::get($matches[1]);
  170 + if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v))
  171 + {
  172 + $v = join(", ", $v);
  173 + }
  174 + $aFields[] = array($oDocField, $v);
  175 +
  176 + // previously it was just one line which is commented, just above line
  177 + // multiselect change end
  178 + }
  179 + }
  180 +
  181 + $aOptions = array(
  182 + 'documenttype' => $oDocumentType,
  183 + 'metadata' => $aFields,
  184 + 'copy_upload' => 'true',
  185 + );
  186 +
  187 + $po =& new JavascriptObserver($this);
  188 + $po->start();
  189 + $oUploadChannel =& KTUploadChannel::getSingleton();
  190 + $oUploadChannel->addObserver($po);
  191 +
  192 + $fs =& new KTFSImportStorage($sPath);
  193 + $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
  194 + if(KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
  195 + {
  196 + require_once(KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php");
  197 + $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
  198 + }
  199 + else
  200 + {
  201 + $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
  202 + }
  203 + DBUtil::startTransaction();
  204 + $res = $bm->import();
  205 + if (PEAR::isError($res)) {
  206 + DBUtil::rollback();
  207 + $_SESSION["KTErrorMessage"][] = _kt("Bulk import failed") . ": " . $res->getMessage();
  208 + } else {
  209 + DBUtil::commit();
  210 + $this->addInfoMessage(_kt("Bulk import succeeded"));
  211 + }
  212 +
  213 + $po->redirectToFolder($this->oFolder->getId());
  214 + exit(0);
  215 + }
  216 +}
... ...
plugins/multiselect/BulkUpload.php
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * KnowledgeTree Community Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
8   - * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
10   - * This program is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU General Public License version 3 as published by the
12   - * Free Software Foundation.
13   - *
14   - * This program is distributed in the hope that it will be useful, but WITHOUT
15   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17   - * details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23   - * California 94120-7775, or email info@knowledgetree.com.
24   - *
25   - * The interactive user interfaces in modified source and object code versions
26   - * of this program must display Appropriate Legal Notices, as required under
27   - * Section 5 of the GNU General Public License version 3.
28   - *
29   - * In accordance with Section 7(b) of the GNU General Public License version 3,
30   - * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
35   - * Contributor( s): ______________________________________
36   - *
37   - */
38   -
39   -require_once(KT_LIB_DIR . "/actions/folderaction.inc.php");
40   -require_once(KT_LIB_DIR . "/import/zipimportstorage.inc.php");
41   -require_once(KT_LIB_DIR . "/import/bulkimport.inc.php");
42   -
43   -require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php");
44   -require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php");
45   -require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php");
46   -
47   -require_once(KT_LIB_DIR . "/validation/dispatchervalidation.inc.php");
48   -
49   -class InetBulkUploadFolderAction extends KTFolderAction {
50   - var $sName = 'inet.actions.folder.bulkUpload';
51   -
52   - var $_sShowPermission = "ktcore.permissions.write";
53   - var $bAutomaticTransaction = false;
54   - /**
55   - * returns the string
56   - * @return
57   - * loads the necessary javascripts too.
58   - *
59   - * iNET Process
60   - */
61   - function getDisplayName() {
62   - if(!KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
63   - {
64   - $js = "<script src='plugins/multiselect/js/jquery-1.2.6.js' type='text/javascript'></script>";
65   - $js .= "<script src='plugins/multiselect/js/hidelink.js' type='text/javascript'></script>";
66   - return $js._kt('Bulk Upload');
67   - }
68   - else
69   - {
70   - return null;
71   - }
72   - }
73   - /**
74   - * Checks for bulk uploads
75   - * @return
76   - *
77   - * iNET Process
78   - */
79   - function check() {
80   - $res = parent::check();
81   - if (empty($res)) {
82   - return $res;
83   - }
84   - $postExpected = KTUtil::arrayGet($_REQUEST, "postExpected");
85   - $postReceived = KTUtil::arrayGet($_REQUEST, "postReceived");
86   - if (!empty($postExpected)) {
87   - $aErrorOptions = array(
88   - 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
89   - 'message' => _kt('Upload larger than maximum POST size (post_max_size variable in .htaccess or php.ini)'),
90   - );
91   - $this->oValidator->notEmpty($postReceived, $aErrorOptions);
92   - }
93   - return true;
94   - }
95   - /**
96   - * default and basic function
97   - * @return template
98   - * @param.
99   - * iNET Process
100   - */
101   - function do_main() {
102   - $this->oPage->setBreadcrumbDetails(_kt("bulk upload"));
103   - $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkUpload');
104   - $add_fields = array();
105   - $add_fields[] = new KTFileUploadWidget(_kt('Archive file'), _kt('The archive file containing the documents you wish to add to the document management system.'), 'file', "", $this->oPage, true, "file");
106   -
107   - $aVocab = array('' => _kt('- Please select a document type -'));
108   - foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) {
109   - if(!$oDocumentType->getDisabled()) {
110   - $aVocab[$oDocumentType->getId()] = $oDocumentType->getName();
111   - }
112   - }
113   - $fieldOptions = array("vocab" => $aVocab);
114   - $add_fields[] = new KTLookupWidget(_kt('Document Type'), _kt('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'), 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions);
115   -
116   - $fieldsets = array();
117   - $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
118   - $activesets = KTFieldset::getGenericFieldsets();
119   - foreach ($activesets as $oFieldset) {
120   - $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
121   - array_push($fieldsets, new $displayClass($oFieldset));
122   - }
123   -
124   - $oTemplate->setData(array(
125   - 'context' => &$this,
126   - 'add_fields' => $add_fields,
127   - 'generic_fieldsets' => $fieldsets,
128   - ));
129   - return $oTemplate->render();
130   - }
131   - /**
132   - * make uploads
133   - * @return
134   - *
135   - * iNET Process
136   - */
137   - function do_upload() {
138   - set_time_limit(0);
139   - $aErrorOptions = array(
140   - 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
141   - );
142   -
143   - $aErrorOptions['message'] = _kt('Invalid document type provided');
144   - $oDocumentType = $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId'], $aErrorOptions);
145   -
146   - unset($aErrorOptions['message']);
147   - $aFile = $this->oValidator->validateFile($_FILES['file'], $aErrorOptions);
148   -
149   - $matches = array();
150   - $aFields = array();
151   - foreach ($_REQUEST as $k => $v) {
152   - if (preg_match('/^metadata_(\d+)$/', $k, $matches)) {
153   - // multiselect change start
154   - $oDocField = DocumentField::get($matches[1]);
155   - if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v))
156   - {
157   - $v = join(", ", $v);
158   - }
159   - $aFields[] = array($oDocField, $v);
160   -
161   - // previously it was just one line which is commented, just above line
162   - // multiselect change end
163   - }
164   - }
165   -
166   - $aOptions = array(
167   - 'documenttype' => $oDocumentType,
168   - 'metadata' => $aFields,
169   - );
170   -
171   - $fs =& new KTZipImportStorage('file');
172   - if(!$fs->CheckFormat()){
173   - $sFormats = $fs->getFormats();
174   - $this->addErrorMessage(_kt("Bulk Upload failed. Archive is not an accepted format. Accepted formats are: ".$sFormats));
175   - controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID());
176   - exit;
177   - }
178   -
179   - if(KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
180   - {
181   - require_once(KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php");
182   - $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
183   - }
184   - else
185   - {
186   - $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
187   - }
188   -
189   - $this->startTransaction();
190   - $res = $bm->import();
191   -
192   - $aErrorOptions['message'] = _kt("Bulk Upload failed");
193   - $this->oValidator->notError($res, $aErrorOptions);
194   -
195   - $this->addInfoMessage(_kt("Bulk Upload successful"));
196   - $this->commitTransaction();
197   - controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID());
198   - exit(0);
199   - }
200   -}
201   -?>
202 1 \ No newline at end of file
  2 +<?php
  3 +/**
  4 + * $Id$
  5 + *
  6 + * KnowledgeTree Community Edition
  7 + * Document Management Made Simple
  8 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  9 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  10 + *
  11 + * This program is free software; you can redistribute it and/or modify it under
  12 + * the terms of the GNU General Public License version 3 as published by the
  13 + * Free Software Foundation.
  14 + *
  15 + * This program is distributed in the hope that it will be useful, but WITHOUT
  16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  18 + * details.
  19 + *
  20 + * You should have received a copy of the GNU General Public License
  21 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22 + *
  23 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  24 + * California 94120-7775, or email info@knowledgetree.com.
  25 + *
  26 + * The interactive user interfaces in modified source and object code versions
  27 + * of this program must display Appropriate Legal Notices, as required under
  28 + * Section 5 of the GNU General Public License version 3.
  29 + *
  30 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  31 + * these Appropriate Legal Notices must retain the display of the "Powered by
  32 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  33 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  34 + * must display the words "Powered by KnowledgeTree" and retain the original
  35 + * copyright notice.
  36 + * Contributor( s): ______________________________________
  37 + *
  38 + */
  39 +
  40 +require_once(KT_LIB_DIR . "/actions/folderaction.inc.php");
  41 +require_once(KT_LIB_DIR . "/import/zipimportstorage.inc.php");
  42 +require_once(KT_LIB_DIR . "/import/bulkimport.inc.php");
  43 +
  44 +require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php");
  45 +require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php");
  46 +require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php");
  47 +
  48 +require_once(KT_LIB_DIR . "/validation/dispatchervalidation.inc.php");
  49 +
  50 +class InetBulkUploadFolderAction extends KTFolderAction {
  51 + var $sName = 'inet.actions.folder.bulkUpload';
  52 +
  53 + var $_sShowPermission = "ktcore.permissions.write";
  54 + var $bAutomaticTransaction = false;
  55 + /**
  56 + * returns the string
  57 + * @return
  58 + * loads the necessary javascripts too.
  59 + *
  60 + * iNET Process
  61 + */
  62 + function getDisplayName() {
  63 + if(!KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
  64 + {
  65 + $js = "<script src='plugins/multiselect/js/jquery-1.2.6.js' type='text/javascript'></script>";
  66 + $js .= "<script src='plugins/multiselect/js/hidelink.js' type='text/javascript'></script>";
  67 + return $js._kt('Bulk Upload');
  68 + }
  69 + else
  70 + {
  71 + return null;
  72 + }
  73 + }
  74 + /**
  75 + * Checks for bulk uploads
  76 + * @return
  77 + *
  78 + * iNET Process
  79 + */
  80 + function check() {
  81 + $res = parent::check();
  82 + if (empty($res)) {
  83 + return $res;
  84 + }
  85 + $postExpected = KTUtil::arrayGet($_REQUEST, "postExpected");
  86 + $postReceived = KTUtil::arrayGet($_REQUEST, "postReceived");
  87 + if (!empty($postExpected)) {
  88 + $aErrorOptions = array(
  89 + 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
  90 + 'message' => _kt('Upload larger than maximum POST size (post_max_size variable in .htaccess or php.ini)'),
  91 + );
  92 + $this->oValidator->notEmpty($postReceived, $aErrorOptions);
  93 + }
  94 + return true;
  95 + }
  96 + /**
  97 + * default and basic function
  98 + * @return template
  99 + * @param.
  100 + * iNET Process
  101 + */
  102 + function do_main() {
  103 + $this->oPage->setBreadcrumbDetails(_kt("bulk upload"));
  104 + $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkUpload');
  105 + $add_fields = array();
  106 + $add_fields[] = new KTFileUploadWidget(_kt('Archive file'), _kt('The archive file containing the documents you wish to add to the document management system.'), 'file', "", $this->oPage, true, "file");
  107 +
  108 + $aVocab = array('' => _kt('- Please select a document type -'));
  109 + foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) {
  110 + if(!$oDocumentType->getDisabled()) {
  111 + $aVocab[$oDocumentType->getId()] = $oDocumentType->getName();
  112 + }
  113 + }
  114 + $fieldOptions = array("vocab" => $aVocab);
  115 + $add_fields[] = new KTLookupWidget(_kt('Document Type'), _kt('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'), 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions);
  116 +
  117 + $fieldsets = array();
  118 + $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
  119 + $activesets = KTFieldset::getGenericFieldsets();
  120 + foreach ($activesets as $oFieldset) {
  121 + $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
  122 + array_push($fieldsets, new $displayClass($oFieldset));
  123 + }
  124 +
  125 + // Implement an electronic signature for accessing the admin section, it will appear every 10 minutes
  126 + global $default;
  127 + $iFolderId = $this->oFolder->getId();
  128 + if($default->enableESignatures){
  129 + $sUrl = KTPluginUtil::getPluginPath('electronic.signatures.plugin', true);
  130 + $heading = _kt('You are attempting to perform a bulk upload');
  131 + $submit['type'] = 'button';
  132 + $submit['onclick'] = "javascript: showSignatureForm('{$sUrl}', '{$heading}', 'ktcore.transactions.bulk_upload', 'bulk', 'bulk_upload_form', 'submit', {$iFolderId});";
  133 + }else{
  134 + $submit['type'] = 'submit';
  135 + $submit['onclick'] = '';
  136 + }
  137 +
  138 + $oTemplate->setData(array(
  139 + 'context' => &$this,
  140 + 'submit' => $submit,
  141 + 'add_fields' => $add_fields,
  142 + 'generic_fieldsets' => $fieldsets,
  143 + ));
  144 + return $oTemplate->render();
  145 + }
  146 + /**
  147 + * make uploads
  148 + * @return
  149 + *
  150 + * iNET Process
  151 + */
  152 + function do_upload() {
  153 + set_time_limit(0);
  154 + $aErrorOptions = array(
  155 + 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
  156 + );
  157 +
  158 + $aErrorOptions['message'] = _kt('Invalid document type provided');
  159 + $oDocumentType = $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId'], $aErrorOptions);
  160 +
  161 + unset($aErrorOptions['message']);
  162 + $aFile = $this->oValidator->validateFile($_FILES['file'], $aErrorOptions);
  163 +
  164 + $matches = array();
  165 + $aFields = array();
  166 + foreach ($_REQUEST as $k => $v) {
  167 + if (preg_match('/^metadata_(\d+)$/', $k, $matches)) {
  168 + // multiselect change start
  169 + $oDocField = DocumentField::get($matches[1]);
  170 + if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v))
  171 + {
  172 + $v = join(", ", $v);
  173 + }
  174 + $aFields[] = array($oDocField, $v);
  175 +
  176 + // previously it was just one line which is commented, just above line
  177 + // multiselect change end
  178 + }
  179 + }
  180 +
  181 + $aOptions = array(
  182 + 'documenttype' => $oDocumentType,
  183 + 'metadata' => $aFields,
  184 + );
  185 +
  186 + $fs =& new KTZipImportStorage('file');
  187 + if(!$fs->CheckFormat()){
  188 + $sFormats = $fs->getFormats();
  189 + $this->addErrorMessage(_kt("Bulk Upload failed. Archive is not an accepted format. Accepted formats are: ".$sFormats));
  190 + controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID());
  191 + exit;
  192 + }
  193 +
  194 + if(KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin'))
  195 + {
  196 + require_once(KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php");
  197 + $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
  198 + }
  199 + else
  200 + {
  201 + $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
  202 + }
  203 +
  204 + $this->startTransaction();
  205 + $res = $bm->import();
  206 +
  207 + $aErrorOptions['message'] = _kt("Bulk Upload failed");
  208 + $this->oValidator->notError($res, $aErrorOptions);
  209 +
  210 + $this->addInfoMessage(_kt("Bulk Upload successful"));
  211 + $this->commitTransaction();
  212 + controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID());
  213 + exit(0);
  214 + }
  215 +}
  216 +?>
... ...
plugins/multiselect/addDocument.php
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * KnowledgeTree Community Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
8   - * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
10   - * This program is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU General Public License version 3 as published by the
12   - * Free Software Foundation.
13   - *
14   - * This program is distributed in the hope that it will be useful, but WITHOUT
15   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17   - * details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23   - * California 94120-7775, or email info@knowledgetree.com.
24   - *
25   - * The interactive user interfaces in modified source and object code versions
26   - * of this program must display Appropriate Legal Notices, as required under
27   - * Section 5 of the GNU General Public License version 3.
28   - *
29   - * In accordance with Section 7(b) of the GNU General Public License version 3,
30   - * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
35   - * Contributor( s): ______________________________________
36   - *
37   - */
38   -
39   -/* The file adds a document with multiselect fields.The main code for fetching multiselect
40   - * fields is written in this file.
41   - */
42   -
43   -require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
44   -require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php");
45   -require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php");
46   -require_once(KT_LIB_DIR . "/foldermanagement/folderutil.inc.php");
47   -require_once(KT_LIB_DIR . "/documentmanagement/observers.inc.php");
48   -require_once(KT_LIB_DIR . "/documentmanagement/documentutil.inc.php");
49   -require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php");
50   -require_once(KT_LIB_DIR . "/util/sanitize.inc");
51   -
52   -class MultiDocumentAddAction extends KTFolderAction {
53   - var $sName = 'inet.multiselect.actions.document.addDocument';
54   - var $_sShowPermission = "ktcore.permissions.write";
55   - var $oDocumentType = null;
56   -
57   - /**
58   - * returns a display name 'Add Document'
59   - * @return
60   - *
61   - * iNET Process
62   - */
63   - function getDisplayName() {
64   - return _kt('Add Document');
65   - }
66   -
67   - /**
68   - * get the button
69   - * @return
70   - *
71   - * iNET Process
72   - */
73   - function getButton(){
74   - $btn = array();
75   - $btn['display_text'] = _kt('Upload Document');
76   - $btn['arrow_class'] = 'arrow_upload';
77   - return $btn;
78   - }
79   - /**
80   - * check if document can be added or not
81   - * @return
82   - *
83   - * iNET Process
84   - */
85   - function check() {
86   - $res = parent::check();
87   - if (empty($res)) {
88   - return $res;
89   - }
90   -
91   - $postExpected = KTUtil::arrayGet($_REQUEST, "postExpected");
92   - $postReceived = KTUtil::arrayGet($_REQUEST, "postReceived");
93   - if (!empty($postExpected)) {
94   - $aErrorOptions = array(
95   - 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
96   - 'message' => _kt('Upload larger than maximum POST size (post_max_size variable in .htaccess or php.ini)'),
97   - );
98   - $this->oValidator->notEmpty($postReceived, $aErrorOptions);
99   - }
100   - return true;
101   - }
102   - /**
103   - * Initializes for data
104   - * @return
105   - *
106   - * iNET Process
107   - */
108   - function form_initialdata() {
109   - $oForm = new KTForm;
110   -
111   - $oForm->setOptions(array(
112   - 'label' => _kt("Add a document"),
113   - 'action' => 'processInitialData',
114   - 'actionparams' => 'postExpected=1&fFolderId='.$this->oFolder->getId(),
115   - 'fail_action' => 'main',
116   - 'context' => &$this,
117   - 'extraargs' => $this->meldPersistQuery("","",true),
118   - 'submit_label' => _kt("Add"),
119   - 'file_upload' => true,
120   - ));
121   -
122   - $aTypes;
123   - foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) {
124   - if(!$oDocumentType->getDisabled()) {
125   - $aTypes[] = $oDocumentType;
126   - }
127   - }
128   -
129   - // Onchange gets the name of the file and inserts it as the document title.
130   - $sFileOnchange = "javascript:
131   - var doc = document.getElementById('document_name');
132   - if(doc.value == ''){
133   - var arrPath=this.value.split('/');
134   - if(arrPath.length == 1){
135   - var arrPath=this.value.split('\\\');
136   - }
137   - var name=arrPath[arrPath.length-1];
138   - var name=name.split('.');
139   - var len = name.length;
140   - if(len > 1){
141   - if(name[len-1].length <= 4){
142   - name.pop();
143   - }
144   - }
145   - var title=name.join('.');
146   - doc.value=title;
147   - }";
148   -
149   - $oForm->setWidgets(array(
150   - array('ktcore.widgets.file',array(
151   - 'label' => _kt('File'),
152   - 'description' => _kt('The contents of the document to be added to the document management system.'),
153   - 'name' => 'file',
154   - 'required' => true,
155   - 'onchange' => $sFileOnchange,
156   - )),
157   - array('ktcore.widgets.string',array(
158   - 'label' => _kt('Document Title'),
159   - 'description' => sprintf(_kt('The document title is used as the main name of a document throughout %s.'), APP_NAME),
160   - 'name' => 'document_name',
161   - 'required' => true,
162   - 'id' => 'document_name',
163   - )),
164   - array('ktcore.widgets.entityselection',array(
165   - 'label' => _kt('Document Type'),
166   - 'description' => _kt('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'),
167   - 'name' => 'document_type',
168   - 'required' => true,
169   - 'vocab' => $aTypes,
170   - 'initial_string' => _kt('- Please select a document type -'),
171   - 'id_method' => 'getId',
172   - 'label_method' => 'getName',
173   - 'simple_select' => false,
174   - )),
175   - ));
176   -
177   - $oForm->setValidators(array(
178   - array('ktcore.validators.file', array(
179   - 'test' => 'file',
180   - 'output' => 'file',
181   - )),
182   - array('ktcore.validators.fileillegalchar', array(
183   - 'test' => 'file',
184   - 'output' => 'file',
185   - )),
186   - array('ktcore.validators.string', array(
187   - 'test' => 'document_name',
188   - 'output' => 'document_name',
189   - )),
190   - array('ktcore.validators.entity', array(
191   - 'test' => 'document_type',
192   - 'output' => 'document_type',
193   - 'class' => 'DocumentType',
194   - 'ids' => true,
195   - )),
196   - ));
197   -
198   - return $oForm;
199   - }
200   - /**
201   - * Get the fieldsets for a particular document type
202   - * @return array
203   - * @param $iTypeId Object
204   - *
205   - * iNET Process
206   - */
207   - function getFieldsetsForType($iTypeId) {
208   - $typeid = KTUtil::getId($iTypeId);
209   - $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
210   - $aSpecificFieldsetIds = KTFieldset::getForDocumentType($typeid, array('ids' => false));
211   -
212   - $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
213   - return $fieldsets;
214   - }
215   - /**
216   - * Main default function
217   - * @param
218   - * @return form
219   - * iNET Process
220   - */
221   - function do_main() {
222   - $this->oPage->setBreadcrumbDetails(_kt("Add a document"));
223   - $oForm = $this->form_initialdata();
224   - return $oForm->renderPage(_kt('Add a document to: ') . $this->oFolder->getName());
225   - }
226   - /**
227   - * Checks for validations and errors
228   - * @return
229   - *
230   - * iNET Process
231   - */
232   - function do_processInitialData() {
233   - $oForm = $this->form_initialdata();
234   - $res = $oForm->validate();
235   - if (!empty($res['errors'])) {
236   - if(!isset($res['errors']['file'])){
237   - $aError['file'] = array(_kt('Please reselect the file to upload.'));
238   - }
239   - return $oForm->handleError('', $aError);
240   - }
241   - $data = $res['results'];
242   - $key = KTUtil::randomString(32);
243   -
244   -
245   - // joy joy, we need to store the file first, or PHP will (helpfully)
246   - // clean it up for us
247   -
248   - $oKTConfig =& KTConfig::getSingleton();
249   - $sBasedir = $oKTConfig->get("urls/tmpDirectory");
250   -
251   - $sFilename = tempnam($sBasedir, 'kt_storecontents');
252   -
253   - $oStorage =& KTStorageManagerUtil::getSingleton();
254   - $oStorage->uploadTmpFile($data['file']['tmp_name'], $sFilename);
255   -
256   - $data['file']['tmp_name'] = $sFilename;
257   - $_SESSION['_add_data'] = array($key => $data);
258   -
259   - // if we don't need metadata
260   - $fieldsets = $this->getFieldsetsForType($data['document_type']);
261   - if (empty($fieldsets)) {
262   - return $this->successRedirectTo('finalise', _kt("File uploaded successfully. Processing."), sprintf("fFileKey=%s", $key));
263   - }
264   -
265   - // if we need metadata
266   -
267   - $this->successRedirectTo('metadata', _kt("File uploaded successfully. Please fill in the metadata below."), sprintf("fFileKey=%s", $key));
268   - }
269   - /**
270   - * get the metadata
271   - * @return form
272   - * @param $sess_key Object
273   - *
274   - * iNET Process
275   - */
276   - function form_metadata($sess_key) {
277   - $oForm = new KTForm;
278   - $oForm->setOptions(array(
279   - 'identifier' => 'ktcore.document.add',
280   - 'label' => _kt('Specify Metadata'),
281   - 'submit_label' => _kt('Save Document'),
282   - 'action' => 'finalise',
283   - 'fail_action' => 'metadata',
284   - 'context' => &$this,
285   - 'extraargs' => $this->meldPersistQuery("","",true),
286   - ));
287   -
288   - $oFReg =& KTFieldsetRegistry::getSingleton();
289   -
290   - $doctypeid = $_SESSION['_add_data'][$sess_key]['document_type'];
291   -
292   - $widgets = array();
293   - $validators = array();
294   - $fieldsets = $this->getFieldsetsForType($doctypeid);
295   -
296   - foreach ($fieldsets as $oFieldset) {
297   - $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument));
298   - $validators = kt_array_merge($validators, $oFReg->validatorsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument));
299   - }
300   -
301   - $oForm->setWidgets($widgets);
302   - $oForm->setValidators($validators);
303   -
304   - return $oForm;
305   - }
306   - /**
307   - * render metadata for a document
308   - * @return form
309   - *
310   - * iNET Process
311   - */
312   - function do_metadata() {
313   - $this->persistParams(array('fFileKey'));
314   -
315   - $oForm = $this->form_metadata($_REQUEST['fFileKey']);
316   - return $oForm->render();
317   - }
318   - /**
319   - * finally adds a document
320   - * @return.
321   - *
322   - * iNET Process
323   - */
324   - function do_finalise() {
325   - $this->persistParams(array('fFileKey'));
326   - $sess_key = $_REQUEST['fFileKey'];
327   - $oForm = $this->form_metadata($sess_key);
328   - $res = $oForm->validate();
329   - if (!empty($res['errors'])) {
330   - return $oForm->handleError();
331   - }
332   - $data = $res['results'];
333   -
334   - $extra_d = $_SESSION['_add_data'][$sess_key];
335   - $doctypeid = $extra_d['document_type'];
336   - $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
337   - $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false));
338   - $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
339   -
340   -
341   - $MDPack = array();
342   - foreach ($fieldsets as $oFieldset) {
343   - $fields = $oFieldset->getFields();
344   - $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId());
345   -
346   - foreach ($fields as $oField) {
347   - $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId());
348   - if ($oFieldset->getIsConditional())
349   - {
350   - if ($val == _kt('No selection.'))
351   - {
352   - $val = null;
353   - }
354   - }
355   - // ALT.METADATA.LAYER.DIE.DIE.DIE
356   - if (!is_null($val)) {
357   - // multiselect change start
358   - if(is_array($val) && $oField->getHasInetLookup())
359   - {
360   - $val = join(", ",$val);
361   - }
362   - // multiselect change end
363   - $MDPack[] = array(
364   - $oField,
365   - $val
366   - );
367   - }
368   -
369   - }
370   - }
371   - // older code
372   -
373   - $mpo =& new JavascriptObserver($this);
374   - $oUploadChannel =& KTUploadChannel::getSingleton();
375   - $oUploadChannel->addObserver($mpo);
376   -
377   - require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php');
378   - require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc');
379   - require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
380   - require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php');
381   -
382   - $aErrorOptions = array(
383   - 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
384   - 'max_str_len' => 200,
385   - );
386   -
387   - $aFile = $this->oValidator->validateFile($extra_d['file'], $aErrorOptions);
388   - $sTitle = $extra_d['document_name'];
389   -
390   - $iFolderId = $this->oFolder->getId();
391   - $aOptions = array(
392   - 'temp_file' => $aFile['tmp_name'],
393   - 'documenttype' => DocumentType::get($extra_d['document_type']),
394   - 'metadata' => $MDPack,
395   - 'description' => $sTitle,
396   - 'cleanup_initial_file' => true,
397   - );
398   -
399   - $mpo->start();
400   - $oDocument =& KTDocumentUtil::add($this->oFolder, $aFile['name'], $this->oUser, $aOptions);
401   - if (PEAR::isError($oDocument)) {
402   - $message = $oDocument->getMessage();
403   - $this->errorRedirectTo('main',sprintf(_kt("Unexpected failure to add document - %s"), $message), 'fFolderId=' . $this->oFolder->getId());
404   - exit(0);
405   - }
406   - $this->addInfoMessage(_kt("Document added"));
407   -
408   - $mpo->redirectToDocument($oDocument->getId());
409   - exit(0);
410   -
411   - }
412   -
413   -}
414   -
415   -?>
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * KnowledgeTree Community Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  8 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + * California 94120-7775, or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +/* The file adds a document with multiselect fields.The main code for fetching multiselect
  40 + * fields is written in this file.
  41 + */
  42 +
  43 +require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
  44 +require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php");
  45 +require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php");
  46 +require_once(KT_LIB_DIR . "/foldermanagement/folderutil.inc.php");
  47 +require_once(KT_LIB_DIR . "/documentmanagement/observers.inc.php");
  48 +require_once(KT_LIB_DIR . "/documentmanagement/documentutil.inc.php");
  49 +require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php");
  50 +require_once(KT_LIB_DIR . "/util/sanitize.inc");
  51 +
  52 +class MultiDocumentAddAction extends KTFolderAction {
  53 + var $sName = 'inet.multiselect.actions.document.addDocument';
  54 + var $_sShowPermission = "ktcore.permissions.write";
  55 + var $oDocumentType = null;
  56 +
  57 + /**
  58 + * returns a display name 'Add Document'
  59 + * @return
  60 + *
  61 + * iNET Process
  62 + */
  63 + function getDisplayName() {
  64 + return _kt('Add Document');
  65 + }
  66 +
  67 + /**
  68 + * get the button
  69 + * @return
  70 + *
  71 + * iNET Process
  72 + */
  73 + function getButton(){
  74 + $btn = array();
  75 + $btn['display_text'] = _kt('Upload Document');
  76 + $btn['arrow_class'] = 'arrow_upload';
  77 + return $btn;
  78 + }
  79 + /**
  80 + * check if document can be added or not
  81 + * @return
  82 + *
  83 + * iNET Process
  84 + */
  85 + function check() {
  86 + $res = parent::check();
  87 + if (empty($res)) {
  88 + return $res;
  89 + }
  90 +
  91 + $postExpected = KTUtil::arrayGet($_REQUEST, "postExpected");
  92 + $postReceived = KTUtil::arrayGet($_REQUEST, "postReceived");
  93 + if (!empty($postExpected)) {
  94 + $aErrorOptions = array(
  95 + 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
  96 + 'message' => _kt('Upload larger than maximum POST size (post_max_size variable in .htaccess or php.ini)'),
  97 + );
  98 + $this->oValidator->notEmpty($postReceived, $aErrorOptions);
  99 + }
  100 + return true;
  101 + }
  102 + /**
  103 + * Initializes for data
  104 + * @return
  105 + *
  106 + * iNET Process
  107 + */
  108 + function form_initialdata() {
  109 + $oForm = new KTForm;
  110 +
  111 + $oForm->setOptions(array(
  112 + 'label' => _kt("Add a document"),
  113 + 'action' => 'processInitialData',
  114 + 'actionparams' => 'postExpected=1&fFolderId='.$this->oFolder->getId(),
  115 + // 'cancel_action' => KTBrowseUtil::getUrlForFolder($this->oFolder),
  116 + 'fail_action' => 'main',
  117 + 'context' => &$this,
  118 + 'extraargs' => $this->meldPersistQuery("","",true),
  119 + 'submit_label' => _kt("Add"),
  120 + 'file_upload' => true,
  121 + ));
  122 +
  123 + $aTypes = array();
  124 + foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) {
  125 + if(!$oDocumentType->getDisabled()) {
  126 + $aTypes[] = $oDocumentType;
  127 + }
  128 + }
  129 +
  130 + // Onchange gets the name of the file and inserts it as the document title.
  131 + $sFileOnchange = "javascript:
  132 + var doc = document.getElementById('document_name');
  133 + if(doc.value == ''){
  134 + var arrPath=this.value.split('/');
  135 + if(arrPath.length == 1){
  136 + var arrPath=this.value.split('\\\');
  137 + }
  138 + var name=arrPath[arrPath.length-1];
  139 + var name=name.split('.');
  140 + var len = name.length;
  141 + if(len > 1){
  142 + if(name[len-1].length <= 4){
  143 + name.pop();
  144 + }
  145 + }
  146 + var title=name.join('.');
  147 + doc.value=title;
  148 + }";
  149 +
  150 + $oForm->setWidgets(array(
  151 + array('ktcore.widgets.file',array(
  152 + 'label' => _kt('File'),
  153 + 'description' => _kt('The contents of the document to be added to the document management system.'),
  154 + 'name' => 'file',
  155 + 'required' => true,
  156 + 'onchange' => $sFileOnchange,
  157 + )),
  158 + array('ktcore.widgets.string',array(
  159 + 'label' => _kt('Document Title'),
  160 + 'description' => sprintf(_kt('The document title is used as the main name of a document throughout %s.'), APP_NAME),
  161 + 'name' => 'document_name',
  162 + 'required' => true,
  163 + 'id' => 'document_name',
  164 + )),
  165 + array('ktcore.widgets.entityselection',array(
  166 + 'label' => _kt('Document Type'),
  167 + 'description' => _kt('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'),
  168 + 'name' => 'document_type',
  169 + 'required' => true,
  170 + 'vocab' => $aTypes,
  171 + 'initial_string' => _kt('- Please select a document type -'),
  172 + 'id_method' => 'getId',
  173 + 'label_method' => 'getName',
  174 + 'simple_select' => false,
  175 + )),
  176 + ));
  177 +
  178 + // Electronic Signature if enabled
  179 + global $default;
  180 + if($default->enableESignatures){
  181 + $oForm->addWidget(array('ktcore.widgets.info', array(
  182 + 'label' => _kt('This action requires authentication'),
  183 + 'description' => _kt('Please provide your user credentials as confirmation of this action.'),
  184 + 'name' => 'info'
  185 + )));
  186 + $oForm->addWidget(array('ktcore.widgets.string', array(
  187 + 'label' => _kt('Username'),
  188 + 'name' => 'sign_username',
  189 + 'required' => true
  190 + )));
  191 + $oForm->addWidget(array('ktcore.widgets.password', array(
  192 + 'label' => _kt('Password'),
  193 + 'name' => 'sign_password',
  194 + 'required' => true
  195 + )));
  196 + $oForm->addWidget(array('ktcore.widgets.reason', array(
  197 + 'label' => _kt('Reason'),
  198 + 'description' => _kt('Please specify why you are checking out this document. It will assist other users in understanding why you have locked this file. Please bear in mind that you can use a maximum of <strong>250</strong> characters.'),
  199 + 'name' => 'reason',
  200 + )));
  201 + }
  202 +
  203 + $oForm->setValidators(array(
  204 + array('ktcore.validators.file', array(
  205 + 'test' => 'file',
  206 + 'output' => 'file',
  207 + )),
  208 + array('ktcore.validators.fileillegalchar', array(
  209 + 'test' => 'file',
  210 + 'output' => 'file',
  211 + )),
  212 + array('ktcore.validators.string', array(
  213 + 'test' => 'document_name',
  214 + 'output' => 'document_name',
  215 + )),
  216 + array('ktcore.validators.entity', array(
  217 + 'test' => 'document_type',
  218 + 'output' => 'document_type',
  219 + 'class' => 'DocumentType',
  220 + 'ids' => true,
  221 + )),
  222 + ));
  223 +
  224 + if($default->enableESignatures){
  225 + $oForm->addValidator(array('electonic.signatures.validators.authenticate', array(
  226 + 'object_id' => $this->oFolder->getId(),
  227 + 'type' => 'folder',
  228 + 'action' => 'ktcore.transactions.add_document',
  229 + 'test' => 'info',
  230 + 'output' => 'info'
  231 + )));
  232 + }
  233 +
  234 + return $oForm;
  235 + }
  236 + /**
  237 + * Get the fieldsets for a particular document type
  238 + * @return array
  239 + * @param $iTypeId Object
  240 + *
  241 + * iNET Process
  242 + */
  243 + function getFieldsetsForType($iTypeId) {
  244 + $typeid = KTUtil::getId($iTypeId);
  245 + $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
  246 + $aSpecificFieldsetIds = KTFieldset::getForDocumentType($typeid, array('ids' => false));
  247 +
  248 + $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
  249 + return $fieldsets;
  250 + }
  251 + /**
  252 + * Main default function
  253 + * @param
  254 + * @return form
  255 + * iNET Process
  256 + */
  257 + function do_main() {
  258 + $this->oPage->setBreadcrumbDetails(_kt("Add a document"));
  259 + $oForm = $this->form_initialdata();
  260 + return $oForm->renderPage(_kt('Add a document to: ') . $this->oFolder->getName());
  261 + }
  262 + /**
  263 + * Checks for validations and errors
  264 + * @return
  265 + *
  266 + * iNET Process
  267 + */
  268 + function do_processInitialData() {
  269 + $oForm = $this->form_initialdata();
  270 + $res = $oForm->validate();
  271 + if (!empty($res['errors'])) {
  272 + if(!isset($res['errors']['file'])){
  273 + $aError['file'] = array(_kt('Please reselect the file to upload.'));
  274 + }
  275 + return $oForm->handleError('', $aError);
  276 + }
  277 + $data = $res['results'];
  278 + $key = KTUtil::randomString(32);
  279 +
  280 +
  281 + // joy joy, we need to store the file first, or PHP will (helpfully)
  282 + // clean it up for us
  283 +
  284 + $oKTConfig =& KTConfig::getSingleton();
  285 + $sBasedir = $oKTConfig->get("urls/tmpDirectory");
  286 +
  287 + $sFilename = tempnam($sBasedir, 'kt_storecontents');
  288 +
  289 + //$oContents = new KTFSFileLike($data['file']['tmp_name']);
  290 + //$oOutputFile = new KTFSFileLike($sFilename);
  291 + //$res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile);
  292 +
  293 + //if (PEAR::isError($res)) {
  294 + // $oForm->handleError(sprintf(_kt("Failed to store file: %s"), $res->getMessage()));
  295 + //}
  296 +
  297 +
  298 + $oStorage =& KTStorageManagerUtil::getSingleton();
  299 + $oStorage->uploadTmpFile($data['file']['tmp_name'], $sFilename);
  300 +
  301 + $data['file']['tmp_name'] = $sFilename;
  302 + $_SESSION['_add_data'] = array($key => $data);
  303 +
  304 + // if we don't need metadata
  305 + $fieldsets = $this->getFieldsetsForType($data['document_type']);
  306 + if (empty($fieldsets)) {
  307 + return $this->successRedirectTo('finalise', _kt("File uploaded successfully. Processing."), sprintf("fFileKey=%s", $key));
  308 + }
  309 +
  310 + // if we need metadata
  311 +
  312 + $this->successRedirectTo('metadata', _kt("File uploaded successfully. Please fill in the metadata below."), sprintf("fFileKey=%s", $key));
  313 + }
  314 + /**
  315 + * get the metadata
  316 + * @return form
  317 + * @param $sess_key Object
  318 + *
  319 + * iNET Process
  320 + */
  321 + function form_metadata($sess_key) {
  322 + $oForm = new KTForm;
  323 + $oForm->setOptions(array(
  324 + 'identifier' => 'ktcore.document.add',
  325 + 'label' => _kt('Specify Metadata'),
  326 + 'submit_label' => _kt('Save Document'),
  327 + 'action' => 'finalise',
  328 + 'fail_action' => 'metadata',
  329 + // 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
  330 + 'context' => &$this,
  331 + 'extraargs' => $this->meldPersistQuery("","",true),
  332 + ));
  333 +
  334 + $oFReg =& KTFieldsetRegistry::getSingleton();
  335 +
  336 + $doctypeid = $_SESSION['_add_data'][$sess_key]['document_type'];
  337 +
  338 + $widgets = array();
  339 + $validators = array();
  340 + $fieldsets = $this->getFieldsetsForType($doctypeid);
  341 +
  342 + foreach ($fieldsets as $oFieldset) {
  343 + $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument));
  344 + $validators = kt_array_merge($validators, $oFReg->validatorsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument));
  345 + }
  346 +
  347 + $oForm->setWidgets($widgets);
  348 + $oForm->setValidators($validators);
  349 +
  350 + return $oForm;
  351 + }
  352 + /**
  353 + * render metadata for a document
  354 + * @return form
  355 + *
  356 + * iNET Process
  357 + */
  358 + function do_metadata() {
  359 + $this->persistParams(array('fFileKey'));
  360 +
  361 + $oForm = $this->form_metadata($_REQUEST['fFileKey']);
  362 + return $oForm->render();
  363 + }
  364 + /**
  365 + * finally adds a document
  366 + * @return.
  367 + *
  368 + * iNET Process
  369 + */
  370 + function do_finalise() {
  371 + $this->persistParams(array('fFileKey'));
  372 + $sess_key = $_REQUEST['fFileKey'];
  373 + $oForm = $this->form_metadata($sess_key);
  374 + $res = $oForm->validate();
  375 + if (!empty($res['errors'])) {
  376 + return $oForm->handleError();
  377 + }
  378 + $data = $res['results'];
  379 +
  380 + $extra_d = $_SESSION['_add_data'][$sess_key];
  381 + $doctypeid = $extra_d['document_type'];
  382 + $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
  383 + $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false));
  384 + $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
  385 +
  386 +
  387 + $MDPack = array();
  388 + foreach ($fieldsets as $oFieldset) {
  389 + $fields = $oFieldset->getFields();
  390 + $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId());
  391 +
  392 + foreach ($fields as $oField) {
  393 + $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId());
  394 + if ($oFieldset->getIsConditional())
  395 + {
  396 + if ($val == _kt('No selection.'))
  397 + {
  398 + $val = null;
  399 + }
  400 + }
  401 + // ALT.METADATA.LAYER.DIE.DIE.DIE
  402 + if (!is_null($val)) {
  403 + // multiselect change start
  404 + if(is_array($val) && $oField->getHasInetLookup())
  405 + {
  406 + $val = join(", ",$val);
  407 + }
  408 + // multiselect change end
  409 + $MDPack[] = array(
  410 + $oField,
  411 + $val
  412 + );
  413 + }
  414 +
  415 + }
  416 + }
  417 + // older code
  418 +
  419 + $mpo =& new JavascriptObserver($this);
  420 + $oUploadChannel =& KTUploadChannel::getSingleton();
  421 + $oUploadChannel->addObserver($mpo);
  422 +
  423 + require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php');
  424 + //require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php');
  425 + require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc');
  426 + require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
  427 + require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php');
  428 +
  429 + $aErrorOptions = array(
  430 + 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
  431 + 'max_str_len' => 200,
  432 + );
  433 +
  434 + $aFile = $this->oValidator->validateFile($extra_d['file'], $aErrorOptions);
  435 + $sTitle = $extra_d['document_name'];
  436 +
  437 + $iFolderId = $this->oFolder->getId();
  438 + $aOptions = array(
  439 + // 'contents' => new KTFSFileLike($aFile['tmp_name']),
  440 + 'temp_file' => $aFile['tmp_name'],
  441 + 'documenttype' => DocumentType::get($extra_d['document_type']),
  442 + 'metadata' => $MDPack,
  443 + 'description' => $sTitle,
  444 + 'cleanup_initial_file' => true,
  445 + );
  446 +
  447 + $mpo->start();
  448 + //$this->startTransaction();
  449 + $oDocument =& KTDocumentUtil::add($this->oFolder, $aFile['name'], $this->oUser, $aOptions);
  450 + if (PEAR::isError($oDocument)) {
  451 + $message = $oDocument->getMessage();
  452 + $this->errorRedirectTo('main',sprintf(_kt("Unexpected failure to add document - %s"), $message), 'fFolderId=' . $this->oFolder->getId());
  453 + exit(0);
  454 + }
  455 + $this->addInfoMessage(_kt("Document added"));
  456 +
  457 + //$this->commitTransaction();
  458 + $mpo->redirectToDocument($oDocument->getId());
  459 + exit(0);
  460 +
  461 + }
  462 +
  463 +}
  464 +
  465 +?>
... ...