function form_owner()
 {
     $oForm = new KTForm();
     $oForm->setOptions(array('label' => _kt('Change Document Ownership'), 'description' => _kt('Changing document ownership allows you to keep the "owner" role relevant, even when the original user no longer is an appropriate choice.'), 'action' => 'reown', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'fail_action' => 'main', 'identifier' => 'ktcore.actions.document.owner', 'context' => $this));
     $oForm->setWidgets(array(array('ktcore.widgets.entityselection', array('label' => _kt('New Owner'), 'description' => _kt('The owner of a document is usually the person with ultimate responsibility for its contents.  It is initially set to the person who created the document, but can be changed to any other user.'), 'important_description' => _kt('Please note that changing the owner may affect access to this document.'), 'label_method' => 'getName', 'vocab' => User::getList('id > 0'), 'value' => $this->oDocument->getOwnerID(), 'name' => 'user_id'))));
     $oForm->setValidators(array(array('ktcore.validators.entity', array('test' => 'user_id', 'class' => 'User', 'output' => 'user'))));
     return $oForm;
 }
示例#2
0
 function do_update()
 {
     $oForm = $this->form_edit();
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $data = $res['results'];
     // we need to format these in MDPack format
     // which is a little archaic:
     //
     //  array(
     //      array($oField, $sValue),
     //      array($oField, $sValue),
     //      array($oField, $sValue),
     //  );
     //
     // we do this the "easy" way.
     $doctypeid = $this->oDocument->getDocumentTypeId();
     if ($_REQUEST['new_type']) {
         $oTestType = DocumentType::get($_REQUEST['new_type']);
         if (!PEAR::isError($oTestType)) {
             $doctypeid = $oTestType->getId();
         }
     }
     $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid);
     $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());
             // FIXME "null" has strange meanings here.
             if (!is_null($val)) {
                 $MDPack[] = array($oField, $val);
             }
         }
     }
     $this->startTransaction();
     if ($this->oDocument->getDocumentTypeId() != $doctypeid) {
         $this->oDocument->setDocumentTypeId($doctypeid);
     }
     $this->oDocument->setName($data['document_title']);
     $this->oDocument->setLastModifiedDate(getCurrentDateTime());
     $this->oDocument->setModifiedUserId($this->oUser->getId());
     // Update the content version / document version
     global $default;
     if ($default->updateContentVersion) {
         $this->oDocument->startNewContentVersion($this->oUser);
         $this->oDocument->setMinorVersionNumber($this->oDocument->getMinorVersionNumber() + 1);
     } else {
         $this->oDocument->startNewMetadataVersion($this->oUser);
     }
     $res = $this->oDocument->update();
     if (PEAR::isError($res)) {
         $oForm->handleError(sprintf(_kt("Unexpected failure to update document title: %s"), $res->getMessage()));
     }
     $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack);
     if (PEAR::isError($core_res)) {
         $oForm->handleError(sprintf(_kt("Unexpected validation failure: %s."), $core_res->getMessage()));
     }
     // post-triggers.
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array("document" => $this->oDocument, "aOptions" => $MDPack);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
     }
     $this->commitTransaction();
     // create the document transaction record
     $oDocumentTransaction =& new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update');
     $oDocumentTransaction->create();
     // 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 changes exists in the DB therefore update permissions after committing the transaction.
     $iPermissionObjectId = $this->oDocument->getPermissionObjectID();
     $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);
     if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) {
         $res = KTPermissionUtil::updatePermissionLookup($this->oDocument);
     }
     redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId()));
     exit(0);
 }
示例#3
0
 function do_disableAdminMode()
 {
     $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId');
     $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId');
     if ($iDocumentId) {
         $oDocument = Document::get($iDocumentId);
         if (PEAR::isError($oDocument) || $oDocument === false) {
             return null;
         }
         $iFolderId = $oDocument->getFolderId();
     }
     if (!Permission::userIsSystemAdministrator() && !Permission::isUnitAdministratorForFolder($this->oUser, $iFolderId)) {
         $this->errorRedirectToMain(_kt('You are not an administrator'));
     }
     // log this entry
     $oLogEntry =& KTUserHistory::createFromArray(array('userid' => $this->oUser->getId(), 'datetime' => date('Y-m-d H:i:s', time()), 'actionnamespace' => 'ktcore.user_history.disable_admin_mode', 'comments' => 'Admin Mode disabled', 'sessionid' => $_SESSION['sessionID']));
     $aOpts = array('redirect_to' => 'main', 'message' => _kt('Unable to log admin mode exit.  Not de-activating admin mode.'));
     $this->oValidator->notError($oLogEntry, $aOpts);
     $_SESSION['adminmode'] = false;
     if ($_REQUEST['fDocumentId']) {
         $_SESSION['KTInfoMessage'][] = _kt('Administrator mode disabled');
         redirect(KTBrowseUtil::getUrlForDocument($iDocumentId));
         exit(0);
     }
     if ($_REQUEST['fFolderId']) {
         $this->successRedirectToMain(_kt('Administrator mode disabled'), sprintf('fFolderId=%d', $_REQUEST['fFolderId']));
     }
     $this->successRedirectToMain(_kt('Administrator mode disabled'));
 }
 function form_main()
 {
     $oForm = new KTForm();
     $oForm->setOptions(array('label' => _kt('Make Immutable'), 'action' => 'immutable', 'fail_action' => 'main', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'submit_label' => _kt('Make Immutable'), 'context' => &$this));
     // Electronic Signature if enabled
     global $default;
     if ($default->enableESignatures) {
         $widgets[] = array('ktcore.widgets.info', array('label' => _kt('This action requires authentication'), 'description' => _kt('Please provide your user credentials as confirmation of this action.'), 'name' => 'info'));
         $widgets[] = array('ktcore.widgets.string', array('label' => _kt('Username'), 'name' => 'sign_username', 'required' => true));
         $widgets[] = array('ktcore.widgets.password', array('label' => _kt('Password'), 'name' => 'sign_password', 'required' => true));
     }
     $widgets[] = array('ktcore.widgets.reason', array('label' => _kt('Reason'), 'description' => _kt('Please specify why you are making this document immutable.  Please bear in mind that you can use a maximum of <strong>250</strong> characters.'), 'name' => 'reason'));
     $oForm->setWidgets($widgets);
     $validators[] = array('ktcore.validators.string', array('test' => 'reason', 'min_length' => 1, 'max_length' => 250, 'output' => 'reason'));
     if ($default->enableESignatures) {
         $validators[] = array('electonic.signatures.validators.authenticate', array('object_id' => $this->oDocument->iId, 'type' => 'document', 'action' => 'ktcore.transactions.immutable', 'test' => 'info', 'output' => 'info'));
     }
     $oForm->setValidators($validators);
     return $oForm;
 }
示例#5
0
 function display_viewlet()
 {
     $oKTTemplating =& KTTemplating::getSingleton();
     $oTemplate =& $oKTTemplating->loadTemplate("ktstandard/links/links_viewlet");
     if (is_null($oTemplate)) {
         return '';
     }
     $iDocId = $this->oDocument->getId();
     $temp_links_from = DocumentLink::getLinksFromDocument($iDocId);
     $temp_links_to = DocumentLink::getLinksToDocument($iDocId);
     $temp_links_external = DocumentLink::getExternalLinks($iDocId);
     $links_to = array();
     $links_from = array();
     $links_external = array();
     if (!empty($temp_links_from)) {
         foreach ($temp_links_from as $link) {
             $oDoc = $link->getChildDocument();
             if (PEAR::isError($oDoc)) {
                 continue;
             }
             if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.read', $oDoc)) {
                 $type = $link->getLinkType();
                 $aInfo = array('url' => KTBrowseUtil::getUrlForDocument($oDoc), 'name' => $oDoc->getName(), 'type' => $type->getName(), 'description' => $type->getDescription());
                 $links_from[] = $aInfo;
             }
         }
     }
     if (!empty($temp_links_to)) {
         foreach ($temp_links_to as $link) {
             $oDoc = $link->getParentDocument();
             if (PEAR::isError($oDoc)) {
                 continue;
             }
             if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.read', $oDoc)) {
                 $type = $link->getLinkType();
                 $aInfo = array('url' => KTBrowseUtil::getUrlForDocument($oDoc), 'name' => $oDoc->getName(), 'type' => $type->getName(), 'description' => $type->getDescription());
                 $links_to[] = $aInfo;
             }
         }
     }
     if (!empty($temp_links_external)) {
         foreach ($temp_links_external as $link) {
             $type = $link->getLinkType();
             $aInfo = array('url' => $link->getTargetUrl(), 'name' => $link->getTargetName(), 'type' => $type->getName(), 'description' => $type->getDescription());
             $links_external[] = $aInfo;
         }
     }
     if (empty($links_from) && empty($links_to) && empty($links_external)) {
         return '';
     }
     $oTemplate->setData(array('context' => $this, 'links_from' => $links_from, 'links_to' => $links_to, 'links_external' => $links_external));
     return $oTemplate->render();
 }
示例#6
0
 function checkRepoDocument($oDocument)
 {
     global $aRepoDocumentProblems;
     $aDCVs = KTDocumentContentVersion::getByDocument($oDocument);
     foreach ($aDCVs as $oDCV) {
         $sDocumentPath = $oDCV->getStoragePath();
         $sFullPath = sprintf("%s/%s", $this->fsPath, $sDocumentPath);
         if (!is_file($sFullPath)) {
             $this->aRepoDocumentProblems[] = array('document' => $oDocument, 'content' => $oDCV, 'path' => $sDocumentPath, 'doclink' => KTBrowseUtil::getUrlForDocument($oDocument));
         }
     }
 }
 function getDocInfo($iDocId)
 {
     $oDocument = Document::get($iDocId);
     if (PEAR::isError($oDocument)) {
         return _kt('Document no longer exists.');
     }
     $sName = htmlentities($oDocument->getName(), ENT_NOQUOTES, 'UTF-8');
     $sLink = KTBrowseUtil::getUrlForDocument($oDocument);
     $aAnchorData = array();
     $aAnchorData[] = $sLink;
     $aAnchorData[] = $sName;
     return $aAnchorData;
 }
 function buildDocumentLink($aDataRow)
 {
     return KTBrowseUtil::getUrlForDocument($aDataRow['document']->getId());
 }
 function form_main()
 {
     $oForm = new KTForm();
     $oForm->setOptions(array('label' => _kt('Convert Document to PDF'), 'action' => 'selectType', 'fail_action' => 'main', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'submit_label' => _kt('Convert Document'), 'context' => &$this));
     $oForm->setWidgets(array(array('ktcore.widgets.selection', array('label' => _kt("Type of conversion"), 'description' => _kt('The following are the types of conversions you can perform on this document.'), 'name' => 'convert_type', 'vocab' => array('Download as PDF'), 'simple_select' => true, 'required' => true))));
     return $oForm;
 }
示例#10
0
 function buildDocumentLink($aDataRow)
 {
     if ($aDataRow['document']->isSymbolicLink()) {
         $iDocId = $aDataRow['document']->getRealDocumentId();
     } else {
         $iDocId = $aDataRow["document"]->getId();
     }
     $url = KTBrowseUtil::getUrlForDocument($iDocId);
     if ($aDataRow['document']->isSymbolicLink()) {
         $aDataRow['document']->switchToRealCore();
         $url .= "&fShortcutFolder=" . $aDataRow['document']->getFolderId();
     }
     return $url;
 }
示例#11
0
 function delete($oDocument, $sReason, $iDestFolderId = null)
 {
     // use the deleteSymbolicLink function is this is a symlink
     if ($oDocument->isSymbolicLink()) {
         return KTDocumentUtil::deleteSymbolicLink($oDocument);
     }
     $oDocument =& KTUtil::getObject('Document', $oDocument);
     if (is_null($iDestFolderId)) {
         $iDestFolderId = $oDocument->getFolderID();
     }
     $oStorageManager =& KTStorageManagerUtil::getSingleton();
     global $default;
     if (count(trim($sReason)) == 0) {
         return PEAR::raiseError(_kt('Deletion requires a reason'));
     }
     if (PEAR::isError($oDocument) || $oDocument == false) {
         return PEAR::raiseError(_kt('Invalid document object.'));
     }
     if ($oDocument->getIsCheckedOut() == true) {
         return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName()));
     }
     if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.delete')) {
         return PEAR::raiseError(_kt('Document cannot be deleted as it is restricted by the workflow.'));
     }
     // IF we're deleted ...
     if ($oDocument->getStatusID() == DELETED) {
         return true;
     }
     $oOrigFolder = Folder::get($oDocument->getFolderId());
     DBUtil::startTransaction();
     // flip the status id
     $oDocument->setStatusID(DELETED);
     // $iDestFolderId is DEPRECATED.
     $oDocument->setFolderID(null);
     $oDocument->setRestoreFolderId($oOrigFolder->getId());
     $oDocument->setRestoreFolderPath(Folder::generateFolderIDs($oOrigFolder->getId()));
     $res = $oDocument->update();
     if (PEAR::isError($res) || $res == false) {
         DBUtil::rollback();
         return PEAR::raiseError(_kt('There was a problem deleting the document from the database.'));
     }
     // now move the document to the delete folder
     $res = $oStorageManager->delete($oDocument);
     if (PEAR::isError($res) || $res == false) {
         //could not delete the document from the file system
         $default->log->error('Deletion: Filesystem error deleting document ' . $oDocument->getFileName() . ' from folder ' . Folder::getFolderPath($oDocument->getFolderID()) . ' id=' . $oDocument->getFolderID());
         // we use a _real_ transaction here ...
         DBUtil::rollback();
         /*
         //reverse the document deletion
         $oDocument->setStatusID(LIVE);
         $oDocument->update();
         */
         return PEAR::raiseError(_kt('There was a problem deleting the document from storage.'));
     }
     // get the user object
     $oUser = User::get($_SESSION['userID']);
     //delete all shortcuts linking to this document
     $aSymlinks = $oDocument->getSymbolicLinks();
     foreach ($aSymlinks as $aSymlink) {
         $oShortcutDocument = Document::get($aSymlink['id']);
         $oOwnerUser = User::get($oShortcutDocument->getOwnerID());
         KTDocumentUtil::deleteSymbolicLink($aSymlink['id']);
         //send an email to the owner of the shortcut
         if ($oOwnerUser->getEmail() != null && $oOwnerUser->getEmailNotification() == true) {
             $emailTemplate = new EmailTemplate("kt3/notifications/notification.SymbolicLinkDeleted", array('user_name' => $oUser->getName(), 'url' => KTUtil::ktLink(KTBrowseUtil::getUrlForDocument($oShortcutDocument)), 'title' => $oShortcutDocument->getName()));
             $email = new EmailAlert($oOwnerUser->getEmail(), _kt("KnowledgeTree Notification"), $emailTemplate->getBody());
             $email->send();
         }
     }
     $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete');
     $oDocumentTransaction->create();
     $oDocument->setFolderID(1);
     DBUtil::commit();
     // we weren't doing notifications on this one
     $oSubscriptionEvent = new SubscriptionEvent();
     $oSubscriptionEvent->RemoveDocument($oDocument, $oOrigFolder);
     // document is now deleted:  triggers are best-effort.
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('delete', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oDocument);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
         if (PEAR::isError($ret)) {
             $oDocument->delete();
             // FIXME nbm: review that on-fail => delete is correct ?!
             return $ret;
         }
     }
 }
示例#12
0
 function do_update()
 {
     $oForm = $this->form_edit();
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $data = $res['results'];
     // we need to format these in MDPack format
     // which is a little archaic:
     //
     //  array(
     //      array($oField, $sValue),
     //      array($oField, $sValue),
     //      array($oField, $sValue),
     //  );
     //
     // we do this the "easy" way.
     $doctypeid = $this->oDocument->getDocumentTypeId();
     if ($_REQUEST['new_type']) {
         $oTestType = DocumentType::get($_REQUEST['new_type']);
         if (!PEAR::isError($oTestType)) {
             $doctypeid = $oTestType->getId();
         }
     }
     $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid);
     $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());
             // for html fields we want to do some stripping :)
             if ($oField->getIsHTML()) {
                 // NOTE this works great...once the text is saved a first time
                 //      but the first time the <script> tags come through encoded, so decode first
                 // HOWEVER html_entity_decode decodes too much (e.g. &nbsp; - which causes a DB error for some reason)!  use this instead
                 // NOTE I considered a preg_replace_callback but str_replace is probably more efficient in this case as we only have
                 //      two symbols to replace
                 $val = str_replace('&lt;', '<', $val);
                 $val = str_replace('&gt;', '>', $val);
                 //$val = preg_replace_callback('/&lt;([^&]*)&gt;/', create_function('$matches', 'return "<" . $matches[1] . ">";'), $val);
                 // in case of script which does not yet contain <!-- //--> around the actual code (i.e. first submission again)
                 // these will not be correctly removed by strip_tags
                 $val = preg_replace('/<script[^>]*>([^<]*)<\\/script>/', '', $val);
                 // remove any attempts to call an onclick/onmouseover/onwhatever call
                 $val = preg_replace_callback('/on[^= ]*=[^; \\/>]*;?"? *\\/? *(>?)/', create_function('$matches', 'if (isset($matches[1])) return $matches[1]; else return null;'), $val);
                 // now strip remaining tags including script tags with code surrounded by <!-- //-->,
                 // which would not be stripped by the previous regex
                 $val = strip_tags($val, '<p><a><b><strong><ol><ul><li><p><br><i><em><u><span>');
                 // remove empty <p> tags?
                 $val = preg_replace('/<p><\\/p>\\r?\\n?/', '', $val);
             }
             if ($oField->getDataType() == "LARGE TEXT" && !is_null($oField->getMaxLength())) {
                 if (strlen(strip_tags($val)) > $oField->getMaxLength()) {
                     $oForm->handleError(sprintf(_kt("Value exceeds max allowed length of %d characters for %s. Current value is %d characters."), $oField->getMaxLength(), $oField->getName(), strlen(strip_tags($val))));
                 }
             }
             // FIXME "null" has strange meanings here.
             if (!is_null($val)) {
                 if (KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && is_array($val) && $oField->getHasInetLookup()) {
                     $val = join(", ", $val);
                 }
                 $MDPack[] = array($oField, $val);
             }
         }
     }
     $this->startTransaction();
     if ($this->oDocument->getDocumentTypeId() != $doctypeid) {
         $this->oDocument->setDocumentTypeId($doctypeid);
     }
     $this->oDocument->setName($data['document_title']);
     $this->oDocument->setLastModifiedDate(getCurrentDateTime());
     $this->oDocument->setModifiedUserId($this->oUser->getId());
     // Update the content version / document version
     global $default;
     if ($default->updateContentVersion) {
         $this->oDocument->startNewContentVersion($this->oUser);
         $this->oDocument->setMinorVersionNumber($this->oDocument->getMinorVersionNumber() + 1);
     } else {
         $this->oDocument->startNewMetadataVersion($this->oUser);
     }
     $res = $this->oDocument->update();
     if (PEAR::isError($res)) {
         $oForm->handleError(sprintf(_kt("Unexpected failure to update document title: %s"), $res->getMessage()));
     }
     $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack);
     if (PEAR::isError($core_res)) {
         $oForm->handleError(sprintf(_kt("Unexpected validation failure: %s."), $core_res->getMessage()));
     }
     // post-triggers.
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array("document" => $this->oDocument, "aOptions" => $MDPack);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
     }
     $this->commitTransaction();
     // create the document transaction record
     $oDocumentTransaction =& new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update');
     $oDocumentTransaction->create();
     // 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 changes exists in the DB therefore update permissions after committing the transaction.
     $iPermissionObjectId = $this->oDocument->getPermissionObjectID();
     $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);
     if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) {
         $res = KTPermissionUtil::updatePermissionLookup($this->oDocument);
     }
     redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId()));
     exit(0);
 }