Пример #1
0
 function do_main()
 {
     $this->oPage->setBreadcrumbDetails(_kt("bulk upload"));
     $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkUpload');
     $add_fields = array();
     $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");
     $aVocab = array('' => _kt('- Please select a document type -'));
     foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) {
         if (!$oDocumentType->getDisabled()) {
             $aVocab[$oDocumentType->getId()] = $oDocumentType->getName();
         }
     }
     $fieldOptions = array("vocab" => $aVocab);
     $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);
     $fieldsets = array();
     $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
     $activesets = KTFieldset::getGenericFieldsets();
     foreach ($activesets as $oFieldset) {
         $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
         array_push($fieldsets, new $displayClass($oFieldset));
     }
     // Implement an electronic signature for accessing the admin section, it will appear every 10 minutes
     global $default;
     $iFolderId = $this->oFolder->getId();
     if ($default->enableESignatures) {
         $sUrl = KTPluginUtil::getPluginPath('electronic.signatures.plugin', true);
         $heading = _kt('You are attempting to perform a bulk upload');
         $submit['type'] = 'button';
         $submit['onclick'] = "javascript: showSignatureForm('{$sUrl}', '{$heading}', 'ktcore.transactions.bulk_upload', 'bulk', 'bulk_upload_form', 'submit', {$iFolderId});";
     } else {
         $submit['type'] = 'submit';
         $submit['onclick'] = '';
     }
     $oTemplate->setData(array('context' => &$this, 'submit' => $submit, 'add_fields' => $add_fields, 'generic_fieldsets' => $fieldsets));
     return $oTemplate->render();
 }
Пример #2
0
 function fieldsetsForDocument($oDocument, $iTypeOverride = null)
 {
     global $default;
     $oDocument = KTUtil::getObject('Document', $oDocument);
     $iMetadataVersionId = $oDocument->getMetadataVersionId();
     $iDocumentTypeId = $oDocument->getDocumentTypeId();
     if (!is_null($iTypeOverride)) {
         $iDocumentTypeId = $iTypeOverride;
     }
     $sQuery = "SELECT DISTINCT F.id AS fieldset_id " . "FROM {$default->document_metadata_version_table} AS DM INNER JOIN document_fields_link AS DFL ON DM.id = DFL.metadata_version_id " . "INNER JOIN {$default->document_fields_table} AS DF ON DF.ID = DFL.document_field_id " . "INNER JOIN {$default->fieldsets_table} AS F ON F.id = DF.parent_fieldset " . "WHERE DM.id = ?" . "AND F.disabled = false";
     $aParam = array($iMetadataVersionId);
     $aDocumentFieldsetIds = DBUtil::getResultArrayKey(array($sQuery, $aParam), 'fieldset_id');
     $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => true));
     $aSpecificFieldsetIds = KTFieldset::getForDocumentType($iDocumentTypeId, array('ids' => true));
     $aFieldsetIds = kt_array_merge($aDocumentFieldsetIds, $aGenericFieldsetIds, $aSpecificFieldsetIds);
     $aFieldsetIds = array_unique($aFieldsetIds);
     sort($aFieldsetIds);
     $aRet = array();
     foreach ($aFieldsetIds as $iID) {
         $aRet[] = call_user_func(array('KTFieldset', 'get'), $iID);
     }
     return $aRet;
 }
Пример #3
0
 function do_viewComparison()
 {
     $document_data = array();
     $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId');
     if ($document_id === null) {
         $this->oPage->addError(sprintf(_kt("No document was requested.  Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl()));
         return $this->do_error();
     }
     $document_data['document_id'] = $document_id;
     $base_version = KTUtil::arrayGet($_REQUEST, 'fBaseVersion');
     // try get the document.
     $oDocument =& Document::get($document_id, $base_version);
     if (PEAR::isError($oDocument)) {
         $this->oPage->addError(sprintf(_kt("The base document you attempted to retrieve is invalid.   Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl()));
         return $this->do_error();
     }
     if (!Permission::userHasDocumentReadPermission($oDocument)) {
         // FIXME inconsistent.
         $this->oPage->addError(_kt('You are not allowed to view this document'));
         return $this->permissionDenied();
     }
     $this->oDocument =& $oDocument;
     $this->oPage->setSecondaryTitle($oDocument->getName());
     $aOptions = array('documentaction' => 'viewDocument', 'folderaction' => 'browse');
     $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions));
     $this->oPage->setBreadcrumbDetails(_kt('compare versions'));
     $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion');
     if ($comparison_version === null) {
         $this->oPage->addError(sprintf(_kt("No comparison version was requested.  Please <a href=\"%s\">select a version</a>."), KTUtil::addQueryStringSelf('action=history&fDocumentId=' . $document_id)));
         return $this->do_error();
     }
     $oComparison =& Document::get($oDocument->getId(), $comparison_version);
     if (PEAR::isError($oComparison)) {
         $this->errorRedirectToMain(_kt('Invalid document to compare against.'));
     }
     $comparison_data = array();
     $comparison_data['document_id'] = $oComparison->getId();
     $document_data['document'] = $oDocument;
     $comparison_data['document'] = $oComparison;
     $document_data['document_type'] =& DocumentType::get($oDocument->getDocumentTypeID());
     $comparison_data['document_type'] =& DocumentType::get($oComparison->getDocumentTypeID());
     // follow twice:  once for normal, once for comparison.
     $is_valid_doctype = true;
     if (PEAR::isError($document_data['document_type'])) {
         $this->oPage->addError(_kt('The document you requested has an invalid <strong>document type</strong>.  Unfortunately, this means that we cannot effectively display it.'));
         $is_valid_doctype = false;
     }
     // we want to grab all the md for this doc, since its faster that way.
     $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($base_version)));
     $field_values = array();
     foreach ($mdlist as $oFieldLink) {
         $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
     }
     $document_data['field_values'] = $field_values;
     $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($comparison_version)));
     $field_values = array();
     foreach ($mdlist as $oFieldLink) {
         $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
     }
     $comparison_data['field_values'] = $field_values;
     // Fieldset generation.
     //
     //   we need to create a set of FieldsetDisplay objects
     //   that adapt the Fieldsets associated with this lot
     //   to the view (i.e. ZX3).   Unfortunately, we don't have
     //   any of the plumbing to do it, so we handle this here.
     $fieldsets = array();
     // we always have a generic.
     array_push($fieldsets, new GenericFieldsetDisplay());
     // FIXME can we key this on fieldset namespace?  or can we have duplicates?
     // now we get the other fieldsets, IF there is a valid doctype.
     if ($is_valid_doctype) {
         // these are the _actual_ fieldsets.
         $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
         // and the generics
         $activesets = KTFieldset::getGenericFieldsets();
         foreach ($activesets as $oFieldset) {
             $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
             array_push($fieldsets, new $displayClass($oFieldset));
         }
         $activesets = KTFieldset::getForDocumentType($oDocument->getDocumentTypeID());
         foreach ($activesets as $oFieldset) {
             $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
             array_push($fieldsets, new $displayClass($oFieldset));
         }
     }
     // FIXME handle ad-hoc fieldsets.
     $this->addPortlets();
     $oTemplate = $this->oValidator->validateTemplate('ktcore/document/compare');
     $aTemplateData = array('context' => $this, 'document_id' => $document_id, 'document' => $oDocument, 'document_data' => $document_data, 'comparison_data' => $comparison_data, 'comparison_document' => $oComparison, 'fieldsets' => $fieldsets);
     //var_dump($aTemplateData['comparison_data']);
     return $oTemplate->render($aTemplateData);
 }
Пример #4
0
 function do_finalise()
 {
     $this->persistParams(array('fFileKey'));
     $sess_key = $_REQUEST['fFileKey'];
     $oForm = $this->form_metadata($sess_key);
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $data = $res['results'];
     $extra_d = $_SESSION['_add_data'][$sess_key];
     $doctypeid = $extra_d['document_type'];
     $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
     $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false));
     $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
     $MDPack = array();
     foreach ($fieldsets as $oFieldset) {
         $fields = $oFieldset->getFields();
         $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId());
         foreach ($fields as $oField) {
             $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId());
             if ($oFieldset->getIsConditional()) {
                 if ($val == _kt('No selection.')) {
                     $val = null;
                 }
             }
             // ALT.METADATA.LAYER.DIE.DIE.DIE
             if (!is_null($val)) {
                 $MDPack[] = array($oField, $val);
             }
         }
     }
     // older code
     $mpo =& new JavascriptObserver($this);
     $oUploadChannel =& KTUploadChannel::getSingleton();
     $oUploadChannel->addObserver($mpo);
     require_once KT_LIB_DIR . '/storage/storagemanager.inc.php';
     //require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php');
     require_once KT_LIB_DIR . '/documentmanagement/DocumentType.inc';
     require_once KT_LIB_DIR . '/metadata/fieldset.inc.php';
     require_once KT_LIB_DIR . '/documentmanagement/documentutil.inc.php';
     $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())), 'max_str_len' => 200);
     $aFile = $this->oValidator->validateFile($extra_d['file'], $aErrorOptions);
     $sTitle = $extra_d['document_name'];
     $iFolderId = $this->oFolder->getId();
     $aOptions = array('temp_file' => $aFile['tmp_name'], 'documenttype' => DocumentType::get($extra_d['document_type']), 'metadata' => $MDPack, 'description' => $sTitle, 'cleanup_initial_file' => true);
     $mpo->start();
     //$this->startTransaction();
     $oDocument =& KTDocumentUtil::add($this->oFolder, $aFile['name'], $this->oUser, $aOptions);
     if (PEAR::isError($oDocument)) {
         $message = $oDocument->getMessage();
         $this->errorRedirectTo('main', sprintf(_kt("Unexpected failure to add document - %s"), $message), 'fFolderId=' . $this->oFolder->getId());
         exit(0);
     }
     $this->addInfoMessage(_kt("Document added"));
     //$this->commitTransaction();
     $mpo->redirectToDocument($oDocument->getId());
     exit(0);
 }
Пример #5
0
 function validateMetadata(&$oDocument, $aMetadata)
 {
     $aFieldsets =& KTFieldset::getGenericFieldsets();
     $aFieldsets =& kt_array_merge($aFieldsets, KTFieldset::getForDocumentType($oDocument->getDocumentTypeId()));
     $aSimpleMetadata = array();
     foreach ($aMetadata as $aSingleMetadatum) {
         list($oField, $sValue) = $aSingleMetadatum;
         if (is_null($oField)) {
             continue;
         }
         $aSimpleMetadata[$oField->getId()] = $sValue;
     }
     $aFailed = array();
     foreach ($aFieldsets as $oFieldset) {
         $aFields =& $oFieldset->getFields();
         $aFieldValues = array();
         $isRealConditional = $oFieldset->getIsConditional() && KTMetadataUtil::validateCompleteness($oFieldset);
         foreach ($aFields as $oField) {
             $v = KTUtil::arrayGet($aSimpleMetadata, $oField->getId());
             if ($oField->getIsMandatory() && !$isRealConditional) {
                 if (empty($v)) {
                     // XXX: What I'd do for a setdefault...
                     $aFailed['field'][$oField->getId()] = 1;
                 }
             }
             if (!empty($v)) {
                 $aFieldValues[$oField->getId()] = $v;
             }
         }
         if ($isRealConditional) {
             $res = KTMetadataUtil::getNext($oFieldset, $aFieldValues);
             if ($res) {
                 foreach ($res as $aMDSet) {
                     if ($aMDSet['field']->getIsMandatory()) {
                         $aFailed['fieldset'][$oFieldset->getId()] = 1;
                     }
                 }
             }
         }
     }
     if (!empty($aFailed)) {
         return new KTMetadataValidationError($aFailed);
     }
     return $aMetadata;
 }
Пример #6
0
 /**
  * This should actually not be in ktapi, but in webservice
  * This method gets metadata fieldsets based on the document type
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $document_type The type of document
  * @return mixed Error object|SOAP object|Array of fieldsets
  */
 public function get_document_type_metadata($document_type = 'Default')
 {
     // now get document type specifc ids
     $typeid = $this->get_documenttypeid($document_type);
     if (is_a($typeid, 'KTAPI_DocumentTypeError')) {
         return $typeid;
     }
     if (is_null($typeid) || PEAR::isError($typeid)) {
         $response['message'] = $typeid->getMessage();
         return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response);
     }
     $doctype_ids = KTFieldset::getForDocumentType($typeid, array('ids' => false));
     if (is_null($doctype_ids) || PEAR::isError($doctype_ids)) {
         $response['message'] = $generic_ids->getMessage();
         return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response);
     }
     // first get generic ids
     $generic_ids = KTFieldset::getGenericFieldsets(array('ids' => false));
     if (is_null($generic_ids) || PEAR::isError($generic_ids)) {
         $response['message'] = $generic_ids->getMessage();
         return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response);
     }
     // lets merge the results
     $fieldsets = kt_array_merge($generic_ids, $doctype_ids);
     $results = array();
     foreach ($fieldsets as $fieldset) {
         if ($fieldset->getIsConditional()) {
             /* this is not implemented...*/
             continue;
         }
         $fields = $fieldset->getFields();
         $result = array('fieldset' => $fieldset->getName(), 'description' => $fieldset->getDescription());
         $fieldsresult = array();
         foreach ($fields as $field) {
             $value = 'n/a';
             //$controltype = 'string';
             // Replace with true
             $controltype = strtolower($field->getDataType());
             if ($field->getHasLookup()) {
                 $controltype = 'lookup';
                 if ($field->getHasLookupTree()) {
                     $controltype = 'tree';
                 }
             }
             $options = array();
             if ($field->getInetLookupType() == 'multiwithcheckboxes' || $field->getInetLookupType() == 'multiwithlist') {
                 $controltype = 'multiselect';
             }
             switch ($controltype) {
                 case 'lookup':
                     $selection = KTAPI::get_metadata_lookup($field->getId());
                     break;
                 case 'tree':
                     $selection = KTAPI::get_metadata_tree($field->getId());
                     break;
                 case 'large text':
                     $options = array('ishtml' => $field->getIsHTML(), 'maxlength' => $field->getMaxLength());
                     $selection = array();
                     break;
                 case 'multiselect':
                     $selection = KTAPI::get_metadata_lookup($field->getId());
                     $options = array('type' => $field->getInetLookupType());
                     break;
                 default:
                     $selection = array();
             }
             $fieldsresult[] = array('name' => $field->getName(), 'required' => $field->getIsMandatory(), 'value' => $value, 'description' => $field->getDescription(), 'control_type' => $controltype, 'selection' => $selection, 'options' => $options);
         }
         $result['fields'] = $fieldsresult;
         $results[] = $result;
     }
     return $results;
 }
Пример #7
0
 /**
  * Performs actual import action. | iNET Process
  * @Return.
  * @param.
  */
 function do_import()
 {
     set_time_limit(0);
     $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())));
     $aErrorOptions['message'] = _kt('Invalid document type provided');
     $requestDocumentType = $_REQUEST['fDocumentTypeId'];
     //Backwards compatibility
     if ($requestDocumentType == '' || $requestDocumentType == NULL) {
         $requestDocumentType = $_REQUEST['data'];
         $requestDocumentType = $requestDocumentType['fDocumentTypeId'];
         //New elements come through as arrays
     }
     $oDocumentType = $this->oValidator->validateDocumentType($requestDocumentType, $aErrorOptions);
     $aErrorOptions['message'] = _kt('Invalid path provided');
     $tmpPath = $_REQUEST['path'];
     //Backwards compatibility
     if ($tmpPath == '') {
         $tmpPath = $_REQUEST['data'];
         $tmpPath = $tmpPath['path'];
     }
     $sPath = $this->oValidator->validateString($tmpPath, $aErrorOptions);
     /*
             $matches = array();
             $aFields = array();
             foreach ($_REQUEST as $k => $v) {
                 if (preg_match('/^metadata_(\d+)$/', $k, $matches)) {
                    
     		 // multiselect change start
     		$oDocField = DocumentField::get($matches[1]);
     		if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v))
     		{
     			$v = join(", ", $v);
     		}
                     $aFields[] = array($oDocField, $v);
     		
     		// previously it was just one line which is commented, just above line
     		// multiselect change end
                 }
             }
     
             $aOptions = array(
                 'documenttype' => $oDocumentType,
                 'metadata' => $aFields,
                 'copy_upload' => 'true',
             );
     */
     // Newer metadata form field catcher that works with ktcore form array type fields named like
     // name='metadata[fieldset][metadata_9]'
     $aData = $_REQUEST['data'];
     $data = $aData;
     /*
     		$oForm = $this->getBulkImportForm();
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $data = $res['results'];
     */
     $doctypeid = $requestDocumentType;
     $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
     $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false));
     $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
     $MDPack = array();
     foreach ($fieldsets as $oFieldset) {
         $fields = $oFieldset->getFields();
         $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId());
         foreach ($fields as $oField) {
             $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId());
             //Fix for multiselect not submitting data due to the value not being flat.
             $sVal = '';
             if (is_array($val)) {
                 foreach ($val as $v) {
                     $sVal .= $v . ", ";
                 }
                 $sVal = substr($sVal, 0, strlen($sVal) - 2);
                 $val = $sVal;
             }
             if ($oFieldset->getIsConditional()) {
                 if ($val == _kt('No selection.')) {
                     $val = null;
                 }
             }
             if (!is_null($val)) {
                 $MDPack[] = array($oField, $val);
             }
         }
     }
     $aOptions = array('documenttype' => $oDocumentType, 'metadata' => $MDPack, 'copy_upload' => 'true');
     $po =& new JavascriptObserver($this);
     $po->start();
     $oUploadChannel =& KTUploadChannel::getSingleton();
     $oUploadChannel->addObserver($po);
     $fs =& new KTFSImportStorage($sPath);
     $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
     if (KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin')) {
         require_once KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php";
         $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
     } else {
         $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
     }
     DBUtil::startTransaction();
     $res = $bm->import();
     if (PEAR::isError($res)) {
         DBUtil::rollback();
         $_SESSION["KTErrorMessage"][] = _kt("Bulk import failed") . ": " . $res->getMessage();
     } else {
         DBUtil::commit();
         $this->addInfoMessage(_kt("Bulk import succeeded"));
     }
     $po->redirectToFolder($this->oFolder->getId());
     exit(0);
 }
Пример #8
0
 /**
  * Returns a JSON object containing a list of fields belonging to a generic fieldset 
  * @return JSON Object
  *
  */
 function getGenericFields()
 {
     $oFReg =& KTFieldsetRegistry::getSingleton();
     $activesets = KTFieldset::getGenericFieldsets();
     $fields = array();
     foreach ($activesets as $oFieldset) {
         $fieldIds = kt_array_merge($fieldIds, $oFReg->getGenericFields($oFieldset));
     }
     $jsOptions = '{ "genericId" : {';
     foreach ($fieldIds as $fieldId) {
         $jsOptions .= "'{$fieldId}' : '{$fieldId}',";
     }
     $jsOptions = substr($jsOptions, 0, strlen($jsOptions) - 1);
     $jsOptions .= '}}';
     return $jsOptions;
 }
Пример #9
0
 /**
  * make uploads
  * @return
  *
  * iNET Process
  */
 function do_upload()
 {
     set_time_limit(0);
     global $default;
     $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())));
     $aErrorOptions['message'] = _kt('Invalid document type provided');
     $requestDocumentType = $_REQUEST['fDocumentTypeId'];
     //Backwards compatibility
     if ($requestDocumentType == '' || $requestDocumentType == NULL) {
         $requestDocumentType = $_REQUEST['data'];
         $requestDocumentType = $requestDocumentType['fDocumentTypeId'];
         //New elements come through as arrays
     }
     $oDocumentType = $this->oValidator->validateDocumentType($requestDocumentType, $aErrorOptions);
     unset($aErrorOptions['message']);
     $fileData = $_FILES['file'];
     $fileName = 'file';
     if ($fileData == '' || $fileData == NULL) {
         $fileData = $_FILES['_kt_attempt_unique_file'];
         //$_FILES['_kt_attempt_unique_file'];
         $fileName = '_kt_attempt_unique_file';
     }
     $aFile = $this->oValidator->validateFile($fileData, $aErrorOptions);
     // Lets move the file from the windows temp directory into our own directory
     $oKTConfig =& KTConfig::getSingleton();
     $sBasedir = $oKTConfig->get("urls/tmpDirectory");
     $tmpFilename = tempnam($sBasedir, 'kt_storebulk');
     $oStorage =& KTStorageManagerUtil::getSingleton();
     $res = $oStorage->uploadTmpFile($fileData['tmp_name'], $tmpFilename, array('copy_upload' => 'true'));
     // Save the new temp filename in the file data array
     $fileData['tmp_name'] = $tmpFilename;
     if ($res === false) {
         $default->log->error('File could not be copied from the system temp directory.');
         exit('File could not be copied from the system temp directory.');
     }
     $matches = array();
     $aFields = array();
     // author: Charl Mert
     // Older kt3 form field submission used name='metadata_9 etc and the aFields array contained them.'
     // Should keep open here for backwards compatibility but will close it to "discover" the other
     // old interfaces.
     /*
     foreach ($_REQUEST as $k => $v) {
     	if (preg_match('/^metadata_(\d+)$/', $k, $matches)) {
     		// multiselect change start
     		$oDocField = DocumentField::get($matches[1]);
     
     		if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v))
     		{
     			$v = join(", ", $v);
     		}
     		$aFields[] = array($oDocField, $v);
     
     		// previously it was just one line which is commented, just above line
     		// multiselect change end
     	}
     }
     */
     //Newer metadata form field catcher that works with ktcore form array type fields named like
     //name='metadata[fieldset][metadata_9]'
     $aData = $_REQUEST['data'];
     /* //This validation breaks with ajax loaded form items e.g. a non generic fieldset that submits
     		 * //values doesn't pass the check below.
     		$oForm = $this->getBulkUploadForm();
             $res = $oForm->validate();
             if (!empty($res['errors'])) {
                 return $oForm->handleError();
             }
             $data = $res['results'];
             var_dump($data);
             */
     $data = $aData;
     $doctypeid = $requestDocumentType;
     $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
     $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false));
     $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
     $MDPack = array();
     foreach ($fieldsets as $oFieldset) {
         $fields = $oFieldset->getFields();
         $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId());
         //var_dump($values);
         foreach ($fields as $oField) {
             //var_dump($oField->getId());
             $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId());
             //Fix for multiselect not submitting data due to the value not being flat.
             $sVal = '';
             if (is_array($val)) {
                 foreach ($val as $v) {
                     $sVal .= $v . ", ";
                 }
                 $sVal = substr($sVal, 0, strlen($sVal) - 2);
                 $val = $sVal;
             }
             if ($oFieldset->getIsConditional()) {
                 if ($val == _kt('No selection.')) {
                     $val = null;
                 }
             }
             if (!is_null($val)) {
                 $MDPack[] = array($oField, $val);
             }
         }
     }
     $aOptions = array('documenttype' => $oDocumentType, 'metadata' => $MDPack);
     $fs =& new KTZipImportStorage($fileName, $fileData);
     if (!$fs->CheckFormat()) {
         $sFormats = $fs->getFormats();
         $this->addErrorMessage(sprintf(_kt("Bulk Upload failed. Archive is not an accepted format. Accepted formats are: .%s"), $sFormats));
         controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID());
         exit;
     }
     if (KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin')) {
         require_once KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php";
         $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
     } else {
         $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions);
     }
     $this->startTransaction();
     $res = $bm->import();
     $aErrorOptions['message'] = _kt("Bulk Upload failed");
     $this->oValidator->notError($res, $aErrorOptions);
     $this->addInfoMessage(_kt("Bulk Upload successful"));
     $this->commitTransaction();
     controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID());
     exit(0);
 }