Пример #1
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);
 }
Пример #2
0
 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');
     $oDocumentType = $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId'], $aErrorOptions);
     $aErrorOptions['message'] = _kt('Invalid path provided');
     $sPath = $this->oValidator->validateString($_REQUEST['path'], $aErrorOptions);
     $matches = array();
     $aFields = array();
     foreach ($_REQUEST as $k => $v) {
         if (preg_match('/^metadata_(\\d+)$/', $k, $matches)) {
             $aFields[] = array(DocumentField::get($matches[1]), $v);
         }
     }
     $aOptions = array('documenttype' => $oDocumentType, 'metadata' => $aFields, '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);
     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);
 }
Пример #3
0
 function &_in_add($oFolder, $sFilename, $oUser, $aOptions)
 {
     $aOrigOptions = $aOptions;
     $sFilename = KTDocumentUtil::getUniqueFilename($oFolder, $sFilename);
     $sName = KTUtil::arrayGet($aOptions, 'description', $sFilename);
     $sName = KTDocumentUtil::getUniqueDocumentName($oFolder, $sName);
     $aOptions['description'] = $sName;
     $oUploadChannel =& KTUploadChannel::getSingleton();
     $oUploadChannel->sendMessage(new KTUploadNewFile($sFilename));
     DBUtil::startTransaction();
     $oDocument =& KTDocumentUtil::_add($oFolder, $sFilename, $oUser, $aOptions);
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Document created')));
     if (PEAR::isError($oDocument)) {
         return $oDocument;
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file')));
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan');
     $iTrigger = 0;
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $oTrigger->setDocument($oDocument);
         // $oUploadChannel->sendMessage(new KTUploadGenericMessage(sprintf(_kt("    (trigger %s)"), $sTrigger)));
         $ret = $oTrigger->scan();
         if (PEAR::isError($ret)) {
             $oDocument->delete();
             return $ret;
         }
     }
     // refresh the document object
     DBUtil::commit();
     $oDocument->clearAllCaches();
     // NEW SEARCH
     Indexer::index($oDocument);
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating transaction')));
     $aOptions = array('user' => $oUser);
     //create the document transaction record
     $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions);
     $res = $oDocumentTransaction->create();
     if (PEAR::isError($res)) {
         $oDocument->delete();
         return $res;
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions')));
     // fire subscription alerts for the checked in document
     $oSubscriptionEvent = new SubscriptionEvent();
     $oFolder = Folder::get($oDocument->getFolderID());
     $oSubscriptionEvent->AddDocument($oDocument, $oFolder);
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oDocument, 'aOptions' => $aOrigOptions);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
     }
     // update document object with additional fields / data from the triggers
     $oDocument = Document::get($oDocument->iId);
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Checking permissions...')));
     // Check if there are any dynamic conditions / permissions that need to be updated on the document
     // If there are dynamic conditions then update the permissions on the document
     // The dynamic condition test fails unless the document exists in the DB therefore update permissions after committing the transaction.
     include_once KT_LIB_DIR . '/permissions/permissiondynamiccondition.inc.php';
     $iPermissionObjectId = $oFolder->getPermissionObjectID();
     $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);
     if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) {
         $res = KTPermissionUtil::updatePermissionLookup($oDocument);
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('All done...')));
     return $oDocument;
 }
Пример #4
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);
 }