function do_main()
 {
     if (!$this->oDocument->getIsCheckedOut()) {
         $this->oDocument->setImmutable(true);
         $this->oDocument->update();
         controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
     } else {
         $this->addErrorMessage(_kt('Document is checked out and cannot be made immutable'));
         controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
     }
 }
Example #2
0
 function do_deleteSearch()
 {
     $this->startTransaction();
     $iSearchId = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId', false);
     $oSearch = KTSavedSearch::get($iSearchId);
     if (PEAR::isError($oSearch) || $oSearch == false) {
         $this->errorRedirectToMain(_kt('No such search'));
         exit(0);
     }
     $res = $oSearch->delete();
     $this->oValidator->notError($res, array('redirect_to' => 'main', 'message' => _kt('Error deleting search')));
     $this->commitTransaction();
     $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', false);
     $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fFolderId', false);
     if ($iFolderId) {
         controllerRedirect('browse', 'fFolderId=' . $iFolderId);
     } else {
         controllerRedirect('viewDocument', 'fDocumentId=' . $iDocumentId);
     }
 }
 function do_performquicktransition()
 {
     $oForm = $this->form_quicktransition();
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $this->startTransaction();
     $data = $res['results'];
     $oTransition = KTWorkflowTransition::get($_REQUEST['fTransitionId']);
     $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $this->oDocument, $this->oUser, $data['reason']);
     if (!Permission::userHasDocumentReadPermission($this->oDocument)) {
         $this->commitTransaction();
         $_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document');
         controllerRedirect('browse', sprintf('fFolderId=%d', $this->oDocument->getFolderId()));
     } else {
         $this->commitTransaction();
         $_SESSION['KTInfoMessage'][] = _kt('Transition performed');
         controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));
     }
 }
 function do_main()
 {
     $iSubscriptionType = SubscriptionEvent::subTypes('Folder');
     if (!Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) {
         $_SESSION['KTErrorMessage'][] = _kt("You were not subscribed to that folder");
     } else {
         $oSubscription =& Subscription::getByIDs($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType);
         $res = $oSubscription->delete();
         if ($res) {
             $_SESSION['KTInfoMessage'][] = _kt("You have been unsubscribed from this folder");
         } else {
             $_SESSION['KTErrorMessage'][] = _kt("There was a problem unsubscribing you from this folder");
         }
     }
     controllerRedirect('browse', 'fFolderId=' . $this->oFolder->getId());
     exit(0);
 }
 function do_immutable()
 {
     $oForm = $this->form_main();
     $res = $oForm->validate();
     $data = $res['results'];
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $sReason = $data['reason'];
     $fFolderId = $this->oDocument->getFolderId();
     $reason = KTUtil::arrayGet($_REQUEST['data'], 'reason');
     $this->oDocument->setImmutable(true);
     $this->oDocument->update();
     // create the document transaction record
     $oDocumentTransaction = new DocumentTransaction($this->oDocument, $reason, 'ktcore.transactions.immutable');
     $oDocumentTransaction->create();
     controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
     exit(0);
 }
Example #6
0
 function do_rename()
 {
     global $default;
     $sFilename = KTUtil::arrayGet($_REQUEST, 'filename');
     $aOptions = array('redirect_to' => array('', sprintf('fDocumentId=%d', $this->oDocument->getId())), 'message' => _kt("No filename given"), 'max_str_len' => 255);
     $this->oValidator->validateString($sFilename, $aOptions);
     $this->oValidator->validateIllegalCharacters($sFilename, $aOptions);
     $res = KTDocumentUtil::rename($this->oDocument, $sFilename, $this->oUser);
     if (PEAR::isError($res)) {
         $_SESSION['KTErrorMessage'][] = $res->getMessage();
         controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));
     } else {
         $_SESSION['KTInfoMessage'][] = sprintf(_kt('Document "%s" renamed.'), $this->oDocument->getName());
     }
     controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));
     exit(0);
 }
Example #7
0
 function do_email()
 {
     $groupNewRight = trim($_REQUEST['groups_items_added'], chr(160));
     $userNewRight = trim($_REQUEST['users_items_added'], chr(160));
     $fEmailAddresses = trim($_REQUEST['fEmailAddresses']);
     $fAttachDocument = $_REQUEST['fAttachDocument'];
     $fComment = $this->oValidator->validateString($_REQUEST['fComment'], array('redirect_to' => array('', sprintf('fDocumentId=%d', $this->oDocument->getId()))));
     // explode group and user ids
     $aGroupIDs = array();
     $aUserIDs = array();
     $aEmailAddresses = array();
     if (!empty($groupNewRight)) {
         $aGroupIDs = explode(',', $groupNewRight);
     }
     if (!empty($userNewRight)) {
         $aUserIDs = explode(',', $userNewRight);
     }
     if (!empty($fEmailAddresses)) {
         $aAddresses = explode("\n", $fEmailAddresses);
         foreach ($aAddresses as $item) {
             $aItems = explode(' ', $item);
             $aEmailAddresses = array_merge($aEmailAddresses, $aItems);
         }
     }
     $oConfig = KTConfig::getSingleton();
     $bAttachment = $oConfig->get('email/allowAttachment', false);
     $bEmailAddresses = $oConfig->get('email/allowEmailAddresses', false);
     if (empty($bAttachment)) {
         $fAttachDocument = false;
     }
     if (empty($bEmailAddresses)) {
         $aEmailAddresses = array();
     }
     //if we're going to send a mail, first make there is someone to send it to
     if (count($aGroupIDs) == 0 && count($aUserIDs) == 0 && count($aEmailAddresses) == 0) {
         $this->errorRedirectToMain(_kt('No recipients set'), sprintf('fDocumentId=%d', $this->oDocument->getId()));
         exit(0);
     }
     $iDocumentID = $this->oDocument->getID();
     $sDocumentName = $this->oDocument->getName();
     $aEmailErrors = array();
     $aUserEmails = array();
     // send group emails
     sendGroupEmails($aGroupIDs, $aUserEmails, $aEmailErrors);
     // send user emails
     sendUserEmails($aUserIDs, $aUserEmails, $aEmailErrors);
     // send manual/external email addresses
     if ((bool) $fAttachDocument) {
         sendManualEmails($aEmailAddresses, $aUserEmails, $aEmailErrors);
     } else {
         sendExternalEmails($aEmailAddresses, $iDocumentID, $sDocumentName, $fComment, $aEmailErrors);
     }
     // get list of email addresses and send
     if (!empty($aUserEmails)) {
         // email addresses are in the keys -> extract the keys
         $aListEmails = array_keys($aUserEmails);
         sendEmail($aListEmails, $iDocumentID, $sDocumentName, $fComment, (bool) $fAttachDocument, $aEmailErrors);
     }
     if (count($aEmailErrors)) {
         $_SESSION['KTErrorMessage'][] = join('<br />\\n', $aEmailErrors);
     }
     $_SESSION['KTInfoMessage'][] = _kt('Email sent');
     //go back to the document view page
     controllerRedirect('viewDocument', sprintf("fDocumentId=%d", $this->oDocument->getId()));
 }
Example #8
0
 function do_upload()
 {
     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);
     unset($aErrorOptions['message']);
     $aFile = $this->oValidator->validateFile($_FILES['file'], $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);
     $fs =& new KTZipImportStorage('file');
     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;
     }
     $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);
 }
Example #9
0
 function do_addFolder()
 {
     $oForm = $this->form_main();
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         $oForm->handleError();
     }
     $res = $res['results'];
     if (KTFolderUtil::exists($this->oFolder, $res['name'])) {
         $oForm->handleError(null, array('name' => _kt('A folder with that name already exists.')));
     }
     $this->startTransaction();
     $res = KTFolderUtil::add($this->oFolder, $res['name'], $this->oUser);
     $aErrorOptions['defaultmessage'] = _kt("Could not create folder in the document management system");
     $this->oValidator->notError($res, $aErrorOptions);
     $this->commitTransaction();
     controllerRedirect('browse', sprintf('fFolderId=%d', $res->getId()));
     exit(0);
 }
Example #10
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);
 }