Commit fab7b22d4a0761a2d113fa0a265e333b27fe2581

Authored by nbm
1 parent 5620e417

View and download previous metadata versions from a metadata version

list.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3533 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/viewUI.inc
@@ -43,19 +43,21 @@ function renderDocumentPath($oDocument, $bDisplayActions = false) { @@ -43,19 +43,21 @@ function renderDocumentPath($oDocument, $bDisplayActions = false) {
43 43
44 function renderDocumentData($oDocument, $bEditable, $sStatusMessage = "") { 44 function renderDocumentData($oDocument, $bEditable, $sStatusMessage = "") {
45 global $default; 45 global $default;
46 - /*ok*/ $sQuery = array("SELECT D.id, D.name, D.modified, DTT.datetime AS created, D.size, U.name AS initiator, CONCAT(CONCAT(D.major_version, '.'), D.minor_version) AS version, WDSL.name AS status, DTL.name AS document_type, D.is_checked_out, COALESCE(U2.name, '') AS c_user " .  
47 - "FROM $default->documents_table AS D INNER JOIN $default->web_documents_table AS WD ON WD.document_id = D.ID " .  
48 - "INNER JOIN $default->web_documents_status_table AS WDSL ON WD.status_id = WDSL.id " . 46 + $iVersionID = KTUtil::arrayGet($_REQUEST, 'fVersionID');
  47 + $aDocuments = array($oDocument->getID());
  48 + if (!empty($iVersionID)) {
  49 + $aDocuments[] = $iVersionID;
  50 + }
  51 + $sWhere = DBUtil::paramArray($aDocuments);
  52 + /*ok*/ $sQuery = array("SELECT D.id, D.name, D.modified, D.created, D.size, U.name AS initiator, D.metadata_version, CONCAT(CONCAT(D.major_version, '.'), D.minor_version) AS version, DTL.name AS document_type, D.is_checked_out, COALESCE(U2.name, '') AS c_user " .
  53 + "FROM $default->documents_table AS D " .
49 "LEFT JOIN $default->users_table AS U ON U.id = D.creator_id " . 54 "LEFT JOIN $default->users_table AS U ON U.id = D.creator_id " .
50 - "INNER JOIN $default->document_transactions_table AS DTT ON DTT.document_id = D.id " .  
51 - "INNER JOIN $default->transaction_types_table AS TT ON DTT.transaction_id = TT.id " .  
52 "INNER JOIN $default->document_types_table AS DTL ON DTL.id = D.document_type_id " . 55 "INNER JOIN $default->document_types_table AS DTL ON DTL.id = D.document_type_id " .
53 "LEFT OUTER JOIN $default->users_table AS U2 ON U2.id = D.checked_out_user_id " . 56 "LEFT OUTER JOIN $default->users_table AS U2 ON U2.id = D.checked_out_user_id " .
54 - "WHERE D.id = ? " .  
55 - "AND TT.name LIKE 'Create'", $oDocument->getID()); 57 + "WHERE D.id IN ($sWhere) ", $aDocuments);
56 58
57 - $aColumns = array("id", "name", "modified", "created", "size", "initiator", "document_type", "version", "status", "c_user");  
58 - $aColumnNames = array(_("ID"), _("Document title"), _("Last updated"), _("Created"), _("File Size"), _("Document initiator"), _("Document Type"), _("Version"), _("Status"), _("Checked out by")); 59 + $aColumns = array("metadata_version", "name", "modified", "created", "size", "initiator", "document_type", "c_user", "id", "version");
  60 + $aColumnNames = array(_("Metadata Version"), _("Document title"), _("Last updated"), _("Created"), _("File Size"), _("Document initiator"), _("Document Type"), _("Checked out by"), _("ID"), _("Document Version"),);
59 $aColumnTypes = array(1,1,1,1,1,1,1,1,1,1); 61 $aColumnTypes = array(1,1,1,1,1,1,1,1,1,1);
60 $oPatternListFromQuery = & new PatternListFromQuery($sQuery, $aColumns, $aColumnNames, $aColumnTypes); 62 $oPatternListFromQuery = & new PatternListFromQuery($sQuery, $aColumns, $aColumnNames, $aColumnTypes);
61 $oPatternListFromQuery->setTableHeading(_("Document Data")); 63 $oPatternListFromQuery->setTableHeading(_("Document Data"));
@@ -82,60 +84,107 @@ function renderDocumentData($oDocument, $bEditable, $sStatusMessage = "") { @@ -82,60 +84,107 @@ function renderDocumentData($oDocument, $bEditable, $sStatusMessage = "") {
82 84
83 function renderGenericMetaData($oDocument, $bEditable) { 85 function renderGenericMetaData($oDocument, $bEditable) {
84 global $default; 86 global $default;
85 - /*ok*/ $sQuery = array("SELECT DF.name AS name, DFL.value as value " . 87 + $iVersionID = KTUtil::arrayGet($_REQUEST, 'fVersionID');
  88 + $aDocuments = array($oDocument->getID());
  89 + if (!empty($iVersionID)) {
  90 + $aDocuments[] = $iVersionID;
  91 + }
  92 + /*ok*/ $sQuery = "SELECT DF.name AS name, DFL.value as value " .
86 "FROM $default->documents_table AS D INNER JOIN $default->document_fields_link_table AS DFL ON D.id = DFL.document_id " . 93 "FROM $default->documents_table AS D INNER JOIN $default->document_fields_link_table AS DFL ON D.id = DFL.document_id " .
87 "INNER JOIN $default->document_fields_table AS DF ON DF.id = DFL.document_field_id " . 94 "INNER JOIN $default->document_fields_table AS DF ON DF.id = DFL.document_field_id " .
88 "WHERE document_id = ? " . 95 "WHERE document_id = ? " .
89 - "AND DF.is_generic = 1", $oDocument->getID());  
90 - $aColumns = array("name", "value");  
91 - $aColumnHeaders = array("Tag", "Value");  
92 - $aColumnTypes = array(1,1);  
93 - $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaders, "500");  
94 - $oPatternTableSqlQuery->setTableHeading(_("Generic Meta Data"));  
95 - $oPatternTableSqlQuery->setEmptyTableMessage(_("No Generic Meta Data"));  
96 -  
97 - $sToRender .= "\t<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";  
98 - $sToRender .= "\t<tr>\n";  
99 - $sToRender .= "\t<td>" . $oPatternTableSqlQuery->render() . "</td>\n";  
100 - $sToRender .= "\t</tr>\n"; 96 + "AND DF.is_generic = 1";
  97 +
  98 +
  99 + $iDocumentsLen = count($aDocuments);
  100 + $map = array();
  101 + $iDocumentCount = 0;
  102 + foreach ($aDocuments as $iDocumentID) {
  103 + $map['Metadata Version'] = KTUtil::arrayGet($map, 'Metadata Version', array_fill(0, $iDocumentsLen, null));
  104 + $oThisDocument =& Document::get($iDocumentID);
  105 + if (PEAR::isError($oThisDocument)) {
  106 + continue;
  107 + }
  108 + if ($oThisDocument === false) {
  109 + continue;
  110 + }
  111 + $map['Metadata Version'][$iDocumentCount] = $oThisDocument->getMetadataVersion();
  112 + $aTDRows = DBUtil::getResultArray(array($sQuery, array($iDocumentID)));
  113 + foreach ($aTDRows as $aRow) {
  114 + $newarray = KTUtil::arrayGet($map, $aRow['name'], array_fill(0, $iDocumentsLen, null));
  115 + $newarray[$iDocumentCount] = $aRow['value'];
  116 + $map[$aRow['name']] = $newarray;
  117 + }
  118 + $iDocumentCount++;
  119 + }
  120 +
  121 + $oTemplating =& KTTemplating::getSingleton();
  122 + $oTemplate = $oTemplating->loadTemplate('ktcore/document_generic_metadata');
101 if ($bEditable) { 123 if ($bEditable) {
102 - $sToRender .= "\t<tr>\n";  
103 - $sToRender .= "<td><a href=\"$default->rootUrl/control.php?action=modifyDocumentGenericMetaData&fDocumentID=" . $oDocument->getID() . "\"><img src=\"" . KTHtml::getEditButton() . "\" border=\"0\"></a></td>\n";  
104 - $sToRender .= "\t</tr>\n"; 124 + $editable = "<a href=\"$default->rootUrl/control.php?action=modifyDocumentGenericMetaData&fDocumentID=" . $oDocument->getID() . "\"><img src=\"" . KTHtml::getEditButton() . "\" border=\"0\"></a>";
  125 + } else {
  126 + $editable = "";
105 } 127 }
106 - $sToRender .= "\t</table>\n"; 128 + $sToRender .= $oTemplate->render(array(
  129 + 'map' => $map,
  130 + 'editable' => $editable,
  131 + ));
107 132
108 return $sToRender; 133 return $sToRender;
109 } 134 }
110 135
111 function renderTypeSpecificMetaData($oDocument, $bEditable) { 136 function renderTypeSpecificMetaData($oDocument, $bEditable) {
112 global $default; 137 global $default;
  138 + $iVersionID = KTUtil::arrayGet($_REQUEST, 'fVersionID');
  139 + $aDocuments = array($oDocument->getID());
  140 + if (!empty($iVersionID)) {
  141 + $aDocuments[] = $iVersionID;
  142 + }
113 143
114 - /*ok*/ $sQuery = array("SELECT DF.name AS name, DFL.value AS value " . 144 + /*ok*/ $sQuery = "SELECT DF.name AS name, DFL.value AS value " .
115 "FROM $default->documents_table AS D INNER JOIN document_fields_link AS DFL ON D.id = DFL.document_id " . 145 "FROM $default->documents_table AS D INNER JOIN document_fields_link AS DFL ON D.id = DFL.document_id " .
116 "INNER JOIN $default->document_fields_table AS DF ON DF.ID = DFL.document_field_id " . 146 "INNER JOIN $default->document_fields_table AS DF ON DF.ID = DFL.document_field_id " .
117 "WHERE D.id = ? " . 147 "WHERE D.id = ? " .
118 "AND DF.name NOT LIKE 'Category' " . 148 "AND DF.name NOT LIKE 'Category' " .
119 - "AND DF.is_generic = 0", $oDocument->getID());  
120 - $aColumns = array("name", "value");  
121 - $aColumnHeaders = array("Tag", "Value");  
122 - $aColumnTypes = array(1,1);  
123 - $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaders, "500");  
124 - $oPatternTableSqlQuery->setTableHeading(_("Type Specific Meta Data"));  
125 - $oPatternTableSqlQuery->setEmptyTableMessage(_("No Type Specific Meta Data"));  
126 -  
127 - $sToRender .= "\t<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";  
128 - $sToRender .= "\t<tr>\n";  
129 - $sToRender .= "\t\t<td>" . $oPatternTableSqlQuery->render() . "</td>\n";  
130 - $sToRender .= "\t</tr>\n"; 149 + "AND DF.is_generic = 0";
  150 +
  151 + $iDocumentsLen = count($aDocuments);
  152 + $map = array();
  153 + $iDocumentCount = 0;
  154 + foreach ($aDocuments as $iDocumentID) {
  155 + $map['Metadata Version'] = KTUtil::arrayGet($map, 'Metadata Version', array_fill(0, $iDocumentsLen, null));
  156 + $oThisDocument =& Document::get($iDocumentID);
  157 + if (PEAR::isError($oThisDocument)) {
  158 + continue;
  159 + }
  160 + if ($oThisDocument === false) {
  161 + continue;
  162 + }
  163 + $map['Metadata Version'][$iDocumentCount] = $oThisDocument->getMetadataVersion();
  164 + $aTDRows = DBUtil::getResultArray(array($sQuery, array($iDocumentID)));
  165 + foreach ($aTDRows as $aRow) {
  166 + $newarray = KTUtil::arrayGet($map, $aRow['name'], array_fill(0, $iDocumentsLen, null));
  167 + $newarray[$iDocumentCount] = $aRow['value'];
  168 + $map[$aRow['name']] = $newarray;
  169 + }
  170 + $iDocumentCount++;
  171 + }
  172 +
  173 + $oTemplating =& KTTemplating::getSingleton();
  174 + $oTemplate = $oTemplating->loadTemplate('ktcore/document_specific_metadata');
131 if ($bEditable) { 175 if ($bEditable) {
132 - $sToRender .= "\t<tr>\n";  
133 - $sToRender .= "<td><a href=\"$default->rootUrl/control.php?action=modifyDocumentTypeMetaData&fDocumentID=" . $oDocument->getID() . "\"><img src=\"" . KTHtml::getEditButton() . "\" border=\"0\"></a></td>\n";  
134 - $sToRender .= "\t</tr>\n"; 176 + $editable = "<a href=\"$default->rootUrl/control.php?action=modifyDocumentTypeMetaData&fDocumentID=" . $oDocument->getID() . "\"><img src=\"" . KTHtml::getEditButton() . "\" border=\"0\"></a>";
  177 + } else {
  178 + $editable = "";
135 } 179 }
136 - $sToRender .= "\t</table>\n";  
137 - return $sToRender; 180 + $sToRender = $oTemplate->render(array(
  181 + 'map' => $map,
  182 + 'editable' => $editable,
  183 + ));
  184 +
  185 + return $sToRender;
138 } 186 }
  187 +
139 function renderDocumentArchiveSettingsDetails($oDocument, $bEditable) { 188 function renderDocumentArchiveSettingsDetails($oDocument, $bEditable) {
140 global $default; 189 global $default;
141 190
@@ -382,6 +431,35 @@ function renderDependantDocuments($oDocument, $bEdit) { @@ -382,6 +431,35 @@ function renderDependantDocuments($oDocument, $bEdit) {
382 return $sToRender; 431 return $sToRender;
383 } 432 }
384 433
  434 +function renderDocumentVersions ($oDocument) {
  435 + $aVersions = Document::getByLiveDocument($oDocument);
  436 + $sToRender = "<table class=\"pretty\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
  437 + $sToRender .= "<thead><tr><th>Metadata Version</th><th>Modified date</th><th>Document Version</th></tr></thead>\n";
  438 + $sToRender .= "<tbody>\n";
  439 + $iDocumentID = $oDocument->getID();
  440 + $sLink = generateControllerLink('viewDocument', "fDocumentID=$iDocumentID");
  441 + $sDocumentLink = generateControllerLink("downloadDocument", "fDocumentID=$iDocumentID");
  442 + $sToRender .= sprintf('<tr><td><a href="%s">%s</a> (Live)</td><td>%s</td><td><a href="%s">%s</a></tr>%s', $sLink, $oDocument->getMetadataVersion(), $oDocument->getLastModifiedDate(), $sDocumentLink, $oDocument->getVersion(), "\n");
  443 + foreach ($aVersions as $oVersion) {
  444 + $iDocumentVersionID = $oVersion->getVersion();
  445 + if ($iDocumentVersionID == $oDocument->getVersion()) {
  446 + $sDocumentLink = generateControllerLink("downloadDocument", "fDocumentID=$iDocumentID");
  447 + } else {
  448 + $sDocumentLink = generateControllerLink("downloadDocument", "fDocumentID=$iDocumentID&fVersion=$iDocumentVersionID");
  449 + }
  450 + $sToRender .= "<tr>\n";
  451 + $iVersionID = $oVersion->getID();
  452 + $sLink = generateControllerLink('viewDocument', "fDocumentID=$iDocumentID&fVersionID=$iVersionID");
  453 + $sToRender .= sprintf('<td><a href="%s">%s</a></td>%s', $sLink, $oVersion->getMetadataVersion(), "\n");
  454 + $sToRender .= sprintf('<td>%s</td>%s', $oVersion->getLastModifiedDate(), "\n");
  455 + $sToRender .= sprintf('<td><a href="%s">%s</td>%s', $sDocumentLink, $oVersion->getVersion(), "\n");
  456 + $sToRender .= "</tr>\n";
  457 + }
  458 + $sToRender .= "</tbody>\n";
  459 + $sToRender .= "</table>\n";
  460 + return $sToRender;
  461 +}
  462 +
385 // This array exists only to give gettext a hint that these buttons 463 // This array exists only to give gettext a hint that these buttons
386 // should be added to the .po file. 464 // should be added to the .po file.
387 465
@@ -640,6 +718,7 @@ function getPage($oDocument, $bEdit, $sStatusMessage = &quot;&quot;) { @@ -640,6 +718,7 @@ function getPage($oDocument, $bEdit, $sStatusMessage = &quot;&quot;) {
640 $sToRender .= renderDocumentSection("archiveSettings", _("Archive Settings"), $bDisplayLink, $oDocument->getID()); 718 $sToRender .= renderDocumentSection("archiveSettings", _("Archive Settings"), $bDisplayLink, $oDocument->getID());
641 $sToRender .= renderDocumentSection("documentRouting", _("Document Routing"), $bDisplayLink, $oDocument->getID()); 719 $sToRender .= renderDocumentSection("documentRouting", _("Document Routing"), $bDisplayLink, $oDocument->getID());
642 $sToRender .= renderDocumentSection("linkedDocuments", _("Linked Documents"), $bDisplayLink, $oDocument->getID()); 720 $sToRender .= renderDocumentSection("linkedDocuments", _("Linked Documents"), $bDisplayLink, $oDocument->getID());
  721 + $sToRender .= renderDocumentSection("metadataVersions", _("Metadata Versions"), $bDisplayLink, $oDocument->getID());
643 722
644 $sToRender .= "</td></tr>"; 723 $sToRender .= "</td></tr>";
645 $sToRender .= "</table>"; 724 $sToRender .= "</table>";
@@ -663,6 +742,8 @@ function getPage($oDocument, $bEdit, $sStatusMessage = &quot;&quot;) { @@ -663,6 +742,8 @@ function getPage($oDocument, $bEdit, $sStatusMessage = &quot;&quot;) {
663 $sToRender .= renderSectionDiv("documentRouting", renderNonEditableDocumentRouting($oDocument)); 742 $sToRender .= renderSectionDiv("documentRouting", renderNonEditableDocumentRouting($oDocument));
664 $sToRender .= renderSectionDiv("linkedDocuments", renderNonEditableLinkedDocuments($oDocument, $bEdit) . renderDependantDocuments($oDocument, $bEdit)); 743 $sToRender .= renderSectionDiv("linkedDocuments", renderNonEditableLinkedDocuments($oDocument, $bEdit) . renderDependantDocuments($oDocument, $bEdit));
665 } 744 }
  745 + $sToRender .= renderSectionDiv("metadataVersions", renderDocumentVersions($oDocument));
  746 +
666 $sToRender .= "<br />"; 747 $sToRender .= "<br />";
667 $sToRender .= "<br />"; 748 $sToRender .= "<br />";
668 $sToRender .= "<br />"; 749 $sToRender .= "<br />";
@@ -701,6 +782,7 @@ function getStatusPage($oDocument, $sStatusMessage) { @@ -701,6 +782,7 @@ function getStatusPage($oDocument, $sStatusMessage) {
701 $sToRender .= renderDocumentSection("archiveSettings", _("Archive Settings"), $bDisplayLink, $oDocument->getID()); 782 $sToRender .= renderDocumentSection("archiveSettings", _("Archive Settings"), $bDisplayLink, $oDocument->getID());
702 $sToRender .= renderDocumentSection("documentRouting", _("Document Routing"), $bDisplayLink, $oDocument->getID()); 783 $sToRender .= renderDocumentSection("documentRouting", _("Document Routing"), $bDisplayLink, $oDocument->getID());
703 $sToRender .= renderDocumentSection("linkedDocuments", _("Linked Documents"), $bDisplayLink, $oDocument->getID()); 784 $sToRender .= renderDocumentSection("linkedDocuments", _("Linked Documents"), $bDisplayLink, $oDocument->getID());
  785 + $sToRender .= renderDocumentSection("metadataVersions", _("Document Versions"), $bDisplayLink, $oDocument->getID());
704 $sToRender .= "</table>"; 786 $sToRender .= "</table>";
705 $sToRender .= "</div>"; 787 $sToRender .= "</div>";
706 $sToRender .= renderDocumentData($oDocument, false, $sStatusMessage); 788 $sToRender .= renderDocumentData($oDocument, false, $sStatusMessage);