Commit 507e2fb8293207abd5dace73e3b7a87d78f9a2b6
1 parent
2e73f774
land Bryn Divey's Links work.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4726 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
8 changed files
with
524 additions
and
70 deletions
lib/documentmanagement/DocumentLink.inc
| ... | ... | @@ -31,94 +31,79 @@ class DocumentLink extends KTEntity { |
| 31 | 31 | /** primary key value */ |
| 32 | 32 | var $iId; |
| 33 | 33 | /** primary key of user responsible for creating document */ |
| 34 | - var $iParentDocumentID; | |
| 34 | + var $iParentDocumentId; | |
| 35 | 35 | /** document title name */ |
| 36 | - var $iChildDocumentID; | |
| 36 | + var $iChildDocumentId; | |
| 37 | 37 | /** type of link */ |
| 38 | - var $iLinkTypeID; | |
| 38 | + var $iLinkTypeId; | |
| 39 | + | |
| 40 | + | |
| 41 | + var $_aFieldToSelect = array( | |
| 42 | + 'iId' => 'id', | |
| 43 | + 'iParentDocumentId' => 'parent_document_id', | |
| 44 | + 'iChildDocumentId' => 'child_document_id', | |
| 45 | + 'iLinkTypeId' => 'link_type_id', | |
| 46 | + ); | |
| 47 | + | |
| 39 | 48 | |
| 40 | 49 | /** |
| 41 | 50 | * Default constructor |
| 42 | 51 | * |
| 43 | 52 | * @param Parent document primary key |
| 44 | 53 | * @param Child document primary key |
| 54 | + * @param Link type primary key | |
| 45 | 55 | * |
| 46 | 56 | */ |
| 47 | - function DocumentLink($iNewParentDocumentID, $iNewChildDocumentID, $iLinkTypeID) { | |
| 57 | + function DocumentLink($iNewParentDocumentID = null, $iNewChildDocumentID = null, $iLinkTypeId = null) { | |
| 48 | 58 | //object not created yet |
| 49 | 59 | global $default; |
| 50 | 60 | $this->iId = -1; |
| 51 | - $this->iParentDocumentID = $iNewParentDocumentID; | |
| 52 | - $this->iChildDocumentID = $iNewChildDocumentID; | |
| 53 | - $this->iLinkTypeID = $iLinkTypeID; | |
| 61 | + $this->iParentDocumentId = $iNewParentDocumentID; | |
| 62 | + $this->iChildDocumentId = $iNewChildDocumentID; | |
| 63 | + $this->iLinkTypeId = $iLinkTypeId; | |
| 54 | 64 | } |
| 55 | 65 | |
| 56 | - /** | |
| 57 | - * Get the document field's primary key value | |
| 58 | - * | |
| 59 | - * @return int document field's primary key value | |
| 60 | - * | |
| 61 | - */ | |
| 62 | - function getID() { | |
| 63 | - return $this->iId; | |
| 64 | - } | |
| 66 | + function getID() { return $this->iId; } | |
| 67 | + function getParentDocumentID() { return $this->iParentDocumentId; } | |
| 68 | + function setParentDocumentID($iNewValue) { $this->iParentDocumentId = $iNewValue; } | |
| 69 | + function getChildDocumentID() { return $this->iChildDocumentId; } | |
| 70 | + function setChildDocumentID($iNewValue) { $this->iChildDocumentId = $iNewValue; } | |
| 71 | + function getLinkTypeID() { return $this->iLinkTypeId; } | |
| 72 | + function setLinkTypeID($iNewValue) { $this->iLinkTypeId = $iNewValue; } | |
| 65 | 73 | |
| 66 | 74 | /** |
| 67 | - * Get the primary key of the parent document | |
| 75 | + * Helper getters | |
| 68 | 76 | */ |
| 69 | - function getParentDocumentID() { | |
| 70 | - return $this->iParentDocumentID; | |
| 71 | - } | |
| 72 | - | |
| 77 | + | |
| 73 | 78 | /** |
| 74 | - * Set the primary key of the parent document | |
| 75 | - * | |
| 76 | - * @param Primary key of parent document | |
| 77 | - * | |
| 79 | + * get parent document | |
| 78 | 80 | */ |
| 79 | - function setParentDocumentID($iNewValue) { | |
| 80 | - $this->iParentDocumentID = $iNewValue; | |
| 81 | - } | |
| 82 | - | |
| 81 | + function & getParentDocument() { | |
| 82 | + return Document::get($this->getParentDocumentId()); | |
| 83 | + } | |
| 84 | + | |
| 83 | 85 | /** |
| 84 | - * Get the child document's primary key | |
| 85 | - * | |
| 86 | - * @return int primary key of child document | |
| 87 | - * | |
| 86 | + * get child document | |
| 88 | 87 | */ |
| 89 | - function getChildDocumentID() { | |
| 90 | - return $this->iChildDocumentID; | |
| 91 | - } | |
| 92 | - | |
| 88 | + function & getChildDocument() { | |
| 89 | + $oDocument = Document::get($this->getChildDocumentId()); | |
| 90 | + return $oDocument; | |
| 91 | + } | |
| 92 | + | |
| 93 | 93 | /** |
| 94 | - * Set the child document's primary key | |
| 95 | - * | |
| 96 | - * @param Primary key of child document | |
| 97 | - * | |
| 94 | + * get link type | |
| 98 | 95 | */ |
| 99 | - function setChildDocumentID($iNewValue) { | |
| 100 | - $this->iChildDocumentID = $iNewValue; | |
| 101 | - } | |
| 96 | + function & getLinkType() { | |
| 97 | + return LinkType::get($this->getLinkTypeId()); | |
| 98 | + } | |
| 102 | 99 | |
| 103 | - /** | |
| 104 | - * Get the primary key of the link type | |
| 105 | - */ | |
| 106 | - function getLinkTypeID() { | |
| 107 | - return $this->iLinkTypeID; | |
| 108 | - } | |
| 109 | 100 | |
| 110 | - /** | |
| 111 | - * Set the primary key of the link type | |
| 112 | - */ | |
| 113 | - function setLinkTypeID($iNewValue) { | |
| 114 | - $this->iLinkTypeID = $iNewValue; | |
| 115 | - } | |
| 116 | 101 | |
| 117 | 102 | function _fieldValues () { |
| 118 | 103 | return array( |
| 119 | - 'parent_document_id' => $this->iParentDocumentID, | |
| 120 | - 'child_document_id' => $this->iChildDocumentID, | |
| 121 | - 'link_type_id' => $this->iLinkTypeID, | |
| 104 | + 'parent_document_id' => $this->iParentDocumentId, | |
| 105 | + 'child_document_id' => $this->iChildDocumentId, | |
| 106 | + 'link_type_id' => $this->iLinkTypeId, | |
| 122 | 107 | ); |
| 123 | 108 | } |
| 124 | 109 | |
| ... | ... | @@ -127,16 +112,11 @@ class DocumentLink extends KTEntity { |
| 127 | 112 | return $default->document_link_table; |
| 128 | 113 | } |
| 129 | 114 | |
| 130 | - /** | |
| 131 | - * Static function. | |
| 132 | - * Given a document_fields primary key it will create a | |
| 133 | - * DocumentFields object and populate it with the | |
| 134 | - * corresponding database values | |
| 135 | - * | |
| 136 | - * @return DocumentField populated DocumentField object on successful query, false otherwise and set $_SESSION["errorMessage"] | |
| 137 | - */ | |
| 115 | + | |
| 116 | + // static boilerplate | |
| 138 | 117 | function & get($iDocumentLinkID) { |
| 139 | 118 | global $default; |
| 119 | + | |
| 140 | 120 | $sql = $default->db; |
| 141 | 121 | $result = $sql->query(array("SELECT * FROM $default->document_link_table WHERE id = ?", $iDocumentLinkID));/*ok*/ |
| 142 | 122 | if ($result) { |
| ... | ... | @@ -151,5 +131,34 @@ class DocumentLink extends KTEntity { |
| 151 | 131 | $_SESSION["errorMessage"] = $lang_err_database; |
| 152 | 132 | return false; |
| 153 | 133 | } |
| 134 | + function getList($sWhereClause = null) { | |
| 135 | + return KTEntityUtil::getList2('DocumentLink', $sWhereClause); | |
| 136 | + } | |
| 137 | + function &createFromArray($aArray) { return KTEntityUtil::createFromArray('DocumentLink', $aArray); } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Static function | |
| 141 | + * Get a list of DocumentLinks where iDocumentId is the parent | |
| 142 | + * | |
| 143 | + * @param Integer Document ID of parent | |
| 144 | + * | |
| 145 | + * @return Array array of DocumentLink objects, false otherwise. | |
| 146 | + */ | |
| 147 | + function getLinksFromDocument($iDocumentId) { | |
| 148 | + return KTEntityUtil::getList2('DocumentLink', sprintf("parent_document_id = %d", $iDocumentId)); | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Static function | |
| 153 | + * Get a list of DocumentLinks where iDocumentId is the child | |
| 154 | + * | |
| 155 | + * @param Integer Document ID of child | |
| 156 | + * | |
| 157 | + * @return Array array of DocumentLink objects, false otherwise. | |
| 158 | + */ | |
| 159 | + function getLinksToDocument($iDocumentId) { | |
| 160 | + return KTEntityUtil::getList2('DocumentLink', sprintf("child_document_id = %d", $iDocumentId)); | |
| 161 | + } | |
| 154 | 162 | } |
| 163 | + | |
| 155 | 164 | ?> | ... | ... |
plugins/ktcore/admin/documentLinks.php
| ... | ... | @@ -139,6 +139,11 @@ class KTDocLinkAdminDispatcher extends KTAdminDispatcher { |
| 139 | 139 | $count = 0; |
| 140 | 140 | foreach ($types_to_delete as $link_id) { |
| 141 | 141 | $oLinkType = LinkType::get($link_id); |
| 142 | + | |
| 143 | + foreach(DocumentLink::getList(sprintf("link_type_id = %d", $link_id)) as $oLink) { | |
| 144 | + $oLink->delete(); | |
| 145 | + } | |
| 146 | + | |
| 142 | 147 | $oLinkType->delete(); // technically, this is a bad thing |
| 143 | 148 | $count += 1; |
| 144 | 149 | } | ... | ... |
plugins/ktstandard/KTDocumentLinks.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); | |
| 4 | +require_once(KT_LIB_DIR . '/documentmanagement/DocumentLink.inc'); | |
| 5 | +require_once(KT_LIB_DIR . '/documentmanagement/LinkType.inc'); | |
| 6 | + | |
| 7 | +require_once(KT_LIB_DIR . "/browse/DocumentCollection.inc.php"); | |
| 8 | +require_once(KT_LIB_DIR . "/browse/BrowseColumns.inc.php"); | |
| 9 | +require_once(KT_LIB_DIR . "/browse/PartialQuery.inc.php"); | |
| 10 | +require_once(KT_LIB_DIR . "/browse/browseutil.inc.php"); | |
| 11 | + | |
| 12 | + | |
| 13 | +class KTDocumentLinkTitle extends TitleColumn { | |
| 14 | + | |
| 15 | + function buildDocumentLink($aDataRow) { | |
| 16 | + $baseurl = KTUtil::arrayGet($this->aOptions, "folderurl", ""); | |
| 17 | + $parentDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); | |
| 18 | + return sprintf('%s?action=type_select&fDocumentId=%d&fTargetDocumentId=%d', $baseurl, $parentDocumentId, $aDataRow["document"]->getId()); | |
| 19 | + } | |
| 20 | + | |
| 21 | + function buildFolderLink($aDataRow) { | |
| 22 | + $baseurl = KTUtil::arrayGet($this->aOptions, "folderurl", ""); | |
| 23 | + $kt_path_info = KTUtil::arrayGet($_REQUEST, 'kt_path_info'); | |
| 24 | + $parentDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); | |
| 25 | + | |
| 26 | + if (empty($kt_path_info)) { | |
| 27 | + return sprintf('%s?action=new&fDocumentId=%d&fFolderId=%d', $baseurl, $parentDocumentId, $aDataRow["folder"]->getId()); | |
| 28 | + } else { | |
| 29 | + return sprintf('%s?kt_path_info=%s&action=new&ftDocumentId=%d&fFolderId=%d', $baseurl, $kt_path_info, $parentDocumentId, $aDataRow["folder"]->getId()); | |
| 30 | + } | |
| 31 | + } | |
| 32 | +} | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | +class KTDocumentLinks extends KTPlugin { | |
| 38 | + var $sNamespace = "ktstandard.documentlinks.plugin"; | |
| 39 | + | |
| 40 | + function setup() { | |
| 41 | + $this->registerAction('documentaction', 'KTDocumentLinkAction', 'ktcore.actions.document.link'); | |
| 42 | + } | |
| 43 | +} | |
| 44 | + | |
| 45 | +class KTDocumentLinkAction extends KTDocumentAction { | |
| 46 | + var $sDisplayName = 'Links'; | |
| 47 | + var $sName = 'ktcore.actions.document.link'; | |
| 48 | + | |
| 49 | + // display existing links | |
| 50 | + function do_main() { | |
| 51 | + $oTemplate =& $this->oValidator->validateTemplate('ktstandard/action/document_links'); | |
| 52 | + $this->oPage->setBreadcrumbDetails(_("Links")); | |
| 53 | + $this->oPage->setTitle(_("Links")); | |
| 54 | + | |
| 55 | + $oDocument = Document::get( | |
| 56 | + KTUtil::arrayGet($_REQUEST, 'fDocumentId', 0) | |
| 57 | + ); | |
| 58 | + | |
| 59 | + $oReadPermission =& KTPermission::getByName('ktcore.permissions.read'); | |
| 60 | + $oWritePermission =& KTPermission::getByName('ktcore.permissions.write'); | |
| 61 | + | |
| 62 | + | |
| 63 | + $aTemplateData = array( | |
| 64 | + 'context' => $this, | |
| 65 | + 'links_from' => DocumentLink::getLinksFromDocument($oDocument->getId()), | |
| 66 | + 'links_to' => DocumentLink::getLinksToDocument($oDocument->getId()), | |
| 67 | + 'read_permission' => KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oReadPermission, $this->oDocument), | |
| 68 | + 'write_permission' => KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oWritePermission, $this->oDocument), | |
| 69 | + ); | |
| 70 | + | |
| 71 | + | |
| 72 | + return $oTemplate->render($aTemplateData); | |
| 73 | + } | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + // select a target for the link | |
| 79 | + function do_new() { | |
| 80 | + $this->oPage->setBreadcrumbDetails(_("New Link")); | |
| 81 | + $this->oPage->setTitle(_("New Link")); | |
| 82 | + | |
| 83 | + $oPermission =& KTPermission::getByName('ktcore.permissions.write'); | |
| 84 | + if (PEAR::isError($oPermission) || | |
| 85 | + !KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument)) { | |
| 86 | + $this->errorRedirectToMain(_('You do not have sufficient permissions to add a document link'), sprintf("fDocumentId=%d", $this->oDocument->getId())); | |
| 87 | + exit(0); | |
| 88 | + } | |
| 89 | + | |
| 90 | + $oParentDocument =& $this->oDocument; | |
| 91 | + | |
| 92 | + if (PEAR::isError($oParentDocument)) { | |
| 93 | + $this->errorRedirectToMain(_('Invalid parent document selected.')); | |
| 94 | + exit(0); | |
| 95 | + } | |
| 96 | + | |
| 97 | + $oFolder = Folder::get(KTUtil::arrayGet($_REQUEST, 'fFolderId', $oParentDocument->getFolderID())); | |
| 98 | + if (PEAR::isError($oFolder) || ($oFolder == false)) { | |
| 99 | + $this->errorRedirectToMain(_('Invalid folder selected.')); | |
| 100 | + exit(0); | |
| 101 | + } | |
| 102 | + $iFolderId = $oFolder->getId(); | |
| 103 | + | |
| 104 | + // Setup the collection for move display. | |
| 105 | + | |
| 106 | + $collection = new DocumentCollection(); | |
| 107 | + $collection->addColumn(new KTDocumentLinkTitle("Target Documents","title")); | |
| 108 | + | |
| 109 | + $qObj = new BrowseQuery($iFolderId); | |
| 110 | + $collection->setQueryObject($qObj); | |
| 111 | + | |
| 112 | + $batchPage = (int) KTUtil::arrayGet($_REQUEST, "page", 0); | |
| 113 | + $batchSize = 20; | |
| 114 | + | |
| 115 | + $resultURL = sprintf("?action=new&fDocumentId=%d", $oParentDocument->getId()); | |
| 116 | + $collection->setBatching($resultURL, $batchPage, $batchSize); | |
| 117 | + | |
| 118 | + // ordering. (direction and column) | |
| 119 | + $displayOrder = KTUtil::arrayGet($_REQUEST, 'sort_order', "asc"); | |
| 120 | + if ($displayOrder !== "asc") { $displayOrder = "desc"; } | |
| 121 | + $displayControl = KTUtil::arrayGet($_REQUEST, 'sort_on', "title"); | |
| 122 | + | |
| 123 | + $collection->setSorting($displayControl, $displayOrder); | |
| 124 | + | |
| 125 | + $collection->getResults(); | |
| 126 | + | |
| 127 | + $aBreadcrumbs = array(); | |
| 128 | + $folder_path_names = $oFolder->getPathArray(); | |
| 129 | + $folder_path_ids = explode(',', $oFolder->getParentFolderIds()); | |
| 130 | + | |
| 131 | + if ($folder_path_ids[0] == 0) { | |
| 132 | + $folder_path_ids = array(); | |
| 133 | + } | |
| 134 | + $folder_path_ids[] = $oFolder->getId(); | |
| 135 | + | |
| 136 | + foreach (range(0, count($folder_path_ids) - 1) as $index) { | |
| 137 | + $id = $folder_path_ids[$index]; | |
| 138 | + $url = sprintf("?action=new&fDocumentId=%d&fFolderId=%d", $oParentDocument->getId(), $id); | |
| 139 | + $aBreadcrumbs[] = array("url" => $url, "name" => $folder_path_names[$index]); | |
| 140 | + } | |
| 141 | + | |
| 142 | + $aTemplateData = array( | |
| 143 | + 'context' => $this, | |
| 144 | + 'folder' => $oFolder, | |
| 145 | + 'breadcrumbs' => $aBreadcrumbs, | |
| 146 | + 'collection' => $collection, | |
| 147 | + 'collection_breadcrumbs' => $aBreadcrumbs, | |
| 148 | + 'link_types' => LinkType::getList("id > 0"), | |
| 149 | + ); | |
| 150 | + | |
| 151 | + $oTemplate =& $this->oValidator->validateTemplate('ktstandard/action/link'); | |
| 152 | + return $oTemplate->render($aTemplateData); | |
| 153 | + } | |
| 154 | + | |
| 155 | + // select a type for the link | |
| 156 | + function do_type_select() { | |
| 157 | + $this->oPage->setBreadcrumbDetails(_("link")); | |
| 158 | + | |
| 159 | + $oParentDocument = Document::get(KTUtil::arrayGet($_REQUEST, 'fDocumentId')); | |
| 160 | + if (PEAR::isError($oParentDocument)) { | |
| 161 | + $this->errorRedirectToMain(_('Invalid parent document selected.')); | |
| 162 | + exit(0); | |
| 163 | + } | |
| 164 | + | |
| 165 | + $oTargetDocument = Document::get(KTUtil::arrayGet($_REQUEST, 'fTargetDocumentId')); | |
| 166 | + if (PEAR::isError($oTargetDocument)) { | |
| 167 | + $this->errorRedirectToMain(_('Invalid target document selected.')); | |
| 168 | + exit(0); | |
| 169 | + } | |
| 170 | + | |
| 171 | + | |
| 172 | + // form fields | |
| 173 | + $aFields = array(); | |
| 174 | + | |
| 175 | + $aVocab = array(); | |
| 176 | + foreach(LinkType::getList("id > 0") as $oLinkType) { | |
| 177 | + $aVocab[$oLinkType->getID()] = $oLinkType->getName(); | |
| 178 | + } | |
| 179 | + | |
| 180 | + $aOptions = array('vocab' => $aVocab); | |
| 181 | + $aFields[] = new KTLookupWidget( | |
| 182 | + _('Link Type'), | |
| 183 | + _('The type of link you wish to use'), | |
| 184 | + 'fLinkTypeId', | |
| 185 | + null, | |
| 186 | + $this->oPage, | |
| 187 | + true, | |
| 188 | + null, | |
| 189 | + null, | |
| 190 | + $aOptions); | |
| 191 | + | |
| 192 | + $aTemplateData = array( | |
| 193 | + 'context' => $this, | |
| 194 | + 'parent_id' => $oParentDocument->getId(), | |
| 195 | + 'target_id' => $oTargetDocument->getId(), | |
| 196 | + 'fields' => $aFields, | |
| 197 | + ); | |
| 198 | + | |
| 199 | + $oTemplate =& $this->oValidator->validateTemplate('ktstandard/action/link_type_select'); | |
| 200 | + return $oTemplate->render($aTemplateData); | |
| 201 | + | |
| 202 | + | |
| 203 | + } | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + // make the link | |
| 208 | + function do_make_link() { | |
| 209 | + $this->oPage->setBreadcrumbDetails(_("link")); | |
| 210 | + | |
| 211 | + // check validity of things | |
| 212 | + $oParentDocument = Document::get(KTUtil::arrayGet($_REQUEST, 'fDocumentId')); | |
| 213 | + if (PEAR::isError($oParentDocument)) { | |
| 214 | + $this->errorRedirectToMain(_('Invalid parent document selected.')); | |
| 215 | + exit(0); | |
| 216 | + } | |
| 217 | + | |
| 218 | + $oTargetDocument = Document::get(KTUtil::arrayGet($_REQUEST, 'fTargetDocumentId')); | |
| 219 | + if (PEAR::isError($oTargetDocument)) { | |
| 220 | + $this->errorRedirectToMain(_('Invalid target document selected.')); | |
| 221 | + exit(0); | |
| 222 | + } | |
| 223 | + | |
| 224 | + $oLinkType = LinkType::get(KTUtil::arrayGet($_REQUEST, 'fLinkTypeId')); | |
| 225 | + if (PEAR::isError($oLinkType)) { | |
| 226 | + $this->errorRedirectToMain(_('Invalid link type selected.')); | |
| 227 | + exit(0); | |
| 228 | + } | |
| 229 | + | |
| 230 | + | |
| 231 | + // create document link | |
| 232 | + $this->startTransaction(); | |
| 233 | + | |
| 234 | + $oDocumentLink =& DocumentLink::createFromArray(array( | |
| 235 | +/* 'parent_document_id' => $oParentDocument->getId(), | |
| 236 | + 'child_document_id' => $oTargetDocument->getId(), | |
| 237 | + 'link_type_id' => $oLinkType->getId(),*/ | |
| 238 | + 'iParentDocumentId' => $oParentDocument->getId(), | |
| 239 | + 'iChildDocumentId' => $oTargetDocument->getId(), | |
| 240 | + 'iLinkTypeId' => $oLinkType->getId(), | |
| 241 | + )); | |
| 242 | + | |
| 243 | + if (PEAR::isError($oDocumentLink)) { | |
| 244 | + $this->errorRedirectToMain(_('Could not create document link'), sprintf('fDocumentId=%d', $oParentDocument->getId())); | |
| 245 | + exit(0); | |
| 246 | + } | |
| 247 | + | |
| 248 | + $this->commitTransaction(); | |
| 249 | + | |
| 250 | + $this->successRedirectToMain(_('Document link created'), sprintf('fDocumentId=%d', $oParentDocument->getId())); | |
| 251 | + exit(0); | |
| 252 | + } | |
| 253 | + | |
| 254 | + | |
| 255 | + // delete a link | |
| 256 | + function do_delete() { | |
| 257 | + $this->oPage->setBreadcrumbDetails(_("link")); | |
| 258 | + | |
| 259 | + // check security | |
| 260 | + $oPermission =& KTPermission::getByName('ktcore.permissions.write'); | |
| 261 | + if (PEAR::isError($oPermission) || | |
| 262 | + !KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument)) { | |
| 263 | + $this->errorRedirectToMain(_('You do not have sufficient permissions to delete a link'), sprintf("fDocumentId=%d", $this->oDocument->getId())); | |
| 264 | + exit(0); | |
| 265 | + } | |
| 266 | + | |
| 267 | + | |
| 268 | + // check validity of things | |
| 269 | + $oDocumentLink = DocumentLink::get(KTUtil::arrayGet($_REQUEST, 'fDocumentLinkId')); | |
| 270 | + if (PEAR::isError($oDocumentLink)) { | |
| 271 | + $this->errorRedirectToMain(_('Invalid document link selected.')); | |
| 272 | + exit(0); | |
| 273 | + } | |
| 274 | + $oParentDocument = Document::get(KTUtil::arrayGet($_REQUEST, 'fDocumentId')); | |
| 275 | + if (PEAR::isError($oParentDocument)) { | |
| 276 | + $this->errorRedirectToMain(_('Invalid document selected.')); | |
| 277 | + exit(0); | |
| 278 | + } | |
| 279 | + | |
| 280 | + // do deletion | |
| 281 | + $this->startTransaction(); | |
| 282 | + | |
| 283 | + $res = $oDocumentLink->delete(); | |
| 284 | + | |
| 285 | + if (PEAR::isError($res)) { | |
| 286 | + $this->errorRedirectToMain(_('Could not delete document link'), sprintf('fDocumentId=%d', $oParentDocument->getId())); | |
| 287 | + exit(0); | |
| 288 | + } | |
| 289 | + | |
| 290 | + $this->commitTransaction(); | |
| 291 | + | |
| 292 | + $this->successRedirectToMain(_('Document link deleted'), sprintf('fDocumentId=%d', $oParentDocument->getId())); | |
| 293 | + exit(0); | |
| 294 | + } | |
| 295 | + | |
| 296 | + | |
| 297 | +} | |
| 298 | + | |
| 299 | +$oRegistry =& KTPluginRegistry::getSingleton(); | |
| 300 | +$oRegistry->registerPlugin('KTDocumentLinks', 'ktstandard.documentlinks.plugin', __FILE__); | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | +?> | |
| 0 | 305 | \ No newline at end of file | ... | ... |
plugins/ktstandard/KTStandardPlugin.php
| ... | ... | @@ -4,6 +4,8 @@ require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); |
| 4 | 4 | require_once('KTSubscriptions.php'); |
| 5 | 5 | require_once('KTDiscussion.php'); |
| 6 | 6 | require_once('KTEmail.php'); |
| 7 | - | |
| 8 | 7 | require_once('KTIndexer.php'); |
| 9 | -require_once('KTWorkflowAssociation.php'); | |
| 10 | 8 | \ No newline at end of file |
| 9 | +require_once('KTDocumentLinks.php'); | |
| 10 | +require_once('KTWorkflowAssociation.php'); | |
| 11 | + | |
| 12 | +?> | ... | ... |
sql/mysql/install/data.sql
| ... | ... | @@ -167,7 +167,7 @@ INSERT INTO `document_transaction_types_lookup` VALUES (16, 'Workflow state tran |
| 167 | 167 | -- Dumping data for table `document_types_lookup` |
| 168 | 168 | -- |
| 169 | 169 | |
| 170 | -INSERT INTO `document_types_lookup` VALUES (1, 'Default'); | |
| 170 | +INSERT INTO `document_types_lookup` VALUES (1, 'Default',0); | |
| 171 | 171 | |
| 172 | 172 | -- |
| 173 | 173 | -- Dumping data for table `documents` | ... | ... |
templates/ktstandard/action/document_links.smarty
0 → 100644
| 1 | +<h2>{i18n}Document Links{/i18n}</h2> | |
| 2 | + | |
| 3 | + | |
| 4 | +<p class="descriptiveText">{i18n}The current links to and from this document are displayed below.{/i18n}</p> | |
| 5 | + | |
| 6 | + | |
| 7 | +<table class="kt_collection" cellspacing="0" cellpadding="0" style="width: auto;"> | |
| 8 | + <thead> | |
| 9 | + <tr> | |
| 10 | + <th style="width:1em"> </th> | |
| 11 | + <th>{i18n}Target{/i18n}</th> | |
| 12 | + <th>{i18n}Type{/i18n}</th> | |
| 13 | + <th>{i18n}Relationship{/i18n}</th> | |
| 14 | + </tr> | |
| 15 | + </thead> | |
| 16 | + | |
| 17 | + <tbody> | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | +{if $links_from || $links_to} | |
| 24 | + | |
| 25 | +{foreach from=$links_from item=link} | |
| 26 | + | |
| 27 | +{assign var="type" value=$link->getLinkType()} | |
| 28 | +{assign var="target" value=$link->getChildDocument()} | |
| 29 | + | |
| 30 | + <tr> | |
| 31 | + <td><a href="?action=delete&fDocumentId={$context->oDocument->getId()}&fDocumentLinkId={$link->getId()}" class="ktAction ktDelete">Delete</a></td> | |
| 32 | + <td><a href="{"viewDocument"|generateControllerUrl}&qs[fDocumentId]={$target->getId()}&qs[action]=main">{$target->getName()}</a></td> | |
| 33 | + <td>{$type->getName()}</td> | |
| 34 | + <td>Linked <b>from</b> this document</td> | |
| 35 | + </tr> | |
| 36 | + | |
| 37 | +{/foreach} | |
| 38 | + | |
| 39 | +{foreach from=$links_to item=link} | |
| 40 | + | |
| 41 | +{assign var="type" value=$link->getLinkType()} | |
| 42 | +{assign var="target" value=$link->getParentDocument()} | |
| 43 | + | |
| 44 | + <tr> | |
| 45 | + <td> | |
| 46 | +{if $write_permission} | |
| 47 | + <a class="ktAction ktDelete">Delete</a></td> | |
| 48 | +{else} | |
| 49 | + | |
| 50 | +{/if} | |
| 51 | + <td><a href="{$target->getId()}">{$target->getName()}</a></td> | |
| 52 | + <td>{$type->getName()}</td> | |
| 53 | + <td>Links <b>to</b> this document</td> | |
| 54 | + </tr> | |
| 55 | + | |
| 56 | +{/foreach} | |
| 57 | + | |
| 58 | + | |
| 59 | +{else} | |
| 60 | +<tr><td colspan="4" align="center">There are no links to or from this document.</td></tr> | |
| 61 | +{/if} | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + </tbody> | |
| 66 | +</table> | |
| 67 | +<br/> | |
| 68 | + | |
| 69 | + | |
| 70 | +{if $write_permission} | |
| 71 | +<a class="ktAction ktAdd ktInline" href="?action=new&fDocumentId={$context->oDocument->getId()}">Add a new link</a> | |
| 72 | +<a href="?action=new&fDocumentId={$context->oDocument->getId()}&fFolderId={$context->oDocument->getFolderId()}">Add a new link</a>. | |
| 73 | +{/if} | |
| 74 | + | ... | ... |
templates/ktstandard/action/link.smarty
0 → 100644
| 1 | +<h2>{i18n}Add Link{/i18n}</h2> | |
| 2 | + | |
| 3 | + | |
| 4 | +{if $link_types} | |
| 5 | +<p class="descriptiveText">{i18n}Select a target document to link to.{/i18n} | |
| 6 | +</p> | |
| 7 | + | |
| 8 | +<form method="POST" action="{$smarty.server.PHP_SELF}"> | |
| 9 | + | |
| 10 | +<p class="descriptiveText">{i18n}Use the folder collection and path below to | |
| 11 | +browse to the document you wish to link to.{/i18n}</p> | |
| 12 | + | |
| 13 | +<input type="hidden" name="fFolderId" value="{$folder->getId()}" /> | |
| 14 | + | |
| 15 | +{foreach from=$collection_breadcrumbs item=breadcrumb name=bc} | |
| 16 | + | |
| 17 | +<a href="{$breadcrumb.url}">{$breadcrumb.name}</a> | |
| 18 | + | |
| 19 | +{if !$smarty.foreach.bc.last} | |
| 20 | +» | |
| 21 | +{/if} | |
| 22 | + | |
| 23 | +{/foreach} | |
| 24 | + | |
| 25 | + | |
| 26 | +{$collection->render()} | |
| 27 | +</div> | |
| 28 | + | |
| 29 | +<div class="form_actions"> | |
| 30 | +<input type="submit" name="submit[move]" value="{i18n}Link{/i18n}" /> | |
| 31 | +</div> | |
| 32 | +</fieldset> | |
| 33 | +</form> | |
| 34 | + | |
| 35 | +{else} | |
| 36 | +<div class="ktInfo"><p> | |
| 37 | +{i18n}No link types are defined. Please ask the administrator to add them.{/i18n}</p></div> | |
| 38 | + | |
| 39 | +{/if} | |
| 0 | 40 | \ No newline at end of file | ... | ... |
templates/ktstandard/action/link_type_select.smarty
0 → 100644
| 1 | +<h2>{i18n}Add Link{/i18n}</h2> | |
| 2 | + | |
| 3 | +<form method="POST" action="{$smarty.server.PHP_SELF}"> | |
| 4 | + | |
| 5 | +<input type="hidden" name="action" value="make_link" /> | |
| 6 | +<input type="hidden" name="fDocumentId" value="{$parent_id}" /> | |
| 7 | +<input type="hidden" name="fTargetDocumentId" value="{$target_id}" /> | |
| 8 | + | |
| 9 | +<fieldset> | |
| 10 | +<legend>{i18n}Select a link type.{/i18n}</legend> | |
| 11 | + | |
| 12 | +{foreach item=oWidget from=$fields} | |
| 13 | +{$oWidget->render()} | |
| 14 | +{/foreach} | |
| 15 | +</fieldset> | |
| 16 | + | |
| 17 | +<div class="form_actions"> | |
| 18 | +<input type="submit" name="submit[move]" value="{i18n}Link{/i18n}" /> | |
| 19 | +</div> | |
| 20 | +</fieldset> | |
| 21 | +</form> | ... | ... |